首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在摄像机上加载三维模型?

问如何在摄像机上加载三维模型?
EN

Stack Overflow用户
提问于 2018-03-01 11:27:00
回答 1查看 966关注 0票数 1

有许多库可以在一个活动中加载一个3D模型。我正试着在直播相机上装一个3D模型。但我什么都找不到。

一个流行的图书馆是Rajawali。

https://github.com/Rajawali/Rajawali

但我不知道是否有可能在直播相机上加载3D模型。

我使用谷歌的ARCore,但我认为我应该等待发布第二个版本。

我的问题是:

  1. 可以在现场摄像机上加载3D模型吗?
  2. 如何用Rajawali库在实时摄像机上加载三维模型。
EN

回答 1

Stack Overflow用户

发布于 2019-07-11 07:14:07

我的解决方案是将具有透明背景的org.rajawali3d.SurfaceView放置在显示硬件摄像机的android.view.TextureView上:

main_activity.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent">

    <TextureView
        android:id="@+id/camera_surface"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- org.rajawali3d.view. -->

    <org.rajawali3d.view.SurfaceView
        android:id="@+id/rajawali_surface"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"/>
</FrameLayout>

这是MainActivity.java

代码语言:javascript
复制
import android.app.Activity;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.TextureView;

import org.rajawali3d.view.ISurface;
import org.rajawali3d.view.SurfaceView;

import java.io.IOException;

import eiggsplore.scot.eiggsplore2.world3d.TerrainRenderer;

public class MainActivity extends Activity implements TextureView.SurfaceTextureListener{

    private TerrainRenderer renderer;
    private Camera cam;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SurfaceView rajawali_surface = (SurfaceView)findViewById(R.id.rajawali_surface);
        rajawali_surface.setFrameRate(60.0);
        rajawali_surface.setRenderMode(ISurface.RENDERMODE_WHEN_DIRTY);
        rajawali_surface.setTransparent(true);
        renderer = new TerrainRenderer(rajawali_surface, this);


        TextureView camera_surface =(TextureView)findViewById(R.id.camera_surface);
        camera_surface.setSurfaceTextureListener(this);
    }

    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
        cam = Camera.open();

        try {
            cam.setPreviewTexture(surface);
            cam.startPreview();
        } catch (IOException ioe) {
            // Something bad happened
        }
    }

    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        // Ignored, Camera does all the work for us
    }

    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        cam.stopPreview();
        cam.release();
        return true;
    }

    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
        // Invoked every time there's a new Camera preview frame
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49048710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档