public MT2(XElement xml) : this() { this.xml = xml; var dblSided = xml.Descendants("DoubleSided").FirstOrDefault(); var castsShads = xml.Descendants("CastsShadows").FirstOrDefault(); var recShads = xml.Descendants("ReceivesShadows").FirstOrDefault(); var fog = xml.Descendants("FogEnabled").FirstOrDefault(); var trans = xml.Descendants("Translucent").FirstOrDefault(); var walk = xml.Descendants("Walkable").FirstOrDefault(); var panic = xml.Descendants("Panickable").FirstOrDefault(); var sit = xml.Descendants("Sitable").FirstOrDefault(); var pick = xml.Descendants("Unpickable").FirstOrDefault(); var needWSVN = xml.Descendants("NeedsWorldSpaceVertexNormal").FirstOrDefault(); var needWEP = xml.Descendants("NeedsWorldEyePos").FirstOrDefault(); var needWVP = xml.Descendants("NeedsWorldVertexPos").FirstOrDefault(); var needWLD = xml.Descendants("NeedsWorldLightDir").FirstOrDefault(); var needLSVN = xml.Descendants("NeedsLightingSpaceVertexNormal").FirstOrDefault(); var needVC = xml.Descendants("NeedsVertexColour").FirstOrDefault(); var needLCM = xml.Descendants("NeedsLocalCubeMap").FirstOrDefault(); var needSOC = xml.Descendants("NeedsSeperateObjectColour").FirstOrDefault(); if (dblSided != null) { bDoubleSided = (dblSided.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (castsShads != null) { bCastsShadows = (castsShads.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (recShads != null) { bReceivesShadows = (recShads.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (fog != null) { bFogEnabled = (fog.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (trans != null) { bTranslucent = (trans.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (walk != null) { bWalkable = (walk.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (panic != null) { bPanickable = (panic.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (sit != null) { bSitable = (sit.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (pick != null) { bUnpickable = (pick.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (needWSVN != null) { bNeedsWorldSpaceVertexNormal = (needWSVN.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (needWEP != null) { bNeedsWorldEyePos = (needWEP.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (needWVP != null) { bNeedsWorldVertexPos = (needWVP.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (needWLD != null) { bNeedsWorldLightDir = (needWLD.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (needLSVN != null) { bNeedsLightingSpaceVertexNormal = (needLSVN.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (needVC != null) { bNeedsVertexColour = (needVC.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (needLCM != null) { bNeedsLocalCubeMap = (needLCM.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } if (needSOC != null) { bNeedsSeperateObjectColour = (needSOC.Attribute("Value").Value.ToLower() == "true" ? Troolean.True : Troolean.False); } var mult = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "Multiplier").FirstOrDefault(); var emml = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "EmissiveLight").FirstOrDefault(); var emmf = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "EmissiveFactor").FirstOrDefault(); var emmc = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "Emissive_Colour").FirstOrDefault(); var refm = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "ReflectionMultiplier").FirstOrDefault(); var fres = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "Fresnel_R0").FirstOrDefault(); var refb = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "ReflectionBluryness").FirstOrDefault(); var alph = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "AlphaCutOff").FirstOrDefault(); if (mult != null) { multiplier = ReadConstant(mult); } if (emml != null) { emissiveLight = ReadConstant(emml); } if (emmf != null) { emissiveFactor = ReadConstant(emmf); } if (emmc != null) { emissiveColour = ReadConstant(emmc); } if (refm != null) { reflectionMultiplier = ReadConstant(refm); } if (fres != null) { fresnelR0 = ReadConstant(fres); } if (refb != null) { reflectionBluryness = ReadConstant(refb); } if (alph != null) { alphaCutOff = ReadConstant(alph); } var vegetation = xml.Descendants("VegetationAnimation").FirstOrDefault(); if (vegetation != null) { vegetationAnimation = VegetationAnimation.CreateFromElement(vegetation); } foreach (var textureCoordSource in xml.Descendants("TextureCoordSource")) { textureCoordSources.Add(TextureCoordSource.CreateFromElement(textureCoordSource)); } foreach (var sampler in xml.Descendants("Sampler")) { samplers.Add(Sampler.CreateFromElement(sampler)); } // Rotator2D var sub = xml.Descendants("Substance").FirstOrDefault(); if (sub != null) { substance = sub.Attribute("Name").Value; } }
private void setUIFromObject(MT2 m) { foreach (var property in m.GetType().GetProperties()) { if (property.CanRead) { object[] attributes = property.GetCustomAttributes(true); bool bRequired = attributes.Any(a => a.GetType() == typeof(Required)); switch (property.PropertyType.ToString().Split('.').Last()) { case "Vector3": break; case "Single": NumericUpDown nud = (this.Controls.Find("nud" + property.Name, true).FirstOrDefault() as NumericUpDown); if (nud == null) { nud = (NumericUpDown)controlWithTag(property.Name, this).First(); } nud.Value = (Decimal)(Single)property.GetValue(m, null); break; case "Troolean": { CheckBox chk = (this.Controls.Find("chk" + property.Name, true).FirstOrDefault() as CheckBox); if (chk == null) { chk = chkNoSortAlpha; } Troolean value = (Troolean)property.GetValue(m, null); if (value != Troolean.Unset) { chk.Checked = (value == Troolean.True); } } break; case "String": { TextBox txt = (this.Controls.Find("txt" + property.Name, true).FirstOrDefault() as TextBox); if (txt == null) { txt = (TextBox)controlWithTag(property.Name, this).FirstOrDefault(); } if (txt == null) { Console.WriteLine("Couldn't find txt{0}", property.Name); continue; } txt.Text = (string)property.GetValue(m, null); setTextBoxState(txt); } break; default: Console.WriteLine("[{2}] {0} = {1}", property.Name, property.GetValue(m, null), property.PropertyType.ToString()); break; } } } }