engine/gamesys/src/gamesys/scripts/script_spine_model.cpp
/*# retrieve the game object corresponding to a spine model skeleton bone
     * Returns the id of the game object that corresponds to a specified skeleton bone.
     * The returned game object can be used for parenting and transform queries.
     * This function has complexity `O(n)`, where `n` is the number of bones in the spine model skeleton.
     * Game objects corresponding to a spine model skeleton bone can not be individually deleted.
     *
     * @name spine.get_go
     * @param url [type:string|hash|url] the spine model to query
     * @param bone_id [type:string|hash] id of the corresponding bone
     * @return id [type:hash] id of the game object
     * @examples
     *
     * The following examples assumes that the spine model has id "spinemodel".
     *
     * How to parent the game object of the calling script to the "right_hand" bone of the spine model in a player game object:
     *
     * ```lua
     * function init(self)
     *   local parent = spine.get_go("player#spinemodel", "right_hand")
     *   msg.post(".", "set_parent", {parent_id = parent})
     * end
     * ```
     */
retrieve the game object corresponding to a spine model skeleton bone
Returns the id of the game object that corresponds to a specified skeleton bone.
The returned game object can be used for parenting and transform queries.
This function has complexity `O(n)`, where `n` is the number of bones in the spine model skeleton.
Game objects corresponding to a spine model skeleton bone can not be individually deleted.



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




retrieve the game object corresponding to a spine model skeleton bone Returns the id of the game object that corresponds to a specified skeleton bone . The returned game object can be used for parenting and transform queries . This function has complexity ` O ( n ) ` where ` n ` is the number of bones in the spine model skeleton . Game objects corresponding to a spine model skeleton bone can not be individually deleted . The following examples assumes that the spine model has id " spinemodel " .
int SpineComp_GetGO(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 bone_id = dmScript::CheckHashOrString(L, 2);
        dmRigDDF::Skeleton* skeleton = component->m_Resource->m_RigScene->m_SkeletonRes->m_Skeleton;
        uint32_t bone_count = skeleton->m_Bones.m_Count;
        uint32_t bone_index = ~0u;
        for (uint32_t i = 0; i < bone_count; ++i)
        {
            if (skeleton->m_Bones[i].m_Id == bone_id)
            {
                bone_index = i;
                break;
            }
        }
        if (bone_index == ~0u)
        {
            return luaL_error(L, "the bone '%s' could not be found", lua_tostring(L, 2));
        }
        if(bone_index >= component->m_NodeInstances.Size())
        {
            return luaL_error(L, "no game object found for the bone '%s'", lua_tostring(L, 2));
        }
        dmGameObject::HInstance instance = component->m_NodeInstances[bone_index];
        if (instance == 0x0)
        {
            return luaL_error(L, "no game object found for the bone '%s'", lua_tostring(L, 2));
        }
        dmhash_t instance_id = dmGameObject::GetIdentifier(instance);
        if (instance_id == 0x0)
        {
            return luaL_error(L, "game object contains no identifier for the bone '%s'", lua_tostring(L, 2));
        }
        dmScript::PushHash(L, instance_id);
        assert(top + 1 == lua_gettop(L));
        return 1;
    }
int SpineComp_GetGO ( 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 bone_id = dmScript :: CheckHashOrString ( L , 2 ) ; dmRigDDF :: Skeleton * skeleton = component -> m_Resource -> m_RigScene -> m_SkeletonRes -> m_Skeleton ; uint32_t bone_count = skeleton -> m_Bones . m_Count ; uint32_t bone_index = ~ 0u ; for ( uint32_t i = 0 ; i < bone_count ; ++ i ) { if ( skeleton -> m_Bones [ i ] . m_Id == bone_id ) { bone_index = i ; break ; } } if ( bone_index == ~ 0u ) { return luaL_error ( L , " " , lua_tostring ( L , 2 ) ) ; } if ( bone_index >= component -> m_NodeInstances . Size ( ) ) { return luaL_error ( L , " " , lua_tostring ( L , 2 ) ) ; } dmGameObject :: HInstance instance = component -> m_NodeInstances [ bone_index ] ; if ( instance == 0x0 ) { return luaL_error ( L , " " , lua_tostring ( L , 2 ) ) ; } dmhash_t instance_id = dmGameObject :: GetIdentifier ( instance ) ; if ( instance_id == 0x0 ) { return luaL_error ( L , " " , lua_tostring ( L , 2 ) ) ; } dmScript :: PushHash ( L , instance_id ) ; assert ( top + 1 == lua_gettop ( L ) ) ; return 1 ; }
retrieve the game object corresponding to a spine model skeleton bone
 Returns the id of the game object that corresponds to a specified skeleton bone.
retrieve the game object corresponding to a spine model skeleton bone Returns the id of the game object that corresponds to a specified skeleton bone .