From 47745d8ade7238a188f7ab78eaf5e8a269d96fdd Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Tue, 27 Aug 2019 21:41:45 -0400 Subject: [PATCH] Smooth keys + box editor. --- BiparamEditor.java | 7 ObjEditor.java | 17 + CameraPane.java | 275 +++++++++++++++++++++++---------- Box.java | 66 ++++++- Camera.java | 2 Object3D.java | 2 Composite.java | 2 BoxEditor.java | 106 ++++++++++--- 8 files changed, 341 insertions(+), 136 deletions(-) diff --git a/BiparamEditor.java b/BiparamEditor.java index 0e9f09e..3685e67 100644 --- a/BiparamEditor.java +++ b/BiparamEditor.java @@ -72,7 +72,7 @@ int count = 50; - uDivsField = (cNumberSlider)AddSlider(uvPanel, "U #", biparam.minUDivs, (int)(count*this.biparam.uStretch()) + biparam.minUDivs, biparam.uDivs).getComponent(1); + uDivsField = (cNumberSlider)AddSlider(uvPanel, "U #", biparam.minUDivs, (int)(count*this.biparam.uStretch() / 2) + biparam.minUDivs, biparam.uDivs).getComponent(1); vDivsField = (cNumberSlider)AddSlider(uvPanel, "V #", biparam.minVDivs, (int)(count) + biparam.minVDivs, biparam.vDivs).getComponent(1); oe.ctrlPanel.add(uvPanel); @@ -104,8 +104,8 @@ if (biparam instanceof Cone) // ends) { oe.ctrlPanel.add(optionCB = new JCheckBox("Close Surface", biparam.endcaps)); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2); - optionCB.addItemListener(this); -oe.ctrlPanel.Return(); + optionCB.addItemListener(this); + oe.ctrlPanel.Return(); //endcaps.setState(!biparam.endcaps); } } @@ -142,6 +142,7 @@ if (//e.getSource() == nameField || e.getSource() == optionCB) { + new Exception().printStackTrace(); //System.out.println(e); applySelf(); //super.applySelf(); diff --git a/Box.java b/Box.java index b674d00..8459450 100644 --- a/Box.java +++ b/Box.java @@ -2,6 +2,8 @@ { static final long serialVersionUID = 0; + boolean open; + Box() { inPnt = new cVector(); @@ -9,9 +11,6 @@ minima = LA.newVector(-0.5, 0, -0.5); maxima = LA.newVector(0.5, 1, 0.5); bRep = new BoundaryRep(); - bRep.redimension(8, 12); - for (int i=0; i < 12; i++) - bRep.setFace(i, faces[i]); recalculate(); CreateMaterial(); @@ -27,11 +26,11 @@ protected void deepCopySelf(Object3D other) { super.deepCopySelf(other); - Box rec = (Box)other; - rec.minima = new cVector(); - LA.vecCopy(minima, rec.minima); - rec.maxima = new cVector(); - LA.vecCopy(maxima, rec.maxima); +// Box rec = (Box)other; +// rec.minima = new cVector(); +// LA.vecCopy(minima, rec.minima); +// rec.maxima = new cVector(); +// LA.vecCopy(maxima, rec.maxima); } void createEditWindow(GroupEditor callee, boolean newWindow) @@ -39,12 +38,12 @@ //editWindow = new BoxEditor(this, deepCopy(), callee); /**/ if (newWindow) - objectUI = new ObjEditor(this, deepCopy(), callee); + objectUI = new BoxEditor(this, deepCopy(), callee); else - objectUI = new ObjEditor(this, callee); + objectUI = new BoxEditor(this, callee); editWindow = objectUI.GetEditor(); - if (!newWindow) - ((ObjEditor)objectUI).SetupUI2(callee); +// if (!newWindow) +// ((ObjEditor)objectUI).SetupUI2(callee); /**/ } @@ -64,6 +63,19 @@ void recalculate() { + if (open) + { + bRep.redimension(8, 8); + for (int i=0; i < 8; i++) + bRep.setFace(i, facesopen[i]); + } + else + { + bRep.redimension(8, 12); + for (int i=0; i < 12; i++) + bRep.setFace(i, faces[i]); + } + for (int i=0; i < 8; i++) { double x = i >= 4 ? maxima.x : minima.x; @@ -71,7 +83,7 @@ double z = i % 2 != 0 ? maxima.z : minima.z; bRep.setVertex(i, x, y, z, umap[i], vmap[i]); } - + // bRep.Trim(false, false); super.recalculate(); @@ -139,5 +151,33 @@ } }; + static int facesopen[][] = { + { + 0, 1, 3 + }, { + 0, 3, 2 + }, { +// 2, 3, 7 +// }, { +// 2, 7, 6 +// }, { + 1, 5, 7 + }, { + 1, 7, 3 + }, { + 4, 6, 7 + }, { + 4, 7, 5 + }, { +// 0, 4, 5 +// }, { +// 0, 5, 1 +// }, { + 0, 2, 6 + }, { + 0, 6, 4 + } + }; + protected cVector inPnt; } diff --git a/BoxEditor.java b/BoxEditor.java index 9860739..7a9962b 100644 --- a/BoxEditor.java +++ b/BoxEditor.java @@ -9,31 +9,46 @@ class BoxEditor extends ObjEditor { + BoxEditor(Box inBox, GroupEditor callee) + { + super(inBox, callee); + + //objEditor = new BiparamEditor(inCone, this, callee); + objEditor = callee.GetEditor(); + + this.box = inBox; + + SetupUI2(GetEditor()); + } + BoxEditor(Box inBox, Object3D copy, GroupEditor callee) { super(inBox, copy, callee); + + new Exception().printStackTrace(); + box = (Box) copy; - ctrlPanel.add(minLabel = new JLabel("Minima"), aConstraints); - aConstraints.gridx += 1; - aConstraints.fill = GridBagConstraints.HORIZONTAL; - aConstraints.gridwidth = ObjEditor.GRIDWIDTH; - ctrlPanel.add(minimaField = new NumberField(), aConstraints); - aConstraints.gridwidth = 1; - minimaField.setVector(box.minima); - aConstraints.gridx = 0; - aConstraints.gridy += 1; - aConstraints.fill = GridBagConstraints.NONE; - ctrlPanel.add(maxLabel = new JLabel("Maxima"), aConstraints); - aConstraints.gridx += 1; - aConstraints.fill = GridBagConstraints.HORIZONTAL; - aConstraints.gridwidth = ObjEditor.GRIDWIDTH; - ctrlPanel.add(maximaField = new NumberField(), aConstraints); - aConstraints.gridwidth = 1; - maximaField.setVector(box.maxima); - aConstraints.fill = GridBagConstraints.NONE; - aConstraints.gridx = 0; - aConstraints.gridy += 1; +// ctrlPanel.add(minLabel = new JLabel("Minima"), aConstraints); +// aConstraints.gridx += 1; +// aConstraints.fill = GridBagConstraints.HORIZONTAL; +// aConstraints.gridwidth = ObjEditor.GRIDWIDTH; +// ctrlPanel.add(minimaField = new NumberField(), aConstraints); +// aConstraints.gridwidth = 1; +// minimaField.setVector(box.minima); +// aConstraints.gridx = 0; +// aConstraints.gridy += 1; +// aConstraints.fill = GridBagConstraints.NONE; +// ctrlPanel.add(maxLabel = new JLabel("Maxima"), aConstraints); +// aConstraints.gridx += 1; +// aConstraints.fill = GridBagConstraints.HORIZONTAL; +// aConstraints.gridwidth = ObjEditor.GRIDWIDTH; +// ctrlPanel.add(maximaField = new NumberField(), aConstraints); +// aConstraints.gridwidth = 1; +// maximaField.setVector(box.maxima); +// aConstraints.fill = GridBagConstraints.NONE; +// aConstraints.gridx = 0; +// aConstraints.gridy += 1; } void Clear() @@ -53,17 +68,56 @@ } */ + void SetupUI2(ObjEditor oe) + { + super.SetupUI2(oe); + + oe.ctrlPanel.add(optionCB = new JCheckBox("Close Surface", box.open)); //, oe.aConstraints, oe.ctrlPanel.getComponentCount()-2); + optionCB.addItemListener(this); + oe.ctrlPanel.Return(); + } + + public void itemStateChanged(ItemEvent e) + { + if (//e.getSource() == nameField || + e.getSource() == optionCB) + { + box.open = (e.getStateChange() == ItemEvent.SELECTED); + + applySelf(); + + objEditor.refreshContents(); + } + else + { + super.itemStateChanged(e); + } + } + + + public void closeUI() + { + ObjEditor oe = GetEditor(); + + oe.ctrlPanel.remove(optionCB); + + super.closeUI(); + } + public void applySelf() { // june 2013 super.applySelf(); - minimaField.getVector(box.minima); - maximaField.getVector(box.maxima); +// minimaField.getVector(box.minima); +// maximaField.getVector(box.maxima); box.recalculate(); } Box box; - JLabel minLabel; - JLabel maxLabel; - NumberField minimaField; - NumberField maximaField; + +// JLabel minLabel; +// JLabel maxLabel; +// NumberField minimaField; +// NumberField maximaField; + + JCheckBox optionCB; } diff --git a/Camera.java b/Camera.java index 0195701..ba4af41 100644 --- a/Camera.java +++ b/Camera.java @@ -328,7 +328,7 @@ location.set(lookAt); lookAt.set(cStatic.point1); - //computeTransform(); + computeTransform(); } //synchronized // june 2014 diff --git a/CameraPane.java b/CameraPane.java index 68bd5e4..e039bde 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -8642,7 +8642,9 @@ { tex.bw = texturecache.texturedata.getWidth(); tex.bh = texturecache.texturedata.getHeight(); - tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); + tex.bumpdata = //CompressJPEG(CreateBim( + ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); + //, tex.bw, tex.bh), 0.5f); } } } @@ -10813,6 +10815,83 @@ if (DrawMode() == DEFAULT) { + if (manipCamera == lightCamera) + { +// switch (e.getKeyCode()) +// { +// case DOWN_ARROW: +// lightCamera.DECAL /= 2; +// repaint(); +// break; +// case UP_ARROW: +// lightCamera.DECAL *= 2; +// repaint(); +// break; +// case LEFT_ARROW: +// lightCamera.SCALE /= 2; +// repaint(); +// break; +// case RIGHT_ARROW: +// lightCamera.SCALE *= 2; +// repaint(); +// break; +// default: +// break; + if (keys[DOWN_ARROW]) + { + lightCamera.DECAL /= 2; + } + + if (keys[UP_ARROW]) + { + lightCamera.DECAL *= 2; + } + + if (keys[LEFT_ARROW]) + { + lightCamera.SCALE /= 2; + } + + if (keys[RIGHT_ARROW]) + { + lightCamera.SCALE *= 2; + } + } + else + { + //pingthread.mute = true; + + boolean keyon = false; + + if (keys[DOWN_ARROW]) + { + GoDown(modifiers); + keyon = true; + } + + if (keys[UP_ARROW]) + { + GoUp(modifiers); + keyon = true; + } + + if (keys[LEFT_ARROW]) + { + GoLeft(modifiers); + keyon = true; + } + + if (keys[RIGHT_ARROW]) + { + GoRight(modifiers); + keyon = true; + } + + if (keyon) + repaint(); + //pingthread.mute = false; + } + currentlydrawing = true; } @@ -11337,9 +11416,9 @@ gl.glMatrixMode(GL.GL_MODELVIEW); -gl.glEnable(gl.GL_POLYGON_SMOOTH); -gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); -gl.glEnable(gl.GL_MULTISAMPLE); +//gl.glEnable(gl.GL_POLYGON_SMOOTH); +//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); +//gl.glEnable(gl.GL_MULTISAMPLE); } else { //gl.glDisable(GL.GL_TEXTURE_2D); @@ -14521,6 +14600,8 @@ { boolean jump; + boolean mute; + // void JumpToTarget() // { // StepToTarget(true); @@ -14535,6 +14616,9 @@ // only one thread!? synchronized void StepToTarget(boolean jump) { + if (mute) + return; + tmp.set(targetLookAt); tmp.sub(manipCamera.lookAt); // june 2014 @@ -14828,6 +14912,9 @@ mouseMode |= ROTATE; } // TRANSLATE; + //System.err.println("lookAt = " + manipCamera.lookAt); + //System.err.println("location = " + manipCamera.location); + targetLookAt.set(manipCamera.lookAt); prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); @@ -15767,98 +15854,112 @@ } } + boolean keys[] = new boolean[256]; + int modifiers = 0; + public void processKeyEvent(KeyEvent e) { switch (e.getID()) { case KeyEvent.KEY_PRESSED: - if (!autorepeat) - { - //System.out.println("processKeyEvent: " + KeyEvent.getKeyText(e.getKeyCode())); - keyPressed(e.getKeyChar(), e.getModifiersEx()); - } - if (manipCamera == lightCamera) - { - switch (e.getKeyCode()) - { - case DOWN_ARROW: - lightCamera.DECAL /= 2; - repaint(); - break; - case UP_ARROW: - lightCamera.DECAL *= 2; - repaint(); - break; - case LEFT_ARROW: - lightCamera.SCALE /= 2; - repaint(); - break; - case RIGHT_ARROW: - lightCamera.SCALE *= 2; - repaint(); - break; - default: - break; - } - - System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE); - } else - { - if (true) // !autorepeat) - { - boolean reset = true; - - switch (e.getKeyCode()) - { - case DOWN_ARROW: - GoDown(e.getModifiersEx()); - repaint(); - break; - case UP_ARROW: - GoUp(e.getModifiersEx()); - repaint(); - break; - case LEFT_ARROW: - GoLeft(e.getModifiersEx()); - repaint(); - break; - case RIGHT_ARROW: - GoRight(e.getModifiersEx()); - repaint(); - break; - default: - reset = false; - break; - } - - if (reset) - { - autorepeat = true; - - targetLookAt.set(manipCamera.lookAt); - } - } - } + keys[e.getKeyCode()] = true; + modifiers = e.getModifiersEx(); + keyPressed(e.getKeyChar(), modifiers); + //Globals.theRenderer.keyPressed(e.getKeyChar()); + repaint(); break; - case KeyEvent.KEY_TYPED: - break; +// if (!autorepeat) +// { +// //System.out.println("processKeyEvent: " + KeyEvent.getKeyText(e.getKeyCode())); +// keyPressed(e.getKeyChar(), e.getModifiersEx()); +// } +// if (manipCamera == lightCamera) +// { +// switch (e.getKeyCode()) +// { +// case DOWN_ARROW: +// lightCamera.DECAL /= 2; +// repaint(); +// break; +// case UP_ARROW: +// lightCamera.DECAL *= 2; +// repaint(); +// break; +// case LEFT_ARROW: +// lightCamera.SCALE /= 2; +// repaint(); +// break; +// case RIGHT_ARROW: +// lightCamera.SCALE *= 2; +// repaint(); +// break; +// default: +// break; +// } +// +// System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE); +// } else +// { +// if (true) // !autorepeat) +// { +// boolean reset = true; +// +// switch (e.getKeyCode()) +// { +// case DOWN_ARROW: +// GoDown(e.getModifiersEx()); +// repaint(); +// break; +// case UP_ARROW: +// GoUp(e.getModifiersEx()); +// repaint(); +// break; +// case LEFT_ARROW: +// GoLeft(e.getModifiersEx()); +// repaint(); +// break; +// case RIGHT_ARROW: +// GoRight(e.getModifiersEx()); +// repaint(); +// break; +// default: +// reset = false; +// break; +// } +// +// if (reset) +// { +// autorepeat = true; +// +// targetLookAt.set(manipCamera.lookAt); +// } +// } +// } +// break; +// case KeyEvent.KEY_TYPED: +// break; case KeyEvent.KEY_RELEASED: - { - switch (e.getKeyCode()) - { - case DOWN_ARROW: - case UP_ARROW: - case LEFT_ARROW: - case RIGHT_ARROW: - MODIFIERS &= ~COMMAND; - autorepeat = false; - break; - default: - break; - } + keys[e.getKeyCode()] = false; + modifiers = e.getModifiersEx(); keyReleased(e.getKeyChar(), e.getModifiersEx()); + repaint(); break; - } +// { +// switch (e.getKeyCode()) +// { +// case DOWN_ARROW: +// case UP_ARROW: +// case LEFT_ARROW: +// case RIGHT_ARROW: +// MODIFIERS &= ~COMMAND; +// autorepeat = false; +// break; +// default: +// break; +// } +// keyReleased(e.getKeyChar(), e.getModifiersEx()); +// break; +// } default: break; } diff --git a/Composite.java b/Composite.java index 4aa0f45..c4deff4 100644 --- a/Composite.java +++ b/Composite.java @@ -877,7 +877,7 @@ } catch (Exception e) { - System.err.println("FAILED: " + this); + // System.err.println("FAILED: " + this); failedPigment = true; } diff --git a/ObjEditor.java b/ObjEditor.java index 68657fd..5d17d71 100644 --- a/ObjEditor.java +++ b/ObjEditor.java @@ -136,10 +136,19 @@ { BufferedImage image; - if (name.endsWith("jpg")) - // Much faster! - image = new sun.awt.image.codec.JPEGImageDecoderImpl(ObjEditor.class.getClassLoader().getResourceAsStream(name)).decodeAsBufferedImage(); - else +// if (name.endsWith("jpg")) +// { +// try +// { +// // Much faster! +// image = new sun.awt.image.codec.JPEGImageDecoderImpl(ObjEditor.class.getClassLoader().getResourceAsStream(name)).decodeAsBufferedImage(); +// } +// catch (Exception e) +// { +// image = javax.imageio.ImageIO.read(ObjEditor.class.getClassLoader().getResourceAsStream(name)); +// } +// } +// else image = javax.imageio.ImageIO.read(ObjEditor.class.getClassLoader().getResourceAsStream(name)); // if (image.getWidth() > 48 && image.getHeight() > 48) diff --git a/Object3D.java b/Object3D.java index b8c4bc0..05d5865 100644 --- a/Object3D.java +++ b/Object3D.java @@ -6351,7 +6351,7 @@ } catch (Exception e) { - System.err.println("FAILED: " + this); + // System.err.println("FAILED: " + this); failedPigment = true; } -- Gitblit v1.6.2