ARcore - невозможно повернуть модель без использования TransformableNode - PullRequest
2 голосов
/ 29 мая 2019

Я создаю приложение 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);

1 Ответ

2 голосов
/ 29 мая 2019

Попробуйте этот код:

// 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);

Надеюсь, это поможет.

...