Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
CameraPane.java
....@@ -187,6 +187,18 @@
187187 }
188188
189189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
190202
191203 void SetAsGLRenderer(boolean b)
192204 {
....@@ -1485,6 +1497,8 @@
14851497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14861498 }
14871499
1500
+ float[] colorV = new float[4];
1501
+
14881502 void SetColor(Object3D obj, Vertex p0)
14891503 {
14901504 CameraPane display = this;
....@@ -1552,8 +1566,6 @@
15521566 {
15531567 return;
15541568 }
1555
-
1556
- float[] colorV = new float[3];
15571569
15581570 if (false) // marked)
15591571 {
....@@ -8346,7 +8358,7 @@
83468358 // else
83478359 // if (!texname.startsWith("/"))
83488360 // texname = "/Users/nbriere/Textures/" + texname;
8349
- if (!FileExists(texname))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
83508362 {
83518363 texname = fallbackTextureName;
83528364 }
....@@ -8429,6 +8441,15 @@
84298441 new Exception().printStackTrace();
84308442 } else
84318443 {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
8451
+ } else
8452
+ {
84328453 if (textureon)
84338454 {
84348455 String cachename = texname;
....@@ -8488,6 +8509,7 @@
84888509 texturecache = new CacheTexture(texturedata,resolution);
84898510 //texture = GetTexture(tex, bump);
84908511 }
8512
+ }
84918513 }
84928514 //}
84938515 }
....@@ -8756,10 +8778,12 @@
87568778
87578779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87588780 MAXSTACK = temp[0];
8759
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87608783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87618784 MAXSTACK = temp[0];
8762
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87638787
87648788 // Use debug pipeline
87658789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8767,7 +8791,8 @@
87678791 gl = drawable.getGL(); //
87688792
87698793 GL gl3 = getGL();
8770
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87718796
87728797
87738798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8932,7 +8957,7 @@
89328957
89338958 if (cubemap == null)
89348959 {
8935
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
89368961 }
89378962
89388963 //cubemap.enable();
....@@ -9219,37 +9244,58 @@
92199244 cubemap = null;
92209245 return;
92219246 case 1:
9222
- name = "cubemaps/box_";
9223
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
92249249 reverseUP = false;
92259250 break;
92269251 case 2:
9227
- name = "cubemaps/uffizi_";
9228
- ext = "png";
9229
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
92309256 case 3:
9231
- name = "cubemaps/CloudyHills_";
9232
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
92339259 reverseUP = false;
92349260 break;
92359261 case 4:
9236
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
92379263 ext = "png";
92389264 reverseUP = false;
92399265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
92409291 default:
9241
- name = "cubemaps/rgb_";
9242
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
92439295 break;
92449296 }
9245
-
9246
- try
9247
- {
9248
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9249
- } catch (IOException e)
9250
- {
9251
- throw new RuntimeException(e);
9252
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
92539299 }
92549300
92559301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9281,8 +9327,12 @@
92819327 static double[] model = new double[16];
92829328 double[] camera2light = new double[16];
92839329 double[] light2camera = new double[16];
9284
- int newenvy = -1;
9285
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
92869336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92879337 //float[] light0 = { 0,0,0 };
92889338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9762,10 +9812,12 @@
97629812 rati = 1 / rati;
97639813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97649814 }
9765
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
97669818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97679819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9768
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
97699821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97709822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97719823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10802,7 +10854,7 @@
1080210854
1080310855 if (wait)
1080410856 {
10805
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1080610858
1080710859 wait = false;
1080810860 }
....@@ -11018,13 +11070,27 @@
1101811070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101911071 }
1102011072
11021
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1102211081 {
11023
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1102411087 }
11025
-
11026
- newenvy = -1;
11027
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1102811094 ratio = ((double) getWidth()) / getHeight();
1102911095 //System.out.println("ratio = " + ratio);
1103011096
....@@ -11040,7 +11106,7 @@
1104011106
1104111107 if (!IsFrozen() && !ambientOcclusion)
1104211108 {
11043
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1104411110 }
1104511111
1104611112 //if (selection_view == -1)
....@@ -11326,7 +11392,7 @@
1132611392
1132711393 // if (cam != lightCamera)
1132811394 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11329
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1133011396 }
1133111397
1133211398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12400,7 +12466,7 @@
1240012466
1240112467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240212468
12403
- String program =
12469
+ String programmin =
1240412470 // Min shader
1240512471 "!!ARBfp1.0\n" +
1240612472 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12451,7 +12517,8 @@
1245112517 //"SUB ndotl.y, zero123.y, ndotl.y;" +
1245212518 //"MUL ndotl.y, ndotl.y, pow2.z;" +
1245312519
12454
- "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
1245512522
1245612523 // Pigment
1245712524 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
....@@ -12466,7 +12533,7 @@
1246612533 "MOV result.color, temp;" +
1246712534 "END";
1246812535
12469
- String program2 =
12536
+ String programmax =
1247012537 "!!ARBfp1.0\n" +
1247112538
1247212539 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12991,7 +13058,7 @@
1299113058 // display shadow only (fakedepth == 0)
1299213059 "SUB temp.x, half.x, shadow.x;" +
1299313060 "MOV temp.y, -params5.z;" + // params6.x;" +
12994
- "SLT temp.z, temp.y, -one2048th.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1299513062 "SUB temp.y, one.x, temp.z;" +
1299613063 "MUL temp.x, temp.x, temp.y;" +
1299713064 "KIL temp.x;" +
....@@ -13322,6 +13389,13 @@
1332213389 //once = true;
1332313390 }
1332413391
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
1332513399 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1332613400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1332713401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -14571,9 +14645,9 @@
1457114645 MODIFIERS |= COMMAND;
1457214646 /**/
1457314647 if((mod&SHIFT) == SHIFT)
14574
- manipCamera.RotatePosition(0, -speed);
14575
- else
1457614648 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14649
+ else
14650
+ manipCamera.RotatePosition(0, -speed);
1457714651 /**/
1457814652 if ((mod & SHIFT) == SHIFT)
1457914653 {
....@@ -14592,9 +14666,9 @@
1459214666 MODIFIERS |= COMMAND;
1459314667 /**/
1459414668 if((mod&SHIFT) == SHIFT)
14595
- manipCamera.RotatePosition(0, speed);
14596
- else
1459714669 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14670
+ else
14671
+ manipCamera.RotatePosition(0, speed);
1459814672 /**/
1459914673 if ((mod & SHIFT) == SHIFT)
1460014674 {
....@@ -15315,20 +15389,24 @@
1531515389 OCCLUSION_CULLING ^= true;
1531615390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1531715391 break;
15318
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1531915393 case '1':
1532015394 case '2':
1532115395 case '3':
1532215396 case '4':
1532315397 case '5':
15324
- newenvy = Character.getNumericValue(key);
15325
- repaint();
15326
- break;
1532715398 case '6':
1532815399 case '7':
1532915400 case '8':
1533015401 case '9':
15331
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1533215410 repaint();
1533315411 break;
1533415412 case '!':
....@@ -16033,7 +16111,7 @@
1603316111 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603416112 break;
1603516113 case Object3D.hitScale: gr.setColor(Color.cyan);
16036
- gr.drawLine(X, Y, 0, 0);
16114
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603716115 break;
1603816116 }
1603916117
....@@ -16519,6 +16597,8 @@
1651916597 private /*static*/ boolean firstime;
1652016598 private /*static*/ cVector newView = new cVector();
1652116599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1652216602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1652316603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1652416604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16531,29 +16611,67 @@
1653116611 {
1653216612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1653316613
16614
+ int usedsuf = 0;
16615
+
1653416616 for (int i = 0; i < suffixes.length; i++)
1653516617 {
16536
- String resourceName = basename + suffixes[i] + "." + suffix;
16537
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16538
- mipmapped,
16539
- FileUtil.getFileSuffix(resourceName));
16540
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1654116623 {
16542
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1654316628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1654416657 //System.out.println("Target = " + targets[i]);
1654516658 cubemap.updateImage(data, targets[i]);
1654616659 }
1654716660
1654816661 return cubemap;
1654916662 }
16663
+
1655016664 int bigsphere = -1;
1655116665
1655216666 float BGcolor = 0.5f;
1655316667
16554
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1655516671 {
16556
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1655716675 {
1655816676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1655916677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16568,7 +16686,17 @@
1656816686 // Compensates for ExaminerViewer's modification of modelview matrix
1656916687 gl.glMatrixMode(GL.GL_MODELVIEW);
1657016688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1657116690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1657216700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1657316701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1657416702
....@@ -16600,6 +16728,7 @@
1660016728 {
1660116729 gl.glScalef(1.0f, -1.0f, 1.0f);
1660216730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1660316732 gl.glMultMatrixd(viewrot_1, 0);
1660416733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1660516734 //viewer.updateInverseRotation(gl);
....@@ -16858,7 +16987,7 @@
1685816987 //new Exception().printStackTrace();
1685916988 System.out.println("select buffer init");
1686016989 // Use debug pipeline
16861
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1686216991
1686316992 GL gl = drawable.getGL();
1686416993