Normand Briere
2019-11-21 ddb10cb84dddfeef1ef9946f2e13cef3c93e6cc4
Object3D.java
....@@ -22,21 +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
3236 String skyboxname;
3337 String skyboxext;
3438
35
- byte[] versions[];
39
+ Object3D[] versionlist;
3640 int versionindex = -1;
3741
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
+
3846 ScriptNode scriptnode;
3947
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
+
40148 void InitOthers()
41149 {
42150 if (projectedVertices == null || projectedVertices.length <= 2)
....@@ -48,6 +156,7 @@
48156 projectedVertices[i] = new cVector2(); // Others
49157 }
50158 projectedVertices[0].x = 100; // bump
159
+ projectedVertices[1].y = 1000; // punchthrough. only for png
51160 }
52161
53162 void MinMax(cVector minima, cVector maxima)
....@@ -127,7 +236,7 @@
127236 return;
128237
129238 transientsupport = support;
130
- transientlink2master = link2master;
239
+ transientlink2master = Link2Support();
131240
132241 support = null;
133242 link2master = false;
....@@ -174,9 +283,42 @@
174283 }
175284 }
176285
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
+
177314 void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
178315 {
316
+ if (blockloop)
317
+ return;
318
+
179319 Object3D o;
320
+
321
+ boolean isnew = false;
180322
181323 if (hashtable.containsKey(GetUUID()))
182324 {
....@@ -190,12 +332,14 @@
190332 }
191333 else
192334 {
335
+ isnew = true;
336
+
193337 o = new Object3D("copy of " + this.name);
194338
195339 hashtable.put(GetUUID(), o);
196340 }
197341
198
- if (!blockloop)
342
+ //if (!blockloop)
199343 {
200344 blockloop = true;
201345
....@@ -206,12 +350,15 @@
206350
207351 blockloop = false;
208352 }
209
-
210
- ExtractBigData(o);
353
+
354
+ //if (isnew)
355
+ ExtractBigData(o);
211356 }
212357
213358 void ExtractBigData(Object3D o)
214359 {
360
+ //System.err.println("ExtractBigData : " + this + " --> " + o);
361
+
215362 if (o.bRep != null)
216363 Grafreed.Assert(o.bRep == this.bRep);
217364
....@@ -222,8 +369,8 @@
222369 // o.bRep.support = null;
223370 // }
224371 o.selection = this.selection;
225
- o.versions = this.versions;
226
- o.versionindex = this.versionindex;
372
+ //o.versionlist = this.versionlist;
373
+ //o.versionindex = this.versionindex;
227374
228375 if (this.support != null)
229376 {
....@@ -246,17 +393,84 @@
246393 // this.fileparent = null;
247394 }
248395
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
+
249463 void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
250464 {
465
+ if (blockloop)
466
+ return;
467
+
251468 if (!hashtable.containsKey(GetUUID()))
252469 return;
253470
254471 Object3D o = hashtable.get(GetUUID());
255472
256473 RestoreBigData(o);
257
-
258
- if (blockloop)
259
- return;
260474
261475 blockloop = true;
262476
....@@ -272,6 +486,9 @@
272486
273487 void RestoreBigData(Object3D o)
274488 {
489
+ //System.err.println("RestoreBigData : " + this + " <-- " + o);
490
+ Grafreed.Assert(this.bRep == null);
491
+
275492 this.bRep = o.bRep;
276493 if (this.support != null && o.transientrep != null)
277494 {
....@@ -280,8 +497,8 @@
280497
281498 this.selection = o.selection;
282499
283
- this.versions = o.versions;
284
- this.versionindex = o.versionindex;
500
+ //this.versionlist = o.versionlist;
501
+ //this.versionindex = o.versionindex;
285502 // July 2019 if (this.bRep != null)
286503 // this.bRep.support = o.transientrep;
287504 // this.support = o.support;
....@@ -432,7 +649,10 @@
432649 transient boolean keepdontselect;
433650 boolean dontselect = false;
434651 boolean hide = false;
435
- 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
+
436656 boolean marked = false; // animation node
437657 boolean skip = false; // centroid issue
438658 boolean skipmocap = false; // mocap data
....@@ -440,6 +660,9 @@
440660 boolean random = false;
441661 boolean speedup = false;
442662 boolean rewind = false;
663
+
664
+ // Option to sort triangles, e.g. for transparency.
665
+ boolean sort = false;
443666
444667 float NORMALPUSH = 0;
445668
....@@ -450,27 +673,74 @@
450673 return this;
451674 }
452675
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
+
453697 void SortBySize()
454698 {
455
- 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();
456721
457
- while (!sorted)
722
+ if (sizecompare == null || sizecompare.length != count)
458723 {
459
- sorted = true;
460
-
461
- for (int i=0; i<size()-1; i++)
724
+ sizecompare = new SizeCompare[count];
725
+
726
+ for (int k=0; k<count; k++)
462727 {
463
- Object3D obji = get(i);
464
- Object3D objj = get(i+1);
465
-
466
- if (obji.MemorySize() < objj.MemorySize())
467
- {
468
- set(i, objj);
469
- set(i+1, obji);
470
-
471
- sorted = false;
472
- }
728
+ sizecompare[k] = new SizeCompare(get(k));
473729 }
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);
474744 }
475745 }
476746
....@@ -482,7 +752,7 @@
482752 {
483753 sorted = true;
484754
485
- for (int i=0; i<size()-1; i++)
755
+ for (int i=0; i<Size()-1; i++)
486756 {
487757 Object3D obji = get(i);
488758 Object3D objj = get(i+1);
....@@ -498,38 +768,63 @@
498768 }
499769 }
500770
501
- int memorysize;
771
+ transient int memorysize; // needs to be transient, dunno why
502772
503773 int MemorySize()
504774 {
505
- 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)
506805 {
507
- try
508
- {
509
- Object3D obj = this;
806
+ return 0;
807
+ }
510808
511
- Object3D parent = obj.parent;
512
- obj.parent = null;
513
- Object3D support = obj.support;
514
- obj.support = null;
515
-
516
- java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
517
- java.io.ObjectOutputStream out = new java.io.ObjectOutputStream(baos);
518
-
519
- out.writeObject(obj);
520
-
521
- obj.parent = parent;
522
- obj.support = support;
523
-
524
- memorysize = baos.toByteArray().length;
525
- }
526
- catch (Exception e)
527
- {
528
- e.printStackTrace();
529
- }
809
+ int memory = 0;
810
+
811
+ if (bRep != null)
812
+ {
813
+ memory = bRep.VertexCount();
530814 }
531815
532
- 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;
533828 }
534829
535830 void Slower()
....@@ -617,7 +912,7 @@
617912 {
618913 if (maxcount != 1)
619914 {
620
- new Exception().printStackTrace();
915
+ //new Exception().printStackTrace();
621916 }
622917
623918 toParentMarked = LA.newMatrix();
....@@ -819,7 +1114,7 @@
8191114
8201115 void Step()
8211116 {
822
- // marde pour serialization de Texture
1117
+ // patch pour serialization de Texture
8231118 resetmaxcount();
8241119 resettransformcount();
8251120 resetstep();
....@@ -854,7 +1149,7 @@
8541149 transformcount++;
8551150 }
8561151
857
- int maxcount;
1152
+ int maxcount = 128;
8581153 int transformcount;
8591154 int step;
8601155
....@@ -907,7 +1202,10 @@
9071202 if (step == 0)
9081203 step = 1;
9091204 if (maxcount == 0)
910
- maxcount = 128; // 2048; // 4;
1205
+ {
1206
+ System.out.println("maxcount == 0");
1207
+ System.exit(0); // maxcount = 128; // 2048; // 4;
1208
+ }
9111209 // if (acceleration == 0)
9121210 // acceleration = 10;
9131211 if (delay == 0) // serial
....@@ -933,6 +1231,8 @@
9331231 (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
9341232 currentframe != Globals.framecount)
9351233 {
1234
+ Globals.lighttouched = true;
1235
+
9361236 currentframe = Globals.framecount;
9371237
9381238 // System.err.println("transformcount = " + transformcount);
....@@ -1012,24 +1312,28 @@
10121312 {
10131313 // return true;
10141314
1015
- if (material == null || material.multiply)
1016
- 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;
10171323
1018
- if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
1019
- return false;
1020
-
1021
- // Transparent objects are dynamic because we have to sort the triangles.
1022
- return material.opacity > 0.99;
1324
+ return !sort;
10231325 }
10241326
10251327 boolean IsOpaque()
10261328 {
10271329 // return true;
10281330
1029
- if (material == null || material.multiply)
1030
- return true;
1331
+// if (material == null || material.multiply)
1332
+// return true;
1333
+//
1334
+// return material.opacity > 0.99;
10311335
1032
- return material.opacity > 0.99;
1336
+ return !sort;
10331337 }
10341338
10351339 Object3D()
....@@ -1107,8 +1411,10 @@
11071411
11081412 // will share the geometry
11091413 assert (!(this instanceof Composite));
1110
- return deepCopy(); // Never called for Composite
1111
-
1414
+
1415
+ Object3D obj = deepCopy(); // Never called for Composite
1416
+ obj.count = 2;
1417
+ return obj;
11121418 }
11131419
11141420 boolean HasLoops()
....@@ -1116,6 +1422,30 @@
11161422 return false;
11171423 }
11181424
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
+
11191449 boolean IsInfinite()
11201450 {
11211451 if (blockloop)
....@@ -1186,78 +1516,16 @@
11861516 return;
11871517
11881518 blockloop = true;
1519
+
1520
+ // other.parent = parent;
1521
+
11891522 //System.out.println("COPY " + this + " to " + other);
11901523 //new Exception().printStackTrace();
1524
+ deepCopyNode(other);
11911525
1192
- other.parent = parent;
1193
- if (toParent != null)
1194
- {
1195
- other.toParent = LA.newMatrix();
1196
- other.fromParent = LA.newMatrix();
1197
- LA.matCopy(toParent, other.toParent);
1198
- LA.matCopy(fromParent, other.fromParent);
1199
- if (toParentMarked != null)
1200
- {
1201
- other.toParentMarked = LA.newMatrix();
1202
- other.fromParentMarked = LA.newMatrix();
1203
- LA.matCopy(toParentMarked, other.toParentMarked);
1204
- LA.matCopy(fromParentMarked, other.fromParentMarked);
1205
- }
1206
- }
1207
- else
1208
- {
1209
- if (other.toParent == null)
1210
-// assert(other.toParent == null);
1211
-// new Exception().printStackTrace();
1212
- System.err.println("null parent: " + other);
1213
- }
1214
- /*
1215
- double ident[][] = LA.newMatrix();
1216
- if (bRep == null)
1217
- other.bRep = null;
1218
- else
1219
- other.bRep = new BoundaryRep(bRep, ident);
1220
- */
1221
- // Really new...
12221526 other.bRep = bRep; // Share the geometry
12231527
12241528 other.support = support; // Share the support
1225
-
1226
- //other.editWindow = null;
1227
- if (name == null)
1228
- other.name = null;
1229
- else
1230
- other.name = new String(name);
1231
-
1232
- if (material != null)
1233
- {
1234
- other.material = new cMaterial(material);
1235
- } else
1236
- {
1237
- other.material = null;
1238
- }
1239
-
1240
- other.GetTextures().name = GetTextures().name;
1241
-
1242
- CopyExtraMaterial(other);
1243
-
1244
- other.touched = touched;
1245
- other.softtouched = softtouched;
1246
-
1247
- other.random = random;
1248
- other.link2master = link2master;
1249
- other.transformcount = transformcount;
1250
- other.marked = marked;
1251
- other.skip = skip;
1252
- other.count = count;
1253
- other.flipV = flipV;
1254
- other.live = live;
1255
- other.rewind = rewind;
1256
- other.hide = hide;
1257
- other.texres = texres;
1258
- other.speedup = speedup;
1259
- other.height = height;
1260
- other.depth = depth;
12611529
12621530 // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist)
12631531 // {
....@@ -1285,7 +1553,7 @@
12851553 Object3D obj = (Object3D)Children().get(i);
12861554 if (IsContainedIn(obj))
12871555 {
1288
-// assert(false); // ?!?!?!?!?!
1556
+ assert(false); // ?!?!?!?!?!
12891557 c.Children().setElementAt(c, i);
12901558 }
12911559 else
....@@ -1313,17 +1581,24 @@
13131581 if ((mask & GEOMETRY) != 0)
13141582 {
13151583 if (bRep != null)
1316
- bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
1317
- else
1318
- assert(other.bRep == null);
1319
-
1320
- if (bRep != null)
13211584 {
1585
+ bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep);
13221586 CameraPane.RemoveList(bRep.displaylist);
13231587 bRep.displaylist = 0; // june 2013 -1;
13241588 }
13251589 else
1326
- 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;
13271602 }
13281603
13291604 /* Use a MASK = GEO/MAT
....@@ -2299,11 +2574,6 @@
22992574
23002575 InitOthers();
23012576
2302
- if (this instanceof Camera)
2303
- {
2304
- material.shift = 90;
2305
- }
2306
-
23072577 material.multiply = multiply;
23082578
23092579 if (multiply)
....@@ -2381,7 +2651,7 @@
23812651 return b;
23822652 }
23832653
2384
- void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate)
2654
+ void UpdateMaterial(cMaterial anchor, cMaterial current, boolean propagate, boolean colorparallax)
23852655 {
23862656 if (blockloop)
23872657 {
....@@ -2391,7 +2661,7 @@
23912661 // super.UpdateMaterial(anchor, current, false);
23922662 if (material != null)
23932663 {
2394
- material.UpdateMaterial(anchor, current);
2664
+ material.UpdateMaterial(anchor, current, colorparallax);
23952665 }
23962666
23972667 if (!propagate)
....@@ -2405,7 +2675,7 @@
24052675 if (child == null)
24062676 continue;
24072677 blockloop = true;
2408
- child.UpdateMaterial(anchor, current, propagate);
2678
+ child.UpdateMaterial(anchor, current, propagate, false);
24092679 blockloop = false;
24102680 Children().release(i);
24112681 }
....@@ -2419,7 +2689,7 @@
24192689 if (child == null)
24202690 continue;
24212691 blockloop = true;
2422
- child.UpdateMaterial(anchor, current, propagate);
2692
+ child.UpdateMaterial(anchor, current, propagate, false);
24232693 blockloop = false;
24242694 Children().release(i);
24252695 }
....@@ -2444,6 +2714,11 @@
24442714 else
24452715 {
24462716 //((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");
24472722 }
24482723 }
24492724
....@@ -3119,7 +3394,10 @@
31193394 {
31203395 if (bRep != null)
31213396 {
3397
+ //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact).
31223398 bRep.GenerateNormals(crease);
3399
+ if (!bRep.trimmed)
3400
+ bRep.MergeNormals();
31233401 Touch();
31243402 }
31253403 }
....@@ -3194,6 +3472,105 @@
31943472 blockloop = false;
31953473 }
31963474
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
+
31973574 void TransformChildren()
31983575 {
31993576 if (toParent != null)
....@@ -3436,6 +3813,7 @@
34363813 if (bRep != null)
34373814 {
34383815 //bRep.RemoveOneTriangle();
3816
+ System.out.println();
34393817 System.out.println("Reducing " + this);
34403818 if (name != null && name.contains("lockpickstraps"))
34413819 name = name;
....@@ -3547,15 +3925,47 @@
35473925
35483926 void ClearMaterials()
35493927 {
3928
+ if (blockloop)
3929
+ return;
3930
+
3931
+ blockloop = true;
3932
+
35503933 ClearMaterial();
3551
- for (int i = 0; i < size(); i++)
3934
+ for (int i = 0; i < Size(); i++)
35523935 {
3553
- Object3D child = (Object3D) reserve(i);
3936
+ Object3D child = (Object3D) get(i);
35543937 if (child == null)
35553938 continue;
35563939 child.ClearMaterials();
3557
- release(i);
35583940 }
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;
35593969 }
35603970
35613971 void FlipV(boolean flip)
....@@ -3734,6 +4144,7 @@
37344144
37354145 void RevertMeshes()
37364146 {
4147
+ // BLOCKLOOP
37374148 if (this instanceof cMesh)
37384149 {
37394150 ((cMesh)this).Revert();
....@@ -3764,11 +4175,6 @@
37644175 Touch();
37654176 }
37664177
3767
- ResetRecur();
3768
- }
3769
-
3770
- void ResetRecur()
3771
- {
37724178 for (int i = 0; i < size(); i++)
37734179 {
37744180 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3791,11 +4197,6 @@
37914197 Step();
37924198 Touch();
37934199
3794
- StepRecur();
3795
- }
3796
-
3797
- void StepRecur()
3798
- {
37994200 for (int i = 0; i < size(); i++)
38004201 {
38014202 Object3D child = (Object3D) get(i); // reserve(i);
....@@ -3982,8 +4383,8 @@
39824383 Touch();
39834384 }
39844385
3985
- transient cVector min = new cVector();
3986
- transient cVector max = new cVector();
4386
+ transient cVector min;
4387
+ transient cVector max;
39874388
39884389 void getBounds(cVector minima, cVector maxima, boolean xform)
39894390 {
....@@ -3999,15 +4400,15 @@
39994400 if (blockloop)
40004401 return;
40014402
4002
- if (min == null) // ???
4403
+ if (min == null)
40034404 {
40044405 min = new cVector();
40054406 max = new cVector();
40064407 }
40074408
4008
- for (int i = 0; i<size(); i++)
4409
+ for (int i = 0; i<Size(); i++)
40094410 {
4010
- Object3D child = (Object3D) reserve(i);
4411
+ Object3D child = (Object3D) get(i); //reserve(i);
40114412 if (child == null)
40124413 continue;
40134414
....@@ -4026,21 +4427,21 @@
40264427 if (child.hide && !(child instanceof Merge) || child.skip)
40274428 //if (child.hide)
40284429 {
4029
- release(i);
4430
+ //release(i);
40304431 continue;
40314432 }
40324433
40334434 blockloop = true;
40344435 child.getBounds(min, max, true); // xform);
40354436 blockloop = false;
4036
- release(i);
4437
+ //release(i);
40374438
40384439 MinMax(minima, maxima);
40394440 }
40404441
40414442 if (bRep != null)
40424443 {
4043
- bRep.getBounds(minima,maxima,this);
4444
+ bRep.getBounds(minima, maxima, xform?this:null);
40444445 }
40454446
40464447 if (false) // xform)
....@@ -5313,8 +5714,9 @@
53135714 {
53145715 }
53155716 // transient int displaylist = 0; // -1;
5316
- transient boolean touched = true;
5317
- 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
53185720
53195721 void Touch()
53205722 {
....@@ -5367,6 +5769,7 @@
53675769 {
53685770 //System.out.println("HardTouch " + this); // new Exception().printStackTrace();
53695771 //new Exception().printStackTrace();
5772
+ reset = true;
53705773 touched = true;
53715774 CameraPane.touched = true;
53725775 //if (parent != null)
....@@ -5545,6 +5948,11 @@
55455948 if (fullname == null)
55465949 return "";
55475950
5951
+ if (fullname.pigment != null)
5952
+ {
5953
+ return fullname.pigment;
5954
+ }
5955
+
55485956 // System.out.println("Fullname = " + fullname);
55495957
55505958 // Does not work on Windows due to C:
....@@ -5557,7 +5965,7 @@
55575965
55585966 if (split.length == 0)
55595967 {
5560
- return "";
5968
+ return fullname.pigment = "";
55615969 }
55625970
55635971 if (split.length <= 2)
....@@ -5565,22 +5973,27 @@
55655973 if (fullname.name.endsWith(":"))
55665974 {
55675975 // Windows
5568
- return fullname.name.substring(0, fullname.name.length()-1);
5976
+ return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1);
55695977 }
55705978
5571
- return split[0];
5979
+ return fullname.pigment = split[0];
55725980 }
55735981
55745982 // Windows
55755983 assert(split.length == 4);
55765984
5577
- return split[0] + ":" + split[1];
5985
+ return fullname.pigment = split[0] + ":" + split[1];
55785986 }
55795987
55805988 static String GetBump(cTexture fullname)
55815989 {
55825990 if (fullname == null)
55835991 return "";
5992
+
5993
+ if (fullname.bump != null)
5994
+ {
5995
+ return fullname.bump;
5996
+ }
55845997
55855998 // System.out.println("Fullname = " + fullname);
55865999 // Does not work on Windows due to C:
....@@ -5592,12 +6005,12 @@
55926005
55936006 if (split.length == 0)
55946007 {
5595
- return "";
6008
+ return fullname.bump = "";
55966009 }
55976010
55986011 if (split.length == 1)
55996012 {
5600
- return "";
6013
+ return fullname.bump = "";
56016014 }
56026015
56036016 if (split.length == 2)
....@@ -5605,16 +6018,16 @@
56056018 if (fullname.name.endsWith(":"))
56066019 {
56076020 // Windows
5608
- return "";
6021
+ return fullname.bump = "";
56096022 }
56106023
5611
- return split[1];
6024
+ return fullname.bump = split[1];
56126025 }
56136026
56146027 // Windows
56156028 assert(split.length == 4);
56166029
5617
- return split[2] + ":" + split[3];
6030
+ return fullname.bump = split[2] + ":" + split[3];
56186031 }
56196032
56206033 String GetPigmentTexture()
....@@ -5697,6 +6110,9 @@
56976110 texname = "";
56986111
56996112 GetTextures().name = texname + ":" + GetBump(GetTextures());
6113
+
6114
+ GetTextures().pigment = null;
6115
+
57006116 Touch();
57016117 }
57026118
....@@ -5770,6 +6186,8 @@
57706186
57716187 GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname;
57726188
6189
+ GetTextures().bump = null;
6190
+
57736191 Touch();
57746192 }
57756193
....@@ -5834,7 +6252,7 @@
58346252 boolean NeedSupport()
58356253 {
58366254 return
5837
- 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
58386256 // PROBLEM with CROWD!!
58396257 && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
58406258 }
....@@ -5852,6 +6270,22 @@
58526270 return parent.IsLive();
58536271 }
58546272
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
+
58556289 void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
58566290 {
58576291 Invariants(); // june 2013
....@@ -5859,6 +6293,29 @@
58596293 if (support != null)
58606294 {
58616295 // 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
+ }
58626319 }
58636320
58646321 if (display.DrawMode() == iCameraPane.SELECTION &&
....@@ -5912,8 +6369,10 @@
59126369 if (support != null)
59136370 support = support;
59146371
5915
- boolean usecalllists = !IsLive() && IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
5916
- //boolean usecalllists = false; //!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);
59176376
59186377 //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
59196378
....@@ -5923,7 +6382,8 @@
59236382 bRep.displaylist = 0;
59246383 }
59256384 // usecalllists &= !(parent instanceof RandomNode);
5926
- // usecalllists = false;
6385
+ if (CameraPane.BOXMODE) // Too dynamic
6386
+ usecalllists = false;
59276387
59286388 if (display.DrawMode() == display.SHADOW)
59296389 //GetBRep() != null)
....@@ -5937,7 +6397,7 @@
59376397
59386398 if (!selectmode && //display.DrawMode() != display.SELECTION &&
59396399 //(touched || (bRep != null && bRep.displaylist <= 0)))
5940
- (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
6400
+ ((Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE) || touched)) // || (bRep != null && bRep.displaylist <= 0)))
59416401 {
59426402 Globals.lighttouched = true;
59436403 } // all panes...
....@@ -5966,7 +6426,9 @@
59666426 display.NewList(bRep.displaylist);
59676427 }
59686428
6429
+ compiling = true;
59696430 CallList(display, root, selected, blocked);
6431
+ compiling = false;
59706432
59716433 // compiled = true;
59726434 if (usecalllists && bRep.displaylist > 0)
....@@ -5979,8 +6441,8 @@
59796441 Globals.lighttouched = true; // all panes...
59806442 }
59816443
5982
- touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
5983
- //touched = false;
6444
+ //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false;
6445
+ touched = false;
59846446
59856447 if (this instanceof Texture || this instanceof TextureNode)
59866448 {
....@@ -6019,7 +6481,7 @@
60196481 {
60206482 if (display.DrawMode() == iCameraPane.SHADOW)
60216483 {
6022
- if (!link2master // tricky to cull in shadow mode.
6484
+ if (!Link2Support() // tricky to cull in shadow mode.
60236485 && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
60246486 {
60256487 //System.out.print("CULLED");
....@@ -6081,6 +6543,20 @@
60816543 {
60826544 drawSelf(display, root, selected, blocked);
60836545 }
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
+// }
60846560 } else
60856561 {
60866562 /*
....@@ -6113,13 +6589,14 @@
61136589 boolean failedPigment = false;
61146590 boolean failedBump = false;
61156591
6592
+ CameraPane.lastObject = this;
61166593 try
61176594 {
61186595 display.BindPigmentTexture(tex, texres);
61196596 }
61206597 catch (Exception e)
61216598 {
6122
- System.err.println("FAILED: " + this);
6599
+ // System.err.println("FAILED: " + this);
61236600 failedPigment = true;
61246601 }
61256602
....@@ -6150,6 +6627,20 @@
61506627 display.CallList(bRep.displaylist);
61516628 // june 2013 drawSelf(display, root, selected);
61526629 }
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
+// }
61536644 }
61546645 }
61556646
....@@ -6203,16 +6694,17 @@
62036694
62046695 void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
62056696 {
6206
- if (GetBRep() == null)
6207
- {
6208
- drawSelf(display, root, selected, blocked);
6209
- } else
6697
+ if (GetBRep() != null)
62106698 {
62116699 DrawNode(display, root, selected);
62126700 if (this instanceof BezierPatch)
62136701 {
62146702 //drawSelf(display, root, selected);
62156703 }
6704
+ }
6705
+ else
6706
+ {
6707
+ drawSelf(display, root, selected, blocked);
62166708 }
62176709 }
62186710
....@@ -6411,15 +6903,18 @@
64116903
64126904 void DrawNode(iCameraPane display, Object3D /*Composite*/ root, boolean selected)
64136905 {
6414
- if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000)
6415
- return; // no shadow for transparent objects
6416
-
6417
- if (display.DrawMode() == iCameraPane.SELECTION && dontselect)
6418
- 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
+ }
64196914
64206915 if (hide)
64216916 return;
6422
-
6917
+
64236918 if (scriptnode != null)
64246919 {
64256920 scriptnode.DrawNode(display, root, selected);
....@@ -6462,7 +6957,8 @@
64626957
64636958 //javax.media.opengl.GL gl = display.GetGL();
64646959
6465
- if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
6960
+ if (CameraPane.BOXMODE && !Link2Support()) //
6961
+ //!selected) // || CameraPane.movingcamera)
64666962 {
64676963 int fc = bRep.FaceCount();
64686964 int vc = bRep.VertexCount();
....@@ -6624,7 +7120,7 @@
66247120 facescompare[k] = new FaceCompare(k);
66257121 }
66267122
6627
- center = new cVector();
7123
+ centertriangle = new cVector();
66287124 }
66297125 else
66307126 {
....@@ -6747,7 +7243,7 @@
67477243 */
67487244 }
67497245
6750
- transient cVector center;
7246
+ transient cVector centertriangle;
67517247
67527248 class FaceCompare implements Comparable
67537249 {
....@@ -6776,14 +7272,14 @@
67767272 Vertex q = bRep.GetVertex(face.q);
67777273 Vertex r = bRep.GetVertex(face.r);
67787274
6779
- center.set(p);
6780
- center.add(q);
6781
- center.add(r);
6782
- center.mul(1.0/3);
7275
+ centertriangle.set(p);
7276
+ centertriangle.add(q);
7277
+ centertriangle.add(r);
7278
+ centertriangle.mul(1.0/3);
67837279
6784
- center.sub(Globals.theRenderer.EyeCamera().location);
7280
+ centertriangle.sub(Globals.theRenderer.EyeCamera().location);
67857281
6786
- distance = center.dot(center);
7282
+ distance = centertriangle.dot(centertriangle);
67877283 }
67887284
67897285 return distance;
....@@ -7373,7 +7869,7 @@
73737869 boundary.y = spot.y - 30;
73747870 boundary.width = spot.width + 60;
73757871 boundary.height = spot.height + 60;
7376
- clickInfo.g.setColor(Color.red);
7872
+ clickInfo.g.setColor(Color.white);
73777873 int spotw = spot.x + spot.width;
73787874 int spoth = spot.y + spot.height;
73797875 clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
....@@ -7393,7 +7889,29 @@
73937889 // {
73947890 // CameraPane.Ymax = spoth;
73957891 // }
7396
- 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);
73977915 spotw = spot.x + spot.width;
73987916 spoth = spot.y + spot.height;
73997917 clickInfo.g.setColor(Color.cyan);
....@@ -7414,28 +7932,7 @@
74147932 // {
74157933 // CameraPane.Ymax = spoth;
74167934 // }
7417
- // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
7418
- //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
7419
- spot.translate(0, -32);
7420
- clickInfo.g.setColor(Color.yellow);
7421
- clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
74227935 clickInfo.g.setColor(Color.green);
7423
-// if (CameraPane.Xmin > spot.x)
7424
-// {
7425
-// CameraPane.Xmin = spot.x;
7426
-// }
7427
-// if (CameraPane.Xmax < spotw)
7428
-// {
7429
-// CameraPane.Xmax = spotw;
7430
-// }
7431
-// if (CameraPane.Ymin > spot.y)
7432
-// {
7433
-// CameraPane.Ymin = spot.y;
7434
-// }
7435
-// if (CameraPane.Ymax < spoth)
7436
-// {
7437
-// CameraPane.Ymax = spoth;
7438
-// }
74397936 clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY,
74407937 (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360);
74417938 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
....@@ -7494,12 +7991,14 @@
74947991 retval = true;
74957992 }
74967993 spot.translate(0, 32);
7994
+ spot.translate(32, 0);
7995
+ spot.translate(0, 32);
74977996 if (spot.contains(clickInfo.x, clickInfo.y))
74987997 {
74997998 hitSomething = hitScale;
75007999
75018000 double scale = 0.005f * clickInfo.camera.Distance();
7502
- double hScale = (double) (clickInfo.x - centerPt.x) / 32;
8001
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
75038002 double sign = 1;
75048003 if (hScale < 0)
75058004 {
....@@ -7511,7 +8010,7 @@
75118010 //hScale = 0.01;
75128011 }
75138012
7514
- double vScale = (double) (clickInfo.y - centerPt.y) / 32;
8013
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
75158014 sign = 1;
75168015 if (vScale < 0)
75178016 {
....@@ -7591,7 +8090,9 @@
75918090
75928091 scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance();
75938092
7594
- if (modified || opposite)
8093
+ // Modified could snap
8094
+ if (//modified ||
8095
+ opposite)
75958096 {
75968097 //assert(false);
75978098 /*
....@@ -7685,7 +8186,7 @@
76858186
76868187 if (modified)
76878188 {
7688
- // Rotate 90 degrees
8189
+ // Rotate 45 degrees
76898190 angle /= (Math.PI / 4);
76908191 angle = Math.floor(angle + 0.5);
76918192 angle *= (Math.PI / 4);
....@@ -7726,7 +8227,7 @@
77268227 break;
77278228
77288229 case hitScale: // scale
7729
- double hScale = (double) (clickInfo.x - centerPt.x) / 32;
8230
+ double hScale = (double) (clickInfo.x - centerPt.x) / 64;
77308231 double sign = 1;
77318232 if (hScale < 0)
77328233 {
....@@ -7738,7 +8239,7 @@
77388239 //hScale = 0.01;
77398240 }
77408241
7741
- double vScale = (double) (clickInfo.y - centerPt.y) / 32;
8242
+ double vScale = (double) (clickInfo.y - centerPt.y) / 64;
77428243 sign = 1;
77438244 if (vScale < 0)
77448245 {
....@@ -7771,21 +8272,27 @@
77718272 case 3: // '\001'
77728273 if (modified || opposite)
77738274 {
8275
+ if (modified) // && opposite)
8276
+ LA.matScale(toParent, totalScale, totalScale, totalScale);
8277
+ else
77748278 //LA.matScale(toParent, 1, hScale, vScale);
7775
- LA.matScale(toParent, totalScale, 1, 1);
8279
+ LA.matScale(toParent, totalScale, 1, 1);
77768280 } // vScale, 1);
77778281 else
77788282 {
77798283 // EXCEPTION!
7780
- LA.matScale(toParent, totalScale, totalScale, totalScale);
8284
+ LA.matScale(toParent, 1, totalScale, totalScale);
77818285 } // vScale, 1);
77828286 break;
77838287
77848288 case 2: // '\002'
77858289 if (modified || opposite)
77868290 {
7787
- //LA.matScale(toParent, hScale, 1, vScale);
7788
- 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);
77898296 } else
77908297 {
77918298 LA.matScale(toParent, totalScale, 1, totalScale);
....@@ -7795,8 +8302,11 @@
77958302 case 1: // '\003'
77968303 if (modified || opposite)
77978304 {
7798
- //LA.matScale(toParent, hScale, vScale, 1);
7799
- 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);
78008310 } else
78018311 {
78028312 LA.matScale(toParent, totalScale, totalScale, 1);
....@@ -7940,19 +8450,19 @@
79408450 objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")";
79418451 } else
79428452 {
7943
- 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) ":"") */ "";
79448454 } // + super.toString();
79458455 //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName();
79468456
79478457 if (!Globals.ADVANCED)
79488458 return objname;
79498459
7950
- return objname + " " + System.identityHashCode(this);
8460
+ return objname + " " + System.identityHashCode(this) + " " + GetUUID();
79518461 }
79528462
79538463 public int hashCode()
79548464 {
7955
- // Fuck Vector...
8465
+ // Do not use Vector...
79568466 return System.identityHashCode(this);
79578467 }
79588468
....@@ -8192,8 +8702,8 @@
81928702 private static cVector2 qq2 = new cVector2();
81938703 private static cVector2 rr2 = new cVector2();
81948704 private static cVector2 ss2 = new cVector2();
8195
- private static cVector edge1 = new cVector();
8196
- private static cVector edge2 = new cVector();
8705
+// private static cVector edge1 = new cVector();
8706
+// private static cVector edge2 = new cVector();
81978707 //private static cVector norm = new cVector();
81988708 /*transient private*/ int hitSomething;
81998709 static final int hitCenter = 1;
....@@ -8391,7 +8901,275 @@
83918901
83928902 Touch();
83938903 }
8904
+
8905
+ static Vertex s1 = new Vertex();
8906
+ static Vertex s2 = new Vertex();
8907
+ static Vertex s3 = new Vertex();
83948908
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
+ }
83959173
83969174 public int Size()
83979175 {
....@@ -8488,5 +9266,17 @@
84889266 return -1;
84899267 }
84909268 */
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
+ }
84919281 }
84929282