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
28
- mocap.reader.BVHReader.BVHResult bvh;
29
- Object3D skeleton;
28
+ // TEMPORARY for versions. No need to be transient.
29
+ mocap.reader.BVHReader.BVHResult savebvh;
30
+ 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,38 +267,102 @@
168267 }
169268 }
170269
171
- void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
270
+ boolean HasBigData()
172271 {
173
- if (hashtable.containsKey(GetUUID()))
272
+ if (blockloop)
273
+ return false;
274
+
275
+ if (bRep != null)
174276 {
175
- Object3D o = hashtable.get(GetUUID());
176
-
177
- Grafreed.Assert(this.bRep == o.bRep);
178
- if (this.bRep != null)
179
- assert(this.bRep.support == o.transientrep);
180
-
181
- return;
182
- }
183
-
184
- Object3D o = new Object3D();
185
-
186
- hashtable.put(GetUUID(), o);
187
-
188
- for (int i=0; i<Size(); i++)
189
- {
190
- get(i).ExtractBigData(hashtable);
277
+ return true;
191278 }
192279
193
- ExtractBigData(o);
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
+
298
+ void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
299
+ {
300
+ if (blockloop)
301
+ return;
302
+
303
+ Object3D o;
304
+
305
+ boolean isnew = false;
306
+
307
+ if (hashtable.containsKey(GetUUID()))
308
+ {
309
+ o = hashtable.get(GetUUID());
310
+
311
+ Grafreed.Assert(this.bRep == o.bRep);
312
+ //if (this.bRep != null)
313
+ // assert(this.bRep.support == o.transientrep);
314
+ if (this.support != null)
315
+ assert(this.support.bRep == o.transientrep);
316
+ }
317
+ else
318
+ {
319
+ isnew = true;
320
+
321
+ o = new Object3D("copy of " + this.name);
322
+
323
+ hashtable.put(GetUUID(), o);
324
+ }
325
+
326
+ //if (!blockloop)
327
+ {
328
+ blockloop = true;
329
+
330
+ for (int i=0; i<Size(); i++)
331
+ {
332
+ get(i).ExtractBigData(hashtable);
333
+ }
334
+
335
+ blockloop = false;
336
+ }
337
+
338
+ //if (isnew)
339
+ ExtractBigData(o);
194340 }
195341
196342 void ExtractBigData(Object3D o)
197343 {
344
+ //System.err.println("ExtractBigData : " + this + " --> " + o);
345
+
346
+ if (o.bRep != null)
347
+ Grafreed.Assert(o.bRep == this.bRep);
348
+
198349 o.bRep = this.bRep;
199
- if (this.bRep != null)
350
+// July 2019 if (this.bRep != null)
351
+// {
352
+// o.transientrep = this.bRep.support;
353
+// o.bRep.support = null;
354
+// }
355
+ o.selection = this.selection;
356
+ //o.versionlist = this.versionlist;
357
+ //o.versionindex = this.versionindex;
358
+
359
+ if (this.support != null)
200360 {
201
- o.transientrep = this.bRep.support;
202
- o.bRep.support = null;
361
+ if (o.transientrep != null)
362
+ Grafreed.Assert(o.transientrep == this.support.bRep);
363
+
364
+ o.transientrep = this.support.bRep;
365
+ this.support.bRep = null;
203366 }
204367
205368 // o.support = this.support;
....@@ -214,8 +377,78 @@
214377 // this.fileparent = null;
215378 }
216379
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
+
217447 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
218448 {
449
+ if (blockloop)
450
+ return;
451
+
219452 if (!hashtable.containsKey(GetUUID()))
220453 return;
221454
....@@ -223,19 +456,35 @@
223456
224457 RestoreBigData(o);
225458
226
- hashtable.remove(GetUUID());
459
+ blockloop = true;
460
+
461
+ //hashtable.remove(GetUUID());
227462
228463 for (int i=0; i<Size(); i++)
229464 {
230465 get(i).RestoreBigData(hashtable);
231466 }
467
+
468
+ blockloop = false;
232469 }
233470
234471 void RestoreBigData(Object3D o)
235472 {
473
+ //System.err.println("RestoreBigData : " + this + " <-- " + o);
474
+ Grafreed.Assert(this.bRep == null);
475
+
236476 this.bRep = o.bRep;
237
- if (this.bRep != null)
238
- this.bRep.support = o.transientrep;
477
+ if (this.support != null && o.transientrep != null)
478
+ {
479
+ this.support.bRep = o.transientrep;
480
+ }
481
+
482
+ this.selection = o.selection;
483
+
484
+ //this.versionlist = o.versionlist;
485
+ //this.versionindex = o.versionindex;
486
+// July 2019 if (this.bRep != null)
487
+// this.bRep.support = o.transientrep;
239488 // this.support = o.support;
240489 // this.fileparent = o.fileparent;
241490 }
....@@ -381,6 +630,7 @@
381630 }
382631
383632 boolean live = false;
633
+ transient boolean keepdontselect;
384634 boolean dontselect = false;
385635 boolean hide = false;
386636 boolean link2master = false; // performs reset support/master at each frame
....@@ -391,6 +641,9 @@
391641 boolean random = false;
392642 boolean speedup = false;
393643 boolean rewind = false;
644
+
645
+ // Option to sort triangles, e.g. for transparency.
646
+ boolean sort = false;
394647
395648 float NORMALPUSH = 0;
396649
....@@ -409,7 +662,7 @@
409662 {
410663 sorted = true;
411664
412
- for (int i=0; i<size()-1; i++)
665
+ for (int i=0; i<Size()-1; i++)
413666 {
414667 Object3D obji = get(i);
415668 Object3D objj = get(i+1);
....@@ -433,7 +686,7 @@
433686 {
434687 sorted = true;
435688
436
- for (int i=0; i<size()-1; i++)
689
+ for (int i=0; i<Size()-1; i++)
437690 {
438691 Object3D obji = get(i);
439692 Object3D objj = get(i+1);
....@@ -449,11 +702,11 @@
449702 }
450703 }
451704
452
- int memorysize;
705
+ transient int memorysize; // needs to be transient, dunno why
453706
454707 int MemorySize()
455708 {
456
- if (true) // memorysize == 0)
709
+ if (memorysize == 0)
457710 {
458711 try
459712 {
....@@ -568,7 +821,7 @@
568821 {
569822 if (maxcount != 1)
570823 {
571
- new Exception().printStackTrace();
824
+ //new Exception().printStackTrace();
572825 }
573826
574827 toParentMarked = LA.newMatrix();
....@@ -881,7 +1134,7 @@
8811134
8821135 if (marked && Globals.isLIVE() && live &&
8831136 //TEMP21aug2018
884
- (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW) &&
1137
+ (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
8851138 currentframe != Globals.framecount)
8861139 {
8871140 currentframe = Globals.framecount;
....@@ -893,7 +1146,8 @@
8931146
8941147 boolean changedir = random && Math.random() < 0.01; // && !link2master;
8951148
896
- if (transformcount*factor > maxcount || (step == 1 && changedir))
1149
+ if (transformcount*factor >= maxcount && (rewind || random) ||
1150
+ (step == 1 && changedir))
8971151 {
8981152 countdown = 1;
8991153 delay = speedup?8:1;
....@@ -962,20 +1216,28 @@
9621216 {
9631217 // return true;
9641218
965
- if (material == null || material.multiply)
966
- 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;
9671227
968
- return material.opacity > 0.99;
1228
+ return !sort;
9691229 }
9701230
9711231 boolean IsOpaque()
9721232 {
9731233 // return true;
9741234
975
- if (material == null || material.multiply)
976
- return true;
1235
+// if (material == null || material.multiply)
1236
+// return true;
1237
+//
1238
+// return material.opacity > 0.99;
9771239
978
- return material.opacity > 0.99;
1240
+ return !sort;
9791241 }
9801242
9811243 Object3D()
....@@ -1053,8 +1315,10 @@
10531315
10541316 // will share the geometry
10551317 assert (!(this instanceof Composite));
1056
- return deepCopy(); // Never called for Composite
1057
-
1318
+
1319
+ Object3D obj = deepCopy(); // Never called for Composite
1320
+ obj.count = 2;
1321
+ return obj;
10581322 }
10591323
10601324 boolean HasLoops()
....@@ -1062,6 +1326,30 @@
10621326 return false;
10631327 }
10641328
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
+
10651353 boolean IsInfinite()
10661354 {
10671355 if (blockloop)
....@@ -1132,78 +1420,16 @@
11321420 return;
11331421
11341422 blockloop = true;
1423
+
1424
+ other.parent = parent;
1425
+
11351426 //System.out.println("COPY " + this + " to " + other);
11361427 //new Exception().printStackTrace();
1428
+ deepCopyNode(other);
11371429
1138
- other.parent = parent;
1139
- if (toParent != null)
1140
- {
1141
- other.toParent = LA.newMatrix();
1142
- other.fromParent = LA.newMatrix();
1143
- LA.matCopy(toParent, other.toParent);
1144
- LA.matCopy(fromParent, other.fromParent);
1145
- if (toParentMarked != null)
1146
- {
1147
- other.toParentMarked = LA.newMatrix();
1148
- other.fromParentMarked = LA.newMatrix();
1149
- LA.matCopy(toParentMarked, other.toParentMarked);
1150
- LA.matCopy(fromParentMarked, other.fromParentMarked);
1151
- }
1152
- }
1153
- else
1154
- {
1155
- if (other.toParent == null)
1156
-// assert(other.toParent == null);
1157
-// new Exception().printStackTrace();
1158
- System.err.println("null parent: " + other);
1159
- }
1160
- /*
1161
- double ident[][] = LA.newMatrix();
1162
- if (bRep == null)
1163
- other.bRep = null;
1164
- else
1165
- other.bRep = new BoundaryRep(bRep, ident);
1166
- */
1167
- // Really new...
11681430 other.bRep = bRep; // Share the geometry
11691431
11701432 other.support = support; // Share the support
1171
-
1172
- //other.editWindow = null;
1173
- if (name == null)
1174
- other.name = null;
1175
- else
1176
- other.name = new String(name);
1177
-
1178
- if (material != null)
1179
- {
1180
- other.material = new cMaterial(material);
1181
- } else
1182
- {
1183
- other.material = null;
1184
- }
1185
-
1186
- other.GetTextures().name = GetTextures().name;
1187
-
1188
- CopyExtraMaterial(other);
1189
-
1190
- other.touched = touched;
1191
- other.softtouched = softtouched;
1192
-
1193
- other.random = random;
1194
- other.link2master = link2master;
1195
- other.transformcount = transformcount;
1196
- other.marked = marked;
1197
- other.skip = skip;
1198
- other.count = count;
1199
- other.flipV = flipV;
1200
- other.live = live;
1201
- other.rewind = rewind;
1202
- other.hide = hide;
1203
- other.texres = texres;
1204
- other.speedup = speedup;
1205
- other.height = height;
1206
- other.depth = depth;
12071433
12081434 // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist)
12091435 // {
....@@ -1259,17 +1485,24 @@
12591485 if ((mask & GEOMETRY) != 0)
12601486 {
12611487 if (bRep != null)
1262
- bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
1263
- else
1264
- assert(other.bRep == null);
1265
-
1266
- if (bRep != null)
12671488 {
1489
+ bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
12681490 CameraPane.RemoveList(bRep.displaylist);
12691491 bRep.displaylist = 0; // june 2013 -1;
12701492 }
12711493 else
1272
- 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;
12731506 }
12741507
12751508 /* Use a MASK = GEO/MAT
....@@ -1365,6 +1598,7 @@
13651598 toParent = LA.newMatrix();
13661599 fromParent = LA.newMatrix();
13671600 }
1601
+
13681602 LA.matCopy(other.toParent, toParent);
13691603 LA.matCopy(other.fromParent, fromParent);
13701604
....@@ -2244,11 +2478,6 @@
22442478
22452479 InitOthers();
22462480
2247
- if (this instanceof Camera)
2248
- {
2249
- material.shift = 90;
2250
- }
2251
-
22522481 material.multiply = multiply;
22532482
22542483 if (multiply)
....@@ -2386,6 +2615,15 @@
23862615 }
23872616 */
23882617 }
2618
+ else
2619
+ {
2620
+ //((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");
2626
+ }
23892627 }
23902628
23912629 void createEditWindow(GroupEditor callee, boolean newWindow) //, boolean root)
....@@ -2427,6 +2665,14 @@
24272665 {
24282666 editWindow.refreshContents();
24292667 }
2668
+ else
2669
+ {
2670
+ if (manipWindow != null)
2671
+ {
2672
+ manipWindow.refreshContents();
2673
+ }
2674
+ }
2675
+
24302676 //if (parent != null)
24312677 //parent.refreshEditWindow();
24322678 }
....@@ -2506,7 +2752,8 @@
25062752 private static final int editSelf = 1;
25072753 private static final int editChild = 2;
25082754
2509
- void drawEditHandles(ClickInfo info, int level)
2755
+ void drawEditHandles(//ClickInfo info,
2756
+ int level)
25102757 {
25112758 if (level == 0)
25122759 {
....@@ -2514,7 +2761,8 @@
25142761 return;
25152762
25162763 Object3D selectee;
2517
- 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))
25182766 {
25192767 selectee = (Object3D) e.nextElement();
25202768 }
....@@ -2522,19 +2770,22 @@
25222770 } else
25232771 {
25242772 //super.
2525
- drawEditHandles0(info, level + 1);
2773
+ drawEditHandles0(//info,
2774
+ level + 1);
25262775 }
25272776 }
25282777
2529
- boolean doEditClick(ClickInfo info, int level)
2778
+ boolean doEditClick(//ClickInfo info,
2779
+ int level)
25302780 {
25312781 doSomething = 0;
25322782 if (level == 0)
25332783 {
2534
- return doParentClick(info);
2784
+ return doParentClick(); //info);
25352785 }
25362786 if (//super.
2537
- doEditClick0(info, level))
2787
+ doEditClick0(//info,
2788
+ level))
25382789 {
25392790 doSomething = 1;
25402791 return true;
....@@ -2544,7 +2795,7 @@
25442795 }
25452796 }
25462797
2547
- boolean doParentClick(ClickInfo info)
2798
+ boolean doParentClick() //ClickInfo info)
25482799 {
25492800 if (selection == null)
25502801 {
....@@ -2557,7 +2808,8 @@
25572808 for (java.util.Enumeration e = selection.elements(); e.hasMoreElements();)
25582809 {
25592810 Object3D selectee = (Object3D) e.nextElement();
2560
- if (selectee.doEditClick(info, 1))
2811
+ if (selectee.doEditClick(//info,
2812
+ 1))
25612813 {
25622814 childToDrag = selectee;
25632815 doSomething = 2;
....@@ -2569,13 +2821,15 @@
25692821 return retval;
25702822 }
25712823
2572
- void doEditDrag(ClickInfo info, boolean opposite)
2824
+ void doEditDrag(//ClickInfo clickInfo,
2825
+ boolean opposite)
25732826 {
25742827 switch (doSomething)
25752828 {
25762829 case 1: // '\001'
25772830 //super.
2578
- doEditDrag0(info, opposite);
2831
+ doEditDrag0(//clickInfo,
2832
+ opposite);
25792833 break;
25802834
25812835 case 2: // '\002'
....@@ -2588,11 +2842,13 @@
25882842 {
25892843 //sel.hitSomething = childToDrag.hitSomething;
25902844 //childToDrag.doEditDrag(info);
2591
- sel.doEditDrag(info, opposite);
2845
+ sel.doEditDrag(//clickInfo,
2846
+ opposite);
25922847 } else
25932848 {
25942849 //super.
2595
- doEditDrag0(info, opposite);
2850
+ doEditDrag0(//clickInfo,
2851
+ opposite);
25962852 }
25972853 }
25982854 break;
....@@ -2610,6 +2866,9 @@
26102866 {
26112867 deselectAll();
26122868 }
2869
+
2870
+ new Exception().printStackTrace();
2871
+
26132872 ClickInfo newInfo = new ClickInfo();
26142873 newInfo.flags = info.flags;
26152874 newInfo.bounds = info.bounds;
....@@ -3039,7 +3298,10 @@
30393298 {
30403299 if (bRep != null)
30413300 {
3301
+ //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact).
30423302 bRep.GenerateNormals(crease);
3303
+ if (!bRep.trimmed)
3304
+ bRep.MergeNormals();
30433305 Touch();
30443306 }
30453307 }
....@@ -3057,7 +3319,7 @@
30573319 {
30583320 if (bRep != null)
30593321 {
3060
- bRep.GenerateNormalsMINE();
3322
+ bRep.MergeNormals(); //.GenerateNormalsMINE();
30613323 Touch();
30623324 }
30633325 }
....@@ -3114,6 +3376,105 @@
31143376 blockloop = false;
31153377 }
31163378
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
+
31173478 void TransformChildren()
31183479 {
31193480 if (toParent != null)
....@@ -3356,6 +3717,7 @@
33563717 if (bRep != null)
33573718 {
33583719 //bRep.RemoveOneTriangle();
3720
+ System.out.println();
33593721 System.out.println("Reducing " + this);
33603722 if (name != null && name.contains("lockpickstraps"))
33613723 name = name;
....@@ -3467,15 +3829,47 @@
34673829
34683830 void ClearMaterials()
34693831 {
3832
+ if (blockloop)
3833
+ return;
3834
+
3835
+ blockloop = true;
3836
+
34703837 ClearMaterial();
3471
- for (int i = 0; i < size(); i++)
3838
+ for (int i = 0; i < Size(); i++)
34723839 {
3473
- Object3D child = (Object3D) reserve(i);
3840
+ Object3D child = (Object3D) get(i);
34743841 if (child == null)
34753842 continue;
34763843 child.ClearMaterials();
3477
- release(i);
34783844 }
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;
34793873 }
34803874
34813875 void FlipV(boolean flip)
....@@ -3503,7 +3897,8 @@
35033897 if (blockloop)
35043898 return;
35053899
3506
- if (marked || (bRep != null && material != null)) // borderline...
3900
+ if (//marked || // does not make sense
3901
+ (bRep != null || material != null)) // borderline...
35073902 live = h;
35083903
35093904 for (int i = 0; i < Size(); i++)
....@@ -3524,7 +3919,8 @@
35243919 return;
35253920
35263921 //if (bRep != null)
3527
- if (marked || (bRep != null && material != null)) // borderline...
3922
+ if (//marked || // does not make sense
3923
+ (bRep != null || material != null)) // borderline...
35283924 link2master = h;
35293925
35303926 for (int i = 0; i < Size(); i++)
....@@ -3544,7 +3940,8 @@
35443940 if (blockloop)
35453941 return;
35463942
3547
- if (marked || (bRep != null && material != null)) // borderline...
3943
+ if (//marked || // does not make sense
3944
+ (bRep != null || material != null)) // borderline...
35483945 hide = h;
35493946
35503947 for (int i = 0; i < Size(); i++)
....@@ -3564,7 +3961,7 @@
35643961 if (blockloop)
35653962 return;
35663963
3567
- if (bRep != null && material != null) // borderline...
3964
+ if (bRep != null || material != null) // borderline...
35683965 marked = h;
35693966
35703967 for (int i = 0; i < Size(); i++)
....@@ -3574,6 +3971,46 @@
35743971 continue;
35753972 blockloop = true;
35763973 child.MarkLeaves(h);
3974
+ blockloop = false;
3975
+ // release(i);
3976
+ }
3977
+ }
3978
+
3979
+ void RewindLeaves(boolean h)
3980
+ {
3981
+ if (blockloop)
3982
+ return;
3983
+
3984
+ if (bRep != null || material != null) // borderline...
3985
+ rewind = h;
3986
+
3987
+ for (int i = 0; i < Size(); i++)
3988
+ {
3989
+ Object3D child = (Object3D) get(i); // reserve(i);
3990
+ if (child == null)
3991
+ continue;
3992
+ blockloop = true;
3993
+ child.RewindLeaves(h);
3994
+ blockloop = false;
3995
+ // release(i);
3996
+ }
3997
+ }
3998
+
3999
+ void RandomLeaves(boolean h)
4000
+ {
4001
+ if (blockloop)
4002
+ return;
4003
+
4004
+ if (bRep != null || material != null) // borderline...
4005
+ random = h;
4006
+
4007
+ for (int i = 0; i < Size(); i++)
4008
+ {
4009
+ Object3D child = (Object3D) get(i); // reserve(i);
4010
+ if (child == null)
4011
+ continue;
4012
+ blockloop = true;
4013
+ child.RandomLeaves(h);
35774014 blockloop = false;
35784015 // release(i);
35794016 }
....@@ -3611,6 +4048,7 @@
36114048
36124049 void RevertMeshes()
36134050 {
4051
+ // BLOCKLOOP
36144052 if (this instanceof cMesh)
36154053 {
36164054 ((cMesh)this).Revert();
....@@ -3641,11 +4079,6 @@
36414079 Touch();
36424080 }
36434081
3644
- ResetRecur();
3645
- }
3646
-
3647
- void ResetRecur()
3648
- {
36494082 for (int i = 0; i < size(); i++)
36504083 {
36514084 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3859,8 +4292,8 @@
38594292 Touch();
38604293 }
38614294
3862
- transient cVector min = new cVector();
3863
- transient cVector max = new cVector();
4295
+ transient cVector min;
4296
+ transient cVector max;
38644297
38654298 void getBounds(cVector minima, cVector maxima, boolean xform)
38664299 {
....@@ -3876,15 +4309,15 @@
38764309 if (blockloop)
38774310 return;
38784311
3879
- if (min == null) // ???
4312
+ if (min == null)
38804313 {
38814314 min = new cVector();
38824315 max = new cVector();
38834316 }
38844317
3885
- for (int i = 0; i<size(); i++)
4318
+ for (int i = 0; i<Size(); i++)
38864319 {
3887
- Object3D child = (Object3D) reserve(i);
4320
+ Object3D child = (Object3D) get(i); //reserve(i);
38884321 if (child == null)
38894322 continue;
38904323
....@@ -3903,21 +4336,21 @@
39034336 if (child.hide && !(child instanceof Merge) || child.skip)
39044337 //if (child.hide)
39054338 {
3906
- release(i);
4339
+ //release(i);
39074340 continue;
39084341 }
39094342
39104343 blockloop = true;
39114344 child.getBounds(min, max, true); // xform);
39124345 blockloop = false;
3913
- release(i);
4346
+ //release(i);
39144347
39154348 MinMax(minima, maxima);
39164349 }
39174350
39184351 if (bRep != null)
39194352 {
3920
- bRep.getBounds(minima,maxima,this);
4353
+ bRep.getBounds(minima, maxima, xform?this:null);
39214354 }
39224355
39234356 if (false) // xform)
....@@ -4347,6 +4780,55 @@
43474780 {
43484781 blockloop = true;
43494782 get(i).RepairShadow();
4783
+ blockloop = false;
4784
+ }
4785
+ }
4786
+
4787
+ void RepairSOV()
4788
+ {
4789
+ if (blockloop)
4790
+ return;
4791
+
4792
+ String texname = this.GetPigmentTexture();
4793
+
4794
+ if (texname.startsWith("sov"))
4795
+ {
4796
+ String[] s = texname.split("/");
4797
+
4798
+ String[] sname = s[1].split("Color.pn");
4799
+
4800
+ texname = sname[0];
4801
+
4802
+ if (sname.length > 1)
4803
+ {
4804
+ texname += "Color.jpg";
4805
+ }
4806
+
4807
+ this.SetPigmentTexture("sov/" + texname);
4808
+ }
4809
+
4810
+ texname = this.GetBumpTexture();
4811
+
4812
+ if (texname.startsWith("sov"))
4813
+ {
4814
+ String[] s = texname.split("/");
4815
+
4816
+ String[] sname = s[1].split("Bump.pn");
4817
+
4818
+ texname = sname[0];
4819
+
4820
+ if (sname.length > 1)
4821
+ {
4822
+ texname += "Bump.jpg";
4823
+ }
4824
+
4825
+ this.SetBumpTexture("sov/" + texname);
4826
+ }
4827
+
4828
+ for (int i=0; i<Size(); i++)
4829
+ {
4830
+ blockloop = true;
4831
+ get(i).RepairSOV();
43504832 blockloop = false;
43514833 }
43524834 }
....@@ -4865,6 +5347,14 @@
48655347 }
48665348 }
48675349
5350
+ ObjEditor GetWindow()
5351
+ {
5352
+ if (editWindow != null)
5353
+ return editWindow;
5354
+
5355
+ return manipWindow;
5356
+ }
5357
+
48685358 cTreePath Select(int indexcount, boolean deselect)
48695359 {
48705360 if (hide || dontselect)
....@@ -4901,10 +5391,11 @@
49015391 if (leaf != null)
49025392 {
49035393 cTreePath tp = new cTreePath(this, leaf);
4904
- if (editWindow != null)
5394
+ ObjEditor window = GetWindow();
5395
+ if (window != null)
49055396 {
49065397 //System.out.println("editWindow = " + editWindow + " vs " + this);
4907
- editWindow.Select(tp, deselect, true);
5398
+ window.Select(tp, deselect, true);
49085399 }
49095400
49105401 return tp;
....@@ -4921,6 +5412,7 @@
49215412
49225413 if (child == null)
49235414 continue;
5415
+
49245416 if (child.HasTransparency() && child.size() != 0)
49255417 {
49265418 cTreePath leaf = child.Select(indexcount, deselect);
....@@ -4930,9 +5422,10 @@
49305422 if (leaf != null)
49315423 {
49325424 cTreePath tp = new cTreePath(this, leaf);
4933
- if (editWindow != null)
5425
+ ObjEditor window = GetWindow();
5426
+ if (window != null)
49345427 {
4935
- editWindow.Select(tp, deselect, true);
5428
+ window.Select(tp, deselect, true);
49365429 }
49375430
49385431 return tp;
....@@ -5257,6 +5750,51 @@
52575750 blockloop = false;
52585751 }
52595752
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
+
52605798 boolean IsSelected()
52615799 {
52625800 if (parent == null)
....@@ -5317,6 +5855,11 @@
53175855 if (fullname == null)
53185856 return "";
53195857
5858
+ if (fullname.pigment != null)
5859
+ {
5860
+ return fullname.pigment;
5861
+ }
5862
+
53205863 // System.out.println("Fullname = " + fullname);
53215864
53225865 // Does not work on Windows due to C:
....@@ -5329,7 +5872,7 @@
53295872
53305873 if (split.length == 0)
53315874 {
5332
- return "";
5875
+ return fullname.pigment = "";
53335876 }
53345877
53355878 if (split.length <= 2)
....@@ -5337,22 +5880,27 @@
53375880 if (fullname.name.endsWith(":"))
53385881 {
53395882 // Windows
5340
- return fullname.name.substring(0, fullname.name.length()-1);
5883
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
53415884 }
53425885
5343
- return split[0];
5886
+ return fullname.pigment = split[0];
53445887 }
53455888
53465889 // Windows
53475890 assert(split.length == 4);
53485891
5349
- return split[0] + ":" + split[1];
5892
+ return fullname.pigment = split[0] + ":" + split[1];
53505893 }
53515894
53525895 static String GetBump(cTexture fullname)
53535896 {
53545897 if (fullname == null)
53555898 return "";
5899
+
5900
+ if (fullname.bump != null)
5901
+ {
5902
+ return fullname.bump;
5903
+ }
53565904
53575905 // System.out.println("Fullname = " + fullname);
53585906 // Does not work on Windows due to C:
....@@ -5364,12 +5912,12 @@
53645912
53655913 if (split.length == 0)
53665914 {
5367
- return "";
5915
+ return fullname.bump = "";
53685916 }
53695917
53705918 if (split.length == 1)
53715919 {
5372
- return "";
5920
+ return fullname.bump = "";
53735921 }
53745922
53755923 if (split.length == 2)
....@@ -5377,16 +5925,16 @@
53775925 if (fullname.name.endsWith(":"))
53785926 {
53795927 // Windows
5380
- return "";
5928
+ return fullname.bump = "";
53815929 }
53825930
5383
- return split[1];
5931
+ return fullname.bump = split[1];
53845932 }
53855933
53865934 // Windows
53875935 assert(split.length == 4);
53885936
5389
- return split[2] + ":" + split[3];
5937
+ return fullname.bump = split[2] + ":" + split[3];
53905938 }
53915939
53925940 String GetPigmentTexture()
....@@ -5469,6 +6017,9 @@
54696017 texname = "";
54706018
54716019 GetTextures().name = texname + ":" + GetBump(GetTextures());
6020
+
6021
+ GetTextures().pigment = null;
6022
+
54726023 Touch();
54736024 }
54746025
....@@ -5542,6 +6093,8 @@
55426093
55436094 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
55446095
6096
+ GetTextures().bump = null;
6097
+
55456098 Touch();
55466099 }
55476100
....@@ -5562,6 +6115,38 @@
55626115
55636116 blockloop = true;
55646117 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);
55656150 blockloop = false;
55666151 }
55676152 }
....@@ -5590,6 +6175,11 @@
55906175 return false;
55916176
55926177 return parent.IsLive();
6178
+ }
6179
+
6180
+ boolean IsDynamic()
6181
+ {
6182
+ return live && bRep != null;
55936183 }
55946184
55956185 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
....@@ -5652,8 +6242,11 @@
56526242 if (support != null)
56536243 support = support;
56546244
5655
- //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5656
- 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.
56576250
56586251 if (!usecalllists && bRep != null && bRep.displaylist > 0)
56596252 {
....@@ -5663,8 +6256,9 @@
56636256 // usecalllists &= !(parent instanceof RandomNode);
56646257 // usecalllists = false;
56656258
5666
- if (GetBRep() != null)
5667
- usecalllists = usecalllists;
6259
+ if (display.DrawMode() == display.SHADOW)
6260
+ //GetBRep() != null)
6261
+ usecalllists = !!usecalllists;
56686262 //System.out.println("draw " + this);
56696263 //new Exception().printStackTrace();
56706264
....@@ -5673,10 +6267,12 @@
56736267 boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
56746268
56756269 if (!selectmode && //display.DrawMode() != display.SELECTION &&
5676
- (touched || (bRep != null && bRep.displaylist <= 0)))
6270
+ //(touched || (bRep != null && bRep.displaylist <= 0)))
6271
+ (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
56776272 {
56786273 Globals.lighttouched = true;
56796274 } // all panes...
6275
+
56806276 //if (usecalllists && display.DrawMode() != display.SELECTION && display.DrawMode() != display.SHADOW &&
56816277 if (bRep != null && usecalllists && !selectmode && // june 2013 display.DrawMode() != display.SHADOW &&
56826278 (touched || (bRep != null && bRep.displaylist <= 0)))
....@@ -5684,7 +6280,7 @@
56846280 if (!(this instanceof Composite))
56856281 touched = false;
56866282 //if (displaylist == -1 && usecalllists)
5687
- if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
6283
+ if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013
56886284 {
56896285 bRep.displaylist = display.GenList();
56906286 assert(bRep.displaylist != 0);
....@@ -5695,7 +6291,7 @@
56956291
56966292 //System.out.println("\tnew list " + list);
56976293 //gl.glDrawBuffer(gl.GL_NONE);
5698
- if (usecalllists)
6294
+ if (usecalllists && bRep.displaylist > 0)
56996295 {
57006296 // System.err.println("new list " + bRep.displaylist + " for " + this);
57016297 display.NewList(bRep.displaylist);
....@@ -5704,7 +6300,7 @@
57046300 CallList(display, root, selected, blocked);
57056301
57066302 // compiled = true;
5707
- if (usecalllists)
6303
+ if (usecalllists && bRep.displaylist > 0)
57086304 {
57096305 // System.err.println("end list " + bRep.displaylist + " for " + this);
57106306 display.EndList();
....@@ -5714,8 +6310,8 @@
57146310 Globals.lighttouched = true; // all panes...
57156311 }
57166312
5717
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
5718
- //touched = false;
6313
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6314
+ touched = false;
57196315
57206316 if (this instanceof Texture || this instanceof TextureNode)
57216317 {
....@@ -5804,6 +6400,7 @@
58046400 if (GetBRep() != null)
58056401 {
58066402 display.NextIndex();
6403
+
58076404 // vertex color conflict : gl.glCallList(list);
58086405 DrawNode(display, root, selected);
58096406 if (this instanceof BezierPatch)
....@@ -5815,6 +6412,20 @@
58156412 {
58166413 drawSelf(display, root, selected, blocked);
58176414 }
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
+// }
58186429 } else
58196430 {
58206431 /*
....@@ -5844,16 +6455,28 @@
58446455 tex = GetTextures();
58456456 }
58466457
5847
- boolean failed = false;
6458
+ boolean failedPigment = false;
6459
+ boolean failedBump = false;
58486460
6461
+ CameraPane.lastObject = this;
58496462 try
58506463 {
5851
- display.BindTextures(tex, texres);
6464
+ display.BindPigmentTexture(tex, texres);
58526465 }
58536466 catch (Exception e)
58546467 {
5855
- System.err.println("FAILED: " + this);
5856
- failed = true;
6468
+ // System.err.println("FAILED: " + this);
6469
+ failedPigment = true;
6470
+ }
6471
+
6472
+ try
6473
+ {
6474
+ display.BindBumpTexture(tex, texres);
6475
+ }
6476
+ catch (Exception e)
6477
+ {
6478
+ //System.err.println("FAILED: " + this);
6479
+ failedBump = true;
58576480 }
58586481
58596482 if (!compiled)
....@@ -5874,10 +6497,27 @@
58746497 // june 2013 drawSelf(display, root, selected);
58756498 }
58766499 }
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
+// }
6513
+ }
58776514 }
58786515
5879
- if (!failed)
5880
- display.ReleaseTextures(tex);
6516
+ if (!failedBump)
6517
+ display.ReleaseBumpTexture(tex);
6518
+
6519
+ if (!failedPigment)
6520
+ display.ReleasePigmentTexture(tex);
58816521
58826522 display.PopMaterial(this, selected);
58836523 }
....@@ -5923,16 +6563,17 @@
59236563
59246564 void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
59256565 {
5926
- if (GetBRep() == null)
5927
- {
5928
- drawSelf(display, root, selected, blocked);
5929
- } else
6566
+ if (GetBRep() != null)
59306567 {
59316568 DrawNode(display, root, selected);
59326569 if (this instanceof BezierPatch)
59336570 {
59346571 //drawSelf(display, root, selected);
59356572 }
6573
+ }
6574
+ else
6575
+ {
6576
+ drawSelf(display, root, selected, blocked);
59366577 }
59376578 }
59386579
....@@ -6250,6 +6891,11 @@
62506891 // dec 2012
62516892 new Exception().printStackTrace();
62526893 return;
6894
+ }
6895
+
6896
+ if (dontselect)
6897
+ {
6898
+ //bRep.GenerateNormalsMINE();
62536899 }
62546900
62556901 display.DrawGeometry(bRep, flipV, selectmode);
....@@ -7035,20 +7681,23 @@
70357681 }
70367682 }
70377683
7038
- 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)
70397688 {
7040
- int hc = info.bounds.x + info.bounds.width / 2;
7041
- int vc = info.bounds.y + info.bounds.height / 2;
7042
- 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;
70437692 if (toscreen == null)
70447693 {
7045
- toscreen = new Camera(info.camera.viewCode).toScreen;
7694
+ toscreen = new Camera(clickInfo.camera.viewCode).toScreen;
70467695 }
70477696 cVector vec = in;
70487697 LA.xformPos(in, toscreen, in);
70497698 //System.out.println("Distance = " + info.camera.Distance());
7050
- vec.x *= 100 * info.camera.SCALE / info.camera.Distance();
7051
- 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();
70527701 outPt.x = hc + (int) vec.x;
70537702 outPt.y = vc - (int) vec.y;
70547703 outRec.x = outPt.x - 3;
....@@ -7056,15 +7705,18 @@
70567705 outRec.width = outRec.height = 6;
70577706 }
70587707
7059
- protected Rectangle calcHotSpot(cVector in, ClickInfo info)
7708
+ protected Rectangle calcHotSpot(cVector in//, ClickInfo clickInfo
7709
+ )
70607710 {
70617711 Point pt = new Point(0, 0);
70627712 Rectangle rec = new Rectangle();
7063
- calcHotSpot(in, info, pt, rec);
7713
+ calcHotSpot(in, //clickInfo,
7714
+ pt, rec);
70647715 return rec;
70657716 }
70667717
7067
- void drawEditHandles0(ClickInfo info, int level)
7718
+ void drawEditHandles0(//ClickInfo clickInfo,
7719
+ int level)
70687720 {
70697721 if (level == 0)
70707722 {
....@@ -7073,16 +7725,19 @@
70737725 {
70747726 cVector origin = new cVector();
70757727 //LA.xformPos(origin, toParent, origin);
7076
- Rectangle spot = calcHotSpot(origin, info);
7728
+ if (this.clickInfo == null)
7729
+ this.clickInfo = new ClickInfo();
7730
+
7731
+ Rectangle spot = calcHotSpot(origin); //, clickInfo);
70777732 Rectangle boundary = new Rectangle();
70787733 boundary.x = spot.x - 30;
70797734 boundary.y = spot.y - 30;
70807735 boundary.width = spot.width + 60;
70817736 boundary.height = spot.height + 60;
7082
- info.g.setColor(Color.red);
7737
+ clickInfo.g.setColor(Color.white);
70837738 int spotw = spot.x + spot.width;
70847739 int spoth = spot.y + spot.height;
7085
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7740
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
70867741 // if (CameraPane.Xmin > spot.x)
70877742 // {
70887743 // CameraPane.Xmin = spot.x;
....@@ -7099,11 +7754,6 @@
70997754 // {
71007755 // CameraPane.Ymax = spoth;
71017756 // }
7102
- spot.translate(32, 32);
7103
- spotw = spot.x + spot.width;
7104
- spoth = spot.y + spot.height;
7105
- info.g.setColor(Color.cyan);
7106
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
71077757 // if (CameraPane.Xmin > spot.x)
71087758 // {
71097759 // CameraPane.Xmin = spot.x;
....@@ -7122,10 +7772,15 @@
71227772 // }
71237773 // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
71247774 //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7125
- spot.translate(0, -32);
7126
- info.g.setColor(Color.yellow);
7127
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7128
- 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);
71297784 // if (CameraPane.Xmin > spot.x)
71307785 // {
71317786 // CameraPane.Xmin = spot.x;
....@@ -7142,8 +7797,9 @@
71427797 // {
71437798 // CameraPane.Ymax = spoth;
71447799 // }
7145
- info.g.drawArc(boundary.x, boundary.y,
7146
- boundary.width, boundary.height, 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);
71477803 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
71487804 // if (CameraPane.Xmin > boundary.x)
71497805 // {
....@@ -7165,7 +7821,8 @@
71657821 }
71667822 }
71677823
7168
- boolean doEditClick0(ClickInfo info, int level)
7824
+ boolean doEditClick0(//ClickInfo clickInfo,
7825
+ int level)
71697826 {
71707827 if (level == 0)
71717828 {
....@@ -7174,8 +7831,8 @@
71747831
71757832 boolean retval = false;
71767833
7177
- startX = info.x;
7178
- startY = info.y;
7834
+ startX = clickInfo.x;
7835
+ startY = clickInfo.y;
71797836
71807837 hitSomething = -1;
71817838 cVector origin = new cVector();
....@@ -7185,22 +7842,53 @@
71857842 {
71867843 centerPt = new Point(0, 0);
71877844 }
7188
- calcHotSpot(origin, info, centerPt, spot);
7189
- if (spot.contains(info.x, info.y))
7845
+ calcHotSpot(origin, //info,
7846
+ centerPt, spot);
7847
+ if (spot.contains(clickInfo.x, clickInfo.y))
71907848 {
71917849 hitSomething = hitCenter;
71927850 retval = true;
71937851 }
71947852 spot.translate(32, 0);
7195
- if (spot.contains(info.x, info.y))
7853
+ if (spot.contains(clickInfo.x, clickInfo.y))
71967854 {
71977855 hitSomething = hitRotate;
71987856 retval = true;
71997857 }
72007858 spot.translate(0, 32);
7201
- 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))
72027862 {
72037863 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
+
72047892 retval = true;
72057893 }
72067894
....@@ -7210,7 +7898,7 @@
72107898 }
72117899
72127900 //System.out.println("info.modifiers = " + info.modifiers);
7213
- modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
7901
+ modified = (clickInfo.modifiers & CameraPane.SHIFT) != 0; // Was META
72147902 //System.out.println("modified = " + modified);
72157903 //new Exception().printStackTrace();
72167904 //viewCode = info.pane.renderCamera.viewCode;
....@@ -7238,7 +7926,8 @@
72387926 return true;
72397927 }
72407928
7241
- void doEditDrag0(ClickInfo info, boolean opposite)
7929
+ void doEditDrag0(//ClickInfo info,
7930
+ boolean opposite)
72427931 {
72437932 if (hitSomething == 0)
72447933 {
....@@ -7252,7 +7941,7 @@
72527941
72537942 //System.out.println("hitSomething = " + hitSomething);
72547943
7255
- double scale = 0.005f * info.camera.Distance();
7944
+ double scale = 0.005f * clickInfo.camera.Distance();
72567945
72577946 cVector xlate = new cVector();
72587947 //cVector xlate2 = new cVector();
....@@ -7266,7 +7955,9 @@
72667955
72677956 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
72687957
7269
- if (modified || opposite)
7958
+ // Modified could snap
7959
+ if (//modified ||
7960
+ opposite)
72707961 {
72717962 //assert(false);
72727963 /*
....@@ -7286,8 +7977,8 @@
72867977 toParent[3][i] = xlate.get(i);
72877978 LA.matInvert(toParent, fromParent);
72887979 */
7289
- cVector delta = LA.newVector(0, 0, startY - info.y);
7290
- 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);
72917982
72927983 LA.matCopy(startMat, toParent);
72937984 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7296,7 +7987,7 @@
72967987 } else
72977988 {
72987989 //LA.xformDir(delta, info.camera.fromScreen, delta);
7299
- cVector up = new cVector(info.camera.up);
7990
+ cVector up = new cVector(clickInfo.camera.up);
73007991 cVector away = new cVector();
73017992 //cVector right2 = new cVector();
73027993 //LA.vecCross(up, cVector.Z, right);
....@@ -7313,19 +8004,19 @@
73138004 LA.xformDir(up, ClickInfo.matbuffer, up);
73148005 // if (!CameraPane.LOCALTRANSFORM)
73158006 LA.xformDir(up, Globals.theRenderer.RenderCamera().toScreen, up);
7316
- LA.xformDir(info.camera.away, ClickInfo.matbuffer, away);
8007
+ LA.xformDir(clickInfo.camera.away, ClickInfo.matbuffer, away);
73178008 // if (!CameraPane.LOCALTRANSFORM)
73188009 LA.xformDir(away, Globals.theRenderer.RenderCamera().toScreen, away);
73198010 //LA.vecCross(up, cVector.Z, right2);
73208011
7321
- cVector delta = LA.newVector(info.x - startX, startY - info.y, 0);
8012
+ cVector delta = LA.newVector(clickInfo.x - startX, startY - clickInfo.y, 0);
73228013
73238014 //System.out.println("DELTA0 = " + delta);
73248015 //System.out.println("AWAY = " + info.camera.away);
73258016 //System.out.println("UP = " + info.camera.up);
73268017 if (away.z > 0)
73278018 {
7328
- if (info.camera.up.x == 0) // LA.vecDot(right, right2)<0)
8019
+ if (clickInfo.camera.up.x == 0) // LA.vecDot(right, right2)<0)
73298020 {
73308021 delta.x = -delta.x;
73318022 } else
....@@ -7340,7 +8031,7 @@
73408031 //System.out.println("DELTA1 = " + delta);
73418032 LA.xformDir(delta, ClickInfo.matbuffer, delta);
73428033 //System.out.println("DELTA2 = " + delta);
7343
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
8034
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
73448035 LA.matCopy(startMat, toParent);
73458036 //System.out.println("DELTA3 = " + delta);
73468037 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7350,8 +8041,8 @@
73508041 break;
73518042
73528043 case hitRotate: // rotate
7353
- int dx = info.x - centerPt.x;
7354
- int dy = -(info.y - centerPt.y);
8044
+ int dx = clickInfo.x - centerPt.x;
8045
+ int dy = -(clickInfo.y - centerPt.y);
73558046 double angle = (double) Math.atan2(dx, dy);
73568047 angle = -(1.570796 - angle);
73578048
....@@ -7360,7 +8051,7 @@
73608051
73618052 if (modified)
73628053 {
7363
- // Rotate 90 degrees
8054
+ // Rotate 45 degrees
73648055 angle /= (Math.PI / 4);
73658056 angle = Math.floor(angle + 0.5);
73668057 angle *= (Math.PI / 4);
....@@ -7374,7 +8065,7 @@
73748065 }
73758066 /**/
73768067
7377
- switch (info.pane.RenderCamera().viewCode)
8068
+ switch (clickInfo.pane.RenderCamera().viewCode)
73788069 {
73798070 case 1: // '\001'
73808071 LA.matZRotate(toParent, angle);
....@@ -7401,7 +8092,7 @@
74018092 break;
74028093
74038094 case hitScale: // scale
7404
- double hScale = (double) (info.x - centerPt.x) / 32;
8095
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
74058096 double sign = 1;
74068097 if (hScale < 0)
74078098 {
....@@ -7413,7 +8104,7 @@
74138104 //hScale = 0.01;
74148105 }
74158106
7416
- double vScale = (double) (info.y - centerPt.y) / 32;
8107
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
74178108 sign = 1;
74188109 if (vScale < 0)
74198110 {
....@@ -7424,6 +8115,7 @@
74248115 {
74258116 //vScale = 0.01;
74268117 }
8118
+
74278119 LA.matCopy(startMat, toParent);
74288120 /**/
74298121 for (int i = 0; i < 3; i++)
....@@ -7433,23 +8125,27 @@
74338125 }
74348126 /**/
74358127
7436
- double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
8128
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / clickInfo.scale;
74378129
74388130 if (totalScale < 0.01)
74398131 {
74408132 totalScale = 0.01;
74418133 }
74428134
7443
- switch (info.pane.RenderCamera().viewCode)
8135
+ switch (clickInfo.pane.RenderCamera().viewCode)
74448136 {
74458137 case 3: // '\001'
74468138 if (modified || opposite)
74478139 {
8140
+ if (modified) // && opposite)
8141
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8142
+ else
74488143 //LA.matScale(toParent, 1, hScale, vScale);
7449
- LA.matScale(toParent, totalScale, 1, 1);
8144
+ LA.matScale(toParent, totalScale, 1, 1);
74508145 } // vScale, 1);
74518146 else
74528147 {
8148
+ // EXCEPTION!
74538149 LA.matScale(toParent, 1, totalScale, totalScale);
74548150 } // vScale, 1);
74558151 break;
....@@ -7457,8 +8153,11 @@
74578153 case 2: // '\002'
74588154 if (modified || opposite)
74598155 {
7460
- //LA.matScale(toParent, hScale, 1, vScale);
7461
- 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);
74628161 } else
74638162 {
74648163 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7468,8 +8167,11 @@
74688167 case 1: // '\003'
74698168 if (modified || opposite)
74708169 {
7471
- //LA.matScale(toParent, hScale, vScale, 1);
7472
- 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);
74738175 } else
74748176 {
74758177 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7506,7 +8208,7 @@
75068208 } // NEW ...
75078209
75088210
7509
- info.pane.repaint();
8211
+ clickInfo.pane.repaint();
75108212 }
75118213
75128214 boolean overflow = false;
....@@ -7620,7 +8322,7 @@
76208322 if (!Globals.ADVANCED)
76218323 return objname;
76228324
7623
- return objname + " " + System.identityHashCode(this);
8325
+ return objname + " " + System.identityHashCode(this) + " " + GetUUID();
76248326 }
76258327
76268328 public int hashCode()
....@@ -7685,6 +8387,10 @@
76858387 {
76868388 editWindow = null;
76878389 } // ?
8390
+ }
8391
+ else
8392
+ {
8393
+ //editWindow.closeUI();
76888394 }
76898395 }
76908396
....@@ -7843,6 +8549,10 @@
78438549 }
78448550
78458551 transient ObjEditor editWindow;
8552
+ transient ObjEditor manipWindow;
8553
+
8554
+ transient boolean pinned;
8555
+
78468556 transient ObjectUI objectUI;
78478557 public static int povDepth = 0;
78488558 private static cVector tbMin = new cVector();
....@@ -7857,8 +8567,8 @@
78578567 private static cVector2 qq2 = new cVector2();
78588568 private static cVector2 rr2 = new cVector2();
78598569 private static cVector2 ss2 = new cVector2();
7860
- private static cVector edge1 = new cVector();
7861
- private static cVector edge2 = new cVector();
8570
+// private static cVector edge1 = new cVector();
8571
+// private static cVector edge2 = new cVector();
78628572 //private static cVector norm = new cVector();
78638573 /*transient private*/ int hitSomething;
78648574 static final int hitCenter = 1;
....@@ -8056,7 +8766,269 @@
80568766
80578767 Touch();
80588768 }
8769
+
8770
+ static Vertex s1 = new Vertex();
8771
+ static Vertex s2 = new Vertex();
8772
+ static Vertex s3 = new Vertex();
80598773
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
+ }
80609032
80619033 public int Size()
80629034 {