SBAPI bool SBM_Init( SBMHANDLE sbmHandle, const char * pythonLibPath, bool logToFile ) { if ( !SBM_HandleExists( sbmHandle ) ) { return false; } // this is the first getScene() called by the system SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); scene->addSceneListener(g_smartbodyDLLInstances[ g_handleId_DLL ]->m_listener); vhcl::Log::g_log.AddListener(g_smartbodyDLLInstances[ g_handleId_DLL ]->m_logListener); vhcl::Log::g_log.AddListener(new vhcl::Log::DebuggerListener()); initPython(pythonLibPath); SBM_InitLocalSpeechRelay(); srArgBuffer arg_buf( "" ); mcu_vrAllCall_func( arg_buf, scene->getCommandManager() ); if (logToFile) { scene->startFileLogging("./smartbody.log"); } return true; }
void SbmPawn::setSkeleton(SkSkeleton* sk) { if (!sk) { LOG("Cannot set a null skeleton on object %s", getName().c_str()); return; } if (_skeleton) { ct_tree_p->remove_skeleton( _skeleton->getName() ); //_skeleton->unref(); delete _skeleton; } _skeleton = sk; _skeleton->ref(); ct_tree_p->add_skeleton( _skeleton->getName(), _skeleton ); //scene_p->init(_skeleton); //int err = mcu.add_scene(scene_p); float height = _skeleton->getCurrentHeight(); setHeight(height); //_skeleton->ref(); SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); std::vector<SmartBody::SBSceneListener*>& listeners = scene->getSceneListeners(); for (size_t i = 0; i < listeners.size(); i++) { listeners[i]->OnCharacterUpdate( getName() ); } }
void SBDebuggerUtility::queryResources() { SmartBody::SBScene* sbScene = SmartBody::SBScene::getScene(); SmartBody::SBDebuggerClient* client = sbScene->getDebuggerClient(); if (!client) return; // get assets std::string assetTypes[4] = {"script", "motion", "audio", "mesh"}; NetRequest::RequestId correspondingIds[4] = {NetRequest::Get_Seq_Asset_Paths, NetRequest::Get_ME_Asset_Paths, NetRequest::Get_Audio_Asset_Paths, NetRequest::Get_Mesh_Asset_Paths}; for (int i = 0; i < 4; i++) { std::string command = vhcl::Format("scene.getAssetPaths(\'%s\')", assetTypes[i].c_str()); client->SendSBMCommand(correspondingIds[i], "string-array", command, QueryResourcesCB, this); } // get scripts, service, motion client->SendSBMCommand(NetRequest::Get_Script_Names, "string-array", "scene.getScriptNames()", QueryResourcesCB, this); client->SendSBMCommand(NetRequest::Get_Service_Names, "string-array", "scene.getServiceManager().getServiceNames()", QueryResourcesCB, this); client->SendSBMCommand(NetRequest::Get_Motion_Names, "string-array", "scene.getMotionNames()", QueryResourcesCB, this); // client->SendSBMCommand(NetRequest::Get_Skeleton_Names, "string-array", "scene.getSkeletonNames()", QueryResourcesCB, this); // client->SendSBMCommand(NetRequest::Get_BoneMap_Names, "string-array", "scene.getBoneMapNames()", QueryResourcesCB, this); // client->SendSBMCommand(NetRequest::Get_EventHandler_Names, "string-array", "scene.getEventHandlerNames()", QueryResourcesCB, this); client->SendSBMCommand(NetRequest::Get_Scene_Scale, "float", "scene.getScale()", QueryResourcesCB, this); }
int SbmPawn::init( SkSkeleton* new_skeleton_p ) { if( _skeleton ) { ct_tree_p->remove_skeleton( _skeleton->getName() ); //_skeleton->unref(); delete _skeleton; } _skeleton = new_skeleton_p; if( _skeleton ) { _skeleton->ref(); if( init_skeleton()!=CMD_SUCCESS ) { return CMD_FAILURE; } ct_tree_p->add_skeleton( _skeleton->getName(), _skeleton ); SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); std::vector<SmartBody::SBSceneListener*>& listeners = scene->getSceneListeners(); for (size_t i = 0; i < listeners.size(); i++) { listeners[i]->OnCharacterUpdate( getName() ); } } // if (colObj_p) // { // initPhysicsObj(); // } // Name the controllers string ct_name( getName() ); ct_name += "'s world_offset writer"; world_offset_writer_p->setName( ct_name.c_str() ); return CMD_SUCCESS; }
void ResourceWindow::updateScriptFiles( Fl_Tree_Item* tree, std::string pname ) { SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); const std::vector<std::string>& scriptPaths = scene->getAssetManager()->getAssetPaths("script"); for (std::vector<std::string>::const_iterator pathIter = scriptPaths.begin(); pathIter != scriptPaths.end(); pathIter++) { boost::filesystem::path path(*pathIter); if (boost::filesystem::is_directory(path)) { boost::filesystem::directory_iterator end; for (boost::filesystem::directory_iterator iter(path); iter != end; iter++) { const boost::filesystem::path& cur = (*iter); std::string ext = boost::filesystem::extension( cur ); if (ext == ".seq" || ext == ".SEQ" || ext == ".py" || ext == ".PY") { std::string fileName = boost::filesystem::basename(cur); if (tree->find_child(fileName.c_str()) == -1) // if the script name does not exist in the tree list { Fl_Tree_Item* item = resourceTree->add(tree, fileName.c_str()); } } } } } }
SBAPI bool SBM_Shutdown( SBMHANDLE sbmHandle ) { if ( !SBM_HandleExists( sbmHandle ) ) { return false; } #ifndef SB_NO_VHMSG SmartBody::SBScene::getScene()->getVHMsgManager()->send("vrProcEnd sbm"); //SmartBody::SBScene::getScene()->getVHMsgManager()->setEnable(false); vhmsg::ttu_close(); #endif XMLPlatformUtils::Terminate(); std::map< int, Smartbody_c_Dll * >::iterator itdll = g_smartbodyDLLInstances.find( sbmHandle ); Smartbody_c_Dll * sbmdll = g_smartbodyDLLInstances[ sbmHandle ]; g_smartbodyDLLInstances.erase( itdll ); SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); scene->removeSceneListener(sbmdll->m_listener); vhcl::Log::g_log.RemoveListener(sbmdll->m_logListener); delete sbmdll; return true; }
void SbmPawn::initSteeringSpaceObject() { SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); if (!scene->getSteerManager()->getEngineDriver()->isInitialized()) return; if (!scene->getSteerManager()->getEngineDriver()->_engine) return; float steerScale = 1.0f / scene->getScale(); // get the size of the steering object float x, y, z, h, p, r; this->get_world_offset(x, y, z, h, p, r); gwiz::quat_t q = gwiz::euler_t(p,h,r); SrQuat pawnQ = SrQuat((float)q.w(), (float)q.x(), (float)q.y(), (float)q.z()); SrVec size = this->getVec3Attribute("collisionShapeScale"); size = size*pawnQ; steeringSpaceObjSize.x = fabs(size.x); steeringSpaceObjSize.y = fabs(size.y); steeringSpaceObjSize.z = fabs(size.z); float xmin = (x - steeringSpaceObjSize.x) / steerScale; float xmax = (x + steeringSpaceObjSize.x) / steerScale; float ymin = (y - steeringSpaceObjSize.y) / steerScale; float ymax = (y + steeringSpaceObjSize.y) / steerScale; float zmin = (z - steeringSpaceObjSize.z) / steerScale; float zmax = (z + steeringSpaceObjSize.z) / steerScale; //LOG("steeringSpaceObjSize = %f %f %f, scale = %f", steeringSpaceObjSize.x, steeringSpaceObjSize.y, steeringSpaceObjSize.z, steerScale); if (steeringSpaceObj_p) { const Util::AxisAlignedBox& box = steeringSpaceObj_p->getBounds(); if (fabs(box.xmax - xmax) > .0001 || fabs(box.xmin - xmin) > .0001 || fabs(box.ymax - ymax) > .0001 || fabs(box.ymin - ymin) > .0001 || fabs(box.zmax - zmax) > .0001 || fabs(box.zmin - zmin) > .0001) { SmartBody::SBScene::getScene()->getSteerManager()->getEngineDriver()->_engine->getSpatialDatabase()->removeObject(steeringSpaceObj_p, steeringSpaceObj_p->getBounds()); Util::AxisAlignedBox& mutableBox = const_cast<Util::AxisAlignedBox&>(box); mutableBox.xmax = xmax; mutableBox.xmin = xmin; mutableBox.ymax = ymax; mutableBox.ymin = ymin; mutableBox.zmax = zmax; mutableBox.zmin = zmin; SmartBody::SBScene::getScene()->getSteerManager()->getEngineDriver()->_engine->getSpatialDatabase()->addObject(steeringSpaceObj_p, steeringSpaceObj_p->getBounds()); } } else { steeringSpaceObj_p = new SteerLib::BoxObstacle(xmin, xmax, ymin, ymax, zmin, zmax); SmartBody::SBScene::getScene()->getSteerManager()->getEngineDriver()->_engine->addObstacle(steeringSpaceObj_p); SmartBody::SBScene::getScene()->getSteerManager()->getEngineDriver()->_engine->getSpatialDatabase()->addObject(steeringSpaceObj_p, steeringSpaceObj_p->getBounds()); } }
void PATransitionCreator::loadMotions() { SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); std::vector<std::string> motionNames = scene->getMotionNames(); std::map<std::string, SkMotion*>::iterator iter; for (std::vector<std::string>::iterator iter = motionNames.begin(); iter != motionNames.end(); iter++) animationList->add(iter->c_str()); }
SBAPI void SBM_SBDebuggerServer_SetRendererIsRightHanded( SBMHANDLE sbmHandle, bool enabled ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBDebuggerServer * debuggerServer = scene->getDebuggerServer(); debuggerServer->m_rendererIsRightHanded = enabled; }
SBAPI void SBM_SBMotion_AddChannel( SBMHANDLE sbmHandle, const char * motionName, const char * channelName, const char * channelType ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBMotion * motion = scene->getMotion(motionName); motion->addChannel(channelName, channelType); }
SBAPI void SBM_SBDiphoneManager_CreateDiphone(SBMHANDLE sbmHandle, const char * fromPhoneme, const char * toPhoneme, const char * name) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBPhonemeManager * diphoneManager = scene->getDiphoneManager(); diphoneManager->createDiphone(fromPhoneme, toPhoneme, name); }
SBAPI void SBM_SBVHMsgManager_SetPort( SBMHANDLE sbmHandle, const char * port ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBVHMsgManager * vhmsgManager = scene->getVHMsgManager(); vhmsgManager->setPort(port); }
SBAPI void SBM_SBDebuggerServer_SetID( SBMHANDLE sbmHandle, const char * id ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBDebuggerServer * debuggerServer = scene->getDebuggerServer(); debuggerServer->setStringAttribute("id", id); }
SBAPI void SBM_SBVHMsgManager_SetEnable( SBMHANDLE sbmHandle, bool enable ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBVHMsgManager * vhmsgManager = scene->getVHMsgManager(); vhmsgManager->setEnable(enable); }
SBAPI void SBM_SBMotion_SetSyncPoint( SBMHANDLE sbmHandle, const char * motionName, const char * syncTag, double time ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBMotion * motion = scene->getMotion(motionName); motion->setSyncPoint(syncTag, time); }
SBAPI bool SBM_GetCharacter( SBMHANDLE sbmHandle, const char * name, SBM_CharacterFrameDataMarshalFriendly * character ) { if ( !SBM_HandleExists( sbmHandle ) ) { LOG("SBM_GetCharcter : Handle %d does not exist", sbmHandle); return false; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBCharacter * sbcharacter = scene->getCharacter(name); const SBM_CharacterFrameDataMarshalFriendly & data = sbcharacter->GetFrameDataMarshalFriendly(); if (character->m_numJoints == 0 || character->m_numJoints != data.m_numJoints) { SBM_ReleaseCharacterJoints(character); character->m_numJoints = data.m_numJoints; character->jname = new char * [ character->m_numJoints ]; character->jx = new float [ character->m_numJoints ]; character->jy = new float [ character->m_numJoints ]; character->jz = new float [ character->m_numJoints ]; character->jrw = new float [ character->m_numJoints ]; character->jrx = new float [ character->m_numJoints ]; character->jry = new float [ character->m_numJoints ]; character->jrz = new float [ character->m_numJoints ]; for ( int i = 0; i < character->m_numJoints; i++ ) { character->jname[ i ] = new char[ strlen(data.jname[ i ]) + 1 ]; strcpy( character->jname[ i ], data.jname[ i ] ); } } character->x = data.x; character->y = data.y; character->z = data.z; character->rw = data.rw; character->rx = data.rx; character->ry = data.ry; character->rz = data.rz; memcpy(character->jx, data.jx, data.m_numJoints * sizeof(float)); memcpy(character->jy, data.jy, data.m_numJoints * sizeof(float)); memcpy(character->jz, data.jz, data.m_numJoints * sizeof(float)); memcpy(character->jrw, data.jrw, data.m_numJoints * sizeof(float)); memcpy(character->jrx, data.jrx, data.m_numJoints * sizeof(float)); memcpy(character->jry, data.jry, data.m_numJoints * sizeof(float)); memcpy(character->jrz, data.jrz, data.m_numJoints * sizeof(float)); return true; }
void SBDebuggerUtility::initCharacterFaceDefinition(const std::string& characterName, const std::string& faceDefName, const std::string& message) { SmartBody::SBScene* sbScene = SmartBody::SBScene::getScene(); SmartBody::SBCharacter* sbCharacter = sbScene->getCharacter(characterName); if (!sbCharacter) return; SmartBody::SBFaceDefinition* faceDef = sbScene->getFaceDefinition(faceDefName); if (!faceDef) return; sbCharacter->setFaceDefinition(faceDef); }
SBAPI bool SBM_SBAssetManager_LoadMotion( SBMHANDLE sbmHandle, const void * data, int sizeBytes, const char * motionName ) { if ( !SBM_HandleExists( sbmHandle ) ) { return false; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBAssetManager * assetManager = scene->getAssetManager(); int ret = assetManager->load_motion( data, sizeBytes, motionName ); return ret == CMD_SUCCESS; }
SBAPI void SBM_SBDiphone_AddKey(SBMHANDLE sbmHandle, const char * fromPhoneme, const char * toPhoneme, const char * name, const char * viseme, float time, float weight) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBPhonemeManager * diphoneManager = scene->getDiphoneManager(); SmartBody::SBDiphone * diphone = diphoneManager->getDiphone(fromPhoneme, toPhoneme, name); diphone->addKey(viseme, time, weight); }
SBAPI bool SBM_ProcessVHMsgs( SBMHANDLE sbmHandle, const char * op, const char * args ) { if ( !SBM_HandleExists( sbmHandle ) ) { return false; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); string s = string(op) + string(" ") + string(args); scene->command( s.c_str() ); scene->getDebuggerServer()->ProcessVHMsgs(op, args); return true; }
SBAPI void SBM_SBJointMap_GetMapTarget( SBMHANDLE sbmHandle, const char * jointMapName, const char * jointName, char * mappedJointName, int maxMappedJointName ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBJointMapManager * jointMapManager = scene->getJointMapManager(); SmartBody::SBJointMap * jointMap = jointMapManager->getJointMap(jointMapName); const std::string & mapTarget = jointMap->getMapTarget(jointName); strncpy(mappedJointName, mapTarget.c_str(), maxMappedJointName); }
SBAPI void SBM_SBMotion_AddFrame( SBMHANDLE sbmHandle, const char * motionName, float frameTime, const float * frameData, int numFrameData ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBMotion * motion = scene->getMotion(motionName); // create vector from float array std::vector<float> frameDataVec(frameData, frameData + numFrameData); motion->addFrame(frameTime, frameDataVec); }
SBAPI bool SBM_UpdateUsingDelta( SBMHANDLE sbmHandle, double deltaTimeInSeconds ) { if ( !SBM_HandleExists( sbmHandle ) ) { return false; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); scene->getSimulationManager()->stepDt(deltaTimeInSeconds); scene->update(); SBM_SanityCheckCallbackQueues(sbmHandle); return true; }
int SbmPawn::setup() { // Verifiy the joint name is not already in use. if( _skeleton->search_joint( SbmPawn::WORLD_OFFSET_JOINT_NAME ) ) { std::stringstream strstr; strstr << "ERROR: SbmPawn::init_skeleton_offset: Skeleton already contains joint \"" << SbmPawn::WORLD_OFFSET_JOINT_NAME << "\"."; LOG(strstr.str().c_str()); return( CMD_FAILURE ); } SkJoint* world_offset_joint = _skeleton->insert_new_root_joint( SkJoint::TypeQuat ); world_offset_joint->name( SbmPawn::WORLD_OFFSET_JOINT_NAME ); world_offset_joint->extName( SbmPawn::WORLD_OFFSET_JOINT_NAME ); // Make sure the world_offset accepts new pos and quat values SkJointPos* world_offset_pos = world_offset_joint->pos(); world_offset_pos->limits( SkVecLimits::X, false ); world_offset_pos->limits( SkVecLimits::Y, false ); world_offset_pos->limits( SkVecLimits::Z, false ); world_offset_joint->quat()->activate(); _skeleton->compress(); _skeleton->make_active_channels(); if( WORLD_OFFSET_CHANNELS_P.size()==0 ) { std::string world_offset_joint_name( WORLD_OFFSET_JOINT_NAME ); WORLD_OFFSET_CHANNELS_P.add( world_offset_joint_name, SkChannel::XPos ); WORLD_OFFSET_CHANNELS_P.add( world_offset_joint_name, SkChannel::YPos ); WORLD_OFFSET_CHANNELS_P.add( world_offset_joint_name, SkChannel::ZPos ); WORLD_OFFSET_CHANNELS_P.add( world_offset_joint_name, SkChannel::Quat ); } world_offset_writer_p->init( this, WORLD_OFFSET_CHANNELS_P, true ); wo_cache.x = 0; wo_cache.y = 0; wo_cache.z = 0; wo_cache.h = 0; wo_cache.p = 0; wo_cache.r = 0; SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); std::vector<SmartBody::SBSceneListener*>& listeners = scene->getSceneListeners(); for (size_t i = 0; i < listeners.size(); i++) { listeners[i]->OnCharacterUpdate( getName() ); } return( CMD_SUCCESS ); }
SBAPI void SBM_SBMotion_AddChannels( SBMHANDLE sbmHandle, const char * motionName, const char ** channelNames, const char ** channelTypes, int count ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBMotion * motion = scene->getMotion(motionName); for (int i = 0; i < count; i++) { //LOG("%s - %s - %s", motionName, channelNames[i], channelTypes[i]); motion->addChannel(channelNames[i], channelTypes[i]); } }
void SBM_InitLocalSpeechRelay() { //AUDIO_Init(); #if defined(__ANDROID__) std::string festivalLibDir = "/sdcard/SBUnity/festival/lib/"; std::string festivalCacheDir = "/sdcard/SBUnity/festival/cache/"; std::string cereprocLibDir = "/sdcard/SBUnity/cerevoice/voices/"; #else std::string festivalLibDir = "./SBUnity/festival/lib/"; std::string festivalCacheDir = "./SBUnity/festival/cache/"; std::string cereprocLibDir = "./SBUnity/cerevoice/voices/"; #endif SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); scene->getSpeechManager()->festivalRelay()->initSpeechRelay(festivalLibDir, festivalCacheDir); scene->getSpeechManager()->cereprocRelay()->initSpeechRelay(cereprocLibDir, festivalCacheDir); }
SBAPI void SBM_SBDebuggerServer_SetCameraValues( SBMHANDLE sbmHandle, double x, double y, double z, double rx, double ry, double rz, double rw, double fov, double aspect, double zNear, double zFar ) { if ( !SBM_HandleExists( sbmHandle ) ) { return; } SmartBody::SBScene * scene = SmartBody::SBScene::getScene(); SmartBody::SBDebuggerServer * debuggerServer = scene->getDebuggerServer(); debuggerServer->m_cameraPos.x = x; debuggerServer->m_cameraPos.y = y; debuggerServer->m_cameraPos.z = z; debuggerServer->m_cameraRot.x = rx; debuggerServer->m_cameraRot.y = ry; debuggerServer->m_cameraRot.z = rz; debuggerServer->m_cameraRot.w = rw; debuggerServer->m_cameraFovY = fov; debuggerServer->m_cameraAspect = aspect; debuggerServer->m_cameraZNear = zNear; debuggerServer->m_cameraZFar = zFar; }
bool QueryResourcesCB(void* caller, NetRequest* req) { SmartBody::SBScene* sbScene = SmartBody::SBScene::getScene(); std::vector<std::string> args = req->Args(); switch (req->Rid()) { case NetRequest::Get_Seq_Asset_Paths: for (size_t i = 0; i < args.size(); i++) sbScene->addAssetPath("script", args[i]); break; case NetRequest::Get_ME_Asset_Paths: for (size_t i = 0; i < args.size(); i++) sbScene->addAssetPath("motion", args[i]); break; case NetRequest::Get_Audio_Asset_Paths: for (size_t i = 0; i < args.size(); i++) sbScene->addAssetPath("audio", args[i]); break; case NetRequest::Get_Mesh_Asset_Paths: for (size_t i = 0; i < args.size(); i++) sbScene->addAssetPath("mesh", args[i]); break; case NetRequest::Get_Script_Names: break; case NetRequest::Get_Service_Names: break; case NetRequest::Get_Motion_Names: for (size_t i = 0; i < args.size(); i++) { SmartBody::SBMotion* motion = SmartBody::SBScene::getScene()->getAssetManager()->createMotion(args[i]); } break; case NetRequest::Get_Skeleton_Names: break; case NetRequest::Get_BoneMap_Names: break; case NetRequest::Get_EventHandler_Names: break; case NetRequest::Get_Scene_Scale: float scale = (float)vhcl::ToDouble(req->ArgsAsString()); sbScene->setScale(scale); break; } return true; }
int main_sb( int argc, char** argv ) { osg::ArgumentParser arguments( &argc, argv ); SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); scene->setMediaPath( "./smartbody/" ); // data/ scene->addAssetPath( "motion", "ChrBrad" ); scene->addAssetPath( "mesh", "mesh"); scene->addAssetPath( "script", "scripts"); scene->loadAssets(); int numMotions = scene->getNumMotions(); std::cout << "Loaded motions: " << numMotions << std::endl; SmartBody::SBCharacter* character = scene->createCharacter( "mycharacter", "" ); SmartBody::SBSkeleton* skeleton = scene->createSkeleton( "ChrBrad.sk" ); character->setSkeleton( skeleton ); character->createStandardControllers(); SmartBody::SBSimulationManager* sim = scene->getSimulationManager(); sim->setupTimer(); osg::ref_ptr<osg::Group> root = new osg::Group; osgViewer::Viewer viewer; viewer.setCameraManipulator( new osgGA::TrackballManipulator ); viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler( new osgViewer::StatsHandler ); viewer.addEventHandler( new osgViewer::WindowSizeHandler ); viewer.setSceneData( root.get() ); viewer.setUpViewOnSingleScreen( 1 ); std::string ret = scene->getBmlProcessor()->execBML( "mycharacter", "<body posture=\"ChrBrad@Idle01\"/>" ); sim->start(); while ( !viewer.done() ) { scene->update(); int numCharacters = scene->getNumCharacters(); if (numCharacters == 0) return true; sim->updateTimer(); viewer.frame(); } sim->stop(); return 0; }
void ResourceWindow::updateGUI() { SmartBody::SBScene* scene = SmartBody::SBScene::getScene(); SmartBody::SBAssetManager* assetManager = scene->getAssetManager(); resourceTree->sortorder(FL_TREE_SORT_ASCENDING); // update path tree updatePath(getTreeFromName("script path"), SmartBody::SBScene::getScene()->getAssetPaths("script")); updatePath(getTreeFromName("motion path"), SmartBody::SBScene::getScene()->getAssetPaths("motion")); updatePath(getTreeFromName("audio path"), SmartBody::SBScene::getScene()->getAssetPaths("audio")); updatePath(getTreeFromName("mesh path"), SmartBody::SBScene::getScene()->getAssetPaths("mesh")); // update sequence file list const std::vector<std::string> scriptPaths = SmartBody::SBScene::getScene()->getAssetPaths("script"); resourceTree->clear_children(getTreeFromName("scriptfiles")); for (size_t p = 0; p < scriptPaths.size(); p++) { updateScriptFiles(getTreeFromName("scriptfiles"), scriptPaths[p]); } // update runtime scripts resourceTree->clear_children(getTreeFromName("script")); std::vector<std::string> scriptName = scene->getScriptNames(); for (size_t i = 0; i < scriptName.size(); i++) { SmartBody::SBScript* script = scene->getScript(scriptName[i]); updateScript(getTreeFromName("script"), script); } // update skeleton resourceTree->clear_children(getTreeFromName("skeleton")); std::vector<std::string> skeletons = scene->getSkeletonNames(); for (size_t c = 0; c < skeletons.size(); c++) { SmartBody::SBSkeleton * skel = scene->getSkeleton(skeletons[c]); updateSkeleton(getTreeFromName("skeleton"), skel); } // update joint maps resourceTree->clear_children(getTreeFromName("jointmap")); SmartBody::SBJointMapManager* jointMapManager = scene->getJointMapManager(); std::vector<std::string> jointMapNames = jointMapManager->getJointMapNames(); for (std::vector<std::string>::iterator iter = jointMapNames.begin(); iter != jointMapNames.end(); iter++) { Fl_Tree_Item* boneMapItem = resourceTree->add(getTreeFromName("jointmap"), (*iter).c_str()); updateJointMap(boneMapItem, jointMapManager->getJointMap((*iter))); } // update gesture maps resourceTree->clear_children(getTreeFromName("gesturemap")); SmartBody::SBGestureMapManager* gestureMapManager = scene->getGestureMapManager(); std::vector<std::string> gestureMapNames = gestureMapManager->getGestureMapNames(); for (std::vector<std::string>::iterator iter = gestureMapNames.begin(); iter != gestureMapNames.end(); iter++) { Fl_Tree_Item* gestureMapItem = resourceTree->add(getTreeFromName("gesturemap"), (*iter).c_str()); updateGestureMap(gestureMapItem, gestureMapManager->getGestureMap((*iter))); } // update motion map resourceTree->clear_children(getTreeFromName("motion")); std::vector<std::string> motionNames = scene->getMotionNames(); for (size_t i = 0; i < motionNames.size(); i++) { //resourceTree->add(treeItemList[ITEM_MOTION],mi->first.c_str()); SmartBody::SBMotion * motion = scene->getMotion(motionNames[i]); updateMotion(getTreeFromName("motion"), motion); } SmartBody::SBAnimationBlendManager* blendManager = scene->getBlendManager(); // update animation blend map resourceTree->clear_children(getTreeFromName("blend")); std::vector<std::string> blendNames = blendManager->getBlendNames(); for (size_t i = 0; i < blendNames.size(); i++) { //resourceTree->add(treeItemList[ITEM_MOTION],mi->first.c_str()); SmartBody::SBAnimationBlend * blend = blendManager->getBlend(blendNames[i]); updateAnimationBlend(getTreeFromName("blend"), blend); } // update blend transition map resourceTree->clear_children(getTreeFromName("transition")); std::vector<std::string> transitionNames = blendManager->getTransitionNames(); for (size_t i = 0; i < transitionNames.size(); i++) { //resourceTree->add(treeItemList[ITEM_MOTION],mi->first.c_str()); SmartBody::SBAnimationTransition * transition = blendManager->getTransitionByName(transitionNames[i]); updateBlendTransition(getTreeFromName("transition"), transition); } // update mesh map resourceTree->clear_children(getTreeFromName("mesh")); std::vector<std::string> meshNames = assetManager->getDeformableMeshNames(); for (size_t i = 0; i < meshNames.size(); i++) { DeformableMesh* mesh = assetManager->getDeformableMesh(meshNames[i]); Fl_Tree_Item* meshItem = resourceTree->add(getTreeFromName("mesh"), mesh->getName().c_str()); updateMesh(meshItem, mesh); } // update face definition map resourceTree->clear_children(getTreeFromName("facedefinition")); std::vector<std::string> faceNames = scene->getFaceDefinitionNames(); for (size_t i = 0; i < faceNames.size(); i++) { //resourceTree->add(treeItemList[ITEM_MOTION],mi->first.c_str()); SmartBody::SBFaceDefinition * face = scene->getFaceDefinition(faceNames[i]); if (!face) continue; Fl_Tree_Item* faceTree = resourceTree->add(getTreeFromName("facedefinition"), face->getName().c_str()); updateFaceDefinition(faceTree, face); } // update event handler list SmartBody::SBEventManager* eventManager = SmartBody::SBScene::getScene()->getEventManager(); std::map<std::string, SmartBody::SBEventHandler*>& eventMap = eventManager->getEventHandlers(); std::map<std::string, SmartBody::SBEventHandler*>::iterator ei; resourceTree->clear_children(getTreeFromName("eventhandler")); for ( ei = eventMap.begin(); ei != eventMap.end(); ei++) { updateEventHandler(getTreeFromName("eventhandler"), ei->second); } // Below are instance objects : // update pawn objects resourceTree->clear_children(getTreeFromName("pawn")); const std::vector<std::string>& pawnNames = scene->getPawnNames(); for (size_t i = 0; i < pawnNames.size(); i++) { SmartBody::SBPawn* pawn = scene->getPawn(pawnNames[i]); updatePawn(getTreeFromName("pawn"), pawn); } // update characters resourceTree->clear_children(getTreeFromName("character")); const std::vector<std::string>& charNames = scene->getCharacterNames(); for (size_t i = 0; i < charNames.size(); i++) { SmartBody::SBCharacter* character = scene->getCharacter(charNames[i]); resourceTree->sortorder(FL_TREE_SORT_ASCENDING); updateCharacter(getTreeFromName("character"), character); } // for (SBPhysicsObjMap::iterator iter = phySim->getPhysicsObjMap().begin(); // iter != phySim->getPhysicsObjMap().end(); // iter++) // { // SBPhysicsObj* obj = (*iter).second; // if (dynamic_cast<SbmJointObj*>(obj) == NULL) // { // // } // } // update services SmartBody::SBServiceManager* serviceManager = scene->getServiceManager(); std::map<std::string, SmartBody::SBService*>& serviceMap = serviceManager->getServices(); resourceTree->clear_children(getTreeFromName("service")); for (std::map<std::string, SmartBody::SBService*>::iterator iter = serviceMap.begin(); iter != serviceMap.end(); iter++) { SmartBody::SBService* service = (*iter).second; resourceTree->sortorder(FL_TREE_SORT_ASCENDING); SmartBody::SBPhysicsManager* phyManager = dynamic_cast<SmartBody::SBPhysicsManager*>(service); if (phyManager) updatePhysicsManager(getTreeFromName("service"),phyManager); else updateService(getTreeFromName("service"), service); } // update behavior sets resourceTree->clear_children(getTreeFromName("behaviorset")); std::map<std::string, SmartBody::SBBehaviorSet*>& behaviorSets = scene->getBehaviorSetManager()->getBehaviorSets(); for (std::map<std::string, SmartBody::SBBehaviorSet*>::iterator iter = behaviorSets.begin(); iter != behaviorSets.end(); iter++) { SmartBody::SBBehaviorSet* behaviorSet = (*iter).second; updateBehaviorSet(getTreeFromName("behaviorset"), behaviorSet); } _dirty = false; if (_firstTime) { hideTree(); _firstTime = false; } }