From b1d79b74514041a059b454a9f6fc3970773c0cb8 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 12 Aug 2019 18:19:30 -0400
Subject: [PATCH] Compact toolbar.

---
 CameraPane.java |  432 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 318 insertions(+), 114 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index ffbe72c..e816ebc 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -187,6 +187,18 @@
     }
     
     private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
+
+    public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
+    {
+        try
+        {
+            cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
+        } catch (IOException e)
+        {
+            System.out.println("NAME = " + name);
+            e.printStackTrace(); // throw new RuntimeException(e);
+        }
+    }
     
     void SetAsGLRenderer(boolean b)
     {
@@ -206,7 +218,8 @@
 
         SetCamera(cam);
 
-        SetLight(new Camera(new cVector(10, 10, -20)));
+        // Warning: not used.
+        SetLight(new Camera(new cVector(15, 10, -20)));
 
         object = o;
 
@@ -1484,6 +1497,8 @@
         gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
     }
     
+    float[] colorV = new float[4];
+        
     void SetColor(Object3D obj, Vertex p0)
     {
         CameraPane display = this;
@@ -1551,8 +1566,6 @@
         {
             return;
         }
-        
-        float[] colorV = new float[3];
         
         if (false) // marked)
         {
@@ -8345,7 +8358,7 @@
 //            else
 //                if (!texname.startsWith("/"))
 //                    texname = "/Users/nbriere/Textures/" + texname;
-            if (!FileExists(texname))
+            if (!FileExists(texname) && !texname.startsWith("@"))
             {
                     texname = fallbackTextureName;
             }
@@ -8428,6 +8441,15 @@
                                 new Exception().printStackTrace();
                         } else
                         {
+                        if (texname.startsWith("@"))
+                        {
+                //            texturecache = textures.get(texname); // suspicious
+                            if (texturecache == null)
+                                texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
+                            else
+                                new Exception().printStackTrace();
+                        } else
+                        {
                             if (textureon)
                             {
                                 String cachename = texname;
@@ -8487,6 +8509,7 @@
                                     texturecache = new CacheTexture(texturedata,resolution);
         //texture = GetTexture(tex, bump);
                             }
+                        }
                         }
                     //}
                 }
@@ -8931,7 +8954,7 @@
 
         if (cubemap == null)
         {
-            LoadEnvy(5);
+            //LoadEnvy(1);
         }
 
         //cubemap.enable();
@@ -9218,37 +9241,58 @@
                 cubemap = null;
                 return;
             case 1:
-                name = "cubemaps/box_";
-                ext = "png";
+                name = "cubemaps/rgb/";
+                ext = "jpg";
                 reverseUP = false;
                 break;
             case 2:
-                name = "cubemaps/uffizi_";
-                ext = "png";
-                break; // reverseUP = true; break;
+                name = "cubemaps/uffizi/";
+                ext = "jpg";
+                reverseUP = false;
+                break;
             case 3:
-                name = "cubemaps/CloudyHills_";
-                ext = "tga";
+                name = "cubemaps/CloudyHills/";
+                ext = "jpg";
                 reverseUP = false;
                 break;
             case 4:
-                name = "cubemaps/cornell_";
+                name = "cubemaps/cornell/";
                 ext = "png";
                 reverseUP = false;
                 break;
+            case 5:
+                name = "cubemaps/skycube/";
+                ext = "jpg";
+                reverseUP = false;
+                break;
+            case 6:
+                name = "cubemaps/SaintLazarusChurch3/";
+                ext = "jpg";
+                reverseUP = false;
+                break;
+            case 7:
+                name = "cubemaps/Sodermalmsallen/";
+                ext = "jpg";
+                reverseUP = false;
+                break;
+            case 8:
+                name = "cubemaps/Sodermalmsallen2/";
+                ext = "jpg";
+                reverseUP = false;
+                break;
+            case 9:
+                name = "cubemaps/UnionSquare/";
+                ext = "jpg";
+                reverseUP = false;
+                break;
             default:
