[Bf-blender-cvs] [04b19017573] new-object-types: Volumes: add option to display points in wireframe mode
Brecht Van Lommel
noreply at git.blender.org
Tue Mar 10 13:47:49 CET 2020
Commit: 04b19017573e5fbe888a43240e0ad266dacdc0f3
Author: Brecht Van Lommel
Date: Tue Mar 10 13:42:53 2020 +0100
Branches: new-object-types
https://developer.blender.org/rB04b19017573e5fbe888a43240e0ad266dacdc0f3
Volumes: add option to display points in wireframe mode
===================================================================
M release/scripts/startup/bl_ui/properties_data_volume.py
M source/blender/blenkernel/intern/volume_render.cc
M source/blender/draw/engines/overlay/overlay_wireframe.c
M source/blender/draw/intern/draw_cache_impl_volume.c
M source/blender/makesdna/DNA_volume_defaults.h
M source/blender/makesdna/DNA_volume_types.h
M source/blender/makesrna/intern/rna_volume.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_volume.py b/release/scripts/startup/bl_ui/properties_data_volume.py
index d5357243793..47b31cebdc4 100644
--- a/release/scripts/startup/bl_ui/properties_data_volume.py
+++ b/release/scripts/startup/bl_ui/properties_data_volume.py
@@ -120,7 +120,10 @@ class DATA_PT_volume_viewport_display(DataButtonsPanel, Panel):
volume = context.volume
display = volume.display
layout.prop(display, "density")
- layout.prop(display, "wireframe_type")
+
+ col = layout.column(align=True)
+ col.prop(display, "wireframe_type")
+ col.prop(display, "wireframe_detail")
class DATA_PT_custom_props_volume(DataButtonsPanel, PropertyPanel, Panel):
diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc
index c946ed738b1..d8fbbce3bae 100644
--- a/source/blender/blenkernel/intern/volume_render.cc
+++ b/source/blender/blenkernel/intern/volume_render.cc
@@ -175,7 +175,7 @@ struct VolumeWireframe {
std::vector<openvdb::Vec2I> edges;
template<typename GridType>
- void add_grid(openvdb::GridBase::ConstPtr gridbase, const bool coarse)
+ void add_grid(openvdb::GridBase::ConstPtr gridbase, const bool points, const bool coarse)
{
using TreeType = typename GridType::TreeType;
using Depth2Type = typename TreeType::RootNodeType::ChildNodeType::ChildNodeType;
@@ -214,12 +214,23 @@ struct VolumeWireframe {
/* +1 to convert from exclusive to include bounds. */
coordbbox.max() = coordbbox.max().offsetBy(1);
openvdb::BBoxd bbox = transform.indexToWorld(coordbbox);
- add_node(bbox);
+
+ if (points) {
+ add_point(bbox);
+ }
+ else {
+ add_box(bbox);
+ }
}
}
}
- void add_node(const openvdb::BBoxd &bbox)
+ void add_point(const openvdb::BBoxd &bbox)
+ {
+ verts.push_back(bbox.getCenter());
+ }
+
+ void add_box(const openvdb::BBoxd &bbox)
{
/* TODO: deduplicate edges, hide flat edges? */
openvdb::Vec3f min = bbox.min();
@@ -279,52 +290,53 @@ void BKE_volume_grid_wireframe(const Volume *volume,
BKE_volume_grid_bounds(volume_grid, min, max);
openvdb::BBoxd bbox(min, max);
- wireframe.add_node(bbox);
+ wireframe.add_box(bbox);
}
else {
/* Tree nodes. */
openvdb::GridBase::ConstPtr grid = BKE_volume_grid_openvdb_for_read(volume, volume_grid);
- const bool coarse = (volume->display.wireframe_type == VOLUME_WIREFRAME_COARSE);
+ const bool points = (volume->display.wireframe_type == VOLUME_WIREFRAME_POINTS);
+ const bool coarse = (volume->display.wireframe_detail == VOLUME_WIREFRAME_COARSE);
switch (BKE_volume_grid_type(volume_grid)) {
case VOLUME_GRID_BOOLEAN: {
- wireframe.add_grid<openvdb::BoolGrid>(grid, coarse);
+ wireframe.add_grid<openvdb::BoolGrid>(grid, points, coarse);
break;
}
case VOLUME_GRID_FLOAT: {
- wireframe.add_grid<openvdb::FloatGrid>(grid, coarse);
+ wireframe.add_grid<openvdb::FloatGrid>(grid, points, coarse);
break;
}
case VOLUME_GRID_DOUBLE: {
- wireframe.add_grid<openvdb::DoubleGrid>(grid, coarse);
+ wireframe.add_grid<openvdb::DoubleGrid>(grid, points, coarse);
break;
}
case VOLUME_GRID_INT: {
- wireframe.add_grid<openvdb::Int32Grid>(grid, coarse);
+ wireframe.add_grid<openvdb::Int32Grid>(grid, points, coarse);
break;
}
case VOLUME_GRID_INT64: {
- wireframe.add_grid<openvdb::Int64Grid>(grid, coarse);
+ wireframe.add_grid<openvdb::Int64Grid>(grid, points, coarse);
break;
}
case VOLUME_GRID_MASK: {
- wireframe.add_grid<openvdb::MaskGrid>(grid, coarse);
+ wireframe.add_grid<openvdb::MaskGrid>(grid, points, coarse);
break;
}
case VOLUME_GRID_VECTOR_FLOAT: {
- wireframe.add_grid<openvdb::Vec3fGrid>(grid, coarse);
+ wireframe.add_grid<openvdb::Vec3fGrid>(grid, points, coarse);
break;
}
case VOLUME_GRID_VECTOR_DOUBLE: {
- wireframe.add_grid<openvdb::Vec3dGrid>(grid, coarse);
+ wireframe.add_grid<openvdb::Vec3dGrid>(grid, points, coarse);
break;
}
case VOLUME_GRID_VECTOR_INT: {
- wireframe.add_grid<openvdb::Vec3IGrid>(grid, coarse);
+ wireframe.add_grid<openvdb::Vec3IGrid>(grid, points, coarse);
break;
}
case VOLUME_GRID_STRING: {
- wireframe.add_grid<openvdb::StringGrid>(grid, coarse);
+ wireframe.add_grid<openvdb::StringGrid>(grid, points, coarse);
break;
}
case VOLUME_GRID_POINTS:
diff --git a/source/blender/draw/engines/overlay/overlay_wireframe.c b/source/blender/draw/engines/overlay/overlay_wireframe.c
index 722055c36f0..b83d5e06124 100644
--- a/source/blender/draw/engines/overlay/overlay_wireframe.c
+++ b/source/blender/draw/engines/overlay/overlay_wireframe.c
@@ -22,6 +22,7 @@
#include "DNA_mesh_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_volume_types.h"
#include "BKE_curve.h"
#include "BKE_displist.h"
@@ -156,6 +157,19 @@ void OVERLAY_wireframe_cache_populate(OVERLAY_Data *vedata,
OVERLAY_extra_wire(cb, geom, ob->obmat, color);
}
}
+ else if (ob->type == OB_VOLUME && use_wire) {
+ /* Volume object as points exception. */
+ Volume *volume = ob->data;
+ if (volume->display.wireframe_type == VOLUME_WIREFRAME_POINTS) {
+ float *color;
+ OVERLAY_ExtraCallBuffers *cb = OVERLAY_extra_call_buffer_get(vedata, ob);
+ DRW_object_wire_theme_get(ob, draw_ctx->view_layer, &color);
+
+ struct GPUBatch *geom = DRW_cache_object_face_wireframe_get(ob);
+ OVERLAY_extra_loose_points(cb, geom, ob->obmat, color);
+ return;
+ }
+ }
/* Fast path for duplis. */
if (dupli && !init_dupli) {
diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c
index 6c2816b3002..9bf131f9172 100644
--- a/source/blender/draw/intern/draw_cache_impl_volume.c
+++ b/source/blender/draw/intern/draw_cache_impl_volume.c
@@ -142,7 +142,8 @@ void DRW_volume_batch_cache_free(Volume *volume)
static void drw_volume_wireframe_cb(
void *userdata, float (*verts)[3], int (*edges)[2], int totvert, int totedge)
{
- VolumeBatchCache *cache = userdata;
+ Volume *volume = userdata;
+ VolumeBatchCache *cache = volume->batch_cache;
/* Create vertex buffer. */
static GPUVertFormat format = {0};
@@ -164,22 +165,34 @@ static void drw_volume_wireframe_cb(
GPUVertBuf *vbo_wiredata = MEM_callocN(sizeof(GPUVertBuf), __func__);
DRW_vertbuf_create_wiredata(vbo_wiredata, totvert);
- /* Create index buffer. */
- GPUIndexBufBuilder elb;
- GPU_indexbuf_init(&elb, GPU_PRIM_LINES, totedge, totvert);
- for (int i = 0; i < totedge; i++) {
- GPU_indexbuf_add_line_verts(&elb, edges[i][0], edges[i][1]);
+ if (volume->display.wireframe_type == VOLUME_WIREFRAME_POINTS) {
+ /* Create batch. */
+ cache->face_wire.batch = GPU_batch_create(
+ GPU_PRIM_POINTS, cache->face_wire.pos_nor_in_order, NULL);
+ }
+ else {
+ /* Create edge index buffer. */
+ GPUIndexBufBuilder elb;
+ GPU_indexbuf_init(&elb, GPU_PRIM_LINES, totedge, totvert);
+ for (int i = 0; i < totedge; i++) {
+ GPU_indexbuf_add_line_verts(&elb, edges[i][0], edges[i][1]);
+ }
+ GPUIndexBuf *ibo = GPU_indexbuf_build(&elb);
+
+ /* Create batch. */
+ cache->face_wire.batch = GPU_batch_create_ex(
+ GPU_PRIM_LINES, cache->face_wire.pos_nor_in_order, ibo, GPU_BATCH_OWNS_INDEX);
}
- GPUIndexBuf *ibo = GPU_indexbuf_build(&elb);
- /* Create batch. */
- cache->face_wire.batch = GPU_batch_create_ex(
- GPU_PRIM_LINES, cache->face_wire.pos_nor_in_order, ibo, GPU_BATCH_OWNS_INDEX);
GPU_batch_vertbuf_add_ex(cache->face_wire.batch, vbo_wiredata, true);
}
GPUBatch *DRW_volume_batch_cache_get_wireframes_face(Volume *volume)
{
+ if (volume->display.wireframe_type == VOLUME_WIREFRAME_NONE) {
+ return NULL;
+ }
+
VolumeBatchCache *cache = volume_batch_cache_get(volume);
if (cache->face_wire.batch == NULL) {
@@ -189,7 +202,7 @@ GPUBatch *DRW_volume_batch_cache_get_wireframes_face(Volume *volume)
}
/* Create wireframe from OpenVDB tree. */
- BKE_volume_grid_wireframe(volume, volume_grid, drw_volume_wireframe_cb, cache);
+ BKE_volume_grid_wireframe(volume, volume_grid, drw_volume_wireframe_cb, volume);
}
return cache->face_wire.batch;
diff --git a/source/blender/makesdna/DNA_volume_defaults.h b/source/blender/makesdna/DNA_volume_defaults.h
index 3b91844429b..81427f38931 100644
--- a/source/blender/makesdna/DNA_volume_defaults.h
+++ b/source/blender/makesdna/DNA_volume_defaults.h
@@ -31,7 +31,8 @@
#define _DNA_DEFAULT_VolumeDisplay \
{ \
.density = 1.0f, \
- .wireframe_type = VOLUME_WIREFRAME_COARSE, \
+ .wireframe_type = VOLUME_WIREFRAME_BOXES, \
+ .wireframe_detail = VOLUME_WIREFRAME_COARSE, \
}
#define _DNA_DEFAULT_Volume \
diff --git a/source/blender/makesdna/DNA_volume_types.h b/source/blender/makesdna/DNA_volume_types.h
index a69dc021520..cb816c5eff7 100644
--- a/source/blender/makesdna/DNA_volume_types.h
+++ b/source/blender/makesdna/DNA_volume_types.h
@@ -42,7 +42,8 @@ typedef struct Volume_Runtime {
typedef struct VolumeDisplay {
float density;
int wireframe_type;
- int _pad[2];
+ int wireframe_detail;
+ int _pad[1];
} VolumeDisplay;
typedef struct Volume {
@@ -99,10 +100,16 @@ typedef enum VolumeSequenceMode {
typedef enum VolumeWireframeType {
VOLUME_WIREFRAME_NONE = 0,
VOLUME_WIREFRAME_BOUNDS = 1,
- VOLUME_WIREFRAME_COARSE = 2,
- VOLUME_WIREFRAME_FINE = 3,
+ VOLUME_WIREFRAME_BOXES = 2,
+ VOLUME_WIREFRAME_POINTS = 3,
} VolumeWireframeType;
+/* VolumeDisplay.wireframe_detail */
+typedef enum VolumeWireframeDetail {
+ VOLUME_WIREFRAME_COARSE = 0,
+ VOLUME_WIREFRAME_FINE = 1,
+} VolumeWireframeDetail;
+
/* Only one material supported currently. */
#define VOLUME_MATERIAL_NR 1
diff --git a/source/blender/makesrna/intern/rna_volume.c b/source/blender/make
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list