google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 604 forks source link

Get rotation from ModelRenderable #383

Closed bobekos closed 5 years ago

bobekos commented 5 years ago

I know that to get the real model size you can use the getCollisionShape function and cast it to the Box Object. But it seems that the quaternion for the rotation is not filled. It doesn't matter which object is loaded the result is always the same.

Box box = ((Box) planeTestRenderable.getCollisionShape());
Vector3 size = box.getSize();
Vector3 center = box.getCenter();
Quaternion rotation = box.getRotation(); //Always the same result

Also

Matrix m = new Matrix();
planeTestRenderable.getFinalModelMatrix(m);
Quaternion quaternion = m.extractQuaternion();

doesn't work.

Is this a bug? And how can i copy the rotation from one renderable to another without modify the node?

many thanks in advance

Ps. The gltf model for the example download

malik-at-work commented 5 years ago

You'll want node.getLocalRotation or node.getWorldRotation.

When Renderables are used, they are used as a template and copied or shared with a node. A single renderable may be copied to many nodes cheaply using this. But it means the data you are looking for is not owned by a Renderable. Only Nodes actually have a position/orientation in the world.

bobekos commented 5 years ago

Hallo @malik-at-work

thanks for the response. Is there another option to replace one renderable with another in the same node? For example i convert the example gltf (see above) to sfb with the default gltf material (it is a simple plane). Now i want to create a texture cube over shapefactory and it should appears at the same location, with the same size and rotation as the renderable from the sfb. Background of the whole thing is, in the example above there is no chance to add a texture at runtime to the renderable. The only parameters i get from getMaterial method are "metallicFactor, roughnessFactor, baseColorFactor, emissiveFactor".So i can't modify the renderable created from the sfb file. That's why I thought I could just copy the renderable data and paste it to a renderable created from shape factory to control the texture. Or is there another way to do that without modify the sfb file?

bobekos commented 5 years ago

@malik-at-work

But I can change the material at runtime. That is actually all I wanted. First read then do. I'm sorry about this 😃