Esempio n. 1
0
        private bool SliceMesh(Mesh mesh, ref Plane slice)
        {
            mesh.GetVertices(_originalVertices);

            if (!MeshIntersection.BoundPlaneIntersect(mesh, ref slice))
            {
                return(false);
            }

            mesh.GetTriangles(_originalTriangles, 0);
            mesh.GetNormals(_originalNormals);
            mesh.GetUVs(0, _originalUVs);

            _meshA.Clear();
            _meshB.Clear();
            _addedPairs.Clear();

            for (int i = 0; i < _originalVertices.Count; ++i)
            {
                if (slice.GetDistanceToPoint(_originalVertices[i]) >= 0)
                {
                    _meshA.AddVertex(_originalVertices, _originalNormals, _originalUVs, i);
                }
                else
                {
                    _meshB.AddVertex(_originalVertices, _originalNormals, _originalUVs, i);
                }
            }

            if (_meshB.Vertices.Count == 0 || _meshA.Vertices.Count == 0)
            {
                return(false);
            }

            for (int i = 0; i < _originalTriangles.Count; i += 3)
            {
                if (_intersection.TrianglePlaneIntersect(_originalVertices, _originalUVs, _originalTriangles, i, ref slice, _meshA, _meshB, _intersectPairs))
                {
                    _addedPairs.AddRange(_intersectPairs);
                }
            }

            if (_addedPairs.Count > 0)
            {
                FillBoundaryFace(_addedPairs);
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public MeshSlicer()
        {
            _originalVertices  = new List <Vector3> (INITIAL_ARRAY_SIZE);
            _originalTriangles = new List <int> (INITIAL_ARRAY_SIZE * 3);
            _originalNormals   = new List <Vector3> (INITIAL_ARRAY_SIZE);
            _originalUVs       = new List <Vector2> (INITIAL_ARRAY_SIZE);
            _intersectPairs    = new Vector3[2];
            _tempTriangles     = new Vector3[3];

            _addedPairs   = new List <Vector3> (INITIAL_ARRAY_SIZE);
            _intersection = new MeshIntersection();

            _meshA = new MeshPiece(INITIAL_ARRAY_SIZE);
            _meshB = new MeshPiece(INITIAL_ARRAY_SIZE);
        }