.. | .. |
---|
22 | 22 | //static final long serialVersionUID = -607422624994562685L; |
---|
23 | 23 | static final long serialVersionUID = 5022536242724664900L; |
---|
24 | 24 | |
---|
| 25 | + // Use GetUUID for backward compatibility with null. |
---|
25 | 26 | private UUID uuid = UUID.randomUUID(); |
---|
26 | 27 | |
---|
27 | | - // TEMPORARY for mocap undo. No need to be transient. |
---|
| 28 | + // TEMPORARY for versions. No need to be transient. |
---|
28 | 29 | mocap.reader.BVHReader.BVHResult savebvh; |
---|
29 | 30 | Object3D saveskeleton; |
---|
| 31 | + |
---|
| 32 | + // FileObject |
---|
| 33 | + Object3D savefilecontent; |
---|
30 | 34 | // |
---|
31 | 35 | |
---|
32 | | - byte[] versions[] = new byte[100][]; |
---|
| 36 | + String skyboxname; |
---|
| 37 | + String skyboxext; |
---|
| 38 | + |
---|
| 39 | + Object3D[] versionlist; |
---|
33 | 40 | int versionindex = -1; |
---|
34 | 41 | |
---|
| 42 | + java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>(); |
---|
| 43 | + |
---|
| 44 | + int tabIndex; |
---|
| 45 | + |
---|
35 | 46 | ScriptNode scriptnode; |
---|
36 | 47 | |
---|
| 48 | + void deepCopyNode(Object3D other) |
---|
| 49 | + { |
---|
| 50 | + other.skyboxname = skyboxname; |
---|
| 51 | + other.skyboxext = skyboxext; |
---|
| 52 | + |
---|
| 53 | + if (toParent != null) |
---|
| 54 | + { |
---|
| 55 | + other.toParent = LA.newMatrix(); |
---|
| 56 | + other.fromParent = LA.newMatrix(); |
---|
| 57 | + LA.matCopy(toParent, other.toParent); |
---|
| 58 | + LA.matCopy(fromParent, other.fromParent); |
---|
| 59 | + if (toParentMarked != null) |
---|
| 60 | + { |
---|
| 61 | + other.toParentMarked = LA.newMatrix(); |
---|
| 62 | + other.fromParentMarked = LA.newMatrix(); |
---|
| 63 | + LA.matCopy(toParentMarked, other.toParentMarked); |
---|
| 64 | + LA.matCopy(fromParentMarked, other.fromParentMarked); |
---|
| 65 | + } |
---|
| 66 | + } |
---|
| 67 | + else |
---|
| 68 | + { |
---|
| 69 | + if (other.toParent == null) |
---|
| 70 | +// assert(other.toParent == null); |
---|
| 71 | +// new Exception().printStackTrace(); |
---|
| 72 | + System.err.println("null parent: " + other); |
---|
| 73 | + } |
---|
| 74 | + |
---|
| 75 | + /* |
---|
| 76 | + double ident[][] = LA.newMatrix(); |
---|
| 77 | + if (bRep == null) |
---|
| 78 | + other.bRep = null; |
---|
| 79 | + else |
---|
| 80 | + other.bRep = new BoundaryRep(bRep, ident); |
---|
| 81 | + */ |
---|
| 82 | + // Really new... |
---|
| 83 | + //other.editWindow = null; |
---|
| 84 | + if (name == null) |
---|
| 85 | + other.name = null; |
---|
| 86 | + else |
---|
| 87 | + other.name = new String(name); |
---|
| 88 | + |
---|
| 89 | + if (material != null) |
---|
| 90 | + { |
---|
| 91 | + other.material = new cMaterial(material); |
---|
| 92 | + } else |
---|
| 93 | + { |
---|
| 94 | + other.material = null; |
---|
| 95 | + } |
---|
| 96 | + |
---|
| 97 | + other.GetTextures().name = GetTextures().name; |
---|
| 98 | + |
---|
| 99 | + CopyExtraMaterial(other); |
---|
| 100 | + |
---|
| 101 | + other.touched = touched; |
---|
| 102 | + other.softtouched = softtouched; |
---|
| 103 | + |
---|
| 104 | + other.random = random; |
---|
| 105 | + other.link2master = Link2Support(); |
---|
| 106 | + other.transformcount = transformcount; |
---|
| 107 | + other.marked = marked; |
---|
| 108 | + other.skip = skip; |
---|
| 109 | + other.count = count; |
---|
| 110 | + other.flipV = flipV; |
---|
| 111 | + other.live = live; |
---|
| 112 | + other.rewind = rewind; |
---|
| 113 | + other.hide = hide; |
---|
| 114 | + other.texres = texres; |
---|
| 115 | + other.speedup = speedup; |
---|
| 116 | + other.height = height; |
---|
| 117 | + other.depth = depth; |
---|
| 118 | + } |
---|
| 119 | + |
---|
| 120 | + int VersionCount() |
---|
| 121 | + { |
---|
| 122 | + int count = 0; |
---|
| 123 | + |
---|
| 124 | + if (versionlist != null) |
---|
| 125 | + for (int i = versionlist.length; --i >= 0;) |
---|
| 126 | + { |
---|
| 127 | + if (versionlist[i] != null) |
---|
| 128 | + count++; |
---|
| 129 | + } |
---|
| 130 | + |
---|
| 131 | + return count; |
---|
| 132 | + } |
---|
| 133 | + |
---|
37 | 134 | void InitOthers() |
---|
38 | 135 | { |
---|
39 | 136 | if (projectedVertices == null || projectedVertices.length <= 2) |
---|
.. | .. |
---|
45 | 142 | projectedVertices[i] = new cVector2(); // Others |
---|
46 | 143 | } |
---|
47 | 144 | projectedVertices[0].x = 100; // bump |
---|
| 145 | + projectedVertices[1].y = 1000; // punchthrough. only for png |
---|
48 | 146 | } |
---|
49 | 147 | |
---|
50 | 148 | void MinMax(cVector minima, cVector maxima) |
---|
.. | .. |
---|
124 | 222 | return; |
---|
125 | 223 | |
---|
126 | 224 | transientsupport = support; |
---|
127 | | - transientlink2master = link2master; |
---|
| 225 | + transientlink2master = Link2Support(); |
---|
128 | 226 | |
---|
129 | 227 | support = null; |
---|
130 | 228 | link2master = false; |
---|
.. | .. |
---|
171 | 269 | } |
---|
172 | 270 | } |
---|
173 | 271 | |
---|
| 272 | + boolean HasBigData() |
---|
| 273 | + { |
---|
| 274 | + if (blockloop) |
---|
| 275 | + return false; |
---|
| 276 | + |
---|
| 277 | + if (bRep != null) |
---|
| 278 | + { |
---|
| 279 | + return true; |
---|
| 280 | + } |
---|
| 281 | + |
---|
| 282 | + blockloop = true; |
---|
| 283 | + |
---|
| 284 | + for (int i = 0; i < Size(); i++) |
---|
| 285 | + { |
---|
| 286 | + Object3D child = (Object3D) get(i); |
---|
| 287 | + if (child == null) |
---|
| 288 | + continue; |
---|
| 289 | + if (child.HasBigData()) |
---|
| 290 | + { |
---|
| 291 | + blockloop = false; |
---|
| 292 | + return true; |
---|
| 293 | + } |
---|
| 294 | + } |
---|
| 295 | + |
---|
| 296 | + blockloop = false; |
---|
| 297 | + return false; |
---|
| 298 | + } |
---|
| 299 | + |
---|
174 | 300 | void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable) |
---|
175 | 301 | { |
---|
| 302 | + if (blockloop) |
---|
| 303 | + return; |
---|
| 304 | + |
---|
176 | 305 | Object3D o; |
---|
| 306 | + |
---|
| 307 | + boolean isnew = false; |
---|
177 | 308 | |
---|
178 | 309 | if (hashtable.containsKey(GetUUID())) |
---|
179 | 310 | { |
---|
.. | .. |
---|
187 | 318 | } |
---|
188 | 319 | else |
---|
189 | 320 | { |
---|
| 321 | + isnew = true; |
---|
| 322 | + |
---|
190 | 323 | o = new Object3D("copy of " + this.name); |
---|
191 | 324 | |
---|
192 | 325 | hashtable.put(GetUUID(), o); |
---|
193 | 326 | } |
---|
194 | 327 | |
---|
195 | | - if (!blockloop) |
---|
| 328 | + //if (!blockloop) |
---|
196 | 329 | { |
---|
197 | 330 | blockloop = true; |
---|
198 | 331 | |
---|
.. | .. |
---|
203 | 336 | |
---|
204 | 337 | blockloop = false; |
---|
205 | 338 | } |
---|
206 | | - |
---|
207 | | - ExtractBigData(o); |
---|
| 339 | + |
---|
| 340 | + //if (isnew) |
---|
| 341 | + ExtractBigData(o); |
---|
208 | 342 | } |
---|
209 | 343 | |
---|
210 | 344 | void ExtractBigData(Object3D o) |
---|
211 | 345 | { |
---|
| 346 | + //System.err.println("ExtractBigData : " + this + " --> " + o); |
---|
| 347 | + |
---|
212 | 348 | if (o.bRep != null) |
---|
213 | 349 | Grafreed.Assert(o.bRep == this.bRep); |
---|
214 | 350 | |
---|
.. | .. |
---|
219 | 355 | // o.bRep.support = null; |
---|
220 | 356 | // } |
---|
221 | 357 | o.selection = this.selection; |
---|
222 | | - o.versions = this.versions; |
---|
223 | | - o.versionindex = this.versionindex; |
---|
| 358 | + //o.versionlist = this.versionlist; |
---|
| 359 | + //o.versionindex = this.versionindex; |
---|
224 | 360 | |
---|
225 | 361 | if (this.support != null) |
---|
226 | 362 | { |
---|
.. | .. |
---|
243 | 379 | // this.fileparent = null; |
---|
244 | 380 | } |
---|
245 | 381 | |
---|
| 382 | +// Object3D GetObject(java.util.UUID uuid) |
---|
| 383 | +// { |
---|
| 384 | +// if (this.uuid.equals(uuid)) |
---|
| 385 | +// return this; |
---|
| 386 | +// |
---|
| 387 | +// if (blockloop) |
---|
| 388 | +// return null; |
---|
| 389 | +// |
---|
| 390 | +// blockloop = true; |
---|
| 391 | +// |
---|
| 392 | +// for (int i=0; i<Size(); i++) |
---|
| 393 | +// { |
---|
| 394 | +// Object3D o = get(i).GetObject(uuid); |
---|
| 395 | +// |
---|
| 396 | +// if (o != null) |
---|
| 397 | +// return o; |
---|
| 398 | +// } |
---|
| 399 | +// |
---|
| 400 | +// blockloop = false; |
---|
| 401 | +// |
---|
| 402 | +// return null; |
---|
| 403 | +// } |
---|
| 404 | + |
---|
| 405 | + transient boolean tag; |
---|
| 406 | + |
---|
| 407 | + void TagObjects(Object3D o, boolean tag) |
---|
| 408 | + { |
---|
| 409 | + if (blockloop) |
---|
| 410 | + return; |
---|
| 411 | + |
---|
| 412 | + o.tag = tag; |
---|
| 413 | + |
---|
| 414 | + if (o == this) |
---|
| 415 | + return; |
---|
| 416 | + |
---|
| 417 | + blockloop = true; |
---|
| 418 | + |
---|
| 419 | + for (int i=0; i<Size(); i++) |
---|
| 420 | + { |
---|
| 421 | + get(i).TagObjects(o, tag); |
---|
| 422 | + } |
---|
| 423 | + |
---|
| 424 | + blockloop = false; |
---|
| 425 | + } |
---|
| 426 | + |
---|
| 427 | + boolean HasTags() |
---|
| 428 | + { |
---|
| 429 | + if (blockloop) |
---|
| 430 | + return false; |
---|
| 431 | + |
---|
| 432 | + blockloop = true; |
---|
| 433 | + |
---|
| 434 | + boolean hasTags = false; |
---|
| 435 | + |
---|
| 436 | + for (int i=0; i<Size(); i++) |
---|
| 437 | + { |
---|
| 438 | + hasTags |= get(i).tag || get(i).HasTags(); |
---|
| 439 | + |
---|
| 440 | + if (hasTags) |
---|
| 441 | + break; |
---|
| 442 | + } |
---|
| 443 | + |
---|
| 444 | + blockloop = false; |
---|
| 445 | + |
---|
| 446 | + return hasTags; |
---|
| 447 | + } |
---|
| 448 | + |
---|
246 | 449 | void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable) |
---|
247 | 450 | { |
---|
| 451 | + if (blockloop) |
---|
| 452 | + return; |
---|
| 453 | + |
---|
248 | 454 | if (!hashtable.containsKey(GetUUID())) |
---|
249 | 455 | return; |
---|
250 | 456 | |
---|
251 | 457 | Object3D o = hashtable.get(GetUUID()); |
---|
252 | 458 | |
---|
253 | 459 | RestoreBigData(o); |
---|
254 | | - |
---|
255 | | - if (blockloop) |
---|
256 | | - return; |
---|
257 | 460 | |
---|
258 | 461 | blockloop = true; |
---|
259 | 462 | |
---|
.. | .. |
---|
269 | 472 | |
---|
270 | 473 | void RestoreBigData(Object3D o) |
---|
271 | 474 | { |
---|
| 475 | + //System.err.println("RestoreBigData : " + this + " <-- " + o); |
---|
| 476 | + Grafreed.Assert(this.bRep == null); |
---|
| 477 | + |
---|
272 | 478 | this.bRep = o.bRep; |
---|
273 | 479 | if (this.support != null && o.transientrep != null) |
---|
274 | 480 | { |
---|
.. | .. |
---|
277 | 483 | |
---|
278 | 484 | this.selection = o.selection; |
---|
279 | 485 | |
---|
280 | | - this.versions = o.versions; |
---|
281 | | - this.versionindex = o.versionindex; |
---|
| 486 | + //this.versionlist = o.versionlist; |
---|
| 487 | + //this.versionindex = o.versionindex; |
---|
282 | 488 | // July 2019 if (this.bRep != null) |
---|
283 | 489 | // this.bRep.support = o.transientrep; |
---|
284 | 490 | // this.support = o.support; |
---|
.. | .. |
---|
426 | 632 | } |
---|
427 | 633 | |
---|
428 | 634 | boolean live = false; |
---|
| 635 | + transient boolean keepdontselect; |
---|
429 | 636 | boolean dontselect = false; |
---|
430 | 637 | boolean hide = false; |
---|
431 | | - boolean link2master = false; // performs reset support/master at each frame |
---|
| 638 | + |
---|
| 639 | + boolean link2master = false; // performs reset support/master at each frame (cannot rename due to serialization) |
---|
| 640 | + boolean link2support = false; // (cannot rename due to serialization) |
---|
| 641 | + |
---|
432 | 642 | boolean marked = false; // animation node |
---|
433 | 643 | boolean skip = false; // centroid issue |
---|
434 | 644 | boolean skipmocap = false; // mocap data |
---|
.. | .. |
---|
436 | 646 | boolean random = false; |
---|
437 | 647 | boolean speedup = false; |
---|
438 | 648 | boolean rewind = false; |
---|
| 649 | + |
---|
| 650 | + // Option to sort triangles, e.g. for transparency. |
---|
| 651 | + boolean sort = false; |
---|
439 | 652 | |
---|
440 | 653 | float NORMALPUSH = 0; |
---|
441 | 654 | |
---|
.. | .. |
---|
454 | 667 | { |
---|
455 | 668 | sorted = true; |
---|
456 | 669 | |
---|
457 | | - for (int i=0; i<size()-1; i++) |
---|
| 670 | + for (int i=0; i<Size()-1; i++) |
---|
458 | 671 | { |
---|
459 | 672 | Object3D obji = get(i); |
---|
460 | 673 | Object3D objj = get(i+1); |
---|
.. | .. |
---|
478 | 691 | { |
---|
479 | 692 | sorted = true; |
---|
480 | 693 | |
---|
481 | | - for (int i=0; i<size()-1; i++) |
---|
| 694 | + for (int i=0; i<Size()-1; i++) |
---|
482 | 695 | { |
---|
483 | 696 | Object3D obji = get(i); |
---|
484 | 697 | Object3D objj = get(i+1); |
---|
.. | .. |
---|
494 | 707 | } |
---|
495 | 708 | } |
---|
496 | 709 | |
---|
497 | | - int memorysize; |
---|
| 710 | + transient int memorysize; // needs to be transient, dunno why |
---|
498 | 711 | |
---|
499 | 712 | int MemorySize() |
---|
500 | 713 | { |
---|
501 | | - if (true) // memorysize == 0) |
---|
| 714 | + if (memorysize == 0) |
---|
502 | 715 | { |
---|
503 | 716 | try |
---|
504 | 717 | { |
---|
.. | .. |
---|
613 | 826 | { |
---|
614 | 827 | if (maxcount != 1) |
---|
615 | 828 | { |
---|
616 | | - new Exception().printStackTrace(); |
---|
| 829 | + //new Exception().printStackTrace(); |
---|
617 | 830 | } |
---|
618 | 831 | |
---|
619 | 832 | toParentMarked = LA.newMatrix(); |
---|
.. | .. |
---|
815 | 1028 | |
---|
816 | 1029 | void Step() |
---|
817 | 1030 | { |
---|
818 | | - // marde pour serialization de Texture |
---|
| 1031 | + // patch pour serialization de Texture |
---|
819 | 1032 | resetmaxcount(); |
---|
820 | 1033 | resettransformcount(); |
---|
821 | 1034 | resetstep(); |
---|
.. | .. |
---|
1008 | 1221 | { |
---|
1009 | 1222 | // return true; |
---|
1010 | 1223 | |
---|
1011 | | - if (material == null || material.multiply) |
---|
1012 | | - return true; |
---|
| 1224 | +// if (material == null || material.multiply) |
---|
| 1225 | +// return true; |
---|
| 1226 | +// |
---|
| 1227 | +// if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000) |
---|
| 1228 | +// return false; |
---|
| 1229 | +// |
---|
| 1230 | +// // Transparent objects are dynamic because we have to sort the triangles. |
---|
| 1231 | +// return material.opacity > 0.99; |
---|
1013 | 1232 | |
---|
1014 | | - // Transparent objects are dynamic because we have to sort the triangles. |
---|
1015 | | - return material.opacity > 0.99; |
---|
| 1233 | + return !sort; |
---|
1016 | 1234 | } |
---|
1017 | 1235 | |
---|
1018 | 1236 | boolean IsOpaque() |
---|
1019 | 1237 | { |
---|
1020 | 1238 | // return true; |
---|
1021 | 1239 | |
---|
1022 | | - if (material == null || material.multiply) |
---|
1023 | | - return true; |
---|
| 1240 | +// if (material == null || material.multiply) |
---|
| 1241 | +// return true; |
---|
| 1242 | +// |
---|
| 1243 | +// return material.opacity > 0.99; |
---|
1024 | 1244 | |
---|
1025 | | - return material.opacity > 0.99; |
---|
| 1245 | + return !sort; |
---|
1026 | 1246 | } |
---|
1027 | 1247 | |
---|
1028 | 1248 | Object3D() |
---|
.. | .. |
---|
1100 | 1320 | |
---|
1101 | 1321 | // will share the geometry |
---|
1102 | 1322 | assert (!(this instanceof Composite)); |
---|
1103 | | - return deepCopy(); // Never called for Composite |
---|
1104 | | - |
---|
| 1323 | + |
---|
| 1324 | + Object3D obj = deepCopy(); // Never called for Composite |
---|
| 1325 | + obj.count = 2; |
---|
| 1326 | + return obj; |
---|
1105 | 1327 | } |
---|
1106 | 1328 | |
---|
1107 | 1329 | boolean HasLoops() |
---|
.. | .. |
---|
1109 | 1331 | return false; |
---|
1110 | 1332 | } |
---|
1111 | 1333 | |
---|
| 1334 | + void ResetUUIDs() |
---|
| 1335 | + { |
---|
| 1336 | + if (blockloop) |
---|
| 1337 | + { |
---|
| 1338 | + return; |
---|
| 1339 | + } |
---|
| 1340 | + |
---|
| 1341 | + this.uuid = null; |
---|
| 1342 | + |
---|
| 1343 | + blockloop = true; |
---|
| 1344 | + |
---|
| 1345 | + for (int i = 0; i < Size(); i++) |
---|
| 1346 | + { |
---|
| 1347 | + Object3D obj = (Object3D) Children().get(i); |
---|
| 1348 | + |
---|
| 1349 | + if (obj != null) |
---|
| 1350 | + { |
---|
| 1351 | + obj.ResetUUIDs(); |
---|
| 1352 | + } |
---|
| 1353 | + } |
---|
| 1354 | + |
---|
| 1355 | + blockloop = false; |
---|
| 1356 | + } |
---|
| 1357 | + |
---|
1112 | 1358 | boolean IsInfinite() |
---|
1113 | 1359 | { |
---|
1114 | 1360 | if (blockloop) |
---|
.. | .. |
---|
1179 | 1425 | return; |
---|
1180 | 1426 | |
---|
1181 | 1427 | blockloop = true; |
---|
| 1428 | + |
---|
| 1429 | + other.parent = parent; |
---|
| 1430 | + |
---|
1182 | 1431 | //System.out.println("COPY " + this + " to " + other); |
---|
1183 | 1432 | //new Exception().printStackTrace(); |
---|
| 1433 | + deepCopyNode(other); |
---|
1184 | 1434 | |
---|
1185 | | - other.parent = parent; |
---|
1186 | | - if (toParent != null) |
---|
1187 | | - { |
---|
1188 | | - other.toParent = LA.newMatrix(); |
---|
1189 | | - other.fromParent = LA.newMatrix(); |
---|
1190 | | - LA.matCopy(toParent, other.toParent); |
---|
1191 | | - LA.matCopy(fromParent, other.fromParent); |
---|
1192 | | - if (toParentMarked != null) |
---|
1193 | | - { |
---|
1194 | | - other.toParentMarked = LA.newMatrix(); |
---|
1195 | | - other.fromParentMarked = LA.newMatrix(); |
---|
1196 | | - LA.matCopy(toParentMarked, other.toParentMarked); |
---|
1197 | | - LA.matCopy(fromParentMarked, other.fromParentMarked); |
---|
1198 | | - } |
---|
1199 | | - } |
---|
1200 | | - else |
---|
1201 | | - { |
---|
1202 | | - if (other.toParent == null) |
---|
1203 | | -// assert(other.toParent == null); |
---|
1204 | | -// new Exception().printStackTrace(); |
---|
1205 | | - System.err.println("null parent: " + other); |
---|
1206 | | - } |
---|
1207 | | - /* |
---|
1208 | | - double ident[][] = LA.newMatrix(); |
---|
1209 | | - if (bRep == null) |
---|
1210 | | - other.bRep = null; |
---|
1211 | | - else |
---|
1212 | | - other.bRep = new BoundaryRep(bRep, ident); |
---|
1213 | | - */ |
---|
1214 | | - // Really new... |
---|
1215 | 1435 | other.bRep = bRep; // Share the geometry |
---|
1216 | 1436 | |
---|
1217 | 1437 | other.support = support; // Share the support |
---|
1218 | | - |
---|
1219 | | - //other.editWindow = null; |
---|
1220 | | - if (name == null) |
---|
1221 | | - other.name = null; |
---|
1222 | | - else |
---|
1223 | | - other.name = new String(name); |
---|
1224 | | - |
---|
1225 | | - if (material != null) |
---|
1226 | | - { |
---|
1227 | | - other.material = new cMaterial(material); |
---|
1228 | | - } else |
---|
1229 | | - { |
---|
1230 | | - other.material = null; |
---|
1231 | | - } |
---|
1232 | | - |
---|
1233 | | - other.GetTextures().name = GetTextures().name; |
---|
1234 | | - |
---|
1235 | | - CopyExtraMaterial(other); |
---|
1236 | | - |
---|
1237 | | - other.touched = touched; |
---|
1238 | | - other.softtouched = softtouched; |
---|
1239 | | - |
---|
1240 | | - other.random = random; |
---|
1241 | | - other.link2master = link2master; |
---|
1242 | | - other.transformcount = transformcount; |
---|
1243 | | - other.marked = marked; |
---|
1244 | | - other.skip = skip; |
---|
1245 | | - other.count = count; |
---|
1246 | | - other.flipV = flipV; |
---|
1247 | | - other.live = live; |
---|
1248 | | - other.rewind = rewind; |
---|
1249 | | - other.hide = hide; |
---|
1250 | | - other.texres = texres; |
---|
1251 | | - other.speedup = speedup; |
---|
1252 | | - other.height = height; |
---|
1253 | | - other.depth = depth; |
---|
1254 | 1438 | |
---|
1255 | 1439 | // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist) |
---|
1256 | 1440 | // { |
---|
.. | .. |
---|
1306 | 1490 | if ((mask & GEOMETRY) != 0) |
---|
1307 | 1491 | { |
---|
1308 | 1492 | if (bRep != null) |
---|
1309 | | - bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep); |
---|
1310 | | - else |
---|
1311 | | - assert(other.bRep == null); |
---|
1312 | | - |
---|
1313 | | - if (bRep != null) |
---|
1314 | 1493 | { |
---|
| 1494 | + bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep); |
---|
1315 | 1495 | CameraPane.RemoveList(bRep.displaylist); |
---|
1316 | 1496 | bRep.displaylist = 0; // june 2013 -1; |
---|
1317 | 1497 | } |
---|
1318 | 1498 | else |
---|
1319 | | - bRep = bRep; |
---|
| 1499 | + { |
---|
| 1500 | + //assert(other.bRep == null); |
---|
| 1501 | + bRep = other.bRep; |
---|
| 1502 | + } |
---|
| 1503 | + |
---|
| 1504 | +// if (bRep != null) |
---|
| 1505 | +// { |
---|
| 1506 | +// CameraPane.RemoveList(bRep.displaylist); |
---|
| 1507 | +// bRep.displaylist = 0; // june 2013 -1; |
---|
| 1508 | +// } |
---|
| 1509 | +// else |
---|
| 1510 | +// bRep = bRep; |
---|
1320 | 1511 | } |
---|
1321 | 1512 | |
---|
1322 | 1513 | /* Use a MASK = GEO/MAT |
---|
.. | .. |
---|
2292 | 2483 | |
---|
2293 | 2484 | InitOthers(); |
---|
2294 | 2485 | |
---|
2295 | | - if (this instanceof Camera) |
---|
2296 | | - { |
---|
2297 | | - material.shift = 90; |
---|
2298 | | - } |
---|
2299 | | - |
---|
2300 | 2486 | material.multiply = multiply; |
---|
2301 | 2487 | |
---|
2302 | 2488 | if (multiply) |
---|
.. | .. |
---|
2437 | 2623 | else |
---|
2438 | 2624 | { |
---|
2439 | 2625 | //((ObjEditor)editWindow).SetupUI2(null); |
---|
| 2626 | + if (objectUI != null) |
---|
| 2627 | + ((ObjEditor)objectUI).pinButton.setSelected(pinned); |
---|
| 2628 | + else |
---|
| 2629 | + //new Exception().printStackTrace(); |
---|
| 2630 | + System.err.println("objectUI is null"); |
---|
2440 | 2631 | } |
---|
2441 | 2632 | } |
---|
2442 | 2633 | |
---|
.. | .. |
---|
2566 | 2757 | private static final int editSelf = 1; |
---|
2567 | 2758 | private static final int editChild = 2; |
---|
2568 | 2759 | |
---|
2569 | | - void drawEditHandles(ClickInfo info, int level) |
---|
| 2760 | + void drawEditHandles(//ClickInfo info, |
---|
| 2761 | + int level) |
---|
2570 | 2762 | { |
---|
2571 | 2763 | if (level == 0) |
---|
2572 | 2764 | { |
---|
.. | .. |
---|
2574 | 2766 | return; |
---|
2575 | 2767 | |
---|
2576 | 2768 | Object3D selectee; |
---|
2577 | | - for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(info, level + 1)) |
---|
| 2769 | + for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(//info, |
---|
| 2770 | + level + 1)) |
---|
2578 | 2771 | { |
---|
2579 | 2772 | selectee = (Object3D) e.nextElement(); |
---|
2580 | 2773 | } |
---|
.. | .. |
---|
2582 | 2775 | } else |
---|
2583 | 2776 | { |
---|
2584 | 2777 | //super. |
---|
2585 | | - drawEditHandles0(info, level + 1); |
---|
| 2778 | + drawEditHandles0(//info, |
---|
| 2779 | + level + 1); |
---|
2586 | 2780 | } |
---|
2587 | 2781 | } |
---|
2588 | 2782 | |
---|
2589 | | - boolean doEditClick(ClickInfo info, int level) |
---|
| 2783 | + boolean doEditClick(//ClickInfo info, |
---|
| 2784 | + int level) |
---|
2590 | 2785 | { |
---|
2591 | 2786 | doSomething = 0; |
---|
2592 | 2787 | if (level == 0) |
---|
2593 | 2788 | { |
---|
2594 | | - return doParentClick(info); |
---|
| 2789 | + return doParentClick(); //info); |
---|
2595 | 2790 | } |
---|
2596 | 2791 | if (//super. |
---|
2597 | | - doEditClick0(info, level)) |
---|
| 2792 | + doEditClick0(//info, |
---|
| 2793 | + level)) |
---|
2598 | 2794 | { |
---|
2599 | 2795 | doSomething = 1; |
---|
2600 | 2796 | return true; |
---|
.. | .. |
---|
2604 | 2800 | } |
---|
2605 | 2801 | } |
---|
2606 | 2802 | |
---|
2607 | | - boolean doParentClick(ClickInfo info) |
---|
| 2803 | + boolean doParentClick() //ClickInfo info) |
---|
2608 | 2804 | { |
---|
2609 | 2805 | if (selection == null) |
---|
2610 | 2806 | { |
---|
.. | .. |
---|
2617 | 2813 | for (java.util.Enumeration e = selection.elements(); e.hasMoreElements();) |
---|
2618 | 2814 | { |
---|
2619 | 2815 | Object3D selectee = (Object3D) e.nextElement(); |
---|
2620 | | - if (selectee.doEditClick(info, 1)) |
---|
| 2816 | + if (selectee.doEditClick(//info, |
---|
| 2817 | + 1)) |
---|
2621 | 2818 | { |
---|
2622 | 2819 | childToDrag = selectee; |
---|
2623 | 2820 | doSomething = 2; |
---|
.. | .. |
---|
2629 | 2826 | return retval; |
---|
2630 | 2827 | } |
---|
2631 | 2828 | |
---|
2632 | | - void doEditDrag(ClickInfo info, boolean opposite) |
---|
| 2829 | + void doEditDrag(//ClickInfo clickInfo, |
---|
| 2830 | + boolean opposite) |
---|
2633 | 2831 | { |
---|
2634 | 2832 | switch (doSomething) |
---|
2635 | 2833 | { |
---|
2636 | 2834 | case 1: // '\001' |
---|
2637 | 2835 | //super. |
---|
2638 | | - doEditDrag0(info, opposite); |
---|
| 2836 | + doEditDrag0(//clickInfo, |
---|
| 2837 | + opposite); |
---|
2639 | 2838 | break; |
---|
2640 | 2839 | |
---|
2641 | 2840 | case 2: // '\002' |
---|
.. | .. |
---|
2648 | 2847 | { |
---|
2649 | 2848 | //sel.hitSomething = childToDrag.hitSomething; |
---|
2650 | 2849 | //childToDrag.doEditDrag(info); |
---|
2651 | | - sel.doEditDrag(info, opposite); |
---|
| 2850 | + sel.doEditDrag(//clickInfo, |
---|
| 2851 | + opposite); |
---|
2652 | 2852 | } else |
---|
2653 | 2853 | { |
---|
2654 | 2854 | //super. |
---|
2655 | | - doEditDrag0(info, opposite); |
---|
| 2855 | + doEditDrag0(//clickInfo, |
---|
| 2856 | + opposite); |
---|
2656 | 2857 | } |
---|
2657 | 2858 | } |
---|
2658 | 2859 | break; |
---|
.. | .. |
---|
2670 | 2871 | { |
---|
2671 | 2872 | deselectAll(); |
---|
2672 | 2873 | } |
---|
| 2874 | + |
---|
| 2875 | + new Exception().printStackTrace(); |
---|
| 2876 | + |
---|
2673 | 2877 | ClickInfo newInfo = new ClickInfo(); |
---|
2674 | 2878 | newInfo.flags = info.flags; |
---|
2675 | 2879 | newInfo.bounds = info.bounds; |
---|
.. | .. |
---|
3099 | 3303 | { |
---|
3100 | 3304 | if (bRep != null) |
---|
3101 | 3305 | { |
---|
| 3306 | + //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact). |
---|
3102 | 3307 | bRep.GenerateNormals(crease); |
---|
| 3308 | + if (!bRep.trimmed) |
---|
| 3309 | + bRep.MergeNormals(); |
---|
3103 | 3310 | Touch(); |
---|
3104 | 3311 | } |
---|
3105 | 3312 | } |
---|
.. | .. |
---|
3117 | 3324 | { |
---|
3118 | 3325 | if (bRep != null) |
---|
3119 | 3326 | { |
---|
3120 | | - bRep.GenerateNormalsMINE(); |
---|
| 3327 | + bRep.MergeNormals(); //.GenerateNormalsMINE(); |
---|
3121 | 3328 | Touch(); |
---|
3122 | 3329 | } |
---|
3123 | 3330 | } |
---|
.. | .. |
---|
3174 | 3381 | blockloop = false; |
---|
3175 | 3382 | } |
---|
3176 | 3383 | |
---|
| 3384 | + public void ResetTransform(int mask) |
---|
| 3385 | + { |
---|
| 3386 | + Object3D obj = this; |
---|
| 3387 | + |
---|
| 3388 | + if (mask == -1) |
---|
| 3389 | + { |
---|
| 3390 | + if (obj instanceof Camera) // jan 2014 |
---|
| 3391 | + { |
---|
| 3392 | + LA.matIdentity(obj.toParent); |
---|
| 3393 | + LA.matIdentity(obj.fromParent); |
---|
| 3394 | + } |
---|
| 3395 | + else |
---|
| 3396 | + { |
---|
| 3397 | + obj.toParent = null; // jan 2014 LA.matIdentity(obj.toParent); |
---|
| 3398 | + obj.fromParent = null; // LA.matIdentity(obj.fromParent); |
---|
| 3399 | + } |
---|
| 3400 | + return; |
---|
| 3401 | + } |
---|
| 3402 | + |
---|
| 3403 | + if ((mask&2) != 0) // Scale/rotation |
---|
| 3404 | + { |
---|
| 3405 | + obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = 1; |
---|
| 3406 | + obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0; |
---|
| 3407 | + obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0; |
---|
| 3408 | + obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1; |
---|
| 3409 | + obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0; |
---|
| 3410 | + obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0; |
---|
| 3411 | + } |
---|
| 3412 | + if ((mask&1) != 0) // Translation |
---|
| 3413 | + { |
---|
| 3414 | + if (obj.toParent != null) |
---|
| 3415 | + { |
---|
| 3416 | + obj.toParent[3][0] = obj.toParent[3][1] = obj.toParent[3][2] = 0; |
---|
| 3417 | + obj.fromParent[3][0] = obj.fromParent[3][1] = obj.fromParent[3][2] = 0; |
---|
| 3418 | + } |
---|
| 3419 | + } |
---|
| 3420 | + } |
---|
| 3421 | + |
---|
| 3422 | + public void Scale(int scale) |
---|
| 3423 | + { |
---|
| 3424 | + Object3D obj = this; |
---|
| 3425 | + |
---|
| 3426 | + obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = scale; |
---|
| 3427 | + obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0; |
---|
| 3428 | + obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0; |
---|
| 3429 | + obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1/scale; |
---|
| 3430 | + obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0; |
---|
| 3431 | + obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0; |
---|
| 3432 | + } |
---|
| 3433 | + |
---|
| 3434 | + public void TextureRatioTransform(int axis) |
---|
| 3435 | + { |
---|
| 3436 | + cTexture tex = GetTextures(); |
---|
| 3437 | + |
---|
| 3438 | + com.sun.opengl.util.texture.TextureData texturedata = null; |
---|
| 3439 | + |
---|
| 3440 | + try |
---|
| 3441 | + { |
---|
| 3442 | + texturedata = Globals.theRenderer.GetTextureData(tex, false, texres); |
---|
| 3443 | + } |
---|
| 3444 | + catch (Exception e) |
---|
| 3445 | + { |
---|
| 3446 | + System.err.println("FAIL TextureRatio: " + this); |
---|
| 3447 | + } |
---|
| 3448 | + |
---|
| 3449 | + LA.matIdentity(Object3D.mat); |
---|
| 3450 | + Object3D.mat[axis][axis] = (double)texturedata.getWidth() / texturedata.getHeight(); |
---|
| 3451 | + |
---|
| 3452 | + if (toParent == null) |
---|
| 3453 | + { |
---|
| 3454 | + toParent = LA.newMatrix(); |
---|
| 3455 | + fromParent = LA.newMatrix(); |
---|
| 3456 | + } |
---|
| 3457 | + |
---|
| 3458 | + ResetTransform(2); |
---|
| 3459 | + |
---|
| 3460 | + LA.matConcat(Object3D.mat, fromParent, fromParent); |
---|
| 3461 | + LA.matInvert(fromParent, toParent); |
---|
| 3462 | + } |
---|
| 3463 | + |
---|
| 3464 | + void TextureRatio(int axis) |
---|
| 3465 | + { |
---|
| 3466 | + if (blockloop) |
---|
| 3467 | + return; |
---|
| 3468 | + |
---|
| 3469 | + blockloop = true; |
---|
| 3470 | + |
---|
| 3471 | + TextureRatioTransform(axis); |
---|
| 3472 | + |
---|
| 3473 | + for (int i=Size(); --i>=0;) |
---|
| 3474 | + { |
---|
| 3475 | + Object3D v = get(i); |
---|
| 3476 | + |
---|
| 3477 | + v.TextureRatio(axis); |
---|
| 3478 | + } |
---|
| 3479 | + |
---|
| 3480 | + blockloop = false; |
---|
| 3481 | + } |
---|
| 3482 | + |
---|
3177 | 3483 | void TransformChildren() |
---|
3178 | 3484 | { |
---|
3179 | 3485 | if (toParent != null) |
---|
.. | .. |
---|
3416 | 3722 | if (bRep != null) |
---|
3417 | 3723 | { |
---|
3418 | 3724 | //bRep.RemoveOneTriangle(); |
---|
| 3725 | + System.out.println(); |
---|
3419 | 3726 | System.out.println("Reducing " + this); |
---|
3420 | 3727 | if (name != null && name.contains("lockpickstraps")) |
---|
3421 | 3728 | name = name; |
---|
.. | .. |
---|
3527 | 3834 | |
---|
3528 | 3835 | void ClearMaterials() |
---|
3529 | 3836 | { |
---|
| 3837 | + if (blockloop) |
---|
| 3838 | + return; |
---|
| 3839 | + |
---|
| 3840 | + blockloop = true; |
---|
| 3841 | + |
---|
3530 | 3842 | ClearMaterial(); |
---|
3531 | | - for (int i = 0; i < size(); i++) |
---|
| 3843 | + for (int i = 0; i < Size(); i++) |
---|
3532 | 3844 | { |
---|
3533 | | - Object3D child = (Object3D) reserve(i); |
---|
| 3845 | + Object3D child = (Object3D) get(i); |
---|
3534 | 3846 | if (child == null) |
---|
3535 | 3847 | continue; |
---|
3536 | 3848 | child.ClearMaterials(); |
---|
3537 | | - release(i); |
---|
3538 | 3849 | } |
---|
| 3850 | + |
---|
| 3851 | + blockloop = false; |
---|
| 3852 | + } |
---|
| 3853 | + |
---|
| 3854 | + void ClearVersionList() |
---|
| 3855 | + { |
---|
| 3856 | + this.versionlist = null; |
---|
| 3857 | + this.versionindex = -1; |
---|
| 3858 | + this.versiontable = null; |
---|
| 3859 | + } |
---|
| 3860 | + |
---|
| 3861 | + void ClearVersions() |
---|
| 3862 | + { |
---|
| 3863 | + if (blockloop) |
---|
| 3864 | + return; |
---|
| 3865 | + |
---|
| 3866 | + blockloop = true; |
---|
| 3867 | + |
---|
| 3868 | + ClearVersionList(); |
---|
| 3869 | + for (int i = 0; i < Size(); i++) |
---|
| 3870 | + { |
---|
| 3871 | + Object3D child = (Object3D) get(i); |
---|
| 3872 | + if (child == null) |
---|
| 3873 | + continue; |
---|
| 3874 | + child.ClearVersions(); |
---|
| 3875 | + } |
---|
| 3876 | + |
---|
| 3877 | + blockloop = false; |
---|
3539 | 3878 | } |
---|
3540 | 3879 | |
---|
3541 | 3880 | void FlipV(boolean flip) |
---|
.. | .. |
---|
3714 | 4053 | |
---|
3715 | 4054 | void RevertMeshes() |
---|
3716 | 4055 | { |
---|
| 4056 | + // BLOCKLOOP |
---|
3717 | 4057 | if (this instanceof cMesh) |
---|
3718 | 4058 | { |
---|
3719 | 4059 | ((cMesh)this).Revert(); |
---|
.. | .. |
---|
3744 | 4084 | Touch(); |
---|
3745 | 4085 | } |
---|
3746 | 4086 | |
---|
3747 | | - ResetRecur(); |
---|
3748 | | - } |
---|
3749 | | - |
---|
3750 | | - void ResetRecur() |
---|
3751 | | - { |
---|
3752 | 4087 | for (int i = 0; i < size(); i++) |
---|
3753 | 4088 | { |
---|
3754 | 4089 | Object3D child = (Object3D) get(i); // reserve(i); |
---|
.. | .. |
---|
3771 | 4106 | Step(); |
---|
3772 | 4107 | Touch(); |
---|
3773 | 4108 | |
---|
3774 | | - StepRecur(); |
---|
3775 | | - } |
---|
3776 | | - |
---|
3777 | | - void StepRecur() |
---|
3778 | | - { |
---|
3779 | 4109 | for (int i = 0; i < size(); i++) |
---|
3780 | 4110 | { |
---|
3781 | 4111 | Object3D child = (Object3D) get(i); // reserve(i); |
---|
.. | .. |
---|
3962 | 4292 | Touch(); |
---|
3963 | 4293 | } |
---|
3964 | 4294 | |
---|
3965 | | - transient cVector min = new cVector(); |
---|
3966 | | - transient cVector max = new cVector(); |
---|
| 4295 | + transient cVector min; |
---|
| 4296 | + transient cVector max; |
---|
3967 | 4297 | |
---|
3968 | 4298 | void getBounds(cVector minima, cVector maxima, boolean xform) |
---|
3969 | 4299 | { |
---|
.. | .. |
---|
3979 | 4309 | if (blockloop) |
---|
3980 | 4310 | return; |
---|
3981 | 4311 | |
---|
3982 | | - if (min == null) // ??? |
---|
| 4312 | + if (min == null) |
---|
3983 | 4313 | { |
---|
3984 | 4314 | min = new cVector(); |
---|
3985 | 4315 | max = new cVector(); |
---|
3986 | 4316 | } |
---|
3987 | 4317 | |
---|
3988 | | - for (int i = 0; i<size(); i++) |
---|
| 4318 | + for (int i = 0; i<Size(); i++) |
---|
3989 | 4319 | { |
---|
3990 | | - Object3D child = (Object3D) reserve(i); |
---|
| 4320 | + Object3D child = (Object3D) get(i); //reserve(i); |
---|
3991 | 4321 | if (child == null) |
---|
3992 | 4322 | continue; |
---|
3993 | 4323 | |
---|
.. | .. |
---|
4006 | 4336 | if (child.hide && !(child instanceof Merge) || child.skip) |
---|
4007 | 4337 | //if (child.hide) |
---|
4008 | 4338 | { |
---|
4009 | | - release(i); |
---|
| 4339 | + //release(i); |
---|
4010 | 4340 | continue; |
---|
4011 | 4341 | } |
---|
4012 | 4342 | |
---|
4013 | 4343 | blockloop = true; |
---|
4014 | 4344 | child.getBounds(min, max, true); // xform); |
---|
4015 | 4345 | blockloop = false; |
---|
4016 | | - release(i); |
---|
| 4346 | + //release(i); |
---|
4017 | 4347 | |
---|
4018 | 4348 | MinMax(minima, maxima); |
---|
4019 | 4349 | } |
---|
4020 | 4350 | |
---|
4021 | 4351 | if (bRep != null) |
---|
4022 | 4352 | { |
---|
4023 | | - bRep.getBounds(minima,maxima,this); |
---|
| 4353 | + bRep.getBounds(minima, maxima, xform?this:null); |
---|
4024 | 4354 | } |
---|
4025 | 4355 | |
---|
4026 | 4356 | if (false) // xform) |
---|
.. | .. |
---|
5420 | 5750 | blockloop = false; |
---|
5421 | 5751 | } |
---|
5422 | 5752 | |
---|
| 5753 | + void ResetSelectable() |
---|
| 5754 | + { |
---|
| 5755 | + if (blockloop) |
---|
| 5756 | + return; |
---|
| 5757 | + |
---|
| 5758 | + blockloop = true; |
---|
| 5759 | + |
---|
| 5760 | + keepdontselect = dontselect; |
---|
| 5761 | + dontselect = true; |
---|
| 5762 | + |
---|
| 5763 | + Object3D child; |
---|
| 5764 | + int nb = Size(); |
---|
| 5765 | + for (int i = 0; i < nb; i++) |
---|
| 5766 | + { |
---|
| 5767 | + child = (Object3D) get(i); |
---|
| 5768 | + if (child == null) |
---|
| 5769 | + continue; |
---|
| 5770 | + child.ResetSelectable(); |
---|
| 5771 | + } |
---|
| 5772 | + |
---|
| 5773 | + blockloop = false; |
---|
| 5774 | + } |
---|
| 5775 | + |
---|
| 5776 | + void RestoreSelectable() |
---|
| 5777 | + { |
---|
| 5778 | + if (blockloop) |
---|
| 5779 | + return; |
---|
| 5780 | + |
---|
| 5781 | + blockloop = true; |
---|
| 5782 | + |
---|
| 5783 | + dontselect = keepdontselect; |
---|
| 5784 | + |
---|
| 5785 | + Object3D child; |
---|
| 5786 | + int nb = Size(); |
---|
| 5787 | + for (int i = 0; i < nb; i++) |
---|
| 5788 | + { |
---|
| 5789 | + child = (Object3D) get(i); |
---|
| 5790 | + if (child == null) |
---|
| 5791 | + continue; |
---|
| 5792 | + child.RestoreSelectable(); |
---|
| 5793 | + } |
---|
| 5794 | + |
---|
| 5795 | + blockloop = false; |
---|
| 5796 | + } |
---|
| 5797 | + |
---|
5423 | 5798 | boolean IsSelected() |
---|
5424 | 5799 | { |
---|
5425 | 5800 | if (parent == null) |
---|
.. | .. |
---|
5480 | 5855 | if (fullname == null) |
---|
5481 | 5856 | return ""; |
---|
5482 | 5857 | |
---|
| 5858 | + if (fullname.pigment != null) |
---|
| 5859 | + { |
---|
| 5860 | + return fullname.pigment; |
---|
| 5861 | + } |
---|
| 5862 | + |
---|
5483 | 5863 | // System.out.println("Fullname = " + fullname); |
---|
5484 | 5864 | |
---|
5485 | 5865 | // Does not work on Windows due to C: |
---|
.. | .. |
---|
5492 | 5872 | |
---|
5493 | 5873 | if (split.length == 0) |
---|
5494 | 5874 | { |
---|
5495 | | - return ""; |
---|
| 5875 | + return fullname.pigment = ""; |
---|
5496 | 5876 | } |
---|
5497 | 5877 | |
---|
5498 | 5878 | if (split.length <= 2) |
---|
.. | .. |
---|
5500 | 5880 | if (fullname.name.endsWith(":")) |
---|
5501 | 5881 | { |
---|
5502 | 5882 | // Windows |
---|
5503 | | - return fullname.name.substring(0, fullname.name.length()-1); |
---|
| 5883 | + return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1); |
---|
5504 | 5884 | } |
---|
5505 | 5885 | |
---|
5506 | | - return split[0]; |
---|
| 5886 | + return fullname.pigment = split[0]; |
---|
5507 | 5887 | } |
---|
5508 | 5888 | |
---|
5509 | 5889 | // Windows |
---|
5510 | 5890 | assert(split.length == 4); |
---|
5511 | 5891 | |
---|
5512 | | - return split[0] + ":" + split[1]; |
---|
| 5892 | + return fullname.pigment = split[0] + ":" + split[1]; |
---|
5513 | 5893 | } |
---|
5514 | 5894 | |
---|
5515 | 5895 | static String GetBump(cTexture fullname) |
---|
5516 | 5896 | { |
---|
5517 | 5897 | if (fullname == null) |
---|
5518 | 5898 | return ""; |
---|
| 5899 | + |
---|
| 5900 | + if (fullname.bump != null) |
---|
| 5901 | + { |
---|
| 5902 | + return fullname.bump; |
---|
| 5903 | + } |
---|
5519 | 5904 | |
---|
5520 | 5905 | // System.out.println("Fullname = " + fullname); |
---|
5521 | 5906 | // Does not work on Windows due to C: |
---|
.. | .. |
---|
5527 | 5912 | |
---|
5528 | 5913 | if (split.length == 0) |
---|
5529 | 5914 | { |
---|
5530 | | - return ""; |
---|
| 5915 | + return fullname.bump = ""; |
---|
5531 | 5916 | } |
---|
5532 | 5917 | |
---|
5533 | 5918 | if (split.length == 1) |
---|
5534 | 5919 | { |
---|
5535 | | - return ""; |
---|
| 5920 | + return fullname.bump = ""; |
---|
5536 | 5921 | } |
---|
5537 | 5922 | |
---|
5538 | 5923 | if (split.length == 2) |
---|
.. | .. |
---|
5540 | 5925 | if (fullname.name.endsWith(":")) |
---|
5541 | 5926 | { |
---|
5542 | 5927 | // Windows |
---|
5543 | | - return ""; |
---|
| 5928 | + return fullname.bump = ""; |
---|
5544 | 5929 | } |
---|
5545 | 5930 | |
---|
5546 | | - return split[1]; |
---|
| 5931 | + return fullname.bump = split[1]; |
---|
5547 | 5932 | } |
---|
5548 | 5933 | |
---|
5549 | 5934 | // Windows |
---|
5550 | 5935 | assert(split.length == 4); |
---|
5551 | 5936 | |
---|
5552 | | - return split[2] + ":" + split[3]; |
---|
| 5937 | + return fullname.bump = split[2] + ":" + split[3]; |
---|
5553 | 5938 | } |
---|
5554 | 5939 | |
---|
5555 | 5940 | String GetPigmentTexture() |
---|
.. | .. |
---|
5632 | 6017 | texname = ""; |
---|
5633 | 6018 | |
---|
5634 | 6019 | GetTextures().name = texname + ":" + GetBump(GetTextures()); |
---|
| 6020 | + |
---|
| 6021 | + GetTextures().pigment = null; |
---|
| 6022 | + |
---|
5635 | 6023 | Touch(); |
---|
5636 | 6024 | } |
---|
5637 | 6025 | |
---|
.. | .. |
---|
5705 | 6093 | |
---|
5706 | 6094 | GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname; |
---|
5707 | 6095 | |
---|
| 6096 | + GetTextures().bump = null; |
---|
| 6097 | + |
---|
5708 | 6098 | Touch(); |
---|
5709 | 6099 | } |
---|
5710 | 6100 | |
---|
.. | .. |
---|
5729 | 6119 | } |
---|
5730 | 6120 | } |
---|
5731 | 6121 | |
---|
| 6122 | + void EmbedTextures(boolean embed) |
---|
| 6123 | + { |
---|
| 6124 | + if (blockloop) |
---|
| 6125 | + return; |
---|
| 6126 | + |
---|
| 6127 | + //if (GetTextures() != null) |
---|
| 6128 | + if (embed) |
---|
| 6129 | + CameraPane.EmbedTextures(GetTextures()); |
---|
| 6130 | + else |
---|
| 6131 | + { |
---|
| 6132 | + GetTextures().pigmentdata = null; |
---|
| 6133 | + GetTextures().bumpdata = null; |
---|
| 6134 | + GetTextures().pw = 0; |
---|
| 6135 | + GetTextures().ph = 0; |
---|
| 6136 | + GetTextures().bw = 0; |
---|
| 6137 | + GetTextures().bh = 0; |
---|
| 6138 | + } |
---|
| 6139 | + |
---|
| 6140 | + int nb = Size(); |
---|
| 6141 | + for (int i = 0; i < nb; i++) |
---|
| 6142 | + { |
---|
| 6143 | + Object3D child = (Object3D) get(i); |
---|
| 6144 | + |
---|
| 6145 | + if (child == null) |
---|
| 6146 | + continue; |
---|
| 6147 | + |
---|
| 6148 | + blockloop = true; |
---|
| 6149 | + child.EmbedTextures(embed); |
---|
| 6150 | + blockloop = false; |
---|
| 6151 | + } |
---|
| 6152 | + } |
---|
| 6153 | + |
---|
5732 | 6154 | void draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) |
---|
5733 | 6155 | { |
---|
5734 | 6156 | Draw(display, root, selected, blocked); |
---|
.. | .. |
---|
5737 | 6159 | boolean NeedSupport() |
---|
5738 | 6160 | { |
---|
5739 | 6161 | return |
---|
5740 | | - CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null |
---|
| 6162 | + CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && Link2Support() && /*live &&*/ support != null |
---|
5741 | 6163 | // PROBLEM with CROWD!! |
---|
5742 | 6164 | && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD); |
---|
5743 | 6165 | } |
---|
.. | .. |
---|
5755 | 6177 | return parent.IsLive(); |
---|
5756 | 6178 | } |
---|
5757 | 6179 | |
---|
| 6180 | + boolean IsDynamic() |
---|
| 6181 | + { |
---|
| 6182 | + return live && bRep != null; |
---|
| 6183 | + } |
---|
| 6184 | + |
---|
| 6185 | + boolean Link2Support() |
---|
| 6186 | + { |
---|
| 6187 | + return link2master || link2support; |
---|
| 6188 | + } |
---|
| 6189 | + |
---|
| 6190 | + static cVector minima = new cVector(); |
---|
| 6191 | + static cVector maxima = new cVector(); |
---|
| 6192 | + static javax.vecmath.Point3d center = new javax.vecmath.Point3d(); |
---|
| 6193 | + |
---|
5758 | 6194 | void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) |
---|
5759 | 6195 | { |
---|
5760 | 6196 | Invariants(); // june 2013 |
---|
.. | .. |
---|
5762 | 6198 | if (support != null) |
---|
5763 | 6199 | { |
---|
5764 | 6200 | // System.err.println("Draw " + this + " Frame # " + ((Mocap)((Merge)support).object).frame); |
---|
| 6201 | + } |
---|
| 6202 | + |
---|
| 6203 | + if (false) // live && Link2Support() && support == null && !this.marked) // project on ground |
---|
| 6204 | + { |
---|
| 6205 | + getBounds(minima, maxima, true); |
---|
| 6206 | + center.x = (minima.x + maxima.x) / 2; |
---|
| 6207 | + center.y = 10000; // (minima.y + maxima.y) / 2; |
---|
| 6208 | + center.z = (minima.z + maxima.z) / 2; |
---|
| 6209 | + |
---|
| 6210 | + Ray ray = new Ray(center, new Vector3d(0,-1,0)); |
---|
| 6211 | + |
---|
| 6212 | + IntersectResult res = new IntersectResult(); |
---|
| 6213 | + res.t = Double.POSITIVE_INFINITY; |
---|
| 6214 | + |
---|
| 6215 | + if (Grafreed.grafreed.universe.intersect(ray, res)) |
---|
| 6216 | + { |
---|
| 6217 | + double resx = ray.eyePoint.x + ray.viewDirection.x * res.t; |
---|
| 6218 | + double resy = ray.eyePoint.y + ray.viewDirection.y * res.t; |
---|
| 6219 | + double resz = ray.eyePoint.z + ray.viewDirection.z * res.t; |
---|
| 6220 | + |
---|
| 6221 | + LA.matTranslate(toParent, 0, resy - minima.y, 0); |
---|
| 6222 | + LA.matInvert(toParent, fromParent); |
---|
| 6223 | + } |
---|
5765 | 6224 | } |
---|
5766 | 6225 | |
---|
5767 | 6226 | if (display.DrawMode() == iCameraPane.SELECTION && |
---|
.. | .. |
---|
5815 | 6274 | if (support != null) |
---|
5816 | 6275 | support = support; |
---|
5817 | 6276 | |
---|
5818 | | - //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch); |
---|
5819 | | - boolean usecalllists = !IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch); |
---|
| 6277 | + boolean usecalllists = !IsDynamic() && |
---|
| 6278 | + IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch); |
---|
| 6279 | + //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch); |
---|
| 6280 | + |
---|
| 6281 | + //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass. |
---|
5820 | 6282 | |
---|
5821 | 6283 | if (!usecalllists && bRep != null && bRep.displaylist > 0) |
---|
5822 | 6284 | { |
---|
.. | .. |
---|
5824 | 6286 | bRep.displaylist = 0; |
---|
5825 | 6287 | } |
---|
5826 | 6288 | // usecalllists &= !(parent instanceof RandomNode); |
---|
5827 | | - // usecalllists = false; |
---|
| 6289 | + if (CameraPane.BOXMODE) // Too dynamic |
---|
| 6290 | + usecalllists = false; |
---|
5828 | 6291 | |
---|
5829 | | - if (GetBRep() != null) |
---|
5830 | | - usecalllists = usecalllists; |
---|
| 6292 | + if (display.DrawMode() == display.SHADOW) |
---|
| 6293 | + //GetBRep() != null) |
---|
| 6294 | + usecalllists = !!usecalllists; |
---|
5831 | 6295 | //System.out.println("draw " + this); |
---|
5832 | 6296 | //new Exception().printStackTrace(); |
---|
5833 | 6297 | |
---|
.. | .. |
---|
5849 | 6313 | if (!(this instanceof Composite)) |
---|
5850 | 6314 | touched = false; |
---|
5851 | 6315 | //if (displaylist == -1 && usecalllists) |
---|
5852 | | - if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013 |
---|
| 6316 | + if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013 |
---|
5853 | 6317 | { |
---|
5854 | 6318 | bRep.displaylist = display.GenList(); |
---|
5855 | 6319 | assert(bRep.displaylist != 0); |
---|
.. | .. |
---|
5860 | 6324 | |
---|
5861 | 6325 | //System.out.println("\tnew list " + list); |
---|
5862 | 6326 | //gl.glDrawBuffer(gl.GL_NONE); |
---|
5863 | | - if (usecalllists) |
---|
| 6327 | + if (usecalllists && bRep.displaylist > 0) |
---|
5864 | 6328 | { |
---|
5865 | 6329 | // System.err.println("new list " + bRep.displaylist + " for " + this); |
---|
5866 | 6330 | display.NewList(bRep.displaylist); |
---|
.. | .. |
---|
5869 | 6333 | CallList(display, root, selected, blocked); |
---|
5870 | 6334 | |
---|
5871 | 6335 | // compiled = true; |
---|
5872 | | - if (usecalllists) |
---|
| 6336 | + if (usecalllists && bRep.displaylist > 0) |
---|
5873 | 6337 | { |
---|
5874 | 6338 | // System.err.println("end list " + bRep.displaylist + " for " + this); |
---|
5875 | 6339 | display.EndList(); |
---|
.. | .. |
---|
5879 | 6343 | Globals.lighttouched = true; // all panes... |
---|
5880 | 6344 | } |
---|
5881 | 6345 | |
---|
5882 | | - touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false; |
---|
5883 | | - //touched = false; |
---|
| 6346 | + //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false; |
---|
| 6347 | + touched = false; |
---|
5884 | 6348 | |
---|
5885 | 6349 | if (this instanceof Texture || this instanceof TextureNode) |
---|
5886 | 6350 | { |
---|
.. | .. |
---|
5919 | 6383 | { |
---|
5920 | 6384 | if (display.DrawMode() == iCameraPane.SHADOW) |
---|
5921 | 6385 | { |
---|
5922 | | - if (!link2master // tricky to cull in shadow mode. |
---|
| 6386 | + if (!Link2Support() // tricky to cull in shadow mode. |
---|
5923 | 6387 | && GetBRep().FrustumCull(this, null, display.LightCamera(), true)) |
---|
5924 | 6388 | { |
---|
5925 | 6389 | //System.out.print("CULLED"); |
---|
.. | .. |
---|
5981 | 6445 | { |
---|
5982 | 6446 | drawSelf(display, root, selected, blocked); |
---|
5983 | 6447 | } |
---|
| 6448 | + |
---|
| 6449 | +// if (!(this instanceof Composite)) |
---|
| 6450 | +// { |
---|
| 6451 | +// for (int i = 0; i < size(); i++) |
---|
| 6452 | +// { |
---|
| 6453 | +// Object3D child = (Object3D) reserve(i); |
---|
| 6454 | +// if (child == null) |
---|
| 6455 | +// continue; |
---|
| 6456 | +// |
---|
| 6457 | +// child.draw(display, root, selected, blocked); |
---|
| 6458 | +// |
---|
| 6459 | +// release(i); |
---|
| 6460 | +// } |
---|
| 6461 | +// } |
---|
5984 | 6462 | } else |
---|
5985 | 6463 | { |
---|
5986 | 6464 | /* |
---|
.. | .. |
---|
6013 | 6491 | boolean failedPigment = false; |
---|
6014 | 6492 | boolean failedBump = false; |
---|
6015 | 6493 | |
---|
| 6494 | + CameraPane.lastObject = this; |
---|
6016 | 6495 | try |
---|
6017 | 6496 | { |
---|
6018 | 6497 | display.BindPigmentTexture(tex, texres); |
---|
6019 | 6498 | } |
---|
6020 | 6499 | catch (Exception e) |
---|
6021 | 6500 | { |
---|
6022 | | - System.err.println("FAILED: " + this); |
---|
| 6501 | + // System.err.println("FAILED: " + this); |
---|
6023 | 6502 | failedPigment = true; |
---|
6024 | 6503 | } |
---|
6025 | 6504 | |
---|
.. | .. |
---|
6050 | 6529 | display.CallList(bRep.displaylist); |
---|
6051 | 6530 | // june 2013 drawSelf(display, root, selected); |
---|
6052 | 6531 | } |
---|
| 6532 | + } |
---|
| 6533 | + |
---|
| 6534 | + assert (!(this instanceof Composite)); |
---|
| 6535 | + { |
---|
| 6536 | +// CRASH MOCAP!! for (int i = 0; i < size(); i++) |
---|
| 6537 | +// { |
---|
| 6538 | +// Object3D child = (Object3D) reserve(i); |
---|
| 6539 | +// if (child == null) |
---|
| 6540 | +// continue; |
---|
| 6541 | +// |
---|
| 6542 | +// child.draw(display, root, selected, blocked); |
---|
| 6543 | +// |
---|
| 6544 | +// release(i); |
---|
| 6545 | +// } |
---|
6053 | 6546 | } |
---|
6054 | 6547 | } |
---|
6055 | 6548 | |
---|
.. | .. |
---|
6103 | 6596 | |
---|
6104 | 6597 | void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) |
---|
6105 | 6598 | { |
---|
6106 | | - if (GetBRep() == null) |
---|
6107 | | - { |
---|
6108 | | - drawSelf(display, root, selected, blocked); |
---|
6109 | | - } else |
---|
| 6599 | + if (GetBRep() != null) |
---|
6110 | 6600 | { |
---|
6111 | 6601 | DrawNode(display, root, selected); |
---|
6112 | 6602 | if (this instanceof BezierPatch) |
---|
6113 | 6603 | { |
---|
6114 | 6604 | //drawSelf(display, root, selected); |
---|
6115 | 6605 | } |
---|
| 6606 | + } |
---|
| 6607 | + else |
---|
| 6608 | + { |
---|
| 6609 | + drawSelf(display, root, selected, blocked); |
---|
6116 | 6610 | } |
---|
6117 | 6611 | } |
---|
6118 | 6612 | |
---|
.. | .. |
---|
6362 | 6856 | |
---|
6363 | 6857 | //javax.media.opengl.GL gl = display.GetGL(); |
---|
6364 | 6858 | |
---|
6365 | | - if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera) |
---|
| 6859 | + if (CameraPane.BOXMODE && !Link2Support()) //selected) // || CameraPane.movingcamera) |
---|
6366 | 6860 | { |
---|
6367 | 6861 | int fc = bRep.FaceCount(); |
---|
6368 | 6862 | int vc = bRep.VertexCount(); |
---|
.. | .. |
---|
6524 | 7018 | facescompare[k] = new FaceCompare(k); |
---|
6525 | 7019 | } |
---|
6526 | 7020 | |
---|
6527 | | - center = new cVector(); |
---|
| 7021 | + centertriangle = new cVector(); |
---|
6528 | 7022 | } |
---|
6529 | 7023 | else |
---|
6530 | 7024 | { |
---|
.. | .. |
---|
6647 | 7141 | */ |
---|
6648 | 7142 | } |
---|
6649 | 7143 | |
---|
6650 | | - transient cVector center; |
---|
| 7144 | + transient cVector centertriangle; |
---|
6651 | 7145 | |
---|
6652 | 7146 | class FaceCompare implements Comparable |
---|
6653 | 7147 | { |
---|
.. | .. |
---|
6676 | 7170 | Vertex q = bRep.GetVertex(face.q); |
---|
6677 | 7171 | Vertex r = bRep.GetVertex(face.r); |
---|
6678 | 7172 | |
---|
6679 | | - center.set(p); |
---|
6680 | | - center.add(q); |
---|
6681 | | - center.add(r); |
---|
6682 | | - center.mul(1.0/3); |
---|
| 7173 | + centertriangle.set(p); |
---|
| 7174 | + centertriangle.add(q); |
---|
| 7175 | + centertriangle.add(r); |
---|
| 7176 | + centertriangle.mul(1.0/3); |
---|
6683 | 7177 | |
---|
6684 | | - center.sub(Globals.theRenderer.EyeCamera().location); |
---|
| 7178 | + centertriangle.sub(Globals.theRenderer.EyeCamera().location); |
---|
6685 | 7179 | |
---|
6686 | | - distance = center.dot(center); |
---|
| 7180 | + distance = centertriangle.dot(centertriangle); |
---|
6687 | 7181 | } |
---|
6688 | 7182 | |
---|
6689 | 7183 | return distance; |
---|
.. | .. |
---|
7220 | 7714 | } |
---|
7221 | 7715 | } |
---|
7222 | 7716 | |
---|
7223 | | - protected void calcHotSpot(cVector in, ClickInfo info, Point outPt, Rectangle outRec) |
---|
| 7717 | + static ClickInfo clickInfo = new ClickInfo(); |
---|
| 7718 | + |
---|
| 7719 | + protected void calcHotSpot(cVector in, //ClickInfo clickInfo, |
---|
| 7720 | + Point outPt, Rectangle outRec) |
---|
7224 | 7721 | { |
---|
7225 | | - int hc = info.bounds.x + info.bounds.width / 2; |
---|
7226 | | - int vc = info.bounds.y + info.bounds.height / 2; |
---|
7227 | | - double[][] toscreen = info.toScreen; |
---|
| 7722 | + int hc = clickInfo.bounds.x + clickInfo.bounds.width / 2; |
---|
| 7723 | + int vc = clickInfo.bounds.y + clickInfo.bounds.height / 2; |
---|
| 7724 | + double[][] toscreen = clickInfo.toScreen; |
---|
7228 | 7725 | if (toscreen == null) |
---|
7229 | 7726 | { |
---|
7230 | | - toscreen = new Camera(info.camera.viewCode).toScreen; |
---|
| 7727 | + toscreen = new Camera(clickInfo.camera.viewCode).toScreen; |
---|
7231 | 7728 | } |
---|
7232 | 7729 | cVector vec = in; |
---|
7233 | 7730 | LA.xformPos(in, toscreen, in); |
---|
7234 | 7731 | //System.out.println("Distance = " + info.camera.Distance()); |
---|
7235 | | - vec.x *= 100 * info.camera.SCALE / info.camera.Distance(); |
---|
7236 | | - vec.y *= 100 * info.camera.SCALE / info.camera.Distance(); |
---|
| 7732 | + vec.x *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance(); |
---|
| 7733 | + vec.y *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance(); |
---|
7237 | 7734 | outPt.x = hc + (int) vec.x; |
---|
7238 | 7735 | outPt.y = vc - (int) vec.y; |
---|
7239 | 7736 | outRec.x = outPt.x - 3; |
---|
.. | .. |
---|
7241 | 7738 | outRec.width = outRec.height = 6; |
---|
7242 | 7739 | } |
---|
7243 | 7740 | |
---|
7244 | | - protected Rectangle calcHotSpot(cVector in, ClickInfo info) |
---|
| 7741 | + protected Rectangle calcHotSpot(cVector in//, ClickInfo clickInfo |
---|
| 7742 | + ) |
---|
7245 | 7743 | { |
---|
7246 | 7744 | Point pt = new Point(0, 0); |
---|
7247 | 7745 | Rectangle rec = new Rectangle(); |
---|
7248 | | - calcHotSpot(in, info, pt, rec); |
---|
| 7746 | + calcHotSpot(in, //clickInfo, |
---|
| 7747 | + pt, rec); |
---|
7249 | 7748 | return rec; |
---|
7250 | 7749 | } |
---|
7251 | 7750 | |
---|
7252 | | - void drawEditHandles0(ClickInfo info, int level) |
---|
| 7751 | + void drawEditHandles0(//ClickInfo clickInfo, |
---|
| 7752 | + int level) |
---|
7253 | 7753 | { |
---|
7254 | 7754 | if (level == 0) |
---|
7255 | 7755 | { |
---|
.. | .. |
---|
7258 | 7758 | { |
---|
7259 | 7759 | cVector origin = new cVector(); |
---|
7260 | 7760 | //LA.xformPos(origin, toParent, origin); |
---|
7261 | | - Rectangle spot = calcHotSpot(origin, info); |
---|
| 7761 | + if (this.clickInfo == null) |
---|
| 7762 | + this.clickInfo = new ClickInfo(); |
---|
| 7763 | + |
---|
| 7764 | + Rectangle spot = calcHotSpot(origin); //, clickInfo); |
---|
7262 | 7765 | Rectangle boundary = new Rectangle(); |
---|
7263 | 7766 | boundary.x = spot.x - 30; |
---|
7264 | 7767 | boundary.y = spot.y - 30; |
---|
7265 | 7768 | boundary.width = spot.width + 60; |
---|
7266 | 7769 | boundary.height = spot.height + 60; |
---|
7267 | | - info.g.setColor(Color.red); |
---|
| 7770 | + clickInfo.g.setColor(Color.white); |
---|
7268 | 7771 | int spotw = spot.x + spot.width; |
---|
7269 | 7772 | int spoth = spot.y + spot.height; |
---|
7270 | | - info.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
| 7773 | + clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
7271 | 7774 | // if (CameraPane.Xmin > spot.x) |
---|
7272 | 7775 | // { |
---|
7273 | 7776 | // CameraPane.Xmin = spot.x; |
---|
.. | .. |
---|
7284 | 7787 | // { |
---|
7285 | 7788 | // CameraPane.Ymax = spoth; |
---|
7286 | 7789 | // } |
---|
7287 | | - spot.translate(32, 32); |
---|
7288 | | - spotw = spot.x + spot.width; |
---|
7289 | | - spoth = spot.y + spot.height; |
---|
7290 | | - info.g.setColor(Color.cyan); |
---|
7291 | | - info.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
7292 | 7790 | // if (CameraPane.Xmin > spot.x) |
---|
7293 | 7791 | // { |
---|
7294 | 7792 | // CameraPane.Xmin = spot.x; |
---|
.. | .. |
---|
7307 | 7805 | // } |
---|
7308 | 7806 | // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15 |
---|
7309 | 7807 | //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15 |
---|
7310 | | - spot.translate(0, -32); |
---|
7311 | | - info.g.setColor(Color.yellow); |
---|
7312 | | - info.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
7313 | | - info.g.setColor(Color.green); |
---|
| 7808 | + spot.translate(32, 0); |
---|
| 7809 | + clickInfo.g.setColor(Color.yellow); |
---|
| 7810 | + clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
| 7811 | + |
---|
| 7812 | + spot.translate(32, 64); |
---|
| 7813 | + spotw = spot.x + spot.width; |
---|
| 7814 | + spoth = spot.y + spot.height; |
---|
| 7815 | + clickInfo.g.setColor(Color.cyan); |
---|
| 7816 | + clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
7314 | 7817 | // if (CameraPane.Xmin > spot.x) |
---|
7315 | 7818 | // { |
---|
7316 | 7819 | // CameraPane.Xmin = spot.x; |
---|
.. | .. |
---|
7327 | 7830 | // { |
---|
7328 | 7831 | // CameraPane.Ymax = spoth; |
---|
7329 | 7832 | // } |
---|
7330 | | - info.g.drawArc(boundary.x + info.DX, boundary.y + info.DY, |
---|
7331 | | - (int)(boundary.width * info.W), (int)(boundary.height * info.W), 0, 360); |
---|
| 7833 | + clickInfo.g.setColor(Color.green); |
---|
| 7834 | + clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY, |
---|
| 7835 | + (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360); |
---|
7332 | 7836 | //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360); |
---|
7333 | 7837 | // if (CameraPane.Xmin > boundary.x) |
---|
7334 | 7838 | // { |
---|
.. | .. |
---|
7350 | 7854 | } |
---|
7351 | 7855 | } |
---|
7352 | 7856 | |
---|
7353 | | - boolean doEditClick0(ClickInfo info, int level) |
---|
| 7857 | + boolean doEditClick0(//ClickInfo clickInfo, |
---|
| 7858 | + int level) |
---|
7354 | 7859 | { |
---|
7355 | 7860 | if (level == 0) |
---|
7356 | 7861 | { |
---|
.. | .. |
---|
7359 | 7864 | |
---|
7360 | 7865 | boolean retval = false; |
---|
7361 | 7866 | |
---|
7362 | | - startX = info.x; |
---|
7363 | | - startY = info.y; |
---|
| 7867 | + startX = clickInfo.x; |
---|
| 7868 | + startY = clickInfo.y; |
---|
7364 | 7869 | |
---|
7365 | 7870 | hitSomething = -1; |
---|
7366 | 7871 | cVector origin = new cVector(); |
---|
.. | .. |
---|
7370 | 7875 | { |
---|
7371 | 7876 | centerPt = new Point(0, 0); |
---|
7372 | 7877 | } |
---|
7373 | | - calcHotSpot(origin, info, centerPt, spot); |
---|
7374 | | - if (spot.contains(info.x, info.y)) |
---|
| 7878 | + calcHotSpot(origin, //info, |
---|
| 7879 | + centerPt, spot); |
---|
| 7880 | + if (spot.contains(clickInfo.x, clickInfo.y)) |
---|
7375 | 7881 | { |
---|
7376 | 7882 | hitSomething = hitCenter; |
---|
7377 | 7883 | retval = true; |
---|
7378 | 7884 | } |
---|
7379 | 7885 | spot.translate(32, 0); |
---|
7380 | | - if (spot.contains(info.x, info.y)) |
---|
| 7886 | + if (spot.contains(clickInfo.x, clickInfo.y)) |
---|
7381 | 7887 | { |
---|
7382 | 7888 | hitSomething = hitRotate; |
---|
7383 | 7889 | retval = true; |
---|
7384 | 7890 | } |
---|
7385 | 7891 | spot.translate(0, 32); |
---|
7386 | | - if (spot.contains(info.x, info.y)) |
---|
| 7892 | + spot.translate(32, 0); |
---|
| 7893 | + spot.translate(0, 32); |
---|
| 7894 | + if (spot.contains(clickInfo.x, clickInfo.y)) |
---|
7387 | 7895 | { |
---|
7388 | 7896 | hitSomething = hitScale; |
---|
| 7897 | + |
---|
| 7898 | + double scale = 0.005f * clickInfo.camera.Distance(); |
---|
| 7899 | + double hScale = (double) (clickInfo.x - centerPt.x) / 64; |
---|
| 7900 | + double sign = 1; |
---|
| 7901 | + if (hScale < 0) |
---|
| 7902 | + { |
---|
| 7903 | + sign = -1; |
---|
| 7904 | + } |
---|
| 7905 | + hScale = sign*Math.pow(sign*hScale, scale * 50); |
---|
| 7906 | + if (hScale < 0.01) |
---|
| 7907 | + { |
---|
| 7908 | + //hScale = 0.01; |
---|
| 7909 | + } |
---|
| 7910 | + |
---|
| 7911 | + double vScale = (double) (clickInfo.y - centerPt.y) / 64; |
---|
| 7912 | + sign = 1; |
---|
| 7913 | + if (vScale < 0) |
---|
| 7914 | + { |
---|
| 7915 | + sign = -1; |
---|
| 7916 | + } |
---|
| 7917 | + vScale = sign*Math.pow(sign*vScale, scale * 50); |
---|
| 7918 | + if (vScale < 0.01) |
---|
| 7919 | + { |
---|
| 7920 | + //vScale = 0.01; |
---|
| 7921 | + } |
---|
| 7922 | + |
---|
| 7923 | + clickInfo.scale = Math.sqrt(hScale*hScale + vScale*vScale); |
---|
| 7924 | + |
---|
7389 | 7925 | retval = true; |
---|
7390 | 7926 | } |
---|
7391 | 7927 | |
---|
.. | .. |
---|
7395 | 7931 | } |
---|
7396 | 7932 | |
---|
7397 | 7933 | //System.out.println("info.modifiers = " + info.modifiers); |
---|
7398 | | - modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META |
---|
| 7934 | + modified = (clickInfo.modifiers & CameraPane.SHIFT) != 0; // Was META |
---|
7399 | 7935 | //System.out.println("modified = " + modified); |
---|
7400 | 7936 | //new Exception().printStackTrace(); |
---|
7401 | 7937 | //viewCode = info.pane.renderCamera.viewCode; |
---|
.. | .. |
---|
7423 | 7959 | return true; |
---|
7424 | 7960 | } |
---|
7425 | 7961 | |
---|
7426 | | - void doEditDrag0(ClickInfo info, boolean opposite) |
---|
| 7962 | + void doEditDrag0(//ClickInfo info, |
---|
| 7963 | + boolean opposite) |
---|
7427 | 7964 | { |
---|
7428 | 7965 | if (hitSomething == 0) |
---|
7429 | 7966 | { |
---|
.. | .. |
---|
7437 | 7974 | |
---|
7438 | 7975 | //System.out.println("hitSomething = " + hitSomething); |
---|
7439 | 7976 | |
---|
7440 | | - double scale = 0.005f * info.camera.Distance(); |
---|
| 7977 | + double scale = 0.005f * clickInfo.camera.Distance(); |
---|
7441 | 7978 | |
---|
7442 | 7979 | cVector xlate = new cVector(); |
---|
7443 | 7980 | //cVector xlate2 = new cVector(); |
---|
.. | .. |
---|
7451 | 7988 | |
---|
7452 | 7989 | scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance(); |
---|
7453 | 7990 | |
---|
7454 | | - if (modified || opposite) |
---|
| 7991 | + // Modified could snap |
---|
| 7992 | + if (//modified || |
---|
| 7993 | + opposite) |
---|
7455 | 7994 | { |
---|
7456 | 7995 | //assert(false); |
---|
7457 | 7996 | /* |
---|
.. | .. |
---|
7471 | 8010 | toParent[3][i] = xlate.get(i); |
---|
7472 | 8011 | LA.matInvert(toParent, fromParent); |
---|
7473 | 8012 | */ |
---|
7474 | | - cVector delta = LA.newVector(0, 0, startY - info.y); |
---|
7475 | | - LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta); |
---|
| 8013 | + cVector delta = LA.newVector(0, 0, startY - clickInfo.y); |
---|
| 8014 | + LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta); |
---|
7476 | 8015 | |
---|
7477 | 8016 | LA.matCopy(startMat, toParent); |
---|
7478 | 8017 | LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale); |
---|
.. | .. |
---|
7481 | 8020 | } else |
---|
7482 | 8021 | { |
---|
7483 | 8022 | //LA.xformDir(delta, info.camera.fromScreen, delta); |
---|
7484 | | - cVector up = new cVector(info.camera.up); |
---|
| 8023 | + cVector up = new cVector(clickInfo.camera.up); |
---|
7485 | 8024 | cVector away = new cVector(); |
---|
7486 | 8025 | //cVector right2 = new cVector(); |
---|
7487 | 8026 | //LA.vecCross(up, cVector.Z, right); |
---|
.. | .. |
---|
7498 | 8037 | LA.xformDir(up, ClickInfo.matbuffer, up); |
---|
7499 | 8038 | // if (!CameraPane.LOCALTRANSFORM) |
---|
7500 | 8039 | LA.xformDir(up, Globals.theRenderer.RenderCamera().toScreen, up); |
---|
7501 | | - LA.xformDir(info.camera.away, ClickInfo.matbuffer, away); |
---|
| 8040 | + LA.xformDir(clickInfo.camera.away, ClickInfo.matbuffer, away); |
---|
7502 | 8041 | // if (!CameraPane.LOCALTRANSFORM) |
---|
7503 | 8042 | LA.xformDir(away, Globals.theRenderer.RenderCamera().toScreen, away); |
---|
7504 | 8043 | //LA.vecCross(up, cVector.Z, right2); |
---|
7505 | 8044 | |
---|
7506 | | - cVector delta = LA.newVector(info.x - startX, startY - info.y, 0); |
---|
| 8045 | + cVector delta = LA.newVector(clickInfo.x - startX, startY - clickInfo.y, 0); |
---|
7507 | 8046 | |
---|
7508 | 8047 | //System.out.println("DELTA0 = " + delta); |
---|
7509 | 8048 | //System.out.println("AWAY = " + info.camera.away); |
---|
7510 | 8049 | //System.out.println("UP = " + info.camera.up); |
---|
7511 | 8050 | if (away.z > 0) |
---|
7512 | 8051 | { |
---|
7513 | | - if (info.camera.up.x == 0) // LA.vecDot(right, right2)<0) |
---|
| 8052 | + if (clickInfo.camera.up.x == 0) // LA.vecDot(right, right2)<0) |
---|
7514 | 8053 | { |
---|
7515 | 8054 | delta.x = -delta.x; |
---|
7516 | 8055 | } else |
---|
.. | .. |
---|
7525 | 8064 | //System.out.println("DELTA1 = " + delta); |
---|
7526 | 8065 | LA.xformDir(delta, ClickInfo.matbuffer, delta); |
---|
7527 | 8066 | //System.out.println("DELTA2 = " + delta); |
---|
7528 | | - LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta); |
---|
| 8067 | + LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta); |
---|
7529 | 8068 | LA.matCopy(startMat, toParent); |
---|
7530 | 8069 | //System.out.println("DELTA3 = " + delta); |
---|
7531 | 8070 | LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale); |
---|
.. | .. |
---|
7535 | 8074 | break; |
---|
7536 | 8075 | |
---|
7537 | 8076 | case hitRotate: // rotate |
---|
7538 | | - int dx = info.x - centerPt.x; |
---|
7539 | | - int dy = -(info.y - centerPt.y); |
---|
| 8077 | + int dx = clickInfo.x - centerPt.x; |
---|
| 8078 | + int dy = -(clickInfo.y - centerPt.y); |
---|
7540 | 8079 | double angle = (double) Math.atan2(dx, dy); |
---|
7541 | 8080 | angle = -(1.570796 - angle); |
---|
7542 | 8081 | |
---|
.. | .. |
---|
7545 | 8084 | |
---|
7546 | 8085 | if (modified) |
---|
7547 | 8086 | { |
---|
7548 | | - // Rotate 90 degrees |
---|
| 8087 | + // Rotate 45 degrees |
---|
7549 | 8088 | angle /= (Math.PI / 4); |
---|
7550 | 8089 | angle = Math.floor(angle + 0.5); |
---|
7551 | 8090 | angle *= (Math.PI / 4); |
---|
.. | .. |
---|
7559 | 8098 | } |
---|
7560 | 8099 | /**/ |
---|
7561 | 8100 | |
---|
7562 | | - switch (info.pane.RenderCamera().viewCode) |
---|
| 8101 | + switch (clickInfo.pane.RenderCamera().viewCode) |
---|
7563 | 8102 | { |
---|
7564 | 8103 | case 1: // '\001' |
---|
7565 | 8104 | LA.matZRotate(toParent, angle); |
---|
.. | .. |
---|
7586 | 8125 | break; |
---|
7587 | 8126 | |
---|
7588 | 8127 | case hitScale: // scale |
---|
7589 | | - double hScale = (double) (info.x - centerPt.x) / 32; |
---|
| 8128 | + double hScale = (double) (clickInfo.x - centerPt.x) / 64; |
---|
7590 | 8129 | double sign = 1; |
---|
7591 | 8130 | if (hScale < 0) |
---|
7592 | 8131 | { |
---|
.. | .. |
---|
7598 | 8137 | //hScale = 0.01; |
---|
7599 | 8138 | } |
---|
7600 | 8139 | |
---|
7601 | | - double vScale = (double) (info.y - centerPt.y) / 32; |
---|
| 8140 | + double vScale = (double) (clickInfo.y - centerPt.y) / 64; |
---|
7602 | 8141 | sign = 1; |
---|
7603 | 8142 | if (vScale < 0) |
---|
7604 | 8143 | { |
---|
.. | .. |
---|
7609 | 8148 | { |
---|
7610 | 8149 | //vScale = 0.01; |
---|
7611 | 8150 | } |
---|
| 8151 | + |
---|
7612 | 8152 | LA.matCopy(startMat, toParent); |
---|
7613 | 8153 | /**/ |
---|
7614 | 8154 | for (int i = 0; i < 3; i++) |
---|
.. | .. |
---|
7618 | 8158 | } |
---|
7619 | 8159 | /**/ |
---|
7620 | 8160 | |
---|
7621 | | - double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2); |
---|
| 8161 | + double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / clickInfo.scale; |
---|
7622 | 8162 | |
---|
7623 | 8163 | if (totalScale < 0.01) |
---|
7624 | 8164 | { |
---|
7625 | 8165 | totalScale = 0.01; |
---|
7626 | 8166 | } |
---|
7627 | 8167 | |
---|
7628 | | - switch (info.pane.RenderCamera().viewCode) |
---|
| 8168 | + switch (clickInfo.pane.RenderCamera().viewCode) |
---|
7629 | 8169 | { |
---|
7630 | 8170 | case 3: // '\001' |
---|
7631 | 8171 | if (modified || opposite) |
---|
7632 | 8172 | { |
---|
| 8173 | + if (modified) // && opposite) |
---|
| 8174 | + LA.matScale(toParent, totalScale, totalScale, totalScale); |
---|
| 8175 | + else |
---|
7633 | 8176 | //LA.matScale(toParent, 1, hScale, vScale); |
---|
7634 | | - LA.matScale(toParent, totalScale, 1, 1); |
---|
| 8177 | + LA.matScale(toParent, totalScale, 1, 1); |
---|
7635 | 8178 | } // vScale, 1); |
---|
7636 | 8179 | else |
---|
7637 | 8180 | { |
---|
7638 | 8181 | // EXCEPTION! |
---|
7639 | | - LA.matScale(toParent, totalScale, totalScale, totalScale); |
---|
| 8182 | + LA.matScale(toParent, 1, totalScale, totalScale); |
---|
7640 | 8183 | } // vScale, 1); |
---|
7641 | 8184 | break; |
---|
7642 | 8185 | |
---|
7643 | 8186 | case 2: // '\002' |
---|
7644 | 8187 | if (modified || opposite) |
---|
7645 | 8188 | { |
---|
7646 | | - //LA.matScale(toParent, hScale, 1, vScale); |
---|
7647 | | - LA.matScale(toParent, 1, totalScale, 1); |
---|
| 8189 | + if (modified) // && opposite) |
---|
| 8190 | + LA.matScale(toParent, totalScale, totalScale, totalScale); |
---|
| 8191 | + else |
---|
| 8192 | + //LA.matScale(toParent, hScale, 1, vScale); |
---|
| 8193 | + LA.matScale(toParent, 1, totalScale, 1); |
---|
7648 | 8194 | } else |
---|
7649 | 8195 | { |
---|
7650 | 8196 | LA.matScale(toParent, totalScale, 1, totalScale); |
---|
.. | .. |
---|
7654 | 8200 | case 1: // '\003' |
---|
7655 | 8201 | if (modified || opposite) |
---|
7656 | 8202 | { |
---|
7657 | | - //LA.matScale(toParent, hScale, vScale, 1); |
---|
7658 | | - LA.matScale(toParent, 1, 1, totalScale); |
---|
| 8203 | + if (modified) // && opposite) |
---|
| 8204 | + LA.matScale(toParent, totalScale, totalScale, totalScale); |
---|
| 8205 | + else |
---|
| 8206 | + //LA.matScale(toParent, hScale, vScale, 1); |
---|
| 8207 | + LA.matScale(toParent, 1, 1, totalScale); |
---|
7659 | 8208 | } else |
---|
7660 | 8209 | { |
---|
7661 | 8210 | LA.matScale(toParent, totalScale, totalScale, 1); |
---|
.. | .. |
---|
7692 | 8241 | } // NEW ... |
---|
7693 | 8242 | |
---|
7694 | 8243 | |
---|
7695 | | - info.pane.repaint(); |
---|
| 8244 | + clickInfo.pane.repaint(); |
---|
7696 | 8245 | } |
---|
7697 | 8246 | |
---|
7698 | 8247 | boolean overflow = false; |
---|
.. | .. |
---|
7806 | 8355 | if (!Globals.ADVANCED) |
---|
7807 | 8356 | return objname; |
---|
7808 | 8357 | |
---|
7809 | | - return objname + " " + System.identityHashCode(this); |
---|
| 8358 | + return objname + " " + System.identityHashCode(this) + " " + GetUUID(); |
---|
7810 | 8359 | } |
---|
7811 | 8360 | |
---|
7812 | 8361 | public int hashCode() |
---|
7813 | 8362 | { |
---|
7814 | | - // Fuck Vector... |
---|
| 8363 | + // Do not use Vector... |
---|
7815 | 8364 | return System.identityHashCode(this); |
---|
7816 | 8365 | } |
---|
7817 | 8366 | |
---|
.. | .. |
---|
8051 | 8600 | private static cVector2 qq2 = new cVector2(); |
---|
8052 | 8601 | private static cVector2 rr2 = new cVector2(); |
---|
8053 | 8602 | private static cVector2 ss2 = new cVector2(); |
---|
8054 | | - private static cVector edge1 = new cVector(); |
---|
8055 | | - private static cVector edge2 = new cVector(); |
---|
| 8603 | +// private static cVector edge1 = new cVector(); |
---|
| 8604 | +// private static cVector edge2 = new cVector(); |
---|
8056 | 8605 | //private static cVector norm = new cVector(); |
---|
8057 | 8606 | /*transient private*/ int hitSomething; |
---|
8058 | 8607 | static final int hitCenter = 1; |
---|
.. | .. |
---|
8250 | 8799 | |
---|
8251 | 8800 | Touch(); |
---|
8252 | 8801 | } |
---|
| 8802 | + |
---|
| 8803 | + static Vertex s1 = new Vertex(); |
---|
| 8804 | + static Vertex s2 = new Vertex(); |
---|
| 8805 | + static Vertex s3 = new Vertex(); |
---|
8253 | 8806 | |
---|
| 8807 | + boolean intersectMesh(Ray ray, IntersectResult result) |
---|
| 8808 | + { |
---|
| 8809 | + boolean success = false; |
---|
| 8810 | + |
---|
| 8811 | + if (bRep.stripified) |
---|
| 8812 | + { |
---|
| 8813 | + int[] strips = bRep.getRawIndices(); |
---|
| 8814 | + |
---|
| 8815 | + // TRIANGLE STRIP ARRAY |
---|
| 8816 | + if (bRep.trimmed) |
---|
| 8817 | + { |
---|
| 8818 | + float[] v = bRep.getRawVertices(); |
---|
| 8819 | + |
---|
| 8820 | + int count3 = 0; |
---|
| 8821 | + |
---|
| 8822 | + if (v.length > 0) |
---|
| 8823 | + { |
---|
| 8824 | + for (int i = 0; i < strips.length; i++) |
---|
| 8825 | + { |
---|
| 8826 | + s1.set(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 8827 | + count3 += 3; |
---|
| 8828 | + |
---|
| 8829 | + s2.set(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 8830 | + count3 += 3; |
---|
| 8831 | + |
---|
| 8832 | + for (int j = 0; j < strips[i] - 2; j++) |
---|
| 8833 | + { |
---|
| 8834 | + s3.set(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 8835 | + count3 += 3; |
---|
| 8836 | + |
---|
| 8837 | + if (j%2 == 0) |
---|
| 8838 | + success |= intersectTriangle(ray, result, s1, s2, s3); |
---|
| 8839 | + else |
---|
| 8840 | + success |= intersectTriangle(ray, result, s1, s3, s2); |
---|
| 8841 | + |
---|
| 8842 | + s1.set(s2); |
---|
| 8843 | + s2.set(s3); |
---|
| 8844 | + } |
---|
| 8845 | + } |
---|
| 8846 | + } |
---|
| 8847 | + |
---|
| 8848 | + assert count3 == v.length; |
---|
| 8849 | + } |
---|
| 8850 | + else // !trimmed |
---|
| 8851 | + { |
---|
| 8852 | + int count = 0; |
---|
| 8853 | + for (int i = 0; i < strips.length; i++) |
---|
| 8854 | + { |
---|
| 8855 | + Vertex p = bRep.GetVertex(bRep.indices[count++]); |
---|
| 8856 | + Vertex q = bRep.GetVertex(bRep.indices[count++]); |
---|
| 8857 | + |
---|
| 8858 | + for (int j = 0; j < strips[i] - 2; j++) |
---|
| 8859 | + { |
---|
| 8860 | + Vertex r = bRep.GetVertex(bRep.indices[count++]); |
---|
| 8861 | + |
---|
| 8862 | + if (j%2 == 0) |
---|
| 8863 | + success |= intersectTriangle(ray, result, p, q, r); |
---|
| 8864 | + else |
---|
| 8865 | + success |= intersectTriangle(ray, result, p, r, q); |
---|
| 8866 | + |
---|
| 8867 | + p = q; |
---|
| 8868 | + q = r; |
---|
| 8869 | + } |
---|
| 8870 | + } |
---|
| 8871 | + } |
---|
| 8872 | + } else // catch (Error e) |
---|
| 8873 | + { |
---|
| 8874 | + int facecount = bRep.FaceCount(); |
---|
| 8875 | + for (int i = 0; i < facecount; i++) |
---|
| 8876 | + { |
---|
| 8877 | + Face face = bRep.GetFace(i); |
---|
| 8878 | + |
---|
| 8879 | + Vertex p = bRep.GetVertex(face.p); |
---|
| 8880 | + Vertex q = bRep.GetVertex(face.q); |
---|
| 8881 | + Vertex r = bRep.GetVertex(face.r); |
---|
| 8882 | + |
---|
| 8883 | + success |= intersectTriangle(ray, result, p, q, r); |
---|
| 8884 | + } |
---|
| 8885 | + } |
---|
| 8886 | + |
---|
| 8887 | + return success; |
---|
| 8888 | + } |
---|
| 8889 | + |
---|
| 8890 | + static cVector eye = new cVector(); |
---|
| 8891 | + static cVector dir = new cVector(); |
---|
| 8892 | + |
---|
| 8893 | + transient BBox bbox = null; |
---|
| 8894 | + |
---|
| 8895 | + boolean intersect(Ray ray, IntersectResult result) |
---|
| 8896 | + { |
---|
| 8897 | + double eyex = ray.eyePoint.x; |
---|
| 8898 | + double eyey = ray.eyePoint.y; |
---|
| 8899 | + double eyez = ray.eyePoint.z; |
---|
| 8900 | + |
---|
| 8901 | + double dirx = ray.viewDirection.x; |
---|
| 8902 | + double diry = ray.viewDirection.y; |
---|
| 8903 | + double dirz = ray.viewDirection.z; |
---|
| 8904 | + |
---|
| 8905 | + if (this.fromParent != null && !(this instanceof TextureNode)) |
---|
| 8906 | + { |
---|
| 8907 | + eye.x = eyex; |
---|
| 8908 | + eye.y = eyey; |
---|
| 8909 | + eye.z = eyez; |
---|
| 8910 | + dir.x = dirx; |
---|
| 8911 | + dir.y = diry; |
---|
| 8912 | + dir.z = dirz; |
---|
| 8913 | + |
---|
| 8914 | + LA.xformPos(eye, this.fromParent, eye); |
---|
| 8915 | + LA.xformDir(dir, this.fromParent, dir); |
---|
| 8916 | + |
---|
| 8917 | + ray.eyePoint.x = eye.x; |
---|
| 8918 | + ray.eyePoint.y = eye.y; |
---|
| 8919 | + ray.eyePoint.z = eye.z; |
---|
| 8920 | + |
---|
| 8921 | + ray.viewDirection.x = dir.x; |
---|
| 8922 | + ray.viewDirection.y = dir.y; |
---|
| 8923 | + ray.viewDirection.z = dir.z; |
---|
| 8924 | + } |
---|
| 8925 | + |
---|
| 8926 | + boolean success = false; |
---|
| 8927 | + |
---|
| 8928 | + boolean touch = false; |
---|
| 8929 | + |
---|
| 8930 | + if (bRep != null && Link2Support()) |
---|
| 8931 | + { |
---|
| 8932 | + if (bbox == null) |
---|
| 8933 | + { |
---|
| 8934 | + bbox = new BBox(); |
---|
| 8935 | + |
---|
| 8936 | + cVector min = new cVector(); |
---|
| 8937 | + cVector max = new cVector(); |
---|
| 8938 | + |
---|
| 8939 | + this.getBounds(min, max, true); |
---|
| 8940 | + |
---|
| 8941 | + bbox.min.x = min.x; |
---|
| 8942 | + bbox.min.y = min.y; |
---|
| 8943 | + bbox.min.z = min.z; |
---|
| 8944 | + |
---|
| 8945 | + bbox.max.x = max.x; |
---|
| 8946 | + bbox.max.y = max.y; |
---|
| 8947 | + bbox.max.z = max.z; |
---|
| 8948 | + } |
---|
| 8949 | + |
---|
| 8950 | + if (true) // NOT WORKING bbox.intersect(ray, result)) |
---|
| 8951 | + { |
---|
| 8952 | + success |= intersectMesh(ray, result); |
---|
| 8953 | + } |
---|
| 8954 | + else |
---|
| 8955 | + { |
---|
| 8956 | + //this.hide = true; |
---|
| 8957 | + touch = true; |
---|
| 8958 | + } |
---|
| 8959 | + } |
---|
| 8960 | + |
---|
| 8961 | + for (int i=0; i<size(); i++) |
---|
| 8962 | + { |
---|
| 8963 | + Object3D child = (Object3D) reserve(i); |
---|
| 8964 | + |
---|
| 8965 | + if (child == null) |
---|
| 8966 | + continue; |
---|
| 8967 | + |
---|
| 8968 | + success |= child.intersect(ray, result); |
---|
| 8969 | + release(i); |
---|
| 8970 | + } |
---|
| 8971 | + |
---|
| 8972 | + ray.eyePoint.x = eyex; |
---|
| 8973 | + ray.eyePoint.y = eyey; |
---|
| 8974 | + ray.eyePoint.z = eyez; |
---|
| 8975 | + |
---|
| 8976 | + ray.viewDirection.x = dirx; |
---|
| 8977 | + ray.viewDirection.y = diry; |
---|
| 8978 | + ray.viewDirection.z = dirz; |
---|
| 8979 | + |
---|
| 8980 | +// if (touch) |
---|
| 8981 | +// this.Touch(); // refresh display list |
---|
| 8982 | + |
---|
| 8983 | + return success; |
---|
| 8984 | + } |
---|
| 8985 | + |
---|
| 8986 | + static Vector3d edge1 = new Vector3d(); |
---|
| 8987 | + static Vector3d edge2 = new Vector3d(); |
---|
| 8988 | + static Vector3d P = new Vector3d(); |
---|
| 8989 | + static Vector3d T = new Vector3d(); |
---|
| 8990 | + static Vector3d Q = new Vector3d(); |
---|
| 8991 | + |
---|
| 8992 | + private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3) |
---|
| 8993 | + { |
---|
| 8994 | + if (false) |
---|
| 8995 | + { |
---|
| 8996 | + result.t = 0; |
---|
| 8997 | + return true; |
---|
| 8998 | + } |
---|
| 8999 | + |
---|
| 9000 | + /* |
---|
| 9001 | + Fast, Minimum Storage Ray/Triangle Intersection, Moller et al. |
---|
| 9002 | + |
---|
| 9003 | + Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf |
---|
| 9004 | + */ |
---|
| 9005 | + |
---|
| 9006 | + // Calculate edges of the triangle |
---|
| 9007 | + edge1.set(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z); |
---|
| 9008 | + edge2.set(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z); |
---|
| 9009 | + |
---|
| 9010 | + // Calculate the determinant (U parameter) |
---|
| 9011 | + P.cross(ray.viewDirection, edge2); |
---|
| 9012 | + double det = edge1.dot(P); |
---|
| 9013 | + |
---|
| 9014 | + if (det > -1e-9 && det < 1e-9) |
---|
| 9015 | + { |
---|
| 9016 | + return false; |
---|
| 9017 | + } // Ray lies in plane of triangle |
---|
| 9018 | + |
---|
| 9019 | + double invDet = 1 / det; |
---|
| 9020 | + |
---|
| 9021 | + // Calculate distance from vertex1 to ray origin |
---|
| 9022 | + T.set(ray.eyePoint.x - v1.x, ray.eyePoint.y - v1.y, ray.eyePoint.z - v1.z); |
---|
| 9023 | + |
---|
| 9024 | + double U = (T.dot(P)) * invDet; // Calculate U parameter |
---|
| 9025 | + |
---|
| 9026 | + if (U < 0.f || U > 1.f) |
---|
| 9027 | + { |
---|
| 9028 | + return false; |
---|
| 9029 | + } // Intersection lies outside of the triangle |
---|
| 9030 | + |
---|
| 9031 | + // Calculate V parameter |
---|
| 9032 | + Q.cross(T, edge1); |
---|
| 9033 | + |
---|
| 9034 | + double V = ray.viewDirection.dot(Q) * invDet; |
---|
| 9035 | + |
---|
| 9036 | + if (V < 0.f || (U + V) > 1.f) |
---|
| 9037 | + { |
---|
| 9038 | + return false; |
---|
| 9039 | + } // Intersection lies outside of the triangle |
---|
| 9040 | + |
---|
| 9041 | + double t = edge2.dot(Q) * invDet; |
---|
| 9042 | + |
---|
| 9043 | + if (t > 1e-9) // Triangle and ray intersects |
---|
| 9044 | + { |
---|
| 9045 | + //result.isIntersected = true; |
---|
| 9046 | + //result.id = id; |
---|
| 9047 | + |
---|
| 9048 | + if (false) // isShadow) |
---|
| 9049 | + { |
---|
| 9050 | + result.t = t; |
---|
| 9051 | + return true; |
---|
| 9052 | + } else if (t < result.t) |
---|
| 9053 | + { |
---|
| 9054 | + result.object = this; |
---|
| 9055 | + |
---|
| 9056 | + result.t = t; |
---|
| 9057 | + |
---|
| 9058 | + //result.p.x = ray.eyePoint.x + ray.viewDirection.x * t; |
---|
| 9059 | + //result.p.y = ray.eyePoint.y + ray.viewDirection.y * t; |
---|
| 9060 | + //result.p.z = ray.eyePoint.z + ray.viewDirection.z * t; |
---|
| 9061 | + |
---|
| 9062 | + result.n.cross(edge1, edge2); |
---|
| 9063 | + result.n.normalize(); |
---|
| 9064 | + } |
---|
| 9065 | + |
---|
| 9066 | + return true; |
---|
| 9067 | + } |
---|
| 9068 | + |
---|
| 9069 | + return false; |
---|
| 9070 | + } |
---|
8254 | 9071 | |
---|
8255 | 9072 | public int Size() |
---|
8256 | 9073 | { |
---|