-                name = "cubemaps/rgb_";
-                ext = "png"; /*mipmap = true;*/ reverseUP = false;
+                name = "cubemaps/box/";
+                ext = "png"; /*mipmap = true;*/
+                reverseUP = false;
                 break;
         }
-
-        try
-        {
-            cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
-        } catch (IOException e)
-        {
-            throw new RuntimeException(e);
-        }
+        
+        LoadSkybox(name, ext, mipmap);
     }
 
     public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
@@ -9280,8 +9324,12 @@
     static double[] model = new double[16];
     double[] camera2light = new double[16];
     double[] light2camera = new double[16];
-    int newenvy = -1;
-    boolean envyoff = true; // false;
+    
+    //int newenvy = -1;
+    //boolean envyoff = false;
+    
+    String loadedskyboxname;
+    
     cVector light0 = new cVector(0, 0, 0); // 1,3,2);
     //float[] light0 = { 0,0,0 };
     cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
@@ -9699,7 +9747,7 @@
         
         if (renderCamera != lightCamera)
         //for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
+            LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
         
 //            LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
             
@@ -9715,7 +9763,7 @@
             
         if (renderCamera != lightCamera)
         //for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
+            LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
 
 //            LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
             
@@ -9761,10 +9809,12 @@
                 rati = 1 / rati;
                 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
             }
-            assert (newenvy == -1);
+            
+            //assert (newenvy == -1);
+            
             gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
             gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
-            DrawSkyBox(gl);
+            DrawSkyBox(gl, (float)rati);
             gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
             gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
             accPerspective(gl, renderCamera.shaper_fovy / ratio,
@@ -10801,7 +10851,7 @@
 
         if (wait)
         {
-            Sleep(500);
+            Sleep(200); // blocks everything
 
             wait = false;
         }
@@ -10916,7 +10966,7 @@
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
             //for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
+                LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
             
             for (int j = 0; j < 4; j++)
             {
@@ -10931,7 +10981,7 @@
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
             //for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
+                LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
         
             //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
             
@@ -11017,13 +11067,27 @@
             gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
         }
 
-        if (newenvy > -1)
+//        if (newenvy > -1)
+//        {
+//            LoadEnvy(newenvy);
+//        }
+//
+//        newenvy = -1;
+        
+        if (object.skyboxname != null)
         {
-            LoadEnvy(newenvy);
+            if (!object.skyboxname.equals(this.loadedskyboxname))
+            {
+                LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
+                loadedskyboxname = object.skyboxname;
+            }
         }
-
-        newenvy = -1;
-
+        else
+        {
+            cubemap = null;
+            loadedskyboxname = null;
+        }
+        
         ratio = ((double) getWidth()) / getHeight();
         //System.out.println("ratio = " + ratio);
 
@@ -11039,7 +11103,7 @@
 
             if (!IsFrozen() && !ambientOcclusion)
             {
-                DrawSkyBox(gl);
+                DrawSkyBox(gl, (float)ratio);
             }
 
             //if (selection_view == -1)
@@ -11325,7 +11389,7 @@
 
 //            if (cam != lightCamera)
             //for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
+                LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
         }
         
         LA.xformDir(lightposition, cam.toScreen, lightposition);
@@ -12399,8 +12463,76 @@
 
         //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
 
-        String program =
+        String programmin =
+                // Min shader
                 "!!ARBfp1.0\n" +
