diff options
-rw-r--r-- | source/blender/blenkernel/BKE_curve.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_displist.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 61 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 51 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 2 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 1 | ||||
-rw-r--r-- | source/blender/editors/object/object_edit.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 6 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_curve_types.h | 1 |
9 files changed, 66 insertions, 64 deletions
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index 94469381a35..f3b3810b587 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -71,6 +71,7 @@ short BKE_curve_type_get(struct Curve *cu); void BKE_curve_type_test(struct Object *ob); void BKE_curve_curve_dimension_update(struct Curve *cu); +void BKE_curve_boundbox_calc(struct Curve *cu, float r_loc[3], float r_size[3]); struct BoundBox *BKE_curve_boundbox_get(struct Object *ob); void BKE_curve_texspace_calc(struct Curve *cu); void BKE_curve_texspace_get(struct Curve *cu, float r_loc[3], float r_rot[3], float r_size[3]); diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index 1cf77c68345..2178f860825 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -102,4 +102,6 @@ float BKE_displist_calc_taper(struct Scene *scene, struct Object *taperobj, int /* add Orco layer to the displist object which has got derived mesh and return orco */ float *BKE_displist_make_orco(struct Scene *scene, struct Object *ob, struct DerivedMesh *derivedFinal, int forRender, int renderResolution); +void BKE_displist_minmax(struct ListBase *dispbase, float min[3], float max[3]); + #endif diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index c0d0ce595f2..1658b513a6c 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -145,6 +145,7 @@ void BKE_curve_editNurb_free(Curve *cu) void BKE_curve_free(Curve *cu) { BKE_nurbList_free(&cu->nurb); + BKE_displist_free(&cu->disp); BKE_curve_editfont_free(cu); BKE_curve_editNurb_free(cu); @@ -364,39 +365,29 @@ void BKE_curve_type_test(Object *ob) BKE_curve_curve_dimension_update((Curve *)ob->data); } -void BKE_curve_texspace_calc(Curve *cu) +void BKE_curve_boundbox_calc(Curve *cu, float r_loc[3], float r_size[3]) { - BoundBox *bb = cu->bb; + BoundBox *bb; float min[3], max[3]; + float mloc[3], msize[3]; - /* Curve's undeformed bounding box is calculated in displist.c, - * as a part of display list calculation. - */ - copy_v3_v3(min, bb->vec[0]); - copy_v3_v3(max, bb->vec[6]); + if (cu->bb == NULL) cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); + bb = cu->bb; - if (cu->texflag & CU_AUTOSPACE) { - mid_v3_v3v3(cu->loc, min, max); - cu->size[0] = (max[0] - min[0]) / 2.0f; - cu->size[1] = (max[1] - min[1]) / 2.0f; - cu->size[2] = (max[2] - min[2]) / 2.0f; - - zero_v3(cu->rot); + if (!r_loc) r_loc = mloc; + if (!r_size) r_size = msize; - if (cu->size[0] == 0.0f) cu->size[0] = 1.0f; - else if (cu->size[0] > 0.0f && cu->size[0] < 0.00001f) cu->size[0] = 0.00001f; - else if (cu->size[0] < 0.0f && cu->size[0] > -0.00001f) cu->size[0] = -0.00001f; + INIT_MINMAX(min, max); + BKE_displist_minmax(&cu->disp, min, max); + mid_v3_v3v3(r_loc, min, max); - if (cu->size[1] == 0.0f) cu->size[1] = 1.0f; - else if (cu->size[1] > 0.0f && cu->size[1] < 0.00001f) cu->size[1] = 0.00001f; - else if (cu->size[1] < 0.0f && cu->size[1] > -0.00001f) cu->size[1] = -0.00001f; + r_size[0] = (max[0] - min[0]) / 2.0f; + r_size[1] = (max[1] - min[1]) / 2.0f; + r_size[2] = (max[2] - min[2]) / 2.0f; - if (cu->size[2] == 0.0f) cu->size[2] = 1.0f; - else if (cu->size[2] > 0.0f && cu->size[2] < 0.00001f) cu->size[2] = 0.00001f; - else if (cu->size[2] < 0.0f && cu->size[2] > -0.00001f) cu->size[2] = -0.00001f; - } + BKE_boundbox_init_from_minmax(bb, min, max); - cu->bb->flag &= ~BOUNDBOX_DIRTY; + bb->flag &= ~BOUNDBOX_DIRTY; } BoundBox *BKE_curve_boundbox_get(Object *ob) @@ -413,6 +404,26 @@ BoundBox *BKE_curve_boundbox_get(Object *ob) return cu->bb; } +void BKE_curve_texspace_calc(Curve *cu) +{ + float loc[3], size[3]; + int a; + + BKE_curve_boundbox_calc(cu, loc, size); + + if (cu->texflag & CU_AUTOSPACE) { + for (a = 0; a < 3; a++) { + if (size[a] == 0.0f) size[a] = 1.0f; + else if (size[a] > 0.0f && size[a] < 0.00001f) size[a] = 0.00001f; + else if (size[a] < 0.0f && size[a] > -0.00001f) size[a] = -0.00001f; + } + + copy_v3_v3(cu->loc, loc); + copy_v3_v3(cu->size, size); + zero_v3(cu->rot); + } +} + void BKE_curve_texspace_get(Curve *cu, float r_loc[3], float r_rot[3], float r_size[3]) { if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) { diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 40aabadc3c0..f90a489ee1a 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -62,7 +62,6 @@ #include "BLI_sys_types.h" // for intptr_t support -static void boundbox_dispbase(BoundBox *bb, ListBase *dispbase); static void boundbox_displist_object(Object *ob); void BKE_displist_elem_free(DispList *dl) @@ -1269,16 +1268,10 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase, } } - /* Calculate curve's boundig box from non-modified display list. */ - /* TODO(sergey): not thread-safe. */ - if (cu->bb == NULL) { - cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); - } - boundbox_dispbase(cu->bb, dispbase); - - if (!forRender) { - BKE_curve_texspace_calc(cu); - } + /* make copy of 'undeformed" displist for texture space calculation + * actually, it's not totally undeformed -- pre-tessellation modifiers are + * already applied, thats how it worked for years, so keep for compatibility (sergey) */ + BKE_displist_copy(&cu->disp, dispbase); if (!forOrco) { curve_calc_modifiers_post(scene, ob, &nubase, dispbase, derivedFinal, @@ -1579,16 +1572,10 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba if ((cu->flag & CU_PATH) && !forOrco) calc_curvepath(ob, &nubase); - /* Calculate curve's boundig box from non-modified display list. */ - /* TODO(sergey): not thread-safe. */ - if (cu->bb == NULL) { - cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox"); - } - boundbox_dispbase(cu->bb, dispbase); - - if (!forRender) { - BKE_curve_texspace_calc(cu); - } + /* make copy of 'undeformed" displist for texture space calculation + * actually, it's not totally undeformed -- pre-tessellation modifiers are + * already applied, thats how it worked for years, so keep for compatibility (sergey) */ + BKE_displist_copy(&cu->disp, dispbase); if (!forOrco) curve_calc_modifiers_post(scene, ob, &nubase, dispbase, derivedFinal, forRender, renderResolution); @@ -1603,6 +1590,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco) { + Curve *cu = ob->data; ListBase *dispbase; /* The same check for duplis as in do_makeDispListCurveTypes. @@ -1611,10 +1599,10 @@ void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco) if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT)) return; - if (ob->curve_cache) { - BKE_displist_free(&(ob->curve_cache->disp)); - } - else { + BKE_displist_free(&cu->disp); + BKE_object_free_derived_caches(ob); + + if (!ob->curve_cache) { ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for curve types"); } @@ -1665,16 +1653,13 @@ float *BKE_displist_make_orco(Scene *scene, Object *ob, DerivedMesh *derivedFina return orco; } -static void boundbox_dispbase(BoundBox *bb, ListBase *dispbase) +void BKE_displist_minmax(ListBase *dispbase, float min[3], float max[3]) { - float min[3], max[3]; DispList *dl; float *vert; int a, tot = 0; int doit = 0; - INIT_MINMAX(min, max); - for (dl = dispbase->first; dl; dl = dl->next) { tot = (dl->type == DL_INDEX3) ? dl->nr : dl->nr * dl->parts; vert = dl->verts; @@ -1689,8 +1674,6 @@ static void boundbox_dispbase(BoundBox *bb, ListBase *dispbase) zero_v3(min); zero_v3(max); } - - BKE_boundbox_init_from_minmax(bb, min, max); } /* this is confusing, there's also min_max_object, appplying the obmat... */ @@ -1709,7 +1692,11 @@ static void boundbox_displist_object(Object *ob) DM_set_object_boundbox(ob, ob->derivedFinal); } else { - boundbox_dispbase(ob->bb, &ob->curve_cache->disp); + float min[3], max[3]; + + INIT_MINMAX(min, max); + BKE_displist_minmax(&ob->curve_cache->disp, min, max); + BKE_boundbox_init_from_minmax(ob->bb, min, max); } } } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 6d2f1a4622a..8f64ce6bef7 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2321,7 +2321,7 @@ BoundBox *BKE_object_boundbox_get(Object *ob) bb = BKE_mesh_boundbox_get(ob); } else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { - bb = ob->bb ? ob->bb : ((Curve *)ob->data)->bb; + bb = BKE_curve_boundbox_get(ob); } else if (ob->type == OB_MBALL) { bb = ob->bb; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index a16b1a72739..554490e2bde 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3398,6 +3398,7 @@ static void direct_link_curve(FileData *fd, Curve *cu) if (cu->wordspace == 0.0f) cu->wordspace = 1.0f; } + cu->disp.first = cu->disp.last = NULL; cu->editnurb = NULL; cu->lastsel = NULL; cu->editfont = NULL; diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index 7f7a0777bbf..47e13f02934 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -1417,8 +1417,9 @@ static void UNUSED_FUNCTION(image_aspect) (Scene *scene, View3D *v3d) space = size[0] / size[1]; } else if (ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF)) { - Curve *cu = ob->data; - space = cu->size[0] / cu->size[1]; + float size[3]; + BKE_curve_texspace_get(ob->data, NULL, NULL, size); + space = size[0] / size[1]; } x = ibuf->x / space; diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 26162651931..d4b30069ace 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -6251,7 +6251,7 @@ static void draw_bounding_volume(Scene *scene, Object *ob, char type) bb = BKE_mesh_boundbox_get(ob); } else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { - bb = ob->bb ? ob->bb : ( (Curve *)ob->data)->bb; + bb = BKE_curve_boundbox_get(ob); } else if (ob->type == OB_MBALL) { if (BKE_mball_is_basis(ob)) { @@ -6286,9 +6286,7 @@ static void drawtexspace(Object *ob) BKE_mesh_texspace_get(ob->data, loc, NULL, size); } else if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { - Curve *cu = ob->data; - copy_v3_v3(size, cu->size); - copy_v3_v3(loc, cu->loc); + BKE_curve_texspace_get(ob->data, loc, NULL, size); } else if (ob->type == OB_MBALL) { MetaBall *mb = ob->data; diff --git a/source/blender/makesdna/DNA_curve_types.h b/source/blender/makesdna/DNA_curve_types.h index 1c99f9ac827..2cfbbbd516b 100644 --- a/source/blender/makesdna/DNA_curve_types.h +++ b/source/blender/makesdna/DNA_curve_types.h @@ -178,6 +178,7 @@ typedef struct Curve { struct BoundBox *bb; ListBase nurb; /* actual data, called splines in rna */ + ListBase disp; /* undeformed display list, used mostly for texture space calculation */ EditNurb *editnurb; /* edited data, not in file, use pointer so we can check for it */ |