예제 #1
0
		private void ParseMaterials(AseParser parser, Scene scene)
		{
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MATERIAL_COUNT", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeInt();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL", StringComparison.InvariantCultureIgnoreCase))
				{
					var id = parser.ConsumeInt();
					while (scene.Materials.Count <= id)
					{
						scene.Materials.Add(null);
					}
					scene.Materials[id] = this.ParseMaterial(parser, scene);
					continue;
				}
				parser.UnknownLexemError();
			}
		}
예제 #2
0
		private void ParseScene(AseParser parser, Scene scene)
		{
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*SCENE_FILENAME", StringComparison.InvariantCultureIgnoreCase))
				{
					scene.Id = parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*SCENE_FIRSTFRAME", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeInt();
					continue;
				}
				if (0 == string.Compare(attr, "*SCENE_LASTFRAME", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeInt();
					continue;
				}
				if (0 == string.Compare(attr, "*SCENE_FRAMESPEED", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*SCENE_TICKSPERFRAME", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*SCENE_BACKGROUND_STATIC", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					parser.ConsumeFloat();
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*SCENE_AMBIENT_STATIC", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					parser.ConsumeFloat();
					parser.ConsumeFloat();
					continue;
				}
				parser.UnknownLexemError();
			}
		}
예제 #3
0
		private void ParseFaceList(AseParser parser, IList<AseFace> faces)
		{
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MESH_FACE", StringComparison.InvariantCultureIgnoreCase))
				{
					var index = int.Parse(parser.Consume().TrimEnd(':'), CultureInfo.InvariantCulture);
					parser.Consume("A:");
					var a = parser.ConsumeInt();
					parser.Consume("B:");
					var b = parser.ConsumeInt();
					parser.Consume("C:");
					var c = parser.ConsumeInt();

					parser.Consume("AB:");
					var ab = parser.ConsumeInt();
					parser.Consume("BC:");
					var bc = parser.ConsumeInt();
					parser.Consume("CA:");
					var ca = parser.ConsumeInt();

					faces[index] = new AseFace { A = a, B = b, C = c };

					if (parser.Lexem == "*MESH_SMOOTHING")
					{
						parser.Consume();
						if (parser.Lexem != "*MESH_MTLID")
						{
							parser.ConsumeInt();
						}
					}
					if (parser.Lexem == "*MESH_MTLID")
					{
						parser.Consume();
						parser.ConsumeInt();
					}
					continue;
				}
				parser.UnknownLexemError();
			}
		}
예제 #4
0
		private IMaterial ParseMaterial(AseParser parser, Scene scene)
		{
			var sceneEffect = new SceneEffect() {CullMode = CullMode.Front};
			var m = new SceneMaterial { Effect = sceneEffect };
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MATERIAL_NAME", StringComparison.InvariantCultureIgnoreCase))
				{
					m.Id = m.Name = sceneEffect.Id = sceneEffect.Name = parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_CLASS", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_AMBIENT", StringComparison.InvariantCultureIgnoreCase))
				{
					sceneEffect.Ambient = new SolidColorSource { Color = ParseColor(parser) };
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_DIFFUSE", StringComparison.InvariantCultureIgnoreCase))
				{
					sceneEffect.Diffuse = new SolidColorSource { Color = ParseColor(parser) };
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_SPECULAR", StringComparison.InvariantCultureIgnoreCase))
				{
					sceneEffect.Specular = new SolidColorSource { Color = ParseColor(parser) };
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_SHINE", StringComparison.InvariantCultureIgnoreCase))
				{
					sceneEffect.Shininess = parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_SHINESTRENGTH", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_TRANSPARENCY", StringComparison.InvariantCultureIgnoreCase))
				{
					sceneEffect.Transparency = parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_WIRESIZE", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_XP_FALLOFF", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_SELFILLUM", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_SHADING", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_FALLOFF", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*MATERIAL_XP_TYPE", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.Consume();
					continue;
				}

				if (0 == string.Compare(attr, "*MAP_AMBIENT", StringComparison.InvariantCultureIgnoreCase))
				{
					sceneEffect.Ambient = this.ParseMap(parser, scene);
					continue;
				}
				if (0 == string.Compare(attr, "*MAP_DIFFUSE", StringComparison.InvariantCultureIgnoreCase))
				{
					sceneEffect.Diffuse = this.ParseMap(parser, scene);
					continue;
				}
				if (0 == string.Compare(attr, "*NUMSUBMTLS", StringComparison.InvariantCultureIgnoreCase))
				{
					var numMaterials = parser.ConsumeInt();
					continue;
				}
				if (0 == string.Compare(attr, "*SUBMATERIAL", StringComparison.InvariantCultureIgnoreCase))
				{
					var index = parser.ConsumeInt();
					while (m.Submaterials.Count <= index) m.Submaterials.Add(null);
					var subm = ParseMaterial(parser, scene);
					m.Submaterials[index] = subm;
					continue;
				}
				

				parser.UnknownLexemError();
			}
			return m;
		}
