diff --git a/Source/Core/GZBuilder/md3/GZModel.cs b/Source/Core/GZBuilder/md3/GZModel.cs index ea1de1b0..f42516f0 100644 --- a/Source/Core/GZBuilder/md3/GZModel.cs +++ b/Source/Core/GZBuilder/md3/GZModel.cs @@ -12,13 +12,13 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 internal byte NUM_MESHES; //can't be greater than 255, can it? internal Vector3[] BoundingBox; internal List Indeces2D; - internal List NumIndeces2D; + internal List NumIndeces2D; internal GZModel() { Meshes = new List(); Textures = new List(); Indeces2D = new List(); - NumIndeces2D = new List(); + NumIndeces2D = new List(); } } diff --git a/Source/Core/GZBuilder/md3/ModelReader.cs b/Source/Core/GZBuilder/md3/ModelReader.cs index 504c583e..a3e0f348 100644 --- a/Source/Core/GZBuilder/md3/ModelReader.cs +++ b/Source/Core/GZBuilder/md3/ModelReader.cs @@ -117,7 +117,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 if (s.Position != ofsSurfaces + start) s.Position = ofsSurfaces + start; - List polyIndecesList = new List(); + List polyIndecesList = new List(); List vertList = new List(); string error = ""; @@ -128,35 +128,36 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 } //indeces for rendering current mesh in 2d - short[] indeces2d_arr = CreateLineListIndeces(polyIndecesList); + int[] indeces2d_arr = CreateLineListIndeces(polyIndecesList); //mesh - Mesh mesh = new Mesh(D3DDevice, polyIndecesList.Count / 3, vertList.Count, MeshFlags.IndexBufferManaged | MeshFlags.VertexBufferManaged, General.Map.Graphics.Shaders.World3D.VertexElements); + Mesh mesh = new Mesh(D3DDevice, polyIndecesList.Count / 3, vertList.Count, MeshFlags.Use32Bit | MeshFlags.IndexBufferManaged | MeshFlags.VertexBufferManaged, General.Map.Graphics.Shaders.World3D.VertexElements); - DataStream stream = mesh.VertexBuffer.Lock(0, 0, LockFlags.None); - stream.WriteRange(vertList.ToArray()); - mesh.VertexBuffer.Unlock(); + using (DataStream stream = mesh.LockVertexBuffer(LockFlags.None)) { + stream.WriteRange(vertList.ToArray()); + } + mesh.UnlockVertexBuffer(); - stream = mesh.IndexBuffer.Lock(0, 0, LockFlags.None); - stream.WriteRange(polyIndecesList.ToArray()); - mesh.IndexBuffer.Unlock(); + using (DataStream stream = mesh.LockIndexBuffer(LockFlags.None)) { + stream.WriteRange(polyIndecesList.ToArray()); + } mesh.OptimizeInPlace(MeshOptimizeFlags.AttributeSort); mde.Model.Meshes.Add(mesh); //2d data - IndexBuffer indeces2d = new IndexBuffer(D3DDevice, 2 * indeces2d_arr.Length, Usage.WriteOnly, Pool.Managed, true); - stream = indeces2d.Lock(0, 0, LockFlags.None); - stream.WriteRange(indeces2d_arr); + IndexBuffer indeces2d = new IndexBuffer(D3DDevice, 4 * indeces2d_arr.Length, Usage.WriteOnly, Pool.Managed, false); + DataStream stream2d = indeces2d.Lock(0, 0, LockFlags.None); + stream2d.WriteRange(indeces2d_arr); indeces2d.Unlock(); mde.Model.Indeces2D.Add(indeces2d); - mde.Model.NumIndeces2D.Add((short)polyIndecesList.Count); + mde.Model.NumIndeces2D.Add(polyIndecesList.Count); } return ""; } - private static string ReadSurface(ref BoundingBoxSizes bbs, BinaryReader br, List polyIndecesList, List vertList, ModeldefEntry mde) { + private static string ReadSurface(ref BoundingBoxSizes bbs, BinaryReader br, List polyIndecesList, List vertList, ModeldefEntry mde) { int vertexOffset = vertList.Count; long start = br.BaseStream.Position; string magic = ReadString(br, 4); @@ -177,7 +178,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 br.BaseStream.Position = start + ofsTriangles; for (int i = 0; i < numTriangles * 3; i++) - polyIndecesList.Add( (short)(vertexOffset + br.ReadInt32()) ); + polyIndecesList.Add( vertexOffset + br.ReadInt32() ); //Vertices @@ -289,8 +290,8 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 int ofs_tris = br.ReadInt32(); //Offset to triangles int ofs_animFrame = br.ReadInt32(); //An offset to the first animation frame - List polyIndecesList = new List(); - List uvIndecesList = new List(); + List polyIndecesList = new List(); + List uvIndecesList = new List(); List uvCoordsList = new List(); List vertList = new List(); @@ -299,13 +300,13 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 s.Position = ofs_tris + start; for (int i = 0; i < num_tris; i++) { - polyIndecesList.Add((short)br.ReadInt16()); - polyIndecesList.Add((short)br.ReadInt16()); - polyIndecesList.Add((short)br.ReadInt16()); + polyIndecesList.Add((int)br.ReadInt16()); + polyIndecesList.Add((int)br.ReadInt16()); + polyIndecesList.Add((int)br.ReadInt16()); - uvIndecesList.Add((short)br.ReadInt16()); - uvIndecesList.Add((short)br.ReadInt16()); - uvIndecesList.Add((short)br.ReadInt16()); + uvIndecesList.Add((int)br.ReadInt16()); + uvIndecesList.Add((int)br.ReadInt16()); + uvIndecesList.Add((int)br.ReadInt16()); } //UV coords @@ -392,39 +393,41 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3 } //indeces for rendering current mesh in 2d - short[] indeces2d_arr = CreateLineListIndeces(polyIndecesList); + int[] indeces2d_arr = CreateLineListIndeces(polyIndecesList); //mesh - Mesh mesh = new Mesh(D3DDevice, polyIndecesList.Count / 3, vertList.Count, MeshFlags.IndexBufferManaged | MeshFlags.VertexBufferManaged, General.Map.Graphics.Shaders.World3D.VertexElements); + Mesh mesh = new Mesh(D3DDevice, polyIndecesList.Count / 3, vertList.Count, MeshFlags.Use32Bit | MeshFlags.IndexBufferManaged | MeshFlags.VertexBufferManaged, General.Map.Graphics.Shaders.World3D.VertexElements); - DataStream stream = mesh.VertexBuffer.Lock(0, 0, LockFlags.None); - stream.WriteRange(vertList.ToArray()); - mesh.VertexBuffer.Unlock(); + using (DataStream stream = mesh.LockVertexBuffer(LockFlags.None)) { + stream.WriteRange(vertList.ToArray()); + } + mesh.UnlockVertexBuffer(); - stream = mesh.IndexBuffer.Lock(0, 0, LockFlags.None); - stream.WriteRange(polyIndecesList.ToArray()); - mesh.IndexBuffer.Unlock(); + using (DataStream stream = mesh.LockIndexBuffer(LockFlags.None)) { + stream.WriteRange(polyIndecesList.ToArray()); + } + mesh.UnlockIndexBuffer(); mesh.OptimizeInPlace(MeshOptimizeFlags.AttributeSort); mde.Model.Meshes.Add(mesh); //2d data - IndexBuffer indeces2d = new IndexBuffer(D3DDevice, 2 * indeces2d_arr.Length, Usage.WriteOnly, Pool.Managed, true); - stream = indeces2d.Lock(0, 0, LockFlags.None); - stream.WriteRange(indeces2d_arr); + IndexBuffer indeces2d = new IndexBuffer(D3DDevice, 4 * indeces2d_arr.Length, Usage.WriteOnly, Pool.Managed, false); + DataStream stream2d = indeces2d.Lock(0, 0, LockFlags.None); + stream2d.WriteRange(indeces2d_arr); indeces2d.Unlock(); mde.Model.Indeces2D.Add(indeces2d); - mde.Model.NumIndeces2D.Add((short)polyIndecesList.Count); + mde.Model.NumIndeces2D.Add((int)polyIndecesList.Count); } return ""; } //this creates list of vertex indeces for rendering using LineList method - private static short[] CreateLineListIndeces(List polyIndecesList) { - short[] indeces2d_arr = new short[polyIndecesList.Count * 2]; - short ind1, ind2, ind3; - for (short i = 0; i < polyIndecesList.Count; i += 3) { + private static int[] CreateLineListIndeces(List polyIndecesList) { + int[] indeces2d_arr = new int[polyIndecesList.Count * 2]; + int ind1, ind2, ind3; + for (int i = 0; i < polyIndecesList.Count; i += 3) { ind1 = polyIndecesList[i]; ind2 = polyIndecesList[i + 1]; ind3 = polyIndecesList[i + 2];