Normand Briere
2019-11-17 cb37a129d1adb403019c96e798e86e2da9667f15
Object3D.java
....@@ -22,18 +22,129 @@
2222 //static final long serialVersionUID = -607422624994562685L;
2323 static final long serialVersionUID = 5022536242724664900L;
2424
25
+ // Use GetUUID for backward compatibility with null.
2526 private UUID uuid = UUID.randomUUID();
2627
27
- // TEMPORARY for mocap undo. No need to be transient.
28
+ // TEMPORARY for versions. No need to be transient.
2829 mocap.reader.BVHReader.BVHResult savebvh;
2930 Object3D saveskeleton;
31
+
32
+ // FileObject
33
+ Object3D savefilecontent;
3034 //
3135
32
- byte[] versions[];
36
+ String skyboxname;
37
+ String skyboxext;
38
+
39
+ Object3D[] versionlist;
3340 int versionindex = -1;
3441
42
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
43
+
44
+ transient int tabIndex; // Tabs can change between sessions.
45
+
3546 ScriptNode scriptnode;
3647
48
+ void GetOrigin(cVector o)
49
+ {
50
+ o.x = this.toParent[3][0];
51
+ o.y = this.toParent[3][1];
52
+ o.z = this.toParent[3][2];
53
+ }
54
+
55
+ void SetOrigin(cVector o)
56
+ {
57
+ this.toParent[3][0] = o.x;
58
+ this.toParent[3][1] = o.y;
59
+ this.toParent[3][2] = o.z;
60
+ }
61
+
62
+ void deepCopyNode(Object3D other)
63
+ {
64
+ other.skyboxname = skyboxname;
65
+ other.skyboxext = skyboxext;
66
+
67
+ if (toParent != null)
68
+ {
69
+ other.toParent = LA.newMatrix();
70
+ other.fromParent = LA.newMatrix();
71
+ LA.matCopy(toParent, other.toParent);
72
+ LA.matCopy(fromParent, other.fromParent);
73
+ if (toParentMarked != null)
74
+ {
75
+ other.toParentMarked = LA.newMatrix();
76
+ other.fromParentMarked = LA.newMatrix();
77
+ LA.matCopy(toParentMarked, other.toParentMarked);
78
+ LA.matCopy(fromParentMarked, other.fromParentMarked);
79
+ }
80
+ }
81
+ else
82
+ {
83
+ if (other.toParent == null)
84
+// assert(other.toParent == null);
85
+// new Exception().printStackTrace();
86
+ System.err.println("null parent: " + other);
87
+ }
88
+
89
+ /*
90
+ double ident[][] = LA.newMatrix();
91
+ if (bRep == null)
92
+ other.bRep = null;
93
+ else
94
+ other.bRep = new BoundaryRep(bRep, ident);
95
+ */
96
+ // Really new...
97
+ //other.editWindow = null;
98
+ if (name == null)
99
+ other.name = null;
100
+ else
101
+ other.name = new String(name);
102
+
103
+ if (material != null)
104
+ {
105
+ other.material = new cMaterial(material);
106
+ } else
107
+ {
108
+ other.material = null;
109
+ }
110
+
111
+ other.GetTextures().name = GetTextures().name;
112
+
113
+ CopyExtraMaterial(other);
114
+
115
+ other.touched = touched;
116
+ other.softtouched = softtouched;
117
+
118
+ other.random = random;
119
+ other.link2master = Link2Support();
120
+ other.transformcount = transformcount;
121
+ other.marked = marked;
122
+ other.skip = skip;
123
+ other.count = count;
124
+ other.flipV = flipV;
125
+ other.live = live;
126
+ other.rewind = rewind;
127
+ other.hide = hide;
128
+ other.texres = texres;
129
+ other.speedup = speedup;
130
+ other.height = height;
131
+ other.depth = depth;
132
+ }
133
+
134
+ int VersionCount()
135
+ {
136
+ int count = 0;
137
+
138
+ if (versionlist != null)
139
+ for (int i = versionlist.length; --i >= 0;)
140
+ {
141
+ if (versionlist[i] != null)
142
+ count++;
143
+ }
144
+
145
+ return count;
146
+ }
147
+
37148 void InitOthers()
38149 {
39150 if (projectedVertices == null || projectedVertices.length <= 2)
....@@ -45,6 +156,7 @@
45156 projectedVertices[i] = new cVector2(); // Others
46157 }
47158 projectedVertices[0].x = 100; // bump
159
+ projectedVertices[1].y = 1000; // punchthrough. only for png
48160 }
49161
50162 void MinMax(cVector minima, cVector maxima)
....@@ -124,7 +236,7 @@
124236 return;
125237
126238 transientsupport = support;
127
- transientlink2master = link2master;
239
+ transientlink2master = Link2Support();
128240
129241 support = null;
130242 link2master = false;
....@@ -171,9 +283,42 @@
171283 }
172284 }
173285
286
+ boolean HasBigData()
287
+ {
288
+ if (blockloop)
289
+ return false;
290
+
291
+ if (bRep != null)
292
+ {
293
+ return true;
294
+ }
295
+
296
+ blockloop = true;
297
+
298
+ for (int i = 0; i < Size(); i++)
299
+ {
300
+ Object3D child = (Object3D) get(i);
301
+ if (child == null)
302
+ continue;
303
+ if (child.HasBigData())
304
+ {
305
+ blockloop = false;
306
+ return true;
307
+ }
308
+ }
309
+
310
+ blockloop = false;
311
+ return false;
312
+ }
313
+
174314 void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
175315 {
316
+ if (blockloop)
317
+ return;
318
+
176319 Object3D o;
320
+
321
+ boolean isnew = false;
177322
178323 if (hashtable.containsKey(GetUUID()))
179324 {
....@@ -187,12 +332,14 @@
187332 }
188333 else
189334 {
335
+ isnew = true;
336
+
190337 o = new Object3D("copy of " + this.name);
191338
192339 hashtable.put(GetUUID(), o);
193340 }
194341
195
- if (!blockloop)
342
+ //if (!blockloop)
196343 {
197344 blockloop = true;
198345
....@@ -203,12 +350,15 @@
203350
204351 blockloop = false;
205352 }
206
-
207
- ExtractBigData(o);
353
+
354
+ //if (isnew)
355
+ ExtractBigData(o);
208356 }
209357
210358 void ExtractBigData(Object3D o)
211359 {
360
+ //System.err.println("ExtractBigData : " + this + " --> " + o);
361
+
212362 if (o.bRep != null)
213363 Grafreed.Assert(o.bRep == this.bRep);
214364
....@@ -219,8 +369,8 @@
219369 // o.bRep.support = null;
220370 // }
221371 o.selection = this.selection;
222
- o.versions = this.versions;
223
- o.versionindex = this.versionindex;
372
+ //o.versionlist = this.versionlist;
373
+ //o.versionindex = this.versionindex;
224374
225375 if (this.support != null)
226376 {
....@@ -243,17 +393,84 @@
243393 // this.fileparent = null;
244394 }
245395
396
+// Object3D GetObject(java.util.UUID uuid)
397
+// {
398
+// if (this.uuid.equals(uuid))
399
+// return this;
400
+//
401
+// if (blockloop)
402
+// return null;
403
+//
404
+// blockloop = true;
405
+//
406
+// for (int i=0; i<Size(); i++)
407
+// {
408
+// Object3D o = get(i).GetObject(uuid);
409
+//
410
+// if (o != null)
411
+// return o;
412
+// }
413
+//
414
+// blockloop = false;
415
+//
416
+// return null;
417
+// }
418
+
419
+ transient boolean tag;
420
+
421
+ void TagObjects(Object3D o, boolean tag)
422
+ {
423
+ if (blockloop)
424
+ return;
425
+
426
+ o.tag = tag;
427
+
428
+ if (o == this)
429
+ return;
430
+
431
+ blockloop = true;
432
+
433
+ for (int i=0; i<Size(); i++)
434
+ {
435
+ get(i).TagObjects(o, tag);
436
+ }
437
+
438
+ blockloop = false;
439
+ }
440
+
441
+ boolean HasTags()
442
+ {
443
+ if (blockloop)
444
+ return false;
445
+
446
+ blockloop = true;
447
+
448
+ boolean hasTags = false;
449
+
450
+ for (int i=0; i<Size(); i++)
451
+ {
452
+ hasTags |= get(i).tag || get(i).HasTags();
453
+
454
+ if (hasTags)
455
+ break;
456
+ }
457
+
458
+ blockloop = false;
459
+
460
+ return hasTags;
461
+ }
462
+
246463 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
247464 {
465
+ if (blockloop)
466
+ return;
467
+
248468 if (!hashtable.containsKey(GetUUID()))
249469 return;
250470
251471 Object3D o = hashtable.get(GetUUID());
252472
253473 RestoreBigData(o);
254
-
255
- if (blockloop)
256
- return;
257474
258475 blockloop = true;
259476
....@@ -269,6 +486,9 @@
269486
270487 void RestoreBigData(Object3D o)
271488 {
489
+ //System.err.println("RestoreBigData : " + this + " <-- " + o);
490
+ Grafreed.Assert(this.bRep == null);
491
+
272492 this.bRep = o.bRep;
273493 if (this.support != null && o.transientrep != null)
274494 {
....@@ -277,8 +497,8 @@
277497
278498 this.selection = o.selection;
279499
280
- this.versions = o.versions;
281
- this.versionindex = o.versionindex;
500
+ //this.versionlist = o.versionlist;
501
+ //this.versionindex = o.versionindex;
282502 // July 2019 if (this.bRep != null)
283503 // this.bRep.support = o.transientrep;
284504 // this.support = o.support;
....@@ -429,7 +649,10 @@
429649 transient boolean keepdontselect;
430650 boolean dontselect = false;
431651 boolean hide = false;
432
- boolean link2master = false; // performs reset support/master at each frame
652
+
653
+ boolean link2master = false; // performs reset support/master at each frame (cannot rename due to serialization)
654
+ boolean link2support = false; // (cannot rename due to serialization)
655
+
433656 boolean marked = false; // animation node
434657 boolean skip = false; // centroid issue
435658 boolean skipmocap = false; // mocap data
....@@ -437,6 +660,9 @@
437660 boolean random = false;
438661 boolean speedup = false;
439662 boolean rewind = false;
663
+
664
+ // Option to sort triangles, e.g. for transparency.
665
+ boolean sort = false;
440666
441667 float NORMALPUSH = 0;
442668
....@@ -447,27 +673,74 @@
447673 return this;
448674 }
449675
676
+ class SizeCompare implements Comparable
677
+ {
678
+ int size;
679
+ Object3D child;
680
+
681
+ SizeCompare(Object3D c)
682
+ {
683
+ child = c;
684
+ size = c.MemorySize();
685
+ }
686
+
687
+ public int compareTo(Object o)
688
+ {
689
+ SizeCompare comp = (SizeCompare) o;
690
+
691
+ return comp.size < size ? 1 : -1;
692
+ }
693
+ }
694
+
695
+ transient SizeCompare[] sizecompare = null;
696
+
450697 void SortBySize()
451698 {
452
- boolean sorted = false;
699
+// boolean sorted = false;
700
+//
701
+// while (!sorted)
702
+// {
703
+// sorted = true;
704
+//
705
+// for (int i=0; i<Size()-1; i++)
706
+// {
707
+// Object3D obji = get(i);
708
+// Object3D objj = get(i+1);
709
+//
710
+// if (obji.MemorySize() < objj.MemorySize())
711
+// {
712
+// set(i, objj);
713
+// set(i+1, obji);
714
+//
715
+// sorted = false;
716
+// }
717
+// }
718
+// }
719
+
720
+ int count = Size();
453721
454
- while (!sorted)
722
+ if (sizecompare == null || sizecompare.length != count)
455723 {
456
- sorted = true;
457
-
458
- for (int i=0; i<size()-1; i++)
724
+ sizecompare = new SizeCompare[count];
725
+
726
+ for (int k=0; k<count; k++)
459727 {
460
- Object3D obji = get(i);
461
- Object3D objj = get(i+1);
462
-
463
- if (obji.MemorySize() < objj.MemorySize())
464
- {
465
- set(i, objj);
466
- set(i+1, obji);
467
-
468
- sorted = false;
469
- }
728
+ sizecompare[k] = new SizeCompare(get(k));
470729 }
730
+ }
731
+ else
732
+ {
733
+ for (int k=0; k<count; k++)
734
+ {
735
+ sizecompare[k].size = get(k).MemorySize();
736
+ }
737
+ }
738
+
739
+ java.util.Arrays.sort(sizecompare);
740
+
741
+ for (int i=0; i<count; i++)
742
+ {
743
+ set(i, sizecompare[i].child);
471744 }
472745 }
473746
....@@ -479,7 +752,7 @@
479752 {
480753 sorted = true;
481754
482
- for (int i=0; i<size()-1; i++)
755
+ for (int i=0; i<Size()-1; i++)
483756 {
484757 Object3D obji = get(i);
485758 Object3D objj = get(i+1);
....@@ -495,38 +768,63 @@
495768 }
496769 }
497770
498
- int memorysize;
771
+ transient int memorysize; // needs to be transient, dunno why
499772
500773 int MemorySize()
501774 {
502
- if (true) // memorysize == 0)
775
+// if (memorysize == 0)
776
+// {
777
+// try
778
+// {
779
+// Object3D obj = this;
780
+//
781
+// Object3D parent = obj.parent;
782
+// obj.parent = null;
783
+// Object3D support = obj.support;
784
+// obj.support = null;
785
+//
786
+// java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
787
+// java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos);
788
+//
789
+// out.writeObject(obj);
790
+//
791
+// obj.parent = parent;
792
+// obj.support = support;
793
+//
794
+// memorysize = baos.toByteArray().length;
795
+// }
796
+// catch (Exception e)
797
+// {
798
+// e.printStackTrace();
799
+// }
800
+// }
801
+//
802
+// return memorysize;
803
+
804
+ if (blockloop)
503805 {
504
- try
505
- {
506
- Object3D obj = this;
806
+ return 0;
807
+ }
507808
508
- Object3D parent = obj.parent;
509
- obj.parent = null;
510
- Object3D support = obj.support;
511
- obj.support = null;
512
-
513
- java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
514
- java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos);
515
-
516
- out.writeObject(obj);
517
-
518
- obj.parent = parent;
519
- obj.support = support;
520
-
521
- memorysize = baos.toByteArray().length;
522
- }
523
- catch (Exception e)
524
- {
525
- e.printStackTrace();
526
- }
809
+ int memory = 0;
810
+
811
+ if (bRep != null)
812
+ {
813
+ memory = bRep.VertexCount();
527814 }
528815
529
- return memorysize;
816
+ blockloop = true;
817
+
818
+ for (int i = 0; i < Size(); i++)
819
+ {
820
+ Object3D obj = (Object3D) Children().get(i);
821
+
822
+ memory += obj.MemorySize();
823
+ }
824
+
825
+ blockloop = false;
826
+
827
+ return memory;
530828 }
531829
532830 void Slower()
....@@ -614,7 +912,7 @@
614912 {
615913 if (maxcount != 1)
616914 {
617
- new Exception().printStackTrace();
915
+ //new Exception().printStackTrace();
618916 }
619917
620918 toParentMarked = LA.newMatrix();
....@@ -816,7 +1114,7 @@
8161114
8171115 void Step()
8181116 {
819
- // marde pour serialization de Texture
1117
+ // patch pour serialization de Texture
8201118 resetmaxcount();
8211119 resettransformcount();
8221120 resetstep();
....@@ -851,7 +1149,7 @@
8511149 transformcount++;
8521150 }
8531151
854
- int maxcount;
1152
+ int maxcount = 128;
8551153 int transformcount;
8561154 int step;
8571155
....@@ -904,7 +1202,10 @@
9041202 if (step == 0)
9051203 step = 1;
9061204 if (maxcount == 0)
907
- maxcount = 128; // 2048; // 4;
1205
+ {
1206
+ System.out.println("maxcount == 0");
1207
+ System.exit(0); // maxcount = 128; // 2048; // 4;
1208
+ }
9081209 // if (acceleration == 0)
9091210 // acceleration = 10;
9101211 if (delay == 0) // serial
....@@ -930,6 +1231,8 @@
9301231 (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
9311232 currentframe != Globals.framecount)
9321233 {
1234
+ Globals.lighttouched = true;
1235
+
9331236 currentframe = Globals.framecount;
9341237
9351238 // System.err.println("transformcount = " + transformcount);
....@@ -1009,21 +1312,28 @@
10091312 {
10101313 // return true;
10111314
1012
- if (material == null || material.multiply)
1013
- return true;
1315
+// if (material == null || material.multiply)
1316
+// return true;
1317
+//
1318
+// if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1319
+// return false;
1320
+//
1321
+// // Transparent objects are dynamic because we have to sort the triangles.
1322
+// return material.opacity > 0.99;
10141323
1015
- // Transparent objects are dynamic because we have to sort the triangles.
1016
- return material.opacity > 0.99;
1324
+ return !sort;
10171325 }
10181326
10191327 boolean IsOpaque()
10201328 {
10211329 // return true;
10221330
1023
- if (material == null || material.multiply)
1024
- return true;
1331
+// if (material == null || material.multiply)
1332
+// return true;
1333
+//
1334
+// return material.opacity > 0.99;
10251335
1026
- return material.opacity > 0.99;
1336
+ return !sort;
10271337 }
10281338
10291339 Object3D()
....@@ -1101,8 +1411,10 @@
11011411
11021412 // will share the geometry
11031413 assert (!(this instanceof Composite));
1104
- return deepCopy(); // Never called for Composite
1105
-
1414
+
1415
+ Object3D obj = deepCopy(); // Never called for Composite
1416
+ obj.count = 2;
1417
+ return obj;
11061418 }
11071419
11081420 boolean HasLoops()
....@@ -1110,6 +1422,30 @@
11101422 return false;
11111423 }
11121424
1425
+ void ResetUUIDs()
1426
+ {
1427
+ if (blockloop)
1428
+ {
1429
+ return;
1430
+ }
1431
+
1432
+ this.uuid = null;
1433
+
1434
+ blockloop = true;
1435
+
1436
+ for (int i = 0; i < Size(); i++)
1437
+ {
1438
+ Object3D obj = (Object3D) Children().get(i);
1439
+
1440
+ if (obj != null)
1441
+ {
1442
+ obj.ResetUUIDs();
1443
+ }
1444
+ }
1445
+
1446
+ blockloop = false;
1447
+ }
1448
+
11131449 boolean IsInfinite()
11141450 {
11151451 if (blockloop)
....@@ -1180,78 +1516,16 @@
11801516 return;
11811517
11821518 blockloop = true;
1519
+
1520
+ // other.parent = parent;
1521
+
11831522 //System.out.println("COPY " + this + " to " + other);
11841523 //new Exception().printStackTrace();
1524
+ deepCopyNode(other);
11851525
1186
- other.parent = parent;
1187
- if (toParent != null)
1188
- {
1189
- other.toParent = LA.newMatrix();
1190
- other.fromParent = LA.newMatrix();
1191
- LA.matCopy(toParent, other.toParent);
1192
- LA.matCopy(fromParent, other.fromParent);
1193
- if (toParentMarked != null)
1194
- {
1195
- other.toParentMarked = LA.newMatrix();
1196
- other.fromParentMarked = LA.newMatrix();
1197
- LA.matCopy(toParentMarked, other.toParentMarked);
1198
- LA.matCopy(fromParentMarked, other.fromParentMarked);
1199
- }
1200
- }
1201
- else
1202
- {
1203
- if (other.toParent == null)
1204
-// assert(other.toParent == null);
1205
-// new Exception().printStackTrace();
1206
- System.err.println("null parent: " + other);
1207
- }
1208
- /*
1209
- double ident[][] = LA.newMatrix();
1210
- if (bRep == null)
1211
- other.bRep = null;
1212
- else
1213
- other.bRep = new BoundaryRep(bRep, ident);
1214
- */
1215
- // Really new...
12161526 other.bRep = bRep; // Share the geometry
12171527
12181528 other.support = support; // Share the support
1219
-
1220
- //other.editWindow = null;
1221
- if (name == null)
1222
- other.name = null;
1223
- else
1224
- other.name = new String(name);
1225
-
1226
- if (material != null)
1227
- {
1228
- other.material = new cMaterial(material);
1229
- } else
1230
- {
1231
- other.material = null;
1232
- }
1233
-
1234
- other.GetTextures().name = GetTextures().name;
1235
-
1236
- CopyExtraMaterial(other);
1237
-
1238
- other.touched = touched;
1239
- other.softtouched = softtouched;
1240
-
1241
- other.random = random;
1242
- other.link2master = link2master;
1243
- other.transformcount = transformcount;
1244
- other.marked = marked;
1245
- other.skip = skip;
1246
- other.count = count;
1247
- other.flipV = flipV;
1248
- other.live = live;
1249
- other.rewind = rewind;
1250
- other.hide = hide;
1251
- other.texres = texres;
1252
- other.speedup = speedup;
1253
- other.height = height;
1254
- other.depth = depth;
12551529
12561530 // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist)
12571531 // {
....@@ -1279,7 +1553,7 @@
12791553 Object3D obj = (Object3D)Children().get(i);
12801554 if (IsContainedIn(obj))
12811555 {
1282
-// assert(false); // ?!?!?!?!?!
1556
+ assert(false); // ?!?!?!?!?!
12831557 c.Children().setElementAt(c, i);
12841558 }
12851559 else
....@@ -1307,17 +1581,24 @@
13071581 if ((mask & GEOMETRY) != 0)
13081582 {
13091583 if (bRep != null)
1310
- bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
1311
- else
1312
- assert(other.bRep == null);
1313
-
1314
- if (bRep != null)
13151584 {
1585
+ bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
13161586 CameraPane.RemoveList(bRep.displaylist);
13171587 bRep.displaylist = 0; // june 2013 -1;
13181588 }
13191589 else
1320
- bRep = bRep;
1590
+ {
1591
+ //assert(other.bRep == null);
1592
+ bRep = other.bRep;
1593
+ }
1594
+
1595
+// if (bRep != null)
1596
+// {
1597
+// CameraPane.RemoveList(bRep.displaylist);
1598
+// bRep.displaylist = 0; // june 2013 -1;
1599
+// }
1600
+// else
1601
+// bRep = bRep;
13211602 }
13221603
13231604 /* Use a MASK = GEO/MAT
....@@ -2293,11 +2574,6 @@
22932574
22942575 InitOthers();
22952576
2296
- if (this instanceof Camera)
2297
- {
2298
- material.shift = 90;
2299
- }
2300
-
23012577 material.multiply = multiply;
23022578
23032579 if (multiply)
....@@ -2375,7 +2651,7 @@
23752651 return b;
23762652 }
23772653
2378
- void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate)
2654
+ void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate, boolean colorparallax)
23792655 {
23802656 if (blockloop)
23812657 {
....@@ -2385,7 +2661,7 @@
23852661 // super.UpdateMaterial(anchor, current, false);
23862662 if (material != null)
23872663 {
2388
- material.UpdateMaterial(anchor, current);
2664
+ material.UpdateMaterial(anchor, current, colorparallax);
23892665 }
23902666
23912667 if (!propagate)
....@@ -2399,7 +2675,7 @@
23992675 if (child == null)
24002676 continue;
24012677 blockloop = true;
2402
- child.UpdateMaterial(anchor, current, propagate);
2678
+ child.UpdateMaterial(anchor, current, propagate, false);
24032679 blockloop = false;
24042680 Children().release(i);
24052681 }
....@@ -2413,7 +2689,7 @@
24132689 if (child == null)
24142690 continue;
24152691 blockloop = true;
2416
- child.UpdateMaterial(anchor, current, propagate);
2692
+ child.UpdateMaterial(anchor, current, propagate, false);
24172693 blockloop = false;
24182694 Children().release(i);
24192695 }
....@@ -2438,6 +2714,11 @@
24382714 else
24392715 {
24402716 //((ObjEditor)editWindow).SetupUI2(null);
2717
+ if (objectUI != null)
2718
+ ((ObjEditor)objectUI).pinButton.setSelected(pinned);
2719
+ else
2720
+ //new Exception().printStackTrace();
2721
+ System.err.println("objectUI is null");
24412722 }
24422723 }
24432724
....@@ -2567,7 +2848,8 @@
25672848 private static final int editSelf = 1;
25682849 private static final int editChild = 2;
25692850
2570
- void drawEditHandles(ClickInfo info, int level)
2851
+ void drawEditHandles(//ClickInfo info,
2852
+ int level)
25712853 {
25722854 if (level == 0)
25732855 {
....@@ -2575,7 +2857,8 @@
25752857 return;
25762858
25772859 Object3D selectee;
2578
- for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(info, level + 1))
2860
+ for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(//info,
2861
+ level + 1))
25792862 {
25802863 selectee = (Object3D) e.nextElement();
25812864 }
....@@ -2583,19 +2866,22 @@
25832866 } else
25842867 {
25852868 //super.
2586
- drawEditHandles0(info, level + 1);
2869
+ drawEditHandles0(//info,
2870
+ level + 1);
25872871 }
25882872 }
25892873
2590
- boolean doEditClick(ClickInfo info, int level)
2874
+ boolean doEditClick(//ClickInfo info,
2875
+ int level)
25912876 {
25922877 doSomething = 0;
25932878 if (level == 0)
25942879 {
2595
- return doParentClick(info);
2880
+ return doParentClick(); //info);
25962881 }
25972882 if (//super.
2598
- doEditClick0(info, level))
2883
+ doEditClick0(//info,
2884
+ level))
25992885 {
26002886 doSomething = 1;
26012887 return true;
....@@ -2605,7 +2891,7 @@
26052891 }
26062892 }
26072893
2608
- boolean doParentClick(ClickInfo info)
2894
+ boolean doParentClick() //ClickInfo info)
26092895 {
26102896 if (selection == null)
26112897 {
....@@ -2618,7 +2904,8 @@
26182904 for (java.util.Enumeration e = selection.elements(); e.hasMoreElements();)
26192905 {
26202906 Object3D selectee = (Object3D) e.nextElement();
2621
- if (selectee.doEditClick(info, 1))
2907
+ if (selectee.doEditClick(//info,
2908
+ 1))
26222909 {
26232910 childToDrag = selectee;
26242911 doSomething = 2;
....@@ -2630,13 +2917,15 @@
26302917 return retval;
26312918 }
26322919
2633
- void doEditDrag(ClickInfo info, boolean opposite)
2920
+ void doEditDrag(//ClickInfo clickInfo,
2921
+ boolean opposite)
26342922 {
26352923 switch (doSomething)
26362924 {
26372925 case 1: // '\001'
26382926 //super.
2639
- doEditDrag0(info, opposite);
2927
+ doEditDrag0(//clickInfo,
2928
+ opposite);
26402929 break;
26412930
26422931 case 2: // '\002'
....@@ -2649,11 +2938,13 @@
26492938 {
26502939 //sel.hitSomething = childToDrag.hitSomething;
26512940 //childToDrag.doEditDrag(info);
2652
- sel.doEditDrag(info, opposite);
2941
+ sel.doEditDrag(//clickInfo,
2942
+ opposite);
26532943 } else
26542944 {
26552945 //super.
2656
- doEditDrag0(info, opposite);
2946
+ doEditDrag0(//clickInfo,
2947
+ opposite);
26572948 }
26582949 }
26592950 break;
....@@ -2671,6 +2962,9 @@
26712962 {
26722963 deselectAll();
26732964 }
2965
+
2966
+ new Exception().printStackTrace();
2967
+
26742968 ClickInfo newInfo = new ClickInfo();
26752969 newInfo.flags = info.flags;
26762970 newInfo.bounds = info.bounds;
....@@ -3100,7 +3394,10 @@
31003394 {
31013395 if (bRep != null)
31023396 {
3397
+ //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact).
31033398 bRep.GenerateNormals(crease);
3399
+ if (!bRep.trimmed)
3400
+ bRep.MergeNormals();
31043401 Touch();
31053402 }
31063403 }
....@@ -3175,6 +3472,105 @@
31753472 blockloop = false;
31763473 }
31773474
3475
+ public void ResetTransform(int mask)
3476
+ {
3477
+ Object3D obj = this;
3478
+
3479
+ if (mask == -1)
3480
+ {
3481
+ if (obj instanceof Camera) // jan 2014
3482
+ {
3483
+ LA.matIdentity(obj.toParent);
3484
+ LA.matIdentity(obj.fromParent);
3485
+ }
3486
+ else
3487
+ {
3488
+ obj.toParent = null; // jan 2014 LA.matIdentity(obj.toParent);
3489
+ obj.fromParent = null; // LA.matIdentity(obj.fromParent);
3490
+ }
3491
+ return;
3492
+ }
3493
+
3494
+ if ((mask&2) != 0) // Scale/rotation
3495
+ {
3496
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = 1;
3497
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3498
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3499
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1;
3500
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3501
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3502
+ }
3503
+ if ((mask&1) != 0) // Translation
3504
+ {
3505
+ if (obj.toParent != null)
3506
+ {
3507
+ obj.toParent[3][0] = obj.toParent[3][1] = obj.toParent[3][2] = 0;
3508
+ obj.fromParent[3][0] = obj.fromParent[3][1] = obj.fromParent[3][2] = 0;
3509
+ }
3510
+ }
3511
+ }
3512
+
3513
+ public void Scale(float scale)
3514
+ {
3515
+ Object3D obj = this;
3516
+
3517
+ obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = scale;
3518
+ obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
3519
+ obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0;
3520
+ obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1/scale;
3521
+ obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
3522
+ obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
3523
+ }
3524
+
3525
+ public void TextureRatioTransform(int axis)
3526
+ {
3527
+ cTexture tex = GetTextures();
3528
+
3529
+ com.sun.opengl.util.texture.TextureData texturedata = null;
3530
+
3531
+ try
3532
+ {
3533
+ texturedata = Globals.theRenderer.GetTextureData(tex, false, texres);
3534
+ }
3535
+ catch (Exception e)
3536
+ {
3537
+ System.err.println("FAIL TextureRatio: " + this);
3538
+ }
3539
+
3540
+ LA.matIdentity(Object3D.mat);
3541
+ Object3D.mat[axis][axis] = (double)texturedata.getWidth() / texturedata.getHeight();
3542
+
3543
+ if (toParent == null)
3544
+ {
3545
+ toParent = LA.newMatrix();
3546
+ fromParent = LA.newMatrix();
3547
+ }
3548
+
3549
+ ResetTransform(2);
3550
+
3551
+ LA.matConcat(Object3D.mat, fromParent, fromParent);
3552
+ LA.matInvert(fromParent, toParent);
3553
+ }
3554
+
3555
+ void TextureRatio(int axis)
3556
+ {
3557
+ if (blockloop)
3558
+ return;
3559
+
3560
+ blockloop = true;
3561
+
3562
+ TextureRatioTransform(axis);
3563
+
3564
+ for (int i=Size(); --i>=0;)
3565
+ {
3566
+ Object3D v = get(i);
3567
+
3568
+ v.TextureRatio(axis);
3569
+ }
3570
+
3571
+ blockloop = false;
3572
+ }
3573
+
31783574 void TransformChildren()
31793575 {
31803576 if (toParent != null)
....@@ -3417,6 +3813,7 @@
34173813 if (bRep != null)
34183814 {
34193815 //bRep.RemoveOneTriangle();
3816
+ System.out.println();
34203817 System.out.println("Reducing " + this);
34213818 if (name != null && name.contains("lockpickstraps"))
34223819 name = name;
....@@ -3528,15 +3925,47 @@
35283925
35293926 void ClearMaterials()
35303927 {
3928
+ if (blockloop)
3929
+ return;
3930
+
3931
+ blockloop = true;
3932
+
35313933 ClearMaterial();
3532
- for (int i = 0; i < size(); i++)
3934
+ for (int i = 0; i < Size(); i++)
35333935 {
3534
- Object3D child = (Object3D) reserve(i);
3936
+ Object3D child = (Object3D) get(i);
35353937 if (child == null)
35363938 continue;
35373939 child.ClearMaterials();
3538
- release(i);
35393940 }
3941
+
3942
+ blockloop = false;
3943
+ }
3944
+
3945
+ void ClearVersionList()
3946
+ {
3947
+ this.versionlist = null;
3948
+ this.versionindex = -1;
3949
+ this.versiontable = null;
3950
+ }
3951
+
3952
+ void ClearVersions()
3953
+ {
3954
+ if (blockloop)
3955
+ return;
3956
+
3957
+ blockloop = true;
3958
+
3959
+ ClearVersionList();
3960
+ for (int i = 0; i < Size(); i++)
3961
+ {
3962
+ Object3D child = (Object3D) get(i);
3963
+ if (child == null)
3964
+ continue;
3965
+ child.ClearVersions();
3966
+ }
3967
+
3968
+ blockloop = false;
35403969 }
35413970
35423971 void FlipV(boolean flip)
....@@ -3715,6 +4144,7 @@
37154144
37164145 void RevertMeshes()
37174146 {
4147
+ // BLOCKLOOP
37184148 if (this instanceof cMesh)
37194149 {
37204150 ((cMesh)this).Revert();
....@@ -3745,11 +4175,6 @@
37454175 Touch();
37464176 }
37474177
3748
- ResetRecur();
3749
- }
3750
-
3751
- void ResetRecur()
3752
- {
37534178 for (int i = 0; i < size(); i++)
37544179 {
37554180 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3772,11 +4197,6 @@
37724197 Step();
37734198 Touch();
37744199
3775
- StepRecur();
3776
- }
3777
-
3778
- void StepRecur()
3779
- {
37804200 for (int i = 0; i < size(); i++)
37814201 {
37824202 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3963,8 +4383,8 @@
39634383 Touch();
39644384 }
39654385
3966
- transient cVector min = new cVector();
3967
- transient cVector max = new cVector();
4386
+ transient cVector min;
4387
+ transient cVector max;
39684388
39694389 void getBounds(cVector minima, cVector maxima, boolean xform)
39704390 {
....@@ -3980,15 +4400,15 @@
39804400 if (blockloop)
39814401 return;
39824402
3983
- if (min == null) // ???
4403
+ if (min == null)
39844404 {
39854405 min = new cVector();
39864406 max = new cVector();
39874407 }
39884408
3989
- for (int i = 0; i<size(); i++)
4409
+ for (int i = 0; i<Size(); i++)
39904410 {
3991
- Object3D child = (Object3D) reserve(i);
4411
+ Object3D child = (Object3D) get(i); //reserve(i);
39924412 if (child == null)
39934413 continue;
39944414
....@@ -4007,21 +4427,21 @@
40074427 if (child.hide && !(child instanceof Merge) || child.skip)
40084428 //if (child.hide)
40094429 {
4010
- release(i);
4430
+ //release(i);
40114431 continue;
40124432 }
40134433
40144434 blockloop = true;
40154435 child.getBounds(min, max, true); // xform);
40164436 blockloop = false;
4017
- release(i);
4437
+ //release(i);
40184438
40194439 MinMax(minima, maxima);
40204440 }
40214441
40224442 if (bRep != null)
40234443 {
4024
- bRep.getBounds(minima,maxima,this);
4444
+ bRep.getBounds(minima, maxima, xform?this:null);
40254445 }
40264446
40274447 if (false) // xform)
....@@ -5294,8 +5714,9 @@
52945714 {
52955715 }
52965716 // transient int displaylist = 0; // -1;
5297
- transient boolean touched = true;
5298
- transient boolean softtouched = true;
5717
+ transient boolean reset = false; // Recalculate
5718
+ transient boolean touched = true; // call list only
5719
+ transient boolean softtouched = true; // aucune idee
52995720
53005721 void Touch()
53015722 {
....@@ -5348,6 +5769,7 @@
53485769 {
53495770 //System.out.println("HardTouch " + this); // new Exception().printStackTrace();
53505771 //new Exception().printStackTrace();
5772
+ reset = true;
53515773 touched = true;
53525774 CameraPane.touched = true;
53535775 //if (parent != null)
....@@ -5526,6 +5948,11 @@
55265948 if (fullname == null)
55275949 return "";
55285950
5951
+ if (fullname.pigment != null)
5952
+ {
5953
+ return fullname.pigment;
5954
+ }
5955
+
55295956 // System.out.println("Fullname = " + fullname);
55305957
55315958 // Does not work on Windows due to C:
....@@ -5538,7 +5965,7 @@
55385965
55395966 if (split.length == 0)
55405967 {
5541
- return "";
5968
+ return fullname.pigment = "";
55425969 }
55435970
55445971 if (split.length <= 2)
....@@ -5546,22 +5973,27 @@
55465973 if (fullname.name.endsWith(":"))
55475974 {
55485975 // Windows
5549
- return fullname.name.substring(0, fullname.name.length()-1);
5976
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
55505977 }
55515978
5552
- return split[0];
5979
+ return fullname.pigment = split[0];
55535980 }
55545981
55555982 // Windows
55565983 assert(split.length == 4);
55575984
5558
- return split[0] + ":" + split[1];
5985
+ return fullname.pigment = split[0] + ":" + split[1];
55595986 }
55605987
55615988 static String GetBump(cTexture fullname)
55625989 {
55635990 if (fullname == null)
55645991 return "";
5992
+
5993
+ if (fullname.bump != null)
5994
+ {
5995
+ return fullname.bump;
5996
+ }
55655997
55665998 // System.out.println("Fullname = " + fullname);
55675999 // Does not work on Windows due to C:
....@@ -5573,12 +6005,12 @@
55736005
55746006 if (split.length == 0)
55756007 {
5576
- return "";
6008
+ return fullname.bump = "";
55776009 }
55786010
55796011 if (split.length == 1)
55806012 {
5581
- return "";
6013
+ return fullname.bump = "";
55826014 }
55836015
55846016 if (split.length == 2)
....@@ -5586,16 +6018,16 @@
55866018 if (fullname.name.endsWith(":"))
55876019 {
55886020 // Windows
5589
- return "";
6021
+ return fullname.bump = "";
55906022 }
55916023
5592
- return split[1];
6024
+ return fullname.bump = split[1];
55936025 }
55946026
55956027 // Windows
55966028 assert(split.length == 4);
55976029
5598
- return split[2] + ":" + split[3];
6030
+ return fullname.bump = split[2] + ":" + split[3];
55996031 }
56006032
56016033 String GetPigmentTexture()
....@@ -5678,6 +6110,9 @@
56786110 texname = "";
56796111
56806112 GetTextures().name = texname + ":" + GetBump(GetTextures());
6113
+
6114
+ GetTextures().pigment = null;
6115
+
56816116 Touch();
56826117 }
56836118
....@@ -5751,6 +6186,8 @@
57516186
57526187 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
57536188
6189
+ GetTextures().bump = null;
6190
+
57546191 Touch();
57556192 }
57566193
....@@ -5815,7 +6252,7 @@
58156252 boolean NeedSupport()
58166253 {
58176254 return
5818
- CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
6255
+ CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && Link2Support() && /*live &&*/ support != null
58196256 // PROBLEM with CROWD!!
58206257 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
58216258 }
....@@ -5833,6 +6270,22 @@
58336270 return parent.IsLive();
58346271 }
58356272
6273
+ boolean IsDynamic()
6274
+ {
6275
+ return live && bRep != null;
6276
+ }
6277
+
6278
+ boolean Link2Support()
6279
+ {
6280
+ return link2master || link2support;
6281
+ }
6282
+
6283
+ static cVector minima = new cVector();
6284
+ static cVector maxima = new cVector();
6285
+ static javax.vecmath.Point3d center = new javax.vecmath.Point3d();
6286
+
6287
+ boolean compiling;
6288
+
58366289 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58376290 {
58386291 Invariants(); // june 2013
....@@ -5840,6 +6293,29 @@
58406293 if (support != null)
58416294 {
58426295 // System.err.println("Draw " + this + " Frame # " + ((Mocap)((Merge)support).object).frame);
6296
+ }
6297
+
6298
+ if (false) // live && Link2Support() && support == null && !this.marked) // project on ground
6299
+ {
6300
+ getBounds(minima, maxima, true);
6301
+ center.x = (minima.x + maxima.x) / 2;
6302
+ center.y = 10000; // (minima.y + maxima.y) / 2;
6303
+ center.z = (minima.z + maxima.z) / 2;
6304
+
6305
+ Ray ray = new Ray(center, new Vector3d(0,-1,0));
6306
+
6307
+ IntersectResult res = new IntersectResult();
6308
+ res.t = Double.POSITIVE_INFINITY;
6309
+
6310
+ if (Grafreed.grafreed.universe.intersect(ray, res))
6311
+ {
6312
+ double resx = ray.eyePoint.x + ray.viewDirection.x * res.t;
6313
+ double resy = ray.eyePoint.y + ray.viewDirection.y * res.t;
6314
+ double resz = ray.eyePoint.z + ray.viewDirection.z * res.t;
6315
+
6316
+ LA.matTranslate(toParent, 0, resy - minima.y, 0);
6317
+ LA.matInvert(toParent, fromParent);
6318
+ }
58436319 }
58446320
58456321 if (display.DrawMode() == iCameraPane.SELECTION &&
....@@ -5893,8 +6369,12 @@
58936369 if (support != null)
58946370 support = support;
58956371
5896
- //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5897
- boolean usecalllists = !IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6372
+ boolean usecalllists = !IsDynamic() &&
6373
+ IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6374
+
6375
+ //usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
6376
+
6377
+ //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
58986378
58996379 if (!usecalllists && bRep != null && bRep.displaylist > 0)
59006380 {
....@@ -5902,10 +6382,12 @@
59026382 bRep.displaylist = 0;
59036383 }
59046384 // usecalllists &= !(parent instanceof RandomNode);
5905
- // usecalllists = false;
6385
+ if (CameraPane.BOXMODE) // Too dynamic
6386
+ usecalllists = false;
59066387
5907
- if (GetBRep() != null)
5908
- usecalllists = usecalllists;
6388
+ if (display.DrawMode() == display.SHADOW)
6389
+ //GetBRep() != null)
6390
+ usecalllists = !!usecalllists;
59096391 //System.out.println("draw " + this);
59106392 //new Exception().printStackTrace();
59116393
....@@ -5915,7 +6397,7 @@
59156397
59166398 if (!selectmode && //display.DrawMode() != display.SELECTION &&
59176399 //(touched || (bRep != null && bRep.displaylist <= 0)))
5918
- (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
6400
+ ((Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE) || touched)) // || (bRep != null && bRep.displaylist <= 0)))
59196401 {
59206402 Globals.lighttouched = true;
59216403 } // all panes...
....@@ -5927,7 +6409,7 @@
59276409 if (!(this instanceof Composite))
59286410 touched = false;
59296411 //if (displaylist == -1 && usecalllists)
5930
- if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
6412
+ if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013
59316413 {
59326414 bRep.displaylist = display.GenList();
59336415 assert(bRep.displaylist != 0);
....@@ -5938,16 +6420,18 @@
59386420
59396421 //System.out.println("\tnew list " + list);
59406422 //gl.glDrawBuffer(gl.GL_NONE);
5941
- if (usecalllists)
6423
+ if (usecalllists && bRep.displaylist > 0)
59426424 {
59436425 // System.err.println("new list " + bRep.displaylist + " for " + this);
59446426 display.NewList(bRep.displaylist);
59456427 }
59466428
6429
+ compiling = true;
59476430 CallList(display, root, selected, blocked);
6431
+ compiling = false;
59486432
59496433 // compiled = true;
5950
- if (usecalllists)
6434
+ if (usecalllists && bRep.displaylist > 0)
59516435 {
59526436 // System.err.println("end list " + bRep.displaylist + " for " + this);
59536437 display.EndList();
....@@ -5957,8 +6441,8 @@
59576441 Globals.lighttouched = true; // all panes...
59586442 }
59596443
5960
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
5961
- //touched = false;
6444
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6445
+ touched = false;
59626446
59636447 if (this instanceof Texture || this instanceof TextureNode)
59646448 {
....@@ -5997,7 +6481,7 @@
59976481 {
59986482 if (display.DrawMode() == iCameraPane.SHADOW)
59996483 {
6000
- if (!link2master // tricky to cull in shadow mode.
6484
+ if (!Link2Support() // tricky to cull in shadow mode.
60016485 && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
60026486 {
60036487 //System.out.print("CULLED");
....@@ -6059,6 +6543,20 @@
60596543 {
60606544 drawSelf(display, root, selected, blocked);
60616545 }
6546
+
6547
+// if (!(this instanceof Composite))
6548
+// {
6549
+// for (int i = 0; i < size(); i++)
6550
+// {
6551
+// Object3D child = (Object3D) reserve(i);
6552
+// if (child == null)
6553
+// continue;
6554
+//
6555
+// child.draw(display, root, selected, blocked);
6556
+//
6557
+// release(i);
6558
+// }
6559
+// }
60626560 } else
60636561 {
60646562 /*
....@@ -6091,13 +6589,14 @@
60916589 boolean failedPigment = false;
60926590 boolean failedBump = false;
60936591
6592
+ CameraPane.lastObject = this;
60946593 try
60956594 {
60966595 display.BindPigmentTexture(tex, texres);
60976596 }
60986597 catch (Exception e)
60996598 {
6100
- System.err.println("FAILED: " + this);
6599
+ // System.err.println("FAILED: " + this);
61016600 failedPigment = true;
61026601 }
61036602
....@@ -6128,6 +6627,20 @@
61286627 display.CallList(bRep.displaylist);
61296628 // june 2013 drawSelf(display, root, selected);
61306629 }
6630
+ }
6631
+
6632
+ // Bezier surface: assert (!(this instanceof Composite));
6633
+ {
6634
+// CRASH MOCAP!! for (int i = 0; i < size(); i++)
6635
+// {
6636
+// Object3D child = (Object3D) reserve(i);
6637
+// if (child == null)
6638
+// continue;
6639
+//
6640
+// child.draw(display, root, selected, blocked);
6641
+//
6642
+// release(i);
6643
+// }
61316644 }
61326645 }
61336646
....@@ -6181,16 +6694,17 @@
61816694
61826695 void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
61836696 {
6184
- if (GetBRep() == null)
6185
- {
6186
- drawSelf(display, root, selected, blocked);
6187
- } else
6697
+ if (GetBRep() != null)
61886698 {
61896699 DrawNode(display, root, selected);
61906700 if (this instanceof BezierPatch)
61916701 {
61926702 //drawSelf(display, root, selected);
61936703 }
6704
+ }
6705
+ else
6706
+ {
6707
+ drawSelf(display, root, selected, blocked);
61946708 }
61956709 }
61966710
....@@ -6389,15 +6903,18 @@
63896903
63906904 void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
63916905 {
6392
- if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6393
- return; // no shadow for transparent objects
6394
-
6395
- if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6396
- return;
6906
+ if (!compiling)
6907
+ {
6908
+ if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6909
+ return; // no shadow for transparent objects
6910
+
6911
+ if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6912
+ return;
6913
+ }
63976914
63986915 if (hide)
63996916 return;
6400
-
6917
+
64016918 if (scriptnode != null)
64026919 {
64036920 scriptnode.DrawNode(display, root, selected);
....@@ -6440,7 +6957,8 @@
64406957
64416958 //javax.media.opengl.GL gl = display.GetGL();
64426959
6443
- if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
6960
+ if (CameraPane.BOXMODE && !Link2Support()) //
6961
+ //!selected) // || CameraPane.movingcamera)
64446962 {
64456963 int fc = bRep.FaceCount();
64466964 int vc = bRep.VertexCount();
....@@ -6602,7 +7120,7 @@
66027120 facescompare[k] = new FaceCompare(k);
66037121 }
66047122
6605
- center = new cVector();
7123
+ centertriangle = new cVector();
66067124 }
66077125 else
66087126 {
....@@ -6725,7 +7243,7 @@
67257243 */
67267244 }
67277245
6728
- transient cVector center;
7246
+ transient cVector centertriangle;
67297247
67307248 class FaceCompare implements Comparable
67317249 {
....@@ -6754,14 +7272,14 @@
67547272 Vertex q = bRep.GetVertex(face.q);
67557273 Vertex r = bRep.GetVertex(face.r);
67567274
6757
- center.set(p);
6758
- center.add(q);
6759
- center.add(r);
6760
- center.mul(1.0/3);
7275
+ centertriangle.set(p);
7276
+ centertriangle.add(q);
7277
+ centertriangle.add(r);
7278
+ centertriangle.mul(1.0/3);
67617279
6762
- center.sub(Globals.theRenderer.EyeCamera().location);
7280
+ centertriangle.sub(Globals.theRenderer.EyeCamera().location);
67637281
6764
- distance = center.dot(center);
7282
+ distance = centertriangle.dot(centertriangle);
67657283 }
67667284
67677285 return distance;
....@@ -7298,20 +7816,23 @@
72987816 }
72997817 }
73007818
7301
- protected void calcHotSpot(cVector in, ClickInfo info, Point outPt, Rectangle outRec)
7819
+ static ClickInfo clickInfo = new ClickInfo();
7820
+
7821
+ protected void calcHotSpot(cVector in, //ClickInfo clickInfo,
7822
+ Point outPt, Rectangle outRec)
73027823 {
7303
- int hc = info.bounds.x + info.bounds.width / 2;
7304
- int vc = info.bounds.y + info.bounds.height / 2;
7305
- double[][] toscreen = info.toScreen;
7824
+ int hc = clickInfo.bounds.x + clickInfo.bounds.width / 2;
7825
+ int vc = clickInfo.bounds.y + clickInfo.bounds.height / 2;
7826
+ double[][] toscreen = clickInfo.toScreen;
73067827 if (toscreen == null)
73077828 {
7308
- toscreen = new Camera(info.camera.viewCode).toScreen;
7829
+ toscreen = new Camera(clickInfo.camera.viewCode).toScreen;
73097830 }
73107831 cVector vec = in;
73117832 LA.xformPos(in, toscreen, in);
73127833 //System.out.println("Distance = " + info.camera.Distance());
7313
- vec.x *= 100 * info.camera.SCALE / info.camera.Distance();
7314
- vec.y *= 100 * info.camera.SCALE / info.camera.Distance();
7834
+ vec.x *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
7835
+ vec.y *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
73157836 outPt.x = hc + (int) vec.x;
73167837 outPt.y = vc - (int) vec.y;
73177838 outRec.x = outPt.x - 3;
....@@ -7319,15 +7840,18 @@
73197840 outRec.width = outRec.height = 6;
73207841 }
73217842
7322
- protected Rectangle calcHotSpot(cVector in, ClickInfo info)
7843
+ protected Rectangle calcHotSpot(cVector in//, ClickInfo clickInfo
7844
+ )
73237845 {
73247846 Point pt = new Point(0, 0);
73257847 Rectangle rec = new Rectangle();
7326
- calcHotSpot(in, info, pt, rec);
7848
+ calcHotSpot(in, //clickInfo,
7849
+ pt, rec);
73277850 return rec;
73287851 }
73297852
7330
- void drawEditHandles0(ClickInfo info, int level)
7853
+ void drawEditHandles0(//ClickInfo clickInfo,
7854
+ int level)
73317855 {
73327856 if (level == 0)
73337857 {
....@@ -7336,16 +7860,19 @@
73367860 {
73377861 cVector origin = new cVector();
73387862 //LA.xformPos(origin, toParent, origin);
7339
- Rectangle spot = calcHotSpot(origin, info);
7863
+ if (this.clickInfo == null)
7864
+ this.clickInfo = new ClickInfo();
7865
+
7866
+ Rectangle spot = calcHotSpot(origin); //, clickInfo);
73407867 Rectangle boundary = new Rectangle();
73417868 boundary.x = spot.x - 30;
73427869 boundary.y = spot.y - 30;
73437870 boundary.width = spot.width + 60;
73447871 boundary.height = spot.height + 60;
7345
- info.g.setColor(Color.red);
7872
+ clickInfo.g.setColor(Color.white);
73467873 int spotw = spot.x + spot.width;
73477874 int spoth = spot.y + spot.height;
7348
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7875
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
73497876 // if (CameraPane.Xmin > spot.x)
73507877 // {
73517878 // CameraPane.Xmin = spot.x;
....@@ -7362,11 +7889,6 @@
73627889 // {
73637890 // CameraPane.Ymax = spoth;
73647891 // }
7365
- spot.translate(32, 32);
7366
- spotw = spot.x + spot.width;
7367
- spoth = spot.y + spot.height;
7368
- info.g.setColor(Color.cyan);
7369
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
73707892 // if (CameraPane.Xmin > spot.x)
73717893 // {
73727894 // CameraPane.Xmin = spot.x;
....@@ -7385,10 +7907,15 @@
73857907 // }
73867908 // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
73877909 //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7388
- spot.translate(0, -32);
7389
- info.g.setColor(Color.yellow);
7390
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7391
- info.g.setColor(Color.green);
7910
+ spot.translate(32, 0);
7911
+ clickInfo.g.setColor(Color.yellow);
7912
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7913
+
7914
+ spot.translate(32, 64);
7915
+ spotw = spot.x + spot.width;
7916
+ spoth = spot.y + spot.height;
7917
+ clickInfo.g.setColor(Color.cyan);
7918
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
73927919 // if (CameraPane.Xmin > spot.x)
73937920 // {
73947921 // CameraPane.Xmin = spot.x;
....@@ -7405,8 +7932,9 @@
74057932 // {
74067933 // CameraPane.Ymax = spoth;
74077934 // }
7408
- info.g.drawArc(boundary.x + info.DX, boundary.y + info.DY,
7409
- (int)(boundary.width * info.W), (int)(boundary.height * info.W), 0, 360);
7935
+ clickInfo.g.setColor(Color.green);
7936
+ clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY,
7937
+ (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360);
74107938 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
74117939 // if (CameraPane.Xmin > boundary.x)
74127940 // {
....@@ -7428,7 +7956,8 @@
74287956 }
74297957 }
74307958
7431
- boolean doEditClick0(ClickInfo info, int level)
7959
+ boolean doEditClick0(//ClickInfo clickInfo,
7960
+ int level)
74327961 {
74337962 if (level == 0)
74347963 {
....@@ -7437,8 +7966,8 @@
74377966
74387967 boolean retval = false;
74397968
7440
- startX = info.x;
7441
- startY = info.y;
7969
+ startX = clickInfo.x;
7970
+ startY = clickInfo.y;
74427971
74437972 hitSomething = -1;
74447973 cVector origin = new cVector();
....@@ -7448,22 +7977,53 @@
74487977 {
74497978 centerPt = new Point(0, 0);
74507979 }
7451
- calcHotSpot(origin, info, centerPt, spot);
7452
- if (spot.contains(info.x, info.y))
7980
+ calcHotSpot(origin, //info,
7981
+ centerPt, spot);
7982
+ if (spot.contains(clickInfo.x, clickInfo.y))
74537983 {
74547984 hitSomething = hitCenter;
74557985 retval = true;
74567986 }
74577987 spot.translate(32, 0);
7458
- if (spot.contains(info.x, info.y))
7988
+ if (spot.contains(clickInfo.x, clickInfo.y))
74597989 {
74607990 hitSomething = hitRotate;
74617991 retval = true;
74627992 }
74637993 spot.translate(0, 32);
7464
- if (spot.contains(info.x, info.y))
7994
+ spot.translate(32, 0);
7995
+ spot.translate(0, 32);
7996
+ if (spot.contains(clickInfo.x, clickInfo.y))
74657997 {
74667998 hitSomething = hitScale;
7999
+
8000
+ double scale = 0.005f * clickInfo.camera.Distance();
8001
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
8002
+ double sign = 1;
8003
+ if (hScale < 0)
8004
+ {
8005
+ sign = -1;
8006
+ }
8007
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
8008
+ if (hScale < 0.01)
8009
+ {
8010
+ //hScale = 0.01;
8011
+ }
8012
+
8013
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
8014
+ sign = 1;
8015
+ if (vScale < 0)
8016
+ {
8017
+ sign = -1;
8018
+ }
8019
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
8020
+ if (vScale < 0.01)
8021
+ {
8022
+ //vScale = 0.01;
8023
+ }
8024
+
8025
+ clickInfo.scale = Math.sqrt(hScale*hScale + vScale*vScale);
8026
+
74678027 retval = true;
74688028 }
74698029
....@@ -7473,7 +8033,7 @@
74738033 }
74748034
74758035 //System.out.println("info.modifiers = " + info.modifiers);
7476
- modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
8036
+ modified = (clickInfo.modifiers & CameraPane.SHIFT) != 0; // Was META
74778037 //System.out.println("modified = " + modified);
74788038 //new Exception().printStackTrace();
74798039 //viewCode = info.pane.renderCamera.viewCode;
....@@ -7501,7 +8061,8 @@
75018061 return true;
75028062 }
75038063
7504
- void doEditDrag0(ClickInfo info, boolean opposite)
8064
+ void doEditDrag0(//ClickInfo info,
8065
+ boolean opposite)
75058066 {
75068067 if (hitSomething == 0)
75078068 {
....@@ -7515,7 +8076,7 @@
75158076
75168077 //System.out.println("hitSomething = " + hitSomething);
75178078
7518
- double scale = 0.005f * info.camera.Distance();
8079
+ double scale = 0.005f * clickInfo.camera.Distance();
75198080
75208081 cVector xlate = new cVector();
75218082 //cVector xlate2 = new cVector();
....@@ -7529,7 +8090,9 @@
75298090
75308091 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
75318092
7532
- if (modified || opposite)
8093
+ // Modified could snap
8094
+ if (//modified ||
8095
+ opposite)
75338096 {
75348097 //assert(false);
75358098 /*
....@@ -7549,8 +8112,8 @@
75498112 toParent[3][i] = xlate.get(i);
75508113 LA.matInvert(toParent, fromParent);
75518114 */
7552
- cVector delta = LA.newVector(0, 0, startY - info.y);
7553
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
8115
+ cVector delta = LA.newVector(0, 0, startY - clickInfo.y);
8116
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
75548117
75558118 LA.matCopy(startMat, toParent);
75568119 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7559,7 +8122,7 @@
75598122 } else
75608123 {
75618124 //LA.xformDir(delta, info.camera.fromScreen, delta);
7562
- cVector up = new cVector(info.camera.up);
8125
+ cVector up = new cVector(clickInfo.camera.up);
75638126 cVector away = new cVector();
75648127 //cVector right2 = new cVector();
75658128 //LA.vecCross(up, cVector.Z, right);
....@@ -7576,19 +8139,19 @@
75768139 LA.xformDir(up, ClickInfo.matbuffer, up);
75778140 // if (!CameraPane.LOCALTRANSFORM)
75788141 LA.xformDir(up, Globals.theRenderer.RenderCamera().toScreen, up);
7579
- LA.xformDir(info.camera.away, ClickInfo.matbuffer, away);
8142
+ LA.xformDir(clickInfo.camera.away, ClickInfo.matbuffer, away);
75808143 // if (!CameraPane.LOCALTRANSFORM)
75818144 LA.xformDir(away, Globals.theRenderer.RenderCamera().toScreen, away);
75828145 //LA.vecCross(up, cVector.Z, right2);
75838146
7584
- cVector delta = LA.newVector(info.x - startX, startY - info.y, 0);
8147
+ cVector delta = LA.newVector(clickInfo.x - startX, startY - clickInfo.y, 0);
75858148
75868149 //System.out.println("DELTA0 = " + delta);
75878150 //System.out.println("AWAY = " + info.camera.away);
75888151 //System.out.println("UP = " + info.camera.up);
75898152 if (away.z > 0)
75908153 {
7591
- if (info.camera.up.x == 0) // LA.vecDot(right, right2)<0)
8154
+ if (clickInfo.camera.up.x == 0) // LA.vecDot(right, right2)<0)
75928155 {
75938156 delta.x = -delta.x;
75948157 } else
....@@ -7603,7 +8166,7 @@
76038166 //System.out.println("DELTA1 = " + delta);
76048167 LA.xformDir(delta, ClickInfo.matbuffer, delta);
76058168 //System.out.println("DELTA2 = " + delta);
7606
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
8169
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
76078170 LA.matCopy(startMat, toParent);
76088171 //System.out.println("DELTA3 = " + delta);
76098172 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7613,8 +8176,8 @@
76138176 break;
76148177
76158178 case hitRotate: // rotate
7616
- int dx = info.x - centerPt.x;
7617
- int dy = -(info.y - centerPt.y);
8179
+ int dx = clickInfo.x - centerPt.x;
8180
+ int dy = -(clickInfo.y - centerPt.y);
76188181 double angle = (double) Math.atan2(dx, dy);
76198182 angle = -(1.570796 - angle);
76208183
....@@ -7623,7 +8186,7 @@
76238186
76248187 if (modified)
76258188 {
7626
- // Rotate 90 degrees
8189
+ // Rotate 45 degrees
76278190 angle /= (Math.PI / 4);
76288191 angle = Math.floor(angle + 0.5);
76298192 angle *= (Math.PI / 4);
....@@ -7637,7 +8200,7 @@
76378200 }
76388201 /**/
76398202
7640
- switch (info.pane.RenderCamera().viewCode)
8203
+ switch (clickInfo.pane.RenderCamera().viewCode)
76418204 {
76428205 case 1: // '\001'
76438206 LA.matZRotate(toParent, angle);
....@@ -7664,7 +8227,7 @@
76648227 break;
76658228
76668229 case hitScale: // scale
7667
- double hScale = (double) (info.x - centerPt.x) / 32;
8230
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
76688231 double sign = 1;
76698232 if (hScale < 0)
76708233 {
....@@ -7676,7 +8239,7 @@
76768239 //hScale = 0.01;
76778240 }
76788241
7679
- double vScale = (double) (info.y - centerPt.y) / 32;
8242
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
76808243 sign = 1;
76818244 if (vScale < 0)
76828245 {
....@@ -7687,6 +8250,7 @@
76878250 {
76888251 //vScale = 0.01;
76898252 }
8253
+
76908254 LA.matCopy(startMat, toParent);
76918255 /**/
76928256 for (int i = 0; i < 3; i++)
....@@ -7696,33 +8260,39 @@
76968260 }
76978261 /**/
76988262
7699
- double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
8263
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / clickInfo.scale;
77008264
77018265 if (totalScale < 0.01)
77028266 {
77038267 totalScale = 0.01;
77048268 }
77058269
7706
- switch (info.pane.RenderCamera().viewCode)
8270
+ switch (clickInfo.pane.RenderCamera().viewCode)
77078271 {
77088272 case 3: // '\001'
77098273 if (modified || opposite)
77108274 {
8275
+ if (modified) // && opposite)
8276
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8277
+ else
77118278 //LA.matScale(toParent, 1, hScale, vScale);
7712
- LA.matScale(toParent, totalScale, 1, 1);
8279
+ LA.matScale(toParent, totalScale, 1, 1);
77138280 } // vScale, 1);
77148281 else
77158282 {
77168283 // EXCEPTION!
7717
- LA.matScale(toParent, totalScale, totalScale, totalScale);
8284
+ LA.matScale(toParent, 1, totalScale, totalScale);
77188285 } // vScale, 1);
77198286 break;
77208287
77218288 case 2: // '\002'
77228289 if (modified || opposite)
77238290 {
7724
- //LA.matScale(toParent, hScale, 1, vScale);
7725
- LA.matScale(toParent, 1, totalScale, 1);
8291
+ if (modified) // && opposite)
8292
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8293
+ else
8294
+ //LA.matScale(toParent, hScale, 1, vScale);
8295
+ LA.matScale(toParent, 1, totalScale, 1);
77268296 } else
77278297 {
77288298 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7732,8 +8302,11 @@
77328302 case 1: // '\003'
77338303 if (modified || opposite)
77348304 {
7735
- //LA.matScale(toParent, hScale, vScale, 1);
7736
- LA.matScale(toParent, 1, 1, totalScale);
8305
+ if (modified) // && opposite)
8306
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8307
+ else
8308
+ //LA.matScale(toParent, hScale, vScale, 1);
8309
+ LA.matScale(toParent, 1, 1, totalScale);
77378310 } else
77388311 {
77398312 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7770,7 +8343,7 @@
77708343 } // NEW ...
77718344
77728345
7773
- info.pane.repaint();
8346
+ clickInfo.pane.repaint();
77748347 }
77758348
77768349 boolean overflow = false;
....@@ -7877,19 +8450,19 @@
78778450 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
78788451 } else
78798452 {
7880
- objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
8453
+ objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + ((bRep==null)?(count - 1):bRep.VertexCount()) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ "";
78818454 } // + super.toString();
78828455 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
78838456
78848457 if (!Globals.ADVANCED)
78858458 return objname;
78868459
7887
- return objname + " " + System.identityHashCode(this);
8460
+ return objname + " " + System.identityHashCode(this) + " " + GetUUID();
78888461 }
78898462
78908463 public int hashCode()
78918464 {
7892
- // Fuck Vector...
8465
+ // Do not use Vector...
78938466 return System.identityHashCode(this);
78948467 }
78958468
....@@ -8129,8 +8702,8 @@
81298702 private static cVector2 qq2 = new cVector2();
81308703 private static cVector2 rr2 = new cVector2();
81318704 private static cVector2 ss2 = new cVector2();
8132
- private static cVector edge1 = new cVector();
8133
- private static cVector edge2 = new cVector();
8705
+// private static cVector edge1 = new cVector();
8706
+// private static cVector edge2 = new cVector();
81348707 //private static cVector norm = new cVector();
81358708 /*transient private*/ int hitSomething;
81368709 static final int hitCenter = 1;
....@@ -8328,7 +8901,275 @@
83288901
83298902 Touch();
83308903 }
8904
+
8905
+ static Vertex s1 = new Vertex();
8906
+ static Vertex s2 = new Vertex();
8907
+ static Vertex s3 = new Vertex();
83318908
8909
+ boolean intersectMesh(Ray ray, IntersectResult result)
8910
+ {
8911
+ boolean success = false;
8912
+
8913
+ if (bRep.stripified)
8914
+ {
8915
+ int[] strips = bRep.getRawIndices();
8916
+
8917
+ // TRIANGLE STRIP ARRAY
8918
+ if (bRep.trimmed)
8919
+ {
8920
+ float[] v = bRep.getRawVertices();
8921
+
8922
+ int count3 = 0;
8923
+
8924
+ if (v.length > 0)
8925
+ {
8926
+ for (int i = 0; i < strips.length; i++)
8927
+ {
8928
+ s1.set(v[count3], v[count3 + 1], v[count3 + 2]);
8929
+ count3 += 3;
8930
+
8931
+ s2.set(v[count3], v[count3 + 1], v[count3 + 2]);
8932
+ count3 += 3;
8933
+
8934
+ for (int j = 0; j < strips[i] - 2; j++)
8935
+ {
8936
+ s3.set(v[count3], v[count3 + 1], v[count3 + 2]);
8937
+ count3 += 3;
8938
+
8939
+ if (j%2 == 0)
8940
+ success |= intersectTriangle(ray, result, s1, s2, s3);
8941
+ else
8942
+ success |= intersectTriangle(ray, result, s1, s3, s2);
8943
+
8944
+ s1.set(s2);
8945
+ s2.set(s3);
8946
+ }
8947
+ }
8948
+ }
8949
+
8950
+ assert count3 == v.length;
8951
+ }
8952
+ else // !trimmed
8953
+ {
8954
+ int count = 0;
8955
+ for (int i = 0; i < strips.length; i++)
8956
+ {
8957
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
8958
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
8959
+
8960
+ for (int j = 0; j < strips[i] - 2; j++)
8961
+ {
8962
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
8963
+
8964
+ if (j%2 == 0)
8965
+ success |= intersectTriangle(ray, result, p, q, r);
8966
+ else
8967
+ success |= intersectTriangle(ray, result, p, r, q);
8968
+
8969
+ p = q;
8970
+ q = r;
8971
+ }
8972
+ }
8973
+ }
8974
+ } else // catch (Error e)
8975
+ {
8976
+ int facecount = bRep.FaceCount();
8977
+ for (int i = 0; i < facecount; i++)
8978
+ {
8979
+ Face face = bRep.GetFace(i);
8980
+
8981
+ Vertex p = bRep.GetVertex(face.p);
8982
+ Vertex q = bRep.GetVertex(face.q);
8983
+ Vertex r = bRep.GetVertex(face.r);
8984
+
8985
+ success |= intersectTriangle(ray, result, p, q, r);
8986
+ }
8987
+ }
8988
+
8989
+ return success;
8990
+ }
8991
+
8992
+ static cVector eye = new cVector();
8993
+ static cVector dir = new cVector();
8994
+
8995
+ transient BBox bbox = null;
8996
+
8997
+ boolean intersect(Ray ray, IntersectResult result)
8998
+ {
8999
+ double eyex = ray.eyePoint.x;
9000
+ double eyey = ray.eyePoint.y;
9001
+ double eyez = ray.eyePoint.z;
9002
+
9003
+ double dirx = ray.viewDirection.x;
9004
+ double diry = ray.viewDirection.y;
9005
+ double dirz = ray.viewDirection.z;
9006
+
9007
+ if (this.fromParent != null && !(this instanceof TextureNode))
9008
+ {
9009
+ eye.x = eyex;
9010
+ eye.y = eyey;
9011
+ eye.z = eyez;
9012
+ dir.x = dirx;
9013
+ dir.y = diry;
9014
+ dir.z = dirz;
9015
+
9016
+ LA.xformPos(eye, this.fromParent, eye);
9017
+ LA.xformDir(dir, this.fromParent, dir);
9018
+
9019
+ ray.eyePoint.x = eye.x;
9020
+ ray.eyePoint.y = eye.y;
9021
+ ray.eyePoint.z = eye.z;
9022
+
9023
+ ray.viewDirection.x = dir.x;
9024
+ ray.viewDirection.y = dir.y;
9025
+ ray.viewDirection.z = dir.z;
9026
+ }
9027
+
9028
+ boolean success = false;
9029
+
9030
+ boolean touch = false;
9031
+
9032
+ if (bRep != null && Link2Support())
9033
+ {
9034
+ if (bbox == null)
9035
+ {
9036
+ bbox = new BBox();
9037
+
9038
+ cVector min = new cVector();
9039
+ cVector max = new cVector();
9040
+
9041
+ this.getBounds(min, max, true);
9042
+
9043
+ bbox.min.x = min.x;
9044
+ bbox.min.y = min.y;
9045
+ bbox.min.z = min.z;
9046
+
9047
+ bbox.max.x = max.x;
9048
+ bbox.max.y = max.y;
9049
+ bbox.max.z = max.z;
9050
+ }
9051
+
9052
+ if (true) // NOT WORKING bbox.intersect(ray, result))
9053
+ {
9054
+ success |= intersectMesh(ray, result);
9055
+ }
9056
+ else
9057
+ {
9058
+ //this.hide = true;
9059
+ touch = true;
9060
+ }
9061
+ }
9062
+
9063
+ for (int i=0; i<size(); i++)
9064
+ {
9065
+ Object3D child = (Object3D) reserve(i);
9066
+
9067
+ if (child == null)
9068
+ continue;
9069
+
9070
+ success |= child.intersect(ray, result);
9071
+ release(i);
9072
+ }
9073
+
9074
+ ray.eyePoint.x = eyex;
9075
+ ray.eyePoint.y = eyey;
9076
+ ray.eyePoint.z = eyez;
9077
+
9078
+ ray.viewDirection.x = dirx;
9079
+ ray.viewDirection.y = diry;
9080
+ ray.viewDirection.z = dirz;
9081
+
9082
+// if (touch)
9083
+// this.Touch(); // refresh display list
9084
+
9085
+ return success;
9086
+ }
9087
+
9088
+ static Vector3d edge1 = new Vector3d();
9089
+ static Vector3d edge2 = new Vector3d();
9090
+ static Vector3d P = new Vector3d();
9091
+ static Vector3d T = new Vector3d();
9092
+ static Vector3d Q = new Vector3d();
9093
+
9094
+ private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3)
9095
+ {
9096
+ if (false)
9097
+ {
9098
+ result.t = 0;
9099
+ return true;
9100
+ }
9101
+
9102
+ /*
9103
+ Fast, Minimum Storage Ray/Triangle Intersection, Moller et al.
9104
+
9105
+ Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
9106
+ */
9107
+
9108
+ // Calculate edges of the triangle
9109
+ edge1.set(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z);
9110
+ edge2.set(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z);
9111
+
9112
+ // Calculate the determinant (U parameter)
9113
+ P.cross(ray.viewDirection, edge2);
9114
+ double det = edge1.dot(P);
9115
+
9116
+ if (det > -1e-9 && det < 1e-9)
9117
+ {
9118
+ return false;
9119
+ } // Ray lies in plane of triangle
9120
+
9121
+ double invDet = 1 / det;
9122
+
9123
+ // Calculate distance from vertex1 to ray origin
9124
+ T.set(ray.eyePoint.x - v1.x, ray.eyePoint.y - v1.y, ray.eyePoint.z - v1.z);
9125
+
9126
+ double U = (T.dot(P)) * invDet; // Calculate U parameter
9127
+
9128
+ if (U < 0.f || U > 1.f)
9129
+ {
9130
+ return false;
9131
+ } // Intersection lies outside of the triangle
9132
+
9133
+ // Calculate V parameter
9134
+ Q.cross(T, edge1);
9135
+
9136
+ double V = ray.viewDirection.dot(Q) * invDet;
9137
+
9138
+ if (V < 0.f || (U + V) > 1.f)
9139
+ {
9140
+ return false;
9141
+ } // Intersection lies outside of the triangle
9142
+
9143
+ double t = edge2.dot(Q) * invDet;
9144
+
9145
+ if (t > 1e-9) // Triangle and ray intersects
9146
+ {
9147
+ //result.isIntersected = true;
9148
+ //result.id = id;
9149
+
9150
+ if (false) // isShadow)
9151
+ {
9152
+ result.t = t;
9153
+ return true;
9154
+ } else if (t < result.t)
9155
+ {
9156
+ result.object = this;
9157
+
9158
+ result.t = t;
9159
+
9160
+ //result.p.x = ray.eyePoint.x + ray.viewDirection.x * t;
9161
+ //result.p.y = ray.eyePoint.y + ray.viewDirection.y * t;
9162
+ //result.p.z = ray.eyePoint.z + ray.viewDirection.z * t;
9163
+
9164
+ result.n.cross(edge1, edge2);
9165
+ result.n.normalize();
9166
+ }
9167
+
9168
+ return true;
9169
+ }
9170
+
9171
+ return false;
9172
+ }
83329173
83339174 public int Size()
83349175 {
....@@ -8425,5 +9266,17 @@
84259266 return -1;
84269267 }
84279268 */
9269
+
9270
+ void Translate(double x, double y, double z)
9271
+ {
9272
+ if (toParent == null)
9273
+ {
9274
+ toParent = LA.newMatrix();
9275
+ fromParent = LA.newMatrix();
9276
+ }
9277
+
9278
+ LA.matTranslate(toParent, x, y, z);
9279
+ LA.matTranslateInv(fromParent, -x, -y, -z);
9280
+ }
84289281 }
84299282