[Bf-blender-cvs] [5086dec] openvdb: Initial support for drawing the VDB tree in the viewport.
Kévin Dietrich
noreply at git.blender.org
Thu Jun 11 12:28:53 CEST 2015
Commit: 5086decb803c7f8e3ff34adda671f9fd4504d754
Author: Kévin Dietrich
Date: Wed Jun 10 19:00:09 2015 +0200
Branches: openvdb
https://developer.blender.org/rB5086decb803c7f8e3ff34adda671f9fd4504d754
Initial support for drawing the VDB tree in the viewport.
To make it possible an OpenVDBPrimitive onject is introduced which hides
a shared pointer to an openvdb::GridBase so it's a bit generic, but by
far not final.
The drawing code is a bit hackish on the side, but at least it works and
here's an example: http://www.pasteall.org/pic/show.php?id=89278
NOTE: This only works when the simulation is imported back in.
===================================================================
M intern/openvdb/CMakeLists.txt
M intern/openvdb/intern/openvdb_dense_convert.h
A intern/openvdb/intern/openvdb_primitive.cpp
A intern/openvdb/intern/openvdb_primitive.h
A intern/openvdb/intern/openvdb_render.cpp
A intern/openvdb/intern/openvdb_render.h
M intern/openvdb/openvdb_capi.cpp
M intern/openvdb/openvdb_capi.h
M source/blender/blenkernel/intern/smoke.c
M source/blender/editors/space_view3d/CMakeLists.txt
M source/blender/editors/space_view3d/drawobject.c
M source/blender/makesdna/DNA_smoke_types.h
===================================================================
diff --git a/intern/openvdb/CMakeLists.txt b/intern/openvdb/CMakeLists.txt
index 61b5dc1..f49e680 100644
--- a/intern/openvdb/CMakeLists.txt
+++ b/intern/openvdb/CMakeLists.txt
@@ -48,8 +48,10 @@ if(WITH_OPENVDB)
)
list(APPEND SRC
- intern/openvdb_reader.cpp
intern/openvdb_dense_convert.cpp
+ intern/openvdb_primitive.cpp
+ intern/openvdb_reader.cpp
+ intern/openvdb_render.cpp
intern/openvdb_writer.cpp
openvdb_capi.cpp
openvdb_util.cpp
diff --git a/intern/openvdb/intern/openvdb_dense_convert.h b/intern/openvdb/intern/openvdb_dense_convert.h
index 9fa2c5f..d0243de 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.h
+++ b/intern/openvdb/intern/openvdb_dense_convert.h
@@ -32,6 +32,7 @@
#include <openvdb/tools/Dense.h>
#include <openvdb/tools/Clip.h>
+#include "openvdb_primitive.h"
#include "openvdb_reader.h"
#include "openvdb_writer.h"
@@ -79,10 +80,10 @@ GridType *OpenVDB_export_grid(OpenVDBWriter *writer,
}
template <typename GridType, typename T>
-void OpenVDB_import_grid(OpenVDBReader *reader,
- const std::string &name,
- T **data,
- const int res[3])
+OpenVDBPrimitive *OpenVDB_import_grid(OpenVDBReader *reader,
+ const std::string &name,
+ T **data,
+ const int res[3])
{
using namespace openvdb;
@@ -107,6 +108,11 @@ void OpenVDB_import_grid(OpenVDBReader *reader,
}
}
#endif
+
+ OpenVDBPrimitive *vdb_prim = new OpenVDBPrimitive();
+ vdb_prim->setGrid(grid_tmp);
+
+ return vdb_prim;
}
openvdb::GridBase *OpenVDB_export_vector_grid(OpenVDBWriter *writer,
diff --git a/intern/openvdb/intern/openvdb_primitive.cpp b/intern/openvdb/intern/openvdb_primitive.cpp
new file mode 100644
index 0000000..301a1a5
--- /dev/null
+++ b/intern/openvdb/intern/openvdb_primitive.cpp
@@ -0,0 +1,92 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Kevin Dietrich
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "openvdb_primitive.h"
+
+OpenVDBPrimitive::OpenVDBPrimitive()
+{}
+
+OpenVDBPrimitive::~OpenVDBPrimitive()
+{}
+
+openvdb::GridBase &OpenVDBPrimitive::getGrid()
+{
+ return *m_grid;
+}
+
+const openvdb::GridBase &OpenVDBPrimitive::getConstGrid() const
+{
+ return *m_grid;
+}
+
+openvdb::GridBase::Ptr OpenVDBPrimitive::getGridPtr()
+{
+ return m_grid;
+}
+
+openvdb::GridBase::ConstPtr OpenVDBPrimitive::getConstGridPtr() const
+{
+ return m_grid;
+}
+
+void OpenVDBPrimitive::setGrid(openvdb::GridBase::Ptr grid)
+{
+ m_grid = grid->copyGrid();
+}
+
+static openvdb::Mat4R convertMatrix(const float mat[4][4])
+{
+ return openvdb::Mat4R(
+ mat[0][0], mat[0][1], mat[0][2], mat[0][3],
+ mat[1][0], mat[1][1], mat[1][2], mat[1][3],
+ mat[2][0], mat[2][1], mat[2][2], mat[2][3],
+ mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
+}
+
+/* A simple protection to avoid crashes for cases when something goes wrong for
+ * some reason in the matrix creation. */
+static openvdb::math::MapBase::Ptr createAffineMap(const float mat[4][4])
+{
+ using namespace openvdb::math;
+ MapBase::Ptr transform;
+
+ try {
+ transform.reset(new AffineMap(convertMatrix(mat)));
+ }
+ catch (const openvdb::ArithmeticError &e) {
+ std::cerr << e.what() << "\n";
+ transform.reset(new AffineMap());
+ }
+
+ return transform;
+}
+
+void OpenVDBPrimitive::setTransform(const float mat[4][4])
+{
+ using namespace openvdb::math;
+
+ Transform::Ptr transform = Transform::Ptr(new Transform(createAffineMap(mat)));
+ m_grid->setTransform(transform);
+}
diff --git a/intern/openvdb/intern/openvdb_primitive.h b/intern/openvdb/intern/openvdb_primitive.h
new file mode 100644
index 0000000..65633df
--- /dev/null
+++ b/intern/openvdb/intern/openvdb_primitive.h
@@ -0,0 +1,47 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Kevin Dietrich
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __OPENVDB_PRIMITIVE_H__
+#define __OPENVDB_PRIMITIVE_H__
+
+#include <openvdb/openvdb.h>
+
+class OpenVDBPrimitive {
+ openvdb::GridBase::Ptr m_grid;
+
+public:
+ OpenVDBPrimitive();
+ ~OpenVDBPrimitive();
+
+ openvdb::GridBase &getGrid();
+ const openvdb::GridBase &getConstGrid() const;
+ openvdb::GridBase::Ptr getGridPtr();
+ openvdb::GridBase::ConstPtr getConstGridPtr() const;
+
+ void setGrid(openvdb::GridBase::Ptr grid);
+ void setTransform(const float mat[4][4]);
+};
+
+#endif /* __OPENVDB_PRIMITIVE_H__ */
diff --git a/intern/openvdb/intern/openvdb_render.cpp b/intern/openvdb/intern/openvdb_render.cpp
new file mode 100644
index 0000000..51aa436
--- /dev/null
+++ b/intern/openvdb/intern/openvdb_render.cpp
@@ -0,0 +1,136 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Kevin Dietrich
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <GL/glew.h>
+#include <openvdb/openvdb.h>
+
+#include "openvdb_primitive.h"
+#include "openvdb_render.h"
+
+namespace internal {
+
+void OpenVDBPrimitive_draw_tree(OpenVDBPrimitive *vdb_prim, const bool draw_root, const bool draw_level_1, const bool draw_level_2, const bool draw_leaves)
+{
+ using namespace openvdb;
+ using namespace openvdb::math;
+
+ FloatGrid::Ptr grid = gridPtrCast<FloatGrid>(vdb_prim->getGridPtr());
+
+ math::Vec3d wmin, wmax;
+ math::Vec3s color(0.0f);
+
+ math::Vec3s node_color[4] = {
+ math::Vec3s(0.0060f, 0.2790f, 0.6250f), // leaf nodes
+ math::Vec3s(0.8710f, 0.3940f, 0.0191f), // intermediate internal node levels
+ math::Vec3s(0.0432f, 0.3300f, 0.0411f), // first internal node level
+ math::Vec3s(0.0450f, 0.0450f, 0.0450f) // root
+ };
+
+ math::CoordBBox bbox;
+
+ glBegin(GL_LINES);
+
+ for (FloatTree::NodeCIter node_iter = grid->tree().cbeginNode(); node_iter; ++node_iter) {
+ node_iter.getBoundingBox(bbox);
+
+ const Vec3d min(bbox.min().x() - 0.5, bbox.min().y() - 0.5, bbox.min().z() - 0.5);
+ const Vec3d max(bbox.max().x() + 0.5, bbox.max().y() + 0.5, bbox.max().z() + 0.5);
+
+ wmin = grid->indexToWorld(min);
+ wmax = grid->indexToWorld(max);
+
+ const int level = node_iter.getLevel();
+
+ if (level == 0) {
+ if (!draw_leaves) {
+ continue;
+ }
+ color = node_color[0];
+ }
+
+ if (level == 1) {
+ if (!draw_level_2) {
+ continue;
+ }
+ color = node_color[1];
+ }
+
+ if (level == 2) {
+ if (!draw_level_1) {
+ continue;
+ }
+ color = node_color[2];
+ }
+
+ if (level == 3) {
+ if (!draw_root) {
+ continue;
+ }
+ color = node_color[3];
+ }
+
+ glColor3f(color[0], color[1], color[2]);
+
+ glVertex3f(wmin.x(), wmax.y(), wmax.z());
+ glVertex3f(wmax.x(), wmax.y(), wmax.z());
+
+ glVertex3f(wmin.x(), wmax.y(), wmin.z());
+ glVertex3f(wmax.x(), wmax.y(), wmin.z());
+
+ glVertex3f(wmin.x(), wmin.y(), wmax.z());
+ glVertex3f(wmax.x(), wmin.y(), wmax.z());
+
+ glVertex3f(wmin.x(), wmin.y(), wmin.z());
+ glVertex3f(wmax.x(), wmin.y(), wmin.z());
+
+ glVertex3f(wmin.x(), wmin.y(), wmin.z());
+ glVertex3f(wmin.x(), wmin.y(), wmax.z());
+
+ glVertex3f(wmin.x(), wmax.y(), wmin.z());
+ glVertex3f(wmin.x(), wmax.y(), wmax.z());
+
+ glVertex3f(wmax.x(), wmin.y(), wmin.z());
+ glVertex3f(wmax.x(), wmin.y(), wmax.z());
+
+ glVertex3f(wmax.x(), wmax.y(), wmin.z());
+ glVertex3f(wmax.x(), wmax.y(), wmax.z());
+
+ glVertex3f(wmin.x(), wmin.y(), wmin.z());
+ glVertex3f(wmin.x(), wmax.y(), wmin.z());
+
+ glVertex3f(wmax.x(), wmin.y(), wmin.z());
+ glVertex3f(wmax.x(), wmax.y(), wmin.z());
+
+ glVertex3f(wmax.x(), wmin.y(), wmax.z());
+ glVertex3f(wmax.x(), wmax.y(), wmax.z());
+
+ glVertex3f(wmin.x(), wmin
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list