MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / fitK_DOP

Method fitK_DOP

Engine/source/ts/tsMeshFit.cpp:565–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

563}
564
565void MeshFit::fitK_DOP( const Vector<Point3F>& planes )
566{
567 // Push the planes up against the mesh
568 Vector<F32> planeDs;
569 for ( S32 i = 0; i < planes.size(); i++ )
570 planeDs.push_back( maxDot( planes[i] ) );
571
572 // Collect the intersection points of any 3 planes that lie inside
573 // the maximum distances found above
574 Vector<Point3F> points;
575 for ( S32 i = 0; i < planes.size()-2; i++ )
576 {
577 for ( S32 j = i+1; j < planes.size()-1; j++ )
578 {
579 for ( S32 k = j+1; k < planes.size(); k++ )
580 {
581 Point3F v23 = mCross( planes[j], planes[k] );
582 F32 denom = mDot( planes[i], v23 );
583 if ( denom == 0 )
584 continue;
585
586 Point3F v31 = mCross( planes[k], planes[i] );
587 Point3F v12 = mCross( planes[i], planes[j] );
588 Point3F p = ( planeDs[i]*v23 + planeDs[j]*v31 + planeDs[k]*v12 ) / denom;
589
590 // Ignore intersection points outside the volume
591 // described by the planes
592 bool addPoint = true;
593 for ( S32 n = 0; n < planes.size(); n++ )
594 {
595 if ( ( mDot( p, planes[n] ) - planeDs[n] ) > 0.005f )
596 {
597 addPoint = false;
598 break;
599 }
600 }
601
602 if ( addPoint )
603 points.push_back( p );
604 }
605 }
606 }
607
608 // Create a convex hull from the point set
609 CONVEX_DECOMPOSITION::HullDesc hd;
610 hd.mVcount = points.size();
611 hd.mVertices = (F32*)points.address();
612 hd.mVertexStride = sizeof(Point3F);
613 hd.mMaxVertices = 64;
614 hd.mSkinWidth = 0.0f;
615
616 CONVEX_DECOMPOSITION::HullLibrary hl;
617 CONVEX_DECOMPOSITION::HullResult result;
618 hl.CreateConvexHull( hd, result );
619
620 // Create TSMesh from convex hull
621 mMeshes.increment();
622 MeshFit::Mesh& lastMesh = mMeshes.last();

Callers

nothing calls this directly

Calls 10

incrementMethod · 0.80
mCrossFunction · 0.50
mDotFunction · 0.50
sizeMethod · 0.45
push_backMethod · 0.45
addressMethod · 0.45
CreateConvexHullMethod · 0.45
lastMethod · 0.45
identityMethod · 0.45
computeBoundsMethod · 0.45

Tested by

no test coverage detected