Exemple #1
0
		private IColorSource ParseColorSource(Scene scene, XElement element)
		{
			var texture = element.Element(this.schema.textureName);
			if (texture != null)
			{
				var imageColorSource = new ImageColorSource();
				var texAttr = texture.Attribute(this.schema.textureAttributeName);
				if (texAttr != null)
				{
					var sampler = (from p1 in element.Parent.Parent.Parent.Elements()
					               where p1.Name == this.schema.newparamName && p1.AttributeValue(this.schema.sidName) == texAttr.Value
					               select p1).FirstOrDefault();
					if (sampler != null)
					{
						// texture reference through sampler
						var sampler2D = sampler.Element(this.schema.sampler2DName);
						if (sampler2D != null)
						{
							var sampler2DSource = sampler2D.Element(this.schema.sourceName);
							var surfaceParam = (from p1 in element.Parent.Parent.Parent.Elements()
							                    where
							                    	p1.Name == this.schema.newparamName
							                    	&& p1.AttributeValue(this.schema.sidName) == sampler2DSource.Value
							                    select p1).First();
							var surface = surfaceParam.Element(this.schema.surfaceName);
							var imageId = surface.ElementValue(this.schema.initFromName);
							foreach (var i in scene.Images.Where(i => i.Id == imageId))
							{
								imageColorSource.Image = i;
								break;
							}
						}
					}
					else
					{
						// texture reference through url
						foreach (var i in scene.Images.Where(i => i.Id == texAttr.Value))
						{
							imageColorSource.Image = i;
							break;
						}
					}
				}
				return imageColorSource;
			}
			var color = element.Element(this.schema.colorName);
			if (color != null)
			{
				var solidColorSource = new SolidColorSource { Color = this.ParseColor(color.Value) };

				return solidColorSource;
			}
			return null;
		}
Exemple #2
0
		private IColorSource ParseMap(AseParser parser, Scene scene)
		{
			var image = new FileReferenceImage();
			var texture = new ImageColorSource { Image = image };
			parser.Consume("{");
			for (;;)
			{
				var attr = parser.Consume();
				if (attr == null || attr == "}")
				{
					break;
				}
				if (0 == string.Compare(attr, "*MAP_NAME", StringComparison.InvariantCultureIgnoreCase))
				{
					image.Id = image.Name = parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*MAP_CLASS", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*MAP_SUBNO", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*MAP_AMOUNT", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*BITMAP", StringComparison.InvariantCultureIgnoreCase))
				{
					image.Path = Path.Combine(this.basePath, parser.Consume());
					continue;
				}
				if (0 == string.Compare(attr, "*MAP_TYPE", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.Consume();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_U_OFFSET", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_V_OFFSET", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_U_TILING", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_V_TILING", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_ANGLE", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_BLUR", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_BLUR_OFFSET", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_NOUSE_AMT", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_NOISE_SIZE", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_NOISE_LEVEL", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*UVW_NOISE_PHASE", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.ConsumeFloat();
					continue;
				}
				if (0 == string.Compare(attr, "*BITMAP_FILTER", StringComparison.InvariantCultureIgnoreCase))
				{
					parser.Consume();
					continue;
				}
				parser.UnknownLexemError();
			}
			return texture;
		}