Merge branch 'ryzom/ark-features' into main/gingo-test
[ryzomcore.git] / nel / src / 3d / u_shape.cpp
blobeb179375ed9dfa09666a6e63fa3a217c08fa198b
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "std3d.h"
19 #include "nel/3d/u_shape.h"
20 #include "nel/3d/mesh.h"
21 #include "nel/3d/mesh_multi_lod.h"
22 #include "nel/3d/u_visual_collision_mesh.h"
25 using namespace std;
26 using namespace NLMISC;
28 #ifdef DEBUG_NEW
29 #define new DEBUG_NEW
30 #endif
32 namespace NL3D
35 // ***************************************************************************
36 bool UShape::getMeshTriangles(std::vector<NLMISC::CVector> &vertices, std::vector<uint32> &indices) const
38 if(!_Object)
39 return false;
41 // **** try to get a CMeshGeom
42 CMesh *mesh= dynamic_cast<CMesh*>(_Object);
43 CMeshMultiLod *meshMulti= dynamic_cast<CMeshMultiLod*>(_Object);
44 const CMeshGeom *meshGeom= NULL;
45 if(mesh)
47 meshGeom= &mesh->getMeshGeom();
49 else if(meshMulti)
51 // get the first (bigger) meshGeom
52 if(meshMulti->getNumSlotMesh())
54 meshGeom= dynamic_cast<const CMeshGeom*>(&meshMulti->getMeshGeom(0));
58 if(!meshGeom)
59 return false;
61 // **** try to retrieve data
62 if(! (meshGeom->retrieveVertices(vertices) && meshGeom->retrieveTriangles(indices)) )
64 vertices.clear();
65 indices.clear();
66 return false;
69 // ok!
70 return true;
74 // ***************************************************************************
75 void UShape::getVisualCollisionMesh(UVisualCollisionMesh &colMesh) const
77 colMesh.attach(NULL);
79 CMeshBase *mesh= dynamic_cast<CMeshBase*>(_Object);
80 if(mesh)
82 // attach the possible col mesh
83 colMesh.attach(mesh->getVisualCollisionMesh());
87 // ***************************************************************************
88 uint UShape::getNumMaterials() const
90 CMeshBase *mesh= dynamic_cast<CMeshBase*>(_Object);
91 if(mesh)
93 return mesh->getNbMaterial();
96 // fails => return 0
97 return 0;
100 // ***************************************************************************
101 UMaterial UShape::getMaterial(uint materialId) const
103 CMeshBase *mesh= dynamic_cast<CMeshBase*>(_Object);
104 if(mesh)
106 if(materialId<mesh->getNbMaterial())
107 return UMaterial(&mesh->getMaterial(materialId));
110 // fails => return NULL material
111 return UMaterial();
114 // ***************************************************************************
115 bool UShape::getDefaultOpacity() const
117 CMeshBase *mesh= dynamic_cast<CMeshBase*>(_Object);
118 if(mesh)
120 return mesh->getDefaultOpacity();
123 return false;
126 // ***************************************************************************
127 bool UShape::getDefaultTransparency() const
129 CMeshBase *mesh= dynamic_cast<CMeshBase*>(_Object);
130 if(mesh)
132 return mesh->getDefaultTransparency();
135 return false;
139 } // NL3D