Esempio n. 1
0
JObject* JBoundsEditor::GetEditorsGroup()
{
    JObject* pEditors = g_pObjectServer->FindObject( "editors", this );
    if (pEditors == NULL)
    {
        pEditors = new JGroup();
        AddChild( pEditors );
        pEditors->SetName( "editors" );
    }
    return pEditors;
}
Esempio n. 2
0
int JLuaServer::FnCreate( lua_State* pLua )
{
    int nParam = lua_gettop( pLua );
    if (nParam < 1 || nParam > 3)
    {
        rlog.err( "LUA: Incorrect command usage: <create>. "
            "Must be: create( <className or fileName> | <templateObject>, [<newName>, <parentObject>] )" );
        lua_settop( pLua, 0 );
        lua_pushnil( pLua );
        return 1;
    }
    
    //  first parameter
    const char* pClassName = lua_tostring( pLua, 1 );
    JObject* pTemplateObj = NULL;
    if (!pClassName)
    {
        pTemplateObj = (JObject*)lua_touserdata( pLua, 1 );
    }

    //  second parameter
    const char* pObjName   = lua_tostring( pLua, 2 );

    //  third parameter
    JObject* pParentObj = NULL;
    if (nParam > 2)
    {
        pParentObj = (JObject*)lua_touserdata( pLua, 3 );
    }
    else
    {
        JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
        assert( pThread->m_pLua == pLua );
        pParentObj = pThread->m_pRootObj;
    }

    JObject* pObj = NULL;
    if (pClassName)
    {
        pObj = g_pObjectServer->Create( pClassName );
        //  try to load from script
        if (pObj == NULL)
        {
            pObj = g_pPersistServer->LoadObject( pClassName );
        }
        if (pObj == NULL)
        {
            rlog.err( "LUA: Cannot create an object because of unknown class (or filename): %s", pClassName );
            lua_settop( pLua, 0 );
            lua_pushnil( pLua );
            return 1;
        }
        if (pObjName) 
        {
            pObj->SetName( pObjName );
        }
    }
    else if (pTemplateObj)
    {
        pObj = pTemplateObj->Clone( pParentObj, pObjName );
    }

    if (pParentObj)
    {
        pParentObj->AddChild( pObj );
    }

    lua_settop( pLua, 0 );
    lua_pushlightuserdata( pLua, pObj );
    return 1;
} // JLuaServer::FnCreate
Esempio n. 3
0
JObject* RBExport::ProcessPhysicsObject( INode* node )
{
    ObjectState os = node->EvalWorldState( m_CurTime ); 
    Object* pObj = os.obj;
    const char* pNodeName = node->GetName();

    if (!pObj)
    {
        Warn( "Physics node %s is invalid.", pNodeName );
    }

    JObject* pPhysObj = NULL;
    Mat4 objTM = Convert( GetLocalTM( node, m_CurTime ) );

    JString hostName = "";

    ExpNode* pExportedParent = GetExportedNode( node->GetParentNode() );
    if (pExportedParent && pExportedParent->m_pObject)
    {
        JObject* pParentObj = pExportedParent->m_pObject;
        if (obj_cast<PhysBody>( pParentObj ))
        {
            hostName = pParentObj->GetName();
        }
        else if (obj_cast<JBone>( pParentObj ))
        {
            hostName = pParentObj->GetName();
        }
    }

    //  check for joint type
    DWORD scID = pObj->SuperClassID();
    if (scID == HELPER_CLASS_ID) 
    {
        PhysJoint* pJoint = new PhysJoint(); 
        pJoint->SetHostBone( hostName.c_str() );
        pPhysObj = pJoint;
    }
    else
    {
        CStr className;
        pObj->GetClassName( className );
        IParamArray* pParam = pObj->GetParamBlock();
        IParamBlock* pParamBlock = NULL;

        if (pParam) pParamBlock = pParam->GetParamBlock();

        if (!stricmp( className, "sphere" ))
        {
            ColSphere* pSphere = new ColSphere();
            pPhysObj = pSphere;
            float radius = 0.0f;
            pParamBlock->GetValue( SPHERE_RADIUS, 0, radius, FOREVER );
            pSphere->SetRadius( radius );
            pSphere->SetHost( hostName.c_str() );
            pSphere->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "box" ))
        {
            ColBox* pBox = new ColBox();
            pPhysObj = pBox;
            Vec3 ext;
            pParamBlock->GetValue( BOXOBJ_LENGTH, 0, ext.x, FOREVER );
            pParamBlock->GetValue( BOXOBJ_WIDTH,  0, ext.y, FOREVER );
            pParamBlock->GetValue( BOXOBJ_HEIGHT, 0, ext.z, FOREVER );
            pBox->SetExtents( ext );
            pBox->SetHost( hostName.c_str() );
            pBox->SetOffsetTM( objTM );
        }
        
        if (!stricmp( className, "capsule" ))
        {
            ColCapsule* pCapsule = new ColCapsule();
            pPhysObj = pCapsule;
            int   bCenters = 0;
            float radius   = 0.0f;
            float height   = 0.0f;
            pParamBlock->GetValue( PB_RADIUS,  0, radius,   FOREVER );
            pParamBlock->GetValue( PB_HEIGHT,  0, height,   FOREVER );
            pParamBlock->GetValue( PB_CENTERS, 0, bCenters, FOREVER );
            pCapsule->SetRadius( radius );
            pCapsule->SetHeight( height );
            pCapsule->SetHost( hostName.c_str() );
            pCapsule->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "cylinder" ))
        {
            ColCylinder* pCylinder = new ColCylinder();
            pPhysObj = pCylinder;
            int   bCenters = 0;
            float radius   = 0.0f;
            float height   = 0.0f;
            pParamBlock->GetValue( PB_RADIUS,  0, radius,   FOREVER );
            pParamBlock->GetValue( PB_HEIGHT,  0, height,   FOREVER );
            pParamBlock->GetValue( PB_CENTERS, 0, bCenters, FOREVER );
            pCylinder->SetRadius( radius );
            pCylinder->SetHeight( height );
            pCylinder->SetHost( hostName.c_str() );
            pCylinder->SetOffsetTM( objTM );
        }

        if (!stricmp( className, "teapot" ))
        {
            //  by teapot we represent physical body (point of mass)
            PhysBody* pBody = new PhysBody();
            pBody->SetHostBone( hostName.c_str() );
            pPhysObj = pBody;
            pBody->SetOffsetTM( objTM );
        }

        //  if none of above,  try to export as trimesh collision primitive
        if (pPhysObj == NULL && scID == GEOMOBJECT_CLASS_ID)
        {
            ColMesh* pMesh = GetColMesh( node );
            if (pMesh)
            {
                pPhysObj = pMesh;
                pMesh->SetHost( hostName.c_str() );
                pMesh->SetOffsetTM( objTM );
            }
        }
    }
    
    if (pPhysObj)
    {
        if (!m_pPhysicsGroup)
        {
            m_pPhysicsGroup = new JGroup();
            m_pPhysicsGroup->SetName( "physics" );
        }
        pPhysObj->SetName( pNodeName );
        m_pPhysicsGroup->AddChild( pPhysObj );
    }
    else
    {
        Warn( "Unrecognized physics object type in  node %s", pNodeName );
        return NULL;
    }
    return pPhysObj;
} // RBExport::ProcessPhysicsObject