1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/3d/shape_info.h"
24 #include "nel/3d/mesh.h"
25 #include "nel/3d/mesh_geom.h"
26 #include "nel/3d/mesh_mrm.h"
27 #include "nel/3d/mesh_multi_lod.h"
29 #include "nel/misc/path.h"
32 using namespace NLMISC
;
41 // ***************************************************************************
42 void CShapeInfo::swap(CShapeInfo
&other
)
44 Tris
.swap(other
.Tris
);
45 std::swap(LocalBBox
, (other
.LocalBBox
));
49 // ***************************************************************************
50 void CShapeInfo::build(const IShape
&shape
)
52 LocalBBox
.setMinMax(CVector::Null
, CVector::Null
);
54 const CMesh
*mesh
=dynamic_cast<const CMesh
*>(&shape
);
56 // Cast to CMeshMultiLod
57 const CMeshMultiLod
*meshMulti
=dynamic_cast<const CMeshMultiLod
*>(&shape
);
59 // Cast to CMeshMultiLod
60 const CMeshMRM
*meshMRM
=dynamic_cast<const CMeshMRM
*>(&shape
);
66 build(*mesh
, mesh
->getMeshGeom());
68 // It is a CMeshMultiLod ?
71 // Get the first geommesh
72 const IMeshGeom
*meshGeom
=&meshMulti
->getMeshGeom (0);
75 const CMeshGeom
*geomMesh
=dynamic_cast<const CMeshGeom
*>(meshGeom
);
78 build(*meshMulti
, *geomMesh
);
82 const CMeshMRMGeom
*mrmGeomMesh
=dynamic_cast<const CMeshMRMGeom
*>(meshGeom
);
85 build(*meshMulti
, *mrmGeomMesh
);
88 // It is a CMeshMultiLod ?
91 // Get the first lod mesh geom
92 build(*meshMRM
, meshMRM
->getMeshGeom ());
97 LocalBBox
.setMinMax(CVector::Null
, CVector::Null
);
101 LocalBBox
.setMinMax(Tris
[0].V0
, Tris
[0].V0
);
102 LocalBBox
.extend(Tris
[0].V1
);
103 LocalBBox
.extend(Tris
[0].V2
);
104 for(uint k
= 1; k
< Tris
.size(); ++k
)
106 LocalBBox
.extend(Tris
[k
].V0
);
107 LocalBBox
.extend(Tris
[k
].V1
);
108 LocalBBox
.extend(Tris
[k
].V2
);
113 // ***************************************************************************
114 void CShapeInfo::build(const CMeshBase
&meshBase
, const CMeshGeom
&meshGeom
)
116 // Get the vertex buffer
117 const CVertexBuffer
&vb
=meshGeom
.getVertexBuffer();
118 CVertexBufferRead vba
;
121 // For each matrix block
122 uint numBlock
=meshGeom
.getNbMatrixBlock();
123 for (uint block
=0; block
<numBlock
; block
++)
125 // For each render pass
126 uint numRenderPass
=meshGeom
.getNbRdrPass(block
);
127 for (uint pass
=0; pass
<numRenderPass
; pass
++)
130 const CMaterial
&material
= meshBase
.getMaterial (meshGeom
.getRdrPassMaterial ( block
, pass
));
132 if (material
.getBlend()) continue; // don't test against transparent materials
133 //if (material.getAlphaTest()) continue; // don't test against transparent materials
137 // Get the primitive block
138 const CIndexBuffer
&primitive
=meshGeom
.getRdrPassPrimitiveBlock ( block
, pass
);
140 CIndexBufferRead iba
;
141 primitive
.lock (iba
);
142 if (iba
.getFormat() == CIndexBuffer::Indices32
)
144 const uint32
* triIndex
= (const uint32
*) iba
.getPtr ();
145 uint numTri
=primitive
.getNumIndexes ()/3;
147 for (tri
=0; tri
<numTri
; tri
++)
150 CVector v0
= *vba
.getVertexCoordPointer (triIndex
[tri
*3]);
151 CVector v1
= *vba
.getVertexCoordPointer (triIndex
[tri
*3+1]);
152 CVector v2
= *vba
.getVertexCoordPointer (triIndex
[tri
*3+2]);
153 Tris
.push_back(NLMISC::CTriangle (v0
, v1
, v2
));
158 const uint16
* triIndex
= (const uint16
*) iba
.getPtr ();
159 uint numTri
=primitive
.getNumIndexes ()/3;
161 for (tri
=0; tri
<numTri
; tri
++)
164 CVector v0
= *vba
.getVertexCoordPointer (triIndex
[tri
*3]);
165 CVector v1
= *vba
.getVertexCoordPointer (triIndex
[tri
*3+1]);
166 CVector v2
= *vba
.getVertexCoordPointer (triIndex
[tri
*3+2]);
167 Tris
.push_back(NLMISC::CTriangle (v0
, v1
, v2
));
175 // ***************************************************************************
176 void CShapeInfo::build(const CMeshBase
&meshBase
, const CMeshMRMGeom
&meshGeom
)
178 // Get the vertex buffer
179 const CVertexBuffer
&vb
=meshGeom
.getVertexBuffer();
180 CVertexBufferRead vba
;
183 // For each render pass
184 uint numRenderPass
=meshGeom
.getNbRdrPass(0);
185 for (uint pass
=0; pass
<numRenderPass
; pass
++)
188 const CMaterial
&material
= meshBase
.getMaterial (meshGeom
.getRdrPassMaterial ( 0, pass
));
190 if (material
.getBlend()) continue; // don't test against transparent materials
191 //if (material.getAlphaTest()) continue; // don't test against transparent materials
194 // Get the primitive block
195 const CIndexBuffer
&primitive
=meshGeom
.getRdrPassPrimitiveBlock ( 0, pass
);
198 CIndexBufferRead iba
;
199 primitive
.lock (iba
);
200 if (iba
.getFormat() == CIndexBuffer::Indices32
)
202 const uint32
* triIndex
= (const uint32
*) iba
.getPtr ();
203 uint numTri
=primitive
.getNumIndexes ()/3;
205 for (tri
=0; tri
<numTri
; tri
++)
208 CVector v0
= *vba
.getVertexCoordPointer (triIndex
[tri
*3]);
209 CVector v1
= *vba
.getVertexCoordPointer (triIndex
[tri
*3+1]);
210 CVector v2
= *vba
.getVertexCoordPointer (triIndex
[tri
*3+2]);
211 Tris
.push_back (NLMISC::CTriangle (v0
, v1
, v2
));
216 const uint16
* triIndex
= (const uint16
*) iba
.getPtr ();
217 uint numTri
=primitive
.getNumIndexes ()/3;
219 for (tri
=0; tri
<numTri
; tri
++)
222 CVector v0
= *vba
.getVertexCoordPointer (triIndex
[tri
*3]);
223 CVector v1
= *vba
.getVertexCoordPointer (triIndex
[tri
*3+1]);
224 CVector v2
= *vba
.getVertexCoordPointer (triIndex
[tri
*3+2]);
225 Tris
.push_back (NLMISC::CTriangle (v0
, v1
, v2
));
232 // ***************************************************************************
233 std::string
standardizeShapeName(const std::string
&name
)
235 std::string result
= NLMISC::toLowerAscii(name
);
236 if (CFile::getExtension(result
).empty())