MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / ExtractPath

Method ExtractPath

engine/Poseidon/Graphics/Rendering/Shape/Shape.cpp:392–561  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390};
391
392Shape* Shape::ExtractPath() // optimize this shape as path lod
393{
394 // scan all faces
395 // replace vertices with degenerate
396 // create a new shape with 2-vertex (degenerate) faces
397 Shape* res = new Shape;
398
399 res->_pointToVertex.Realloc(_pointToVertex.Size());
400 res->_pointToVertex.Resize(_pointToVertex.Size());
401 for (int i = 0; i < res->_pointToVertex.Size(); i++)
402 {
403 res->_pointToVertex[i] = -1;
404 }
405
406 // first of all convert all points to their respective "merged" variants
407 // find longest of the shortest edges
408
409 float maxMerge2 = 0;
410 for (Offset o = BeginFaces(); o < EndFaces(); NextFace(o))
411 {
412 float shortestEdge2 = 1e10;
413 const Poly& face = Face(o);
414 for (int v = 0, p = face.N() - 1; v < face.N(); p = v++)
415 {
416 Vector3Val vpos = Pos(face.GetVertex(v));
417 Vector3Val ppos = Pos(face.GetVertex(p));
418 float dist2 = vpos.Distance2(ppos);
419 saturateMin(shortestEdge2, dist2);
420 }
421 if (shortestEdge2 < Square(1.5))
422 {
423 saturateMax(maxMerge2, shortestEdge2);
424 }
425 }
426 maxMerge2 *= 1.01;
427 LOG_DEBUG(Graphics, " longest shortest edge {:.1f}", sqrt(maxMerge2));
428 saturate(maxMerge2, Square(0.5), Square(1.5));
429 // or use property from model
430
431 AutoArray<MergedVertex> vertex;
432 Temp<int> vertexReplacedBy(NPos());
433
434 res->_pointToVertex.Realloc(_pointToVertex.Size());
435 res->_pointToVertex.Resize(_pointToVertex.Size());
436 for (int i = 0; i < res->_pointToVertex.Size(); i++)
437 {
438 res->_pointToVertex[i] = -1;
439 }
440 for (int i = 0; i < NPos(); i++)
441 {
442 Vector3Val pos = Pos(i);
443 // search if the point is already present
444 // check i point selection
445 // check i
446 int pointI = VertexToPoint(i);
447 int selI = -1;
448 const char* name = "";
449 for (int s = 0; s < NNamedSel(); s++)

Callers

nothing calls this directly

Calls 15

FaceClass · 0.85
saturateMinFunction · 0.85
saturateMaxFunction · 0.85
sqrtFunction · 0.85
saturateFunction · 0.85
GetVertexMethod · 0.80
AddVertexFastMethod · 0.80
AccessMethod · 0.80
AddNamedSelMethod · 0.80
SetNMethod · 0.80
StoreOriginalMinMaxMethod · 0.80
SquareFunction · 0.50

Tested by

no test coverage detected