Commit: 28da4a786e38fa61e5294469f751585ea7f98160
Author: Martin Felke
Date: Mon Feb 23 14:20:56 2015 +0100
Branches: fracture_modifier
https://developer.blender.org/rB28da4a786e38fa61e5294469f751585ea7f98160
fix: loading for subobject groups partially fixed, needs manual refresh
afterwards still, TODO, proper material handling ("merge" object materials)
===================================================================
M source/blender/blenloader/intern/readfile.c
M source/blender/modifiers/intern/MOD_fracture.c
===================================================================
diff --git a/source/blender/blenloader/intern/readfile.c
b/source/blender/blenloader/intern/readfile.c
index da58dc5..36c732c 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8063,6 +8063,133 @@ static BHead *read_userdef(BlendFileData *bfd, FileData
*fd, BHead *bhead)
return bhead;
}
+static void fix_fracture_image_hack(Main* main)
+{
+ if (!MAIN_VERSION_ATLEAST(main, 273, 1)) {
+ Object *ob;
+#if 0
+ /*fix modifier images on modifiers without dm_group in a first
pass */
+ for (ob = main->object.first; ob; ob = ob->id.next) {
+ FractureModifierData *fmd =
(FractureModifierData*)modifiers_findByType(ob, eModifierType_Fracture);
+ if (fmd && fmd->visible_mesh_cached && ob->type ==
OB_MESH) {
+ CustomData* pdata =
&fmd->visible_mesh_cached->polyData;
+ int i = 0;
+ int totface =
fmd->visible_mesh_cached->numPolyData;
+ Mesh* me = ob->data;
+ if (me && CustomData_has_layer(pdata,
CD_MTEXPOLY)) {
+ for (i = 0; i < pdata->totlayer; i++) {
+ CustomDataLayer *layer =
&pdata->layers[i];
+
+ if (layer->type == CD_MTEXPOLY)
{
+ MTexPoly *tf =
layer->data;
+ int j = 0;
+ for (j = 0; j <
totface; j++, tf++) {
+ //simply use
first image here...
+ tf->tpage =
me->mtpoly->tpage;
+ tf->mode =
me->mtpoly->mode;
+ tf->flag =
me->mtpoly->flag;
+ tf->tile =
me->mtpoly->tile;
+ tf->transp =
me->mtpoly->transp;
+
+ if (tf->tpage
&& tf->tpage->id.us == 0) {
+
tf->tpage->id.us = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+#endif
+ for (ob = main->object.first; ob; ob = ob->id.next) {
+ FractureModifierData *fmd =
(FractureModifierData*)modifiers_findByType(ob, eModifierType_Fracture);
+ if (fmd && fmd->dm_group && fmd->visible_mesh_cached) {
+ GroupObject *go;
+// int polystart = 0;
+
+ for (go = fmd->dm_group->gobject.first; go; go
= go->next)
+ {
+ if (go->ob && go->ob->type == OB_MESH)
+ {
+#if 0
+ FractureModifierData *fmd2 =
(FractureModifierData*)modifiers_findByType(go->ob, eModifierType_Fracture);
+ if (fmd2 && !fmd2->dm_group &&
fmd2->visible_mesh_cached)
+ {
+ CustomData* pdata =
&fmd->visible_mesh_cached->polyData;
+ CustomData* pdata2 =
&fmd2->visible_mesh_cached->polyData;
+ int i;
+ int totface =
fmd2->visible_mesh_cached->numPolyData;
+
+ /*assume same layer
count !*/
+ if (pdata->totlayer ==
pdata2->totlayer)
+ {
+ for (i = 0; i <
pdata->totlayer; i++) {
+
CustomDataLayer *layer = &pdata->layers[i];
+
CustomDataLayer *layer2 = &pdata2->layers[i];
+
+ if
(layer->type == CD_MTEXPOLY && layer2->type == CD_MTEXPOLY) {
+
MTexPoly *tf = ((MTexPoly*)layer->data) + polystart;
+
MTexPoly *tf2 = layer2->data;
+
int j;
+
+
for (j = 0; j < totface; j++, tf++, tf2++) {
+
tf->tpage = tf2->tpage;
+
tf->mode = tf2->mode;
+
tf->flag = tf2->flag;
+
tf->tile = tf2->tile;
+
tf->transp = tf2->transp;
+
+
if (tf->tpage && tf->tpage->id.us == 0) {
+
tf->tpage->id.us = 1;
+
}
+
}
+ }
+ }
+ }
+ polystart += totface;
+ }
+ else if (!fmd2)/*fallback*/
+#endif
+ {
+ Mesh* me = go->ob->data;
+ CustomData* pdata =
&fmd->visible_mesh_cached->polyData;
+
+ if (me &&
CustomData_has_layer(pdata, CD_MTEXPOLY)) {
+ /*argh, would
need to know which images belong to which "part" of the mesh, but for now
+ just allow
proper loading and fix manually afterwards */
+ int i;
+ int totface =
fmd->visible_mesh_cached->numPolyData;
+
+ for (i = 0; i <
pdata->totlayer; i++) {
+
CustomDataLayer *layer = &pdata->layers[i];
+
+ if
(layer->type == CD_MTEXPOLY && me->mtpoly) {
+
MTexPoly *tf = layer->data;
+
int j;
+
+
for (j = 0; j < totface; j++, tf++) {
+
//simply use first image here...
+
tf->tpage = me->mtpoly->tpage;
+
tf->mode = me->mtpoly->mode;
+
tf->flag = me->mtpoly->flag;
+
tf->tile = me->mtpoly->tile;
+
tf->transp = me->mtpoly->transp;
+
+
if (tf->tpage && tf->tpage->id.us == 0) {
+
tf->tpage->id.us = 1;
+
}
+
}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
{
BHead *bhead = blo_firstbhead(fd);
@@ -8139,6 +8266,9 @@ BlendFileData *blo_read_file_internal(FileData *fd, const
char *filepath)
blo_join_main(&mainlist);
lib_link_all(fd, bfd->main);
+
+ fix_fracture_image_hack(bfd->main);
+
//do_versions_after_linking(fd, NULL, bfd->main); // XXX: not here (or
even in this function at all)! this causes crashes on many files - Aligorith
(July 04, 2010)
lib_verify_nodetree(bfd->main, true);
fix_relpaths_library(fd->relabase, bfd->main); /* make all relative
paths, relative to the open blend file */
diff --git a/source/blender/modifiers/intern/MOD_fracture.c
b/source/blender/modifiers/intern/MOD_fracture.c
index 4f71b52..851eda8 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -1336,7 +1336,7 @@ static float mesh_separate_tagged(FractureModifierData
*rmd, Object *ob, BMVert
BM_calc_center_centroid(bm_new, centroid, false);
BM_mesh_elem_index_ensure(bm_new, BM_VERT | BM_EDGE | BM_FACE);
- if (rmd->shards_to_islands || rmd->frac_mesh->shard_count < 2) {
+ if ((rmd->shards_to_islands || rmd->frac_mesh->shard_count < 2) &&
(!rmd->dm_group)) {
/* store temporary shards for each island */
dmtemp = CDDM_from_bmesh(bm_new, true);
s = BKE_create_fracture_shard(dmtemp->getVertArray(dmtemp),
dmtemp->getPolyArray(dmtemp), dmtemp->getLoopArray(dmtemp),
@@ -1544,7 +1544,8 @@ static void
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
startno = MEM_reallocN(startno, (tag_counter + 1) * 3 *
sizeof(short));
normal_float_to_short_v3(vno, v_seed->no);
- find_normal(dm, rmd->nor_tree, v_seed->co, vno, no,
rmd->nor_range);
+ if (rmd->fix_normals)
+ find_normal(dm, rmd->nor_tree, v_seed->co, vno,
no, rmd->nor_range);
startno[3 * tag_counter] = no[0];
startno[3 * tag_counter + 1] = no[1];
startno[3 * tag_counter + 2] = no[2];
@@ -1581,7 +1582,8 @@ static void
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
startno = MEM_reallocN(startno, (tag_counter +
1) * 3 * sizeof(short));
normal_float_to_short_v3(vno, e->v1->no);
- find_normal(dm, rmd->nor_tree, e->v1->co, vno,
no, rmd->nor_range);
+ if (rmd->fix_normals)
+ find_normal(dm, rmd->nor_tree,
e->v1->co, vno, no, rmd->nor_range);
startno[3 * tag_counter] = no[0];
startno[3 * tag_counter + 1] = no[1];
startno[3 * tag_counter + 2] = no[2];
@@ -1607,7 +1609,8 @@ static void
mesh_separate_loose_partition(FractureModifierData *rmd, Object *ob,
startno = MEM_reallocN(startno, (tag_counter +
1) * 3 * sizeof(short));
normal_float_to_short_v3(vno, e->v2->no);
- find_normal(dm, rmd->nor_tree, e->v2->co, vno,
no, rmd->nor_range);
+ if (rmd->fix_normals)
+ find_normal(dm, rmd->nor_tree,
e->v2->co, vno, no, rmd->nor_range);
startno[3 * tag_counter] = no[0];
startno[3 * tag_counter + 1] = no[1];
startno[3 * tag_counter + 2] = no[2];
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs