private static Block GetLitTextureShaderBlock(Shader shader) { var w = new BlockWriter(); w.WriteString(shader.Name); // shader name w.WriteU32(1); // Lit texture shader attributes: 1 = Lights enabled w.WriteF32(0f); // Alpha Test Reference w.WriteU32(0x00000617); // Alpha Test Function: ALWAYS w.WriteU32(0x00000605); // Color Blend Function: FB_MULTIPLY w.WriteU32(1); // Render pass enabled flags w.WriteU32(string.IsNullOrEmpty(shader.Texture) ? 0u : 1u); // Shader channels (active texture count) w.WriteU32(0); // Alpha texture channels w.WriteString(shader.Material); // Material name // Texture information. if (!string.IsNullOrEmpty(shader.Texture)) { w.WriteString(shader.Texture); // Texture name w.WriteF32(1f); // Texture Intensity w.WriteU8(0); // Blend function: 0 - Multiply w.WriteU8(1); // Blend Source, 1 - blending constant w.WriteF32(1f); // Blend Constant w.WriteU8(0x00); // Texture Mod; 0x00: TM_NONE; shader should use texture coordinates of the model w.WriteArray(Matrix4.GetIdentityMatrix().ToArray()); // Texture Transform Matrix Element w.WriteArray(Matrix4.GetIdentityMatrix().ToArray()); // Texture Wrap Transform Matrix Element w.WriteU8(0x03); // Texture Repeat } return(w.GetBlock(BlockType.LitTextureShader)); }
private static Block GetMeshContinuationBlock(Mesh mesh) { var w = new BlockWriter(); w.WriteString(mesh.Name); // mesh name w.WriteU32(0); // chain index // Base Mesh Description. w.WriteU32((uint)mesh.Triangles.Count); // base face count w.WriteU32((uint)mesh.Positions.Count); // base position count w.WriteU32((uint)mesh.Normals.Count); // base normal count w.WriteU32(0); // base diffuse color count w.WriteU32(0); // base specular color count w.WriteU32((uint)mesh.TextureCoordinates.Count); // base texture coordinate count // Base Mesh Data. foreach (Vector3 position in mesh.Positions) { w.WriteF32(position.X); w.WriteF32(position.Y); w.WriteF32(position.Z); } foreach (Vector3 normal in mesh.Normals) { w.WriteF32(normal.X); w.WriteF32(normal.Y); w.WriteF32(normal.Z); } foreach (Vector2 textureCoordinate in mesh.TextureCoordinates) { w.WriteF32(textureCoordinate.X); w.WriteF32(textureCoordinate.Y); w.WriteF32(0); w.WriteF32(0); } // Base Face. foreach (Triangle triangle in mesh.Triangles) { w.WriteU32(0u); // shading id foreach (Corner corner in triangle) { w.WriteU32((uint)corner.Position); if (corner.Normal >= 0) { w.WriteU32((uint)corner.Normal); } if (corner.TextureCoordinate >= 0) { w.WriteU32((uint)corner.TextureCoordinate); } } } return(w.GetBlock(BlockType.MeshContinuation)); }
private static Block GetMeshDeclarationBlock(Mesh mesh) { var w = new BlockWriter(); w.WriteString(mesh.Name); // mesh name w.WriteU32(0); // chain index // Max mesh description. w.WriteU32(mesh.Normals.Count == 0 ? 1u : 0u); // mesh attributes: 1 = no normals w.WriteU32((uint)mesh.Triangles.Count); // face count w.WriteU32((uint)mesh.Positions.Count); // positions count w.WriteU32((uint)mesh.Normals.Count); // normal count w.WriteU32(0); // diffuse color count w.WriteU32(0); // specular color count w.WriteU32((uint)mesh.TextureCoordinates.Count); // texture coord count w.WriteU32(1); // shading count // Shading description. w.WriteU32(0); // shading attributes w.WriteU32(mesh.TextureCoordinates.Count == 0 ? 0u : 1u); // texture layer count if (mesh.TextureCoordinates.Count > 0) { w.WriteU32(2); // texture coord dimensions } w.WriteU32(0); // original shading id // Clod desc. w.WriteU32((uint)mesh.Positions.Count); // minimum resolution w.WriteU32((uint)mesh.Positions.Count); // maximum resolution // Resource Description. w.WriteU32(300); // position quality factor w.WriteU32(300); // normal quality factor w.WriteU32(300); // texture coord quality factor w.WriteF32(0.01f); // position inverse quant w.WriteF32(0.01f); // normal inverse quant w.WriteF32(0.01f); // texture coord inverse quant w.WriteF32(0.01f); // diffuse color inverse quant w.WriteF32(0.01f); // specular color inverse quant w.WriteF32(0.9f); // normal crease parameter w.WriteF32(0.5f); // normal update parameter w.WriteF32(0.985f); // normal tolerance parameter // Skeleton Description. w.WriteU32(0); // bone count return(w.GetBlock(BlockType.MeshDeclaration)); }
private static Block GetMaterialResourceBlock(Material material) { var w = new BlockWriter(); w.WriteString(material.Name); // Material resource name w.WriteU32(0x0000003F); // Material attributes: use all colors, opacity and reflectivity 0x0000003F w.WriteF32(material.Ambient.R); // Ambient red w.WriteF32(material.Ambient.G); // Ambient green w.WriteF32(material.Ambient.B); // Ambient blue w.WriteF32(material.Diffuse.R); // Diffuse red w.WriteF32(material.Diffuse.G); // Diffuse green w.WriteF32(material.Diffuse.B); // Diffuse blue w.WriteF32(material.Specular.R); // Specular red w.WriteF32(material.Specular.G); // Specular green w.WriteF32(material.Specular.B); // Specular blue w.WriteF32(material.Emissive.R); // Emissive red w.WriteF32(material.Emissive.G); // Emissive green w.WriteF32(material.Emissive.B); // Emissive blue w.WriteF32(material.Reflectivity); // Reflectivity w.WriteF32(material.Opacity); // Opacity return(w.GetBlock(BlockType.MaterialResource)); }