Normand Briere
2019-09-17 d248db5fc21c4b0ab24968974e5e590f413ef8fc
Object3D.java
....@@ -22,15 +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 //
35
+
36
+ String skyboxname;
37
+ String skyboxext;
38
+
39
+ Object3D[] versionlist;
40
+ int versionindex = -1;
41
+
42
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
3143
3244 ScriptNode scriptnode;
3345
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
+
34132 void InitOthers()
35133 {
36134 if (projectedVertices == null || projectedVertices.length <= 2)
....@@ -42,6 +140,7 @@
42140 projectedVertices[i] = new cVector2(); // Others
43141 }
44142 projectedVertices[0].x = 100; // bump
143
+ projectedVertices[1].y = 1000; // punchthrough. only for png
45144 }
46145
47146 void MinMax(cVector minima, cVector maxima)
....@@ -168,9 +267,42 @@
168267 }
169268 }
170269
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
+
171298 void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
172299 {
300
+ if (blockloop)
301
+ return;
302
+
173303 Object3D o;
304
+
305
+ boolean isnew = false;
174306
175307 if (hashtable.containsKey(GetUUID()))
176308 {
....@@ -184,12 +316,14 @@
184316 }
185317 else
186318 {
319
+ isnew = true;
320
+
187321 o = new Object3D("copy of " + this.name);
188322
189323 hashtable.put(GetUUID(), o);
190324 }
191325
192
- if (!blockloop)
326
+ //if (!blockloop)
193327 {
194328 blockloop = true;
195329
....@@ -200,12 +334,15 @@
200334
201335 blockloop = false;
202336 }
203
-
204
- ExtractBigData(o);
337
+
338
+ //if (isnew)
339
+ ExtractBigData(o);
205340 }
206341
207342 void ExtractBigData(Object3D o)
208343 {
344
+ //System.err.println("ExtractBigData : " + this + " --> " + o);
345
+
209346 if (o.bRep != null)
210347 Grafreed.Assert(o.bRep == this.bRep);
211348
....@@ -215,6 +352,9 @@
215352 // o.transientrep = this.bRep.support;
216353 // o.bRep.support = null;
217354 // }
355
+ o.selection = this.selection;
356
+ //o.versionlist = this.versionlist;
357
+ //o.versionindex = this.versionindex;
218358
219359 if (this.support != null)
220360 {
....@@ -237,17 +377,84 @@
237377 // this.fileparent = null;
238378 }
239379
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
+
240447 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
241448 {
449
+ if (blockloop)
450
+ return;
451
+
242452 if (!hashtable.containsKey(GetUUID()))
243453 return;
244454
245455 Object3D o = hashtable.get(GetUUID());
246456
247457 RestoreBigData(o);
248
-
249
- if (blockloop)
250
- return;
251458
252459 blockloop = true;
253460
....@@ -263,11 +470,19 @@
263470
264471 void RestoreBigData(Object3D o)
265472 {
473
+ //System.err.println("RestoreBigData : " + this + " <-- " + o);
474
+ Grafreed.Assert(this.bRep == null);
475
+
266476 this.bRep = o.bRep;
267477 if (this.support != null && o.transientrep != null)
268478 {
269479 this.support.bRep = o.transientrep;
270480 }
481
+
482
+ this.selection = o.selection;
483
+
484
+ //this.versionlist = o.versionlist;
485
+ //this.versionindex = o.versionindex;
271486 // July 2019 if (this.bRep != null)
272487 // this.bRep.support = o.transientrep;
273488 // this.support = o.support;
....@@ -415,6 +630,7 @@
415630 }
416631
417632 boolean live = false;
633
+ transient boolean keepdontselect;
418634 boolean dontselect = false;
419635 boolean hide = false;
420636 boolean link2master = false; // performs reset support/master at each frame
....@@ -425,6 +641,9 @@
425641 boolean random = false;
426642 boolean speedup = false;
427643 boolean rewind = false;
644
+
645
+ // Option to sort triangles, e.g. for transparency.
646
+ boolean sort = false;
428647
429648 float NORMALPUSH = 0;
430649
....@@ -443,7 +662,7 @@
443662 {
444663 sorted = true;
445664
446
- for (int i=0; i<size()-1; i++)
665
+ for (int i=0; i<Size()-1; i++)
447666 {
448667 Object3D obji = get(i);
449668 Object3D objj = get(i+1);
....@@ -467,7 +686,7 @@
467686 {
468687 sorted = true;
469688
470
- for (int i=0; i<size()-1; i++)
689
+ for (int i=0; i<Size()-1; i++)
471690 {
472691 Object3D obji = get(i);
473692 Object3D objj = get(i+1);
....@@ -483,11 +702,11 @@
483702 }
484703 }
485704
486
- int memorysize;
705
+ transient int memorysize; // needs to be transient, dunno why
487706
488707 int MemorySize()
489708 {
490
- if (true) // memorysize == 0)
709
+ if (memorysize == 0)
491710 {
492711 try
493712 {
....@@ -602,7 +821,7 @@
602821 {
603822 if (maxcount != 1)
604823 {
605
- new Exception().printStackTrace();
824
+ //new Exception().printStackTrace();
606825 }
607826
608827 toParentMarked = LA.newMatrix();
....@@ -997,21 +1216,28 @@
9971216 {
9981217 // return true;
9991218
1000
- if (material == null || material.multiply)
1001
- 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;
10021227
1003
- // Transparent objects are dynamic because we have to sort the triangles.
1004
- return material.opacity > 0.99;
1228
+ return !sort;
10051229 }
10061230
10071231 boolean IsOpaque()
10081232 {
10091233 // return true;
10101234
1011
- if (material == null || material.multiply)
1012
- return true;
1235
+// if (material == null || material.multiply)
1236
+// return true;
1237
+//
1238
+// return material.opacity > 0.99;
10131239
1014
- return material.opacity > 0.99;
1240
+ return !sort;
10151241 }
10161242
10171243 Object3D()
....@@ -1089,8 +1315,10 @@
10891315
10901316 // will share the geometry
10911317 assert (!(this instanceof Composite));
1092
- return deepCopy(); // Never called for Composite
1093
-
1318
+
1319
+ Object3D obj = deepCopy(); // Never called for Composite
1320
+ obj.count = 2;
1321
+ return obj;
10941322 }
10951323
10961324 boolean HasLoops()
....@@ -1098,6 +1326,30 @@
10981326 return false;
10991327 }
11001328
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
+
11011353 boolean IsInfinite()
11021354 {
11031355 if (blockloop)
....@@ -1168,78 +1420,16 @@
11681420 return;
11691421
11701422 blockloop = true;
1423
+
1424
+ other.parent = parent;
1425
+
11711426 //System.out.println("COPY " + this + " to " + other);
11721427 //new Exception().printStackTrace();
1428
+ deepCopyNode(other);
11731429
1174
- other.parent = parent;
1175
- if (toParent != null)
1176
- {
1177
- other.toParent = LA.newMatrix();
1178
- other.fromParent = LA.newMatrix();
1179
- LA.matCopy(toParent, other.toParent);
1180
- LA.matCopy(fromParent, other.fromParent);
1181
- if (toParentMarked != null)
1182
- {
1183
- other.toParentMarked = LA.newMatrix();
1184
- other.fromParentMarked = LA.newMatrix();
1185
- LA.matCopy(toParentMarked, other.toParentMarked);
1186
- LA.matCopy(fromParentMarked, other.fromParentMarked);
1187
- }
1188
- }
1189
- else
1190
- {
1191
- if (other.toParent == null)
1192
-// assert(other.toParent == null);
1193
-// new Exception().printStackTrace();
1194
- System.err.println("null parent: " + other);
1195
- }
1196
- /*
1197
- double ident[][] = LA.newMatrix();
1198
- if (bRep == null)
1199
- other.bRep = null;
1200
- else
1201
- other.bRep = new BoundaryRep(bRep, ident);
1202
- */
1203
- // Really new...
12041430 other.bRep = bRep; // Share the geometry
12051431
12061432 other.support = support; // Share the support
1207
-
1208
- //other.editWindow = null;
1209
- if (name == null)
1210
- other.name = null;
1211
- else
1212
- other.name = new String(name);
1213
-
1214
- if (material != null)
1215
- {
1216
- other.material = new cMaterial(material);
1217
- } else
1218
- {
1219
- other.material = null;
1220
- }
1221
-
1222
- other.GetTextures().name = GetTextures().name;
1223
-
1224
- CopyExtraMaterial(other);
1225
-
1226
- other.touched = touched;
1227
- other.softtouched = softtouched;
1228
-
1229
- other.random = random;
1230
- other.link2master = link2master;
1231
- other.transformcount = transformcount;
1232
- other.marked = marked;
1233
- other.skip = skip;
1234
- other.count = count;
1235
- other.flipV = flipV;
1236
- other.live = live;
1237
- other.rewind = rewind;
1238
- other.hide = hide;
1239
- other.texres = texres;
1240
- other.speedup = speedup;
1241
- other.height = height;
1242
- other.depth = depth;
12431433
12441434 // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist)
12451435 // {
....@@ -1295,17 +1485,24 @@
12951485 if ((mask & GEOMETRY) != 0)
12961486 {
12971487 if (bRep != null)
1298
- bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
1299
- else
1300
- assert(other.bRep == null);
1301
-
1302
- if (bRep != null)
13031488 {
1489
+ bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
13041490 CameraPane.RemoveList(bRep.displaylist);
13051491 bRep.displaylist = 0; // june 2013 -1;
13061492 }
13071493 else
1308
- 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;
13091506 }
13101507
13111508 /* Use a MASK = GEO/MAT
....@@ -2281,11 +2478,6 @@
22812478
22822479 InitOthers();
22832480
2284
- if (this instanceof Camera)
2285
- {
2286
- material.shift = 90;
2287
- }
2288
-
22892481 material.multiply = multiply;
22902482
22912483 if (multiply)
....@@ -2426,6 +2618,11 @@
24262618 else
24272619 {
24282620 //((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");
24292626 }
24302627 }
24312628
....@@ -2555,7 +2752,8 @@
25552752 private static final int editSelf = 1;
25562753 private static final int editChild = 2;
25572754
2558
- void drawEditHandles(ClickInfo info, int level)
2755
+ void drawEditHandles(//ClickInfo info,
2756
+ int level)
25592757 {
25602758 if (level == 0)
25612759 {
....@@ -2563,7 +2761,8 @@
25632761 return;
25642762
25652763 Object3D selectee;
2566
- 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))
25672766 {
25682767 selectee = (Object3D) e.nextElement();
25692768 }
....@@ -2571,19 +2770,22 @@
25712770 } else
25722771 {
25732772 //super.
2574
- drawEditHandles0(info, level + 1);
2773
+ drawEditHandles0(//info,
2774
+ level + 1);
25752775 }
25762776 }
25772777
2578
- boolean doEditClick(ClickInfo info, int level)
2778
+ boolean doEditClick(//ClickInfo info,
2779
+ int level)
25792780 {
25802781 doSomething = 0;
25812782 if (level == 0)
25822783 {
2583
- return doParentClick(info);
2784
+ return doParentClick(); //info);
25842785 }
25852786 if (//super.
2586
- doEditClick0(info, level))
2787
+ doEditClick0(//info,
2788
+ level))
25872789 {
25882790 doSomething = 1;
25892791 return true;
....@@ -2593,7 +2795,7 @@
25932795 }
25942796 }
25952797
2596
- boolean doParentClick(ClickInfo info)
2798
+ boolean doParentClick() //ClickInfo info)
25972799 {
25982800 if (selection == null)
25992801 {
....@@ -2606,7 +2808,8 @@
26062808 for (java.util.Enumeration e = selection.elements(); e.hasMoreElements();)
26072809 {
26082810 Object3D selectee = (Object3D) e.nextElement();
2609
- if (selectee.doEditClick(info, 1))
2811
+ if (selectee.doEditClick(//info,
2812
+ 1))
26102813 {
26112814 childToDrag = selectee;
26122815 doSomething = 2;
....@@ -2618,13 +2821,15 @@
26182821 return retval;
26192822 }
26202823
2621
- void doEditDrag(ClickInfo info, boolean opposite)
2824
+ void doEditDrag(//ClickInfo clickInfo,
2825
+ boolean opposite)
26222826 {
26232827 switch (doSomething)
26242828 {
26252829 case 1: // '\001'
26262830 //super.
2627
- doEditDrag0(info, opposite);
2831
+ doEditDrag0(//clickInfo,
2832
+ opposite);
26282833 break;
26292834
26302835 case 2: // '\002'
....@@ -2637,11 +2842,13 @@
26372842 {
26382843 //sel.hitSomething = childToDrag.hitSomething;
26392844 //childToDrag.doEditDrag(info);
2640
- sel.doEditDrag(info, opposite);
2845
+ sel.doEditDrag(//clickInfo,
2846
+ opposite);
26412847 } else
26422848 {
26432849 //super.
2644
- doEditDrag0(info, opposite);
2850
+ doEditDrag0(//clickInfo,
2851
+ opposite);
26452852 }
26462853 }
26472854 break;
....@@ -2659,6 +2866,9 @@
26592866 {
26602867 deselectAll();
26612868 }
2869
+
2870
+ new Exception().printStackTrace();
2871
+
26622872 ClickInfo newInfo = new ClickInfo();
26632873 newInfo.flags = info.flags;
26642874 newInfo.bounds = info.bounds;
....@@ -3088,7 +3298,10 @@
30883298 {
30893299 if (bRep != null)
30903300 {
3301
+ //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact).
30913302 bRep.GenerateNormals(crease);
3303
+ if (!bRep.trimmed)
3304
+ bRep.MergeNormals();
30923305 Touch();
30933306 }
30943307 }
....@@ -3106,7 +3319,7 @@
31063319 {
31073320 if (bRep != null)
31083321 {
3109
- bRep.GenerateNormalsMINE();
3322
+ bRep.MergeNormals(); //.GenerateNormalsMINE();
31103323 Touch();
31113324 }
31123325 }
....@@ -3163,6 +3376,105 @@
31633376 blockloop = false;
31643377 }
31653378
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
+
31663478 void TransformChildren()
31673479 {
31683480 if (toParent != null)
....@@ -3405,6 +3717,7 @@
34053717 if (bRep != null)
34063718 {
34073719 //bRep.RemoveOneTriangle();
3720
+ System.out.println();
34083721 System.out.println("Reducing " + this);
34093722 if (name != null && name.contains("lockpickstraps"))
34103723 name = name;
....@@ -3516,15 +3829,47 @@
35163829
35173830 void ClearMaterials()
35183831 {
3832
+ if (blockloop)
3833
+ return;
3834
+
3835
+ blockloop = true;
3836
+
35193837 ClearMaterial();
3520
- for (int i = 0; i < size(); i++)
3838
+ for (int i = 0; i < Size(); i++)
35213839 {
3522
- Object3D child = (Object3D) reserve(i);
3840
+ Object3D child = (Object3D) get(i);
35233841 if (child == null)
35243842 continue;
35253843 child.ClearMaterials();
3526
- release(i);
35273844 }
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;
35283873 }
35293874
35303875 void FlipV(boolean flip)
....@@ -3703,6 +4048,7 @@
37034048
37044049 void RevertMeshes()
37054050 {
4051
+ // BLOCKLOOP
37064052 if (this instanceof cMesh)
37074053 {
37084054 ((cMesh)this).Revert();
....@@ -3733,11 +4079,6 @@
37334079 Touch();
37344080 }
37354081
3736
- ResetRecur();
3737
- }
3738
-
3739
- void ResetRecur()
3740
- {
37414082 for (int i = 0; i < size(); i++)
37424083 {
37434084 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3951,8 +4292,8 @@
39514292 Touch();
39524293 }
39534294
3954
- transient cVector min = new cVector();
3955
- transient cVector max = new cVector();
4295
+ transient cVector min;
4296
+ transient cVector max;
39564297
39574298 void getBounds(cVector minima, cVector maxima, boolean xform)
39584299 {
....@@ -3968,15 +4309,15 @@
39684309 if (blockloop)
39694310 return;
39704311
3971
- if (min == null) // ???
4312
+ if (min == null)
39724313 {
39734314 min = new cVector();
39744315 max = new cVector();
39754316 }
39764317
3977
- for (int i = 0; i<size(); i++)
4318
+ for (int i = 0; i<Size(); i++)
39784319 {
3979
- Object3D child = (Object3D) reserve(i);
4320
+ Object3D child = (Object3D) get(i); //reserve(i);
39804321 if (child == null)
39814322 continue;
39824323
....@@ -3995,21 +4336,21 @@
39954336 if (child.hide && !(child instanceof Merge) || child.skip)
39964337 //if (child.hide)
39974338 {
3998
- release(i);
4339
+ //release(i);
39994340 continue;
40004341 }
40014342
40024343 blockloop = true;
40034344 child.getBounds(min, max, true); // xform);
40044345 blockloop = false;
4005
- release(i);
4346
+ //release(i);
40064347
40074348 MinMax(minima, maxima);
40084349 }
40094350
40104351 if (bRep != null)
40114352 {
4012
- bRep.getBounds(minima,maxima,this);
4353
+ bRep.getBounds(minima, maxima, xform?this:null);
40134354 }
40144355
40154356 if (false) // xform)
....@@ -5409,6 +5750,51 @@
54095750 blockloop = false;
54105751 }
54115752
5753
+ void ResetSelectable()
5754
+ {
5755
+ if (blockloop)
5756
+ return;
5757
+
5758
+ blockloop = true;
5759
+
5760
+ keepdontselect = dontselect;
5761
+ dontselect = true;
5762
+
5763
+ Object3D child;
5764
+ int nb = Size();
5765
+ for (int i = 0; i < nb; i++)
5766
+ {
5767
+ child = (Object3D) get(i);
5768
+ if (child == null)
5769
+ continue;
5770
+ child.ResetSelectable();
5771
+ }
5772
+
5773
+ blockloop = false;
5774
+ }
5775
+
5776
+ void RestoreSelectable()
5777
+ {
5778
+ if (blockloop)
5779
+ return;
5780
+
5781
+ blockloop = true;
5782
+
5783
+ dontselect = keepdontselect;
5784
+
5785
+ Object3D child;
5786
+ int nb = Size();
5787
+ for (int i = 0; i < nb; i++)
5788
+ {
5789
+ child = (Object3D) get(i);
5790
+ if (child == null)
5791
+ continue;
5792
+ child.RestoreSelectable();
5793
+ }
5794
+
5795
+ blockloop = false;
5796
+ }
5797
+
54125798 boolean IsSelected()
54135799 {
54145800 if (parent == null)
....@@ -5469,6 +5855,11 @@
54695855 if (fullname == null)
54705856 return "";
54715857
5858
+ if (fullname.pigment != null)
5859
+ {
5860
+ return fullname.pigment;
5861
+ }
5862
+
54725863 // System.out.println("Fullname = " + fullname);
54735864
54745865 // Does not work on Windows due to C:
....@@ -5481,7 +5872,7 @@
54815872
54825873 if (split.length == 0)
54835874 {
5484
- return "";
5875
+ return fullname.pigment = "";
54855876 }
54865877
54875878 if (split.length <= 2)
....@@ -5489,22 +5880,27 @@
54895880 if (fullname.name.endsWith(":"))
54905881 {
54915882 // Windows
5492
- return fullname.name.substring(0, fullname.name.length()-1);
5883
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
54935884 }
54945885
5495
- return split[0];
5886
+ return fullname.pigment = split[0];
54965887 }
54975888
54985889 // Windows
54995890 assert(split.length == 4);
55005891
5501
- return split[0] + ":" + split[1];
5892
+ return fullname.pigment = split[0] + ":" + split[1];
55025893 }
55035894
55045895 static String GetBump(cTexture fullname)
55055896 {
55065897 if (fullname == null)
55075898 return "";
5899
+
5900
+ if (fullname.bump != null)
5901
+ {
5902
+ return fullname.bump;
5903
+ }
55085904
55095905 // System.out.println("Fullname = " + fullname);
55105906 // Does not work on Windows due to C:
....@@ -5516,12 +5912,12 @@
55165912
55175913 if (split.length == 0)
55185914 {
5519
- return "";
5915
+ return fullname.bump = "";
55205916 }
55215917
55225918 if (split.length == 1)
55235919 {
5524
- return "";
5920
+ return fullname.bump = "";
55255921 }
55265922
55275923 if (split.length == 2)
....@@ -5529,16 +5925,16 @@
55295925 if (fullname.name.endsWith(":"))
55305926 {
55315927 // Windows
5532
- return "";
5928
+ return fullname.bump = "";
55335929 }
55345930
5535
- return split[1];
5931
+ return fullname.bump = split[1];
55365932 }
55375933
55385934 // Windows
55395935 assert(split.length == 4);
55405936
5541
- return split[2] + ":" + split[3];
5937
+ return fullname.bump = split[2] + ":" + split[3];
55425938 }
55435939
55445940 String GetPigmentTexture()
....@@ -5621,6 +6017,9 @@
56216017 texname = "";
56226018
56236019 GetTextures().name = texname + ":" + GetBump(GetTextures());
6020
+
6021
+ GetTextures().pigment = null;
6022
+
56246023 Touch();
56256024 }
56266025
....@@ -5694,6 +6093,8 @@
56946093
56956094 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
56966095
6096
+ GetTextures().bump = null;
6097
+
56976098 Touch();
56986099 }
56996100
....@@ -5714,6 +6115,38 @@
57146115
57156116 blockloop = true;
57166117 child.ResetBumpTexture();
6118
+ blockloop = false;
6119
+ }
6120
+ }
6121
+
6122
+ void EmbedTextures(boolean embed)
6123
+ {
6124
+ if (blockloop)
6125
+ return;
6126
+
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
+ }
6139
+
6140
+ int nb = Size();
6141
+ for (int i = 0; i < nb; i++)
6142
+ {
6143
+ Object3D child = (Object3D) get(i);
6144
+
6145
+ if (child == null)
6146
+ continue;
6147
+
6148
+ blockloop = true;
6149
+ child.EmbedTextures(embed);
57176150 blockloop = false;
57186151 }
57196152 }
....@@ -5742,6 +6175,11 @@
57426175 return false;
57436176
57446177 return parent.IsLive();
6178
+ }
6179
+
6180
+ boolean IsDynamic()
6181
+ {
6182
+ return live && bRep != null;
57456183 }
57466184
57476185 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
....@@ -5804,8 +6242,11 @@
58046242 if (support != null)
58056243 support = support;
58066244
5807
- //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5808
- 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.
58096250
58106251 if (!usecalllists && bRep != null && bRep.displaylist > 0)
58116252 {
....@@ -5815,8 +6256,9 @@
58156256 // usecalllists &= !(parent instanceof RandomNode);
58166257 // usecalllists = false;
58176258
5818
- if (GetBRep() != null)
5819
- usecalllists = usecalllists;
6259
+ if (display.DrawMode() == display.SHADOW)
6260
+ //GetBRep() != null)
6261
+ usecalllists = !!usecalllists;
58206262 //System.out.println("draw " + this);
58216263 //new Exception().printStackTrace();
58226264
....@@ -5838,7 +6280,7 @@
58386280 if (!(this instanceof Composite))
58396281 touched = false;
58406282 //if (displaylist == -1 && usecalllists)
5841
- if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
6283
+ if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013
58426284 {
58436285 bRep.displaylist = display.GenList();
58446286 assert(bRep.displaylist != 0);
....@@ -5849,7 +6291,7 @@
58496291
58506292 //System.out.println("\tnew list " + list);
58516293 //gl.glDrawBuffer(gl.GL_NONE);
5852
- if (usecalllists)
6294
+ if (usecalllists && bRep.displaylist > 0)
58536295 {
58546296 // System.err.println("new list " + bRep.displaylist + " for " + this);
58556297 display.NewList(bRep.displaylist);
....@@ -5858,7 +6300,7 @@
58586300 CallList(display, root, selected, blocked);
58596301
58606302 // compiled = true;
5861
- if (usecalllists)
6303
+ if (usecalllists && bRep.displaylist > 0)
58626304 {
58636305 // System.err.println("end list " + bRep.displaylist + " for " + this);
58646306 display.EndList();
....@@ -5868,8 +6310,8 @@
58686310 Globals.lighttouched = true; // all panes...
58696311 }
58706312
5871
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
5872
- //touched = false;
6313
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6314
+ touched = false;
58736315
58746316 if (this instanceof Texture || this instanceof TextureNode)
58756317 {
....@@ -5970,6 +6412,20 @@
59706412 {
59716413 drawSelf(display, root, selected, blocked);
59726414 }
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
+// }
59736429 } else
59746430 {
59756431 /*
....@@ -6002,13 +6458,14 @@
60026458 boolean failedPigment = false;
60036459 boolean failedBump = false;
60046460
6461
+ CameraPane.lastObject = this;
60056462 try
60066463 {
60076464 display.BindPigmentTexture(tex, texres);
60086465 }
60096466 catch (Exception e)
60106467 {
6011
- System.err.println("FAILED: " + this);
6468
+ // System.err.println("FAILED: " + this);
60126469 failedPigment = true;
60136470 }
60146471
....@@ -6039,6 +6496,20 @@
60396496 display.CallList(bRep.displaylist);
60406497 // june 2013 drawSelf(display, root, selected);
60416498 }
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
+// }
60426513 }
60436514 }
60446515
....@@ -6092,16 +6563,17 @@
60926563
60936564 void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
60946565 {
6095
- if (GetBRep() == null)
6096
- {
6097
- drawSelf(display, root, selected, blocked);
6098
- } else
6566
+ if (GetBRep() != null)
60996567 {
61006568 DrawNode(display, root, selected);
61016569 if (this instanceof BezierPatch)
61026570 {
61036571 //drawSelf(display, root, selected);
61046572 }
6573
+ }
6574
+ else
6575
+ {
6576
+ drawSelf(display, root, selected, blocked);
61056577 }
61066578 }
61076579
....@@ -7209,20 +7681,23 @@
72097681 }
72107682 }
72117683
7212
- 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)
72137688 {
7214
- int hc = info.bounds.x + info.bounds.width / 2;
7215
- int vc = info.bounds.y + info.bounds.height / 2;
7216
- 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;
72177692 if (toscreen == null)
72187693 {
7219
- toscreen = new Camera(info.camera.viewCode).toScreen;
7694
+ toscreen = new Camera(clickInfo.camera.viewCode).toScreen;
72207695 }
72217696 cVector vec = in;
72227697 LA.xformPos(in, toscreen, in);
72237698 //System.out.println("Distance = " + info.camera.Distance());
7224
- vec.x *= 100 * info.camera.SCALE / info.camera.Distance();
7225
- 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();
72267701 outPt.x = hc + (int) vec.x;
72277702 outPt.y = vc - (int) vec.y;
72287703 outRec.x = outPt.x - 3;
....@@ -7230,15 +7705,18 @@
72307705 outRec.width = outRec.height = 6;
72317706 }
72327707
7233
- protected Rectangle calcHotSpot(cVector in, ClickInfo info)
7708
+ protected Rectangle calcHotSpot(cVector in//, ClickInfo clickInfo
7709
+ )
72347710 {
72357711 Point pt = new Point(0, 0);
72367712 Rectangle rec = new Rectangle();
7237
- calcHotSpot(in, info, pt, rec);
7713
+ calcHotSpot(in, //clickInfo,
7714
+ pt, rec);
72387715 return rec;
72397716 }
72407717
7241
- void drawEditHandles0(ClickInfo info, int level)
7718
+ void drawEditHandles0(//ClickInfo clickInfo,
7719
+ int level)
72427720 {
72437721 if (level == 0)
72447722 {
....@@ -7247,16 +7725,19 @@
72477725 {
72487726 cVector origin = new cVector();
72497727 //LA.xformPos(origin, toParent, origin);
7250
- Rectangle spot = calcHotSpot(origin, info);
7728
+ if (this.clickInfo == null)
7729
+ this.clickInfo = new ClickInfo();
7730
+
7731
+ Rectangle spot = calcHotSpot(origin); //, clickInfo);
72517732 Rectangle boundary = new Rectangle();
72527733 boundary.x = spot.x - 30;
72537734 boundary.y = spot.y - 30;
72547735 boundary.width = spot.width + 60;
72557736 boundary.height = spot.height + 60;
7256
- info.g.setColor(Color.red);
7737
+ clickInfo.g.setColor(Color.white);
72577738 int spotw = spot.x + spot.width;
72587739 int spoth = spot.y + spot.height;
7259
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7740
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
72607741 // if (CameraPane.Xmin > spot.x)
72617742 // {
72627743 // CameraPane.Xmin = spot.x;
....@@ -7273,11 +7754,6 @@
72737754 // {
72747755 // CameraPane.Ymax = spoth;
72757756 // }
7276
- spot.translate(32, 32);
7277
- spotw = spot.x + spot.width;
7278
- spoth = spot.y + spot.height;
7279
- info.g.setColor(Color.cyan);
7280
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
72817757 // if (CameraPane.Xmin > spot.x)
72827758 // {
72837759 // CameraPane.Xmin = spot.x;
....@@ -7296,10 +7772,15 @@
72967772 // }
72977773 // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
72987774 //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7299
- spot.translate(0, -32);
7300
- info.g.setColor(Color.yellow);
7301
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7302
- 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);
73037784 // if (CameraPane.Xmin > spot.x)
73047785 // {
73057786 // CameraPane.Xmin = spot.x;
....@@ -7316,8 +7797,9 @@
73167797 // {
73177798 // CameraPane.Ymax = spoth;
73187799 // }
7319
- info.g.drawArc(boundary.x + info.DX, boundary.y + info.DY,
7320
- (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);
73217803 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
73227804 // if (CameraPane.Xmin > boundary.x)
73237805 // {
....@@ -7339,7 +7821,8 @@
73397821 }
73407822 }
73417823
7342
- boolean doEditClick0(ClickInfo info, int level)
7824
+ boolean doEditClick0(//ClickInfo clickInfo,
7825
+ int level)
73437826 {
73447827 if (level == 0)
73457828 {
....@@ -7348,8 +7831,8 @@
73487831
73497832 boolean retval = false;
73507833
7351
- startX = info.x;
7352
- startY = info.y;
7834
+ startX = clickInfo.x;
7835
+ startY = clickInfo.y;
73537836
73547837 hitSomething = -1;
73557838 cVector origin = new cVector();
....@@ -7359,22 +7842,53 @@
73597842 {
73607843 centerPt = new Point(0, 0);
73617844 }
7362
- calcHotSpot(origin, info, centerPt, spot);
7363
- if (spot.contains(info.x, info.y))
7845
+ calcHotSpot(origin, //info,
7846
+ centerPt, spot);
7847
+ if (spot.contains(clickInfo.x, clickInfo.y))
73647848 {
73657849 hitSomething = hitCenter;
73667850 retval = true;
73677851 }
73687852 spot.translate(32, 0);
7369
- if (spot.contains(info.x, info.y))
7853
+ if (spot.contains(clickInfo.x, clickInfo.y))
73707854 {
73717855 hitSomething = hitRotate;
73727856 retval = true;
73737857 }
73747858 spot.translate(0, 32);
7375
- 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))
73767862 {
73777863 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
+
73787892 retval = true;
73797893 }
73807894
....@@ -7384,7 +7898,7 @@
73847898 }
73857899
73867900 //System.out.println("info.modifiers = " + info.modifiers);
7387
- modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
7901
+ modified = (clickInfo.modifiers & CameraPane.SHIFT) != 0; // Was META
73887902 //System.out.println("modified = " + modified);
73897903 //new Exception().printStackTrace();
73907904 //viewCode = info.pane.renderCamera.viewCode;
....@@ -7412,7 +7926,8 @@
74127926 return true;
74137927 }
74147928
7415
- void doEditDrag0(ClickInfo info, boolean opposite)
7929
+ void doEditDrag0(//ClickInfo info,
7930
+ boolean opposite)
74167931 {
74177932 if (hitSomething == 0)
74187933 {
....@@ -7426,7 +7941,7 @@
74267941
74277942 //System.out.println("hitSomething = " + hitSomething);
74287943
7429
- double scale = 0.005f * info.camera.Distance();
7944
+ double scale = 0.005f * clickInfo.camera.Distance();
74307945
74317946 cVector xlate = new cVector();
74327947 //cVector xlate2 = new cVector();
....@@ -7440,7 +7955,9 @@
74407955
74417956 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
74427957
7443
- if (modified || opposite)
7958
+ // Modified could snap
7959
+ if (//modified ||
7960
+ opposite)
74447961 {
74457962 //assert(false);
74467963 /*
....@@ -7460,8 +7977,8 @@
74607977 toParent[3][i] = xlate.get(i);
74617978 LA.matInvert(toParent, fromParent);
74627979 */
7463
- cVector delta = LA.newVector(0, 0, startY - info.y);
7464
- 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);
74657982
74667983 LA.matCopy(startMat, toParent);
74677984 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7470,7 +7987,7 @@
74707987 } else
74717988 {
74727989 //LA.xformDir(delta, info.camera.fromScreen, delta);
7473
- cVector up = new cVector(info.camera.up);
7990
+ cVector up = new cVector(clickInfo.camera.up);
74747991 cVector away = new cVector();
74757992 //cVector right2 = new cVector();
74767993 //LA.vecCross(up, cVector.Z, right);
....@@ -7487,19 +8004,19 @@
74878004 LA.xformDir(up, ClickInfo.matbuffer, up);
74888005 // if (!CameraPane.LOCALTRANSFORM)
74898006 LA.xformDir(up, Globals.theRenderer.RenderCamera().toScreen, up);
7490
- LA.xformDir(info.camera.away, ClickInfo.matbuffer, away);
8007
+ LA.xformDir(clickInfo.camera.away, ClickInfo.matbuffer, away);
74918008 // if (!CameraPane.LOCALTRANSFORM)
74928009 LA.xformDir(away, Globals.theRenderer.RenderCamera().toScreen, away);
74938010 //LA.vecCross(up, cVector.Z, right2);
74948011
7495
- cVector delta = LA.newVector(info.x - startX, startY - info.y, 0);
8012
+ cVector delta = LA.newVector(clickInfo.x - startX, startY - clickInfo.y, 0);
74968013
74978014 //System.out.println("DELTA0 = " + delta);
74988015 //System.out.println("AWAY = " + info.camera.away);
74998016 //System.out.println("UP = " + info.camera.up);
75008017 if (away.z > 0)
75018018 {
7502
- if (info.camera.up.x == 0) // LA.vecDot(right, right2)<0)
8019
+ if (clickInfo.camera.up.x == 0) // LA.vecDot(right, right2)<0)
75038020 {
75048021 delta.x = -delta.x;
75058022 } else
....@@ -7514,7 +8031,7 @@
75148031 //System.out.println("DELTA1 = " + delta);
75158032 LA.xformDir(delta, ClickInfo.matbuffer, delta);
75168033 //System.out.println("DELTA2 = " + delta);
7517
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
8034
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
75188035 LA.matCopy(startMat, toParent);
75198036 //System.out.println("DELTA3 = " + delta);
75208037 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7524,8 +8041,8 @@
75248041 break;
75258042
75268043 case hitRotate: // rotate
7527
- int dx = info.x - centerPt.x;
7528
- int dy = -(info.y - centerPt.y);
8044
+ int dx = clickInfo.x - centerPt.x;
8045
+ int dy = -(clickInfo.y - centerPt.y);
75298046 double angle = (double) Math.atan2(dx, dy);
75308047 angle = -(1.570796 - angle);
75318048
....@@ -7534,7 +8051,7 @@
75348051
75358052 if (modified)
75368053 {
7537
- // Rotate 90 degrees
8054
+ // Rotate 45 degrees
75388055 angle /= (Math.PI / 4);
75398056 angle = Math.floor(angle + 0.5);
75408057 angle *= (Math.PI / 4);
....@@ -7548,7 +8065,7 @@
75488065 }
75498066 /**/
75508067
7551
- switch (info.pane.RenderCamera().viewCode)
8068
+ switch (clickInfo.pane.RenderCamera().viewCode)
75528069 {
75538070 case 1: // '\001'
75548071 LA.matZRotate(toParent, angle);
....@@ -7575,7 +8092,7 @@
75758092 break;
75768093
75778094 case hitScale: // scale
7578
- double hScale = (double) (info.x - centerPt.x) / 32;
8095
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
75798096 double sign = 1;
75808097 if (hScale < 0)
75818098 {
....@@ -7587,7 +8104,7 @@
75878104 //hScale = 0.01;
75888105 }
75898106
7590
- double vScale = (double) (info.y - centerPt.y) / 32;
8107
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
75918108 sign = 1;
75928109 if (vScale < 0)
75938110 {
....@@ -7598,6 +8115,7 @@
75988115 {
75998116 //vScale = 0.01;
76008117 }
8118
+
76018119 LA.matCopy(startMat, toParent);
76028120 /**/
76038121 for (int i = 0; i < 3; i++)
....@@ -7607,33 +8125,39 @@
76078125 }
76088126 /**/
76098127
7610
- double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
8128
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / clickInfo.scale;
76118129
76128130 if (totalScale < 0.01)
76138131 {
76148132 totalScale = 0.01;
76158133 }
76168134
7617
- switch (info.pane.RenderCamera().viewCode)
8135
+ switch (clickInfo.pane.RenderCamera().viewCode)
76188136 {
76198137 case 3: // '\001'
76208138 if (modified || opposite)
76218139 {
8140
+ if (modified) // && opposite)
8141
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8142
+ else
76228143 //LA.matScale(toParent, 1, hScale, vScale);
7623
- LA.matScale(toParent, totalScale, 1, 1);
8144
+ LA.matScale(toParent, totalScale, 1, 1);
76248145 } // vScale, 1);
76258146 else
76268147 {
76278148 // EXCEPTION!
7628
- LA.matScale(toParent, totalScale, totalScale, totalScale);
8149
+ LA.matScale(toParent, 1, totalScale, totalScale);
76298150 } // vScale, 1);
76308151 break;
76318152
76328153 case 2: // '\002'
76338154 if (modified || opposite)
76348155 {
7635
- //LA.matScale(toParent, hScale, 1, vScale);
7636
- 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);
76378161 } else
76388162 {
76398163 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7643,8 +8167,11 @@
76438167 case 1: // '\003'
76448168 if (modified || opposite)
76458169 {
7646
- //LA.matScale(toParent, hScale, vScale, 1);
7647
- 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);
76488175 } else
76498176 {
76508177 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7681,7 +8208,7 @@
76818208 } // NEW ...
76828209
76838210
7684
- info.pane.repaint();
8211
+ clickInfo.pane.repaint();
76858212 }
76868213
76878214 boolean overflow = false;
....@@ -7795,7 +8322,7 @@
77958322 if (!Globals.ADVANCED)
77968323 return objname;
77978324
7798
- return objname + " " + System.identityHashCode(this);
8325
+ return objname + " " + System.identityHashCode(this) + " " + GetUUID();
77998326 }
78008327
78018328 public int hashCode()
....@@ -8040,8 +8567,8 @@
80408567 private static cVector2 qq2 = new cVector2();
80418568 private static cVector2 rr2 = new cVector2();
80428569 private static cVector2 ss2 = new cVector2();
8043
- private static cVector edge1 = new cVector();
8044
- private static cVector edge2 = new cVector();
8570
+// private static cVector edge1 = new cVector();
8571
+// private static cVector edge2 = new cVector();
80458572 //private static cVector norm = new cVector();
80468573 /*transient private*/ int hitSomething;
80478574 static final int hitCenter = 1;
....@@ -8239,7 +8766,269 @@
82398766
82408767 Touch();
82418768 }
8769
+
8770
+ static Vertex s1 = new Vertex();
8771
+ static Vertex s2 = new Vertex();
8772
+ static Vertex s3 = new Vertex();
82428773
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
+ }
82439032
82449033 public int Size()
82459034 {