问题
I'm trying to place a large 3D object (generated from .obj file) in front of camera and not able to do it. The model gets placed considering the hit result as the center point. Any way to get it done?
回答1:
The following code will place an anchor 1M in front of the camera - you can adjust the depth to whatever you need:
// Place the anchor 1m in front of the camera.
Log.d(TAG,"adding Andy in fornt of camera");
Frame frame = arFragment.getArSceneView().getArFrame();
Session session = arFragment.getArSceneView().getSession();
Anchor newMarkAnchor = session.createAnchor(
frame.getCamera().getPose()
.compose(Pose.makeTranslation(0, 0, -1f))
.extractTranslation());
AnchorNode addedAnchorNode = new AnchorNode(newMarkAnchor);
addedAnchorNode.setRenderable(andyRenderable);
addedAnchorNode.setParent(arFragment.getArSceneView().getScene());
You can see a full working example here - this uses a button to add the node rather than using the hit result, which may be useful for you also: https://github.com/mickod/LineView
来源:https://stackoverflow.com/questions/56679208/placing-objects-right-in-front-of-camera-in-arcore-android