From 6266c8a4b2485b29a7d5bcb217460d7aad3e1c4a Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sun, 25 Aug 2019 20:58:10 -0400 Subject: [PATCH] Proto version slider. --- CameraPane.java | 441 ++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 324 insertions(+), 117 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index 8953dc4..b983dd6 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -110,7 +110,11 @@ //private Mat4f spotlightTransform = new Mat4f(); //private Mat4f spotlightInverseTransform = new Mat4f(); static GLContext glcontext = null; - /*static*/ com.sun.opengl.util.texture.Texture cubemap; + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; + boolean transformMode; + boolean reverseUP = false; static boolean frozen = false; boolean enablebackspace = false; // patch for back buffer refresh @@ -164,7 +168,7 @@ // OPTIONS - boolean Skinshader = true; + boolean Skinshader = false; // true; boolean cameraLight = false; boolean UVdebug = false; boolean Udebug = false; @@ -173,7 +177,7 @@ static boolean doublesided = false; // true; // reversed normals are awful for conformance boolean anisotropy = true; boolean softshadow = true; // slower but better false; - boolean opacityhalo = false; + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) boolean macromode = false; @@ -188,15 +192,16 @@ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); - public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException { try { - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); } catch (IOException e) { System.out.println("NAME = " + name); e.printStackTrace(); // throw new RuntimeException(e); + return null; } } @@ -537,7 +542,8 @@ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1); LA.vecCross(obj.v0, obj.v1, obj.v2); LA.vecNormalize(obj.v2); - gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z); + + SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z); } // P @@ -559,7 +565,7 @@ y += ny * obj.NORMALPUSH; z += nz * obj.NORMALPUSH; - gl.glNormal3f(nx, ny, nz); + SetGLNormal(gl, nx, ny, nz); } gl.glColor4f(pv.AO, pv.AO, pv.AO, 1); SetColor(obj, pv); @@ -591,7 +597,7 @@ y += ny * obj.NORMALPUSH; z += nz * obj.NORMALPUSH; - gl.glNormal3f(nx, ny, nz); + SetGLNormal(gl, nx, ny, nz); } //System.out.println("vertexq = " + qv.s + ", " + qv.t); // boolean locked = false; @@ -639,7 +645,7 @@ y += ny * obj.NORMALPUSH; z += nz * obj.NORMALPUSH; - gl.glNormal3f(nx, ny, nz); + SetGLNormal(gl, nx, ny, nz); } // if ((dot&4) == 0) @@ -875,7 +881,7 @@ //// tris.postdraw(this); } - static Camera localcamera = new Camera(); + static Camera localAOcamera = new Camera(); static cVector from = new cVector(); static cVector to = new cVector(); @@ -884,7 +890,7 @@ CameraPane cp = this; Camera keep = cp.RenderCamera(); - cp.renderCamera = localcamera; + cp.renderCamera = localAOcamera; if (br.trimmed) { @@ -902,7 +908,7 @@ br.positions[i3 + 2] + br.normals[i3 + 2]); LA.xformPos(from, transform, from); LA.xformPos(to, transform, to); // RIGID ONLY - localcamera.setAim(from, to); + localAOcamera.setAim(from, to); CameraPane.occlusionbuffer.display(); @@ -936,7 +942,7 @@ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z); LA.xformPos(from, transform, from); LA.xformPos(to, transform, to); // RIGID ONLY - localcamera.setAim(from, to); + localAOcamera.setAim(from, to); CameraPane.occlusionbuffer.display(); @@ -1245,10 +1251,10 @@ { if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) { - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); } else { - gl.glNormal3f(0, 0, 1); + SetGLNormal(gl, 0, 0, 1); } if (c != null) @@ -1272,10 +1278,10 @@ { if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) { - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); } else { - gl.glNormal3f(0, 0, 1); + SetGLNormal(gl, 0, 0, 1); } if (c != null) { @@ -1300,10 +1306,10 @@ { if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) { - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); } else { - gl.glNormal3f(0, 0, 1); + SetGLNormal(gl, 0, 0, 1); } if (c != null) { @@ -1485,7 +1491,7 @@ { if (!selectmode) { - gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z); + SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z); gl.glColor4f(pv.AO, pv.AO, pv.AO, 1); if (flipV) @@ -1814,7 +1820,7 @@ display.modelParams7[0] = 0; display.modelParams7[1] = 1000; - display.modelParams7[2] = 0; + display.modelParams7[2] = material.parallax; display.modelParams7[3] = 0; //display.modelParams6[0] = 100; // criss de bug de bump @@ -2047,9 +2053,9 @@ switch(viewcode) { case 0: return "main"; - case 1: return "one"; - case 2: return "two"; - case 3: return "three"; + case 1: return "Red"; + case 2: return "Green"; + case 3: return "Blue"; case 4: return "light"; } @@ -2470,6 +2476,18 @@ return CreateBim(bytes, width, height); } + private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz) + { + gl.glNormal3f(nx, ny, nz); + + if (ny > 0.9 || ny < -0.9) + // Ground or ceiling + gl.glVertexAttrib3f(4, 1, 0, 0); + else + // Walls + gl.glVertexAttrib3f(4, 0, 1, 0); + } + /**/ class CacheTexture { @@ -2512,7 +2530,7 @@ com.sun.opengl.util.texture.TextureIO.newTextureData( getClass().getClassLoader().getResourceAsStream(name), true, - com.sun.opengl.util.texture.TextureIO.PNG); + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); } catch (java.io.IOException e) { throw new javax.media.opengl.GLException(e); @@ -8358,7 +8376,7 @@ // else // if (!texname.startsWith("/")) // texname = "/Users/nbriere/Textures/" + texname; - if (!FileExists(texname)) + if (!FileExists(texname) && !texname.startsWith("@")) { texname = fallbackTextureName; } @@ -8441,6 +8459,15 @@ new Exception().printStackTrace(); } else { + if (texname.startsWith("@")) + { + // texturecache = textures.get(texname); // suspicious + if (texturecache == null) + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); + else + new Exception().printStackTrace(); + } else + { if (textureon) { String cachename = texname; @@ -8500,6 +8527,7 @@ texturecache = new CacheTexture(texturedata,resolution); //texture = GetTexture(tex, bump); } + } } //} } @@ -8768,10 +8796,12 @@ gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); MAXSTACK = temp[0]; - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); + if (Globals.DEBUG) + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); MAXSTACK = temp[0]; - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); + if (Globals.DEBUG) + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); // Use debug pipeline //drawable.setGL(new DebugGL(gl)); // @@ -8779,7 +8809,8 @@ gl = drawable.getGL(); // GL gl3 = getGL(); - System.out.println("INIT GL IS: " + gl.getClass().getName()); + if (Globals.DEBUG) + System.out.println("INIT GL IS: " + gl.getClass().getName()); //float pos[] = { 100, 100, 100, 0 }; @@ -9220,6 +9251,8 @@ void LoadEnvy(int which) { + assert(false); + String name; String ext; @@ -9316,10 +9349,9 @@ double[] light2camera = new double[16]; //int newenvy = -1; - boolean envyoff = true; // false; - String skyboxname = ""; - String skyboxext; - String loadedskyboxname = ""; + //boolean envyoff = false; + + String loadedskyboxname; cVector light0 = new cVector(0, 0, 0); // 1,3,2); //float[] light0 = { 0,0,0 }; @@ -10671,9 +10703,18 @@ static boolean init = false; double[][] matrix = LA.newMatrix(); + + // This is to refresh the UI of the material panel. + ObjEditor patchMaterial; public void display(GLAutoDrawable drawable) { + if (patchMaterial.patchMaterial) + { + patchMaterial.patchMaterial = false; + patchMaterial.objectPanel.setSelectedIndex(1); + } + if (Grafreed.savesound && Grafreed.hassound) { Grafreed.wav.save(); @@ -10842,7 +10883,7 @@ if (wait) { - Sleep(500); + Sleep(200); // blocks everything wait = false; } @@ -11065,10 +11106,34 @@ // // newenvy = -1; - if (!skyboxname.equals(this.loadedskyboxname)) + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) { - LoadSkybox(skyboxname + "/", skyboxext, false); - loadedskyboxname = skyboxname; + if (cubemaprgb == null) + { + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); + } + + cubemap = cubemaprgb; + } + else + { + if (object.skyboxname != null) + { + if (!object.skyboxname.equals(this.loadedskyboxname)) + { + if (cubemap != null && cubemap != cubemaprgb) + cubemap.dispose(); + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); + loadedskyboxname = object.skyboxname; + } + } + else + { + cubemapcustom = null; + loadedskyboxname = null; + } + + cubemap = cubemapcustom; } ratio = ((double) getWidth()) / getHeight(); @@ -11372,7 +11437,7 @@ // if (cam != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 } LA.xformDir(lightposition, cam.toScreen, lightposition); @@ -12446,11 +12511,12 @@ //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); - String program0 = + String programmin = // Min shader "!!ARBfp1.0\n" + - "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + - "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + + "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" + + "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" + + "PARAM pow2 = { 2, 4, 8, 0.0 };" + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + @@ -12465,10 +12531,11 @@ "TEMP eye;" + "TEMP pos;" + - "MAD normal, fragment.color, zero123.z, -zero123.y;" + + "MAD normal, fragment.color, zero12t.z, -zero12t.y;" + Normalize("normal") + "MOV light, state.light[0].position;" + "DP3 ndotl.x, light, normal;" + + "MAX ndotl.x, ndotl.x, zero12t.x;" + // shadow "MOV pos, fragment.texcoord[1];" + @@ -12484,7 +12551,7 @@ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow // Backlit - "MOV pos.w, zero123.y;" + + "MOV pos.w, zero12t.y;" + // one "DP4 eye.x, pos, light2cam0;" + "DP4 eye.y, pos, light2cam1;" + "DP4 eye.z, pos, light2cam2;" + @@ -12492,28 +12559,32 @@ "DP3 ndotl.y, -eye, normal;" + //"MUL ndotl.y, ndotl.y, pow2.x;" + - "POW ndotl.y, ndotl.y, pow2.z;" + // backlit - "SUB ndotl.y, zero123.y, ndotl.y;" + + "POW ndotl.y, ndotl.y, pow2.x;" + // backlit + "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y + //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit //"SUB ndotl.y, zero123.y, ndotl.y;" + //"MUL ndotl.y, ndotl.y, pow2.z;" + + "ADD ndotl.y, ndotl.y, one.x;" + + "MUL ndotl.y, ndotl.y, pow_2.x;" + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient // Pigment "TEX temp, fragment.texcoord[0], texture[0], 2D;" + - "LRP temp, zero123.w, temp, one;" + // texture proportion - "MUL temp, temp, ndotl.x;" + - - "MUL temp, temp, zero123.z;" + + "LRP temp, zero12t.w, temp, one;" + // texture proportion + "MUL temp, temp, zero12t.w;" + // Times x //"MUL temp, temp, ndotl.y;" + + "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" + - "MOV temp.w, zero123.y;" + // reset alpha + "MUL temp, temp, ndotl.x;" + // lambert + + "MOV temp.w, zero12t.y;" + // reset alpha "MOV result.color, temp;" + "END"; - String program = + String programmax = "!!ARBfp1.0\n" + //"OPTION ARB_fragment_program_shadow;" + @@ -12541,7 +12612,7 @@ "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough - "PARAM params7 = program.env[7];" + // noise power, opacity power + "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax "PARAM options0 = program.env[63];" + // fog density, intensity, elevation "PARAM options1 = program.env[62];" + // fog rgb color "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen @@ -12786,7 +12857,7 @@ "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut // mar 2013 ??? "KIL alpha.a;" + "MOV alpha, texSamp.aaaa;" + // y;" + - "KIL alpha.a;" + + "KIL alpha.a;" + // not sure with parallax mapping /* "MUL temp.xy, temp, two;" + "TXB bump, temp, texture[0], 2D;" + @@ -12872,11 +12943,6 @@ "SUB bump0, bump0, half;" + "ADD bump, bump, bump0;" + - "MOV temp.x, texSamp.a;" + - "LRP texSamp, params5.x, texSamp, one;" + // texture proportion - //"LRP texSamp0, params5.x, texSamp0, one;" + - "MOV texSamp.a, temp.x;" + - // double-sided /**/ (doublesided?"DP3 temp.z, normal, eye;" + @@ -12886,26 +12952,73 @@ "ADD temp.x, temp.x, one.x;" + "MUL normal, normal, temp.xxxx;":"" ) + - /**/ -//// Normalize("normal") + -//// "MAX normal.z, eps.x, normal.z;" + -// Normalize("normal") + - "MOV normald, normal;" + - "MOV normals, normal;" + + /**/ + + "MOV temp, fragment.texcoord[4];" + // UV base //"DP3 UP.x,state.matrix.modelview.row[0],Y;" + //"DP3 UP.y,state.matrix.modelview.row[1],Y;" + //"DP3 UP.z,state.matrix.modelview.row[2],Y;" + - "DP3 UP.x,state.matrix.texture[7].row[0],Y;" + - "DP3 UP.y,state.matrix.texture[7].row[1],Y;" + - "DP3 UP.z,state.matrix.texture[7].row[2],Y;" + + "DP3 UP.x,state.matrix.texture[7].row[0],temp;" + + "DP3 UP.y,state.matrix.texture[7].row[1],temp;" + + "DP3 UP.z,state.matrix.texture[7].row[2],temp;" + + Normalize("UP") + + "XPD V, normal, UP;" + Normalize("V") + "XPD U, V, normal;" + Normalize("U") + + "MOV temp, fragment.texcoord[0];" + + +// "MAD normal, -temp.x, U, normal;" + +// "MAD normal, -temp.y, V, normal;" + +// Normalize("normal") + + +//// "MAX normal.z, eps.x, normal.z;" + +// Normalize("normal") + + "MOV normald, normal;" + + "MOV normals, normal;" + + // parallax mapping + + "DP3 temp2.x, V, eye;" + + "DP3 temp2.y, U, eye;" + + "DP3 temp2.z, normal, eye;" + + "RCP temp2.z, temp2.z;" + + + "DP3 temp2.w, texSamp, texSamp;" + // Height + "RSQ temp2.w, temp2.w;" + + "RCP temp2.w, temp2.w;" + + + "SUB temp2.w, temp2.w, half;" + + // "SGE temp.x, temp2.w, eps.x;" + + // "MUL temp2.w, temp2.w, temp.x;" + + + // "MOV texSamp, U;" + + + "MUL temp2.z, temp2.z, temp2.w;" + + "MUL temp2.z, temp2.z, params7.z;" + // parallax + + "MUL temp2, temp2, temp2.z;" + + + "SUB temp, temp, temp2;" + + + "TEX temp, temp, texture[0], 2D;" + + "POW temp.a, temp.a, params6.w;" + // punch through + + "ADD texSamp, temp, texSamp;" + + "MUL texSamp.xyz, half, texSamp;" + + + "MOV alpha, texSamp.aaaa;" + + +// parallax mapping + + "MOV temp.x, texSamp.a;" + + "LRP texSamp, params5.x, texSamp, one;" + // texture proportion + //"LRP texSamp0, params5.x, texSamp0, one;" + + "MOV texSamp.a, temp.x;" + //"MOV temp, fragment.texcoord[0];" + // @@ -13369,8 +13482,19 @@ //once = true; } - System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); - System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); + String program = programmax; + + if (Globals.MINSHADER) + { + program = programmin; + } + + if (Globals.DEBUG) + { + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); + System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); + } + loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); //gl.glNewList(displayListID, GL.GL_COMPILE); @@ -13417,7 +13541,8 @@ "\n" + "END\n"; - System.out.println("Program shadow #" + 0 + "; length = " + program.length()); + if (Globals.DEBUG) + System.out.println("Program shadow #" + 0 + "; length = " + program.length()); loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); //gl.glNewList(displayListID, GL.GL_COMPILE); @@ -13675,7 +13800,7 @@ /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough - /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power + /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax //Object3D.cVector2[] vector2buffer; @@ -13842,7 +13967,7 @@ "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" + "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" + "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" + - "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" + + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" + "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" + //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" + @@ -13903,7 +14028,7 @@ "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" + "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" + "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" + - //"MOV result.texcoord, vertex.texcoord;" + + //"MOV result.texcoord, vertex.fogcoord;" + "MOV result.texcoord, temp;" + // border fade "MOV result.texcoord[3], vertex.texcoord;" + @@ -13950,7 +14075,9 @@ //"ADD temp.z, temp.z, one;" + - "MOV result.color, temp;" + "MOV result.texcoord[4], vertex.attrib[4];" + // U dir + + "MOV result.color, temp;" // Normal : "MOV result.color, vertex.color;") + ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;" : "") + @@ -14609,18 +14736,24 @@ } } PingThread pingthread = new PingThread(); - int delta = 5; - int speed = 5; + int delta = 2; + int speed = 10; boolean autorepeat = false; void GoDown(int mod) { MODIFIERS |= COMMAND; + boolean isVR = (mouseMode&VR)!=0; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(0, -speed); + { + if (isVR) + manipCamera.RotateInterest(0, -speed); + else + manipCamera.RotatePosition(0, -speed); + } else - manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); /**/ if ((mod & SHIFT) == SHIFT) { @@ -14630,6 +14763,8 @@ mouseMode |= BACKFORTH; } + targetLookAt.set(manipCamera.lookAt); + //prevX = X = anchorX; prevY = Y = anchorY - (int) (renderCamera.Distance()); } @@ -14638,10 +14773,17 @@ { MODIFIERS |= COMMAND; /**/ + boolean isVR = (mouseMode&VR)!=0; + if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(0, speed); + { + if (isVR) + manipCamera.RotateInterest(0, speed); + else + manipCamera.RotatePosition(0, speed); + } else - manipCamera.BackForth(0, speed*delta, 0); // getWidth()); + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); /**/ if ((mod & SHIFT) == SHIFT) { @@ -14651,6 +14793,8 @@ mouseMode |= BACKFORTH; } + targetLookAt.set(manipCamera.lookAt); + //prevX = X = anchorX; prevY = Y = anchorY + (int) (renderCamera.Distance()); } @@ -14660,9 +14804,14 @@ MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.Translate(speed*delta, 0, getWidth()); + manipCamera.Translate(speed*delta, 0, getWidth()); else - manipCamera.RotatePosition(speed, 0); + { + if ((mouseMode&VR)!=0) + manipCamera.RotateInterest(-speed, 0); + else + manipCamera.RotatePosition(speed, 0); + } /**/ if ((mod & SHIFT) == SHIFT) { @@ -14672,6 +14821,8 @@ mouseMode |= ROTATE; } // TRANSLATE; + targetLookAt.set(manipCamera.lookAt); + prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); prevY = Y = anchorY; } @@ -14681,9 +14832,15 @@ MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.Translate(-speed*delta, 0, getWidth()); + manipCamera.Translate(-speed*delta, 0, getWidth()); else - manipCamera.RotatePosition(-speed, 0); + { + if ((mouseMode&VR)!=0) + manipCamera.RotateInterest(speed, 0); + else + manipCamera.RotatePosition(-speed, 0); + } + /**/ if ((mod & SHIFT) == SHIFT) { @@ -14693,6 +14850,8 @@ mouseMode |= ROTATE; } // TRANSLATE; + targetLookAt.set(manipCamera.lookAt); + prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); prevY = Y = anchorY; } @@ -15195,8 +15354,8 @@ case 'K': KOMPACTTEXTURE ^= true; //textures.clear(); - break; - case 'P': // Texture Projection macros + // break; + //case 'P': // Texture Projection macros // SAVETEXTURE ^= true; macromode = true; Udebug = Vdebug = NORMALdebug = false; programInitialized = false; @@ -15317,7 +15476,7 @@ targetLookAt.set(manipCamera.lookAt); repaint(); break; - case 'p': + case 'P': // p': // c'est quoi ca au juste? spherical ^= true; Skinshader ^= true; programInitialized = false; repaint(); @@ -15355,14 +15514,14 @@ repaint(); break; case 'O': - Globals.drawMode = OCCLUSION; // WARNING + // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING repaint(); break; case 'o': OCCLUSION_CULLING ^= true; System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); break; - case '0': envyoff ^= true; repaint(); break; + //case '0': envyoff ^= true; repaint(); break; case '1': case '2': case '3': @@ -15372,7 +15531,7 @@ case '7': case '8': case '9': - if (envyoff) + if (true) // envyoff) { BGcolor = (key - '1')/8.f; } @@ -16077,14 +16236,14 @@ { switch (hitSomething) { - case Object3D.hitCenter: gr.setColor(Color.pink); + case Object3D.hitCenter: gr.setColor(Color.white); gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; case Object3D.hitRotate: gr.setColor(Color.yellow); gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; case Object3D.hitScale: gr.setColor(Color.cyan); - gr.drawLine(X, Y, 0, 0); + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; } @@ -16103,7 +16262,7 @@ if (hasMarquee) { gr.setXORMode(Color.white); - gr.setColor(Color.red); + gr.setColor(Color.white); if (!firstime) { gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); @@ -16570,6 +16729,8 @@ private /*static*/ boolean firstime; private /*static*/ cVector newView = new cVector(); private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, @@ -16582,22 +16743,56 @@ { com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); + int usedsuf = 0; + for (int i = 0; i < suffixes.length; i++) { - String resourceName = basename + suffixes[i] + "." + suffix; - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), - mipmapped, - FileUtil.getFileSuffix(resourceName)); - if (data == null) + String[] suffixe = suffixes; + String[] fallback = suffixes2; + String[] fallfallback = suffixes3; + + for (int c=usedsuf; --c>=0;) { - throw new IOException("Unable to load texture " + resourceName); +// String[] temp = suffixe; +// suffixe = fallback; +// fallback = fallfallback; +// fallfallback = temp; } + + String resourceName = basename + suffixe[i] + "." + suffix; + TextureData data; + + try + { + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + catch (Exception e) + { + try + { + resourceName = basename + fallback[i] + "." + suffix; + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + catch (Exception e2) + { + resourceName = basename + fallfallback[i] + "." + suffix; + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + } + //System.out.println("Target = " + targets[i]); cubemap.updateImage(data, targets[i]); } return cubemap; } + int bigsphere = -1; float BGcolor = 0.5f; @@ -16606,7 +16801,9 @@ private void DrawSkyBox(GL gl, float ratio) { - if (envyoff || cubemap == null) + if (//envyoff || + WIREFRAME || + cubemap == null) { gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); gl.glClear(gl.GL_COLOR_BUFFER_BIT); @@ -16623,14 +16820,14 @@ gl.glLoadIdentity(); gl.glScalef(1,ratio,1); - colorV[0] = 2; - colorV[1] = 2; - colorV[2] = 2; - colorV[3] = 1; - gl.glDisable(gl.GL_COLOR_MATERIAL); - gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); - - gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); +// colorV[0] = 2; +// colorV[1] = 2; +// colorV[2] = 2; +// colorV[3] = 1; +// gl.glDisable(gl.GL_COLOR_MATERIAL); +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); +// +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); //gl.glActiveTexture(GL.GL_TEXTURE1); //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); @@ -16644,7 +16841,7 @@ // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting // causes the normals to be sent down. Thanks to Ken Dyke. //gl.glEnable(GL.GL_LIGHTING); - gl.glEnable(GL.GL_LIGHTING); + gl.glDisable(GL.GL_LIGHTING); gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); @@ -16663,6 +16860,7 @@ { gl.glScalef(1.0f, -1.0f, 1.0f); } + gl.glScalef(-1.0f, 1.0f, 1.0f); gl.glMultMatrixd(viewrot_1, 0); gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); //viewer.updateInverseRotation(gl); @@ -16703,7 +16901,8 @@ gl.glDisable(GL.GL_TEXTURE_GEN_R); cubemap.disable(); - ////cubemap.unbind(); + //cubemap.dispose(); + if (CULLFACE) { gl.glEnable(gl.GL_CULL_FACE); @@ -16759,7 +16958,7 @@ gl.glScalef(1.0f, -1.0f, 1.0f); } - gl.glNormal3f(0.0f, 0.0f, 1.0f); + SetGLNormal(gl, 0.0f, 0.0f, 1.0f); float step = 2; // 0.1666f; //0.25f; float stepv = 2; // step * 1652 / 998; @@ -17239,6 +17438,7 @@ public void init(GLAutoDrawable drawable) { + if (Globals.DEBUG) System.out.println("shadow buffer init"); GL gl = drawable.getGL(); @@ -17467,10 +17667,14 @@ gl.glFlush(); /**/ - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); - float[] pixels = occlusionsizebuffer.array(); + float[] depths = occlusiondepthbuffer.array(); + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); + + int[] pixels = selectsizebuffer.array(); + double r = 0, g = 0, b = 0; double count = 0; @@ -17481,7 +17685,7 @@ double FACTOR = 1; - for (int i = 0; i < pixels.length; i++) + for (int i = 0; i < depths.length; i++) { int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; @@ -17564,7 +17768,7 @@ double scale = ray.z; // 1; // cos - float depth = pixels[newindex]; + float depth = depths[newindex]; /* int newindex2 = (x + 1) * OCCLUSION_SIZE + y; @@ -17761,11 +17965,14 @@ static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); static IntBuffer bigAAbuffer; static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); + + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); + static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); -- Gitblit v1.6.2