1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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 "mesh_camera_col_manager.h"
19 #include "precipitation_clip_grid.h"
20 #include "nel/3d/u_visual_collision_manager.h"
21 #include "nel/3d/u_shape_bank.h"
22 #include "nel/misc/hierarchical_timer.h"
23 #include "nel/misc/system_info.h"
24 #include "nel/3d/u_visual_collision_mesh.h"
27 using namespace NLMISC
;
31 // ***************************************************************************
32 CMeshCameraColManager MeshCameraColManager
;
35 // ***************************************************************************
36 extern UVisualCollisionManager
*CollisionManager
;
37 extern UDriver
*Driver
;
40 // ***************************************************************************
41 CMeshCameraColManager::CMeshCameraColManager()
45 // ***************************************************************************
46 CMeshCameraColManager::~CMeshCameraColManager()
51 // reset any remaining mesh
53 for(it
= _IgMap
.begin();it
!=_IgMap
.end();it
++)
55 CMeshGroup
&mg
= it
->second
;
56 for(uint i
=0;i
<mg
.Meshs
.size();i
++)
58 CollisionManager
->removeMeshCollision(mg
.Meshs
[i
]);
64 // ***************************************************************************
65 void CMeshCameraColManager::instanceGroupLoaded(NL3D::UInstanceGroup
* /* ig */)
70 // ***************************************************************************
71 void CMeshCameraColManager::instanceGroupAdded(NL3D::UInstanceGroup
*ig
)
80 // Build a list of Mesh to add to the collision manager
83 // for all instance of the ig
84 for(uint i
=0;i
<ig
->getNumInstance();i
++)
86 string shapeName
= ig
->getShapeName(i
);
87 if (!shapeName
.empty())
89 // well... get the actual name (not transformed)
90 if (shapeName
.find('.') == std::string::npos
)
91 shapeName
+= ".shape";
93 // try to get the shape
94 UShape shape
= Driver
->getShapeBank()->getShape(shapeName
);
98 UVisualCollisionMesh colMesh
;
99 shape
.getVisualCollisionMesh(colMesh
);
100 // if this mesh has a collision
103 // get the instance matrix
105 ig
->getInstanceMatrix(i
, mat
);
107 // special code for matis serre. Use the same flags as for shadows
108 bool avoidCollisionInside
= ig
->dontCastShadowForInterior(i
);
109 bool avoidCollisionOutside
= ig
->dontCastShadowForExterior(i
);
110 // very special patch for the matis serre (grrrrrrrrrrrrr)
111 avoidCollisionOutside
= avoidCollisionOutside
|| toLowerAscii(shapeName
)== "ma_serre_interieur.shape";
113 // then send the result to the collision manager, and keep the mesh col id if succeed
114 uint32 meshId
= CollisionManager
->addMeshInstanceCollision(colMesh
, mat
, avoidCollisionInside
, avoidCollisionOutside
);
116 mg
.Meshs
.push_back(meshId
);
122 // if mesh group not empty, append to the map (for future remove)
123 if(!mg
.Meshs
.empty())
125 // should not be present
126 nlassert(_IgMap
.find(ig
)==_IgMap
.end());
133 double freq = (double) CSystemInfo::getProcessorFrequency(false);
134 double msPerTick = 1000 / (double) freq;
135 nlinfo("IG Camera Added: {%x, %d}: %.3f ms", (uint32)ig, ig->getNumInstance(), msPerTick * clock.getNumTicks());*/
138 // ***************************************************************************
139 void CMeshCameraColManager::instanceGroupRemoved(NL3D::UInstanceGroup
*ig
)
141 // find the ig in the map
142 TIgMap::iterator it
= _IgMap
.find(ig
);
146 /*CSimpleClock clock;
149 // remove the mesh collision from the manager
150 CMeshGroup
&mg
= it
->second
;
151 for(uint i
=0;i
<mg
.Meshs
.size();i
++)
153 CollisionManager
->removeMeshCollision(mg
.Meshs
[i
]);
154 //HeightGrid.removeCollisionMesh(mg.Meshs[i]);
161 double freq = (double) CSystemInfo::getProcessorFrequency(false);
162 double msPerTick = 1000 / (double) freq;
163 nlinfo("IG Camera Removed: %.3f ms", msPerTick * clock.getNumTicks());*/