From 475f8cbdbd96fdbf8f5b216ffebb31a51f25c2f9 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 29 Jul 2019 20:08:48 -0400
Subject: [PATCH] Save skybox.

---
 CameraPane.java |   79 +++++++++++++++++++++++++++++++--------
 1 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index bd26db2..28924e5 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -9316,10 +9316,9 @@
     double[] light2camera = new double[16];
     
     //int newenvy = -1;
-    boolean envyoff = true; // false;
-    String skyboxname = "";
-    String skyboxext;
-    String loadedskyboxname = "";
+    //boolean envyoff = false;
+    
+    String loadedskyboxname;
     
     cVector light0 = new cVector(0, 0, 0); // 1,3,2);
     //float[] light0 = { 0,0,0 };
@@ -11065,10 +11064,18 @@
 //
 //        newenvy = -1;
         
-        if (!skyboxname.equals(this.loadedskyboxname))
+        if (object.skyboxname != null)
         {
-            LoadSkybox(skyboxname + "/", skyboxext, false);
-            loadedskyboxname = skyboxname;
+            if (!object.skyboxname.equals(this.loadedskyboxname))
+            {
+                LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
+                loadedskyboxname = object.skyboxname;
+            }
+        }
+        else
+        {
+            cubemap = null;
+            loadedskyboxname = null;
         }
         
         ratio = ((double) getWidth()) / getHeight();
@@ -13038,7 +13045,7 @@
            // 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;" +
@@ -15362,7 +15369,7 @@
                 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':
@@ -15372,7 +15379,7 @@
             case '7':
             case '8':
             case '9':
-                if (envyoff)
+                if (true) // envyoff)
                 {
                     BGcolor = (key - '1')/8.f;
                 }
@@ -16570,6 +16577,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,
@@ -16582,22 +16591,56 @@
     {
         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;
@@ -16606,7 +16649,8 @@
     
     private void DrawSkyBox(GL gl, float ratio)
     {
-        if (envyoff || cubemap == null)
+        if (//envyoff ||
+                cubemap == null)
         {
             gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
             gl.glClear(gl.GL_COLOR_BUFFER_BIT);
@@ -16663,6 +16707,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);

--
Gitblit v1.6.2