[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42677] trunk/blender/source/blender: Fix #29640: make duplicates release keep hierarchy and parent properties not
Brecht Van Lommel
brechtvanlommel at pandora.be
Sat Dec 17 00:56:19 CET 2011
Revision: 42677
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42677
Author: blendix
Date: 2011-12-16 23:56:18 +0000 (Fri, 16 Dec 2011)
Log Message:
-----------
Fix #29640: make duplicates release keep hierarchy and parent properties not
working for multiple objects.
ID.newid only worked for one object, now it uses a hash instead.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_ghash.h
trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
trunk/blender/source/blender/editors/object/object_add.c
Modified: trunk/blender/source/blender/blenlib/BLI_ghash.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_ghash.h 2011-12-16 23:50:55 UTC (rev 42676)
+++ trunk/blender/source/blender/blenlib/BLI_ghash.h 2011-12-16 23:56:18 UTC (rev 42677)
@@ -142,6 +142,16 @@
unsigned int BLI_ghashutil_inthash (const void *ptr);
int BLI_ghashutil_intcmp (const void *a, const void *b);
+typedef struct GHashPair {
+ const void *first;
+ int second;
+} GHashPair;
+
+GHashPair* BLI_ghashutil_pairalloc (const void *first, int second);
+unsigned int BLI_ghashutil_pairhash (const void *ptr);
+int BLI_ghashutil_paircmp (const void *a, const void *b);
+void BLI_ghashutil_pairfree (const void *ptr);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2011-12-16 23:50:55 UTC (rev 42676)
+++ trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2011-12-16 23:56:18 UTC (rev 42677)
@@ -285,3 +285,31 @@
int BLI_ghashutil_strcmp(const void *a, const void *b) {
return strcmp(a, b);
}
+
+GHashPair *BLI_ghashutil_pairalloc(const void *first, int second) {
+ GHashPair *pair = MEM_mallocN(sizeof(GHashPair), "GHashPair");
+ pair->first = first;
+ pair->second = second;
+ return pair;
+}
+
+unsigned int BLI_ghashutil_pairhash(const void *ptr) {
+ const GHashPair *pair = ptr;
+ unsigned int hash = BLI_ghashutil_ptrhash(pair->first);
+ return hash ^ BLI_ghashutil_inthash(SET_INT_IN_POINTER(pair->second));
+}
+
+int BLI_ghashutil_paircmp(const void *a, const void *b) {
+ const GHashPair *A = a;
+ const GHashPair *B = b;
+
+ int cmp = BLI_ghashutil_ptrcmp(A->first, B->first);
+ if(cmp == 0)
+ return BLI_ghashutil_intcmp(SET_INT_IN_POINTER(A->second), SET_INT_IN_POINTER(B->second));
+ return cmp;
+}
+
+void BLI_ghashutil_pairfree(const void *ptr) {
+ MEM_freeN((void*)ptr);
+}
+
Modified: trunk/blender/source/blender/editors/object/object_add.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_add.c 2011-12-16 23:50:55 UTC (rev 42676)
+++ trunk/blender/source/blender/editors/object/object_add.c 2011-12-16 23:56:18 UTC (rev 42677)
@@ -47,9 +47,10 @@
#include "DNA_speaker_types.h"
#include "DNA_vfont_types.h"
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_string.h"
-#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "BKE_anim.h"
@@ -1050,11 +1051,17 @@
{
ListBase *lb;
DupliObject *dob;
-
+ GHash *dupli_gh= NULL, *parent_gh= NULL;
+
if(!(base->object->transflag & OB_DUPLI))
return;
lb= object_duplilist(scene, base->object);
+
+ if(use_hierarchy || use_base_parent) {
+ dupli_gh= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "make_object_duplilist_real dupli_gh");
+ parent_gh= BLI_ghash_new(BLI_ghashutil_pairhash, BLI_ghashutil_paircmp, "make_object_duplilist_real parent_gh");
+ }
for(dob= lb->first; dob; dob= dob->next) {
Base *basen;
@@ -1083,6 +1090,11 @@
copy_m4_m4(ob->obmat, dob->mat);
object_apply_mat4(ob, ob->obmat, FALSE, FALSE);
+
+ if(dupli_gh)
+ BLI_ghash_insert(dupli_gh, dob, ob);
+ if(parent_gh)
+ BLI_ghash_insert(parent_gh, BLI_ghashutil_pairalloc(dob->ob, dob->index), ob);
}
if (use_hierarchy) {
@@ -1091,12 +1103,17 @@
Object *ob_src= dob->ob;
Object *ob_src_par= ob_src->parent;
- Object *ob_dst= (Object *)ob_src->id.newid;
+ Object *ob_dst= BLI_ghash_lookup(dupli_gh, dob);
+ Object *ob_dst_par= NULL;
- if (ob_src_par && ob_src_par->id.newid) {
- /* the parent was also made real, parent newly real duplis */
- Object *ob_dst_par= (Object *)ob_src_par->id.newid;
+ /* find parent that was also made real */
+ if(ob_src_par) {
+ GHashPair *pair = BLI_ghashutil_pairalloc(ob_src_par, dob->index);
+ ob_dst_par = BLI_ghash_lookup(parent_gh, pair);
+ BLI_ghashutil_pairfree(pair);
+ }
+ if (ob_dst_par) {
/* allow for all possible parent types */
ob_dst->partype= ob_src->partype;
BLI_strncpy(ob_dst->parsubstr, ob_src->parsubstr, sizeof(ob_dst->parsubstr));
@@ -1130,8 +1147,7 @@
* base object */
for(dob= lb->first; dob; dob= dob->next) {
/* original parents */
- Object *ob_src= dob->ob;
- Object *ob_dst= (Object *)ob_src->id.newid;
+ Object *ob_dst= BLI_ghash_lookup(dupli_gh, dob);
ob_dst->parent= base->object;
ob_dst->partype= PAROBJECT;
@@ -1145,6 +1161,11 @@
}
}
+ if(dupli_gh)
+ BLI_ghash_free(dupli_gh, NULL, NULL);
+ if(parent_gh)
+ BLI_ghash_free(parent_gh, BLI_ghashutil_pairfree, NULL);
+
copy_object_set_idnew(C, 0);
free_object_duplilist(lb);
More information about the Bf-blender-cvs
mailing list