Normand Briere
2019-08-16 83d0c2fa0bd2e96448f776144e1a89cdb1bb6998
CameraPane.java
....@@ -110,7 +110,11 @@
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;
116
+ boolean transformMode;
117
+
114118 boolean reverseUP = false;
115119 static boolean frozen = false;
116120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -173,7 +177,7 @@
173177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174178 boolean anisotropy = true;
175179 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177181
178182 boolean macromode = false;
179183
....@@ -188,15 +192,16 @@
188192
189193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190194
191
- public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192196 {
193197 try
194198 {
195
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196200 } catch (IOException e)
197201 {
198202 System.out.println("NAME = " + name);
199203 e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
200205 }
201206 }
202207
....@@ -2512,7 +2517,7 @@
25122517 com.sun.opengl.util.texture.TextureIO.newTextureData(
25132518 getClass().getClassLoader().getResourceAsStream(name),
25142519 true,
2515
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25162521 } catch (java.io.IOException e)
25172522 {
25182523 throw new javax.media.opengl.GLException(e);
....@@ -8358,7 +8363,7 @@
83588363 // else
83598364 // if (!texname.startsWith("/"))
83608365 // texname = "/Users/nbriere/Textures/" + texname;
8361
- if (!FileExists(texname))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
83628367 {
83638368 texname = fallbackTextureName;
83648369 }
....@@ -8441,6 +8446,15 @@
84418446 new Exception().printStackTrace();
84428447 } else
84438448 {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
8456
+ } else
8457
+ {
84448458 if (textureon)
84458459 {
84468460 String cachename = texname;
....@@ -8500,6 +8514,7 @@
85008514 texturecache = new CacheTexture(texturedata,resolution);
85018515 //texture = GetTexture(tex, bump);
85028516 }
8517
+ }
85038518 }
85048519 //}
85058520 }
....@@ -8768,10 +8783,12 @@
87688783
87698784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87708785 MAXSTACK = temp[0];
8771
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87728788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87738789 MAXSTACK = temp[0];
8774
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87758792
87768793 // Use debug pipeline
87778794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8779,7 +8796,8 @@
87798796 gl = drawable.getGL(); //
87808797
87818798 GL gl3 = getGL();
8782
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87838801
87848802
87858803 //float pos[] = { 100, 100, 100, 0 };
....@@ -9220,6 +9238,8 @@
92209238
92219239 void LoadEnvy(int which)
92229240 {
9241
+ assert(false);
9242
+
92239243 String name;
92249244 String ext;
92259245
....@@ -11064,18 +11084,34 @@
1106411084 //
1106511085 // newenvy = -1;
1106611086
11067
- if (object.skyboxname != null)
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1106811088 {
11069
- if (!object.skyboxname.equals(this.loadedskyboxname))
11089
+ if (cubemaprgb == null)
1107011090 {
11071
- LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
- loadedskyboxname = object.skyboxname;
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
1107311092 }
11093
+
11094
+ cubemap = cubemaprgb;
1107411095 }
1107511096 else
1107611097 {
11077
- cubemap = null;
11078
- loadedskyboxname = null;
11098
+ if (object.skyboxname != null)
11099
+ {
11100
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11101
+ {
11102
+ if (cubemap != null && cubemap != cubemaprgb)
11103
+ cubemap.dispose();
11104
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11105
+ loadedskyboxname = object.skyboxname;
11106
+ }
11107
+ }
11108
+ else
11109
+ {
11110
+ cubemapcustom = null;
11111
+ loadedskyboxname = null;
11112
+ }
11113
+
11114
+ cubemap = cubemapcustom;
1107911115 }
1108011116
1108111117 ratio = ((double) getWidth()) / getHeight();
....@@ -13383,8 +13419,12 @@
1338313419 program = programmin;
1338413420 }
1338513421
13386
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13387
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13422
+ if (Globals.DEBUG)
13423
+ {
13424
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13425
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13426
+ }
13427
+
1338813428 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1338913429
1339013430 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13431,7 +13471,8 @@
1343113471 "\n" +
1343213472 "END\n";
1343313473
13434
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13474
+ if (Globals.DEBUG)
13475
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1343513476 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1343613477
1343713478 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -14630,11 +14671,17 @@
1463014671 void GoDown(int mod)
1463114672 {
1463214673 MODIFIERS |= COMMAND;
14674
+ boolean isVR = (mouseMode&VR)!=0;
1463314675 /**/
1463414676 if((mod&SHIFT) == SHIFT)
14635
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14677
+ {
14678
+ if (isVR)
14679
+ manipCamera.RotateInterest(0, -speed);
14680
+ else
14681
+ manipCamera.RotatePosition(0, -speed);
14682
+ }
1463614683 else
14637
- manipCamera.RotatePosition(0, -speed);
14684
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1463814685 /**/
1463914686 if ((mod & SHIFT) == SHIFT)
1464014687 {
....@@ -14644,6 +14691,8 @@
1464414691 mouseMode |= BACKFORTH;
1464514692 }
1464614693
14694
+ targetLookAt.set(manipCamera.lookAt);
14695
+
1464714696 //prevX = X = anchorX;
1464814697 prevY = Y = anchorY - (int) (renderCamera.Distance());
1464914698 }
....@@ -14652,10 +14701,17 @@
1465214701 {
1465314702 MODIFIERS |= COMMAND;
1465414703 /**/
14704
+ boolean isVR = (mouseMode&VR)!=0;
14705
+
1465514706 if((mod&SHIFT) == SHIFT)
14656
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14707
+ {
14708
+ if (isVR)
14709
+ manipCamera.RotateInterest(0, speed);
14710
+ else
14711
+ manipCamera.RotatePosition(0, speed);
14712
+ }
1465714713 else
14658
- manipCamera.RotatePosition(0, speed);
14714
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1465914715 /**/
1466014716 if ((mod & SHIFT) == SHIFT)
1466114717 {
....@@ -14665,6 +14721,8 @@
1466514721 mouseMode |= BACKFORTH;
1466614722 }
1466714723
14724
+ targetLookAt.set(manipCamera.lookAt);
14725
+
1466814726 //prevX = X = anchorX;
1466914727 prevY = Y = anchorY + (int) (renderCamera.Distance());
1467014728 }
....@@ -14674,9 +14732,14 @@
1467414732 MODIFIERS |= COMMAND;
1467514733 /**/
1467614734 if((mod&SHIFT) == SHIFT)
14677
- manipCamera.Translate(speed*delta, 0, getWidth());
14735
+ manipCamera.Translate(speed*delta, 0, getWidth());
1467814736 else
14679
- manipCamera.RotatePosition(speed, 0);
14737
+ {
14738
+ if ((mouseMode&VR)!=0)
14739
+ manipCamera.RotateInterest(-speed, 0);
14740
+ else
14741
+ manipCamera.RotatePosition(speed, 0);
14742
+ }
1468014743 /**/
1468114744 if ((mod & SHIFT) == SHIFT)
1468214745 {
....@@ -14686,6 +14749,8 @@
1468614749 mouseMode |= ROTATE;
1468714750 } // TRANSLATE;
1468814751
14752
+ targetLookAt.set(manipCamera.lookAt);
14753
+
1468914754 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1469014755 prevY = Y = anchorY;
1469114756 }
....@@ -14695,9 +14760,15 @@
1469514760 MODIFIERS |= COMMAND;
1469614761 /**/
1469714762 if((mod&SHIFT) == SHIFT)
14698
- manipCamera.Translate(-speed*delta, 0, getWidth());
14763
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1469914764 else
14700
- manipCamera.RotatePosition(-speed, 0);
14765
+ {
14766
+ if ((mouseMode&VR)!=0)
14767
+ manipCamera.RotateInterest(speed, 0);
14768
+ else
14769
+ manipCamera.RotatePosition(-speed, 0);
14770
+ }
14771
+
1470114772 /**/
1470214773 if ((mod & SHIFT) == SHIFT)
1470314774 {
....@@ -14707,6 +14778,8 @@
1470714778 mouseMode |= ROTATE;
1470814779 } // TRANSLATE;
1470914780
14781
+ targetLookAt.set(manipCamera.lookAt);
14782
+
1471014783 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1471114784 prevY = Y = anchorY;
1471214785 }
....@@ -16091,7 +16164,7 @@
1609116164 {
1609216165 switch (hitSomething)
1609316166 {
16094
- case Object3D.hitCenter: gr.setColor(Color.pink);
16167
+ case Object3D.hitCenter: gr.setColor(Color.white);
1609516168 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1609616169 break;
1609716170 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -16117,7 +16190,7 @@
1611716190 if (hasMarquee)
1611816191 {
1611916192 gr.setXORMode(Color.white);
16120
- gr.setColor(Color.red);
16193
+ gr.setColor(Color.white);
1612116194 if (!firstime)
1612216195 {
1612316196 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16657,6 +16730,7 @@
1665716730 private void DrawSkyBox(GL gl, float ratio)
1665816731 {
1665916732 if (//envyoff ||
16733
+ WIREFRAME ||
1666016734 cubemap == null)
1666116735 {
1666216736 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
....@@ -16755,7 +16829,8 @@
1675516829 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1675616830
1675716831 cubemap.disable();
16758
- ////cubemap.unbind();
16832
+ //cubemap.dispose();
16833
+
1675916834 if (CULLFACE)
1676016835 {
1676116836 gl.glEnable(gl.GL_CULL_FACE);
....@@ -17291,6 +17366,7 @@
1729117366
1729217367 public void init(GLAutoDrawable drawable)
1729317368 {
17369
+ if (Globals.DEBUG)
1729417370 System.out.println("shadow buffer init");
1729517371
1729617372 GL gl = drawable.getGL();
....@@ -17519,10 +17595,14 @@
1751917595 gl.glFlush();
1752017596
1752117597 /**/
17522
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17598
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1752317599
17524
- float[] pixels = occlusionsizebuffer.array();
17600
+ float[] depths = occlusiondepthbuffer.array();
1752517601
17602
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17603
+
17604
+ int[] pixels = selectsizebuffer.array();
17605
+
1752617606 double r = 0, g = 0, b = 0;
1752717607
1752817608 double count = 0;
....@@ -17533,7 +17613,7 @@
1753317613
1753417614 double FACTOR = 1;
1753517615
17536
- for (int i = 0; i < pixels.length; i++)
17616
+ for (int i = 0; i < depths.length; i++)
1753717617 {
1753817618 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1753917619 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17616,7 +17696,7 @@
1761617696
1761717697 double scale = ray.z; // 1; // cos
1761817698
17619
- float depth = pixels[newindex];
17699
+ float depth = depths[newindex];
1762017700
1762117701 /*
1762217702 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17813,11 +17893,14 @@
1781317893 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1781417894 static IntBuffer bigAAbuffer;
1781517895 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17816
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17896
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1781717897 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1781817898 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1781917899 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17820
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17900
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17901
+
17902
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17903
+
1782117904 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1782217905 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1782317906 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();