[Bf-blender-cvs] [53ac275] gooseberry: New data structure for restoring strand data originating from particles.

Lukas Tönne noreply at git.blender.org
Tue Mar 24 17:53:26 CET 2015


Commit: 53ac275aceb72959a3788b341bace93677d36bb1
Author: Lukas Tönne
Date:   Tue Mar 24 17:50:46 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB53ac275aceb72959a3788b341bace93677d36bb1

New data structure for restoring strand data originating from particles.

The rationale here is that we don't try to replace particle data
temporarily like we do with DerivedMesh. This would be needed for
drawing cached data overrides in the viewport and pass them to renderers
(unless these read Alembic directly) and later for performing dupli
simulation.

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

M	source/blender/blenkernel/BKE_anim.h
A	source/blender/blenkernel/BKE_strands.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/object_dupli.c
A	source/blender/blenkernel/intern/strands.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/pointcache/alembic/abc_cloth.cpp
M	source/blender/pointcache/alembic/abc_group.cpp
M	source/blender/pointcache/alembic/abc_group.h
M	source/blender/pointcache/alembic/abc_mesh.cpp
M	source/blender/pointcache/alembic/abc_mesh.h
M	source/blender/pointcache/alembic/abc_object.cpp
M	source/blender/pointcache/alembic/abc_object.h
M	source/blender/pointcache/alembic/abc_particles.cpp
M	source/blender/pointcache/alembic/abc_particles.h
M	source/blender/pointcache/alembic/abc_reader.h
M	source/blender/pointcache/intern/ptc_types.h

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

diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index ce965a1..3b839a2 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -47,6 +47,7 @@ struct DupliCache;
 struct DupliObject;
 struct DupliObjectData;
 struct DerivedMesh;
+struct Strands;
 
 /* ---------------------------------------------------- */
 /* Animation Visualization */
@@ -84,11 +85,14 @@ void BKE_object_dupli_cache_free(struct Object *ob);
 bool BKE_object_dupli_cache_contains(struct Object *ob, struct Object *other);
 struct DupliObjectData *BKE_dupli_cache_find_data(struct DupliCache *dupcache, struct Object *ob);
 
-void BKE_dupli_object_data_init(struct DupliObjectData *data, struct Object *ob, struct DerivedMesh *dm);
+void BKE_dupli_object_data_init(struct DupliObjectData *data, struct Object *ob);
 /* does not free data itself */
 void BKE_dupli_object_data_clear(struct DupliObjectData *data);
+void BKE_dupli_object_data_set_mesh(struct DupliObjectData *data, struct DerivedMesh *dm);
+void BKE_dupli_object_data_add_strands(struct DupliObjectData *data, struct Strands *strands);
+
+struct DupliObjectData *BKE_dupli_cache_add_object(struct DupliCache *dupcache, struct Object *ob);
 
