From 4113164b3be1e50251ac40d6fd65660f0a6c2e63 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Tue, 11 Jun 2019 18:46:21 -0400 Subject: [PATCH] Compressed undo stack. --- Object3D.java | 206 +++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 172 insertions(+), 34 deletions(-) diff --git a/Object3D.java b/Object3D.java index 9c74924..5c5d71f 100644 --- a/Object3D.java +++ b/Object3D.java @@ -14,11 +14,15 @@ import //weka.core. matrix.Matrix; +import java.util.UUID; + //import net.sourceforge.sizeof.SizeOf; public class Object3D extends Vector<Object3D> implements java.io.Serializable, iSendInfo //, aurelienribon.tweenengine.TweenAccessor<Object3D> { //static final long serialVersionUID = -607422624994562685L; static final long serialVersionUID = 5022536242724664900L; + + private UUID uuid = UUID.randomUUID(); ScriptNode scriptnode; @@ -156,6 +160,67 @@ blockloop = true; child.RestoreSupports(); blockloop = false; + } +} + +void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable) +{ + if (hashtable.containsKey(GetUUID())) + { + Object3D o = hashtable.get(GetUUID()); + + assert(this.bRep == o.bRep); + if (this.bRep != null) + assert(this.bRep.support == o.transientrep); + + return; + } + + Object3D o = new Object3D(); + o.bRep = this.bRep; + if (this.bRep != null) + { + o.transientrep = this.bRep.support; + o.bRep.support = null; + } + +// o.support = this.support; +// o.fileparent = this.fileparent; +// if (this.bRep != null) +// o.bRep = this.bRep.support; + + hashtable.put(GetUUID(), o); + + this.bRep = null; +// if (this.bRep != null) +// this.bRep.support = null; +// this.support = null; +// this.fileparent = null; + + for (int i=0; i<Size(); i++) + { + get(i).ExtractBigData(hashtable); + } +} + +void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable) +{ + if (!hashtable.containsKey(GetUUID())) + return; + + Object3D o = hashtable.get(GetUUID()); + + this.bRep = o.bRep; + if (this.bRep != null) + this.bRep.support = o.transientrep; +// this.support = o.support; +// this.fileparent = o.fileparent; + + hashtable.remove(GetUUID()); + + for (int i=0; i<Size(); i++) + { + get(i).RestoreBigData(hashtable); } } @@ -300,6 +365,7 @@ } boolean live = false; + boolean dontselect = false; boolean hide = false; boolean link2master = false; // performs reset support/master at each frame boolean marked = false; // animation node @@ -774,7 +840,7 @@ if (step == 0) step = 1; if (maxcount == 0) - maxcount = 2048; // 4; + maxcount = 128; // 2048; // 4; // if (acceleration == 0) // acceleration = 10; if (delay == 0) // serial @@ -1834,12 +1900,15 @@ if (obj.name == null) continue; // can't be a null one + // Try perfect match first. if (n.equals(obj.name)) { theobj = obj; count++; } } + + // not needed: n = n.split(":")[0]; // Poser generates a count if (count != 1) for (int i=Size(); --i>=0;) @@ -3002,8 +3071,10 @@ v.fromParent = LA.newMatrix(); } - LA.matConcat(v.toParent, toParent, v.toParent); - LA.matConcat(fromParent, v.fromParent, v.fromParent); +// LA.matConcat(v.toParent, toParent, v.toParent); +// LA.matConcat(fromParent, v.fromParent, v.fromParent); + LA.matConcat(toParent, v.toParent, v.toParent); + LA.matConcat(v.fromParent, fromParent, v.fromParent); } toParent = null; // LA.matIdentity(toParent); @@ -3236,7 +3307,9 @@ bRep.support = null; BoundaryRep temprep = (BoundaryRep) Grafreed.clone(bRep); // bRep.SplitInTwo(onlyone); // thread... - temprep.SplitInTwo(reduction34, onlyone); + + while(temprep.SplitInTwo(reduction34, onlyone)); + bRep = temprep; bRep.support = sup; Touch(); @@ -4711,7 +4784,7 @@ cTreePath SelectLeaf(int indexcount, boolean deselect) { - if (hide) + if (hide || dontselect) return null; if (count <= 0) @@ -4737,7 +4810,7 @@ cTreePath Select(int indexcount, boolean deselect) { - if (hide) + if (hide || dontselect) return null; if (count <= 0) @@ -5363,6 +5436,43 @@ } } + UUID GetUUID() + { + if (uuid == null) + { + // Serial + uuid = UUID.randomUUID(); + } + + return uuid; + } + + Object3D GetObject(UUID uid) + { + if (blockloop) + return null; + + if (GetUUID().equals(uid)) + return this; + + int nb = Size(); + for (int i = 0; i < nb; i++) + { + Object3D child = (Object3D) get(i); + + if (child == null) + continue; + + blockloop = true; + Object3D obj = child.GetObject(uid); + blockloop = false; + if (obj != null) + return obj; + } + + return null; + } + void SetBumpTexture(String tex) { if (GetTextures() == null) @@ -5407,7 +5517,7 @@ boolean NeedSupport() { return - CameraPane.SUPPORT && !CameraPane.movingcamera && link2master && /*live &&*/ support != null + CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null // PROBLEM with CROWD!! && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD); } @@ -5424,7 +5534,7 @@ } if (display.DrawMode() == iCameraPane.SELECTION && - hide) + (hide || dontselect)) return; if (name != null && name.contains("sclera")) @@ -5666,7 +5776,17 @@ tex = GetTextures(); } - display.BindTextures(tex, texres); + boolean failed = false; + + try + { + display.BindTextures(tex, texres); + } + catch (Exception e) + { + System.err.println("FAILED: " + this); + failed = true; + } if (!compiled) { @@ -5688,7 +5808,8 @@ } } - display.ReleaseTextures(tex); + if (!failed) + display.ReleaseTextures(tex); display.PopMaterial(this, selected); } @@ -5817,6 +5938,9 @@ void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) { + if (display.DrawMode() == iCameraPane.SELECTION && dontselect) + return; + if (hide) return; // shadow optimisation @@ -5941,6 +6065,9 @@ { if (display.DrawMode() == display.SHADOW && projectedVertices != null && projectedVertices.length > 2 && projectedVertices[2].y >= 10000) return; // no shadow for transparent objects + + if (display.DrawMode() == iCameraPane.SELECTION && dontselect) + return; if (hide) return; @@ -6925,8 +7052,8 @@ // { // CameraPane.Ymax = spoth; // } - info.g.drawLine(spotw, spoth, spotw, spoth - 15); - info.g.drawLine(spotw, spoth, spotw - 15, spoth); + // bonhommes info.g.drawLine(spotw, spoth, spotw, spoth - 15); + //info.g.drawLine(spotw, spoth, spotw - 15, spoth); spot.translate(0, -32); info.g.setColor(Color.green); info.g.fillRect(spot.x, spot.y, spot.width, spot.height); @@ -6981,7 +7108,7 @@ startX = info.x; startY = info.y; - hitSomething = 0; + hitSomething = -1; cVector origin = new cVector(); //LA.xformPos(origin, toParent, origin); Rectangle spot = new Rectangle(); @@ -7057,6 +7184,7 @@ //System.out.println("hitSomething = " + hitSomething); double scale = 0.005f * info.camera.Distance(); + cVector xlate = new cVector(); //cVector xlate2 = new cVector(); switch (hitSomething) @@ -7205,24 +7333,27 @@ case hitScale: // scale double hScale = (double) (info.x - centerPt.x) / 32; + double sign = 1; + if (hScale < 0) + { + sign = -1; + } + hScale = sign*Math.pow(sign*hScale, scale * 50); if (hScale < 0.01) { - hScale = 0.01; + //hScale = 0.01; } - hScale = Math.pow(hScale, scale * 50); - if (hScale < 0.01) - { - hScale = 0.01; - } + double vScale = (double) (info.y - centerPt.y) / 32; - if (vScale < 0.01) + sign = 1; + if (vScale < 0) { - vScale = 0.01; + sign = -1; } - vScale = Math.pow(vScale, scale * 50); + vScale = sign*Math.pow(sign*vScale, scale * 50); if (vScale < 0.01) { - vScale = 0.01; + //vScale = 0.01; } LA.matCopy(startMat, toParent); /**/ @@ -7233,17 +7364,24 @@ } /**/ + double totalScale = Math.sqrt(hScale*hScale + vScale*vScale) / Math.sqrt(2); + + if (totalScale < 0.01) + { + totalScale = 0.01; + } + switch (info.pane.RenderCamera().viewCode) { case 3: // '\001' if (modified) { //LA.matScale(toParent, 1, hScale, vScale); - LA.matScale(toParent, vScale, 1, 1); + LA.matScale(toParent, totalScale, 1, 1); } // vScale, 1); else { - LA.matScale(toParent, vScale, vScale, vScale); + LA.matScale(toParent, totalScale, totalScale, totalScale); } // vScale, 1); break; @@ -7251,10 +7389,10 @@ if (modified) { //LA.matScale(toParent, hScale, 1, vScale); - LA.matScale(toParent, 1, vScale, 1); + LA.matScale(toParent, 1, totalScale, 1); } else { - LA.matScale(toParent, vScale, 1, vScale); + LA.matScale(toParent, totalScale, 1, totalScale); } break; @@ -7262,10 +7400,10 @@ if (modified) { //LA.matScale(toParent, hScale, vScale, 1); - LA.matScale(toParent, 1, 1, vScale); + LA.matScale(toParent, 1, 1, totalScale); } else { - LA.matScale(toParent, vScale, vScale, 1); + LA.matScale(toParent, totalScale, totalScale, 1); } break; } @@ -7406,7 +7544,7 @@ objname = name + " " + System.identityHashCode(this) + " (" + parent.name + " " + System.identityHashCode(parent) + ")"; } else { - objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count /*- 1*/) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ ""; + objname = GetName() + (Math.abs(count) == 1000 ? (count == 1000 ? " " : " * ") : (" (" + (count - 1) + ")")) + /*(IsSelected()?"(selected) ":"") + (touched?"(touched) ":"") */ ""; } // + super.toString(); //return name + " (" + (SizeOf.deepSizeOf(this)/1024) + "K) " + this.getClass().getName(); @@ -7490,7 +7628,7 @@ /*transient*/ cVector2[] projectedVertices = new cVector2[0]; Object3D /*Composite*/ parent; - Object3D /*Composite*/ fileparent; + Object3D /*Composite*/ fileparent; // In the case of FileObject double[][] toParent; // dynamic matrix double[][] fromParent; @@ -7654,9 +7792,9 @@ private static cVector edge2 = new cVector(); //private static cVector norm = new cVector(); /*transient private*/ int hitSomething; - private static final int hitCenter = 1; - private static final int hitScale = 2; - private static final int hitRotate = 3; + static final int hitCenter = 1; + static final int hitScale = 2; + static final int hitRotate = 3; /*transient*/ /*private*/ int viewCode; // Now used for transparency cache flag /*transient*/ private Point centerPt; /*transient*/ private int startX; -- Gitblit v1.6.2