Beispiel #1
0
            public void Init(
                Vector3 positionOffset, Vector3 positionScale,
                Vector3[] positions, int vertexCount,
                MyVoxelTriangle[] triangles, int triangleCount)
            {
                if (vertexCount == 0)
                {
                    VoxelVerticesCount  = 0;
                    VoxelTrianglesCount = 0;
                    m_octree            = null;
                    m_positions         = null;
                    return;
                }
                Debug.Assert(vertexCount <= Int16.MaxValue);

                // copy voxel vertices
                m_positionOffset = positionOffset;
                m_positionScale  = positionScale;
                m_positions      = new Vector3[vertexCount];
                Array.Copy(positions, m_positions, vertexCount);

                ProfilerShort.Begin("build octree");
                if (m_octree == null)
                {
                    m_octree = new MyOctree();
                }
                m_octree.Init(m_positions, vertexCount, triangles, triangleCount, out VoxelTriangles);
                ProfilerShort.End();

                // set size only after the arrays are fully allocated
                VoxelVerticesCount  = vertexCount;
                VoxelTrianglesCount = triangleCount;
            }
        public void PrepareCache(MyVoxelVertex[] vertices, int vertexCount, MyVoxelTriangle[] triangles, int triangleCount)
        {
            lock (m_syncRoot)
            {
                if (vertexCount == 0)
                {
                    VoxelVerticesCount = 0;
                    VoxelTrianglesCount = 0;
                    m_octree = null;
                    VoxelVertices = null;
                    return;
                }
                MyCommonDebugUtils.AssertDebug(vertexCount <= Int16.MaxValue);

                MyRender.GetRenderProfiler().StartProfilingBlock("build octree");
                if (m_octree == null)
                    m_octree = new MyOctree();
                m_octree.Init(ref vertices, ref vertexCount, ref triangles, ref triangleCount, out VoxelTriangles);
                MyRender.GetRenderProfiler().EndProfilingBlock();

                // copy voxel vertices
                VoxelVertices = new MyVoxelVertex[vertexCount];
                for (int i = 0; i < vertexCount; i++)
                    VoxelVertices[i] = vertices[i];

                // set size only after the arrays are fully allocated
                VoxelVerticesCount = vertexCount;
                VoxelTrianglesCount = triangleCount;
            }
        }
        public void PrepareCache(MyVoxelVertex[] vertices, int vertexCount, MyVoxelTriangle[] triangles, int triangleCount)
        {
            lock (m_syncRoot)
            {
                if (vertexCount == 0)
                {
                    VoxelVerticesCount  = 0;
                    VoxelTrianglesCount = 0;
                    m_octree            = null;
                    VoxelVertices       = null;
                    return;
                }
                MyCommonDebugUtils.AssertDebug(vertexCount <= Int16.MaxValue);

                MyRender.GetRenderProfiler().StartProfilingBlock("build octree");
                if (m_octree == null)
                {
                    m_octree = new MyOctree();
                }
                m_octree.Init(ref vertices, ref vertexCount, ref triangles, ref triangleCount, out VoxelTriangles);
                MyRender.GetRenderProfiler().EndProfilingBlock();

                // copy voxel vertices
                VoxelVertices = new MyVoxelVertex[vertexCount];
                for (int i = 0; i < vertexCount; i++)
                {
                    VoxelVertices[i] = vertices[i];
                }

                // set size only after the arrays are fully allocated
                VoxelVerticesCount  = vertexCount;
                VoxelTrianglesCount = triangleCount;
            }
        }
        //  This methods needs to be called after every cell cache released!! It releases vertex buffer. It's important,
        //  because when this cell cache will be associated to a new cell, not same material vertex buffer will be used so unused needs to be disposed!!
        public void Reset()
        {
            lock (m_syncRoot)
            {
                VoxelTrianglesCount = 0;
                VoxelTriangles      = null;
                m_octree            = null;

                VoxelVerticesCount = 0;
                VoxelVertices      = null;
                Key = INVALID_KEY;
            }
        }
