Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -110,7 +110,9 @@
110110 //private Mat4f spotlightTransform = new Mat4f();
111111 //private Mat4f spotlightInverseTransform = new Mat4f();
112112 static GLContext glcontext = null;
113
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
114116 boolean reverseUP = false;
115117 static boolean frozen = false;
116118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -173,7 +175,7 @@
173175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174176 boolean anisotropy = true;
175177 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177179
178180 boolean macromode = false;
179181
....@@ -188,15 +190,16 @@
188190
189191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190192
191
- public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192194 {
193195 try
194196 {
195
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196198 } catch (IOException e)
197199 {
198200 System.out.println("NAME = " + name);
199201 e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
200203 }
201204 }
202205
....@@ -8358,7 +8361,7 @@
83588361 // else
83598362 // if (!texname.startsWith("/"))
83608363 // texname = "/Users/nbriere/Textures/" + texname;
8361
- if (!FileExists(texname))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
83628365 {
83638366 texname = fallbackTextureName;
83648367 }
....@@ -8441,6 +8444,15 @@
84418444 new Exception().printStackTrace();
84428445 } else
84438446 {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
8454
+ } else
8455
+ {
84448456 if (textureon)
84458457 {
84468458 String cachename = texname;
....@@ -8500,6 +8512,7 @@
85008512 texturecache = new CacheTexture(texturedata,resolution);
85018513 //texture = GetTexture(tex, bump);
85028514 }
8515
+ }
85038516 }
85048517 //}
85058518 }
....@@ -8768,10 +8781,12 @@
87688781
87698782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87708783 MAXSTACK = temp[0];
8771
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87728786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87738787 MAXSTACK = temp[0];
8774
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87758790
87768791 // Use debug pipeline
87778792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8779,7 +8794,8 @@
87798794 gl = drawable.getGL(); //
87808795
87818796 GL gl3 = getGL();
8782
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87838799
87848800
87858801 //float pos[] = { 100, 100, 100, 0 };
....@@ -9220,6 +9236,8 @@
92209236
92219237 void LoadEnvy(int which)
92229238 {
9239
+ assert(false);
9240
+
92239241 String name;
92249242 String ext;
92259243
....@@ -9316,10 +9334,9 @@
93169334 double[] light2camera = new double[16];
93179335
93189336 //int newenvy = -1;
9319
- boolean envyoff = true; // false;
9320
- String skyboxname = "";
9321
- String skyboxext;
9322
- String loadedskyboxname = "";
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
93239340
93249341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
93259342 //float[] light0 = { 0,0,0 };
....@@ -10842,7 +10859,7 @@
1084210859
1084310860 if (wait)
1084410861 {
10845
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1084610863
1084710864 wait = false;
1084810865 }
....@@ -11065,10 +11082,32 @@
1106511082 //
1106611083 // newenvy = -1;
1106711084
11068
- if (!skyboxname.equals(this.loadedskyboxname))
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1106911086 {
11070
- LoadSkybox(skyboxname + "/", skyboxext, false);
11071
- loadedskyboxname = skyboxname;
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
11093
+ }
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
1107211111 }
1107311112
1107411113 ratio = ((double) getWidth()) / getHeight();
....@@ -11372,7 +11411,7 @@
1137211411
1137311412 // if (cam != lightCamera)
1137411413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11375
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1137611415 }
1137711416
1137811417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12446,7 +12485,7 @@
1244612485
1244712486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1244812487
12449
- String program0 =
12488
+ String programmin =
1245012489 // Min shader
1245112490 "!!ARBfp1.0\n" +
1245212491 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12513,7 +12552,7 @@
1251312552 "MOV result.color, temp;" +
1251412553 "END";
1251512554
12516
- String program =
12555
+ String programmax =
1251712556 "!!ARBfp1.0\n" +
1251812557
1251912558 //"OPTION ARB_fragment_program_shadow;" +
....@@ -13369,6 +13408,13 @@
1336913408 //once = true;
1337013409 }
1337113410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1337213418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1337313419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1337413420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -14618,9 +14664,9 @@
1461814664 MODIFIERS |= COMMAND;
1461914665 /**/
1462014666 if((mod&SHIFT) == SHIFT)
14621
- manipCamera.RotatePosition(0, -speed);
14622
- else
1462314667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1462414670 /**/
1462514671 if ((mod & SHIFT) == SHIFT)
1462614672 {
....@@ -14639,9 +14685,9 @@
1463914685 MODIFIERS |= COMMAND;
1464014686 /**/
1464114687 if((mod&SHIFT) == SHIFT)
14642
- manipCamera.RotatePosition(0, speed);
14643
- else
1464414688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1464514691 /**/
1464614692 if ((mod & SHIFT) == SHIFT)
1464714693 {
....@@ -15362,7 +15408,7 @@
1536215408 OCCLUSION_CULLING ^= true;
1536315409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1536415410 break;
15365
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1536615412 case '1':
1536715413 case '2':
1536815414 case '3':
....@@ -15372,7 +15418,7 @@
1537215418 case '7':
1537315419 case '8':
1537415420 case '9':
15375
- if (envyoff)
15421
+ if (true) // envyoff)
1537615422 {
1537715423 BGcolor = (key - '1')/8.f;
1537815424 }
....@@ -16084,7 +16130,7 @@
1608416130 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1608516131 break;
1608616132 case Object3D.hitScale: gr.setColor(Color.cyan);
16087
- gr.drawLine(X, Y, 0, 0);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1608816134 break;
1608916135 }
1609016136
....@@ -16570,6 +16616,8 @@
1657016616 private /*static*/ boolean firstime;
1657116617 private /*static*/ cVector newView = new cVector();
1657216618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1657316621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1657416622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1657516623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16582,22 +16630,56 @@
1658216630 {
1658316631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1658416632
16633
+ int usedsuf = 0;
16634
+
1658516635 for (int i = 0; i < suffixes.length; i++)
1658616636 {
16587
- String resourceName = basename + suffixes[i] + "." + suffix;
16588
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16589
- mipmapped,
16590
- FileUtil.getFileSuffix(resourceName));
16591
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1659216642 {
16593
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1659416647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1659516676 //System.out.println("Target = " + targets[i]);
1659616677 cubemap.updateImage(data, targets[i]);
1659716678 }
1659816679
1659916680 return cubemap;
1660016681 }
16682
+
1660116683 int bigsphere = -1;
1660216684
1660316685 float BGcolor = 0.5f;
....@@ -16606,7 +16688,9 @@
1660616688
1660716689 private void DrawSkyBox(GL gl, float ratio)
1660816690 {
16609
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1661016694 {
1661116695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1661216696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16623,14 +16707,14 @@
1662316707 gl.glLoadIdentity();
1662416708 gl.glScalef(1,ratio,1);
1662516709
16626
- colorV[0] = 2;
16627
- colorV[1] = 2;
16628
- colorV[2] = 2;
16629
- colorV[3] = 1;
16630
- gl.glDisable(gl.GL_COLOR_MATERIAL);
16631
- gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16632
-
16633
- gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
1663416718
1663516719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1663616720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
....@@ -16644,7 +16728,7 @@
1664416728 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1664516729 // causes the normals to be sent down. Thanks to Ken Dyke.
1664616730 //gl.glEnable(GL.GL_LIGHTING);
16647
- gl.glEnable(GL.GL_LIGHTING);
16731
+ gl.glDisable(GL.GL_LIGHTING);
1664816732
1664916733 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1665016734 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16663,6 +16747,7 @@
1666316747 {
1666416748 gl.glScalef(1.0f, -1.0f, 1.0f);
1666516749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1666616751 gl.glMultMatrixd(viewrot_1, 0);
1666716752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1666816753 //viewer.updateInverseRotation(gl);
....@@ -17467,10 +17552,14 @@
1746717552 gl.glFlush();
1746817553
1746917554 /**/
17470
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1747117556
17472
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1747317558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1747417563 double r = 0, g = 0, b = 0;
1747517564
1747617565 double count = 0;
....@@ -17481,7 +17570,7 @@
1748117570
1748217571 double FACTOR = 1;
1748317572
17484
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1748517574 {
1748617575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1748717576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17564,7 +17653,7 @@
1756417653
1756517654 double scale = ray.z; // 1; // cos
1756617655
17567
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1756817657
1756917658 /*
1757017659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17761,11 +17850,14 @@
1776117850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1776217851 static IntBuffer bigAAbuffer;
1776317852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17764
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1776517854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1776617855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1776717856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17768
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1776917861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1777017862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1777117863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();