+                "PARAM zero123      = { 0.0, 1.0, 2, 1.25 };" +
+                "PARAM pow2      = { 0.5, 0.25, 0.125, 0.0 };" +
+                "PARAM one      = { 1.0, 1.0, 1.0, 1.0 };" +
+                "PARAM eps      = { 0.001, 0.001, 0.001, 1.0 };" +
+                "PARAM infinity  = { 100000000, 100000000, 100000000, 1.0 };" +
+                "PARAM light2cam0   = program.env[10];" +
+                "PARAM light2cam1   = program.env[11];" +
+                "PARAM light2cam2   = program.env[12];" +
+                "TEMP temp;" +
+                "TEMP light;" +
+                "TEMP ndotl;" +
+                "TEMP normal;" +
+                "TEMP depth;" +
+                "TEMP eye;" +
+                "TEMP pos;" +
+                
+                "MAD normal, fragment.color, zero123.z, -zero123.y;" +
+                Normalize("normal") +
+                "MOV light, state.light[0].position;" +
+                "DP3 ndotl.x, light, normal;" +
+
+                // shadow
+                "MOV pos, fragment.texcoord[1];" +
+                "MOV temp, pos;" +
+                ShadowTextureFetch("depth", "temp", "1") +
+                //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
+                "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
+
+                // No shadow when out of frustum
+                //"SGE temp.y, depth.z, zero123.y;" +
+                //"LRP temp.x, temp.y, zero123.y, temp.x;" +
+                
+                "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
+                
+                // Backlit
+                "MOV pos.w, zero123.y;" +
+                "DP4 eye.x, pos, light2cam0;" +
+                "DP4 eye.y, pos, light2cam1;" +
+                "DP4 eye.z, pos, light2cam2;" +
+                Normalize("eye") +
+                
+                "DP3 ndotl.y, -eye, normal;" +
+                //"MUL ndotl.y, ndotl.y, pow2.x;" +
+                "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
+                "SUB ndotl.y, zero123.y, ndotl.y;" +
+                //"SUB ndotl.y, zero123.y, ndotl.y;" +
+                //"MUL ndotl.y, ndotl.y, pow2.z;" +
+                
+                //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
+                //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
+                
+                // Pigment
+                "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
+                "LRP temp, zero123.w, temp, one;" + // texture proportion
+                "MUL temp, temp, ndotl.x;" +
+                
+                "MUL temp, temp, zero123.z;" +
+                
+                //"MUL temp, temp, ndotl.y;" +
+                
+                "MOV temp.w, zero123.y;" + // reset alpha
+                "MOV result.color, temp;" +
+                "END";
+        
+        String programmax =
+                "!!ARBfp1.0\n" +
+                
                 //"OPTION ARB_fragment_program_shadow;" +
                 "PARAM light2cam0   = program.env[10];" +
                 "PARAM light2cam1   = program.env[11];" +
@@ -12515,8 +12647,7 @@
                 "TEMP shininess;" +
                 "\n" +
                 "MOV texSamp, one;" +
