[Bf-blender-cvs] [cc1d9c3] openvdb: Move Volume class definition to volume.h, also move some properties from the VolumeManager there, added some more code to handle attributes.
Kévin Dietrich
noreply at git.blender.org
Sun Nov 13 21:44:09 CET 2016
Commit: cc1d9c34935fb3780eb4e926a37a37acfa41509b
Author: Kévin Dietrich
Date: Sun Feb 21 07:39:25 2016 +0100
Branches: openvdb
https://developer.blender.org/rBcc1d9c34935fb3780eb4e926a37a37acfa41509b
Move Volume class definition to volume.h, also move some properties from
the VolumeManager there, added some more code to handle attributes.
===================================================================
M intern/cycles/blender/CMakeLists.txt
M intern/cycles/blender/blender_object.cpp
M intern/cycles/blender/blender_sync.h
M intern/cycles/blender/blender_volume.cpp
M intern/cycles/render/volume.cpp
M intern/cycles/render/volume.h
M source/blender/makesrna/intern/makesrna.c
===================================================================
diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt
index a8cc490..48393db 100644
--- a/intern/cycles/blender/CMakeLists.txt
+++ b/intern/cycles/blender/CMakeLists.txt
@@ -32,6 +32,7 @@ set(SRC
blender_shader.cpp
blender_sync.cpp
blender_texture.cpp
+ blender_volume.cpp
CCL_api.h
blender_sync.h
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index afdabb6..42def9c 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -380,8 +380,9 @@ Object *BlenderSync::sync_object(BL::Object& b_parent,
if(object_has_sparse_volume(b_ob)) {
//object->mesh = NULL;
printf("object has sparse volume\n");
+ sync_volume(b_ob);
}
- /*else*/ {
+ else {
/* mesh sync */
object->mesh = sync_mesh(b_ob, object_updated, hide_tris);
}
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index 5f726e5..b25f31e 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -45,6 +45,7 @@ class Scene;
class Shader;
class ShaderGraph;
class ShaderNode;
+class Volume;
class BlenderSync {
public:
@@ -114,7 +115,7 @@ private:
BL::Object& b_ob,
bool motion,
int time_index = 0);
- void sync_volume(BL::Object& b_ob);
+ Volume *sync_volume(BL::Object& b_ob);
Object *sync_object(BL::Object& b_parent,
int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
BL::DupliObject& b_dupli_ob,
diff --git a/intern/cycles/blender/blender_volume.cpp b/intern/cycles/blender/blender_volume.cpp
index 0b5e905..889906e 100644
--- a/intern/cycles/blender/blender_volume.cpp
+++ b/intern/cycles/blender/blender_volume.cpp
@@ -16,16 +16,14 @@
#include "blender_sync.h"
+#include "attribute.h"
#include "../render/volume.h"
+#include "util_foreach.h"
+
#include <openvdb/openvdb.h>
-class Volume {
-public:
- vector<uint> used_shaders;
- AttributeSet attributes;
- string name;
-};
+CCL_NAMESPACE_BEGIN
static Attribute *get_openvdb_attribute(Volume *volume, const string& filename, const ustring& name)
{
@@ -38,7 +36,6 @@ static Attribute *get_openvdb_attribute(Volume *volume, const string& filename,
openvdb::GridBase::ConstPtr grid = file.readGrid(name.string());
- openvdb::Name name = grid->getName();
openvdb::Name value_type = grid->valueType();
if(value_type == "float") {
@@ -53,19 +50,23 @@ static Attribute *get_openvdb_attribute(Volume *volume, const string& filename,
}
}
+ fprintf(stderr, "Adding volume attribute: %s\n", name.string().c_str());
+
return attr;
}
-static void create_mesh_volume_attribute(BL::Object& b_ob,
- Volume *volume,
- VolumeManager *volume_manager,
- const ustring &name,
- float frame)
+static void create_volume_attribute(BL::Object& b_ob,
+ Volume *volume,
+ VolumeManager *volume_manager,
+ const ustring& name,
+ float /*frame*/)
{
BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
- if(!b_domain)
+ if(!b_domain) {
+ fprintf(stderr, "No domain found!\n");
return;
+ }
char filename[1024];
SmokeDomainSettings_cache_filename_get(&b_domain.ptr, filename);
@@ -75,7 +76,7 @@ static void create_mesh_volume_attribute(BL::Object& b_ob,
// TODO(kevin): add volume fields to the Volume*
// volume_data->manager = volume_manager;
- volume_data->slot = volume_manager->add_volume(filename, name, 0, 0);
+ volume_data->slot = volume_manager->add_volume(volume, filename, name.string());
}
static void create_volume_attributes(Scene *scene,
@@ -85,23 +86,47 @@ static void create_volume_attributes(Scene *scene,
{
foreach(uint id, volume->used_shaders) {
Shader *shader = scene->shaders[id];
+ fprintf(stderr, "Number of attribute requests: %lu\n", shader->attributes.requests.size());
- foreach(AttributeRequest attribute, shader->attributes.requests) {
- if (attribute.name == "") {
+ foreach(AttributeRequest req, shader->attributes.requests) {
+ ustring name;
+
+ if (req.std == ATTR_STD_VOLUME_DENSITY) {
+ name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_DENSITY));
+ }
+ else if (req.std == ATTR_STD_VOLUME_FLAME) {
+ name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_FLAME));
+ }
+ else if (req.std == ATTR_STD_VOLUME_COLOR) {
+ name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_COLOR));
+ }
+ else if (req.std == ATTR_STD_VOLUME_VELOCITY) {
+ name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY));
+ }
+ else if (req.std == ATTR_STD_VOLUME_HEAT) {
+ name = ustring(Attribute::standard_name(ATTR_STD_VOLUME_HEAT));
+ }
+ else if (req.name != "") {
+ name = req.name;
+ }
+ else {
continue;
}
- create_volume_attribute(b_ob, volume, scene->volume_manager, attribute.name, frame);
+ create_volume_attribute(b_ob, volume, scene->volume_manager, name, frame);
}
}
}
-void BlenderSync::sync_volume(BL::Object &b_ob)
+Volume *BlenderSync::sync_volume(BL::Object &b_ob)
{
BL::Material material_override = render_layer.material_override;
/* find shader indices */
vector<uint> used_shaders;
+ BL::ID b_ob_data = b_ob.data();
+
+ fprintf(stderr, "%s: before material assignment\n", __func__);
BL::Object::material_slots_iterator slot;
for(b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
@@ -121,9 +146,17 @@ void BlenderSync::sync_volume(BL::Object &b_ob)
used_shaders.push_back(scene->default_volume);
}
- Volume *volume;
+ fprintf(stderr, "%s: after material assignment\n", __func__);
+
+ Volume *volume = new Volume;
volume->used_shaders = used_shaders;
volume->name = ustring(b_ob_data.name().c_str());
+ fprintf(stderr, "Number of shaders: %lu\n", volume->used_shaders.size());
+
create_volume_attributes(scene, b_ob, volume, b_scene.frame_current());
+
+ return volume;
}
+
+CCL_NAMESPACE_END
diff --git a/intern/cycles/render/volume.cpp b/intern/cycles/render/volume.cpp
index 6f92c11..945e9b3 100644
--- a/intern/cycles/render/volume.cpp
+++ b/intern/cycles/render/volume.cpp
@@ -14,8 +14,10 @@
* limitations under the License.
*/
-#include "volume.h"
#include "scene.h"
+#include "volume.h"
+
+#include "util_foreach.h"
#include "util_logging.h"
#include "util_progress.h"
#include "util_task.h"
@@ -37,11 +39,13 @@ VolumeManager::VolumeManager()
#endif
need_update = true;
+ num_float_volume = 0;
+ num_float3_volume = 0;
}
VolumeManager::~VolumeManager()
{
-#ifdef WITH_OPENVDB
+#if 0
for(size_t i = 0; i < float_volumes.size(); ++i) {
delete float_volumes[i];
}
@@ -49,11 +53,30 @@ VolumeManager::~VolumeManager()
for(size_t i = 0; i < float3_volumes.size(); ++i) {
delete float3_volumes[i];
}
+#endif
+
+ for (size_t i = 0; i < volumes.size(); ++i) {
+ Volume *volume = volumes[i];
+
+ for(size_t i = 0; i < volume->float_fields.size(); ++i) {
+ delete volume->float_fields[i];
+ }
+
+ for(size_t i = 0; i < volume->float3_fields.size(); ++i) {
+ delete volume->float3_fields[i];
+ }
+
+#ifdef WITH_OPENVDB
+ volume->scalar_grids.clear();
+ volume->vector_grids.clear();
+#endif
+ }
+#ifdef WITH_OPENVDB
scalar_grids.clear();
vector_grids.clear();
- current_grids.clear();
#endif
+ current_grids.clear();
}
static inline void catch_exceptions()
@@ -94,6 +117,38 @@ int VolumeManager::add_volume(const string& filename, const string& name, int sa
return slot;
}
+int VolumeManager::add_volume(Volume *volume, const std::string &filename, const std::string &name)
+{
+ size_t slot = -1;
+
+ if((slot = find_existing_slot(volume, filename, name)) != -1) {
+ return slot;
+ }
+
+ if((num_float_volume + num_float3_volume + 1) > MAX_VOLUME) {
+ printf("VolumeManager::add_volume: volume limit reached %d!\n", MAX_VOLUME);
+ return -1;
+ }
+
+ try {
+ if(is_openvdb_file(filename)) {
+ slot = add_openvdb_volume(volume, filename, name);
+ }
+
+ add_grid_description(volume, filename, name, slot);
+
+ volumes.push_back(volume);
+ need_update = true;
+ }
+ catch(...) {
+ catch_exceptions();
+ need_update = false;
+ slot = -1;
+ }
+
+ return slot;
+}
+
int VolumeManager::find_existing_slot(const string& filename, const string& name, int sampling, int grid_type)
{
for(size_t i = 0; i < current_grids.size(); ++i) {
@@ -125,6 +180,21 @@ int VolumeManager::find_existing_slot(const string& filename, const string& name
return -1;
}
+int VolumeManager::find_existing_slot(Volume *volume, const std::string &filename, const std::string &name)
+{
+ for(size_t i = 0; i < current_grids.size(); ++i) {
+ GridDescription grid = current_grids[i];
+
+ if(grid.volume == volume) {
+ if(grid.filename == filename && grid.name == name) {
+ return grid.slot;
+ }
+ }
+ }
+
+ return -1;
+}
+
int VolumeManager::find_density_slot()
{
/* first try finding a matching grid name */
@@ -220,6 +290,50 @@ size_t VolumeManager::add_openvdb_volume(const std::string& filename, const std:
return slot;
}
+size_t VolumeManager::add_openvdb_volume(Volume *volume, const std::string &filename, const std::string &name)
+{
+ size_t slot = -1;
+
+#ifdef WITH_OPENVDB
+ openvdb::io::File file(filename);
+ file.open();
+
+ if(!file.hasGrid(name)) return -1;
+
+ openvdb::GridBase::Ptr grid = file.readGrid(name);
+ if(grid->getGridClass() == openvdb::GRID_LEVEL_SET) return -1;
+
+ if(grid->isType<openvdb::FloatGrid>()) {
+ openvdb::FloatGrid::Ptr fgrid = openvdb::gridPtrCast<openvdb::FloatGrid>(grid);
+
+ vdb_float_volume *vol = new vdb_float_volume(fgrid);
+ vol->create_threads_utils(TaskScheduler::thread_ids());
+
+ volume->float_fields.push_back(vol);
+ volume->scalar_grids.push_back(fgrid);
+
+ slot = num_float_volume++;
+ }
+ else if(grid->isType<openvdb::Vec3SGrid>()) {
+ openvdb::Vec3SGrid::Ptr vgrid = openvdb::gridPtrCast<openvdb::Vec3SGrid>(grid);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list