From 57c5b6cd8d12ffdaa3e0b099451e3c031012750a Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Thu, 03 Oct 2019 20:34:32 -0400 Subject: [PATCH] Fix lighttouched --- CameraPane.java | 4804 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 3,892 insertions(+), 912 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index 073c943..b60cf14 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -1,4 +1,5 @@ +import com.bulletphysics.dynamics.RigidBody; import java.awt.*; import java.awt.event.*; import java.awt.image.*; @@ -18,7 +19,10 @@ import javax.imageio.ImageIO; import javax.imageio.ImageWriteParam; import javax.imageio.ImageWriter; +import javax.imageio.ImageReadParam; +import javax.imageio.ImageReader; import javax.imageio.plugins.jpeg.JPEGImageWriteParam; +import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.ImageOutputStream; import javax.imageio.ImageWriteParam; @@ -30,10 +34,14 @@ import java.nio.*; import gleem.linalg.Mat4f; +import javax.imageio.ImageTypeSpecifier; -class CameraPane extends GLCanvas implements Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener +class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener { - static boolean DEBUG = false; + static cMaterial[] materialstack = new cMaterial[65536]; + static boolean[] selectedstack = new boolean[65536]; + static int materialdepth = 0; + static boolean FRUSTUM = false; // still bogus true; // frustum culling // camera change fix @@ -42,25 +50,40 @@ static int STEP = 1; - static boolean ONESTEP = false; // do LIVE once - - /** - * @return the LIVE - */ - public static boolean isLIVE() + private static BufferedImage CreateBim(byte[] bytes, int width, int height) { - return LIVE || ONESTEP; + int[] pixels = new int[bytes.length/3]; + for (int i=pixels.length; --i>=0;) + { + int i3 = i*3; + pixels[i] = 0xFF; + pixels[i] <<= 8; + pixels[i] |= bytes[i3+2] & 0xFF; + pixels[i] <<= 8; + pixels[i] |= bytes[i3+1] & 0xFF; + pixels[i] <<= 8; + pixels[i] |= bytes[i3] & 0xFF; + } + /* + int r=0,g=0,b=0,a=0; + for (int i=0; i<width; i++) + for (int j=0; j<height; j++) + { + int index = j*width+i; + int p = pixels[index]; + a = ((p>>24) & 0xFF); + r = ((p>>16) & 0xFF); + g = ((p>>8) & 0xFF); + b = (p & 0xFF); + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; + } + /**/ + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); + return rendImage; } - /** - * @param aLIVE the LIVE to set - */ - public static void setLIVE(boolean aLIVE) - { - LIVE = aLIVE; - } - - /*static*/ boolean CULLFACE = false; // true; + /*static*/ private boolean CULLFACE = false; // true; /*static*/ boolean NEAREST = false; // true; /*static*/ boolean WIREFRAME = false; // true; @@ -70,14 +93,12 @@ static int CURRENTANTIALIAS = 0; // 1; /*static*/ boolean RENDERSHADOW = true; /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal - static boolean ANIMATION = false; - static String filename; boolean DISPLAYTEXT = false; //boolean REDUCETEXTURE = true; boolean CACHETEXTURE = true; boolean CLEANCACHE = false; // true; - boolean MIPMAP = false; // true; + boolean MIPMAP = false; // true; // never works... boolean COMPRESSTEXTURE = false; boolean KOMPACTTEXTURE = false; // true; boolean RESIZETEXTURE = false; @@ -90,27 +111,31 @@ //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 static boolean textureon = true; static boolean LOCALTRANSFORM = false; -private static boolean LIVE = false; static boolean FULLSCREEN = false; static boolean SUPPORT = true; -static boolean CROWD = false; -static boolean INERTIA = true; +static boolean INERTIA = false; // true; static boolean FAST = false; static boolean SLOWPOSE = false; static boolean FOOTCONTACT = true; static int tickcount = 0; // slow pose issue +static boolean BUTTONLESSWHEEL = false; +static boolean ZOOMBOXMODE = false; static boolean BOXMODE = false; static boolean IMAGEFLIP = false; -static boolean SMOOTHFOCUS = false; +static boolean SMOOTHFOCUS = true; // false; static boolean SPEAKERMOCAP = true; // jan 2014 false; static boolean SPEAKERCAMERA = false; static boolean SPEAKERFOCUS = false; @@ -122,7 +147,7 @@ static boolean OEIL = true; static boolean OEILONCE = false; // do oeilon then oeiloff static boolean LOOKAT = true; -static boolean RANDOM = true; // false; +static boolean SWITCH = true; // false; static boolean HANDLES = false; // selection doesn't work!! static boolean PAINTMODE = false; @@ -144,16 +169,16 @@ // OPTIONS - boolean Skinshader = true; + boolean Skinshader = false; // true; boolean cameraLight = false; boolean UVdebug = false; boolean Udebug = false; boolean Vdebug = false; boolean NORMALdebug = false; - static boolean doublesided = false; // true; // reversed normals are awful for conformance + static boolean doublesided = true; // false; // 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; @@ -165,12 +190,55 @@ defaultcaps.setAccumBlueBits(16); defaultcaps.setAccumAlphaBits(16); } - static CameraPane theRenderer; + + private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException + { + try + { + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); + } catch (IOException e) + { + System.out.println("NAME = " + name); + e.printStackTrace(); // throw new RuntimeException(e); + return null; + } + } + void SetAsGLRenderer(boolean b) { isRenderer = b; - theRenderer = this; + Globals.theRenderer = this; + } + + CameraPane(Object3D o, Camera cam, boolean withcontext) + { + super(defaultcaps, null, withcontext?glcontext:null, null); + + //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523)); + glcontext = getContext(); + + cameras = new Camera[2]; + targetLookAts = new cVector[2]; + + SetCamera(cam, true); + + // Warning: not used. + //SetLight(new Camera(new cVector(15, 10, -20))); + + object = o; + + setBackground(Color.white); + + addKeyListener(this); + addMouseListener(this); + addMouseMotionListener(this); + addMouseWheelListener(this); + //System.out.println("addGLEventListener: " + this); + addGLEventListener(this); + +// pingthread.start(); // may 2013 } static boolean AntialiasingEnabled() @@ -178,12 +246,53 @@ return CURRENTANTIALIAS > 0; } - void ClearDepth() + /// INTERFACE + + public javax.media.opengl.GL GetGL0() + { + return currentGL; + } + + public int GenList() + { + javax.media.opengl.GL gl = GetGL(); + return gl.glGenLists(1); + } + + public void NewList(int id) + { + javax.media.opengl.GL gl = GetGL(); + gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE); + } + + public void CallList(int id) + { + javax.media.opengl.GL gl = GetGL(); + gl.glCallList(id); + } + + public void EndList() + { + javax.media.opengl.GL gl = GetGL(); + gl.glEndList(); + } + + public boolean IsBoxMode() + { + return BOXMODE; + } + + public boolean IsZoomBoxMode() + { + return ZOOMBOXMODE; + } + + public void ClearDepth() { GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT); } - void DepthTest(boolean depthtest) + public void DepthTest(boolean depthtest) { if (depthtest) GetGL().glDepthFunc(GL.GL_LEQUAL); @@ -191,7 +300,7 @@ GetGL().glDepthFunc(GL.GL_ALWAYS); } - void DepthWrite(boolean depthwrite) + public void DepthWrite(boolean depthwrite) { if (depthwrite) GetGL().glDepthMask(true); @@ -199,12 +308,1617 @@ GetGL().glDepthMask(false); } - void BackFaceCull(boolean bfc) + public void BackFaceCull(boolean bfc) { if (bfc) GetGL().glEnable(GetGL().GL_CULL_FACE); else GetGL().glDisable(GetGL().GL_CULL_FACE); + } + + public boolean BackFaceCullMode() + { + return this.CULLFACE; + } + + public boolean IsAmbientOcclusionOn() + { + return this.ambientOcclusion; + } + + public boolean IsDebugSelection() + { + return DEBUG_SELECTION; + } + + public boolean IsFrozen() + { + boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection(); + + return !selectmode && cameracount == 0; // != 0; + } + + // Currently in Globals + public int DrawMode() + { + return Globals.DrawMode(); + } + + public Camera EyeCamera() + { + return eyeCamera; + } + + public Camera LightCamera() + { + return lightCamera; + } + + public Camera ManipCamera() + { + return manipCamera; + } + + public Camera RenderCamera() + { + return renderCamera; + } + + public Camera[] Cameras() + { + return cameras; + } + + public void PushMaterial(Object3D obj, boolean selected) + { + CameraPane display = this; + javax.media.opengl.GL gl = display.GetGL(); + cMaterial material = obj.material; + + if (material != null) + { + materialstack[materialdepth] = material; + selectedstack[materialdepth] = selected; + cStatic.objectstack[materialdepth++] = obj; + //System.out.println("material " + material); + //Applet3D.tracein(this, selected); + //display.vector2buffer = obj.projectedVertices; + if (obj instanceof Camera) + { + display.options1[0] = material.shift; + //System.out.println("shift " + material.shift); + display.options1[1] = material.lightarea; + display.options1[2] = material.shadowbias; + display.options1[3] = material.aniso; + display.options1[4] = material.anisoV; +// System.out.println("display.options1[0] " + display.options1[0]); +// System.out.println("display.options1[1] " + display.options1[1]); +// System.out.println("display.options1[2] " + display.options1[2]); +// System.out.println("display.options1[3] " + display.options1[3]); +// System.out.println("display.options1[4] " + display.options1[4]); + display.options2[0] = material.opacity; + display.options2[1] = material.diffuse; + display.options2[2] = material.factor; +// System.out.println("display.options2[0] " + display.options2[0]); +// System.out.println("display.options2[1] " + display.options2[1]); +// System.out.println("display.options2[2] " + display.options2[2]); + + cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3); +// System.out.println("display.options3[0] " + display.options3[0]); +// System.out.println("display.options3[1] " + display.options3[1]); +// System.out.println("display.options3[2] " + display.options3[2]); + display.options4[0] = material.cameralight/0.2f; + display.options4[1] = material.subsurface; + display.options4[2] = material.sheen; +// System.out.println("display.options4[0] " + display.options4[0]); +// System.out.println("display.options4[1] " + display.options4[1]); +// System.out.println("display.options4[2] " + display.options4[2]); + + // if (display.CURRENTANTIALIAS > 0) + // display.options3[3] /= 4; + + /* + System.out.println("Focus = " + display.options1[0]); + System.out.println("Aperture = " + display.options1[1]); + System.out.println("ShadowBlur = " + display.options1[2]); + System.out.println("Antialiasing = " + display.options1[3]); + System.out.println("Fog = " + display.options2[0]); + System.out.println("Intensity = " + display.options2[1]); + System.out.println("Elevation = " + display.options2[2]); + /**/ + } else + { + DrawMaterial(material, selected, obj.projectedVertices); + } + } else + { + if (selected && CameraPane.flash) + { + display.modelParams4[1] = 100; + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0); + } + } + } + + public void PushMaterial2(Object3D obj, boolean selected) + { + CameraPane display = this; + cMaterial material = obj.material; + + if (material != null) + { + materialstack[materialdepth] = material; + selectedstack[materialdepth] = selected; + cStatic.objectstack[materialdepth++] = obj; + //System.out.println("material " + material); + //Applet3D.tracein("selected ", selected); + //display.vector2buffer = obj.projectedVertices; + display.DrawMaterial(material, selected, obj.projectedVertices); + } + } + + public void PopMaterial(Object3D obj, boolean selected) + { + CameraPane display = this; + javax.media.opengl.GL gl = display.GetGL(); + cMaterial material = obj.material; + + //if (parent != null && parent.GetMaterial() != null) + // parent.GetMaterial().Draw(display, parent.IsSelected(this)); + if (material != null) + { + materialdepth -= 1; + if (materialdepth > 0) + { + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); + } + //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); + } else if (selected && CameraPane.flash && obj.GetMaterial() != null) + { + display.modelParams4[1] = obj.GetMaterial().cameralight; + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0); + } + } + + public void PopMaterial2(Object3D obj) + { + CameraPane display = this; + cMaterial material = obj.material; + + if (material != null) + { + materialdepth -= 1; + if (materialdepth > 0) + { + //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; + display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); + } + //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???"); + //else + //material.Draw(display, false); + } + } + + public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face) + { + CameraPane display = this; + + if (pv.y == -10000 || + qv.y == -10000 || + rv.y == -10000) + return; + +// float b = f.nbiterations & 1; +// float g = (f.nbiterations>>1) & 1; +// float r = (f.nbiterations>>2) & 1; +// +// //if (f.weight == 10000) +// //{ +// // r = 1; g = b = 0; +// //} +// //else +// //{ +// // assert(f.weight < 10000); +// r = g = b = (float)bRep.FaceWeight(f)*100; +// if (r<0) +// assert(r>=0); +// //} + + javax.media.opengl.GL gl = display.GetGL(); + + boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection(); + + //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv); + if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0) + { + //gl.glBegin(gl.GL_TRIANGLES); + boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0) + // TEST LIVE NORMALS && !obj.dontselect + ; + if (!hasnorm) + { + // System.out.println("Mesh normal"); + LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0); + LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1); + LA.vecCross(obj.v0, obj.v1, obj.v2); + LA.vecNormalize(obj.v2); + + SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z); + } + + // P + float x = (float)pv.x; + float y = (float)pv.y; + float z = (float)pv.z; + + if (hasnorm) + { +// if (!pv.norm.normalized()) +// assert(pv.norm.normalized()); + + //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z); + float nx = (float)pv.norm.x; + float ny = (float)pv.norm.y; + float nz = (float)pv.norm.z; + + x += nx * obj.NORMALPUSH; + y += ny * obj.NORMALPUSH; + z += nz * obj.NORMALPUSH; + + SetGLNormal(gl, nx, ny, nz); + } + gl.glColor4f(pv.AO, pv.AO, pv.AO, 1); + SetColor(obj, pv); + //gl.glColor4f(r, g, b, 1); + //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1); + if (obj.flipV) + gl.glTexCoord2f((float) pv.s, 1-(float) pv.t); + else + gl.glTexCoord2f((float) pv.s, (float) pv.t); + //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z); + + gl.glVertex3f(x, y, z); + + // Q + x = (float)qv.x; + y = (float)qv.y; + z = (float)qv.z; + +// Print(pv); + if (hasnorm) + { +// assert(qv.norm.normalized()); + //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z); + float nx = (float)qv.norm.x; + float ny = (float)qv.norm.y; + float nz = (float)qv.norm.z; + + x += nx * obj.NORMALPUSH; + y += ny * obj.NORMALPUSH; + z += nz * obj.NORMALPUSH; + + SetGLNormal(gl, nx, ny, nz); + } + //System.out.println("vertexq = " + qv.s + ", " + qv.t); + // boolean locked = false; + // float eps = 0.1f; + // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice + + // int dot = 0; //*/ (int)f.dot; + + // if ((dot&1) == 0) + // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1; + + // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) + if (obj.flipV) + gl.glTexCoord2f((float) qv.s, 1-(float) qv.t); + else + gl.glTexCoord2f((float) qv.s, (float) qv.t); + // else + // { + // locked = true; + // gl.glTexCoord2f((float) pv.s, (float) pv.t); + // } + gl.glColor4f(qv.AO, qv.AO, qv.AO, 1); + SetColor(obj, qv); + + gl.glVertex3f(x, y, z); + //gl.glColor4f(r, g, b, 1); + //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1); + //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z); +// Print(qv); + + // R + x = (float)rv.x; + y = (float)rv.y; + z = (float)rv.z; + + if (hasnorm) + { +// assert(rv.norm.normalized()); + //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z); + float nx = (float)rv.norm.x; + float ny = (float)rv.norm.y; + float nz = (float)rv.norm.z; + + x += nx * obj.NORMALPUSH; + y += ny * obj.NORMALPUSH; + z += nz * obj.NORMALPUSH; + + SetGLNormal(gl, nx, ny, nz); + } + + // if ((dot&4) == 0) + // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4; + + // if (wrap || !locked && (dot&8) != 0) + if (obj.flipV) + gl.glTexCoord2f((float) rv.s, 1-(float) rv.t); + else + gl.glTexCoord2f((float) rv.s, (float) rv.t); + // else + // gl.glTexCoord2f((float) pv.s, (float) pv.t); + + // f.dot = dot; + + gl.glColor4f(rv.AO, rv.AO, rv.AO, 1); + SetColor(obj, rv); + //gl.glColor4f(r, g, b, 1); + //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1); + //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z); + gl.glVertex3f(x, y, z); +// Print(rv); + //gl.glEnd(); + } + else + { + gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); + gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z); + gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z); + + } + + if (false) // (attributes & WIREFRAME) != 0) + { + gl.glDisable(gl.GL_LIGHTING); + + gl.glBegin(gl.GL_LINE_LOOP); + gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z); + gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z); + gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z); + gl.glEnd(); + + gl.glEnable(gl.GL_LIGHTING); + } + } + + /** + * <code>draw</code> renders a <code>TriMesh</code> object including + * it's normals, colors, textures and vertices. + * + * @see Renderer#draw(TriMesh) + * @param tris + * the mesh to render. + */ + public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris) + { + CameraPane display = this; + + float r = display.modelParams0[0]; + float g = display.modelParams0[1]; + float b = display.modelParams0[2]; + float opacity = display.modelParams5[1]; + + //final GL gl = GLU.getCurrentGL(); + GL gl = display.GetGL(); // getGL(); + + FloatBuffer vertBuf = geo.vertBuf; + + int v = vertBuf.capacity(); + + int count = 0; + + boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE); + gl.glEnable(gl.GL_CULL_FACE); + // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024); + for (int i=0; i<v/3; i++) + { + int index3 = i*3; + + if (geo.sizeBuf.get(index3+1) == 0) + continue; + + count++; + + int index4 = i*4; + + float tx = vertBuf.get(index3); + float ty = vertBuf.get(index3+1); + float tz = vertBuf.get(index3+2); + + // if (tx == 0 && ty == 0 && tz == 0) + // continue; + + gl.glMatrixMode(gl.GL_TEXTURE); + gl.glPushMatrix(); + + float[] texmat = geo.texmat; + texmat[12] = texmat[13] = texmat[14] = i; + + gl.glMultMatrixf(texmat, 0); + + gl.glMatrixMode(gl.GL_MODELVIEW); + gl.glPushMatrix(); + + gl.glTranslatef(tx,ty,tz); + + if (rotate) + gl.glRotatef(i, 0, 1, 0); + + float size = geo.sizeBuf.get(index3) / 100; + gl.glScalef(size,size,size); + + float cr = geo.colorBuf.get(index4); + float cg = geo.colorBuf.get(index4+1); + float cb = geo.colorBuf.get(index4+2); + float ca = geo.colorBuf.get(index4+3); + + display.modelParams0[0] = r * cr; + display.modelParams0[1] = g * cg; + display.modelParams0[2] = b * cb; + + display.modelParams5[1] = opacity * ca; + + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0); + + RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i; + RandomNode.globalseed2 = RandomNode.globalseed; + +// gl.glColor4f(cr,cg,cb,ca); + // gl.glScalef(1024/16,1024/16,1024/16); + shape.Draw/*Node*/(display,null,selected,false); // blocked + // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024); + //gl.glTranslatef(-tx,-ty,-tz); + gl.glPopMatrix(); + + gl.glMatrixMode(gl.GL_TEXTURE); + gl.glPopMatrix(); + } + // gl.glScalef(1024,1024,1024); + if (!cf) + gl.glDisable(gl.GL_CULL_FACE); + + display.modelParams0[0] = r; + display.modelParams0[1] = g; + display.modelParams0[2] = b; + + display.modelParams5[1] = opacity; + + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0); + + gl.glMatrixMode(gl.GL_MODELVIEW); + +// System.err.println("total = " + v/3 + "; displayed = " + count); + if (true) + return; + +//// if (!tris.predraw(this)) +//// { +//// return; +//// } +//// if (Debug.stats) +//// { +//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount()); +//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount()); +//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1); +//// } +//// +//// if (tris.getDisplayListID() != -1) +//// { +//// renderDisplayList(tris); +//// return; +//// } +//// +//// if (!generatingDisplayList) +//// { +//// applyStates(tris.states, tris); +//// } +//// if (Debug.stats) +//// { +//// StatCollector.startStat(StatType.STAT_RENDER_TIMER); +//// } +//// boolean transformed = doTransforms(tris); +// +// int glMode = GL.GL_TRIANGLES; +// switch (getMode()) +// { +// case Triangles: +// glMode = GL.GL_TRIANGLES; +// break; +// case Strip: +// glMode = GL.GL_TRIANGLE_STRIP; +// break; +// case Fan: +// glMode = GL.GL_TRIANGLE_FAN; +// break; +// } +// +// if (!predrawGeometry(gl)) +// { +// // make sure only the necessary indices are sent through on old +// // cards. +// IntBuffer indices = this.getIndexBuffer(); +// if (indices == null) +// { +// logger.severe("missing indices on geometry object: " + this.toString()); +// } else +// { +// indices.rewind(); +// indices.limit(this.getMaxIndex()); +// +// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT +// +// indices.clear(); +// } +// } else +// { +// gl.glDrawElements(glMode, this.getIndexBuffer().limit(), +// GL.GL_UNSIGNED_INT, 0); +// } +// +//// postdrawGeometry(tris); +//// if (transformed) +//// { +//// undoTransforms(tris); +//// } +//// +//// if (Debug.stats) +//// { +//// StatCollector.endStat(StatType.STAT_RENDER_TIMER); +//// } +//// tris.postdraw(this); + } + + static Camera localAOcamera = new Camera(); + static cVector from = new cVector(); + static cVector to = new cVector(); + + public void PrepOcclusion(BoundaryRep br, double[][] transform) + { + CameraPane cp = this; + + Camera keep = cp.RenderCamera(); + cp.renderCamera = localAOcamera; + + if (br.trimmed) + { + float[] colors = new float[br.positions.length / 3]; + + int i3 = 0; + for (int i = 0; i < br.positions.length / 3; i++, i3 += 3) + { + if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0) + continue; + + from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]); + to.set(br.positions[i3] + br.normals[i3], + br.positions[i3 + 1] + br.normals[i3 + 1], + br.positions[i3 + 2] + br.normals[i3 + 2]); + LA.xformPos(from, transform, from); + LA.xformPos(to, transform, to); // RIGID ONLY + localAOcamera.setAim(from, to); + + CameraPane.occlusionbuffer.display(); + + if (CameraPane.DEBUG_OCCLUSION) + cp.display(); // debug + + colors[i] = cp.vertexOcclusion.r; + //colors[i3 + 1] = cp.vertexOcclusion.g; + //colors[i3 + 2] = cp.vertexOcclusion.b; + + if ((i % 100) == 0 && i != 0) + { + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); + //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done"); + System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")"); + } + } + + br.colors = colors; + } + else + { + for (int i = 0; i < br.VertexCount(); i++) + { + Vertex v = br.GetVertex(i); + + if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0) + continue; + + from.set(v.x, v.y, v.z); + 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 + localAOcamera.setAim(from, to); + + CameraPane.occlusionbuffer.display(); + + if (CameraPane.DEBUG_OCCLUSION) + cp.display(); // debug + + v.AO = cp.vertexOcclusion.r; + + if ((i % 100) == 0 && i != 0) + { + Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); + //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done"); + System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")"); + } + } + } + + //System.out.println("done."); + + cp.renderCamera = keep; + } + + void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked) + { + CameraPane display = this; + pointFlow.CreateHT(); + + float r = display.modelParams0[0]; + float g = display.modelParams0[1]; + float b = display.modelParams0[2]; + float opacity = display.modelParams5[1]; + + //final GL gl = GLU.getCurrentGL(); + GL gl = display.GetGL(); // getGL(); + + int s = pointFlow.points.size(); + + boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE); + gl.glEnable(gl.GL_CULL_FACE); + + for (int i=s; --i>=0;) + //for (int i=0; i<s; i++) + { + cVector v = pointFlow.points.get(i); + + double mindist = Double.MAX_VALUE; + + double size = pointFlow.minimumSize; + + double distancenext = 0; + + if (i > 0) + { + cVector w = pointFlow.points.get(i-1); + + double dist = w.distance(v); + + distancenext = dist; + + if (mindist > dist) + { + mindist = dist; + size = mindist*pointFlow.resizefactor; + } + } + + if (i < s-1) + { + cVector w = pointFlow.points.get(i+1); + + double dist = w.distance(v); + + if (mindist > dist) + { + mindist = dist; + size = mindist*pointFlow.resizefactor; + } + } + + if (size < pointFlow.minimumSize) + size = pointFlow.minimumSize; + if (size > pointFlow.maximumSize) + size = pointFlow.maximumSize; + + double tx = v.x; + double ty = v.y; + double tz = v.z; + + // if (tx == 0 && ty == 0 && tz == 0) + // continue; + + gl.glMatrixMode(gl.GL_TEXTURE); + gl.glPushMatrix(); + pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i; + + gl.glMultMatrixf(pointFlow.texmat, 0); + + gl.glMatrixMode(gl.GL_MODELVIEW); + gl.glPushMatrix(); + + gl.glTranslated(tx,ty,tz); + + gl.glScaled(size,size,size); + +// float cr = colorBuf.get(index4); +// float cg = colorBuf.get(index4+1); +// float cb = colorBuf.get(index4+2); +// float ca = colorBuf.get(index4+3); +// +// display.modelParams0[0] = r * cr; +// display.modelParams0[1] = g * cg; +// display.modelParams0[2] = b * cb; +// +// display.modelParams5[1] = opacity * ca; +// +// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0); +// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0); +// +// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i; +// RandomNode.globalseed2 = RandomNode.globalseed; +// +//// gl.glColor4f(cr,cg,cb,ca); +// // gl.glScalef(1024/16,1024/16,1024/16); + pointFlow.geo.Draw/*Node*/(display,null,selected, blocked); + + gl.glPopMatrix(); + + double step = size/4; // + + if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step) + continue; + + int nbsteps = (int)(distancenext/step); + + step = distancenext/nbsteps; + + cVector next = pointFlow.points.get(i-1); + + tmp.set(next); + tmp.sub(v); + tmp.normalize(); + tmp.mul(step); + + // calculate next size + mindist = Double.MAX_VALUE; + + double nextsize = pointFlow.minimumSize; + + if (i > 1) + { + cVector w = pointFlow.points.get(i-2); + + double dist = w.distance(next); + + if (mindist > dist) + { + mindist = dist; + nextsize = mindist*pointFlow.resizefactor; + } + } + + double dist = v.distance(next); + + if (mindist > dist) + { + mindist = dist; + nextsize = mindist*pointFlow.resizefactor; + } + + if (nextsize < pointFlow.minimumSize) + nextsize = pointFlow.minimumSize; + if (nextsize > pointFlow.maximumSize) + nextsize = pointFlow.maximumSize; + // + + double count = 0; + + while (distancenext > 0.000000001) // step + { + gl.glPushMatrix(); + + gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count); + + double K = count/nbsteps; + + double intersize = K*nextsize + (1-K)*size; + + gl.glScaled(intersize,intersize,intersize); + + pointFlow.geo.Draw/*Node*/(display,null,selected,blocked); + + count++; + + distancenext -= step; + + gl.glPopMatrix(); + } + + if (count != nbsteps) + assert(count == nbsteps); + + // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024); + //gl.glTranslatef(-tx,-ty,-tz); + + gl.glMatrixMode(gl.GL_TEXTURE); + gl.glPopMatrix(); + } + + if (!cf) + gl.glDisable(gl.GL_CULL_FACE); + +// display.modelParams0[0] = r; +// display.modelParams0[1] = g; +// display.modelParams0[2] = b; +// +// display.modelParams5[1] = opacity; +// +// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0); +// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0); + + gl.glMatrixMode(gl.GL_MODELVIEW); + } + + public void DrawBox(cVector min, cVector max) + { + javax.media.opengl.GL gl = GetGL(); + gl.glBegin(gl.GL_LINES); + + gl.glVertex3d(min.x, min.y, min.z); + gl.glVertex3d(min.x, min.y, max.z); + gl.glVertex3d(min.x, min.y, min.z); + gl.glVertex3d(min.x, max.y, min.z); + gl.glVertex3d(min.x, min.y, min.z); + gl.glVertex3d(max.x, min.y, min.z); + + gl.glVertex3d(max.x, max.y, max.z); + gl.glVertex3d(min.x, max.y, max.z); + gl.glVertex3d(max.x, max.y, max.z); + gl.glVertex3d(max.x, min.y, max.z); + gl.glVertex3d(max.x, max.y, max.z); + gl.glVertex3d(max.x, max.y, min.z); + + gl.glEnd(); + } + + public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode) + { + int[] strips = bRep.getRawIndices(); + + javax.media.opengl.GL gl = GetGL(); + + // TRIANGLE STRIP ARRAY + if (bRep.trimmed) + { + float[] v = bRep.getRawVertices(); + float[] n = bRep.getRawNormals(); + float[] c = bRep.getRawColors(); + float[] uv = bRep.getRawUVMap(); + + int count2 = 0; + int count3 = 0; + + if (n.length > 0) + { + for (int i = 0; i < strips.length; i++) + { + gl.glBegin(gl.GL_TRIANGLE_STRIP); + + /* + boolean locked = false; + float eps = 0.1f; + boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice + + int dot = 0; + + if ((dot&1) == 0) + dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1; + + if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) + gl.glTexCoord2f((float) qv.s, (float) qv.t); + else + { + locked = true; + gl.glTexCoord2f((float) pv.s, (float) pv.t); + } + //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z); + gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z); + if (hasnorm) + { + //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z); + gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z); + } + + if ((dot&4) == 0) + dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4; + + if (wrap || !locked && (dot&8) != 0) + gl.glTexCoord2f((float) rv.s, (float) rv.t); + else + gl.glTexCoord2f((float) pv.s, (float) pv.t); + + f.dot = dot; + */ + + if (!selectmode) + { + if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) + { + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); + } else + { + SetGLNormal(gl, 0, 0, 1); + } + + if (c != null) + //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]); + { + gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); + } + } + + if (flipV) + gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); + else + gl.glTexCoord2f(uv[count2], uv[count2 + 1]); + + //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); + gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); + + count2 += 2; + count3 += 3; + if (!selectmode) + { + if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) + { + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); + } else + { + SetGLNormal(gl, 0, 0, 1); + } + if (c != null) + { + gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); + } + } + + if (flipV) + gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); + else + gl.glTexCoord2f(uv[count2], uv[count2 + 1]); + + //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]); + gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); + + count2 += 2; + count3 += 3; + for (int j = 0; j < strips[i] - 2; j++) + { + //gl.glTexCoord2d(...); + if (!selectmode) + { + if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) + { + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); + } else + { + SetGLNormal(gl, 0, 0, 1); + } + if (c != null) + { + gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1); + } + } + + if (flipV) + gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]); + else + gl.glTexCoord2f(uv[count2], uv[count2 + 1]); + + //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]); + gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]); + + count2 += 2; + count3 += 3; + } + + gl.glEnd(); + } + } + + assert count3 == v.length; + } + else // !trimmed + { + int count = 0; + for (int i = 0; i < strips.length; i++) + { + gl.glBegin(gl.GL_TRIANGLE_STRIP); + + Vertex p = bRep.GetVertex(bRep.indices[count++]); + Vertex q = bRep.GetVertex(bRep.indices[count++]); + + drawVertex(gl, p, flipV, selectmode); + drawVertex(gl, q, flipV, selectmode); + + for (int j = 0; j < strips[i] - 2; j++) + { + Vertex r = bRep.GetVertex(bRep.indices[count++]); + + // if (j%2 == 0) + // drawFace(p, q, r, display, null); + // else + // drawFace(p, r, q, display, null); + + // p = q; + // q = r; + drawVertex(gl, r, flipV, selectmode); + } + + gl.glEnd(); + } + } + } + + static cSpring.Point3D temp = new cSpring.Point3D(); + static cSpring.Point3D temp2 = new cSpring.Point3D(); + static cSpring.Point3D temp3 = new cSpring.Point3D(); + + public void DrawDynamicMesh(cMesh mesh) + { + GL gl = GetGL(); // getGL(); + + cSpring.PhysicsController3D Phys = mesh.Phys; + + gl.glDisable(gl.GL_LIGHTING); + + gl.glLineWidth(1); + gl.glColor3f(1,1,1); + gl.glBegin(gl.GL_LINES); + double scale = 0; + int count = 0; + for (int s=0; s<Phys.allSprings.size(); s++) + { + cSpring.Spring spring = Phys.allSprings.get(s); + if(s == 0) + { + //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position); + } + if (mesh.showsprings) + { + temp.set(spring.a.position); + temp.add(spring.b.position); + temp.mul(0.5); + temp2.set(spring.a.position); + temp2.sub(spring.b.position); + temp2.mul(spring.restLength/2); + temp.sub(temp2); + gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z); + temp.add(temp2); + temp.add(temp2); + gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z); + } + + if (spring.isHandle) + continue; + + //if (scale < spring.restLength) + scale += spring.restLength; + count++; + } + gl.glEnd(); + + if (count == 0) + scale = 0.01; + else + scale /= count * 3; + + //scale = 0.25; + + if (mesh.ShowInfo()) + { + gl.glLineWidth(4); + for (int s=0; s<Phys.allNodes.size(); s++) + { + cSpring.DynamicNode node = Phys.allNodes.get(s); + if (node.mass == 0) + continue; + + int i = node.springs==null?-1:node.springs.size(); + gl.glColor3f((i>>2)&1,(i>>1)&1,i&1); + //temp.set(node.springForce.x, node.springForce.y, node.springForce.z); + //temp.normalize(); + //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2); + gl.glBegin(gl.GL_LINES); + gl.glVertex3d(node.position.x, node.position.y, node.position.z); + //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale); + gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale, + node.position.y + mesh.bRep.GetVertex(s).norm.y*scale, + node.position.z + mesh.bRep.GetVertex(s).norm.z*scale); + gl.glEnd(); + } + + gl.glLineWidth(8); + for (int s=0; s<Phys.allNodes.size(); s++) + { + cSpring.DynamicNode node = Phys.allNodes.get(s); + + if (node.springs != null) + { + for (int i=0; i<node.springs.size(); i+=1) + { + cSpring.DynamicNode f = node.springs.get(i).GetOther(node); + + int c = i+1; + // c = node.springs.get(i).nbcopies; + + gl.glColor3f((c>>2)&1,(c>>1)&1,c&1); + gl.glBegin(gl.GL_LINES); + gl.glVertex3d(node.position.x, node.position.y, node.position.z); + gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3); + gl.glEnd(); + } + } + } + + gl.glLineWidth(1); + } + + gl.glEnable(gl.GL_LIGHTING); + } + + /// INTERFACE + + public void StartTriangles() + { + javax.media.opengl.GL gl = GetGL(); + gl.glBegin(gl.GL_TRIANGLES); + } + + public void EndTriangles() + { + GetGL().glEnd(); + } + + void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode) + { + if (!selectmode) + { + 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) + gl.glTexCoord2f((float) pv.s, 1-(float) pv.t); + else + gl.glTexCoord2f((float) pv.s, (float) pv.t); + } + + gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); + } + + float[] colorV = new float[4]; + + void SetColor(Object3D obj, Vertex p0) + { + CameraPane display = this; + BoundaryRep bRep = obj.bRep; + + if (RENDERPROGRAM == 0) + { + float r = 0; + if (bRep != null) + { + if (bRep.stripified) + { + r = 1; + } + } + float g = 0; + if (bRep != null) + { + if (bRep.trimmed) + { + g = 1; + } + } + float b = 0; + if (obj.support != null && obj.Link2Support()) + { + b = 1; + } + display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO); + return; + } + + if (display.DrawMode() != CameraPane.SHADOW) + return; + + javax.media.opengl.GL gl = display.GetGL(); +// if (true) return; +// float ao = p.AO; +// +// // if (ao == 0 && !bRep.AOdone) // transient problem! +// // ao = 1; +// +// gl.glColor4f(ao, ao, ao, 1); + +// CameraPane.selectedpoint. +// getAverage(cStatic.point1, true); + if (CameraPane.pointflow == null) // !random) // live) + { + return; + } + + cStatic.point1.set(0,0,0); + LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1); + + cStatic.point1.sub(p0); + + +// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta? +// { +// return; +// } + + //if (true) + if (cStatic.point1.dot(cStatic.point1) > 0.000001) + { + return; + } + + if (false) // marked) + { + // debug rigging weights + for (int object = 0; object < p0.vertexlinks.length; object++) + { + float weight = p0.weights[object] / p0.totalweight; + + // if (weight < 0.1) + // { + // assert(weight == 0); + // continue; + // } + + if (p0.vertexlinks[object] == -1) + continue; + + Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]); + + int color = //1 << object; // + //p.vertexlinks.length; + obj.support.bRep.supports[p0.closestsupport].links[object]; + colorV[2] += (color & 1) * weight; + colorV[1] += ((color & 2) >> 1) * weight; + colorV[0] += ((color & 4) >> 2) * weight; + } + } + else + { + if (obj.drawingstarted) + { + // find next point + if (bRep.GetVertex(0).faceindices == null) + { + bRep.InitFaceIndices(); + } + + double ymin = p0.y; + + Vertex newp = p0; + + for (int fii = 0; fii < p0.faceindices.length; fii++) + { + int fi = p0.faceindices[fii]; + + if (fi == -1) + break; + + Face f = bRep.GetFace(fi); + + Vertex p = bRep.GetVertex(f.p); + Vertex q = bRep.GetVertex(f.q); + Vertex r = bRep.GetVertex(f.r); + + int swap = (int)(Math.random()*3); + +// for (int s=swap; --s>=0;) +// { +// Vertex t = p; +// p = q; +// q = r; +// r = t; +// } + if (ymin > p.y) + { + ymin = p.y; + newp = p; +// break; + } + if (ymin > q.y) + { + ymin = q.y; + newp = q; +// break; + } + if (ymin > r.y) + { + ymin = r.y; + newp = r; +// break; + } + } + + CameraPane.selectedpoint.toParent[3][0] = newp.x; + CameraPane.selectedpoint.toParent[3][1] = newp.y; + CameraPane.selectedpoint.toParent[3][2] = newp.z; + + obj.drawingstarted = false; + + // return; + } + + if (false) // CameraPane.DRAW + { + p0.AO = colorV[0] = 2; + colorV[1] = 2; + colorV[2] = 2; + } + + CameraPane.pointflow.add(p0); + CameraPane.pointflow.Touch(); + } + +// gl.glColor3f(colorV[0], colorV[1], colorV[2]); +// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0); +// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0); + } + + void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others) + { + CameraPane display = this; + //new Exception().printStackTrace(); + + if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW) + { + return; + } + + javax.media.opengl.GL gl = display.GetGL(); + + //Color col = Color.getHSBColor(color,modulation,1); + //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0); + if (!material.multiply) + { + display.color = material.color; + display.saturation = material.modulation; + } + else + { + display.color *= material.color*2; + display.saturation *= material.modulation*2; + } + + cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0); + + float[] colorV = Grafreed.colorV; + + /**/ + if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0) + { + colorV[0] = display.modelParams0[0] * material.diffuse; + colorV[1] = display.modelParams0[1] * material.diffuse; + colorV[2] = display.modelParams0[2] * material.diffuse; + colorV[3] = 1; // material.opacity; + + gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity); + //System.out.println("Opacity = " + opacity); + + gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0); + //color[0] /= 2; color[1] /= 2; color[2] /= 2; + gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0); + + float amb = material.ambient; + if (amb < material.cameralight) + { + amb = material.cameralight; + } + colorV[0] = display.modelParams0[0] * material.diffuse * amb; + colorV[1] = display.modelParams0[1] * material.diffuse * amb; + colorV[2] = display.modelParams0[2] * material.diffuse * amb; + gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0); + //color[0] /= 2; color[1] /= 2; color[2] /= 2; + gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0); + + /**/ + colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular; + colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular; + colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular; + gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0); + //color[0] /= 2; color[1] /= 2; color[2] /= 2; + gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0); + colorV[0] = 10 / material.shininess; // 1/0.005f; + //System.out.println("shininess = " + colorV[0]); + if (colorV[0] > 128) + { + colorV[0] = 128; + } + gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0); + gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0); + /**/ + } + /**/ + + //selected = false; + selected = selected && display.flash; + + //display.modelParams0[0] = 0; // pigment.r; + //display.modelParams0[1] = 0; // pigment.g; + //display.modelParams0[2] = 0; // pigment.b; + if (!material.multiply) + { + display.modelParams0[3] = material.metalness; + display.modelParams1[0] = material.diffuse; + display.modelParams1[1] = material.specular; + display.modelParams1[2] = 1 / material.shininess; + display.modelParams1[3] = material.shift; + display.modelParams2[0] = material.ambient; + display.modelParams2[1] = material.lightarea; + //System.out.println("light area = " + lightarea); + display.modelParams2[2] = 1 / material.factor; // diffuseness + display.modelParams2[3] = material.velvet; + display.modelParams3[0] = material.sheen; + display.modelParams3[1] = material.subsurface; + display.modelParams3[2] = material.bump; // backlit + display.modelParams3[3] = material.aniso; + display.modelParams4[0] = material.anisoV; + display.modelParams4[1] = selected ? 100 : material.cameralight; + //System.out.println("selected = " + selected); + display.modelParams4[2] = material.diffuseness; + display.modelParams4[3] = material.shadow; + display.modelParams5[0] = material.texture; + display.modelParams5[1] = material.opacity; + display.modelParams5[2] = material.fakedepth; + display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10; + } + else + { + display.modelParams0[3] *= material.metalness*2; + display.modelParams1[0] *= material.diffuse*2; + display.modelParams1[1] *= material.specular*2; + display.modelParams1[2] *= material.shininess*2; + display.modelParams1[3] *= material.shift*2; + display.modelParams2[0] *= material.ambient*2; + display.modelParams2[1] *= material.lightarea*2; + display.modelParams2[2] *= material.factor*2; + display.modelParams2[3] *= material.velvet*2; + display.modelParams3[0] *= material.sheen*2; + display.modelParams3[1] *= material.subsurface*2; + display.modelParams3[2] *= material.bump*2; + display.modelParams3[3] *= material.aniso*2; + display.modelParams4[0] *= material.anisoV*2; + display.modelParams4[1] *= material.cameralight*2; + //System.out.println("selected = " + selected); + display.modelParams4[2] *= material.diffuseness*2; + display.modelParams4[3] *= material.shadow*2; + display.modelParams5[0] *= material.texture*2; + display.modelParams5[1] *= material.opacity*2; + display.modelParams5[2] *= material.fakedepth*2; + display.modelParams5[3] *= material.shadowbias*2; + } + + display.modelParams6[0] = 0; + display.modelParams6[1] = 0; + display.modelParams6[2] = 0; + display.modelParams6[3] = 0; + + display.modelParams7[0] = 0; + display.modelParams7[1] = 1000; + display.modelParams7[2] = material.parallax; + display.modelParams7[3] = 0; + + //display.modelParams6[0] = 100; // criss de bug de bump + + Object3D.cVector2[] extparams = others; // display.vector2buffer; + if (extparams != null && extparams.length > 0 && extparams[0] != null) + { + display.modelParams6[0] = extparams[0].x / 1000.0f; // bump + display.modelParams6[1] = extparams[0].y / 1000.0f; // noise + if (extparams.length > 1) + { + display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade + display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough + if (extparams.length > 2) + { + display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power + float x = extparams[2].y / 1000.0f; + //if (x == 0) + // x = 1f; + display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power + if (extparams[2].y > 0) + { + //System.out.println("extparams[1].y = " + extparams[1].y); + //System.out.println("extparams[2].y = " + extparams[2].y); + //System.out.println("opacity power = " + display.modelParams7[1]); + } + } + } + } + + //if (display.modelParams6[2] != 0) + /* + System.out.println("modelParams0[0] = " + display.modelParams0[0]); + System.out.println("modelParams0[1] = " + display.modelParams0[1]); + System.out.println("modelParams0[2] = " + display.modelParams0[2]); + System.out.println("modelParams0[3] = " + display.modelParams0[3]); + System.out.println("modelParams1[0] = " + display.modelParams1[0]); + System.out.println("modelParams1[1] = " + display.modelParams1[1]); + System.out.println("modelParams1[2] = " + display.modelParams1[2]); + System.out.println("modelParams1[3] = " + display.modelParams1[3]); + System.out.println("modelParams2[0] = " + display.modelParams2[0]); + System.out.println("modelParams2[1] = " + display.modelParams2[1]); + System.out.println("modelParams2[2] = " + display.modelParams2[2]); + System.out.println("modelParams2[3] = " + display.modelParams2[3]); + System.out.println("modelParams3[0] = " + display.modelParams3[0]); + System.out.println("modelParams3[1] = " + display.modelParams3[1]); + System.out.println("modelParams3[2] = " + display.modelParams3[2]); + System.out.println("modelParams3[3] = " + display.modelParams3[3]); + System.out.println("modelParams4[0] = " + display.modelParams4[0]); + System.out.println("modelParams4[1] = " + display.modelParams4[1]); + System.out.println("modelParams4[2] = " + display.modelParams4[2]); + System.out.println("modelParams4[3] = " + display.modelParams4[3]); + System.out.println("modelParams5[0] = " + display.modelParams5[0]); + System.out.println("modelParams5[1] = " + display.modelParams5[1]); + System.out.println("modelParams5[2] = " + display.modelParams5[2]); + System.out.println("modelParams5[3] = " + display.modelParams5[3]); + System.out.println("modelParams6[0] = " + display.modelParams6[0]); + System.out.println("modelParams6[1] = " + display.modelParams6[1]); + System.out.println("modelParams6[2] = " + display.modelParams6[2]); + System.out.println("modelParams6[3] = " + display.modelParams6[3]); + System.out.println("modelParams7[0] = " + display.modelParams7[0]); + System.out.println("modelParams7[1] = " + display.modelParams7[1]); + System.out.println("modelParams7[2] = " + display.modelParams7[2]); + System.out.println("modelParams7[3] = " + display.modelParams7[3]); + /**/ + //assert (display.modelParams6[2] == 0); + + //System.out.println("noise power = " + display.modelParams7[0]); + //System.out.println("shadowbias = " + shadowbias); + + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0); + + int mode = display.FP_SHADER; + + if (material.aniso != material.anisoV || material.aniso > 0.002) + { + mode |= display.FP_ANISO; + } + + display.EnableProgram(mode); + + //System.out.println("opacity power = " + display.modelParams7[1]); + + if (!material.multiply) + { + if (Globals.drawMode == CameraPane.SHADOW) + gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1); + else + gl.glDepthMask(material.opacity >= 0.99); + } } int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0; @@ -225,7 +1939,7 @@ currentGL.glMultMatrixd(model, 0); } - void PushMatrix(double[][] matrix, int count) + public void PushMatrix(double[][] matrix, int count) // INTERFACE { matrixdepth++; // GrafreeD.tracein(matrix); @@ -254,7 +1968,7 @@ void PushMatrix(double[][] matrix) { // GrafreeD.tracein(matrix); - PushMatrix(matrix,1); + PushMatrix(matrix, 1); } void PushMatrix() @@ -270,7 +1984,7 @@ double[][] tmpmat = new double[4][4]; - void PopMatrix(double[][] inverse) + public void PopMatrix(double[][] inverse) // INTERFACE { --matrixdepth; @@ -310,7 +2024,7 @@ PushTextureMatrix(matrix, 1); } - void PushTextureMatrix(double[][] matrix, int count) + public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE { currentGL.glActiveTexture(GetGL().GL_TEXTURE0); @@ -324,7 +2038,7 @@ currentGL.glMatrixMode(GetGL().GL_MODELVIEW); } - void PopTextureMatrix(double[][] inverse) + public void PopTextureMatrix(double[][] inverse) // INTERFACE { currentGL.glActiveTexture(GetGL().GL_TEXTURE0); currentGL.glMatrixMode(GetGL().GL_TEXTURE); @@ -340,9 +2054,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"; } @@ -351,15 +2065,15 @@ static int camerachangeframe; - boolean SetCamera(Camera cam) + public boolean SetCamera(Camera cam, boolean set) { // may 2014 if (cam == cameras[0] || cam == cameras[1]) // return false; - if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount) + if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount) { // check for last change - if (framecount < camerachangeframe + 400) // 120 == 1 second + if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second { // refuse the camera change System.err.println("Camera " + cam + " REFUSED"); @@ -367,9 +2081,10 @@ } } - camerachangeframe = framecount; + camerachangeframe = Globals.framecount; - cam.hAspect = -1; // Read only + if (cam != null) + cam.hAspect = -1; // Read only cameras[0] = cam; targetLookAts[0] = new cVector(cam.lookAt); @@ -379,11 +2094,14 @@ { cameras[i] = new Camera(cam.viewCode); } - - cameras[i].setAim(cam.location, cam.lookAt); - cameras[i].shaper_fovy = cam.shaper_fovy; - cameras[i].UP.set(cam.UP); - targetLookAts[i] = new cVector(cameras[i].lookAt); + + if (set) + { + cameras[i].setAim(cam.location, cam.lookAt); + cameras[i].shaper_fovy = cam.shaper_fovy; + cameras[i].UP.set(cam.UP); + targetLookAts[i] = new cVector(cameras[i].lookAt); + } } cameracount = 0; targetLookAt = targetLookAts[cameracount]; @@ -392,13 +2110,13 @@ // Start with free camera SwitchCameras(true); - pingthread.jump = true; // optional? +// pingthread.jump = true; // optional? if (TRACKONCE) { //System.err.println("Oeil on"); TRACK = true; -// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode) +// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) // object.editWindow.ScreenFit(trackedobject); //pingthread.StepToTarget(true); } @@ -407,8 +2125,8 @@ { //System.err.println("Oeil on"); OEIL = true; - if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode) - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); + if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); //pingthread.StepToTarget(true); } @@ -471,39 +2189,12 @@ { frozen ^= true; // Weird... - lighttouched = true; + Globals.lighttouched = true; } void ToggleDL() { mainDL ^= true; - } - - void ToggleTexture() - { - textureon ^= true; - } - - void ToggleLive() - { - setLIVE(isLIVE() ^ true); - - System.err.println("LIVE = " + isLIVE()); - - if (!isLIVE()) // save sound - GrafreeD.savesound = true; // wav.save(); - // else - repaint(); // start loop // may 2013 - } - - void ToggleSupport() - { - SUPPORT ^= true; - } - - void ToggleAbort() - { - ABORTMODE ^= true; } void ToggleFullScreen() @@ -513,12 +2204,7 @@ void ToggleCrowd() { - CROWD ^= true; - } - - void ToggleInertia() - { - INERTIA ^= true; + Globals.CROWD ^= true; } void ToggleLocal() @@ -526,14 +2212,114 @@ LOCALTRANSFORM ^= true; } - void ToggleFast() + public void ToggleTexture() + { + textureon ^= true; + } + + public void ToggleLive() + { + Globals.setLIVE(Globals.isLIVE() ^ true); + + System.err.println("LIVE = " + Globals.isLIVE()); + + if (!Globals.isLIVE()) // save sound + Grafreed.savesound = true; // wav.save(); + // else + repaint(); // start loop // may 2013 + } + + public void ToggleSupport() + { + SUPPORT ^= true; + } + + public void ToggleAbort() + { + ABORTMODE ^= true; + } + + public void ToggleInertia() + { + INERTIA ^= true; + } + + public void ToggleFast() { FAST ^= true; } - void ToggleSlowPose() + public void ToggleSlowPose() { SLOWPOSE ^= true; + } + + public void ToggleBoxMode() + { + BOXMODE ^= true; + } + + public void ToggleZoomBoxMode() + { + ZOOMBOXMODE ^= true; + } + + public void ToggleSmoothFocus() + { + SMOOTHFOCUS ^= true; + } + + public void ToggleImageFlip() + { + IMAGEFLIP ^= true; + } + + public void ToggleSpeakerMocap() + { + SPEAKERMOCAP ^= true; + } + + public void ToggleSpeakerCamera() + { + SPEAKERCAMERA ^= true; + } + + public void ToggleSpeakerFocus() + { + SPEAKERFOCUS ^= true; + } + + public void ToggleFrustum() + { + FRUSTUM ^= true; + } + + public void ToggleTrack() + { + TRACK ^= true; + + repaint(); + } + + public void ToggleTrackOnce() + { + TRACKONCE ^= true; + } + + public void ToggleShadowTrack() + { + SHADOWTRACK ^= true; + repaint(); + } + + public void ToggleOeil() + { + OEIL ^= true; + } + + public void ToggleOeilOnce() + { + OEILONCE ^= true; } void ToggleFootContact() @@ -541,84 +2327,9 @@ FOOTCONTACT ^= true; } - void ToggleBoxMode() - { - BOXMODE ^= true; - } - - void ToggleSmoothFocus() - { - SMOOTHFOCUS ^= true; - } - - void ToggleImageFlip() - { - IMAGEFLIP ^= true; - } - - void ToggleSpeakerMocap() - { - SPEAKERMOCAP ^= true; - } - - void ToggleSpeakerCamera() - { - SPEAKERCAMERA ^= true; - } - - void ToggleSpeakerFocus() - { - SPEAKERFOCUS ^= true; - } - void ToggleDebug() { - DEBUG ^= true; - } - - void ToggleFrustum() - { - FRUSTUM ^= true; - } - - void ToggleTrack() - { - TRACK ^= true; - if (TRACK) - { - if (object.selection != null && - object.selection.size() > 0 && - object.selection.elementAt(0) != null && - !(object.selection.elementAt(0) instanceof Camera) && - !(object.selection.elementAt(0) instanceof ScriptNode)) - { - trackedobject = object.selection.elementAt(0); - repaint(); - } - } - - repaint(); - } - - void ToggleTrackOnce() - { - TRACKONCE ^= true; - } - - void ToggleShadowTrack() - { - SHADOWTRACK ^= true; - repaint(); - } - - void ToggleOeil() - { - OEIL ^= true; - } - - void ToggleOeilOnce() - { - OEILONCE ^= true; + Globals.DEBUG ^= true; } void ToggleLookAt() @@ -626,9 +2337,9 @@ LOOKAT ^= true; } - void ToggleRandom() + void ToggleSwitch() { - RANDOM ^= true; + SWITCH ^= true; } void ToggleHandles() @@ -636,10 +2347,17 @@ HANDLES ^= true; } + Object3D paintFolder; + void TogglePaint() { PAINTMODE ^= true; paintcount = 0; + + if (PAINTMODE) + { + paintFolder = GetFolder(); + } } void SwapCamera(int a, int b) @@ -670,36 +2388,9 @@ { //System.out.println("PROTECTION = " + cam.hAspect); //assert (cam.hAspect == 0); - cam.hAspect = 0; + if (cam != null) + cam.hAspect = 0; lightCamera = cam; - } - - CameraPane(Object3D o, Camera cam, boolean withcontext) - { - super(defaultcaps, null, withcontext?glcontext:null, null); - - //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523)); - glcontext = getContext(); - - cameras = new Camera[2]; - targetLookAts = new cVector[2]; - - SetCamera(cam); - - SetLight(new Camera(new cVector(10, 10, -20))); - - object = o; - - setBackground(Color.white); - - addKeyListener(this); - addMouseListener(this); - addMouseMotionListener(this); - addMouseWheelListener(this); - //System.out.println("addGLEventListener: " + this); - addGLEventListener(this); - -// pingthread.start(); // may 2013 } private static void ApplyTransform(GL gl, Mat4f xform) @@ -759,11 +2450,38 @@ GL currentGL; - GL GetGL() + public GL GetGL() // INTERFACE { return currentGL; } - + + static private BufferedImage CreateBim(TextureData texturedata) + { + Grafreed.Assert(texturedata != null); + + int width = texturedata.getWidth(); + int height = texturedata.getHeight(); + + Buffer buffer = texturedata.getBuffer(); + ByteBuffer bytebuf = (ByteBuffer)buffer; + + byte[] bytes = bytebuf.array(); + + 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 { @@ -772,28 +2490,31 @@ int resolution; - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) { - texture = tex; + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); + texturedata = texdata; resolution = res; } } /**/ // TEXTURE static Texture texture; - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>(); + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); + int pigmentdepth = 0; public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; int bumpdepth = 0; public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); - public static String NOISE_TEXTURE = "WHITE_NOISE"; + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) { TextureData texturedata = null; @@ -803,7 +2524,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); @@ -812,13 +2533,34 @@ if (bump) texturedata = ConvertBump(texturedata, false); - com.sun.opengl.util.texture.Texture texture = - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); +// com.sun.opengl.util.texture.Texture texture = +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); - return texture; + return texturedata; + } + + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) + { + TextureData texturedata = null; + + try + { + texturedata = + com.sun.opengl.util.texture.TextureIO.newTextureData( + bim, + true); + } catch (Exception e) + { + throw new javax.media.opengl.GLException(e); + } + + if (bump) + texturedata = ConvertBump(texturedata, false); + + return texturedata; } boolean HUESMOOTH = true; // wrap around bug... true; @@ -1848,6 +3590,8 @@ }; /**/ + static Object3D lastObject; + //com.sun.opengl.util.texture.Texture TextureData GetFileTexture(String name, boolean bump, int resolution) @@ -1884,6 +3628,8 @@ // return null; //if (i == 2) // return null; + // TIFF issue sept 2019 + System.err.println("lastObject = " + lastObject); e.printStackTrace(); name = name.split("\\.tif")[0] + ".jpg"; } @@ -1891,6 +3637,8 @@ System.out.println("LOADING TEXTURE : " + name); + Object x = texturedata.getMipmapData(); // .getBuffer(); + // if (false) // compressbit > 0) { @@ -2000,10 +3748,12 @@ */ TextureData ReduceTexture(TextureData texturedata, int resolution) // String name) { + int pixelformat = texturedata.getPixelFormat(); + int stride = 1; - if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE) + if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE) stride = 3; - if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA) + if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA) stride = 4; int width = texturedata.getWidth(); @@ -2593,6 +4343,7 @@ com.sun.opengl.util.texture.Texture CompressTexture2(String name) { + new Exception().printStackTrace(); System.exit(0); com.sun.opengl.util.texture.Texture texture = null; @@ -5211,30 +6962,30 @@ short residu = 0; // wraparound workarounds - short fuck = (short) (buffer[i] & 0xFF); + short ww = (short) (buffer[i] & 0xFF); /* - residu += (fuck%2); - if(fuck/2 < 256-residu/2) + residu += (ww%2); + if(ww/2 < 256-residu/2) { - fuck = (short)((fuck/2) + residu/2); + ww = (short)((ww/2) + residu/2); if(residu == 2) residu = 0; } else { residu = 0; - fuck /= 2; + ww /= 2; } */ - if (i < imglength / 3 || rnd.nextFloat() < 0.5 || fuck >= 254) + if (i < imglength / 3 || rnd.nextFloat() < 0.5 || ww >= 254) { - fuck /= 2; + ww /= 2; } else { - fuck = (short) ((fuck / 2) + fuck % 2); + ww = (short) ((ww / 2) + ww % 2); } - buffer[i] = (byte) fuck; + buffer[i] = (byte) ww; } //System.out.print(bytes[i] + " "); //if(buffer[i] >= 0 && buffer[i]<=eps-1) buffer[i] = eps; @@ -6269,7 +8020,7 @@ return null; } - void ReleaseTextures(cTexture tex) + public void ReleaseTextures(cTexture tex) // INTERFACE { if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) { @@ -6286,7 +8037,7 @@ String pigment = Object3D.GetPigment(tex); String bump = Object3D.GetBump(tex); - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); // System.out.println("; bump = " + bump); @@ -6301,13 +8052,71 @@ pigment = null; } - ReleaseTexture(bump, true); - ReleaseTexture(pigment, false); + ReleaseTexture(tex, true); + ReleaseTexture(tex, false); } - void ReleaseTexture(String tex, boolean bump) + public void ReleasePigmentTexture(cTexture tex) // INTERFACE { - if (// drawMode != 0 || /*tex == null ||*/ + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) + { + return; + } + + if (tex == null) + { + ReleaseTexture(null, false); + return; + } + + String pigment = Object3D.GetPigment(tex); + + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + { + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); + // System.out.println("; bump = " + bump); + } + + if (pigment.equals("")) + { + pigment = null; + } + + ReleaseTexture(tex, false); + } + + public void ReleaseBumpTexture(cTexture tex) // INTERFACE + { + if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) + { + return; + } + + if (tex == null) + { + ReleaseTexture(null, true); + return; + } + + String bump = Object3D.GetBump(tex); + + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + { + // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); + // System.out.println("; bump = " + bump); + } + + if (bump.equals("")) + { + bump = null; + } + + ReleaseTexture(tex, true); + } + + void ReleaseTexture(cTexture tex, boolean bump) + { + if (// DrawMode() != 0 || /*tex == null ||*/ ambientOcclusion ) // || !textureon) { return; @@ -6316,7 +8125,7 @@ CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; if (tex != null) - texture = textures.get(tex); + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); // //assert( texture != null ); // if (texture == null) @@ -6408,9 +8217,57 @@ } } - /*boolean*/ void BindTextures(cTexture tex, int resolution) + /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE { - if (// drawMode != 0 || /*tex == null ||*/ +// if (// DrawMode() != 0 || /*tex == null ||*/ +// ambientOcclusion ) // || !textureon) +// { +// return; // false; +// } +// +// if (tex == null) +// { +// BindTexture(null,false,resolution); +// BindTexture(null,true,resolution); +// return; +// } +// +// String pigment = Object3D.GetPigment(tex); +// String bump = Object3D.GetBump(tex); +// +// usedtextures.add(pigment); +// usedtextures.add(bump); +// +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) +// { +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); +// // System.out.println("; bump = " + bump); +// } +// +// if (bump.equals("")) +// { +// bump = null; +// } +// if (pigment.equals("")) +// { +// pigment = null; +// } +// +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); +// BindTexture(pigment, false, resolution); +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); +// BindTexture(bump, true, resolution); +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); +// +// return; // true; + + BindPigmentTexture(tex, resolution); + BindBumpTexture(tex, resolution); + } + + /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE + { + if (// DrawMode() != 0 || /*tex == null ||*/ ambientOcclusion ) // || !textureon) { return; // false; @@ -6419,17 +8276,47 @@ if (tex == null) { BindTexture(null,false,resolution); - BindTexture(null,true,resolution); return; } String pigment = Object3D.GetPigment(tex); + + usedtextures.add(tex); + + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + { + // System.out.print("BIND +++++++++++++++ pigment = " + pigment); + // System.out.println("; bump = " + bump); + } + + if (pigment.equals("")) + { + pigment = null; + } + + GetGL().glActiveTexture(GetGL().GL_TEXTURE0); + BindTexture(tex, false, resolution); + } + + /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE + { + if (// DrawMode() != 0 || /*tex == null ||*/ + ambientOcclusion ) // || !textureon) + { + return; // false; + } + + if (tex == null) + { + BindTexture(null,true,resolution); + return; + } + String bump = Object3D.GetBump(tex); - usedtextures.put(pigment, pigment); - usedtextures.put(bump, bump); + usedtextures.add(tex); - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { // System.out.print("BIND +++++++++++++++ pigment = " + pigment); // System.out.println("; bump = " + bump); @@ -6439,43 +8326,94 @@ { bump = null; } - if (pigment.equals("")) - { - pigment = null; - } - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); - BindTexture(pigment, false, resolution); GetGL().glActiveTexture(GetGL().GL_TEXTURE2); - BindTexture(bump, true, resolution); + BindTexture(tex, true, resolution); GetGL().glActiveTexture(GetGL().GL_TEXTURE0); - - return; // true; } - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) + java.util.HashSet<String> missingTextures = new java.util.HashSet<String>(); + + private boolean FileExists(String tex) { - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; + if (missingTextures.contains(tex)) + { + return false; + } + + boolean fileExists = new File(tex).exists(); + + if (!fileExists) + { + // If file exists, the "new File()" is not executed sgain + missingTextures.add(tex); + } + + return fileExists; + } + + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception + { + CacheTexture texturecache = null; if (tex != null) { - String texname = tex; + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; - String[] split = tex.split("Textures"); - if (split.length > 1) - texname = "/Users/nbriere/Textures" + split[split.length-1]; - else - if (!texname.startsWith("/")) - texname = "/Users/nbriere/Textures/" + texname; + if (texname.equals("") && texdata == null) + { + return null; + } + + String fallbackTextureName = defaultDirectory + "/Textures/" + texname; + +// String[] split = tex.split("Textures"); +// if (split.length > 1) +// texname = "/Users/nbriere/Textures" + split[split.length-1]; +// else +// if (!texname.startsWith("/")) +// texname = "/Users/nbriere/Textures/" + texname; + if (!FileExists(texname) && !texname.startsWith("@")) + { + texname = fallbackTextureName; + } if (CACHETEXTURE) - texture = textures.get(texname); // TEXTURE CACHE - - TextureData texturedata = null; - - if (texture == null || texture.resolution < resolution) { - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) + if (texdata == null) + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); + else + texturecache = bimtextures.get(texdata); + } + + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) + { + TextureData texturedata = null; + + if (texdata != null && textureon) + { + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); + + try + { + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); + } + catch (Exception e) + { + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); + } + + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); + bimtextures.put(texdata, texturecache); + + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); + + //Object bim2 = CreateBim(texturecache.texturedata); + //bim2 = bim; + } + else + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) { assert(!bump); // if (bump) @@ -6486,19 +8424,23 @@ // } // else // { - texture = textures.get(tex); - if (texture == null) + // texturecache = textures.get(texname); // suspicious + if (texturecache == null) { - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); } + else + new Exception().printStackTrace(); // } } else - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) { assert(bump); - texture = textures.get(tex); - if (texture == null) - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); + // texturecache = textures.get(texname); // suspicious + if (texturecache == null) + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); + else + new Exception().printStackTrace(); } else { //if (tex.equals("IMMORTAL")) @@ -6506,11 +8448,22 @@ // texture = GetResourceTexture("default.png"); //} else //{ - if (tex.equals("WHITE_NOISE")) + if (texname.endsWith("WHITE_NOISE")) { - texture = textures.get(tex); - if (texture == null) - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); + // texturecache = textures.get(texname); // suspicious + if (texturecache == null) + texturecache = new CacheTexture(GetResourceTexture("whitenoise.jpg", bump),resolution); + else + new Exception().printStackTrace(); + } else + { + if (texname.startsWith("@") && textureon) + { + // texturecache = textures.get(texname); // suspicious + if (texturecache == null) + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); + else + new Exception().printStackTrace(); } else { if (textureon) @@ -6535,7 +8488,7 @@ } cachename = texname.substring(0, texname.length()-4)+ext+".jpg"; - if (!new File(cachename).exists()) + if (!FileExists(cachename)) cachename = texname; else processbump = false; // don't process bump map again @@ -6557,7 +8510,7 @@ } cachename = texname.substring(0, texname.length()-4)+ext+".png"; - if (!new File(cachename).exists()) + if (!FileExists(cachename)) cachename = texname; else processbump = false; // don't process bump map again @@ -6566,20 +8519,23 @@ texturedata = GetFileTexture(cachename, processbump, resolution); - if (texturedata != null) - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); + if (texturedata == null) + throw new Exception(); + + texturecache = new CacheTexture(texturedata,resolution); //texture = GetTexture(tex, bump); } + } } //} } - if (/*CACHETEXTURE &&*/ texture != null && textureon) + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) { //return false; // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) { // String ext = "_highres"; // if (REDUCETEXTURE) @@ -6596,52 +8552,17 @@ File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); if (!cachefile.exists()) { - // cache to disk - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); - //buffers[0]. - - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); - int[] pixels = new int[bytebuf.capacity()/3]; - - // squared size heuristic... - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) + //if (texturedata.getWidth() == texturedata.getHeight()) { - for (int i=pixels.length; --i>=0;) - { - int i3 = i*3; - pixels[i] = 0xFF; - pixels[i] <<= 8; - pixels[i] |= bytebuf.get(i3+2) & 0xFF; - pixels[i] <<= 8; - pixels[i] |= bytebuf.get(i3+1) & 0xFF; - pixels[i] <<= 8; - pixels[i] |= bytebuf.get(i3) & 0xFF; - } - - /* - int r=0,g=0,b=0,a=0; - for (int i=0; i<width; i++) - for (int j=0; j<height; j++) - { - int index = j*width+i; - int p = pixels[index]; - a = ((p>>24) & 0xFF); - r = ((p>>16) & 0xFF); - g = ((p>>8) & 0xFF); - b = (p & 0xFF); - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; - } - /**/ - int width = (int)Math.sqrt(pixels.length); // squared - int height = width; - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); + BufferedImage rendImage = CreateBim(texturedata); + ImageWriter writer = null; Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); if (iter.hasNext()) { writer = (ImageWriter)iter.next(); } - float compressionQuality = 0.9f; + + float compressionQuality = 0.85f; try { ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); @@ -6658,18 +8579,20 @@ } } } - + + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; + //System.out.println("Texture = " + tex); - if (textures.containsKey(texname)) + if (textures.containsKey(tex)) { - CacheTexture thetex = textures.get(texname); + CacheTexture thetex = textures.get(tex); thetex.texture.disable(); thetex.texture.dispose(); - textures.remove(texname); + textures.remove(tex); } - texture.texturedata = texturedata; - textures.put(texname, texture); + //texture.texturedata = texturedata; + textures.put(tex, texturecache); // newtex = true; } @@ -6685,10 +8608,46 @@ } } - return texture; + return texturecache; } - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) + static void EmbedTextures(cTexture tex) + { + if (tex.pigmentdata == null) + { + //String texname = Object3D.GetPigment(tex); + + CacheTexture texturecache = texturepigment.get(tex); + + if (texturecache != null) + { + tex.pw = texturecache.texturedata.getWidth(); + tex.ph = texturecache.texturedata.getHeight(); + tex.pigmentdata = //CompressJPEG(CreateBim + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() + ; + //, tex.pw, tex.ph), 0.5f); + } + } + + if (tex.bumpdata == null) + { + //String texname = Object3D.GetBump(tex); + + CacheTexture texturecache = texturebump.get(tex); + + if (texturecache != null) + { + tex.bw = texturecache.texturedata.getWidth(); + tex.bh = texturecache.texturedata.getHeight(); + tex.bumpdata = //CompressJPEG(CreateBim( + ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); + //, tex.bw, tex.bh), 0.5f); + } + } + } + + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception { CacheTexture texture = GetCacheTexture(tex, bump, resolution); @@ -6706,21 +8665,21 @@ return texture!=null?texture.texture:null; } - com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception { CacheTexture texture = GetCacheTexture(tex, bump, resolution); return texture!=null?texture.texturedata:null; } - boolean BindTexture(String tex, boolean bump, int resolution) + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception { if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) { return false; } - boolean newtex = false; + //boolean newtex = false; com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); @@ -6752,9 +8711,75 @@ texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); - return newtex; + return true; // Warning: not used. } + public static byte[] CompressJPEG(BufferedImage image, float quality) + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); + ImageWriter writer = writers.next(); + + ImageWriteParam param = writer.getDefaultWriteParam(); + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionQuality(quality); + + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); + writer.setOutput(ios); + writer.write(null, new IIOImage(image, null, null), param); + + byte[] data = baos.toByteArray(); + writer.dispose(); + return data; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException + { + ByteArrayInputStream baos = new ByteArrayInputStream(image); + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); + ImageReader reader = writers.next(); + + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + + ImageReadParam param = reader.getDefaultReadParam(); + param.setDestination(bim); + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); + + ImageInputStream ios = ImageIO.createImageInputStream(baos); + reader.setInput(ios); + BufferedImage bim2 = reader.read(0, param); + reader.dispose(); + +// WritableRaster raster = bim2.getRaster(); +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); +// byte[] bytes = data.getData(); +// +// int[] pixels = new int[bytes.length/3]; +// for (int i=pixels.length; --i>=0;) +// { +// int i3 = i*3; +// pixels[i] = 0xFF; +// pixels[i] <<= 8; +// pixels[i] |= bytes[i3+2] & 0xFF; +// pixels[i] <<= 8; +// pixels[i] |= bytes[i3+1] & 0xFF; +// pixels[i] <<= 8; +// pixels[i] |= bytes[i3] & 0xFF; +// } +// +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); + + return bim; + } + ShadowBuffer shadowPBuf; AntialiasBuffer antialiasPBuf; int MAXSTACK; @@ -6771,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)); // @@ -6782,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 }; @@ -6947,7 +8975,7 @@ if (cubemap == null) { - LoadEnvy(5); + //LoadEnvy(1); } //cubemap.enable(); @@ -7223,6 +9251,8 @@ void LoadEnvy(int which) { + assert(false); + String name; String ext; @@ -7234,37 +9264,58 @@ cubemap = null; return; case 1: - name = "cubemaps/box_"; - ext = "png"; + name = "cubemaps/rgb/"; + ext = "jpg"; reverseUP = false; break; case 2: - name = "cubemaps/uffizi_"; - ext = "png"; - break; // reverseUP = true; break; + name = "cubemaps/uffizi/"; + ext = "jpg"; + reverseUP = false; + break; case 3: - name = "cubemaps/CloudyHills_"; - ext = "tga"; + name = "cubemaps/CloudyHills/"; + ext = "jpg"; reverseUP = false; break; case 4: - name = "cubemaps/cornell_"; + name = "cubemaps/cornell/"; ext = "png"; reverseUP = false; break; + case 5: + name = "cubemaps/skycube/"; + ext = "jpg"; + reverseUP = false; + break; + case 6: + name = "cubemaps/SaintLazarusChurch3/"; + ext = "jpg"; + reverseUP = false; + break; + case 7: + name = "cubemaps/Sodermalmsallen/"; + ext = "jpg"; + reverseUP = false; + break; + case 8: + name = "cubemaps/Sodermalmsallen2/"; + ext = "jpg"; + reverseUP = false; + break; + case 9: + name = "cubemaps/UnionSquare/"; + ext = "jpg"; + reverseUP = false; + break; default: - name = "cubemaps/rgb_"; - ext = "png"; /*mipmap = true;*/ reverseUP = false; + name = "cubemaps/box/"; + ext = "png"; /*mipmap = true;*/ + reverseUP = false; break; } - - try - { - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); - } catch (IOException e) - { - throw new RuntimeException(e); - } + + LoadSkybox(name, ext, mipmap); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) @@ -7296,8 +9347,12 @@ static double[] model = new double[16]; double[] camera2light = new double[16]; double[] light2camera = new double[16]; - int newenvy = -1; - boolean envyoff = true; // false; + + //int newenvy = -1; + //boolean envyoff = false; + + String loadedskyboxname; + cVector light0 = new cVector(0, 0, 0); // 1,3,2); //float[] light0 = { 0,0,0 }; cVector dirlight = new cVector(0, 0, 1); // 1,3,2); @@ -7310,9 +9365,9 @@ static boolean occlusionInitialized = false; boolean selection = false; boolean pointselection = false; - /*static*/ boolean lighttouched = true; + ///*static*/ boolean lighttouched = true; boolean deselect; - boolean ambientOcclusion = false; + private boolean ambientOcclusion = false; static boolean flash = false; /*static*/ boolean wait = false; boolean displaydone = false; // after repaint() calls @@ -7442,6 +9497,8 @@ //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100); //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar); double scale = lightCamera.SCALE / lightCamera.Distance(); +// PATCH FILLE AUX JEANS + //scale *= lightCamera.shaper_fovy / 25; gl.glScaled(2 * scale, 2 * scale, -scale); gl.glTranslated(0, 0, lightCamera.DECAL); @@ -7588,17 +9645,40 @@ jy8[3] = 0.5f; } - float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV + float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation - float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity + float[] options3 = new float[]{1, 1, 1, 0}; // fog color + float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen + void ResetOptions() + { + options1[0] = 100; + options1[1] = 0.025f; + options1[2] = 0.01f; + options1[3] = 0; + options1[4] = 0; + + options2[0] = 0; + options2[1] = 0.75f; + options2[2] = 0; + options2[3] = 0; + + options3[0] = 1; + options3[1] = 1; + options3[2] = 1; + options3[3] = 0; + + options4[0] = 1; + options4[1] = 0; + options4[2] = 1; + options4[3] = 0; + } + static int imagecount = 0; // movie generation static int jitter = 0; boolean restartframe = false; - - static int framecount = 0; // general-purpose global count void displayAntiAliased(javax.media.opengl.GL gl) { @@ -7630,7 +9710,7 @@ gl.glClear(gl.GL_ACCUM_BUFFER_BIT); for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0) { - framecount++; + Globals.framecount++; if (CameraPane.tickcount > 0) CameraPane.tickcount--; @@ -7668,7 +9748,7 @@ gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0); */ - lighttouched = true; + Globals.lighttouched = true; //System.err.println(" shadowbuffer: " + jitter); shadowbuffer.display(); @@ -7689,8 +9769,8 @@ assert (parentcam != renderCamera); if (renderCamera != lightCamera) - for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(parentcam.toParent, matrix, matrix); + //for (int count = parentcam.GetTransformCount(); --count>=0;) + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); @@ -7705,8 +9785,8 @@ LA.matCopy(renderCamera.fromScreen, matrix); if (renderCamera != lightCamera) - for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(matrix, parentcam.fromParent, matrix); + //for (int count = parentcam.GetTransformCount(); --count>=0;) + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); @@ -7752,13 +9832,18 @@ rati = 1 / rati; gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); } - assert (newenvy == -1); + + //assert (newenvy == -1); + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); - DrawSkyBox(gl); + DrawSkyBox(gl, (float)rati); gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); - accPerspective(gl, renderCamera.shaper_fovy / ratio, + + boolean vr = capsLocked && !lightMode; + + accPerspective(gl, renderCamera.shaper_fovy / ratio * (vr ? 1.2 : 1), ratio, //near_plane, far_plane, renderCamera.shaper_zNear * renderCamera.Distance(), renderCamera.shaper_zFar * renderCamera.Distance(), @@ -7778,7 +9863,7 @@ //gl.glFlush(); gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE); - if (ANIMATION && ABORTED) + if (Globals.ANIMATION && ABORTED) { System.err.println(" ABORTED FRAME"); break; @@ -7808,7 +9893,7 @@ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); // save image - if (ANIMATION && !ABORTED) + if (Globals.ANIMATION && !ABORTED) { VPwidth = viewport[2]; VPheight = viewport[3]; @@ -7919,11 +10004,11 @@ // imagecount++; - String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext; + String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext; if (!BOXMODE) { - System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")"); + System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")"); } if (!BOXMODE) @@ -7961,7 +10046,7 @@ ABORTED = false; } else - GrafreeD.wav.cursor += 735 * ACSIZE; + Grafreed.wav.cursor += 735 * ACSIZE; if (false) { @@ -8615,32 +10700,34 @@ } } - boolean IsFrozen() - { - boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION; - - return !selectmode && cameracount == 0; // != 0; - } - boolean niceon = false; javax.swing.Timer AAtimer = new javax.swing.Timer(750, this); boolean currentlydrawing = false; 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 (GrafreeD.savesound && GrafreeD.hassound) + if (patchMaterial.patchMaterial) { - GrafreeD.wav.save(); - GrafreeD.savesound = false; - GrafreeD.hassound = false; + patchMaterial.patchMaterial = false; + patchMaterial.objectTabbedPane.setSelectedIndex(1); + } + + if (Grafreed.savesound && Grafreed.hassound) + { + Grafreed.wav.save(); + Grafreed.savesound = false; + Grafreed.hassound = false; } // if (DEBUG_SELECTION) // { -// if (drawMode != SELECTION) -// drawMode = SELECTION; +// if (DrawMode() != SELECTION) +// DrawMode() = SELECTION; // } if (!isRenderer) @@ -8674,7 +10761,9 @@ } /**/ - if (selection) + boolean control = ((modifiers & CTRL) != 0); + + if (selection && (!Globals.isLIVE() || control)) { selectbuffer.display(); return; @@ -8696,9 +10785,9 @@ //ANTIALIAS = 0; - if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0) + if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0) { - if (niceon || isLIVE()) + if (niceon || Globals.isLIVE()) { //if(active == 0) // antialiaser = null; @@ -8711,6 +10800,7 @@ ANTIALIAS = 0; //System.out.println("RESTART"); AAtimer.restart(); + Globals.TIMERRUNNING = true; } } } @@ -8723,8 +10813,114 @@ assert eyeCamera.shaper_zFar == 1E5f; // 500.0f; */ - if (drawMode == DEFAULT) + if (DrawMode() == DEFAULT) { + if (manipCamera == lightCamera) + { +// switch (e.getKeyCode()) +// { +// case DOWN_ARROW: +// lightCamera.DECAL /= 2; +// repaint(); +// break; +// case UP_ARROW: +// lightCamera.DECAL *= 2; +// repaint(); +// break; +// case LEFT_ARROW: +// lightCamera.SCALE /= 2; +// repaint(); +// break; +// case RIGHT_ARROW: +// lightCamera.SCALE *= 2; +// repaint(); +// break; +// default: +// break; + if (keys[DOWN_ARROW]) + { + lightCamera.DECAL /= 2; + } + + if (keys[UP_ARROW]) + { + lightCamera.DECAL *= 2; + } + + if (keys[LEFT_ARROW]) + { + lightCamera.SCALE /= 2; + } + + if (keys[RIGHT_ARROW]) + { + lightCamera.SCALE *= 2; + } + } + else + { + //pingthread.mute = true; + + boolean keyon = false; + + if (keys[DOWN_ARROW]) + { + speed = ++speedkey[DOWN_ARROW]; + if (speed > 20) + speed = 20; + GoDown(modifiers); + keyon = true; + } + else + speedkey[DOWN_ARROW] = 0; + + if (keys[UP_ARROW]) + { + speed = ++speedkey[UP_ARROW]; + if (speed > 20) + speed = 20; + GoUp(modifiers); + keyon = true; + } + else + speedkey[UP_ARROW] = 0; + + if (keys[LEFT_ARROW]) + { + speed = ++speedkey[LEFT_ARROW]; + if (speed > 20) + speed = 20; + GoLeft(modifiers); + keyon = true; + } + else + speedkey[LEFT_ARROW] = 0; + + if (keys[RIGHT_ARROW]) + { + speed = ++speedkey[RIGHT_ARROW]; + if (speed > 20) + speed = 20; + GoRight(modifiers); + keyon = true; + } + else + speedkey[RIGHT_ARROW] = 0; + + if (Globals.WALK && capsLocked) + { + Walk(); + keyon = true; + } + + if (keyon) + { + repaint(); + } + + //pingthread.mute = false; + } + currentlydrawing = true; } @@ -8754,18 +10950,18 @@ // if(Applet3D.clipboard != null) // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent); -//drawMode = SELECTION; +//DrawMode() = SELECTION; indexcount = 0; - if (drawMode == OCCLUSION) + if (DrawMode() == OCCLUSION) { - drawMode = DEFAULT; + Globals.drawMode = DEFAULT; // WARNING ambientOcclusion = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Object3D theobject = object; Object3D theparent = object.parent; object.parent = null; - object = (Object3D)GrafreeD.clone(object); + object = (Object3D)Grafreed.clone(object); object.Stripify(); if (theobject.selection == null || theobject.selection.Size() == 0) theobject.PreprocessOcclusion(this); @@ -8778,26 +10974,27 @@ ambientOcclusion = false; } - if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN) + if (//Globals.lighttouched && + DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN) { //if (RENDERSHADOW) // ? if (!IsFrozen()) { // dec 2012 - if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)) + if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0)) { - framecount++; + Globals.framecount++; shadowbuffer.display(); } } - lighttouched = false; // ?? + Globals.lighttouched = false; // ?? //drawing = true; //lighttouched = true; } if (wait) { - Sleep(500); + Sleep(200); // blocks everything wait = false; } @@ -8811,9 +11008,9 @@ //eyeCamera.shaper_fovy = 1; } - if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION) + if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION) { - //System.out.println("drawMode = " + drawMode); + //System.out.println("DrawMode() = " + DrawMode()); vertexMode |= VP_PASS; //vertexMode |= VP_PROJECTION; if (!ambientOcclusion) @@ -8873,7 +11070,7 @@ Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera; //Camera lightcam = new Camera(light0); - if (drawMode == SHADOW) + if (DrawMode() == SHADOW) { /* gl.glMatrixMode(GL.GL_MODELVIEW); @@ -8911,8 +11108,8 @@ // if (parentcam != renderCamera) // not a light if (cam != lightCamera) - for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(parentcam.toParent, matrix, matrix); + //for (int count = parentcam.GetTransformCount(); --count>=0;) + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); for (int j = 0; j < 4; j++) { @@ -8926,8 +11123,8 @@ // if (parentcam != renderCamera) // not a light if (cam != lightCamera) - for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(matrix, parentcam.fromParent, matrix); + //for (int count = parentcam.GetTransformCount(); --count>=0;) + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); @@ -8963,7 +11160,7 @@ gl.glClear(gl.GL_DEPTH_BUFFER_BIT); } else { - if (drawMode != DEFAULT) + if (DrawMode() != DEFAULT) { gl.glClearColor(1, 1, 1, 0); } // 1); @@ -9013,13 +11210,43 @@ gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); } - if (newenvy > -1) +// if (newenvy > -1) +// { +// LoadEnvy(newenvy); +// } +// +// newenvy = -1; + + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) { - LoadEnvy(newenvy); + if (cubemaprgb == null) + { + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); + } + + cubemap = cubemaprgb; } - - newenvy = -1; - + 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(); //System.out.println("ratio = " + ratio); @@ -9028,14 +11255,14 @@ fast &= !ambientOcclusion; - if (drawMode == DEFAULT) + if (DrawMode() == DEFAULT) { //gl.glEnable(gl.GL_ALPHA_TEST); //gl.glActiveTexture(GL.GL_TEXTURE0); if (!IsFrozen() && !ambientOcclusion) { - DrawSkyBox(gl); + DrawSkyBox(gl, (float)ratio); } //if (selection_view == -1) @@ -9089,6 +11316,8 @@ //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100); //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar); double scale = lightCamera.SCALE / lightCamera.Distance(); +// PATCH FILLE AUX JEANS + //scale *= lightCamera.shaper_fovy / 25; gl.glScaled(2 * scale, 2 * scale, -scale); gl.glTranslated(0, 0, lightCamera.DECAL); @@ -9184,7 +11413,16 @@ // Bump noise gl.glActiveTexture(GL.GL_TEXTURE6); //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise); - BindTexture(NOISE_TEXTURE, false, 2); + + try + { + BindTexture(NOISE_TEXTURE, false, 2); + } + catch (Exception e) + { + System.err.println("FAILED: " + NOISE_TEXTURE); + } + gl.glActiveTexture(GL.GL_TEXTURE0); gl.glEnable(GL.GL_TEXTURE_2D); @@ -9207,8 +11445,8 @@ gl.glMatrixMode(GL.GL_MODELVIEW); -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); //gl.glEnable(gl.GL_POLYGON_SMOOTH); +//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); //gl.glEnable(gl.GL_MULTISAMPLE); } else { @@ -9220,14 +11458,16 @@ //System.out.println("BLENDING ON"); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); - +// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); - if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0) + if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0) { //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar); double scale = lightCamera.SCALE / lightCamera.Distance(); +// PATCH FILLE AUX JEANS + //scale *= lightCamera.shaper_fovy / 25; gl.glScaled(2 * scale, 2 * scale, -scale); gl.glTranslated(0, 0, lightCamera.DECAL); //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE); @@ -9268,7 +11508,10 @@ //gl.glOrtho(-BOOST, BOOST, -BOOST, BOOST, 0.001, 1000); } else { - glu.gluPerspective(cam.shaper_fovy / ratio, ratio, cam.shaper_zNear * cam.Distance(), cam.shaper_zFar * cam.Distance()); + boolean vr = capsLocked && !lightMode; + + glu.gluPerspective(cam.shaper_fovy / ratio * (vr ? 1.2 : 1), + ratio, cam.shaper_zNear * cam.Distance(), cam.shaper_zFar * cam.Distance()); } } @@ -9280,7 +11523,7 @@ //gl.glPushMatrix(); gl.glLoadIdentity(); - if (!ambientOcclusion) // drawMode != OCCLUSION) + if (!ambientOcclusion) // DrawMode() != OCCLUSION) { //LA.xformPos(light0, lightCamera.fromScreen, light); LA.xformDir(dirlight, lightCamera.fromScreen, lightposition); @@ -9307,8 +11550,8 @@ System.err.println("parentcam != renderCamera"); // if (cam != lightCamera) - for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013 + //for (int count = parentcam.GetTransformCount(); --count>=0;) + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 } LA.xformDir(lightposition, cam.toScreen, lightposition); @@ -9329,8 +11572,8 @@ if (true) // TODO { if (cam != lightCamera) - for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformDir(light0, parentcam.toParent, light0); // may 2013 + //for (int count = parentcam.GetTransformCount(); --count>=0;) + LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013 } LA.xformPos(light0, cam.toScreen, light0); @@ -9367,7 +11610,7 @@ } /**/ - if (true) // drawMode == SELECTION) // != DEFAULT) + if (true) // DrawMode() == SELECTION) // != DEFAULT) gl.glDisable(gl.GL_LIGHTING); else gl.glEnable(gl.GL_LIGHTING); @@ -9379,12 +11622,13 @@ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0); options2[0] *= renderCamera.Distance(); lightslot = 64; - if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT) + if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT) { DrawLights(object); } @@ -9395,7 +11639,7 @@ fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso //System.out.println("fragmentMode = " + fragmentMode); - if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION) + if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection()) { /* if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING)) @@ -9428,7 +11672,7 @@ } } - if (drawMode == DEFAULT) + if (DrawMode() == DEFAULT) { if (WIREFRAME && !ambientOcclusion) { @@ -9446,7 +11690,7 @@ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); - if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) // + if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) // { if (vertexMode != 0) // && !fast) { @@ -9466,7 +11710,7 @@ } } - if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion) + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) { //gl.glDepthFunc(GL.GL_LEQUAL); //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); @@ -9474,27 +11718,24 @@ boolean texon = textureon; - if (RENDERPROGRAM > 0) - { - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); - textureon = false; - } + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); + textureon = false; + //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); //System.out.println("ALLO"); gl.glColorMask(false, false, false, false); DrawObject(gl); - if (RENDERPROGRAM > 0) - { - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); - textureon = texon; - } + + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); + textureon = texon; + gl.glColorMask(true, true, true, true); gl.glDepthFunc(GL.GL_EQUAL); - //gl.glDepthMask(false); + gl.glDepthMask(false); } - if (false) // drawMode == SHADOW) + if (false) // DrawMode() == SHADOW) { //SetColumnMajorData(cameraInverseTransform, view_1); //System.out.println("light = " + cameraInverseTransform); @@ -9508,16 +11749,16 @@ //System.out.println("object = " + object); if (!frozen && !imageLocked) { - if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0) + if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0) { displayAntiAliased(gl); } else { programcount = 0; - int keepmode = drawMode; + int keepmode = DrawMode(); // if (DEBUG_SELECTION) // { -// drawMode = SELECTION; +// DrawMode() = SELECTION; // } // for point selection // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0); @@ -9527,10 +11768,10 @@ DrawObject(gl); // jan 2013 System.err.println("RESET ABORT (display)"); - // if (drawMode == DEFAULT) + // if (DrawMode() == DEFAULT) // ABORTED = false; fullreset = false; - drawMode = keepmode; + Globals.drawMode = keepmode; // WARNING //System.out.println("PROGRAM SWITCH " + programcount); } } @@ -9538,11 +11779,11 @@ gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); - if (drawMode == DEFAULT) + if (DrawMode() == DEFAULT) { ReleaseTexture(NOISE_TEXTURE, false); } - //if (drawMode == DEFAULT) + //if (DrawMode() == DEFAULT) { gl.glActiveTexture(GL.GL_TEXTURE1); @@ -9554,7 +11795,7 @@ //else //gl.glDisable(gl.GL_TEXTURE_2D); //gl.glPopMatrix(); - if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion) + if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion) { //new Exception().printStackTrace(); //System.out.println("Draw image " + width + ", " + height); @@ -9596,7 +11837,7 @@ //gl.glFlush(); } - if (flash && drawMode == DEFAULT) + if (flash && DrawMode() == DEFAULT) { flash = false; wait = true; @@ -9604,9 +11845,9 @@ } //drawing = false; - //if(drawMode == DEFAULT) + //if(DrawMode() == DEFAULT) // niceon = false; - if (drawMode == DEFAULT) + if (DrawMode() == DEFAULT) { currentlydrawing = false; } @@ -9626,8 +11867,11 @@ repaint(); } - if (isLIVE() && drawMode == DEFAULT) // may 2013 + if (Globals.isLIVE() && DrawMode() == DEFAULT || pingthread.live) // may 2013 + { + renderCamera.computeTransform(); repaint(); + } displaydone = true; } @@ -9645,8 +11889,14 @@ { renderpass++; // System.out.println("Draw object... "); + STEP = 1; if (FAST) // in case there is no script - STEP = 16; + STEP = 8; + + if (CURRENTANTIALIAS == 0 || ACSIZE == 1) + { + STEP *= 4; + } //object.FullInvariants(); @@ -9660,24 +11910,59 @@ e.printStackTrace(); } - if (GrafreeD.RENDERME > 0) - GrafreeD.RENDERME--; // mechante magouille + if (Grafreed.RENDERME > 0) + Grafreed.RENDERME--; // mechante magouille - ONESTEP = false; + Globals.ONESTEP = false; } static boolean zoomonce = false; + static void CreateSelectedPoint() + { + if (selectedpoint == null) + { + debugpointG = new Sphere(); + debugpointP = new Sphere(); + debugpointC = new Sphere(); + debugpointR = new Sphere(); + + selectedpoint = new Superellipsoid(); + + for (int i=0; i<8; i++) + { + debugpoints[i] = new Sphere(); + } + } + } + void DrawObject(GL gl, boolean draw) { + // To clear camera values + ResetOptions(); + //System.out.println("DRAW OBJECT " + mouseDown); -// drawMode = SELECTION; +// DrawMode() = SELECTION; //GL gl = getGL(); if ((TRACK || SHADOWTRACK) || zoomonce) { - if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode) - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); - pingthread.StepToTarget(true); // true); + if (TRACK) + { + if (object.selection != null && + object.selection.size() > 0 && + object.selection.elementAt(0) != null && + !(object.selection.elementAt(0) instanceof Camera) && + !(object.selection.elementAt(0) instanceof ScriptNode)) + { + trackedobject = object.selection.elementAt(0); + //repaint(); + } + else + trackedobject = null; + } + if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode) + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); + pingthread.StepToTarget(); // true); // zoomonce = false; } @@ -9696,9 +11981,9 @@ callist = gl.glGenLists(1); } - boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION; + boolean selectmode = DrawMode() == SELECTION || IsDebugSelection(); - boolean active = !selectmode; // drawMode != SELECTION; // mouseDown; + boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown; if (!mainDL || !active || touched) { @@ -9725,13 +12010,20 @@ PushMatrix(ClickInfo.matbuffer); } - if (drawMode == 0) + if (DrawMode() == 0) { // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++"); usedtextures.clear(); - BindTextures(DEFAULT_TEXTURES, 2); + try + { + BindTextures(DEFAULT_TEXTURES, 2); + } + catch (Exception e) + { + System.err.println("FAILED: " + DEFAULT_TEXTURES); + } } //System.out.println("--> " + stackdepth); // GrafreeD.traceon(); @@ -9739,10 +12031,11 @@ // DRAW object.draw(this, /*(Composite)*/ object, false, false); - if (drawMode == DEFAULT) + if (DrawMode() == DEFAULT) { - if (DEBUG) + if (Globals.DEBUG) { + CreateSelectedPoint(); float radius = 0.05f; if (selectedpoint.radius != radius) { @@ -9750,40 +12043,40 @@ selectedpoint.radius = radius; selectedpoint.recalculate(); selectedpoint.material = new cMaterial(); - selectedpoint.material.color = 0.25f; + selectedpoint.material.color = 0.15f; // Yellow selectedpoint.material.modulation = 0.75f; - debugpoint.radius = radius; - debugpoint.recalculate(); - debugpoint.material = new cMaterial(); - debugpoint.material.color = 0.25f; - debugpoint.material.modulation = 0.75f; + debugpointG.radius = radius; + debugpointG.recalculate(); + debugpointG.material = new cMaterial(); + debugpointG.material.color = 0.25f; // Green + debugpointG.material.modulation = 0.75f; - debugpoint2.radius = radius; - debugpoint2.recalculate(); - debugpoint2.material = new cMaterial(); - debugpoint2.material.color = 0.75f; - debugpoint2.material.modulation = 0.75f; + debugpointP.radius = radius; + debugpointP.recalculate(); + debugpointP.material = new cMaterial(); + debugpointP.material.color = 0.75f; // Purple + debugpointP.material.modulation = 0.75f; - debugpoint3.radius = radius; - debugpoint3.recalculate(); - debugpoint3.material = new cMaterial(); - debugpoint3.material.color = 0.5f; - debugpoint3.material.modulation = 0.75f; + debugpointC.radius = radius; + debugpointC.recalculate(); + debugpointC.material = new cMaterial(); + debugpointC.material.color = 0.5f; // Cyan + debugpointC.material.modulation = 0.75f; - debugpoint4.radius = radius; - debugpoint4.recalculate(); - debugpoint4.material = new cMaterial(); - debugpoint4.material.color = 0f; - debugpoint4.material.modulation = 0.75f; + debugpointR.radius = radius; + debugpointR.recalculate(); + debugpointR.material = new cMaterial(); + debugpointR.material.color = 0f; // Red + debugpointR.material.modulation = 0.75f; InitPoints(radius); } selectedpoint.draw(this, /*(Composite)*/ null, false, false); - debugpoint.draw(this, /*(Composite)*/ null, false,false); - debugpoint2.draw(this, /*(Composite)*/ null, false,false); - debugpoint3.draw(this, /*(Composite)*/ null, false,false); - debugpoint4.draw(this, /*(Composite)*/ null, false,false); + debugpointG.draw(this, /*(Composite)*/ null, false,false); + debugpointP.draw(this, /*(Composite)*/ null, false,false); + debugpointC.draw(this, /*(Composite)*/ null, false,false); + debugpointR.draw(this, /*(Composite)*/ null, false,false); // DrawPoints(this); } @@ -9791,42 +12084,63 @@ } // GrafreeD.traceoff(); //System.out.println(stackdepth); - if (drawMode == 0) + if (DrawMode() == 0) { ReleaseTextures(DEFAULT_TEXTURES); if (CLEANCACHE) - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) { - String tex = e.nextElement(); + cTexture tex = e.nextElement(); // System.out.println("Texture --------- " + tex); - if (tex.equals("WHITE_NOISE")) + if (tex.equals("WHITE_NOISE:")) continue; - if (!usedtextures.containsKey(tex)) + if (!usedtextures.contains(tex)) { + CacheTexture gettex = texturepigment.get(tex); // System.out.println("DISPOSE +++++++++++++++ " + tex); - textures.get(tex).texture.dispose(); - textures.remove(tex); + if (gettex != null) + { + gettex.texture.dispose(); + texturepigment.remove(tex); + } + + gettex = texturebump.get(tex); + // System.out.println("DISPOSE +++++++++++++++ " + tex); + if (gettex != null) + { + gettex.texture.dispose(); + texturebump.remove(tex); + } } } } checker = null; - if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT) + if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT) FindChecker(object); - if (checker != null && drawMode == DEFAULT) + if (checker != null && DrawMode() == DEFAULT) { - // BindTexture(IMMORTAL_TEXTURE); + //BindTexture(IMMORTAL_TEXTURE); + try + { + BindTextures(checker.GetTextures(), checker.texres); + } + catch (Exception e) + { + System.err.println("FAILED: " + checker.GetTextures()); + } // NEAREST GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR); DrawChecker(gl); //checker.Draw(this, null, false); // ReleaseTexture(IMMORTAL_TEXTURE); + ReleaseTextures(checker.GetTextures()); } if (object.parent != null) @@ -9839,7 +12153,7 @@ //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); - if (DISPLAYTEXT && drawMode == DEFAULT) + if (DISPLAYTEXT && DrawMode() == DEFAULT) { // Draw it once, then use the raster Balloon(gl, balloon.createGraphics()); @@ -9895,14 +12209,14 @@ int[] xs = new int[3]; int[] ys = new int[3]; - void DrawString(Object3D obj) // String string) + public void DrawString(Object3D obj) // String string) // INTERFACE { - if (!DISPLAYTEXT || drawMode != DEFAULT) + if (!DISPLAYTEXT || DrawMode() != DEFAULT) { return; } - String string = obj.GetToolTip(); + String string = obj.toString(); //.GetToolTip(); GL gl = GetGL(); @@ -10219,8 +12533,8 @@ //obj.TransformToWorld(light, light); for (int i = tp.size(); --i >= 0;) { - for (int count = tp.get(i).GetTransformCount(); --count>=0;) - LA.xformPos(light, tp.get(i).toParent, light); + //for (int count = tp.get(i).GetTransformCount(); --count>=0;) + LA.xformPos(light, tp.get(i).GlobalTransformInv(), light); } @@ -10237,8 +12551,8 @@ parentcam = cameras[0]; } - for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformPos(light, parentcam.toParent, light); // may 2013 + //for (int count = parentcam.GetTransformCount(); --count>=0;) + LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013 LA.xformPos(light, renderCamera.toScreen, light); @@ -10328,8 +12642,82 @@ //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); - String program = + String programmin = + // Min shader "!!ARBfp1.0\n" + + "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 };" + + "PARAM light2cam0 = program.env[10];" + + "PARAM light2cam1 = program.env[11];" + + "PARAM light2cam2 = program.env[12];" + + "TEMP temp;" + + "TEMP light;" + + "TEMP ndotl;" + + "TEMP normal;" + + "TEMP depth;" + + "TEMP eye;" + + "TEMP pos;" + + + "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];" + + "MOV temp, pos;" + + ShadowTextureFetch("depth", "temp", "1") + + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + + + // No shadow when out of frustum + //"SGE temp.y, depth.z, zero123.y;" + + //"LRP temp.x, temp.y, zero123.y, temp.x;" + + + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow + + // Backlit + "MOV pos.w, zero12t.y;" + // one + "DP4 eye.x, pos, light2cam0;" + + "DP4 eye.y, pos, light2cam1;" + + "DP4 eye.z, pos, light2cam2;" + + Normalize("eye") + + + "DP3 ndotl.y, -eye, normal;" + + //"MUL ndotl.y, ndotl.y, pow2.x;" + + "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, 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;" + + + "MUL temp, temp, ndotl.x;" + // lambert + + "MOV temp.w, zero12t.y;" + // reset alpha + "MOV result.color, temp;" + + "END"; + + String programmax = + "!!ARBfp1.0\n" + + //"OPTION ARB_fragment_program_shadow;" + "PARAM light2cam0 = program.env[10];" + "PARAM light2cam1 = program.env[11];" + @@ -10355,13 +12743,15 @@ "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, image intensity + "PARAM options1 = program.env[62];" + // fog rgb color + "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen "PARAM pointlight = program.env[127];" + // ... "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" + "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" + "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" + + "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" + "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" + "PARAM ten = { 10, 10, 10, 1.0 };" + "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" + @@ -10382,6 +12772,7 @@ "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" + + "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" + "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" + "PARAM c256 = { 256, 256, 256, 1.0 };" + "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" + @@ -10422,6 +12813,10 @@ "TEMP R1;" + "TEMP R2;" + "TEMP R3;" + + "TEMP min;" + + "TEMP max;" + + "TEMP average;" + + "TEMP saturation;" + "TEMP keep1;" + "TEMP keep2;" + "TEMP keep3;" + @@ -10437,8 +12832,7 @@ "TEMP shininess;" + "\n" + "MOV texSamp, one;" + - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + - + "MOV mapgrid.x, one2048th.x;" + "MOV temp, fragment.texcoord[1];" + /* @@ -10459,20 +12853,20 @@ "MUL temp, floor, mapgrid.x;" + //"TEX depth0, temp, texture[1], 2D;" + (((mode & FP_SOFTSHADOW) == 0) ? "" : - TextureFetch("depth0", "temp", "1") + + ShadowTextureFetch("depth0", "temp", "1") + "") + "ADD temp.x, temp.x, mapgrid.x;" + //"TEX depth1, temp, texture[1], 2D;" + (((mode & FP_SOFTSHADOW) == 0) ? "" : - TextureFetch("depth1", "temp", "1") + + ShadowTextureFetch("depth1", "temp", "1") + "") + "ADD temp.y, temp.y, mapgrid.x;" + //"TEX depth2, temp, texture[1], 2D;" + - TextureFetch("depth2", "temp", "1") + + ShadowTextureFetch("depth2", "temp", "1") + "SUB temp.x, temp.x, mapgrid.x;" + //"TEX depth3, temp, texture[1], 2D;" + (((mode & FP_SOFTSHADOW) == 0) ? "" : - TextureFetch("depth3", "temp", "1") + + ShadowTextureFetch("depth3", "temp", "1") + "") + //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + //"MOV params, material;" + @@ -10594,7 +12988,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;" + @@ -10680,11 +13074,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;" + @@ -10694,26 +13083,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];" + // @@ -10843,10 +13279,10 @@ "MAD shadow.x, buffer.x, frac.y, shadow.x;" + "") + - // display shadow only (bump == 0) + // display shadow only (fakedepth == 0) "SUB temp.x, half.x, shadow.x;" + - "MOV temp.y, -params6.x;" + - "SLT temp.z, temp.y, zero.x;" + + "MOV temp.y, -params5.z;" + // params6.x;" + + "SLT temp.z, temp.y, -c256i.x;" + "SUB temp.y, one.x, temp.z;" + "MUL temp.x, temp.x, temp.y;" + "KIL temp.x;" + @@ -10952,10 +13388,42 @@ // skin? // Saturation for skin - /**/ // c'est ici - (Skinshader? "DP3 temp.x, final,one;" + + /**/ + (Skinshader? + "DP3 average.x, final,one;" + + "MUL average, one3rd.xxxx,average.xxxx;" + + + "MIN min.x, final.x,final.y;" + + "MIN min.x, min.x,final.z;" + + + "MAX max.x, final.x,final.y;" + + "MAX max.x, max.x,final.z;" + + "MOV max, max.xxxx;" + + + "SUB saturation, max, final;" + + + "ADD temp.x, max.x, one10th.x;" + + "RCP temp.x, temp.x;" + + "MUL temp.x, temp.x, half.x;" + + "MUL saturation, saturation, temp.xxxx;" + + + "DP3 ndotl.x, normald, light;" + + "MAX ndotl.x, ndotl.x, -ndotl.x;" + + + "SUB temp.x, one.x, ndotl.x;" + + // Tuning for default skin + //"ADD temp.x, temp.x, options2.z;" + // lightsheen + "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen + "ADD temp.y, one.y, options2.y;" + // subsurface + "MUL temp.x, temp.x, temp.y;" + + + "MUL saturation, saturation, temp.xxxx;" + + "SUB_SAT temp, max, saturation;" + +/** + "DP3 temp.x, final,one;" + "MUL R2, one3rd.xxxx,temp.xxxx;" + - "SUB temp, final,R2;" + + "SUB temp, final, R2;" + + // using light angle "DP3 ndotl.x, normald,light;" + //"SLT ndotl.y, ndotl.x, zero.x;" + @@ -10968,7 +13436,6 @@ // using light intensity "MOV ndotl.z, R2.x;" + "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning... - // june 2014 "MAD R1.x, ndotl.z,slope.y,one.x;" + // "SUB ndotl.x, one.x, ndotl.x;" + @@ -10980,6 +13447,7 @@ //"MUL R2.y, shadow.x,R2.y;" + // avril 2014 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin) +/**/ // "ADD final, R2,temp;" + "MOV final, temp;" @@ -11069,7 +13537,7 @@ /**/ // HDR "MOV temp.z, final.a;" + - "MUL final, final,options1.w;" + + "MUL final, final,options2.x;" + "MOV final.a, temp.z;" + /**/ @@ -11145,8 +13613,19 @@ //once = true; } - System.out.print("Program #" + mode + "; 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); @@ -11193,7 +13672,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); @@ -11238,30 +13718,32 @@ return out; } - String TextureFetch(String dest, String src, String unit) + // Also does frustum culling + String ShadowTextureFetch(String dest, String src, String unit) { return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + "SGE " + src + ".w, " + src + ".x, eps.x;" + "SGE " + src + ".z, " + src + ".y, eps.x;" + + "SLT " + dest + ".x, " + src + ".x, one.x;" + + "SLT " + dest + ".y, " + src + ".y, one.x;" + "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + - "SLT " + src + ".z, " + src + ".x, one.x;" + - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + - "SLT " + src + ".z, " + src + ".y, one.x;" + - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + //"SWZ buffer, temp, w,w,w,w;"; - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + "SUB " + src + ".z, " + "one.x, " + src + ".w;" + //"MUL " + src + ".z, " + src + ".z, infinity.x;" + //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; } String Shadow(String depth, String shadow) { return "MAX temp.x, ndotl.x, one64th.x;" + + "MIN temp.x, temp.x, ninetenth.x;" + /**/ // Sine "MUL temp.y, temp.x, temp.x;" + @@ -11277,12 +13759,16 @@ "ADD " + depth + ".z, " + depth + ".z, temp.x;" + //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing! + + // Compare fragment depth in light space with shadowmap. "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" + "SGE temp.y, temp.x, zero.x;" + - "SUB " + shadow + ".y, one.x, temp.y;" + + "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded + + // Reverse comparison "SUB temp.x, one.x, temp.x;" + "MUL " + shadow + ".x, temp.x, temp.y;" + - "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded + "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" + @@ -11296,6 +13782,10 @@ // No shadow for backface "DP3 temp.x, normal, lightd;" + "SLT temp.x, temp.x, zero.x;" + // shadoweps + "LRP " + shadow + ", temp.x, one, " + shadow + ";" + + + // No shadow when out of frustum + "SGE temp.x, " + depth + ".z, one.z;" + "LRP " + shadow + ", temp.x, one, " + shadow + ";" + ""; } @@ -11441,8 +13931,9 @@ /*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 - Object3D.cVector2[] vector2buffer; + /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax + + //Object3D.cVector2[] vector2buffer; // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea // OUT : diff, spec @@ -11458,9 +13949,10 @@ "DP3 " + dest + ".z," + "normals," + "eye;" + "MAX " + dest + ".w," + dest + ".z," + "eps.x;" + //"MOV " + dest + ".w," + "normal.z;" + - "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + - "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + - //"MOV " + dest + ".z," + "params2.w;" + +// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET +// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" + + + "MOV " + dest + ".z," + "params2.w;" + // EXACT "POW " + dest + ".w," + dest + ".w," + dest + ".z;" + "RCP " + dest + ".w," + dest + ".w;" + //"RSQ " + dest + ".w," + dest + ".w;" + @@ -11606,7 +14098,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 };" + @@ -11667,7 +14159,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;" + @@ -11714,7 +14206,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;" : "") + @@ -11849,12 +14343,13 @@ public void mouseClicked(MouseEvent e) { System.out.println("mouseClicked: " + e); + System.exit(0); } public void mousePressed(MouseEvent e) { //System.out.println("mousePressed: " + e); - clickStart(e.getX(), e.getY(), e.getModifiersEx()); + clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx()); } static long prevtime = 0; @@ -11881,14 +14376,18 @@ //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio); + if (BUTTONLESSWHEEL) if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30) { return; } + //boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK); + + boolean vr = capsLocked && !lightMode; // TIMER - if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR + if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !vr) // VR { keepboxmode = BOXMODE; keepsupport = SUPPORT; @@ -11928,8 +14427,8 @@ // mode |= META; //} - SetMouseMode(WHEEL | e.getModifiersEx()); - drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0); + SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx()); + drag(anchorX, anchorY + e.getUnitsToScroll()*8, e.getModifiers(), e.getModifiersEx()); anchorX = ax; anchorY = ay; prevX = px; @@ -11963,6 +14462,7 @@ else if (evt.getSource() == AAtimer) { + Globals.TIMERRUNNING = false; if (mouseDown) { //new Exception().printStackTrace(); @@ -11988,6 +14488,10 @@ // LIVE = waslive; // wasliveok = true; // waslive = false; + + // May 2019 Forget it: + if (true) + return; // source == timer if (mouseDown) @@ -12017,22 +14521,24 @@ // ObjEditor.tweenManager.update(1f / 60f); // fev 2014??? - if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode) - object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK); - pingthread.StepToTarget(true); // true); + if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode) + object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK); + pingthread.StepToTarget(); // true); } + // if (!LIVE) super.repaint(); } javax.swing.Timer timer = new javax.swing.Timer(350, this); - void clickStart(int x, int y, int modifiers) + void clickStart(int x, int y, int modifiers, int modifiersex) { if (!wasliveok) return; AAtimer.restart(); // + Globals.TIMERRUNNING = true; // waslive = LIVE; // LIVE = false; @@ -12044,7 +14550,7 @@ // touched = true; // main DL if (isRenderer) { - SetMouseMode(modifiers); + SetMouseMode(modifiers, modifiersex); } selectX = anchorX = x; @@ -12057,7 +14563,7 @@ clicked = true; hold = false; - if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection + if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection { // System.out.println("RESTART II " + modifiers); @@ -12082,14 +14588,15 @@ drag = false; //System.out.println("Mouse DOWN"); editObj = false; - ClickInfo info = new ClickInfo(); - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); - info.pane = this; - info.camera = renderCamera; - info.x = x; - info.y = y; - info.modifiers = modifiers; - editObj = object.doEditClick(info, 0); + //ClickInfo info = new ClickInfo(); + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); + object.clickInfo.pane = this; + object.clickInfo.camera = renderCamera; + object.clickInfo.x = x; + object.clickInfo.y = y; + object.clickInfo.modifiers = modifiersex; + editObj = object.doEditClick(//info, + 0); if (!editObj) { hasMarquee = true; @@ -12105,19 +14612,22 @@ public void mouseDragged(MouseEvent e) { + Globals.MOUSEDRAGGED = true; + + //System.out.println("mouseDragged: " + e); if (isRenderer) movingcamera = true; + //if (drawing) //return; - //System.out.println("mouseDragged: " + e); - if ((e.getModifiersEx() & CTRL) != 0 - || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen()) + if ((e.getModifiersEx() & CTRL) != 0 || + (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen()) { //System.out.println("mouseDragged: " + e); clickEnd(e.getX(), e.getY(), e.getModifiersEx()); } else - drag(e.getX(), e.getY(), e.getModifiersEx()); + drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx()); //try { Thread.sleep(1); } catch (Exception ex) {} } @@ -12130,9 +14640,22 @@ cVector tmp2 = new cVector(); boolean isMoving; + public cVector TargetLookAt() + { + return targetLookAt; + } + + javax.vecmath.Point3d eye = new javax.vecmath.Point3d(); + javax.vecmath.Point3d eye2 = new javax.vecmath.Point3d(); + javax.vecmath.Vector3d dir = new javax.vecmath.Vector3d(); + + class PingThread extends Thread { boolean jump; + boolean live; + + boolean mute = false; // void JumpToTarget() // { @@ -12148,6 +14671,95 @@ // only one thread!? synchronized void StepToTarget(boolean jump) { + RigidBody.pos.x = 0; + RigidBody.pos.y = 0; + RigidBody.pos.z = 0; + if (RigidBody.justclicked) + { +// RigidBody.pos.x = (float)manipCamera.lookAt.x; +// RigidBody.pos.y = (float)manipCamera.lookAt.y; +// RigidBody.pos.z = (float)manipCamera.lookAt.z; + // System.err.println("selected point = " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][1]) + " " + Trunk(selectedpoint.toParent[3][2])); + CreateSelectedPoint(); + + RigidBody.pos.x = (float)selectedpoint.toParent[3][0]; + RigidBody.pos.y = (float)selectedpoint.toParent[3][1]; + RigidBody.pos.z = (float)selectedpoint.toParent[3][2]; + + RigidBody.wind.set(RigidBody.pos); + RigidBody.wind.x -= (float)manipCamera.location.x; + RigidBody.wind.y -= (float)manipCamera.location.y; + RigidBody.wind.z -= (float)manipCamera.location.z; + RigidBody.wind.normalize(); + } + + if (mute) + return; + + if (capsLocked && manipCamera.viewCode == 0) + { + eye.x = manipCamera.location.x; + eye.y = manipCamera.location.y + 0.25; + eye.z = manipCamera.location.z; + + dir.y = -1; + + Ray ray = new Ray(eye, dir); + + IntersectResult res = new IntersectResult(); + res.t = Double.POSITIVE_INFINITY; + + tmp.set(targetLookAt); + tmp.sub(manipCamera.location); + + double dist = tmp.length(); + + tmp.normalize(); + + eye2.x = manipCamera.location.x + tmp.x * 0.25; + eye2.y = manipCamera.location.y + 0.25; + eye2.z = manipCamera.location.z + tmp.z * 0.25; + + Ray ray2 = new Ray(eye2, dir); + + IntersectResult res2 = new IntersectResult(); + res2.t = Double.POSITIVE_INFINITY; + + if (object.intersect(ray, res) && object.intersect(ray2, res2) && Math.abs(res.t - res2.t) < 0.25) + { + //tmp.set(manipCamera.location); + + manipCamera.location.x = ray.eyePoint.x + ray.viewDirection.x * res.t; + manipCamera.location.y = ray.eyePoint.y + ray.viewDirection.y * res.t + 0.5; + manipCamera.location.z = ray.eyePoint.z + ray.viewDirection.z * res.t; + + //tmp.sub(manipCamera.location); + + targetLookAt.x = ray2.eyePoint.x + ray2.viewDirection.x * res2.t; + targetLookAt.y = ray2.eyePoint.y + ray2.viewDirection.y * res2.t + 0.5; + targetLookAt.z = ray2.eyePoint.z + ray2.viewDirection.z * res2.t; + + targetLookAt.sub(manipCamera.location); + targetLookAt.normalize(); + targetLookAt.mul(dist); + targetLookAt.add(manipCamera.location); + + //if (tmp.dot(tmp) > 0.000001) + // System.out.println("INTERSECTION " + manipCamera.location); + + manipCamera.lookAt.set(targetLookAt); + + tmp.x = res.n.x; + tmp.y = res.n.y; + tmp.z = res.n.z; + tmp.x += res2.n.x; + tmp.y += res2.n.y; + tmp.z += res2.n.z; + tmp.normalize(); + manipCamera.UP.set(tmp); + } + } + tmp.set(targetLookAt); tmp.sub(manipCamera.lookAt); // june 2014 @@ -12185,7 +14797,7 @@ if (tmp.dot(tmp) > 1) // may 2014. far away: jump to target { - jump = true; // step = 1; + // sep 2019 jump = true; // step = 1; } if (OEILONCE && OEIL) @@ -12220,7 +14832,10 @@ if (tmp.dot(tmp) < 0.00001) { zoomonce = false; + live = false; } + else + live = true; tmp.mul(step > step2 ? step : step2); } @@ -12247,7 +14862,7 @@ { if (LOOKAT) manipCamera.lookAt.add(tmp); - if (OEIL) + if (OEIL && !capsLocked) manipCamera.location.add(tmp); { @@ -12262,13 +14877,16 @@ lightCamera.computeTransform(); } } - manipCamera.computeTransform(); + if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0) + { + manipCamera.computeTransform(); + } } // ?????? mouseDown = true; //System.out.println("---------------- ---------- Paint " + tmp.length2()); if (lightMode) { - lighttouched = true; + Globals.lighttouched = true; } if (OEILONCE && OEIL) @@ -12285,6 +14903,7 @@ public void run() { + new Exception().printStackTrace(); System.exit(0); for (;;) { @@ -12326,7 +14945,7 @@ mouseDown = false; if (lightMode) { - lighttouched = true; + Globals.lighttouched = true; } repaint(); alreadypainted = true; @@ -12334,7 +14953,7 @@ isMoving = false; } //?? - if (isLIVE() && !alreadypainted) + if (Globals.isLIVE() && !alreadypainted) { // FOR DEBUG BREAKPOINT USING PAUSE: while (true) repaint(); @@ -12346,57 +14965,115 @@ { if (lightMode) { - lighttouched = true; + Globals.lighttouched = true; } - drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS); + drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS); } //else } } } + PingThread pingthread = new PingThread(); - int delta = 5; - int speed = 5; + int delta = 1; + int speed = 1; + int walk = 8; boolean autorepeat = false; + void Walk() + { + manipCamera.BackForth(0, walk, 1000); + + targetLookAt.set(manipCamera.lookAt); + } + + void ViewAngle(float dy) + { + double factor = Math.exp(-dy/300.0); // (1 + dy/100); + + if (manipCamera.shaper_fovy * factor > 1 && + manipCamera.shaper_fovy * factor < 150) + { + manipCamera.shaper_fovy *= factor; + //System.out.println("fovy = " + shaper_fovy); + } + } + void GoDown(int mod) { MODIFIERS |= COMMAND; - /* + boolean isVR = (mouseMode&VR)!=0; + /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(0, -speed); - else - manipCamera.BackForth(0, -speed*delta, getWidth()); - */ - if ((mod & SHIFT) == SHIFT) { - mouseMode = mouseMode; // VR?? - } else - { - mouseMode |= BACKFORTH; +// if (isVR) +// manipCamera.RotateInterest(0, speed); +// else + if (isVR) + ViewAngle(-speed*delta); + else + manipCamera.Translate(0, -speed*delta, getWidth()); } + else + { + if (isVR) + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); + else + manipCamera.RotatePosition(0, -speed); + } + + /**/ +// if ((mod & SHIFT) == SHIFT) +// { +// mouseMode = mouseMode; // VR?? +// } else +// { +// mouseMode |= BACKFORTH; +// } + targetLookAt.set(manipCamera.lookAt); + //prevX = X = anchorX; prevY = Y = anchorY - (int) (renderCamera.Distance()); } void GoUp(int mod) { + RigidBody.justclicked = true; + MODIFIERS |= COMMAND; - /* + /**/ + boolean isVR = (mouseMode&VR)!=0; + if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(0, speed); - else - manipCamera.BackForth(0, speed*delta, getWidth()); - */ - if ((mod & SHIFT) == SHIFT) { - mouseMode = mouseMode; - } else - { - mouseMode |= BACKFORTH; +// if (isVR) +// manipCamera.RotateInterest(0, -speed); +// else + if (isVR) + ViewAngle(speed*delta); + else + manipCamera.Translate(0, speed*delta, getWidth()); } + else + { + if (isVR) + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); + else + manipCamera.RotatePosition(0, speed); + } + + /**/ +// if ((mod & SHIFT) == SHIFT) +// { +// mouseMode = mouseMode; +// } else +// { +// mouseMode |= BACKFORTH; +// } + targetLookAt.set(manipCamera.lookAt); + //prevX = X = anchorX; prevY = Y = anchorY + (int) (renderCamera.Distance()); } @@ -12404,20 +15081,31 @@ void GoLeft(int mod) { MODIFIERS |= COMMAND; - /* + /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(speed, 0); + manipCamera.Translate(speed, 0, getWidth()); else - manipCamera.Translate(speed*delta, 0, getWidth()); - */ - if ((mod & SHIFT) == SHIFT) { - mouseMode = mouseMode; - } else - { - mouseMode |= ROTATE; - } // TRANSLATE; + if ((mouseMode&VR)!=0) + manipCamera.RotateInterest(-speed*manipCamera.shaper_fovy/90, 0); + else + manipCamera.RotatePosition(speed*manipCamera.shaper_fovy/90, 0); + } + + /**/ +// if ((mod & SHIFT) == SHIFT) +// { +// mouseMode = mouseMode; +// } else +// { +// mouseMode |= ROTATE; +// } // TRANSLATE; + //System.err.println("lookAt = " + manipCamera.lookAt); + //System.err.println("location = " + manipCamera.location); + + targetLookAt.set(manipCamera.lookAt); + prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); prevY = Y = anchorY; } @@ -12425,20 +15113,28 @@ void GoRight(int mod) { MODIFIERS |= COMMAND; - /* + /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(-speed, 0); + manipCamera.Translate(-speed, 0, getWidth()); else - manipCamera.Translate(-speed*delta, 0, getWidth()); - */ - if ((mod & SHIFT) == SHIFT) { - mouseMode = mouseMode; - } else - { - mouseMode |= ROTATE; - } // TRANSLATE; + if ((mouseMode&VR)!=0) + manipCamera.RotateInterest(speed*manipCamera.shaper_fovy/90, 0); + else + manipCamera.RotatePosition(-speed*manipCamera.shaper_fovy/90, 0); + } + + /**/ +// if ((mod & SHIFT) == SHIFT) +// { +// mouseMode = mouseMode; +// } else +// { +// mouseMode |= ROTATE; +// } // TRANSLATE; + targetLookAt.set(manipCamera.lookAt); + prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); prevY = Y = anchorY; } @@ -12448,7 +15144,7 @@ int X, Y; boolean SX, SY; - void drag(int x, int y, int modifiers) + void drag(int x, int y, int modifiers, int modifiersex) { if (IsFrozen()) { @@ -12457,17 +15153,17 @@ drag = true; // NEW - boolean continuous = (modifiers & COMMAND) == COMMAND; + boolean continuous = (modifiersex & COMMAND) == COMMAND; X = x; Y = y; // floating state for animation - MODIFIERS = modifiers; - modifiers &= ~1024; + MODIFIERS = modifiersex; + modifiersex &= ~1024; if (false) // modifiers != 0) { //new Exception().printStackTrace(); - System.out.println("mouseDragged: " + modifiers); + System.out.println("mouseDragged: " + modifiersex); System.out.println("SHIFT = " + SHIFT); System.out.println("CONTROL = " + COMMAND); System.out.println("META = " + META); @@ -12480,14 +15176,16 @@ if (editObj) { drag = true; - ClickInfo info = new ClickInfo(); - info.bounds.setBounds(0, 0, + //ClickInfo info = new ClickInfo(); + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); - info.pane = this; - info.camera = renderCamera; - info.x = x; - info.y = y; - object.editWindow.copy.doEditDrag(info); + object.clickInfo.pane = this; + object.clickInfo.camera = renderCamera; + object.clickInfo.x = x; + object.clickInfo.y = y; + object //.GetWindow().copy + .doEditDrag(//info, + (modifiers & MouseEvent.BUTTON3_MASK) != 0); } else { if (x < startX) @@ -12570,6 +15268,11 @@ if ((mouseMode & ZOOM) != 0) { //if ((mouseMode & BACKFORTH) != 0) + if ((modifiersex & SHIFT) == SHIFT) + { + ViewAngle(dy); + } + else if ((mouseMode & VR) != 0) manipCamera.BackForth(dx, dy, getWidth()); else @@ -12589,6 +15292,7 @@ { manipCamera.Translate(dx, dy, getWidth()); } + else if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0) { manipCamera.RotateInterest(dx, dy); @@ -12599,7 +15303,7 @@ if (manipCamera == lightCamera) { - lighttouched = true; + Globals.lighttouched = true; } /* switch (mode) @@ -12635,23 +15339,30 @@ } } +// ClickInfo clickInfo = new ClickInfo(); + public void mouseMoved(MouseEvent e) { - //System.out.println("mouseMoved: " + e); +//object.editWindow.frame. + setCursor(Cursor.getDefaultCursor()); + //System.out.println("mouseMoved: " + e); if (isRenderer) return; - ClickInfo ci = new ClickInfo(); - ci.x = e.getX(); - ci.y = e.getY(); - ci.modifiers = e.getModifiersEx(); - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); - ci.pane = this; - ci.camera = renderCamera; + // Mouse cursor feedback + object.clickInfo.x = e.getX(); + object.clickInfo.y = e.getY(); + object.clickInfo.modifiers = e.getModifiersEx(); + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); + object.clickInfo.pane = this; + object.clickInfo.camera = renderCamera; if (!isRenderer) { - if (object.editWindow.copy.doEditClick(ci, 0)) + //ObjEditor editWindow = object.editWindow; + //Object3D copy = editWindow.copy; + if (object.doEditClick(//clickInfo, + 0)) { setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else @@ -12663,7 +15374,17 @@ public void mouseReleased(MouseEvent e) { + if (isRenderer && !movingcamera) + { + RigidBody.justclicked = true; + System.out.println("justclicked: " + e); + } + + Globals.MOUSEDRAGGED = false; + movingcamera = false; + X = 0; // getBounds().width/2; + Y = 0; // getBounds().height/2; //System.out.println("mouseReleased: " + e); clickEnd(e.getX(), e.getY(), e.getModifiersEx()); } @@ -12686,9 +15407,9 @@ boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection - if (control || command || IsFrozen()) +// No delay if (control || command || IsFrozen()) timeout = true; - else +// ?? May 2019 else // timer.setDelay((modifiers & 128) != 0?0:350); mouseDown = false; if (!control && !command) // june 2013 @@ -12798,7 +15519,7 @@ System.out.println("keyReleased: " + e); } - void SetMouseMode(int modifiers) + void SetMouseMode(int modifiers, int modifiersex) { //System.out.println("SetMouseMode = " + modifiers); //modifiers &= ~1024; @@ -12810,24 +15531,30 @@ //if (modifiers == 0) // || (modifiers == (1024 | CONTROL))) // return; //System.out.println("SetMode = " + modifiers); - if ((modifiers & WHEEL) == WHEEL) + if ((modifiersex & WHEEL) == WHEEL) { mouseMode |= ZOOM; } - if ((modifiers & META) == META) + + //boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK); + boolean vr = capsLocked && !lightMode; + + if (vr) // || (modifiers & META) == META) { mouseMode |= VR; // BACKFORTH; } - if ((modifiers & CTRLCLICK) == CTRLCLICK) - { - mouseMode |= SELECT; // BACKFORTH; - } - if ((modifiers & COMMAND) == COMMAND) + if ((modifiersex & CTRLCLICK) == CTRLCLICK) { mouseMode |= SELECT; } - if ((modifiers & SHIFT) == SHIFT || forcetranslate) + if ((modifiersex & COMMAND) == COMMAND) { + mouseMode |= SELECT; + } + if (//(modifiersex & SHIFT) == SHIFT || + forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0) + { + mouseMode &= ~VR; mouseMode |= TRANSLATE; } // if ((modifiers & SHIFT_META) == SHIFT_META) @@ -12854,10 +15581,10 @@ if (isRenderer) // { - SetMouseMode(modifiers); + SetMouseMode(0, modifiers); } - theRenderer.keyPressed(key); + Globals.theRenderer.keyPressed(key); } int kompactbit = 4; // power bit @@ -12869,8 +15596,18 @@ float SATPOW = 1; // 2; // 0.5f; float BRIPOW = 1; // 0.5f; // 0.5f; - void keyPressed(int key) +static BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); + +// Create a new blank cursor. +static Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor( + cursorImg, new Point(0, 0), "blank cursor"); + + public void keyPressed(int key) { +// Set the blank cursor to the JFrame. +//object.editWindow.frame. + setCursor(blankCursor); + if (key >= '0' && key <= '5') clampbit = (key-'0'); @@ -12916,7 +15653,8 @@ // break; case 'T': CACHETEXTURE ^= true; - textures.clear(); + texturepigment.clear(); + texturebump.clear(); // repaint(); break; case 'Y': @@ -12926,8 +15664,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; @@ -12984,7 +15722,7 @@ case 'B': BRISMOOTH ^= true; SHADOWCULLFACE ^= true; - lighttouched = true; + Globals.lighttouched = true; repaint(); break; case 'b': @@ -13001,7 +15739,9 @@ case 'E' : COMPACT ^= true; repaint(); break; - case 'W' : DEBUGHSB ^= true; + case 'W' : // Wide Window (fullscreen) + //DEBUGHSB ^= true; + ObjEditor.theFrame.ToggleFullScreen(); repaint(); break; case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break; @@ -13026,8 +15766,8 @@ RevertCamera(); repaint(); break; + //case 'l': case 'L': - case 'l': if (lightMode) { lightMode = false; @@ -13046,7 +15786,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(); @@ -13057,7 +15797,8 @@ break; case 'm': { - PrintMemory(); + //PrintMemory(); + ToggleImageFlip(); break; } case 'M': @@ -13084,27 +15825,31 @@ repaint(); break; case 'O': - drawMode = OCCLUSION; - repaint(); - break; + // 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': case '4': case '5': - newenvy = Character.getNumericValue(key); - repaint(); - break; case '6': case '7': case '8': case '9': - BGcolor = (key - '6')/3.f; + if (true) // envyoff) + { + BGcolor = (key - '1')/8.f; + } + else + { + //newenvy = Character.getNumericValue(key); + } repaint(); break; case '!': @@ -13170,28 +15915,47 @@ case '_': kompactbit = 5; break; - case '+': - kompactbit = 6; - break; +// case '+': +// kompactbit = 6; +// break; case ' ': + capsLocked ^= true; + repaint(); + break; + case 'l': lightMode ^= true; - lighttouched = true; + if (lightMode) + { + keepshadow = Globals.RENDERSHADOW; + Globals.RENDERSHADOW = false; + } + else + { + Globals.RENDERSHADOW = keepshadow; + } + + Globals.lighttouched = true; manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; targetLookAt.set(manipCamera.lookAt); repaint(); break; //case '`' : case ESC: + if (FULLSCREEN) + object.editWindow.ToggleFullScreen(); + break; + case 'p': RENDERPROGRAM += 1; RENDERPROGRAM %= 3; + repaint(); break; case 'Z': - RESIZETEXTURE ^= true; - break; + //RESIZETEXTURE ^= true; + //break; case 'z': - RENDERSHADOW ^= true; - lighttouched = true; + Globals.RENDERSHADOW ^= true; + Globals.lighttouched = true; repaint(); break; //case UP: @@ -13217,13 +15981,19 @@ FlipTransform(); break; case ENTER: - object.editWindow.ScreenFit(); // Edit(); + // object.editWindow.ScreenFit(); // Edit(); + ToggleLive(); + if (capsLocked) + { + Globals.WALK ^= true; + } break; case DELETE: ClearSelection(); break; - /* case '+': + + /* //fontsize += 1; bbzoom *= 2; repaint(); @@ -13240,30 +16010,36 @@ case '=': IncDepth(); //fontsize += 1; - object.editWindow.refreshContents(true); + object.GetWindow().refreshContents(true); maskbit = 6; break; case '-': //if (PixelThreshold>1) PixelThreshold /= 2; DecDepth(); maskbit = 5; //if(fontsize > 1) fontsize -= 1; - if (object.editWindow == null) - new Exception().printStackTrace(); - else - object.editWindow.refreshContents(true); +// if (object.editWindow == null) +// new Exception().printStackTrace(); +// else + object.GetWindow().refreshContents(true); break; case '{': - manipCamera.shaper_fovy /= 1.1; + double factor = 1.1; + if (manipCamera.shaper_fovy / factor > 0.1) + manipCamera.shaper_fovy /= factor; System.out.println("FOV = " + manipCamera.shaper_fovy); repaint(); break; case '}': - manipCamera.shaper_fovy *= 1.1; + factor = 1.1; + if (manipCamera.shaper_fovy * factor < 150) + manipCamera.shaper_fovy *= factor; System.out.println("FOV = " + manipCamera.shaper_fovy); repaint(); break; case '[': - manipCamera.shaper_fovy /= 1.01; + factor = 1.01; + if (manipCamera.shaper_fovy / factor > 0.1) + manipCamera.shaper_fovy /= factor; if (false) //manipCamera.hAspect == 0) { double x = Math.tan(manipCamera.shaper_fovy * Math.PI / 180 / 2); @@ -13279,7 +16055,9 @@ break; case ']': //manipCamera.shaper_fovy += (180 - manipCamera.shaper_fovy)*0.1; - manipCamera.shaper_fovy *= 1.01; + factor = 1.01; + if (manipCamera.shaper_fovy * factor < 150) + manipCamera.shaper_fovy *= factor; if (false) //manipCamera.hAspect == 0) { double x = Math.tan(manipCamera.shaper_fovy * Math.PI / 180 / 2); @@ -13305,6 +16083,7 @@ } //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy); } + static double OCCLUSIONBOOST = 1; // 0.5; void keyReleased(int key, int modifiers) @@ -13312,102 +16091,117 @@ //mode = ROTATE; if ((MODIFIERS & COMMAND) == 0) // VR?? { - SetMouseMode(modifiers); + SetMouseMode(0, modifiers); } } - protected void processKeyEvent(KeyEvent e) + boolean keys[] = new boolean[256]; + int speedkey[] = new int[256]; + int modifiers = 0; + + public void processKeyEvent(KeyEvent e) { switch (e.getID()) { case KeyEvent.KEY_PRESSED: - if (!autorepeat) - { - //System.out.println("processKeyEvent: " + KeyEvent.getKeyText(e.getKeyCode())); - keyPressed(e.getKeyChar(), e.getModifiersEx()); - } - if (manipCamera == lightCamera) - { - switch (e.getKeyCode()) - { - case DOWN_ARROW: - lightCamera.DECAL /= 2; - repaint(); - break; - case UP_ARROW: - lightCamera.DECAL *= 2; - repaint(); - break; - case LEFT_ARROW: - lightCamera.SCALE /= 2; - repaint(); - break; - case RIGHT_ARROW: - lightCamera.SCALE *= 2; - repaint(); - break; - default: - break; - } - - System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE); - } else - { - if (true) // !autorepeat) - { - boolean reset = true; - - switch (e.getKeyCode()) - { - case DOWN_ARROW: - GoDown(e.getModifiersEx()); - repaint(); - break; - case UP_ARROW: - GoUp(e.getModifiersEx()); - repaint(); - break; - case LEFT_ARROW: - GoLeft(e.getModifiersEx()); - repaint(); - break; - case RIGHT_ARROW: - GoRight(e.getModifiersEx()); - repaint(); - break; - default: - reset = false; - break; - } - - if (reset) - { - autorepeat = true; - - targetLookAt.set(manipCamera.lookAt); - } - } - } + keys[e.getKeyCode()] = true; + modifiers = e.getModifiersEx(); + keyPressed(e.getKeyChar(), modifiers); + //Globals.theRenderer.keyPressed(e.getKeyChar()); + repaint(); break; - case KeyEvent.KEY_TYPED: - break; +// if (!autorepeat) +// { +// //System.out.println("processKeyEvent: " + KeyEvent.getKeyText(e.getKeyCode())); +// keyPressed(e.getKeyChar(), e.getModifiersEx()); +// } +// if (manipCamera == lightCamera) +// { +// switch (e.getKeyCode()) +// { +// case DOWN_ARROW: +// lightCamera.DECAL /= 2; +// repaint(); +// break; +// case UP_ARROW: +// lightCamera.DECAL *= 2; +// repaint(); +// break; +// case LEFT_ARROW: +// lightCamera.SCALE /= 2; +// repaint(); +// break; +// case RIGHT_ARROW: +// lightCamera.SCALE *= 2; +// repaint(); +// break; +// default: +// break; +// } +// +// System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE); +// } else +// { +// if (true) // !autorepeat) +// { +// boolean reset = true; +// +// switch (e.getKeyCode()) +// { +// case DOWN_ARROW: +// GoDown(e.getModifiersEx()); +// repaint(); +// break; +// case UP_ARROW: +// GoUp(e.getModifiersEx()); +// repaint(); +// break; +// case LEFT_ARROW: +// GoLeft(e.getModifiersEx()); +// repaint(); +// break; +// case RIGHT_ARROW: +// GoRight(e.getModifiersEx()); +// repaint(); +// break; +// default: +// reset = false; +// break; +// } +// +// if (reset) +// { +// autorepeat = true; +// +// targetLookAt.set(manipCamera.lookAt); +// } +// } +// } +// break; +// case KeyEvent.KEY_TYPED: +// break; case KeyEvent.KEY_RELEASED: - { - switch (e.getKeyCode()) - { - case DOWN_ARROW: - case UP_ARROW: - case LEFT_ARROW: - case RIGHT_ARROW: - MODIFIERS &= ~COMMAND; - autorepeat = false; - break; - default: - break; - } + keys[e.getKeyCode()] = false; + modifiers = e.getModifiersEx(); keyReleased(e.getKeyChar(), e.getModifiersEx()); + repaint(); break; - } +// { +// switch (e.getKeyCode()) +// { +// case DOWN_ARROW: +// case UP_ARROW: +// case LEFT_ARROW: +// case RIGHT_ARROW: +// MODIFIERS &= ~COMMAND; +// autorepeat = false; +// break; +// default: +// break; +// } +// keyReleased(e.getKeyChar(), e.getModifiersEx()); +// break; +// } default: break; } @@ -13446,8 +16240,9 @@ protected void processMouseMotionEvent(MouseEvent e) { - //System.out.println("processMouseMotionEvent: " + mouseMode); - if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0) + //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton()); + //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0) + if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0) { mouseMoved(e); } else @@ -13472,11 +16267,12 @@ } */ - object.editWindow.EditSelection(); + object.GetWindow().EditSelection(false); } void SelectParent() { + new Exception().printStackTrace(); System.exit(0); Composite group = (Composite) object; java.util.Vector selectees = new java.util.Vector(group.selection); @@ -13488,10 +16284,10 @@ { //selectees.remove(i); System.out.println("select parent of " + elem); - group.editWindow.Select(elem.parent.GetTreePath(), first, true); + group.GetWindow().Select(elem.parent.GetTreePath(), first, true); } else { - group.editWindow.Select(elem.GetTreePath(), first, true); + group.GetWindow().Select(elem.GetTreePath(), first, true); } first = false; @@ -13500,6 +16296,7 @@ void SelectChildren() { + new Exception().printStackTrace(); System.exit(0); /* Composite group = (Composite) object; @@ -13532,12 +16329,12 @@ for (int j = 0; j < group.children.size(); j++) { elem = (Object3D) group.children.elementAt(j); - object.editWindow.Select(elem.GetTreePath(), first, true); + object.GetWindow().Select(elem.GetTreePath(), first, true); first = false; } } else { - object.editWindow.Select(elem.GetTreePath(), first, true); + object.GetWindow().Select(elem.GetTreePath(), first, true); } first = false; @@ -13548,21 +16345,21 @@ { //Composite group = (Composite) object; Object3D group = object; - group.editWindow.loadClipboard(true); // ClearSelection(false); + group.GetWindow().loadClipboard(true); // ClearSelection(false); } void ResetTransform(int mask) { //Composite group = (Composite) object; Object3D group = object; - group.editWindow.ResetTransform(mask); + group.GetWindow().ResetTransform(mask); } void FlipTransform() { //Composite group = (Composite) object; Object3D group = object; - group.editWindow.FlipTransform(); + group.GetWindow().FlipTransform(); // group.editWindow.ReduceMesh(true); } @@ -13570,7 +16367,7 @@ { //Composite group = (Composite) object; Object3D group = object; - group.editWindow.PrintMemory(); + group.GetWindow().PrintMemory(); // group.editWindow.ReduceMesh(true); } @@ -13578,7 +16375,7 @@ { //Composite group = (Composite) object; Object3D group = object; - group.editWindow.ResetCentroid(); + group.GetWindow().ResetCentroid(); } void IncDepth() @@ -13660,11 +16457,11 @@ int width = getBounds().width; int height = getBounds().height; - ClickInfo info = new ClickInfo(); - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); //Image img = CreateImage(width, height); //System.out.println("width = " + width + "; height = " + height + "\n"); + Graphics gr = g; // img.getGraphics(); + if (!hasMarquee) { if (Xmin < Xmax) // !locked) @@ -13736,44 +16533,92 @@ } if (object != null && !hasMarquee) { + if (object.clickInfo == null) + object.clickInfo = new ClickInfo(); + ClickInfo info = object.clickInfo; + //ClickInfo info = new ClickInfo(); + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); + if (isRenderer) { - info.flags++; + object.clickInfo.flags++; double frameAspect = (double) width / (double) height; if (frameAspect > renderCamera.aspect) { int desired = (int) ((double) height * renderCamera.aspect); - info.bounds.width -= width - desired; - info.bounds.x += (width - desired) / 2; + object.clickInfo.bounds.width -= width - desired; + object.clickInfo.bounds.x += (width - desired) / 2; } else { int desired = (int) ((double) width / renderCamera.aspect); - info.bounds.height -= height - desired; - info.bounds.y += (height - desired) / 2; + object.clickInfo.bounds.height -= height - desired; + object.clickInfo.bounds.y += (height - desired) / 2; } } - info.g = gr; - info.camera = renderCamera; + + object.clickInfo.g = gr; + object.clickInfo.camera = renderCamera; /* // Memory intensive (brep.verticescopy) if (!(object instanceof Composite)) object.draw(info, 0, false); // SLOW : */ - if (!isRenderer) + if (!isRenderer) // && drag) { - object.drawEditHandles(info, 0); + Grafreed.Assert(object != null); + Grafreed.Assert(object.selection != null); + if (object.selection.Size() > 0) + { + int hitSomething = object.selection.get(0).hitSomething; + + object.clickInfo.DX = 0; + object.clickInfo.DY = 0; + object.clickInfo.W = 1; + if (hitSomething == Object3D.hitCenter) + { + info.DX = X; + if (X != 0) + info.DX -= info.bounds.width/2; + + info.DY = Y; + if (Y != 0) + info.DY -= info.bounds.height/2; + } + + object.drawEditHandles(//info, + 0); + + if (drag && (X != 0 || Y != 0)) + { + switch (hitSomething) + { + 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, info.bounds.width/2, info.bounds.height/2); + break; + } + + } + } } } + if (isRenderer) { //gr.setColor(Color.black); //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1); //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3); } + if (hasMarquee) { gr.setXORMode(Color.white); - gr.setColor(Color.red); + gr.setColor(Color.white); if (!firstime) { gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); @@ -13792,6 +16637,7 @@ //if (g != gr) g.drawImage(img, 0, 0, width, height, null); } + // To avoid clear. public void update(Graphics g) { paint(g); @@ -13881,6 +16727,7 @@ public boolean mouseDown(Event evt, int x, int y) { System.out.println("mouseDown: " + evt); + System.exit(0); /* locked = true; drag = false; @@ -13924,13 +16771,14 @@ { keyPressed(0, modifiers); } - clickStart(x, y, modifiers); + // clickStart(x, y, modifiers); return true; } public boolean mouseDrag(Event evt, int x, int y) { - //System.out.println("mouseDrag: " + evt); + System.out.println("mouseDrag: " + evt); + System.exit(0); /* drag = true; //System.out.println("Mouse DRAG"); @@ -14042,13 +16890,14 @@ { keyReleased(0, 0); } - drag(x, y, modifiers); + drag(x, y, 0, modifiers); return true; } public boolean mouseUp(Event evt, int x, int y) { System.out.println("mouseUp: " + evt); + System.exit(0); /* locked = false; if (isRenderer) @@ -14174,7 +17023,7 @@ Object3D object; static Object3D trackedobject; Camera renderCamera; // Light or Eye (or Occlusion) - /*static*/ Camera manipCamera; // Light or Eye + /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light /*static*/ Camera eyeCamera; /*static*/ Camera lightCamera; int cameracount; @@ -14238,6 +17087,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, @@ -14250,36 +17101,74 @@ { 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; - private void DrawSkyBox(GL gl) + float ambientLight[] = {1f, 1f, 1f, 1.0f}; + + 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); return; } - if (WIREFRAME) + //if (WIREFRAME) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL); gl.glDisable(gl.GL_CULL_FACE); @@ -14287,7 +17176,17 @@ // Compensates for ExaminerViewer's modification of modelview matrix gl.glMatrixMode(GL.GL_MODELVIEW); 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); + //gl.glActiveTexture(GL.GL_TEXTURE1); //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); @@ -14319,6 +17218,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); @@ -14359,7 +17259,8 @@ gl.glDisable(GL.GL_TEXTURE_GEN_R); cubemap.disable(); - ////cubemap.unbind(); + //cubemap.dispose(); + if (CULLFACE) { gl.glEnable(gl.GL_CULL_FACE); @@ -14367,6 +17268,8 @@ if (WIREFRAME) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE); + else + gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL); } private void DrawChecker(GL gl) @@ -14394,7 +17297,7 @@ gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS); gl.glPushMatrix(); gl.glLoadIdentity(); - PushMatrix(checker.toParent); + //PushMatrix(checker.toParent); gl.glMatrixMode(GL.GL_TEXTURE); gl.glPushMatrix(); @@ -14415,10 +17318,10 @@ 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 = 0.1666f; //0.25f; - float stepv = step * 1652 / 998; + float step = 2; // 0.1666f; //0.25f; + float stepv = 2; // step * 1652 / 998; int i0 = 0; /* @@ -14454,20 +17357,21 @@ /**/ //checker.GetMaterial().opacity = 1.1f; ////checker.GetMaterial().ambient = 0.99f; - Object3D.materialstack[Object3D.materialdepth] = checker.material; - Object3D.selectedstack[Object3D.materialdepth] = false; - cStatic.objectstack[Object3D.materialdepth++] = checker; + materialstack[materialdepth] = checker.material; + selectedstack[materialdepth] = false; + cStatic.objectstack[materialdepth++] = checker; //System.out.println("material " + material); //Applet3D.tracein(this, selected); - vector2buffer = checker.projectedVertices; + //vector2buffer = checker.projectedVertices; - checker.GetMaterial().Draw(this, false); // true); + //checker.GetMaterial().Draw(this, false); // true); + DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true); - Object3D.materialdepth -= 1; - if (Object3D.materialdepth > 0) + materialdepth -= 1; + if (materialdepth > 0) { - vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices; - Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]); + //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices; + DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices); } //checker.GetMaterial().opacity = 1f; ////checker.GetMaterial().ambient = 1f; @@ -14488,15 +17392,27 @@ //float u = (i+1)/2; //float v = (j+1)/2; - gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2); + if (checker.flipV) + gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2); + else + gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2); gl.glVertex3f(i, j, -0.5f); + if (checker.flipV) + gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2); + else gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2); gl.glVertex3f(i + step, j, -0.5f); + if (checker.flipV) + gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2); + else gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2); gl.glVertex3f(i + step, j + stepv, -0.5f); + if (checker.flipV) + gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2); + else gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2); gl.glVertex3f(i, j + stepv, -0.5f); } @@ -14508,7 +17424,7 @@ gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); - PopMatrix(null); // checker.toParent); // null); + //PopMatrix(null); // checker.toParent); // null); gl.glPopMatrix(); PopTextureMatrix(checker.toParent); gl.glMatrixMode(GL.GL_TEXTURE); @@ -14541,6 +17457,14 @@ } } + private Object3D GetFolder() + { + Object3D folder = object.GetWindow().copy; + if (object.GetWindow().copy.selection.Size() > 0) + folder = object.GetWindow().copy.selection.elementAt(0); + return folder; + } + class SelectBuffer implements GLEventListener { @@ -14556,7 +17480,7 @@ //new Exception().printStackTrace(); System.out.println("select buffer init"); // Use debug pipeline - drawable.setGL(new DebugGL(drawable.getGL())); + //drawable.setGL(new DebugGL(drawable.getGL())); GL gl = drawable.getGL(); @@ -14599,6 +17523,7 @@ { if (!selection) { + new Exception().printStackTrace(); System.exit(0); return; } @@ -14619,17 +17544,39 @@ //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); + if (PAINTMODE) + { + if (object.GetWindow().copy.selection.Size() > 0) + { + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); + + // Make what you paint not selectable. + paintobj.ResetSelectable(); + } + } + //int tmp = selection_view; //selection_view = -1; - int temp = drawMode; - drawMode = SELECTION; + int temp = DrawMode(); + Globals.drawMode = SELECTION; // WARNING indexcount = 0; parent.display(drawable); //selection_view = tmp; //if (temp == SELECTION) // temp = DEFAULT; // patch for selection debug - drawMode = temp; + Globals.drawMode = temp; // WARNING + if (PAINTMODE) + { + if (object.GetWindow().copy.selection.Size() > 0) + { + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); + + // Revert. + paintobj.RestoreSelectable(); + } + } + //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); // trying different ways of getting the depth info over @@ -14660,7 +17607,7 @@ float depth = depths[y * TEX_SIZE + x]; - if (pointselection && mouseMode == SELECT && depth != 0 && depth != 1) + if (pointselection && (mouseMode & SELECT) == SELECT && depth != 0 && depth != 1) { pointselection = false; @@ -14677,6 +17624,13 @@ // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]); // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]); // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]); + + CreateSelectedPoint(); + + // Will fit the mesh !!! + selectedpoint.toParent[0][0] = 0.0001; + selectedpoint.toParent[1][1] = 0.0001; + selectedpoint.toParent[2][2] = 0.0001; glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0); @@ -14721,34 +17675,36 @@ System.out.println("; fromto " + sel + " " + Trunk(previousselectedpoint.toParent[3][0]) + " " + Trunk(previousselectedpoint.toParent[3][2]) + " " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][2])); } - previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint); + previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint); } } if (!movingcamera && !PAINTMODE) - object.editWindow.ScreenFitPoint(); // fev 2014 + object.GetWindow().ScreenFitPoint(); // fev 2014 - if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) { - Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); - Object3D group = new Object3D("inst" + paintcount++); + if (object.GetWindow().copy.selection.Size() > 0) + { + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); - group.CreateMaterial(); // use a void leaf to select instances - - group.add(paintobj); // link - - object.editWindow.SnapObject(group); - - Object3D folder = object.editWindow.copy; - - if (object.editWindow.copy.selection.Size() > 0) - folder = object.editWindow.copy.selection.elementAt(0); - - folder.add(group); - - object.editWindow.ResetModel(); - object.editWindow.refreshContents(); + Object3D inst = new Object3D("inst" + paintcount++); + + inst.CreateMaterial(); // use a void leaf to select instances + + inst.add(paintobj); // link + + object.GetWindow().SnapObject(inst); + + Object3D folder = paintFolder; // GetFolder(); + + folder.add(inst); + + object.GetWindow().ResetModel(); + object.GetWindow().refreshContents(); + } } else paintcount = 0; @@ -14787,6 +17743,11 @@ //System.out.println("objects[color] = " + objects[color]); //objects[color].Select(); indexcount = 0; + ObjEditor window = object.GetWindow(); + if (window != null && deselect) + { + window.Select(null, deselect, true); + } object.Select(color, deselect); } @@ -14837,6 +17798,7 @@ public void init(GLAutoDrawable drawable) { + if (Globals.DEBUG) System.out.println("shadow buffer init"); GL gl = drawable.getGL(); @@ -14886,7 +17848,7 @@ gl.glDisable(gl.GL_CULL_FACE); } - if (!RENDERSHADOW) + if (!Globals.RENDERSHADOW) gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // SB gl.glPolygonOffset(2.5f, 10); @@ -14896,14 +17858,14 @@ //gl.glColorMask(false, false, false, false); //render_scene_from_light_view(gl, drawable, 0, 0); - if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed()) + if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed()) { gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); - int temp = drawMode; - drawMode = SHADOW; + int temp = DrawMode(); + Globals.drawMode = SHADOW; // WARNING parent.display(drawable); - drawMode = temp; + Globals.drawMode = temp; // WARNING } gl.glCullFace(gl.GL_BACK); @@ -14956,7 +17918,6 @@ class AntialiasBuffer implements GLEventListener { - CameraPane parent = null; AntialiasBuffer(CameraPane p) @@ -15066,15 +18027,25 @@ gl.glFlush(); /**/ - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer); + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); - int[] 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; + + gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0); + + float mindepth = 1; + + 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; @@ -15157,7 +18128,7 @@ double scale = ray.z; // 1; // cos - int p = pixels[newindex]; + float depth = depths[newindex]; /* int newindex2 = (x + 1) * OCCLUSION_SIZE + y; @@ -15181,10 +18152,23 @@ scale = (1 - modu) * modv; */ - r += ((p >> 16) & 0xFF) * scale / 255; - g += ((p >> 8) & 0xFF) * scale / 255; - b += (p & 0xFF) * scale / 255; + //r += ((p >> 16) & 0xFF) * scale / 255; + //g += ((p >> 8) & 0xFF) * scale / 255; + //b += (p & 0xFF) * scale / 255; + + if (mindepth > depth) + { + mindepth = depth; + } + double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]); + + double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR); + + r += factor * scale; + g += factor * scale; + b += factor * scale; + count += scale; } @@ -15282,17 +18266,16 @@ GLUT glut = new GLUT(); - static final public int DEFAULT = 0; - static final public int SELECTION = 1; - static final public int SHADOW = 2; - static final public int OCCLUSION = 3; - static - public int drawMode = DEFAULT; public boolean spherical = false; static boolean DEBUG_OCCLUSION = false; static boolean DEBUG_SELECTION = false; boolean OCCLUSION_CULLING = false; //true; public boolean lightMode = false; + + private boolean keepshadow; + + static public boolean capsLocked = false; // VR + static public int indexcount = 0; /*static*/ cColor vertexOcclusion = new cColor(); //private int selection_view = -1; @@ -15300,23 +18283,15 @@ int AAbuffersize = 0; //double[] selectedpoint = new double[3]; - static Sphere selectedpoint = new Sphere(); + static Superellipsoid selectedpoint; static Sphere previousselectedpoint = null; - static Sphere debugpoint = new Sphere(); - static Sphere debugpoint2 = new Sphere(); - static Sphere debugpoint3 = new Sphere(); - static Sphere debugpoint4 = new Sphere(); + static Sphere debugpointG; + static Sphere debugpointP; + static Sphere debugpointC; + static Sphere debugpointR; static Sphere debugpoints[] = new Sphere[8]; - static - { - for (int i=0; i<8; i++) - { - debugpoints[i] = new Sphere(); - } - } - static void InitPoints(float radius) { for (int i=0; i<8; i++) @@ -15336,7 +18311,7 @@ } } - static void DrawPoints(CameraPane cpane) + static void DrawPoints(iCameraPane cpane) { for (int i=0; i<8; i++) // first and last are red { @@ -15355,10 +18330,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 IntBuffer occlusionsizebuffer = IntBuffer.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>(); @@ -15367,10 +18346,11 @@ static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT); // Depth buffer format //private int depth_format; - static public void NextIndex(Object3D o, GL gl) + + public void NextIndex() { indexcount+=16; - gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0); + GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0); //objects[indexcount] = o; //System.out.println("indexcount = " + indexcount); } -- Gitblit v1.6.2