~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/object.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* object.c
2
2
 *
3
3
 * 
4
 
 * $Id: object.c,v 1.16 2004/04/04 17:23:51 theeth Exp $
 
4
 * $Id: object.c,v 1.43 2005/05/20 20:44:33 ton Exp $
5
5
 *
6
6
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
7
7
 *
40
40
#include <config.h>
41
41
#endif
42
42
 
43
 
#ifdef WIN32
44
 
#include "BLI_winstuff.h"
45
 
#endif
46
43
#include "MEM_guardedalloc.h"
47
44
 
48
45
#include "DNA_action_types.h"
59
56
#include "DNA_mesh_types.h"
60
57
#include "DNA_meshdata_types.h"
61
58
#include "DNA_object_types.h"
 
59
#include "DNA_object_force.h"
 
60
#include "DNA_oops_types.h"
62
61
#include "DNA_scene_types.h"
63
62
#include "DNA_screen_types.h"
64
63
#include "DNA_space_types.h"
100
99
#include "BKE_lattice.h"
101
100
#include "BKE_constraint.h"
102
101
#include "BKE_scene.h"
 
102
#include "BKE_softbody.h"
103
103
 
104
104
#include "BPY_extern.h"
105
105
 
147
147
        }
148
148
}
149
149
 
 
150
static void free_hooks(ListBase *lb)
 
151
{
 
152
        while(lb->first) {
 
153
                ObHook *hook= lb->first;
 
154
                if(hook->indexar) MEM_freeN(hook->indexar);
 
155
                BLI_remlink(lb, hook);
 
156
                MEM_freeN(hook);
 
157
        }
 
158
}
 
159
 
 
160
static void copy_hooks(ListBase *new, ListBase *old)
 
161
{
 
162
        ObHook *hook, *hookn;
 
163
        new->first= new->last= NULL;
 
164
        
 
165
        for(hook= old->first; hook; hook= hook->next) {
 
166
                hookn= MEM_dupallocN(hook);
 
167
                hookn->indexar= MEM_dupallocN(hookn->indexar);
 
168
                BLI_addtail(new, hookn);
 
169
        }
 
170
 
 
171
}
 
172
 
150
173
/* do not free object itself */
151
174
void free_object(Object *ob)
152
175
{
192
215
        free_constraints(&ob->constraints);
193
216
        free_constraint_channels(&ob->constraintChannels);
194
217
        free_nlastrips(&ob->nlastrips);
195
 
 
 
218
        
 
219
        free_hooks(&ob->hooks);
 
220
        
196
221
        freedisplist(&ob->disp);
197
222
        
198
223
        BPY_free_scriptlink(&ob->scriptlink);
 
224
        
 
225
        if(ob->pd) MEM_freeN(ob->pd);
 
226
        if(ob->soft) sbFree(ob->soft);
199
227
}
200
228
 
201
229
void unlink_object(Object *ob)
207
235
        Scene *sce;
208
236
        Curve *cu;
209
237
        Tex *tex;
 
238
        ObHook *hook;
210
239
        Group *group;
211
240
        int a;
212
241
 
216
245
        /* check all objects: parents en bevels */
217
246
        obt= G.main->object.first;