예제 #5
0
		private void Parse3DsMaxSciiExport(AseParser parser, Scene scene)
		{
			parser.ConsumeInt();
		}
예제 #6
0
		private void ParseColList(AseParser parser, IList<Color> colors)
		{
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MESH_VERTCOL", StringComparison.InvariantCultureIgnoreCase))
				{
					var index = parser.ConsumeInt();
					var a = parser.ConsumeFloat();
					var b = parser.ConsumeFloat();
					var c = parser.ConsumeFloat();
					colors[index] = Color.FromArgb(255, this.ClampCol(a), this.ClampCol(b), this.ClampCol(c));
					continue;
				}
				parser.UnknownLexemError();
			}
		}
예제 #7
0
		private void ParsSubMesh(AseParser parser, Scene scene, Node node)
		{
			var mesh = new SeparateStreamsMesh();
			var submesh = mesh.CreateSubmesh();
			node.Mesh = mesh;
			scene.Geometries.Add(mesh);

			ArrayMeshStream<Float3> vertices = null;
			ListMeshStream<Float3> normalStream = null;
			FaceNormal[] normals = null;
			ArrayMeshStream<Float3> tvertices = null;
			ArrayMeshStream<Color> cols = null;
			AseFace[] faces = null;
			AseTFace[] tfaces = null;
			Tuple<int, int, int>[] colFaces = null;
			//TODO: submesh can have it's own vertex streams
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*TIMEVALUE", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMVERTEX", StringComparison.InvariantCultureIgnoreCase))
				{
					vertices = new ArrayMeshStream<Float3>(parser.ConsumeInt(), converterFactory);
					mesh.SetStream(Streams.Position, 0, vertices);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_VERTEX_LIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseVertexList(parser, vertices);
					continue;
				}
				
				if (0 == string.Compare(attr, "*MESH_NUMTVERTEX", StringComparison.InvariantCultureIgnoreCase))
				{
					tvertices = new ArrayMeshStream<Float3>(parser.ConsumeInt(), converterFactory);
					mesh.SetStream(Streams.TexCoord, 0, tvertices);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_TVERTLIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseTVertList(parser, tvertices);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMTVFACES", StringComparison.InvariantCultureIgnoreCase))
				{
					tfaces = new AseTFace[parser.ConsumeInt()];
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_TFACELIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseTFaceList(parser, tfaces);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMCVERTEX", StringComparison.InvariantCultureIgnoreCase))
				{
					cols = new ArrayMeshStream<Color>(parser.ConsumeInt(), converterFactory);
					mesh.SetStream(Streams.Color, 0, cols);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_CVERTLIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseColList(parser, cols);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMCVFACES", StringComparison.InvariantCultureIgnoreCase))
				{
					colFaces = new Tuple<int, int, int>[parser.ConsumeInt()];
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_CFACELIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseColFaceList(parser, colFaces);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NORMALS", StringComparison.InvariantCultureIgnoreCase))
				{
					normals = new FaceNormal[faces.Length];
					this.ParsNormalList(parser, normals);
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_NUMFACES", StringComparison.InvariantCultureIgnoreCase))
				{
					faces = new AseFace[parser.ConsumeInt()];
					continue;
				}

				if (0 == string.Compare(attr, "*MESH_FACE_LIST", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParseFaceList(parser, faces);
					continue;
				}
				parser.UnknownLexemError();
			}
			ListMeshStream<int> positionIndices = null;
			if (vertices != null)
			{
				positionIndices = new ListMeshStream<int>(faces.Length * 3,converterFactory);
				submesh.SetIndexStream(Streams.Position, 0, positionIndices);
			}
			ListMeshStream<int> normalIndices = null;
			if (normals != null)
			{
				normalStream = new ListMeshStream<Float3>(faces.Length * 3, converterFactory);
				mesh.SetStream(Streams.Normal, 0, normalStream);
				normalIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory);
				submesh.SetIndexStream(Streams.Normal, 0, normalIndices);
			}
			ListMeshStream<int> colorIndices = null;
			if (cols != null)
			{
				colorIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory);
				submesh.SetIndexStream(Streams.Color, 0, colorIndices);
			}
			ListMeshStream<int> texCoordIndices = null;
			if (tvertices != null)
			{
				texCoordIndices = new ListMeshStream<int>(faces.Length * 3, converterFactory);
				submesh.SetIndexStream(Streams.TexCoord, 0, texCoordIndices);
			}
			for (int i = 0; i < faces.Length; ++i)
			{
				// -------------------------------------------------- //
				if (positionIndices != null)
				{
					positionIndices.Add(faces[i].A);
				}
				if (normalIndices != null)
				{
					normalIndices.Add(normalStream.Count);
					normalStream.Add(normals[i].A.Normal);
				}
				if (colorIndices != null)
				{
					colorIndices.Add(colFaces[i].Item1);
				}
				if (texCoordIndices != null)
				{
					texCoordIndices.Add(tfaces[i].A);
				}
		
				// -------------------------------------------------- //
				if (positionIndices != null)
				{
					positionIndices.Add(faces[i].C);
				}
				if (normalIndices != null)
				{
					normalIndices.Add(normalStream.Count);
					normalStream.Add(normals[i].C.Normal);
				}
				if (colorIndices != null)
				{
					colorIndices.Add(colFaces[i].Item3);
				}
				if (texCoordIndices != null)
				{
					texCoordIndices.Add(tfaces[i].C);
				}
				// -------------------------------------------------- //
				if (positionIndices != null)
				{
					positionIndices.Add(faces[i].B);
				}
				if (normalIndices != null)
				{
					normalIndices.Add(normalStream.Count);
					normalStream.Add(normals[i].B.Normal);
				}
				if (colorIndices != null)
				{
					colorIndices.Add(colFaces[i].Item2);
				}
				if (texCoordIndices != null)
				{
					texCoordIndices.Add(tfaces[i].B);
				}
				// -------------------------------------------------- //
			}

		}
예제 #8
0
		private void ParseColFaceList(AseParser parser, Tuple<int, int, int>[] colFaces)
		{
			parser.Consume("{");
			for (; ; )
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MESH_CFACE", StringComparison.InvariantCultureIgnoreCase))
				{
					var index = parser.ConsumeInt();
					var a = parser.ConsumeInt();
					var b = parser.ConsumeInt();
					var c = parser.ConsumeInt();
					colFaces[index] = new Tuple<int, int, int>(a,b,c);
					continue;
				}
				parser.UnknownLexemError();
			}
		}
예제 #9
0
		private void ParsSubMesh(AseParser parser, Scene scene, Node node,string attr)
		{
				
				if (0 == string.Compare(attr, "*MESH", StringComparison.InvariantCultureIgnoreCase))
				{
					ParsSubMesh(parser, scene, node);
					return;
				}
				if (0 == string.Compare(attr, "*MESH_ANIMATION", StringComparison.InvariantCultureIgnoreCase))
				{
					this.ParsMeshAnimation(parser, scene, node);
					return;
				}
				if (0 == string.Compare(attr, "*PROP_MOTIONBLUR", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					return;
				}
				if (0 == string.Compare(attr, "*PROP_CASTSHADOW", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeInt();
					return;
				}
				if (0 == string.Compare(attr, "*PROP_RECVSHADOW", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeInt();
					return;
				}
				if (0 == string.Compare(attr, "*MATERIAL_REF", StringComparison.InvariantCultureIgnoreCase))
				{
					var materialId = parser.ConsumeInt();
					if (scene.Materials != null && scene.Materials.Count > 0)
					{
						foreach (var submesh in node.Mesh.Submeshes)
						{
							submesh.Material = scene.Materials[materialId];
						}
					}
					return;
				}
				if (0 == string.Compare(attr, "*TM_ANIMATION", StringComparison.InvariantCultureIgnoreCase))
				{
					this.SkipBlock(parser);
					return;
				}
				if (0 == string.Compare(attr, "*WIREFRAME_COLOR", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					parser.ConsumeFloat();
					parser.ConsumeFloat();
					return;
				}

				parser.UnknownLexemError();
			
		}
예제 #10
0
		private void ParseLight(AseParser parser, Scene scene, Node node, string attr)
		{
			if (0 == string.Compare(attr, "*LIGHT_TYPE", StringComparison.InvariantCultureIgnoreCase))
			{
				parser.Consume();
				return;
			}
			if (0 == string.Compare(attr, "*LIGHT_SHADOWS", StringComparison.InvariantCultureIgnoreCase))
			{
				parser.Consume();
				return;
			}
			if (0 == string.Compare(attr, "*LIGHT_USELIGHT", StringComparison.InvariantCultureIgnoreCase))
			{
				parser.ConsumeInt();
				return;
			}
			if (0 == string.Compare(attr, "*LIGHT_SPOTSHAPE", StringComparison.InvariantCultureIgnoreCase))
			{
				parser.Consume();
				return;
			}
			if (0 == string.Compare(attr, "*LIGHT_USEGLOBAL", StringComparison.InvariantCultureIgnoreCase))
			{
				parser.ConsumeInt();
				return;
			}
			if (0 == string.Compare(attr, "*LIGHT_ABSMAPBIAS", StringComparison.InvariantCultureIgnoreCase))
			{
				parser.ConsumeInt();
				return;
			}
			if (0 == string.Compare(attr, "*LIGHT_OVERSHOOT", StringComparison.InvariantCultureIgnoreCase))
			{
				parser.ConsumeInt();
				return;
			}
			if (0 == string.Compare(attr, "*LIGHT_SETTINGS", StringComparison.InvariantCultureIgnoreCase))
			{
				this.SkipBlock(parser);
				//*TIMEVALUE 0
				//*LIGHT_COLOR 1.0000	1.0000	1.0000
				//*LIGHT_INTENS 1.0000
				//*LIGHT_ASPECT -1.0000
				//*LIGHT_TDIST -1.0000
				//*LIGHT_MAPBIAS 1.0000
				//*LIGHT_MAPRANGE 4.0000
				//*LIGHT_MAPSIZE 512
				//*LIGHT_RAYBIAS 0.0000
				return;
			}

			parser.UnknownLexemError();
		}
예제 #11
0
		private void ParsNormalList(AseParser parser, FaceNormal[] normals)
		{
			int faceIndex = 0;
			int faceVertexIndex = 0;
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MESH_FACENORMAL", StringComparison.InvariantCultureIgnoreCase))
				{
					faceIndex = parser.ConsumeInt();
					var x = parser.ConsumeFloat();
					var y = parser.ConsumeFloat();
					var z = parser.ConsumeFloat();
					normals[faceIndex].A.Normal =
						normals[faceIndex].B.Normal = normals[faceIndex].C.Normal = normals[faceIndex].Normal = new Float3(x, y, z);
					faceVertexIndex = 0;
					continue;
				}
				if (0 == string.Compare(attr, "*MESH_VERTEXNORMAL", StringComparison.InvariantCultureIgnoreCase))
				{
					var index = parser.ConsumeInt();
					var x = parser.ConsumeFloat();
					var y = parser.ConsumeFloat();
					var z = parser.ConsumeFloat();
					Float3 v = new Float3(x, y, z);
					switch (faceVertexIndex)
					{
						case 0:
							normals[faceIndex].A.Index = index;
							normals[faceIndex].A.Normal = v;
							break;
						case 1:
							normals[faceIndex].B.Index = index;
							normals[faceIndex].B.Normal = v;
							break;
						case 2:
							normals[faceIndex].C.Index = index;
							normals[faceIndex].C.Normal = v;
							break;
					}
					++faceVertexIndex;
					continue;
				}
				parser.UnknownLexemError();
			}
		}
예제 #12
0
		private void ParseVertexList(AseParser parser, IList<Float3> vertices)
		{
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MESH_VERTEX", StringComparison.InvariantCultureIgnoreCase))
				{
					var index = parser.ConsumeInt();
					var x = parser.ConsumeFloat();
					var y = parser.ConsumeFloat();
					var z = parser.ConsumeFloat();
					vertices[index] = new Float3(x, y, z);
					continue;
				}
				parser.UnknownLexemError();
			}
		}
예제 #13
0
		private void ParseTFaceList(AseParser parser, IList<AseTFace> faces)
		{
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MESH_TFACE", StringComparison.InvariantCultureIgnoreCase))
				{
					var index = parser.ConsumeInt();
					var a = parser.ConsumeInt();
					var b = parser.ConsumeInt();
					var c = parser.ConsumeInt();
					faces[index] = new AseTFace { A = a, B = b, C = c };
					continue;
				}
				parser.UnknownLexemError();
			}
		}