[英]how to load a 3D model on camera?
There are many libraries to load a 3D model inside an activity. 有许多库可在活动中加载3D模型。 I'm trying to load a 3D model on a live camera. 我正在尝试在实时摄像机上加载3D模型。 but I don't find anything to do this. 但是我什么都找不到。
one the popular library is Rajawali
: 最受欢迎的图书馆之一是Rajawali
:
https://github.com/Rajawali/Rajawali https://github.com/Rajawali/Rajawali
but I don't know is it possible to load a 3D model on live camera or not. 但我不知道是否可以在实时摄像机上加载3D模型。
I used google's ARCore but I think I should be waiting to release second version. 我使用了Google的ARCore,但我想我应该等待发布第二个版本。
my questions are: 我的问题是:
Rajawali
library. 如何使用Rajawali
库在实时摄像机上加载3D模型。 My solution was to place an org.rajawali3d.SurfaceView
with transparent background over an android.view.TextureView
that displays the hardware camera: 我的解决方案是将具有透明背景的org.rajawali3d.SurfaceView
放置在显示硬件摄像头的android.view.TextureView
上:
main_activity.xml 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>
And here is MainActivity.java 这是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.