[Bf-blender-cvs] [a4bc9cd] alembic: SimDebugData writer/reader for Alembic caches.

Lukas Tönne noreply at git.blender.org
Sun Apr 5 14:52:51 CEST 2015


Commit: a4bc9cd0bdb098538a7525597eeef16585b5c613
Author: Lukas Tönne
Date:   Sun Apr 5 14:47:56 2015 +0200
Branches: alembic
https://developer.blender.org/rBa4bc9cd0bdb098538a7525597eeef16585b5c613

SimDebugData writer/reader for Alembic caches.

This will allow debug visualization data to be stored inside caches
along the actual simulation state.

While the regular simulation allows examining simulation data on-the-fly
by stepping through the regular timeline, the new baking mechanism used
for caches does not easily allow simulation data to be visualized frame
by frame. Caching this data will allow adding it to the global sim debug
data.

This would also still be very handy if the baking process itself becomes
more interactive again. Unlike the current simulation progression, the
cached data can be accessed randomly, so scrubbing throught the timeline
becomes possible.

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

M	source/blender/blenkernel/BKE_effect.h
M	source/blender/blenkernel/intern/effect.c
M	source/blender/pointcache/alembic/CMakeLists.txt
A	source/blender/pointcache/alembic/abc_simdebug.cpp
A	source/blender/pointcache/alembic/abc_simdebug.h

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

diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h
index f8fee44..8c08a39 100644
--- a/source/blender/blenkernel/BKE_effect.h
+++ b/source/blender/blenkernel/BKE_effect.h
@@ -193,7 +193,10 @@ void BKE_sim_debug_data_free(void);
 
 void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3],
                                     float r, float g, float b, const char *category, unsigned int hash);
+void BKE_sim_debug_data_add_element_ex(struct SimDebugData *debug_data, int type, const float v1[3], const float v2[3],
+                                       float r, float g, float b, unsigned int category_hash, unsigned int hash);
 void BKE_sim_debug_data_remove_element(unsigned int hash);
+void BKE_sim_debug_data_remove_element_ex(struct SimDebugData *debug_data, unsigned int hash);
 
 #define BKE_sim_debug_data_add_dot(p, r, g, b, category, ...) { \
 	const float v2[3] = { 0.0f, 0.0f, 0.0f }; \
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 296a56a..1c7b737 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -1121,10 +1121,10 @@ static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem)
 		BLI_ghash_insert(debug_data->gh, elem, elem);
 }
 
