コード例 #1
0
    void Start()
    {
        var meshList = meshRoot.GetComponentsInChildren <MeshFilter>();

        if (meshList.Length <= 0)
        {
            return;
        }

        objBounds = meshList[0].mesh.bounds;
        foreach (var meshF in meshList)
        {
            var boundsList = SpatialUtils.GetMeshTriangleBoundsList(meshF.mesh);
            objBoundsList.AddRange(boundsList);
            objBounds.Encapsulate(meshF.mesh.bounds);
        }

        bvhtree.BuildTree(objBoundsList);
        octree.BuildTree(objBoundsList, objBounds);
    }
コード例 #2
0
ファイル: TriangleMeshModel.cs プロジェクト: FrankyBoy/JRayX
        public TriangleMeshModel(List <I3DObject> triangleEdgeData)
        {
            _triangles = triangleEdgeData.ToArray();

            var max = new Vect3
            {
                X = double.NegativeInfinity,
                Y = double.NegativeInfinity,
                Z = double.NegativeInfinity
            };
            var min = new Vect3
            {
                X = double.PositiveInfinity,
                Y = double.PositiveInfinity,
                Z = double.PositiveInfinity
            };

            foreach (MinimalTriangle m in _triangles)
            {
                Vect3 p = m.GetBoundingSphere().Position;

                if (p.X > max.X)
                {
                    max.X = p.X;
                }
                if (p.Y > max.Y)
                {
                    max.Y = p.Y;
                }
                if (p.Z > max.Z)
                {
                    max.Z = p.Z;
                }
                if (p.X < min.X)
                {
                    min.X = p.X;
                }
                if (p.Y < min.Y)
                {
                    min.Y = p.Y;
                }
                if (p.Z < min.Z)
                {
                    min.Z = p.Z;
                }
            }

            max = (max + min) / 2;

            double radius = 0;

            foreach (MinimalTriangle m in _triangles)
            {
                Vect3 p = m.GetBoundingSphere().Position;
                min = p - max;
                double dist = m.GetBoundingSphereRadius() + min.Length();

                if (dist > radius)
                {
                    radius = dist;
                }
            }

            _bounds = new Sphere(max, radius, Color.Black);

            _tree = Octree.BuildTree(_bounds.Position, _triangles);

            foreach (MinimalTriangle m in _triangles)
            {
                m.Purge();
            }
        }