This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/blenkernel/intern/displist.c

1693 lines
41 KiB
C
Raw Normal View History

2011-10-10 09:38:02 +00:00
/*
* ***** BEGIN GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*/
2011-02-27 20:40:57 +00:00
/** \file blender/blenkernel/intern/displist.c
* \ingroup bke
*/
2002-10-12 11:37:38 +00:00
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_curve_types.h"
#include "DNA_meshdata_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_material_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_scanfill.h"
#include "BLI_utildefines.h"
2002-10-12 11:37:38 +00:00
#include "BKE_global.h"
#include "BKE_displist.h"
#include "BKE_cdderivedmesh.h"
2002-10-12 11:37:38 +00:00
#include "BKE_object.h"
#include "BKE_mball.h"
#include "BKE_material.h"
#include "BKE_curve.h"
#include "BKE_key.h"
2002-10-12 11:37:38 +00:00
#include "BKE_anim.h"
#include "BKE_font.h"
#include "BKE_lattice.h"
#include "BKE_modifier.h"
2002-10-12 11:37:38 +00:00
#include "BLO_sys_types.h" // for intptr_t support
static void boundbox_displist(Object *ob);
static void boundbox_dispbase(BoundBox *bb, ListBase *dispbase);
2012-05-07 06:58:03 +00:00
void BKE_displist_elem_free(DispList *dl)
2002-10-12 11:37:38 +00:00
{
if (dl) {
if (dl->verts) MEM_freeN(dl->verts);
if (dl->nors) MEM_freeN(dl->nors);
if (dl->index) MEM_freeN(dl->index);
if (dl->col1) MEM_freeN(dl->col1);
if (dl->col2) MEM_freeN(dl->col2);
if (dl->bevelSplitFlag) MEM_freeN(dl->bevelSplitFlag);
2002-10-12 11:37:38 +00:00
MEM_freeN(dl);
}
}
2012-05-07 06:58:03 +00:00
void BKE_displist_free(ListBase *lb)
2002-10-12 11:37:38 +00:00
{
DispList *dl;
2012-05-06 17:22:54 +00:00
dl = lb->first;
while (dl) {
2002-10-12 11:37:38 +00:00
BLI_remlink(lb, dl);
2012-05-07 06:58:03 +00:00
BKE_displist_elem_free(dl);
2012-05-06 17:22:54 +00:00
dl = lb->first;
2002-10-12 11:37:38 +00:00
}
}
2012-05-07 06:58:03 +00:00
DispList *BKE_displist_find_or_create(ListBase *lb, int type)
2002-10-12 11:37:38 +00:00
{
DispList *dl;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl = lb->first;
while (dl) {
2012-05-07 06:58:03 +00:00
if (dl->type == type)
return dl;
2012-05-06 17:22:54 +00:00
dl = dl->next;
2002-10-12 11:37:38 +00:00
}
2012-05-06 17:22:54 +00:00
dl = MEM_callocN(sizeof(DispList), "find_disp");
dl->type = type;
2002-10-12 11:37:38 +00:00
BLI_addtail(lb, dl);
return dl;
}
2012-05-07 06:58:03 +00:00
DispList *BKE_displist_find(ListBase *lb, int type)
2002-10-12 11:37:38 +00:00
{
DispList *dl;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl = lb->first;
while (dl) {
2012-05-07 06:58:03 +00:00
if (dl->type == type)
return dl;
2012-05-06 17:22:54 +00:00
dl = dl->next;
2002-10-12 11:37:38 +00:00
}
return NULL;
2002-10-12 11:37:38 +00:00
}
bool BKE_displist_has_faces(ListBase *lb)
{
DispList *dl;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
for (dl = lb->first; dl; dl = dl->next) {
if (ELEM3(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
return true;
}
}
2012-05-07 06:58:03 +00:00
return false;
}
2012-05-07 06:58:03 +00:00
void BKE_displist_copy(ListBase *lbn, ListBase *lb)
2002-10-12 11:37:38 +00:00
{
DispList *dln, *dl;
2012-05-07 06:58:03 +00:00
BKE_displist_free(lbn);
2012-05-06 17:22:54 +00:00
dl = lb->first;
while (dl) {
2012-05-06 17:22:54 +00:00
dln = MEM_dupallocN(dl);
2002-10-12 11:37:38 +00:00
BLI_addtail(lbn, dln);
2012-05-06 17:22:54 +00:00
dln->verts = MEM_dupallocN(dl->verts);
dln->nors = MEM_dupallocN(dl->nors);
dln->index = MEM_dupallocN(dl->index);
dln->col1 = MEM_dupallocN(dl->col1);
dln->col2 = MEM_dupallocN(dl->col2);
if (dl->bevelSplitFlag)
2012-05-06 17:22:54 +00:00
dln->bevelSplitFlag = MEM_dupallocN(dl->bevelSplitFlag);
2012-05-06 17:22:54 +00:00
dl = dl->next;
2002-10-12 11:37:38 +00:00
}
}
2012-05-07 06:58:03 +00:00
void BKE_displist_normals_add(ListBase *lb)
2002-10-12 11:37:38 +00:00
{
DispList *dl = NULL;
float *vdata, *ndata, nor[3];
float *v1, *v2, *v3, *v4;
float *n1, *n2, *n3, *n4;
int a, b, p1, p2, p3, p4;
2012-05-06 17:22:54 +00:00
dl = lb->first;
2012-05-07 06:58:03 +00:00
while (dl) {
2012-05-06 17:22:54 +00:00
if (dl->type == DL_INDEX3) {
if (dl->nors == NULL) {
dl->nors = MEM_callocN(sizeof(float) * 3, "dlnors");
2012-05-07 06:58:03 +00:00
if (dl->verts[2] < 0.0f)
dl->nors[2] = -1.0f;
else
dl->nors[2] = 1.0f;
2002-10-12 11:37:38 +00:00
}
}
2012-05-06 17:22:54 +00:00
else if (dl->type == DL_SURF) {
if (dl->nors == NULL) {
dl->nors = MEM_callocN(sizeof(float) * 3 * dl->nr * dl->parts, "dlnors");
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
vdata = dl->verts;
ndata = dl->nors;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
for (a = 0; a < dl->parts; a++) {
2012-05-07 06:58:03 +00:00
if (BKE_displist_surfindex_get(dl, a, &b, &p1, &p2, &p3, &p4) == 0)
break;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
v1 = vdata + 3 * p1;
n1 = ndata + 3 * p1;
v2 = vdata + 3 * p2;
n2 = ndata + 3 * p2;
v3 = vdata + 3 * p3;
n3 = ndata + 3 * p3;
v4 = vdata + 3 * p4;
n4 = ndata + 3 * p4;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
for (; b < dl->nr; b++) {
2012-04-29 15:47:02 +00:00
normal_quad_v3(nor, v1, v3, v4, v2);
2012-05-07 06:58:03 +00:00
add_v3_v3(n1, nor);
add_v3_v3(n2, nor);
add_v3_v3(n3, nor);
add_v3_v3(n4, nor);
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
v2 = v1; v1 += 3;
v4 = v3; v3 += 3;
n2 = n1; n1 += 3;
n4 = n3; n3 += 3;
2002-10-12 11:37:38 +00:00
}
}
2012-05-06 17:22:54 +00:00
a = dl->parts * dl->nr;
v1 = ndata;
while (a--) {
normalize_v3(v1);
2012-05-06 17:22:54 +00:00
v1 += 3;
2002-10-12 11:37:38 +00:00
}
}
}
2012-05-06 17:22:54 +00:00
dl = dl->next;
2002-10-12 11:37:38 +00:00
}
}
void BKE_displist_count(ListBase *lb, int *totvert, int *totface, int *tottri)
{
DispList *dl;
2012-05-07 06:58:03 +00:00
for (dl = lb->first; dl; dl = dl->next) {
int vert_tot = 0;
int face_tot = 0;
int tri_tot = 0;
switch (dl->type) {
case DL_SURF:
{
vert_tot = dl->nr * dl->parts;
face_tot = (dl->nr - 1) * (dl->parts - 1);
tri_tot = face_tot * 2;
break;
}
case DL_INDEX3:
{
vert_tot = dl->nr;
face_tot = dl->parts;
tri_tot = face_tot;
break;
}
case DL_INDEX4:
{
vert_tot = dl->nr;
face_tot = dl->parts;
tri_tot = face_tot * 2;
break;
}
case DL_POLY:
case DL_SEGM:
{
vert_tot = dl->nr * dl->parts;
2012-05-07 06:58:03 +00:00
break;
}
}
2012-05-07 06:58:03 +00:00
*totvert += vert_tot;
*totface += face_tot;
*tottri += tri_tot;
}
}
bool BKE_displist_surfindex_get(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4)
{
2012-05-06 17:22:54 +00:00
if ((dl->flag & DL_CYCL_V) == 0 && a == (dl->parts) - 1) {
return false;
}
2012-05-07 06:58:03 +00:00
if (dl->flag & DL_CYCL_U) {
2012-05-06 17:22:54 +00:00
(*p1) = dl->nr * a;
(*p2) = (*p1) + dl->nr - 1;
(*p3) = (*p1) + dl->nr;
(*p4) = (*p2) + dl->nr;
(*b) = 0;
}
else {
2012-05-06 17:22:54 +00:00
(*p2) = dl->nr * a;
(*p1) = (*p2) + 1;
(*p4) = (*p2) + dl->nr;
(*p3) = (*p1) + dl->nr;
(*b) = 1;
}
2012-05-07 06:58:03 +00:00
if ((dl->flag & DL_CYCL_V) && a == dl->parts - 1) {
2012-05-06 17:22:54 +00:00
(*p3) -= dl->nr * dl->parts;
(*p4) -= dl->nr * dl->parts;
}
2012-05-07 06:58:03 +00:00
return true;
}
/* ****************** make displists ********************* */
2002-10-12 11:37:38 +00:00
static void curve_to_displist(Curve *cu, ListBase *nubase, ListBase *dispbase, int forRender)
2002-10-12 11:37:38 +00:00
{
Nurb *nu;
DispList *dl;
BezTriple *bezt, *prevbezt;
BPoint *bp;
float *data;
int a, len, resolu;
const int editmode = (!forRender && (cu->editnurb || cu->editfont));
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
nu = nubase->first;
while (nu) {
if (nu->hide == 0 || editmode == 0) {
2012-05-06 17:22:54 +00:00
if (forRender && cu->resolu_ren != 0)
resolu = cu->resolu_ren;
else
2012-05-06 17:22:54 +00:00
resolu = nu->resolu;
2012-05-07 06:58:03 +00:00
2012-10-07 09:48:59 +00:00
if (!BKE_nurb_check_valid_u(nu)) {
/* pass */
}
else if (nu->type == CU_BEZIER) {
/* count */
2012-05-06 17:22:54 +00:00
len = 0;
a = nu->pntsu - 1;
if (nu->flagu & CU_NURB_CYCLIC) a++;
2002-10-12 11:37:38 +00:00
2012-05-06 17:22:54 +00:00
prevbezt = nu->bezt;
bezt = prevbezt + 1;
while (a--) {
2012-05-07 06:58:03 +00:00
if (a == 0 && (nu->flagu & CU_NURB_CYCLIC))
bezt = nu->bezt;
if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT)
len++;
else
len += resolu;
if (a == 0 && (nu->flagu & CU_NURB_CYCLIC) == 0)
len++;
2012-05-06 17:22:54 +00:00
prevbezt = bezt;
2002-10-12 11:37:38 +00:00
bezt++;
}
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl = MEM_callocN(sizeof(DispList), "makeDispListbez");
/* len+1 because of 'forward_diff_bezier' function */
2012-05-06 17:22:54 +00:00
dl->verts = MEM_callocN((len + 1) * 3 * sizeof(float), "dlverts");
2002-10-12 11:37:38 +00:00
BLI_addtail(dispbase, dl);
2012-05-06 17:22:54 +00:00
dl->parts = 1;
dl->nr = len;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
2002-10-12 11:37:38 +00:00
2012-05-06 17:22:54 +00:00
data = dl->verts;
2002-10-12 11:37:38 +00:00
if (nu->flagu & CU_NURB_CYCLIC) {
2012-05-06 17:22:54 +00:00
dl->type = DL_POLY;
a = nu->pntsu;
2002-10-12 11:37:38 +00:00
}
else {
2012-05-06 17:22:54 +00:00
dl->type = DL_SEGM;
a = nu->pntsu - 1;
2002-10-12 11:37:38 +00:00
}
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
prevbezt = nu->bezt;
bezt = prevbezt + 1;
2012-05-07 06:58:03 +00:00
while (a--) {
2012-05-07 06:58:03 +00:00
if (a == 0 && dl->type == DL_POLY)
bezt = nu->bezt;
2012-05-06 17:22:54 +00:00
if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) {
2011-11-06 15:17:43 +00:00
copy_v3_v3(data, prevbezt->vec[1]);
2012-05-06 17:22:54 +00:00
data += 3;
2002-10-12 11:37:38 +00:00
}
else {
int j;
2012-05-06 17:22:54 +00:00
for (j = 0; j < 3; j++) {
BKE_curve_forward_diff_bezier(prevbezt->vec[1][j],
prevbezt->vec[2][j],
bezt->vec[0][j],
bezt->vec[1][j],
data + j, resolu, 3 * sizeof(float));
}
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
data += 3 * resolu;
2002-10-12 11:37:38 +00:00
}
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
if (a == 0 && dl->type == DL_SEGM) {
2011-11-06 15:17:43 +00:00
copy_v3_v3(data, bezt->vec[1]);
2002-10-12 11:37:38 +00:00
}
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
prevbezt = bezt;
2002-10-12 11:37:38 +00:00
bezt++;
}
}
else if (nu->type == CU_NURBS) {
2012-05-06 17:22:54 +00:00
len = (resolu * SEGMENTSU(nu));
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl = MEM_callocN(sizeof(DispList), "makeDispListsurf");
dl->verts = MEM_callocN(len * 3 * sizeof(float), "dlverts");
2002-10-12 11:37:38 +00:00
BLI_addtail(dispbase, dl);
2012-05-06 17:22:54 +00:00
dl->parts = 1;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl->nr = len;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
2002-10-12 11:37:38 +00:00
2012-05-06 17:22:54 +00:00
data = dl->verts;
2012-05-07 06:58:03 +00:00
if (nu->flagu & CU_NURB_CYCLIC)
dl->type = DL_POLY;
2012-05-06 17:22:54 +00:00
else dl->type = DL_SEGM;
BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3 * sizeof(float));
2002-10-12 11:37:38 +00:00
}
else if (nu->type == CU_POLY) {
2012-05-06 17:22:54 +00:00
len = nu->pntsu;
dl = MEM_callocN(sizeof(DispList), "makeDispListpoly");
dl->verts = MEM_callocN(len * 3 * sizeof(float), "dlverts");
2002-10-12 11:37:38 +00:00
BLI_addtail(dispbase, dl);
2012-05-06 17:22:54 +00:00
dl->parts = 1;
dl->nr = len;
dl->col = nu->mat_nr;
More text object fancyness, and fixes: - "Flush" is now split into two seperate Alignment modes "Flush" and "Justify": - Justify does exactly the same as a normal word processor's justify function does, and in addition, it uses *whitespace* instead of *character spacing* (kerning) to fill lines. Much more readable. - Flush is pretty much the old Blender "Flush" mode - and as such it uses character spacing to fill lines. Just as Justify, this only works with at least one textframe. - Underlining for text objects. Not a lot to explain. New button "U" in the editbuttons, and CTRL-U as hotkey toggle underlining for newly entered characters or for the selection, just like CTRL-B/CTRL-I do for bold/italic. Underline height (thickness) and Underline position (vertical) can be set in the editbuttons. Implemented as CU_POLY polygon curves. - The B, U and i buttons (and the corresponding CTRL-B/U/I keystrokes) have been fixed to only affect *one* attribute at a time. Formerly, hitting CTRL-B when no other style was active, on a text portion with italics text, for example, would kill the italics and just apply bold. Now, these attributes always add or substract only, but do not replace the style. - In the past, there were bugs with material indices uninitialized, and thus crashes in the renderer with illegal material indices. Even though I assume they have been fixed, I've put in a check that checks (hah) if the material index of a character is illegal (bigger than ob->totcol), and then sets it to zero, and spits out a warning on stderr. If you see such warnings, please report and link to the .blend. - Bugfix: All alignment modes only worked if there were at least *two* lines of text in the text object. Fixed There's now a regression test file for text objects, please add to the corresponding repository: http://blender.instinctive.de/downloads/release/demo/text-regression.blend.gz
2005-08-29 12:46:07 +00:00
dl->charidx = nu->charidx;
2002-10-12 11:37:38 +00:00
2012-05-06 17:22:54 +00:00
data = dl->verts;
if (nu->flagu & CU_NURB_CYCLIC) dl->type = DL_POLY;
else dl->type = DL_SEGM;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
a = len;
bp = nu->bp;
while (a--) {
2011-11-06 15:17:43 +00:00
copy_v3_v3(data, bp->vec);
2002-10-12 11:37:38 +00:00
bp++;
2012-05-06 17:22:54 +00:00
data += 3;
2002-10-12 11:37:38 +00:00
}
}
}
2012-05-06 17:22:54 +00:00
nu = nu->next;
2002-10-12 11:37:38 +00:00
}
}
2012-05-07 06:58:03 +00:00
void BKE_displist_fill(ListBase *dispbase, ListBase *to, int flipnormal)
2002-10-12 11:37:38 +00:00
{
ScanFillContext sf_ctx;
ScanFillVert *sf_vert, *sf_vert_new, *sf_vert_last;
ScanFillFace *sf_tri;
2012-05-06 17:22:54 +00:00
DispList *dlnew = NULL, *dl;
2002-10-12 11:37:38 +00:00
float *f1;
2012-05-06 17:22:54 +00:00
int colnr = 0, charidx = 0, cont = 1, tot, a, *index, nextcol = 0;
intptr_t totvert;
2012-05-07 06:58:03 +00:00
if (dispbase == NULL)
return;
if (dispbase->first == NULL)
return;
2002-10-12 11:37:38 +00:00
while (cont) {
2012-05-06 17:22:54 +00:00
cont = 0;
totvert = 0;
nextcol = 0;
2012-05-07 06:58:03 +00:00
BLI_scanfill_begin(&sf_ctx);
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl = dispbase->first;
while (dl) {
2012-05-06 17:22:54 +00:00
if (dl->type == DL_POLY) {
2012-05-07 06:58:03 +00:00
if (charidx < dl->charidx)
cont = 1;
2012-05-06 17:22:54 +00:00
else if (charidx == dl->charidx) { /* character with needed index */
if (colnr == dl->col) {
/* make editverts and edges */
2012-05-06 17:22:54 +00:00
f1 = dl->verts;
a = dl->nr;
sf_vert = sf_vert_new = NULL;
2012-05-07 06:58:03 +00:00
while (a--) {
sf_vert_last = sf_vert;
sf_vert = BLI_scanfill_vert_add(&sf_ctx, f1);
totvert++;
if (sf_vert_last == NULL)
sf_vert_new = sf_vert;
else {
BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert);
}
2012-05-06 17:22:54 +00:00
f1 += 3;
2002-10-12 11:37:38 +00:00
}
if (sf_vert != NULL && sf_vert_new != NULL) {
BLI_scanfill_edge_add(&sf_ctx, sf_vert, sf_vert_new);
}
}
2012-05-06 17:22:54 +00:00
else if (colnr < dl->col) {
/* got poly with next material at current char */
2012-05-06 17:22:54 +00:00
cont = 1;
nextcol = 1;
2002-10-12 11:37:38 +00:00
}
}
}
2012-05-06 17:22:54 +00:00
dl = dl->next;
2002-10-12 11:37:38 +00:00
}
2012-05-07 06:58:03 +00:00
2013-02-02 04:58:03 +00:00
/* XXX (obedit && obedit->actcol) ? (obedit->actcol-1) : 0)) { */
if (totvert && (tot = BLI_scanfill_calc(&sf_ctx, BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_HOLES))) {
if (tot) {
2012-05-06 17:22:54 +00:00
dlnew = MEM_callocN(sizeof(DispList), "filldisplist");
dlnew->type = DL_INDEX3;
dlnew->col = colnr;
dlnew->nr = totvert;
dlnew->parts = tot;
dlnew->index = MEM_mallocN(tot * 3 * sizeof(int), "dlindex");
dlnew->verts = MEM_mallocN(totvert * 3 * sizeof(float), "dlverts");
2012-05-07 06:58:03 +00:00
/* vert data */
2012-05-06 17:22:54 +00:00
f1 = dlnew->verts;
totvert = 0;
for (sf_vert = sf_ctx.fillvertbase.first; sf_vert; sf_vert = sf_vert->next) {
copy_v3_v3(f1, sf_vert->co);
2012-05-06 17:22:54 +00:00
f1 += 3;
2012-05-07 06:58:03 +00:00
/* index number */
sf_vert->tmp.l = totvert;
2002-10-12 11:37:38 +00:00
totvert++;
}
2012-05-07 06:58:03 +00:00
/* index data */
sf_tri = sf_ctx.fillfacebase.first;
2012-05-06 17:22:54 +00:00
index = dlnew->index;
while (sf_tri) {
index[0] = (intptr_t)sf_tri->v1->tmp.l;
index[1] = (intptr_t)sf_tri->v2->tmp.l;
index[2] = (intptr_t)sf_tri->v3->tmp.l;
if (flipnormal)
SWAP(int, index[0], index[2]);
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
index += 3;
sf_tri = sf_tri->next;
2002-10-12 11:37:38 +00:00
}
}
BLI_addhead(to, dlnew);
}
BLI_scanfill_end(&sf_ctx);
2002-10-12 11:37:38 +00:00
if (nextcol) {
/* stay at current char but fill polys with next material */
colnr++;
}
else {
/* switch to next char and start filling from first material */
charidx++;
2012-05-06 17:22:54 +00:00
colnr = 0;
}
2002-10-12 11:37:38 +00:00
}
2012-05-07 06:58:03 +00:00
/* do not free polys, needed for wireframe display */
2002-10-12 11:37:38 +00:00
}
static void bevels_to_filledpoly(Curve *cu, ListBase *dispbase)
{
ListBase front, back;
DispList *dl, *dlnew;
float *fp, *fp1;
int a, dpoly;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
front.first = front.last = back.first = back.last = NULL;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl = dispbase->first;
while (dl) {
2012-05-06 17:22:54 +00:00
if (dl->type == DL_SURF) {
2012-05-07 06:58:03 +00:00
if ((dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U) == 0) {
if ( (cu->flag & CU_BACK) && (dl->flag & DL_BACK_CURVE)) {
2012-05-06 17:22:54 +00:00
dlnew = MEM_callocN(sizeof(DispList), "filldisp");
2002-10-12 11:37:38 +00:00
BLI_addtail(&front, dlnew);
2012-05-06 17:22:54 +00:00
dlnew->verts = fp1 = MEM_mallocN(sizeof(float) * 3 * dl->parts, "filldisp1");
dlnew->nr = dl->parts;
dlnew->parts = 1;
dlnew->type = DL_POLY;
dlnew->col = dl->col;
dlnew->charidx = dl->charidx;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
fp = dl->verts;
dpoly = 3 * dl->nr;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
a = dl->parts;
while (a--) {
2011-11-06 15:17:43 +00:00
copy_v3_v3(fp1, fp);
2012-05-06 17:22:54 +00:00
fp1 += 3;
fp += dpoly;
2002-10-12 11:37:38 +00:00
}
}
2012-05-07 06:58:03 +00:00
if ((cu->flag & CU_FRONT) && (dl->flag & DL_FRONT_CURVE)) {
2012-05-06 17:22:54 +00:00
dlnew = MEM_callocN(sizeof(DispList), "filldisp");
2002-10-12 11:37:38 +00:00
BLI_addtail(&back, dlnew);
2012-05-06 17:22:54 +00:00
dlnew->verts = fp1 = MEM_mallocN(sizeof(float) * 3 * dl->parts, "filldisp1");
dlnew->nr = dl->parts;
dlnew->parts = 1;
dlnew->type = DL_POLY;
dlnew->col = dl->col;
dlnew->charidx = dl->charidx;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
fp = dl->verts + 3 * (dl->nr - 1);
dpoly = 3 * dl->nr;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
a = dl->parts;
while (a--) {
2011-11-06 15:17:43 +00:00
copy_v3_v3(fp1, fp);
2012-05-06 17:22:54 +00:00
fp1 += 3;
fp += dpoly;
2002-10-12 11:37:38 +00:00
}
}
}
}
2012-05-06 17:22:54 +00:00
dl = dl->next;
2002-10-12 11:37:38 +00:00
}
2012-05-07 06:58:03 +00:00
BKE_displist_fill(&front, dispbase, 1);
BKE_displist_fill(&back, dispbase, 0);
BKE_displist_free(&front);
BKE_displist_free(&back);
2002-10-12 11:37:38 +00:00
2012-05-07 06:58:03 +00:00
BKE_displist_fill(dispbase, dispbase, 0);
2002-10-12 11:37:38 +00:00
}
static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dispbase)
2002-10-12 11:37:38 +00:00
{
2012-05-07 06:58:03 +00:00
if (cu->flag & CU_3D)
return;
2002-10-12 11:37:38 +00:00
2012-05-06 17:22:54 +00:00
if (dispbase->first && ((DispList *) dispbase->first)->type == DL_SURF) {
bevels_to_filledpoly(cu, dispbase);
}
2002-10-12 11:37:38 +00:00
else {
2012-05-07 06:58:03 +00:00
BKE_displist_fill(dispbase, dispbase, 0);
2002-10-12 11:37:38 +00:00
}
}
/* taper rules:
2012-03-09 18:28:30 +00:00
* - only 1 curve
* - first point left, last point right
* - based on subdivided points in original curve, not on points in taper curve (still)
*/
static float displist_calc_taper(Scene *scene, Object *taperobj, float fac)
{
DispList *dl;
2012-05-07 06:58:03 +00:00
if (taperobj == NULL || taperobj->type != OB_CURVE)
return 1.0;
2012-05-06 17:22:54 +00:00
dl = taperobj->disp.first;
if (dl == NULL) {
2012-05-07 06:58:03 +00:00
BKE_displist_make_curveTypes(scene, taperobj, 0);
2012-05-06 17:22:54 +00:00
dl = taperobj->disp.first;
}
if (dl) {
float minx, dx, *fp;
int a;
2012-05-07 06:58:03 +00:00
/* horizontal size */
2012-05-06 17:22:54 +00:00
minx = dl->verts[0];
dx = dl->verts[3 * (dl->nr - 1)] - minx;
if (dx > 0.0f) {
2012-05-06 17:22:54 +00:00
fp = dl->verts;
for (a = 0; a < dl->nr; a++, fp += 3) {
2012-05-07 06:58:03 +00:00
if ((fp[0] - minx) / dx >= fac) {
/* interpolate with prev */
2012-05-06 17:22:54 +00:00
if (a > 0) {
float fac1 = (fp[-3] - minx) / dx;
float fac2 = (fp[0] - minx) / dx;
if (fac1 != fac2)
return fp[1] * (fac1 - fac) / (fac1 - fac2) + fp[-2] * (fac - fac2) / (fac1 - fac2);
}
return fp[1];
}
}
2012-05-06 17:22:54 +00:00
return fp[-2]; // last y coord
}
}
2012-05-07 06:58:03 +00:00
return 1.0;
}
float BKE_displist_calc_taper(Scene *scene, Object *taperobj, int cur, int tot)
{
float fac = ((float)cur) / (float)(tot - 1);
return displist_calc_taper(scene, taperobj, fac);
}
2012-05-07 06:58:03 +00:00
void BKE_displist_make_mball(Scene *scene, Object *ob)
{
2012-05-07 06:58:03 +00:00
if (!ob || ob->type != OB_MBALL)
return;
2012-05-07 06:58:03 +00:00
/* XXX: mball stuff uses plenty of global variables
* while this is unchanged updating during render is unsafe
*/
if (G.is_rendering)
2012-05-07 06:58:03 +00:00
return;
2012-05-07 06:58:03 +00:00
BKE_displist_free(&(ob->disp));
2012-05-06 17:22:54 +00:00
if (ob->type == OB_MBALL) {
if (ob == BKE_mball_basis_find(scene, ob)) {
BKE_mball_polygonize(scene, ob, &ob->disp);
BKE_mball_texspace_calc(ob);
object_deform_mball(ob, &ob->disp);
Result of 2 weeks of quiet coding work in Greece :) Aim was to get a total refresh of the animation system. This is needed because; - we need to upgrade it with 21st century features - current code is spaghetti/hack combo, and hides good design - it should become lag-free with using dependency graphs A full log, with complete code API/structure/design explanation will follow, that's a load of work... so here below the list with hot changes; - The entire object update system (matrices, geometry) is now centralized. Calls to where_is_object and makeDispList are forbidden, instead we tag objects 'changed' and let the depgraph code sort it out - Removed all old "Ika" code - Depgraph is aware of all relationships, including meta balls, constraints, bevelcurve, and so on. - Made depgraph aware of relation types and layers, to do smart flushing of 'changed' events. Nothing gets calculated too often! - Transform uses depgraph to detect changes - On frame-advance, depgraph flushes animated changes Armatures; Almost all armature related code has been fully built from scratch. It now reveils the original design much better, with a very clean implementation, lag free without even calculating each Bone more than once. Result is quite a speedup yes! Important to note is; 1) Armature is data containing the 'rest position' 2) Pose is the changes of rest position, and always on object level. That way more Objects can use same Pose. Also constraints are in Pose 3) Actions only contain the Ipos to change values in Poses. - Bones draw unrotated now - Drawing bones speedup enormously (10-20 times) - Bone selecting in EditMode, selection state is saved for PoseMode, and vice-versa - Undo in editmode - Bone renaming does vertexgroups, constraints, posechannels, actions, for all users of Armature in entire file - Added Bone renaming in NKey panel - Nkey PoseMode shows eulers now - EditMode and PoseMode now have 'active' bone too (last clicked) - Parenting in EditMode' CTRL+P, ALT+P, with nice options! - Pose is added in Outliner now, with showing that constraints are in the Pose, not Armature - Disconnected IK solving from constraints. It's a separate phase now, on top of the full Pose calculations - Pose itself has a dependency graph too, so evaluation order is lag free. TODO NOW; - Rotating in Posemode has incorrect inverse transform (Martin will fix) - Python Bone/Armature/Pose API disabled... needs full recode too (wait for my doc!) - Game engine will need upgrade too - Depgraph code needs revision, cleanup, can be much faster! (But, compliments for Jean-Luc, it works like a charm!) - IK changed, it now doesnt use previous position to advance to next position anymore. That system looks nice (no flips) but is not well suited for NLA and background render. TODO LATER; We now can do loadsa new nifty features as well; like: - Kill PoseMode (can be option for armatures itself) - Make B-Bones (Bezier, Bspline, like for spines) - Move all silly button level edit to 3d window (like CTRL+I = add IK) - Much better & informative drawing - Fix action/nla editors - Put all ipos in Actions (object, mesh key, lamp color) - Add hooks - Null bones - Much more advanced constraints... Bugfixes; - OGL render (view3d header) had wrong first frame on anim render - Ipo 'recording' mode had wrong playback speed - Vertex-key mode now sticks to show 'active key', until frame change -Ton-
2005-07-03 17:35:38 +00:00
}
2002-10-12 11:37:38 +00:00
}
2012-05-07 06:58:03 +00:00
boundbox_displist(ob);
}
2012-05-07 06:58:03 +00:00
void BKE_displist_make_mball_forRender(Scene *scene, Object *ob, ListBase *dispbase)
{
BKE_mball_polygonize(scene, ob, dispbase);
BKE_mball_texspace_calc(ob);
2012-05-07 06:58:03 +00:00
object_deform_mball(ob, dispbase);
}
static ModifierData *curve_get_tessellate_point(Scene *scene, Object *ob, int forRender, int editmode)
{
ModifierData *md = modifiers_getVirtualModifierList(ob);
ModifierData *pretessellatePoint;
int required_mode;
2012-05-07 06:58:03 +00:00
if (forRender)
required_mode = eModifierMode_Render;
else
required_mode = eModifierMode_Realtime;
2012-05-07 06:58:03 +00:00
if (editmode)
required_mode |= eModifierMode_Editmode;
pretessellatePoint = NULL;
2012-05-06 17:22:54 +00:00
for (; md; md = md->next) {
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
2012-05-07 06:58:03 +00:00
if (!modifier_isEnabled(scene, md, required_mode))
continue;
if (mti->type == eModifierTypeType_Constructive)
return pretessellatePoint;
if (ELEM3(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_MeshDeform)) {
pretessellatePoint = md;
/* this modifiers are moving point of tessellation automatically
2012-03-18 07:38:51 +00:00
* (some of them even can't be applied on tessellated curve), set flag
* for information button in modifier's header
2012-05-07 06:58:03 +00:00
*/
md->mode |= eModifierMode_ApplyOnSpline;
}
2012-05-06 17:22:54 +00:00
else if (md->mode & eModifierMode_ApplyOnSpline) {
pretessellatePoint = md;
}
}
return pretessellatePoint;
}
static void curve_calc_modifiers_pre(Scene *scene, Object *ob, int forRender, float (**originalVerts_r)[3],
float (**deformedVerts_r)[3], int *numVerts_r)
{
ModifierData *md = modifiers_getVirtualModifierList(ob);
ModifierData *pretessellatePoint;
2012-05-06 17:22:54 +00:00
Curve *cu = ob->data;
ListBase *nurb = BKE_curve_nurbs_get(cu);
int numVerts = 0;
const int editmode = (!forRender && (cu->editnurb || cu->editfont));
ModifierApplyFlag app_flag = 0;
float (*originalVerts)[3] = NULL;
float (*deformedVerts)[3] = NULL;
2012-05-06 17:22:54 +00:00
float *keyVerts = NULL;
int required_mode;
if (editmode)
app_flag |= MOD_APPLY_USECACHE;
if (forRender) {
app_flag |= MOD_APPLY_RENDER;
2012-05-07 06:58:03 +00:00
required_mode = eModifierMode_Render;
}
2012-05-07 06:58:03 +00:00
else
required_mode = eModifierMode_Realtime;
pretessellatePoint = curve_get_tessellate_point(scene, ob, forRender, editmode);
2012-05-07 06:58:03 +00:00
if (editmode)
required_mode |= eModifierMode_Editmode;
2012-05-06 17:22:54 +00:00
if (cu->editnurb == NULL) {
keyVerts = BKE_key_evaluate_object(scene, ob, &numVerts);
if (keyVerts) {
/* split coords from key data, the latter also includes
2012-03-09 18:28:30 +00:00
* tilts, which is passed through in the modifier stack.
* this is also the reason curves do not use a virtual
* shape key modifier yet. */
2012-05-06 17:22:54 +00:00
deformedVerts = BKE_curve_keyVertexCos_get(cu, nurb, keyVerts);
originalVerts = MEM_dupallocN(deformedVerts);
BLI_assert(BKE_nurbList_verts_count(nurb) == numVerts);
}
}
2012-05-07 06:58:03 +00:00
if (pretessellatePoint) {
2012-05-06 17:22:54 +00:00
for (; md; md = md->next) {
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
2012-05-06 17:22:54 +00:00
md->scene = scene;
2012-05-07 06:58:03 +00:00
if (!modifier_isEnabled(scene, md, required_mode))
2012-05-07 06:58:03 +00:00
continue;
if (mti->type != eModifierTypeType_OnlyDeform)
continue;
if (!deformedVerts) {
deformedVerts = BKE_curve_vertexCos_get(cu, nurb, &numVerts);
originalVerts = MEM_dupallocN(deformedVerts);
}
mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, app_flag);
2012-05-06 17:22:54 +00:00
if (md == pretessellatePoint)
break;
}
}
if (deformedVerts)
BK_curve_vertexCos_apply(cu, nurb, deformedVerts);
if (keyVerts) /* these are not passed through modifier stack */
BKE_curve_keyVertexTilts_apply(cu, nurb, keyVerts);
if (keyVerts)
MEM_freeN(keyVerts);
*originalVerts_r = originalVerts;
*deformedVerts_r = deformedVerts;
*numVerts_r = numVerts;
}
2012-05-06 17:22:54 +00:00
static float (*displist_get_allverts(ListBase * dispbase, int *totvert))[3]
{
DispList *dl;
float (*allverts)[3], *fp;
2012-05-06 17:22:54 +00:00
*totvert = 0;
2012-05-06 17:22:54 +00:00
for (dl = dispbase->first; dl; dl = dl->next)
*totvert += (dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr;
2012-05-06 17:22:54 +00:00
allverts = MEM_mallocN((*totvert) * sizeof(float) * 3, "displist_get_allverts allverts");
fp = (float *)allverts;
for (dl = dispbase->first; dl; dl = dl->next) {
int offs = 3 * ((dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr);
memcpy(fp, dl->verts, sizeof(float) * offs);
2012-05-06 17:22:54 +00:00
fp += offs;
}
return allverts;
}
static void displist_apply_allverts(ListBase *dispbase, float (*allverts)[3])
{
DispList *dl;
float *fp;
2012-05-06 17:22:54 +00:00
fp = (float *)allverts;
for (dl = dispbase->first; dl; dl = dl->next) {
int offs = 3 * ((dl->type == DL_INDEX3) ? dl->nr : dl->parts * dl->nr);
memcpy(dl->verts, fp, sizeof(float) * offs);
2012-05-06 17:22:54 +00:00
fp += offs;
}
}
2012-05-07 06:58:03 +00:00
static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispbase, DerivedMesh **derivedFinal,
int forRender, float (*originalVerts)[3], float (*deformedVerts)[3])
{
ModifierData *md = modifiers_getVirtualModifierList(ob);
ModifierData *pretessellatePoint;
2012-05-06 17:22:54 +00:00
Curve *cu = ob->data;
ListBase *nurb = BKE_curve_nurbs_get(cu);
int required_mode = 0, totvert = 0;
int editmode = (!forRender && (cu->editnurb || cu->editfont));
2012-05-06 17:22:54 +00:00
DerivedMesh *dm = NULL, *ndm;
float (*vertCos)[3] = NULL;
int useCache = !forRender;
ModifierApplyFlag app_flag = 0;
if (forRender) {
app_flag |= MOD_APPLY_RENDER;
2012-05-07 06:58:03 +00:00
required_mode = eModifierMode_Render;
}
2012-05-07 06:58:03 +00:00
else
required_mode = eModifierMode_Realtime;
pretessellatePoint = curve_get_tessellate_point(scene, ob, forRender, editmode);
2012-05-07 06:58:03 +00:00
if (editmode)
required_mode |= eModifierMode_Editmode;
if (pretessellatePoint) {
md = pretessellatePoint->next;
}
if (derivedFinal && *derivedFinal) {
2012-05-06 17:22:54 +00:00
(*derivedFinal)->release(*derivedFinal);
}
2012-05-06 17:22:54 +00:00
for (; md; md = md->next) {
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
ModifierApplyFlag appf = app_flag;
2012-05-06 17:22:54 +00:00
md->scene = scene;
if (!modifier_isEnabled(scene, md, required_mode))
2012-05-07 06:58:03 +00:00
continue;
if (mti->type == eModifierTypeType_OnlyDeform ||
(mti->type == eModifierTypeType_DeformOrConstruct && !dm))
{
if (editmode)
appf |= MOD_APPLY_USECACHE;
if (dm) {
if (!vertCos) {
totvert = dm->getNumVerts(dm);
vertCos = MEM_mallocN(sizeof(*vertCos) * totvert, "dfmv");
dm->getVertCos(dm, vertCos);
}
mti->deformVerts(md, ob, dm, vertCos, totvert, appf);
}
else {
if (!vertCos) {
2012-05-06 17:22:54 +00:00
vertCos = displist_get_allverts(dispbase, &totvert);
}
mti->deformVerts(md, ob, NULL, vertCos, totvert, appf);
}
}
else {
if (!derivedFinal) {
2012-05-07 06:58:03 +00:00
/* makeDisplistCurveTypes could be used for beveling, where derived mesh
* is totally unnecessary, so we could stop modifiers applying
* when we found constructive modifier but derived mesh is unwanted result
*/
break;
}
if (dm) {
if (vertCos) {
DerivedMesh *tdm = CDDM_copy(dm);
dm->release(dm);
dm = tdm;
CDDM_apply_vert_coords(dm, vertCos);
CDDM_calc_normals_mapping(dm);
}
}
else {
if (vertCos) {
displist_apply_allverts(dispbase, vertCos);
}
if (ELEM(ob->type, OB_CURVE, OB_FONT) && (cu->flag & CU_DEFORM_FILL)) {
curve_to_filledpoly(cu, nurb, dispbase);
}
dm = CDDM_from_curve_displist(ob, dispbase);
CDDM_calc_normals_mapping(dm);
}
if (vertCos) {
/* Vertex coordinates were applied to necessary data, could free it */
MEM_freeN(vertCos);
2012-05-06 17:22:54 +00:00
vertCos = NULL;
}
if (useCache)
appf |= MOD_APPLY_USECACHE;
ndm = mti->applyModifier(md, ob, dm, appf);
if (ndm) {
/* Modifier returned a new derived mesh */
if (dm && dm != ndm) /* Modifier */
2012-05-06 17:22:54 +00:00
dm->release(dm);
dm = ndm;
}
}
}
if (vertCos) {
if (dm) {
DerivedMesh *tdm = CDDM_copy(dm);
dm->release(dm);
dm = tdm;
CDDM_apply_vert_coords(dm, vertCos);
CDDM_calc_normals_mapping(dm);
MEM_freeN(vertCos);
}
else {
displist_apply_allverts(dispbase, vertCos);
MEM_freeN(vertCos);
2012-05-06 17:22:54 +00:00
vertCos = NULL;
}
}
if (derivedFinal) {
2012-05-07 06:58:03 +00:00
if (dm)
DM_ensure_tessface(dm); /* needed for drawing */
(*derivedFinal) = dm;
}
if (deformedVerts) {
BK_curve_vertexCos_apply(ob->data, nurb, originalVerts);
MEM_freeN(originalVerts);
MEM_freeN(deformedVerts);
}
}
static void displist_surf_indices(DispList *dl)
{
int a, b, p1, p2, p3, p4;
int *index;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl->totindex = 0;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
index = dl->index = MEM_mallocN(4 * sizeof(int) * (dl->parts + 1) * (dl->nr + 1), "index array nurbs");
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
for (a = 0; a < dl->parts; a++) {
2012-05-07 06:58:03 +00:00
if (BKE_displist_surfindex_get(dl, a, &b, &p1, &p2, &p3, &p4) == 0)
break;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
for (; b < dl->nr; b++, index += 4) {
index[0] = p1;
index[1] = p2;
index[2] = p4;
index[3] = p3;
2012-05-07 06:58:03 +00:00
dl->totindex++;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
p2 = p1; p1++;
p4 = p3; p3++;
}
}
}
static DerivedMesh *create_orco_dm(Scene *scene, Object *ob)
{
DerivedMesh *dm;
2012-05-06 17:22:54 +00:00
ListBase disp = {NULL, NULL};
/* OrcoDM should be created from underformed disp lists */
2012-05-07 06:58:03 +00:00
BKE_displist_make_curveTypes_forOrco(scene, ob, &disp);
dm = CDDM_from_curve_displist(ob, &disp);
2012-05-07 06:58:03 +00:00
BKE_displist_free(&disp);
return dm;
}
static void add_orco_dm(Scene *scene, Object *ob, DerivedMesh *dm, DerivedMesh *orcodm)
{
float (*orco)[3], (*layerorco)[3];
int totvert, a;
2012-05-06 17:22:54 +00:00
Curve *cu = ob->data;
2012-05-06 17:22:54 +00:00
totvert = dm->getNumVerts(dm);
if (orcodm) {
2012-05-06 17:22:54 +00:00
orco = MEM_callocN(sizeof(float) * 3 * totvert, "dm orco");
if (orcodm->getNumVerts(orcodm) == totvert)
orcodm->getVertCos(orcodm, orco);
else
dm->getVertCos(dm, orco);
}
else {
2012-05-06 17:22:54 +00:00
orco = (float(*)[3])BKE_curve_make_orco(scene, ob);
}
2012-05-06 17:22:54 +00:00
for (a = 0; a < totvert; a++) {
float *co = orco[a];
2012-05-06 17:22:54 +00:00
co[0] = (co[0] - cu->loc[0]) / cu->size[0];
co[1] = (co[1] - cu->loc[1]) / cu->size[1];
co[2] = (co[2] - cu->loc[2]) / cu->size[2];
}
if ((layerorco = DM_get_vert_data_layer(dm, CD_ORCO))) {
2012-05-06 17:22:54 +00:00
memcpy(layerorco, orco, sizeof(float) * totvert);
MEM_freeN(orco);
}
else
DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, orco);
}
static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *derivedFinal, int forRender)
{
2012-05-07 06:58:03 +00:00
/* this function represents logic of mesh's orcodm calculation
* for displist-based objects
*/
ModifierData *md = modifiers_getVirtualModifierList(ob);
ModifierData *pretessellatePoint;
2012-05-06 17:22:54 +00:00
Curve *cu = ob->data;
int required_mode;
int editmode = (!forRender && (cu->editnurb || cu->editfont));
2012-05-06 17:22:54 +00:00
DerivedMesh *ndm, *orcodm = NULL;
const ModifierApplyFlag app_flag = forRender ? MOD_APPLY_RENDER : 0;
2012-05-07 06:58:03 +00:00
if (forRender)
required_mode = eModifierMode_Render;
else
required_mode = eModifierMode_Realtime;
pretessellatePoint = curve_get_tessellate_point(scene, ob, forRender, editmode);
2012-05-07 06:58:03 +00:00
if (editmode)
required_mode |= eModifierMode_Editmode;
if (pretessellatePoint) {
md = pretessellatePoint->next;
}
2012-05-06 17:22:54 +00:00
for (; md; md = md->next) {
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
2012-05-06 17:22:54 +00:00
md->scene = scene;
if (!modifier_isEnabled(scene, md, required_mode))
2012-05-07 06:58:03 +00:00
continue;
if (mti->type != eModifierTypeType_Constructive)
continue;
if (!orcodm)
2012-05-06 17:22:54 +00:00
orcodm = create_orco_dm(scene, ob);
ndm = mti->applyModifier(md, ob, orcodm, app_flag);
if (ndm) {
/* if the modifier returned a new dm, release the old one */
if (orcodm && orcodm != ndm) {
orcodm->release(orcodm);
}
orcodm = ndm;
}
}
/* add an orco layer if needed */
add_orco_dm(scene, ob, derivedFinal, orcodm);
if (orcodm)
orcodm->release(orcodm);
}
2012-05-07 06:58:03 +00:00
void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
DerivedMesh **derivedFinal, int forRender, int forOrco)
{
ListBase *nubase;
Nurb *nu;
Curve *cu = ob->data;
DispList *dl;
float *data;
int len;
int numVerts;
float (*originalVerts)[3];
float (*deformedVerts)[3];
if (!forRender && cu->editnurb)
2012-05-06 17:22:54 +00:00
nubase = BKE_curve_editNurbs_get(cu);
else
2012-05-06 17:22:54 +00:00
nubase = &cu->nurb;
if (!forOrco)
curve_calc_modifiers_pre(scene, ob, forRender, &originalVerts, &deformedVerts, &numVerts);
2012-05-06 17:22:54 +00:00
for (nu = nubase->first; nu; nu = nu->next) {
if (forRender || nu->hide == 0) {
int resolu = nu->resolu, resolv = nu->resolv;
if (forRender) {
2012-05-07 06:58:03 +00:00
if (cu->resolu_ren)
resolu = cu->resolu_ren;
if (cu->resolv_ren)
resolv = cu->resolv_ren;
}
2012-05-06 17:22:54 +00:00
if (nu->pntsv == 1) {
len = SEGMENTSU(nu) * resolu;
2012-05-06 17:22:54 +00:00
dl = MEM_callocN(sizeof(DispList), "makeDispListsurf");
dl->verts = MEM_callocN(len * 3 * sizeof(float), "dlverts");
BLI_addtail(dispbase, dl);
2012-05-06 17:22:54 +00:00
dl->parts = 1;
dl->nr = len;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
/* dl->rt will be used as flag for render face and */
/* CU_2D conflicts with R_NOPUNOFLIP */
2012-05-06 17:22:54 +00:00
dl->rt = nu->flag & ~CU_2D;
2012-05-06 17:22:54 +00:00
data = dl->verts;
if (nu->flagu & CU_NURB_CYCLIC) dl->type = DL_POLY;
else dl->type = DL_SEGM;
2012-05-06 17:22:54 +00:00
BKE_nurb_makeCurve(nu, data, NULL, NULL, NULL, resolu, 3 * sizeof(float));
}
else {
2012-05-06 17:22:54 +00:00
len = (nu->pntsu * resolu) * (nu->pntsv * resolv);
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl = MEM_callocN(sizeof(DispList), "makeDispListsurf");
dl->verts = MEM_callocN(len * 3 * sizeof(float), "dlverts");
BLI_addtail(dispbase, dl);
2012-05-06 17:22:54 +00:00
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
/* dl->rt will be used as flag for render face and */
/* CU_2D conflicts with R_NOPUNOFLIP */
2012-05-06 17:22:54 +00:00
dl->rt = nu->flag & ~CU_2D;
2012-05-06 17:22:54 +00:00
data = dl->verts;
dl->type = DL_SURF;
2012-05-06 17:22:54 +00:00
dl->parts = (nu->pntsu * resolu); /* in reverse, because makeNurbfaces works that way */
dl->nr = (nu->pntsv * resolv);
if (nu->flagv & CU_NURB_CYCLIC) dl->flag |= DL_CYCL_U; /* reverse too! */
if (nu->flagu & CU_NURB_CYCLIC) dl->flag |= DL_CYCL_V;
BKE_nurb_makeFaces(nu, data, 0, resolu, resolv);
2012-05-07 06:58:03 +00:00
/* gl array drawing: using indices */
displist_surf_indices(dl);
2002-10-12 11:37:38 +00:00
}
}
}
/* make copy of 'undeformed" displist for texture space calculation
2012-03-09 18:28:30 +00:00
* actually, it's not totally undeformed -- pre-tessellation modifiers are
* already applied, thats how it worked for years, so keep for compatibility (sergey) */
2012-05-07 06:58:03 +00:00
BKE_displist_copy(&cu->disp, dispbase);
if (!forRender) {
2012-05-05 21:28:12 +00:00
BKE_curve_texspace_calc(cu);
}
2012-05-07 06:58:03 +00:00
if (!forOrco) {
curve_calc_modifiers_post(scene, ob, dispbase, derivedFinal,
2012-05-06 17:22:54 +00:00
forRender, originalVerts, deformedVerts);
2012-05-07 06:58:03 +00:00
}
}
static void rotateBevelPiece(Curve *cu, BevPoint *bevp, BevPoint *nbevp, DispList *dlb, float bev_blend, float widfac, float fac, float **data_r)
{
float *fp, *data = *data_r;
int b;
fp = dlb->verts;
2012-05-06 17:22:54 +00:00
for (b = 0; b < dlb->nr; b++, fp += 3, data += 3) {
if (cu->flag & CU_3D) {
float vec[3], quat[4];
2012-05-06 17:22:54 +00:00
vec[0] = fp[1] + widfac;
vec[1] = fp[2];
2012-05-06 17:22:54 +00:00
vec[2] = 0.0;
if (nbevp == NULL) {
copy_v3_v3(data, bevp->vec);
copy_qt_qt(quat, bevp->quat);
}
else {
interp_v3_v3v3(data, bevp->vec, nbevp->vec, bev_blend);
interp_qt_qtqt(quat, bevp->quat, nbevp->quat, bev_blend);
}
mul_qt_v3(quat, vec);
data[0] += fac * vec[0];
data[1] += fac * vec[1];
data[2] += fac * vec[2];
}
else {
float sina, cosa;
if (nbevp == NULL) {
copy_v3_v3(data, bevp->vec);
sina = bevp->sina;
cosa = bevp->cosa;
}
else {
interp_v3_v3v3(data, bevp->vec, nbevp->vec, bev_blend);
/* perhaps we need to interpolate angles instead. but the thing is
* cosa and sina are not actually sine and cosine
*/
sina = nbevp->sina * bev_blend + bevp->sina * (1.0f - bev_blend);
cosa = nbevp->cosa * bev_blend + bevp->cosa * (1.0f - bev_blend);
}
data[0] += fac * (widfac + fp[1]) * sina;
data[1] += fac * (widfac + fp[1]) * cosa;
data[2] += fac * fp[2];
}
}
*data_r = data;
}
static void fillBevelCap(Nurb *nu, DispList *dlb, float *prev_fp, ListBase *dispbase)
{
DispList *dl;
float *data;
int b;
2012-05-06 17:22:54 +00:00
dl = MEM_callocN(sizeof(DispList), "makeDispListbev2");
dl->verts = data = MEM_callocN(3 * sizeof(float) * dlb->nr, "dlverts");
2012-05-06 17:22:54 +00:00
dl->type = DL_POLY;
2012-05-06 17:22:54 +00:00
dl->parts = 1;
dl->nr = dlb->nr;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
/* dl->rt will be used as flag for render face and */
/* CU_2D conflicts with R_NOPUNOFLIP */
2012-05-06 17:22:54 +00:00
dl->rt = nu->flag & ~CU_2D;
for (b = 0; b < dlb->nr; b++, prev_fp += 3, data += 3)
copy_v3_v3(data, prev_fp);
BLI_addtail(dispbase, dl);
}
static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispbase,
2012-05-06 17:22:54 +00:00
DerivedMesh **derivedFinal, int forRender, int forOrco)
{
Curve *cu = ob->data;
/* we do allow duplis... this is only displist on curve level */
if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT)) return;
2012-05-06 17:22:54 +00:00
if (ob->type == OB_SURF) {
2012-05-07 06:58:03 +00:00
BKE_displist_make_surf(scene, ob, dispbase, derivedFinal, forRender, forOrco);
2002-10-12 11:37:38 +00:00
}
else if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
ListBase dlbev;
ListBase *nubase;
float (*originalVerts)[3];
float (*deformedVerts)[3];
int numVerts;
2012-05-06 17:22:54 +00:00
nubase = BKE_curve_nurbs_get(cu);
Result of 2 weeks of quiet coding work in Greece :) Aim was to get a total refresh of the animation system. This is needed because; - we need to upgrade it with 21st century features - current code is spaghetti/hack combo, and hides good design - it should become lag-free with using dependency graphs A full log, with complete code API/structure/design explanation will follow, that's a load of work... so here below the list with hot changes; - The entire object update system (matrices, geometry) is now centralized. Calls to where_is_object and makeDispList are forbidden, instead we tag objects 'changed' and let the depgraph code sort it out - Removed all old "Ika" code - Depgraph is aware of all relationships, including meta balls, constraints, bevelcurve, and so on. - Made depgraph aware of relation types and layers, to do smart flushing of 'changed' events. Nothing gets calculated too often! - Transform uses depgraph to detect changes - On frame-advance, depgraph flushes animated changes Armatures; Almost all armature related code has been fully built from scratch. It now reveils the original design much better, with a very clean implementation, lag free without even calculating each Bone more than once. Result is quite a speedup yes! Important to note is; 1) Armature is data containing the 'rest position' 2) Pose is the changes of rest position, and always on object level. That way more Objects can use same Pose. Also constraints are in Pose 3) Actions only contain the Ipos to change values in Poses. - Bones draw unrotated now - Drawing bones speedup enormously (10-20 times) - Bone selecting in EditMode, selection state is saved for PoseMode, and vice-versa - Undo in editmode - Bone renaming does vertexgroups, constraints, posechannels, actions, for all users of Armature in entire file - Added Bone renaming in NKey panel - Nkey PoseMode shows eulers now - EditMode and PoseMode now have 'active' bone too (last clicked) - Parenting in EditMode' CTRL+P, ALT+P, with nice options! - Pose is added in Outliner now, with showing that constraints are in the Pose, not Armature - Disconnected IK solving from constraints. It's a separate phase now, on top of the full Pose calculations - Pose itself has a dependency graph too, so evaluation order is lag free. TODO NOW; - Rotating in Posemode has incorrect inverse transform (Martin will fix) - Python Bone/Armature/Pose API disabled... needs full recode too (wait for my doc!) - Game engine will need upgrade too - Depgraph code needs revision, cleanup, can be much faster! (But, compliments for Jean-Luc, it works like a charm!) - IK changed, it now doesnt use previous position to advance to next position anymore. That system looks nice (no flips) but is not well suited for NLA and background render. TODO LATER; We now can do loadsa new nifty features as well; like: - Kill PoseMode (can be option for armatures itself) - Make B-Bones (Bezier, Bspline, like for spines) - Move all silly button level edit to 3d window (like CTRL+I = add IK) - Much better & informative drawing - Fix action/nla editors - Put all ipos in Actions (object, mesh key, lamp color) - Add hooks - Null bones - Much more advanced constraints... Bugfixes; - OGL render (view3d header) had wrong first frame on anim render - Ipo 'recording' mode had wrong playback speed - Vertex-key mode now sticks to show 'active key', until frame change -Ton-
2005-07-03 17:35:38 +00:00
BLI_freelistN(&(cu->bev));
if (cu->path) free_path(cu->path);
2012-05-06 17:22:54 +00:00
cu->path = NULL;
2012-05-07 06:58:03 +00:00
if (ob->type == OB_FONT)
BKE_vfont_to_curve(G.main, scene, ob, 0);
2012-05-07 06:58:03 +00:00
if (!forOrco)
curve_calc_modifiers_pre(scene, ob, forRender, &originalVerts, &deformedVerts, &numVerts);
BKE_curve_bevelList_make(ob);
/* If curve has no bevel will return nothing */
BKE_curve_bevel_make(scene, ob, &dlbev, forRender);
2002-10-12 11:37:38 +00:00
/* no bevel or extrude, and no width correction? */
2012-05-06 17:22:54 +00:00
if (!dlbev.first && cu->width == 1.0f) {
curve_to_displist(cu, nubase, dispbase, forRender);
}
else {
2012-05-06 17:22:54 +00:00
float widfac = cu->width - 1.0f;
BevList *bl = cu->bev.first;
Nurb *nu = nubase->first;
2012-05-06 17:22:54 +00:00
for (; bl && nu; bl = bl->next, nu = nu->next) {
DispList *dl;
float *data;
BevPoint *bevp;
int a;
if (bl->nr) { /* blank bevel lists can happen */
/* exception handling; curve without bevel or extrude, with width correction */
2012-05-06 17:22:54 +00:00
if (dlbev.first == NULL) {
dl = MEM_callocN(sizeof(DispList), "makeDispListbev");
dl->verts = MEM_callocN(3 * sizeof(float) * bl->nr, "dlverts");
BLI_addtail(dispbase, dl);
2012-05-06 17:22:54 +00:00
if (bl->poly != -1) dl->type = DL_POLY;
else dl->type = DL_SEGM;
2012-05-06 17:22:54 +00:00
if (dl->type == DL_SEGM) dl->flag = (DL_FRONT_CURVE | DL_BACK_CURVE);
2012-05-06 17:22:54 +00:00
dl->parts = 1;
dl->nr = bl->nr;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
/* dl->rt will be used as flag for render face and */
/* CU_2D conflicts with R_NOPUNOFLIP */
2012-05-06 17:22:54 +00:00
dl->rt = nu->flag & ~CU_2D;
2012-05-06 17:22:54 +00:00
a = dl->nr;
bevp = (BevPoint *)(bl + 1);
data = dl->verts;
while (a--) {
2012-05-06 17:22:54 +00:00
data[0] = bevp->vec[0] + widfac * bevp->sina;
data[1] = bevp->vec[1] + widfac * bevp->cosa;
data[2] = bevp->vec[2];
bevp++;
2012-05-06 17:22:54 +00:00
data += 3;
}
}
else {
DispList *dlb;
ListBase bottom_capbase = {NULL, NULL};
ListBase top_capbase = {NULL, NULL};
2012-05-06 17:22:54 +00:00
for (dlb = dlbev.first; dlb; dlb = dlb->next) {
const float bevfac1 = min_ff(cu->bevfac1, cu->bevfac2);
const float bevfac2 = max_ff(cu->bevfac1, cu->bevfac2);
float firstblend = 0.0f, lastblend = 0.0f;
int i, start, steps;
if (bevfac2 - bevfac1 == 0.0f)
continue;
2012-05-06 17:22:54 +00:00
start = (int)(bevfac1 * (bl->nr - 1));
steps = 2 + (int)((bevfac2) * (bl->nr - 1)) - start;
firstblend = 1.0f - (bevfac1 * (bl->nr - 1) - (int)(bevfac1 * (bl->nr - 1)));
lastblend = bevfac2 * (bl->nr - 1) - (int)(bevfac2 * (bl->nr - 1));
if (start + steps > bl->nr) {
steps = bl->nr - start;
lastblend = 1.0f;
}
/* for each part of the bevel use a separate displblock */
2012-05-06 17:22:54 +00:00
dl = MEM_callocN(sizeof(DispList), "makeDispListbev1");
dl->verts = data = MEM_callocN(3 * sizeof(float) * dlb->nr * steps, "dlverts");
BLI_addtail(dispbase, dl);
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl->type = DL_SURF;
2012-05-07 06:58:03 +00:00
2012-05-06 17:22:54 +00:00
dl->flag = dlb->flag & (DL_FRONT_CURVE | DL_BACK_CURVE);
if (dlb->type == DL_POLY) dl->flag |= DL_CYCL_U;
if (bl->poly >= 0) dl->flag |= DL_CYCL_V;
2012-05-06 17:22:54 +00:00
dl->parts = steps;
dl->nr = dlb->nr;
dl->col = nu->mat_nr;
dl->charidx = nu->charidx;
/* dl->rt will be used as flag for render face and */
/* CU_2D conflicts with R_NOPUNOFLIP */
2012-05-06 17:22:54 +00:00
dl->rt = nu->flag & ~CU_2D;
dl->bevelSplitFlag = MEM_callocN(sizeof(*dl->col2) * ((steps + 0x1F) >> 5),
"bevelSplitFlag");
2012-05-07 06:58:03 +00:00
/* for each point of poly make a bevel piece */
2012-05-06 17:22:54 +00:00
bevp = (BevPoint *)(bl + 1) + start;
for (i = start, a = 0; a < steps; i++, bevp++, a++) {
float fac = 1.0;
float *cur_data = data;
2012-05-06 17:22:54 +00:00
if (cu->taperobj == NULL) {
fac = bevp->radius;
}
else {
float len, taper_fac;
if (cu->flag & CU_MAP_TAPER) {
len = (steps - 3) + firstblend + lastblend;
if (a == 0)
taper_fac = 0.0f;
else if (a == steps - 1)
taper_fac = 1.0f;
else
taper_fac = ((float) a - (1.0f - firstblend)) / len;
}
else {
len = bl->nr - 1;
taper_fac = (float) i / len;
if (a == 0)
taper_fac += (1.0f - firstblend) / len;
else if (a == steps - 1)
taper_fac -= (1.0f - lastblend) / len;
}
fac = displist_calc_taper(scene, cu->taperobj, taper_fac);
}
if (bevp->split_tag) {
2012-05-06 17:22:54 +00:00
dl->bevelSplitFlag[a >> 5] |= 1 << (a & 0x1F);
}
2012-05-07 06:58:03 +00:00
/* rotate bevel piece and write in data */
if (a == 0)
rotateBevelPiece(cu, bevp, bevp + 1, dlb, 1.0f - firstblend, widfac, fac, &data);
else if (a == steps - 1)
rotateBevelPiece(cu, bevp, bevp - 1, dlb, 1.0f - lastblend, widfac, fac, &data);
else
rotateBevelPiece(cu, bevp, NULL, dlb, 0.0f, widfac, fac, &data);
if (cu->bevobj && (cu->flag & CU_FILL_CAPS)) {
2012-05-07 06:58:03 +00:00
if (a == 1)
2012-05-06 17:22:54 +00:00
fillBevelCap(nu, dlb, cur_data - 3 * dlb->nr, &bottom_capbase);
if (a == steps - 1)
fillBevelCap(nu, dlb, cur_data, &top_capbase);
}
2002-10-12 11:37:38 +00:00
}
/* gl array drawing: using indices */
displist_surf_indices(dl);
2002-10-12 11:37:38 +00:00
}
if (bottom_capbase.first) {
2012-05-07 06:58:03 +00:00
BKE_displist_fill(&bottom_capbase, dispbase, 1);
BKE_displist_fill(&top_capbase, dispbase, 0);
BKE_displist_free(&bottom_capbase);
BKE_displist_free(&top_capbase);
2002-10-12 11:37:38 +00:00
}
}
}
}
2012-05-07 06:58:03 +00:00
BKE_displist_free(&dlbev);
2002-10-12 11:37:38 +00:00
}
if (!(cu->flag & CU_DEFORM_FILL)) {
curve_to_filledpoly(cu, nubase, dispbase);
}
2012-05-07 06:58:03 +00:00
if ((cu->flag & CU_PATH) && !forOrco)
calc_curvepath(ob);
2002-10-12 11:37:38 +00:00
/* make copy of 'undeformed" displist for texture space calculation
2012-03-09 18:28:30 +00:00
* actually, it's not totally undeformed -- pre-tessellation modifiers are
* already applied, thats how it worked for years, so keep for compatibility (sergey) */
2012-05-07 06:58:03 +00:00
BKE_displist_copy(&cu->disp, dispbase);
if (!forRender) {
2012-05-05 21:28:12 +00:00
BKE_curve_texspace_calc(cu);
}
2012-05-07 06:58:03 +00:00
if (!forOrco)
curve_calc_modifiers_post(scene, ob, dispbase, derivedFinal, forRender, originalVerts, deformedVerts);
if (cu->flag & CU_DEFORM_FILL && !ob->derivedFinal) {
curve_to_filledpoly(cu, nubase, dispbase);
}
2002-10-12 11:37:38 +00:00
}
}
2012-05-07 06:58:03 +00:00
void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco)
{
2012-05-06 17:22:54 +00:00
Curve *cu = ob->data;
ListBase *dispbase;
/* The same check for duplis as in do_makeDispListCurveTypes.
2012-03-09 18:28:30 +00:00
* Happens when curve used for constraint/bevel was converted to mesh.
* check there is still needed for render displist and orco displists. */
2012-05-07 06:58:03 +00:00
if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT))
return;
2012-05-07 06:58:03 +00:00
BKE_displist_free(&(ob->disp));
2012-05-06 17:22:54 +00:00
dispbase = &(ob->disp);
2012-05-07 06:58:03 +00:00
BKE_displist_free(dispbase);
/* free displist used for textspace */
2012-05-07 06:58:03 +00:00
BKE_displist_free(&cu->disp);
do_makeDispListCurveTypes(scene, ob, dispbase, &ob->derivedFinal, 0, forOrco);
if (ob->derivedFinal) {
2012-05-06 17:22:54 +00:00
DM_set_object_boundbox(ob, ob->derivedFinal);
/* always keep curve's BB in sync with non-deformed displist */
if (cu->bb == NULL)
cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
boundbox_dispbase(cu->bb, &cu->disp);
}
else {
2012-05-06 17:22:54 +00:00
boundbox_displist(ob);
}
}
2012-05-07 06:58:03 +00:00
void BKE_displist_make_curveTypes_forRender(Scene *scene, Object *ob, ListBase *dispbase,
2012-05-06 17:22:54 +00:00
DerivedMesh **derivedFinal, int forOrco)
{
do_makeDispListCurveTypes(scene, ob, dispbase, derivedFinal, 1, forOrco);
}
2012-05-07 06:58:03 +00:00
void BKE_displist_make_curveTypes_forOrco(struct Scene *scene, struct Object *ob, struct ListBase *dispbase)
{
do_makeDispListCurveTypes(scene, ob, dispbase, NULL, 1, 1);
}
/* add Orco layer to the displist object which has got derived mesh and return orco */
2012-05-07 06:58:03 +00:00
float *BKE_displist_make_orco(Scene *scene, Object *ob, DerivedMesh *derivedFinal, int forRender)
{
float *orco;
if (derivedFinal == NULL)
2012-05-06 17:22:54 +00:00
derivedFinal = ob->derivedFinal;
if (!derivedFinal->getVertDataArray(derivedFinal, CD_ORCO)) {
curve_calc_orcodm(scene, ob, derivedFinal, forRender);
}
2012-05-06 17:22:54 +00:00
orco = derivedFinal->getVertDataArray(derivedFinal, CD_ORCO);
if (orco) {
2012-05-06 17:22:54 +00:00
orco = MEM_dupallocN(orco);
}
return orco;
2002-10-12 11:37:38 +00:00
}
static void boundbox_dispbase(BoundBox *bb, ListBase *dispbase)
2002-10-12 11:37:38 +00:00
{
float min[3], max[3];
DispList *dl;
float *vert;
2012-05-06 17:22:54 +00:00
int a, tot = 0;
int doit = 0;
2012-05-07 06:58:03 +00:00
2002-10-12 11:37:38 +00:00
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;
for (a = 0; a < tot; a++, vert += 3) {
minmax_v3v3_v3(min, max, vert);
}
doit |= (tot != 0);
}
if (!doit) {
/* there's no geometry in displist, use zero-sized boundbox */
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... */
static void boundbox_displist(Object *ob)
{
if (ELEM3(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
2012-05-06 17:22:54 +00:00
Curve *cu = ob->data;
2002-10-12 11:37:38 +00:00
/* calculate curve's BB based on non-deformed displist */
if (cu->bb == NULL)
cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
2012-05-07 06:58:03 +00:00
boundbox_dispbase(cu->bb, &cu->disp);
2012-05-07 06:58:03 +00:00
/* object's BB is calculated from final displist */
if (ob->bb == NULL)
ob->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
2012-05-07 06:58:03 +00:00
boundbox_dispbase(ob->bb, &ob->disp);
2002-10-12 11:37:38 +00:00
}
}