Replace node renderable ( same rotation, position and scale ) with another node renderable in Sceneform sdk

不打扰是莪最后的温柔 提交于 2019-12-10 23:33:47

问题


I am new to sceneform sdk for Android . I have added one Transformable Node , then i applied some rotation , scaling and changed its position also. Now on click of button i need to place second node with same rotation , scaling and position.

For that what i did is:

 Node nodeTwo = new Node(); // second node
 nodeTwo.setLocalPosition(nodeOne);
 nodeTwo.setLocalRotation(nodeOne);
 nodeTwo.setLocalScale(nodeOne);
 nodeTwo.setRenderable(renderable); 

I have also tried with setWorldPosition() , setWorldRotation().. But nothing works , second node got placed on fix position and rotation.

Can I do something to 'fix' this?


回答1:


anchor = hitResult.createAnchor();
        anchorNode = new AnchorNode(anchor);
        anchorNode.setParent(arView.getArSceneView().getScene());
        transformableNode = new TransformableNode(arView.getTransformationSystem()); // As you said i have added one transformablenode which will allow transformation.
        transformableNode.setParent(anchorNode);
        transformableNode.setRenderable(modelRenderable);
        transformableNode.select();

Then i added another node which is going to replace first one with same transformation.

 Node node = new Node();
        Vector3 position = transformableNode.getLocalPosition();
        Quaternion rotation = transformableNode.getLocalRotation();
        TransformableNode andyNOde = new TransformableNode(arView.getTransformationSystem());
        andyNOde.setRenderable(andyRenderable);
        andyNOde.setLocalPosition(position);
        andyNOde.setLocalRotation(rotation);
        andyNOde.setParent(node);
        anchorNode.removeChild(transformableNode);
        anchorNode.addChild(node);

It is working with this code, may be you were doing something wrong, check your code twice. Hope it will help!




回答2:


Try this:

Node nodeTwo = new Node(); // second node
nodeTwo.setWorldPosition(nodeOne.getWorldPosition()); 
nodeTwo.setWorldRotation(nodeOne.getWorldRotation());
nodeTwo.setWorldScale(nodeOne.getWorldScale());
nodeTwo.setRenderable(renderable); 


来源:https://stackoverflow.com/questions/53058940/replace-node-renderable-same-rotation-position-and-scale-with-another-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!