.. | .. |
---|
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 | // |
---|
| 35 | + |
---|
| 36 | + String skyboxname; |
---|
| 37 | + String skyboxext; |
---|
| 38 | + |
---|
| 39 | + Object3D[] versionlist; |
---|
| 40 | + int versionindex = -1; |
---|
| 41 | + |
---|
| 42 | + java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>(); |
---|
31 | 43 | |
---|
32 | 44 | ScriptNode scriptnode; |
---|
33 | 45 | |
---|
| 46 | + void deepCopyNode(Object3D other) |
---|
| 47 | + { |
---|
| 48 | + other.skyboxname = skyboxname; |
---|
| 49 | + other.skyboxext = skyboxext; |
---|
| 50 | + |
---|
| 51 | + if (toParent != null) |
---|
| 52 | + { |
---|
| 53 | + other.toParent = LA.newMatrix(); |
---|
| 54 | + other.fromParent = LA.newMatrix(); |
---|
| 55 | + LA.matCopy(toParent, other.toParent); |
---|
| 56 | + LA.matCopy(fromParent, other.fromParent); |
---|
| 57 | + if (toParentMarked != null) |
---|
| 58 | + { |
---|
| 59 | + other.toParentMarked = LA.newMatrix(); |
---|
| 60 | + other.fromParentMarked = LA.newMatrix(); |
---|
| 61 | + LA.matCopy(toParentMarked, other.toParentMarked); |
---|
| 62 | + LA.matCopy(fromParentMarked, other.fromParentMarked); |
---|
| 63 | + } |
---|
| 64 | + } |
---|
| 65 | + else |
---|
| 66 | + { |
---|
| 67 | + if (other.toParent == null) |
---|
| 68 | +// assert(other.toParent == null); |
---|
| 69 | +// new Exception().printStackTrace(); |
---|
| 70 | + System.err.println("null parent: " + other); |
---|
| 71 | + } |
---|
| 72 | + |
---|
| 73 | + /* |
---|
| 74 | + double ident[][] = LA.newMatrix(); |
---|
| 75 | + if (bRep == null) |
---|
| 76 | + other.bRep = null; |
---|
| 77 | + else |
---|
| 78 | + other.bRep = new BoundaryRep(bRep, ident); |
---|
| 79 | + */ |
---|
| 80 | + // Really new... |
---|
| 81 | + //other.editWindow = null; |
---|
| 82 | + if (name == null) |
---|
| 83 | + other.name = null; |
---|
| 84 | + else |
---|
| 85 | + other.name = new String(name); |
---|
| 86 | + |
---|
| 87 | + if (material != null) |
---|
| 88 | + { |
---|
| 89 | + other.material = new cMaterial(material); |
---|
| 90 | + } else |
---|
| 91 | + { |
---|
| 92 | + other.material = null; |
---|
| 93 | + } |
---|
| 94 | + |
---|
| 95 | + other.GetTextures().name = GetTextures().name; |
---|
| 96 | + |
---|
| 97 | + CopyExtraMaterial(other); |
---|
| 98 | + |
---|
| 99 | + other.touched = touched; |
---|
| 100 | + other.softtouched = softtouched; |
---|
| 101 | + |
---|
| 102 | + other.random = random; |
---|
| 103 | + other.link2master = link2master; |
---|
| 104 | + other.transformcount = transformcount; |
---|
| 105 | + other.marked = marked; |
---|
| 106 | + other.skip = skip; |
---|
| 107 | + other.count = count; |
---|
| 108 | + other.flipV = flipV; |
---|
| 109 | + other.live = live; |
---|
| 110 | + other.rewind = rewind; |
---|
| 111 | + other.hide = hide; |
---|
| 112 | + other.texres = texres; |
---|
| 113 | + other.speedup = speedup; |
---|
| 114 | + other.height = height; |
---|
| 115 | + other.depth = depth; |
---|
| 116 | + } |
---|
| 117 | + |
---|
| 118 | + int VersionCount() |
---|
| 119 | + { |
---|
| 120 | + int count = 0; |
---|
| 121 | + |
---|
| 122 | + if (versionlist != null) |
---|
| 123 | + for (int i = versionlist.length; --i >= 0;) |
---|
| 124 | + { |
---|
| 125 | + if (versionlist[i] != null) |
---|
| 126 | + count++; |
---|
| 127 | + } |
---|
| 128 | + |
---|
| 129 | + return count; |
---|
| 130 | + } |
---|
| 131 | + |
---|
34 | 132 | void InitOthers() |
---|
35 | 133 | { |
---|
36 | 134 | if (projectedVertices == null || projectedVertices.length <= 2) |
---|
.. | .. |
---|
42 | 140 | projectedVertices[i] = new cVector2(); // Others |
---|
43 | 141 | } |
---|
44 | 142 | projectedVertices[0].x = 100; // bump |
---|
| 143 | + projectedVertices[1].y = 1000; // punchthrough. only for png |
---|
45 | 144 | } |
---|
46 | 145 | |
---|
47 | 146 | void MinMax(cVector minima, cVector maxima) |
---|
.. | .. |
---|
168 | 267 | } |
---|
169 | 268 | } |
---|
170 | 269 | |
---|
| 270 | + boolean HasBigData() |
---|
| 271 | + { |
---|
| 272 | + if (blockloop) |
---|
| 273 | + return false; |
---|
| 274 | + |
---|
| 275 | + if (bRep != null) |
---|
| 276 | + { |
---|
| 277 | + return true; |
---|
| 278 | + } |
---|
| 279 | + |
---|
| 280 | + blockloop = true; |
---|
| 281 | + |
---|
| 282 | + for (int i = 0; i < Size(); i++) |
---|
| 283 | + { |
---|
| 284 | + Object3D child = (Object3D) get(i); |
---|
| 285 | + if (child == null) |
---|
| 286 | + continue; |
---|
| 287 | + if (child.HasBigData()) |
---|
| 288 | + { |
---|
| 289 | + blockloop = false; |
---|
| 290 | + return true; |
---|
| 291 | + } |
---|
| 292 | + } |
---|
| 293 | + |
---|
| 294 | + blockloop = false; |
---|
| 295 | + return false; |
---|
| 296 | + } |
---|
| 297 | + |
---|
171 | 298 | void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable) |
---|
172 | 299 | { |
---|
| 300 | + if (blockloop) |
---|
| 301 | + return; |
---|
| 302 | + |
---|
173 | 303 | Object3D o; |
---|
| 304 | + |
---|
| 305 | + boolean isnew = false; |
---|
174 | 306 | |
---|
175 | 307 | if (hashtable.containsKey(GetUUID())) |
---|
176 | 308 | { |
---|
.. | .. |
---|
184 | 316 | } |
---|
185 | 317 | else |
---|
186 | 318 | { |
---|
| 319 | + isnew = true; |
---|
| 320 | + |
---|
187 | 321 | o = new Object3D("copy of " + this.name); |
---|
188 | 322 | |
---|
189 | 323 | hashtable.put(GetUUID(), o); |
---|
190 | 324 | } |
---|
191 | 325 | |
---|
192 | | - if (!blockloop) |
---|
| 326 | + //if (!blockloop) |
---|
193 | 327 | { |
---|
194 | 328 | blockloop = true; |
---|
195 | 329 | |
---|
.. | .. |
---|
200 | 334 | |
---|
201 | 335 | blockloop = false; |
---|
202 | 336 | } |
---|
203 | | - |
---|
204 | | - ExtractBigData(o); |
---|
| 337 | + |
---|
| 338 | + //if (isnew) |
---|
| 339 | + ExtractBigData(o); |
---|
205 | 340 | } |
---|
206 | 341 | |
---|
207 | 342 | void ExtractBigData(Object3D o) |
---|
208 | 343 | { |
---|
| 344 | + //System.err.println("ExtractBigData : " + this + " --> " + o); |
---|
| 345 | + |
---|
209 | 346 | if (o.bRep != null) |
---|
210 | 347 | Grafreed.Assert(o.bRep == this.bRep); |
---|
211 | 348 | |
---|
.. | .. |
---|
215 | 352 | // o.transientrep = this.bRep.support; |
---|
216 | 353 | // o.bRep.support = null; |
---|
217 | 354 | // } |
---|
| 355 | + o.selection = this.selection; |
---|
| 356 | + //o.versionlist = this.versionlist; |
---|
| 357 | + //o.versionindex = this.versionindex; |
---|
218 | 358 | |
---|
219 | 359 | if (this.support != null) |
---|
220 | 360 | { |
---|
.. | .. |
---|
237 | 377 | // this.fileparent = null; |
---|
238 | 378 | } |
---|
239 | 379 | |
---|
| 380 | +// Object3D GetObject(java.util.UUID uuid) |
---|
| 381 | +// { |
---|
| 382 | +// if (this.uuid.equals(uuid)) |
---|
| 383 | +// return this; |
---|
| 384 | +// |
---|
| 385 | +// if (blockloop) |
---|
| 386 | +// return null; |
---|
| 387 | +// |
---|
| 388 | +// blockloop = true; |
---|
| 389 | +// |
---|
| 390 | +// for (int i=0; i<Size(); i++) |
---|
| 391 | +// { |
---|
| 392 | +// Object3D o = get(i).GetObject(uuid); |
---|
| 393 | +// |
---|
| 394 | +// if (o != null) |
---|
| 395 | +// return o; |
---|
| 396 | +// } |
---|
| 397 | +// |
---|
| 398 | +// blockloop = false; |
---|
| 399 | +// |
---|
| 400 | +// return null; |
---|
| 401 | +// } |
---|
| 402 | + |
---|
| 403 | + transient boolean tag; |
---|
| 404 | + |
---|
| 405 | + void TagObjects(Object3D o, boolean tag) |
---|
| 406 | + { |
---|
| 407 | + if (blockloop) |
---|
| 408 | + return; |
---|
| 409 | + |
---|
| 410 | + o.tag = tag; |
---|
| 411 | + |
---|
| 412 | + if (o == this) |
---|
| 413 | + return; |
---|
| 414 | + |
---|
| 415 | + blockloop = true; |
---|
| 416 | + |
---|
| 417 | + for (int i=0; i<Size(); i++) |
---|
| 418 | + { |
---|
| 419 | + get(i).TagObjects(o, tag); |
---|
| 420 | + } |
---|
| 421 | + |
---|
| 422 | + blockloop = false; |
---|
| 423 | + } |
---|
| 424 | + |
---|
| 425 | + boolean HasTags() |
---|
| 426 | + { |
---|
| 427 | + if (blockloop) |
---|
| 428 | + return false; |
---|
| 429 | + |
---|
| 430 | + blockloop = true; |
---|
| 431 | + |
---|
| 432 | + boolean hasTags = false; |
---|
| 433 | + |
---|
| 434 | + for (int i=0; i<Size(); i++) |
---|
| 435 | + { |
---|
| 436 | + hasTags |= get(i).tag || get(i).HasTags(); |
---|
| 437 | + |
---|
| 438 | + if (hasTags) |
---|
| 439 | + break; |
---|
| 440 | + } |
---|
| 441 | + |
---|
| 442 | + blockloop = false; |
---|
| 443 | + |
---|
| 444 | + return hasTags; |
---|
| 445 | + } |
---|
| 446 | + |
---|
240 | 447 | void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable) |
---|
241 | 448 | { |
---|
| 449 | + if (blockloop) |
---|
| 450 | + return; |
---|
| 451 | + |
---|
242 | 452 | if (!hashtable.containsKey(GetUUID())) |
---|
243 | 453 | return; |
---|
244 | 454 | |
---|
245 | 455 | Object3D o = hashtable.get(GetUUID()); |
---|
246 | 456 | |
---|
247 | 457 | RestoreBigData(o); |
---|
248 | | - |
---|
249 | | - if (blockloop) |
---|
250 | | - return; |
---|
251 | 458 | |
---|
252 | 459 | blockloop = true; |
---|
253 | 460 | |
---|
.. | .. |
---|
263 | 470 | |
---|
264 | 471 | void RestoreBigData(Object3D o) |
---|
265 | 472 | { |
---|
| 473 | + //System.err.println("RestoreBigData : " + this + " <-- " + o); |
---|
| 474 | + Grafreed.Assert(this.bRep == null); |
---|
| 475 | + |
---|
266 | 476 | this.bRep = o.bRep; |
---|
267 | 477 | if (this.support != null && o.transientrep != null) |
---|
268 | 478 | { |
---|
269 | 479 | this.support.bRep = o.transientrep; |
---|
270 | 480 | } |
---|
| 481 | + |
---|
| 482 | + this.selection = o.selection; |
---|
| 483 | + |
---|
| 484 | + //this.versionlist = o.versionlist; |
---|
| 485 | + //this.versionindex = o.versionindex; |
---|
271 | 486 | // July 2019 if (this.bRep != null) |
---|
272 | 487 | // this.bRep.support = o.transientrep; |
---|
273 | 488 | // this.support = o.support; |
---|
.. | .. |
---|
415 | 630 | } |
---|
416 | 631 | |
---|
417 | 632 | boolean live = false; |
---|
| 633 | + transient boolean keepdontselect; |
---|
418 | 634 | boolean dontselect = false; |
---|
419 | 635 | boolean hide = false; |
---|
420 | 636 | boolean link2master = false; // performs reset support/master at each frame |
---|
.. | .. |
---|
425 | 641 | boolean random = false; |
---|
426 | 642 | boolean speedup = false; |
---|
427 | 643 | boolean rewind = false; |
---|
| 644 | + |
---|
| 645 | + // Option to sort triangles, e.g. for transparency. |
---|
| 646 | + boolean sort = false; |
---|
428 | 647 | |
---|
429 | 648 | float NORMALPUSH = 0; |
---|
430 | 649 | |
---|
.. | .. |
---|
443 | 662 | { |
---|
444 | 663 | sorted = true; |
---|
445 | 664 | |
---|
446 | | - for (int i=0; i<size()-1; i++) |
---|
| 665 | + for (int i=0; i<Size()-1; i++) |
---|
447 | 666 | { |
---|
448 | 667 | Object3D obji = get(i); |
---|
449 | 668 | Object3D objj = get(i+1); |
---|
.. | .. |
---|
467 | 686 | { |
---|
468 | 687 | sorted = true; |
---|
469 | 688 | |
---|
470 | | - for (int i=0; i<size()-1; i++) |
---|
| 689 | + for (int i=0; i<Size()-1; i++) |
---|
471 | 690 | { |
---|
472 | 691 | Object3D obji = get(i); |
---|
473 | 692 | Object3D objj = get(i+1); |
---|
.. | .. |
---|
483 | 702 | } |
---|
484 | 703 | } |
---|
485 | 704 | |
---|
486 | | - int memorysize; |
---|
| 705 | + transient int memorysize; // needs to be transient, dunno why |
---|
487 | 706 | |
---|
488 | 707 | int MemorySize() |
---|
489 | 708 | { |
---|
490 | | - if (true) // memorysize == 0) |
---|
| 709 | + if (memorysize == 0) |
---|
491 | 710 | { |
---|
492 | 711 | try |
---|
493 | 712 | { |
---|
.. | .. |
---|
602 | 821 | { |
---|
603 | 822 | if (maxcount != 1) |
---|
604 | 823 | { |
---|
605 | | - new Exception().printStackTrace(); |
---|
| 824 | + //new Exception().printStackTrace(); |
---|
606 | 825 | } |
---|
607 | 826 | |
---|
608 | 827 | toParentMarked = LA.newMatrix(); |
---|
.. | .. |
---|
997 | 1216 | { |
---|
998 | 1217 | // return true; |
---|
999 | 1218 | |
---|
1000 | | - if (material == null || material.multiply) |
---|
1001 | | - return true; |
---|
| 1219 | +// if (material == null || material.multiply) |
---|
| 1220 | +// return true; |
---|
| 1221 | +// |
---|
| 1222 | +// if (projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000) |
---|
| 1223 | +// return false; |
---|
| 1224 | +// |
---|
| 1225 | +// // Transparent objects are dynamic because we have to sort the triangles. |
---|
| 1226 | +// return material.opacity > 0.99; |
---|
1002 | 1227 | |
---|
1003 | | - // Transparent objects are dynamic because we have to sort the triangles. |
---|
1004 | | - return material.opacity > 0.99; |
---|
| 1228 | + return !sort; |
---|
1005 | 1229 | } |
---|
1006 | 1230 | |
---|
1007 | 1231 | boolean IsOpaque() |
---|
1008 | 1232 | { |
---|
1009 | 1233 | // return true; |
---|
1010 | 1234 | |
---|
1011 | | - if (material == null || material.multiply) |
---|
1012 | | - return true; |
---|
| 1235 | +// if (material == null || material.multiply) |
---|
| 1236 | +// return true; |
---|
| 1237 | +// |
---|
| 1238 | +// return material.opacity > 0.99; |
---|
1013 | 1239 | |
---|
1014 | | - return material.opacity > 0.99; |
---|
| 1240 | + return !sort; |
---|
1015 | 1241 | } |
---|
1016 | 1242 | |
---|
1017 | 1243 | Object3D() |
---|
.. | .. |
---|
1089 | 1315 | |
---|
1090 | 1316 | // will share the geometry |
---|
1091 | 1317 | assert (!(this instanceof Composite)); |
---|
1092 | | - return deepCopy(); // Never called for Composite |
---|
1093 | | - |
---|
| 1318 | + |
---|
| 1319 | + Object3D obj = deepCopy(); // Never called for Composite |
---|
| 1320 | + obj.count = 2; |
---|
| 1321 | + return obj; |
---|
1094 | 1322 | } |
---|
1095 | 1323 | |
---|
1096 | 1324 | boolean HasLoops() |
---|
.. | .. |
---|
1098 | 1326 | return false; |
---|
1099 | 1327 | } |
---|
1100 | 1328 | |
---|
| 1329 | + void ResetUUIDs() |
---|
| 1330 | + { |
---|
| 1331 | + if (blockloop) |
---|
| 1332 | + { |
---|
| 1333 | + return; |
---|
| 1334 | + } |
---|
| 1335 | + |
---|
| 1336 | + this.uuid = null; |
---|
| 1337 | + |
---|
| 1338 | + blockloop = true; |
---|
| 1339 | + |
---|
| 1340 | + for (int i = 0; i < Size(); i++) |
---|
| 1341 | + { |
---|
| 1342 | + Object3D obj = (Object3D) Children().get(i); |
---|
| 1343 | + |
---|
| 1344 | + if (obj != null) |
---|
| 1345 | + { |
---|
| 1346 | + obj.ResetUUIDs(); |
---|
| 1347 | + } |
---|
| 1348 | + } |
---|
| 1349 | + |
---|
| 1350 | + blockloop = false; |
---|
| 1351 | + } |
---|
| 1352 | + |
---|
1101 | 1353 | boolean IsInfinite() |
---|
1102 | 1354 | { |
---|
1103 | 1355 | if (blockloop) |
---|
.. | .. |
---|
1168 | 1420 | return; |
---|
1169 | 1421 | |
---|
1170 | 1422 | blockloop = true; |
---|
| 1423 | + |
---|
| 1424 | + other.parent = parent; |
---|
| 1425 | + |
---|
1171 | 1426 | //System.out.println("COPY " + this + " to " + other); |
---|
1172 | 1427 | //new Exception().printStackTrace(); |
---|
| 1428 | + deepCopyNode(other); |
---|
1173 | 1429 | |
---|
1174 | | - other.parent = parent; |
---|
1175 | | - if (toParent != null) |
---|
1176 | | - { |
---|
1177 | | - other.toParent = LA.newMatrix(); |
---|
1178 | | - other.fromParent = LA.newMatrix(); |
---|
1179 | | - LA.matCopy(toParent, other.toParent); |
---|
1180 | | - LA.matCopy(fromParent, other.fromParent); |
---|
1181 | | - if (toParentMarked != null) |
---|
1182 | | - { |
---|
1183 | | - other.toParentMarked = LA.newMatrix(); |
---|
1184 | | - other.fromParentMarked = LA.newMatrix(); |
---|
1185 | | - LA.matCopy(toParentMarked, other.toParentMarked); |
---|
1186 | | - LA.matCopy(fromParentMarked, other.fromParentMarked); |
---|
1187 | | - } |
---|
1188 | | - } |
---|
1189 | | - else |
---|
1190 | | - { |
---|
1191 | | - if (other.toParent == null) |
---|
1192 | | -// assert(other.toParent == null); |
---|
1193 | | -// new Exception().printStackTrace(); |
---|
1194 | | - System.err.println("null parent: " + other); |
---|
1195 | | - } |
---|
1196 | | - /* |
---|
1197 | | - double ident[][] = LA.newMatrix(); |
---|
1198 | | - if (bRep == null) |
---|
1199 | | - other.bRep = null; |
---|
1200 | | - else |
---|
1201 | | - other.bRep = new BoundaryRep(bRep, ident); |
---|
1202 | | - */ |
---|
1203 | | - // Really new... |
---|
1204 | 1430 | other.bRep = bRep; // Share the geometry |
---|
1205 | 1431 | |
---|
1206 | 1432 | other.support = support; // Share the support |
---|
1207 | | - |
---|
1208 | | - //other.editWindow = null; |
---|
1209 | | - if (name == null) |
---|
1210 | | - other.name = null; |
---|
1211 | | - else |
---|
1212 | | - other.name = new String(name); |
---|
1213 | | - |
---|
1214 | | - if (material != null) |
---|
1215 | | - { |
---|
1216 | | - other.material = new cMaterial(material); |
---|
1217 | | - } else |
---|
1218 | | - { |
---|
1219 | | - other.material = null; |
---|
1220 | | - } |
---|
1221 | | - |
---|
1222 | | - other.GetTextures().name = GetTextures().name; |
---|
1223 | | - |
---|
1224 | | - CopyExtraMaterial(other); |
---|
1225 | | - |
---|
1226 | | - other.touched = touched; |
---|
1227 | | - other.softtouched = softtouched; |
---|
1228 | | - |
---|
1229 | | - other.random = random; |
---|
1230 | | - other.link2master = link2master; |
---|
1231 | | - other.transformcount = transformcount; |
---|
1232 | | - other.marked = marked; |
---|
1233 | | - other.skip = skip; |
---|
1234 | | - other.count = count; |
---|
1235 | | - other.flipV = flipV; |
---|
1236 | | - other.live = live; |
---|
1237 | | - other.rewind = rewind; |
---|
1238 | | - other.hide = hide; |
---|
1239 | | - other.texres = texres; |
---|
1240 | | - other.speedup = speedup; |
---|
1241 | | - other.height = height; |
---|
1242 | | - other.depth = depth; |
---|
1243 | 1433 | |
---|
1244 | 1434 | // aout 2013 if (/*displaylist != -1 &&*/other.displaylist != displaylist) |
---|
1245 | 1435 | // { |
---|
.. | .. |
---|
1295 | 1485 | if ((mask & GEOMETRY) != 0) |
---|
1296 | 1486 | { |
---|
1297 | 1487 | if (bRep != null) |
---|
1298 | | - bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep); |
---|
1299 | | - else |
---|
1300 | | - assert(other.bRep == null); |
---|
1301 | | - |
---|
1302 | | - if (bRep != null) |
---|
1303 | 1488 | { |
---|
| 1489 | + bRep.overwriteThis(other.bRep==null?other.transientrep:other.bRep); |
---|
1304 | 1490 | CameraPane.RemoveList(bRep.displaylist); |
---|
1305 | 1491 | bRep.displaylist = 0; // june 2013 -1; |
---|
1306 | 1492 | } |
---|
1307 | 1493 | else |
---|
1308 | | - bRep = bRep; |
---|
| 1494 | + { |
---|
| 1495 | + //assert(other.bRep == null); |
---|
| 1496 | + bRep = other.bRep; |
---|
| 1497 | + } |
---|
| 1498 | + |
---|
| 1499 | +// if (bRep != null) |
---|
| 1500 | +// { |
---|
| 1501 | +// CameraPane.RemoveList(bRep.displaylist); |
---|
| 1502 | +// bRep.displaylist = 0; // june 2013 -1; |
---|
| 1503 | +// } |
---|
| 1504 | +// else |
---|
| 1505 | +// bRep = bRep; |
---|
1309 | 1506 | } |
---|
1310 | 1507 | |
---|
1311 | 1508 | /* Use a MASK = GEO/MAT |
---|
.. | .. |
---|
2281 | 2478 | |
---|
2282 | 2479 | InitOthers(); |
---|
2283 | 2480 | |
---|
2284 | | - if (this instanceof Camera) |
---|
2285 | | - { |
---|
2286 | | - material.shift = 90; |
---|
2287 | | - } |
---|
2288 | | - |
---|
2289 | 2481 | material.multiply = multiply; |
---|
2290 | 2482 | |
---|
2291 | 2483 | if (multiply) |
---|
.. | .. |
---|
2426 | 2618 | else |
---|
2427 | 2619 | { |
---|
2428 | 2620 | //((ObjEditor)editWindow).SetupUI2(null); |
---|
| 2621 | + if (objectUI != null) |
---|
| 2622 | + ((ObjEditor)objectUI).pinButton.setSelected(pinned); |
---|
| 2623 | + else |
---|
| 2624 | + //new Exception().printStackTrace(); |
---|
| 2625 | + System.err.println("objectUI is null"); |
---|
2429 | 2626 | } |
---|
2430 | 2627 | } |
---|
2431 | 2628 | |
---|
.. | .. |
---|
2555 | 2752 | private static final int editSelf = 1; |
---|
2556 | 2753 | private static final int editChild = 2; |
---|
2557 | 2754 | |
---|
2558 | | - void drawEditHandles(ClickInfo info, int level) |
---|
| 2755 | + void drawEditHandles(//ClickInfo info, |
---|
| 2756 | + int level) |
---|
2559 | 2757 | { |
---|
2560 | 2758 | if (level == 0) |
---|
2561 | 2759 | { |
---|
.. | .. |
---|
2563 | 2761 | return; |
---|
2564 | 2762 | |
---|
2565 | 2763 | Object3D selectee; |
---|
2566 | | - for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(info, level + 1)) |
---|
| 2764 | + for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(//info, |
---|
| 2765 | + level + 1)) |
---|
2567 | 2766 | { |
---|
2568 | 2767 | selectee = (Object3D) e.nextElement(); |
---|
2569 | 2768 | } |
---|
.. | .. |
---|
2571 | 2770 | } else |
---|
2572 | 2771 | { |
---|
2573 | 2772 | //super. |
---|
2574 | | - drawEditHandles0(info, level + 1); |
---|
| 2773 | + drawEditHandles0(//info, |
---|
| 2774 | + level + 1); |
---|
2575 | 2775 | } |
---|
2576 | 2776 | } |
---|
2577 | 2777 | |
---|
2578 | | - boolean doEditClick(ClickInfo info, int level) |
---|
| 2778 | + boolean doEditClick(//ClickInfo info, |
---|
| 2779 | + int level) |
---|
2579 | 2780 | { |
---|
2580 | 2781 | doSomething = 0; |
---|
2581 | 2782 | if (level == 0) |
---|
2582 | 2783 | { |
---|
2583 | | - return doParentClick(info); |
---|
| 2784 | + return doParentClick(); //info); |
---|
2584 | 2785 | } |
---|
2585 | 2786 | if (//super. |
---|
2586 | | - doEditClick0(info, level)) |
---|
| 2787 | + doEditClick0(//info, |
---|
| 2788 | + level)) |
---|
2587 | 2789 | { |
---|
2588 | 2790 | doSomething = 1; |
---|
2589 | 2791 | return true; |
---|
.. | .. |
---|
2593 | 2795 | } |
---|
2594 | 2796 | } |
---|
2595 | 2797 | |
---|
2596 | | - boolean doParentClick(ClickInfo info) |
---|
| 2798 | + boolean doParentClick() //ClickInfo info) |
---|
2597 | 2799 | { |
---|
2598 | 2800 | if (selection == null) |
---|
2599 | 2801 | { |
---|
.. | .. |
---|
2606 | 2808 | for (java.util.Enumeration e = selection.elements(); e.hasMoreElements();) |
---|
2607 | 2809 | { |
---|
2608 | 2810 | Object3D selectee = (Object3D) e.nextElement(); |
---|
2609 | | - if (selectee.doEditClick(info, 1)) |
---|
| 2811 | + if (selectee.doEditClick(//info, |
---|
| 2812 | + 1)) |
---|
2610 | 2813 | { |
---|
2611 | 2814 | childToDrag = selectee; |
---|
2612 | 2815 | doSomething = 2; |
---|
.. | .. |
---|
2618 | 2821 | return retval; |
---|
2619 | 2822 | } |
---|
2620 | 2823 | |
---|
2621 | | - void doEditDrag(ClickInfo info, boolean opposite) |
---|
| 2824 | + void doEditDrag(//ClickInfo clickInfo, |
---|
| 2825 | + boolean opposite) |
---|
2622 | 2826 | { |
---|
2623 | 2827 | switch (doSomething) |
---|
2624 | 2828 | { |
---|
2625 | 2829 | case 1: // '\001' |
---|
2626 | 2830 | //super. |
---|
2627 | | - doEditDrag0(info, opposite); |
---|
| 2831 | + doEditDrag0(//clickInfo, |
---|
| 2832 | + opposite); |
---|
2628 | 2833 | break; |
---|
2629 | 2834 | |
---|
2630 | 2835 | case 2: // '\002' |
---|
.. | .. |
---|
2637 | 2842 | { |
---|
2638 | 2843 | //sel.hitSomething = childToDrag.hitSomething; |
---|
2639 | 2844 | //childToDrag.doEditDrag(info); |
---|
2640 | | - sel.doEditDrag(info, opposite); |
---|
| 2845 | + sel.doEditDrag(//clickInfo, |
---|
| 2846 | + opposite); |
---|
2641 | 2847 | } else |
---|
2642 | 2848 | { |
---|
2643 | 2849 | //super. |
---|
2644 | | - doEditDrag0(info, opposite); |
---|
| 2850 | + doEditDrag0(//clickInfo, |
---|
| 2851 | + opposite); |
---|
2645 | 2852 | } |
---|
2646 | 2853 | } |
---|
2647 | 2854 | break; |
---|
.. | .. |
---|
2659 | 2866 | { |
---|
2660 | 2867 | deselectAll(); |
---|
2661 | 2868 | } |
---|
| 2869 | + |
---|
| 2870 | + new Exception().printStackTrace(); |
---|
| 2871 | + |
---|
2662 | 2872 | ClickInfo newInfo = new ClickInfo(); |
---|
2663 | 2873 | newInfo.flags = info.flags; |
---|
2664 | 2874 | newInfo.bounds = info.bounds; |
---|
.. | .. |
---|
3088 | 3298 | { |
---|
3089 | 3299 | if (bRep != null) |
---|
3090 | 3300 | { |
---|
| 3301 | + //bRep.GenerateNormals2(crease); // in-place doesn't work. it gives wrong normals (diamond artifact). |
---|
3091 | 3302 | bRep.GenerateNormals(crease); |
---|
| 3303 | + if (!bRep.trimmed) |
---|
| 3304 | + bRep.MergeNormals(); |
---|
3092 | 3305 | Touch(); |
---|
3093 | 3306 | } |
---|
3094 | 3307 | } |
---|
.. | .. |
---|
3106 | 3319 | { |
---|
3107 | 3320 | if (bRep != null) |
---|
3108 | 3321 | { |
---|
3109 | | - bRep.GenerateNormalsMINE(); |
---|
| 3322 | + bRep.MergeNormals(); //.GenerateNormalsMINE(); |
---|
3110 | 3323 | Touch(); |
---|
3111 | 3324 | } |
---|
3112 | 3325 | } |
---|
.. | .. |
---|
3163 | 3376 | blockloop = false; |
---|
3164 | 3377 | } |
---|
3165 | 3378 | |
---|
| 3379 | + public void ResetTransform(int mask) |
---|
| 3380 | + { |
---|
| 3381 | + Object3D obj = this; |
---|
| 3382 | + |
---|
| 3383 | + if (mask == -1) |
---|
| 3384 | + { |
---|
| 3385 | + if (obj instanceof Camera) // jan 2014 |
---|
| 3386 | + { |
---|
| 3387 | + LA.matIdentity(obj.toParent); |
---|
| 3388 | + LA.matIdentity(obj.fromParent); |
---|
| 3389 | + } |
---|
| 3390 | + else |
---|
| 3391 | + { |
---|
| 3392 | + obj.toParent = null; // jan 2014 LA.matIdentity(obj.toParent); |
---|
| 3393 | + obj.fromParent = null; // LA.matIdentity(obj.fromParent); |
---|
| 3394 | + } |
---|
| 3395 | + return; |
---|
| 3396 | + } |
---|
| 3397 | + |
---|
| 3398 | + if ((mask&2) != 0) // Scale/rotation |
---|
| 3399 | + { |
---|
| 3400 | + obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = 1; |
---|
| 3401 | + obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0; |
---|
| 3402 | + obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0; |
---|
| 3403 | + obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1; |
---|
| 3404 | + obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0; |
---|
| 3405 | + obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0; |
---|
| 3406 | + } |
---|
| 3407 | + if ((mask&1) != 0) // Translation |
---|
| 3408 | + { |
---|
| 3409 | + if (obj.toParent != null) |
---|
| 3410 | + { |
---|
| 3411 | + obj.toParent[3][0] = obj.toParent[3][1] = obj.toParent[3][2] = 0; |
---|
| 3412 | + obj.fromParent[3][0] = obj.fromParent[3][1] = obj.fromParent[3][2] = 0; |
---|
| 3413 | + } |
---|
| 3414 | + } |
---|
| 3415 | + } |
---|
| 3416 | + |
---|
| 3417 | + public void Scale(int scale) |
---|
| 3418 | + { |
---|
| 3419 | + Object3D obj = this; |
---|
| 3420 | + |
---|
| 3421 | + obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = scale; |
---|
| 3422 | + obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0; |
---|
| 3423 | + obj.toParent[0][2] = obj.toParent[1][2] = obj.toParent[2][1] = 0; |
---|
| 3424 | + obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1/scale; |
---|
| 3425 | + obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0; |
---|
| 3426 | + obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0; |
---|
| 3427 | + } |
---|
| 3428 | + |
---|
| 3429 | + public void TextureRatioTransform(int axis) |
---|
| 3430 | + { |
---|
| 3431 | + cTexture tex = GetTextures(); |
---|
| 3432 | + |
---|
| 3433 | + com.sun.opengl.util.texture.TextureData texturedata = null; |
---|
| 3434 | + |
---|
| 3435 | + try |
---|
| 3436 | + { |
---|
| 3437 | + texturedata = Globals.theRenderer.GetTextureData(tex, false, texres); |
---|
| 3438 | + } |
---|
| 3439 | + catch (Exception e) |
---|
| 3440 | + { |
---|
| 3441 | + System.err.println("FAIL TextureRatio: " + this); |
---|
| 3442 | + } |
---|
| 3443 | + |
---|
| 3444 | + LA.matIdentity(Object3D.mat); |
---|
| 3445 | + Object3D.mat[axis][axis] = (double)texturedata.getWidth() / texturedata.getHeight(); |
---|
| 3446 | + |
---|
| 3447 | + if (toParent == null) |
---|
| 3448 | + { |
---|
| 3449 | + toParent = LA.newMatrix(); |
---|
| 3450 | + fromParent = LA.newMatrix(); |
---|
| 3451 | + } |
---|
| 3452 | + |
---|
| 3453 | + ResetTransform(2); |
---|
| 3454 | + |
---|
| 3455 | + LA.matConcat(Object3D.mat, fromParent, fromParent); |
---|
| 3456 | + LA.matInvert(fromParent, toParent); |
---|
| 3457 | + } |
---|
| 3458 | + |
---|
| 3459 | + void TextureRatio(int axis) |
---|
| 3460 | + { |
---|
| 3461 | + if (blockloop) |
---|
| 3462 | + return; |
---|
| 3463 | + |
---|
| 3464 | + blockloop = true; |
---|
| 3465 | + |
---|
| 3466 | + TextureRatioTransform(axis); |
---|
| 3467 | + |
---|
| 3468 | + for (int i=Size(); --i>=0;) |
---|
| 3469 | + { |
---|
| 3470 | + Object3D v = get(i); |
---|
| 3471 | + |
---|
| 3472 | + v.TextureRatio(axis); |
---|
| 3473 | + } |
---|
| 3474 | + |
---|
| 3475 | + blockloop = false; |
---|
| 3476 | + } |
---|
| 3477 | + |
---|
3166 | 3478 | void TransformChildren() |
---|
3167 | 3479 | { |
---|
3168 | 3480 | if (toParent != null) |
---|
.. | .. |
---|
3405 | 3717 | if (bRep != null) |
---|
3406 | 3718 | { |
---|
3407 | 3719 | //bRep.RemoveOneTriangle(); |
---|
| 3720 | + System.out.println(); |
---|
3408 | 3721 | System.out.println("Reducing " + this); |
---|
3409 | 3722 | if (name != null && name.contains("lockpickstraps")) |
---|
3410 | 3723 | name = name; |
---|
.. | .. |
---|
3516 | 3829 | |
---|
3517 | 3830 | void ClearMaterials() |
---|
3518 | 3831 | { |
---|
| 3832 | + if (blockloop) |
---|
| 3833 | + return; |
---|
| 3834 | + |
---|
| 3835 | + blockloop = true; |
---|
| 3836 | + |
---|
3519 | 3837 | ClearMaterial(); |
---|
3520 | | - for (int i = 0; i < size(); i++) |
---|
| 3838 | + for (int i = 0; i < Size(); i++) |
---|
3521 | 3839 | { |
---|
3522 | | - Object3D child = (Object3D) reserve(i); |
---|
| 3840 | + Object3D child = (Object3D) get(i); |
---|
3523 | 3841 | if (child == null) |
---|
3524 | 3842 | continue; |
---|
3525 | 3843 | child.ClearMaterials(); |
---|
3526 | | - release(i); |
---|
3527 | 3844 | } |
---|
| 3845 | + |
---|
| 3846 | + blockloop = false; |
---|
| 3847 | + } |
---|
| 3848 | + |
---|
| 3849 | + void ClearVersionList() |
---|
| 3850 | + { |
---|
| 3851 | + this.versionlist = null; |
---|
| 3852 | + this.versionindex = -1; |
---|
| 3853 | + this.versiontable = null; |
---|
| 3854 | + } |
---|
| 3855 | + |
---|
| 3856 | + void ClearVersions() |
---|
| 3857 | + { |
---|
| 3858 | + if (blockloop) |
---|
| 3859 | + return; |
---|
| 3860 | + |
---|
| 3861 | + blockloop = true; |
---|
| 3862 | + |
---|
| 3863 | + ClearVersionList(); |
---|
| 3864 | + for (int i = 0; i < Size(); i++) |
---|
| 3865 | + { |
---|
| 3866 | + Object3D child = (Object3D) get(i); |
---|
| 3867 | + if (child == null) |
---|
| 3868 | + continue; |
---|
| 3869 | + child.ClearVersions(); |
---|
| 3870 | + } |
---|
| 3871 | + |
---|
| 3872 | + blockloop = false; |
---|
3528 | 3873 | } |
---|
3529 | 3874 | |
---|
3530 | 3875 | void FlipV(boolean flip) |
---|
.. | .. |
---|
3703 | 4048 | |
---|
3704 | 4049 | void RevertMeshes() |
---|
3705 | 4050 | { |
---|
| 4051 | + // BLOCKLOOP |
---|
3706 | 4052 | if (this instanceof cMesh) |
---|
3707 | 4053 | { |
---|
3708 | 4054 | ((cMesh)this).Revert(); |
---|
.. | .. |
---|
3733 | 4079 | Touch(); |
---|
3734 | 4080 | } |
---|
3735 | 4081 | |
---|
3736 | | - ResetRecur(); |
---|
3737 | | - } |
---|
3738 | | - |
---|
3739 | | - void ResetRecur() |
---|
3740 | | - { |
---|
3741 | 4082 | for (int i = 0; i < size(); i++) |
---|
3742 | 4083 | { |
---|
3743 | 4084 | Object3D child = (Object3D) get(i); // reserve(i); |
---|
.. | .. |
---|
3951 | 4292 | Touch(); |
---|
3952 | 4293 | } |
---|
3953 | 4294 | |
---|
3954 | | - transient cVector min = new cVector(); |
---|
3955 | | - transient cVector max = new cVector(); |
---|
| 4295 | + transient cVector min; |
---|
| 4296 | + transient cVector max; |
---|
3956 | 4297 | |
---|
3957 | 4298 | void getBounds(cVector minima, cVector maxima, boolean xform) |
---|
3958 | 4299 | { |
---|
.. | .. |
---|
3968 | 4309 | if (blockloop) |
---|
3969 | 4310 | return; |
---|
3970 | 4311 | |
---|
3971 | | - if (min == null) // ??? |
---|
| 4312 | + if (min == null) |
---|
3972 | 4313 | { |
---|
3973 | 4314 | min = new cVector(); |
---|
3974 | 4315 | max = new cVector(); |
---|
3975 | 4316 | } |
---|
3976 | 4317 | |
---|
3977 | | - for (int i = 0; i<size(); i++) |
---|
| 4318 | + for (int i = 0; i<Size(); i++) |
---|
3978 | 4319 | { |
---|
3979 | | - Object3D child = (Object3D) reserve(i); |
---|
| 4320 | + Object3D child = (Object3D) get(i); //reserve(i); |
---|
3980 | 4321 | if (child == null) |
---|
3981 | 4322 | continue; |
---|
3982 | 4323 | |
---|
.. | .. |
---|
3995 | 4336 | if (child.hide && !(child instanceof Merge) || child.skip) |
---|
3996 | 4337 | //if (child.hide) |
---|
3997 | 4338 | { |
---|
3998 | | - release(i); |
---|
| 4339 | + //release(i); |
---|
3999 | 4340 | continue; |
---|
4000 | 4341 | } |
---|
4001 | 4342 | |
---|
4002 | 4343 | blockloop = true; |
---|
4003 | 4344 | child.getBounds(min, max, true); // xform); |
---|
4004 | 4345 | blockloop = false; |
---|
4005 | | - release(i); |
---|
| 4346 | + //release(i); |
---|
4006 | 4347 | |
---|
4007 | 4348 | MinMax(minima, maxima); |
---|
4008 | 4349 | } |
---|
4009 | 4350 | |
---|
4010 | 4351 | if (bRep != null) |
---|
4011 | 4352 | { |
---|
4012 | | - bRep.getBounds(minima,maxima,this); |
---|
| 4353 | + bRep.getBounds(minima, maxima, xform?this:null); |
---|
4013 | 4354 | } |
---|
4014 | 4355 | |
---|
4015 | 4356 | if (false) // xform) |
---|
.. | .. |
---|
5409 | 5750 | blockloop = false; |
---|
5410 | 5751 | } |
---|
5411 | 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 | + |
---|
5412 | 5798 | boolean IsSelected() |
---|
5413 | 5799 | { |
---|
5414 | 5800 | if (parent == null) |
---|
.. | .. |
---|
5469 | 5855 | if (fullname == null) |
---|
5470 | 5856 | return ""; |
---|
5471 | 5857 | |
---|
| 5858 | + if (fullname.pigment != null) |
---|
| 5859 | + { |
---|
| 5860 | + return fullname.pigment; |
---|
| 5861 | + } |
---|
| 5862 | + |
---|
5472 | 5863 | // System.out.println("Fullname = " + fullname); |
---|
5473 | 5864 | |
---|
5474 | 5865 | // Does not work on Windows due to C: |
---|
.. | .. |
---|
5481 | 5872 | |
---|
5482 | 5873 | if (split.length == 0) |
---|
5483 | 5874 | { |
---|
5484 | | - return ""; |
---|
| 5875 | + return fullname.pigment = ""; |
---|
5485 | 5876 | } |
---|
5486 | 5877 | |
---|
5487 | 5878 | if (split.length <= 2) |
---|
.. | .. |
---|
5489 | 5880 | if (fullname.name.endsWith(":")) |
---|
5490 | 5881 | { |
---|
5491 | 5882 | // Windows |
---|
5492 | | - return fullname.name.substring(0, fullname.name.length()-1); |
---|
| 5883 | + return fullname.pigment = fullname.name.substring(0, fullname.name.length()-1); |
---|
5493 | 5884 | } |
---|
5494 | 5885 | |
---|
5495 | | - return split[0]; |
---|
| 5886 | + return fullname.pigment = split[0]; |
---|
5496 | 5887 | } |
---|
5497 | 5888 | |
---|
5498 | 5889 | // Windows |
---|
5499 | 5890 | assert(split.length == 4); |
---|
5500 | 5891 | |
---|
5501 | | - return split[0] + ":" + split[1]; |
---|
| 5892 | + return fullname.pigment = split[0] + ":" + split[1]; |
---|
5502 | 5893 | } |
---|
5503 | 5894 | |
---|
5504 | 5895 | static String GetBump(cTexture fullname) |
---|
5505 | 5896 | { |
---|
5506 | 5897 | if (fullname == null) |
---|
5507 | 5898 | return ""; |
---|
| 5899 | + |
---|
| 5900 | + if (fullname.bump != null) |
---|
| 5901 | + { |
---|
| 5902 | + return fullname.bump; |
---|
| 5903 | + } |
---|
5508 | 5904 | |
---|
5509 | 5905 | // System.out.println("Fullname = " + fullname); |
---|
5510 | 5906 | // Does not work on Windows due to C: |
---|
.. | .. |
---|
5516 | 5912 | |
---|
5517 | 5913 | if (split.length == 0) |
---|
5518 | 5914 | { |
---|
5519 | | - return ""; |
---|
| 5915 | + return fullname.bump = ""; |
---|
5520 | 5916 | } |
---|
5521 | 5917 | |
---|
5522 | 5918 | if (split.length == 1) |
---|
5523 | 5919 | { |
---|
5524 | | - return ""; |
---|
| 5920 | + return fullname.bump = ""; |
---|
5525 | 5921 | } |
---|
5526 | 5922 | |
---|
5527 | 5923 | if (split.length == 2) |
---|
.. | .. |
---|
5529 | 5925 | if (fullname.name.endsWith(":")) |
---|
5530 | 5926 | { |
---|
5531 | 5927 | // Windows |
---|
5532 | | - return ""; |
---|
| 5928 | + return fullname.bump = ""; |
---|
5533 | 5929 | } |
---|
5534 | 5930 | |
---|
5535 | | - return split[1]; |
---|
| 5931 | + return fullname.bump = split[1]; |
---|
5536 | 5932 | } |
---|
5537 | 5933 | |
---|
5538 | 5934 | // Windows |
---|
5539 | 5935 | assert(split.length == 4); |
---|
5540 | 5936 | |
---|
5541 | | - return split[2] + ":" + split[3]; |
---|
| 5937 | + return fullname.bump = split[2] + ":" + split[3]; |
---|
5542 | 5938 | } |
---|
5543 | 5939 | |
---|
5544 | 5940 | String GetPigmentTexture() |
---|
.. | .. |
---|
5621 | 6017 | texname = ""; |
---|
5622 | 6018 | |
---|
5623 | 6019 | GetTextures().name = texname + ":" + GetBump(GetTextures()); |
---|
| 6020 | + |
---|
| 6021 | + GetTextures().pigment = null; |
---|
| 6022 | + |
---|
5624 | 6023 | Touch(); |
---|
5625 | 6024 | } |
---|
5626 | 6025 | |
---|
.. | .. |
---|
5694 | 6093 | |
---|
5695 | 6094 | GetTextures().name = Object3D.GetPigment(GetTextures()) + ":" + texname; |
---|
5696 | 6095 | |
---|
| 6096 | + GetTextures().bump = null; |
---|
| 6097 | + |
---|
5697 | 6098 | Touch(); |
---|
5698 | 6099 | } |
---|
5699 | 6100 | |
---|
.. | .. |
---|
5714 | 6115 | |
---|
5715 | 6116 | blockloop = true; |
---|
5716 | 6117 | child.ResetBumpTexture(); |
---|
| 6118 | + blockloop = false; |
---|
| 6119 | + } |
---|
| 6120 | + } |
---|
| 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); |
---|
5717 | 6150 | blockloop = false; |
---|
5718 | 6151 | } |
---|
5719 | 6152 | } |
---|
.. | .. |
---|
5742 | 6175 | return false; |
---|
5743 | 6176 | |
---|
5744 | 6177 | return parent.IsLive(); |
---|
| 6178 | + } |
---|
| 6179 | + |
---|
| 6180 | + boolean IsDynamic() |
---|
| 6181 | + { |
---|
| 6182 | + return live && bRep != null; |
---|
5745 | 6183 | } |
---|
5746 | 6184 | |
---|
5747 | 6185 | void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) |
---|
.. | .. |
---|
5804 | 6242 | if (support != null) |
---|
5805 | 6243 | support = support; |
---|
5806 | 6244 | |
---|
5807 | | - //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch); |
---|
5808 | | - boolean usecalllists = !IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch); |
---|
| 6245 | + boolean usecalllists = !IsDynamic() && |
---|
| 6246 | + IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch); |
---|
| 6247 | + //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch); |
---|
| 6248 | + |
---|
| 6249 | + //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass. |
---|
5809 | 6250 | |
---|
5810 | 6251 | if (!usecalllists && bRep != null && bRep.displaylist > 0) |
---|
5811 | 6252 | { |
---|
.. | .. |
---|
5815 | 6256 | // usecalllists &= !(parent instanceof RandomNode); |
---|
5816 | 6257 | // usecalllists = false; |
---|
5817 | 6258 | |
---|
5818 | | - if (GetBRep() != null) |
---|
5819 | | - usecalllists = usecalllists; |
---|
| 6259 | + if (display.DrawMode() == display.SHADOW) |
---|
| 6260 | + //GetBRep() != null) |
---|
| 6261 | + usecalllists = !!usecalllists; |
---|
5820 | 6262 | //System.out.println("draw " + this); |
---|
5821 | 6263 | //new Exception().printStackTrace(); |
---|
5822 | 6264 | |
---|
.. | .. |
---|
5838 | 6280 | if (!(this instanceof Composite)) |
---|
5839 | 6281 | touched = false; |
---|
5840 | 6282 | //if (displaylist == -1 && usecalllists) |
---|
5841 | | - if ((bRep != null && bRep.displaylist <= 0) && usecalllists) // june 2013 |
---|
| 6283 | + if (bRep.displaylist <= 0 && usecalllists) // && display.DrawMode() == display.DEFAULT) // june 2013 |
---|
5842 | 6284 | { |
---|
5843 | 6285 | bRep.displaylist = display.GenList(); |
---|
5844 | 6286 | assert(bRep.displaylist != 0); |
---|
.. | .. |
---|
5849 | 6291 | |
---|
5850 | 6292 | //System.out.println("\tnew list " + list); |
---|
5851 | 6293 | //gl.glDrawBuffer(gl.GL_NONE); |
---|
5852 | | - if (usecalllists) |
---|
| 6294 | + if (usecalllists && bRep.displaylist > 0) |
---|
5853 | 6295 | { |
---|
5854 | 6296 | // System.err.println("new list " + bRep.displaylist + " for " + this); |
---|
5855 | 6297 | display.NewList(bRep.displaylist); |
---|
.. | .. |
---|
5858 | 6300 | CallList(display, root, selected, blocked); |
---|
5859 | 6301 | |
---|
5860 | 6302 | // compiled = true; |
---|
5861 | | - if (usecalllists) |
---|
| 6303 | + if (usecalllists && bRep.displaylist > 0) |
---|
5862 | 6304 | { |
---|
5863 | 6305 | // System.err.println("end list " + bRep.displaylist + " for " + this); |
---|
5864 | 6306 | display.EndList(); |
---|
.. | .. |
---|
5868 | 6310 | Globals.lighttouched = true; // all panes... |
---|
5869 | 6311 | } |
---|
5870 | 6312 | |
---|
5871 | | - touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false; |
---|
5872 | | - //touched = false; |
---|
| 6313 | + //touched = GetBRep() == null; // this instanceof Composite || this instanceof FileObject; // false; |
---|
| 6314 | + touched = false; |
---|
5873 | 6315 | |
---|
5874 | 6316 | if (this instanceof Texture || this instanceof TextureNode) |
---|
5875 | 6317 | { |
---|
.. | .. |
---|
5970 | 6412 | { |
---|
5971 | 6413 | drawSelf(display, root, selected, blocked); |
---|
5972 | 6414 | } |
---|
| 6415 | + |
---|
| 6416 | +// if (!(this instanceof Composite)) |
---|
| 6417 | +// { |
---|
| 6418 | +// for (int i = 0; i < size(); i++) |
---|
| 6419 | +// { |
---|
| 6420 | +// Object3D child = (Object3D) reserve(i); |
---|
| 6421 | +// if (child == null) |
---|
| 6422 | +// continue; |
---|
| 6423 | +// |
---|
| 6424 | +// child.draw(display, root, selected, blocked); |
---|
| 6425 | +// |
---|
| 6426 | +// release(i); |
---|
| 6427 | +// } |
---|
| 6428 | +// } |
---|
5973 | 6429 | } else |
---|
5974 | 6430 | { |
---|
5975 | 6431 | /* |
---|
.. | .. |
---|
6002 | 6458 | boolean failedPigment = false; |
---|
6003 | 6459 | boolean failedBump = false; |
---|
6004 | 6460 | |
---|
| 6461 | + CameraPane.lastObject = this; |
---|
6005 | 6462 | try |
---|
6006 | 6463 | { |
---|
6007 | 6464 | display.BindPigmentTexture(tex, texres); |
---|
6008 | 6465 | } |
---|
6009 | 6466 | catch (Exception e) |
---|
6010 | 6467 | { |
---|
6011 | | - System.err.println("FAILED: " + this); |
---|
| 6468 | + // System.err.println("FAILED: " + this); |
---|
6012 | 6469 | failedPigment = true; |
---|
6013 | 6470 | } |
---|
6014 | 6471 | |
---|
.. | .. |
---|
6039 | 6496 | display.CallList(bRep.displaylist); |
---|
6040 | 6497 | // june 2013 drawSelf(display, root, selected); |
---|
6041 | 6498 | } |
---|
| 6499 | + } |
---|
| 6500 | + |
---|
| 6501 | + assert (!(this instanceof Composite)); |
---|
| 6502 | + { |
---|
| 6503 | +// CRASH MOCAP!! for (int i = 0; i < size(); i++) |
---|
| 6504 | +// { |
---|
| 6505 | +// Object3D child = (Object3D) reserve(i); |
---|
| 6506 | +// if (child == null) |
---|
| 6507 | +// continue; |
---|
| 6508 | +// |
---|
| 6509 | +// child.draw(display, root, selected, blocked); |
---|
| 6510 | +// |
---|
| 6511 | +// release(i); |
---|
| 6512 | +// } |
---|
6042 | 6513 | } |
---|
6043 | 6514 | } |
---|
6044 | 6515 | |
---|
.. | .. |
---|
6092 | 6563 | |
---|
6093 | 6564 | void CallList(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) |
---|
6094 | 6565 | { |
---|
6095 | | - if (GetBRep() == null) |
---|
6096 | | - { |
---|
6097 | | - drawSelf(display, root, selected, blocked); |
---|
6098 | | - } else |
---|
| 6566 | + if (GetBRep() != null) |
---|
6099 | 6567 | { |
---|
6100 | 6568 | DrawNode(display, root, selected); |
---|
6101 | 6569 | if (this instanceof BezierPatch) |
---|
6102 | 6570 | { |
---|
6103 | 6571 | //drawSelf(display, root, selected); |
---|
6104 | 6572 | } |
---|
| 6573 | + } |
---|
| 6574 | + else |
---|
| 6575 | + { |
---|
| 6576 | + drawSelf(display, root, selected, blocked); |
---|
6105 | 6577 | } |
---|
6106 | 6578 | } |
---|
6107 | 6579 | |
---|
.. | .. |
---|
7209 | 7681 | } |
---|
7210 | 7682 | } |
---|
7211 | 7683 | |
---|
7212 | | - protected void calcHotSpot(cVector in, ClickInfo info, Point outPt, Rectangle outRec) |
---|
| 7684 | + static ClickInfo clickInfo = new ClickInfo(); |
---|
| 7685 | + |
---|
| 7686 | + protected void calcHotSpot(cVector in, //ClickInfo clickInfo, |
---|
| 7687 | + Point outPt, Rectangle outRec) |
---|
7213 | 7688 | { |
---|
7214 | | - int hc = info.bounds.x + info.bounds.width / 2; |
---|
7215 | | - int vc = info.bounds.y + info.bounds.height / 2; |
---|
7216 | | - double[][] toscreen = info.toScreen; |
---|
| 7689 | + int hc = clickInfo.bounds.x + clickInfo.bounds.width / 2; |
---|
| 7690 | + int vc = clickInfo.bounds.y + clickInfo.bounds.height / 2; |
---|
| 7691 | + double[][] toscreen = clickInfo.toScreen; |
---|
7217 | 7692 | if (toscreen == null) |
---|
7218 | 7693 | { |
---|
7219 | | - toscreen = new Camera(info.camera.viewCode).toScreen; |
---|
| 7694 | + toscreen = new Camera(clickInfo.camera.viewCode).toScreen; |
---|
7220 | 7695 | } |
---|
7221 | 7696 | cVector vec = in; |
---|
7222 | 7697 | LA.xformPos(in, toscreen, in); |
---|
7223 | 7698 | //System.out.println("Distance = " + info.camera.Distance()); |
---|
7224 | | - vec.x *= 100 * info.camera.SCALE / info.camera.Distance(); |
---|
7225 | | - vec.y *= 100 * info.camera.SCALE / info.camera.Distance(); |
---|
| 7699 | + vec.x *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance(); |
---|
| 7700 | + vec.y *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance(); |
---|
7226 | 7701 | outPt.x = hc + (int) vec.x; |
---|
7227 | 7702 | outPt.y = vc - (int) vec.y; |
---|
7228 | 7703 | outRec.x = outPt.x - 3; |
---|
.. | .. |
---|
7230 | 7705 | outRec.width = outRec.height = 6; |
---|
7231 | 7706 | } |
---|
7232 | 7707 | |
---|
7233 | | - protected Rectangle calcHotSpot(cVector in, ClickInfo info) |
---|
| 7708 | + protected Rectangle calcHotSpot(cVector in//, ClickInfo clickInfo |
---|
| 7709 | + ) |
---|
7234 | 7710 | { |
---|
7235 | 7711 | Point pt = new Point(0, 0); |
---|
7236 | 7712 | Rectangle rec = new Rectangle(); |
---|
7237 | | - calcHotSpot(in, info, pt, rec); |
---|
| 7713 | + calcHotSpot(in, //clickInfo, |
---|
| 7714 | + pt, rec); |
---|
7238 | 7715 | return rec; |
---|
7239 | 7716 | } |
---|
7240 | 7717 | |
---|
7241 | | - void drawEditHandles0(ClickInfo info, int level) |
---|
| 7718 | + void drawEditHandles0(//ClickInfo clickInfo, |
---|
| 7719 | + int level) |
---|
7242 | 7720 | { |
---|
7243 | 7721 | if (level == 0) |
---|
7244 | 7722 | { |
---|
.. | .. |
---|
7247 | 7725 | { |
---|
7248 | 7726 | cVector origin = new cVector(); |
---|
7249 | 7727 | //LA.xformPos(origin, toParent, origin); |
---|
7250 | | - Rectangle spot = calcHotSpot(origin, info); |
---|
| 7728 | + if (this.clickInfo == null) |
---|
| 7729 | + this.clickInfo = new ClickInfo(); |
---|
| 7730 | + |
---|
| 7731 | + Rectangle spot = calcHotSpot(origin); //, clickInfo); |
---|
7251 | 7732 | Rectangle boundary = new Rectangle(); |
---|
7252 | 7733 | boundary.x = spot.x - 30; |
---|
7253 | 7734 | boundary.y = spot.y - 30; |
---|
7254 | 7735 | boundary.width = spot.width + 60; |
---|
7255 | 7736 | boundary.height = spot.height + 60; |
---|
7256 | | - info.g.setColor(Color.red); |
---|
| 7737 | + clickInfo.g.setColor(Color.white); |
---|
7257 | 7738 | int spotw = spot.x + spot.width; |
---|
7258 | 7739 | int spoth = spot.y + spot.height; |
---|
7259 | | - info.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
| 7740 | + clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
7260 | 7741 | // if (CameraPane.Xmin > spot.x) |
---|
7261 | 7742 | // { |
---|
7262 | 7743 | // CameraPane.Xmin = spot.x; |
---|
.. | .. |
---|
7273 | 7754 | // { |
---|
7274 | 7755 | // CameraPane.Ymax = spoth; |
---|
7275 | 7756 | // } |
---|
7276 | | - spot.translate(32, 32); |
---|
7277 | | - spotw = spot.x + spot.width; |
---|
7278 | | - spoth = spot.y + spot.height; |
---|
7279 | | - info.g.setColor(Color.cyan); |
---|
7280 | | - info.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
7281 | 7757 | // if (CameraPane.Xmin > spot.x) |
---|
7282 | 7758 | // { |
---|
7283 | 7759 | // CameraPane.Xmin = spot.x; |
---|
.. | .. |
---|
7296 | 7772 | // } |
---|
7297 | 7773 | // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15 |
---|
7298 | 7774 | //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15 |
---|
7299 | | - spot.translate(0, -32); |
---|
7300 | | - info.g.setColor(Color.yellow); |
---|
7301 | | - info.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
7302 | | - info.g.setColor(Color.green); |
---|
| 7775 | + spot.translate(32, 0); |
---|
| 7776 | + clickInfo.g.setColor(Color.yellow); |
---|
| 7777 | + clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
| 7778 | + |
---|
| 7779 | + spot.translate(32, 64); |
---|
| 7780 | + spotw = spot.x + spot.width; |
---|
| 7781 | + spoth = spot.y + spot.height; |
---|
| 7782 | + clickInfo.g.setColor(Color.cyan); |
---|
| 7783 | + clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height); |
---|
7303 | 7784 | // if (CameraPane.Xmin > spot.x) |
---|
7304 | 7785 | // { |
---|
7305 | 7786 | // CameraPane.Xmin = spot.x; |
---|
.. | .. |
---|
7316 | 7797 | // { |
---|
7317 | 7798 | // CameraPane.Ymax = spoth; |
---|
7318 | 7799 | // } |
---|
7319 | | - info.g.drawArc(boundary.x + info.DX, boundary.y + info.DY, |
---|
7320 | | - (int)(boundary.width * info.W), (int)(boundary.height * info.W), 0, 360); |
---|
| 7800 | + clickInfo.g.setColor(Color.green); |
---|
| 7801 | + clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY, |
---|
| 7802 | + (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360); |
---|
7321 | 7803 | //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360); |
---|
7322 | 7804 | // if (CameraPane.Xmin > boundary.x) |
---|
7323 | 7805 | // { |
---|
.. | .. |
---|
7339 | 7821 | } |
---|
7340 | 7822 | } |
---|
7341 | 7823 | |
---|
7342 | | - boolean doEditClick0(ClickInfo info, int level) |
---|
| 7824 | + boolean doEditClick0(//ClickInfo clickInfo, |
---|
| 7825 | + int level) |
---|
7343 | 7826 | { |
---|
7344 | 7827 | if (level == 0) |
---|
7345 | 7828 | { |
---|
.. | .. |
---|
7348 | 7831 | |
---|
7349 | 7832 | boolean retval = false; |
---|
7350 | 7833 | |
---|
7351 | | - startX = info.x; |
---|
7352 | | - startY = info.y; |
---|
| 7834 | + startX = clickInfo.x; |
---|
| 7835 | + startY = clickInfo.y; |
---|
7353 | 7836 | |
---|
7354 | 7837 | hitSomething = -1; |
---|
7355 | 7838 | cVector origin = new cVector(); |
---|
.. | .. |
---|
7359 | 7842 | { |
---|
7360 | 7843 | centerPt = new Point(0, 0); |
---|
7361 | 7844 | } |
---|
7362 | | - calcHotSpot(origin, info, centerPt, spot); |
---|
7363 | | - if (spot.contains(info.x, info.y)) |
---|
| 7845 | + calcHotSpot(origin, //info, |
---|
| 7846 | + centerPt, spot); |
---|
| 7847 | + if (spot.contains(clickInfo.x, clickInfo.y)) |
---|
7364 | 7848 | { |
---|
7365 | 7849 | hitSomething = hitCenter; |
---|
7366 | 7850 | retval = true; |
---|
7367 | 7851 | } |
---|
7368 | 7852 | spot.translate(32, 0); |
---|
7369 | | - if (spot.contains(info.x, info.y)) |
---|
| 7853 | + if (spot.contains(clickInfo.x, clickInfo.y)) |
---|
7370 | 7854 | { |
---|
7371 | 7855 | hitSomething = hitRotate; |
---|
7372 | 7856 | retval = true; |
---|
7373 | 7857 | } |
---|
7374 | 7858 | spot.translate(0, 32); |
---|
7375 | | - if (spot.contains(info.x, info.y)) |
---|
| 7859 | + spot.translate(32, 0); |
---|
| 7860 | + spot.translate(0, 32); |
---|
| 7861 | + if (spot.contains(clickInfo.x, clickInfo.y)) |
---|
7376 | 7862 | { |
---|
7377 | 7863 | hitSomething = hitScale; |
---|
| 7864 | + |
---|
| 7865 | + double scale = 0.005f * clickInfo.camera.Distance(); |
---|
| 7866 | + double hScale = (double) (clickInfo.x - centerPt.x) / 64; |
---|
| 7867 | + double sign = 1; |
---|
| 7868 | + if (hScale < 0) |
---|
| 7869 | + { |
---|
| 7870 | + sign = -1; |
---|
| 7871 | + } |
---|
| 7872 | + hScale = sign*Math.pow(sign*hScale, scale * 50); |
---|
| 7873 | + if (hScale < 0.01) |
---|
| 7874 | + { |
---|
| 7875 | + //hScale = 0.01; |
---|
| 7876 | + } |
---|
| 7877 | + |
---|
| 7878 | + double vScale = (double) (clickInfo.y - centerPt.y) / 64; |
---|
| 7879 | + sign = 1; |
---|
| 7880 | + if (vScale < 0) |
---|
| 7881 | + { |
---|
| 7882 | + sign = -1; |
---|
| 7883 | + } |
---|
| 7884 | + vScale = sign*Math.pow(sign*vScale, scale * 50); |
---|
| 7885 | + if (vScale < 0.01) |
---|
| 7886 | + { |
---|
| 7887 | + //vScale = 0.01; |
---|
| 7888 | + } |
---|
| 7889 | + |
---|
| 7890 | + clickInfo.scale = Math.sqrt(hScale*hScale + vScale*vScale); |
---|
| 7891 | + |
---|
7378 | 7892 | retval = true; |
---|
7379 | 7893 | } |
---|
7380 | 7894 | |
---|
.. | .. |
---|
7384 | 7898 | } |
---|
7385 | 7899 | |
---|
7386 | 7900 | //System.out.println("info.modifiers = " + info.modifiers); |
---|
7387 | | - modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META |
---|
| 7901 | + modified = (clickInfo.modifiers & CameraPane.SHIFT) != 0; // Was META |
---|
7388 | 7902 | //System.out.println("modified = " + modified); |
---|
7389 | 7903 | //new Exception().printStackTrace(); |
---|
7390 | 7904 | //viewCode = info.pane.renderCamera.viewCode; |
---|
.. | .. |
---|
7412 | 7926 | return true; |
---|
7413 | 7927 | } |
---|
7414 | 7928 | |
---|
7415 | | - void doEditDrag0(ClickInfo info, boolean opposite) |
---|
| 7929 | + void doEditDrag0(//ClickInfo info, |
---|
| 7930 | + boolean opposite) |
---|
7416 | 7931 | { |
---|
7417 | 7932 | if (hitSomething == 0) |
---|
7418 | 7933 | { |
---|
.. | .. |
---|
7426 | 7941 | |
---|
7427 | 7942 | //System.out.println("hitSomething = " + hitSomething); |
---|
7428 | 7943 | |
---|
7429 | | - double scale = 0.005f * info.camera.Distance(); |
---|
| 7944 | + double scale = 0.005f * clickInfo.camera.Distance(); |
---|
7430 | 7945 | |
---|
7431 | 7946 | cVector xlate = new cVector(); |
---|
7432 | 7947 | //cVector xlate2 = new cVector(); |
---|
.. | .. |
---|
7440 | 7955 | |
---|
7441 | 7956 | scale *= 0.05f * Globals.theRenderer.RenderCamera().Distance(); |
---|
7442 | 7957 | |
---|
7443 | | - if (modified || opposite) |
---|
| 7958 | + // Modified could snap |
---|
| 7959 | + if (//modified || |
---|
| 7960 | + opposite) |
---|
7444 | 7961 | { |
---|
7445 | 7962 | //assert(false); |
---|
7446 | 7963 | /* |
---|
.. | .. |
---|
7460 | 7977 | toParent[3][i] = xlate.get(i); |
---|
7461 | 7978 | LA.matInvert(toParent, fromParent); |
---|
7462 | 7979 | */ |
---|
7463 | | - cVector delta = LA.newVector(0, 0, startY - info.y); |
---|
7464 | | - LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta); |
---|
| 7980 | + cVector delta = LA.newVector(0, 0, startY - clickInfo.y); |
---|
| 7981 | + LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta); |
---|
7465 | 7982 | |
---|
7466 | 7983 | LA.matCopy(startMat, toParent); |
---|
7467 | 7984 | LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale); |
---|
.. | .. |
---|
7470 | 7987 | } else |
---|
7471 | 7988 | { |
---|
7472 | 7989 | //LA.xformDir(delta, info.camera.fromScreen, delta); |
---|
7473 | | - cVector up = new cVector(info.camera.up); |
---|
| 7990 | + cVector up = new cVector(clickInfo.camera.up); |
---|
7474 | 7991 | cVector away = new cVector(); |
---|
7475 | 7992 | //cVector right2 = new cVector(); |
---|
7476 | 7993 | //LA.vecCross(up, cVector.Z, right); |
---|
.. | .. |
---|
7487 | 8004 | LA.xformDir(up, ClickInfo.matbuffer, up); |
---|
7488 | 8005 | // if (!CameraPane.LOCALTRANSFORM) |
---|
7489 | 8006 | LA.xformDir(up, Globals.theRenderer.RenderCamera().toScreen, up); |
---|
7490 | | - LA.xformDir(info.camera.away, ClickInfo.matbuffer, away); |
---|
| 8007 | + LA.xformDir(clickInfo.camera.away, ClickInfo.matbuffer, away); |
---|
7491 | 8008 | // if (!CameraPane.LOCALTRANSFORM) |
---|
7492 | 8009 | LA.xformDir(away, Globals.theRenderer.RenderCamera().toScreen, away); |
---|
7493 | 8010 | //LA.vecCross(up, cVector.Z, right2); |
---|
7494 | 8011 | |
---|
7495 | | - cVector delta = LA.newVector(info.x - startX, startY - info.y, 0); |
---|
| 8012 | + cVector delta = LA.newVector(clickInfo.x - startX, startY - clickInfo.y, 0); |
---|
7496 | 8013 | |
---|
7497 | 8014 | //System.out.println("DELTA0 = " + delta); |
---|
7498 | 8015 | //System.out.println("AWAY = " + info.camera.away); |
---|
7499 | 8016 | //System.out.println("UP = " + info.camera.up); |
---|
7500 | 8017 | if (away.z > 0) |
---|
7501 | 8018 | { |
---|
7502 | | - if (info.camera.up.x == 0) // LA.vecDot(right, right2)<0) |
---|
| 8019 | + if (clickInfo.camera.up.x == 0) // LA.vecDot(right, right2)<0) |
---|
7503 | 8020 | { |
---|
7504 | 8021 | delta.x = -delta.x; |
---|
7505 | 8022 | } else |
---|
.. | .. |
---|
7514 | 8031 | //System.out.println("DELTA1 = " + delta); |
---|
7515 | 8032 | LA.xformDir(delta, ClickInfo.matbuffer, delta); |
---|
7516 | 8033 | //System.out.println("DELTA2 = " + delta); |
---|
7517 | | - LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta); |
---|
| 8034 | + LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta); |
---|
7518 | 8035 | LA.matCopy(startMat, toParent); |
---|
7519 | 8036 | //System.out.println("DELTA3 = " + delta); |
---|
7520 | 8037 | LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale); |
---|
.. | .. |
---|
7524 | 8041 | break; |
---|
7525 | 8042 | |
---|
7526 | 8043 | case hitRotate: // rotate |
---|
7527 | | - int dx = info.x - centerPt.x; |
---|
7528 | | - int dy = -(info.y - centerPt.y); |
---|
| 8044 | + int dx = clickInfo.x - centerPt.x; |
---|
| 8045 | + int dy = -(clickInfo.y - centerPt.y); |
---|
7529 | 8046 | double angle = (double) Math.atan2(dx, dy); |
---|
7530 | 8047 | angle = -(1.570796 - angle); |
---|
7531 | 8048 | |
---|
.. | .. |
---|
7534 | 8051 | |
---|
7535 | 8052 | if (modified) |
---|
7536 | 8053 | { |
---|
7537 | | - // Rotate 90 degrees |
---|
| 8054 | + // Rotate 45 degrees |
---|
7538 | 8055 | angle /= (Math.PI / 4); |
---|
7539 | 8056 | angle = Math.floor(angle + 0.5); |
---|
7540 | 8057 | angle *= (Math.PI / 4); |
---|
.. | .. |
---|
7548 | 8065 | } |
---|
7549 | 8066 | /**/ |
---|
7550 | 8067 | |
---|
7551 | | - switch (info.pane.RenderCamera().viewCode) |
---|
| 8068 | + switch (clickInfo.pane.RenderCamera().viewCode) |
---|
7552 | 8069 | { |
---|
7553 | 8070 | case 1: // '\001' |
---|
7554 | 8071 | LA.matZRotate(toParent, angle); |
---|
.. | .. |
---|
7575 | 8092 | break; |
---|
7576 | 8093 | |
---|
7577 | 8094 | case hitScale: // scale |
---|
7578 | | - double hScale = (double) (info.x - centerPt.x) / 32; |
---|
| 8095 | + double hScale = (double) (clickInfo.x - centerPt.x) / 64; |
---|
7579 | 8096 | double sign = 1; |
---|
7580 | 8097 | if (hScale < 0) |
---|
7581 | 8098 | { |
---|
.. | .. |
---|
7587 | 8104 | //hScale = 0.01; |
---|
7588 | 8105 | } |
---|
7589 | 8106 | |
---|
7590 | | - double vScale = (double) (info.y - centerPt.y) / 32; |
---|
| 8107 | + double vScale = (double) (clickInfo.y - centerPt.y) / 64; |
---|
7591 | 8108 | sign = 1; |
---|
7592 | 8109 | if (vScale < 0) |
---|
7593 | 8110 | { |
---|
.. | .. |
---|
7598 | 8115 | { |
---|
7599 | 8116 | //vScale = 0.01; |
---|
7600 | 8117 | } |
---|
| 8118 | + |
---|
7601 | 8119 | LA.matCopy(startMat, toParent); |
---|
7602 | 8120 | /**/ |
---|
7603 | 8121 | for (int i = 0; i < 3; i++) |
---|
.. | .. |
---|
7607 | 8125 | } |
---|
7608 | 8126 | /**/ |
---|
7609 | 8127 | |
---|
7610 | | - double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2); |
---|
| 8128 | + double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / clickInfo.scale; |
---|
7611 | 8129 | |
---|
7612 | 8130 | if (totalScale < 0.01) |
---|
7613 | 8131 | { |
---|
7614 | 8132 | totalScale = 0.01; |
---|
7615 | 8133 | } |
---|
7616 | 8134 | |
---|
7617 | | - switch (info.pane.RenderCamera().viewCode) |
---|
| 8135 | + switch (clickInfo.pane.RenderCamera().viewCode) |
---|
7618 | 8136 | { |
---|
7619 | 8137 | case 3: // '\001' |
---|
7620 | 8138 | if (modified || opposite) |
---|
7621 | 8139 | { |
---|
| 8140 | + if (modified) // && opposite) |
---|
| 8141 | + LA.matScale(toParent, totalScale, totalScale, totalScale); |
---|
| 8142 | + else |
---|
7622 | 8143 | //LA.matScale(toParent, 1, hScale, vScale); |
---|
7623 | | - LA.matScale(toParent, totalScale, 1, 1); |
---|
| 8144 | + LA.matScale(toParent, totalScale, 1, 1); |
---|
7624 | 8145 | } // vScale, 1); |
---|
7625 | 8146 | else |
---|
7626 | 8147 | { |
---|
7627 | 8148 | // EXCEPTION! |
---|
7628 | | - LA.matScale(toParent, totalScale, totalScale, totalScale); |
---|
| 8149 | + LA.matScale(toParent, 1, totalScale, totalScale); |
---|
7629 | 8150 | } // vScale, 1); |
---|
7630 | 8151 | break; |
---|
7631 | 8152 | |
---|
7632 | 8153 | case 2: // '\002' |
---|
7633 | 8154 | if (modified || opposite) |
---|
7634 | 8155 | { |
---|
7635 | | - //LA.matScale(toParent, hScale, 1, vScale); |
---|
7636 | | - LA.matScale(toParent, 1, totalScale, 1); |
---|
| 8156 | + if (modified) // && opposite) |
---|
| 8157 | + LA.matScale(toParent, totalScale, totalScale, totalScale); |
---|
| 8158 | + else |
---|
| 8159 | + //LA.matScale(toParent, hScale, 1, vScale); |
---|
| 8160 | + LA.matScale(toParent, 1, totalScale, 1); |
---|
7637 | 8161 | } else |
---|
7638 | 8162 | { |
---|
7639 | 8163 | LA.matScale(toParent, totalScale, 1, totalScale); |
---|
.. | .. |
---|
7643 | 8167 | case 1: // '\003' |
---|
7644 | 8168 | if (modified || opposite) |
---|
7645 | 8169 | { |
---|
7646 | | - //LA.matScale(toParent, hScale, vScale, 1); |
---|
7647 | | - LA.matScale(toParent, 1, 1, totalScale); |
---|
| 8170 | + if (modified) // && opposite) |
---|
| 8171 | + LA.matScale(toParent, totalScale, totalScale, totalScale); |
---|
| 8172 | + else |
---|
| 8173 | + //LA.matScale(toParent, hScale, vScale, 1); |
---|
| 8174 | + LA.matScale(toParent, 1, 1, totalScale); |
---|
7648 | 8175 | } else |
---|
7649 | 8176 | { |
---|
7650 | 8177 | LA.matScale(toParent, totalScale, totalScale, 1); |
---|
.. | .. |
---|
7681 | 8208 | } // NEW ... |
---|
7682 | 8209 | |
---|
7683 | 8210 | |
---|
7684 | | - info.pane.repaint(); |
---|
| 8211 | + clickInfo.pane.repaint(); |
---|
7685 | 8212 | } |
---|
7686 | 8213 | |
---|
7687 | 8214 | boolean overflow = false; |
---|
.. | .. |
---|
7795 | 8322 | if (!Globals.ADVANCED) |
---|
7796 | 8323 | return objname; |
---|
7797 | 8324 | |
---|
7798 | | - return objname + " " + System.identityHashCode(this); |
---|
| 8325 | + return objname + " " + System.identityHashCode(this) + " " + GetUUID(); |
---|
7799 | 8326 | } |
---|
7800 | 8327 | |
---|
7801 | 8328 | public int hashCode() |
---|
.. | .. |
---|
8040 | 8567 | private static cVector2 qq2 = new cVector2(); |
---|
8041 | 8568 | private static cVector2 rr2 = new cVector2(); |
---|
8042 | 8569 | private static cVector2 ss2 = new cVector2(); |
---|
8043 | | - private static cVector edge1 = new cVector(); |
---|
8044 | | - private static cVector edge2 = new cVector(); |
---|
| 8570 | +// private static cVector edge1 = new cVector(); |
---|
| 8571 | +// private static cVector edge2 = new cVector(); |
---|
8045 | 8572 | //private static cVector norm = new cVector(); |
---|
8046 | 8573 | /*transient private*/ int hitSomething; |
---|
8047 | 8574 | static final int hitCenter = 1; |
---|
.. | .. |
---|
8239 | 8766 | |
---|
8240 | 8767 | Touch(); |
---|
8241 | 8768 | } |
---|
| 8769 | + |
---|
| 8770 | + static Vertex s1 = new Vertex(); |
---|
| 8771 | + static Vertex s2 = new Vertex(); |
---|
| 8772 | + static Vertex s3 = new Vertex(); |
---|
8242 | 8773 | |
---|
| 8774 | + boolean intersectMesh(Ray ray, IntersectResult result) |
---|
| 8775 | + { |
---|
| 8776 | + boolean success = false; |
---|
| 8777 | + |
---|
| 8778 | + if (bRep.stripified) |
---|
| 8779 | + { |
---|
| 8780 | + int[] strips = bRep.getRawIndices(); |
---|
| 8781 | + |
---|
| 8782 | + // TRIANGLE STRIP ARRAY |
---|
| 8783 | + if (bRep.trimmed) |
---|
| 8784 | + { |
---|
| 8785 | + float[] v = bRep.getRawVertices(); |
---|
| 8786 | + |
---|
| 8787 | + int count3 = 0; |
---|
| 8788 | + |
---|
| 8789 | + if (v.length > 0) |
---|
| 8790 | + { |
---|
| 8791 | + for (int i = 0; i < strips.length; i++) |
---|
| 8792 | + { |
---|
| 8793 | + s1.set(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 8794 | + count3 += 3; |
---|
| 8795 | + |
---|
| 8796 | + s2.set(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 8797 | + count3 += 3; |
---|
| 8798 | + |
---|
| 8799 | + for (int j = 0; j < strips[i] - 2; j++) |
---|
| 8800 | + { |
---|
| 8801 | + s3.set(v[count3], v[count3 + 1], v[count3 + 2]); |
---|
| 8802 | + count3 += 3; |
---|
| 8803 | + |
---|
| 8804 | + if (j%2 == 0) |
---|
| 8805 | + success |= intersectTriangle(ray, result, s1, s2, s3); |
---|
| 8806 | + else |
---|
| 8807 | + success |= intersectTriangle(ray, result, s1, s3, s2); |
---|
| 8808 | + |
---|
| 8809 | + s1.set(s2); |
---|
| 8810 | + s2.set(s3); |
---|
| 8811 | + } |
---|
| 8812 | + } |
---|
| 8813 | + } |
---|
| 8814 | + |
---|
| 8815 | + assert count3 == v.length; |
---|
| 8816 | + } |
---|
| 8817 | + else // !trimmed |
---|
| 8818 | + { |
---|
| 8819 | + int count = 0; |
---|
| 8820 | + for (int i = 0; i < strips.length; i++) |
---|
| 8821 | + { |
---|
| 8822 | + Vertex p = bRep.GetVertex(bRep.indices[count++]); |
---|
| 8823 | + Vertex q = bRep.GetVertex(bRep.indices[count++]); |
---|
| 8824 | + |
---|
| 8825 | + for (int j = 0; j < strips[i] - 2; j++) |
---|
| 8826 | + { |
---|
| 8827 | + Vertex r = bRep.GetVertex(bRep.indices[count++]); |
---|
| 8828 | + |
---|
| 8829 | + if (j%2 == 0) |
---|
| 8830 | + success |= intersectTriangle(ray, result, p, q, r); |
---|
| 8831 | + else |
---|
| 8832 | + success |= intersectTriangle(ray, result, p, r, q); |
---|
| 8833 | + |
---|
| 8834 | + p = q; |
---|
| 8835 | + q = r; |
---|
| 8836 | + } |
---|
| 8837 | + } |
---|
| 8838 | + } |
---|
| 8839 | + } else // catch (Error e) |
---|
| 8840 | + { |
---|
| 8841 | + int facecount = bRep.FaceCount(); |
---|
| 8842 | + for (int i = 0; i < facecount; i++) |
---|
| 8843 | + { |
---|
| 8844 | + Face face = bRep.GetFace(i); |
---|
| 8845 | + |
---|
| 8846 | + Vertex p = bRep.GetVertex(face.p); |
---|
| 8847 | + Vertex q = bRep.GetVertex(face.q); |
---|
| 8848 | + Vertex r = bRep.GetVertex(face.r); |
---|
| 8849 | + |
---|
| 8850 | + success |= intersectTriangle(ray, result, p, q, r); |
---|
| 8851 | + } |
---|
| 8852 | + } |
---|
| 8853 | + |
---|
| 8854 | + return success; |
---|
| 8855 | + } |
---|
| 8856 | + |
---|
| 8857 | + static cVector eye = new cVector(); |
---|
| 8858 | + static cVector dir = new cVector(); |
---|
| 8859 | + |
---|
| 8860 | + transient BBox bbox = null; |
---|
| 8861 | + |
---|
| 8862 | + boolean intersect(Ray ray, IntersectResult result) |
---|
| 8863 | + { |
---|
| 8864 | + double eyex = ray.eyePoint.x; |
---|
| 8865 | + double eyey = ray.eyePoint.y; |
---|
| 8866 | + double eyez = ray.eyePoint.z; |
---|
| 8867 | + |
---|
| 8868 | + double dirx = ray.viewDirection.x; |
---|
| 8869 | + double diry = ray.viewDirection.y; |
---|
| 8870 | + double dirz = ray.viewDirection.z; |
---|
| 8871 | + |
---|
| 8872 | + if (this.fromParent != null) |
---|
| 8873 | + { |
---|
| 8874 | + eye.x = eyex; |
---|
| 8875 | + eye.y = eyey; |
---|
| 8876 | + eye.z = eyez; |
---|
| 8877 | + dir.x = dirx; |
---|
| 8878 | + dir.y = diry; |
---|
| 8879 | + dir.z = dirz; |
---|
| 8880 | + |
---|
| 8881 | + LA.xformPos(eye, this.fromParent, eye); |
---|
| 8882 | + LA.xformDir(dir, this.fromParent, dir); |
---|
| 8883 | + |
---|
| 8884 | + ray.eyePoint.x = eye.x; |
---|
| 8885 | + ray.eyePoint.y = eye.y; |
---|
| 8886 | + ray.eyePoint.z = eye.z; |
---|
| 8887 | + |
---|
| 8888 | + ray.viewDirection.x = dir.x; |
---|
| 8889 | + ray.viewDirection.y = dir.y; |
---|
| 8890 | + ray.viewDirection.z = dir.z; |
---|
| 8891 | + } |
---|
| 8892 | + |
---|
| 8893 | + boolean success = false; |
---|
| 8894 | + |
---|
| 8895 | + boolean touch = false; |
---|
| 8896 | + |
---|
| 8897 | + if (bRep != null) |
---|
| 8898 | + { |
---|
| 8899 | + if (bbox == null) |
---|
| 8900 | + { |
---|
| 8901 | + bbox = new BBox(); |
---|
| 8902 | + |
---|
| 8903 | + cVector min = new cVector(); |
---|
| 8904 | + cVector max = new cVector(); |
---|
| 8905 | + |
---|
| 8906 | + this.getBounds(min, max, false); |
---|
| 8907 | + |
---|
| 8908 | + bbox.min.x = min.x; |
---|
| 8909 | + bbox.min.y = min.y; |
---|
| 8910 | + bbox.min.z = min.z; |
---|
| 8911 | + |
---|
| 8912 | + bbox.max.x = max.x; |
---|
| 8913 | + bbox.max.y = max.y; |
---|
| 8914 | + bbox.max.z = max.z; |
---|
| 8915 | + } |
---|
| 8916 | + |
---|
| 8917 | + if (bbox.intersect(ray, result)) |
---|
| 8918 | + { |
---|
| 8919 | + success |= intersectMesh(ray, result); |
---|
| 8920 | + } |
---|
| 8921 | + else |
---|
| 8922 | + { |
---|
| 8923 | + //this.hide = true; |
---|
| 8924 | + touch = true; |
---|
| 8925 | + } |
---|
| 8926 | + } |
---|
| 8927 | + |
---|
| 8928 | + for (int i=0; i<size(); i++) |
---|
| 8929 | + { |
---|
| 8930 | + Object3D child = (Object3D) reserve(i); |
---|
| 8931 | + |
---|
| 8932 | + if (child == null) |
---|
| 8933 | + continue; |
---|
| 8934 | + |
---|
| 8935 | + success |= child.intersect(ray, result); |
---|
| 8936 | + release(i); |
---|
| 8937 | + } |
---|
| 8938 | + |
---|
| 8939 | + ray.eyePoint.x = eyex; |
---|
| 8940 | + ray.eyePoint.y = eyey; |
---|
| 8941 | + ray.eyePoint.z = eyez; |
---|
| 8942 | + |
---|
| 8943 | + ray.viewDirection.x = dirx; |
---|
| 8944 | + ray.viewDirection.y = diry; |
---|
| 8945 | + ray.viewDirection.z = dirz; |
---|
| 8946 | + |
---|
| 8947 | +// if (touch) |
---|
| 8948 | +// this.Touch(); // refresh display list |
---|
| 8949 | + |
---|
| 8950 | + return success; |
---|
| 8951 | + } |
---|
| 8952 | + |
---|
| 8953 | + static Vector3d edge1 = new Vector3d(); |
---|
| 8954 | + static Vector3d edge2 = new Vector3d(); |
---|
| 8955 | + static Vector3d P = new Vector3d(); |
---|
| 8956 | + static Vector3d T = new Vector3d(); |
---|
| 8957 | + static Vector3d Q = new Vector3d(); |
---|
| 8958 | + |
---|
| 8959 | + private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3) |
---|
| 8960 | + { |
---|
| 8961 | + /* |
---|
| 8962 | + Fast, Minimum Storage Ray/Triangle Intersection, Moller et al. |
---|
| 8963 | + |
---|
| 8964 | + Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf |
---|
| 8965 | + */ |
---|
| 8966 | + |
---|
| 8967 | + // Calculate edges of the triangle |
---|
| 8968 | + edge1.set(v2.x - v1.x, v2.y - v1.y, v2.z - v1.z); |
---|
| 8969 | + edge2.set(v3.x - v1.x, v3.y - v1.y, v3.z - v1.z); |
---|
| 8970 | + |
---|
| 8971 | + // Calculate the determinant (U parameter) |
---|
| 8972 | + P.cross(ray.viewDirection, edge2); |
---|
| 8973 | + double det = edge1.dot(P); |
---|
| 8974 | + |
---|
| 8975 | + if (det > -1e-9 && det < 1e-9) |
---|
| 8976 | + { |
---|
| 8977 | + return false; |
---|
| 8978 | + } // Ray lies in plane of triangle |
---|
| 8979 | + |
---|
| 8980 | + double invDet = 1 / det; |
---|
| 8981 | + |
---|
| 8982 | + // Calculate distance from vertex1 to ray origin |
---|
| 8983 | + T.set(ray.eyePoint.x - v1.x, ray.eyePoint.y - v1.y, ray.eyePoint.z - v1.z); |
---|
| 8984 | + |
---|
| 8985 | + double U = (T.dot(P)) * invDet; // Calculate U parameter |
---|
| 8986 | + |
---|
| 8987 | + if (U < 0.f || U > 1.f) |
---|
| 8988 | + { |
---|
| 8989 | + return false; |
---|
| 8990 | + } // Intersection lies outside of the triangle |
---|
| 8991 | + |
---|
| 8992 | + // Calculate V parameter |
---|
| 8993 | + Q.cross(T, edge1); |
---|
| 8994 | + |
---|
| 8995 | + double V = ray.viewDirection.dot(Q) * invDet; |
---|
| 8996 | + |
---|
| 8997 | + if (V < 0.f || (U + V) > 1.f) |
---|
| 8998 | + { |
---|
| 8999 | + return false; |
---|
| 9000 | + } // Intersection lies outside of the triangle |
---|
| 9001 | + |
---|
| 9002 | + double t = edge2.dot(Q) * invDet; |
---|
| 9003 | + |
---|
| 9004 | + if (t > 1e-9) // Triangle and ray intersects |
---|
| 9005 | + { |
---|
| 9006 | + //result.isIntersected = true; |
---|
| 9007 | + //result.id = id; |
---|
| 9008 | + |
---|
| 9009 | + if (false) // isShadow) |
---|
| 9010 | + { |
---|
| 9011 | + result.t = t; |
---|
| 9012 | + return true; |
---|
| 9013 | + } else if (t < result.t) |
---|
| 9014 | + { |
---|
| 9015 | + result.object = this; |
---|
| 9016 | + |
---|
| 9017 | + result.t = t; |
---|
| 9018 | + |
---|
| 9019 | + //result.p.x = ray.eyePoint.x + ray.viewDirection.x * t; |
---|
| 9020 | + //result.p.y = ray.eyePoint.y + ray.viewDirection.y * t; |
---|
| 9021 | + //result.p.z = ray.eyePoint.z + ray.viewDirection.z * t; |
---|
| 9022 | + |
---|
| 9023 | + result.n.cross(edge1, edge2); |
---|
| 9024 | + result.n.normalize(); |
---|
| 9025 | + } |
---|
| 9026 | + |
---|
| 9027 | + return true; |
---|
| 9028 | + } |
---|
| 9029 | + |
---|
| 9030 | + return false; |
---|
| 9031 | + } |
---|
8243 | 9032 | |
---|
8244 | 9033 | public int Size() |
---|
8245 | 9034 | { |
---|