Normand Briere
2019-10-06 9cf2c36d644d0aaa28797f57a3e71591d8e66973
Object3D.java
....@@ -25,21 +25,112 @@
2525 // Use GetUUID for backward compatibility with null.
2626 private UUID uuid = UUID.randomUUID();
2727
28
- // TEMPORARY for mocap undo. No need to be transient.
28
+ // TEMPORARY for versions. No need to be transient.
2929 mocap.reader.BVHReader.BVHResult savebvh;
3030 Object3D saveskeleton;
31
+
32
+ // FileObject
33
+ Object3D savefilecontent;
3134 //
3235
3336 String skyboxname;
3437 String skyboxext;
3538
36
- Object3D versionlist[];
39
+ Object3D[] versionlist;
3740 int versionindex = -1;
3841
3942 java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
4043
44
+ transient int tabIndex; // Tabs can change between sessions.
45
+
4146 ScriptNode scriptnode;
4247
48
+ void deepCopyNode(Object3D other)
49
+ {
50
+ other.skyboxname = skyboxname;
51
+ other.skyboxext = skyboxext;
52
+
53
+ if (toParent != null)
54
+ {
55
+ other.toParent = LA.newMatrix();
56
+ other.fromParent = LA.newMatrix();
57
+ LA.matCopy(toParent, other.toParent);
58
+ LA.matCopy(fromParent, other.fromParent);
59
+ if (toParentMarked != null)
60
+ {
61
+ other.toParentMarked = LA.newMatrix();
62
+ other.fromParentMarked = LA.newMatrix();
63
+ LA.matCopy(toParentMarked, other.toParentMarked);
64
+ LA.matCopy(fromParentMarked, other.fromParentMarked);
65
+ }
66
+ }
67
+ else
68
+ {
69
+ if (other.toParent == null)
70
+// assert(other.toParent == null);
71
+// new Exception().printStackTrace();
72
+ System.err.println("null parent: " + other);
73
+ }
74
+
75
+ /*
76
+ double ident[][] = LA.newMatrix();
77
+ if (bRep == null)
78
+ other.bRep = null;
79
+ else
80
+ other.bRep = new BoundaryRep(bRep, ident);
81
+ */
82
+ // Really new...
83
+ //other.editWindow = null;
84
+ if (name == null)
85
+ other.name = null;
86
+ else
87
+ other.name = new String(name);
88
+
89
+ if (material != null)
90
+ {
91
+ other.material = new cMaterial(material);
92
+ } else
93
+ {
94
+ other.material = null;
95
+ }
96
+
97
+ other.GetTextures().name = GetTextures().name;
98
+
99
+ CopyExtraMaterial(other);
100
+
101
+ other.touched = touched;
102
+ other.softtouched = softtouched;
103
+
104
+ other.random = random;
105
+ other.link2master = Link2Support();
106
+ other.transformcount = transformcount;
107
+ other.marked = marked;
108
+ other.skip = skip;
109
+ other.count = count;
110
+ other.flipV = flipV;
111
+ other.live = live;
112
+ other.rewind = rewind;
113
+ other.hide = hide;
114
+ other.texres = texres;
115
+ other.speedup = speedup;
116
+ other.height = height;
117
+ other.depth = depth;
118
+ }
119
+
120
+ int VersionCount()
121
+ {
122
+ int count = 0;
123
+
124
+ if (versionlist != null)
125
+ for (int i = versionlist.length; --i >= 0;)
126
+ {
127
+ if (versionlist[i] != null)
128
+ count++;
129
+ }
130
+
131
+ return count;
132
+ }
133
+
43134 void InitOthers()
44135 {
45136 if (projectedVertices == null || projectedVertices.length <= 2)
....@@ -51,6 +142,7 @@
51142 projectedVertices[i] = new cVector2(); // Others
52143 }
53144 projectedVertices[0].x = 100; // bump
145
+ projectedVertices[1].y = 1000; // punchthrough. only for png
54146 }
55147
56148 void MinMax(cVector minima, cVector maxima)
....@@ -130,7 +222,7 @@
130222 return;
131223
132224 transientsupport = support;
133
- transientlink2master = link2master;
225
+ transientlink2master = Link2Support();
134226
135227 support = null;
136228 link2master = false;
....@@ -177,9 +269,42 @@
177269 }
178270 }
179271
272
+ boolean HasBigData()
273
+ {
274
+ if (blockloop)
275
+ return false;
276
+
277
+ if (bRep != null)
278
+ {
279
+ return true;
280
+ }
281
+
282
+ blockloop = true;
283
+
284
+ for (int i = 0; i < Size(); i++)
285
+ {
286
+ Object3D child = (Object3D) get(i);
287
+ if (child == null)
288
+ continue;
289
+ if (child.HasBigData())
290
+ {
291
+ blockloop = false;
292
+ return true;
293
+ }
294
+ }
295
+
296
+ blockloop = false;
297
+ return false;
298
+ }
299
+
180300 void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
181301 {
302
+ if (blockloop)
303
+ return;
304
+
182305 Object3D o;
306
+
307
+ boolean isnew = false;
183308
184309 if (hashtable.containsKey(GetUUID()))
185310 {
....@@ -193,12 +318,14 @@
193318 }
194319 else
195320 {
321
+ isnew = true;
322
+
196323 o = new Object3D("copy of " + this.name);
197324
198325 hashtable.put(GetUUID(), o);
199326 }
200327
201
- if (!blockloop)
328
+ //if (!blockloop)
202329 {
203330 blockloop = true;
204331
....@@ -209,12 +336,15 @@
209336
210337 blockloop = false;
211338 }
212
-
213
- ExtractBigData(o);
339
+
340
+ //if (isnew)
341
+ ExtractBigData(o);
214342 }
215343
216344 void ExtractBigData(Object3D o)
217345 {
346
+ //System.err.println("ExtractBigData : " + this + " --> " + o);
347
+
218348 if (o.bRep != null)
219349 Grafreed.Assert(o.bRep == this.bRep);
220350
....@@ -225,8 +355,8 @@
225355 // o.bRep.support = null;
226356 // }
227357 o.selection = this.selection;
228
- o.versionlist = this.versionlist;
229
- o.versionindex = this.versionindex;
358
+ //o.versionlist = this.versionlist;
359
+ //o.versionindex = this.versionindex;
230360
231361 if (this.support != null)
232362 {
....@@ -318,15 +448,15 @@
318448
319449 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
320450 {
451
+ if (blockloop)
452
+ return;
453
+
321454 if (!hashtable.containsKey(GetUUID()))
322455 return;
323456
324457 Object3D o = hashtable.get(GetUUID());
325458
326459 RestoreBigData(o);
327
-
328
- if (blockloop)
329
- return;
330460
331461 blockloop = true;
332462
....@@ -342,6 +472,9 @@
342472
343473 void RestoreBigData(Object3D o)
344474 {
475
+ //System.err.println("RestoreBigData : " + this + " <-- " + o);
476
+ Grafreed.Assert(this.bRep == null);
477
+
345478 this.bRep = o.bRep;
346479 if (this.support != null && o.transientrep != null)
347480 {
....@@ -350,8 +483,8 @@
350483
351484 this.selection = o.selection;
352485
353
- this.versionlist = o.versionlist;
354
- this.versionindex = o.versionindex;
486
+ //this.versionlist = o.versionlist;
487
+ //this.versionindex = o.versionindex;
355488 // July 2019 if (this.bRep != null)
356489 // this.bRep.support = o.transientrep;
357490 // this.support = o.support;
....@@ -502,7 +635,10 @@
502635 transient boolean keepdontselect;
503636 boolean dontselect = false;
504637 boolean hide = false;
505
- boolean link2master = false; // performs reset support/master at each frame
638
+
639
+ boolean link2master = false; // performs reset support/master at each frame (cannot rename due to serialization)
640
+ boolean link2support = false; // (cannot rename due to serialization)
641
+
506642 boolean marked = false; // animation node
507643 boolean skip = false; // centroid issue
508644 boolean skipmocap = false; // mocap data
....@@ -510,6 +646,9 @@
510646 boolean random = false;
511647 boolean speedup = false;
512648 boolean rewind = false;
649
+
650
+ // Option to sort triangles, e.g. for transparency.
651
+ boolean sort = false;
513652
514653 float NORMALPUSH = 0;
515654
....@@ -528,7 +667,7 @@
528667 {
529668 sorted = true;
530669
531
- for (int i=0; i<size()-1; i++)
670
+ for (int i=0; i<Size()-1; i++)
532671 {
533672 Object3D obji = get(i);
534673 Object3D objj = get(i+1);
....@@ -552,7 +691,7 @@
552691 {
553692 sorted = true;
554693
555
- for (int i=0; i<size()-1; i++)
694
+ for (int i=0; i<Size()-1; i++)
556695 {
557696 Object3D obji = get(i);
558697 Object3D objj = get(i+1);
....@@ -568,11 +707,11 @@
568707 }
569708 }
570709
571
- int memorysize;
710
+ transient int memorysize; // needs to be transient, dunno why
572711
573712 int MemorySize()
574713 {
575
- if (true) // memorysize == 0)
714
+ if (memorysize == 0)
576715 {
577716 try
578717 {
....@@ -889,7 +1028,7 @@
8891028
8901029 void Step()
8911030 {
892
- // marde pour serialization de Texture
1031
+ // patch pour serialization de Texture
8931032 resetmaxcount();
8941033 resettransformcount();
8951034 resetstep();
....@@ -1003,6 +1142,8 @@
10031142 (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
10041143 currentframe != Globals.framecount)
10051144 {
1145
+ Globals.lighttouched = true;
1146
+
10061147 currentframe = Globals.framecount;
10071148
10081149 // System.err.println("transformcount = " + transformcount);
....@@ -1082,24 +1223,28 @@
10821223 {
10831224 // return true;
10841225
1085
- if (material == null || material.multiply)
1086
- return true;
1226
+// if (material == null || material.multiply)
1227
+// return true;
1228
+//
1229
+// if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1230
+// return false;
1231
+//
1232
+// // Transparent objects are dynamic because we have to sort the triangles.
1233
+// return material.opacity > 0.99;
10871234
1088
- if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1089
- return false;
1090
-
1091
- // Transparent objects are dynamic because we have to sort the triangles.
1092
- return material.opacity > 0.99;
1235
+ return !sort;
10931236 }
10941237
10951238 boolean IsOpaque()
10961239 {
10971240 // return true;
10981241
1099
- if (material == null || material.multiply)
1100
- return true;
1242
+// if (material == null || material.multiply)
1243
+// return true;
1244
+//
1245
+// return material.opacity > 0.99;
11011246
1102
- return material.opacity > 0.99;
1247
+ return !sort;
11031248 }
11041249
11051250 Object3D()
....@@ -1177,8 +1322,10 @@
11771322
11781323 // will share the geometry
11791324 assert (!(this instanceof Composite));
1180
- return deepCopy(); // Never called for Composite
1181
-
1325
+
1326
+ Object3D obj = deepCopy(); // Never called for Composite
1327
+ obj.count = 2;
1328
+ return obj;
11821329 }
11831330
11841331 boolean HasLoops()
....@@ -1186,6 +1333,30 @@
11861333 return false;
11871334 }
11881335
1336
+ void ResetUUIDs()
1337
+ {
1338
+ if (blockloop)
1339
+ {
1340
+ return;
1341
+ }
1342
+
1343
+ this.uuid = null;
1344
+
1345
+ blockloop = true;
1346
+
1347
+ for (int i = 0; i < Size(); i++)
1348
+ {
1349
+ Object3D obj = (Object3D) Children().get(i);
1350
+
1351
+ if (obj != null)
1352
+ {
1353
+ obj.ResetUUIDs();
1354
+ }
1355
+ }
1356
+
1357
+ blockloop = false;
1358
+ }
1359
+
11891360 boolean IsInfinite()
11901361 {
11911362 if (blockloop)
....@@ -1256,78 +1427,16 @@
12561427 return;
12571428
12581429 blockloop = true;
1430
+
1431
+ other.parent = parent;
1432
+
12591433 //System.out.println("COPY " + this + " to " + other);
12601434 //new Exception().printStackTrace();
1435
+ deepCopyNode(other);
12611436
1262
- other.parent = parent;
1263
- if (toParent != null)
1264
- {
1265
- other.toParent = LA.newMatrix();
1266
- other.fromParent = LA.newMatrix();
1267
- LA.matCopy(toParent, other.toParent);
1268
- LA.matCopy(fromParent, other.fromParent);
1269
- if (toParentMarked != null)
1270
- {
1271
- other.toParentMarked = LA.newMatrix();
1272
- other.fromParentMarked = LA.newMatrix();
1273
- LA.matCopy(toParentMarked, other.toParentMarked);
1274
- LA.matCopy(fromParentMarked, other.fromParentMarked);
1275
- }
1276
- }
1277
- else
1278
- {
1279
- if (other.toParent == null)
1280
-// assert(other.toParent == null);
1281
-// new Exception().printStackTrace();
1282
- System.err.println("null parent: " + other);
1283
- }
1284
- /*
1285
- double ident[][] = LA.newMatrix();
1286
- if (bRep == null)
1287
- other.bRep = null;
1288
- else
1289
- other.bRep = new BoundaryRep(bRep, ident);
1290
- */
1291
- // Really new...
12921437 other.bRep = bRep; // Share the geometry
12931438
12941439 other.support = support; // Share the support
1295
-
1296
- //other.editWindow = null;
1297
- if (name == null)
1298
- other.name = null;
1299
- else
1300
- other.name = new String(name);
1301
-
1302
- if (material != null)
1303
- {
1304
- other.material = new cMaterial(material);
1305
- } else
1306
- {
1307
- other.material = null;
1308
- }
1309
-
1310
- other.GetTextures().name = GetTextures().name;
1311
-
1312
- CopyExtraMaterial(other);
1313
-
1314
- other.touched = touched;
1315
- other.softtouched = softtouched;
1316
-
1317
- other.random = random;
1318
- other.link2master = link2master;
1319
- other.transformcount = transformcount;
1320
- other.marked = marked;
1321
- other.skip = skip;
1322
- other.count = count;
1323
- other.flipV = flipV;
1324
- other.live = live;
1325
- other.rewind = rewind;
1326
- other.hide = hide;
1327
- other.texres = texres;
1328
- other.speedup = speedup;
1329
- other.height = height;
1330
- other.depth = depth;
13311440
13321441 // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist)
13331442 // {
....@@ -1383,17 +1492,24 @@
13831492 if ((mask & GEOMETRY) != 0)
13841493 {
13851494 if (bRep != null)
1386
- bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
1387
- else
1388
- assert(other.bRep == null);
1389
-
1390
- if (bRep != null)
13911495 {
1496
+ bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
13921497 CameraPane.RemoveList(bRep.displaylist);
13931498 bRep.displaylist = 0; // june 2013 -1;
13941499 }
13951500 else
1396
- bRep = bRep;
1501
+ {
1502
+ //assert(other.bRep == null);
1503
+ bRep = other.bRep;
1504
+ }
1505
+
1506
+// if (bRep != null)
1507
+// {
1508
+// CameraPane.RemoveList(bRep.displaylist);
1509
+// bRep.displaylist = 0; // june 2013 -1;
1510
+// }
1511
+// else
1512
+// bRep = bRep;
13971513 }
13981514
13991515 /* Use a MASK = GEO/MAT
....@@ -3189,7 +3305,10 @@
31893305 {
31903306 if (bRep != null)
31913307 {
3308
+ //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact).
31923309 bRep.GenerateNormals(crease);
3310
+ if (!bRep.trimmed)
3311
+ bRep.MergeNormals();
31933312 Touch();
31943313 }
31953314 }
....@@ -3264,6 +3383,105 @@
32643383 blockloop = false;
32653384 }
32663385
3386
+ public void ResetTransform(int mask)
3387
+ {
3388
+ Object3D obj = this;
3389
+
3390
+ if (mask == -1)
3391
+ {
3392
+ if (obj instanceof Camera) // jan 2014
3393
+ {
3394
+ LA.matIdentity(obj.toParent);
3395
+ LA.matIdentity(obj.fromParent);
3396
+ }
3397
+ else
3398
+ {
3399
+ obj.toParent = null; // jan 2014 LA.matIdentity(obj.toParent);
3400
+ obj.fromParent = null; // LA.matIdentity(obj.fromParent);
3401
+ }
3402
+ return;
3403
+ }
3404
+
3405
+ if ((mask&2) != 0) // Scale/rotation
3406
+ {
3407
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = 1;
3408
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3409
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3410
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1;
3411
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3412
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3413
+ }
3414
+ if ((mask&1) != 0) // Translation
3415
+ {
3416
+ if (obj.toParent != null)
3417
+ {
3418
+ obj.toParent[3][0] = obj.toParent[3][1] = obj.toParent[3][2] = 0;
3419
+ obj.fromParent[3][0] = obj.fromParent[3][1] = obj.fromParent[3][2] = 0;
3420
+ }
3421
+ }
3422
+ }
3423
+
3424
+ public void Scale(float scale)
3425
+ {
3426
+ Object3D obj = this;
3427
+
3428
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = scale;
3429
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3430
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3431
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1/scale;
3432
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3433
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3434
+ }
3435
+
3436
+ public void TextureRatioTransform(int axis)
3437
+ {
3438
+ cTexture tex = GetTextures();
3439
+
3440
+ com.sun.opengl.util.texture.TextureData texturedata = null;
3441
+
3442
+ try
3443
+ {
3444
+ texturedata = Globals.theRenderer.GetTextureData(tex, false, texres);
3445
+ }
3446
+ catch (Exception e)
3447
+ {
3448
+ System.err.println("FAIL TextureRatio: " + this);
3449
+ }
3450
+
3451
+ LA.matIdentity(Object3D.mat);
3452
+ Object3D.mat[axis][axis] = (double)texturedata.getWidth() / texturedata.getHeight();
3453
+
3454
+ if (toParent == null)
3455
+ {
3456
+ toParent = LA.newMatrix();
3457
+ fromParent = LA.newMatrix();
3458
+ }
3459
+
3460
+ ResetTransform(2);
3461
+
3462
+ LA.matConcat(Object3D.mat, fromParent, fromParent);
3463
+ LA.matInvert(fromParent, toParent);
3464
+ }
3465
+
3466
+ void TextureRatio(int axis)
3467
+ {
3468
+ if (blockloop)
3469
+ return;
3470
+
3471
+ blockloop = true;
3472
+
3473
+ TextureRatioTransform(axis);
3474
+
3475
+ for (int i=Size(); --i>=0;)
3476
+ {
3477
+ Object3D v = get(i);
3478
+
3479
+ v.TextureRatio(axis);
3480
+ }
3481
+
3482
+ blockloop = false;
3483
+ }
3484
+
32673485 void TransformChildren()
32683486 {
32693487 if (toParent != null)
....@@ -3506,6 +3724,7 @@
35063724 if (bRep != null)
35073725 {
35083726 //bRep.RemoveOneTriangle();
3727
+ System.out.println();
35093728 System.out.println("Reducing " + this);
35103729 if (name != null && name.contains("lockpickstraps"))
35113730 name = name;
....@@ -3836,6 +4055,7 @@
38364055
38374056 void RevertMeshes()
38384057 {
4058
+ // BLOCKLOOP
38394059 if (this instanceof cMesh)
38404060 {
38414061 ((cMesh)this).Revert();
....@@ -3866,11 +4086,6 @@
38664086 Touch();
38674087 }
38684088
3869
- ResetRecur();
3870
- }
3871
-
3872
- void ResetRecur()
3873
- {
38744089 for (int i = 0; i < size(); i++)
38754090 {
38764091 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3893,11 +4108,6 @@
38934108 Step();
38944109 Touch();
38954110
3896
- StepRecur();
3897
- }
3898
-
3899
- void StepRecur()
3900
- {
39014111 for (int i = 0; i < size(); i++)
39024112 {
39034113 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -4084,8 +4294,8 @@
40844294 Touch();
40854295 }
40864296
4087
- transient cVector min = new cVector();
4088
- transient cVector max = new cVector();
4297
+ transient cVector min;
4298
+ transient cVector max;
40894299
40904300 void getBounds(cVector minima, cVector maxima, boolean xform)
40914301 {
....@@ -4101,15 +4311,15 @@
41014311 if (blockloop)
41024312 return;
41034313
4104
- if (min == null) // ???
4314
+ if (min == null)
41054315 {
41064316 min = new cVector();
41074317 max = new cVector();
41084318 }
41094319
4110
- for (int i = 0; i<size(); i++)
4320
+ for (int i = 0; i<Size(); i++)
41114321 {
4112
- Object3D child = (Object3D) reserve(i);
4322
+ Object3D child = (Object3D) get(i); //reserve(i);
41134323 if (child == null)
41144324 continue;
41154325
....@@ -4128,21 +4338,21 @@
41284338 if (child.hide && !(child instanceof Merge) || child.skip)
41294339 //if (child.hide)
41304340 {
4131
- release(i);
4341
+ //release(i);
41324342 continue;
41334343 }
41344344
41354345 blockloop = true;
41364346 child.getBounds(min, max, true); // xform);
41374347 blockloop = false;
4138
- release(i);
4348
+ //release(i);
41394349
41404350 MinMax(minima, maxima);
41414351 }
41424352
41434353 if (bRep != null)
41444354 {
4145
- bRep.getBounds(minima,maxima,this);
4355
+ bRep.getBounds(minima, maxima, xform?this:null);
41464356 }
41474357
41484358 if (false) // xform)
....@@ -5951,7 +6161,7 @@
59516161 boolean NeedSupport()
59526162 {
59536163 return
5954
- CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
6164
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && Link2Support() && /*live &&*/ support != null
59556165 // PROBLEM with CROWD!!
59566166 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
59576167 }
....@@ -5969,6 +6179,20 @@
59696179 return parent.IsLive();
59706180 }
59716181
6182
+ boolean IsDynamic()
6183
+ {
6184
+ return live && bRep != null;
6185
+ }
6186
+
6187
+ boolean Link2Support()
6188
+ {
6189
+ return link2master || link2support;
6190
+ }
6191
+
6192
+ static cVector minima = new cVector();
6193
+ static cVector maxima = new cVector();
6194
+ static javax.vecmath.Point3d center = new javax.vecmath.Point3d();
6195
+
59726196 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
59736197 {
59746198 Invariants(); // june 2013
....@@ -5976,6 +6200,29 @@
59766200 if (support != null)
59776201 {
59786202 // System.err.println("Draw " + this + " Frame # " + ((Mocap)((Merge)support).object).frame);
6203
+ }
6204
+
6205
+ if (false) // live && Link2Support() && support == null && !this.marked) // project on ground
6206
+ {
6207
+ getBounds(minima, maxima, true);
6208
+ center.x = (minima.x + maxima.x) / 2;
6209
+ center.y = 10000; // (minima.y + maxima.y) / 2;
6210
+ center.z = (minima.z + maxima.z) / 2;
6211
+
6212
+ Ray ray = new Ray(center, new Vector3d(0,-1,0));
6213
+
6214
+ IntersectResult res = new IntersectResult();
6215
+ res.t = Double.POSITIVE_INFINITY;
6216
+
6217
+ if (Grafreed.grafreed.universe.intersect(ray, res))
6218
+ {
6219
+ double resx = ray.eyePoint.x + ray.viewDirection.x * res.t;
6220
+ double resy = ray.eyePoint.y + ray.viewDirection.y * res.t;
6221
+ double resz = ray.eyePoint.z + ray.viewDirection.z * res.t;
6222
+
6223
+ LA.matTranslate(toParent, 0, resy - minima.y, 0);
6224
+ LA.matInvert(toParent, fromParent);
6225
+ }
59796226 }
59806227
59816228 if (display.DrawMode() == iCameraPane.SELECTION &&
....@@ -6029,7 +6276,8 @@
60296276 if (support != null)
60306277 support = support;
60316278
6032
- boolean usecalllists = !IsLive() && IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6279
+ boolean usecalllists = !IsDynamic() &&
6280
+ IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
60336281 //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
60346282
60356283 //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
....@@ -6040,7 +6288,8 @@
60406288 bRep.displaylist = 0;
60416289 }
60426290 // usecalllists &= !(parent instanceof RandomNode);
6043
- // usecalllists = false;
6291
+ if (CameraPane.BOXMODE) // Too dynamic
6292
+ usecalllists = false;
60446293
60456294 if (display.DrawMode() == display.SHADOW)
60466295 //GetBRep() != null)
....@@ -6054,7 +6303,7 @@
60546303
60556304 if (!selectmode && //display.DrawMode() != display.SELECTION &&
60566305 //(touched || (bRep != null && bRep.displaylist <= 0)))
6057
- (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
6306
+ ((Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE) || touched)) // || (bRep != null && bRep.displaylist <= 0)))
60586307 {
60596308 Globals.lighttouched = true;
60606309 } // all panes...
....@@ -6096,8 +6345,8 @@
60966345 Globals.lighttouched = true; // all panes...
60976346 }
60986347
6099
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6100
- //touched = false;
6348
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6349
+ touched = false;
61016350
61026351 if (this instanceof Texture || this instanceof TextureNode)
61036352 {
....@@ -6136,7 +6385,7 @@
61366385 {
61376386 if (display.DrawMode() == iCameraPane.SHADOW)
61386387 {
6139
- if (!link2master // tricky to cull in shadow mode.
6388
+ if (!Link2Support() // tricky to cull in shadow mode.
61406389 && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
61416390 {
61426391 //System.out.print("CULLED");
....@@ -6198,6 +6447,20 @@
61986447 {
61996448 drawSelf(display, root, selected, blocked);
62006449 }
6450
+
6451
+// if (!(this instanceof Composite))
6452
+// {
6453
+// for (int i = 0; i < size(); i++)
6454
+// {
6455
+// Object3D child = (Object3D) reserve(i);
6456
+// if (child == null)
6457
+// continue;
6458
+//
6459
+// child.draw(display, root, selected, blocked);
6460
+//
6461
+// release(i);
6462
+// }
6463
+// }
62016464 } else
62026465 {
62036466 /*
....@@ -6230,13 +6493,14 @@
62306493 boolean failedPigment = false;
62316494 boolean failedBump = false;
62326495
6496
+ CameraPane.lastObject = this;
62336497 try
62346498 {
62356499 display.BindPigmentTexture(tex, texres);
62366500 }
62376501 catch (Exception e)
62386502 {
6239
- System.err.println("FAILED: " + this);
6503
+ // System.err.println("FAILED: " + this);
62406504 failedPigment = true;
62416505 }
62426506
....@@ -6267,6 +6531,20 @@
62676531 display.CallList(bRep.displaylist);
62686532 // june 2013 drawSelf(display, root, selected);
62696533 }
6534
+ }
6535
+
6536
+ assert (!(this instanceof Composite));
6537
+ {
6538
+// CRASH MOCAP!! for (int i = 0; i < size(); i++)
6539
+// {
6540
+// Object3D child = (Object3D) reserve(i);
6541
+// if (child == null)
6542
+// continue;
6543
+//
6544
+// child.draw(display, root, selected, blocked);
6545
+//
6546
+// release(i);
6547
+// }
62706548 }
62716549 }
62726550
....@@ -6320,16 +6598,17 @@
63206598
63216599 void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
63226600 {
6323
- if (GetBRep() == null)
6324
- {
6325
- drawSelf(display, root, selected, blocked);
6326
- } else
6601
+ if (GetBRep() != null)
63276602 {
63286603 DrawNode(display, root, selected);
63296604 if (this instanceof BezierPatch)
63306605 {
63316606 //drawSelf(display, root, selected);
63326607 }
6608
+ }
6609
+ else
6610
+ {
6611
+ drawSelf(display, root, selected, blocked);
63336612 }
63346613 }
63356614
....@@ -6579,7 +6858,8 @@
65796858
65806859 //javax.media.opengl.GL gl = display.GetGL();
65816860
6582
- if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
6861
+ if (CameraPane.BOXMODE && //!Link2Support()) //
6862
+ !selected) // || CameraPane.movingcamera)
65836863 {
65846864 int fc = bRep.FaceCount();
65856865 int vc = bRep.VertexCount();
....@@ -6741,7 +7021,7 @@
67417021 facescompare[k] = new FaceCompare(k);
67427022 }
67437023
6744
- center = new cVector();
7024
+ centertriangle = new cVector();
67457025 }
67467026 else
67477027 {
....@@ -6864,7 +7144,7 @@
68647144 */
68657145 }
68667146
6867
- transient cVector center;
7147
+ transient cVector centertriangle;
68687148
68697149 class FaceCompare implements Comparable
68707150 {
....@@ -6893,14 +7173,14 @@
68937173 Vertex q = bRep.GetVertex(face.q);
68947174 Vertex r = bRep.GetVertex(face.r);
68957175
6896
- center.set(p);
6897
- center.add(q);
6898
- center.add(r);
6899
- center.mul(1.0/3);
7176
+ centertriangle.set(p);
7177
+ centertriangle.add(q);
7178
+ centertriangle.add(r);
7179
+ centertriangle.mul(1.0/3);
69007180
6901
- center.sub(Globals.theRenderer.EyeCamera().location);
7181
+ centertriangle.sub(Globals.theRenderer.EyeCamera().location);
69027182
6903
- distance = center.dot(center);
7183
+ distance = centertriangle.dot(centertriangle);
69047184 }
69057185
69067186 return distance;
....@@ -8078,12 +8358,12 @@
80788358 if (!Globals.ADVANCED)
80798359 return objname;
80808360
8081
- return objname + " " + System.identityHashCode(this);
8361
+ return objname + " " + System.identityHashCode(this) + " " + GetUUID();
80828362 }
80838363
80848364 public int hashCode()
80858365 {
8086
- // Fuck Vector...
8366
+ // Do not use Vector...
80878367 return System.identityHashCode(this);
80888368 }
80898369
....@@ -8323,8 +8603,8 @@
83238603 private static cVector2 qq2 = new cVector2();
83248604 private static cVector2 rr2 = new cVector2();
83258605 private static cVector2 ss2 = new cVector2();
8326
- private static cVector edge1 = new cVector();
8327
- private static cVector edge2 = new cVector();
8606
+// private static cVector edge1 = new cVector();
8607
+// private static cVector edge2 = new cVector();
83288608 //private static cVector norm = new cVector();
83298609 /*transient private*/ int hitSomething;
83308610 static final int hitCenter = 1;
....@@ -8522,7 +8802,275 @@
85228802
85238803 Touch();
85248804 }
8805
+
8806
+ static Vertex s1 = new Vertex();
8807
+ static Vertex s2 = new Vertex();
8808
+ static Vertex s3 = new Vertex();
85258809
8810
+ boolean intersectMesh(Ray ray, IntersectResult result)
8811
+ {
8812
+ boolean success = false;
8813
+
8814
+ if (bRep.stripified)
8815
+ {
8816
+ int[] strips = bRep.getRawIndices();
8817
+
8818
+ // TRIANGLE STRIP ARRAY
8819
+ if (bRep.trimmed)
8820
+ {
8821
+ float[] v = bRep.getRawVertices();
8822
+
8823
+ int count3 = 0;
8824
+
8825
+ if (v.length > 0)
8826
+ {
8827
+ for (int i = 0; i < strips.length; i++)
8828
+ {
8829
+ s1.set(v[count3], v[count3 + 1], v[count3 + 2]);
8830
+ count3 += 3;
8831
+
8832
+ s2.set(v[count3], v[count3 + 1], v[count3 + 2]);
8833
+ count3 += 3;
8834
+
8835
+ for (int j = 0; j < strips[i] - 2; j++)
8836
+ {
8837
+ s3.set(v[count3], v[count3 + 1], v[count3 + 2]);
8838
+ count3 += 3;
8839
+
8840
+ if (j%2 == 0)
8841
+ success |= intersectTriangle(ray, result, s1, s2, s3);
8842
+ else
8843
+ success |= intersectTriangle(ray, result, s1, s3, s2);
8844
+
8845
+ s1.set(s2);
8846
+ s2.set(s3);
8847
+ }
8848
+ }
8849
+ }
8850
+
8851
+ assert count3 == v.length;
8852
+ }
8853
+ else // !trimmed
8854
+ {
8855
+ int count = 0;
8856
+ for (int i = 0; i < strips.length; i++)
8857
+ {
8858
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
8859
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
8860
+
8861
+ for (int j = 0; j < strips[i] - 2; j++)
8862
+ {
8863
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
8864
+
8865
+ if (j%2 == 0)
8866
+ success |= intersectTriangle(ray, result, p, q, r);
8867
+ else
8868
+ success |= intersectTriangle(ray, result, p, r, q);
8869
+
8870
+ p = q;
8871
+ q = r;
8872
+ }
8873
+ }
8874
+ }
8875
+ } else // catch (Error e)
8876
+ {
8877
+ int facecount = bRep.FaceCount();
8878
+ for (int i = 0; i < facecount; i++)
8879
+ {
8880
+ Face face = bRep.GetFace(i);
8881
+
8882
+ Vertex p = bRep.GetVertex(face.p);
8883
+ Vertex q = bRep.GetVertex(face.q);
8884
+ Vertex r = bRep.GetVertex(face.r);
8885
+
8886
+ success |= intersectTriangle(ray, result, p, q, r);
8887
+ }
8888
+ }
8889
+
8890
+ return success;
8891
+ }
8892
+
8893
+ static cVector eye = new cVector();
8894
+ static cVector dir = new cVector();
8895
+
8896
+ transient BBox bbox = null;
8897
+
8898
+ boolean intersect(Ray ray, IntersectResult result)
8899
+ {
8900
+ double eyex = ray.eyePoint.x;
8901
+ double eyey = ray.eyePoint.y;
8902
+ double eyez = ray.eyePoint.z;
8903
+
8904
+ double dirx = ray.viewDirection.x;
8905
+ double diry = ray.viewDirection.y;
8906
+ double dirz = ray.viewDirection.z;
8907
+
8908
+ if (this.fromParent != null && !(this instanceof TextureNode))
8909
+ {
8910
+ eye.x = eyex;
8911
+ eye.y = eyey;
8912
+ eye.z = eyez;
8913
+ dir.x = dirx;
8914
+ dir.y = diry;
8915
+ dir.z = dirz;
8916
+
8917
+ LA.xformPos(eye, this.fromParent, eye);
8918
+ LA.xformDir(dir, this.fromParent, dir);
8919
+
8920
+ ray.eyePoint.x = eye.x;
8921
+ ray.eyePoint.y = eye.y;
8922
+ ray.eyePoint.z = eye.z;
8923
+
8924
+ ray.viewDirection.x = dir.x;
8925
+ ray.viewDirection.y = dir.y;
8926
+ ray.viewDirection.z = dir.z;
8927
+ }
8928
+
8929
+ boolean success = false;
8930
+
8931
+ boolean touch = false;
8932
+
8933
+ if (bRep != null && Link2Support())
8934
+ {
8935
+ if (bbox == null)
8936
+ {
8937
+ bbox = new BBox();
8938
+
8939
+ cVector min = new cVector();
8940
+ cVector max = new cVector();
8941
+
8942
+ this.getBounds(min, max, true);
8943
+
8944
+ bbox.min.x = min.x;
8945
+ bbox.min.y = min.y;
8946
+ bbox.min.z = min.z;
8947
+
8948
+ bbox.max.x = max.x;
8949
+ bbox.max.y = max.y;
8950
+ bbox.max.z = max.z;
8951
+ }
8952
+
8953
+ if (true) // NOT WORKING bbox.intersect(ray, result))
8954
+ {
8955
+ success |= intersectMesh(ray, result);
8956
+ }
8957
+ else
8958
+ {
8959
+ //this.hide = true;
8960
+ touch = true;
8961
+ }
8962
+ }
8963
+
8964
+ for (int i=0; i<size(); i++)
8965
+ {
8966
+ Object3D child = (Object3D) reserve(i);
8967
+
8968
+ if (child == null)
8969
+ continue;
8970
+
8971
+ success |= child.intersect(ray, result);
8972
+ release(i);
8973
+ }
8974
+
8975
+ ray.eyePoint.x = eyex;
8976
+ ray.eyePoint.y = eyey;
8977
+ ray.eyePoint.z = eyez;
8978
+
8979
+ ray.viewDirection.x = dirx;
8980
+ ray.viewDirection.y = diry;
8981
+ ray.viewDirection.z = dirz;
8982
+
8983
+// if (touch)
8984
+// this.Touch(); // refresh display list
8985
+
8986
+ return success;
8987
+ }
8988
+
8989
+ static Vector3d edge1 = new Vector3d();
8990
+ static Vector3d edge2 = new Vector3d();
8991
+ static Vector3d P = new Vector3d();
8992
+ static Vector3d T = new Vector3d();
8993
+ static Vector3d Q = new Vector3d();
8994
+
8995
+ private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3)
8996
+ {
8997
+ if (false)
8998
+ {
8999
+ result.t = 0;
9000
+ return true;
9001
+ }
9002
+
9003
+ /*
9004
+ Fast, Minimum Storage Ray/Triangle Intersection, Moller et al.
9005
+
9006
+ Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
9007
+ */
9008
+
9009
+ // Calculate edges of the triangle
9010
+ edge1.set(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z);
9011
+ edge2.set(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z);
9012
+
9013
+ // Calculate the determinant (U parameter)
9014
+ P.cross(ray.viewDirection, edge2);
9015
+ double det = edge1.dot(P);
9016
+
9017
+ if (det > -1e-9 && det < 1e-9)
9018
+ {
9019
+ return false;
9020
+ } // Ray lies in plane of triangle
9021
+
9022
+ double invDet = 1 / det;
9023
+
9024
+ // Calculate distance from vertex1 to ray origin
9025
+ T.set(ray.eyePoint.x - v1.x, ray.eyePoint.y - v1.y, ray.eyePoint.z - v1.z);
9026
+
9027
+ double U = (T.dot(P)) * invDet; // Calculate U parameter
9028
+
9029
+ if (U < 0.f || U > 1.f)
9030
+ {
9031
+ return false;
9032
+ } // Intersection lies outside of the triangle
9033
+
9034
+ // Calculate V parameter
9035
+ Q.cross(T, edge1);
9036
+
9037
+ double V = ray.viewDirection.dot(Q) * invDet;
9038
+
9039
+ if (V < 0.f || (U + V) > 1.f)
9040
+ {
9041
+ return false;
9042
+ } // Intersection lies outside of the triangle
9043
+
9044
+ double t = edge2.dot(Q) * invDet;
9045
+
9046
+ if (t > 1e-9) // Triangle and ray intersects
9047
+ {
9048
+ //result.isIntersected = true;
9049
+ //result.id = id;
9050
+
9051
+ if (false) // isShadow)
9052
+ {
9053
+ result.t = t;
9054
+ return true;
9055
+ } else if (t < result.t)
9056
+ {
9057
+ result.object = this;
9058
+
9059
+ result.t = t;
9060
+
9061
+ //result.p.x = ray.eyePoint.x + ray.viewDirection.x * t;
9062
+ //result.p.y = ray.eyePoint.y + ray.viewDirection.y * t;
9063
+ //result.p.z = ray.eyePoint.z + ray.viewDirection.z * t;
9064
+
9065
+ result.n.cross(edge1, edge2);
9066
+ result.n.normalize();
9067
+ }
9068
+
9069
+ return true;
9070
+ }
9071
+
9072
+ return false;
9073
+ }
85269074
85279075 public int Size()
85289076 {