public void CheckMetals() { if (_autoMetal) { if (MessageBox.Show(null, "Are you sure you want to turn this on?\nAny existing metal materials will be modified.", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (_children == null) Populate(); for (int x = 0; x < _matList.Count; x++) { MDL0MaterialNode n = (MDL0MaterialNode)_matList[x]; if (!n.isMetal) { if (n.MetalMaterial == null) { MDL0MaterialNode node = new MDL0MaterialNode(); _matGroup.AddChild(node); node._updating = true; node.Name = n.Name + "_ExtMtl"; node._ssc = 4; node.New = true; for (int i = 0; i <= n.Children.Count; i++) { MDL0MaterialRefNode mr = new MDL0MaterialRefNode(); node.AddChild(mr); mr.Texture = "metal00"; mr._index1 = mr._index2 = i; mr.SignalPropertyChange(); if (i == n.Children.Count || ((MDL0MaterialRefNode)n.Children[i]).HasTextureMatrix) { mr._minFltr = 5; mr._magFltr = 1; mr._lodBias = -2; mr.HasTextureMatrix = true; node.Rebuild(true); mr._projection = (int)TexProjection.STQ; mr._inputForm = (int)TexInputForm.ABC1; mr._texGenType = (int)TexTexgenType.Regular; mr._sourceRow = (int)TexSourceRow.Normals; mr._embossSource = 4; mr._embossLight = 2; mr.Normalize = true; mr.MapMode = (MDL0MaterialRefNode.MappingMethod)1; mr.getTexMtxVal(); break; } } node._chan1 = new LightChannel(63, new RGBAPixel(128, 128, 128, 255), new RGBAPixel(255, 255, 255, 255), 0, 0, node); node.C1ColorEnabled = true; node.C1ColorDiffuseFunction = GXDiffuseFn.Clamped; node.C1ColorAttenuation = GXAttnFn.Spotlight; node.C1AlphaEnabled = true; node.C1AlphaDiffuseFunction = GXDiffuseFn.Clamped; node.C1AlphaAttenuation = GXAttnFn.Spotlight; node._chan2 = new LightChannel(63, new RGBAPixel(255, 255, 255, 255), new RGBAPixel(), 0, 0, node); node.C2ColorEnabled = true; node.C2ColorDiffuseFunction = GXDiffuseFn.Disabled; node.C2ColorAttenuation = GXAttnFn.Specular; node.C2AlphaDiffuseFunction = GXDiffuseFn.Disabled; node.C2AlphaAttenuation = GXAttnFn.Specular; node._lSet = n._lSet; node._fSet = n._fSet; node._cull = n._cull; node._numLights = 2; node.ZCompareLoc = false; node._normMapRefLight1 = node._normMapRefLight2 = node._normMapRefLight3 = node._normMapRefLight4 = -1; node.SignalPropertyChange(); } } } foreach (MDL0MaterialNode node in _matList) { if (!node.isMetal) continue; if (node.ShaderNode != null) { if (node.ShaderNode._autoMetal && node.ShaderNode.texCount == node.Children.Count) { node._updating = false; continue; } else { if (node.ShaderNode._stages == 4) { foreach (MDL0MaterialNode y in node.ShaderNode._materials) if (!y.isMetal || y.Children.Count != node.Children.Count) goto Next; node.ShaderNode.DefaultAsMetal(node.Children.Count); continue; } } } Next: bool found = false; foreach (MDL0ShaderNode s in _shadGroup.Children) { if (s._autoMetal && s.texCount == node.Children.Count) { node.ShaderNode = s; found = true; } else { if (s._stages == 4) { foreach (MDL0MaterialNode y in s._materials) if (!y.isMetal || y.Children.Count != node.Children.Count) goto NotFound; node.ShaderNode = s; found = true; goto End; NotFound: continue; } } } End: if (!found) { MDL0ShaderNode shader = new MDL0ShaderNode(); _shadGroup.AddChild(shader); shader.DefaultAsMetal(node.Children.Count); node.ShaderNode = shader; } } foreach (MDL0MaterialNode m in _matList) m._updating = false; } else _autoMetal = false; } }
public void NewMaterial() { if (_modelViewerOpen) return; MDL0Node model = ((MDL0Node)_resource); if (model._matGroup == null) { MDL0GroupNode g = model._matGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Materials), true); model._matGroup = g; model._matList = g.Children; } } MDL0MaterialNode mat = new MDL0MaterialNode(); model._matGroup.AddChild(mat); mat.Name = "Material" + mat.Index; mat.New = true; if (model._shadGroup == null) { MDL0GroupNode g = model._shadGroup; if (g == null) { model.AddChild(g = new MDL0GroupNode(MDLResourceType.Shaders), true); model._shadGroup = g; model._shadList = g.Children; } } if (model._shadList.Count == 0) NewShader(); mat.ShaderNode = (MDL0ShaderNode)model._shadList[0]; mat.AddChild(new MDL0MaterialRefNode() { Name = "MatRef0" }); mat.Rebuild(true); BaseWrapper b = FindResource(mat, true); if (b != null) b.EnsureVisible(); }