218
247
        while(obt) {
219
 
                if(obt->id.lib==0) {
 
248
                if(obt->id.lib==NULL) {
220
249
                        if(obt->parent==ob) {
221
 
                                obt->parent= 0;
 
250
                                obt->parent= NULL;
222
251
                                if(ob->type==OB_LATTICE) freedisplist(&obt->disp);
223
252
                        }
224
 
                        if(obt->track==ob) obt->track= 0;
 
253
                        if(obt->track==ob) obt->track= NULL;
 
254
                        for(hook=obt->hooks.first; hook; hook= hook->next) {
 
255
                                if(hook->parent==ob) hook->parent= NULL;
 
256
                        }
225
257
                        if ELEM(obt->type, OB_CURVE, OB_FONT) {
226
258
                                cu= obt->data;
227
 
                                if(cu->bevobj==ob) cu->bevobj= 0;
228
 
                                if(cu->textoncurve==ob) cu->textoncurve= 0;
 
259
                                if(cu->bevobj==ob) cu->bevobj= NULL;
 
260
                                if(cu->taperobj==ob) cu->taperobj= NULL;
 
261
                                if(cu->textoncurve==ob) cu->textoncurve= NULL;
229
262
                        }
230
263
                        if(obt->type==OB_IKA) {
231
264
                                Ika *ika= obt->data;
232
265
                                Deform *def= ika->def;
233
266
                                
234
 
                                if(ika->parent==ob) ika->parent= 0;
 
267
                                if(ika->parent==ob) ika->parent= NULL;
235
268
                                a= ika->totdef;
236
269
                                while(a--) {
237
270
                                        if(def->ob==ob) {
238
271
                                                ika->totdef= 0;
239
272
                                                MEM_freeN(ika->def);
240
 
                                                ika->def= 0;
 
273
                                                ika->def= NULL;
241
274
                                                break;
242
275
                                        }
243
276
                                        def++;
252
285
        mat= G.main->mat.first;
253
286
        while(mat) {
254
287
        
255
 
                for(a=0; a<8; a++) {
 
288
                for(a=0; a<MAX_MTEX; a++) {
256
289
                        if(mat->mtex[a] && ob==mat->mtex[a]->object) {
257
290
                                /* actually, test for lib here... to do */
258
291
                                mat->mtex[a]->object= 0;
281
314
        wrld= G.main->world.first;
282
315
        while(wrld) {
283
316
                if(wrld->id.lib==0) {
284
 
                        for(a=0; a<6; a++) {
 
317
                        for(a=0; a<MAX_MTEX; a++) {
285
318
                                if(wrld->mtex[a] && ob==wrld->mtex[a]->object)
286
319
                                        wrld->mtex[a]->object =0;
287
320
                        }
320
353
                                                if(v3d->localvd->persp>1) v3d->localvd->persp= 1;
321
354
                                        }
322
355
                                }
 
356
                                else if(sl->spacetype==SPACE_IPO) {
 
357
                                        SpaceIpo *sipo= (SpaceIpo *)sl;
 
358
                                        if(sipo->from == (ID *)ob) sipo->from= NULL;
 
359
                                }
 
360
                                else if(sl->spacetype==SPACE_OOPS) {
 
361
                                        SpaceOops *so= (SpaceOops *)sl;
 
362
                                        Oops *oops;
 
363
 
 
364
                                        oops= so->oops.first;
 
365
                                        while(oops) {
 
366
                                                if(oops->id==(ID *)ob) oops->id= NULL;
 
367
                                                oops= oops->next;
 
368
                                        }
 
369
                                        if(so->treestore) {
 
370
                                                TreeStoreElem *tselem= so->treestore->data;
 
371
                                                int a;
 
372
                                                for(a=0; a<so->treestore->usedelem; a++, tselem++) {
 
373
                                                        if(tselem->id==(ID *)ob) tselem->id= NULL;
 
374
                                                }
 
375
                                        }
 
376
                                        so->lockpoin= NULL;
 
377
                                }
323
378
                        }
324
379
 
325
380
                        sa= sa->next;
357
412
        cam->clipsta= 0.1f;
358
413
        cam->clipend= 100.0f;
359
414
        cam->drawsize= 0.5f;
 
415
        cam->ortho_scale= 6.0;
360
416
        
361
417
        return cam;
362
418
}
462
518
        
463
519
        lan= copy_libblock(la);
464
520
 
465
 
        for(a=0; a<8; a++) {
 
521
        for(a=0; a<MAX_MTEX; a++) {
466
522
                if(lan->mtex[a]) {
467
523
                        lan->mtex[a]= MEM_mallocN(sizeof(MTex), "copylamptex");
468
524
                        memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex));
543
599
                
544
600
        BPY_free_scriptlink(&la->scriptlink);
545
601
        
546
 
        for(a=0; a<8; a++) {
 
602
        for(a=0; a<MAX_MTEX; a++) {
547
603
                mtex= la->mtex[a];
548
604
                if(mtex && mtex->tex) mtex->tex->id.us--;
549
605
                if(mtex) MEM_freeN(mtex);
645
701
                ob->upflag= OB_POSZ;
646
702
        }
647
703
        ob->ipoflag = OB_OFFS_OB+OB_OFFS_PARENT;
648
 
        
 
704
        ob->ipowin= ID_OB;      /* the ipowin shown */
649
705
        ob->dupon= 1; ob->dupoff= 0;
650
706
        ob->dupsta= 1; ob->dupend= 100;
651
707
 
690
746
        v3d->viewquat[0]= -v3d->viewquat[0];
691
747
}
692
748
 
 
749
SoftBody *copy_softbody(SoftBody *sb)
 
750
{
 
751
        SoftBody *sbn;
 
752
        
 
753
        if (sb==NULL) return(NULL);
 
754
        
 
755
        sbn= MEM_dupallocN(sb);
 
756
        sbn->totspring= sbn->totpoint= 0;
 
757
        sbn->bpoint= NULL;
 
758
        sbn->bspring= NULL;
 
759
        sbn->ctime= 0.0f;
 
760
        
 
761
        sbn->keys= NULL;
 
762
        sbn->totkey= sbn->totpointkey= 0;
 
763
        
 
764
        return sbn;
 
765
}
 
766
 
693
767
Object *copy_object(Object *ob)
694
768
{
695
769
        Object *obn;
722
796
        copy_nlastrips(&obn->nlastrips, &ob->nlastrips);
723
797
        copy_constraints (&obn->constraints, &ob->constraints);
724
798
 
 
799
        copy_hooks( &obn->hooks, &ob->hooks);
 
800
        
725
801
        actcon = clone_constraint_channels (&obn->constraintChannels, &ob->constraintChannels, ob->activecon);
726
802
        /* If the active constraint channel was in this list, update it */
727
803
        if (actcon)
728
804
                obn->activecon = actcon;
729
805
 
 
806
 
730
807
        /* increase user numbers */
731
808
        id_us_plus((ID *)obn->data);
732
809
        id_us_plus((ID *)obn->ipo);
733
810
        id_us_plus((ID *)obn->action);
734
811
        for(a=0; a<obn->totcol; a++) id_us_plus((ID *)obn->mat[a]);
735
812
        
736
 
        obn->disp.first= obn->disp.last= 0;
 
813
        obn->disp.first= obn->disp.last= NULL;
 
814
        
 
815
        if(ob->pd) obn->pd= MEM_dupallocN(ob->pd);
 
816
        obn->soft= copy_softbody(ob->soft);
737
817
        
738
818
        return obn;
739
819
}
833
913
        no_speed_curve= val;
834
914
}
835
915
 
 
916
/* ob can be NULL */
836
917
float bsystem_time(Object *ob, Object *par, float cfra, float ofs)
837
918
{
838
919
        /* returns float ( see frame_to_float in ipo.c) */
839
920
 
840
 
        if(no_speed_curve==0) if(ob && ob->ipo) cfra= calc_ipo_time(ob->ipo, cfra);
841
 
        
842
921
        /* 2nd field */
843
922
        if(R.flag & R_SEC_FIELD) {
844
923
                if(R.r.mode & R_FIELDSTILL); else cfra+= .5;
845
924
        }
846
925
 
847
 
        /* motion blur */
848
 
        cfra+= bluroffs;
849
926
 
850
 
        /* global time */
851
 
        cfra*= G.scene->r.framelen;     
 
927
        if(ob && (ob->flag & OB_FROMDUPLI));
 
928
        else {
 
929
                        /* motion blur */
 
930
                cfra+= bluroffs;
 
931
        
 
932
                /* global time */
 
933
                cfra*= G.scene->r.framelen;     
 
934
        }
 
935
        
 
936
        if(no_speed_curve==0) if(ob && ob->ipo) cfra= calc_ipo_time(ob->ipo, cfra);
852
937
        
853
938
        /* ofset frames */
854
939
        if(ob && (ob->ipoflag & OB_OFFS_PARENT)) {
923
1008
{
924
1009
        Curve *cu;
925
1010
        float q[4], vec[4], dir[3], *quat, x1, ctime;
 
1011
        float timeoffs= 0.0;
926
1012
        
927
1013
        Mat4One(mat);
928
1014
        
929
1015
        cu= par->data;
930
 
        if(cu->path==0 || cu->path->data==0) calc_curvepath(par);
931
 
        if(cu->path==0) return;
 
1016
        if(cu->path==NULL || cu->path->data==NULL) calc_curvepath(par);
 
1017
        if(cu->path==NULL) return;
 
1018
        
 
1019
        /* exception, timeoffset is regarded as distance offset */
 
1020
        if(cu->flag & CU_OFFS_PATHDIST) {
 
1021
                SWAP(float, timeoffs, ob->sf);
 
1022
        }
932
1023
        
933
1024
        /* catch exceptions: curve paths used as a duplicator */
934
1025
        if(enable_cu_speed) {
945
1036
                
946
1037
                CLAMP(ctime, 0.0, 1.0);
947
1038
        }
 
1039
        
 
1040
        /* time calculus is correct, now apply distance offset */
 
1041
        if(cu->flag & CU_OFFS_PATHDIST) {
 
1042
                ctime += timeoffs/cu->path->totdist;
948
1043
 
 
1044
                /* restore */
 
1045
                SWAP(float, timeoffs, ob->sf);
 
1046
        }
 
1047
        
 
1048
        
 
1049
        /* vec: 4 items! */
949
1050
        if( where_on_path(par, ctime, vec, dir) ) {
950
1051
 
951
1052
                if(cu->flag & CU_FOLLOW) {
952
1053
                        quat= vectoquat(dir, ob->trackflag, ob->upflag);
953
 
 
 
1054
                        
 
1055
                        /* the tilt */
954
1056
                        Normalise(dir);
955
1057
                        q[0]= (float)cos(0.5*vec[3]);
956
1058
                        x1= (float)sin(0.5*vec[3]);
1167
1269
static int during_script_flag=0;
1168
1270
void disable_where_script(short on)
1169
1271
{
1170
 
        during_script_flag= on; 
 
1272
        during_script_flag= on;
1171
1273
}
1172
1274
 
1173
1275
int during_script(void) {
1174
1276
        return during_script_flag;
1175
1277
}
1176
1278
 
 
1279
static int during_scriptlink_flag=0;
 
1280
void disable_where_scriptlink(short on)
 
1281
{
 
1282
        during_scriptlink_flag= on;
 
1283
}
 
1284
 
 
1285
int during_scriptlink(void) {
 
1286
        return during_scriptlink_flag;
 
1287
}
 
1288
 
1177
1289
void where_is_object_time(Object *ob, float ctime)
1178
1290
{
1179
1291
        Object *par;
1180
1292
        float *fp1, *fp2, slowmat[4][4] = MAT4_UNITY;
1181
 
        float stime, fac1, fac2;
 
1293
        float stime, fac1, fac2, vec[3];
1182
1294
        int a;
1183
1295
        int pop; 
1184
1296
        
1185
1297
        /* new version: correct parent+vertexparent and track+parent */
1186
1298
        /* this one only calculates direct attached parent and track */
1187
 
        /* hij is sneller, maar moet wel de timeoffs in de gaten houden */
 
1299
        /* is faster, but should keep track of timeoffs */
1188
1300
        
1189
1301
        if(ob==0) return;
1190
1302
 
1214
1326
                pop= 0;
1215
1327
                if(no_parent_ipo==0 && ctime != par->ctime) {
1216
1328
                
1217
 
                        // alleen voor ipo systemen? 
 
1329
                        // only for ipo systems? 
1218
1330
                        pushdata(par, sizeof(Object));
1219
1331
                        pop= 1;
1220
1332
                        
1228
1340
                }
1229
1341
                
1230
1342
                if(ob->partype & PARSLOW) {
1231
 
                        // framerate meetellen 
 
1343
                        // include framerate
1232
1344
 
1233
1345
                        fac1= (float)(timefac/(1.0+ fabs(ob->sf)));
1234
1346
                        if(fac1>=1.0) return;
1256
1368
        solve_constraints (ob, TARGET_OBJECT, NULL, ctime);
1257
1369
 
1258
1370
        if(ob->scriptlink.totscript && !during_script()) {
1259
 
                BPY_do_pyscript((ID *)ob, SCRIPT_REDRAW);
 
1371
                if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript((ID *)ob, SCRIPT_REDRAW);
1260
1372
        }
 
1373
        
 
1374
        /* set negative scale flag in object */
 
1375
        Crossf(vec, ob->obmat[0], ob->obmat[1]);
 
1376
        if( Inpf(vec, ob->obmat[2]) < 0.0 ) ob->transflag |= OB_NEG_SCALE;
 
1377
        else ob->transflag &= ~OB_NEG_SCALE;
1261
1378
}
1262
1379
 
1263
1380
static void solve_parenting (Object *ob, Object *par, float slowmat[][4], int simul)
1328
1445
#endif
1329
1446
        }
1330
1447
        
1331
 
        // totaal 
 
1448
        // total 
1332
1449
        Mat4MulSerie(tmat, totmat, ob->parentinv,         
1333
1450
                NULL, NULL, NULL, NULL, NULL, NULL);
1334
1451
        Mat4MulSerie(ob->obmat, tmat, obmat,         
1338
1455
 
1339
1456
        }
1340
1457
        else{
1341
 
                // >>>>>>>>>>>>>>>>>>
1342
 
                // dit is een extern bruikbare originmat 
 
1458
                // external usable originmat 
1343
1459
                Mat3CpyMat4(originmat, tmat);
1344
1460
                
1345
 
                // origin, voor hulplijntje 
 
1461
                // origin, voor help line
1346
1462
                if( (ob->partype & 15)==PARSKEL ) {
1347
1463
                        VECCOPY(ob->orig, par->obmat[3]);
1348
1464
                }
1472
1588
                                enf = con->enforce;
1473
1589
 
1474
1590
                        /* Get the targetmat */
1475
 
                        get_constraint_target(con, obtype, obdata, tmat, size, ctime);
 
1591
                        get_constraint_target_matrix(con, obtype, obdata, tmat, size, ctime);
1476
1592
                        
1477
1593
                        Mat4CpyMat4(focusmat, tmat);
1478
1594