/// <summary> /// Initializes a new instance of the <see cref="MeshReader"/> class. /// </summary> /// <param name="version">The engine version to target.</param> /// <param name="mesh">The mesh.</param> /// <param name="definition">The mesh's definition data.</param> public MeshReader(DefinitionSet version, Mesh mesh, RenderGeometryResourceDefinition definition) { _version = version; Mesh = mesh; Definition = definition; VertexStreams = new VertexBufferDefinition[StreamCount]; IndexBuffers = new IndexBufferDefinition[IndexBufferCount]; BindVertexStreams(); BindIndexBuffers(); }
private void SerializeDefinitionData(TagSerializer serializer, RenderGeometryResourceDefinition definition) { _model.Geometry.Resource = new ResourceReference { Type = 5, // FIXME: hax DefinitionFixups = new List <ResourceDefinitionFixup>(), D3DObjectFixups = new List <D3DObjectFixup>(), Unknown68 = 1, }; var context = new ResourceSerializationContext(_model.Geometry.Resource); serializer.Serialize(context, definition); }
private void BuildResourceData(TagSerializer serializer, Stream resourceDataStream) { var definition = new RenderGeometryResourceDefinition(); definition.VertexBuffers = new List <D3DPointer <VertexBufferDefinition> >(); definition.IndexBuffers = new List <D3DPointer <IndexBufferDefinition> >(); foreach (var mesh in Meshes) { // Serialize the mesh's vertex buffer var vertexBufferStart = (int)resourceDataStream.Position; var vertexCount = SerializeVertexBuffer(mesh, resourceDataStream); var vertexBufferEnd = (int)resourceDataStream.Position; // Add a definition for it mesh.Mesh.VertexBuffers[0] = (ushort)definition.VertexBuffers.Count; definition.VertexBuffers.Add(new D3DPointer <VertexBufferDefinition> { Definition = new VertexBufferDefinition { Count = vertexCount, Format = mesh.VertexFormat, VertexSize = VertexSizes[mesh.VertexFormat], Data = new ResourceDataReference(vertexBufferEnd - vertexBufferStart, new ResourceAddress(ResourceAddressType.Resource, vertexBufferStart)), }, }); // Serialize the mesh's index buffer var indexBufferStart = vertexBufferEnd; SerializeIndexBuffer(mesh, resourceDataStream); var indexBufferEnd = (int)resourceDataStream.Position; // Add a definition for it mesh.Mesh.IndexBuffers[0] = (ushort)definition.IndexBuffers.Count; definition.IndexBuffers.Add(new D3DPointer <IndexBufferDefinition> { Definition = new IndexBufferDefinition { Type = mesh.Mesh.IndexBufferType, Data = new ResourceDataReference(indexBufferEnd - indexBufferStart, new ResourceAddress(ResourceAddressType.Resource, indexBufferStart)), }, }); } SerializeDefinitionData(serializer, definition); }