Commit: 9fe8f6e2913bfe498cdedd5472995953f12e3d13
Author: Kévin Dietrich
Date:   Mon May 11 14:28:13 2015 +0200
Branches: openvdb
https://developer.blender.org/rB9fe8f6e2913bfe498cdedd5472995953f12e3d13

Dynamically add sockets to the node based on the grids available in the
file.

===================================================================

M       source/blender/blenkernel/BKE_node.h
M       source/blender/makesrna/intern/rna_nodetree.c
M       source/blender/nodes/CMakeLists.txt
M       source/blender/nodes/shader/nodes/node_shader_openvdb.c
M       source/blender/openvdb/CMakeLists.txt
M       source/blender/openvdb/openvdb_capi.cpp
M       source/blender/openvdb/openvdb_capi.h

===================================================================

diff --git a/source/blender/blenkernel/BKE_node.h 
b/source/blender/blenkernel/BKE_node.h
index b5c2e58..3d2a770 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -811,6 +811,8 @@ void            set_node_shader_lamp_loop(void 
(*lamp_loop_func)(struct ShadeInp
 
 void            ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct 
GPUMaterial *mat, short compatibility);
 
+void            ntreeUpdateOpenVDBNode(struct bNodeTree *ntree, struct bNode 
*node);
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c 
b/source/blender/makesrna/intern/rna_nodetree.c
index 4bfa151..5afb143 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -2969,6 +2969,15 @@ static void rna_CompositorNodeScale_update(Main *bmain, 
Scene *scene, PointerRNA
        rna_Node_update(bmain, scene, ptr);
 }
 
+static void rna_ShaderNodeOpenVDB_update(Main *bmain, Scene *scene, PointerRNA 
*ptr)
+{
+       bNodeTree *ntree = (bNodeTree *)ptr->id.data;
+       bNode *node = (bNode *)ptr->data;
+
+       ntreeUpdateOpenVDBNode(ntree, node);
+       rna_Node_update(bmain, scene, ptr);
+}
+
 #else
 
 static EnumPropertyItem prop_image_layer_items[] = {
@@ -3888,7 +3897,7 @@ static void def_sh_openvdb(StructRNA *srna)
 
        prop = RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
        RNA_def_property_ui_text(prop, "File Path", "Path to the file to use");
-       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+       RNA_def_property_update(prop, NC_NODE | NA_EDITED, 
"rna_ShaderNodeOpenVDB_update");
 
        prop = RNA_def_property(srna, "sampling", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_items(prop, prop_openvdb_sampling);
diff --git a/source/blender/nodes/CMakeLists.txt 
b/source/blender/nodes/CMakeLists.txt
index fc8f4ab..b49501a 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -36,6 +36,7 @@ set(INC
        ../imbuf
        ../makesdna
        ../makesrna
+       ../openvdb
        ../render/extern/include
        ../../../intern/guardedalloc
        ../../../intern/glew-mx
diff --git a/source/blender/nodes/shader/nodes/node_shader_openvdb.c 
b/source/blender/nodes/shader/nodes/node_shader_openvdb.c
index 8552825..a5d368a 100644
--- a/source/blender/nodes/shader/nodes/node_shader_openvdb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_openvdb.c
@@ -27,14 +27,7 @@
 
 #include "../node_shader_util.h"
 
-static bNodeSocketTemplate sh_node_openvdb_out[] = {
-       { SOCK_FLOAT,  0, N_("density"),  0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
-       { SOCK_FLOAT,  0, N_("heat"),     0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
-       { SOCK_FLOAT,  0, N_("flame"),    0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
-       { SOCK_FLOAT,  0, N_("fuel"),     0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
-       { SOCK_VECTOR, 0, N_("velocity"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f },
-       { -1, 0, ""     }
-};
+#include "openvdb_capi.h"
 
 static void node_shader_init_openvdb(bNodeTree *UNUSED(ntree), bNode *node)
 {
@@ -42,13 +35,22 @@ static void node_shader_init_openvdb(bNodeTree 
*UNUSED(ntree), bNode *node)
        node->storage = vdb;
 }
 
+void ntreeUpdateOpenVDBNode(bNodeTree *ntree, bNode *node)
+{
+       NodeShaderOpenVDB *vdb = node->storage;
+
+       if (vdb) {
+               BLI_listbase_clear(&node->outputs);
+               OpenVDB_getNodeSockets(vdb->filename, ntree, node);
+       }
+}
+
 void register_node_type_sh_openvdb(void)
 {
        static bNodeType ntype;
 
        sh_node_type_base(&ntype, SH_NODE_OPENVDB, "OpenVDB Volume", 
NODE_CLASS_INPUT, 0);
        node_type_compatibility(&ntype, NODE_NEW_SHADING);
-       node_type_socket_templates(&ntype, NULL, sh_node_openvdb_out);
        node_type_init(&ntype, node_shader_init_openvdb);
        node_type_storage(&ntype, "NodeShaderOpenVDB", 
node_free_standard_storage, node_copy_standard_storage);
 
diff --git a/source/blender/openvdb/CMakeLists.txt 
b/source/blender/openvdb/CMakeLists.txt
index eb50baa..ca28294 100644
--- a/source/blender/openvdb/CMakeLists.txt
+++ b/source/blender/openvdb/CMakeLists.txt
@@ -29,6 +29,8 @@ set(INC
     ../blenkernel
     ../blenlib
     ../makesdna
+    ../makesrna
+    ../../../intern/guardedalloc
     ../../../intern/smoke/intern
 )
 
diff --git a/source/blender/openvdb/openvdb_capi.cpp 
b/source/blender/openvdb/openvdb_capi.cpp
index be474de..96c827d 100644
--- a/source/blender/openvdb/openvdb_capi.cpp
+++ b/source/blender/openvdb/openvdb_capi.cpp
@@ -25,6 +25,16 @@
 
 #include <openvdb/openvdb.h>
 
+extern "C" {
+#include "DNA_node_types.h"
+
+#include "BKE_node.h"
+
+#include "BLI_listbase.h"
+}
+
+#include "MEM_guardedalloc.h"
+
 #include "openvdb_capi.h"
 #include "openvdb_intern.h"
 #include "openvdb_util.h"
@@ -36,19 +46,34 @@ int OpenVDB_getVersionHex()
     return OPENVDB_LIBRARY_VERSION;
 }
 
-void OpenVDB_getGridInfo(const char *filename)
+void OpenVDB_getNodeSockets(const char *filename, bNodeTree *ntree, bNode 
*node)
 {
        int ret = OPENVDB_NO_ERROR;
+       initialize();
 
        try {
                io::File file(filename);
                file.open();
 
-               for (io::File::NameIterator name_iter = file.beginName();
-                    name_iter != file.endName();
-                    ++name_iter)
-               {
-                       std::cout << name_iter.gridName() << std::endl;
+               GridPtrVecPtr grids = file.getGrids();
+
+               for (size_t i = 0; i < grids->size(); ++i) {
+                       GridBase::ConstPtr grid = (*grids)[i];
+                       int type;
+
+                       if (grid->valueType() == "float") {
+                               type = SOCK_FLOAT;
+                       }
+                       else if (grid->valueType() == "vec3s") {
+                               type = SOCK_VECTOR;
+                       }
+                       else {
+                               continue;
+                       }
+
+                       const char *name = grid->getName().c_str();
+
+                       nodeAddStaticSocket(ntree, node, SOCK_OUT, type, 
PROP_NONE, NULL, name);
                }
        }
        catch (...) {
diff --git a/source/blender/openvdb/openvdb_capi.h 
b/source/blender/openvdb/openvdb_capi.h
index 8e4ae41..0315851 100644
--- a/source/blender/openvdb/openvdb_capi.h
+++ b/source/blender/openvdb/openvdb_capi.h
@@ -30,12 +30,14 @@
 extern "C" {
 #endif
 
+struct bNode;
+struct bNodeTree;
 struct FLUID_3D;
 struct WTURBULENCE;
 
 int OpenVDB_getVersionHex(void);
 
-void OpenVDB_getGridInfo(const char *filename);
+void OpenVDB_getNodeSockets(const char *filename, struct bNodeTree *ntree, 
struct bNode *node);
 
 
 /* This duplicates a few properties from SmokeDomainSettings,

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to