-                //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
-
+                
                 "MOV mapgrid.x, one2048th.x;" +
                 "MOV temp, fragment.texcoord[1];" +
                 /*
@@ -12537,20 +12668,20 @@
                 "MUL temp, floor, mapgrid.x;" +
                 //"TEX depth0, temp, texture[1], 2D;" +
                 (((mode & FP_SOFTSHADOW) == 0) ? "" :
-                TextureFetch("depth0", "temp", "1") +
+                ShadowTextureFetch("depth0", "temp", "1") +
                 "") +
                 "ADD temp.x, temp.x, mapgrid.x;" +
                 //"TEX depth1, temp, texture[1], 2D;" +
                 (((mode & FP_SOFTSHADOW) == 0) ? "" :
-                TextureFetch("depth1", "temp", "1") +
+                ShadowTextureFetch("depth1", "temp", "1") +
                 "") +
                 "ADD temp.y, temp.y, mapgrid.x;" +
                 //"TEX depth2, temp, texture[1], 2D;" +
-                TextureFetch("depth2", "temp", "1") +
+                ShadowTextureFetch("depth2", "temp", "1") +
                 "SUB temp.x, temp.x, mapgrid.x;" +
                 //"TEX depth3, temp, texture[1], 2D;" +
                 (((mode & FP_SOFTSHADOW) == 0) ? "" :
-                TextureFetch("depth3", "temp", "1") +
+                ShadowTextureFetch("depth3", "temp", "1") +
                 "") +
                 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
                 //"MOV params, material;" +
@@ -12921,10 +13052,10 @@
                 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
                 "") +
 
-           // display shadow only (bump == 0)
+           // display shadow only (fakedepth == 0)
          "SUB temp.x, half.x, shadow.x;" +
          "MOV temp.y, -params5.z;" + // params6.x;" +
-         "SLT temp.z, temp.y, -one2048th.x;" +
+         "SLT temp.z, temp.y, -c256i.x;" +
          "SUB temp.y, one.x, temp.z;" +
          "MUL temp.x, temp.x, temp.y;" +
          "KIL temp.x;" +
@@ -13255,6 +13386,13 @@
             //once = true;
         }
 
+        String program = programmax;
+        
+        if (Globals.MINSHADER)
+        {
+            program = programmin;
+        }
+        
         System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
         System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
         loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
@@ -13348,25 +13486,26 @@
         return out;
     }
 
-    String TextureFetch(String dest, String src, String unit)
+    // Also does frustum culling
+    String ShadowTextureFetch(String dest, String src, String unit)
     {
         return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
                 "SGE " + src + ".w, " + src + ".x, eps.x;" +
                 "SGE " + src + ".z, " + src + ".y, eps.x;" +
+                "SLT " + dest + ".x, " + src + ".x, one.x;" +
+                "SLT " + dest + ".y, " + src + ".y, one.x;" +
                 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
-                "SLT " + src + ".z, " + src + ".x, one.x;" +
-                "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
-                "SLT " + src + ".z, " + src + ".y, one.x;" +
-                "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
+                "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
+                "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
                 //"SWZ buffer, temp, w,w,w,w;";
-                "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
+                //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
                 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
                 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
                 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
-                "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
+                //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
 
-    //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
-    //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
+    //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
+    "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
     }
 
     String Shadow(String depth, String shadow)
@@ -13413,7 +13552,7 @@
                 "SLT temp.x, temp.x, zero.x;" + // shadoweps
                 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
 
-                // No shadow when out of frustrum
+                // No shadow when out of frustum
                 "SGE temp.x, " + depth + ".z, one.z;" +
                 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
                 "";
@@ -14211,14 +14350,15 @@
             drag = false;
             //System.out.println("Mouse DOWN");
             editObj = false;
-            ClickInfo info = new ClickInfo();
-            info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
-            info.pane = this;
-            info.camera = renderCamera;
-            info.x = x;
-            info.y = y;
-            info.modifiers = modifiersex;
-            editObj = object.doEditClick(info, 0);
+            //ClickInfo info = new ClickInfo();
+            object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
+            object.clickInfo.pane = this;
+            object.clickInfo.camera = renderCamera;
+            object.clickInfo.x = x;
+            object.clickInfo.y = y;
+            object.clickInfo.modifiers = modifiersex;
+            editObj = object.doEditClick(//info,
+                    0);
             if (!editObj)
             {
                 hasMarquee = true;
@@ -14502,9 +14642,9 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.RotatePosition(0, -speed);
-        else
         manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
+        else
+        manipCamera.RotatePosition(0, -speed);
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14523,9 +14663,9 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.RotatePosition(0, speed);
-        else
         manipCamera.BackForth(0, speed*delta, 0); // getWidth());
+        else
+        manipCamera.RotatePosition(0, speed);
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14618,15 +14758,16 @@
             if (editObj)
             {
                 drag = true;
-                ClickInfo info = new ClickInfo();
-                info.bounds.setBounds(0, 0,
+                //ClickInfo info = new ClickInfo();
+                object.clickInfo.bounds.setBounds(0, 0,
                         (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
-                info.pane = this;
-                info.camera = renderCamera;
-                info.x = x;
-                info.y = y;
-                object.GetWindow().copy
-                        .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
+                object.clickInfo.pane = this;
+                object.clickInfo.camera = renderCamera;
+                object.clickInfo.x = x;
+                object.clickInfo.y = y;
+                object //.GetWindow().copy
+                        .doEditDrag(//info,
+                                (modifiers & MouseEvent.BUTTON3_MASK) != 0);
             } else
             {
                 if (x < startX)
@@ -14775,24 +14916,27 @@
         }
     }
 
+//        ClickInfo clickInfo = new ClickInfo();
+        
     public void mouseMoved(MouseEvent e)
     {
         //System.out.println("mouseMoved: " + e);
         if (isRenderer)
             return;
         
-        ClickInfo ci = new ClickInfo();
-        ci.x = e.getX();
-        ci.y = e.getY();
-        ci.modifiers = e.getModifiersEx();
-        ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
-        ci.pane = this;
-        ci.camera = renderCamera;
+        // Mouse cursor feedback
+        object.clickInfo.x = e.getX();
+        object.clickInfo.y = e.getY();
+        object.clickInfo.modifiers = e.getModifiersEx();
+        object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
+        object.clickInfo.pane = this;
+        object.clickInfo.camera = renderCamera;
         if (!isRenderer)
         {
             //ObjEditor editWindow = object.editWindow;
             //Object3D copy = editWindow.copy;
-            if (object.doEditClick(ci, 0))
+            if (object.doEditClick(//clickInfo,
+                                0))
             {
                 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
             } else
@@ -15242,20 +15386,24 @@
                 OCCLUSION_CULLING ^= true;
                 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
                 break;
-            case '0': envyoff ^= true; repaint(); break;
+            //case '0': envyoff ^= true; repaint(); break;
             case '1':
             case '2':
             case '3':
             case '4':
             case '5':
-                newenvy = Character.getNumericValue(key);
-                repaint();
-                break;
             case '6':
             case '7':
             case '8':
             case '9':
-                BGcolor = (key - '6')/3.f;
+                if (true) // envyoff)
+                {
+                    BGcolor = (key - '1')/8.f;
+                }
+                else
+                {
+                    //newenvy = Character.getNumericValue(key);
+                }
                 repaint();
                 break;
             case '!':
@@ -15818,8 +15966,6 @@
 
         int width = getBounds().width;
         int height = getBounds().height;
-        ClickInfo info = new ClickInfo();
-        info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
         //Image img = CreateImage(width, height);
         //System.out.println("width = " + width + "; height = " + height + "\n");
         
@@ -15896,31 +16042,37 @@
         }
         if (object != null && !hasMarquee)
         {
+            if (object.clickInfo == null)
+                object.clickInfo = new ClickInfo();
+            ClickInfo info = object.clickInfo;
+            //ClickInfo info = new ClickInfo();
+            info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
+        
             if (isRenderer)
             {
-                info.flags++;
+                object.clickInfo.flags++;
                 double frameAspect = (double) width / (double) height;
                 if (frameAspect > renderCamera.aspect)
                 {
                     int desired = (int) ((double) height * renderCamera.aspect);
-                    info.bounds.width -= width - desired;
-                    info.bounds.x += (width - desired) / 2;
+                    object.clickInfo.bounds.width -= width - desired;
+                    object.clickInfo.bounds.x += (width - desired) / 2;
                 } else
                 {
                     int desired = (int) ((double) width / renderCamera.aspect);
-                    info.bounds.height -= height - desired;
-                    info.bounds.y += (height - desired) / 2;
+                    object.clickInfo.bounds.height -= height - desired;
+                    object.clickInfo.bounds.y += (height - desired) / 2;
                 }
             }
             
-            info.g = gr;
-            info.camera = renderCamera;
+            object.clickInfo.g = gr;
+            object.clickInfo.camera = renderCamera;
             /* 
             // Memory intensive (brep.verticescopy)
             if (!(object instanceof Composite))
             object.draw(info, 0, false); // SLOW : 
              */
