1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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/>.
21 #include "mesh_camera_col_manager.h"
22 #include "precipitation_clip_grid.h"
23 #include "nel/3d/u_visual_collision_manager.h"
24 #include "nel/3d/u_shape_bank.h"
25 #include "nel/misc/hierarchical_timer.h"
26 #include "nel/misc/system_info.h"
27 #include "nel/3d/u_visual_collision_mesh.h"
30 using namespace NLMISC
;
34 // ***************************************************************************
35 CMeshCameraColManager MeshCameraColManager
;
38 // ***************************************************************************
39 extern UVisualCollisionManager
*CollisionManager
;
40 extern UDriver
*Driver
;
43 // ***************************************************************************
44 CMeshCameraColManager::CMeshCameraColManager()
48 // ***************************************************************************
49 CMeshCameraColManager::~CMeshCameraColManager()
54 // reset any remaining mesh
56 for(it
= _IgMap
.begin();it
!=_IgMap
.end();it
++)
58 CMeshGroup
&mg
= it
->second
;
59 for(uint i
=0;i
<mg
.Meshs
.size();i
++)
61 CollisionManager
->removeMeshCollision(mg
.Meshs
[i
]);
67 // ***************************************************************************
68 void CMeshCameraColManager::instanceGroupLoaded(NL3D::UInstanceGroup
* /* ig */)
73 // ***************************************************************************
74 void CMeshCameraColManager::instanceGroupAdded(NL3D::UInstanceGroup
*ig
)
83 // Build a list of Mesh to add to the collision manager
86 // for all instance of the ig
87 for(uint i
=0;i
<ig
->getNumInstance();i
++)
89 string shapeName
= ig
->getShapeName(i
);
90 if (!shapeName
.empty())
92 // well... get the actual name (not transformed)
93 if (shapeName
.find('.') == std::string::npos
)
94 shapeName
+= ".shape";
96 // try to get the shape
97 UShape shape
= Driver
->getShapeBank()->getShape(shapeName
);
101 UVisualCollisionMesh colMesh
;
102 shape
.getVisualCollisionMesh(colMesh
);
103 // if this mesh has a collision
106 // get the instance matrix
108 ig
->getInstanceMatrix(i
, mat
);
110 // special code for matis serre. Use the same flags as for shadows
111 bool avoidCollisionInside
= ig
->dontCastShadowForInterior(i
);
112 bool avoidCollisionOutside
= ig
->dontCastShadowForExterior(i
);
113 // very special patch for the matis serre (grrrrrrrrrrrrr)
114 avoidCollisionOutside
= avoidCollisionOutside
|| toLowerAscii(shapeName
)== "ma_serre_interieur.shape";
116 // then send the result to the collision manager, and keep the mesh col id if succeed
117 uint32 meshId
= CollisionManager
->addMeshInstanceCollision(colMesh
, mat
, avoidCollisionInside
, avoidCollisionOutside
);
119 mg
.Meshs
.push_back(meshId
);
125 // if mesh group not empty, append to the map (for future remove)
126 if(!mg
.Meshs
.empty())
128 // should not be present
129 nlassert(_IgMap
.find(ig
)==_IgMap
.end());
136 double freq = (double) CSystemInfo::getProcessorFrequency(false);
137 double msPerTick = 1000 / (double) freq;
138 nlinfo("IG Camera Added: {%x, %d}: %.3f ms", (uint32)ig, ig->getNumInstance(), msPerTick * clock.getNumTicks());*/
141 // ***************************************************************************
142 void CMeshCameraColManager::instanceGroupRemoved(NL3D::UInstanceGroup
*ig
)
144 // find the ig in the map
145 TIgMap::iterator it
= _IgMap
.find(ig
);
149 /*CSimpleClock clock;
152 // remove the mesh collision from the manager
153 CMeshGroup
&mg
= it
->second
;
154 for(uint i
=0;i
<mg
.Meshs
.size();i
++)
156 CollisionManager
->removeMeshCollision(mg
.Meshs
[i
]);
157 //HeightGrid.removeCollisionMesh(mg.Meshs[i]);
164 double freq = (double) CSystemInfo::getProcessorFrequency(false);
165 double msPerTick = 1000 / (double) freq;
166 nlinfo("IG Camera Removed: %.3f ms", msPerTick * clock.getNumTicks());*/