Partial revert of recenr cu->disp merge commit

That ended up in tricky code trying to mimic depsgraph
branch behavior API-wise preserving texspace and bound
box calculation compatible with previous releases.

So for now bring cu->disp back to the trunk but keep
texpsace and boundbox APIs the same as in the branch.

This keeps texpsapce and boundbox behavior fully compatible
with previous releases and still makes API the same as
for meshes.
This commit is contained in:
Sergey Sharybin
2013-08-21 07:40:19 +00:00
parent 8937a8b839
commit 785a67f396
9 changed files with 66 additions and 64 deletions

View File

@@ -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]);

View File

@@ -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

View File

@@ -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;
if (!r_loc) r_loc = mloc;
if (!r_size) r_size = msize;
zero_v3(cu->rot);
INIT_MINMAX(min, max);
BKE_displist_minmax(&cu->disp, min, max);
mid_v3_v3v3(r_loc, min, max);
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;
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[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;
BKE_boundbox_init_from_minmax(bb, min, max);
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;
}
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)) {

View File

@@ -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);
}
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 */