diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2020-08-19 16:46:50 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2020-08-19 16:47:09 +0300 |
commit | aa1e4baa22b3393dc723d48061c9781f4b8b42c7 (patch) | |
tree | abef7319b60e2a1faa5ce227ed8c73ac2d37e1f4 /intern/cycles/blender/blender_volume.cpp | |
parent | 3e56dd8fd9210735c654661c8ada5a5f92623826 (diff) |
Cycles : add a Volume Geometry Node
This splits the volume related data (properties for rendering and attributes) of the Mesh node
into a new `Volume` node type.
This `Volume` node derives from the `Mesh` class since we generate a mesh for the bounds of the
volume, as such we can safely work on `Volumes` as if they were `Meshes`, e.g. for BVH creation.
However such code should still check for the geometry type of the object to be `MESH` or `VOLUME`
which may be bug prone if this is forgotten.
This is part of T79131.
Reviewed By: brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8538
Diffstat (limited to 'intern/cycles/blender/blender_volume.cpp')
-rw-r--r-- | intern/cycles/blender/blender_volume.cpp | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/intern/cycles/blender/blender_volume.cpp b/intern/cycles/blender/blender_volume.cpp index d0e1e4d6131..e039d8a4895 100644 --- a/intern/cycles/blender/blender_volume.cpp +++ b/intern/cycles/blender/blender_volume.cpp @@ -17,8 +17,8 @@ #include "render/colorspace.h" #include "render/image.h" #include "render/image_vdb.h" -#include "render/mesh.h" #include "render/object.h" +#include "render/volume.h" #include "blender/blender_sync.h" #include "blender/blender_util.h" @@ -181,7 +181,7 @@ class BlenderSmokeLoader : public ImageLoader { AttributeStandard attribute; }; -static void sync_smoke_volume(Scene *scene, BL::Object &b_ob, Mesh *mesh, float frame) +static void sync_smoke_volume(Scene *scene, BL::Object &b_ob, Volume *volume, float frame) { BL::FluidDomainSettings b_domain = object_fluid_gas_domain_find(b_ob); if (!b_domain) { @@ -198,13 +198,13 @@ static void sync_smoke_volume(Scene *scene, BL::Object &b_ob, Mesh *mesh, float for (int i = 0; attributes[i] != ATTR_STD_NONE; i++) { AttributeStandard std = attributes[i]; - if (!mesh->need_attribute(scene, std)) { + if (!volume->need_attribute(scene, std)) { continue; } - mesh->volume_clipping = b_domain.clipping(); + volume->clipping = b_domain.clipping(); - Attribute *attr = mesh->attributes.add(std); + Attribute *attr = volume->attributes.add(std); ImageLoader *loader = new BlenderSmokeLoader(b_ob, std); ImageParams params; @@ -228,7 +228,7 @@ class BlenderVolumeLoader : public VDBImageLoader { if (b_volume_grid.name() == grid_name) { const bool unload = !b_volume_grid.is_loaded(); - Volume *volume = (Volume *)b_volume.ptr.data; + ::Volume *volume = (::Volume *)b_volume.ptr.data; VolumeGrid *volume_grid = (VolumeGrid *)b_volume_grid.ptr.data; grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid); @@ -252,16 +252,19 @@ class BlenderVolumeLoader : public VDBImageLoader { BL::Volume b_volume; }; -static void sync_volume_object(BL::BlendData &b_data, BL::Object &b_ob, Scene *scene, Mesh *mesh) +static void sync_volume_object(BL::BlendData &b_data, + BL::Object &b_ob, + Scene *scene, + Volume *volume) { BL::Volume b_volume(b_ob.data()); b_volume.grids.load(b_data.ptr.data); BL::VolumeRender b_render(b_volume.render()); - mesh->volume_clipping = b_render.clipping(); - mesh->volume_step_size = b_render.step_size(); - mesh->volume_object_space = (b_render.space() == BL::VolumeRender::space_OBJECT); + volume->clipping = b_render.clipping(); + volume->step_size = b_render.step_size(); + volume->object_space = (b_render.space() == BL::VolumeRender::space_OBJECT); /* Find grid with matching name. */ BL::Volume::grids_iterator b_grid_iter; @@ -289,11 +292,11 @@ static void sync_volume_object(BL::BlendData &b_data, BL::Object &b_ob, Scene *s std = ATTR_STD_VOLUME_VELOCITY; } - if ((std != ATTR_STD_NONE && mesh->need_attribute(scene, std)) || - mesh->need_attribute(scene, name)) { + if ((std != ATTR_STD_NONE && volume->need_attribute(scene, std)) || + volume->need_attribute(scene, name)) { Attribute *attr = (std != ATTR_STD_NONE) ? - mesh->attributes.add(std) : - mesh->attributes.add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL); + volume->attributes.add(std) : + volume->attributes.add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL); ImageLoader *loader = new BlenderVolumeLoader(b_data, b_volume, name.string()); ImageParams params; @@ -317,28 +320,30 @@ static vector<int> get_voxel_image_slots(Mesh *mesh) return slots; } -void BlenderSync::sync_volume(BL::Object &b_ob, Mesh *mesh, const vector<Shader *> &used_shaders) +void BlenderSync::sync_volume(BL::Object &b_ob, + Volume *volume, + const vector<Shader *> &used_shaders) { - vector<int> old_voxel_slots = get_voxel_image_slots(mesh); + vector<int> old_voxel_slots = get_voxel_image_slots(volume); - mesh->clear(); - mesh->used_shaders = used_shaders; + volume->clear(); + volume->used_shaders = used_shaders; if (view_layer.use_volumes) { if (b_ob.type() == BL::Object::type_VOLUME) { /* Volume object. Create only attributes, bounding mesh will then * be automatically generated later. */ - sync_volume_object(b_data, b_ob, scene, mesh); + sync_volume_object(b_data, b_ob, scene, volume); } else { /* Smoke domain. */ - sync_smoke_volume(scene, b_ob, mesh, b_scene.frame_current()); + sync_smoke_volume(scene, b_ob, volume, b_scene.frame_current()); } } /* Tag update. */ - bool rebuild = (old_voxel_slots != get_voxel_image_slots(mesh)); - mesh->tag_update(scene, rebuild); + bool rebuild = (old_voxel_slots != get_voxel_image_slots(volume)); + volume->tag_update(scene, rebuild); } CCL_NAMESPACE_END |