Forum

Constraining dynamically loaded objects

11 September 2015 16:24 #3753
I have two json files loaded dynamically, each containing a number of objects parented to an armature.
Manipulating and add constraints the objects of the firstly loaded json file work fine.
The objects from the secondly loaded file can be moved around by API calls and constrained successfully by
append_copy_trans()
against each other.
But when I use
append_stiff_trans_rot()
(which I need to use to append objects to other objects of this file) the objects get snug to some center point of this group of objects. There's no way for me to get around this
It seems that all objects are dynamic and parented in the same way to a single bone of their armature.

Before real armature API handling comes down the road I need a way to work around this, Please?
11 September 2015 18:12 #3757
Hello,

This behavior seems expectable to me. If we'll take a look at the description for the append_stiff_trans_rot() method:
append_stiff_trans_rot(obj, target, offset, rotation_offsetopt);

we'll notice the offset parameter. If it is set to [0,0,0], all constrainted objects will move to the center of the target object.

But the same situation will occur with append_copy_trans() method and I'm not sure that you really have some difference in these two cases.

Maybe, I misunderstood something. Then it is better to see a real example and the code.
Blend4Web developer
14 September 2015 08:55 #3766
Well, I use translational offset in both cases. I have a function, that determines this offset and uses the resulting vector during appending. This has been debugged and seems to work fine.
function appendObjects(child, target, DoF, delta){
    var tmp1 = m_trans.get_translation(child);
    var tmp2 = m_trans.get_translation(target);
    if(!delta){
        delta =  m_vec3.create();
        m_vec3.sub(tmp1, tmp2, delta); 
    }
        
    if(DoF == "rot")
        m_cons.append_stiff_trans_rot(child, target, delta);
    else
        m_cons.append_copy_trans(child, target, delta);

Could there be any issue with the model, in terms of Do I have to prepare the model in any way for successfully using this function?
14 September 2015 09:19 #3767
I just found out, loading the first json file as second file again and thus using the same model twice doesn't show the strange behaviour. I am appending the second model to the first model, but loading the same json file this time.
So there must be something about the model. Something with the centers?
14 September 2015 10:55 #3774
Ответ на сообщение пользователя goeck
I just found out, loading the first json file as second file again and thus using the same model twice doesn't show the strange behaviour. I am appending the second model to the first model, but loading the same json file this time.
So there must be something about the model. Something with the centers?
Probably it is. Constraints use the origin from Blender. If you have such behavior, maybe there is really something wrong with models. Can we see the example Blend file? If we can, specify please which object is constrained to which one.
Blend4Web developer
14 September 2015 11:26 #3777
Could I please mail or PM the file to you? The models contain intellectual property which is not public domain.

In the meantime I discovered a major difference between the two models is, the one had an armature and vertex groups attached to the armature. The other had no vertex groups but simply objects parented to bones, so I introduced the vertex groups which makes the bin file bigger but had no positive effect on the contraining.
14 September 2015 11:37 #3778
Yes. You can send me a mail to evgeny-ar@blend4web.com. I'll answer about the investigation in this topic.
Blend4Web developer
14 September 2015 12:12 #3779
I've just sent you a mail containing a link where you can download the files. Blend files and the webinterface files.
thanks so much
15 September 2015 15:39 #3810
Hello,

After inspecting your blend files, I've found that most of the scene objects have a scale value of 0.001. Here what we have because of this.
As you've described above, the following code calculates delta:
var tmp1 = m_trans.get_translation(child);
var tmp2 = m_trans.get_translation(target);
delta =  m_vec3.create();
m_vec3.sub(tmp1, tmp2, delta); 

And it is given in the world space.

After this you apply this delta in the constraint:
m_cons.append_stiff_trans_rot(child, target, delta);

and here is the error because, as it is mentioned in the documentation, offset here is given in the parent's local space. So instead of for example [1, 2, 1] delta we have [0.001, 0.002, 0.001].

Everything you need to do is to apply scale. Hope, this will help.
Blend4Web developer
16 September 2015 10:30 #3840
Evgeny,

thanks so much for investigating this issue. The solution you gave was perfectly right.
I applied the scale and also rotation in blender, reexported and the model just looked and worked fine in the webplayer.
Only issue left is, I need to rotate a segment that is constrained by
append_stiff_trans_rot()
from within an javascript event handler.
I tried with removing the constraints at the beginning of the event handler code, applying a rotation and reconstraining the object again. This leads to no solution…


 
Please register or log in to leave a reply.