📄 geometryserver.cpp
字号:
/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: geometryserver.cpp,v 1.3 2008/02/22 07:52:15 hedayat Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "geometryserver.h"#include "meshimporter.h"#include "meshexporter.h"#include <zeitgeist/logserver/logserver.h>using namespace oxygen;using namespace zeitgeist;using namespace salt;using namespace std;using namespace boost;GeometryServer::GeometryServer() : Node(){}GeometryServer::~GeometryServer(){}voidGeometryServer::OnLink(){ if (mChildren.size() == 0) { InitMeshImporter("oxygen/StdMeshImporter"); }}boolGeometryServer::InitMeshImporter(const string& importerName){ shared_ptr<MeshImporter> importer = shared_dynamic_cast<MeshImporter>(GetCore()->New(importerName)); if (importer.get() == 0) { GetLog()->Error() << "(GeometryServer) ERROR: " << "unable to create '" << importerName << "'\n"; return false; } importer->SetName(importerName); AddChildReference(importer); GetLog()->Normal() << "(GeometryServer) MeshImporter '" << importerName << "' registered\n"; return true;}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 shared_ptr<TriMesh>(); } // try to mangle the name for ( TLeafList::iterator iter = importer.begin(); iter != importer.end(); ++iter ) { shared_ptr<MeshImporter> importer = shared_static_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 ) { shared_ptr<MeshImporter> importer = shared_static_cast<MeshImporter>(*iter); 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()->Normal() << "(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 shared_ptr<TriMesh>();}voidGeometryServer::RegisterMesh(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()->Normal() << "(GeometryServer) mesh " << name << " registered\n"; TLeafList exporters; ListChildrenSupportingClass<MeshExporter>(exporters); for (TLeafList::const_iterator bi = exporters.begin(); bi != exporters.end(); ++bi) { GetLog()->Normal() << "(GeometryServer) additionally registered mesh " << name << " via MeshExporter '" << (*bi)->GetName() << "'\n"; shared_ptr<MeshExporter> mb = shared_static_cast<MeshExporter>(*bi); mb->RegisterMesh(mesh); }}boolGeometryServer::InitMeshExporter(const string& name){ shared_ptr<MeshExporter> exporter = shared_dynamic_cast<MeshExporter>(GetCore()->New(name)); if (exporter.get() == 0) { GetLog()->Error() << "(GeometryServer) ERROR: " << "unable to create MeshExporter '" << name << "'\n"; return false; } exporter->SetName(name); AddChildReference(exporter); GetLog()->Normal() << "(GeometryServer) MeshExporter '" << name << "' registered\n"; return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -