From 0a52bd4800459cd9935f360d7ca9555b6bea2146 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Fri, 19 Jul 2019 20:56:44 -0400
Subject: [PATCH] CSG + paint mode.

---
 CameraPane.java |  244 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 156 insertions(+), 88 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index b2db6b7..52608e6 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -2065,7 +2065,7 @@
             //System.err.println("Oeil on");
             OEIL = true;
             if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
-                object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
+                object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
             //pingthread.StepToTarget(true);
         }
         
@@ -2298,10 +2298,17 @@
         HANDLES ^= true;
     }
 
+    Object3D paintFolder;
+    
     void TogglePaint()
     {
         PAINTMODE ^= true;
         paintcount = 0;
+        
+        if (PAINTMODE)
+        {
+            paintFolder = GetFolder();
+        }
     }
 
     void SwapCamera(int a, int b)
@@ -8503,7 +8510,7 @@
         return texture!=null?texture.texturedata:null;
     }
     
-    boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
+    com.sun.opengl.util.texture.Texture BindTexture(String tex, boolean bump, int resolution) throws Exception
     {
         if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
         {
@@ -8515,7 +8522,7 @@
         com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
 
         if (texture == null)
-            return false;
+            return texture;
         /**/
 
         if (textureon || tex.equals("DEFAULT_TEXTURE") || tex.equals("DEFAULT_TEXTURE_BUMP") || tex.equals("WHITE_NOISE")) // || tex.equals("IMMORTAL"))
@@ -11028,9 +11035,9 @@
 
             gl.glMatrixMode(GL.GL_MODELVIEW);
 
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
-//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);
@@ -11041,7 +11048,7 @@
         //System.out.println("BLENDING ON");
         gl.glEnable(GL.GL_BLEND);
         gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
-
+//        gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
         gl.glMatrixMode(gl.GL_PROJECTION);
         gl.glLoadIdentity();
 
@@ -11527,7 +11534,7 @@
         if ((TRACK || SHADOWTRACK) || zoomonce)
         {
             if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
-                object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
+                object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
             pingthread.StepToTarget(true); // true);
        //     zoomonce = false;
         }
@@ -13375,9 +13382,10 @@
                 "DP3 " + dest + ".z," + "normals," + "eye;" +
                 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
                 //"MOV " + dest + ".w," + "normal.z;" +
-                "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
-                "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
-                //"MOV " + dest + ".z," + "params2.w;" + 
+//            "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
+//            "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
+                
+                "MOV " + dest + ".z," + "params2.w;" + // EXACT
                 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
                 "RCP " + dest + ".w," + dest + ".w;" +
                 //"RSQ " + dest + ".w," + dest + ".w;" +
@@ -13942,7 +13950,7 @@
             
 // fev 2014???
             if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
-                object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
+                object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
             pingthread.StepToTarget(true); // true);
         }
     //    if (!LIVE)
@@ -14296,12 +14304,12 @@
     void GoDown(int mod)
     {
         MODIFIERS |= COMMAND;
-        /*
+        /**/
         if((mod&SHIFT) == SHIFT)
         manipCamera.RotatePosition(0, -speed);
         else
-        manipCamera.BackForth(0, -speed*delta, getWidth());
-         */
+        manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
+        /**/
         if ((mod & SHIFT) == SHIFT)
         {
             mouseMode = mouseMode; // VR??
@@ -14317,12 +14325,12 @@
     void GoUp(int mod)
     {
         MODIFIERS |= COMMAND;
-        /*
+        /**/
         if((mod&SHIFT) == SHIFT)
         manipCamera.RotatePosition(0, speed);
         else
-        manipCamera.BackForth(0, speed*delta, getWidth());
-         */
+        manipCamera.BackForth(0, speed*delta, 0); // getWidth());
+        /**/
         if ((mod & SHIFT) == SHIFT)
         {
             mouseMode = mouseMode;
@@ -14338,12 +14346,12 @@
     void GoLeft(int mod)
     {
         MODIFIERS |= COMMAND;
-        /*
+        /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.RotatePosition(speed, 0);
-        else
         manipCamera.Translate(speed*delta, 0, getWidth());
-         */
+        else
+        manipCamera.RotatePosition(speed, 0);
+        /**/
         if ((mod & SHIFT) == SHIFT)
         {
             mouseMode = mouseMode;
@@ -14359,12 +14367,12 @@
     void GoRight(int mod)
     {
         MODIFIERS |= COMMAND;
-        /*
+        /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.RotatePosition(-speed, 0);
-        else
         manipCamera.Translate(-speed*delta, 0, getWidth());
-         */
+        else
+        manipCamera.RotatePosition(-speed, 0);
+        /**/
         if ((mod & SHIFT) == SHIFT)
         {
             mouseMode = mouseMode;
@@ -14603,7 +14611,8 @@
         Globals.MOUSEDRAGGED = false;
         
         movingcamera = false;
-        X = Y = 0;
+        X = 0; // getBounds().width/2;
+        Y = 0; // getBounds().height/2;
         //System.out.println("mouseReleased: " + e);
         clickEnd(e.getX(), e.getY(), e.getModifiersEx());
     }
@@ -14944,7 +14953,9 @@
             case 'E' : COMPACT ^= true;
                 repaint();
                 break;
-            case 'W' : DEBUGHSB ^= true;
+            case 'W' : // Wide Window (fullscreen)
+                //DEBUGHSB ^= true;
+                ObjEditor.theFrame.ToggleFullScreen();
                 repaint();
                 break;
             case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
@@ -14970,13 +14981,7 @@
                 repaint();
                 break;
             case 'l':
-                lightMode ^= true;
-                Globals.lighttouched = true;
-                manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
-                targetLookAt.set(manipCamera.lookAt);
-                repaint();
-                break;
-            case 'L':
+            //case 'L':
                 if (lightMode)
                 {
                     lightMode = false;
@@ -15119,11 +15124,14 @@
             case '_':
                 kompactbit = 5;
                 break;
-            case '+':
-                kompactbit = 6;
-                break;
+//            case '+':
+//                kompactbit = 6;
+//                break;
             case ' ':
-                ObjEditor.theFrame.ToggleFullScreen();
+                lightMode ^= true;
+                Globals.lighttouched = true;
+                manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
+                targetLookAt.set(manipCamera.lookAt);
                 repaint();
                 break;
             //case '`' :
@@ -15170,8 +15178,9 @@
             case DELETE:
                 ClearSelection();
                 break;
-                /*
             case '+':
+                
+                /*
                 //fontsize += 1;
                 bbzoom *= 2;
                 repaint();
@@ -15188,17 +15197,17 @@
             case '=':
                 IncDepth();
                 //fontsize += 1;
-                object.editWindow.refreshContents(true);
+                object.GetWindow().refreshContents(true);
                 maskbit = 6;
                 break;
             case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
                 DecDepth();
                 maskbit = 5;
                 //if(fontsize > 1) fontsize -= 1;
-                if (object.editWindow == null)
-                    new Exception().printStackTrace();
-                else
-                    object.editWindow.refreshContents(true);
+//                if (object.editWindow == null)
+//                    new Exception().printStackTrace();
+//                else
+                    object.GetWindow().refreshContents(true);
                 break;
             case '{':
                 manipCamera.shaper_fovy /= 1.1;
@@ -15422,7 +15431,7 @@
         }
          */
 
-        object.editWindow.EditSelection(false);
+        object.GetWindow().EditSelection(false);
     }
 
     void SelectParent()
@@ -15439,10 +15448,10 @@
             {
                 //selectees.remove(i);
                 System.out.println("select parent of " + elem);
-                group.editWindow.Select(elem.parent.GetTreePath(), first, true);
+                group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
             } else
             {
-                group.editWindow.Select(elem.GetTreePath(), first, true);
+                group.GetWindow().Select(elem.GetTreePath(), first, true);
             }
 
             first = false;
@@ -15484,12 +15493,12 @@
                 for (int j = 0; j < group.children.size(); j++)
                 {
                     elem = (Object3D) group.children.elementAt(j);
-                    object.editWindow.Select(elem.GetTreePath(), first, true);
+                    object.GetWindow().Select(elem.GetTreePath(), first, true);
                     first = false;
                 }
             } else
             {
-                object.editWindow.Select(elem.GetTreePath(), first, true);
+                object.GetWindow().Select(elem.GetTreePath(), first, true);
             }
 
             first = false;
@@ -15500,21 +15509,21 @@
     {
         //Composite group = (Composite) object;
         Object3D group = object;
-        group.editWindow.loadClipboard(true); // ClearSelection(false);
+        group.GetWindow().loadClipboard(true); // ClearSelection(false);
     }
 
     void ResetTransform(int mask)
     {
         //Composite group = (Composite) object;
         Object3D group = object;
-        group.editWindow.ResetTransform(mask);
+        group.GetWindow().ResetTransform(mask);
     }
 
     void FlipTransform()
     {
         //Composite group = (Composite) object;
         Object3D group = object;
-        group.editWindow.FlipTransform();
+        group.GetWindow().FlipTransform();
 //        group.editWindow.ReduceMesh(true);
     }
 
@@ -15522,7 +15531,7 @@
     {
         //Composite group = (Composite) object;
         Object3D group = object;
-        group.editWindow.PrintMemory();
+        group.GetWindow().PrintMemory();
 //        group.editWindow.ReduceMesh(true);
     }
     
@@ -15530,7 +15539,7 @@
     {
         //Composite group = (Composite) object;
         Object3D group = object;
-        group.editWindow.ResetCentroid();
+        group.GetWindow().ResetCentroid();
     }
 
     void IncDepth()
@@ -15706,6 +15715,7 @@
                     info.bounds.y += (height - desired) / 2;
                 }
             }
+            
             info.g = gr;
             info.camera = renderCamera;
             /* 
@@ -15715,23 +15725,44 @@
              */
             if (!isRenderer)
             {
-                object.drawEditHandles(info, 0);
-                
-                if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
+                Grafreed.Assert(object != null);
+                Grafreed.Assert(object.selection != null);
+                if (object.selection.Size() > 0)
                 {
-                    switch (object.selection.get(0).hitSomething)
+                    int hitSomething = object.selection.get(0).hitSomething;
+
+                    info.DX = 0;
+                    info.DY = 0;
+                    info.W = 1;
+                    if (hitSomething == Object3D.hitCenter)
                     {
-                        case Object3D.hitCenter: gr.setColor(Color.pink);
-                            gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
-                            break;
-                        case Object3D.hitRotate: gr.setColor(Color.yellow);
-                            gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
-                        break;
-                        case Object3D.hitScale: gr.setColor(Color.cyan);
-                            gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
-                        break;
+                        info.DX = X;
+                        if (X != 0)
+                            info.DX -= info.bounds.width/2;
+
+                        info.DY = Y;
+                        if (Y != 0)
+                            info.DY -= info.bounds.height/2;
                     }
-                    
+
+                    object.drawEditHandles(info, 0);
+
+                    if (drag && (X != 0 || Y != 0))
+                    {
+                        switch (hitSomething)
+                        {
+                            case Object3D.hitCenter: gr.setColor(Color.pink);
+                                gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
+                                break;
+                            case Object3D.hitRotate: gr.setColor(Color.yellow);
+                                gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
+                            break;
+                            case Object3D.hitScale: gr.setColor(Color.cyan);
+                                gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
+                            break;
+                        }
+
+                    }
                 }
             }
         }
@@ -16529,6 +16560,14 @@
         }
     }
     
+    private Object3D GetFolder()
+    {
+        Object3D folder = object.GetWindow().copy;
+        if (object.GetWindow().copy.selection.Size() > 0)
+            folder = object.GetWindow().copy.selection.elementAt(0);
+        return folder;
+    }
+
     class SelectBuffer implements GLEventListener
     {
 
@@ -16608,6 +16647,17 @@
 
             //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
 
+                if (PAINTMODE)
+                {
+                    if (object.GetWindow().copy.selection.Size() > 0)
+                    {
+                        Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
+
+                        // Make what you paint not selectable.
+                        paintobj.ResetSelectable();
+                    }
+                }
+                
             //int tmp = selection_view;
             //selection_view = -1;
             int temp = DrawMode();
@@ -16619,6 +16669,17 @@
             //    temp = DEFAULT; // patch for selection debug
             Globals.drawMode = temp; // WARNING
 
+                if (PAINTMODE)
+                {
+                    if (object.GetWindow().copy.selection.Size() > 0)
+                    {
+                        Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
+
+                        // Revert.
+                        paintobj.RestoreSelectable();
+                    }
+                }
+                
             //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
 
             // trying different ways of getting the depth info over
@@ -16722,29 +16783,31 @@
                 }
                 
                 if (!movingcamera && !PAINTMODE)
-                    object.editWindow.ScreenFitPoint(); // fev 2014
+                    object.GetWindow().ScreenFitPoint(); // fev 2014
                 
-                if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
+                if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
                 {
-                    Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
+                    //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
                     
-                    Object3D group = new Object3D("inst" + paintcount++);
+                    if (object.GetWindow().copy.selection.Size() > 0)
+                    {
+                        Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
                     
-                    group.CreateMaterial(); // use a void leaf to select instances
-                    
-                    group.add(paintobj); // link
-                    
-                    object.editWindow.SnapObject(group);
-                    
-                    Object3D folder = object.editWindow.copy;
-                    
-                    if (object.editWindow.copy.selection.Size() > 0)
-                        folder = object.editWindow.copy.selection.elementAt(0);
-                    
-                    folder.add(group);
-                    
-                    object.editWindow.ResetModel();
-                    object.editWindow.refreshContents();
+                        Object3D inst = new Object3D("inst" + paintcount++);
+
+                        inst.CreateMaterial(); // use a void leaf to select instances
+
+                        inst.add(paintobj); // link
+
+                        object.GetWindow().SnapObject(inst);
+
+                        Object3D folder = paintFolder; // GetFolder();
+
+                        folder.add(inst);
+
+                        object.GetWindow().ResetModel();
+                        object.GetWindow().refreshContents();
+                    }
                 }
                 else
                     paintcount = 0;
@@ -16783,6 +16846,11 @@
                 //System.out.println("objects[color] = " + objects[color]);
                 //objects[color].Select();
                 indexcount = 0;
+                    ObjEditor window = object.GetWindow();
+                    if (window != null && deselect)
+                    {
+                        window.Select(null, deselect, true);
+                    }
                 object.Select(color, deselect);
             }
 

--
Gitblit v1.6.2