用Sceneform SDK中的另一个可渲染节点替换可渲染的节点(相同的旋转,位置和比例) [英] Replace node renderable ( same rotation, position and scale ) with another node renderable in Sceneform sdk

查看:202
本文介绍了用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中的另一个可渲染节点替换可渲染的节点(相同的旋转,位置和比例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