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 ?
2D Scaling problem(4 posts) (2 voices)
Can you post your smart object in this thread?
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.
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.
You must log in to post.