Normand Briere
2019-10-01 65bdec7ae2c99ca2102c55f92bd62b48c9f14847
Object3D.java
....@@ -22,18 +22,115 @@
2222 //static final long serialVersionUID = -607422624994562685L;
2323 static final long serialVersionUID = 5022536242724664900L;
2424
25
+ // Use GetUUID for backward compatibility with null.
2526 private UUID uuid = UUID.randomUUID();
2627
27
- // TEMPORARY for mocap undo. No need to be transient.
28
+ // TEMPORARY for versions. No need to be transient.
2829 mocap.reader.BVHReader.BVHResult savebvh;
2930 Object3D saveskeleton;
31
+
32
+ // FileObject
33
+ Object3D savefilecontent;
3034 //
3135
32
- byte[] versions[] = new byte[100][];
36
+ String skyboxname;
37
+ String skyboxext;
38
+
39
+ Object3D[] versionlist;
3340 int versionindex = -1;
3441
42
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
43
+
44
+ int tabIndex;
45
+
3546 ScriptNode scriptnode;
3647
48
+ void deepCopyNode(Object3D other)
49
+ {
50
+ other.skyboxname = skyboxname;
51
+ other.skyboxext = skyboxext;
52
+
53
+ if (toParent != null)
54
+ {
55
+ other.toParent = LA.newMatrix();
56
+ other.fromParent = LA.newMatrix();
57
+ LA.matCopy(toParent, other.toParent);
58
+ LA.matCopy(fromParent, other.fromParent);
59
+ if (toParentMarked != null)
60
+ {
61
+ other.toParentMarked = LA.newMatrix();
62
+ other.fromParentMarked = LA.newMatrix();
63
+ LA.matCopy(toParentMarked, other.toParentMarked);
64
+ LA.matCopy(fromParentMarked, other.fromParentMarked);
65
+ }
66
+ }
67
+ else
68
+ {
69
+ if (other.toParent == null)
70
+// assert(other.toParent == null);
71
+// new Exception().printStackTrace();
72
+ System.err.println("null parent: " + other);
73
+ }
74
+
75
+ /*
76
+ double ident[][] = LA.newMatrix();
77
+ if (bRep == null)
78
+ other.bRep = null;
79
+ else
80
+ other.bRep = new BoundaryRep(bRep, ident);
81
+ */
82
+ // Really new...
83
+ //other.editWindow = null;
84
+ if (name == null)
85
+ other.name = null;
86
+ else
87
+ other.name = new String(name);
88
+
89
+ if (material != null)
90
+ {
91
+ other.material = new cMaterial(material);
92
+ } else
93
+ {
94
+ other.material = null;
95
+ }
96
+
97
+ other.GetTextures().name = GetTextures().name;
98
+
99
+ CopyExtraMaterial(other);
100
+
101
+ other.touched = touched;
102
+ other.softtouched = softtouched;
103
+
104
+ other.random = random;
105
+ other.link2master = Link2Support();
106
+ other.transformcount = transformcount;
107
+ other.marked = marked;
108
+ other.skip = skip;
109
+ other.count = count;
110
+ other.flipV = flipV;
111
+ other.live = live;
112
+ other.rewind = rewind;
113
+ other.hide = hide;
114
+ other.texres = texres;
115
+ other.speedup = speedup;
116
+ other.height = height;
117
+ other.depth = depth;
118
+ }
119
+
120
+ int VersionCount()
121
+ {
122
+ int count = 0;
123
+
124
+ if (versionlist != null)
125
+ for (int i = versionlist.length; --i >= 0;)
126
+ {
127
+ if (versionlist[i] != null)
128
+ count++;
129
+ }
130
+
131
+ return count;
132
+ }
133
+
37134 void InitOthers()
38135 {
39136 if (projectedVertices == null || projectedVertices.length <= 2)
....@@ -45,6 +142,7 @@
45142 projectedVertices[i] = new cVector2(); // Others
46143 }
47144 projectedVertices[0].x = 100; // bump
145
+ projectedVertices[1].y = 1000; // punchthrough. only for png
48146 }
49147
50148 void MinMax(cVector minima, cVector maxima)
....@@ -124,7 +222,7 @@
124222 return;
125223
126224 transientsupport = support;
127
- transientlink2master = link2master;
225
+ transientlink2master = Link2Support();
128226
129227 support = null;
130228 link2master = false;
....@@ -171,9 +269,42 @@
171269 }
172270 }
173271
272
+ boolean HasBigData()
273
+ {
274
+ if (blockloop)
275
+ return false;
276
+
277
+ if (bRep != null)
278
+ {
279
+ return true;
280
+ }
281
+
282
+ blockloop = true;
283
+
284
+ for (int i = 0; i < Size(); i++)
285
+ {
286
+ Object3D child = (Object3D) get(i);
287
+ if (child == null)
288
+ continue;
289
+ if (child.HasBigData())
290
+ {
291
+ blockloop = false;
292
+ return true;
293
+ }
294
+ }
295
+
296
+ blockloop = false;
297
+ return false;
298
+ }
299
+
174300 void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
175301 {
302
+ if (blockloop)
303
+ return;
304
+
176305 Object3D o;
306
+
307
+ boolean isnew = false;
177308
178309 if (hashtable.containsKey(GetUUID()))
179310 {
....@@ -187,12 +318,14 @@
187318 }
188319 else
189320 {
321
+ isnew = true;
322
+
190323 o = new Object3D("copy of " + this.name);
191324
192325 hashtable.put(GetUUID(), o);
193326 }
194327
195
- if (!blockloop)
328
+ //if (!blockloop)
196329 {
197330 blockloop = true;
198331
....@@ -203,12 +336,15 @@
203336
204337 blockloop = false;
205338 }
206
-
207
- ExtractBigData(o);
339
+
340
+ //if (isnew)
341
+ ExtractBigData(o);
208342 }
209343
210344 void ExtractBigData(Object3D o)
211345 {
346
+ //System.err.println("ExtractBigData : " + this + " --> " + o);
347
+
212348 if (o.bRep != null)
213349 Grafreed.Assert(o.bRep == this.bRep);
214350
....@@ -219,6 +355,8 @@
219355 // o.bRep.support = null;
220356 // }
221357 o.selection = this.selection;
358
+ //o.versionlist = this.versionlist;
359
+ //o.versionindex = this.versionindex;
222360
223361 if (this.support != null)
224362 {
....@@ -241,17 +379,84 @@
241379 // this.fileparent = null;
242380 }
243381
382
+// Object3D GetObject(java.util.UUID uuid)
383
+// {
384
+// if (this.uuid.equals(uuid))
385
+// return this;
386
+//
387
+// if (blockloop)
388
+// return null;
389
+//
390
+// blockloop = true;
391
+//
392
+// for (int i=0; i<Size(); i++)
393
+// {
394
+// Object3D o = get(i).GetObject(uuid);
395
+//
396
+// if (o != null)
397
+// return o;
398
+// }
399
+//
400
+// blockloop = false;
401
+//
402
+// return null;
403
+// }
404
+
405
+ transient boolean tag;
406
+
407
+ void TagObjects(Object3D o, boolean tag)
408
+ {
409
+ if (blockloop)
410
+ return;
411
+
412
+ o.tag = tag;
413
+
414
+ if (o == this)
415
+ return;
416
+
417
+ blockloop = true;
418
+
419
+ for (int i=0; i<Size(); i++)
420
+ {
421
+ get(i).TagObjects(o, tag);
422
+ }
423
+
424
+ blockloop = false;
425
+ }
426
+
427
+ boolean HasTags()
428
+ {
429
+ if (blockloop)
430
+ return false;
431
+
432
+ blockloop = true;
433
+
434
+ boolean hasTags = false;
435
+
436
+ for (int i=0; i<Size(); i++)
437
+ {
438
+ hasTags |= get(i).tag || get(i).HasTags();
439
+
440
+ if (hasTags)
441
+ break;
442
+ }
443
+
444
+ blockloop = false;
445
+
446
+ return hasTags;
447
+ }
448
+
244449 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
245450 {
451
+ if (blockloop)
452
+ return;
453
+
246454 if (!hashtable.containsKey(GetUUID()))
247455 return;
248456
249457 Object3D o = hashtable.get(GetUUID());
250458
251459 RestoreBigData(o);
252
-
253
- if (blockloop)
254
- return;
255460
256461 blockloop = true;
257462
....@@ -267,6 +472,9 @@
267472
268473 void RestoreBigData(Object3D o)
269474 {
475
+ //System.err.println("RestoreBigData : " + this + " <-- " + o);
476
+ Grafreed.Assert(this.bRep == null);
477
+
270478 this.bRep = o.bRep;
271479 if (this.support != null && o.transientrep != null)
272480 {
....@@ -274,6 +482,9 @@
274482 }
275483
276484 this.selection = o.selection;
485
+
486
+ //this.versionlist = o.versionlist;
487
+ //this.versionindex = o.versionindex;
277488 // July 2019 if (this.bRep != null)
278489 // this.bRep.support = o.transientrep;
279490 // this.support = o.support;
....@@ -421,9 +632,13 @@
421632 }
422633
423634 boolean live = false;
635
+ transient boolean keepdontselect;
424636 boolean dontselect = false;
425637 boolean hide = false;
426
- boolean link2master = false; // performs reset support/master at each frame
638
+
639
+ boolean link2master = false; // performs reset support/master at each frame (cannot rename due to serialization)
640
+ boolean link2support = false; // (cannot rename due to serialization)
641
+
427642 boolean marked = false; // animation node
428643 boolean skip = false; // centroid issue
429644 boolean skipmocap = false; // mocap data
....@@ -431,6 +646,9 @@
431646 boolean random = false;
432647 boolean speedup = false;
433648 boolean rewind = false;
649
+
650
+ // Option to sort triangles, e.g. for transparency.
651
+ boolean sort = false;
434652
435653 float NORMALPUSH = 0;
436654
....@@ -449,7 +667,7 @@
449667 {
450668 sorted = true;
451669
452
- for (int i=0; i<size()-1; i++)
670
+ for (int i=0; i<Size()-1; i++)
453671 {
454672 Object3D obji = get(i);
455673 Object3D objj = get(i+1);
....@@ -473,7 +691,7 @@
473691 {
474692 sorted = true;
475693
476
- for (int i=0; i<size()-1; i++)
694
+ for (int i=0; i<Size()-1; i++)
477695 {
478696 Object3D obji = get(i);
479697 Object3D objj = get(i+1);
....@@ -489,11 +707,11 @@
489707 }
490708 }
491709
492
- int memorysize;
710
+ transient int memorysize; // needs to be transient, dunno why
493711
494712 int MemorySize()
495713 {
496
- if (true) // memorysize == 0)
714
+ if (memorysize == 0)
497715 {
498716 try
499717 {
....@@ -608,7 +826,7 @@
608826 {
609827 if (maxcount != 1)
610828 {
611
- new Exception().printStackTrace();
829
+ //new Exception().printStackTrace();
612830 }
613831
614832 toParentMarked = LA.newMatrix();
....@@ -810,7 +1028,7 @@
8101028
8111029 void Step()
8121030 {
813
- // marde pour serialization de Texture
1031
+ // patch pour serialization de Texture
8141032 resetmaxcount();
8151033 resettransformcount();
8161034 resetstep();
....@@ -1003,21 +1221,28 @@
10031221 {
10041222 // return true;
10051223
1006
- if (material == null || material.multiply)
1007
- return true;
1224
+// if (material == null || material.multiply)
1225
+// return true;
1226
+//
1227
+// if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1228
+// return false;
1229
+//
1230
+// // Transparent objects are dynamic because we have to sort the triangles.
1231
+// return material.opacity > 0.99;
10081232
1009
- // Transparent objects are dynamic because we have to sort the triangles.
1010
- return material.opacity > 0.99;
1233
+ return !sort;
10111234 }
10121235
10131236 boolean IsOpaque()
10141237 {
10151238 // return true;
10161239
1017
- if (material == null || material.multiply)
1018
- return true;
1240
+// if (material == null || material.multiply)
1241
+// return true;
1242
+//
1243
+// return material.opacity > 0.99;
10191244
1020
- return material.opacity > 0.99;
1245
+ return !sort;
10211246 }
10221247
10231248 Object3D()
....@@ -1095,8 +1320,10 @@
10951320
10961321 // will share the geometry
10971322 assert (!(this instanceof Composite));
1098
- return deepCopy(); // Never called for Composite
1099
-
1323
+
1324
+ Object3D obj = deepCopy(); // Never called for Composite
1325
+ obj.count = 2;
1326
+ return obj;
11001327 }
11011328
11021329 boolean HasLoops()
....@@ -1104,6 +1331,30 @@
11041331 return false;
11051332 }
11061333
1334
+ void ResetUUIDs()
1335
+ {
1336
+ if (blockloop)
1337
+ {
1338
+ return;
1339
+ }
1340
+
1341
+ this.uuid = null;
1342
+
1343
+ blockloop = true;
1344
+
1345
+ for (int i = 0; i < Size(); i++)
1346
+ {
1347
+ Object3D obj = (Object3D) Children().get(i);
1348
+
1349
+ if (obj != null)
1350
+ {
1351
+ obj.ResetUUIDs();
1352
+ }
1353
+ }
1354
+
1355
+ blockloop = false;
1356
+ }
1357
+
11071358 boolean IsInfinite()
11081359 {
11091360 if (blockloop)
....@@ -1174,78 +1425,16 @@
11741425 return;
11751426
11761427 blockloop = true;
1428
+
1429
+ other.parent = parent;
1430
+
11771431 //System.out.println("COPY " + this + " to " + other);
11781432 //new Exception().printStackTrace();
1433
+ deepCopyNode(other);
11791434
1180
- other.parent = parent;
1181
- if (toParent != null)
1182
- {
1183
- other.toParent = LA.newMatrix();
1184
- other.fromParent = LA.newMatrix();
1185
- LA.matCopy(toParent, other.toParent);
1186
- LA.matCopy(fromParent, other.fromParent);
1187
- if (toParentMarked != null)
1188
- {
1189
- other.toParentMarked = LA.newMatrix();
1190
- other.fromParentMarked = LA.newMatrix();
1191
- LA.matCopy(toParentMarked, other.toParentMarked);
1192
- LA.matCopy(fromParentMarked, other.fromParentMarked);
1193
- }
1194
- }
1195
- else
1196
- {
1197
- if (other.toParent == null)
1198
-// assert(other.toParent == null);
1199
-// new Exception().printStackTrace();
1200
- System.err.println("null parent: " + other);
1201
- }
1202
- /*
1203
- double ident[][] = LA.newMatrix();
1204
- if (bRep == null)
1205
- other.bRep = null;
1206
- else
1207
- other.bRep = new BoundaryRep(bRep, ident);
1208
- */
1209
- // Really new...
12101435 other.bRep = bRep; // Share the geometry
12111436
12121437 other.support = support; // Share the support
1213
-
1214
- //other.editWindow = null;
1215
- if (name == null)
1216
- other.name = null;
1217
- else
1218
- other.name = new String(name);
1219
-
1220
- if (material != null)
1221
- {
1222
- other.material = new cMaterial(material);
1223
- } else
1224
- {
1225
- other.material = null;
1226
- }
1227
-
1228
- other.GetTextures().name = GetTextures().name;
1229
-
1230
- CopyExtraMaterial(other);
1231
-
1232
- other.touched = touched;
1233
- other.softtouched = softtouched;
1234
-
1235
- other.random = random;
1236
- other.link2master = link2master;
1237
- other.transformcount = transformcount;
1238
- other.marked = marked;
1239
- other.skip = skip;
1240
- other.count = count;
1241
- other.flipV = flipV;
1242
- other.live = live;
1243
- other.rewind = rewind;
1244
- other.hide = hide;
1245
- other.texres = texres;
1246
- other.speedup = speedup;
1247
- other.height = height;
1248
- other.depth = depth;
12491438
12501439 // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist)
12511440 // {
....@@ -1301,17 +1490,24 @@
13011490 if ((mask & GEOMETRY) != 0)
13021491 {
13031492 if (bRep != null)
1304
- bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
1305
- else
1306
- assert(other.bRep == null);
1307
-
1308
- if (bRep != null)
13091493 {
1494
+ bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
13101495 CameraPane.RemoveList(bRep.displaylist);
13111496 bRep.displaylist = 0; // june 2013 -1;
13121497 }
13131498 else
1314
- bRep = bRep;
1499
+ {
1500
+ //assert(other.bRep == null);
1501
+ bRep = other.bRep;
1502
+ }
1503
+
1504
+// if (bRep != null)
1505
+// {
1506
+// CameraPane.RemoveList(bRep.displaylist);
1507
+// bRep.displaylist = 0; // june 2013 -1;
1508
+// }
1509
+// else
1510
+// bRep = bRep;
13151511 }
13161512
13171513 /* Use a MASK = GEO/MAT
....@@ -2287,11 +2483,6 @@
22872483
22882484 InitOthers();
22892485
2290
- if (this instanceof Camera)
2291
- {
2292
- material.shift = 90;
2293
- }
2294
-
22952486 material.multiply = multiply;
22962487
22972488 if (multiply)
....@@ -2432,6 +2623,11 @@
24322623 else
24332624 {
24342625 //((ObjEditor)editWindow).SetupUI2(null);
2626
+ if (objectUI != null)
2627
+ ((ObjEditor)objectUI).pinButton.setSelected(pinned);
2628
+ else
2629
+ //new Exception().printStackTrace();
2630
+ System.err.println("objectUI is null");
24352631 }
24362632 }
24372633
....@@ -2561,7 +2757,8 @@
25612757 private static final int editSelf = 1;
25622758 private static final int editChild = 2;
25632759
2564
- void drawEditHandles(ClickInfo info, int level)
2760
+ void drawEditHandles(//ClickInfo info,
2761
+ int level)
25652762 {
25662763 if (level == 0)
25672764 {
....@@ -2569,7 +2766,8 @@
25692766 return;
25702767
25712768 Object3D selectee;
2572
- for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(info, level + 1))
2769
+ for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(//info,
2770
+ level + 1))
25732771 {
25742772 selectee = (Object3D) e.nextElement();
25752773 }
....@@ -2577,19 +2775,22 @@
25772775 } else
25782776 {
25792777 //super.
2580
- drawEditHandles0(info, level + 1);
2778
+ drawEditHandles0(//info,
2779
+ level + 1);
25812780 }
25822781 }
25832782
2584
- boolean doEditClick(ClickInfo info, int level)
2783
+ boolean doEditClick(//ClickInfo info,
2784
+ int level)
25852785 {
25862786 doSomething = 0;
25872787 if (level == 0)
25882788 {
2589
- return doParentClick(info);
2789
+ return doParentClick(); //info);
25902790 }
25912791 if (//super.
2592
- doEditClick0(info, level))
2792
+ doEditClick0(//info,
2793
+ level))
25932794 {
25942795 doSomething = 1;
25952796 return true;
....@@ -2599,7 +2800,7 @@
25992800 }
26002801 }
26012802
2602
- boolean doParentClick(ClickInfo info)
2803
+ boolean doParentClick() //ClickInfo info)
26032804 {
26042805 if (selection == null)
26052806 {
....@@ -2612,7 +2813,8 @@
26122813 for (java.util.Enumeration e = selection.elements(); e.hasMoreElements();)
26132814 {
26142815 Object3D selectee = (Object3D) e.nextElement();
2615
- if (selectee.doEditClick(info, 1))
2816
+ if (selectee.doEditClick(//info,
2817
+ 1))
26162818 {
26172819 childToDrag = selectee;
26182820 doSomething = 2;
....@@ -2624,13 +2826,15 @@
26242826 return retval;
26252827 }
26262828
2627
- void doEditDrag(ClickInfo info, boolean opposite)
2829
+ void doEditDrag(//ClickInfo clickInfo,
2830
+ boolean opposite)
26282831 {
26292832 switch (doSomething)
26302833 {
26312834 case 1: // '\001'
26322835 //super.
2633
- doEditDrag0(info, opposite);
2836
+ doEditDrag0(//clickInfo,
2837
+ opposite);
26342838 break;
26352839
26362840 case 2: // '\002'
....@@ -2643,11 +2847,13 @@
26432847 {
26442848 //sel.hitSomething = childToDrag.hitSomething;
26452849 //childToDrag.doEditDrag(info);
2646
- sel.doEditDrag(info, opposite);
2850
+ sel.doEditDrag(//clickInfo,
2851
+ opposite);
26472852 } else
26482853 {
26492854 //super.
2650
- doEditDrag0(info, opposite);
2855
+ doEditDrag0(//clickInfo,
2856
+ opposite);
26512857 }
26522858 }
26532859 break;
....@@ -2665,6 +2871,9 @@
26652871 {
26662872 deselectAll();
26672873 }
2874
+
2875
+ new Exception().printStackTrace();
2876
+
26682877 ClickInfo newInfo = new ClickInfo();
26692878 newInfo.flags = info.flags;
26702879 newInfo.bounds = info.bounds;
....@@ -3094,7 +3303,10 @@
30943303 {
30953304 if (bRep != null)
30963305 {
3306
+ //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact).
30973307 bRep.GenerateNormals(crease);
3308
+ if (!bRep.trimmed)
3309
+ bRep.MergeNormals();
30983310 Touch();
30993311 }
31003312 }
....@@ -3112,7 +3324,7 @@
31123324 {
31133325 if (bRep != null)
31143326 {
3115
- bRep.GenerateNormalsMINE();
3327
+ bRep.MergeNormals(); //.GenerateNormalsMINE();
31163328 Touch();
31173329 }
31183330 }
....@@ -3169,6 +3381,105 @@
31693381 blockloop = false;
31703382 }
31713383
3384
+ public void ResetTransform(int mask)
3385
+ {
3386
+ Object3D obj = this;
3387
+
3388
+ if (mask == -1)
3389
+ {
3390
+ if (obj instanceof Camera) // jan 2014
3391
+ {
3392
+ LA.matIdentity(obj.toParent);
3393
+ LA.matIdentity(obj.fromParent);
3394
+ }
3395
+ else
3396
+ {
3397
+ obj.toParent = null; // jan 2014 LA.matIdentity(obj.toParent);
3398
+ obj.fromParent = null; // LA.matIdentity(obj.fromParent);
3399
+ }
3400
+ return;
3401
+ }
3402
+
3403
+ if ((mask&2) != 0) // Scale/rotation
3404
+ {
3405
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = 1;
3406
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3407
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3408
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1;
3409
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3410
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3411
+ }
3412
+ if ((mask&1) != 0) // Translation
3413
+ {
3414
+ if (obj.toParent != null)
3415
+ {
3416
+ obj.toParent[3][0] = obj.toParent[3][1] = obj.toParent[3][2] = 0;
3417
+ obj.fromParent[3][0] = obj.fromParent[3][1] = obj.fromParent[3][2] = 0;
3418
+ }
3419
+ }
3420
+ }
3421
+
3422
+ public void Scale(int scale)
3423
+ {
3424
+ Object3D obj = this;
3425
+
3426
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = scale;
3427
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3428
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3429
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1/scale;
3430
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3431
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3432
+ }
3433
+
3434
+ public void TextureRatioTransform(int axis)
3435
+ {
3436
+ cTexture tex = GetTextures();
3437
+
3438
+ com.sun.opengl.util.texture.TextureData texturedata = null;
3439
+
3440
+ try
3441
+ {
3442
+ texturedata = Globals.theRenderer.GetTextureData(tex, false, texres);
3443
+ }
3444
+ catch (Exception e)
3445
+ {
3446
+ System.err.println("FAIL TextureRatio: " + this);
3447
+ }
3448
+
3449
+ LA.matIdentity(Object3D.mat);
3450
+ Object3D.mat[axis][axis] = (double)texturedata.getWidth() / texturedata.getHeight();
3451
+
3452
+ if (toParent == null)
3453
+ {
3454
+ toParent = LA.newMatrix();
3455
+ fromParent = LA.newMatrix();
3456
+ }
3457
+
3458
+ ResetTransform(2);
3459
+
3460
+ LA.matConcat(Object3D.mat, fromParent, fromParent);
3461
+ LA.matInvert(fromParent, toParent);
3462
+ }
3463
+
3464
+ void TextureRatio(int axis)
3465
+ {
3466
+ if (blockloop)
3467
+ return;
3468
+
3469
+ blockloop = true;
3470
+
3471
+ TextureRatioTransform(axis);
3472
+
3473
+ for (int i=Size(); --i>=0;)
3474
+ {
3475
+ Object3D v = get(i);
3476
+
3477
+ v.TextureRatio(axis);
3478
+ }
3479
+
3480
+ blockloop = false;
3481
+ }
3482
+
31723483 void TransformChildren()
31733484 {
31743485 if (toParent != null)
....@@ -3411,6 +3722,7 @@
34113722 if (bRep != null)
34123723 {
34133724 //bRep.RemoveOneTriangle();
3725
+ System.out.println();
34143726 System.out.println("Reducing " + this);
34153727 if (name != null && name.contains("lockpickstraps"))
34163728 name = name;
....@@ -3522,15 +3834,47 @@
35223834
35233835 void ClearMaterials()
35243836 {
3837
+ if (blockloop)
3838
+ return;
3839
+
3840
+ blockloop = true;
3841
+
35253842 ClearMaterial();
3526
- for (int i = 0; i < size(); i++)
3843
+ for (int i = 0; i < Size(); i++)
35273844 {
3528
- Object3D child = (Object3D) reserve(i);
3845
+ Object3D child = (Object3D) get(i);
35293846 if (child == null)
35303847 continue;
35313848 child.ClearMaterials();
3532
- release(i);
35333849 }
3850
+
3851
+ blockloop = false;
3852
+ }
3853
+
3854
+ void ClearVersionList()
3855
+ {
3856
+ this.versionlist = null;
3857
+ this.versionindex = -1;
3858
+ this.versiontable = null;
3859
+ }
3860
+
3861
+ void ClearVersions()
3862
+ {
3863
+ if (blockloop)
3864
+ return;
3865
+
3866
+ blockloop = true;
3867
+
3868
+ ClearVersionList();
3869
+ for (int i = 0; i < Size(); i++)
3870
+ {
3871
+ Object3D child = (Object3D) get(i);
3872
+ if (child == null)
3873
+ continue;
3874
+ child.ClearVersions();
3875
+ }
3876
+
3877
+ blockloop = false;
35343878 }
35353879
35363880 void FlipV(boolean flip)
....@@ -3709,6 +4053,7 @@
37094053
37104054 void RevertMeshes()
37114055 {
4056
+ // BLOCKLOOP
37124057 if (this instanceof cMesh)
37134058 {
37144059 ((cMesh)this).Revert();
....@@ -3739,11 +4084,6 @@
37394084 Touch();
37404085 }
37414086
3742
- ResetRecur();
3743
- }
3744
-
3745
- void ResetRecur()
3746
- {
37474087 for (int i = 0; i < size(); i++)
37484088 {
37494089 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3766,11 +4106,6 @@
37664106 Step();
37674107 Touch();
37684108
3769
- StepRecur();
3770
- }
3771
-
3772
- void StepRecur()
3773
- {
37744109 for (int i = 0; i < size(); i++)
37754110 {
37764111 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3957,8 +4292,8 @@
39574292 Touch();
39584293 }
39594294
3960
- transient cVector min = new cVector();
3961
- transient cVector max = new cVector();
4295
+ transient cVector min;
4296
+ transient cVector max;
39624297
39634298 void getBounds(cVector minima, cVector maxima, boolean xform)
39644299 {
....@@ -3974,15 +4309,15 @@
39744309 if (blockloop)
39754310 return;
39764311
3977
- if (min == null) // ???
4312
+ if (min == null)
39784313 {
39794314 min = new cVector();
39804315 max = new cVector();
39814316 }
39824317
3983
- for (int i = 0; i<size(); i++)
4318
+ for (int i = 0; i<Size(); i++)
39844319 {
3985
- Object3D child = (Object3D) reserve(i);
4320
+ Object3D child = (Object3D) get(i); //reserve(i);
39864321 if (child == null)
39874322 continue;
39884323
....@@ -4001,21 +4336,21 @@
40014336 if (child.hide && !(child instanceof Merge) || child.skip)
40024337 //if (child.hide)
40034338 {
4004
- release(i);
4339
+ //release(i);
40054340 continue;
40064341 }
40074342
40084343 blockloop = true;
40094344 child.getBounds(min, max, true); // xform);
40104345 blockloop = false;
4011
- release(i);
4346
+ //release(i);
40124347
40134348 MinMax(minima, maxima);
40144349 }
40154350
40164351 if (bRep != null)
40174352 {
4018
- bRep.getBounds(minima,maxima,this);
4353
+ bRep.getBounds(minima, maxima, xform?this:null);
40194354 }
40204355
40214356 if (false) // xform)
....@@ -5415,6 +5750,51 @@
54155750 blockloop = false;
54165751 }
54175752
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
+
54185798 boolean IsSelected()
54195799 {
54205800 if (parent == null)
....@@ -5475,6 +5855,11 @@
54755855 if (fullname == null)
54765856 return "";
54775857
5858
+ if (fullname.pigment != null)
5859
+ {
5860
+ return fullname.pigment;
5861
+ }
5862
+
54785863 // System.out.println("Fullname = " + fullname);
54795864
54805865 // Does not work on Windows due to C:
....@@ -5487,7 +5872,7 @@
54875872
54885873 if (split.length == 0)
54895874 {
5490
- return "";
5875
+ return fullname.pigment = "";
54915876 }
54925877
54935878 if (split.length <= 2)
....@@ -5495,22 +5880,27 @@
54955880 if (fullname.name.endsWith(":"))
54965881 {
54975882 // Windows
5498
- return fullname.name.substring(0, fullname.name.length()-1);
5883
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
54995884 }
55005885
5501
- return split[0];
5886
+ return fullname.pigment = split[0];
55025887 }
55035888
55045889 // Windows
55055890 assert(split.length == 4);
55065891
5507
- return split[0] + ":" + split[1];
5892
+ return fullname.pigment = split[0] + ":" + split[1];
55085893 }
55095894
55105895 static String GetBump(cTexture fullname)
55115896 {
55125897 if (fullname == null)
55135898 return "";
5899
+
5900
+ if (fullname.bump != null)
5901
+ {
5902
+ return fullname.bump;
5903
+ }
55145904
55155905 // System.out.println("Fullname = " + fullname);
55165906 // Does not work on Windows due to C:
....@@ -5522,12 +5912,12 @@
55225912
55235913 if (split.length == 0)
55245914 {
5525
- return "";
5915
+ return fullname.bump = "";
55265916 }
55275917
55285918 if (split.length == 1)
55295919 {
5530
- return "";
5920
+ return fullname.bump = "";
55315921 }
55325922
55335923 if (split.length == 2)
....@@ -5535,16 +5925,16 @@
55355925 if (fullname.name.endsWith(":"))
55365926 {
55375927 // Windows
5538
- return "";
5928
+ return fullname.bump = "";
55395929 }
55405930
5541
- return split[1];
5931
+ return fullname.bump = split[1];
55425932 }
55435933
55445934 // Windows
55455935 assert(split.length == 4);
55465936
5547
- return split[2] + ":" + split[3];
5937
+ return fullname.bump = split[2] + ":" + split[3];
55485938 }
55495939
55505940 String GetPigmentTexture()
....@@ -5627,6 +6017,9 @@
56276017 texname = "";
56286018
56296019 GetTextures().name = texname + ":" + GetBump(GetTextures());
6020
+
6021
+ GetTextures().pigment = null;
6022
+
56306023 Touch();
56316024 }
56326025
....@@ -5700,6 +6093,8 @@
57006093
57016094 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
57026095
6096
+ GetTextures().bump = null;
6097
+
57036098 Touch();
57046099 }
57056100
....@@ -5724,6 +6119,38 @@
57246119 }
57256120 }
57266121
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);
6150
+ blockloop = false;
6151
+ }
6152
+ }
6153
+
57276154 void draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
57286155 {
57296156 Draw(display, root, selected, blocked);
....@@ -5732,7 +6159,7 @@
57326159 boolean NeedSupport()
57336160 {
57346161 return
5735
- CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
6162
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && Link2Support() && /*live &&*/ support != null
57366163 // PROBLEM with CROWD!!
57376164 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
57386165 }
....@@ -5750,6 +6177,20 @@
57506177 return parent.IsLive();
57516178 }
57526179
6180
+ boolean IsDynamic()
6181
+ {
6182
+ return live && bRep != null;
6183
+ }
6184
+
6185
+ boolean Link2Support()
6186
+ {
6187
+ return link2master || link2support;
6188
+ }
6189
+
6190
+ static cVector minima = new cVector();
6191
+ static cVector maxima = new cVector();
6192
+ static javax.vecmath.Point3d center = new javax.vecmath.Point3d();
6193
+
57536194 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
57546195 {
57556196 Invariants(); // june 2013
....@@ -5757,6 +6198,29 @@
57576198 if (support != null)
57586199 {
57596200 // System.err.println("Draw " + this + " Frame # " + ((Mocap)((Merge)support).object).frame);
6201
+ }
6202
+
6203
+ if (false) // live && Link2Support() && support == null && !this.marked) // project on ground
6204
+ {
6205
+ getBounds(minima, maxima, true);
6206
+ center.x = (minima.x + maxima.x) / 2;
6207
+ center.y = 10000; // (minima.y + maxima.y) / 2;
6208
+ center.z = (minima.z + maxima.z) / 2;
6209
+
6210
+ Ray ray = new Ray(center, new Vector3d(0,-1,0));
6211
+
6212
+ IntersectResult res = new IntersectResult();
6213
+ res.t = Double.POSITIVE_INFINITY;
6214
+
6215
+ if (Grafreed.grafreed.universe.intersect(ray, res))
6216
+ {
6217
+ double resx = ray.eyePoint.x + ray.viewDirection.x * res.t;
6218
+ double resy = ray.eyePoint.y + ray.viewDirection.y * res.t;
6219
+ double resz = ray.eyePoint.z + ray.viewDirection.z * res.t;
6220
+
6221
+ LA.matTranslate(toParent, 0, resy - minima.y, 0);
6222
+ LA.matInvert(toParent, fromParent);
6223
+ }
57606224 }
57616225
57626226 if (display.DrawMode() == iCameraPane.SELECTION &&
....@@ -5810,8 +6274,11 @@
58106274 if (support != null)
58116275 support = support;
58126276
5813
- //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5814
- boolean usecalllists = !IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6277
+ boolean usecalllists = !IsDynamic() &&
6278
+ IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6279
+ //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6280
+
6281
+ //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
58156282
58166283 if (!usecalllists && bRep != null && bRep.displaylist > 0)
58176284 {
....@@ -5819,10 +6286,12 @@
58196286 bRep.displaylist = 0;
58206287 }
58216288 // usecalllists &= !(parent instanceof RandomNode);
5822
- // usecalllists = false;
6289
+ if (CameraPane.BOXMODE) // Too dynamic
6290
+ usecalllists = false;
58236291
5824
- if (GetBRep() != null)
5825
- usecalllists = usecalllists;
6292
+ if (display.DrawMode() == display.SHADOW)
6293
+ //GetBRep() != null)
6294
+ usecalllists = !!usecalllists;
58266295 //System.out.println("draw " + this);
58276296 //new Exception().printStackTrace();
58286297
....@@ -5844,7 +6313,7 @@
58446313 if (!(this instanceof Composite))
58456314 touched = false;
58466315 //if (displaylist == -1 && usecalllists)
5847
- if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
6316
+ if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013
58486317 {
58496318 bRep.displaylist = display.GenList();
58506319 assert(bRep.displaylist != 0);
....@@ -5855,7 +6324,7 @@
58556324
58566325 //System.out.println("\tnew list " + list);
58576326 //gl.glDrawBuffer(gl.GL_NONE);
5858
- if (usecalllists)
6327
+ if (usecalllists && bRep.displaylist > 0)
58596328 {
58606329 // System.err.println("new list " + bRep.displaylist + " for " + this);
58616330 display.NewList(bRep.displaylist);
....@@ -5864,7 +6333,7 @@
58646333 CallList(display, root, selected, blocked);
58656334
58666335 // compiled = true;
5867
- if (usecalllists)
6336
+ if (usecalllists && bRep.displaylist > 0)
58686337 {
58696338 // System.err.println("end list " + bRep.displaylist + " for " + this);
58706339 display.EndList();
....@@ -5874,8 +6343,8 @@
58746343 Globals.lighttouched = true; // all panes...
58756344 }
58766345
5877
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
5878
- //touched = false;
6346
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6347
+ touched = false;
58796348
58806349 if (this instanceof Texture || this instanceof TextureNode)
58816350 {
....@@ -5914,7 +6383,7 @@
59146383 {
59156384 if (display.DrawMode() == iCameraPane.SHADOW)
59166385 {
5917
- if (!link2master // tricky to cull in shadow mode.
6386
+ if (!Link2Support() // tricky to cull in shadow mode.
59186387 && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
59196388 {
59206389 //System.out.print("CULLED");
....@@ -5976,6 +6445,20 @@
59766445 {
59776446 drawSelf(display, root, selected, blocked);
59786447 }
6448
+
6449
+// if (!(this instanceof Composite))
6450
+// {
6451
+// for (int i = 0; i < size(); i++)
6452
+// {
6453
+// Object3D child = (Object3D) reserve(i);
6454
+// if (child == null)
6455
+// continue;
6456
+//
6457
+// child.draw(display, root, selected, blocked);
6458
+//
6459
+// release(i);
6460
+// }
6461
+// }
59796462 } else
59806463 {
59816464 /*
....@@ -6008,13 +6491,14 @@
60086491 boolean failedPigment = false;
60096492 boolean failedBump = false;
60106493
6494
+ CameraPane.lastObject = this;
60116495 try
60126496 {
60136497 display.BindPigmentTexture(tex, texres);
60146498 }
60156499 catch (Exception e)
60166500 {
6017
- System.err.println("FAILED: " + this);
6501
+ // System.err.println("FAILED: " + this);
60186502 failedPigment = true;
60196503 }
60206504
....@@ -6045,6 +6529,20 @@
60456529 display.CallList(bRep.displaylist);
60466530 // june 2013 drawSelf(display, root, selected);
60476531 }
6532
+ }
6533
+
6534
+ assert (!(this instanceof Composite));
6535
+ {
6536
+// CRASH MOCAP!! for (int i = 0; i < size(); i++)
6537
+// {
6538
+// Object3D child = (Object3D) reserve(i);
6539
+// if (child == null)
6540
+// continue;
6541
+//
6542
+// child.draw(display, root, selected, blocked);
6543
+//
6544
+// release(i);
6545
+// }
60486546 }
60496547 }
60506548
....@@ -6098,16 +6596,17 @@
60986596
60996597 void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
61006598 {
6101
- if (GetBRep() == null)
6102
- {
6103
- drawSelf(display, root, selected, blocked);
6104
- } else
6599
+ if (GetBRep() != null)
61056600 {
61066601 DrawNode(display, root, selected);
61076602 if (this instanceof BezierPatch)
61086603 {
61096604 //drawSelf(display, root, selected);
61106605 }
6606
+ }
6607
+ else
6608
+ {
6609
+ drawSelf(display, root, selected, blocked);
61116610 }
61126611 }
61136612
....@@ -6357,7 +6856,7 @@
63576856
63586857 //javax.media.opengl.GL gl = display.GetGL();
63596858
6360
- if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
6859
+ if (CameraPane.BOXMODE && !Link2Support()) //selected) // || CameraPane.movingcamera)
63616860 {
63626861 int fc = bRep.FaceCount();
63636862 int vc = bRep.VertexCount();
....@@ -6519,7 +7018,7 @@
65197018 facescompare[k] = new FaceCompare(k);
65207019 }
65217020
6522
- center = new cVector();
7021
+ centertriangle = new cVector();
65237022 }
65247023 else
65257024 {
....@@ -6642,7 +7141,7 @@
66427141 */
66437142 }
66447143
6645
- transient cVector center;
7144
+ transient cVector centertriangle;
66467145
66477146 class FaceCompare implements Comparable
66487147 {
....@@ -6671,14 +7170,14 @@
66717170 Vertex q = bRep.GetVertex(face.q);
66727171 Vertex r = bRep.GetVertex(face.r);
66737172
6674
- center.set(p);
6675
- center.add(q);
6676
- center.add(r);
6677
- center.mul(1.0/3);
7173
+ centertriangle.set(p);
7174
+ centertriangle.add(q);
7175
+ centertriangle.add(r);
7176
+ centertriangle.mul(1.0/3);
66787177
6679
- center.sub(Globals.theRenderer.EyeCamera().location);
7178
+ centertriangle.sub(Globals.theRenderer.EyeCamera().location);
66807179
6681
- distance = center.dot(center);
7180
+ distance = centertriangle.dot(centertriangle);
66827181 }
66837182
66847183 return distance;
....@@ -7215,20 +7714,23 @@
72157714 }
72167715 }
72177716
7218
- protected void calcHotSpot(cVector in, ClickInfo info, Point outPt, Rectangle outRec)
7717
+ static ClickInfo clickInfo = new ClickInfo();
7718
+
7719
+ protected void calcHotSpot(cVector in, //ClickInfo clickInfo,
7720
+ Point outPt, Rectangle outRec)
72197721 {
7220
- int hc = info.bounds.x + info.bounds.width / 2;
7221
- int vc = info.bounds.y + info.bounds.height / 2;
7222
- double[][] toscreen = info.toScreen;
7722
+ int hc = clickInfo.bounds.x + clickInfo.bounds.width / 2;
7723
+ int vc = clickInfo.bounds.y + clickInfo.bounds.height / 2;
7724
+ double[][] toscreen = clickInfo.toScreen;
72237725 if (toscreen == null)
72247726 {
7225
- toscreen = new Camera(info.camera.viewCode).toScreen;
7727
+ toscreen = new Camera(clickInfo.camera.viewCode).toScreen;
72267728 }
72277729 cVector vec = in;
72287730 LA.xformPos(in, toscreen, in);
72297731 //System.out.println("Distance = " + info.camera.Distance());
7230
- vec.x *= 100 * info.camera.SCALE / info.camera.Distance();
7231
- vec.y *= 100 * info.camera.SCALE / info.camera.Distance();
7732
+ vec.x *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
7733
+ vec.y *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
72327734 outPt.x = hc + (int) vec.x;
72337735 outPt.y = vc - (int) vec.y;
72347736 outRec.x = outPt.x - 3;
....@@ -7236,15 +7738,18 @@
72367738 outRec.width = outRec.height = 6;
72377739 }
72387740
7239
- protected Rectangle calcHotSpot(cVector in, ClickInfo info)
7741
+ protected Rectangle calcHotSpot(cVector in//, ClickInfo clickInfo
7742
+ )
72407743 {
72417744 Point pt = new Point(0, 0);
72427745 Rectangle rec = new Rectangle();
7243
- calcHotSpot(in, info, pt, rec);
7746
+ calcHotSpot(in, //clickInfo,
7747
+ pt, rec);
72447748 return rec;
72457749 }
72467750
7247
- void drawEditHandles0(ClickInfo info, int level)
7751
+ void drawEditHandles0(//ClickInfo clickInfo,
7752
+ int level)
72487753 {
72497754 if (level == 0)
72507755 {
....@@ -7253,16 +7758,19 @@
72537758 {
72547759 cVector origin = new cVector();
72557760 //LA.xformPos(origin, toParent, origin);
7256
- Rectangle spot = calcHotSpot(origin, info);
7761
+ if (this.clickInfo == null)
7762
+ this.clickInfo = new ClickInfo();
7763
+
7764
+ Rectangle spot = calcHotSpot(origin); //, clickInfo);
72577765 Rectangle boundary = new Rectangle();
72587766 boundary.x = spot.x - 30;
72597767 boundary.y = spot.y - 30;
72607768 boundary.width = spot.width + 60;
72617769 boundary.height = spot.height + 60;
7262
- info.g.setColor(Color.red);
7770
+ clickInfo.g.setColor(Color.white);
72637771 int spotw = spot.x + spot.width;
72647772 int spoth = spot.y + spot.height;
7265
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7773
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
72667774 // if (CameraPane.Xmin > spot.x)
72677775 // {
72687776 // CameraPane.Xmin = spot.x;
....@@ -7279,11 +7787,6 @@
72797787 // {
72807788 // CameraPane.Ymax = spoth;
72817789 // }
7282
- spot.translate(32, 32);
7283
- spotw = spot.x + spot.width;
7284
- spoth = spot.y + spot.height;
7285
- info.g.setColor(Color.cyan);
7286
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
72877790 // if (CameraPane.Xmin > spot.x)
72887791 // {
72897792 // CameraPane.Xmin = spot.x;
....@@ -7302,10 +7805,15 @@
73027805 // }
73037806 // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
73047807 //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7305
- spot.translate(0, -32);
7306
- info.g.setColor(Color.yellow);
7307
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7308
- info.g.setColor(Color.green);
7808
+ spot.translate(32, 0);
7809
+ clickInfo.g.setColor(Color.yellow);
7810
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7811
+
7812
+ spot.translate(32, 64);
7813
+ spotw = spot.x + spot.width;
7814
+ spoth = spot.y + spot.height;
7815
+ clickInfo.g.setColor(Color.cyan);
7816
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
73097817 // if (CameraPane.Xmin > spot.x)
73107818 // {
73117819 // CameraPane.Xmin = spot.x;
....@@ -7322,8 +7830,9 @@
73227830 // {
73237831 // CameraPane.Ymax = spoth;
73247832 // }
7325
- info.g.drawArc(boundary.x + info.DX, boundary.y + info.DY,
7326
- (int)(boundary.width * info.W), (int)(boundary.height * info.W), 0, 360);
7833
+ clickInfo.g.setColor(Color.green);
7834
+ clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY,
7835
+ (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360);
73277836 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
73287837 // if (CameraPane.Xmin > boundary.x)
73297838 // {
....@@ -7345,7 +7854,8 @@
73457854 }
73467855 }
73477856
7348
- boolean doEditClick0(ClickInfo info, int level)
7857
+ boolean doEditClick0(//ClickInfo clickInfo,
7858
+ int level)
73497859 {
73507860 if (level == 0)
73517861 {
....@@ -7354,8 +7864,8 @@
73547864
73557865 boolean retval = false;
73567866
7357
- startX = info.x;
7358
- startY = info.y;
7867
+ startX = clickInfo.x;
7868
+ startY = clickInfo.y;
73597869
73607870 hitSomething = -1;
73617871 cVector origin = new cVector();
....@@ -7365,22 +7875,53 @@
73657875 {
73667876 centerPt = new Point(0, 0);
73677877 }
7368
- calcHotSpot(origin, info, centerPt, spot);
7369
- if (spot.contains(info.x, info.y))
7878
+ calcHotSpot(origin, //info,
7879
+ centerPt, spot);
7880
+ if (spot.contains(clickInfo.x, clickInfo.y))
73707881 {
73717882 hitSomething = hitCenter;
73727883 retval = true;
73737884 }
73747885 spot.translate(32, 0);
7375
- if (spot.contains(info.x, info.y))
7886
+ if (spot.contains(clickInfo.x, clickInfo.y))
73767887 {
73777888 hitSomething = hitRotate;
73787889 retval = true;
73797890 }
73807891 spot.translate(0, 32);
7381
- if (spot.contains(info.x, info.y))
7892
+ spot.translate(32, 0);
7893
+ spot.translate(0, 32);
7894
+ if (spot.contains(clickInfo.x, clickInfo.y))
73827895 {
73837896 hitSomething = hitScale;
7897
+
7898
+ double scale = 0.005f * clickInfo.camera.Distance();
7899
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
7900
+ double sign = 1;
7901
+ if (hScale < 0)
7902
+ {
7903
+ sign = -1;
7904
+ }
7905
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
7906
+ if (hScale < 0.01)
7907
+ {
7908
+ //hScale = 0.01;
7909
+ }
7910
+
7911
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
7912
+ sign = 1;
7913
+ if (vScale < 0)
7914
+ {
7915
+ sign = -1;
7916
+ }
7917
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
7918
+ if (vScale < 0.01)
7919
+ {
7920
+ //vScale = 0.01;
7921
+ }
7922
+
7923
+ clickInfo.scale = Math.sqrt(hScale*hScale + vScale*vScale);
7924
+
73847925 retval = true;
73857926 }
73867927
....@@ -7390,7 +7931,7 @@
73907931 }
73917932
73927933 //System.out.println("info.modifiers = " + info.modifiers);
7393
- modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
7934
+ modified = (clickInfo.modifiers & CameraPane.SHIFT) != 0; // Was META
73947935 //System.out.println("modified = " + modified);
73957936 //new Exception().printStackTrace();
73967937 //viewCode = info.pane.renderCamera.viewCode;
....@@ -7418,7 +7959,8 @@
74187959 return true;
74197960 }
74207961
7421
- void doEditDrag0(ClickInfo info, boolean opposite)
7962
+ void doEditDrag0(//ClickInfo info,
7963
+ boolean opposite)
74227964 {
74237965 if (hitSomething == 0)
74247966 {
....@@ -7432,7 +7974,7 @@
74327974
74337975 //System.out.println("hitSomething = " + hitSomething);
74347976
7435
- double scale = 0.005f * info.camera.Distance();
7977
+ double scale = 0.005f * clickInfo.camera.Distance();
74367978
74377979 cVector xlate = new cVector();
74387980 //cVector xlate2 = new cVector();
....@@ -7446,7 +7988,9 @@
74467988
74477989 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
74487990
7449
- if (modified || opposite)
7991
+ // Modified could snap
7992
+ if (//modified ||
7993
+ opposite)
74507994 {
74517995 //assert(false);
74527996 /*
....@@ -7466,8 +8010,8 @@
74668010 toParent[3][i] = xlate.get(i);
74678011 LA.matInvert(toParent, fromParent);
74688012 */
7469
- cVector delta = LA.newVector(0, 0, startY - info.y);
7470
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
8013
+ cVector delta = LA.newVector(0, 0, startY - clickInfo.y);
8014
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
74718015
74728016 LA.matCopy(startMat, toParent);
74738017 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7476,7 +8020,7 @@
74768020 } else
74778021 {
74788022 //LA.xformDir(delta, info.camera.fromScreen, delta);
7479
- cVector up = new cVector(info.camera.up);
8023
+ cVector up = new cVector(clickInfo.camera.up);
74808024 cVector away = new cVector();
74818025 //cVector right2 = new cVector();
74828026 //LA.vecCross(up, cVector.Z, right);
....@@ -7493,19 +8037,19 @@
74938037 LA.xformDir(up, ClickInfo.matbuffer, up);
74948038 // if (!CameraPane.LOCALTRANSFORM)
74958039 LA.xformDir(up, Globals.theRenderer.RenderCamera().toScreen, up);
7496
- LA.xformDir(info.camera.away, ClickInfo.matbuffer, away);
8040
+ LA.xformDir(clickInfo.camera.away, ClickInfo.matbuffer, away);
74978041 // if (!CameraPane.LOCALTRANSFORM)
74988042 LA.xformDir(away, Globals.theRenderer.RenderCamera().toScreen, away);
74998043 //LA.vecCross(up, cVector.Z, right2);
75008044
7501
- cVector delta = LA.newVector(info.x - startX, startY - info.y, 0);
8045
+ cVector delta = LA.newVector(clickInfo.x - startX, startY - clickInfo.y, 0);
75028046
75038047 //System.out.println("DELTA0 = " + delta);
75048048 //System.out.println("AWAY = " + info.camera.away);
75058049 //System.out.println("UP = " + info.camera.up);
75068050 if (away.z > 0)
75078051 {
7508
- if (info.camera.up.x == 0) // LA.vecDot(right, right2)<0)
8052
+ if (clickInfo.camera.up.x == 0) // LA.vecDot(right, right2)<0)
75098053 {
75108054 delta.x = -delta.x;
75118055 } else
....@@ -7520,7 +8064,7 @@
75208064 //System.out.println("DELTA1 = " + delta);
75218065 LA.xformDir(delta, ClickInfo.matbuffer, delta);
75228066 //System.out.println("DELTA2 = " + delta);
7523
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
8067
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
75248068 LA.matCopy(startMat, toParent);
75258069 //System.out.println("DELTA3 = " + delta);
75268070 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7530,8 +8074,8 @@
75308074 break;
75318075
75328076 case hitRotate: // rotate
7533
- int dx = info.x - centerPt.x;
7534
- int dy = -(info.y - centerPt.y);
8077
+ int dx = clickInfo.x - centerPt.x;
8078
+ int dy = -(clickInfo.y - centerPt.y);
75358079 double angle = (double) Math.atan2(dx, dy);
75368080 angle = -(1.570796 - angle);
75378081
....@@ -7540,7 +8084,7 @@
75408084
75418085 if (modified)
75428086 {
7543
- // Rotate 90 degrees
8087
+ // Rotate 45 degrees
75448088 angle /= (Math.PI / 4);
75458089 angle = Math.floor(angle + 0.5);
75468090 angle *= (Math.PI / 4);
....@@ -7554,7 +8098,7 @@
75548098 }
75558099 /**/
75568100
7557
- switch (info.pane.RenderCamera().viewCode)
8101
+ switch (clickInfo.pane.RenderCamera().viewCode)
75588102 {
75598103 case 1: // '\001'
75608104 LA.matZRotate(toParent, angle);
....@@ -7581,7 +8125,7 @@
75818125 break;
75828126
75838127 case hitScale: // scale
7584
- double hScale = (double) (info.x - centerPt.x) / 32;
8128
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
75858129 double sign = 1;
75868130 if (hScale < 0)
75878131 {
....@@ -7593,7 +8137,7 @@
75938137 //hScale = 0.01;
75948138 }
75958139
7596
- double vScale = (double) (info.y - centerPt.y) / 32;
8140
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
75978141 sign = 1;
75988142 if (vScale < 0)
75998143 {
....@@ -7604,6 +8148,7 @@
76048148 {
76058149 //vScale = 0.01;
76068150 }
8151
+
76078152 LA.matCopy(startMat, toParent);
76088153 /**/
76098154 for (int i = 0; i < 3; i++)
....@@ -7613,33 +8158,39 @@
76138158 }
76148159 /**/
76158160
7616
- double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
8161
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / clickInfo.scale;
76178162
76188163 if (totalScale < 0.01)
76198164 {
76208165 totalScale = 0.01;
76218166 }
76228167
7623
- switch (info.pane.RenderCamera().viewCode)
8168
+ switch (clickInfo.pane.RenderCamera().viewCode)
76248169 {
76258170 case 3: // '\001'
76268171 if (modified || opposite)
76278172 {
8173
+ if (modified) // && opposite)
8174
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8175
+ else
76288176 //LA.matScale(toParent, 1, hScale, vScale);
7629
- LA.matScale(toParent, totalScale, 1, 1);
8177
+ LA.matScale(toParent, totalScale, 1, 1);
76308178 } // vScale, 1);
76318179 else
76328180 {
76338181 // EXCEPTION!
7634
- LA.matScale(toParent, totalScale, totalScale, totalScale);
8182
+ LA.matScale(toParent, 1, totalScale, totalScale);
76358183 } // vScale, 1);
76368184 break;
76378185
76388186 case 2: // '\002'
76398187 if (modified || opposite)
76408188 {
7641
- //LA.matScale(toParent, hScale, 1, vScale);
7642
- LA.matScale(toParent, 1, totalScale, 1);
8189
+ if (modified) // && opposite)
8190
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8191
+ else
8192
+ //LA.matScale(toParent, hScale, 1, vScale);
8193
+ LA.matScale(toParent, 1, totalScale, 1);
76438194 } else
76448195 {
76458196 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7649,8 +8200,11 @@
76498200 case 1: // '\003'
76508201 if (modified || opposite)
76518202 {
7652
- //LA.matScale(toParent, hScale, vScale, 1);
7653
- LA.matScale(toParent, 1, 1, totalScale);
8203
+ if (modified) // && opposite)
8204
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8205
+ else
8206
+ //LA.matScale(toParent, hScale, vScale, 1);
8207
+ LA.matScale(toParent, 1, 1, totalScale);
76548208 } else
76558209 {
76568210 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7687,7 +8241,7 @@
76878241 } // NEW ...
76888242
76898243
7690
- info.pane.repaint();
8244
+ clickInfo.pane.repaint();
76918245 }
76928246
76938247 boolean overflow = false;
....@@ -7801,12 +8355,12 @@
78018355 if (!Globals.ADVANCED)
78028356 return objname;
78038357
7804
- return objname + " " + System.identityHashCode(this);
8358
+ return objname + " " + System.identityHashCode(this) + " " + GetUUID();
78058359 }
78068360
78078361 public int hashCode()
78088362 {
7809
- // Fuck Vector...
8363
+ // Do not use Vector...
78108364 return System.identityHashCode(this);
78118365 }
78128366
....@@ -8046,8 +8600,8 @@
80468600 private static cVector2 qq2 = new cVector2();
80478601 private static cVector2 rr2 = new cVector2();
80488602 private static cVector2 ss2 = new cVector2();
8049
- private static cVector edge1 = new cVector();
8050
- private static cVector edge2 = new cVector();
8603
+// private static cVector edge1 = new cVector();
8604
+// private static cVector edge2 = new cVector();
80518605 //private static cVector norm = new cVector();
80528606 /*transient private*/ int hitSomething;
80538607 static final int hitCenter = 1;
....@@ -8245,7 +8799,275 @@
82458799
82468800 Touch();
82478801 }
8802
+
8803
+ static Vertex s1 = new Vertex();
8804
+ static Vertex s2 = new Vertex();
8805
+ static Vertex s3 = new Vertex();
82488806
8807
+ boolean intersectMesh(Ray ray, IntersectResult result)
8808
+ {
8809
+ boolean success = false;
8810
+
8811
+ if (bRep.stripified)
8812
+ {
8813
+ int[] strips = bRep.getRawIndices();
8814
+
8815
+ // TRIANGLE STRIP ARRAY
8816
+ if (bRep.trimmed)
8817
+ {
8818
+ float[] v = bRep.getRawVertices();
8819
+
8820
+ int count3 = 0;
8821
+
8822
+ if (v.length > 0)
8823
+ {
8824
+ for (int i = 0; i < strips.length; i++)
8825
+ {
8826
+ s1.set(v[count3], v[count3 + 1], v[count3 + 2]);
8827
+ count3 += 3;
8828
+
8829
+ s2.set(v[count3], v[count3 + 1], v[count3 + 2]);
8830
+ count3 += 3;
8831
+
8832
+ for (int j = 0; j < strips[i] - 2; j++)
8833
+ {
8834
+ s3.set(v[count3], v[count3 + 1], v[count3 + 2]);
8835
+ count3 += 3;
8836
+
8837
+ if (j%2 == 0)
8838
+ success |= intersectTriangle(ray, result, s1, s2, s3);
8839
+ else
8840
+ success |= intersectTriangle(ray, result, s1, s3, s2);
8841
+
8842
+ s1.set(s2);
8843
+ s2.set(s3);
8844
+ }
8845
+ }
8846
+ }
8847
+
8848
+ assert count3 == v.length;
8849
+ }
8850
+ else // !trimmed
8851
+ {
8852
+ int count = 0;
8853
+ for (int i = 0; i < strips.length; i++)
8854
+ {
8855
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
8856
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
8857
+
8858
+ for (int j = 0; j < strips[i] - 2; j++)
8859
+ {
8860
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
8861
+
8862
+ if (j%2 == 0)
8863
+ success |= intersectTriangle(ray, result, p, q, r);
8864
+ else
8865
+ success |= intersectTriangle(ray, result, p, r, q);
8866
+
8867
+ p = q;
8868
+ q = r;
8869
+ }
8870
+ }
8871
+ }
8872
+ } else // catch (Error e)
8873
+ {
8874
+ int facecount = bRep.FaceCount();
8875
+ for (int i = 0; i < facecount; i++)
8876
+ {
8877
+ Face face = bRep.GetFace(i);
8878
+
8879
+ Vertex p = bRep.GetVertex(face.p);
8880
+ Vertex q = bRep.GetVertex(face.q);
8881
+ Vertex r = bRep.GetVertex(face.r);
8882
+
8883
+ success |= intersectTriangle(ray, result, p, q, r);
8884
+ }
8885
+ }
8886
+
8887
+ return success;
8888
+ }
8889
+
8890
+ static cVector eye = new cVector();
8891
+ static cVector dir = new cVector();
8892
+
8893
+ transient BBox bbox = null;
8894
+
8895
+ boolean intersect(Ray ray, IntersectResult result)
8896
+ {
8897
+ double eyex = ray.eyePoint.x;
8898
+ double eyey = ray.eyePoint.y;
8899
+ double eyez = ray.eyePoint.z;
8900
+
8901
+ double dirx = ray.viewDirection.x;
8902
+ double diry = ray.viewDirection.y;
8903
+ double dirz = ray.viewDirection.z;
8904
+
8905
+ if (this.fromParent != null && !(this instanceof TextureNode))
8906
+ {
8907
+ eye.x = eyex;
8908
+ eye.y = eyey;
8909
+ eye.z = eyez;
8910
+ dir.x = dirx;
8911
+ dir.y = diry;
8912
+ dir.z = dirz;
8913
+
8914
+ LA.xformPos(eye, this.fromParent, eye);
8915
+ LA.xformDir(dir, this.fromParent, dir);
8916
+
8917
+ ray.eyePoint.x = eye.x;
8918
+ ray.eyePoint.y = eye.y;
8919
+ ray.eyePoint.z = eye.z;
8920
+
8921
+ ray.viewDirection.x = dir.x;
8922
+ ray.viewDirection.y = dir.y;
8923
+ ray.viewDirection.z = dir.z;
8924
+ }
8925
+
8926
+ boolean success = false;
8927
+
8928
+ boolean touch = false;
8929
+
8930
+ if (bRep != null && Link2Support())
8931
+ {
8932
+ if (bbox == null)
8933
+ {
8934
+ bbox = new BBox();
8935
+
8936
+ cVector min = new cVector();
8937
+ cVector max = new cVector();
8938
+
8939
+ this.getBounds(min, max, true);
8940
+
8941
+ bbox.min.x = min.x;
8942
+ bbox.min.y = min.y;
8943
+ bbox.min.z = min.z;
8944
+
8945
+ bbox.max.x = max.x;
8946
+ bbox.max.y = max.y;
8947
+ bbox.max.z = max.z;
8948
+ }
8949
+
8950
+ if (true) // NOT WORKING bbox.intersect(ray, result))
8951
+ {
8952
+ success |= intersectMesh(ray, result);
8953
+ }
8954
+ else
8955
+ {
8956
+ //this.hide = true;
8957
+ touch = true;
8958
+ }
8959
+ }
8960
+
8961
+ for (int i=0; i<size(); i++)
8962
+ {
8963
+ Object3D child = (Object3D) reserve(i);
8964
+
8965
+ if (child == null)
8966
+ continue;
8967
+
8968
+ success |= child.intersect(ray, result);
8969
+ release(i);
8970
+ }
8971
+
8972
+ ray.eyePoint.x = eyex;
8973
+ ray.eyePoint.y = eyey;
8974
+ ray.eyePoint.z = eyez;
8975
+
8976
+ ray.viewDirection.x = dirx;
8977
+ ray.viewDirection.y = diry;
8978
+ ray.viewDirection.z = dirz;
8979
+
8980
+// if (touch)
8981
+// this.Touch(); // refresh display list
8982
+
8983
+ return success;
8984
+ }
8985
+
8986
+ static Vector3d edge1 = new Vector3d();
8987
+ static Vector3d edge2 = new Vector3d();
8988
+ static Vector3d P = new Vector3d();
8989
+ static Vector3d T = new Vector3d();
8990
+ static Vector3d Q = new Vector3d();
8991
+
8992
+ private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3)
8993
+ {
8994
+ if (false)
8995
+ {
8996
+ result.t = 0;
8997
+ return true;
8998
+ }
8999
+
9000
+ /*
9001
+ Fast, Minimum Storage Ray/Triangle Intersection, Moller et al.
9002
+
9003
+ Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
9004
+ */
9005
+
9006
+ // Calculate edges of the triangle
9007
+ edge1.set(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z);
9008
+ edge2.set(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z);
9009
+
9010
+ // Calculate the determinant (U parameter)
9011
+ P.cross(ray.viewDirection, edge2);
9012
+ double det = edge1.dot(P);
9013
+
9014
+ if (det > -1e-9 && det < 1e-9)
9015
+ {
9016
+ return false;
9017
+ } // Ray lies in plane of triangle
9018
+
9019
+ double invDet = 1 / det;
9020
+
9021
+ // Calculate distance from vertex1 to ray origin
9022
+ T.set(ray.eyePoint.x - v1.x, ray.eyePoint.y - v1.y, ray.eyePoint.z - v1.z);
9023
+
9024
+ double U = (T.dot(P)) * invDet; // Calculate U parameter
9025
+
9026
+ if (U < 0.f || U > 1.f)
9027
+ {
9028
+ return false;
9029
+ } // Intersection lies outside of the triangle
9030
+
9031
+ // Calculate V parameter
9032
+ Q.cross(T, edge1);
9033
+
9034
+ double V = ray.viewDirection.dot(Q) * invDet;
9035
+
9036
+ if (V < 0.f || (U + V) > 1.f)
9037
+ {
9038
+ return false;
9039
+ } // Intersection lies outside of the triangle
9040
+
9041
+ double t = edge2.dot(Q) * invDet;
9042
+
9043
+ if (t > 1e-9) // Triangle and ray intersects
9044
+ {
9045
+ //result.isIntersected = true;
9046
+ //result.id = id;
9047
+
9048
+ if (false) // isShadow)
9049
+ {
9050
+ result.t = t;
9051
+ return true;
9052
+ } else if (t < result.t)
9053
+ {
9054
+ result.object = this;
9055
+
9056
+ result.t = t;
9057
+
9058
+ //result.p.x = ray.eyePoint.x + ray.viewDirection.x * t;
9059
+ //result.p.y = ray.eyePoint.y + ray.viewDirection.y * t;
9060
+ //result.p.z = ray.eyePoint.z + ray.viewDirection.z * t;
9061
+
9062
+ result.n.cross(edge1, edge2);
9063
+ result.n.normalize();
9064
+ }
9065
+
9066
+ return true;
9067
+ }
9068
+
9069
+ return false;
9070
+ }
82499071
82509072 public int Size()
82519073 {