-struct DupliObjectData *BKE_dupli_cache_add_mesh(struct DupliCache *dupcache, struct Object *ob, struct DerivedMesh *dm);
 void BKE_dupli_cache_add_instance(struct DupliCache *dupcache, float obmat[4][4], struct DupliObjectData *data);
 
 typedef struct DupliExtraData {
diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
new file mode 100644
index 0000000..950df1c
--- /dev/null
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2015, 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.
+ */
+
+#ifndef __BKE_STRANDS_H__
+#define __BKE_STRANDS_H__
+
+#include "BLI_utildefines.h"
+
+#define STRANDS_BLOCK_SIZE                          (1 << 14) /* 16384 */
+#define STRANDS_INDEX_TO_BLOCK(i)                   ((i) >> 14)
+#define STRANDS_INDEX_TO_BLOCK_OFFSET(i)            ((i) - STRANDS_INDEX_TO_BLOCK((i)))
+#define STRANDS_BLOCK_TO_INDEX(block, offset)       ((block) * STRANDS_BLOCK_SIZE + (offset))
+
+typedef struct StrandsVertexBlock {
+	float co[STRANDS_BLOCK_SIZE][3];
+	float vel[STRANDS_BLOCK_SIZE][3];
+	float rot[STRANDS_BLOCK_SIZE][4];
+	float col[STRANDS_BLOCK_SIZE][3];
+	float time[STRANDS_BLOCK_SIZE];
+} StrandsVertexBlock;
+
+typedef struct StrandsBlock {
+	int numverts[STRANDS_BLOCK_SIZE];
+	int parent[STRANDS_BLOCK_SIZE];
+} StrandsBlock;
+
+typedef struct Strands {
+	StrandsBlock *strands;
+	StrandsVertexBlock *verts;
+	int totstrands, totverts;
+} Strands;
+
+struct Strands *BKE_strands_new(int strands, int verts);
+void BKE_strands_free(struct Strands *strands);
+
+/* ------------------------------------------------------------------------- */
+
+#if 0
+typedef struct StrandsIterator {
+	int totstrands; /* total number of strands to loop over */
+	int strand_index, strand_block; /* index of current strand and index in the block */
+	int vertex_start, vertex_block_next;
+	
+	int *numverts, *parent;
+} StrandsIterator;
+
+BLI_INLINE void BKE_strands_iter_init(StrandsIterator *iter, Strands *strands)
+{
+	iter->strand_index = 0;
+	iter->strand_block = 0;
+	iter->totstrands = strands->totstrands;
+	
+	iter->vertex_start = 0;
+	iter->vertex_block_next = 0;
+	
+	iter->numverts = strands->strands->numverts;
+	iter->parent = strands->strands->parent;
+}
+
+BLI_INLINE bool BKE_strands_iter_valid(StrandsIterator *iter)
+{
+	return (iter->strand_index < iter->totstrands);
+}
+
+BLI_INLINE void BKE_strand_iter_next(StrandsIterator *iter)
+{
+	int numverts = *iter->numverts;
+	
+	++iter->strand_index;
+	++iter->strand_block;
+	if (iter->strand_block > STRANDS_BLOCK_SIZE)
+		iter->strand_block -= STRANDS_BLOCK_SIZE;
+	
+	iter->vertex_start += numverts;
+	iter->vertex_block_next += numverts;
+	if (iter->vertex_block_next > STRANDS_BLOCK_SIZE)
+		iter->vertex_block_next = 0;
+}
+#endif
+
+
+#if 0
+typedef struct StrandsIterator {
+	int strand_index, vertex_index;
+	int strand_block, vertex_block;
+	int totstrands, totverts;
+	float *co[3], *vel[3], *rot[4], *col[3], *time;
+} StrandsIterator;
+
+BLI_INLINE void BKE_strands_iter_init(StrandsIterator *iter, Strands *strands)
+{
+	iter->strand_index = 0;
+	iter->strand_block = 0;
+	iter->totstrands = strands->totstrands;
+	iter->totverts = strands->totverts;
+	iter->vertex_index = 0;
+	iter->vertex_block = 0;
+	iter->co = strands->verts->co;
+	iter->vel = strands->verts->vel;
+	iter->rot = strands->verts->rot;
+	iter->col = strands->verts->col;
+	iter->time = strands->verts->time;
+}
+
+BLI_INLINE bool BKE_strands_iter_valid(StrandsIterator *iter)
+{
+	return (iter->strand_index < iter->totstrands) && (iter->vertex_index < iter->totverts);
+}
+
+BLI_INLINE void BKE_strand_iter_next(StrandsIterator *iter)
+{
+	++iter->vertex_index;
+	++iter->vertex_block;
+}
+#endif
+
+#endif  /* __BKE_STRANDS_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index b866046..0064626 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -163,6 +163,7 @@ set(SRC
 	intern/softbody.c
 	intern/sound.c
 	intern/speaker.c
+	intern/strands.c
 	intern/subsurf_ccg.c
 	intern/suggestions.c
 	intern/text.c
@@ -268,6 +269,7 @@ set(SRC
 	BKE_softbody.h
 	BKE_sound.h
 	BKE_speaker.h
+	BKE_strands.h
 	BKE_subsurf.h
 	BKE_suggestions.h
 	BKE_editmesh.h
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 20d330e..4159205 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -64,7 +64,7 @@
 #include "BKE_scene.h"
 #include "BKE_editmesh.h"
 #include "BKE_anim.h"
-
+#include "BKE_strands.h"
 
 #include "BLI_strict_flags.h"
 
@@ -1338,12 +1338,12 @@ static void dupli_cache_calc_boundbox(DupliObjectData *data)
 	BKE_boundbox_init_from_minmax(&data->bb, min, max);
 }
 
-void BKE_dupli_object_data_init(DupliObjectData *data, Object *ob, DerivedMesh *dm)
+void BKE_dupli_object_data_init(DupliObjectData *data, Object *ob)
 {
 	data->ob = ob;
 	
-	data->dm = dm;
-	dm->needsFree = false; /* take ownership */
+	data->dm = NULL;
+	BLI_listbase_clear(&data->strands);
 	
 	memset(&data->bb, 0, sizeof(data->bb));
 	dupli_cache_calc_boundbox(data);
@@ -1351,16 +1351,52 @@ void BKE_dupli_object_data_init(DupliObjectData *data, Object *ob, DerivedMesh *
 
 void BKE_dupli_object_data_clear(DupliObjectData *data)
 {
+	LinkData *link;
+	
 	if (data->dm) {
 		/* we lock DMs in the cache to prevent freeing outside,
 		 * now allow releasing again
 		 */
 		data->dm->needsFree = true;
-		
-		data->cache_dm->release(data->cache_dm);
+		data->dm->release(data->dm);
 	}
+	
+	for (link = data->strands.first; link; link = link->next) {
+		if (link->data)
+			BKE_strands_free(link->data);
+	}
+	BLI_freelistN(&data->strands);
 }
 
+void BKE_dupli_object_data_set_mesh(DupliObjectData *data, DerivedMesh *dm)
+{
+	if (data->dm) {
+		/* we lock DMs in the cache to prevent freeing outside,
+		 * now allow releasing again
+		 */
+		data->dm->needsFree = true;
+		data->dm->release(data->dm);
+	}
+	
+	data->dm = dm;
+	/* we own this dm now and need to protect it until we free it ourselves */
+	dm->needsFree = false;
+	
+	dupli_cache_calc_boundbox(data);
+}
+
+void BKE_dupli_object_data_add_strands(DupliObjectData *data, Strands *strands)
+{
+	LinkData *link = MEM_callocN(sizeof(LinkData), "strands link");
+	link->data = strands;
+	
+	BLI_addtail(&data->strands, link);
+	
+	dupli_cache_calc_boundbox(data);
+}
+
+/* ------------------------------------------------------------------------- */
+
 static void dupli_object_data_free(DupliObjectData *data)
 {
 	BKE_dupli_object_data_clear(data);
@@ -1496,15 +1532,9 @@ DupliObjectData *BKE_dupli_cache_find_data(DupliCache *dupcache, Object *ob)
 	return data;
 }
 
-DupliObjectData *BKE_dupli_cache_add_mesh(DupliCache *dupcache, Object *ob, DerivedMesh *dm)
+DupliObjectData *BKE_dupli_cache_add_object(DupliCache *dupcache, Object *ob)
 {
 	DupliObjectData *data = dupli_cache_add_object_data(dupcache, ob);
-	data->dm = dm;
-	dupli_cache_calc_boundbox(data);
-	
-	/* we own this dm now and need to protect it until we free it ourselves */
-	dm->needsFree = false;
-	
 	return data;
 }
 
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
new file mode 100644
index 0000000..7fcfc88
--- /dev/null
+++ b/source/blender/blenkernel/intern/strands.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2015, 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 "MEM_guardedalloc.h"
+
+#inclu

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list