.. | .. |
---|
60 | 60 | //boolean REDUCETEXTURE = true; |
---|
61 | 61 | boolean CACHETEXTURE = true; |
---|
62 | 62 | boolean CLEANCACHE = false; // true; |
---|
63 | | - boolean MIPMAP = false; // true; |
---|
| 63 | + boolean MIPMAP = true; // false; // true; |
---|
64 | 64 | boolean COMPRESSTEXTURE = false; |
---|
65 | 65 | boolean KOMPACTTEXTURE = false; // true; |
---|
66 | 66 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
2298 | 2298 | HANDLES ^= true; |
---|
2299 | 2299 | } |
---|
2300 | 2300 | |
---|
| 2301 | + Object3D paintFolder; |
---|
| 2302 | + |
---|
2301 | 2303 | void TogglePaint() |
---|
2302 | 2304 | { |
---|
2303 | 2305 | PAINTMODE ^= true; |
---|
2304 | 2306 | paintcount = 0; |
---|
| 2307 | + |
---|
| 2308 | + if (PAINTMODE) |
---|
| 2309 | + { |
---|
| 2310 | + paintFolder = GetFolder(); |
---|
| 2311 | + } |
---|
2305 | 2312 | } |
---|
2306 | 2313 | |
---|
2307 | 2314 | void SwapCamera(int a, int b) |
---|
.. | .. |
---|
2398 | 2405 | return currentGL; |
---|
2399 | 2406 | } |
---|
2400 | 2407 | |
---|
| 2408 | + private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2409 | + { |
---|
| 2410 | + // cache to disk |
---|
| 2411 | + Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
| 2412 | + //buffers[0]. |
---|
| 2413 | + ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
| 2414 | + int[] pixels = new int[bytebuf.capacity()/3]; |
---|
| 2415 | + int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared |
---|
| 2416 | + int height = width; |
---|
| 2417 | + for (int i=pixels.length; --i>=0;) |
---|
| 2418 | + { |
---|
| 2419 | + int i3 = i*3; |
---|
| 2420 | + pixels[i] = 0xFF; |
---|
| 2421 | + pixels[i] <<= 8; |
---|
| 2422 | + pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
| 2423 | + pixels[i] <<= 8; |
---|
| 2424 | + pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
| 2425 | + pixels[i] <<= 8; |
---|
| 2426 | + pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
| 2427 | + } |
---|
| 2428 | + /* |
---|
| 2429 | + int r=0,g=0,b=0,a=0; |
---|
| 2430 | + for (int i=0; i<width; i++) |
---|
| 2431 | + for (int j=0; j<height; j++) |
---|
| 2432 | + { |
---|
| 2433 | + int index = j*width+i; |
---|
| 2434 | + int p = pixels[index]; |
---|
| 2435 | + a = ((p>>24) & 0xFF); |
---|
| 2436 | + r = ((p>>16) & 0xFF); |
---|
| 2437 | + g = ((p>>8) & 0xFF); |
---|
| 2438 | + b = (p & 0xFF); |
---|
| 2439 | + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
| 2440 | + } |
---|
| 2441 | + /**/ |
---|
| 2442 | + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
| 2443 | + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 2444 | + return rendImage; |
---|
| 2445 | + } |
---|
| 2446 | + |
---|
2401 | 2447 | /**/ |
---|
2402 | 2448 | class CacheTexture |
---|
2403 | 2449 | { |
---|
.. | .. |
---|
2415 | 2461 | /**/ |
---|
2416 | 2462 | |
---|
2417 | 2463 | // TEXTURE static Texture texture; |
---|
2418 | | - static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures |
---|
2419 | | - = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>(); |
---|
2420 | | - static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>(); |
---|
| 2464 | + static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>(); |
---|
| 2465 | + static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>(); |
---|
| 2466 | + static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>(); |
---|
| 2467 | + |
---|
2421 | 2468 | int pigmentdepth = 0; |
---|
2422 | 2469 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2423 | 2470 | int bumpdepth = 0; |
---|
.. | .. |
---|
2439 | 2486 | true, |
---|
2440 | 2487 | com.sun.opengl.util.texture.TextureIO.PNG); |
---|
2441 | 2488 | } catch (java.io.IOException e) |
---|
| 2489 | + { |
---|
| 2490 | + throw new javax.media.opengl.GLException(e); |
---|
| 2491 | + } |
---|
| 2492 | + |
---|
| 2493 | + if (bump) |
---|
| 2494 | + texturedata = ConvertBump(texturedata, false); |
---|
| 2495 | + |
---|
| 2496 | + com.sun.opengl.util.texture.Texture texture = |
---|
| 2497 | + com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2498 | + |
---|
| 2499 | + texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2500 | + texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2501 | + |
---|
| 2502 | + return texture; |
---|
| 2503 | + } |
---|
| 2504 | + |
---|
| 2505 | + com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2506 | + { |
---|
| 2507 | + TextureData texturedata = null; |
---|
| 2508 | + |
---|
| 2509 | + try |
---|
| 2510 | + { |
---|
| 2511 | + texturedata = |
---|
| 2512 | + com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
| 2513 | + name, |
---|
| 2514 | + true); |
---|
| 2515 | + } catch (Exception e) |
---|
2442 | 2516 | { |
---|
2443 | 2517 | throw new javax.media.opengl.GLException(e); |
---|
2444 | 2518 | } |
---|
.. | .. |
---|
3525 | 3599 | |
---|
3526 | 3600 | System.out.println("LOADING TEXTURE : " + name); |
---|
3527 | 3601 | |
---|
| 3602 | + Object x = texturedata.getMipmapData(); // .getBuffer(); |
---|
| 3603 | + |
---|
3528 | 3604 | // |
---|
3529 | 3605 | if (false) // compressbit > 0) |
---|
3530 | 3606 | { |
---|
.. | .. |
---|
7923 | 7999 | String pigment = Object3D.GetPigment(tex); |
---|
7924 | 8000 | String bump = Object3D.GetBump(tex); |
---|
7925 | 8001 | |
---|
7926 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8002 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7927 | 8003 | { |
---|
7928 | 8004 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7929 | 8005 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7957 | 8033 | |
---|
7958 | 8034 | String pigment = Object3D.GetPigment(tex); |
---|
7959 | 8035 | |
---|
7960 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8036 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7961 | 8037 | { |
---|
7962 | 8038 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7963 | 8039 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
7986 | 8062 | |
---|
7987 | 8063 | String bump = Object3D.GetBump(tex); |
---|
7988 | 8064 | |
---|
7989 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8065 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
7990 | 8066 | { |
---|
7991 | 8067 | // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment); |
---|
7992 | 8068 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8105 | 8181 | |
---|
8106 | 8182 | /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
8107 | 8183 | { |
---|
8108 | | - if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8109 | | - ambientOcclusion ) // || !textureon) |
---|
8110 | | - { |
---|
8111 | | - return; // false; |
---|
8112 | | - } |
---|
8113 | | - |
---|
8114 | | - if (tex == null) |
---|
8115 | | - { |
---|
8116 | | - BindTexture(null,false,resolution); |
---|
8117 | | - BindTexture(null,true,resolution); |
---|
8118 | | - return; |
---|
8119 | | - } |
---|
| 8184 | +// if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
| 8185 | +// ambientOcclusion ) // || !textureon) |
---|
| 8186 | +// { |
---|
| 8187 | +// return; // false; |
---|
| 8188 | +// } |
---|
| 8189 | +// |
---|
| 8190 | +// if (tex == null) |
---|
| 8191 | +// { |
---|
| 8192 | +// BindTexture(null,false,resolution); |
---|
| 8193 | +// BindTexture(null,true,resolution); |
---|
| 8194 | +// return; |
---|
| 8195 | +// } |
---|
| 8196 | +// |
---|
| 8197 | +// String pigment = Object3D.GetPigment(tex); |
---|
| 8198 | +// String bump = Object3D.GetBump(tex); |
---|
| 8199 | +// |
---|
| 8200 | +// usedtextures.add(pigment); |
---|
| 8201 | +// usedtextures.add(bump); |
---|
| 8202 | +// |
---|
| 8203 | +// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8204 | +// { |
---|
| 8205 | +// // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
| 8206 | +// // System.out.println("; bump = " + bump); |
---|
| 8207 | +// } |
---|
| 8208 | +// |
---|
| 8209 | +// if (bump.equals("")) |
---|
| 8210 | +// { |
---|
| 8211 | +// bump = null; |
---|
| 8212 | +// } |
---|
| 8213 | +// if (pigment.equals("")) |
---|
| 8214 | +// { |
---|
| 8215 | +// pigment = null; |
---|
| 8216 | +// } |
---|
| 8217 | +// |
---|
| 8218 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8219 | +// BindTexture(pigment, false, resolution); |
---|
| 8220 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
| 8221 | +// BindTexture(bump, true, resolution); |
---|
| 8222 | +// GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
| 8223 | +// |
---|
| 8224 | +// return; // true; |
---|
8120 | 8225 | |
---|
8121 | | - String pigment = Object3D.GetPigment(tex); |
---|
8122 | | - String bump = Object3D.GetBump(tex); |
---|
8123 | | - |
---|
8124 | | - usedtextures.put(pigment, pigment); |
---|
8125 | | - usedtextures.put(bump, bump); |
---|
8126 | | - |
---|
8127 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8128 | | - { |
---|
8129 | | - // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8130 | | - // System.out.println("; bump = " + bump); |
---|
8131 | | - } |
---|
8132 | | - |
---|
8133 | | - if (bump.equals("")) |
---|
8134 | | - { |
---|
8135 | | - bump = null; |
---|
8136 | | - } |
---|
8137 | | - if (pigment.equals("")) |
---|
8138 | | - { |
---|
8139 | | - pigment = null; |
---|
8140 | | - } |
---|
8141 | | - |
---|
8142 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8143 | | - BindTexture(pigment, false, resolution); |
---|
8144 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8145 | | - BindTexture(bump, true, resolution); |
---|
8146 | | - GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8147 | | - |
---|
8148 | | - return; // true; |
---|
| 8226 | + BindPigmentTexture(tex, resolution); |
---|
| 8227 | + BindBumpTexture(tex, resolution); |
---|
8149 | 8228 | } |
---|
8150 | 8229 | |
---|
8151 | 8230 | /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8158 | 8237 | |
---|
8159 | 8238 | if (tex == null) |
---|
8160 | 8239 | { |
---|
8161 | | - BindTexture(null,false,resolution); |
---|
| 8240 | + BindTexture(null, null,false,resolution); |
---|
8162 | 8241 | return; |
---|
8163 | 8242 | } |
---|
8164 | 8243 | |
---|
8165 | 8244 | String pigment = Object3D.GetPigment(tex); |
---|
8166 | 8245 | |
---|
8167 | | - usedtextures.put(pigment, pigment); |
---|
| 8246 | + usedtextures.add(pigment); |
---|
8168 | 8247 | |
---|
8169 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8248 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8170 | 8249 | { |
---|
8171 | 8250 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8172 | 8251 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8178 | 8257 | } |
---|
8179 | 8258 | |
---|
8180 | 8259 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8181 | | - BindTexture(pigment, false, resolution); |
---|
| 8260 | + BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
8182 | 8261 | } |
---|
8183 | 8262 | |
---|
8184 | 8263 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8191 | 8270 | |
---|
8192 | 8271 | if (tex == null) |
---|
8193 | 8272 | { |
---|
8194 | | - BindTexture(null,true,resolution); |
---|
| 8273 | + BindTexture(null, null,true,resolution); |
---|
8195 | 8274 | return; |
---|
8196 | 8275 | } |
---|
8197 | 8276 | |
---|
8198 | 8277 | String bump = Object3D.GetBump(tex); |
---|
8199 | 8278 | |
---|
8200 | | - usedtextures.put(bump, bump); |
---|
| 8279 | + usedtextures.add(bump); |
---|
8201 | 8280 | |
---|
8202 | | - if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
| 8281 | + //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8203 | 8282 | { |
---|
8204 | 8283 | // System.out.print("BIND +++++++++++++++ pigment = " + pigment); |
---|
8205 | 8284 | // System.out.println("; bump = " + bump); |
---|
.. | .. |
---|
8211 | 8290 | } |
---|
8212 | 8291 | |
---|
8213 | 8292 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8214 | | - BindTexture(bump, true, resolution); |
---|
| 8293 | + BindTexture(tex.bumptexture, bump, true, resolution); |
---|
8215 | 8294 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8216 | 8295 | } |
---|
8217 | 8296 | |
---|
.. | .. |
---|
8235 | 8314 | return fileExists; |
---|
8236 | 8315 | } |
---|
8237 | 8316 | |
---|
8238 | | - CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8317 | + CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception |
---|
8239 | 8318 | { |
---|
8240 | | - CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
| 8319 | + CacheTexture texturecache = null; |
---|
8241 | 8320 | |
---|
8242 | 8321 | if (tex != null) |
---|
8243 | 8322 | { |
---|
.. | .. |
---|
8257 | 8336 | } |
---|
8258 | 8337 | |
---|
8259 | 8338 | if (CACHETEXTURE) |
---|
8260 | | - texture = textures.get(texname); // TEXTURE CACHE |
---|
8261 | | - |
---|
8262 | | - TextureData texturedata = null; |
---|
8263 | | - |
---|
8264 | | - if (texture == null || texture.resolution < resolution) |
---|
8265 | 8339 | { |
---|
| 8340 | + if (bim == null) |
---|
| 8341 | + texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8342 | + else |
---|
| 8343 | + texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8344 | + } |
---|
| 8345 | + |
---|
| 8346 | + if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8347 | + { |
---|
| 8348 | + TextureData texturedata = null; |
---|
| 8349 | + |
---|
| 8350 | + if (bim != null) |
---|
| 8351 | + { |
---|
| 8352 | + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8353 | + } |
---|
| 8354 | + else |
---|
8266 | 8355 | if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8267 | 8356 | { |
---|
8268 | 8357 | assert(!bump); |
---|
.. | .. |
---|
8274 | 8363 | // } |
---|
8275 | 8364 | // else |
---|
8276 | 8365 | // { |
---|
8277 | | - texture = textures.get(tex); |
---|
8278 | | - if (texture == null) |
---|
| 8366 | + texturecache = textures.get(tex); |
---|
| 8367 | + if (texturecache == null) |
---|
8279 | 8368 | { |
---|
8280 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8369 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8281 | 8370 | } |
---|
| 8371 | + else |
---|
| 8372 | + new Exception().printStackTrace(); |
---|
8282 | 8373 | // } |
---|
8283 | 8374 | } else |
---|
8284 | 8375 | if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8285 | 8376 | { |
---|
8286 | 8377 | assert(bump); |
---|
8287 | | - texture = textures.get(tex); |
---|
8288 | | - if (texture == null) |
---|
8289 | | - texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8378 | + texturecache = textures.get(tex); |
---|
| 8379 | + if (texturecache == null) |
---|
| 8380 | + texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
| 8381 | + else |
---|
| 8382 | + new Exception().printStackTrace(); |
---|
8290 | 8383 | } else |
---|
8291 | 8384 | { |
---|
8292 | 8385 | //if (tex.equals("IMMORTAL")) |
---|
.. | .. |
---|
8296 | 8389 | //{ |
---|
8297 | 8390 | if (tex.equals("WHITE_NOISE")) |
---|
8298 | 8391 | { |
---|
8299 | | - texture = textures.get(tex); |
---|
8300 | | - if (texture == null) |
---|
8301 | | - texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8392 | + texturecache = textures.get(tex); |
---|
| 8393 | + if (texturecache == null) |
---|
| 8394 | + texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8395 | + else |
---|
| 8396 | + new Exception().printStackTrace(); |
---|
8302 | 8397 | } else |
---|
8303 | 8398 | { |
---|
8304 | 8399 | if (textureon) |
---|
.. | .. |
---|
8357 | 8452 | if (texturedata == null) |
---|
8358 | 8453 | throw new Exception(); |
---|
8359 | 8454 | |
---|
8360 | | - texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8455 | + texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
8361 | 8456 | //texture = GetTexture(tex, bump); |
---|
8362 | 8457 | } |
---|
8363 | 8458 | } |
---|
8364 | 8459 | //} |
---|
8365 | 8460 | } |
---|
8366 | 8461 | |
---|
8367 | | - if (/*CACHETEXTURE &&*/ texture != null && textureon) |
---|
| 8462 | + if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8368 | 8463 | { |
---|
8369 | 8464 | //return false; |
---|
| 8465 | + assert(bim == null); |
---|
8370 | 8466 | |
---|
8371 | 8467 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8372 | | - if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG"))) |
---|
| 8468 | + if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
8373 | 8469 | { |
---|
8374 | 8470 | // String ext = "_highres"; |
---|
8375 | 8471 | // if (REDUCETEXTURE) |
---|
.. | .. |
---|
8386 | 8482 | File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); |
---|
8387 | 8483 | if (!cachefile.exists()) |
---|
8388 | 8484 | { |
---|
8389 | | - // cache to disk |
---|
8390 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
8391 | | - //buffers[0]. |
---|
8392 | | - |
---|
8393 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
8394 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
8395 | | - |
---|
8396 | | - // squared size heuristic... |
---|
8397 | | - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) |
---|
| 8485 | + //if (texturedata.getWidth() == texturedata.getHeight()) |
---|
8398 | 8486 | { |
---|
8399 | | - for (int i=pixels.length; --i>=0;) |
---|
8400 | | - { |
---|
8401 | | - int i3 = i*3; |
---|
8402 | | - pixels[i] = 0xFF; |
---|
8403 | | - pixels[i] <<= 8; |
---|
8404 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
8405 | | - pixels[i] <<= 8; |
---|
8406 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
8407 | | - pixels[i] <<= 8; |
---|
8408 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
8409 | | - } |
---|
8410 | | - |
---|
8411 | | - /* |
---|
8412 | | - int r=0,g=0,b=0,a=0; |
---|
8413 | | - for (int i=0; i<width; i++) |
---|
8414 | | - for (int j=0; j<height; j++) |
---|
8415 | | - { |
---|
8416 | | - int index = j*width+i; |
---|
8417 | | - int p = pixels[index]; |
---|
8418 | | - a = ((p>>24) & 0xFF); |
---|
8419 | | - r = ((p>>16) & 0xFF); |
---|
8420 | | - g = ((p>>8) & 0xFF); |
---|
8421 | | - b = (p & 0xFF); |
---|
8422 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
8423 | | - } |
---|
8424 | | - /**/ |
---|
8425 | | - int width = (int)Math.sqrt(pixels.length); // squared |
---|
8426 | | - int height = width; |
---|
8427 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
8428 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 8487 | + BufferedImage rendImage = CreateBim(texturedata); |
---|
| 8488 | + |
---|
8429 | 8489 | ImageWriter writer = null; |
---|
8430 | 8490 | Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); |
---|
8431 | 8491 | if (iter.hasNext()) { |
---|
8432 | 8492 | writer = (ImageWriter)iter.next(); |
---|
8433 | 8493 | } |
---|
8434 | | - float compressionQuality = 0.9f; |
---|
| 8494 | + |
---|
| 8495 | + float compressionQuality = 0.85f; |
---|
8435 | 8496 | try |
---|
8436 | 8497 | { |
---|
8437 | 8498 | ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); |
---|
.. | .. |
---|
8458 | 8519 | textures.remove(texname); |
---|
8459 | 8520 | } |
---|
8460 | 8521 | |
---|
8461 | | - texture.texturedata = texturedata; |
---|
8462 | | - textures.put(texname, texture); |
---|
| 8522 | + //texture.texturedata = texturedata; |
---|
| 8523 | + textures.put(texname, texturecache); |
---|
8463 | 8524 | |
---|
8464 | 8525 | // newtex = true; |
---|
8465 | 8526 | } |
---|
.. | .. |
---|
8475 | 8536 | } |
---|
8476 | 8537 | } |
---|
8477 | 8538 | |
---|
8478 | | - return texture; |
---|
| 8539 | + return texturecache; |
---|
8479 | 8540 | } |
---|
8480 | 8541 | |
---|
8481 | | - com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8542 | + static void EmbedTextures(cTexture tex) |
---|
8482 | 8543 | { |
---|
8483 | | - CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
| 8544 | + |
---|
| 8545 | + } |
---|
| 8546 | + |
---|
| 8547 | + com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8548 | + { |
---|
| 8549 | + CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
8484 | 8550 | |
---|
8485 | 8551 | if (bump) |
---|
8486 | 8552 | { |
---|
.. | .. |
---|
8496 | 8562 | return texture!=null?texture.texture:null; |
---|
8497 | 8563 | } |
---|
8498 | 8564 | |
---|
8499 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception |
---|
| 8565 | + public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
8500 | 8566 | { |
---|
8501 | | - CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
| 8567 | + CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
8502 | 8568 | |
---|
8503 | 8569 | return texture!=null?texture.texturedata:null; |
---|
8504 | 8570 | } |
---|
8505 | 8571 | |
---|
8506 | | - boolean BindTexture(String tex, boolean bump, int resolution) throws Exception |
---|
| 8572 | + boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
8507 | 8573 | { |
---|
8508 | 8574 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8509 | 8575 | { |
---|
8510 | 8576 | return false; |
---|
8511 | 8577 | } |
---|
8512 | 8578 | |
---|
8513 | | - boolean newtex = false; |
---|
| 8579 | + //boolean newtex = false; |
---|
8514 | 8580 | |
---|
8515 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
| 8581 | + com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
8516 | 8582 | |
---|
8517 | 8583 | if (texture == null) |
---|
8518 | 8584 | return false; |
---|
.. | .. |
---|
8542 | 8608 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT); |
---|
8543 | 8609 | texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT); |
---|
8544 | 8610 | |
---|
8545 | | - return newtex; |
---|
| 8611 | + return true; // Warning: not used. |
---|
8546 | 8612 | } |
---|
8547 | 8613 | |
---|
8548 | 8614 | ShadowBuffer shadowPBuf; |
---|
.. | .. |
---|
10999 | 11065 | |
---|
11000 | 11066 | try |
---|
11001 | 11067 | { |
---|
11002 | | - BindTexture(NOISE_TEXTURE, false, 2); |
---|
| 11068 | + BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
11003 | 11069 | } |
---|
11004 | 11070 | catch (Exception e) |
---|
11005 | 11071 | { |
---|
.. | .. |
---|
11664 | 11730 | if (tex.equals("WHITE_NOISE")) |
---|
11665 | 11731 | continue; |
---|
11666 | 11732 | |
---|
11667 | | - if (!usedtextures.containsKey(tex)) |
---|
| 11733 | + if (!usedtextures.contains(tex)) |
---|
11668 | 11734 | { |
---|
11669 | 11735 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11670 | 11736 | textures.get(tex).texture.dispose(); |
---|
.. | .. |
---|
16553 | 16619 | } |
---|
16554 | 16620 | } |
---|
16555 | 16621 | |
---|
| 16622 | + private Object3D GetFolder() |
---|
| 16623 | + { |
---|
| 16624 | + Object3D folder = object.GetWindow().copy; |
---|
| 16625 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16626 | + folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16627 | + return folder; |
---|
| 16628 | + } |
---|
| 16629 | + |
---|
16556 | 16630 | class SelectBuffer implements GLEventListener |
---|
16557 | 16631 | { |
---|
16558 | 16632 | |
---|
.. | .. |
---|
16632 | 16706 | |
---|
16633 | 16707 | //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL); |
---|
16634 | 16708 | |
---|
| 16709 | + if (PAINTMODE) |
---|
| 16710 | + { |
---|
| 16711 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16712 | + { |
---|
| 16713 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16714 | + |
---|
| 16715 | + // Make what you paint not selectable. |
---|
| 16716 | + paintobj.ResetSelectable(); |
---|
| 16717 | + } |
---|
| 16718 | + } |
---|
| 16719 | + |
---|
16635 | 16720 | //int tmp = selection_view; |
---|
16636 | 16721 | //selection_view = -1; |
---|
16637 | 16722 | int temp = DrawMode(); |
---|
.. | .. |
---|
16643 | 16728 | // temp = DEFAULT; // patch for selection debug |
---|
16644 | 16729 | Globals.drawMode = temp; // WARNING |
---|
16645 | 16730 | |
---|
| 16731 | + if (PAINTMODE) |
---|
| 16732 | + { |
---|
| 16733 | + if (object.GetWindow().copy.selection.Size() > 0) |
---|
| 16734 | + { |
---|
| 16735 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16736 | + |
---|
| 16737 | + // Revert. |
---|
| 16738 | + paintobj.RestoreSelectable(); |
---|
| 16739 | + } |
---|
| 16740 | + } |
---|
| 16741 | + |
---|
16646 | 16742 | //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view); |
---|
16647 | 16743 | |
---|
16648 | 16744 | // trying different ways of getting the depth info over |
---|
.. | .. |
---|
16748 | 16844 | if (!movingcamera && !PAINTMODE) |
---|
16749 | 16845 | object.GetWindow().ScreenFitPoint(); // fev 2014 |
---|
16750 | 16846 | |
---|
16751 | | - if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
| 16847 | + if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0) |
---|
16752 | 16848 | { |
---|
16753 | | - Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16754 | | - |
---|
16755 | | - Object3D group = new Object3D("inst" + paintcount++); |
---|
16756 | | - |
---|
16757 | | - group.CreateMaterial(); // use a void leaf to select instances |
---|
16758 | | - |
---|
16759 | | - group.add(paintobj); // link |
---|
16760 | | - |
---|
16761 | | - object.GetWindow().SnapObject(group); |
---|
16762 | | - |
---|
16763 | | - Object3D folder = object.GetWindow().copy; |
---|
| 16849 | + //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0); |
---|
16764 | 16850 | |
---|
16765 | 16851 | if (object.GetWindow().copy.selection.Size() > 0) |
---|
16766 | | - folder = object.GetWindow().copy.selection.elementAt(0); |
---|
| 16852 | + { |
---|
| 16853 | + Object3D paintobj = object.GetWindow().copy.selection.elementAt(0); |
---|
16767 | 16854 | |
---|
16768 | | - folder.add(group); |
---|
16769 | | - |
---|
16770 | | - object.GetWindow().ResetModel(); |
---|
16771 | | - object.GetWindow().refreshContents(); |
---|
| 16855 | + Object3D inst = new Object3D("inst" + paintcount++); |
---|
| 16856 | + |
---|
| 16857 | + inst.CreateMaterial(); // use a void leaf to select instances |
---|
| 16858 | + |
---|
| 16859 | + inst.add(paintobj); // link |
---|
| 16860 | + |
---|
| 16861 | + object.GetWindow().SnapObject(inst); |
---|
| 16862 | + |
---|
| 16863 | + Object3D folder = paintFolder; // GetFolder(); |
---|
| 16864 | + |
---|
| 16865 | + folder.add(inst); |
---|
| 16866 | + |
---|
| 16867 | + object.GetWindow().ResetModel(); |
---|
| 16868 | + object.GetWindow().refreshContents(); |
---|
| 16869 | + } |
---|
16772 | 16870 | } |
---|
16773 | 16871 | else |
---|
16774 | 16872 | paintcount = 0; |
---|