Пример #1
0
        public List <Vector3> OverlapVerts(OBB obb, MeshTransform meshTransform)
        {
            if (!_isBuilt)
            {
                Build();
            }

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

            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, meshSpaceOBB.Center, meshSpaceOBB.Size, meshSpaceOBB.Rotation))
                    {
                        overlappedVerts.Add(meshTransform.TransformPoint(modelVert));
                        usedIndices.Add(vertIndex);
                    }
                }
            }

            return(overlappedVerts);
        }
Пример #2
0
        public bool OverlapVerts(OBB obb, MeshTransform meshTransform, List <Vector3> verts)
        {
            verts.Clear();
            if (!_isBuilt)
            {
                Build();
            }

            OBB meshSpaceOBB = meshTransform.InverseTransformOBB(obb);

            if (!_tree.OverlapBox(meshSpaceOBB, _nodeBuffer))
            {
                return(false);
            }

            _vertexIndexSet.Clear();
            foreach (var node in _nodeBuffer)
            {
                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 (_vertexIndexSet.Contains(vertIndex))
                    {
                        continue;
                    }

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

            return(verts.Count != 0);
        }