-            if (!isRenderer)
+            if (!isRenderer) // && drag)
             {
                 Grafreed.Assert(object != null);
                 Grafreed.Assert(object.selection != null);
@@ -15928,9 +16080,9 @@
                 {
                     int hitSomething = object.selection.get(0).hitSomething;
 
-                    info.DX = 0;
-                    info.DY = 0;
-                    info.W = 1;
+                    object.clickInfo.DX = 0;
+                    object.clickInfo.DY = 0;
+                    object.clickInfo.W = 1;
                     if (hitSomething == Object3D.hitCenter)
                     {
                         info.DX = X;
@@ -15942,7 +16094,8 @@
                             info.DY -= info.bounds.height/2;
                     }
 
-                    object.drawEditHandles(info, 0);
+                    object.drawEditHandles(//info,
+                                            0);
 
                     if (drag && (X != 0 || Y != 0))
                     {
@@ -16441,6 +16594,8 @@
     private /*static*/ boolean firstime;
     private /*static*/ cVector newView = new cVector();
     private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
+    private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
+    private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
     private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
                                              GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
                                              GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
@@ -16453,29 +16608,67 @@
     {
         com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
 
+        int usedsuf = 0;
+        
         for (int i = 0; i < suffixes.length; i++)
         {
-            String resourceName = basename + suffixes[i] + "." + suffix;
-            TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
-                    mipmapped,
-                    FileUtil.getFileSuffix(resourceName));
-            if (data == null)
+            String[] suffixe = suffixes;
+            String[] fallback = suffixes2;
+            String[] fallfallback = suffixes3;
+            
+            for (int c=usedsuf; --c>=0;)
             {
-                throw new IOException("Unable to load texture " + resourceName);
+//                String[] temp = suffixe;
+//                suffixe = fallback;
+//                fallback = fallfallback;
+//                fallfallback = temp;
             }
+            
+            String resourceName = basename + suffixe[i] + "." + suffix;
+            TextureData data;
+            
+            try
+            {
+                data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                        mipmapped,
+                        FileUtil.getFileSuffix(resourceName));
+            }
+            catch (Exception e)
+            {
+                try
+                {
+                    resourceName = basename + fallback[i] + "." + suffix;
+                    data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                            mipmapped,
+                            FileUtil.getFileSuffix(resourceName));
+                }
+                catch (Exception e2)
+                {
+                    resourceName = basename + fallfallback[i] + "." + suffix;
+                    data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                            mipmapped,
+                            FileUtil.getFileSuffix(resourceName));
+                }
+            }
+            
             //System.out.println("Target = " + targets[i]);
             cubemap.updateImage(data, targets[i]);
         }
 
         return cubemap;
     }
