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, 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(); } }
// 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; } }