Ejemplo n.º 1
0
        public List <Vector3> OverlapVerts(OBB obb, MeshTransform meshTransform)
        {
            if (!_isBuilt)
            {
                Build();
            }

            OBB           meshSpaceOBB = meshTransform.InverseTransformOBB(obb);
            HashSet <int> usedIndices  = new HashSet <int>();
            List <SphereTreeNode <MeshTriangle> > overlappedNodes = _tree.OverlapBox(meshSpaceOBB);

            if (overlappedNodes.Count == 0)
            {
                return(new List <Vector3>());
            }

            List <Vector3> overlappedVerts = new List <Vector3>(50);

            foreach (SphereTreeNode <MeshTriangle> node in overlappedNodes)
            {
                int          triangleIndex = node.Data.TriangleIndex;
                MeshTriangle triangleInfo  = _mesh.GetTriangle(triangleIndex);
                Vector3[]    modelVerts    = triangleInfo.Vertices;

                for (int ptIndex = 0; ptIndex < modelVerts.Length; ++ptIndex)
                {
                    int vertIndex = triangleInfo.GetVertIndex(ptIndex);
                    if (usedIndices.Contains(vertIndex))
                    {
                        continue;
                    }

                    Vector3 modelVert = modelVerts[ptIndex];
                    if (BoxMath.ContainsPoint(modelVert, meshSpaceOBB.Center, meshSpaceOBB.Size, meshSpaceOBB.Rotation))
                    {
                        overlappedVerts.Add(meshTransform.TransformPoint(modelVert));
                        usedIndices.Add(vertIndex);
                    }
                }
            }

            return(overlappedVerts);
        }
Ejemplo n.º 2
0
        public List <Vector3> OverlapModelVerts(OBB modelOBB)
        {
            if (!_isBuilt)
            {
                Build();
            }

            HashSet <int> usedIndices     = new HashSet <int>();
            var           overlappedNodes = _tree.OverlapBox(modelOBB);

            if (overlappedNodes.Count == 0)
            {
                return(new List <Vector3>());
            }

            var overlappedVerts = new List <Vector3>(50);

            foreach (var node in overlappedNodes)
            {
                int          triangleIndex = node.Data.TriangleIndex;
                MeshTriangle triangleInfo  = _mesh.GetTriangle(triangleIndex);
                var          modelVerts    = triangleInfo.Vertices;

                for (int ptIndex = 0; ptIndex < modelVerts.Length; ++ptIndex)
                {
                    int vertIndex = triangleInfo.GetVertIndex(ptIndex);
                    if (usedIndices.Contains(vertIndex))
                    {
                        continue;
                    }

                    Vector3 modelVert = modelVerts[ptIndex];
                    if (BoxMath.ContainsPoint(modelVert, modelOBB.Center, modelOBB.Size, modelOBB.Rotation))
                    {
                        overlappedVerts.Add(modelVert);
                        usedIndices.Add(vertIndex);
                    }
                }
            }

            return(overlappedVerts);
        }