Allow a <parameters> section of a material definition, to pass parameters straight into the effect.

This commit is contained in:
Stuart Buchanan
2012-08-01 21:06:59 +01:00
parent e288549c9e
commit 8b585db238
2 changed files with 13 additions and 0 deletions

View File

@@ -387,6 +387,13 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
if (name)
glyphs[name] = new SGMaterialGlyph(glyph_nodes[i]);
}
// Read parameters entry, which is passed into the effect
if (props->hasChild("parameters")) {
parameters = props->getChild("parameters");
} else {
parameters = new SGPropertyNode();
}
// Read conditions node
const SGPropertyNode *conditionNode = props->getChild("condition");
@@ -481,7 +488,10 @@ void SGMaterial::buildEffectProperties(const SGReaderWriterOptions* options)
ref_ptr<SGMaterialUserData> user = new SGMaterialUserData(this);
SGPropertyNode_ptr propRoot = new SGPropertyNode();
makeChild(propRoot, "inherits-from")->setStringValue(effect);
SGPropertyNode* paramProp = makeChild(propRoot, "parameters");
copyProperties(parameters, paramProp);
SGPropertyNode* materialProp = makeChild(paramProp, "material");
makeChild(materialProp, "ambient")->setValue(SGVec4d(ambient));
makeChild(materialProp, "diffuse")->setValue(SGVec4d(diffuse));

View File

@@ -484,6 +484,9 @@ private:
// Condition, indicating when this material is active
SGSharedPtr<const SGCondition> condition;
// Parameters from the materials file
const SGPropertyNode* parameters;
////////////////////////////////////////////////////////////////////
// Internal constructors and methods.