Normand Briere
2019-09-17 d248db5fc21c4b0ab24968974e5e590f413ef8fc
Object3D.java
....@@ -22,18 +22,113 @@
2222 //static final long serialVersionUID = -607422624994562685L;
2323 static final long serialVersionUID = 5022536242724664900L;
2424
25
+ // Use GetUUID for backward compatibility with null.
2526 private UUID uuid = UUID.randomUUID();
2627
27
- // TEMPORARY for mocap undo. No need to be transient.
28
+ // TEMPORARY for versions. No need to be transient.
2829 mocap.reader.BVHReader.BVHResult savebvh;
2930 Object3D saveskeleton;
31
+
32
+ // FileObject
33
+ Object3D savefilecontent;
3034 //
3135
32
- byte[] versions[];
36
+ String skyboxname;
37
+ String skyboxext;
38
+
39
+ Object3D[] versionlist;
3340 int versionindex = -1;
3441
42
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
43
+
3544 ScriptNode scriptnode;
3645
46
+ void deepCopyNode(Object3D other)
47
+ {
48
+ other.skyboxname = skyboxname;
49
+ other.skyboxext = skyboxext;
50
+
51
+ if (toParent != null)
52
+ {
53
+ other.toParent = LA.newMatrix();
54
+ other.fromParent = LA.newMatrix();
55
+ LA.matCopy(toParent, other.toParent);
56
+ LA.matCopy(fromParent, other.fromParent);
57
+ if (toParentMarked != null)
58
+ {
59
+ other.toParentMarked = LA.newMatrix();
60
+ other.fromParentMarked = LA.newMatrix();
61
+ LA.matCopy(toParentMarked, other.toParentMarked);
62
+ LA.matCopy(fromParentMarked, other.fromParentMarked);
63
+ }
64
+ }
65
+ else
66
+ {
67
+ if (other.toParent == null)
68
+// assert(other.toParent == null);
69
+// new Exception().printStackTrace();
70
+ System.err.println("null parent: " + other);
71
+ }
72
+
73
+ /*
74
+ double ident[][] = LA.newMatrix();
75
+ if (bRep == null)
76
+ other.bRep = null;
77
+ else
78
+ other.bRep = new BoundaryRep(bRep, ident);
79
+ */
80
+ // Really new...
81
+ //other.editWindow = null;
82
+ if (name == null)
83
+ other.name = null;
84
+ else
85
+ other.name = new String(name);
86
+
87
+ if (material != null)
88
+ {
89
+ other.material = new cMaterial(material);
90
+ } else
91
+ {
92
+ other.material = null;
93
+ }
94
+
95
+ other.GetTextures().name = GetTextures().name;
96
+
97
+ CopyExtraMaterial(other);
98
+
99
+ other.touched = touched;
100
+ other.softtouched = softtouched;
101
+
102
+ other.random = random;
103
+ other.link2master = link2master;
104
+ other.transformcount = transformcount;
105
+ other.marked = marked;
106
+ other.skip = skip;
107
+ other.count = count;
108
+ other.flipV = flipV;
109
+ other.live = live;
110
+ other.rewind = rewind;
111
+ other.hide = hide;
112
+ other.texres = texres;
113
+ other.speedup = speedup;
114
+ other.height = height;
115
+ other.depth = depth;
116
+ }
117
+
118
+ int VersionCount()
119
+ {
120
+ int count = 0;
121
+
122
+ if (versionlist != null)
123
+ for (int i = versionlist.length; --i >= 0;)
124
+ {
125
+ if (versionlist[i] != null)
126
+ count++;
127
+ }
128
+
129
+ return count;
130
+ }
131
+
37132 void InitOthers()
38133 {
39134 if (projectedVertices == null || projectedVertices.length <= 2)
....@@ -45,6 +140,7 @@
45140 projectedVertices[i] = new cVector2(); // Others
46141 }
47142 projectedVertices[0].x = 100; // bump
143
+ projectedVertices[1].y = 1000; // punchthrough. only for png
48144 }
49145
50146 void MinMax(cVector minima, cVector maxima)
....@@ -171,9 +267,42 @@
171267 }
172268 }
173269
270
+ boolean HasBigData()
271
+ {
272
+ if (blockloop)
273
+ return false;
274
+
275
+ if (bRep != null)
276
+ {
277
+ return true;
278
+ }
279
+
280
+ blockloop = true;
281
+
282
+ for (int i = 0; i < Size(); i++)
283
+ {
284
+ Object3D child = (Object3D) get(i);
285
+ if (child == null)
286
+ continue;
287
+ if (child.HasBigData())
288
+ {
289
+ blockloop = false;
290
+ return true;
291
+ }
292
+ }
293
+
294
+ blockloop = false;
295
+ return false;
296
+ }
297
+
174298 void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
175299 {
300
+ if (blockloop)
301
+ return;
302
+
176303 Object3D o;
304
+
305
+ boolean isnew = false;
177306
178307 if (hashtable.containsKey(GetUUID()))
179308 {
....@@ -187,12 +316,14 @@
187316 }
188317 else
189318 {
319
+ isnew = true;
320
+
190321 o = new Object3D("copy of " + this.name);
191322
192323 hashtable.put(GetUUID(), o);
193324 }
194325
195
- if (!blockloop)
326
+ //if (!blockloop)
196327 {
197328 blockloop = true;
198329
....@@ -203,12 +334,15 @@
203334
204335 blockloop = false;
205336 }
206
-
207
- ExtractBigData(o);
337
+
338
+ //if (isnew)
339
+ ExtractBigData(o);
208340 }
209341
210342 void ExtractBigData(Object3D o)
211343 {
344
+ //System.err.println("ExtractBigData : " + this + " --> " + o);
345
+
212346 if (o.bRep != null)
213347 Grafreed.Assert(o.bRep == this.bRep);
214348
....@@ -219,8 +353,8 @@
219353 // o.bRep.support = null;
220354 // }
221355 o.selection = this.selection;
222
- o.versions = this.versions;
223
- o.versionindex = this.versionindex;
356
+ //o.versionlist = this.versionlist;
357
+ //o.versionindex = this.versionindex;
224358
225359 if (this.support != null)
226360 {
....@@ -243,17 +377,84 @@
243377 // this.fileparent = null;
244378 }
245379
380
+// Object3D GetObject(java.util.UUID uuid)
381
+// {
382
+// if (this.uuid.equals(uuid))
383
+// return this;
384
+//
385
+// if (blockloop)
386
+// return null;
387
+//
388
+// blockloop = true;
389
+//
390
+// for (int i=0; i<Size(); i++)
391
+// {
392
+// Object3D o = get(i).GetObject(uuid);
393
+//
394
+// if (o != null)
395
+// return o;
396
+// }
397
+//
398
+// blockloop = false;
399
+//
400
+// return null;
401
+// }
402
+
403
+ transient boolean tag;
404
+
405
+ void TagObjects(Object3D o, boolean tag)
406
+ {
407
+ if (blockloop)
408
+ return;
409
+
410
+ o.tag = tag;
411
+
412
+ if (o == this)
413
+ return;
414
+
415
+ blockloop = true;
416
+
417
+ for (int i=0; i<Size(); i++)
418
+ {
419
+ get(i).TagObjects(o, tag);
420
+ }
421
+
422
+ blockloop = false;
423
+ }
424
+
425
+ boolean HasTags()
426
+ {
427
+ if (blockloop)
428
+ return false;
429
+
430
+ blockloop = true;
431
+
432
+ boolean hasTags = false;
433
+
434
+ for (int i=0; i<Size(); i++)
435
+ {
436
+ hasTags |= get(i).tag || get(i).HasTags();
437
+
438
+ if (hasTags)
439
+ break;
440
+ }
441
+
442
+ blockloop = false;
443
+
444
+ return hasTags;
445
+ }
446
+
246447 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
247448 {
449
+ if (blockloop)
450
+ return;
451
+
248452 if (!hashtable.containsKey(GetUUID()))
249453 return;
250454
251455 Object3D o = hashtable.get(GetUUID());
252456
253457 RestoreBigData(o);
254
-
255
- if (blockloop)
256
- return;
257458
258459 blockloop = true;
259460
....@@ -269,6 +470,9 @@
269470
270471 void RestoreBigData(Object3D o)
271472 {
473
+ //System.err.println("RestoreBigData : " + this + " <-- " + o);
474
+ Grafreed.Assert(this.bRep == null);
475
+
272476 this.bRep = o.bRep;
273477 if (this.support != null && o.transientrep != null)
274478 {
....@@ -277,8 +481,8 @@
277481
278482 this.selection = o.selection;
279483
280
- this.versions = o.versions;
281
- this.versionindex = o.versionindex;
484
+ //this.versionlist = o.versionlist;
485
+ //this.versionindex = o.versionindex;
282486 // July 2019 if (this.bRep != null)
283487 // this.bRep.support = o.transientrep;
284488 // this.support = o.support;
....@@ -438,6 +642,9 @@
438642 boolean speedup = false;
439643 boolean rewind = false;
440644
645
+ // Option to sort triangles, e.g. for transparency.
646
+ boolean sort = false;
647
+
441648 float NORMALPUSH = 0;
442649
443650 Object3D support;
....@@ -455,7 +662,7 @@
455662 {
456663 sorted = true;
457664
458
- for (int i=0; i<size()-1; i++)
665
+ for (int i=0; i<Size()-1; i++)
459666 {
460667 Object3D obji = get(i);
461668 Object3D objj = get(i+1);
....@@ -479,7 +686,7 @@
479686 {
480687 sorted = true;
481688
482
- for (int i=0; i<size()-1; i++)
689
+ for (int i=0; i<Size()-1; i++)
483690 {
484691 Object3D obji = get(i);
485692 Object3D objj = get(i+1);
....@@ -495,11 +702,11 @@
495702 }
496703 }
497704
498
- int memorysize;
705
+ transient int memorysize; // needs to be transient, dunno why
499706
500707 int MemorySize()
501708 {
502
- if (true) // memorysize == 0)
709
+ if (memorysize == 0)
503710 {
504711 try
505712 {
....@@ -614,7 +821,7 @@
614821 {
615822 if (maxcount != 1)
616823 {
617
- new Exception().printStackTrace();
824
+ //new Exception().printStackTrace();
618825 }
619826
620827 toParentMarked = LA.newMatrix();
....@@ -1009,21 +1216,28 @@
10091216 {
10101217 // return true;
10111218
1012
- if (material == null || material.multiply)
1013
- return true;
1219
+// if (material == null || material.multiply)
1220
+// return true;
1221
+//
1222
+// if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1223
+// return false;
1224
+//
1225
+// // Transparent objects are dynamic because we have to sort the triangles.
1226
+// return material.opacity > 0.99;
10141227
1015
- // Transparent objects are dynamic because we have to sort the triangles.
1016
- return material.opacity > 0.99;
1228
+ return !sort;
10171229 }
10181230
10191231 boolean IsOpaque()
10201232 {
10211233 // return true;
10221234
1023
- if (material == null || material.multiply)
1024
- return true;
1235
+// if (material == null || material.multiply)
1236
+// return true;
1237
+//
1238
+// return material.opacity > 0.99;
10251239
1026
- return material.opacity > 0.99;
1240
+ return !sort;
10271241 }
10281242
10291243 Object3D()
....@@ -1101,8 +1315,10 @@
11011315
11021316 // will share the geometry
11031317 assert (!(this instanceof Composite));
1104
- return deepCopy(); // Never called for Composite
1105
-
1318
+
1319
+ Object3D obj = deepCopy(); // Never called for Composite
1320
+ obj.count = 2;
1321
+ return obj;
11061322 }
11071323
11081324 boolean HasLoops()
....@@ -1110,6 +1326,30 @@
11101326 return false;
11111327 }
11121328
1329
+ void ResetUUIDs()
1330
+ {
1331
+ if (blockloop)
1332
+ {
1333
+ return;
1334
+ }
1335
+
1336
+ this.uuid = null;
1337
+
1338
+ blockloop = true;
1339
+
1340
+ for (int i = 0; i < Size(); i++)
1341
+ {
1342
+ Object3D obj = (Object3D) Children().get(i);
1343
+
1344
+ if (obj != null)
1345
+ {
1346
+ obj.ResetUUIDs();
1347
+ }
1348
+ }
1349
+
1350
+ blockloop = false;
1351
+ }
1352
+
11131353 boolean IsInfinite()
11141354 {
11151355 if (blockloop)
....@@ -1180,78 +1420,16 @@
11801420 return;
11811421
11821422 blockloop = true;
1423
+
1424
+ other.parent = parent;
1425
+
11831426 //System.out.println("COPY " + this + " to " + other);
11841427 //new Exception().printStackTrace();
1428
+ deepCopyNode(other);
11851429
1186
- other.parent = parent;
1187
- if (toParent != null)
1188
- {
1189
- other.toParent = LA.newMatrix();
1190
- other.fromParent = LA.newMatrix();
1191
- LA.matCopy(toParent, other.toParent);
1192
- LA.matCopy(fromParent, other.fromParent);
1193
- if (toParentMarked != null)
1194
- {
1195
- other.toParentMarked = LA.newMatrix();
1196
- other.fromParentMarked = LA.newMatrix();
1197
- LA.matCopy(toParentMarked, other.toParentMarked);
1198
- LA.matCopy(fromParentMarked, other.fromParentMarked);
1199
- }
1200
- }
1201
- else
1202
- {
1203
- if (other.toParent == null)
1204
-// assert(other.toParent == null);
1205
-// new Exception().printStackTrace();
1206
- System.err.println("null parent: " + other);
1207
- }
1208
- /*
1209
- double ident[][] = LA.newMatrix();
1210
- if (bRep == null)
1211
- other.bRep = null;
1212
- else
1213
- other.bRep = new BoundaryRep(bRep, ident);
1214
- */
1215
- // Really new...
12161430 other.bRep = bRep; // Share the geometry
12171431
12181432 other.support = support; // Share the support
1219
-
1220
- //other.editWindow = null;
1221
- if (name == null)
1222
- other.name = null;
1223
- else
1224
- other.name = new String(name);
1225
-
1226
- if (material != null)
1227
- {
1228
- other.material = new cMaterial(material);
1229
- } else
1230
- {
1231
- other.material = null;
1232
- }
1233
-
1234
- other.GetTextures().name = GetTextures().name;
1235
-
1236
- CopyExtraMaterial(other);
1237
-
1238
- other.touched = touched;
1239
- other.softtouched = softtouched;
1240
-
1241
- other.random = random;
1242
- other.link2master = link2master;
1243
- other.transformcount = transformcount;
1244
- other.marked = marked;
1245
- other.skip = skip;
1246
- other.count = count;
1247
- other.flipV = flipV;
1248
- other.live = live;
1249
- other.rewind = rewind;
1250
- other.hide = hide;
1251
- other.texres = texres;
1252
- other.speedup = speedup;
1253
- other.height = height;
1254
- other.depth = depth;
12551433
12561434 // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist)
12571435 // {
....@@ -1307,17 +1485,24 @@
13071485 if ((mask & GEOMETRY) != 0)
13081486 {
13091487 if (bRep != null)
1310
- bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
1311
- else
1312
- assert(other.bRep == null);
1313
-
1314
- if (bRep != null)
13151488 {
1489
+ bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
13161490 CameraPane.RemoveList(bRep.displaylist);
13171491 bRep.displaylist = 0; // june 2013 -1;
13181492 }
13191493 else
1320
- bRep = bRep;
1494
+ {
1495
+ //assert(other.bRep == null);
1496
+ bRep = other.bRep;
1497
+ }
1498
+
1499
+// if (bRep != null)
1500
+// {
1501
+// CameraPane.RemoveList(bRep.displaylist);
1502
+// bRep.displaylist = 0; // june 2013 -1;
1503
+// }
1504
+// else
1505
+// bRep = bRep;
13211506 }
13221507
13231508 /* Use a MASK = GEO/MAT
....@@ -2293,11 +2478,6 @@
22932478
22942479 InitOthers();
22952480
2296
- if (this instanceof Camera)
2297
- {
2298
- material.shift = 90;
2299
- }
2300
-
23012481 material.multiply = multiply;
23022482
23032483 if (multiply)
....@@ -2438,6 +2618,11 @@
24382618 else
24392619 {
24402620 //((ObjEditor)editWindow).SetupUI2(null);
2621
+ if (objectUI != null)
2622
+ ((ObjEditor)objectUI).pinButton.setSelected(pinned);
2623
+ else
2624
+ //new Exception().printStackTrace();
2625
+ System.err.println("objectUI is null");
24412626 }
24422627 }
24432628
....@@ -2567,7 +2752,8 @@
25672752 private static final int editSelf = 1;
25682753 private static final int editChild = 2;
25692754
2570
- void drawEditHandles(ClickInfo info, int level)
2755
+ void drawEditHandles(//ClickInfo info,
2756
+ int level)
25712757 {
25722758 if (level == 0)
25732759 {
....@@ -2575,7 +2761,8 @@
25752761 return;
25762762
25772763 Object3D selectee;
2578
- for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(info, level + 1))
2764
+ for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(//info,
2765
+ level + 1))
25792766 {
25802767 selectee = (Object3D) e.nextElement();
25812768 }
....@@ -2583,19 +2770,22 @@
25832770 } else
25842771 {
25852772 //super.
2586
- drawEditHandles0(info, level + 1);
2773
+ drawEditHandles0(//info,
2774
+ level + 1);
25872775 }
25882776 }
25892777
2590
- boolean doEditClick(ClickInfo info, int level)
2778
+ boolean doEditClick(//ClickInfo info,
2779
+ int level)
25912780 {
25922781 doSomething = 0;
25932782 if (level == 0)
25942783 {
2595
- return doParentClick(info);
2784
+ return doParentClick(); //info);
25962785 }
25972786 if (//super.
2598
- doEditClick0(info, level))
2787
+ doEditClick0(//info,
2788
+ level))
25992789 {
26002790 doSomething = 1;
26012791 return true;
....@@ -2605,7 +2795,7 @@
26052795 }
26062796 }
26072797
2608
- boolean doParentClick(ClickInfo info)
2798
+ boolean doParentClick() //ClickInfo info)
26092799 {
26102800 if (selection == null)
26112801 {
....@@ -2618,7 +2808,8 @@
26182808 for (java.util.Enumeration e = selection.elements(); e.hasMoreElements();)
26192809 {
26202810 Object3D selectee = (Object3D) e.nextElement();
2621
- if (selectee.doEditClick(info, 1))
2811
+ if (selectee.doEditClick(//info,
2812
+ 1))
26222813 {
26232814 childToDrag = selectee;
26242815 doSomething = 2;
....@@ -2630,13 +2821,15 @@
26302821 return retval;
26312822 }
26322823
2633
- void doEditDrag(ClickInfo info, boolean opposite)
2824
+ void doEditDrag(//ClickInfo clickInfo,
2825
+ boolean opposite)
26342826 {
26352827 switch (doSomething)
26362828 {
26372829 case 1: // '\001'
26382830 //super.
2639
- doEditDrag0(info, opposite);
2831
+ doEditDrag0(//clickInfo,
2832
+ opposite);
26402833 break;
26412834
26422835 case 2: // '\002'
....@@ -2649,11 +2842,13 @@
26492842 {
26502843 //sel.hitSomething = childToDrag.hitSomething;
26512844 //childToDrag.doEditDrag(info);
2652
- sel.doEditDrag(info, opposite);
2845
+ sel.doEditDrag(//clickInfo,
2846
+ opposite);
26532847 } else
26542848 {
26552849 //super.
2656
- doEditDrag0(info, opposite);
2850
+ doEditDrag0(//clickInfo,
2851
+ opposite);
26572852 }
26582853 }
26592854 break;
....@@ -2671,6 +2866,9 @@
26712866 {
26722867 deselectAll();
26732868 }
2869
+
2870
+ new Exception().printStackTrace();
2871
+
26742872 ClickInfo newInfo = new ClickInfo();
26752873 newInfo.flags = info.flags;
26762874 newInfo.bounds = info.bounds;
....@@ -3100,7 +3298,10 @@
31003298 {
31013299 if (bRep != null)
31023300 {
3301
+ //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact).
31033302 bRep.GenerateNormals(crease);
3303
+ if (!bRep.trimmed)
3304
+ bRep.MergeNormals();
31043305 Touch();
31053306 }
31063307 }
....@@ -3175,6 +3376,105 @@
31753376 blockloop = false;
31763377 }
31773378
3379
+ public void ResetTransform(int mask)
3380
+ {
3381
+ Object3D obj = this;
3382
+
3383
+ if (mask == -1)
3384
+ {
3385
+ if (obj instanceof Camera) // jan 2014
3386
+ {
3387
+ LA.matIdentity(obj.toParent);
3388
+ LA.matIdentity(obj.fromParent);
3389
+ }
3390
+ else
3391
+ {
3392
+ obj.toParent = null; // jan 2014 LA.matIdentity(obj.toParent);
3393
+ obj.fromParent = null; // LA.matIdentity(obj.fromParent);
3394
+ }
3395
+ return;
3396
+ }
3397
+
3398
+ if ((mask&2) != 0) // Scale/rotation
3399
+ {
3400
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = 1;
3401
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3402
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3403
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1;
3404
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3405
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3406
+ }
3407
+ if ((mask&1) != 0) // Translation
3408
+ {
3409
+ if (obj.toParent != null)
3410
+ {
3411
+ obj.toParent[3][0] = obj.toParent[3][1] = obj.toParent[3][2] = 0;
3412
+ obj.fromParent[3][0] = obj.fromParent[3][1] = obj.fromParent[3][2] = 0;
3413
+ }
3414
+ }
3415
+ }
3416
+
3417
+ public void Scale(int scale)
3418
+ {
3419
+ Object3D obj = this;
3420
+
3421
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = scale;
3422
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3423
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3424
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1/scale;
3425
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3426
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3427
+ }
3428
+
3429
+ public void TextureRatioTransform(int axis)
3430
+ {
3431
+ cTexture tex = GetTextures();
3432
+
3433
+ com.sun.opengl.util.texture.TextureData texturedata = null;
3434
+
3435
+ try
3436
+ {
3437
+ texturedata = Globals.theRenderer.GetTextureData(tex, false, texres);
3438
+ }
3439
+ catch (Exception e)
3440
+ {
3441
+ System.err.println("FAIL TextureRatio: " + this);
3442
+ }
3443
+
3444
+ LA.matIdentity(Object3D.mat);
3445
+ Object3D.mat[axis][axis] = (double)texturedata.getWidth() / texturedata.getHeight();
3446
+
3447
+ if (toParent == null)
3448
+ {
3449
+ toParent = LA.newMatrix();
3450
+ fromParent = LA.newMatrix();
3451
+ }
3452
+
3453
+ ResetTransform(2);
3454
+
3455
+ LA.matConcat(Object3D.mat, fromParent, fromParent);
3456
+ LA.matInvert(fromParent, toParent);
3457
+ }
3458
+
3459
+ void TextureRatio(int axis)
3460
+ {
3461
+ if (blockloop)
3462
+ return;
3463
+
3464
+ blockloop = true;
3465
+
3466
+ TextureRatioTransform(axis);
3467
+
3468
+ for (int i=Size(); --i>=0;)
3469
+ {
3470
+ Object3D v = get(i);
3471
+
3472
+ v.TextureRatio(axis);
3473
+ }
3474
+
3475
+ blockloop = false;
3476
+ }
3477
+
31783478 void TransformChildren()
31793479 {
31803480 if (toParent != null)
....@@ -3417,6 +3717,7 @@
34173717 if (bRep != null)
34183718 {
34193719 //bRep.RemoveOneTriangle();
3720
+ System.out.println();
34203721 System.out.println("Reducing " + this);
34213722 if (name != null && name.contains("lockpickstraps"))
34223723 name = name;
....@@ -3528,15 +3829,47 @@
35283829
35293830 void ClearMaterials()
35303831 {
3832
+ if (blockloop)
3833
+ return;
3834
+
3835
+ blockloop = true;
3836
+
35313837 ClearMaterial();
3532
- for (int i = 0; i < size(); i++)
3838
+ for (int i = 0; i < Size(); i++)
35333839 {
3534
- Object3D child = (Object3D) reserve(i);
3840
+ Object3D child = (Object3D) get(i);
35353841 if (child == null)
35363842 continue;
35373843 child.ClearMaterials();
3538
- release(i);
35393844 }
3845
+
3846
+ blockloop = false;
3847
+ }
3848
+
3849
+ void ClearVersionList()
3850
+ {
3851
+ this.versionlist = null;
3852
+ this.versionindex = -1;
3853
+ this.versiontable = null;
3854
+ }
3855
+
3856
+ void ClearVersions()
3857
+ {
3858
+ if (blockloop)
3859
+ return;
3860
+
3861
+ blockloop = true;
3862
+
3863
+ ClearVersionList();
3864
+ for (int i = 0; i < Size(); i++)
3865
+ {
3866
+ Object3D child = (Object3D) get(i);
3867
+ if (child == null)
3868
+ continue;
3869
+ child.ClearVersions();
3870
+ }
3871
+
3872
+ blockloop = false;
35403873 }
35413874
35423875 void FlipV(boolean flip)
....@@ -3715,6 +4048,7 @@
37154048
37164049 void RevertMeshes()
37174050 {
4051
+ // BLOCKLOOP
37184052 if (this instanceof cMesh)
37194053 {
37204054 ((cMesh)this).Revert();
....@@ -3745,11 +4079,6 @@
37454079 Touch();
37464080 }
37474081
3748
- ResetRecur();
3749
- }
3750
-
3751
- void ResetRecur()
3752
- {
37534082 for (int i = 0; i < size(); i++)
37544083 {
37554084 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3963,8 +4292,8 @@
39634292 Touch();
39644293 }
39654294
3966
- transient cVector min = new cVector();
3967
- transient cVector max = new cVector();
4295
+ transient cVector min;
4296
+ transient cVector max;
39684297
39694298 void getBounds(cVector minima, cVector maxima, boolean xform)
39704299 {
....@@ -3980,15 +4309,15 @@
39804309 if (blockloop)
39814310 return;
39824311
3983
- if (min == null) // ???
4312
+ if (min == null)
39844313 {
39854314 min = new cVector();
39864315 max = new cVector();
39874316 }
39884317
3989
- for (int i = 0; i<size(); i++)
4318
+ for (int i = 0; i<Size(); i++)
39904319 {
3991
- Object3D child = (Object3D) reserve(i);
4320
+ Object3D child = (Object3D) get(i); //reserve(i);
39924321 if (child == null)
39934322 continue;
39944323
....@@ -4007,21 +4336,21 @@
40074336 if (child.hide && !(child instanceof Merge) || child.skip)
40084337 //if (child.hide)
40094338 {
4010
- release(i);
4339
+ //release(i);
40114340 continue;
40124341 }
40134342
40144343 blockloop = true;
40154344 child.getBounds(min, max, true); // xform);
40164345 blockloop = false;
4017
- release(i);
4346
+ //release(i);
40184347
40194348 MinMax(minima, maxima);
40204349 }
40214350
40224351 if (bRep != null)
40234352 {
4024
- bRep.getBounds(minima,maxima,this);
4353
+ bRep.getBounds(minima, maxima, xform?this:null);
40254354 }
40264355
40274356 if (false) // xform)
....@@ -5526,6 +5855,11 @@
55265855 if (fullname == null)
55275856 return "";
55285857
5858
+ if (fullname.pigment != null)
5859
+ {
5860
+ return fullname.pigment;
5861
+ }
5862
+
55295863 // System.out.println("Fullname = " + fullname);
55305864
55315865 // Does not work on Windows due to C:
....@@ -5538,7 +5872,7 @@
55385872
55395873 if (split.length == 0)
55405874 {
5541
- return "";
5875
+ return fullname.pigment = "";
55425876 }
55435877
55445878 if (split.length <= 2)
....@@ -5546,22 +5880,27 @@
55465880 if (fullname.name.endsWith(":"))
55475881 {
55485882 // Windows
5549
- return fullname.name.substring(0, fullname.name.length()-1);
5883
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
55505884 }
55515885
5552
- return split[0];
5886
+ return fullname.pigment = split[0];
55535887 }
55545888
55555889 // Windows
55565890 assert(split.length == 4);
55575891
5558
- return split[0] + ":" + split[1];
5892
+ return fullname.pigment = split[0] + ":" + split[1];
55595893 }
55605894
55615895 static String GetBump(cTexture fullname)
55625896 {
55635897 if (fullname == null)
55645898 return "";
5899
+
5900
+ if (fullname.bump != null)
5901
+ {
5902
+ return fullname.bump;
5903
+ }
55655904
55665905 // System.out.println("Fullname = " + fullname);
55675906 // Does not work on Windows due to C:
....@@ -5573,12 +5912,12 @@
55735912
55745913 if (split.length == 0)
55755914 {
5576
- return "";
5915
+ return fullname.bump = "";
55775916 }
55785917
55795918 if (split.length == 1)
55805919 {
5581
- return "";
5920
+ return fullname.bump = "";
55825921 }
55835922
55845923 if (split.length == 2)
....@@ -5586,16 +5925,16 @@
55865925 if (fullname.name.endsWith(":"))
55875926 {
55885927 // Windows
5589
- return "";
5928
+ return fullname.bump = "";
55905929 }
55915930
5592
- return split[1];
5931
+ return fullname.bump = split[1];
55935932 }
55945933
55955934 // Windows
55965935 assert(split.length == 4);
55975936
5598
- return split[2] + ":" + split[3];
5937
+ return fullname.bump = split[2] + ":" + split[3];
55995938 }
56005939
56015940 String GetPigmentTexture()
....@@ -5678,6 +6017,9 @@
56786017 texname = "";
56796018
56806019 GetTextures().name = texname + ":" + GetBump(GetTextures());
6020
+
6021
+ GetTextures().pigment = null;
6022
+
56816023 Touch();
56826024 }
56836025
....@@ -5751,6 +6093,8 @@
57516093
57526094 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
57536095
6096
+ GetTextures().bump = null;
6097
+
57546098 Touch();
57556099 }
57566100
....@@ -5775,12 +6119,23 @@
57756119 }
57766120 }
57776121
5778
- void EmbedTextures()
6122
+ void EmbedTextures(boolean embed)
57796123 {
57806124 if (blockloop)
57816125 return;
57826126
5783
- CameraPane.EmbedTextures(texture);
6127
+ //if (GetTextures() != null)
6128
+ if (embed)
6129
+ CameraPane.EmbedTextures(GetTextures());
6130
+ else
6131
+ {
6132
+ GetTextures().pigmentdata = null;
6133
+ GetTextures().bumpdata = null;
6134
+ GetTextures().pw = 0;
6135
+ GetTextures().ph = 0;
6136
+ GetTextures().bw = 0;
6137
+ GetTextures().bh = 0;
6138
+ }
57846139
57856140 int nb = Size();
57866141 for (int i = 0; i < nb; i++)
....@@ -5791,7 +6146,7 @@
57916146 continue;
57926147
57936148 blockloop = true;
5794
- child.EmbedTextures();
6149
+ child.EmbedTextures(embed);
57956150 blockloop = false;
57966151 }
57976152 }
....@@ -5820,6 +6175,11 @@
58206175 return false;
58216176
58226177 return parent.IsLive();
6178
+ }
6179
+
6180
+ boolean IsDynamic()
6181
+ {
6182
+ return live && bRep != null;
58236183 }
58246184
58256185 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
....@@ -5882,8 +6242,11 @@
58826242 if (support != null)
58836243 support = support;
58846244
5885
- //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5886
- boolean usecalllists = !IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6245
+ boolean usecalllists = !IsDynamic() &&
6246
+ IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6247
+ //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6248
+
6249
+ //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
58876250
58886251 if (!usecalllists && bRep != null && bRep.displaylist > 0)
58896252 {
....@@ -5893,8 +6256,9 @@
58936256 // usecalllists &= !(parent instanceof RandomNode);
58946257 // usecalllists = false;
58956258
5896
- if (GetBRep() != null)
5897
- usecalllists = usecalllists;
6259
+ if (display.DrawMode() == display.SHADOW)
6260
+ //GetBRep() != null)
6261
+ usecalllists = !!usecalllists;
58986262 //System.out.println("draw " + this);
58996263 //new Exception().printStackTrace();
59006264
....@@ -5916,7 +6280,7 @@
59166280 if (!(this instanceof Composite))
59176281 touched = false;
59186282 //if (displaylist == -1 && usecalllists)
5919
- if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
6283
+ if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013
59206284 {
59216285 bRep.displaylist = display.GenList();
59226286 assert(bRep.displaylist != 0);
....@@ -5927,7 +6291,7 @@
59276291
59286292 //System.out.println("\tnew list " + list);
59296293 //gl.glDrawBuffer(gl.GL_NONE);
5930
- if (usecalllists)
6294
+ if (usecalllists && bRep.displaylist > 0)
59316295 {
59326296 // System.err.println("new list " + bRep.displaylist + " for " + this);
59336297 display.NewList(bRep.displaylist);
....@@ -5936,7 +6300,7 @@
59366300 CallList(display, root, selected, blocked);
59376301
59386302 // compiled = true;
5939
- if (usecalllists)
6303
+ if (usecalllists && bRep.displaylist > 0)
59406304 {
59416305 // System.err.println("end list " + bRep.displaylist + " for " + this);
59426306 display.EndList();
....@@ -5946,8 +6310,8 @@
59466310 Globals.lighttouched = true; // all panes...
59476311 }
59486312
5949
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
5950
- //touched = false;
6313
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6314
+ touched = false;
59516315
59526316 if (this instanceof Texture || this instanceof TextureNode)
59536317 {
....@@ -6048,6 +6412,20 @@
60486412 {
60496413 drawSelf(display, root, selected, blocked);
60506414 }
6415
+
6416
+// if (!(this instanceof Composite))
6417
+// {
6418
+// for (int i = 0; i < size(); i++)
6419
+// {
6420
+// Object3D child = (Object3D) reserve(i);
6421
+// if (child == null)
6422
+// continue;
6423
+//
6424
+// child.draw(display, root, selected, blocked);
6425
+//
6426
+// release(i);
6427
+// }
6428
+// }
60516429 } else
60526430 {
60536431 /*
....@@ -6080,13 +6458,14 @@
60806458 boolean failedPigment = false;
60816459 boolean failedBump = false;
60826460
6461
+ CameraPane.lastObject = this;
60836462 try
60846463 {
60856464 display.BindPigmentTexture(tex, texres);
60866465 }
60876466 catch (Exception e)
60886467 {
6089
- System.err.println("FAILED: " + this);
6468
+ // System.err.println("FAILED: " + this);
60906469 failedPigment = true;
60916470 }
60926471
....@@ -6117,6 +6496,20 @@
61176496 display.CallList(bRep.displaylist);
61186497 // june 2013 drawSelf(display, root, selected);
61196498 }
6499
+ }
6500
+
6501
+ assert (!(this instanceof Composite));
6502
+ {
6503
+// CRASH MOCAP!! for (int i = 0; i < size(); i++)
6504
+// {
6505
+// Object3D child = (Object3D) reserve(i);
6506
+// if (child == null)
6507
+// continue;
6508
+//
6509
+// child.draw(display, root, selected, blocked);
6510
+//
6511
+// release(i);
6512
+// }
61206513 }
61216514 }
61226515
....@@ -6170,16 +6563,17 @@
61706563
61716564 void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
61726565 {
6173
- if (GetBRep() == null)
6174
- {
6175
- drawSelf(display, root, selected, blocked);
6176
- } else
6566
+ if (GetBRep() != null)
61776567 {
61786568 DrawNode(display, root, selected);
61796569 if (this instanceof BezierPatch)
61806570 {
61816571 //drawSelf(display, root, selected);
61826572 }
6573
+ }
6574
+ else
6575
+ {
6576
+ drawSelf(display, root, selected, blocked);
61836577 }
61846578 }
61856579
....@@ -7287,20 +7681,23 @@
72877681 }
72887682 }
72897683
7290
- protected void calcHotSpot(cVector in, ClickInfo info, Point outPt, Rectangle outRec)
7684
+ static ClickInfo clickInfo = new ClickInfo();
7685
+
7686
+ protected void calcHotSpot(cVector in, //ClickInfo clickInfo,
7687
+ Point outPt, Rectangle outRec)
72917688 {
7292
- int hc = info.bounds.x + info.bounds.width / 2;
7293
- int vc = info.bounds.y + info.bounds.height / 2;
7294
- double[][] toscreen = info.toScreen;
7689
+ int hc = clickInfo.bounds.x + clickInfo.bounds.width / 2;
7690
+ int vc = clickInfo.bounds.y + clickInfo.bounds.height / 2;
7691
+ double[][] toscreen = clickInfo.toScreen;
72957692 if (toscreen == null)
72967693 {
7297
- toscreen = new Camera(info.camera.viewCode).toScreen;
7694
+ toscreen = new Camera(clickInfo.camera.viewCode).toScreen;
72987695 }
72997696 cVector vec = in;
73007697 LA.xformPos(in, toscreen, in);
73017698 //System.out.println("Distance = " + info.camera.Distance());
7302
- vec.x *= 100 * info.camera.SCALE / info.camera.Distance();
7303
- vec.y *= 100 * info.camera.SCALE / info.camera.Distance();
7699
+ vec.x *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
7700
+ vec.y *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
73047701 outPt.x = hc + (int) vec.x;
73057702 outPt.y = vc - (int) vec.y;
73067703 outRec.x = outPt.x - 3;
....@@ -7308,15 +7705,18 @@
73087705 outRec.width = outRec.height = 6;
73097706 }
73107707
7311
- protected Rectangle calcHotSpot(cVector in, ClickInfo info)
7708
+ protected Rectangle calcHotSpot(cVector in//, ClickInfo clickInfo
7709
+ )
73127710 {
73137711 Point pt = new Point(0, 0);
73147712 Rectangle rec = new Rectangle();
7315
- calcHotSpot(in, info, pt, rec);
7713
+ calcHotSpot(in, //clickInfo,
7714
+ pt, rec);
73167715 return rec;
73177716 }
73187717
7319
- void drawEditHandles0(ClickInfo info, int level)
7718
+ void drawEditHandles0(//ClickInfo clickInfo,
7719
+ int level)
73207720 {
73217721 if (level == 0)
73227722 {
....@@ -7325,16 +7725,19 @@
73257725 {
73267726 cVector origin = new cVector();
73277727 //LA.xformPos(origin, toParent, origin);
7328
- Rectangle spot = calcHotSpot(origin, info);
7728
+ if (this.clickInfo == null)
7729
+ this.clickInfo = new ClickInfo();
7730
+
7731
+ Rectangle spot = calcHotSpot(origin); //, clickInfo);
73297732 Rectangle boundary = new Rectangle();
73307733 boundary.x = spot.x - 30;
73317734 boundary.y = spot.y - 30;
73327735 boundary.width = spot.width + 60;
73337736 boundary.height = spot.height + 60;
7334
- info.g.setColor(Color.red);
7737
+ clickInfo.g.setColor(Color.white);
73357738 int spotw = spot.x + spot.width;
73367739 int spoth = spot.y + spot.height;
7337
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7740
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
73387741 // if (CameraPane.Xmin > spot.x)
73397742 // {
73407743 // CameraPane.Xmin = spot.x;
....@@ -7351,11 +7754,6 @@
73517754 // {
73527755 // CameraPane.Ymax = spoth;
73537756 // }
7354
- spot.translate(32, 32);
7355
- spotw = spot.x + spot.width;
7356
- spoth = spot.y + spot.height;
7357
- info.g.setColor(Color.cyan);
7358
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
73597757 // if (CameraPane.Xmin > spot.x)
73607758 // {
73617759 // CameraPane.Xmin = spot.x;
....@@ -7374,10 +7772,15 @@
73747772 // }
73757773 // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
73767774 //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7377
- spot.translate(0, -32);
7378
- info.g.setColor(Color.yellow);
7379
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7380
- info.g.setColor(Color.green);
7775
+ spot.translate(32, 0);
7776
+ clickInfo.g.setColor(Color.yellow);
7777
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7778
+
7779
+ spot.translate(32, 64);
7780
+ spotw = spot.x + spot.width;
7781
+ spoth = spot.y + spot.height;
7782
+ clickInfo.g.setColor(Color.cyan);
7783
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
73817784 // if (CameraPane.Xmin > spot.x)
73827785 // {
73837786 // CameraPane.Xmin = spot.x;
....@@ -7394,8 +7797,9 @@
73947797 // {
73957798 // CameraPane.Ymax = spoth;
73967799 // }
7397
- info.g.drawArc(boundary.x + info.DX, boundary.y + info.DY,
7398
- (int)(boundary.width * info.W), (int)(boundary.height * info.W), 0, 360);
7800
+ clickInfo.g.setColor(Color.green);
7801
+ clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY,
7802
+ (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360);
73997803 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
74007804 // if (CameraPane.Xmin > boundary.x)
74017805 // {
....@@ -7417,7 +7821,8 @@
74177821 }
74187822 }
74197823
7420
- boolean doEditClick0(ClickInfo info, int level)
7824
+ boolean doEditClick0(//ClickInfo clickInfo,
7825
+ int level)
74217826 {
74227827 if (level == 0)
74237828 {
....@@ -7426,8 +7831,8 @@
74267831
74277832 boolean retval = false;
74287833
7429
- startX = info.x;
7430
- startY = info.y;
7834
+ startX = clickInfo.x;
7835
+ startY = clickInfo.y;
74317836
74327837 hitSomething = -1;
74337838 cVector origin = new cVector();
....@@ -7437,22 +7842,53 @@
74377842 {
74387843 centerPt = new Point(0, 0);
74397844 }
7440
- calcHotSpot(origin, info, centerPt, spot);
7441
- if (spot.contains(info.x, info.y))
7845
+ calcHotSpot(origin, //info,
7846
+ centerPt, spot);
7847
+ if (spot.contains(clickInfo.x, clickInfo.y))
74427848 {
74437849 hitSomething = hitCenter;
74447850 retval = true;
74457851 }
74467852 spot.translate(32, 0);
7447
- if (spot.contains(info.x, info.y))
7853
+ if (spot.contains(clickInfo.x, clickInfo.y))
74487854 {
74497855 hitSomething = hitRotate;
74507856 retval = true;
74517857 }
74527858 spot.translate(0, 32);
7453
- if (spot.contains(info.x, info.y))
7859
+ spot.translate(32, 0);
7860
+ spot.translate(0, 32);
7861
+ if (spot.contains(clickInfo.x, clickInfo.y))
74547862 {
74557863 hitSomething = hitScale;
7864
+
7865
+ double scale = 0.005f * clickInfo.camera.Distance();
7866
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
7867
+ double sign = 1;
7868
+ if (hScale < 0)
7869
+ {
7870
+ sign = -1;
7871
+ }
7872
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
7873
+ if (hScale < 0.01)
7874
+ {
7875
+ //hScale = 0.01;
7876
+ }
7877
+
7878
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
7879
+ sign = 1;
7880
+ if (vScale < 0)
7881
+ {
7882
+ sign = -1;
7883
+ }
7884
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
7885
+ if (vScale < 0.01)
7886
+ {
7887
+ //vScale = 0.01;
7888
+ }
7889
+
7890
+ clickInfo.scale = Math.sqrt(hScale*hScale + vScale*vScale);
7891
+
74567892 retval = true;
74577893 }
74587894
....@@ -7462,7 +7898,7 @@
74627898 }
74637899
74647900 //System.out.println("info.modifiers = " + info.modifiers);
7465
- modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
7901
+ modified = (clickInfo.modifiers & CameraPane.SHIFT) != 0; // Was META
74667902 //System.out.println("modified = " + modified);
74677903 //new Exception().printStackTrace();
74687904 //viewCode = info.pane.renderCamera.viewCode;
....@@ -7490,7 +7926,8 @@
74907926 return true;
74917927 }
74927928
7493
- void doEditDrag0(ClickInfo info, boolean opposite)
7929
+ void doEditDrag0(//ClickInfo info,
7930
+ boolean opposite)
74947931 {
74957932 if (hitSomething == 0)
74967933 {
....@@ -7504,7 +7941,7 @@
75047941
75057942 //System.out.println("hitSomething = " + hitSomething);
75067943
7507
- double scale = 0.005f * info.camera.Distance();
7944
+ double scale = 0.005f * clickInfo.camera.Distance();
75087945
75097946 cVector xlate = new cVector();
75107947 //cVector xlate2 = new cVector();
....@@ -7518,7 +7955,9 @@
75187955
75197956 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
75207957
7521
- if (modified || opposite)
7958
+ // Modified could snap
7959
+ if (//modified ||
7960
+ opposite)
75227961 {
75237962 //assert(false);
75247963 /*
....@@ -7538,8 +7977,8 @@
75387977 toParent[3][i] = xlate.get(i);
75397978 LA.matInvert(toParent, fromParent);
75407979 */
7541
- cVector delta = LA.newVector(0, 0, startY - info.y);
7542
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
7980
+ cVector delta = LA.newVector(0, 0, startY - clickInfo.y);
7981
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
75437982
75447983 LA.matCopy(startMat, toParent);
75457984 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7548,7 +7987,7 @@
75487987 } else
75497988 {
75507989 //LA.xformDir(delta, info.camera.fromScreen, delta);
7551
- cVector up = new cVector(info.camera.up);
7990
+ cVector up = new cVector(clickInfo.camera.up);
75527991 cVector away = new cVector();
75537992 //cVector right2 = new cVector();
75547993 //LA.vecCross(up, cVector.Z, right);
....@@ -7565,19 +8004,19 @@
75658004 LA.xformDir(up, ClickInfo.matbuffer, up);
75668005 // if (!CameraPane.LOCALTRANSFORM)
75678006 LA.xformDir(up, Globals.theRenderer.RenderCamera().toScreen, up);
7568
- LA.xformDir(info.camera.away, ClickInfo.matbuffer, away);
8007
+ LA.xformDir(clickInfo.camera.away, ClickInfo.matbuffer, away);
75698008 // if (!CameraPane.LOCALTRANSFORM)
75708009 LA.xformDir(away, Globals.theRenderer.RenderCamera().toScreen, away);
75718010 //LA.vecCross(up, cVector.Z, right2);
75728011
7573
- cVector delta = LA.newVector(info.x - startX, startY - info.y, 0);
8012
+ cVector delta = LA.newVector(clickInfo.x - startX, startY - clickInfo.y, 0);
75748013
75758014 //System.out.println("DELTA0 = " + delta);
75768015 //System.out.println("AWAY = " + info.camera.away);
75778016 //System.out.println("UP = " + info.camera.up);
75788017 if (away.z > 0)
75798018 {
7580
- if (info.camera.up.x == 0) // LA.vecDot(right, right2)<0)
8019
+ if (clickInfo.camera.up.x == 0) // LA.vecDot(right, right2)<0)
75818020 {
75828021 delta.x = -delta.x;
75838022 } else
....@@ -7592,7 +8031,7 @@
75928031 //System.out.println("DELTA1 = " + delta);
75938032 LA.xformDir(delta, ClickInfo.matbuffer, delta);
75948033 //System.out.println("DELTA2 = " + delta);
7595
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
8034
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
75968035 LA.matCopy(startMat, toParent);
75978036 //System.out.println("DELTA3 = " + delta);
75988037 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7602,8 +8041,8 @@
76028041 break;
76038042
76048043 case hitRotate: // rotate
7605
- int dx = info.x - centerPt.x;
7606
- int dy = -(info.y - centerPt.y);
8044
+ int dx = clickInfo.x - centerPt.x;
8045
+ int dy = -(clickInfo.y - centerPt.y);
76078046 double angle = (double) Math.atan2(dx, dy);
76088047 angle = -(1.570796 - angle);
76098048
....@@ -7612,7 +8051,7 @@
76128051
76138052 if (modified)
76148053 {
7615
- // Rotate 90 degrees
8054
+ // Rotate 45 degrees
76168055 angle /= (Math.PI / 4);
76178056 angle = Math.floor(angle + 0.5);
76188057 angle *= (Math.PI / 4);
....@@ -7626,7 +8065,7 @@
76268065 }
76278066 /**/
76288067
7629
- switch (info.pane.RenderCamera().viewCode)
8068
+ switch (clickInfo.pane.RenderCamera().viewCode)
76308069 {
76318070 case 1: // '\001'
76328071 LA.matZRotate(toParent, angle);
....@@ -7653,7 +8092,7 @@
76538092 break;
76548093
76558094 case hitScale: // scale
7656
- double hScale = (double) (info.x - centerPt.x) / 32;
8095
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
76578096 double sign = 1;
76588097 if (hScale < 0)
76598098 {
....@@ -7665,7 +8104,7 @@
76658104 //hScale = 0.01;
76668105 }
76678106
7668
- double vScale = (double) (info.y - centerPt.y) / 32;
8107
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
76698108 sign = 1;
76708109 if (vScale < 0)
76718110 {
....@@ -7676,6 +8115,7 @@
76768115 {
76778116 //vScale = 0.01;
76788117 }
8118
+
76798119 LA.matCopy(startMat, toParent);
76808120 /**/
76818121 for (int i = 0; i < 3; i++)
....@@ -7685,33 +8125,39 @@
76858125 }
76868126 /**/
76878127
7688
- double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
8128
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / clickInfo.scale;
76898129
76908130 if (totalScale < 0.01)
76918131 {
76928132 totalScale = 0.01;
76938133 }
76948134
7695
- switch (info.pane.RenderCamera().viewCode)
8135
+ switch (clickInfo.pane.RenderCamera().viewCode)
76968136 {
76978137 case 3: // '\001'
76988138 if (modified || opposite)
76998139 {
8140
+ if (modified) // && opposite)
8141
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8142
+ else
77008143 //LA.matScale(toParent, 1, hScale, vScale);
7701
- LA.matScale(toParent, totalScale, 1, 1);
8144
+ LA.matScale(toParent, totalScale, 1, 1);
77028145 } // vScale, 1);
77038146 else
77048147 {
77058148 // EXCEPTION!
7706
- LA.matScale(toParent, totalScale, totalScale, totalScale);
8149
+ LA.matScale(toParent, 1, totalScale, totalScale);
77078150 } // vScale, 1);
77088151 break;
77098152
77108153 case 2: // '\002'
77118154 if (modified || opposite)
77128155 {
7713
- //LA.matScale(toParent, hScale, 1, vScale);
7714
- LA.matScale(toParent, 1, totalScale, 1);
8156
+ if (modified) // && opposite)
8157
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8158
+ else
8159
+ //LA.matScale(toParent, hScale, 1, vScale);
8160
+ LA.matScale(toParent, 1, totalScale, 1);
77158161 } else
77168162 {
77178163 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7721,8 +8167,11 @@
77218167 case 1: // '\003'
77228168 if (modified || opposite)
77238169 {
7724
- //LA.matScale(toParent, hScale, vScale, 1);
7725
- LA.matScale(toParent, 1, 1, totalScale);
8170
+ if (modified) // && opposite)
8171
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8172
+ else
8173
+ //LA.matScale(toParent, hScale, vScale, 1);
8174
+ LA.matScale(toParent, 1, 1, totalScale);
77268175 } else
77278176 {
77288177 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7759,7 +8208,7 @@
77598208 } // NEW ...
77608209
77618210
7762
- info.pane.repaint();
8211
+ clickInfo.pane.repaint();
77638212 }
77648213
77658214 boolean overflow = false;
....@@ -7873,7 +8322,7 @@
78738322 if (!Globals.ADVANCED)
78748323 return objname;
78758324
7876
- return objname + " " + System.identityHashCode(this);
8325
+ return objname + " " + System.identityHashCode(this) + " " + GetUUID();
78778326 }
78788327
78798328 public int hashCode()
....@@ -8118,8 +8567,8 @@
81188567 private static cVector2 qq2 = new cVector2();
81198568 private static cVector2 rr2 = new cVector2();
81208569 private static cVector2 ss2 = new cVector2();
8121
- private static cVector edge1 = new cVector();
8122
- private static cVector edge2 = new cVector();
8570
+// private static cVector edge1 = new cVector();
8571
+// private static cVector edge2 = new cVector();
81238572 //private static cVector norm = new cVector();
81248573 /*transient private*/ int hitSomething;
81258574 static final int hitCenter = 1;
....@@ -8317,7 +8766,269 @@
83178766
83188767 Touch();
83198768 }
8769
+
8770
+ static Vertex s1 = new Vertex();
8771
+ static Vertex s2 = new Vertex();
8772
+ static Vertex s3 = new Vertex();
83208773
8774
+ boolean intersectMesh(Ray ray, IntersectResult result)
8775
+ {
8776
+ boolean success = false;
8777
+
8778
+ if (bRep.stripified)
8779
+ {
8780
+ int[] strips = bRep.getRawIndices();
8781
+
8782
+ // TRIANGLE STRIP ARRAY
8783
+ if (bRep.trimmed)
8784
+ {
8785
+ float[] v = bRep.getRawVertices();
8786
+
8787
+ int count3 = 0;
8788
+
8789
+ if (v.length > 0)
8790
+ {
8791
+ for (int i = 0; i < strips.length; i++)
8792
+ {
8793
+ s1.set(v[count3], v[count3 + 1], v[count3 + 2]);
8794
+ count3 += 3;
8795
+
8796
+ s2.set(v[count3], v[count3 + 1], v[count3 + 2]);
8797
+ count3 += 3;
8798
+
8799
+ for (int j = 0; j < strips[i] - 2; j++)
8800
+ {
8801
+ s3.set(v[count3], v[count3 + 1], v[count3 + 2]);
8802
+ count3 += 3;
8803
+
8804
+ if (j%2 == 0)
8805
+ success |= intersectTriangle(ray, result, s1, s2, s3);
8806
+ else
8807
+ success |= intersectTriangle(ray, result, s1, s3, s2);
8808
+
8809
+ s1.set(s2);
8810
+ s2.set(s3);
8811
+ }
8812
+ }
8813
+ }
8814
+
8815
+ assert count3 == v.length;
8816
+ }
8817
+ else // !trimmed
8818
+ {
8819
+ int count = 0;
8820
+ for (int i = 0; i < strips.length; i++)
8821
+ {
8822
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
8823
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
8824
+
8825
+ for (int j = 0; j < strips[i] - 2; j++)
8826
+ {
8827
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
8828
+
8829
+ if (j%2 == 0)
8830
+ success |= intersectTriangle(ray, result, p, q, r);
8831
+ else
8832
+ success |= intersectTriangle(ray, result, p, r, q);
8833
+
8834
+ p = q;
8835
+ q = r;
8836
+ }
8837
+ }
8838
+ }
8839
+ } else // catch (Error e)
8840
+ {
8841
+ int facecount = bRep.FaceCount();
8842
+ for (int i = 0; i < facecount; i++)
8843
+ {
8844
+ Face face = bRep.GetFace(i);
8845
+
8846
+ Vertex p = bRep.GetVertex(face.p);
8847
+ Vertex q = bRep.GetVertex(face.q);
8848
+ Vertex r = bRep.GetVertex(face.r);
8849
+
8850
+ success |= intersectTriangle(ray, result, p, q, r);
8851
+ }
8852
+ }
8853
+
8854
+ return success;
8855
+ }
8856
+
8857
+ static cVector eye = new cVector();
8858
+ static cVector dir = new cVector();
8859
+
8860
+ transient BBox bbox = null;
8861
+
8862
+ boolean intersect(Ray ray, IntersectResult result)
8863
+ {
8864
+ double eyex = ray.eyePoint.x;
8865
+ double eyey = ray.eyePoint.y;
8866
+ double eyez = ray.eyePoint.z;
8867
+
8868
+ double dirx = ray.viewDirection.x;
8869
+ double diry = ray.viewDirection.y;
8870
+ double dirz = ray.viewDirection.z;
8871
+
8872
+ if (this.fromParent != null)
8873
+ {
8874
+ eye.x = eyex;
8875
+ eye.y = eyey;
8876
+ eye.z = eyez;
8877
+ dir.x = dirx;
8878
+ dir.y = diry;
8879
+ dir.z = dirz;
8880
+
8881
+ LA.xformPos(eye, this.fromParent, eye);
8882
+ LA.xformDir(dir, this.fromParent, dir);
8883
+
8884
+ ray.eyePoint.x = eye.x;
8885
+ ray.eyePoint.y = eye.y;
8886
+ ray.eyePoint.z = eye.z;
8887
+
8888
+ ray.viewDirection.x = dir.x;
8889
+ ray.viewDirection.y = dir.y;
8890
+ ray.viewDirection.z = dir.z;
8891
+ }
8892
+
8893
+ boolean success = false;
8894
+
8895
+ boolean touch = false;
8896
+
8897
+ if (bRep != null)
8898
+ {
8899
+ if (bbox == null)
8900
+ {
8901
+ bbox = new BBox();
8902
+
8903
+ cVector min = new cVector();
8904
+ cVector max = new cVector();
8905
+
8906
+ this.getBounds(min, max, false);
8907
+
8908
+ bbox.min.x = min.x;
8909
+ bbox.min.y = min.y;
8910
+ bbox.min.z = min.z;
8911
+
8912
+ bbox.max.x = max.x;
8913
+ bbox.max.y = max.y;
8914
+ bbox.max.z = max.z;
8915
+ }
8916
+
8917
+ if (bbox.intersect(ray, result))
8918
+ {
8919
+ success |= intersectMesh(ray, result);
8920
+ }
8921
+ else
8922
+ {
8923
+ //this.hide = true;
8924
+ touch = true;
8925
+ }
8926
+ }
8927
+
8928
+ for (int i=0; i<size(); i++)
8929
+ {
8930
+ Object3D child = (Object3D) reserve(i);
8931
+
8932
+ if (child == null)
8933
+ continue;
8934
+
8935
+ success |= child.intersect(ray, result);
8936
+ release(i);
8937
+ }
8938
+
8939
+ ray.eyePoint.x = eyex;
8940
+ ray.eyePoint.y = eyey;
8941
+ ray.eyePoint.z = eyez;
8942
+
8943
+ ray.viewDirection.x = dirx;
8944
+ ray.viewDirection.y = diry;
8945
+ ray.viewDirection.z = dirz;
8946
+
8947
+// if (touch)
8948
+// this.Touch(); // refresh display list
8949
+
8950
+ return success;
8951
+ }
8952
+
8953
+ static Vector3d edge1 = new Vector3d();
8954
+ static Vector3d edge2 = new Vector3d();
8955
+ static Vector3d P = new Vector3d();
8956
+ static Vector3d T = new Vector3d();
8957
+ static Vector3d Q = new Vector3d();
8958
+
8959
+ private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3)
8960
+ {
8961
+ /*
8962
+ Fast, Minimum Storage Ray/Triangle Intersection, Moller et al.
8963
+
8964
+ Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
8965
+ */
8966
+
8967
+ // Calculate edges of the triangle
8968
+ edge1.set(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z);
8969
+ edge2.set(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z);
8970
+
8971
+ // Calculate the determinant (U parameter)
8972
+ P.cross(ray.viewDirection, edge2);
8973
+ double det = edge1.dot(P);
8974
+
8975
+ if (det > -1e-9 && det < 1e-9)
8976
+ {
8977
+ return false;
8978
+ } // Ray lies in plane of triangle
8979
+
8980
+ double invDet = 1 / det;
8981
+
8982
+ // Calculate distance from vertex1 to ray origin
8983
+ T.set(ray.eyePoint.x - v1.x, ray.eyePoint.y - v1.y, ray.eyePoint.z - v1.z);
8984
+
8985
+ double U = (T.dot(P)) * invDet; // Calculate U parameter
8986
+
8987
+ if (U < 0.f || U > 1.f)
8988
+ {
8989
+ return false;
8990
+ } // Intersection lies outside of the triangle
8991
+
8992
+ // Calculate V parameter
8993
+ Q.cross(T, edge1);
8994
+
8995
+ double V = ray.viewDirection.dot(Q) * invDet;
8996
+
8997
+ if (V < 0.f || (U + V) > 1.f)
8998
+ {
8999
+ return false;
9000
+ } // Intersection lies outside of the triangle
9001
+
9002
+ double t = edge2.dot(Q) * invDet;
9003
+
9004
+ if (t > 1e-9) // Triangle and ray intersects
9005
+ {
9006
+ //result.isIntersected = true;
9007
+ //result.id = id;
9008
+
9009
+ if (false) // isShadow)
9010
+ {
9011
+ result.t = t;
9012
+ return true;
9013
+ } else if (t < result.t)
9014
+ {
9015
+ result.object = this;
9016
+
9017
+ result.t = t;
9018
+
9019
+ //result.p.x = ray.eyePoint.x + ray.viewDirection.x * t;
9020
+ //result.p.y = ray.eyePoint.y + ray.viewDirection.y * t;
9021
+ //result.p.z = ray.eyePoint.z + ray.viewDirection.z * t;
9022
+
9023
+ result.n.cross(edge1, edge2);
9024
+ result.n.normalize();
9025
+ }
9026
+
9027
+ return true;
9028
+ }
9029
+
9030
+ return false;
9031
+ }
83219032
83229033 public int Size()
83239034 {