Sceneform-android-sdk: How to make pick up / put down translation

Created on 31 May 2018  路  4Comments  路  Source: google-ar/sceneform-android-sdk

Hi,
I trying implement pick up / put down translation on Y axis in example hellosceneform. Now I set setWorldPosition with modified Y-axis value when model is anchored, this picks up model.
How to make this translation based on gesture, like translation on Z or X axis. It is possible with TransformableNode / TranslationController ?

Vector3 cameraPos = this.sceneformFragment.getArSceneView().getScene().getCamera().getWorldPosition();
Vector3 cameraForward = this.sceneformFragment.getArSceneView().getScene().getCamera().getForward();
Vector3 cameraPosUp = new Vector3(cameraPos.x,0.35f,cameraPos.z);
Vector3 finalPosition = Vector3.add(cameraPosUp, cameraForward.scaled(1.0f));
transformableNode.setWorldPosition(finalPosition);

Thanks

Most helpful comment

I've created a working example for how to create an additional gesture and additional transformation controller for raising and lowering a node that can be checked out here.

It uses a two-finger drag gesture to raise/lower the node.

In general, these were the steps:

  1. Create new subclasses of BaseGesture and BaseGestureRecognizer for TwoFingerDragGesture.
  2. Create a new subclass of BaseTransformationController that uses the TwoFingerDragGesture to raise and lower the object.
  3. Create a subclass of TransformableNode to integrate it all together.

One important note: The RaiseController works by raising/lowering a child of the TransformableNode, not the TransformableNode itself. This is so the RaiseController does not conflict with the TranslationController. To make this work, the Renderable is attached to the child of TransformableNode, not the TransformableNode itself.

All 4 comments

If I understand the question correctly you are trying to add a completely new gesture that works with the existing ones, but moves an object up/down instead of on the xz plane?

If so I'll look into this.

@malik-at-work Yes, you understand the question correctly.

I've created a working example for how to create an additional gesture and additional transformation controller for raising and lowering a node that can be checked out here.

It uses a two-finger drag gesture to raise/lower the node.

In general, these were the steps:

  1. Create new subclasses of BaseGesture and BaseGestureRecognizer for TwoFingerDragGesture.
  2. Create a new subclass of BaseTransformationController that uses the TwoFingerDragGesture to raise and lower the object.
  3. Create a subclass of TransformableNode to integrate it all together.

One important note: The RaiseController works by raising/lowering a child of the TransformableNode, not the TransformableNode itself. This is so the RaiseController does not conflict with the TranslationController. To make this work, the Renderable is attached to the child of TransformableNode, not the TransformableNode itself.

@dsternfeld7 Thank you, your implementation works exactly as I wanted.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kunal-wayfair picture kunal-wayfair  路  3Comments

PaulTVungle picture PaulTVungle  路  3Comments

dementia2029 picture dementia2029  路  3Comments

arilotter picture arilotter  路  3Comments

StevenOttoG picture StevenOttoG  路  4Comments