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_client/mesh_instance.h>
00031 #include <rve_render_client/material.h>
00032 #include <rve_render_client/scene.h>
00033 #include <rve_render_client/client_context.h>
00034
00035 #include <rve_interfaces/MeshInstance.h>
00036 #include <rve_msgs/make_vector3.h>
00037 #include <rve_msgs/Mesh.h>
00038
00039 #include <boost/bind.hpp>
00040
00041 namespace rve_render_client
00042 {
00043
00044 MeshInstancePtr createMeshInstance(Scene* scene, const std::string& mesh_resource)
00045 {
00046 MeshPtr mesh = loadMesh(mesh_resource);
00047
00048 return createMeshInstance(scene, loadMesh(mesh_resource));
00049 }
00050
00051 MeshInstancePtr createMeshInstance(const std::string& mesh_resource)
00052 {
00053 MeshPtr mesh = loadMesh(mesh_resource);
00054
00055 return createMeshInstance(loadMesh(mesh_resource));
00056 }
00057
00058 MeshInstancePtr createMeshInstance(const MeshPtr& mesh)
00059 {
00060 MeshInstancePtr inst(new MeshInstance(mesh), destroySceneObject);
00061 return inst;
00062 }
00063
00064 MeshInstancePtr createMeshInstance(Scene* scene, const MeshPtr& mesh)
00065 {
00066 MeshInstancePtr inst = createMeshInstance(mesh);
00067 scene->addObject(inst.get());
00068 return inst;
00069 }
00070
00071 MeshInstance::MeshInstance(const MeshPtr& mesh)
00072 : mesh_(mesh)
00073 {
00074 orientation_.w = 1.0;
00075 scale_ = rve_msgs::makeVector3(1.0, 1.0, 1.0);
00076 proxy_index_ = addProxy("mesh_instance");
00077 }
00078
00079 MeshInstance::~MeshInstance()
00080 {
00081 }
00082
00083 rve_interfaces::MeshInstanceProxy* MeshInstance::getProxy(const ContextInfo& context)
00084 {
00085 return SceneObject::getProxy<rve_interfaces::MeshInstanceProxy>(context, proxy_index_);
00086 }
00087
00088 void MeshInstance::doCreate(ContextInfo& context)
00089 {
00090 if (!context.context->hasObject(mesh_.get()))
00091 {
00092 context.context->addObject(mesh_.get());
00093 }
00094
00095 rve_interfaces::MeshInstanceProxy* proxy = getProxy(context);
00096 proxy->create(getSceneID(context.scene), getID(), mesh_->getID());
00097
00098 rve_common::UUID scene_id = getSceneID(context.scene);
00099 proxy->setPositionAsync(scene_id, getID(), position_);
00100 proxy->setOrientationAsync(scene_id, getID(), orientation_);
00101 proxy->setScaleAsync(scene_id, getID(), scale_);
00102
00103 {
00104 M_Material::iterator it = materials_.begin();
00105 M_Material::iterator end = materials_.end();
00106 for (; it != end; ++it)
00107 {
00108 proxy->setMaterialForSubMesh(scene_id, getID(), it->first, it->second->getID());
00109 }
00110 }
00111 }
00112
00113 void MeshInstance::doDestroy(ContextInfo& context)
00114 {
00115 rve_interfaces::MeshInstanceProxy* proxy = getProxy(context);
00116 proxy->destroyAsync(getSceneID(context.scene), getID());
00117 }
00118
00119 void MeshInstance::getContextDependencies(V_UUID& deps)
00120 {
00121 M_Material::iterator it = materials_.begin();
00122 M_Material::iterator end = materials_.end();
00123 for (; it != end; ++it)
00124 {
00125 const MaterialPtr& mat = it->second;
00126 deps.push_back(mat->getID());
00127 }
00128 }
00129
00130 #define MESH_INSTANCE_MULTIPLEX(func, ...) \
00131 multiplex<rve_interfaces::MeshInstanceProxy>(boost::bind(&rve_interfaces::MeshInstanceProxy::func, _1, _2, getID(), __VA_ARGS__), proxy_index_);
00132
00133 void MeshInstance::setPosition(const rve_msgs::Vector3& pos)
00134 {
00135 position_ = pos;
00136 MESH_INSTANCE_MULTIPLEX(setPositionAsync, pos);
00137 }
00138
00139 void MeshInstance::setOrientation(const rve_msgs::Quaternion& orient)
00140 {
00141 orientation_ = orient;
00142 MESH_INSTANCE_MULTIPLEX(setOrientationAsync, orient);
00143 }
00144
00145 void MeshInstance::setScale(const rve_msgs::Vector3& scale)
00146 {
00147 scale_ = scale;
00148 MESH_INSTANCE_MULTIPLEX(setScaleAsync, scale);
00149 }
00150
00151 void MeshInstance::setMaterial(const MaterialPtr& mat)
00152 {
00153 materials_.clear();
00154 for (size_t i = 0; i < mesh_->getMesh()->submeshes.size(); ++i)
00155 {
00156 materials_[i] = mat;
00157 }
00158
00159 MESH_INSTANCE_MULTIPLEX(setMaterialAsync, mat->getID());
00160 }
00161
00162 void MeshInstance::setMaterial(uint32_t submesh_index, const MaterialPtr& mat)
00163 {
00164 materials_[submesh_index] = mat;
00165 MESH_INSTANCE_MULTIPLEX(setMaterialForSubMeshAsync, submesh_index, mat->getID());
00166 }
00167
00168 }
00169