engine/gamesys/src/gamesys/scripts/script_spine_model.cpp
/*# set the IK constraint object target position to follow position of a game object
     *
     * Sets a game object as target position of an inverse kinematic (IK) object. As the
     * target game object's position is updated, the constraint object is updated with the
     * new position.
     *
     * @name spine.set_ik_target
     * @param url [type:string|hash|url] the spine model containing the object
     * @param ik_constraint_id [type:string|hash] id of the corresponding IK constraint object
     * @param target_url [type:string|hash|url] target game object
     * @examples
     *
     * The following example assumes that the spine model has id "spinemodel".
     *
     * How to set the target IK position of the right_hand_constraint constraint object of the player object
     * to follow the position of game object with url "some_game_object"
     *
     * ```lua
     * function init(self)
     *   spine.set_ik_target("player#spinemodel", "right_hand_constraint", "some_game_object")
     * end
     * ```
     */
set the IK constraint object target position to follow position of a game object
Sets a game object as target position of an inverse kinematic (IK) object. As the
target game object's position is updated, the constraint object is updated with the
new position.



The following example assumes that the spine model has id "spinemodel".




set the IK constraint object target position to follow position of a game object Sets a game object as target position of an inverse kinematic ( IK ) object . As the target game object ' s position is updated the constraint object is updated with the new position . The following example assumes that the spine model has id " spinemodel " .
int SpineComp_SetIKTarget(lua_State* L)
    {
        int top = lua_gettop(L);
        dmGameObject::HInstance sender_instance = CheckGoInstance(L);
        dmGameObject::HCollection collection = dmGameObject::GetCollection(sender_instance);
        uintptr_t user_data;
        dmMessage::URL receiver;
        SpineModelWorld* world = 0;
        dmGameObject::GetComponentUserDataFromLua(L, 1, collection, SPINE_MODEL_EXT, &user_data, &receiver, (void**) &world);
        SpineModelComponent* component = world->m_Components.Get(user_data);
        dmhash_t ik_constraint_id = dmScript::CheckHashOrString(L, 2);
        dmMessage::URL sender;
        dmScript::GetURL(L, &sender);
        dmMessage::URL target;
        dmScript::ResolveURL(L, 3, &target, &sender);
        if (target.m_Socket != dmGameObject::GetMessageSocket(collection))
        {
            return luaL_error(L, "spine.set_ik_target can only use instances within the same collection.");
        }
        dmGameObject::HInstance target_instance = dmGameObject::GetInstanceFromIdentifier(collection, target.m_Path);
        if (target_instance == 0)
            return luaL_error(L, "Could not find any instance with id '%s'.", dmHashReverseSafe64(target.m_Path));
        if (!CompSpineModelSetIKTargetInstance(component, ik_constraint_id, 1.0f, target.m_Path))
        {
            char str[128];
            return luaL_error(L, "the IK constraint target '%s' could not be found", dmScript::GetStringFromHashOrString(L, 2, str, sizeof(str)));
        }
        assert(top == lua_gettop(L));
        return 0;
    }
int SpineComp_SetIKTarget ( lua_State * L ) { int top = lua_gettop ( L ) ; dmGameObject :: HInstance sender_instance = CheckGoInstance ( L ) ; dmGameObject :: HCollection collection = dmGameObject :: GetCollection ( sender_instance ) ; uintptr_t user_data ; dmMessage :: URL receiver ; SpineModelWorld * world = 0 ; dmGameObject :: GetComponentUserDataFromLua ( L , 1 , collection , SPINE_MODEL_EXT , & user_data , & receiver , ( void * * ) & world ) ; SpineModelComponent * component = world -> m_Components . Get ( user_data ) ; dmhash_t ik_constraint_id = dmScript :: CheckHashOrString ( L , 2 ) ; dmMessage :: URL sender ; dmScript :: GetURL ( L , & sender ) ; dmMessage :: URL target ; dmScript :: ResolveURL ( L , 3 , & target , & sender ) ; if ( target . m_Socket != dmGameObject :: GetMessageSocket ( collection ) ) { return luaL_error ( L , " " ) ; } dmGameObject :: HInstance target_instance = dmGameObject :: GetInstanceFromIdentifier ( collection , target . m_Path ) ; if ( target_instance == 0 ) return luaL_error ( L , " " , dmHashReverseSafe64 ( target . m_Path ) ) ; if ( ! CompSpineModelSetIKTargetInstance ( component , ik_constraint_id , 1.0f , target . m_Path ) ) { char str [ 128 ] ; return luaL_error ( L , " " , dmScript :: GetStringFromHashOrString ( L , 2 , str , sizeof ( str ) ) ) ; } assert ( top == lua_gettop ( L ) ) ; return 0 ; }
set the IK constraint object target position to follow position of a game object
 Sets a game object as target position of an inverse kinematic (IK) object.
set the IK constraint object target position to follow position of a game object Sets a game object as target position of an inverse kinematic ( IK ) object .