我正在创建一个AR应用程序,但是我的模型之一方向错误。
我需要旋转它,但不允许用户通过触摸旋转它。 加载后,必须保持相同的方向。
我尝试了下面的代码和TransformableNode。
AnchorNode anchorNode = new AnchorNode(anchor);
if (imageName.equals("fox")){
anchorNode.setLocalRotation(Quaternion.axisAngle(new
Vector3(0f, 0, 1f), 180f));
}else
anchorNode.setLocalRotation(Quaternion.axisAngle(new
Vector3(1f, 0, 0f), -10f));
anchorNode.setRenderable(modelRenderable);
arFragment.getArSceneView().getScene().onAddChild(anchorNode);
答案 0 :(得分:2)
尝试以下代码:
// Imaginary anchor – example 1
float[] position = { 0, 0, -0.5 };
float[] rotation = { 0, 0, 0, 1 };
Anchor anchor = session.createAnchor(new Pose(position, rotation));
// Imaginary anchor – example 2
Anchor anchor = hitResult.createAnchor();
///////////////////////////////////////////////
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());
// 180 Degrees CCW
Quaternion rotation180 = Quaternion.axisAngle(new Vector3(0.0f, 0.0f, 1.0f), 180);
// 10 Degrees CW
Quaternion rotation010 = Quaternion.axisAngle(new Vector3(1.0f, 0.0f, 0.0f), -10);
TransformableNode node = new TransformableNode(arFragment.getTransformationSystem());
node.setParent(anchorNode);
node.select();
if (imageName.equals("fox")) {
node.setLocalRotation(rotation180);
Node foxxy = new Node();
foxxy.setParent(node);
foxxy.setRenderable(modelRenderable);
} else {
node.setLocalRotation(rotation010);
Node notFox = new Node();
notFox.setParent(node);
notFox.setRenderable(modelRenderable);
}
arFragment.getArSceneView().getScene().onAddChild(node);
希望这会有所帮助。