本文介绍了用 Sceneform sdk 中的另一个可渲染节点替换可渲染节点(相同的旋转、位置和缩放)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 版 Sceneform sdk 的新手.我添加了一个 Transformable Node ,然后我应用了一些旋转、缩放并改变了它的位置.现在单击按钮,我需要放置具有相同旋转、缩放和位置的第二个节点.

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.

为此,我所做的是:

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

我也尝试过 setWorldPosition() , setWorldRotation() ..但是没有任何效果,第二个节点被放置在固定位置和旋转位置.

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?

推荐答案

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!

这篇关于用 Sceneform sdk 中的另一个可渲染节点替换可渲染节点(相同的旋转、位置和缩放)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:35