Beispiel #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;
            }));
        }
Beispiel #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);
                }
            }));
        }
Beispiel #3
0
        public static W3dVertexMapperArgs Parse(string value)
        {
            var result = new W3dVertexMapperArgs();

            if (string.IsNullOrEmpty(value))
            {
                return(result);
            }

            var splitMapperArgs0 = value.Split(new[] { "\r\n", "\n" }, System.StringSplitOptions.RemoveEmptyEntries);

            foreach (var mapperArg in splitMapperArgs0)
            {
                var splitMapperArg = mapperArg.Split('=');

                var mapperArgName = splitMapperArg[0].Trim();

                var mapperArgValue = splitMapperArg[1].Trim();
                if (mapperArgValue.Contains(";"))
                {
                    // ';' indicates a comment
                    mapperArgValue = mapperArgValue.Substring(0, mapperArgValue.IndexOf(';')).Trim();
                }

                mapperArgValue = mapperArgValue.TrimEnd('f').Replace("..", ".");

                switch (mapperArgName)
                {
                case "UPerSec":
                    TryParseFloat(mapperArgValue, out result.UPerSec);
                    break;

                case "VPerSec":
                    TryParseFloat(mapperArgValue, out result.VPerSec);
                    break;

                case "UScale":
                    TryParseFloat(mapperArgValue, out result.UScale);
                    break;

                case "VScale":
                    TryParseFloat(mapperArgValue, out result.VScale);
                    break;

                case "FPS":
                    TryParseFloat(mapperArgValue, out result.FPS);
                    break;

                case "Log1Width":
                    result.Log1Width = int.Parse(mapperArgValue);
                    break;

                case "Log2Width":
                    result.Log2Width = int.Parse(mapperArgValue);
                    break;

                case "Last":
                    int.TryParse(mapperArgValue, out result.Last);
                    break;

                case "Speed":
                    TryParseFloat(mapperArgValue, out result.Speed);
                    break;

                case "UCenter":
                    TryParseFloat(mapperArgValue, out result.UCenter);
                    break;

                case "VCenter":
                    TryParseFloat(mapperArgValue, out result.VCenter);
                    break;

                case "UAmp":
                    TryParseFloat(mapperArgValue, out result.UAmp);
                    break;

                case "UFreq":
                    TryParseFloat(mapperArgValue, out result.UFreq);
                    break;

                case "UPhase":
                    TryParseFloat(mapperArgValue, out result.UPhase);
                    break;

                case "VAmp":
                    TryParseFloat(mapperArgValue, out result.VAmp);
                    break;

                case "VFreq":
                    TryParseFloat(mapperArgValue, out result.VFreq);
                    break;

                case "VPhase":
                    TryParseFloat(mapperArgValue, out result.VPhase);
                    break;

                case "BumpRotation":
                    TryParseFloat(mapperArgValue, out result.BumpRotation);
                    break;

                case "BumpScale":
                    TryParseFloat(mapperArgValue, out result.BumpScale);
                    break;

                case "UStep":
                    TryParseFloat(mapperArgValue, out result.UStep);
                    break;

                case "VStep":
                    TryParseFloat(mapperArgValue, out result.VStep);
                    break;

                case "SPS":
                    TryParseFloat(mapperArgValue, out result.StepsPerSecond);
                    break;

                default:
                    throw new InvalidDataException($"Unknown mapper arg. Name = {mapperArgName}, Value = {splitMapperArg[1]}");
                }
            }

            return(result);
        }