2D Scaling problem

(4 posts) (2 voices)

Tags:

No tags yet.

  1. staleb

    member
    Joined: May '13
    Posts: 11

    Hi,
    I have created a smartobject under Studio that contains a 2D Textured node. I use a VSL script to adjust the size and scale of this node according to the dimensions of other objects in the smartobject.
    The problem I am having is that the size of the node isn't the same under studio, 3DVIA player or 3DVIA scenes.
    I also tried to resize the parent node (an empty 3D entity) instead, but it didn't work.
    Is there some way to bypass this issue ?
    Thanks !

    Posted 2 years ago #
  2. tiusnonos

    Studio/Virtools Guru
    Joined: Jun '07
    Posts: 343

    Hi staleb,
    Can you post your smart object in this thread?
    Thx

    Posted 2 years ago #
  3. staleb

    member
    Joined: May '13
    Posts: 11

    Ok, I've created two projects to illustrate my problem.

    In the first one, I have a static 2D Node that I try to resize according to the dimensions of a 3D object, but I need to set a scale of 15 to have a somewhat correct view in Studio. Under 3DVIA Scenes I have the same visual result, but under 3DVIA Player the whole Smart Object is too small (but i guess this is a different issue).

    In the second project, I created the node dynamically, and here, even when setting a normal scale ( = 1 ), the 2D node appears too big in 3DVIA scenes and player (and in the last one, the smart object is still too small).
    Plus, in Scenes, when I try to delete the smart object, the 2D node stays active until I restart the scene.

    Thanks

    Attachments

    1. dynamic2d.zip (406.2 KB, 3 downloads) 2 years old
    2. static2d.zip (406.1 KB, 1 downloads) 2 years old
    WARNING: Files uploaded in the forums are not monitored by 3DVIA and therefore might contain content that is malicious or offensive. Download at your own risk
    Posted 2 years ago #
  4. tiusnonos

    Studio/Virtools Guru
    Joined: Jun '07
    Posts: 343

    Best Answer

    Hello staleb,

    Concerning your first project, you have linked a vkNode2D to a vkNode3D so your Node3D be displayed into the 3DView.
    This is a smart way to get a 3D plan whose size can be changed easily but there are some consequences concerning size.

    But first, you shouldn't use the dimension property of your Node3D. Because it does not take into account the scale factor of your object. The dimension property is only the refrential size of the object.
    The best way to know exactly the size of your object is to get its bounding volume.

    vkAABox box;
    Entity3D.ComputeBoundingAABox(box);
    vkDebugInfos::Instance().RegisterPrimitive(box, vkIColor(255,0,0,255), 10000); // Just to display the bounding volume

    Now you could resize your vkNode2D according to the boundingbox.

    vkVec2 size(box.halfsize.z * 2.0f, box.halfsize.y * 2.0f);
    Node2D.SetSize(size);

    But this won't work in your case because the consequence of using a vkNode2D parented to a vkNode3D is that you need to multiply the actual dimension of the vkNode3D by the size you want of the vkNode2D. This is quite tricky!
    Here is the code you should use:

    // Get the dimension of the Node3D parent
    vkNode3DPtr Node3D = Node2D; // casting vkNode2D to get the vkNode3D in the component ring
    vkVec3 dim;
    Node3D.GetDimensions(dim);
    
    // Set the size of the Node2D
    vkVec2 size(box.halfsize.z * 2.0f * dim.x, box.halfsize.y * 2.0f * dim.y);
    Node2D.SetSize(size);

    Be carefull, it seems that the pivot of your 3D model is not centred.

    Posted 2 years ago #

Reply

You must log in to post.