예제 #1
0
        internal static W3dShaderMaterial Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var result = new W3dShaderMaterial();

                ParseChunks(reader, context.CurrentEndPosition, chunkType =>
                {
                    switch (chunkType)
                    {
                    case W3dChunkType.W3D_CHUNK_SHADER_MATERIAL_HEADER:
                        result.Header = W3dShaderMaterialHeader.Parse(reader, context);
                        break;

                    case W3dChunkType.W3D_CHUNK_SHADER_MATERIAL_PROPERTY:
                        result.Properties.Add(W3dShaderMaterialProperty.Parse(reader, context));
                        break;

                    default:
                        throw CreateUnknownChunkException(chunkType);
                    }
                });

                return result;
            }));
        }
예제 #2
0
        internal static W3dShaderMaterialProperty Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var result = new W3dShaderMaterialProperty
                {
                    PropertyType = reader.ReadUInt32AsEnum <W3dShaderMaterialPropertyType>(),
                    PropertyName = reader.ReadFixedLengthString((int)reader.ReadUInt32())
                };

                var value = new W3dShaderMaterialPropertyValue();

                switch (result.PropertyType)
                {
                case W3dShaderMaterialPropertyType.Texture:
                    result.StringValue = reader.ReadFixedLengthString((int)reader.ReadUInt32());
                    break;

                case W3dShaderMaterialPropertyType.Float:
                case W3dShaderMaterialPropertyType.Vector2:
                case W3dShaderMaterialPropertyType.Vector3:
                case W3dShaderMaterialPropertyType.Vector4:
                case W3dShaderMaterialPropertyType.Int:
                case W3dShaderMaterialPropertyType.Bool:
                    value = W3dShaderMaterialPropertyValue.Parse(reader, result.PropertyType);
                    break;

                default:
                    throw new InvalidDataException();
                }

                result.Value = value;

                return result;
            }));
        }