// NeL - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . #include "std3d.h" // #include "nel/3d/shape_info.h" #include "nel/3d/mesh.h" #include "nel/3d/mesh_geom.h" #include "nel/3d/mesh_mrm.h" #include "nel/3d/mesh_multi_lod.h" // #include "nel/misc/path.h" // using namespace NLMISC; namespace NL3D { // *************************************************************************** void CShapeInfo::swap(CShapeInfo &other) { Tris.swap(other.Tris); std::swap(LocalBBox, (other.LocalBBox)); } // *************************************************************************** void CShapeInfo::build(const IShape &shape) { LocalBBox.setMinMax(CVector::Null, CVector::Null); // Cast to CMesh const CMesh *mesh=dynamic_cast(&shape); // Cast to CMeshMultiLod const CMeshMultiLod *meshMulti=dynamic_cast(&shape); // Cast to CMeshMultiLod const CMeshMRM *meshMRM=dynamic_cast(&shape); // It is a mesh ? if (mesh) { // Add its triangles build(*mesh, mesh->getMeshGeom()); } // It is a CMeshMultiLod ? else if (meshMulti) { // Get the first geommesh const IMeshGeom *meshGeom=&meshMulti->getMeshGeom (0); // Dynamic cast const CMeshGeom *geomMesh=dynamic_cast(meshGeom); if (geomMesh) { build(*meshMulti, *geomMesh); } // Dynamic cast const CMeshMRMGeom *mrmGeomMesh=dynamic_cast(meshGeom); if (mrmGeomMesh) { build(*meshMulti, *mrmGeomMesh); } } // It is a CMeshMultiLod ? else if (meshMRM) { // Get the first lod mesh geom build(*meshMRM, meshMRM->getMeshGeom ()); } // compute bbox if (Tris.empty()) { LocalBBox.setMinMax(CVector::Null, CVector::Null); } else { LocalBBox.setMinMax(Tris[0].V0, Tris[0].V0); LocalBBox.extend(Tris[0].V1); LocalBBox.extend(Tris[0].V2); for(uint k = 1; k < Tris.size(); ++k) { LocalBBox.extend(Tris[k].V0); LocalBBox.extend(Tris[k].V1); LocalBBox.extend(Tris[k].V2); } } } // *************************************************************************** void CShapeInfo::build(const CMeshBase &meshBase, const CMeshGeom &meshGeom) { // Get the vertex buffer const CVertexBuffer &vb=meshGeom.getVertexBuffer(); CVertexBufferRead vba; vb.lock (vba); // For each matrix block uint numBlock=meshGeom.getNbMatrixBlock(); for (uint block=0; block