Rhino C++ plugin question : How do I get an object's transformation attributes?


(Alex) #1

Hi there, I am using the C++ SDK for rhino, and I want to get the attributes regarding the transformation (and translation, rotation, scale, etc) of that object.
I have been looking through the docs, but so far I have only found:
bool ON_3dmObjectAttributes::Transform ( const ON_Xform & xform )

I don’t think that this will be useful for me. So, what do I do to get the object’s transformation data?
Thanks!


#2

Hi Alex
if You are talking about block instances then the transform is inside the reference
objects.
Geometric objects do not have a transformation like other modelling programs
where the object lives in a local space and gets instantiated trough a hierarchy of transformations.

gerry


(Dale Fugier) #3

Hi @alexian007,

Rhino object do not maintain any kind of translation (or translation history) information.

Why do you need this?

– Dale


(Alex) #4

Hi @dale,

So, if it is not stored, then how does Rhino determine its position, where it is right now? Usually, in 3D programs and game engines, all objects do have a Vector3 (x,y,z) points to represent their vertices and position.

I need this, as I am making a 3DM exporter to another file format. How should I do that then? How did the Rhino team handle the task of transferring all the object information accurately into another 3d modeling software, especially the object’s position (and also the mesh, mesh indices, etc) ?


(Alex) #5

Hi Garry!

I am not talking about the blocks. What I mean is, a regular rhino object, say, a line, a box, etc.

Okay, so how exactly do I get the data where to place the rhino objects when exporting them to another file format in another 3D modeling software/ or a 3D model viewer software, as the one I’m working with requires the transform attributes to decide where to display the object?


(Dale Fugier) #6

The geometry defines the position. When you transform an object in Rhino, you’re transforming (e.g. modifying) the geometry.

I’m not sure I understand the question, let alone how to answer it. I’ll need more information on the format you’re trying to support.

– Dale


(Alex) #7

Hey @dale,

So sorry for not being precise and clear with my question. I will explain it now, in a clear manner.

So, my aim is to get the transforms, rotation (quaternion), translations of a rhino object.
Why?
Well, you see, I am working with a 3D viewer software, that has its own object something like this, that is equivalent of a Rhino Object :

struct Object
{
string Name;   // which I can get from rhino_object->Name(); 
string UUID; // equivalent to :  rhino_object->Attributes().m_uuid;
bool isVisible; // rhino_object->IsActiveInDocument();
...
..
Vector3 transformation; (Here, vector3 is a custom data structure, that can hold 3 float values. eg (1.2,1.2,3.4))
...
}

So, I need to get the transformation value to let the custom 3D viewer software know the location of the Rhino object.

Now, so far, I’ve got the Rhino objects through the ObjectIterator and the name and UUID through its Attributes(). But, I have no clue regarding how do I get the transformation property.

Was that clear?

Please let me know if it wasn’t . Also, I would love to hear more from you on how can I do this ?

Thank you!


(Dale Fugier) #8

Hi @alexian007,

A vector isn’t going to give you rotation. But it might serve as a translation (e.g. direction) vector.

This is something you’ll have to play with to get right. I’d start by doing something like this:

ON_BoundingBox bbox  = rhino_object->BoundingBox();
ON_3dVector dir = bbox.Center() - ON_3dPoint::Origin;

Then translate dir to the Vector3 object type.

– Dale


#9

Hi Alex
Rhino objects are simply root objects
With a identity transform

Inviato dal mio dispositivo Huawei

alexian007
Alex

    December 3

Hi Garry!

gerryark:
if You are talking about block instances then the transform is inside the reference

objects.

I am not talking about the blocks. What I mean is, a regular rhino object, say, a line, a box, etc.

gerryark:
Geometric objects do not have a transformation like other modelling programs

where the object lives in a local space and gets instantiated trough a hierarchy of transformations.

gerry

Okay, so how exactly do I get the data where to place the rhino objects when exporting them to another file format in another 3D modeling software/ or a 3D model viewer software, as the one I’m working with requires the transform attributes to decide where to display the object?


Visit Topic or reply to this email to respond.


In Reply To

gerryark

    December 3

Hi Alex if You are talking about block instances then the transform is inside the reference objects. Geometric objects do not have a transformation like other modelling programs where the object lives in a local space and gets instantiated trough a hierarchy of transformations. gerry


Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click here.

-------- Messaggio originale --------


(Willem Derks) #10

Hi Alex

In Rhino, Objects have their 3D location stored without an additional transformation ( except for blocks but thats not for now)

So a mesh has vertices defined by an xyz coordinate at the location they are at in the file.
There is no additional transformation.

Indeed for many applications there is a base definition of an object and on top there are transformations to orient it in 3D space.

In your struct Object I’d start with storing the Vector3 transformation as (0,0,0) and see what happens.

However thinking about this, it might be this Vector3 provides a means to map/orient the object on another axissystem:

Many viewers have xy for the vertical plane and xz for the horizontal, where Rhino has xz as vertical plane and xy as horizontal.

good luck
-Willem


(jesterKing) #11

For the 3dm importer I do just that: rhino objects at (0,0,0) as their object location. If users want they can always reposition the object origos to i.e. the geometry bounding box center.


(Alex) #12

Hi @dale,
So from what I have gathered from all the helpful answers in here, Rhino objects do not have a separate values to denote their current scale, translation and rotation, right?

(For example, this is a gameobject in Unity3D, which has a Transform component that gives data about its various values:)
unityTransform

So I will use the bounding box and get their origin as the object’s translate (position on the 3d world), as you have mentioned.

Also, so what would be a suitable way to get their scale and their rotation, as these information are crucial for the custom 3D viewer to correctly place objects on the scene?


(Alex) #13

Hey @jesterking
Yes, that sounds like the way to go for getting the location. Could you also share with me your approach for getting the scale and the rotational values ?


(Alex) #14

Hey @Willem,

Thank you for clearing that up, I simply thought that there would be an additional transform component, but as you’ve said, it’s not the case.

Ah yes, I would also have to take that into consideration. Thanks for pointing that out!

Also, if you had any ideas on how should I proceed further on, I would love to hear it !

Thank you!


(Alex) #15

Thanks for clearing that up @gerryark ! That makes sense.


(Wim Dekeyser) #16

It’s simply the same with all transformations - position, scale, and rotation. The object is where it is, at scale 1:1 and not rotated.


(Alex) #17

Hey wim,
I apologize , but I’m not sure that I got what you were trying to say.
And I also think I should be more descriptive, so here goes:

Here’s a box in Rhino:
1

Now, I moved it a few units here and there:
2

So, what I’m asking is that if the object was at origin in the first at 0,0,0 and now I’ve moved it, how do I know what position is it at right now? Is it stored in somewhere?

In some game engines, there is a separate component inside the object that tells me all that.

For eg, in Unity3D:
unityTransform
I can clearly get the scale, position, rotation value of any object.

So I’m asking, is there any equivalent thing in Rhino for a CRhinoObject, or how should I proceed to get these values?


(jesterKing) #18

You’ll find that the transform is still the identity transform, and that the geometry is now different. In other words the geometry gets recalculated completely, and the transform “history” is thus lost.