Normand Briere
2019-07-21 40f408aaee14abd85d391008b4d22977dc586b50
CameraPane.java
....@@ -60,7 +60,7 @@
6060 //boolean REDUCETEXTURE = true;
6161 boolean CACHETEXTURE = true;
6262 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
63
+ boolean MIPMAP = true; // false; // true;
6464 boolean COMPRESSTEXTURE = false;
6565 boolean KOMPACTTEXTURE = false; // true;
6666 boolean RESIZETEXTURE = false;
....@@ -2298,10 +2298,17 @@
22982298 HANDLES ^= true;
22992299 }
23002300
2301
+ Object3D paintFolder;
2302
+
23012303 void TogglePaint()
23022304 {
23032305 PAINTMODE ^= true;
23042306 paintcount = 0;
2307
+
2308
+ if (PAINTMODE)
2309
+ {
2310
+ paintFolder = GetFolder();
2311
+ }
23052312 }
23062313
23072314 void SwapCamera(int a, int b)
....@@ -2415,9 +2422,10 @@
24152422 /**/
24162423
24172424 // 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>();
2425
+ static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>();
2426
+ static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>();
2427
+ static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>();
2428
+
24212429 int pigmentdepth = 0;
24222430 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24232431 int bumpdepth = 0;
....@@ -2439,6 +2447,33 @@
24392447 true,
24402448 com.sun.opengl.util.texture.TextureIO.PNG);
24412449 } catch (java.io.IOException e)
2450
+ {
2451
+ throw new javax.media.opengl.GLException(e);
2452
+ }
2453
+
2454
+ if (bump)
2455
+ texturedata = ConvertBump(texturedata, false);
2456
+
2457
+ com.sun.opengl.util.texture.Texture texture =
2458
+ com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2459
+
2460
+ texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2461
+ texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2462
+
2463
+ return texture;
2464
+ }
2465
+
2466
+ com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump)
2467
+ {
2468
+ TextureData texturedata = null;
2469
+
2470
+ try
2471
+ {
2472
+ texturedata =
2473
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2474
+ name,
2475
+ true);
2476
+ } catch (Exception e)
24422477 {
24432478 throw new javax.media.opengl.GLException(e);
24442479 }
....@@ -3525,6 +3560,8 @@
35253560
35263561 System.out.println("LOADING TEXTURE : " + name);
35273562
3563
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3564
+
35283565 //
35293566 if (false) // compressbit > 0)
35303567 {
....@@ -7923,7 +7960,7 @@
79237960 String pigment = Object3D.GetPigment(tex);
79247961 String bump = Object3D.GetBump(tex);
79257962
7926
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7963
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79277964 {
79287965 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79297966 // System.out.println("; bump = " + bump);
....@@ -7957,7 +7994,7 @@
79577994
79587995 String pigment = Object3D.GetPigment(tex);
79597996
7960
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7997
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79617998 {
79627999 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79638000 // System.out.println("; bump = " + bump);
....@@ -7986,7 +8023,7 @@
79868023
79878024 String bump = Object3D.GetBump(tex);
79888025
7989
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8026
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79908027 {
79918028 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79928029 // System.out.println("; bump = " + bump);
....@@ -8105,47 +8142,50 @@
81058142
81068143 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81078144 {
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
- }
8145
+// if (// DrawMode() != 0 || /*tex == null ||*/
8146
+// ambientOcclusion ) // || !textureon)
8147
+// {
8148
+// return; // false;
8149
+// }
8150
+//
8151
+// if (tex == null)
8152
+// {
8153
+// BindTexture(null,false,resolution);
8154
+// BindTexture(null,true,resolution);
8155
+// return;
8156
+// }
8157
+//
8158
+// String pigment = Object3D.GetPigment(tex);
8159
+// String bump = Object3D.GetBump(tex);
8160
+//
8161
+// usedtextures.add(pigment);
8162
+// usedtextures.add(bump);
8163
+//
8164
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8165
+// {
8166
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8167
+// // System.out.println("; bump = " + bump);
8168
+// }
8169
+//
8170
+// if (bump.equals(""))
8171
+// {
8172
+// bump = null;
8173
+// }
8174
+// if (pigment.equals(""))
8175
+// {
8176
+// pigment = null;
8177
+// }
8178
+//
8179
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8180
+// BindTexture(pigment, false, resolution);
8181
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8182
+// BindTexture(bump, true, resolution);
8183
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8184
+//
8185
+// return; // true;
81208186
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;
8187
+ BindPigmentTexture(tex, resolution);
8188
+ BindBumpTexture(tex, resolution);
81498189 }
81508190
81518191 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8158,15 +8198,15 @@
81588198
81598199 if (tex == null)
81608200 {
8161
- BindTexture(null,false,resolution);
8201
+ BindTexture(null, null,false,resolution);
81628202 return;
81638203 }
81648204
81658205 String pigment = Object3D.GetPigment(tex);
81668206
8167
- usedtextures.put(pigment, pigment);
8207
+ usedtextures.add(pigment);
81688208
8169
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8209
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81708210 {
81718211 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81728212 // System.out.println("; bump = " + bump);
....@@ -8178,7 +8218,7 @@
81788218 }
81798219
81808220 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8181
- BindTexture(pigment, false, resolution);
8221
+ BindTexture(tex.pigmenttexture, pigment, false, resolution);
81828222 }
81838223
81848224 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8191,15 +8231,15 @@
81918231
81928232 if (tex == null)
81938233 {
8194
- BindTexture(null,true,resolution);
8234
+ BindTexture(null, null,true,resolution);
81958235 return;
81968236 }
81978237
81988238 String bump = Object3D.GetBump(tex);
81998239
8200
- usedtextures.put(bump, bump);
8240
+ usedtextures.add(bump);
82018241
8202
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8242
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82038243 {
82048244 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82058245 // System.out.println("; bump = " + bump);
....@@ -8211,7 +8251,7 @@
82118251 }
82128252
82138253 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8214
- BindTexture(bump, true, resolution);
8254
+ BindTexture(tex.bumptexture, bump, true, resolution);
82158255 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82168256 }
82178257
....@@ -8235,9 +8275,9 @@
82358275 return fileExists;
82368276 }
82378277
8238
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8278
+ CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception
82398279 {
8240
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8280
+ CacheTexture texturecache = null;
82418281
82428282 if (tex != null)
82438283 {
....@@ -8257,12 +8297,22 @@
82578297 }
82588298
82598299 if (CACHETEXTURE)
8260
- texture = textures.get(texname); // TEXTURE CACHE
8261
-
8262
- TextureData texturedata = null;
8263
-
8264
- if (texture == null || texture.resolution < resolution)
82658300 {
8301
+ if (bim == null)
8302
+ texturecache = textures.get(texname); // TEXTURE CACHE
8303
+ else
8304
+ texturecache = bimtextures.get(bim); // TEXTURE CACHE
8305
+ }
8306
+
8307
+ if (texturecache == null || texturecache.resolution < resolution)
8308
+ {
8309
+ TextureData texturedata = null;
8310
+
8311
+ if (bim == null)
8312
+ {
8313
+
8314
+ }
8315
+ else
82668316 if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82678317 {
82688318 assert(!bump);
....@@ -8274,19 +8324,19 @@
82748324 // }
82758325 // else
82768326 // {
8277
- texture = textures.get(tex);
8278
- if (texture == null)
8327
+ texturecache = textures.get(tex);
8328
+ if (texturecache == null)
82798329 {
8280
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8330
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82818331 }
82828332 // }
82838333 } else
82848334 if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82858335 {
82868336 assert(bump);
8287
- texture = textures.get(tex);
8288
- if (texture == null)
8289
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8337
+ texturecache = textures.get(tex);
8338
+ if (texturecache == null)
8339
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82908340 } else
82918341 {
82928342 //if (tex.equals("IMMORTAL"))
....@@ -8296,9 +8346,9 @@
82968346 //{
82978347 if (tex.equals("WHITE_NOISE"))
82988348 {
8299
- texture = textures.get(tex);
8300
- if (texture == null)
8301
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8349
+ texturecache = textures.get(tex);
8350
+ if (texturecache == null)
8351
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
83028352 } else
83038353 {
83048354 if (textureon)
....@@ -8357,19 +8407,19 @@
83578407 if (texturedata == null)
83588408 throw new Exception();
83598409
8360
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8410
+ texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
83618411 //texture = GetTexture(tex, bump);
83628412 }
83638413 }
83648414 //}
83658415 }
83668416
8367
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8417
+ if (/*CACHETEXTURE &&*/ texturecache != null && textureon)
83688418 {
83698419 //return false;
83708420
83718421 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8372
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8422
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83738423 {
83748424 // String ext = "_highres";
83758425 // if (REDUCETEXTURE)
....@@ -8458,8 +8508,8 @@
84588508 textures.remove(texname);
84598509 }
84608510
8461
- texture.texturedata = texturedata;
8462
- textures.put(texname, texture);
8511
+ //texture.texturedata = texturedata;
8512
+ textures.put(texname, texturecache);
84638513
84648514 // newtex = true;
84658515 }
....@@ -8475,12 +8525,12 @@
84758525 }
84768526 }
84778527
8478
- return texture;
8528
+ return texturecache;
84798529 }
84808530
8481
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8531
+ com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
84828532 {
8483
- CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8533
+ CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
84848534
84858535 if (bump)
84868536 {
....@@ -8496,23 +8546,23 @@
84968546 return texture!=null?texture.texture:null;
84978547 }
84988548
8499
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8549
+ public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
85008550 {
8501
- CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8551
+ CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution);
85028552
85038553 return texture!=null?texture.texturedata:null;
85048554 }
85058555
8506
- boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
8556
+ boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception
85078557 {
85088558 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85098559 {
85108560 return false;
85118561 }
85128562
8513
- boolean newtex = false;
8563
+ //boolean newtex = false;
85148564
8515
- com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
8565
+ com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution);
85168566
85178567 if (texture == null)
85188568 return false;
....@@ -8542,7 +8592,7 @@
85428592 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85438593 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85448594
8545
- return newtex;
8595
+ return true; // Warning: not used.
85468596 }
85478597
85488598 ShadowBuffer shadowPBuf;
....@@ -10999,7 +11049,7 @@
1099911049
1100011050 try
1100111051 {
11002
- BindTexture(NOISE_TEXTURE, false, 2);
11052
+ BindTexture(null, NOISE_TEXTURE, false, 2);
1100311053 }
1100411054 catch (Exception e)
1100511055 {
....@@ -11664,7 +11714,7 @@
1166411714 if (tex.equals("WHITE_NOISE"))
1166511715 continue;
1166611716
11667
- if (!usedtextures.containsKey(tex))
11717
+ if (!usedtextures.contains(tex))
1166811718 {
1166911719 // System.out.println("DISPOSE +++++++++++++++ " + tex);
1167011720 textures.get(tex).texture.dispose();
....@@ -15708,6 +15758,7 @@
1570815758 info.bounds.y += (height - desired) / 2;
1570915759 }
1571015760 }
15761
+
1571115762 info.g = gr;
1571215763 info.camera = renderCamera;
1571315764 /*
....@@ -15717,6 +15768,8 @@
1571715768 */
1571815769 if (!isRenderer)
1571915770 {
15771
+ Grafreed.Assert(object != null);
15772
+ Grafreed.Assert(object.selection != null);
1572015773 if (object.selection.Size() > 0)
1572115774 {
1572215775 int hitSomething = object.selection.get(0).hitSomething;
....@@ -16550,6 +16603,14 @@
1655016603 }
1655116604 }
1655216605
16606
+ private Object3D GetFolder()
16607
+ {
16608
+ Object3D folder = object.GetWindow().copy;
16609
+ if (object.GetWindow().copy.selection.Size() > 0)
16610
+ folder = object.GetWindow().copy.selection.elementAt(0);
16611
+ return folder;
16612
+ }
16613
+
1655316614 class SelectBuffer implements GLEventListener
1655416615 {
1655516616
....@@ -16629,6 +16690,17 @@
1662916690
1663016691 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1663116692
16693
+ if (PAINTMODE)
16694
+ {
16695
+ if (object.GetWindow().copy.selection.Size() > 0)
16696
+ {
16697
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16698
+
16699
+ // Make what you paint not selectable.
16700
+ paintobj.ResetSelectable();
16701
+ }
16702
+ }
16703
+
1663216704 //int tmp = selection_view;
1663316705 //selection_view = -1;
1663416706 int temp = DrawMode();
....@@ -16640,6 +16712,17 @@
1664016712 // temp = DEFAULT; // patch for selection debug
1664116713 Globals.drawMode = temp; // WARNING
1664216714
16715
+ if (PAINTMODE)
16716
+ {
16717
+ if (object.GetWindow().copy.selection.Size() > 0)
16718
+ {
16719
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16720
+
16721
+ // Revert.
16722
+ paintobj.RestoreSelectable();
16723
+ }
16724
+ }
16725
+
1664316726 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1664416727
1664516728 // trying different ways of getting the depth info over
....@@ -16745,27 +16828,29 @@
1674516828 if (!movingcamera && !PAINTMODE)
1674616829 object.GetWindow().ScreenFitPoint(); // fev 2014
1674716830
16748
- if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16831
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1674916832 {
16750
- Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16751
-
16752
- Object3D group = new Object3D("inst" + paintcount++);
16753
-
16754
- group.CreateMaterial(); // use a void leaf to select instances
16755
-
16756
- group.add(paintobj); // link
16757
-
16758
- object.GetWindow().SnapObject(group);
16759
-
16760
- Object3D folder = object.GetWindow().copy;
16833
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1676116834
1676216835 if (object.GetWindow().copy.selection.Size() > 0)
16763
- folder = object.GetWindow().copy.selection.elementAt(0);
16836
+ {
16837
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1676416838
16765
- folder.add(group);
16766
-
16767
- object.GetWindow().ResetModel();
16768
- object.GetWindow().refreshContents();
16839
+ Object3D inst = new Object3D("inst" + paintcount++);
16840
+
16841
+ inst.CreateMaterial(); // use a void leaf to select instances
16842
+
16843
+ inst.add(paintobj); // link
16844
+
16845
+ object.GetWindow().SnapObject(inst);
16846
+
16847
+ Object3D folder = paintFolder; // GetFolder();
16848
+
16849
+ folder.add(inst);
16850
+
16851
+ object.GetWindow().ResetModel();
16852
+ object.GetWindow().refreshContents();
16853
+ }
1676916854 }
1677016855 else
1677116856 paintcount = 0;