diff options
author | Joseph Eagar <joeedh@gmail.com> | 2011-03-31 04:52:12 +0400 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2011-03-31 04:52:12 +0400 |
commit | 90fa130a696afd50676aa50578e0563a02493884 (patch) | |
tree | 2c4fd3534f9e6286a210f2ee24f8e313cd458fda /source | |
parent | 7d465aa82da599a24a3dfe50d44d8d53ca1af935 (diff) |
=bmesh= various bugfixes
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedbmesh.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/multires.c | 79 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 12 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmesh_tools.c | 10 | ||||
-rw-r--r-- | source/blender/editors/mesh/meshtools.c | 8 |
6 files changed, 33 insertions, 82 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 1a4fc77c7a4..3ed8c0f091a 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1272,7 +1272,7 @@ float (*editbmesh_get_vertex_cos(BMEditMesh *em, int *numVerts_r))[3] BMIter iter; BMVert *eve; - cos = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos"); + cos = MEM_mallocN(sizeof(float)*3*numVerts, "vertexcos"); eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL); for (i=0; eve; eve=BMIter_Step(&iter), i++) { diff --git a/source/blender/blenkernel/intern/editderivedbmesh.c b/source/blender/blenkernel/intern/editderivedbmesh.c index 62d38506eef..fda25e19b37 100644 --- a/source/blender/blenkernel/intern/editderivedbmesh.c +++ b/source/blender/blenkernel/intern/editderivedbmesh.c @@ -439,8 +439,8 @@ static void bmDM_foreachMappedEdge(DerivedMesh *dm, void (*func)(void *userData, eed = BMIter_New(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); for(i=0; eed; i++,eed=BMIter_Step(&iter)) func(userData, i, - bmdm->vertexCos[BMINDEX_GET(eve)], - bmdm->vertexCos[BMINDEX_GET(eve)]); + bmdm->vertexCos[BMINDEX_GET(eed->v1)], + bmdm->vertexCos[BMINDEX_GET(eed->v2)]); } else { eed = BMIter_New(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL); for(i=0; eed; i++,eed=BMIter_Step(&iter)) diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 5714ec2f66d..fc1b43e882e 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -179,7 +179,7 @@ void multires_force_external_reload(Object *ob) { Mesh *me = get_mesh(ob); - CustomData_external_reload(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface); + CustomData_external_reload(&me->ldata, &me->id, CD_MASK_MDISPS, me->totloop); multires_force_update(ob); } @@ -258,7 +258,7 @@ static int get_levels_from_disps(Object *ob) MDisps *mdisp, *md; int i, j, totlvl= 0; - mdisp = CustomData_get_layer(&me->fdata, CD_MDISPS); + mdisp = CustomData_get_layer(&me->ldata, CD_MDISPS); for(i = 0; i < me->totpoly; ++i) { int S = me->mpoly[i].totloop; @@ -441,7 +441,7 @@ void multiresModifier_del_levels(MultiresModifierData *mmd, Object *ob, int dire MDisps *mdisps; multires_set_tot_mdisps(me, mmd->totlvl); - CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface); + CustomData_external_read(&me->ldata, &me->id, CD_MASK_MDISPS, me->totloop); mdisps= CustomData_get_layer(&me->ldata, CD_MDISPS); multires_force_update(ob); @@ -1749,8 +1749,8 @@ static void multires_sync_levels(Scene *scene, Object *ob, Object *to_ob) Mesh *me= (Mesh*)ob->data; - CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface); - CustomData_free_layer_active(&me->fdata, CD_MDISPS, me->totface); + CustomData_external_remove(&me->ldata, &me->id, CD_MDISPS, me->totloop); + CustomData_free_layer_active(&me->ldata, CD_MDISPS, me->totloop); } if(!mmd || !to_mmd) return; @@ -1764,7 +1764,8 @@ static void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3]) DerivedMesh *dm= NULL, *cddm= NULL, *subdm= NULL; DMGridData **gridData, **subGridData; Mesh *me= (Mesh*)ob->data; - MFace *mface= me->mface; + MPoly *mpoly= me->mpoly; + MLoop *mloop = me->mloop; MDisps *mdisps; int *gridOffset; int i, /*numGrids,*/ gridSize, dGridSize, dSkip, totvert; @@ -1772,8 +1773,8 @@ static void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3]) MultiresModifierData *mmd= get_multires_modifier(scene, ob, 1); MultiresModifierData high_mmd; - CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface); - mdisps= CustomData_get_layer(&me->fdata, CD_MDISPS); + CustomData_external_read(&me->ldata, &me->id, CD_MASK_MDISPS, me->totloop); + mdisps= CustomData_get_layer(&me->ldata, CD_MDISPS); if(!mdisps || !mmd) return; @@ -1809,15 +1810,15 @@ static void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3]) dSkip= (dGridSize-1)/(gridSize-1); #pragma omp parallel for private(i) if(me->totface*gridSize*gridSize*4 >= CCG_OMP_LIMIT) - for(i = 0; i < me->totface; ++i) { - const int numVerts= mface[i].v4 ? 4 : 3; - MDisps *mdisp= &mdisps[i]; + for(i = 0; i < me->totpoly; ++i) { + const int numVerts= mpoly[i].totloop; + MDisps *mdisp= &mdisps[mpoly[i].loopstart]; int S, x, y, gIndex = gridOffset[i]; - for(S = 0; S < numVerts; ++S, ++gIndex) { + for(S = 0; S < numVerts; ++S, ++gIndex, mdisp++) { DMGridData *grid= gridData[gIndex]; DMGridData *subgrid= subGridData[gIndex]; - float (*dispgrid)[3]= &mdisp->disps[S*dGridSize*dGridSize]; + float (*dispgrid)[3]= mdisp->disps; for(y = 0; y < gridSize; y++) { for(x = 0; x < gridSize; x++) { @@ -1889,58 +1890,6 @@ void multiresModifier_prepare_join(Scene *scene, Object *ob, Object *to_ob) multires_apply_smat(scene, ob, mat); } -/* update multires data after topology changing */ -void multires_topology_changed(Scene *scene, Object *ob) -{ - Mesh *me= (Mesh*)ob->data; - MDisps *mdisp= NULL, *cur= NULL; - int i, grid= 0, corners; - MultiresModifierData *mmd= get_multires_modifier(scene, ob, 1); - - if(mmd) - multires_set_tot_mdisps(me, mmd->totlvl); - - CustomData_external_read(&me->fdata, &me->id, CD_MASK_MDISPS, me->totface); - mdisp= CustomData_get_layer(&me->fdata, CD_MDISPS); - - if(!mdisp) return; - - cur= mdisp; - for(i = 0; i < me->totface; i++, cur++) { - if(mdisp->totdisp) { - corners= multires_mdisp_corners(mdisp); - grid= mdisp->totdisp / corners; - - break; - } - } - - for(i = 0; i < me->totface; i++, mdisp++) { - int nvert= me->mface[i].v4 ? 4 : 3; - - /* allocate memory for mdisp, the whole disp layer would be erased otherwise */ - if(!mdisp->totdisp) { - if(grid) { - mdisp->totdisp= nvert*grid; - mdisp->disps= BLI_cellalloc_calloc(mdisp->totdisp*sizeof(float)*3, "mdisp topology"); - } - - continue; - } - - corners= multires_mdisp_corners(mdisp); - - if(corners!=nvert) { - mdisp->totdisp= (mdisp->totdisp/corners)*nvert; - - if(mdisp->disps) - BLI_cellalloc_free(mdisp->disps); - - mdisp->disps= BLI_cellalloc_calloc(mdisp->totdisp*sizeof(float)*3, "mdisp topology"); - } - } -} - /* makes displacement along grid boundary symmetrical */ void multires_mdisp_smooth_bounds(MDisps *disps) { diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 95e05569d95..dc3e749fbc8 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -231,7 +231,7 @@ typedef struct OldNewMap { /* local prototypes */ static void *read_struct(FileData *fd, BHead *bh, const char *blockname); - +static void convert_mfaces_to_mpolys(Mesh *mesh); static OldNewMap *oldnewmap_new(void) { @@ -3409,6 +3409,11 @@ static void lib_link_mesh(FileData *fd, Main *main) lib_link_customdata_mtface(fd, me, &me->mr->fdata, ((MultiresLevel*)me->mr->levels.first)->totface); + /*check if we need to convert mfaces to mpolys*/ + if (me->totface && !me->totpoly) { + convert_mfaces_to_mpolys(me); + } + me->id.flag -= LIB_NEEDLINK; } me= me->id.next; @@ -3735,11 +3740,6 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh) SWITCH_INT(tf->col[3]); } } - - /*check if we need to convert mfaces to mpolys*/ - if (mesh->totface && !mesh->totpoly) { - convert_mfaces_to_mpolys(mesh); - } } /* ************ READ LATTICE ***************** */ diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index 34ff4164fad..d6e5dc5949d 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -3744,10 +3744,10 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO return OPERATOR_CANCELLED; bmnew = BM_Make_Mesh(obedit, allocsize); - CustomData_copy(&bmnew->vdata, &em->bm->vdata, CD_MASK_BMESH, CD_CALLOC, 0); - CustomData_copy(&bmnew->edata, &em->bm->edata, CD_MASK_BMESH, CD_CALLOC, 0); - CustomData_copy(&bmnew->ldata, &em->bm->ldata, CD_MASK_BMESH, CD_CALLOC, 0); - CustomData_copy(&bmnew->pdata, &em->bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0); + CustomData_copy(&em->bm->vdata, &bmnew->vdata, CD_MASK_BMESH, CD_CALLOC, 0); + CustomData_copy(&em->bm->edata, &bmnew->edata, CD_MASK_BMESH, CD_CALLOC, 0); + CustomData_copy(&em->bm->ldata, &bmnew->ldata, CD_MASK_BMESH, CD_CALLOC, 0); + CustomData_copy(&em->bm->pdata, &bmnew->pdata, CD_MASK_BMESH, CD_CALLOC, 0); CustomData_bmesh_init_pool(&bmnew->vdata, allocsize[0]); CustomData_bmesh_init_pool(&bmnew->edata, allocsize[1]); @@ -3787,6 +3787,7 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO BMO_CallOpf(bmnew, "bmesh_to_mesh mesh=%p object=%p", basenew->object->data, basenew->object); BM_Free_Mesh(bmnew); + ((Mesh*)basenew->object->data)->edit_btmesh = NULL; return 1; } @@ -3816,6 +3817,7 @@ static int mesh_separate_exec(bContext *C, wmOperator *op) retval= mesh_separate_loose(bmain, scene, base, op); if(retval) { + DAG_id_tag_update(base->object->data, OB_RECALC_DATA); WM_event_add_notifier(C, NC_GEOM|ND_DATA, base->object->data); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 153153552bd..d84507267a8 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -418,9 +418,6 @@ int join_mesh_exec(bContext *C, wmOperator *op) } } - if(base->object!=ob) - multiresModifier_prepare_join(scene, base->object, ob); - CustomData_merge(&me->fdata, &fdata, CD_MASK_MESH, CD_DEFAULT, totface); CustomData_copy_data(&me->fdata, &fdata, 0, faceofs, me->totface); @@ -450,6 +447,9 @@ int join_mesh_exec(bContext *C, wmOperator *op) } if (me->totloop) { + if(base->object!=ob) + multiresModifier_prepare_join(scene, base->object, ob); + CustomData_merge(&me->ldata, &ldata, CD_MASK_MESH, CD_DEFAULT, totloop); CustomData_copy_data(&me->ldata, &ldata, 0, loopofs, me->totloop); @@ -477,7 +477,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) for(a=0; a<me->totpoly; a++, mpoly++) { mpoly->loopstart += loopofs; - mpoly->mat_nr= matmap[(int)mpoly->mat_nr]; + mpoly->mat_nr= matmap ? matmap[(int)mpoly->mat_nr] : 0; } polyofs += me->totpoly; |