ConstraintPlugin¶
Last updated 20/04/2012
The Constraint plugin allows models to be bound to other models with matching bone names.
For example, a sword containing a bone named "left_hand", when bound to a avatar model containing a bone called "left_hand", will move the sword so that the matching bones are in the same position and orientation. The sword will continue move around as the avatar model moves and animates.
Local binding¶
Models can be bound locally so that other clients within the same world will not see the binding. Note that the binding will fail if another user has already network bound the same child element.
To perform a local binding in Lua:
avatar_model = scene:getelement('Avatar')
sword_model = scene:getelement('Sword')
constraintplugin:bind(avatar_model, sword_model)
Networked binding¶
Models can also be bound across the network so that all users see the same thing. When network binding, the user that does the binding is the only one that can remove the binding, either by explicitly removing the binding, or by leaving/disconnecting from the world.
To perform a networked binding in Lua:
avatar_model = scene:getelement('Avatar')
sword_model = scene:getelement('Sword')
constraintplugin:networkbind(avatar_model, sword_model)
Unbinding¶
To unbind either a locally bound or network bound model in Lua:
sword_model = scene:getelement('Sword')
constraintplugin:unbind(sword_model)
Note that calling unbind on a non-bound element will not throw an exception in a Lua script. Also, calling unbind on a network bound model owned by a different user will have no effect.
Querying bindings¶
To query bound children of an element in Lua:
avatar_model = scene:getelement('Avatar')
bound_children = constrainplugin:getboundchildren(avatar_model)
for i = 0, bound_children.count - 1 do
-- access children with bound_children[i]
end
To query if a model is bound to a parent, and to see what that model is:
sword_model = scene:getelement('Sword')
bound_parent = constraintplugin:getboundparent(sword_model)
if bound_parent ~= nil then
-- the child is bound to bound_parent
else
-- the child is not bound
end