Normand Briere
2019-08-18 480ad70047e54b2b92f974e6c2ac5a6c0bdc5a5c
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
....@@ -164,7 +168,7 @@
164168
165169
166170 // OPTIONS
167
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
168172 boolean cameraLight = false;
169173 boolean UVdebug = false;
170174 boolean Udebug = false;
....@@ -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
....@@ -2047,9 +2052,9 @@
20472052 switch(viewcode)
20482053 {
20492054 case 0: return "main";
2050
- case 1: return "one";
2051
- case 2: return "two";
2052
- case 3: return "three";
2055
+ case 1: return "Red";
2056
+ case 2: return "Green";
2057
+ case 3: return "Blue";
20532058 case 4: return "light";
20542059 }
20552060
....@@ -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);
....@@ -8778,10 +8783,12 @@
87788783
87798784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87808785 MAXSTACK = temp[0];
8781
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87828788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87838789 MAXSTACK = temp[0];
8784
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87858792
87868793 // Use debug pipeline
87878794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8789,7 +8796,8 @@
87898796 gl = drawable.getGL(); //
87908797
87918798 GL gl3 = getGL();
8792
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87938801
87948802
87958803 //float pos[] = { 100, 100, 100, 0 };
....@@ -9230,6 +9238,8 @@
92309238
92319239 void LoadEnvy(int which)
92329240 {
9241
+ assert(false);
9242
+
92339243 String name;
92349244 String ext;
92359245
....@@ -10680,9 +10690,18 @@
1068010690 static boolean init = false;
1068110691
1068210692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1068310696
1068410697 public void display(GLAutoDrawable drawable)
1068510698 {
10699
+ if (patchMaterial.patchMaterial)
10700
+ {
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(1);
10703
+ }
10704
+
1068610705 if (Grafreed.savesound && Grafreed.hassound)
1068710706 {
1068810707 Grafreed.wav.save();
....@@ -11074,18 +11093,34 @@
1107411093 //
1107511094 // newenvy = -1;
1107611095
11077
- if (object.skyboxname != null)
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1107811097 {
11079
- if (!object.skyboxname.equals(this.loadedskyboxname))
11098
+ if (cubemaprgb == null)
1108011099 {
11081
- LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
- loadedskyboxname = object.skyboxname;
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
1108311101 }
11102
+
11103
+ cubemap = cubemaprgb;
1108411104 }
1108511105 else
1108611106 {
11087
- cubemap = null;
11088
- loadedskyboxname = null;
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
1108911124 }
1109011125
1109111126 ratio = ((double) getWidth()) / getHeight();
....@@ -13393,8 +13428,12 @@
1339313428 program = programmin;
1339413429 }
1339513430
13396
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13397
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13431
+ if (Globals.DEBUG)
13432
+ {
13433
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13434
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13435
+ }
13436
+
1339813437 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1339913438
1340013439 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13441,7 +13480,8 @@
1344113480 "\n" +
1344213481 "END\n";
1344313482
13444
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13483
+ if (Globals.DEBUG)
13484
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1344513485 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1344613486
1344713487 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -14640,11 +14680,17 @@
1464014680 void GoDown(int mod)
1464114681 {
1464214682 MODIFIERS |= COMMAND;
14683
+ boolean isVR = (mouseMode&VR)!=0;
1464314684 /**/
1464414685 if((mod&SHIFT) == SHIFT)
14645
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14686
+ {
14687
+ if (isVR)
14688
+ manipCamera.RotateInterest(0, -speed);
14689
+ else
14690
+ manipCamera.RotatePosition(0, -speed);
14691
+ }
1464614692 else
14647
- manipCamera.RotatePosition(0, -speed);
14693
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1464814694 /**/
1464914695 if ((mod & SHIFT) == SHIFT)
1465014696 {
....@@ -14654,6 +14700,8 @@
1465414700 mouseMode |= BACKFORTH;
1465514701 }
1465614702
14703
+ targetLookAt.set(manipCamera.lookAt);
14704
+
1465714705 //prevX = X = anchorX;
1465814706 prevY = Y = anchorY - (int) (renderCamera.Distance());
1465914707 }
....@@ -14662,10 +14710,17 @@
1466214710 {
1466314711 MODIFIERS |= COMMAND;
1466414712 /**/
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+
1466514715 if((mod&SHIFT) == SHIFT)
14666
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, speed);
14721
+ }
1466714722 else
14668
- manipCamera.RotatePosition(0, speed);
14723
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1466914724 /**/
1467014725 if ((mod & SHIFT) == SHIFT)
1467114726 {
....@@ -14675,6 +14730,8 @@
1467514730 mouseMode |= BACKFORTH;
1467614731 }
1467714732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1467814735 //prevX = X = anchorX;
1467914736 prevY = Y = anchorY + (int) (renderCamera.Distance());
1468014737 }
....@@ -14684,9 +14741,14 @@
1468414741 MODIFIERS |= COMMAND;
1468514742 /**/
1468614743 if((mod&SHIFT) == SHIFT)
14687
- manipCamera.Translate(speed*delta, 0, getWidth());
14744
+ manipCamera.Translate(speed*delta, 0, getWidth());
1468814745 else
14689
- manipCamera.RotatePosition(speed, 0);
14746
+ {
14747
+ if ((mouseMode&VR)!=0)
14748
+ manipCamera.RotateInterest(-speed, 0);
14749
+ else
14750
+ manipCamera.RotatePosition(speed, 0);
14751
+ }
1469014752 /**/
1469114753 if ((mod & SHIFT) == SHIFT)
1469214754 {
....@@ -14696,6 +14758,8 @@
1469614758 mouseMode |= ROTATE;
1469714759 } // TRANSLATE;
1469814760
14761
+ targetLookAt.set(manipCamera.lookAt);
14762
+
1469914763 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1470014764 prevY = Y = anchorY;
1470114765 }
....@@ -14705,9 +14769,15 @@
1470514769 MODIFIERS |= COMMAND;
1470614770 /**/
1470714771 if((mod&SHIFT) == SHIFT)
14708
- manipCamera.Translate(-speed*delta, 0, getWidth());
14772
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1470914773 else
14710
- manipCamera.RotatePosition(-speed, 0);
14774
+ {
14775
+ if ((mouseMode&VR)!=0)
14776
+ manipCamera.RotateInterest(speed, 0);
14777
+ else
14778
+ manipCamera.RotatePosition(-speed, 0);
14779
+ }
14780
+
1471114781 /**/
1471214782 if ((mod & SHIFT) == SHIFT)
1471314783 {
....@@ -14717,6 +14787,8 @@
1471714787 mouseMode |= ROTATE;
1471814788 } // TRANSLATE;
1471914789
14790
+ targetLookAt.set(manipCamera.lookAt);
14791
+
1472014792 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1472114793 prevY = Y = anchorY;
1472214794 }
....@@ -15219,8 +15291,8 @@
1521915291 case 'K':
1522015292 KOMPACTTEXTURE ^= true;
1522115293 //textures.clear();
15222
- break;
15223
- case 'P': // Texture Projection macros
15294
+ // break;
15295
+ //case 'P': // Texture Projection macros
1522415296 // SAVETEXTURE ^= true;
1522515297 macromode = true;
1522615298 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15341,7 +15413,7 @@
1534115413 targetLookAt.set(manipCamera.lookAt);
1534215414 repaint();
1534315415 break;
15344
- case 'p':
15416
+ case 'P': // p':
1534515417 // c'est quoi ca au juste? spherical ^= true;
1534615418 Skinshader ^= true; programInitialized = false;
1534715419 repaint();
....@@ -16101,7 +16173,7 @@
1610116173 {
1610216174 switch (hitSomething)
1610316175 {
16104
- case Object3D.hitCenter: gr.setColor(Color.pink);
16176
+ case Object3D.hitCenter: gr.setColor(Color.white);
1610516177 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1610616178 break;
1610716179 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -16127,7 +16199,7 @@
1612716199 if (hasMarquee)
1612816200 {
1612916201 gr.setXORMode(Color.white);
16130
- gr.setColor(Color.red);
16202
+ gr.setColor(Color.white);
1613116203 if (!firstime)
1613216204 {
1613316205 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16667,6 +16739,7 @@
1666716739 private void DrawSkyBox(GL gl, float ratio)
1666816740 {
1666916741 if (//envyoff ||
16742
+ WIREFRAME ||
1667016743 cubemap == null)
1667116744 {
1667216745 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
....@@ -16765,7 +16838,8 @@
1676516838 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1676616839
1676716840 cubemap.disable();
16768
- ////cubemap.unbind();
16841
+ //cubemap.dispose();
16842
+
1676916843 if (CULLFACE)
1677016844 {
1677116845 gl.glEnable(gl.GL_CULL_FACE);
....@@ -17301,6 +17375,7 @@
1730117375
1730217376 public void init(GLAutoDrawable drawable)
1730317377 {
17378
+ if (Globals.DEBUG)
1730417379 System.out.println("shadow buffer init");
1730517380
1730617381 GL gl = drawable.getGL();
....@@ -17529,10 +17604,14 @@
1752917604 gl.glFlush();
1753017605
1753117606 /**/
17532
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17607
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1753317608
17534
- float[] pixels = occlusionsizebuffer.array();
17609
+ float[] depths = occlusiondepthbuffer.array();
1753517610
17611
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17612
+
17613
+ int[] pixels = selectsizebuffer.array();
17614
+
1753617615 double r = 0, g = 0, b = 0;
1753717616
1753817617 double count = 0;
....@@ -17543,7 +17622,7 @@
1754317622
1754417623 double FACTOR = 1;
1754517624
17546
- for (int i = 0; i < pixels.length; i++)
17625
+ for (int i = 0; i < depths.length; i++)
1754717626 {
1754817627 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1754917628 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17626,7 +17705,7 @@
1762617705
1762717706 double scale = ray.z; // 1; // cos
1762817707
17629
- float depth = pixels[newindex];
17708
+ float depth = depths[newindex];
1763017709
1763117710 /*
1763217711 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17823,11 +17902,14 @@
1782317902 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1782417903 static IntBuffer bigAAbuffer;
1782517904 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17826
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17905
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1782717906 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1782817907 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1782917908 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17830
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17909
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17910
+
17911
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17912
+
1783117913 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1783217914 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1783317915 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();