Normand Briere
2019-08-17 ecc1309a04b527c62ffe97e814daf050dbd025cd
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
....@@ -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
....@@ -10670,9 +10690,18 @@
1067010690 static boolean init = false;
1067110691
1067210692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1067310696
1067410697 public void display(GLAutoDrawable drawable)
1067510698 {
10699
+ if (patchMaterial.patchMaterial)
10700
+ {
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(0);
10703
+ }
10704
+
1067610705 if (Grafreed.savesound && Grafreed.hassound)
1067710706 {
1067810707 Grafreed.wav.save();
....@@ -10841,7 +10870,7 @@
1084110870
1084210871 if (wait)
1084310872 {
10844
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1084510874
1084610875 wait = false;
1084710876 }
....@@ -11064,18 +11093,34 @@
1106411093 //
1106511094 // newenvy = -1;
1106611095
11067
- if (object.skyboxname != null)
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1106811097 {
11069
- if (!object.skyboxname.equals(this.loadedskyboxname))
11098
+ if (cubemaprgb == null)
1107011099 {
11071
- LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
- loadedskyboxname = object.skyboxname;
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
1107311101 }
11102
+
11103
+ cubemap = cubemaprgb;
1107411104 }
1107511105 else
1107611106 {
11077
- cubemap = null;
11078
- 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;
1107911124 }
1108011125
1108111126 ratio = ((double) getWidth()) / getHeight();
....@@ -11379,7 +11424,7 @@
1137911424
1138011425 // if (cam != lightCamera)
1138111426 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11382
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1138311428 }
1138411429
1138511430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12453,7 +12498,7 @@
1245312498
1245412499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1245512500
12456
- String program0 =
12501
+ String programmin =
1245712502 // Min shader
1245812503 "!!ARBfp1.0\n" +
1245912504 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12520,7 +12565,7 @@
1252012565 "MOV result.color, temp;" +
1252112566 "END";
1252212567
12523
- String program =
12568
+ String programmax =
1252412569 "!!ARBfp1.0\n" +
1252512570
1252612571 //"OPTION ARB_fragment_program_shadow;" +
....@@ -13376,8 +13421,19 @@
1337613421 //once = true;
1337713422 }
1337813423
13379
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13380
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13424
+ String program = programmax;
13425
+
13426
+ if (Globals.MINSHADER)
13427
+ {
13428
+ program = programmin;
13429
+ }
13430
+
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
+
1338113437 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1338213438
1338313439 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13424,7 +13480,8 @@
1342413480 "\n" +
1342513481 "END\n";
1342613482
13427
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13483
+ if (Globals.DEBUG)
13484
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1342813485 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1342913486
1343013487 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -14623,11 +14680,17 @@
1462314680 void GoDown(int mod)
1462414681 {
1462514682 MODIFIERS |= COMMAND;
14683
+ boolean isVR = (mouseMode&VR)!=0;
1462614684 /**/
1462714685 if((mod&SHIFT) == SHIFT)
14628
- manipCamera.RotatePosition(0, -speed);
14686
+ {
14687
+ if (isVR)
14688
+ manipCamera.RotateInterest(0, -speed);
14689
+ else
14690
+ manipCamera.RotatePosition(0, -speed);
14691
+ }
1462914692 else
14630
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14693
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1463114694 /**/
1463214695 if ((mod & SHIFT) == SHIFT)
1463314696 {
....@@ -14637,6 +14700,8 @@
1463714700 mouseMode |= BACKFORTH;
1463814701 }
1463914702
14703
+ targetLookAt.set(manipCamera.lookAt);
14704
+
1464014705 //prevX = X = anchorX;
1464114706 prevY = Y = anchorY - (int) (renderCamera.Distance());
1464214707 }
....@@ -14645,10 +14710,17 @@
1464514710 {
1464614711 MODIFIERS |= COMMAND;
1464714712 /**/
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+
1464814715 if((mod&SHIFT) == SHIFT)
14649
- manipCamera.RotatePosition(0, speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, speed);
14721
+ }
1465014722 else
14651
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14723
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1465214724 /**/
1465314725 if ((mod & SHIFT) == SHIFT)
1465414726 {
....@@ -14658,6 +14730,8 @@
1465814730 mouseMode |= BACKFORTH;
1465914731 }
1466014732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1466114735 //prevX = X = anchorX;
1466214736 prevY = Y = anchorY + (int) (renderCamera.Distance());
1466314737 }
....@@ -14667,9 +14741,14 @@
1466714741 MODIFIERS |= COMMAND;
1466814742 /**/
1466914743 if((mod&SHIFT) == SHIFT)
14670
- manipCamera.Translate(speed*delta, 0, getWidth());
14744
+ manipCamera.Translate(speed*delta, 0, getWidth());
1467114745 else
14672
- manipCamera.RotatePosition(speed, 0);
14746
+ {
14747
+ if ((mouseMode&VR)!=0)
14748
+ manipCamera.RotateInterest(-speed, 0);
14749
+ else
14750
+ manipCamera.RotatePosition(speed, 0);
14751
+ }
1467314752 /**/
1467414753 if ((mod & SHIFT) == SHIFT)
1467514754 {
....@@ -14679,6 +14758,8 @@
1467914758 mouseMode |= ROTATE;
1468014759 } // TRANSLATE;
1468114760
14761
+ targetLookAt.set(manipCamera.lookAt);
14762
+
1468214763 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1468314764 prevY = Y = anchorY;
1468414765 }
....@@ -14688,9 +14769,15 @@
1468814769 MODIFIERS |= COMMAND;
1468914770 /**/
1469014771 if((mod&SHIFT) == SHIFT)
14691
- manipCamera.Translate(-speed*delta, 0, getWidth());
14772
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1469214773 else
14693
- manipCamera.RotatePosition(-speed, 0);
14774
+ {
14775
+ if ((mouseMode&VR)!=0)
14776
+ manipCamera.RotateInterest(speed, 0);
14777
+ else
14778
+ manipCamera.RotatePosition(-speed, 0);
14779
+ }
14780
+
1469414781 /**/
1469514782 if ((mod & SHIFT) == SHIFT)
1469614783 {
....@@ -14700,6 +14787,8 @@
1470014787 mouseMode |= ROTATE;
1470114788 } // TRANSLATE;
1470214789
14790
+ targetLookAt.set(manipCamera.lookAt);
14791
+
1470314792 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1470414793 prevY = Y = anchorY;
1470514794 }
....@@ -15202,8 +15291,8 @@
1520215291 case 'K':
1520315292 KOMPACTTEXTURE ^= true;
1520415293 //textures.clear();
15205
- break;
15206
- case 'P': // Texture Projection macros
15294
+ // break;
15295
+ //case 'P': // Texture Projection macros
1520715296 // SAVETEXTURE ^= true;
1520815297 macromode = true;
1520915298 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15324,7 +15413,7 @@
1532415413 targetLookAt.set(manipCamera.lookAt);
1532515414 repaint();
1532615415 break;
15327
- case 'p':
15416
+ case 'P': // p':
1532815417 // c'est quoi ca au juste? spherical ^= true;
1532915418 Skinshader ^= true; programInitialized = false;
1533015419 repaint();
....@@ -16084,7 +16173,7 @@
1608416173 {
1608516174 switch (hitSomething)
1608616175 {
16087
- case Object3D.hitCenter: gr.setColor(Color.pink);
16176
+ case Object3D.hitCenter: gr.setColor(Color.white);
1608816177 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1608916178 break;
1609016179 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -16110,7 +16199,7 @@
1611016199 if (hasMarquee)
1611116200 {
1611216201 gr.setXORMode(Color.white);
16113
- gr.setColor(Color.red);
16202
+ gr.setColor(Color.white);
1611416203 if (!firstime)
1611516204 {
1611616205 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16650,6 +16739,7 @@
1665016739 private void DrawSkyBox(GL gl, float ratio)
1665116740 {
1665216741 if (//envyoff ||
16742
+ WIREFRAME ||
1665316743 cubemap == null)
1665416744 {
1665516745 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
....@@ -16667,14 +16757,14 @@
1666716757 gl.glLoadIdentity();
1666816758 gl.glScalef(1,ratio,1);
1666916759
16670
- colorV[0] = 2;
16671
- colorV[1] = 2;
16672
- colorV[2] = 2;
16673
- colorV[3] = 1;
16674
- gl.glDisable(gl.GL_COLOR_MATERIAL);
16675
- gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16676
-
16677
- gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16760
+// colorV[0] = 2;
16761
+// colorV[1] = 2;
16762
+// colorV[2] = 2;
16763
+// colorV[3] = 1;
16764
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16765
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16766
+//
16767
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
1667816768
1667916769 //gl.glActiveTexture(GL.GL_TEXTURE1);
1668016770 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
....@@ -16688,7 +16778,7 @@
1668816778 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1668916779 // causes the normals to be sent down. Thanks to Ken Dyke.
1669016780 //gl.glEnable(GL.GL_LIGHTING);
16691
- gl.glEnable(GL.GL_LIGHTING);
16781
+ gl.glDisable(GL.GL_LIGHTING);
1669216782
1669316783 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1669416784 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16748,7 +16838,8 @@
1674816838 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1674916839
1675016840 cubemap.disable();
16751
- ////cubemap.unbind();
16841
+ //cubemap.dispose();
16842
+
1675216843 if (CULLFACE)
1675316844 {
1675416845 gl.glEnable(gl.GL_CULL_FACE);
....@@ -17284,6 +17375,7 @@
1728417375
1728517376 public void init(GLAutoDrawable drawable)
1728617377 {
17378
+ if (Globals.DEBUG)
1728717379 System.out.println("shadow buffer init");
1728817380
1728917381 GL gl = drawable.getGL();
....@@ -17512,10 +17604,14 @@
1751217604 gl.glFlush();
1751317605
1751417606 /**/
17515
- 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);
1751617608
17517
- float[] pixels = occlusionsizebuffer.array();
17609
+ float[] depths = occlusiondepthbuffer.array();
1751817610
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
+
1751917615 double r = 0, g = 0, b = 0;
1752017616
1752117617 double count = 0;
....@@ -17526,7 +17622,7 @@
1752617622
1752717623 double FACTOR = 1;
1752817624
17529
- for (int i = 0; i < pixels.length; i++)
17625
+ for (int i = 0; i < depths.length; i++)
1753017626 {
1753117627 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1753217628 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17609,7 +17705,7 @@
1760917705
1761017706 double scale = ray.z; // 1; // cos
1761117707
17612
- float depth = pixels[newindex];
17708
+ float depth = depths[newindex];
1761317709
1761417710 /*
1761517711 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17806,11 +17902,14 @@
1780617902 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1780717903 static IntBuffer bigAAbuffer;
1780817904 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17809
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17905
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1781017906 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1781117907 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1781217908 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17813
- 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
+
1781417913 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1781517914 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1781617915 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();