]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/mat.cxx
Merge branch 'zan/stencil'
[simgear.git] / simgear / scene / material / mat.cxx
index 63b8aebd06239632a1266d9acc1a5b67f31516b8..2fc7e9c84c3573c09a958419fbff39ca08e21c5a 100644 (file)
@@ -41,7 +41,7 @@
 #include <osg/StateSet>
 #include <osg/TexEnv>
 #include <osg/Texture2D>
-#include <osgDB/Options>
+#include <osgDB/ReaderWriter>
 #include <osgDB/ReadFile>
 #include <osgDB/Registry>
 #include <osgDB/FileUtils>
@@ -68,12 +68,12 @@ using namespace simgear;
 ////////////////////////////////////////////////////////////////////////
 
 SGMaterial::_internal_state::_internal_state(Effect *e, const string &t, bool l,
-                                             const osgDB::Options* o ) :
+                                             const osgDB::ReaderWriter::Options* o ) :
   effect(e), texture_path(t), effect_realized(l), options(o)
 {
 }
 
-SGMaterial::SGMaterial( const osgDB::Options* options,
+SGMaterial::SGMaterial( const osgDB::ReaderWriter::Options* options,
                         const SGPropertyNode *props )
 {
     init();
@@ -91,7 +91,7 @@ SGMaterial::~SGMaterial (void)
 ////////////////////////////////////////////////////////////////////////
 
 void
-SGMaterial::read_properties(const osgDB::Options* options,
+SGMaterial::read_properties(const osgDB::ReaderWriter::Options* options,
                             const SGPropertyNode *props)
 {
                                // Gather the path(s) to the texture(s)
@@ -104,14 +104,11 @@ SGMaterial::read_properties(const osgDB::Options* options,
     }
     SGPath tpath("Textures.high");
     tpath.append(tname);
-    osgDB::Registry* reg = osgDB::Registry::instance();
-    string fullTexPath = reg->findDataFile(tpath.str(), options,
-                                           osgDB::CASE_SENSITIVE);
+    string fullTexPath = osgDB::findDataFile(tpath.str(), options);
     if (fullTexPath.empty()) {
       tpath = SGPath("Textures");
       tpath.append(tname);
-      fullTexPath = reg->findDataFile(tpath.str(), options,
-                                      osgDB::CASE_SENSITIVE);
+      fullTexPath = osgDB::findDataFile(tpath.str(), options);
     }
 
     if (!fullTexPath.empty() ) {
@@ -134,16 +131,18 @@ SGMaterial::read_properties(const osgDB::Options* options,
   wrapv = props->getBoolValue("wrapv", true);
   mipmap = props->getBoolValue("mipmap", true);
   light_coverage = props->getDoubleValue("light-coverage", 0.0);
-  tree_coverage = props->getDoubleValue("tree-coverage", 0.0);
+  wood_coverage = props->getDoubleValue("wood-coverage", 0.0);
+  wood_size = props->getDoubleValue("wood-size", 0.0);
+  tree_density = props->getDoubleValue("tree-density", 1.0);
   tree_height = props->getDoubleValue("tree-height-m", 0.0);
   tree_width = props->getDoubleValue("tree-width-m", 0.0);
   tree_range = props->getDoubleValue("tree-range-m", 0.0);
   tree_varieties = props->getIntValue("tree-varieties", 1);
+
   const SGPropertyNode* treeTexNode = props->getChild("tree-texture");
   if (treeTexNode) {
     string treeTexPath = props->getStringValue("tree-texture");
-    tree_texture = osgDB::Registry::instance()
-      ->findDataFile(treeTexPath, options, osgDB::CASE_SENSITIVE);
+    tree_texture = osgDB::findDataFile(treeTexPath, options);
   }
 
   // surface values for use with ground reactions
@@ -246,9 +245,11 @@ Effect* SGMaterial::get_effect(int n)
     return _status[i].effect.get();
 }
 
-void SGMaterial::buildEffectProperties(const osgDB::Options* options)
+void SGMaterial::buildEffectProperties(const osgDB::ReaderWriter::Options*
+                                       options)
 {
     using namespace osg;
+    ref_ptr<SGMaterialUserData> user = new SGMaterialUserData(this);
     SGPropertyNode_ptr propRoot = new SGPropertyNode();
     makeChild(propRoot, "inherits-from")->setStringValue(effect);
     SGPropertyNode* paramProp = makeChild(propRoot, "parameters");
@@ -271,15 +272,15 @@ void SGMaterial::buildEffectProperties(const osgDB::Options* options)
         copyProperties(propRoot, effectProp);
         SGPropertyNode* effectParamProp = effectProp->getChild("parameters", 0);
         SGPropertyNode* texProp = makeChild(effectParamProp, "texture");
-        SGPropertyNode* tex2dProp = makeChild(texProp, "texture2d");
-        makeChild(tex2dProp, "image")->setStringValue(matState.texture_path);
-        makeChild(tex2dProp, "filter")
+        makeChild(texProp, "image")->setStringValue(matState.texture_path);
+        makeChild(texProp, "filter")
             ->setStringValue(mipmap ? "linear-mipmap-linear" : "nearest");
-        makeChild(tex2dProp, "wrap-s")
+        makeChild(texProp, "wrap-s")
             ->setStringValue(wrapu ? "repeat" : "clamp");
-        makeChild(tex2dProp, "wrap-t")
+        makeChild(texProp, "wrap-t")
             ->setStringValue(wrapv ? "repeat" : "clamp");
         matState.effect = makeEffect(effectProp, false, options);
+        matState.effect->setUserData(user.get());
     }
 }