Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "rve_render_server/scene.h"
00031 #include "rve_render_server/renderer.h"
00032 #include "rve_render_server/camera.h"
00033 #include "rve_render_server/mesh_instance.h"
00034 #include "rve_render_server/billboard_text.h"
00035 #include "rve_render_server/batching/points_manager.h"
00036 #include "rve_render_server/batching/lines_manager.h"
00037 #include "rve_render_server/batching/triangles_manager.h"
00038
00039 #include <OGRE/OgreSceneManager.h>
00040 #include <OGRE/OgreCamera.h>
00041 #include <OGRE/OgreRoot.h>
00042 #include <OGRE/OgreEntity.h>
00043
00044 #include <ros/assert.h>
00045
00046 using namespace rve_common;
00047
00048 namespace rve_render_server
00049 {
00050
00051 Scene::Scene(const UUID& id, Ogre::SceneManager* scene_manager)
00052 : id_(id)
00053 , scene_manager_(scene_manager)
00054 , points_manager_(new PointsManager(scene_manager))
00055 , lines_manager_(new LinesManager(scene_manager))
00056 , triangles_manager_(new TrianglesManager(scene_manager))
00057 {
00058 }
00059
00060 Scene::~Scene()
00061 {
00062 cameras_.clear();
00063 mesh_instances_.clear();
00064 billboard_texts_.clear();
00065 delete points_manager_;
00066 delete lines_manager_;
00067 delete triangles_manager_;
00068 Ogre::Root::getSingleton().destroySceneManager(scene_manager_);
00069 }
00070
00071 Camera* Scene::createCamera(const UUID& id)
00072 {
00073 Ogre::Camera* ogre_cam = scene_manager_->createCamera(id.toString());
00074 ogre_cam->setPosition(0, 10, 10);
00075 ogre_cam->lookAt(0, 0, 0);
00076 ogre_cam->setNearClipDistance(0.01);
00077 ogre_cam->setFarClipDistance(1000.0);
00078 ogre_cam->setAutoAspectRatio(false);
00079
00080 CameraPtr cam(new Camera(ogre_cam));
00081 cameras_[id] = cam;
00082
00083 return cam.get();
00084 }
00085
00086 void Scene::destroyCamera(const UUID& id)
00087 {
00088 M_Camera::iterator it = cameras_.find(id);
00089 ROS_ASSERT(it != cameras_.end());
00090
00091 const CameraPtr& cam = it->second;
00092 scene_manager_->destroyCamera(cam->getOgreCamera());
00093
00094 cameras_.erase(it);
00095 }
00096
00097 Camera* Scene::getCamera(const UUID& id)
00098 {
00099 M_Camera::iterator it = cameras_.find(id);
00100 if (it == cameras_.end())
00101 {
00102 return 0;
00103 }
00104
00105 return it->second.get();
00106 }
00107
00108 MeshInstance* Scene::createMeshInstance(const rve_common::UUID& id, const rve_common::UUID& mesh_id)
00109 {
00110 MeshPtr mesh = getRenderer()->getMesh(mesh_id);
00111 MeshInstancePtr inst(new MeshInstance(id, scene_manager_, mesh));
00112 mesh_instances_[id] = inst;
00113 return inst.get();
00114 }
00115
00116 MeshInstance* Scene::getMeshInstance(const rve_common::UUID& id)
00117 {
00118 M_MeshInstance::iterator it = mesh_instances_.find(id);
00119 if (it == mesh_instances_.end())
00120 {
00121 throw std::runtime_error("Mesh instance [" + id.toString() + "] does not exist");
00122 }
00123
00124 return it->second.get();
00125 }
00126
00127 void Scene::destroyMeshInstance(const rve_common::UUID& id)
00128 {
00129 mesh_instances_.erase(id);
00130 }
00131
00132 BillboardText* Scene::createBillboardText(const rve_common::UUID& id)
00133 {
00134 BillboardTextPtr bbt(new BillboardText(id, scene_manager_));
00135 billboard_texts_[id] = bbt;
00136 return bbt.get();
00137 }
00138
00139 void Scene::destroyBillboardText(const rve_common::UUID& id)
00140 {
00141 billboard_texts_.erase(id);
00142 }
00143
00144 BillboardText* Scene::getBillboardText(const rve_common::UUID& id)
00145 {
00146 M_BillboardText::iterator it = billboard_texts_.find(id);
00147 if (it == billboard_texts_.end())
00148 {
00149 return 0;
00150 }
00151
00152 return it->second.get();
00153 }
00154
00155 }