00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __Ogre_Volume_MeshBuilder_H__ 00029 #define __Ogre_Volume_MeshBuilder_H__ 00030 00031 #include <vector> 00032 #include "OgreSimpleRenderable.h" 00033 #include "OgreManualObject.h" 00034 #include "OgreRenderOperation.h" 00035 #include "OgreVector3.h" 00036 #include "OgreAxisAlignedBox.h" 00037 #include "OgreSceneManager.h" 00038 #include "OgreVolumePrerequisites.h" 00039 00040 namespace Ogre { 00041 namespace Volume { 00042 00045 typedef struct _OgreVolumeExport Vertex 00046 { 00048 Real x; 00049 00051 Real y; 00052 00054 Real z; 00055 00057 Real nX; 00058 00060 Real nY; 00061 00063 Real nZ; 00064 00071 Vertex(const Vector3 &v, const Vector3 &n) : 00072 x(v.x), y(v.y), z(v.z), 00073 nX(n.x), nY(n.y), nZ(n.z) 00074 { 00075 } 00076 Vertex() 00077 { 00078 } 00079 } Vertex; 00080 00087 bool _OgreVolumeExport operator==(Vertex const& a, Vertex const& b); 00088 00097 bool _OgreVolumeExport operator<(const Vertex& a, const Vertex& b); 00098 00101 typedef vector<Vertex>::type VecVertex; 00102 00105 typedef vector<size_t>::type VecIndices; 00106 00110 class _OgreVolumeExport MeshBuilderCallback 00111 { 00112 public: 00113 virtual ~MeshBuilderCallback() {} 00114 00127 virtual void ready(const SimpleRenderable *simpleRenderable, const VecVertex &vertices, const VecIndices &indices, size_t level, int inProcess) = 0; 00128 }; 00129 00132 class _OgreVolumeExport MeshBuilder : public UtilityAlloc 00133 { 00134 protected: 00135 00137 static const unsigned short MAIN_BINDING; 00138 00140 typedef map<Vertex, size_t>::type UMapVertexIndex; 00141 UMapVertexIndex mIndexMap; 00142 00144 VecVertex mVertices; 00145 00147 VecIndices mIndices; 00148 00150 AxisAlignedBox mBox; 00151 00153 bool mBoxInit; 00154 00159 inline void addVertex(const Vertex &v) 00160 { 00161 size_t i = 0; 00162 if (mIndexMap.find(v) == mIndexMap.end()) 00163 { 00164 i = mVertices.size(); 00165 mIndexMap[v] = i; 00166 mVertices.push_back(v); 00167 00168 // Update bounding box 00169 if (!mBoxInit) 00170 { 00171 mBox.setExtents(v.x, v.y, v.z, v.x, v.y, v.z); 00172 mBoxInit = true; 00173 } 00174 else 00175 { 00176 if (v.x < mBox.getMinimum().x) 00177 { 00178 mBox.setMinimumX(v.x); 00179 } 00180 if (v.y < mBox.getMinimum().y) 00181 { 00182 mBox.setMinimumY(v.y); 00183 } 00184 if (v.z < mBox.getMinimum().z) 00185 { 00186 mBox.setMinimumZ(v.z); 00187 } 00188 if (v.x > mBox.getMaximum().x) 00189 { 00190 mBox.setMaximumX(v.x); 00191 } 00192 if (v.y > mBox.getMaximum().y) 00193 { 00194 mBox.setMaximumY(v.y); 00195 } 00196 if (v.z > mBox.getMaximum().z) 00197 { 00198 mBox.setMaximumZ(v.z); 00199 } 00200 } 00201 } 00202 else 00203 { 00204 i = mIndexMap[v]; 00205 } 00206 mIndices.push_back(i); 00207 } 00208 00209 public: 00210 00238 static inline void addCubeToManualObject( 00239 ManualObject *manual, 00240 const Vector3 &c0, 00241 const Vector3 &c1, 00242 const Vector3 &c2, 00243 const Vector3 &c3, 00244 const Vector3 &c4, 00245 const Vector3 &c5, 00246 const Vector3 &c6, 00247 const Vector3 &c7, 00248 uint32 &baseIndex 00249 ) 00250 { 00251 manual->position(c0); 00252 manual->position(c1); 00253 manual->position(c2); 00254 manual->position(c3); 00255 manual->position(c4); 00256 manual->position(c5); 00257 manual->position(c6); 00258 manual->position(c7); 00259 00260 manual->index(baseIndex + 0); manual->index(baseIndex + 1); 00261 manual->index(baseIndex + 1); manual->index(baseIndex + 2); 00262 manual->index(baseIndex + 2); manual->index(baseIndex + 3); 00263 manual->index(baseIndex + 3); manual->index(baseIndex + 0); 00264 00265 manual->index(baseIndex + 4); manual->index(baseIndex + 5); 00266 manual->index(baseIndex + 5); manual->index(baseIndex + 6); 00267 manual->index(baseIndex + 6); manual->index(baseIndex + 7); 00268 manual->index(baseIndex + 7); manual->index(baseIndex + 4); 00269 00270 manual->index(baseIndex + 0); manual->index(baseIndex + 4); 00271 manual->index(baseIndex + 1); manual->index(baseIndex + 5); 00272 manual->index(baseIndex + 2); manual->index(baseIndex + 6); 00273 manual->index(baseIndex + 3); manual->index(baseIndex + 7); 00274 baseIndex += 8; 00275 } 00276 00279 MeshBuilder(void); 00280 00295 inline void addTriangle(const Vector3 &v0, const Vector3 &n0, const Vector3 &v1, const Vector3 &n1, const Vector3 &v2, const Vector3 &n2) 00296 { 00297 addVertex(Vertex(v0, n0)); 00298 addVertex(Vertex(v1, n1)); 00299 addVertex(Vertex(v2, n2)); 00300 } 00301 00309 size_t generateBuffers(RenderOperation &operation); 00310 00321 Entity* generateWithManualObject(SceneManager *sceneManager, const String &name, const String &material); 00322 00327 AxisAlignedBox getBoundingBox(void); 00328 00339 void executeCallback(MeshBuilderCallback *callback, const SimpleRenderable *simpleRenderable, size_t level, int inProcess) const; 00340 00341 }; 00342 } 00343 } 00344 00345 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:48