Normand Briere
2019-07-27 1af7d3700724834e40ad8636bc9a56cdc3b19b15
Object3D.java
....@@ -29,7 +29,7 @@
2929 Object3D saveskeleton;
3030 //
3131
32
- byte[] versions[] = new byte[100][];
32
+ byte[] versions[];
3333 int versionindex = -1;
3434
3535 ScriptNode scriptnode;
....@@ -426,6 +426,7 @@
426426 }
427427
428428 boolean live = false;
429
+ transient boolean keepdontselect;
429430 boolean dontselect = false;
430431 boolean hide = false;
431432 boolean link2master = false; // performs reset support/master at each frame
....@@ -2566,7 +2567,8 @@
25662567 private static final int editSelf = 1;
25672568 private static final int editChild = 2;
25682569
2569
- void drawEditHandles(ClickInfo info, int level)
2570
+ void drawEditHandles(//ClickInfo info,
2571
+ int level)
25702572 {
25712573 if (level == 0)
25722574 {
....@@ -2574,7 +2576,8 @@
25742576 return;
25752577
25762578 Object3D selectee;
2577
- for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(info, level + 1))
2579
+ for (java.util.Enumeration e = selection.elements(); e.hasMoreElements(); selectee.drawEditHandles(//info,
2580
+ level + 1))
25782581 {
25792582 selectee = (Object3D) e.nextElement();
25802583 }
....@@ -2582,19 +2585,22 @@
25822585 } else
25832586 {
25842587 //super.
2585
- drawEditHandles0(info, level + 1);
2588
+ drawEditHandles0(//info,
2589
+ level + 1);
25862590 }
25872591 }
25882592
2589
- boolean doEditClick(ClickInfo info, int level)
2593
+ boolean doEditClick(//ClickInfo info,
2594
+ int level)
25902595 {
25912596 doSomething = 0;
25922597 if (level == 0)
25932598 {
2594
- return doParentClick(info);
2599
+ return doParentClick(); //info);
25952600 }
25962601 if (//super.
2597
- doEditClick0(info, level))
2602
+ doEditClick0(//info,
2603
+ level))
25982604 {
25992605 doSomething = 1;
26002606 return true;
....@@ -2604,7 +2610,7 @@
26042610 }
26052611 }
26062612
2607
- boolean doParentClick(ClickInfo info)
2613
+ boolean doParentClick() //ClickInfo info)
26082614 {
26092615 if (selection == null)
26102616 {
....@@ -2617,7 +2623,8 @@
26172623 for (java.util.Enumeration e = selection.elements(); e.hasMoreElements();)
26182624 {
26192625 Object3D selectee = (Object3D) e.nextElement();
2620
- if (selectee.doEditClick(info, 1))
2626
+ if (selectee.doEditClick(//info,
2627
+ 1))
26212628 {
26222629 childToDrag = selectee;
26232630 doSomething = 2;
....@@ -2629,13 +2636,15 @@
26292636 return retval;
26302637 }
26312638
2632
- void doEditDrag(ClickInfo info, boolean opposite)
2639
+ void doEditDrag(//ClickInfo clickInfo,
2640
+ boolean opposite)
26332641 {
26342642 switch (doSomething)
26352643 {
26362644 case 1: // '\001'
26372645 //super.
2638
- doEditDrag0(info, opposite);
2646
+ doEditDrag0(//clickInfo,
2647
+ opposite);
26392648 break;
26402649
26412650 case 2: // '\002'
....@@ -2648,11 +2657,13 @@
26482657 {
26492658 //sel.hitSomething = childToDrag.hitSomething;
26502659 //childToDrag.doEditDrag(info);
2651
- sel.doEditDrag(info, opposite);
2660
+ sel.doEditDrag(//clickInfo,
2661
+ opposite);
26522662 } else
26532663 {
26542664 //super.
2655
- doEditDrag0(info, opposite);
2665
+ doEditDrag0(//clickInfo,
2666
+ opposite);
26562667 }
26572668 }
26582669 break;
....@@ -2670,6 +2681,9 @@
26702681 {
26712682 deselectAll();
26722683 }
2684
+
2685
+ new Exception().printStackTrace();
2686
+
26732687 ClickInfo newInfo = new ClickInfo();
26742688 newInfo.flags = info.flags;
26752689 newInfo.bounds = info.bounds;
....@@ -3117,7 +3131,7 @@
31173131 {
31183132 if (bRep != null)
31193133 {
3120
- bRep.GenerateNormalsMINE();
3134
+ bRep.MergeNormals(); //.GenerateNormalsMINE();
31213135 Touch();
31223136 }
31233137 }
....@@ -5420,6 +5434,51 @@
54205434 blockloop = false;
54215435 }
54225436
5437
+ void ResetSelectable()
5438
+ {
5439
+ if (blockloop)
5440
+ return;
5441
+
5442
+ blockloop = true;
5443
+
5444
+ keepdontselect = dontselect;
5445
+ dontselect = true;
5446
+
5447
+ Object3D child;
5448
+ int nb = Size();
5449
+ for (int i = 0; i < nb; i++)
5450
+ {
5451
+ child = (Object3D) get(i);
5452
+ if (child == null)
5453
+ continue;
5454
+ child.ResetSelectable();
5455
+ }
5456
+
5457
+ blockloop = false;
5458
+ }
5459
+
5460
+ void RestoreSelectable()
5461
+ {
5462
+ if (blockloop)
5463
+ return;
5464
+
5465
+ blockloop = true;
5466
+
5467
+ dontselect = keepdontselect;
5468
+
5469
+ Object3D child;
5470
+ int nb = Size();
5471
+ for (int i = 0; i < nb; i++)
5472
+ {
5473
+ child = (Object3D) get(i);
5474
+ if (child == null)
5475
+ continue;
5476
+ child.RestoreSelectable();
5477
+ }
5478
+
5479
+ blockloop = false;
5480
+ }
5481
+
54235482 boolean IsSelected()
54245483 {
54255484 if (parent == null)
....@@ -5729,6 +5788,38 @@
57295788 }
57305789 }
57315790
5791
+ void EmbedTextures(boolean embed)
5792
+ {
5793
+ if (blockloop)
5794
+ return;
5795
+
5796
+ //if (GetTextures() != null)
5797
+ if (embed)
5798
+ CameraPane.EmbedTextures(GetTextures());
5799
+ else
5800
+ {
5801
+ GetTextures().pigmentdata = null;
5802
+ GetTextures().bumpdata = null;
5803
+ GetTextures().pw = 0;
5804
+ GetTextures().ph = 0;
5805
+ GetTextures().bw = 0;
5806
+ GetTextures().bh = 0;
5807
+ }
5808
+
5809
+ int nb = Size();
5810
+ for (int i = 0; i < nb; i++)
5811
+ {
5812
+ Object3D child = (Object3D) get(i);
5813
+
5814
+ if (child == null)
5815
+ continue;
5816
+
5817
+ blockloop = true;
5818
+ child.EmbedTextures(embed);
5819
+ blockloop = false;
5820
+ }
5821
+ }
5822
+
57325823 void draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
57335824 {
57345825 Draw(display, root, selected, blocked);
....@@ -5816,7 +5907,7 @@
58165907 support = support;
58175908
58185909 //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);
5910
+ boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
58205911
58215912 if (!usecalllists && bRep != null && bRep.displaylist > 0)
58225913 {
....@@ -7220,20 +7311,23 @@
72207311 }
72217312 }
72227313
7223
- protected void calcHotSpot(cVector in, ClickInfo info, Point outPt, Rectangle outRec)
7314
+ static ClickInfo clickInfo = new ClickInfo();
7315
+
7316
+ protected void calcHotSpot(cVector in, //ClickInfo clickInfo,
7317
+ Point outPt, Rectangle outRec)
72247318 {
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;
7319
+ int hc = clickInfo.bounds.x + clickInfo.bounds.width / 2;
7320
+ int vc = clickInfo.bounds.y + clickInfo.bounds.height / 2;
7321
+ double[][] toscreen = clickInfo.toScreen;
72287322 if (toscreen == null)
72297323 {
7230
- toscreen = new Camera(info.camera.viewCode).toScreen;
7324
+ toscreen = new Camera(clickInfo.camera.viewCode).toScreen;
72317325 }
72327326 cVector vec = in;
72337327 LA.xformPos(in, toscreen, in);
72347328 //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();
7329
+ vec.x *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
7330
+ vec.y *= 100 * clickInfo.camera.SCALE / clickInfo.camera.Distance();
72377331 outPt.x = hc + (int) vec.x;
72387332 outPt.y = vc - (int) vec.y;
72397333 outRec.x = outPt.x - 3;
....@@ -7241,15 +7335,18 @@
72417335 outRec.width = outRec.height = 6;
72427336 }
72437337
7244
- protected Rectangle calcHotSpot(cVector in, ClickInfo info)
7338
+ protected Rectangle calcHotSpot(cVector in//, ClickInfo clickInfo
7339
+ )
72457340 {
72467341 Point pt = new Point(0, 0);
72477342 Rectangle rec = new Rectangle();
7248
- calcHotSpot(in, info, pt, rec);
7343
+ calcHotSpot(in, //clickInfo,
7344
+ pt, rec);
72497345 return rec;
72507346 }
72517347
7252
- void drawEditHandles0(ClickInfo info, int level)
7348
+ void drawEditHandles0(//ClickInfo clickInfo,
7349
+ int level)
72537350 {
72547351 if (level == 0)
72557352 {
....@@ -7258,16 +7355,19 @@
72587355 {
72597356 cVector origin = new cVector();
72607357 //LA.xformPos(origin, toParent, origin);
7261
- Rectangle spot = calcHotSpot(origin, info);
7358
+ if (this.clickInfo == null)
7359
+ this.clickInfo = new ClickInfo();
7360
+
7361
+ Rectangle spot = calcHotSpot(origin); //, clickInfo);
72627362 Rectangle boundary = new Rectangle();
72637363 boundary.x = spot.x - 30;
72647364 boundary.y = spot.y - 30;
72657365 boundary.width = spot.width + 60;
72667366 boundary.height = spot.height + 60;
7267
- info.g.setColor(Color.red);
7367
+ clickInfo.g.setColor(Color.red);
72687368 int spotw = spot.x + spot.width;
72697369 int spoth = spot.y + spot.height;
7270
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7370
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
72717371 // if (CameraPane.Xmin > spot.x)
72727372 // {
72737373 // CameraPane.Xmin = spot.x;
....@@ -7287,8 +7387,8 @@
72877387 spot.translate(32, 32);
72887388 spotw = spot.x + spot.width;
72897389 spoth = spot.y + spot.height;
7290
- info.g.setColor(Color.cyan);
7291
- info.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7390
+ clickInfo.g.setColor(Color.cyan);
7391
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
72927392 // if (CameraPane.Xmin > spot.x)
72937393 // {
72947394 // CameraPane.Xmin = spot.x;
....@@ -7308,9 +7408,9 @@
73087408 // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - boundary.height/2); // 15
73097409 //info.g.drawLine(spotw, spoth, spotw - boundary.width/2, spoth); // 15
73107410 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);
7411
+ clickInfo.g.setColor(Color.yellow);
7412
+ clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
7413
+ clickInfo.g.setColor(Color.green);
73147414 // if (CameraPane.Xmin > spot.x)
73157415 // {
73167416 // CameraPane.Xmin = spot.x;
....@@ -7327,8 +7427,8 @@
73277427 // {
73287428 // CameraPane.Ymax = spoth;
73297429 // }
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);
7430
+ clickInfo.g.drawArc(boundary.x + clickInfo.DX, boundary.y + clickInfo.DY,
7431
+ (int)(boundary.width * clickInfo.W), (int)(boundary.height * clickInfo.W), 0, 360);
73327432 //info.g.drawArc(spot.x, spotw, spot.width/2, boundary.height/2, 0, 360);
73337433 // if (CameraPane.Xmin > boundary.x)
73347434 // {
....@@ -7350,7 +7450,8 @@
73507450 }
73517451 }
73527452
7353
- boolean doEditClick0(ClickInfo info, int level)
7453
+ boolean doEditClick0(//ClickInfo clickInfo,
7454
+ int level)
73547455 {
73557456 if (level == 0)
73567457 {
....@@ -7359,8 +7460,8 @@
73597460
73607461 boolean retval = false;
73617462
7362
- startX = info.x;
7363
- startY = info.y;
7463
+ startX = clickInfo.x;
7464
+ startY = clickInfo.y;
73647465
73657466 hitSomething = -1;
73667467 cVector origin = new cVector();
....@@ -7370,22 +7471,51 @@
73707471 {
73717472 centerPt = new Point(0, 0);
73727473 }
7373
- calcHotSpot(origin, info, centerPt, spot);
7374
- if (spot.contains(info.x, info.y))
7474
+ calcHotSpot(origin, //info,
7475
+ centerPt, spot);
7476
+ if (spot.contains(clickInfo.x, clickInfo.y))
73757477 {
73767478 hitSomething = hitCenter;
73777479 retval = true;
73787480 }
73797481 spot.translate(32, 0);
7380
- if (spot.contains(info.x, info.y))
7482
+ if (spot.contains(clickInfo.x, clickInfo.y))
73817483 {
73827484 hitSomething = hitRotate;
73837485 retval = true;
73847486 }
73857487 spot.translate(0, 32);
7386
- if (spot.contains(info.x, info.y))
7488
+ if (spot.contains(clickInfo.x, clickInfo.y))
73877489 {
73887490 hitSomething = hitScale;
7491
+
7492
+ double scale = 0.005f * clickInfo.camera.Distance();
7493
+ double hScale = (double) (clickInfo.x /*- centerPt.x*/) / 32;
7494
+ double sign = 1;
7495
+ if (hScale < 0)
7496
+ {
7497
+ sign = -1;
7498
+ }
7499
+ hScale = sign*Math.pow(sign*hScale, scale * 50);
7500
+ if (hScale < 0.01)
7501
+ {
7502
+ //hScale = 0.01;
7503
+ }
7504
+
7505
+ double vScale = (double) (clickInfo.y /*- centerPt.y*/) / 32;
7506
+ sign = 1;
7507
+ if (vScale < 0)
7508
+ {
7509
+ sign = -1;
7510
+ }
7511
+ vScale = sign*Math.pow(sign*vScale, scale * 50);
7512
+ if (vScale < 0.01)
7513
+ {
7514
+ //vScale = 0.01;
7515
+ }
7516
+
7517
+ clickInfo.scale = Math.sqrt(hScale*hScale + vScale*vScale);
7518
+
73897519 retval = true;
73907520 }
73917521
....@@ -7395,7 +7525,7 @@
73957525 }
73967526
73977527 //System.out.println("info.modifiers = " + info.modifiers);
7398
- modified = (info.modifiers & CameraPane.SHIFT) != 0; // Was META
7528
+ modified = (clickInfo.modifiers & CameraPane.SHIFT) != 0; // Was META
73997529 //System.out.println("modified = " + modified);
74007530 //new Exception().printStackTrace();
74017531 //viewCode = info.pane.renderCamera.viewCode;
....@@ -7423,7 +7553,8 @@
74237553 return true;
74247554 }
74257555
7426
- void doEditDrag0(ClickInfo info, boolean opposite)
7556
+ void doEditDrag0(//ClickInfo info,
7557
+ boolean opposite)
74277558 {
74287559 if (hitSomething == 0)
74297560 {
....@@ -7437,7 +7568,7 @@
74377568
74387569 //System.out.println("hitSomething = " + hitSomething);
74397570
7440
- double scale = 0.005f * info.camera.Distance();
7571
+ double scale = 0.005f * clickInfo.camera.Distance();
74417572
74427573 cVector xlate = new cVector();
74437574 //cVector xlate2 = new cVector();
....@@ -7471,8 +7602,8 @@
74717602 toParent[3][i] = xlate.get(i);
74727603 LA.matInvert(toParent, fromParent);
74737604 */
7474
- cVector delta = LA.newVector(0, 0, startY - info.y);
7475
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
7605
+ cVector delta = LA.newVector(0, 0, startY - clickInfo.y);
7606
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
74767607
74777608 LA.matCopy(startMat, toParent);
74787609 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7481,7 +7612,7 @@
74817612 } else
74827613 {
74837614 //LA.xformDir(delta, info.camera.fromScreen, delta);
7484
- cVector up = new cVector(info.camera.up);
7615
+ cVector up = new cVector(clickInfo.camera.up);
74857616 cVector away = new cVector();
74867617 //cVector right2 = new cVector();
74877618 //LA.vecCross(up, cVector.Z, right);
....@@ -7498,19 +7629,19 @@
74987629 LA.xformDir(up, ClickInfo.matbuffer, up);
74997630 // if (!CameraPane.LOCALTRANSFORM)
75007631 LA.xformDir(up, Globals.theRenderer.RenderCamera().toScreen, up);
7501
- LA.xformDir(info.camera.away, ClickInfo.matbuffer, away);
7632
+ LA.xformDir(clickInfo.camera.away, ClickInfo.matbuffer, away);
75027633 // if (!CameraPane.LOCALTRANSFORM)
75037634 LA.xformDir(away, Globals.theRenderer.RenderCamera().toScreen, away);
75047635 //LA.vecCross(up, cVector.Z, right2);
75057636
7506
- cVector delta = LA.newVector(info.x - startX, startY - info.y, 0);
7637
+ cVector delta = LA.newVector(clickInfo.x - startX, startY - clickInfo.y, 0);
75077638
75087639 //System.out.println("DELTA0 = " + delta);
75097640 //System.out.println("AWAY = " + info.camera.away);
75107641 //System.out.println("UP = " + info.camera.up);
75117642 if (away.z > 0)
75127643 {
7513
- if (info.camera.up.x == 0) // LA.vecDot(right, right2)<0)
7644
+ if (clickInfo.camera.up.x == 0) // LA.vecDot(right, right2)<0)
75147645 {
75157646 delta.x = -delta.x;
75167647 } else
....@@ -7525,7 +7656,7 @@
75257656 //System.out.println("DELTA1 = " + delta);
75267657 LA.xformDir(delta, ClickInfo.matbuffer, delta);
75277658 //System.out.println("DELTA2 = " + delta);
7528
- LA.xformDir(delta, new Camera(info.camera.viewCode).fromScreen, delta);
7659
+ LA.xformDir(delta, new Camera(clickInfo.camera.viewCode).fromScreen, delta);
75297660 LA.matCopy(startMat, toParent);
75307661 //System.out.println("DELTA3 = " + delta);
75317662 LA.matTranslate(toParent, delta.x * scale, delta.y * scale, delta.z * scale);
....@@ -7535,8 +7666,8 @@
75357666 break;
75367667
75377668 case hitRotate: // rotate
7538
- int dx = info.x - centerPt.x;
7539
- int dy = -(info.y - centerPt.y);
7669
+ int dx = clickInfo.x - centerPt.x;
7670
+ int dy = -(clickInfo.y - centerPt.y);
75407671 double angle = (double) Math.atan2(dx, dy);
75417672 angle = -(1.570796 - angle);
75427673
....@@ -7559,7 +7690,7 @@
75597690 }
75607691 /**/
75617692
7562
- switch (info.pane.RenderCamera().viewCode)
7693
+ switch (clickInfo.pane.RenderCamera().viewCode)
75637694 {
75647695 case 1: // '\001'
75657696 LA.matZRotate(toParent, angle);
....@@ -7586,7 +7717,7 @@
75867717 break;
75877718
75887719 case hitScale: // scale
7589
- double hScale = (double) (info.x - centerPt.x) / 32;
7720
+ double hScale = (double) (clickInfo.x /*- centerPt.x*/) / 32;
75907721 double sign = 1;
75917722 if (hScale < 0)
75927723 {
....@@ -7598,7 +7729,7 @@
75987729 //hScale = 0.01;
75997730 }
76007731
7601
- double vScale = (double) (info.y - centerPt.y) / 32;
7732
+ double vScale = (double) (clickInfo.y /*- centerPt.y*/) / 32;
76027733 sign = 1;
76037734 if (vScale < 0)
76047735 {
....@@ -7609,6 +7740,7 @@
76097740 {
76107741 //vScale = 0.01;
76117742 }
7743
+
76127744 LA.matCopy(startMat, toParent);
76137745 /**/
76147746 for (int i = 0; i < 3; i++)
....@@ -7618,14 +7750,14 @@
76187750 }
76197751 /**/
76207752
7621
- double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2);
7753
+ double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / clickInfo.scale;
76227754
76237755 if (totalScale < 0.01)
76247756 {
76257757 totalScale = 0.01;
76267758 }
76277759
7628
- switch (info.pane.RenderCamera().viewCode)
7760
+ switch (clickInfo.pane.RenderCamera().viewCode)
76297761 {
76307762 case 3: // '\001'
76317763 if (modified || opposite)
....@@ -7692,7 +7824,7 @@
76927824 } // NEW ...
76937825
76947826
7695
- info.pane.repaint();
7827
+ clickInfo.pane.repaint();
76967828 }
76977829
76987830 boolean overflow = false;