2

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?

ImLearning
  • 357
  • 1
  • 3
  • 16

2 Answers2

5
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!

RoshanPatel
  • 111
  • 5
  • Thanks man !!! It's working , it was just a silly mistake. I was adding one Base below Anchor node as parent which is the cause of problem. – ImLearning Oct 31 '18 at 05:11
0

Try this:

Node nodeTwo = new Node(); // second node
nodeTwo.setWorldPosition(nodeOne.getWorldPosition()); 
nodeTwo.setWorldRotation(nodeOne.getWorldRotation());
nodeTwo.setWorldScale(nodeOne.getWorldScale());
nodeTwo.setRenderable(renderable); 
Shubham Agrawal
  • 1,252
  • 12
  • 29
  • @ImLearning please explain what do you want to achieve or what's your final result you want, so that I can help – Shubham Agrawal Oct 30 '18 at 12:14
  • Thanks for reply, let say i have added one Transformable node with some renderable , now i am applying some rotation , scaling and position changes . Now on click of button i want to remove first node and add a new node with different renderable which having same rotation , scaling and position same as first node having. I Hope this will help you to understand the question – ImLearning Oct 30 '18 at 12:35
  • Why should the OP, or anyone else reading this "try this"? Instead of adding such non-sentences to your posts, please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post. – Adriaan Oct 04 '22 at 06:45