Exemple #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;
            }
        }
Exemple #3
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();
                    }
                }
            }