Example #1
0
        internal static W3dVertexMaterial Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var result = new W3dVertexMaterial();
                ParseChunks(reader, context.CurrentEndPosition, chunkType =>
                {
                    switch (chunkType)
                    {
                    case W3dChunkType.W3D_CHUNK_VERTEX_MATERIAL_NAME:
                        result.Name = W3dVertexMaterialName.Parse(reader, context);
                        break;

                    case W3dChunkType.W3D_CHUNK_VERTEX_MAPPER_ARGS0:
                        result.MapperArgs0 = W3dVertexMapperArgs.Parse(reader, context, chunkType);
                        break;

                    case W3dChunkType.W3D_CHUNK_VERTEX_MAPPER_ARGS1:
                        result.MapperArgs1 = W3dVertexMapperArgs.Parse(reader, context, chunkType);
                        break;

                    case W3dChunkType.W3D_CHUNK_VERTEX_MATERIAL_INFO:
                        result.Info = W3dVertexMaterialInfo.Parse(reader, context);
                        break;

                    default:
                        throw CreateUnknownChunkException(chunkType);
                    }
                });
                return result;
            }));
        }
Example #2
0
        public static W3dMaterial Parse(BinaryReader reader, uint chunkSize)
        {
            return(ParseChunk <W3dMaterial>(reader, chunkSize, (result, header) =>
            {
                switch (header.ChunkType)
                {
                case W3dChunkType.W3D_CHUNK_VERTEX_MATERIAL_NAME:
                    result.Name = reader.ReadFixedLengthString((int)header.ChunkSize);
                    break;

                case W3dChunkType.W3D_CHUNK_VERTEX_MAPPER_ARGS0:
                    result.MapperArgs0 = W3dVertexMapperArgs.Parse(reader.ReadFixedLengthString((int)header.ChunkSize));
                    break;

                case W3dChunkType.W3D_CHUNK_VERTEX_MAPPER_ARGS1:
                    result.MapperArgs1 = W3dVertexMapperArgs.Parse(reader.ReadFixedLengthString((int)header.ChunkSize));
                    break;

                case W3dChunkType.W3D_CHUNK_VERTEX_MATERIAL_INFO:
                    result.VertexMaterialInfo = W3dVertexMaterial.Parse(reader);
                    break;

                default:
                    throw CreateUnknownChunkException(header);
                }
            }));
        }
Example #3
0
        public static W3dVertexMaterial Parse(BinaryReader reader)
        {
            var rawAttributes = reader.ReadUInt32();

            var result = new W3dVertexMaterial
            {
                Attributes = (W3dVertexMaterialFlags)(rawAttributes & 0xF),

                Stage0Mapping = ConvertStageMapping(rawAttributes, 0x00FF0000, 16),
                Stage1Mapping = ConvertStageMapping(rawAttributes, 0x0000FF00, 8),

                Ambient  = W3dRgb.Parse(reader),
                Diffuse  = W3dRgb.Parse(reader),
                Specular = W3dRgb.Parse(reader),
                Emissive = W3dRgb.Parse(reader),

                Shininess    = reader.ReadSingle(),
                Opacity      = reader.ReadSingle(),
                Translucency = reader.ReadSingle()
            };

            return(result);
        }