void SexpMonitor::AddAgents(boost::shared_ptr<Scene> activeScene, std::ostringstream& ss) const { TLeafList nodes; activeScene->ListChildrenSupportingClass<AgentAspect>(nodes, true); for (TLeafList::iterator i = nodes.begin(); i != nodes.end(); ++i) { boost::shared_ptr<AgentAspect> aspect = shared_static_cast<AgentAspect>(*i); const salt::Vector3f& pos = aspect->GetWorldTransform().Pos(); ss << "(P "; boost::shared_ptr<AgentState> state = shared_static_cast<AgentState> (aspect->GetChildOfClass("AgentState")); boost::shared_ptr<SayEffector> sayEff = shared_static_cast<SayEffector> (aspect->GetChildOfClass("SayEffector")); if (state.get() != 0) { ss << "(s " << state->GetTeamIndex() << ")"; ss << "(id " << state->GetUniformNumber() << ")"; } // pos ss << "(pos " << pos << ")"; if (mSendRotMatrix) { // world transform ss << "(rot "; const salt::Matrix& trans = aspect->GetWorldTransform(); for (int i=0;i<16;++i) { ss << trans.m[i] << " "; } ss << ")"; } // extra field if the agent was the last colliding with the ball boost::shared_ptr<AgentAspect> agent; TTime time; mBallState->GetLastCollidingAgent(agent,time); if (agent == aspect) { ss << "(last)"; } if (sayEff !=0 && sayEff->IfText()) { //ss <<"(say " <<sayEff->GetText()<<")"; } ss << ")"; } }
void RenderServer::PreviousCamera() { TLeafList cameras; mActiveScene->GetChildrenOfClass("Camera", cameras, true); for (TLeafList::iterator iter = cameras.begin(); iter != cameras.end(); ++iter) if (*iter == mCamera) { mCamera = iter != cameras.begin() ? static_pointer_cast<Camera>(*(--iter)) : static_pointer_cast<Camera>(cameras.back()); break; } }
void MaterialServer::ExportMaterial(boost::shared_ptr<Material> material) { TLeafList exporters; ListChildrenSupportingClass<MaterialExporter>(exporters); for (TLeafList::const_iterator bi = exporters.begin(); bi != exporters.end(); ++bi) { boost::shared_ptr<MaterialExporter> mb = static_pointer_cast<MaterialExporter>(*bi); mb->RegisterMaterial(material); } }
void RenderServer::NextCamera() { TLeafList cameras; mActiveScene->GetChildrenOfClass("Camera", cameras, true); for (TLeafList::iterator iter = cameras.begin(); iter != cameras.end(); ++iter) if (*iter == mCamera) { ++iter; mCamera = iter != cameras.end() ? shared_static_cast<Camera>(*iter) : shared_static_cast<Camera>(cameras.front()); break; } }
void Leaf::GetChildren(const std::string &name, TLeafList &baseList, bool /*recursive*/) { if (name.compare("..") == 0) { baseList.push_back(GetParent().lock()); } if (name.compare(".") == 0) { baseList.push_back(static_pointer_cast<Leaf>(GetSelf().lock())); } }
void MaterialServer::ExportAllMaterial() { GetLog()->Debug() << "(MaterialServer) ExportAllMaterial\n"; TLeafList materials; ListChildrenSupportingClass<Material>(materials); for (TLeafList::const_iterator mi = materials.begin(); mi != materials.end(); ++mi) { boost::shared_ptr<Material> m = static_pointer_cast<Material>(*mi); ExportMaterial(m); } GetLog()->Debug() << "(MaterialServer) ExportAllMaterial done\n"; }
void SparkMonitor::DescribeScene(stringstream& ss, boost::shared_ptr<BaseNode> node) { bool closeParen = DescribeNode(ss, node); TLeafList baseNodes = node->GetBaseNodeChildren(); for (TLeafList::iterator i = baseNodes.begin(); i!= baseNodes.end(); ++i) { boost::shared_ptr<BaseNode> baseNode = dynamic_pointer_cast<BaseNode>(*i); DescribeScene(ss,baseNode); } if (closeParen) { ss << ")"; } }
void RenderControl::RenderCustom() { // get list of registered CustomMonitor objects TLeafList customList; ListChildrenSupportingClass<CustomRender>(customList); for ( TLeafList::iterator iter = customList.begin(); iter != customList.end(); ++iter ) { shared_static_cast<CustomRender>((*iter))->Render(); } }
void SparkMonitor::ParseMonitorMessage(const std::string& data) { // pass the received string on to all installed CommandParsers TLeafList items; ListChildrenSupportingClass<MonitorCmdParser>(items); for ( TLeafList::iterator iter = items.begin(); iter != items.end(); ++iter ) { static_pointer_cast<MonitorCmdParser>(*iter) ->ParseMonitorMessage(data); } }
void RestrictedVisionPerceptor::SetupLines(TLineList& visibleLines) { TLeafList lineList; mActiveScene->GetChildrenOfClass("Line", lineList, true); // determine position relative to the local reference frame const Matrix& mat = mTransformParent->GetWorldTransform(); // get the transformation matrix describing the current orientation Vector3f myPos = mat.Pos(); if (mAddNoise) { myPos -= mError; } for (TLeafList::iterator i = lineList.begin(); i != lineList.end(); ++i) { LineData ld; ld.mLine = static_pointer_cast<Line > (*i); if (ld.mLine.get() == 0) { GetLog()->Error() << "Error: (RestrictedVisionPerceptor) skipped line: " << (*i)->GetName() << "\n"; continue; // this should never happen } boost::shared_ptr<Transform> j = ld.mLine->GetTransformParent(); if (j.get() == 0) { GetLog()->Error() << "Error: (RestrictedVisionPerceptor) skipped line (2): " << (*i)->GetName() << "\n"; continue; // this should never happen } const salt::Matrix& t = j->GetWorldTransform(); ld.mBeginPoint.mRelPos = mat.InverseRotate( t * ld.mLine->BeginPoint() - myPos ); ld.mEndPoint.mRelPos = mat.InverseRotate( t * ld.mLine->EndPoint() - myPos ); visibleLines.push_back(ld); } }
void SparkMonitorLogFileServer::ParseCustomPredicates(sexp_t* sexp) { // ( (name param1 param2 ...) (name param1 param2 ...) ... ) if (sexp == 0) { return; } // get list of registered CustomMonitor objects TLeafList customList; ListChildrenSupportingClass<CustomMonitor>(customList); customList.push_back(GetCore()->Get("/sys/server/simulation/SparkMonitorClient/SoccerMonitor")); if (customList.empty()) { return; } // parse predicates PredicateList pList; sexp = sexp->list; while (sexp != 0) { if (sexp->ty == SEXP_LIST) { sexp_t* sPred = sexp->list; ParseCustomPredicates(sPred,pList); } sexp = sexp->next; } // pass predicates to all registered CustomMonitor objects for ( TLeafList::iterator iter = customList.begin(); iter != customList.end(); ++iter ) { static_pointer_cast<CustomMonitor>((*iter)) ->ParseCustomPredicates(pList); } }
void SparkMonitorClient::ParseCustomPredicates(sexp_t* sexp) { // ( (name param1 param2 ...) (name param1 param2 ...) ... ) if (sexp == 0) { return; } // get list of registered CustomMonitor objects TLeafList customList; ListChildrenSupportingClass<CustomMonitor>(customList); if (customList.empty()) { return; } // parse predicates PredicateList pList; sexp = sexp->list; while (sexp != 0) { if (sexp->ty == SEXP_LIST) { sexp_t* sPred = sexp->list; ParseCustomPredicates(sPred,pList); } sexp = sexp->next; } // pass predicates to all registered CustomMonitor objects for ( TLeafList::iterator iter = customList.begin(); iter != customList.end(); ++iter ) { shared_static_cast<CustomMonitor>((*iter)) ->ParseCustomPredicates(pList); } }
void Space::DestroySpaceObjects() { boost::shared_ptr<Scene> scene = GetScene(); if (scene.get() == 0) { return; } TLeafList objects; const bool recursive = true; scene->ListChildrenSupportingClass<PhysicsObject>(objects, recursive); bool globalSpace = IsGlobalSpace(); shared_ptr<Space> self = shared_static_cast<Space>(GetSelf().lock()); for ( TLeafList::iterator iter = objects.begin(); iter != objects.end(); ++iter ) { shared_ptr<PhysicsObject> object = shared_static_cast<PhysicsObject>(*iter); if (object == self) { continue; } // destroy objects registered to this space; the top level // space object also destroy any other ODE object const long parentSpace = object->GetParentSpaceID(); if ( ( (globalSpace) && (parentSpace == 0) ) || (parentSpace == mSpaceID) ) { object->DestroyPhysicsObject(); } } }
void AgentAspect::UpdateEffectorMap() { // build list of effectors, searching recursively TLeafList effectors; ListChildrenSupportingClass<Effector>(effectors,true); // build the effector map mEffectorMap.clear(); for ( TLeafList::iterator iter = effectors.begin(); iter != effectors.end(); ++iter ) { boost::shared_ptr<Effector> effector = static_pointer_cast<Effector>(*iter); mEffectorMap[effector->GetPredicate()] = effector; } }
void GeometryServer::RegisterMesh(boost::shared_ptr<TriMesh> mesh) { if (mesh.get() == 0) { GetLog()->Debug() << "(GeometryServer) RegisterMesh called with NULL mesh\n"; return; } std::string name = mesh->GetName(); if (name.empty()) { GetLog()->Error() << "(GeometryServer) Cannot register a mesh without a name\n"; return; } TMeshMap::const_iterator iter = mMeshMap.find(name); if (iter != mMeshMap.end()) { GetLog()->Debug() << "(GeometryServer) replacing mesh " << name << "\n"; } mMeshMap[name] = mesh; GetLog()->Debug() << "(GeometryServer) mesh " << name << " registered\n"; TLeafList exporters; ListChildrenSupportingClass<MeshExporter>(exporters); for (TLeafList::const_iterator bi = exporters.begin(); bi != exporters.end(); ++bi) { GetLog()->Debug() << "(GeometryServer) additionally registered mesh " << name << " via MeshExporter '" << (*bi)->GetName() << "'\n"; boost::shared_ptr<MeshExporter> mb = static_pointer_cast<MeshExporter>(*bi); mb->RegisterMesh(mesh); } }
shared_ptr<PredicateList> AgentAspect::QueryPerceptors() { mPerceptorCycle++; // build list of perceptors, searching recursively TLeafList perceptors; ListChildrenSupportingClass<Perceptor>(perceptors,true); shared_ptr<PredicateList> predList(new PredicateList()); // query the perceptors for new data for ( TLeafList::iterator iter = perceptors.begin(); iter != perceptors.end(); ++iter ) { shared_ptr<Perceptor> pct = shared_static_cast<Perceptor>(*iter); if ( mPerceptorCycle % pct->GetInterval() == 0 ) pct->Percept(predList); } return predList; }
void Node::GetChildren(const std::string& name, TLeafList& baseList, bool recursive) { Leaf::GetChildren(name, baseList, recursive); for (TLeafList::iterator i = mChildren.begin(); i != mChildren.end(); ++i) { // check if we have found a match and add it if ((*i)->GetName().compare(name) == 0) { baseList.push_back(*i); } if (recursive) (*i)->GetChildren(name, baseList, recursive); } }
void Node::GetChildrenOfClass(const std::string& name, TLeafList& baseList, bool recursive) { Leaf::GetChildrenOfClass(name, baseList, recursive); for (TLeafList::iterator i = mChildren.begin(); i != mChildren.end(); ++i) { // check if we have found a match and add it boost::shared_ptr<Class> theClass = (*i)->GetClass(); if (theClass.get() != NULL && theClass->GetName().compare(name) == 0) { baseList.push_back(*i); } if (recursive) (*i)->GetChildrenOfClass(name, baseList, recursive); } }
boost::shared_ptr<TriMesh> GeometryServer::GetMesh(const string& name, const::ParameterList& parameter) { // try a direct match string meshName = name; TMeshMap::const_iterator meshIter = mMeshMap.find(meshName); if (meshIter != mMeshMap.end()) { return (*meshIter).second; } TLeafList importer; ListChildrenSupportingClass<MeshImporter>(importer); if (importer.size() == 0) { GetLog()->Error() << "(GeometryServer) Warning: no MeshImporter registered\n"; return boost::shared_ptr<TriMesh>(); } // try to mangle the name for ( TLeafList::iterator iter = importer.begin(); iter != importer.end(); ++iter ) { boost::shared_ptr<MeshImporter> importer = static_pointer_cast<MeshImporter>(*iter); string str = importer->MangleName(name, parameter); if (str != meshName) { meshName = str; meshIter = mMeshMap.find(meshName); if (meshIter != mMeshMap.end()) { return (*meshIter).second; } } } // try to import the mesh for ( TLeafList::iterator iter = importer.begin(); iter != importer.end(); ++iter ) { boost::shared_ptr<MeshImporter> importer = static_pointer_cast<MeshImporter>(*iter); boost::shared_ptr<TriMesh> mesh = importer->ImportMesh(name,parameter); if (mesh.get() == 0) { continue; } string meshName = mesh->GetName(); if (meshName.empty()) { meshName = name; mesh->SetName(name); } GetLog()->Debug() << "(GeometryServer) imported mesh '" << meshName << " with '" << importer->GetName() << "'\n"; if (mesh.get() == 0 || mesh->GetVertexCount() == 0) { continue; } RegisterMesh(mesh); return mesh; } GetLog()->Error() << "(GeometryServer) ERROR: cannot import mesh '" << name << "'\n"; return boost::shared_ptr<TriMesh>(); }
bool SceneServer::ImportScene(const string& fileName, boost::shared_ptr<BaseNode> root, boost::shared_ptr<ParameterList> parameter) { string file; if (! GetFile()->LocateResource(fileName, file)) { GetLog()->Error() << "(SceneServer) ERROR: cannot locate file '" << fileName << "'\n"; return false; } if (root.get() == 0) { GetLog()->Error() << "(SceneServer) ERROR: NULL node given as ImportScene " << "root node, fileName was " << fileName << "\n"; } GetLog()->Debug() << "(SceneServer) ImportScene fileName=" << fileName << " root=" << root->GetFullPath() << "\n"; TLeafList importer; ListChildrenSupportingClass<SceneImporter>(importer); if (importer.empty()) { GetLog()->Error() << "(SceneServer) Warning: no SceneImporter registered\n"; } // because the importer will create ODE objects, // so we have to lock the ODE boost::recursive_mutex::scoped_lock lock(mMutex); for ( TLeafList::iterator iter = importer.begin(); iter != importer.end(); ++iter ) { boost::shared_ptr<SceneImporter> importer = shared_static_cast<SceneImporter>(*iter); importer->SetSceneDict(&SceneDict::GetInstance()); GetLog()->Debug() << "(SceneServer) trying importer " << importer->GetName() << std::endl; if (importer->ImportScene(file,root,parameter)) { GetLog()->Debug() << "(SceneServer) imported scene file '" << file << " with '" << importer->GetName() << " at " << root->GetFullPath() << endl; RemoveTransformPaths(root); // mark the corresponding scene as modified boost::shared_ptr<Scene> scene = root->GetScene(); if (scene.get() != 0) { scene->SetModified(true); } return true; } } GetLog()->Error() << "(SceneServer) ERROR: cannot import scene file '" << file << "'\n"; return false; }
void RenderServer::Render(bool clean) { int err = glGetError(); if (err) GetLog()->Error() << "OpenGLError before picking preparation: " << err << std::endl; PreparePicking(); err = glGetError(); if (err) GetLog()->Error() << "OpenGLError after picking preparation: " << err << std::endl; if (! GetActiveScene()) { return; } // if no camera is selected yet, select the first one if (mCamera.get() == 0) mCamera = static_pointer_cast<Camera>(mActiveScene->GetChildOfClass("Camera", true)); if (mCamera.get() == 0) { GetLog()->Error() << "(RenderServer) ERROR: found no camera node in the active scene\n"; return; } err = glGetError(); if (err) GetLog()->Error() << "OpenGLError before binding camera: " << err << std::endl; // set the view transformation BindCamera(mCamera); err = glGetError(); if (err) GetLog()->Error() << "OpenGLError after binding camera: " << err << std::endl; glClearColor( mAmbientColor.r(), mAmbientColor.g(), mAmbientColor.b(), mAmbientColor.a() ); if (clean) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } else { glClear(GL_DEPTH_BUFFER_BIT); } glColor3f(1, 1, 1); // actual rendering // ambient pass glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glAlphaFunc(GL_GREATER, 0.1); glEnable(GL_ALPHA_TEST); TLeafList lights; mActiveScene->ListChildrenSupportingClass<Light>(lights,true); if (lights.size() == 0) { // no lights in the scene, disable lighting glDisable(GL_LIGHTING); } else { glEnable(GL_LIGHTING); glShadeModel (GL_SMOOTH); // prepare all lights for ( TLeafList::iterator iter = lights.begin(); iter != lights.end(); ++iter ) { (static_pointer_cast<Light>(*iter))->Prepare(); } } err = glGetError(); if (err) GetLog()->Error() << "OpenGLError before render pass 0: " << err << std::endl; // standard rendering RenderScene(mActiveScene, 0); err = glGetError(); if (err) GetLog()->Error() << "OpenGLError after render pass 0: " << err << std::endl; RenderScene(mActiveScene, 1); err = glGetError(); if (err) GetLog()->Error() << "OpenGLError after render pass 1: " << err << std::endl; // reset GL lights glDisable(GL_LIGHTING); if (mEnablePicking) { ProcessPicks(); } err = glGetError(); if (err) GetLog()->Error() << "OpenGLError after processing picks: " << err << std::endl; }
void SoccerInput::ProcessInput(const Input& input) { // get list of registered SoccerMonitor objects TLeafList soccerMonitorList; mMonitorClient->ListChildrenSupportingClass<SoccerMonitor>(soccerMonitorList); if (soccerMonitorList.empty()) { GetLog()->Error() << "ERROR: (SoccerInput) Unable to get SoccerMonitor\n"; return; } shared_ptr<SoccerMonitor> soccerMonitor = shared_static_cast<SoccerMonitor>(soccerMonitorList.front()); switch (input.mId) { default: return; case CmdKickOff: if (input.GetKeyPress()) { SendCommand("(kickOff Left)"); } break; case CmdKickOffRight: if (input.GetKeyPress()) { SendCommand("(kickOff Right)"); } break; case CmdMoveAgent: if (input.GetKeyPress()) { //SendCommand("(agent (team Left)(unum 1)(pos -2.0 1.0 3.5))"); } break; case CmdDropBall: if (input.GetKeyPress()) { SendCommand("(dropBall)"); } break; case CmdShootBall: if (input.GetKeyPress()) { //SendCommand("(ball (vel -4.0 0.0 2.0))"); } break; case CmdMoveBall: if (input.GetKeyPress()) { //SendCommand("(ball (pos -42.0 0.0 0.3))"); } break; case CmdCameraLeftGoal: if (input.GetKeyPress()) { salt::Vector2f fieldSize = soccerMonitor->GetFieldSize(); salt::Vector3f pos(-fieldSize.x()*0.8, 0.0, fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(90); mFPS->SetVAngleDeg(35); } break; case CmdCameraLeftCorner: if (input.GetKeyPress()) { salt::Vector2f fieldSize = soccerMonitor->GetFieldSize(); salt::Vector3f pos(-fieldSize.x()*0.8, -fieldSize.y(), fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(50); mFPS->SetVAngleDeg(30); } break; case CmdCameraMiddleLeft: if (input.GetKeyPress()) { salt::Vector2f fieldSize = soccerMonitor->GetFieldSize(); salt::Vector3f pos(0, -fieldSize.y(), fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(salt::gRadToDeg(-0.625)); mFPS->SetVAngleDeg(40); } break; case CmdCameraMiddleRight: if (input.GetKeyPress()) { salt::Vector2f fieldSize = soccerMonitor->GetFieldSize(); salt::Vector3f pos(0, -fieldSize.y(), fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(salt::gRadToDeg(0.625)); mFPS->SetVAngleDeg(40); } break; case CmdCameraMiddle: if (input.GetKeyPress()) { salt::Vector2f fieldSize = soccerMonitor->GetFieldSize(); salt::Vector3f pos(0, -fieldSize.y()*1.1, fieldSize.x()*0.6); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(0); mFPS->SetVAngleDeg(45); } break; case CmdCameraRightCorner: if (input.GetKeyPress()) { salt::Vector2f fieldSize = soccerMonitor->GetFieldSize(); salt::Vector3f pos(fieldSize.x()*0.8, -fieldSize.y(), fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(-50); mFPS->SetVAngleDeg(30); } break; case CmdCameraRightGoal: if (input.GetKeyPress()) { salt::Vector2f fieldSize = soccerMonitor->GetFieldSize(); salt::Vector3f pos(fieldSize.x()*0.8, 0.0, fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(-90); mFPS->SetVAngleDeg(35); } break; case CmdFreeKickLeft: if (input.GetKeyPress()) { SendCommand("(playMode free_kick_left)"); } break; case CmdFreeKickRight: if (input.GetKeyPress()) { SendCommand("(playMode free_kick_right)"); } break; }; }
void SoccerInput::SelectCamera(int idx) { // get list of registered SoccerMonitor objects TLeafList soccerMonitorList; mMonitorClient->ListChildrenSupportingClass<SoccerMonitor>(soccerMonitorList); if (soccerMonitorList.empty()) { GetLog()->Error() << "ERROR: (SoccerInput) Unable to get SoccerMonitor\n"; return; } boost::shared_ptr<SoccerMonitor> soccerMonitor = shared_static_cast<SoccerMonitor>(soccerMonitorList.front()); salt::Vector2f fieldSize = soccerMonitor->GetFieldSize(); switch (idx) { case 0: { salt::Vector3f pos(-fieldSize.x()*0.8, 0.0, fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(90); mFPS->SetVAngleDeg(35); } break; case 1: { salt::Vector3f pos(-fieldSize.x()*0.8, -fieldSize.y(), fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(50); mFPS->SetVAngleDeg(30); } break; case 2: { salt::Vector3f pos(0, -fieldSize.y(), fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(salt::gRadToDeg(-0.625)); mFPS->SetVAngleDeg(40); } break; case 3: { salt::Vector3f pos(0, -fieldSize.y()*1.1, fieldSize.x()*0.6); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(0); mFPS->SetVAngleDeg(45); } break; case 4: { salt::Vector3f pos(0, -fieldSize.y(), fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(salt::gRadToDeg(0.625)); mFPS->SetVAngleDeg(40); } break; case 5: { salt::Vector3f pos(fieldSize.x()*0.8, -fieldSize.y(), fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(-50); mFPS->SetVAngleDeg(30); } break; case 6: { salt::Vector3f pos(fieldSize.x()*0.8, 0.0, fieldSize.x()*0.4); mCameraBody->SetPosition(pos); mFPS->SetHAngleDeg(-90); mFPS->SetVAngleDeg(35); } break; } }
void StaticMeshInitEffector::PrePhysicsUpdateInternal(float deltaTime) { if ( ( mAction.get() == 0 ) || (mGameState.get() == 0) || (mAgentAspect.get() == 0) ) { return; } InitEffector::PrePhysicsUpdateInternal(deltaTime); // search for the AgentState boost::shared_ptr<AgentState> state = static_pointer_cast<AgentState> (mAgentAspect->GetChildOfClass("AgentState",true)); if (state.get() == 0) { GetLog()->Error() << "ERROR: (StaticMeshInitEffector) cannot find AgentState\n"; return; } TTeamIndex team = state->GetTeamIndex(); string teamMat = "matTeam"; if (team == TI_LEFT) { teamMat = "matLeft"; } else if (team == TI_RIGHT) { teamMat = "matRight"; } else { GetLog()->Error() << "ERROR: (StaticMeshInitEffector) Found no team\n"; return; } int unum = state->GetUniformNumber(); string unumMat = "matNum" + lexical_cast<string>(unum); // get parent of the agent aspect boost::shared_ptr<Node> parent = dynamic_pointer_cast<Node> (mAgentAspect->GetParent().lock()); if (parent.get() == 0) { GetLog()->Error() << "ERROR: (SingleMatInitEffector) cannot find parent of agent aspect\n"; return; } // build list of meshes, searching recursively TLeafList meshes; parent->ListChildrenSupportingClass<StaticMesh>(meshes,true); // change the meshes for new team material for ( TLeafList::iterator iter = meshes.begin(); iter != meshes.end(); ++iter ) { boost::shared_ptr<StaticMesh> m = static_pointer_cast<StaticMesh>(*iter); m->ChangeMaterial("matTeam",teamMat); m->ChangeMaterial("matNum",unumMat); } // set the scene modified, the monitor will update boost::shared_ptr<SceneServer> sceneServer = dynamic_pointer_cast<SceneServer>(GetCore()->Get("/sys/server/scene")); if (sceneServer.get() ==0) { GetLog()->Error() << "(SingleMatInitEffector) ERROR: SceneServer not found\n"; return; } boost::shared_ptr<Scene> scene = sceneServer->GetActiveScene(); if (scene.get() == 0) { GetLog()->Error() << "(SingleMatInitEffector) ERROR: Scene not found\n"; return; } scene->SetModified(true); }