繁体   English   中英

如何在相机上加载3D模型?

[英]how to load a 3D model on camera?

有许多库可在活动中加载3D模型。 我正在尝试在实时摄像机上加载3D模型。 但是我什么都找不到。

最受欢迎的图书馆之一是Rajawali

https://github.com/Rajawali/Rajawali

但我不知道是否可以在实时摄像机上加载3D模型。

我使用了Google的ARCore,但我想我应该等待发布第二个版本。

我的问题是:

  1. 是否可以在实时摄像机上加载3D模型?
  2. 如何使用Rajawali库在实时摄像机上加载3D模型。

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

main_activity.xml

<?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

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
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM