From c570e1e38f2ff8622a71f81436654bad01cfdd5b Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sun, 21 Jul 2019 23:12:19 -0400 Subject: [PATCH] Raw embed texture (too big). --- CameraPane.java | 596 ++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 386 insertions(+), 210 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index d0c68fd..cef7cdb 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -45,6 +45,39 @@ static int STEP = 1; + private static BufferedImage CreateBim(byte[] bytes, int width, int height) + { + 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; + } + /*static*/ private boolean CULLFACE = false; // true; /*static*/ boolean NEAREST = false; // true; /*static*/ boolean WIREFRAME = false; // true; @@ -60,7 +93,7 @@ //boolean REDUCETEXTURE = true; boolean CACHETEXTURE = true; boolean CLEANCACHE = false; // true; - boolean MIPMAP = false; // true; + boolean MIPMAP = true; // false; // true; boolean COMPRESSTEXTURE = false; boolean KOMPACTTEXTURE = false; // true; boolean RESIZETEXTURE = false; @@ -2298,10 +2331,17 @@ HANDLES ^= true; } + Object3D paintFolder; + void TogglePaint() { PAINTMODE ^= true; paintcount = 0; + + if (PAINTMODE) + { + paintFolder = GetFolder(); + } } void SwapCamera(int a, int b) @@ -2398,6 +2438,21 @@ 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); + } + /**/ class CacheTexture { @@ -2406,28 +2461,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; @@ -2446,13 +2504,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; @@ -3525,6 +3604,8 @@ System.out.println("LOADING TEXTURE : " + name); + Object x = texturedata.getMipmapData(); // .getBuffer(); + // if (false) // compressbit > 0) { @@ -7923,7 +8004,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); @@ -7938,8 +8019,8 @@ pigment = null; } - ReleaseTexture(bump, true); - ReleaseTexture(pigment, false); + ReleaseTexture(tex, true); + ReleaseTexture(tex, false); } public void ReleasePigmentTexture(cTexture tex) // INTERFACE @@ -7957,7 +8038,7 @@ String pigment = Object3D.GetPigment(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); @@ -7968,7 +8049,7 @@ pigment = null; } - ReleaseTexture(pigment, false); + ReleaseTexture(tex, false); } public void ReleaseBumpTexture(cTexture tex) // INTERFACE @@ -7986,7 +8067,7 @@ 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); @@ -7997,10 +8078,10 @@ bump = null; } - ReleaseTexture(bump, true); + ReleaseTexture(tex, true); } - void ReleaseTexture(String tex, boolean bump) + void ReleaseTexture(cTexture tex, boolean bump) { if (// DrawMode() != 0 || /*tex == null ||*/ ambientOcclusion ) // || !textureon) @@ -8011,7 +8092,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) @@ -8105,47 +8186,50 @@ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE { - if (// DrawMode() != 0 || /*tex == null ||*/ - ambientOcclusion ) // || !textureon) - { - return; // false; - } - - if (tex == null) - { - BindTexture(null,false,resolution); - BindTexture(null,true,resolution); - return; - } +// 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; - String pigment = Object3D.GetPigment(tex); - String bump = Object3D.GetBump(tex); - - usedtextures.put(pigment, pigment); - usedtextures.put(bump, 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 @@ -8164,9 +8248,9 @@ String pigment = Object3D.GetPigment(tex); - usedtextures.put(pigment, pigment); + 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); @@ -8178,7 +8262,7 @@ } GetGL().glActiveTexture(GetGL().GL_TEXTURE0); - BindTexture(pigment, false, resolution); + BindTexture(tex, false, resolution); } /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE @@ -8197,9 +8281,9 @@ String bump = Object3D.GetBump(tex); - 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); @@ -8211,7 +8295,7 @@ } GetGL().glActiveTexture(GetGL().GL_TEXTURE2); - BindTexture(bump, true, resolution); + BindTexture(tex, true, resolution); GetGL().glActiveTexture(GetGL().GL_TEXTURE0); } @@ -8235,13 +8319,19 @@ return fileExists; } - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception { - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; + 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; + + if (texname.equals("") && texdata == null) + { + return null; + } String fallbackTextureName = defaultDirectory + "/Textures/" + texname; @@ -8251,19 +8341,34 @@ // else // if (!texname.startsWith("/")) // texname = "/Users/nbriere/Textures/" + texname; - if (!FileExists(tex)) + if (!FileExists(texname)) { 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) + { + BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); + + CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); + + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); + bimtextures.put(texdata, texturecache); + } + else + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) { assert(!bump); // if (bump) @@ -8274,19 +8379,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")) @@ -8294,11 +8403,13 @@ // 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.png", bump),resolution); + else + new Exception().printStackTrace(); } else { if (textureon) @@ -8357,19 +8468,19 @@ if (texturedata == null) throw new Exception(); - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); + 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) @@ -8386,52 +8497,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); @@ -8448,18 +8524,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; } @@ -8475,10 +8553,41 @@ } } - return texture; + return texturecache; } - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception + static void EmbedTextures(cTexture tex) + { + if (tex.pigmentdata == null) + { + String texname = Object3D.GetPigment(tex); + + CacheTexture texturecache = texturepigment.get(tex); + + if (texturecache != null) + { + tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); + tex.pw = texturecache.texturedata.getWidth(); + tex.ph = texturecache.texturedata.getHeight(); + } + } + + if (tex.bumpdata == null) + { + String texname = Object3D.GetBump(tex); + + CacheTexture texturecache = texturebump.get(tex); + + if (texturecache != null) + { + tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); + tex.bw = texturecache.texturedata.getWidth(); + tex.bh = texturecache.texturedata.getHeight(); + } + } + } + + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception { CacheTexture texture = GetCacheTexture(tex, bump, resolution); @@ -8496,21 +8605,21 @@ return texture!=null?texture.texture:null; } - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception + 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) throws Exception + 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); @@ -8542,7 +8651,7 @@ 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. } ShadowBuffer shadowPBuf; @@ -11028,9 +11137,9 @@ gl.glMatrixMode(GL.GL_MODELVIEW); -//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); -//gl.glEnable(gl.GL_POLYGON_SMOOTH); -//gl.glEnable(gl.GL_MULTISAMPLE); +gl.glEnable(gl.GL_POLYGON_SMOOTH); +gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST); +gl.glEnable(gl.GL_MULTISAMPLE); } else { //gl.glDisable(GL.GL_TEXTURE_2D); @@ -11041,7 +11150,7 @@ //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(); @@ -11655,20 +11764,32 @@ 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); + } } } } @@ -14297,12 +14418,12 @@ void GoDown(int mod) { MODIFIERS |= COMMAND; - /* + /**/ if((mod&SHIFT) == SHIFT) manipCamera.RotatePosition(0, -speed); else - manipCamera.BackForth(0, -speed*delta, getWidth()); - */ + manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); + /**/ if ((mod & SHIFT) == SHIFT) { mouseMode = mouseMode; // VR?? @@ -14318,12 +14439,12 @@ void GoUp(int mod) { MODIFIERS |= COMMAND; - /* + /**/ if((mod&SHIFT) == SHIFT) manipCamera.RotatePosition(0, speed); else - manipCamera.BackForth(0, speed*delta, getWidth()); - */ + manipCamera.BackForth(0, speed*delta, 0); // getWidth()); + /**/ if ((mod & SHIFT) == SHIFT) { mouseMode = mouseMode; @@ -14339,12 +14460,12 @@ void GoLeft(int mod) { MODIFIERS |= COMMAND; - /* + /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(speed, 0); - else manipCamera.Translate(speed*delta, 0, getWidth()); - */ + else + manipCamera.RotatePosition(speed, 0); + /**/ if ((mod & SHIFT) == SHIFT) { mouseMode = mouseMode; @@ -14360,12 +14481,12 @@ void GoRight(int mod) { MODIFIERS |= COMMAND; - /* + /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(-speed, 0); - else manipCamera.Translate(-speed*delta, 0, getWidth()); - */ + else + manipCamera.RotatePosition(-speed, 0); + /**/ if ((mod & SHIFT) == SHIFT) { mouseMode = mouseMode; @@ -14604,7 +14725,8 @@ Globals.MOUSEDRAGGED = false; movingcamera = false; - X = Y = 0; + X = 0; // getBounds().width/2; + Y = 0; // getBounds().height/2; //System.out.println("mouseReleased: " + e); clickEnd(e.getX(), e.getY(), e.getModifiersEx()); } @@ -14860,7 +14982,8 @@ // break; case 'T': CACHETEXTURE ^= true; - textures.clear(); + texturepigment.clear(); + texturebump.clear(); // repaint(); break; case 'Y': @@ -14945,7 +15068,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; @@ -14971,13 +15096,7 @@ repaint(); break; case 'l': - lightMode ^= true; - Globals.lighttouched = true; - manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; - targetLookAt.set(manipCamera.lookAt); - repaint(); - break; - case 'L': + //case 'L': if (lightMode) { lightMode = false; @@ -15124,7 +15243,10 @@ // kompactbit = 6; // break; case ' ': - ObjEditor.theFrame.ToggleFullScreen(); + lightMode ^= true; + Globals.lighttouched = true; + manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera; + targetLookAt.set(manipCamera.lookAt); repaint(); break; //case '`' : @@ -15708,6 +15830,7 @@ info.bounds.y += (height - desired) / 2; } } + info.g = gr; info.camera = renderCamera; /* @@ -15717,23 +15840,44 @@ */ if (!isRenderer) { - object.drawEditHandles(info, 0); - - if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0) + Grafreed.Assert(object != null); + Grafreed.Assert(object.selection != null); + if (object.selection.Size() > 0) { - switch (object.selection.get(0).hitSomething) + int hitSomething = object.selection.get(0).hitSomething; + + info.DX = 0; + info.DY = 0; + info.W = 1; + if (hitSomething == Object3D.hitCenter) { - case Object3D.hitCenter: gr.setColor(Color.pink); - 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; + 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.pink); + 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; + } + + } } } } @@ -16531,6 +16675,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 { @@ -16610,6 +16762,17 @@ //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(); @@ -16621,6 +16784,17 @@ // temp = DEFAULT; // patch for selection debug 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 @@ -16726,27 +16900,29 @@ if (!movingcamera && !PAINTMODE) 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 group = new Object3D("inst" + paintcount++); - - group.CreateMaterial(); // use a void leaf to select instances - - group.add(paintobj); // link - - object.GetWindow().SnapObject(group); - - Object3D folder = object.GetWindow().copy; + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); if (object.GetWindow().copy.selection.Size() > 0) - folder = object.GetWindow().copy.selection.elementAt(0); + { + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); - folder.add(group); - - object.GetWindow().ResetModel(); - object.GetWindow().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; -- Gitblit v1.6.2