Beispiel #5
0
            public void PrepareCache(
                MyVoxelVertex[] vertices, int vertexCount,
                MyVoxelTriangle[] triangles, int triangleCount,
                float positionScale, Vector3 positionOffset,
                bool createPhysicsShape)
            {
                using (m_syncRoot.AcquireExclusiveUsing())
                {
                    if (vertexCount == 0)
                    {
                        VoxelVerticesCount  = 0;
                        VoxelTrianglesCount = 0;
                        m_octree            = null;
                        m_voxelVertices     = null;
                        PositionOffset      = new Vector3(0f);
                        PositionScale       = 0f;
                        return;
                    }
                    Debug.Assert(vertexCount <= Int16.MaxValue);

                    // copy voxel vertices
                    m_voxelVertices = new MyPackedVoxelVertex[vertexCount];
                    for (int i = 0; i < vertexCount; i++)
                    {
                        m_voxelVertices[i] = (MyPackedVoxelVertex)vertices[i];
                    }

                    Profiler.Begin("build octree");
                    if (m_octree == null)
                    {
                        m_octree = new MyOctree();
                    }
                    m_octree.Init(ref m_voxelVertices, ref vertexCount, ref triangles, ref triangleCount, out VoxelTriangles);
                    Profiler.End();

                    // set size only after the arrays are fully allocated
                    VoxelVerticesCount  = vertexCount;
                    VoxelTrianglesCount = triangleCount;
                    PositionOffset      = positionOffset;
                    PositionScale       = positionScale;

                    if (createPhysicsShape)
                    {
                        CreateMeshShape();
                    }
                }
            }
Beispiel #6
0
            //  This methods needs to be called after every cell cache released!! It releases vertex buffer. It's important,
            //  because when this cell cache will be associated to a new cell, not same material vertex buffer will be used so unused needs to be disposed!!
            public void Reset()
            {
                using (m_syncRoot.AcquireExclusiveUsing())
                {
                    if (!m_meshShape.Base.IsZero)
                    {
                        MyPhysics.AssertThread();
                        Debug.Assert(m_meshShape.Base.ReferenceCount > 0);
                        m_meshShape.Base.RemoveReference();
                    }
                    m_meshShape = (HkBvCompressedMeshShape)HkShape.Empty;

                    VoxelTrianglesCount = 0;
                    VoxelTriangles      = null;
                    m_octree            = null;

                    VoxelVerticesCount = 0;
                    m_voxelVertices    = null;
                    Key = INVALID_KEY;

                    m_octree = null;
                }
            }
Beispiel #7
0
 public void Init(Vector3 positionOffset, Vector3 positionScale, Vector3[] positions, int vertexCount, MyVoxelTriangle[] triangles, int triangleCount)
 {
     if (vertexCount == 0)
     {
         this.VoxelVerticesCount  = 0;
         this.VoxelTrianglesCount = 0;
         this.m_octree            = null;
         this.m_positions         = null;
     }
     else
     {
         this.m_positionOffset = positionOffset;
         this.m_positionScale  = positionScale;
         this.m_positions      = new Vector3[vertexCount];
         Array.Copy(positions, this.m_positions, vertexCount);
         if (this.m_octree == null)
         {
             this.m_octree = new MyOctree();
         }
         this.m_octree.Init(this.m_positions, vertexCount, triangles, triangleCount, out this.VoxelTriangles);
         this.VoxelVerticesCount  = vertexCount;
         this.VoxelTrianglesCount = triangleCount;
     }
 }
        //  This methods needs to be called after every cell cache released!! It releases vertex buffer. It's important, 
        //  because when this cell cache will be associated to a new cell, not same material vertex buffer will be used so unused needs to be disposed!!
        public void Reset()
        {
            lock (m_syncRoot)
            {
                VoxelTrianglesCount = 0;
                VoxelTriangles = null;
                m_octree = null;

                VoxelVerticesCount = 0;
                VoxelVertices = null;
                Key = INVALID_KEY;
            }
        }