ARCore - 在平面上显示 3D 模型
ARCore - Displaying 3D Model over a plane
我已经使用 ARCore 成功显示了一个 3D 模型,但是我如何将模型直接放置在平面上?
mArFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ar_fragment);
mArFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
Anchor anchor = hitResult.createAnchor();
ModelRenderable.builder()
.setSource(this, Uri.parse("ArcticFox_Posed.sfb"))
.build()
.thenAccept(modelRenderable -> addModelToScene(anchor, modelRenderable))
.exceptionally(throwable -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(throwable.getMessage())
.show();
return null;
});
});
您可以使用 ShapeFactory 使平面可渲染,并使您的狐狸可渲染成为平面对象的子对象,如下所示:
private fun addModelToScene(anchor: Anchor, renderable: Renderable) {
val anchorNode = AnchorNode(anchor)
val node = TransformableNode(fragment.transformationSystem)
node.renderable = renderablePlane //create plane renderable
node.setParent(anchorNode)
val nodeFox = Node()
nodeFox.renderable = renderable
//edit localPosition to fit on the plane with nodeFox.localPosition
nodeFox.setParent(node)
fragment.arSceneView.scene.addChild(anchorNode)
}
我已经使用 ARCore 成功显示了一个 3D 模型,但是我如何将模型直接放置在平面上?
mArFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ar_fragment);
mArFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
Anchor anchor = hitResult.createAnchor();
ModelRenderable.builder()
.setSource(this, Uri.parse("ArcticFox_Posed.sfb"))
.build()
.thenAccept(modelRenderable -> addModelToScene(anchor, modelRenderable))
.exceptionally(throwable -> {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(throwable.getMessage())
.show();
return null;
});
});
您可以使用 ShapeFactory 使平面可渲染,并使您的狐狸可渲染成为平面对象的子对象,如下所示:
private fun addModelToScene(anchor: Anchor, renderable: Renderable) {
val anchorNode = AnchorNode(anchor)
val node = TransformableNode(fragment.transformationSystem)
node.renderable = renderablePlane //create plane renderable
node.setParent(anchorNode)
val nodeFox = Node()
nodeFox.renderable = renderable
//edit localPosition to fit on the plane with nodeFox.localPosition
nodeFox.setParent(node)
fragment.arSceneView.scene.addChild(anchorNode)
}