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/anim.c

554 lines
13 KiB
C
Raw Normal View History

/** anim.c
*
*
2002-10-12 11:37:38 +00:00
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* 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. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* 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,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* 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/BL DUAL LICENSE BLOCK *****
*/
#include <math.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "DNA_listBase.h"
#include "DNA_object_types.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
#include "DNA_view3d_types.h"
#include "DNA_effect_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_scene_types.h"
#include "BKE_global.h"
#include "BKE_utildefines.h"
#include "BKE_anim.h"
#include "BKE_ipo.h"
#include "BKE_object.h"
#include "BKE_displist.h"
#include "BKE_key.h"
#include "BKE_font.h"
#include "BKE_effect.h"
#include "BKE_bad_level_calls.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
2002-10-12 11:37:38 +00:00
ListBase duplilist= {0, 0};
void free_path(Path *path)
{
if(path->data) MEM_freeN(path->data);
MEM_freeN(path);
}
void calc_curvepath(Object *ob)
{
BevList *bl;
2002-10-30 00:37:19 +00:00
BevPoint *bevp, *bevpn, *bevpfirst, *bevplast, *tempbevp;
2002-10-12 11:37:38 +00:00
Curve *cu;
Nurb *nu;
Path *path;
float *fp, *dist, *maxdist, x, y, z;
float fac, d=0, fac1, fac2;
int a, tot, cycl=0;
float *ft;
/* in a path vertices are with equal differences: path->len = number of verts */
/* NOW WITH BEVELCURVE!!! */
2002-10-12 11:37:38 +00:00
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
if(ob==NULL || ob->type != OB_CURVE) return;
2002-10-12 11:37:38 +00:00
cu= ob->data;
if(ob==G.obedit) nu= editNurb.first;
else nu= cu->nurb.first;
if(cu->path) free_path(cu->path);
cu->path= NULL;
2002-10-12 11:37:38 +00:00
bl= cu->bev.first;
if(bl==NULL) return;
2002-10-12 11:37:38 +00:00
cu->path=path= MEM_callocN(sizeof(Path), "path");
/* if POLY: last vertice != first vertice */
2002-10-12 11:37:38 +00:00
cycl= (bl->poly!= -1);
if(cycl) tot= bl->nr;
else tot= bl->nr-1;
path->len= tot+1;
/* exception: vector handle paths and polygon paths should be subdivided at least a factor 6 (or more?) */
if(path->len<6*nu->pntsu) path->len= 6*nu->pntsu;
dist= (float *)MEM_mallocN((tot+1)*4, "calcpathdist");
2002-10-12 11:37:38 +00:00
/* all lengths in *dist */
2002-10-12 11:37:38 +00:00
bevp= bevpfirst= (BevPoint *)(bl+1);
fp= dist;
*fp= 0;
for(a=0; a<tot; a++) {
fp++;
if(cycl && a==tot-1) {
x= bevpfirst->x - bevp->x;
y= bevpfirst->y - bevp->y;
z= bevpfirst->z - bevp->z;
}
else {
2002-10-30 00:37:19 +00:00
tempbevp = bevp+1;
x= (tempbevp)->x - bevp->x;
y= (tempbevp)->y - bevp->y;
z= (tempbevp)->z - bevp->z;
2002-10-12 11:37:38 +00:00
}
*fp= *(fp-1)+ (float)sqrt(x*x+y*y+z*z);
bevp++;
}
path->totdist= *fp;
/* the path verts in path->data */
/* now also with TILT value */
2002-10-12 11:37:38 +00:00
ft= path->data = (float *)MEM_callocN(16*path->len, "pathdata");
bevp= bevpfirst;
bevpn= bevp+1;
bevplast= bevpfirst + (bl->nr-1);
fp= dist+1;
maxdist= dist+tot;
fac= 1.0f/((float)path->len-1.0f);
2002-10-30 00:37:19 +00:00
fac = fac * path->totdist;
2002-10-12 11:37:38 +00:00
for(a=0; a<path->len; a++) {
2002-10-30 00:37:19 +00:00
d= ((float)a)*fac;
2002-10-12 11:37:38 +00:00
/* we're looking for location (distance) 'd' in the array */
2002-10-12 11:37:38 +00:00
while((d>= *fp) && fp<maxdist) {
fp++;
if(bevp<bevplast) bevp++;
bevpn= bevp+1;
if(bevpn>bevplast) {
if(cycl) bevpn= bevpfirst;
else bevpn= bevplast;
}
}
fac1= *(fp)- *(fp-1);
fac2= *(fp)-d;
fac1= fac2/fac1;
fac2= 1.0f-fac1;
ft[0]= fac1*bevp->x+ fac2*(bevpn)->x;
ft[1]= fac1*bevp->y+ fac2*(bevpn)->y;
ft[2]= fac1*bevp->z+ fac2*(bevpn)->z;
ft[3]= fac1*bevp->alfa+ fac2*(bevpn)->alfa;
ft+= 4;
}
MEM_freeN(dist);
}
int interval_test(int min, int max, int p1, int cycl)
{
if(cycl) {
if( p1 < min)
p1= ((p1 -min) % (max-min+1)) + max+1;
else if(p1 > max)
p1= ((p1 -min) % (max-min+1)) + min;
}
else {
if(p1 < min) p1= min;
else if(p1 > max) p1= max;
}
return p1;
}
/* warning, *vec needs FOUR items! */
int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* returns OK */
2002-10-12 11:37:38 +00:00
{
Curve *cu;
Nurb *nu;
BevList *bl;
Path *path;
float *fp, *p0, *p1, *p2, *p3, fac;
float data[4];
int cycl=0, s0, s1, s2, s3;
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
if(ob==NULL || ob->type != OB_CURVE) return 0;
2002-10-12 11:37:38 +00:00
cu= ob->data;
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
if(cu->path==NULL || cu->path->data==NULL) {
printf("no path!\n");
}
2002-10-12 11:37:38 +00:00
path= cu->path;
fp= path->data;
/* test for cyclic */
2002-10-12 11:37:38 +00:00
bl= cu->bev.first;
if(bl && bl->poly> -1) cycl= 1;
ctime *= (path->len-1);
s1= (int)floor(ctime);
fac= (float)(s1+1)-ctime;
/* path->len is corected for cyclic */
2002-10-12 11:37:38 +00:00
s0= interval_test(0, path->len-1-cycl, s1-1, cycl);
s1= interval_test(0, path->len-1-cycl, s1, cycl);
s2= interval_test(0, path->len-1-cycl, s1+1, cycl);
s3= interval_test(0, path->len-1-cycl, s1+2, cycl);
p0= fp + 4*s0;
p1= fp + 4*s1;
p2= fp + 4*s2;
p3= fp + 4*s3;
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
/* note, commented out for follow constraint */
//if(cu->flag & CU_FOLLOW) {
2002-10-12 11:37:38 +00:00
set_afgeleide_four_ipo(1.0f-fac, data, KEY_BSPLINE);
dir[0]= data[0]*p0[0] + data[1]*p1[0] + data[2]*p2[0] + data[3]*p3[0] ;
dir[1]= data[0]*p0[1] + data[1]*p1[1] + data[2]*p2[1] + data[3]*p3[1] ;
dir[2]= data[0]*p0[2] + data[1]*p1[2] + data[2]*p2[2] + data[3]*p3[2] ;
/* make compatible with vectoquat */
2002-10-12 11:37:38 +00:00
dir[0]= -dir[0];
dir[1]= -dir[1];
dir[2]= -dir[2];
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
nu= cu->nurb.first;
/* make sure that first and last frame are included in the vectors here */
2002-10-12 11:37:38 +00:00
if((nu->type & 7)==CU_POLY) set_four_ipo(1.0f-fac, data, KEY_LINEAR);
else if((nu->type & 7)==CU_BEZIER) set_four_ipo(1.0f-fac, data, KEY_LINEAR);
else if(s0==s1 || p2==p3) set_four_ipo(1.0f-fac, data, KEY_CARDINAL);
else set_four_ipo(1.0f-fac, data, KEY_BSPLINE);
vec[0]= data[0]*p0[0] + data[1]*p1[0] + data[2]*p2[0] + data[3]*p3[0] ;
vec[1]= data[0]*p0[1] + data[1]*p1[1] + data[2]*p2[1] + data[3]*p3[1] ;
vec[2]= data[0]*p0[2] + data[1]*p1[2] + data[2]*p2[2] + data[3]*p3[2] ;
vec[3]= data[0]*p0[3] + data[1]*p1[3] + data[2]*p2[3] + data[3]*p3[3] ;
return 1;
}
static Object *new_dupli_object(ListBase *lb, Object *ob, Object *par)
{
Object *newob;
newob= MEM_mallocN(sizeof(Object), "newobj dupli");
memcpy(newob, ob, sizeof(Object));
newob->flag |= OB_FROMDUPLI;
newob->id.newid= (ID *)par; /* store duplicator */
/* only basis-ball gets displist */
if(newob->type==OB_MBALL) newob->disp.first= newob->disp.last= NULL;
if(ob!=par) { // dupliverts, particle
newob->parent= NULL;
newob->track= NULL;
}
BLI_addtail(lb, newob);
return newob;
}
2002-10-12 11:37:38 +00:00
void frames_duplilist(Object *ob)
{
extern int enable_cu_speed; /* object.c */
Object *newob;
int cfrao, ok;
cfrao= G.scene->r.cfra;
if(ob->parent==0 && ob->track==0 && ob->ipo==0) return;
if(ob->transflag & OB_DUPLINOSPEED) enable_cu_speed= 0;
/* this to make sure that something is z-buffered in drawobject.c */
2002-10-12 11:37:38 +00:00
if(G.background==0 && ob->type==OB_MESH) {
Mesh *me= ob->data;
DispList *dl;
if(me->disp.first==0) addnormalsDispList(ob, &me->disp);
if(ob->dt==OB_SHADED) {
dl= ob->disp.first;
if(dl==0 || dl->col1==0) shadeDispList(ob);
}
}
for(G.scene->r.cfra= ob->dupsta; G.scene->r.cfra<=ob->dupend; G.scene->r.cfra++) {
ok= 1;
if(ob->dupoff) {
ok= G.scene->r.cfra - ob->dupsta;
ok= ok % (ob->dupon+ob->dupoff);
if(ok < ob->dupon) ok= 1;
else ok= 0;
}
if(ok) {
newob= new_dupli_object(&duplilist, ob, ob);
2002-10-12 11:37:38 +00:00
do_ob_ipo(newob);
where_is_object_time(newob, (float)G.scene->r.cfra);
2002-10-12 11:37:38 +00:00
}
}
G.scene->r.cfra= cfrao;
enable_cu_speed= 1;
do_ob_ipo(ob);
}
void vertex_duplilist(Scene *sce, Object *par)
{
Object *ob, *newob;
Base *base;
MVert *mvert;
Mesh *me;
DispList *dl;
float *extverts=NULL, vec[3], pvec[3], pmat[4][4], mat[3][3], tmat[4][4];
2002-10-12 11:37:38 +00:00
float *q2;
int lay, totvert, a;
Mat4CpyMat4(pmat, par->obmat);
Mat4One(tmat);
lay= G.scene->lay;
dl= find_displist(&par->disp, DL_VERTS);
if(dl) extverts= dl->verts;
2002-10-12 11:37:38 +00:00
base= sce->base.first;
while(base) {
if(base->object->type>0 && (lay & base->lay) && G.obedit!=base->object) {
ob= base->object->parent;
while(ob) {
if(ob==par) {
ob= base->object;
/* mballs have a different dupli handling */
if(ob->type!=OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */
me= par->data;
mvert= me->mvert;
mvert+= (me->totvert-1);
VECCOPY(pvec, mvert->co);
Mat4MulVecfl(pmat, pvec);
mvert= me->mvert;
totvert= me->totvert;
for(a=0; a<totvert; a++, mvert++) {
/* calc the extra offset for children (wrt. centre parent) */
if(extverts) {
VECCOPY(vec, extverts+3*a);
}
else {
VECCOPY(vec, mvert->co);
}
2002-10-12 11:37:38 +00:00
Mat4MulVecfl(pmat, vec);
VecSubf(vec, vec, pmat[3]);
VecAddf(vec, vec, ob->obmat[3]);
newob= new_dupli_object(&duplilist, ob, par);
2002-10-12 11:37:38 +00:00
VECCOPY(newob->obmat[3], vec);
if(par->transflag & OB_DUPLIROT) {
VECCOPY(vec, mvert->no);
vec[0]= -vec[0]; vec[1]= -vec[1]; vec[2]= -vec[2];
q2= vectoquat(vec, ob->trackflag, ob->upflag);
QuatToMat3(q2, mat);
Mat4CpyMat4(tmat, newob->obmat);
Mat4MulMat43(newob->obmat, tmat, mat);
}
VECCOPY(pvec, vec);
}
break;
}
ob= ob->parent;
}
}
base= base->next;
}
}
void particle_duplilist(Scene *sce, Object *par, PartEff *paf)
{
Object *ob, *newob;
Base *base;
Particle *pa;
float ctime, vec1[3];
float vec[3], tmat[4][4], mat[3][3];
float *q2;
int lay, a;
pa= paf->keys;
if(pa==0) {
build_particle_system(par);
pa= paf->keys;
if(pa==0) return;
}
ctime= bsystem_time(par, 0, (float)G.scene->r.cfra, 0.0);
lay= G.scene->lay;
base= sce->base.first;
while(base) {
if(base->object->type>0 && (base->lay & lay) && G.obedit!=base->object) {
ob= base->object->parent;
while(ob) {
if(ob==par) {
ob= base->object;
pa= paf->keys;
for(a=0; a<paf->totpart; a++, pa+=paf->totkey) {
if(paf->flag & PAF_STATIC) {
float mtime;
where_is_particle(paf, pa, pa->time, vec1);
mtime= pa->time+pa->lifetime;
for(ctime= pa->time; ctime<mtime; ctime+=paf->staticstep) {
newob= new_dupli_object(&duplilist, ob, par);
/* make sure hair grows until the end.. */
if(ctime>pa->time+pa->lifetime) ctime= pa->time+pa->lifetime;
2002-10-12 11:37:38 +00:00
/* to give ipos in object correct offset */
where_is_object_time(newob, ctime-pa->time);
where_is_particle(paf, pa, ctime, vec); // makes sure there's always a vec
Mat4MulVecfl(par->obmat, vec);
2002-10-12 11:37:38 +00:00
if(paf->stype==PAF_VECT) {
where_is_particle(paf, pa, ctime+1.0, vec1); // makes sure there's always a vec
Mat4MulVecfl(par->obmat, vec1);
2002-10-12 11:37:38 +00:00
VecSubf(vec1, vec1, vec);
q2= vectoquat(vec1, ob->trackflag, ob->upflag);
2002-10-12 11:37:38 +00:00
QuatToMat3(q2, mat);
Mat4CpyMat4(tmat, newob->obmat);
Mat4MulMat43(newob->obmat, tmat, mat);
}
2002-10-12 11:37:38 +00:00
VECCOPY(newob->obmat[3], vec);
}
}
else { // non static particles
if(ctime > pa->time) {
if(ctime < pa->time+pa->lifetime) {
newob= new_dupli_object(&duplilist, ob, par);
/* to give ipos in object correct offset */
where_is_object_time(newob, ctime-pa->time);
where_is_particle(paf, pa, ctime, vec);
if(paf->stype==PAF_VECT) {
where_is_particle(paf, pa, ctime+1.0f, vec1);
VecSubf(vec1, vec1, vec);
q2= vectoquat(vec1, ob->trackflag, ob->upflag);
2002-10-12 11:37:38 +00:00
QuatToMat3(q2, mat);
Mat4CpyMat4(tmat, newob->obmat);
Mat4MulMat43(newob->obmat, tmat, mat);
}
VECCOPY(newob->obmat[3], vec);
}
2002-10-12 11:37:38 +00:00
}
}
}
break;
}
ob= ob->parent;
}
}
base= base->next;
}
}
void free_duplilist()
{
Object *ob;
while( (ob= duplilist.first) ) {
2002-10-12 11:37:38 +00:00
BLI_remlink(&duplilist, ob);
MEM_freeN(ob);
}
}
void make_duplilist(Scene *sce, Object *ob)
{
PartEff *paf;
if(ob->transflag & OB_DUPLI) {
if(ob->transflag & OB_DUPLIVERTS) {
if(ob->type==OB_MESH) {
if(ob->transflag & OB_DUPLIVERTS) {
if( (paf=give_parteff(ob)) ) particle_duplilist(sce, ob, paf);
2002-10-12 11:37:38 +00:00
else vertex_duplilist(sce, ob);
}
}
else if(ob->type==OB_FONT) {
font_duplilist(ob);
}
}
else if(ob->transflag & OB_DUPLIFRAMES) frames_duplilist(ob);
}
}