public Managed Parse(TextParser parser, string defaultName) { ShaderTechnique shader = new ShaderTechnique(this.resourceManager); shader.Name = defaultName; shader.BasePath = parser.BasePath; parser.Consume("CIwGxShaderTechnique"); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); shader.Name = parser.ConsumeString(); continue; } if (attribute == "param") { this.ParseParam(parser, shader); continue; } if (attribute == "shader") { parser.Consume(); attribute = parser.Lexem; if (attribute == "vertex") { this.ParseVertexShader(parser, shader); } else if (attribute == "fragment") { this.ParseFragmentShader(parser, shader); } else { parser.UnknownLexemError(); } continue; } parser.UnknownLexemError(); } return shader; }
private void ParseKeyFrame(TextParser parser, Anim mesh) { var frame = this.context.Resolve<AnimKeyFrame>(); parser.Consume("CIwAnimKeyFrame"); parser.Consume("{"); AnimBone bone = null; for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "time") { parser.Consume(); frame.Time = parser.ConsumeFloat(); continue; } if (attribute == "bone") { parser.Consume(); bone = frame.Bones[frame.Bones.EnsureItem(parser.ConsumeString())]; continue; } if (attribute == "pos") { parser.Consume(); bone.BindingPos = parser.ConsumeVector3(); continue; } if (attribute == "rot") { parser.Consume(); bone.BindingRot = parser.ConsumeQuaternion(); continue; } parser.UnknownLexemError(); } mesh.AddFrame(frame); }
public Managed Parse(TextParser parser, string defaultName) { var model = this.context.Resolve<Model>(); model.Name = defaultName; if (parser.Lexem == "CMesh") { model.Meshes.Add(this.ParseMesh(parser)); return model; } parser.Consume("CIwModel"); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); model.Name = parser.ConsumeString(); continue; } if (attribute == "CMesh") { model.Meshes.Add(this.ParseMesh(parser)); continue; } parser.UnknownLexemError(); } return model; }
public Managed Parse(TextParser parser, string defaultName) { Anim mesh = this.context.Resolve<Anim>(); mesh.Name = defaultName; parser.Consume("CIwAnim"); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); mesh.Name = parser.ConsumeString(); continue; } if (attribute == "skeleton") { parser.Consume(); parser.ConsumeResourceReference(mesh.Skeleton); continue; } if (attribute == "CIwAnimKeyFrame") { this.ParseKeyFrame(parser, mesh); continue; } parser.UnknownLexemError(); } return mesh; }
public Managed Parse(TextParser parser, string defaultName) { AnimSkin skin = this.context.Resolve<AnimSkin>(); skin.Name = defaultName; parser.Consume("CIwAnimSkin"); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); skin.Name = parser.ConsumeString(); continue; } if (attribute == "skeleton") { parser.Consume(); parser.ConsumeResourceReference(skin.Skeleton); continue; } if (attribute == "model") { parser.Consume(); parser.ConsumeResourceReference(skin.SkeletonModel); continue; } if (attribute == "CIwAnimSkinSet") { parser.Consume(); ParseAnimSkinSet(parser, skin); continue; } parser.UnknownLexemError(); } return skin; }
private static void ParseBone(TextParser parser, AnimSkel mesh) { parser.Consume("{"); AnimBone bone = null; for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); bone = mesh.Bones[mesh.EnsureBone(parser.ConsumeString())]; continue; } if (attribute == "parent") { parser.Consume(); bone.Parent = mesh.EnsureBone(parser.ConsumeString()); continue; } if (attribute == "pos") { parser.Consume(); bone.BindingPos = parser.ConsumeVector3(); continue; } if (attribute == "rot") { parser.Consume(); bone.BindingRot = parser.ConsumeQuaternion(); continue; } parser.UnknownLexemError(); } }
public Managed Parse(TextParser parser, string defaultName) { var skel = this.context.Resolve<AnimSkel>(); skel.Name = defaultName; parser.Consume("CIwAnimSkel"); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); skel.Name = parser.ConsumeString(); continue; } if (attribute == "numBones") { parser.Consume(); skel.Bones.Capacity = parser.ConsumeInt(); continue; } if (attribute == "CIwAnimBone") { parser.Consume(); ParseBone(parser, skel); continue; } parser.UnknownLexemError(); } return skel; }
private void ParseTris(TextParser parser, ModelBlockPrimBase submesh) { var tmp = new ComplexIndex[3]; for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "numTris") { parser.Consume(); submesh.Indices.Capacity = submesh.Indices.Count + parser.ConsumeInt(); continue; } if (attribute == "t") { parser.Consume(); ParseTriangle(parser, tmp); submesh.Indices.Add(tmp[0]); submesh.Indices.Add(tmp[2]); submesh.Indices.Add(tmp[1]); continue; } parser.UnknownLexemError(); } }
private Surface ParseSurface(TextParser parser, Mesh mesh) { parser.Consume("CSurface"); parser.Consume("{"); var surface = this.context.Resolve<ModelBlockPrimBase>(); surface.Mesh = mesh; for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "material") { parser.Consume(); parser.ConsumeResourceReference(surface.Material); continue; } if (attribute == "CTris") { parser.Consume(); parser.Consume("{"); this.ParseTris(parser, surface); continue; } if (attribute == "CQuads") { parser.Consume(); parser.Consume("{"); this.ParseQuads(parser, surface); continue; } parser.UnknownLexemError(); } return surface; }
private void ParseQuads(TextParser parser, ModelBlockPrimBase submesh) { var tmp = new ComplexIndex[4]; int startIndex = submesh.Indices.Count; for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "numQuads") { parser.Consume(); submesh.Indices.Capacity = startIndex + parser.ConsumeInt() * 2; continue; } if (attribute == "q") { parser.Consume(); ParseQuad(parser, tmp); submesh.Indices.Add(tmp[0]); submesh.Indices.Add(tmp[2]); submesh.Indices.Add(tmp[1]); submesh.Indices.Add(tmp[0]); submesh.Indices.Add(tmp[3]); submesh.Indices.Add(tmp[2]); continue; } parser.UnknownLexemError(); } }
private ModelExtSelSetFace ParseModelExtSelSetFace(TextParser parser, Mesh mesh) { var sel = new ModelExtSelSetFace(); parser.Consume("CIwModelExtSelSetFace"); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); sel.Name = parser.ConsumeString(); continue; } if (attribute == "otzOfs") { parser.Consume(); sel.otzOfs = parser.ConsumeFloat(); continue; } if (attribute == "f") { parser.Consume(); sel.F.Add(parser.ConsumeInt()); continue; } parser.UnknownLexemError(); } return sel; }
private static void ParseVerts(TextParser parser, ListMeshStream<Vector3> vertices) { for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "numVerts") { parser.Consume(); vertices.Capacity = parser.ConsumeInt(); continue; } if (attribute == "v") { parser.Consume(); vertices.Add(parser.ConsumeVector3()); continue; } parser.UnknownLexemError(); } }
private static void ParseAnimSkinSet(TextParser parser, AnimSkin mesh) { List<int> bones = new List<int>(4); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "useBones") { parser.Consume(); parser.Consume("{"); for (;;) { attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } bones.Add(mesh.EnsureBone(parser.ConsumeString())); parser.Skip(","); } continue; } if (attribute == "numVerts") { parser.Consume(); parser.ConsumeInt(); continue; } if (attribute == "vertWeights") { parser.Consume(); ParseVertWeights(parser, bones, mesh); continue; } parser.UnknownLexemError(); } }
private static void ParseVertWeights(TextParser parser, List<int> bones, AnimSkin mesh) { parser.Consume("{"); var bone = parser.ConsumeInt(); mesh.Weights.EnsureAt(bone); parser.Skip(","); VertexWeights w = VertexWeights.Empty; if (bones.Count > 0) { w.Bone0 = new VertexWeight { BoneIndex = bones[0], Weight = parser.ConsumeFloat() }; parser.Skip(","); if (bones.Count > 1) { w.Bone1 = new VertexWeight { BoneIndex = bones[1], Weight = parser.ConsumeFloat() }; parser.Skip(","); if (bones.Count > 2) { w.Bone2 = new VertexWeight { BoneIndex = bones[2], Weight = parser.ConsumeFloat() }; parser.Skip(","); if (bones.Count > 3) { w.Bone3 = new VertexWeight { BoneIndex = bones[3], Weight = parser.ConsumeFloat() }; parser.Skip(","); if (bones.Count > 4) { throw new TextParserException("max 4 bones supported"); } } } } } parser.Consume("}"); }
private void ParseVertexShader(TextParser parser, ShaderTechnique shader) { parser.Consume(); shader.VertexShaderSource = parser.ConsumeBlock(); }
private void ParseParam(TextParser parser, ShaderTechnique shader) { parser.Consume("param"); var paramName = parser.ConsumeString(); var typeName = parser.ConsumeString(); var numArgs = parser.ConsumeInt(); switch (typeName) { case "float": this.ParseFloatParam(parser, shader, paramName, numArgs); break; case "vec3": this.ParseVec3Param(parser, shader, paramName, numArgs); break; default: parser.Error(string.Format(CultureInfo.InvariantCulture, "Unknown param type {0}", typeName)); break; } }
private void ParseFragmentShader(TextParser parser, ShaderTechnique shader) { parser.Consume(); shader.FragmentShaderSource = parser.ConsumeBlock(); }
public Mesh ParseMesh(TextParser parser) { parser.Consume("CMesh"); parser.Consume("{"); var mesh = this.context.Resolve<Mesh>(); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); mesh.Name = parser.ConsumeString(); continue; } if (attribute == "baseName") { parser.Consume(); mesh.BaseName = parser.ConsumeString(); continue; } if (attribute == "useGeo") { parser.Consume(); mesh.UseGeo = parser.ConsumeString(); continue; } if (attribute == "useGroup") { parser.Consume(); mesh.UseGroup = parser.ConsumeString(); continue; } if (attribute == "scale") { parser.Consume(); mesh.Scale = parser.ConsumeFloat(); continue; } if (attribute == "CVerts") { parser.Consume(); parser.Consume("{"); ParseVerts(parser, mesh.Vertices); continue; } if (attribute == "CVertNorms") { parser.Consume(); parser.Consume("{"); ParseVertNorms(parser, mesh.Normals); continue; } if (attribute == "CVertCols") { parser.Consume(); parser.Consume("{"); ParseVertCols(parser, mesh); continue; } if (attribute == "CUVs") { parser.Consume(); parser.Consume("{"); ParseUVs(parser, mesh); continue; } if (attribute == "CSurface") { mesh.Surfaces.Add(this.ParseSurface(parser, mesh)); continue; } if (attribute == "CIwModelExtSelSetFace") { this.ParseModelExtSelSetFace(parser, mesh); continue; } parser.UnknownLexemError(); } mesh.CalculateTangents(); return mesh; }
private static ComplexIndex ParseTrisIndexes(TextParser parser) { parser.Consume("{"); var i = new ComplexIndex(); i.Vertex = parser.ConsumeInt(); parser.Skip(","); if (parser.Lexem == "}") { i.Normal = -1; } else { i.Normal = parser.ConsumeInt(); parser.Skip(","); } if (parser.Lexem == "}") { i.UV0 = -1; } else { i.UV0 = parser.ConsumeInt(); parser.Skip(","); } if (parser.Lexem == "}") { i.UV1 = -1; } else { i.UV1 = parser.ConsumeInt(); parser.Skip(","); } if (parser.Lexem == "}") { i.Color = -1; } else { i.Color = parser.ConsumeInt(); } parser.Consume("}"); return i; }
private static void ParseUVs(TextParser parser, Mesh mesh) { ListMeshStream<Vector2> uvs = null; for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "setID") { parser.Consume(); var setId = parser.ConsumeInt(); if (setId == 0) { uvs = mesh.UV0; } else if (setId == 1) { uvs = mesh.UV1; } else { parser.Error("Only 2 UV streams supported"); } continue; } if (attribute == "numUVs") { parser.Consume(); if (uvs == null) { uvs = mesh.UV0; } uvs.Capacity = parser.ConsumeInt(); continue; } if (attribute == "uv") { parser.Consume(); if (uvs == null) { uvs = mesh.UV0; } uvs.Add(parser.ConsumeVector2()); continue; } parser.UnknownLexemError(); } }
private static void ParseVertCols(TextParser parser, Mesh mesh) { for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "numVertCols") { parser.Consume(); mesh.Colors.Capacity = parser.ConsumeInt(); continue; } if (attribute == "col") { parser.Consume(); mesh.Colors.Add(parser.ConsumeColor()); continue; } parser.UnknownLexemError(); } }
public Managed Parse(TextParser parser, string defaultName) { ResGroup group = new ResGroup(this.context.Resolve<IResourceManager>(), parser.ResourceFile, this.context) { BasePath = parser.BasePath }; group.Name = defaultName; parser.Consume("CIwResGroup"); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); group.Name = parser.ConsumeString(); continue; } if (attribute == "shared") { parser.Consume(); group.IsShared = parser.ConsumeBool(); continue; } if (attribute == "useTemplate") { //TODO: make a template handler parser.Consume(); var ext = parser.ConsumeString(); var name = parser.ConsumeString(); continue; } var relPath = attribute.Replace('/', Path.DirectorySeparatorChar); if (relPath.Length > 2 && relPath[0] == '.' && relPath[1] == Path.DirectorySeparatorChar) { relPath = relPath.Substring(2); } string fullPath; if (relPath[0] == Path.DirectorySeparatorChar) { var searchPath = parser.BasePath; do { var subpath = relPath.Substring(1); fullPath = Path.Combine(searchPath, subpath); if (File.Exists(fullPath)) { ParseFileReference(parser, @group, fullPath); continue; } searchPath = Path.GetDirectoryName(searchPath); } while (!string.IsNullOrEmpty(searchPath)); //fullPath = Path.Combine(searchPath, parser.BasePath); //ParseFileReference(parser, @group, fullPath); //continue; } else { fullPath = Path.Combine(parser.BasePath, relPath); //if (File.Exists(fullPath)) { ParseFileReference(parser, @group, fullPath); continue; } } parser.UnknownLexemError(); } return group; }
//public IList<Material> Load(Stream stream) //{ // IList<Material> materials = new List<Material>(); // using (var source = new StreamReader(stream)) // { // var parser = new TextParser(source, Directory.GetCurrentDirectory()); // materials.Add((Material)this.Parse(parser, TODO)); // } // return materials; //} #region Public Methods and Operators public Managed Parse(TextParser parser, string defaultName) { Material material = this.context.Resolve<Material>(); material.Name = defaultName; material.BasePath = parser.BasePath; parser.Consume("CIwMaterial"); parser.Consume("{"); for (;;) { var attribute = parser.Lexem; if (attribute == "}") { parser.Consume(); break; } if (attribute == "name") { parser.Consume(); material.Name = parser.ConsumeString(); continue; } if (attribute == "celW") { parser.Consume(); this.EnsureAnim(material).CelW = parser.ConsumeByte(); continue; } if (attribute == "celH") { parser.Consume(); this.EnsureAnim(material).CelH = parser.ConsumeByte(); continue; } if (attribute == "celNumU") { parser.Consume(); this.EnsureAnim(material).CelNumU = parser.ConsumeByte(); continue; } if (attribute == "clampUV") { parser.Consume(); material.ClampUV = parser.ConsumeBool(); continue; } if (attribute == "specularPower") { parser.Consume(); material.SpecularPower = parser.ConsumeByte(); continue; } if (attribute == "celNum") { parser.Consume(); this.EnsureAnim(material).CelNum = parser.ConsumeByte(); continue; } if (attribute == "celPeriod") { parser.Consume(); this.EnsureAnim(material).CelPeriod = parser.ConsumeByte(); continue; } if (attribute == "zDepthOfs") { parser.Consume(); material.ZDepthOfs = parser.ConsumeShort(); continue; } if (attribute == "modulateMode") { parser.Consume(); material.ModulateMode = parser.ConsumeEnum<ModulateMode>(); continue; } if (attribute == "alphaMode") { parser.Consume(); material.AlphaMode = parser.ConsumeEnum<AlphaMode>(); continue; } if (attribute == "cullMode") { parser.Consume(); material.CullMode = parser.ConsumeEnum<CullMode>(); continue; } if (attribute == "colAmbient") { parser.Consume(); material.ColAmbient = parser.ConsumeColor(); continue; } if (attribute == "colEmissive") { parser.Consume(); material.ColEmissive = parser.ConsumeColor(); continue; } if (attribute == "colDiffuse") { parser.Consume(); material.ColDiffuse = parser.ConsumeColor(); continue; } if (attribute == "colSpecular") { parser.Consume(); material.ColSpecular = parser.ConsumeColor(); continue; } if (attribute == "noFog") { parser.Consume(); material.NoFog = parser.ConsumeBool(); continue; } if (attribute == "texture0" || attribute == "mapDiffuse") { parser.Consume(); parser.ConsumeResourceReference(material.Texture0, "textures"); continue; } if (attribute == "texture1") { parser.Consume(); parser.ConsumeResourceReference(material.Texture1, "textures"); continue; } if (attribute == "texture2") { parser.Consume(); parser.ConsumeResourceReference(material.Texture2, "textures"); continue; } if (attribute == "texture3") { parser.Consume(); parser.ConsumeResourceReference(material.Texture3, "textures"); continue; } if (attribute == "effectPreset") { parser.Consume(); material.EffectPreset = parser.ConsumeEnum<EffectPreset>(); continue; } if (attribute == "shadeMode") { parser.Consume(); material.ShadeMode = parser.ConsumeEnum<ShadeMode>(); continue; } if (attribute == "blendMode") { parser.Consume(); material.BlendMode = parser.ConsumeEnum<BlendMode>(); continue; } if (attribute == "shaderTechnique") { parser.Consume(); parser.ConsumeResourceReference(material.ShaderTechnique); continue; } if (attribute == "vertexShader") { parser.Consume(); material.VertexShader = parser.ConsumeString(); continue; } parser.UnknownLexemError(); } return material; }