MCPcopy Create free account
hub / github.com/axmolengine/axmol / createBVTree

Function createBVTree

3rdparty/recast/DetourNavMeshBuilder.cpp:171–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171static int createBVTree(dtNavMeshCreateParams* params, dtBVNode* nodes, int /*nnodes*/)
172{
173 // Build tree
174 float quantFactor = 1 / params->cs;
175 BVItem* items = (BVItem*)dtAlloc(sizeof(BVItem)*params->polyCount, DT_ALLOC_TEMP);
176 for (int i = 0; i < params->polyCount; i++)
177 {
178 BVItem& it = items[i];
179 it.i = i;
180 // Calc polygon bounds. Use detail meshes if available.
181 if (params->detailMeshes)
182 {
183 int vb = (int)params->detailMeshes[i*4+0];
184 int ndv = (int)params->detailMeshes[i*4+1];
185 float bmin[3];
186 float bmax[3];
187
188 const float* dv = &params->detailVerts[vb*3];
189 dtVcopy(bmin, dv);
190 dtVcopy(bmax, dv);
191
192 for (int j = 1; j < ndv; j++)
193 {
194 dtVmin(bmin, &dv[j * 3]);
195 dtVmax(bmax, &dv[j * 3]);
196 }
197
198 // BV-tree uses cs for all dimensions
199 it.bmin[0] = (unsigned short)dtClamp((int)((bmin[0] - params->bmin[0])*quantFactor), 0, 0xffff);
200 it.bmin[1] = (unsigned short)dtClamp((int)((bmin[1] - params->bmin[1])*quantFactor), 0, 0xffff);
201 it.bmin[2] = (unsigned short)dtClamp((int)((bmin[2] - params->bmin[2])*quantFactor), 0, 0xffff);
202
203 it.bmax[0] = (unsigned short)dtClamp((int)((bmax[0] - params->bmin[0])*quantFactor), 0, 0xffff);
204 it.bmax[1] = (unsigned short)dtClamp((int)((bmax[1] - params->bmin[1])*quantFactor), 0, 0xffff);
205 it.bmax[2] = (unsigned short)dtClamp((int)((bmax[2] - params->bmin[2])*quantFactor), 0, 0xffff);
206 }
207 else
208 {
209 const unsigned short* p = &params->polys[i*params->nvp * 2];
210 it.bmin[0] = it.bmax[0] = params->verts[p[0] * 3 + 0];
211 it.bmin[1] = it.bmax[1] = params->verts[p[0] * 3 + 1];
212 it.bmin[2] = it.bmax[2] = params->verts[p[0] * 3 + 2];
213
214 for (int j = 1; j < params->nvp; ++j)
215 {
216 if (p[j] == MESH_NULL_IDX) break;
217 unsigned short x = params->verts[p[j] * 3 + 0];
218 unsigned short y = params->verts[p[j] * 3 + 1];
219 unsigned short z = params->verts[p[j] * 3 + 2];
220
221 if (x < it.bmin[0]) it.bmin[0] = x;
222 if (y < it.bmin[1]) it.bmin[1] = y;
223 if (z < it.bmin[2]) it.bmin[2] = z;
224
225 if (x > it.bmax[0]) it.bmax[0] = x;
226 if (y > it.bmax[1]) it.bmax[1] = y;
227 if (z > it.bmax[2]) it.bmax[2] = z;
228 }

Callers 1

dtCreateNavMeshDataFunction · 0.85

Calls 9

dtAllocFunction · 0.85
dtVcopyFunction · 0.85
dtVminFunction · 0.85
dtVmaxFunction · 0.85
dtClampFunction · 0.85
dtMathFloorfFunction · 0.85
dtMathCeilfFunction · 0.85
subdivideFunction · 0.85
dtFreeFunction · 0.85

Tested by

no test coverage detected