Normand Briere
2019-11-21 ddb10cb84dddfeef1ef9946f2e13cef3c93e6cc4
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
....@@ -3113,7 +3394,10 @@
31133394 {
31143395 if (bRep != null)
31153396 {
3397
+ //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact).
31163398 bRep.GenerateNormals(crease);
3399
+ if (!bRep.trimmed)
3400
+ bRep.MergeNormals();
31173401 Touch();
31183402 }
31193403 }
....@@ -3188,6 +3472,105 @@
31883472 blockloop = false;
31893473 }
31903474
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
+
31913574 void TransformChildren()
31923575 {
31933576 if (toParent != null)
....@@ -3430,6 +3813,7 @@
34303813 if (bRep != null)
34313814 {
34323815 //bRep.RemoveOneTriangle();
3816
+ System.out.println();
34333817 System.out.println("Reducing " + this);
34343818 if (name != null && name.contains("lockpickstraps"))
34353819 name = name;
....@@ -3541,15 +3925,47 @@
35413925
35423926 void ClearMaterials()
35433927 {
3928
+ if (blockloop)
3929
+ return;
3930
+
3931
+ blockloop = true;
3932
+
35443933 ClearMaterial();
3545
- for (int i = 0; i < size(); i++)
3934
+ for (int i = 0; i < Size(); i++)
35463935 {
3547
- Object3D child = (Object3D) reserve(i);
3936
+ Object3D child = (Object3D) get(i);
35483937 if (child == null)
35493938 continue;
35503939 child.ClearMaterials();
3551
- release(i);
35523940 }
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;
35533969 }
35543970
35553971 void FlipV(boolean flip)
....@@ -3728,6 +4144,7 @@
37284144
37294145 void RevertMeshes()
37304146 {
4147
+ // BLOCKLOOP
37314148 if (this instanceof cMesh)
37324149 {
37334150 ((cMesh)this).Revert();
....@@ -3758,11 +4175,6 @@
37584175 Touch();
37594176 }
37604177
3761
- ResetRecur();
3762
- }
3763
-
3764
- void ResetRecur()
3765
- {
37664178 for (int i = 0; i < size(); i++)
37674179 {
37684180 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3785,11 +4197,6 @@
37854197 Step();
37864198 Touch();
37874199
3788
- StepRecur();
3789
- }
3790
-
3791
- void StepRecur()
3792
- {
37934200 for (int i = 0; i < size(); i++)
37944201 {
37954202 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3976,8 +4383,8 @@
39764383 Touch();
39774384 }
39784385
3979
- transient cVector min = new cVector();
3980
- transient cVector max = new cVector();
4386
+ transient cVector min;
4387
+ transient cVector max;
39814388
39824389 void getBounds(cVector minima, cVector maxima, boolean xform)
39834390 {
....@@ -3993,15 +4400,15 @@
39934400 if (blockloop)
39944401 return;
39954402
3996
- if (min == null) // ???
4403
+ if (min == null)
39974404 {
39984405 min = new cVector();
39994406 max = new cVector();
40004407 }
40014408
4002
- for (int i = 0; i<size(); i++)
4409
+ for (int i = 0; i<Size(); i++)
40034410 {
4004
- Object3D child = (Object3D) reserve(i);
4411
+ Object3D child = (Object3D) get(i); //reserve(i);
40054412 if (child == null)
40064413 continue;
40074414
....@@ -4020,21 +4427,21 @@
40204427 if (child.hide && !(child instanceof Merge) || child.skip)
40214428 //if (child.hide)
40224429 {
4023
- release(i);
4430
+ //release(i);
40244431 continue;
40254432 }
40264433
40274434 blockloop = true;
40284435 child.getBounds(min, max, true); // xform);
40294436 blockloop = false;
4030
- release(i);
4437
+ //release(i);
40314438
40324439 MinMax(minima, maxima);
40334440 }
40344441
40354442 if (bRep != null)
40364443 {
4037
- bRep.getBounds(minima,maxima,this);
4444
+ bRep.getBounds(minima, maxima, xform?this:null);
40384445 }
40394446
40404447 if (false) // xform)
....@@ -5307,8 +5714,9 @@
53075714 {
53085715 }
53095716 // transient int displaylist = 0; // -1;
5310
- transient boolean touched = true;
5311
- 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
53125720
53135721 void Touch()
53145722 {
....@@ -5361,6 +5769,7 @@
53615769 {
53625770 //System.out.println("HardTouch " + this); // new Exception().printStackTrace();
53635771 //new Exception().printStackTrace();
5772
+ reset = true;
53645773 touched = true;
53655774 CameraPane.touched = true;
53665775 //if (parent != null)
....@@ -5539,6 +5948,11 @@
55395948 if (fullname == null)
55405949 return "";
55415950
5951
+ if (fullname.pigment != null)
5952
+ {
5953
+ return fullname.pigment;
5954
+ }
5955
+
55425956 // System.out.println("Fullname = " + fullname);
55435957
55445958 // Does not work on Windows due to C:
....@@ -5551,7 +5965,7 @@
55515965
55525966 if (split.length == 0)
55535967 {
5554
- return "";
5968
+ return fullname.pigment = "";
55555969 }
55565970
55575971 if (split.length <= 2)
....@@ -5559,22 +5973,27 @@
55595973 if (fullname.name.endsWith(":"))
55605974 {
55615975 // Windows
5562
- return fullname.name.substring(0, fullname.name.length()-1);
5976
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
55635977 }
55645978
5565
- return split[0];
5979
+ return fullname.pigment = split[0];
55665980 }
55675981
55685982 // Windows
55695983 assert(split.length == 4);
55705984
5571
- return split[0] + ":" + split[1];
5985
+ return fullname.pigment = split[0] + ":" + split[1];
55725986 }
55735987
55745988 static String GetBump(cTexture fullname)
55755989 {
55765990 if (fullname == null)
55775991 return "";
5992
+
5993
+ if (fullname.bump != null)
5994
+ {
5995
+ return fullname.bump;
5996
+ }
55785997
55795998 // System.out.println("Fullname = " + fullname);
55805999 // Does not work on Windows due to C:
....@@ -5586,12 +6005,12 @@
55866005
55876006 if (split.length == 0)
55886007 {
5589
- return "";
6008
+ return fullname.bump = "";
55906009 }
55916010
55926011 if (split.length == 1)
55936012 {
5594
- return "";
6013
+ return fullname.bump = "";
55956014 }
55966015
55976016 if (split.length == 2)
....@@ -5599,16 +6018,16 @@
55996018 if (fullname.name.endsWith(":"))
56006019 {
56016020 // Windows
5602
- return "";
6021
+ return fullname.bump = "";
56036022 }
56046023
5605
- return split[1];
6024
+ return fullname.bump = split[1];
56066025 }
56076026
56086027 // Windows
56096028 assert(split.length == 4);
56106029
5611
- return split[2] + ":" + split[3];
6030
+ return fullname.bump = split[2] + ":" + split[3];
56126031 }
56136032
56146033 String GetPigmentTexture()
....@@ -5691,6 +6110,9 @@
56916110 texname = "";
56926111
56936112 GetTextures().name = texname + ":" + GetBump(GetTextures());
6113
+
6114
+ GetTextures().pigment = null;
6115
+
56946116 Touch();
56956117 }
56966118
....@@ -5764,6 +6186,8 @@
57646186
57656187 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
57666188
6189
+ GetTextures().bump = null;
6190
+
57676191 Touch();
57686192 }
57696193
....@@ -5828,7 +6252,7 @@
58286252 boolean NeedSupport()
58296253 {
58306254 return
5831
- 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
58326256 // PROBLEM with CROWD!!
58336257 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
58346258 }
....@@ -5846,6 +6270,22 @@
58466270 return parent.IsLive();
58476271 }
58486272
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
+
58496289 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58506290 {
58516291 Invariants(); // june 2013
....@@ -5853,6 +6293,29 @@
58536293 if (support != null)
58546294 {
58556295 // 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
+ }
58566319 }
58576320
58586321 if (display.DrawMode() == iCameraPane.SELECTION &&
....@@ -5906,8 +6369,12 @@
59066369 if (support != null)
59076370 support = support;
59086371
5909
- //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5910
- 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.
59116378
59126379 if (!usecalllists && bRep != null && bRep.displaylist > 0)
59136380 {
....@@ -5915,10 +6382,12 @@
59156382 bRep.displaylist = 0;
59166383 }
59176384 // usecalllists &= !(parent instanceof RandomNode);
5918
- // usecalllists = false;
6385
+ if (CameraPane.BOXMODE) // Too dynamic
6386
+ usecalllists = false;
59196387
5920
- if (GetBRep() != null)
5921
- usecalllists = usecalllists;
6388
+ if (display.DrawMode() == display.SHADOW)
6389
+ //GetBRep() != null)
6390
+ usecalllists = !!usecalllists;
59226391 //System.out.println("draw " + this);
59236392 //new Exception().printStackTrace();
59246393
....@@ -5928,7 +6397,7 @@
59286397
59296398 if (!selectmode && //display.DrawMode() != display.SELECTION &&
59306399 //(touched || (bRep != null && bRep.displaylist <= 0)))
5931
- (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
6400
+ ((Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE) || touched)) // || (bRep != null && bRep.displaylist <= 0)))
59326401 {
59336402 Globals.lighttouched = true;
59346403 } // all panes...
....@@ -5940,7 +6409,7 @@
59406409 if (!(this instanceof Composite))
59416410 touched = false;
59426411 //if (displaylist == -1 && usecalllists)
5943
- if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013
6412
+ if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013
59446413 {
59456414 bRep.displaylist = display.GenList();
59466415 assert(bRep.displaylist != 0);
....@@ -5951,16 +6420,18 @@
59516420
59526421 //System.out.println("\tnew list " + list);
59536422 //gl.glDrawBuffer(gl.GL_NONE);
5954
- if (usecalllists)
6423
+ if (usecalllists && bRep.displaylist > 0)
59556424 {
59566425 // System.err.println("new list " + bRep.displaylist + " for " + this);
59576426 display.NewList(bRep.displaylist);
59586427 }
59596428
6429
+ compiling = true;
59606430 CallList(display, root, selected, blocked);
6431
+ compiling = false;
59616432
59626433 // compiled = true;
5963
- if (usecalllists)
6434
+ if (usecalllists && bRep.displaylist > 0)
59646435 {
59656436 // System.err.println("end list " + bRep.displaylist + " for " + this);
59666437 display.EndList();
....@@ -5970,8 +6441,8 @@
59706441 Globals.lighttouched = true; // all panes...
59716442 }
59726443
5973
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
5974
- //touched = false;
6444
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6445
+ touched = false;
59756446
59766447 if (this instanceof Texture || this instanceof TextureNode)
59776448 {
....@@ -6010,7 +6481,7 @@
60106481 {
60116482 if (display.DrawMode() == iCameraPane.SHADOW)
60126483 {
6013
- if (!link2master // tricky to cull in shadow mode.
6484
+ if (!Link2Support() // tricky to cull in shadow mode.
60146485 && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
60156486 {
60166487 //System.out.print("CULLED");
....@@ -6072,6 +6543,20 @@
60726543 {
60736544 drawSelf(display, root, selected, blocked);
60746545 }
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
+// }
60756560 } else
60766561 {
60776562 /*
....@@ -6104,13 +6589,14 @@
61046589 boolean failedPigment = false;
61056590 boolean failedBump = false;
61066591
6592
+ CameraPane.lastObject = this;
61076593 try
61086594 {
61096595 display.BindPigmentTexture(tex, texres);
61106596 }
61116597 catch (Exception e)
61126598 {
6113
- System.err.println("FAILED: " + this);
6599
+ // System.err.println("FAILED: " + this);
61146600 failedPigment = true;
61156601 }
61166602
....@@ -6141,6 +6627,20 @@
61416627 display.CallList(bRep.displaylist);
61426628 // june 2013 drawSelf(display, root, selected);
61436629 }
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
+// }
61446644 }
61456645 }
61466646
....@@ -6194,16 +6694,17 @@
61946694
61956695 void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
61966696 {
6197
- if (GetBRep() == null)
6198
- {
6199
- drawSelf(display, root, selected, blocked);
6200
- } else
6697
+ if (GetBRep() != null)
62016698 {
62026699 DrawNode(display, root, selected);
62036700 if (this instanceof BezierPatch)
62046701 {
62056702 //drawSelf(display, root, selected);
62066703 }
6704
+ }
6705
+ else
6706
+ {
6707
+ drawSelf(display, root, selected, blocked);
62076708 }
62086709 }
62096710
....@@ -6402,15 +6903,18 @@
64026903
64036904 void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
64046905 {
6405
- if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6406
- return; // no shadow for transparent objects
6407
-
6408
- if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6409
- 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
+ }
64106914
64116915 if (hide)
64126916 return;
6413
-
6917
+
64146918 if (scriptnode != null)
64156919 {
64166920 scriptnode.DrawNode(display, root, selected);
....@@ -6453,7 +6957,8 @@
64536957
64546958 //javax.media.opengl.GL gl = display.GetGL();
64556959
6456
- if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
6960
+ if (CameraPane.BOXMODE && !Link2Support()) //
6961
+ //!selected) // || CameraPane.movingcamera)
64576962 {
64586963 int fc = bRep.FaceCount();
64596964 int vc = bRep.VertexCount();
....@@ -6615,7 +7120,7 @@
66157120 facescompare[k] = new FaceCompare(k);
66167121 }
66177122
6618
- center = new cVector();
7123
+ centertriangle = new cVector();
66197124 }
66207125 else
66217126 {
....@@ -6738,7 +7243,7 @@
67387243 */
67397244 }
67407245
6741
- transient cVector center;
7246
+ transient cVector centertriangle;
67427247
67437248 class FaceCompare implements Comparable
67447249 {
....@@ -6767,14 +7272,14 @@
67677272 Vertex q = bRep.GetVertex(face.q);
67687273 Vertex r = bRep.GetVertex(face.r);
67697274
6770
- center.set(p);
6771
- center.add(q);
6772
- center.add(r);
6773
- center.mul(1.0/3);
7275
+ centertriangle.set(p);
7276
+ centertriangle.add(q);
7277
+ centertriangle.add(r);
7278
+ centertriangle.mul(1.0/3);
67747279
6775
- center.sub(Globals.theRenderer.EyeCamera().location);
7280
+ centertriangle.sub(Globals.theRenderer.EyeCamera().location);
67767281
6777
- distance = center.dot(center);
7282
+ distance = centertriangle.dot(centertriangle);
67787283 }
67797284
67807285 return distance;
....@@ -7364,7 +7869,7 @@
73647869 boundary.y = spot.y - 30;
73657870 boundary.width = spot.width + 60;
73667871 boundary.height = spot.height + 60;
7367
- clickInfo.g.setColor(Color.red);
7872
+ clickInfo.g.setColor(Color.white);
73687873 int spotw = spot.x + spot.width;
73697874 int spoth = spot.y + spot.height;
73707875 clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -7384,7 +7889,29 @@
73847889 // {
73857890 // CameraPane.Ymax = spoth;
73867891 // }
7387
- spot.translate(32, 32);
7892
+// if (CameraPane.Xmin > spot.x)
7893
+// {
7894
+// CameraPane.Xmin = spot.x;
7895
+// }
7896
+// if (CameraPane.Xmax < spotw)
7897
+// {
7898
+// CameraPane.Xmax = spotw;
7899
+// }
7900
+// if (CameraPane.Ymin > spot.y)
7901
+// {
7902
+// CameraPane.Ymin = spot.y;
7903
+// }
7904
+// if (CameraPane.Ymax < spoth)
7905
+// {
7906
+// CameraPane.Ymax = spoth;
7907
+// }
7908
+ // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7909
+ //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
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);
73887915 spotw = spot.x + spot.width;
73897916 spoth = spot.y + spot.height;
73907917 clickInfo.g.setColor(Color.cyan);
....@@ -7405,28 +7932,7 @@
74057932 // {
74067933 // CameraPane.Ymax = spoth;
74077934 // }
7408
- // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7409
- //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7410
- spot.translate(0, -32);
7411
- clickInfo.g.setColor(Color.yellow);
7412
- clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
74137935 clickInfo.g.setColor(Color.green);
7414
-// if (CameraPane.Xmin > spot.x)
7415
-// {
7416
-// CameraPane.Xmin = spot.x;
7417
-// }
7418
-// if (CameraPane.Xmax < spotw)
7419
-// {
7420
-// CameraPane.Xmax = spotw;
7421
-// }
7422
-// if (CameraPane.Ymin > spot.y)
7423
-// {
7424
-// CameraPane.Ymin = spot.y;
7425
-// }
7426
-// if (CameraPane.Ymax < spoth)
7427
-// {
7428
-// CameraPane.Ymax = spoth;
7429
-// }
74307936 clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY,
74317937 (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360);
74327938 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
....@@ -7485,12 +7991,14 @@
74857991 retval = true;
74867992 }
74877993 spot.translate(0, 32);
7994
+ spot.translate(32, 0);
7995
+ spot.translate(0, 32);
74887996 if (spot.contains(clickInfo.x, clickInfo.y))
74897997 {
74907998 hitSomething = hitScale;
74917999
74928000 double scale = 0.005f * clickInfo.camera.Distance();
7493
- double hScale = (double) (clickInfo.x /*- centerPt.x*/) / 32;
8001
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
74948002 double sign = 1;
74958003 if (hScale < 0)
74968004 {
....@@ -7502,7 +8010,7 @@
75028010 //hScale = 0.01;
75038011 }
75048012
7505
- double vScale = (double) (clickInfo.y /*- centerPt.y*/) / 32;
8013
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
75068014 sign = 1;
75078015 if (vScale < 0)
75088016 {
....@@ -7582,7 +8090,9 @@
75828090
75838091 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
75848092
7585
- if (modified || opposite)
8093
+ // Modified could snap
8094
+ if (//modified ||
8095
+ opposite)
75868096 {
75878097 //assert(false);
75888098 /*
....@@ -7676,7 +8186,7 @@
76768186
76778187 if (modified)
76788188 {
7679
- // Rotate 90 degrees
8189
+ // Rotate 45 degrees
76808190 angle /= (Math.PI / 4);
76818191 angle = Math.floor(angle + 0.5);
76828192 angle *= (Math.PI / 4);
....@@ -7717,7 +8227,7 @@
77178227 break;
77188228
77198229 case hitScale: // scale
7720
- double hScale = (double) (clickInfo.x /*- centerPt.x*/) / 32;
8230
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
77218231 double sign = 1;
77228232 if (hScale < 0)
77238233 {
....@@ -7729,7 +8239,7 @@
77298239 //hScale = 0.01;
77308240 }
77318241
7732
- double vScale = (double) (clickInfo.y /*- centerPt.y*/) / 32;
8242
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
77338243 sign = 1;
77348244 if (vScale < 0)
77358245 {
....@@ -7762,21 +8272,27 @@
77628272 case 3: // '\001'
77638273 if (modified || opposite)
77648274 {
8275
+ if (modified) // && opposite)
8276
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8277
+ else
77658278 //LA.matScale(toParent, 1, hScale, vScale);
7766
- LA.matScale(toParent, totalScale, 1, 1);
8279
+ LA.matScale(toParent, totalScale, 1, 1);
77678280 } // vScale, 1);
77688281 else
77698282 {
77708283 // EXCEPTION!
7771
- LA.matScale(toParent, totalScale, totalScale, totalScale);
8284
+ LA.matScale(toParent, 1, totalScale, totalScale);
77728285 } // vScale, 1);
77738286 break;
77748287
77758288 case 2: // '\002'
77768289 if (modified || opposite)
77778290 {
7778
- //LA.matScale(toParent, hScale, 1, vScale);
7779
- 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);
77808296 } else
77818297 {
77828298 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7786,8 +8302,11 @@
77868302 case 1: // '\003'
77878303 if (modified || opposite)
77888304 {
7789
- //LA.matScale(toParent, hScale, vScale, 1);
7790
- 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);
77918310 } else
77928311 {
77938312 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7931,19 +8450,19 @@
79318450 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
79328451 } else
79338452 {
7934
- 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) ":"") */ "";
79358454 } // + super.toString();
79368455 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
79378456
79388457 if (!Globals.ADVANCED)
79398458 return objname;
79408459
7941
- return objname + " " + System.identityHashCode(this);
8460
+ return objname + " " + System.identityHashCode(this) + " " + GetUUID();
79428461 }
79438462
79448463 public int hashCode()
79458464 {
7946
- // Fuck Vector...
8465
+ // Do not use Vector...
79478466 return System.identityHashCode(this);
79488467 }
79498468
....@@ -8183,8 +8702,8 @@
81838702 private static cVector2 qq2 = new cVector2();
81848703 private static cVector2 rr2 = new cVector2();
81858704 private static cVector2 ss2 = new cVector2();
8186
- private static cVector edge1 = new cVector();
8187
- private static cVector edge2 = new cVector();
8705
+// private static cVector edge1 = new cVector();
8706
+// private static cVector edge2 = new cVector();
81888707 //private static cVector norm = new cVector();
81898708 /*transient private*/ int hitSomething;
81908709 static final int hitCenter = 1;
....@@ -8382,7 +8901,275 @@
83828901
83838902 Touch();
83848903 }
8904
+
8905
+ static Vertex s1 = new Vertex();
8906
+ static Vertex s2 = new Vertex();
8907
+ static Vertex s3 = new Vertex();
83858908
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
+ }
83869173
83879174 public int Size()
83889175 {
....@@ -8479,5 +9266,17 @@
84799266 return -1;
84809267 }
84819268 */
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
+ }
84829281 }
84839282