+    
     int bigsphere = -1;
 
     float BGcolor = 0.5f;
     
-    private void DrawSkyBox(GL gl)
+    float ambientLight[] = {1f, 1f, 1f, 1.0f};
+    
+    private void DrawSkyBox(GL gl, float ratio)
     {
-        if (envyoff || cubemap == null)
+        if (//envyoff ||
+            WIREFRAME ||
+                cubemap == null)
         {
             gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
             gl.glClear(gl.GL_COLOR_BUFFER_BIT);
@@ -16490,7 +16683,17 @@
         // Compensates for ExaminerViewer's modification of modelview matrix
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glLoadIdentity();
+        gl.glScalef(1,ratio,1);
 
+//        colorV[0] = 2;
+//        colorV[1] = 2;
+//        colorV[2] = 2;
+//        colorV[3] = 1;
+//        gl.glDisable(gl.GL_COLOR_MATERIAL);
+//        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
+//        
+//        gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
+        
         //gl.glActiveTexture(GL.GL_TEXTURE1);
         //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
 
@@ -16522,6 +16725,7 @@
         {
             gl.glScalef(1.0f, -1.0f, 1.0f);
         }
+        gl.glScalef(-1.0f, 1.0f, 1.0f);
         gl.glMultMatrixd(viewrot_1, 0);
         gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance());  // 0.5f);
         //viewer.updateInverseRotation(gl);
@@ -16780,7 +16984,7 @@
             //new Exception().printStackTrace();
             System.out.println("select buffer init");
             // Use debug pipeline
-            drawable.setGL(new DebugGL(drawable.getGL()));
+            //drawable.setGL(new DebugGL(drawable.getGL()));
 
             GL gl = drawable.getGL();
 

--
Gitblit v1.6.2