private void CreateVertexBuffer(List <MyRenderBatchPart> batchParts, int vbSize) { if (m_vertexBuffer == null || m_vertexBuffer.Description.SizeInBytes < vbSize) { if (m_vertexBuffer != null) { m_vertexBuffer.Dispose(); } m_vertexBuffer = new VertexBuffer(MyRender.GraphicsDevice, vbSize, Usage.WriteOnly, VertexFormat.None, Pool.Default); } // Transform and copy vertices int vbOffset = 0; for (int i = 0; i < batchParts.Count; i++) { var part = batchParts[i]; var model = MyRenderModels.GetModel(part.Model); var matrix = part.ModelMatrix; var modelVb = model.VertexBuffer.Lock(0, model.GetVBSize, LockFlags.ReadOnly); var compoundVb = m_vertexBuffer.Lock(vbOffset, model.GetVBSize, LockFlags.None); for (int v = 0; v < model.GetVerticesCount(); v++) { var vertexPos = v * model.GetVertexStride(); modelVb.Seek(vertexPos, System.IO.SeekOrigin.Begin); var position = modelVb.Read <HalfVector4>(); Vector3D pos = (Vector3D)VF_Packer.UnpackPosition(ref position); var transformedPos = Vector3D.Transform(pos, matrix); m_localAABB = m_localAABB.Include(ref transformedPos); var transformedPos2 = (Vector3)transformedPos; compoundVb.Write <HalfVector4>(VF_Packer.PackPosition(ref transformedPos2)); // Transform and copy position compoundVb.WriteRange(modelVb.PositionPointer, model.GetVertexStride() - (modelVb.Position - vertexPos)); // Copy rest } m_vertexBuffer.Unlock(); model.VertexBuffer.Unlock(); vbOffset += model.GetVBSize; } BoundingSphereD.CreateFromBoundingBox(ref m_localAABB, out m_localVolume); m_localVolumeOffset = m_localVolume.Center; SetDirty(); }
public Vector3 GetVertexInt(int vertexIndex) { return(VF_Packer.UnpackPosition(ref m_vertices[vertexIndex].Position)); }