public MdfRenderMaterial(int id, string name, MdfMaterial mdfMaterial, Material material) { mId = id; mName = name; mDeviceMaterial = material.Ref(); mSpec = mdfMaterial; }
private MdfMaterial ParseClipper() { var result = new MdfMaterial(MdfType.Clipper); result.enableZWrite = false; result.enableColorWrite = false; var tokenizer = new Tokenizer(mContent); tokenizer.NextToken(); // Skip material type while (tokenizer.NextToken()) { if (tokenizer.IsNamedIdentifier("wire")) { result.wireframe = true; result.enableColorWrite = true; } else if (tokenizer.IsNamedIdentifier("zfill")) { result.enableZWrite = true; } else if (tokenizer.IsNamedIdentifier("outline")) { result.outline = true; result.enableColorWrite = true; } else { if (mStrict) { throw CreateError("Unrecognized token '{0}'", tokenizer.TokenText.ToString()); } } } return(result); }
private MdfMaterial ParseGeneral() { var result = new MdfMaterial(MdfType.General); var tokenizer = new Tokenizer(mContent); tokenizer.NextToken(); // Skip material type while (tokenizer.NextToken()) { if (!tokenizer.IsIdentifier) { if (mStrict) { throw CreateError("Unexpected token: {0}", tokenizer.TokenText.ToString()); } continue; } if (tokenizer.IsNamedIdentifier("highquality")) { // In no case is the GPU the bottleneck anymore, // so we will always parse the high quality section // Previously, it did cancel here if the GPU supported // less than 4 textures continue; } if (tokenizer.IsNamedIdentifier("texture")) { if (!ParseTextureStageId(ref tokenizer)) { continue; } var samplerNo = tokenizer.TokenInt; if (ParseFilename(ref tokenizer, "Texture")) { result.samplers[samplerNo].filename = tokenizer.TokenText.ToString(); } continue; } if (tokenizer.IsNamedIdentifier("glossmap")) { if (ParseFilename(ref tokenizer, "GlossMap")) { result.glossmap = tokenizer.TokenText.ToString(); } continue; } if (tokenizer.IsNamedIdentifier("uvtype")) { if (!ParseTextureStageId(ref tokenizer)) { continue; } var samplerNo = tokenizer.TokenInt; if (!ParseIdentifier(ref tokenizer, "UvType")) { continue; } MdfUvType uvType; if (tokenizer.IsNamedIdentifier("mesh")) { uvType = MdfUvType.Mesh; } else if (tokenizer.IsNamedIdentifier("environment")) { uvType = MdfUvType.Environment; } else if (tokenizer.IsNamedIdentifier("drift")) { uvType = MdfUvType.Drift; } else if (tokenizer.IsNamedIdentifier("swirl")) { uvType = MdfUvType.Swirl; } else if (tokenizer.IsNamedIdentifier("wavey")) { uvType = MdfUvType.Wavey; } else { if (mStrict) { throw CreateError("Unrecognized UvType: {0}", tokenizer.TokenText.ToString()); } continue; } result.samplers[samplerNo].uvType = uvType; continue; } if (tokenizer.IsNamedIdentifier("blendtype")) { if (!ParseTextureStageId(ref tokenizer)) { continue; } var samplerNo = tokenizer.TokenInt; if (!ParseIdentifier(ref tokenizer, "BlendType")) { continue; } MdfTextureBlendType blendType; if (tokenizer.IsNamedIdentifier("modulate")) { blendType = MdfTextureBlendType.Modulate; } else if (tokenizer.IsNamedIdentifier("add")) { blendType = MdfTextureBlendType.Add; } else if (tokenizer.IsNamedIdentifier("texturealpha")) { blendType = MdfTextureBlendType.TextureAlpha; } else if (tokenizer.IsNamedIdentifier("currentalpha")) { blendType = MdfTextureBlendType.CurrentAlpha; } else if (tokenizer.IsNamedIdentifier("currentalphaadd")) { blendType = MdfTextureBlendType.CurrentAlphaAdd; } else { if (mStrict) { throw CreateError("Unrecognized BlendType: {0}", tokenizer.TokenText.ToString()); } continue; } result.samplers[samplerNo].blendType = blendType; continue; } if (tokenizer.IsNamedIdentifier("color")) { uint argbColor; if (ParseRgba(ref tokenizer, "Color", out argbColor)) { result.diffuse = argbColor; } continue; } if (tokenizer.IsNamedIdentifier("specular")) { uint argbColor; if (ParseRgba(ref tokenizer, "Specular", out argbColor)) { result.specular = argbColor; } continue; } if (tokenizer.IsNamedIdentifier("specularpower")) { if (!tokenizer.NextToken()) { if (mStrict) { throw CreateError("Unexpected end of file after SpecularPower"); } } else if (!tokenizer.IsNumber) { if (mStrict) { throw CreateError("Expected number after SpecularPower, but got: {0}", tokenizer.TokenText.ToString()); } } else { result.specularPower = tokenizer.TokenFloat; } continue; } if (tokenizer.IsNamedIdentifier("materialblendtype")) { if (!ParseIdentifier(ref tokenizer, "MaterialBlendType")) { continue; } if (tokenizer.IsNamedIdentifier("none")) { result.blendType = MdfBlendType.None; } else if (tokenizer.IsNamedIdentifier("alpha")) { result.blendType = MdfBlendType.Alpha; } else if (tokenizer.IsNamedIdentifier("add")) { result.blendType = MdfBlendType.Add; } else if (tokenizer.IsNamedIdentifier("alphaadd")) { result.blendType = MdfBlendType.AlphaAdd; } else { if (mStrict) { throw CreateError("Unrecognized MaterialBlendType: {0}", tokenizer.TokenText.ToString()); } } continue; } if (tokenizer.IsNamedIdentifier("speed")) { if (!ParseNumber(ref tokenizer, "Speed")) { continue; } var speed = tokenizer.TokenFloat * 60.0f; // Set the speed for all texture stages and for both U and V foreach (var sampler in result.samplers) { sampler.speedU = speed; sampler.speedV = speed; } continue; } if (tokenizer.IsNamedIdentifier("speedu")) { if (!ParseTextureStageId(ref tokenizer)) { continue; } var samplerNo = tokenizer.TokenInt; if (!ParseNumber(ref tokenizer, "SpeedU")) { continue; } var speed = tokenizer.TokenFloat * 60.0f; result.samplers[samplerNo].speedU = speed; continue; } if (tokenizer.IsNamedIdentifier("speedv")) { if (!ParseTextureStageId(ref tokenizer)) { continue; } var samplerNo = tokenizer.TokenInt; if (!ParseNumber(ref tokenizer, "SpeedV")) { continue; } var speed = tokenizer.TokenFloat * 60.0f; result.samplers[samplerNo].speedV = speed; continue; } if (tokenizer.IsNamedIdentifier("double")) { result.faceCulling = false; continue; } if (tokenizer.IsNamedIdentifier("linearfiltering")) { result.linearFiltering = true; continue; } if (tokenizer.IsNamedIdentifier("recalculatenormals")) { result.recalculateNormals = true; continue; } if (tokenizer.IsNamedIdentifier("zfillonly")) { result.enableColorWrite = false; result.enableZWrite = true; continue; } if (tokenizer.IsNamedIdentifier("colorfillonly")) { result.enableColorWrite = true; result.enableZWrite = false; continue; } if (tokenizer.IsNamedIdentifier("notlit")) { result.notLit = true; continue; } if (tokenizer.IsNamedIdentifier("disablez")) { result.disableZ = true; continue; } if (mStrict) { throw CreateError("Unrecognized token: {0}", tokenizer.TokenText.ToString()); } } return(result); }
private MdfMaterial ParseTextured() { var result = new MdfMaterial(MdfType.Textured); var tokenizer = new Tokenizer(mContent); /* * For some reason ToEE doesn't use the tokenizer for this * shader type normally. So we disable escape sequences to * get some form of compatibility. */ tokenizer.IsEnableEscapes = false; tokenizer.NextToken(); // Skip material type while (tokenizer.NextToken()) { if (tokenizer.IsNamedIdentifier("color")) { if (!ParseRgba(ref tokenizer, "Color", out result.diffuse)) { throw CreateError("Unable to parse diffuse color"); } } else if (tokenizer.IsNamedIdentifier("texture")) { if (!tokenizer.NextToken() || !tokenizer.IsQuotedString) { throw CreateError("Missing filename for texture"); } result.samplers[0].filename = tokenizer.TokenText.ToString(); } else if (tokenizer.IsNamedIdentifier("colorfillonly")) { result.enableZWrite = false; result.enableColorWrite = true; } else if (tokenizer.IsNamedIdentifier("notlit")) { result.notLit = true; } else if (tokenizer.IsNamedIdentifier("notlite")) { // The original ToEE parser only does prefix parsing, which is why // "notlite" was accepted as "notlit". result.notLit = true; } else if (tokenizer.IsNamedIdentifier("disablez")) { result.disableZ = true; } else if (tokenizer.IsNamedIdentifier("double")) { result.faceCulling = false; } else if (tokenizer.IsNamedIdentifier("clamp")) { result.clamp = true; } else { if (mStrict) { throw CreateError("Unrecognized token '{0}'", tokenizer.TokenText.ToString()); } } } return(result); }