-void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], float r, float g, float b, const char *category, unsigned int hash)
+void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3],
+                                    float r, float g, float b, const char *category, unsigned int hash)
 {
 	unsigned int category_hash = BLI_ghashutil_strhash_p(category);
-	SimDebugElement *elem;
 	
 	if (!_sim_debug_data) {
 		if (G.debug & G_DEBUG_SIMDATA)
@@ -1133,6 +1133,16 @@ void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[
 			return;
 	}
 	
+	BKE_sim_debug_data_add_element_ex(_sim_debug_data, type, v1, v2, r, g, b, category_hash, hash);
+}
+
+void BKE_sim_debug_data_add_element_ex(SimDebugData *debug_data, int type, const float v1[3], const float v2[3],
+                                       float r, float g, float b, unsigned int category_hash, unsigned int hash)
+{
+	SimDebugElement *elem;
+	if (!debug_data)
+		return;
+	
 	elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element");
 	elem->type = type;
 	elem->category_hash = category_hash;
@@ -1143,17 +1153,22 @@ void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[
 	copy_v3_v3(elem->v1, v1);
 	copy_v3_v3(elem->v2, v2);
 	
-	debug_data_insert(_sim_debug_data, elem);
+	debug_data_insert(debug_data, elem);
 }
 
 void BKE_sim_debug_data_remove_element(unsigned int hash)
 {
+	BKE_sim_debug_data_remove_element_ex(_sim_debug_data, hash);
+}
+
+void BKE_sim_debug_data_remove_element_ex(SimDebugData *debug_data, unsigned int hash)
+{
 	SimDebugElement dummy;
-	if (!_sim_debug_data)
+	if (!debug_data)
 		return;
 	
 	dummy.hash = hash;
-	BLI_ghash_remove(_sim_debug_data->gh, &dummy, NULL, debug_element_free);
+	BLI_ghash_remove(debug_data->gh, &dummy, NULL, debug_element_free);
 }
 
 void BKE_sim_debug_data_clear(void)
diff --git a/source/blender/pointcache/alembic/CMakeLists.txt b/source/blender/pointcache/alembic/CMakeLists.txt
index 5c6ece8..31dbff3 100644
--- a/source/blender/pointcache/alembic/CMakeLists.txt
+++ b/source/blender/pointcache/alembic/CMakeLists.txt
@@ -64,6 +64,8 @@ set(SRC
 	abc_object.h
 	abc_particles.cpp
 	abc_particles.h
+	abc_simdebug.cpp
+	abc_simdebug.h
 )
 
 add_definitions(-DWITH_ALEMBIC)
diff --git a/source/blender/pointcache/alembic/abc_simdebug.cpp b/source/blender/pointcache/alembic/abc_simdebug.cpp
new file mode 100644
index 0000000..659cfe7
--- /dev/null
+++ b/source/blender/pointcache/alembic/abc_simdebug.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2014, Blender Foundation.
+ *
+ * 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.
+ */
+
+#include "abc_simdebug.h"
+
+extern "C" {
+#include "BLI_ghash.h"
+#include "BLI_math.h"
+}
+
+#include "PTC_api.h"
+
+namespace PTC {
+
+using namespace Abc;
+
+struct SimDebugSample {
+	std::vector<uint32_t> category_hash;
+	std::vector<uint32_t> hash;
+	
+	std::vector<int32_t> type;
+	std::vector<C3f> color;
+	std::vector<V3f> v1;
+	std::vector<V3f> v2;
+};
+
+AbcSimDebugWriter::AbcSimDebugWriter(const std::string &name, SimDebugData *data) :
+    m_name(name),
+    m_data(data)
+{
+}
+
+AbcSimDebugWriter::~AbcSimDebugWriter()
+{
+}
+
+void AbcSimDebugWriter::init_abc(OObject parent)
+{
+	if (m_object)
+		return;
+	
+	m_object = OObject(parent, m_name, abc_archive()->frame_sampling_index());
+	OCompoundProperty props = m_object.getProperties();
+	
+	m_prop_category_hash = OUInt32ArrayProperty(props, "category_hash", abc_archive()->frame_sampling_index());
+	m_prop_hash = OUInt32ArrayProperty(props, "hash", abc_archive()->frame_sampling_index());
+	m_prop_type = OInt32ArrayProperty(props, "type", abc_archive()->frame_sampling_index());
+	m_prop_color = OC3fArrayProperty(props, "color", abc_archive()->frame_sampling_index());
+	m_prop_v1 = OV3fArrayProperty(props, "v1", abc_archive()->frame_sampling_index());
+	m_prop_v2 = OV3fArrayProperty(props, "v2", abc_archive()->frame_sampling_index());
+}
+
+static void create_sample(SimDebugData *data, SimDebugSample &sample)
+{
+	int numelem = BLI_ghash_size(data->gh);
+	GHashIterator iter;
+	
+	sample.category_hash.reserve(numelem);
+	sample.hash.reserve(numelem);
+	sample.type.reserve(numelem);
+	sample.color.reserve(numelem);
+	sample.v1.reserve(numelem);
+	sample.v2.reserve(numelem);
+	
+	for (BLI_ghashIterator_init(&iter, data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
+		SimDebugElement *elem = (SimDebugElement *)BLI_ghashIterator_getValue(&iter);
+		
+		sample.category_hash.push_back(elem->category_hash);
+		sample.hash.push_back(elem->hash);
+		sample.type.push_back(elem->type);
+		sample.color.push_back(C3f(elem->color[0], elem->color[1], elem->color[2]));
+		sample.v1.push_back(V3f(elem->v1[0], elem->v1[1], elem->v1[2]));
+		sample.v2.push_back(V3f(elem->v2[0], elem->v2[1], elem->v2[2]));
+	}
+}
+
+void AbcSimDebugWriter::write_sample()
+{
+	if (!m_object)
+		return;
+	
+	SimDebugSample sample;
+	
+	create_sample(m_data, sample);
+	
+	m_prop_category_hash.set(UInt32ArraySample(sample.category_hash));
+	m_prop_hash.set(UInt32ArraySample(sample.hash));
+	m_prop_type.set(Int32ArraySample(sample.type));
+	m_prop_color.set(C3fArraySample(sample.color));
+	m_prop_v1.set(V3fArraySample(sample.v1));
+	m_prop_v2.set(V3fArraySample(sample.v2));
+}
+
+/* ========================================================================= */
+
+AbcSimDebugReader::AbcSimDebugReader(SimDebugData *data) :
+    m_data(data)
+{
+}
+
+AbcSimDebugReader::~AbcSimDebugReader()
+{
+}
+
+void AbcSimDebugReader::init_abc(IObject object)
+{
+	if (m_object)
+		return;
+	m_object = IObject(object, kWrapExisting);
+	ICompoundProperty props = m_object.getProperties();
+	
+	m_prop_category_hash = IUInt32ArrayProperty(props, "category_hash");
+	m_prop_hash = IUInt32ArrayProperty(props, "hash");
+	m_prop_type = IInt32ArrayProperty(props, "type");
+	m_prop_color = IC3fArrayProperty(props, "color");
+	m_prop_v1 = IV3fArrayProperty(props, "v1");
+	m_prop_v2 = IV3fArrayProperty(props, "v2");
+}
+
+static PTCReadSampleResult apply_sample(SimDebugData *data,
+                                        UInt32ArraySamplePtr sample_category_hash, UInt32ArraySamplePtr sample_hash,
+                                        Int32ArraySamplePtr sample_type, C3fArraySamplePtr sample_color,
+                                        V3fArraySamplePtr sample_v1, V3fArraySamplePtr sample_v2)
+{
+	int numelem = sample_hash->size();
+	
+	if (sample_category_hash->size() != numelem ||
+	    sample_type->size() != numelem ||
+	    sample_color->size() != numelem ||
+	    sample_v1->size() != numelem ||
+	    sample_v2->size() != numelem)
+	{
+		return PTC_READ_SAMPLE_INVALID;
+	}
+	
+	const uint32_t *data_category_hash = sample_category_hash->get();
+	const uint32_t *data_hash = sample_hash->get();
+	const int32_t *data_type = sample_type->get();
+	const C3f *data_color = sample_color->get();
+	const V3f *data_v1 = sample_v1->get();
+	const V3f *data_v2 = sample_v2->get();
+	
+	for (int i = 0; i < numelem; ++i) {
+		BKE_sim_debug_data_add_element_ex(data, *data_type, data_v1->getValue(), data_v2->getValue(), data_color->x, data_color->y, data_color->z, *data_category_hash, *data_hash);
+	}
+	
+	return PTC_READ_SAMPLE_EXACT;
+}
+
+PTCReadSampleResult AbcSimDebugReader::read_sample(float frame)
+{
+	if (!m_object)
+		return PTC_READ_SAMPLE_INVALID;
+	
+	ISampleSelector ss = abc_archive()->get_frame_sample_selector(frame);
+	
+	apply_sample(m_data, m_prop_category_hash.getValue(ss), m_prop_hash.getValue(ss), m_prop_type.getValue(ss),
+	                   m_prop_color.getValue(ss), m_prop_v1.getValue(ss), m_prop_v2.getValue(ss));
+	
+	return PTC_READ_SAMPLE_EXACT;
+}
+
+} /* namespace PTC */
diff --git a/source/blender/pointcache/alembic/abc_simdebug.h b/source/blender/pointcache/alembic/abc_simdebug.h
new file mode 100644
index 0000000..487ec65
--- /dev/null
+++ b/source/blender/pointcache/alembic/abc_simdebug.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2014, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published b

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list