Normand Briere
2019-09-25 51e45bf615e1e2b4aca2edf9f7333b687c7d015e
CameraPane.java
....@@ -1,4 +1,5 @@
11
2
+import com.bulletphysics.dynamics.RigidBody;
23 import java.awt.*;
34 import java.awt.event.*;
45 import java.awt.image.*;
....@@ -18,7 +19,10 @@
1819 import javax.imageio.ImageIO;
1920 import javax.imageio.ImageWriteParam;
2021 import javax.imageio.ImageWriter;
22
+import javax.imageio.ImageReadParam;
23
+import javax.imageio.ImageReader;
2124 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
25
+import javax.imageio.stream.ImageInputStream;
2226 import javax.imageio.stream.ImageOutputStream;
2327 import javax.imageio.ImageWriteParam;
2428
....@@ -30,6 +34,7 @@
3034 import java.nio.*;
3135
3236 import gleem.linalg.Mat4f;
37
+import javax.imageio.ImageTypeSpecifier;
3338
3439 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3540 {
....@@ -44,6 +49,39 @@
4449 static boolean ABORTED = false;
4550
4651 static int STEP = 1;
52
+
53
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
54
+ {
55
+ int[] pixels = new int[bytes.length/3];
56
+ for (int i=pixels.length; --i>=0;)
57
+ {
58
+ int i3 = i*3;
59
+ pixels[i] = 0xFF;
60
+ pixels[i] <<= 8;
61
+ pixels[i] |= bytes[i3+2] & 0xFF;
62
+ pixels[i] <<= 8;
63
+ pixels[i] |= bytes[i3+1] & 0xFF;
64
+ pixels[i] <<= 8;
65
+ pixels[i] |= bytes[i3] & 0xFF;
66
+ }
67
+ /*
68
+ int r=0,g=0,b=0,a=0;
69
+ for (int i=0; i<width; i++)
70
+ for (int j=0; j<height; j++)
71
+ {
72
+ int index = j*width+i;
73
+ int p = pixels[index];
74
+ a = ((p>>24) & 0xFF);
75
+ r = ((p>>16) & 0xFF);
76
+ g = ((p>>8) & 0xFF);
77
+ b = (p & 0xFF);
78
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
79
+ }
80
+ /**/
81
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
82
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
83
+ return rendImage;
84
+ }
4785
4886 /*static*/ private boolean CULLFACE = false; // true;
4987 /*static*/ boolean NEAREST = false; // true;
....@@ -60,7 +98,7 @@
6098 //boolean REDUCETEXTURE = true;
6199 boolean CACHETEXTURE = true;
62100 boolean CLEANCACHE = false; // true;
63
- boolean MIPMAP = false; // true;
101
+ boolean MIPMAP = false; // true; // never works...
64102 boolean COMPRESSTEXTURE = false;
65103 boolean KOMPACTTEXTURE = false; // true;
66104 boolean RESIZETEXTURE = false;
....@@ -73,7 +111,11 @@
73111 //private Mat4f spotlightTransform = new Mat4f();
74112 //private Mat4f spotlightInverseTransform = new Mat4f();
75113 static GLContext glcontext = null;
76
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
116
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
117
+ boolean transformMode;
118
+
77119 boolean reverseUP = false;
78120 static boolean frozen = false;
79121 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -93,7 +135,7 @@
93135 static boolean ZOOMBOXMODE = false;
94136 static boolean BOXMODE = false;
95137 static boolean IMAGEFLIP = false;
96
-static boolean SMOOTHFOCUS = false;
138
+static boolean SMOOTHFOCUS = true; // false;
97139 static boolean SPEAKERMOCAP = true; // jan 2014 false;
98140 static boolean SPEAKERCAMERA = false;
99141 static boolean SPEAKERFOCUS = false;
....@@ -127,16 +169,16 @@
127169
128170
129171 // OPTIONS
130
- boolean Skinshader = true;
172
+ boolean Skinshader = false; // true;
131173 boolean cameraLight = false;
132174 boolean UVdebug = false;
133175 boolean Udebug = false;
134176 boolean Vdebug = false;
135177 boolean NORMALdebug = false;
136
- static boolean doublesided = false; // true; // reversed normals are awful for conformance
178
+ static boolean doublesided = true; // false; // reversed normals are awful for conformance
137179 boolean anisotropy = true;
138180 boolean softshadow = true; // slower but better false;
139
- boolean opacityhalo = false;
181
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
140182
141183 boolean macromode = false;
142184
....@@ -150,6 +192,19 @@
150192 }
151193
152194 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
195
+
196
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
197
+ {
198
+ try
199
+ {
200
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
201
+ } catch (IOException e)
202
+ {
203
+ System.out.println("NAME = " + name);
204
+ e.printStackTrace(); // throw new RuntimeException(e);
205
+ return null;
206
+ }
207
+ }
153208
154209 void SetAsGLRenderer(boolean b)
155210 {
....@@ -167,9 +222,10 @@
167222 cameras = new Camera[2];
168223 targetLookAts = new cVector[2];
169224
170
- SetCamera(cam);
225
+ SetCamera(cam, true);
171226
172
- SetLight(new Camera(new cVector(10, 10, -20)));
227
+ // Warning: not used.
228
+ //SetLight(new Camera(new cVector(15, 10, -20)));
173229
174230 object = o;
175231
....@@ -487,7 +543,8 @@
487543 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
488544 LA.vecCross(obj.v0, obj.v1, obj.v2);
489545 LA.vecNormalize(obj.v2);
490
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
546
+
547
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
491548 }
492549
493550 // P
....@@ -509,7 +566,7 @@
509566 y += ny * obj.NORMALPUSH;
510567 z += nz * obj.NORMALPUSH;
511568
512
- gl.glNormal3f(nx, ny, nz);
569
+ SetGLNormal(gl, nx, ny, nz);
513570 }
514571 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
515572 SetColor(obj, pv);
....@@ -541,7 +598,7 @@
541598 y += ny * obj.NORMALPUSH;
542599 z += nz * obj.NORMALPUSH;
543600
544
- gl.glNormal3f(nx, ny, nz);
601
+ SetGLNormal(gl, nx, ny, nz);
545602 }
546603 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
547604 // boolean locked = false;
....@@ -589,7 +646,7 @@
589646 y += ny * obj.NORMALPUSH;
590647 z += nz * obj.NORMALPUSH;
591648
592
- gl.glNormal3f(nx, ny, nz);
649
+ SetGLNormal(gl, nx, ny, nz);
593650 }
594651
595652 // if ((dot&4) == 0)
....@@ -825,7 +882,7 @@
825882 //// tris.postdraw(this);
826883 }
827884
828
- static Camera localcamera = new Camera();
885
+ static Camera localAOcamera = new Camera();
829886 static cVector from = new cVector();
830887 static cVector to = new cVector();
831888
....@@ -834,7 +891,7 @@
834891 CameraPane cp = this;
835892
836893 Camera keep = cp.RenderCamera();
837
- cp.renderCamera = localcamera;
894
+ cp.renderCamera = localAOcamera;
838895
839896 if (br.trimmed)
840897 {
....@@ -852,7 +909,7 @@
852909 br.positions[i3 + 2] + br.normals[i3 + 2]);
853910 LA.xformPos(from, transform, from);
854911 LA.xformPos(to, transform, to); // RIGID ONLY
855
- localcamera.setAim(from, to);
912
+ localAOcamera.setAim(from, to);
856913
857914 CameraPane.occlusionbuffer.display();
858915
....@@ -886,7 +943,7 @@
886943 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
887944 LA.xformPos(from, transform, from);
888945 LA.xformPos(to, transform, to); // RIGID ONLY
889
- localcamera.setAim(from, to);
946
+ localAOcamera.setAim(from, to);
890947
891948 CameraPane.occlusionbuffer.display();
892949
....@@ -1195,10 +1252,10 @@
11951252 {
11961253 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
11971254 {
1198
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1255
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
11991256 } else
12001257 {
1201
- gl.glNormal3f(0, 0, 1);
1258
+ SetGLNormal(gl, 0, 0, 1);
12021259 }
12031260
12041261 if (c != null)
....@@ -1222,10 +1279,10 @@
12221279 {
12231280 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12241281 {
1225
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1282
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12261283 } else
12271284 {
1228
- gl.glNormal3f(0, 0, 1);
1285
+ SetGLNormal(gl, 0, 0, 1);
12291286 }
12301287 if (c != null)
12311288 {
....@@ -1250,10 +1307,10 @@
12501307 {
12511308 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12521309 {
1253
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1310
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12541311 } else
12551312 {
1256
- gl.glNormal3f(0, 0, 1);
1313
+ SetGLNormal(gl, 0, 0, 1);
12571314 }
12581315 if (c != null)
12591316 {
....@@ -1435,7 +1492,7 @@
14351492 {
14361493 if (!selectmode)
14371494 {
1438
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1495
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14391496 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14401497
14411498 if (flipV)
....@@ -1447,6 +1504,8 @@
14471504 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14481505 }
14491506
1507
+ float[] colorV = new float[4];
1508
+
14501509 void SetColor(Object3D obj, Vertex p0)
14511510 {
14521511 CameraPane display = this;
....@@ -1514,8 +1573,6 @@
15141573 {
15151574 return;
15161575 }
1517
-
1518
- float[] colorV = new float[3];
15191576
15201577 if (false) // marked)
15211578 {
....@@ -1764,7 +1821,7 @@
17641821
17651822 display.modelParams7[0] = 0;
17661823 display.modelParams7[1] = 1000;
1767
- display.modelParams7[2] = 0;
1824
+ display.modelParams7[2] = material.parallax;
17681825 display.modelParams7[3] = 0;
17691826
17701827 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -1997,9 +2054,9 @@
19972054 switch(viewcode)
19982055 {
19992056 case 0: return "main";
2000
- case 1: return "one";
2001
- case 2: return "two";
2002
- case 3: return "three";
2057
+ case 1: return "Red";
2058
+ case 2: return "Green";
2059
+ case 3: return "Blue";
20032060 case 4: return "light";
20042061 }
20052062
....@@ -2008,7 +2065,7 @@
20082065
20092066 static int camerachangeframe;
20102067
2011
- public boolean SetCamera(Camera cam)
2068
+ public boolean SetCamera(Camera cam, boolean set)
20122069 {
20132070 // may 2014 if (cam == cameras[0] || cam == cameras[1])
20142071 // return false;
....@@ -2026,7 +2083,8 @@
20262083
20272084 camerachangeframe = Globals.framecount;
20282085
2029
- cam.hAspect = -1; // Read only
2086
+ if (cam != null)
2087
+ cam.hAspect = -1; // Read only
20302088
20312089 cameras[0] = cam;
20322090 targetLookAts[0] = new cVector(cam.lookAt);
....@@ -2036,11 +2094,14 @@
20362094 {
20372095 cameras[i] = new Camera(cam.viewCode);
20382096 }
2039
-
2040
- cameras[i].setAim(cam.location, cam.lookAt);
2041
- cameras[i].shaper_fovy = cam.shaper_fovy;
2042
- cameras[i].UP.set(cam.UP);
2043
- targetLookAts[i] = new cVector(cameras[i].lookAt);
2097
+
2098
+ if (set)
2099
+ {
2100
+ cameras[i].setAim(cam.location, cam.lookAt);
2101
+ cameras[i].shaper_fovy = cam.shaper_fovy;
2102
+ cameras[i].UP.set(cam.UP);
2103
+ targetLookAts[i] = new cVector(cameras[i].lookAt);
2104
+ }
20442105 }
20452106 cameracount = 0;
20462107 targetLookAt = targetLookAts[cameracount];
....@@ -2049,7 +2110,7 @@
20492110 // Start with free camera
20502111 SwitchCameras(true);
20512112
2052
- pingthread.jump = true; // optional?
2113
+// pingthread.jump = true; // optional?
20532114
20542115 if (TRACKONCE)
20552116 {
....@@ -2236,18 +2297,6 @@
22362297 public void ToggleTrack()
22372298 {
22382299 TRACK ^= true;
2239
- if (TRACK)
2240
- {
2241
- if (object.selection != null &&
2242
- object.selection.size() > 0 &&
2243
- object.selection.elementAt(0) != null &&
2244
- !(object.selection.elementAt(0) instanceof Camera) &&
2245
- !(object.selection.elementAt(0) instanceof ScriptNode))
2246
- {
2247
- trackedobject = object.selection.elementAt(0);
2248
- repaint();
2249
- }
2250
- }
22512300
22522301 repaint();
22532302 }
....@@ -2339,7 +2388,8 @@
23392388 {
23402389 //System.out.println("PROTECTION = " + cam.hAspect);
23412390 //assert (cam.hAspect == 0);
2342
- cam.hAspect = 0;
2391
+ if (cam != null)
2392
+ cam.hAspect = 0;
23432393 lightCamera = cam;
23442394 }
23452395
....@@ -2405,6 +2455,33 @@
24052455 return currentGL;
24062456 }
24072457
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
2473
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2474
+ {
2475
+ gl.glNormal3f(nx, ny, nz);
2476
+
2477
+ if (ny > 0.9 || ny < -0.9)
2478
+ // Ground or ceiling
2479
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2480
+ else
2481
+ // Walls
2482
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2483
+ }
2484
+
24082485 /**/
24092486 class CacheTexture
24102487 {
....@@ -2413,28 +2490,31 @@
24132490
24142491 int resolution;
24152492
2416
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2493
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
24172494 {
2418
- texture = tex;
2495
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2496
+ texturedata = texdata;
24192497 resolution = res;
24202498 }
24212499 }
24222500 /**/
24232501
24242502 // TEXTURE static Texture texture;
2425
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
2426
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
2427
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2503
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2504
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2505
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2506
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2507
+
24282508 int pigmentdepth = 0;
24292509 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
24302510 int bumpdepth = 0;
24312511 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
24322512 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
24332513 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
2434
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2514
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
24352515 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
24362516
2437
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2517
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
24382518 {
24392519 TextureData texturedata = null;
24402520
....@@ -2444,7 +2524,7 @@
24442524 com.sun.opengl.util.texture.TextureIO.newTextureData(
24452525 getClass().getClassLoader().getResourceAsStream(name),
24462526 true,
2447
- com.sun.opengl.util.texture.TextureIO.PNG);
2527
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
24482528 } catch (java.io.IOException e)
24492529 {
24502530 throw new javax.media.opengl.GLException(e);
....@@ -2453,13 +2533,34 @@
24532533 if (bump)
24542534 texturedata = ConvertBump(texturedata, false);
24552535
2456
- com.sun.opengl.util.texture.Texture texture =
2457
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2536
+// com.sun.opengl.util.texture.Texture texture =
2537
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
24582538
2459
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2460
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2539
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2540
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
24612541
2462
- return texture;
2542
+ return texturedata;
2543
+ }
2544
+
2545
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2546
+ {
2547
+ TextureData texturedata = null;
2548
+
2549
+ try
2550
+ {
2551
+ texturedata =
2552
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2553
+ bim,
2554
+ true);
2555
+ } catch (Exception e)
2556
+ {
2557
+ throw new javax.media.opengl.GLException(e);
2558
+ }
2559
+
2560
+ if (bump)
2561
+ texturedata = ConvertBump(texturedata, false);
2562
+
2563
+ return texturedata;
24632564 }
24642565
24652566 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -3489,6 +3590,8 @@
34893590 };
34903591 /**/
34913592
3593
+ static Object3D lastObject;
3594
+
34923595 //com.sun.opengl.util.texture.Texture
34933596 TextureData
34943597 GetFileTexture(String name, boolean bump, int resolution)
....@@ -3525,6 +3628,8 @@
35253628 // return null;
35263629 //if (i == 2)
35273630 // return null;
3631
+ // TIFF issue sept 2019
3632
+ System.err.println("lastObject = " + lastObject);
35283633 e.printStackTrace();
35293634 name = name.split("\\.tif")[0] + ".jpg";
35303635 }
....@@ -3532,6 +3637,8 @@
35323637
35333638 System.out.println("LOADING TEXTURE : " + name);
35343639
3640
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3641
+
35353642 //
35363643 if (false) // compressbit > 0)
35373644 {
....@@ -6855,30 +6962,30 @@
68556962 short residu = 0;
68566963
68576964 // wraparound workarounds
6858
- short fuck = (short) (buffer[i] & 0xFF);
6965
+ short ww = (short) (buffer[i] & 0xFF);
68596966 /*
6860
- residu += (fuck%2);
6861
- if(fuck/2 < 256-residu/2)
6967
+ residu += (ww%2);
6968
+ if(ww/2 < 256-residu/2)
68626969 {
6863
- fuck = (short)((fuck/2) + residu/2);
6970
+ ww = (short)((ww/2) + residu/2);
68646971 if(residu == 2)
68656972 residu = 0;
68666973 }
68676974 else
68686975 {
68696976 residu = 0;
6870
- fuck /= 2;
6977
+ ww /= 2;
68716978 }
68726979 */
6873
- if (i < imglength / 3 || rnd.nextFloat() < 0.5 || fuck >= 254)
6980
+ if (i < imglength / 3 || rnd.nextFloat() < 0.5 || ww >= 254)
68746981 {
6875
- fuck /= 2;
6982
+ ww /= 2;
68766983 } else
68776984 {
6878
- fuck = (short) ((fuck / 2) + fuck % 2);
6985
+ ww = (short) ((ww / 2) + ww % 2);
68796986 }
68806987
6881
- buffer[i] = (byte) fuck;
6988
+ buffer[i] = (byte) ww;
68826989 }
68836990 //System.out.print(bytes[i] + " ");
68846991 //if(buffer[i] >= 0 && buffer[i]<=eps-1) buffer[i] = eps;
....@@ -7930,7 +8037,7 @@
79308037 String pigment = Object3D.GetPigment(tex);
79318038 String bump = Object3D.GetBump(tex);
79328039
7933
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8040
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79348041 {
79358042 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79368043 // System.out.println("; bump = " + bump);
....@@ -7945,8 +8052,8 @@
79458052 pigment = null;
79468053 }
79478054
7948
- ReleaseTexture(bump, true);
7949
- ReleaseTexture(pigment, false);
8055
+ ReleaseTexture(tex, true);
8056
+ ReleaseTexture(tex, false);
79508057 }
79518058
79528059 public void ReleasePigmentTexture(cTexture tex) // INTERFACE
....@@ -7964,7 +8071,7 @@
79648071
79658072 String pigment = Object3D.GetPigment(tex);
79668073
7967
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79688075 {
79698076 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79708077 // System.out.println("; bump = " + bump);
....@@ -7975,7 +8082,7 @@
79758082 pigment = null;
79768083 }
79778084
7978
- ReleaseTexture(pigment, false);
8085
+ ReleaseTexture(tex, false);
79798086 }
79808087
79818088 public void ReleaseBumpTexture(cTexture tex) // INTERFACE
....@@ -7993,7 +8100,7 @@
79938100
79948101 String bump = Object3D.GetBump(tex);
79958102
7996
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8103
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
79978104 {
79988105 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
79998106 // System.out.println("; bump = " + bump);
....@@ -8004,10 +8111,10 @@
80048111 bump = null;
80058112 }
80068113
8007
- ReleaseTexture(bump, true);
8114
+ ReleaseTexture(tex, true);
80088115 }
80098116
8010
- void ReleaseTexture(String tex, boolean bump)
8117
+ void ReleaseTexture(cTexture tex, boolean bump)
80118118 {
80128119 if (// DrawMode() != 0 || /*tex == null ||*/
80138120 ambientOcclusion ) // || !textureon)
....@@ -8018,7 +8125,7 @@
80188125 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80198126
80208127 if (tex != null)
8021
- texture = textures.get(tex);
8128
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
80228129
80238130 // //assert( texture != null );
80248131 // if (texture == null)
....@@ -8112,47 +8219,50 @@
81128219
81138220 /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
81148221 {
8115
- if (// DrawMode() != 0 || /*tex == null ||*/
8116
- ambientOcclusion ) // || !textureon)
8117
- {
8118
- return; // false;
8119
- }
8120
-
8121
- if (tex == null)
8122
- {
8123
- BindTexture(null,false,resolution);
8124
- BindTexture(null,true,resolution);
8125
- return;
8126
- }
8222
+// if (// DrawMode() != 0 || /*tex == null ||*/
8223
+// ambientOcclusion ) // || !textureon)
8224
+// {
8225
+// return; // false;
8226
+// }
8227
+//
8228
+// if (tex == null)
8229
+// {
8230
+// BindTexture(null,false,resolution);
8231
+// BindTexture(null,true,resolution);
8232
+// return;
8233
+// }
8234
+//
8235
+// String pigment = Object3D.GetPigment(tex);
8236
+// String bump = Object3D.GetBump(tex);
8237
+//
8238
+// usedtextures.add(pigment);
8239
+// usedtextures.add(bump);
8240
+//
8241
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8242
+// {
8243
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8244
+// // System.out.println("; bump = " + bump);
8245
+// }
8246
+//
8247
+// if (bump.equals(""))
8248
+// {
8249
+// bump = null;
8250
+// }
8251
+// if (pigment.equals(""))
8252
+// {
8253
+// pigment = null;
8254
+// }
8255
+//
8256
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8257
+// BindTexture(pigment, false, resolution);
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8259
+// BindTexture(bump, true, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8261
+//
8262
+// return; // true;
81278263
8128
- String pigment = Object3D.GetPigment(tex);
8129
- String bump = Object3D.GetBump(tex);
8130
-
8131
- usedtextures.put(pigment, pigment);
8132
- usedtextures.put(bump, bump);
8133
-
8134
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8135
- {
8136
- // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8137
- // System.out.println("; bump = " + bump);
8138
- }
8139
-
8140
- if (bump.equals(""))
8141
- {
8142
- bump = null;
8143
- }
8144
- if (pigment.equals(""))
8145
- {
8146
- pigment = null;
8147
- }
8148
-
8149
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8150
- BindTexture(pigment, false, resolution);
8151
- GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8152
- BindTexture(bump, true, resolution);
8153
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8154
-
8155
- return; // true;
8264
+ BindPigmentTexture(tex, resolution);
8265
+ BindBumpTexture(tex, resolution);
81568266 }
81578267
81588268 /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8171,9 +8281,9 @@
81718281
81728282 String pigment = Object3D.GetPigment(tex);
81738283
8174
- usedtextures.put(pigment, pigment);
8284
+ usedtextures.add(tex);
81758285
8176
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
81778287 {
81788288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
81798289 // System.out.println("; bump = " + bump);
....@@ -8185,7 +8295,7 @@
81858295 }
81868296
81878297 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8188
- BindTexture(pigment, false, resolution);
8298
+ BindTexture(tex, false, resolution);
81898299 }
81908300
81918301 /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
....@@ -8204,9 +8314,9 @@
82048314
82058315 String bump = Object3D.GetBump(tex);
82068316
8207
- usedtextures.put(bump, bump);
8317
+ usedtextures.add(tex);
82088318
8209
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8319
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
82108320 {
82118321 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
82128322 // System.out.println("; bump = " + bump);
....@@ -8218,7 +8328,7 @@
82188328 }
82198329
82208330 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8221
- BindTexture(bump, true, resolution);
8331
+ BindTexture(tex, true, resolution);
82228332 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
82238333 }
82248334
....@@ -8242,13 +8352,19 @@
82428352 return fileExists;
82438353 }
82448354
8245
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
8355
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
82468356 {
8247
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8357
+ CacheTexture texturecache = null;
82488358
82498359 if (tex != null)
82508360 {
8251
- String texname = tex;
8361
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8362
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
8363
+
8364
+ if (texname.equals("") && texdata == null)
8365
+ {
8366
+ return null;
8367
+ }
82528368
82538369 String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
82548370
....@@ -8258,19 +8374,46 @@
82588374 // else
82598375 // if (!texname.startsWith("/"))
82608376 // texname = "/Users/nbriere/Textures/" + texname;
8261
- if (!FileExists(tex))
8377
+ if (!FileExists(texname) && !texname.startsWith("@"))
82628378 {
82638379 texname = fallbackTextureName;
82648380 }
82658381
82668382 if (CACHETEXTURE)
8267
- texture = textures.get(texname); // TEXTURE CACHE
8268
-
8269
- TextureData texturedata = null;
8270
-
8271
- if (texture == null || texture.resolution < resolution)
82728383 {
8273
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8384
+ if (texdata == null)
8385
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8386
+ else
8387
+ texturecache = bimtextures.get(texdata);
8388
+ }
8389
+
8390
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8391
+ {
8392
+ TextureData texturedata = null;
8393
+
8394
+ if (texdata != null && textureon)
8395
+ {
8396
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8397
+
8398
+ try
8399
+ {
8400
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8401
+ }
8402
+ catch (Exception e)
8403
+ {
8404
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8405
+ }
8406
+
8407
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8408
+ bimtextures.put(texdata, texturecache);
8409
+
8410
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8411
+
8412
+ //Object bim2 = CreateBim(texturecache.texturedata);
8413
+ //bim2 = bim;
8414
+ }
8415
+ else
8416
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
82748417 {
82758418 assert(!bump);
82768419 // if (bump)
....@@ -8281,19 +8424,23 @@
82818424 // }
82828425 // else
82838426 // {
8284
- texture = textures.get(tex);
8285
- if (texture == null)
8427
+ // texturecache = textures.get(texname); // suspicious
8428
+ if (texturecache == null)
82868429 {
8287
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
82888431 }
8432
+ else
8433
+ new Exception().printStackTrace();
82898434 // }
82908435 } else
8291
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8436
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
82928437 {
82938438 assert(bump);
8294
- texture = textures.get(tex);
8295
- if (texture == null)
8296
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8439
+ // texturecache = textures.get(texname); // suspicious
8440
+ if (texturecache == null)
8441
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8442
+ else
8443
+ new Exception().printStackTrace();
82978444 } else
82988445 {
82998446 //if (tex.equals("IMMORTAL"))
....@@ -8301,11 +8448,22 @@
83018448 // texture = GetResourceTexture("default.png");
83028449 //} else
83038450 //{
8304
- if (tex.equals("WHITE_NOISE"))
8451
+ if (texname.endsWith("WHITE_NOISE"))
83058452 {
8306
- texture = textures.get(tex);
8307
- if (texture == null)
8308
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8453
+ // texturecache = textures.get(texname); // suspicious
8454
+ if (texturecache == null)
8455
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.jpg", bump),resolution);
8456
+ else
8457
+ new Exception().printStackTrace();
8458
+ } else
8459
+ {
8460
+ if (texname.startsWith("@") && textureon)
8461
+ {
8462
+ // texturecache = textures.get(texname); // suspicious
8463
+ if (texturecache == null)
8464
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8465
+ else
8466
+ new Exception().printStackTrace();
83098467 } else
83108468 {
83118469 if (textureon)
....@@ -8364,19 +8522,20 @@
83648522 if (texturedata == null)
83658523 throw new Exception();
83668524
8367
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8525
+ texturecache = new CacheTexture(texturedata,resolution);
83688526 //texture = GetTexture(tex, bump);
83698527 }
8528
+ }
83708529 }
83718530 //}
83728531 }
83738532
8374
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8533
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
83758534 {
83768535 //return false;
83778536
83788537 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
8379
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8538
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
83808539 {
83818540 // String ext = "_highres";
83828541 // if (REDUCETEXTURE)
....@@ -8393,52 +8552,17 @@
83938552 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
83948553 if (!cachefile.exists())
83958554 {
8396
- // cache to disk
8397
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
8398
- //buffers[0].
8399
-
8400
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
8401
- int[] pixels = new int[bytebuf.capacity()/3];
8402
-
8403
- // squared size heuristic...
8404
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8555
+ //if (texturedata.getWidth() == texturedata.getHeight())
84058556 {
8406
- for (int i=pixels.length; --i>=0;)
8407
- {
8408
- int i3 = i*3;
8409
- pixels[i] = 0xFF;
8410
- pixels[i] <<= 8;
8411
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
8412
- pixels[i] <<= 8;
8413
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
8414
- pixels[i] <<= 8;
8415
- pixels[i] |= bytebuf.get(i3) & 0xFF;
8416
- }
8417
-
8418
- /*
8419
- int r=0,g=0,b=0,a=0;
8420
- for (int i=0; i<width; i++)
8421
- for (int j=0; j<height; j++)
8422
- {
8423
- int index = j*width+i;
8424
- int p = pixels[index];
8425
- a = ((p>>24) & 0xFF);
8426
- r = ((p>>16) & 0xFF);
8427
- g = ((p>>8) & 0xFF);
8428
- b = (p & 0xFF);
8429
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
8430
- }
8431
- /**/
8432
- int width = (int)Math.sqrt(pixels.length); // squared
8433
- int height = width;
8434
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
8435
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8557
+ BufferedImage rendImage = CreateBim(texturedata);
8558
+
84368559 ImageWriter writer = null;
84378560 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
84388561 if (iter.hasNext()) {
84398562 writer = (ImageWriter)iter.next();
84408563 }
8441
- float compressionQuality = 0.9f;
8564
+
8565
+ float compressionQuality = 0.85f;
84428566 try
84438567 {
84448568 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -8455,18 +8579,20 @@
84558579 }
84568580 }
84578581 }
8458
-
8582
+
8583
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8584
+
84598585 //System.out.println("Texture = " + tex);
8460
- if (textures.containsKey(texname))
8586
+ if (textures.containsKey(tex))
84618587 {
8462
- CacheTexture thetex = textures.get(texname);
8588
+ CacheTexture thetex = textures.get(tex);
84638589 thetex.texture.disable();
84648590 thetex.texture.dispose();
8465
- textures.remove(texname);
8591
+ textures.remove(tex);
84668592 }
84678593
8468
- texture.texturedata = texturedata;
8469
- textures.put(texname, texture);
8594
+ //texture.texturedata = texturedata;
8595
+ textures.put(tex, texturecache);
84708596
84718597 // newtex = true;
84728598 }
....@@ -8482,10 +8608,46 @@
84828608 }
84838609 }
84848610
8485
- return texture;
8611
+ return texturecache;
84868612 }
84878613
8488
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
8614
+ static void EmbedTextures(cTexture tex)
8615
+ {
8616
+ if (tex.pigmentdata == null)
8617
+ {
8618
+ //String texname = Object3D.GetPigment(tex);
8619
+
8620
+ CacheTexture texturecache = texturepigment.get(tex);
8621
+
8622
+ if (texturecache != null)
8623
+ {
8624
+ tex.pw = texturecache.texturedata.getWidth();
8625
+ tex.ph = texturecache.texturedata.getHeight();
8626
+ tex.pigmentdata = //CompressJPEG(CreateBim
8627
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8628
+ ;
8629
+ //, tex.pw, tex.ph), 0.5f);
8630
+ }
8631
+ }
8632
+
8633
+ if (tex.bumpdata == null)
8634
+ {
8635
+ //String texname = Object3D.GetBump(tex);
8636
+
8637
+ CacheTexture texturecache = texturebump.get(tex);
8638
+
8639
+ if (texturecache != null)
8640
+ {
8641
+ tex.bw = texturecache.texturedata.getWidth();
8642
+ tex.bh = texturecache.texturedata.getHeight();
8643
+ tex.bumpdata = //CompressJPEG(CreateBim(
8644
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8645
+ //, tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
84898651 {
84908652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
84918653
....@@ -8503,26 +8665,26 @@
85038665 return texture!=null?texture.texture:null;
85048666 }
85058667
8506
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
85078669 {
85088670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
85098671
85108672 return texture!=null?texture.texturedata:null;
85118673 }
85128674
8513
- com.sun.opengl.util.texture.Texture BindTexture(String tex, boolean bump, int resolution) throws Exception
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
85148676 {
85158677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
85168678 {
85178679 return false;
85188680 }
85198681
8520
- boolean newtex = false;
8682
+ //boolean newtex = false;
85218683
85228684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
85238685
85248686 if (texture == null)
8525
- return texture;
8687
+ return false;
85268688 /**/
85278689
85288690 if (textureon || tex.equals("DEFAULT_TEXTURE") || tex.equals("DEFAULT_TEXTURE_BUMP") || tex.equals("WHITE_NOISE")) // || tex.equals("IMMORTAL"))
....@@ -8549,9 +8711,75 @@
85498711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
85508712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
85518713
8552
- return newtex;
8714
+ return true; // Warning: not used.
85538715 }
85548716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
85558783 ShadowBuffer shadowPBuf;
85568784 AntialiasBuffer antialiasPBuf;
85578785 int MAXSTACK;
....@@ -8568,10 +8796,12 @@
85688796
85698797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
85708798 MAXSTACK = temp[0];
8571
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
85728801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
85738802 MAXSTACK = temp[0];
8574
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
85758805
85768806 // Use debug pipeline
85778807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8579,7 +8809,8 @@
85798809 gl = drawable.getGL(); //
85808810
85818811 GL gl3 = getGL();
8582
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
85838814
85848815
85858816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8744,7 +8975,7 @@
87448975
87458976 if (cubemap == null)
87468977 {
8747
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
87488979 }
87498980
87508981 //cubemap.enable();
....@@ -9020,6 +9251,8 @@
90209251
90219252 void LoadEnvy(int which)
90229253 {
9254
+ assert(false);
9255
+
90239256 String name;
90249257 String ext;
90259258
....@@ -9031,37 +9264,58 @@
90319264 cubemap = null;
90329265 return;
90339266 case 1:
9034
- name = "cubemaps/box_";
9035
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
90369269 reverseUP = false;
90379270 break;
90389271 case 2:
9039
- name = "cubemaps/uffizi_";
9040
- ext = "png";
9041
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
90429276 case 3:
9043
- name = "cubemaps/CloudyHills_";
9044
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
90459279 reverseUP = false;
90469280 break;
90479281 case 4:
9048
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
90499283 ext = "png";
90509284 reverseUP = false;
90519285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
90529311 default:
9053
- name = "cubemaps/rgb_";
9054
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
90559315 break;
90569316 }
9057
-
9058
- try
9059
- {
9060
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9061
- } catch (IOException e)
9062
- {
9063
- throw new RuntimeException(e);
9064
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
90659319 }
90669320
90679321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9093,8 +9347,12 @@
90939347 static double[] model = new double[16];
90949348 double[] camera2light = new double[16];
90959349 double[] light2camera = new double[16];
9096
- int newenvy = -1;
9097
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
90989356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
90999357 //float[] light0 = { 0,0,0 };
91009358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9512,7 +9770,7 @@
95129770
95139771 if (renderCamera != lightCamera)
95149772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9515
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
95169774
95179775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
95189776
....@@ -9528,7 +9786,7 @@
95289786
95299787 if (renderCamera != lightCamera)
95309788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9531
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
95329790
95339791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
95349792
....@@ -9574,13 +9832,18 @@
95749832 rati = 1 / rati;
95759833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
95769834 }
9577
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
95789838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
95799839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9580
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
95819841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
95829842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
9583
- accPerspective(gl, renderCamera.shaper_fovy / ratio,
9843
+
9844
+ boolean vr = capsLocked && !lightMode;
9845
+
9846
+ accPerspective(gl, renderCamera.shaper_fovy / ratio * (vr ? 1.2 : 1),
95849847 ratio,
95859848 //near_plane, far_plane,
95869849 renderCamera.shaper_zNear * renderCamera.Distance(), renderCamera.shaper_zFar * renderCamera.Distance(),
....@@ -10443,9 +10706,18 @@
1044310706 static boolean init = false;
1044410707
1044510708 double[][] matrix = LA.newMatrix();
10709
+
10710
+ // This is to refresh the UI of the material panel.
10711
+ ObjEditor patchMaterial;
1044610712
1044710713 public void display(GLAutoDrawable drawable)
1044810714 {
10715
+ if (patchMaterial.patchMaterial)
10716
+ {
10717
+ patchMaterial.patchMaterial = false;
10718
+ patchMaterial.objectTabbedPane.setSelectedIndex(1);
10719
+ }
10720
+
1044910721 if (Grafreed.savesound && Grafreed.hassound)
1045010722 {
1045110723 Grafreed.wav.save();
....@@ -10541,6 +10813,112 @@
1054110813
1054210814 if (DrawMode() == DEFAULT)
1054310815 {
10816
+ if (manipCamera == lightCamera)
10817
+ {
10818
+// switch (e.getKeyCode())
10819
+// {
10820
+// case DOWN_ARROW:
10821
+// lightCamera.DECAL /= 2;
10822
+// repaint();
10823
+// break;
10824
+// case UP_ARROW:
10825
+// lightCamera.DECAL *= 2;
10826
+// repaint();
10827
+// break;
10828
+// case LEFT_ARROW:
10829
+// lightCamera.SCALE /= 2;
10830
+// repaint();
10831
+// break;
10832
+// case RIGHT_ARROW:
10833
+// lightCamera.SCALE *= 2;
10834
+// repaint();
10835
+// break;
10836
+// default:
10837
+// break;
10838
+ if (keys[DOWN_ARROW])
10839
+ {
10840
+ lightCamera.DECAL /= 2;
10841
+ }
10842
+
10843
+ if (keys[UP_ARROW])
10844
+ {
10845
+ lightCamera.DECAL *= 2;
10846
+ }
10847
+
10848
+ if (keys[LEFT_ARROW])
10849
+ {
10850
+ lightCamera.SCALE /= 2;
10851
+ }
10852
+
10853
+ if (keys[RIGHT_ARROW])
10854
+ {
10855
+ lightCamera.SCALE *= 2;
10856
+ }
10857
+ }
10858
+ else
10859
+ {
10860
+ //pingthread.mute = true;
10861
+
10862
+ boolean keyon = false;
10863
+
10864
+ if (keys[DOWN_ARROW])
10865
+ {
10866
+ speed = ++speedkey[DOWN_ARROW];
10867
+ if (speed > 20)
10868
+ speed = 20;
10869
+ GoDown(modifiers);
10870
+ keyon = true;
10871
+ }
10872
+ else
10873
+ speedkey[DOWN_ARROW] = 0;
10874
+
10875
+ if (keys[UP_ARROW])
10876
+ {
10877
+ speed = ++speedkey[UP_ARROW];
10878
+ if (speed > 20)
10879
+ speed = 20;
10880
+ GoUp(modifiers);
10881
+ keyon = true;
10882
+ }
10883
+ else
10884
+ speedkey[UP_ARROW] = 0;
10885
+
10886
+ if (keys[LEFT_ARROW])
10887
+ {
10888
+ speed = ++speedkey[LEFT_ARROW];
10889
+ if (speed > 20)
10890
+ speed = 20;
10891
+ GoLeft(modifiers);
10892
+ keyon = true;
10893
+ }
10894
+ else
10895
+ speedkey[LEFT_ARROW] = 0;
10896
+
10897
+ if (keys[RIGHT_ARROW])
10898
+ {
10899
+ speed = ++speedkey[RIGHT_ARROW];
10900
+ if (speed > 20)
10901
+ speed = 20;
10902
+ GoRight(modifiers);
10903
+ keyon = true;
10904
+ }
10905
+ else
10906
+ speedkey[RIGHT_ARROW] = 0;
10907
+
10908
+ if (Globals.WALK && capsLocked)
10909
+ {
10910
+ Walk();
10911
+ keyon = true;
10912
+ }
10913
+
10914
+ if (keyon)
10915
+ {
10916
+ repaint();
10917
+ }
10918
+
10919
+ //pingthread.mute = false;
10920
+ }
10921
+
1054410922 currentlydrawing = true;
1054510923 }
1054610924
....@@ -10614,7 +10992,7 @@
1061410992
1061510993 if (wait)
1061610994 {
10617
- Sleep(500);
10995
+ Sleep(200); // blocks everything
1061810996
1061910997 wait = false;
1062010998 }
....@@ -10729,7 +11107,7 @@
1072911107 // if (parentcam != renderCamera) // not a light
1073011108 if (cam != lightCamera)
1073111109 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10732
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11110
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1073311111
1073411112 for (int j = 0; j < 4; j++)
1073511113 {
....@@ -10744,7 +11122,7 @@
1074411122 // if (parentcam != renderCamera) // not a light
1074511123 if (cam != lightCamera)
1074611124 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10747
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11125
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1074811126
1074911127 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1075011128
....@@ -10830,13 +11208,43 @@
1083011208 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1083111209 }
1083211210
10833
- if (newenvy > -1)
11211
+// if (newenvy > -1)
11212
+// {
11213
+// LoadEnvy(newenvy);
11214
+// }
11215
+//
11216
+// newenvy = -1;
11217
+
11218
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1083411219 {
10835
- LoadEnvy(newenvy);
11220
+ if (cubemaprgb == null)
11221
+ {
11222
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11223
+ }
11224
+
11225
+ cubemap = cubemaprgb;
1083611226 }
10837
-
10838
- newenvy = -1;
10839
-
11227
+ else
11228
+ {
11229
+ if (object.skyboxname != null)
11230
+ {
11231
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11232
+ {
11233
+ if (cubemap != null && cubemap != cubemaprgb)
11234
+ cubemap.dispose();
11235
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11236
+ loadedskyboxname = object.skyboxname;
11237
+ }
11238
+ }
11239
+ else
11240
+ {
11241
+ cubemapcustom = null;
11242
+ loadedskyboxname = null;
11243
+ }
11244
+
11245
+ cubemap = cubemapcustom;
11246
+ }
11247
+
1084011248 ratio = ((double) getWidth()) / getHeight();
1084111249 //System.out.println("ratio = " + ratio);
1084211250
....@@ -10852,7 +11260,7 @@
1085211260
1085311261 if (!IsFrozen() && !ambientOcclusion)
1085411262 {
10855
- DrawSkyBox(gl);
11263
+ DrawSkyBox(gl, (float)ratio);
1085611264 }
1085711265
1085811266 //if (selection_view == -1)
....@@ -11035,9 +11443,9 @@
1103511443
1103611444 gl.glMatrixMode(GL.GL_MODELVIEW);
1103711445
11038
-gl.glEnable(gl.GL_POLYGON_SMOOTH);
11039
-gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11040
-gl.glEnable(gl.GL_MULTISAMPLE);
11446
+//gl.glEnable(gl.GL_POLYGON_SMOOTH);
11447
+//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11448
+//gl.glEnable(gl.GL_MULTISAMPLE);
1104111449 } else
1104211450 {
1104311451 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -11098,7 +11506,10 @@
1109811506 //gl.glOrtho(-BOOST, BOOST, -BOOST, BOOST, 0.001, 1000);
1109911507 } else
1110011508 {
11101
- glu.gluPerspective(cam.shaper_fovy / ratio, ratio, cam.shaper_zNear * cam.Distance(), cam.shaper_zFar * cam.Distance());
11509
+ boolean vr = capsLocked && !lightMode;
11510
+
11511
+ glu.gluPerspective(cam.shaper_fovy / ratio * (vr ? 1.2 : 1),
11512
+ ratio, cam.shaper_zNear * cam.Distance(), cam.shaper_zFar * cam.Distance());
1110211513 }
1110311514 }
1110411515
....@@ -11138,7 +11549,7 @@
1113811549
1113911550 // if (cam != lightCamera)
1114011551 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11141
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11552
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1114211553 }
1114311554
1114411555 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11297,7 +11708,7 @@
1129711708 }
1129811709 }
1129911710
11300
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11711
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1130111712 {
1130211713 //gl.glDepthFunc(GL.GL_LEQUAL);
1130311714 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11305,24 +11716,21 @@
1130511716
1130611717 boolean texon = textureon;
1130711718
11308
- if (RENDERPROGRAM > 0)
11309
- {
11310
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11311
- textureon = false;
11312
- }
11719
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11720
+ textureon = false;
11721
+
1131311722 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1131411723 //System.out.println("ALLO");
1131511724 gl.glColorMask(false, false, false, false);
1131611725 DrawObject(gl);
11317
- if (RENDERPROGRAM > 0)
11318
- {
11319
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11320
- textureon = texon;
11321
- }
11726
+
11727
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11728
+ textureon = texon;
11729
+
1132211730 gl.glColorMask(true, true, true, true);
1132311731
1132411732 gl.glDepthFunc(GL.GL_EQUAL);
11325
- //gl.glDepthMask(false);
11733
+ gl.glDepthMask(false);
1132611734 }
1132711735
1132811736 if (false) // DrawMode() == SHADOW)
....@@ -11457,8 +11865,11 @@
1145711865 repaint();
1145811866 }
1145911867
11460
- if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
11868
+ if (Globals.isLIVE() && DrawMode() == DEFAULT || pingthread.live) // may 2013
11869
+ {
11870
+ renderCamera.computeTransform();
1146111871 repaint();
11872
+ }
1146211873
1146311874 displaydone = true;
1146411875 }
....@@ -11533,9 +11944,23 @@
1153311944 //GL gl = getGL();
1153411945 if ((TRACK || SHADOWTRACK) || zoomonce)
1153511946 {
11947
+ if (TRACK)
11948
+ {
11949
+ if (object.selection != null &&
11950
+ object.selection.size() > 0 &&
11951
+ object.selection.elementAt(0) != null &&
11952
+ !(object.selection.elementAt(0) instanceof Camera) &&
11953
+ !(object.selection.elementAt(0) instanceof ScriptNode))
11954
+ {
11955
+ trackedobject = object.selection.elementAt(0);
11956
+ //repaint();
11957
+ }
11958
+ else
11959
+ trackedobject = null;
11960
+ }
1153611961 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1153711962 object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11538
- pingthread.StepToTarget(true); // true);
11963
+ pingthread.StepToTarget(); // true);
1153911964 // zoomonce = false;
1154011965 }
1154111966
....@@ -11662,20 +12087,32 @@
1166212087 ReleaseTextures(DEFAULT_TEXTURES);
1166312088
1166412089 if (CLEANCACHE)
11665
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
12090
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1166612091 {
11667
- String tex = e.nextElement();
12092
+ cTexture tex = e.nextElement();
1166812093
1166912094 // System.out.println("Texture --------- " + tex);
1167012095
11671
- if (tex.equals("WHITE_NOISE"))
12096
+ if (tex.equals("WHITE_NOISE:"))
1167212097 continue;
1167312098
11674
- if (!usedtextures.containsKey(tex))
12099
+ if (!usedtextures.contains(tex))
1167512100 {
12101
+ CacheTexture gettex = texturepigment.get(tex);
1167612102 // System.out.println("DISPOSE +++++++++++++++ " + tex);
11677
- textures.get(tex).texture.dispose();
11678
- textures.remove(tex);
12103
+ if (gettex != null)
12104
+ {
12105
+ gettex.texture.dispose();
12106
+ texturepigment.remove(tex);
12107
+ }
12108
+
12109
+ gettex = texturebump.get(tex);
12110
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
12111
+ if (gettex != null)
12112
+ {
12113
+ gettex.texture.dispose();
12114
+ texturebump.remove(tex);
12115
+ }
1167912116 }
1168012117 }
1168112118 }
....@@ -12203,8 +12640,82 @@
1220312640
1220412641 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1220512642
12206
- String program =
12643
+ String programmin =
12644
+ // Min shader
1220712645 "!!ARBfp1.0\n" +
12646
+ "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" +
12647
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12648
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
12649
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12650
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12651
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12652
+ "PARAM light2cam0 = program.env[10];" +
12653
+ "PARAM light2cam1 = program.env[11];" +
12654
+ "PARAM light2cam2 = program.env[12];" +
12655
+ "TEMP temp;" +
12656
+ "TEMP light;" +
12657
+ "TEMP ndotl;" +
12658
+ "TEMP normal;" +
12659
+ "TEMP depth;" +
12660
+ "TEMP eye;" +
12661
+ "TEMP pos;" +
12662
+
12663
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12664
+ Normalize("normal") +
12665
+ "MOV light, state.light[0].position;" +
12666
+ "DP3 ndotl.x, light, normal;" +
12667
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
12668
+
12669
+ // shadow
12670
+ "MOV pos, fragment.texcoord[1];" +
12671
+ "MOV temp, pos;" +
12672
+ ShadowTextureFetch("depth", "temp", "1") +
12673
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12674
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12675
+
12676
+ // No shadow when out of frustum
12677
+ //"SGE temp.y, depth.z, zero123.y;" +
12678
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12679
+
12680
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12681
+
12682
+ // Backlit
12683
+ "MOV pos.w, zero12t.y;" + // one
12684
+ "DP4 eye.x, pos, light2cam0;" +
12685
+ "DP4 eye.y, pos, light2cam1;" +
12686
+ "DP4 eye.z, pos, light2cam2;" +
12687
+ Normalize("eye") +
12688
+
12689
+ "DP3 ndotl.y, -eye, normal;" +
12690
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12691
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12692
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12693
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12694
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12695
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12696
+ "ADD ndotl.y, ndotl.y, one.x;" +
12697
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12698
+
12699
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12700
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12701
+
12702
+ // Pigment
12703
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12704
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12705
+ "MUL temp, temp, zero12t.w;" + // Times x
12706
+
12707
+ //"MUL temp, temp, ndotl.y;" +
12708
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
12709
+
12710
+ "MUL temp, temp, ndotl.x;" + // lambert
12711
+
12712
+ "MOV temp.w, zero12t.y;" + // reset alpha
12713
+ "MOV result.color, temp;" +
12714
+ "END";
12715
+
12716
+ String programmax =
12717
+ "!!ARBfp1.0\n" +
12718
+
1220812719 //"OPTION ARB_fragment_program_shadow;" +
1220912720 "PARAM light2cam0 = program.env[10];" +
1221012721 "PARAM light2cam1 = program.env[11];" +
....@@ -12230,7 +12741,7 @@
1223012741 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1223112742 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1223212743 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12233
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12744
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1223412745 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1223512746 "PARAM options1 = program.env[62];" + // fog rgb color
1223612747 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12319,8 +12830,7 @@
1231912830 "TEMP shininess;" +
1232012831 "\n" +
1232112832 "MOV texSamp, one;" +
12322
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12323
-
12833
+
1232412834 "MOV mapgrid.x, one2048th.x;" +
1232512835 "MOV temp, fragment.texcoord[1];" +
1232612836 /*
....@@ -12341,20 +12851,20 @@
1234112851 "MUL temp, floor, mapgrid.x;" +
1234212852 //"TEX depth0, temp, texture[1], 2D;" +
1234312853 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12344
- TextureFetch("depth0", "temp", "1") +
12854
+ ShadowTextureFetch("depth0", "temp", "1") +
1234512855 "") +
1234612856 "ADD temp.x, temp.x, mapgrid.x;" +
1234712857 //"TEX depth1, temp, texture[1], 2D;" +
1234812858 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12349
- TextureFetch("depth1", "temp", "1") +
12859
+ ShadowTextureFetch("depth1", "temp", "1") +
1235012860 "") +
1235112861 "ADD temp.y, temp.y, mapgrid.x;" +
1235212862 //"TEX depth2, temp, texture[1], 2D;" +
12353
- TextureFetch("depth2", "temp", "1") +
12863
+ ShadowTextureFetch("depth2", "temp", "1") +
1235412864 "SUB temp.x, temp.x, mapgrid.x;" +
1235512865 //"TEX depth3, temp, texture[1], 2D;" +
1235612866 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12357
- TextureFetch("depth3", "temp", "1") +
12867
+ ShadowTextureFetch("depth3", "temp", "1") +
1235812868 "") +
1235912869 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1236012870 //"MOV params, material;" +
....@@ -12476,7 +12986,7 @@
1247612986 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1247712987 // mar 2013 ??? "KIL alpha.a;" +
1247812988 "MOV alpha, texSamp.aaaa;" + // y;" +
12479
- "KIL alpha.a;" +
12989
+ "KIL alpha.a;" + // not sure with parallax mapping
1248012990 /*
1248112991 "MUL temp.xy, temp, two;" +
1248212992 "TXB bump, temp, texture[0], 2D;" +
....@@ -12562,11 +13072,6 @@
1256213072 "SUB bump0, bump0, half;" +
1256313073 "ADD bump, bump, bump0;" +
1256413074
12565
- "MOV temp.x, texSamp.a;" +
12566
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12567
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12568
- "MOV texSamp.a, temp.x;" +
12569
-
1257013075 // double-sided
1257113076 /**/
1257213077 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12576,26 +13081,73 @@
1257613081 "ADD temp.x, temp.x, one.x;" +
1257713082 "MUL normal, normal, temp.xxxx;":""
1257813083 ) +
12579
- /**/
12580
-//// Normalize("normal") +
12581
-//// "MAX normal.z, eps.x, normal.z;" +
12582
-// Normalize("normal") +
12583
- "MOV normald, normal;" +
12584
- "MOV normals, normal;" +
13084
+ /**/
13085
+
13086
+ "MOV temp, fragment.texcoord[4];" +
1258513087
1258613088 // UV base
1258713089 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1258813090 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1258913091 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12590
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12591
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12592
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
13092
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
13093
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
13094
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
13095
+ Normalize("UP") +
13096
+
1259313097 "XPD V, normal, UP;" +
1259413098 Normalize("V") +
1259513099 "XPD U, V, normal;" +
1259613100 Normalize("U") +
1259713101
13102
+ "MOV temp, fragment.texcoord[0];" +
13103
+
13104
+// "MAD normal, -temp.x, U, normal;" +
13105
+// "MAD normal, -temp.y, V, normal;" +
13106
+// Normalize("normal") +
13107
+
13108
+//// "MAX normal.z, eps.x, normal.z;" +
13109
+// Normalize("normal") +
13110
+ "MOV normald, normal;" +
13111
+ "MOV normals, normal;" +
13112
+
1259813113 // parallax mapping
13114
+
13115
+ "DP3 temp2.x, V, eye;" +
13116
+ "DP3 temp2.y, U, eye;" +
13117
+ "DP3 temp2.z, normal, eye;" +
13118
+ "RCP temp2.z, temp2.z;" +
13119
+
13120
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
13121
+ "RSQ temp2.w, temp2.w;" +
13122
+ "RCP temp2.w, temp2.w;" +
13123
+
13124
+ "SUB temp2.w, temp2.w, half;" +
13125
+ // "SGE temp.x, temp2.w, eps.x;" +
13126
+ // "MUL temp2.w, temp2.w, temp.x;" +
13127
+
13128
+ // "MOV texSamp, U;" +
13129
+
13130
+ "MUL temp2.z, temp2.z, temp2.w;" +
13131
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
13132
+
13133
+ "MUL temp2, temp2, temp2.z;" +
13134
+
13135
+ "SUB temp, temp, temp2;" +
13136
+
13137
+ "TEX temp, temp, texture[0], 2D;" +
13138
+ "POW temp.a, temp.a, params6.w;" + // punch through
13139
+
13140
+ "ADD texSamp, temp, texSamp;" +
13141
+ "MUL texSamp.xyz, half, texSamp;" +
13142
+
13143
+ "MOV alpha, texSamp.aaaa;" +
13144
+
13145
+// parallax mapping
13146
+
13147
+ "MOV temp.x, texSamp.a;" +
13148
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13149
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13150
+ "MOV texSamp.a, temp.x;" +
1259913151
1260013152 //"MOV temp, fragment.texcoord[0];" +
1260113153 //
....@@ -12725,10 +13277,10 @@
1272513277 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1272613278 "") +
1272713279
12728
- // display shadow only (bump == 0)
13280
+ // display shadow only (fakedepth == 0)
1272913281 "SUB temp.x, half.x, shadow.x;" +
1273013282 "MOV temp.y, -params5.z;" + // params6.x;" +
12731
- "SLT temp.z, temp.y, -one2048th.x;" +
13283
+ "SLT temp.z, temp.y, -c256i.x;" +
1273213284 "SUB temp.y, one.x, temp.z;" +
1273313285 "MUL temp.x, temp.x, temp.y;" +
1273413286 "KIL temp.x;" +
....@@ -13059,8 +13611,19 @@
1305913611 //once = true;
1306013612 }
1306113613
13062
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13063
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13614
+ String program = programmax;
13615
+
13616
+ if (Globals.MINSHADER)
13617
+ {
13618
+ program = programmin;
13619
+ }
13620
+
13621
+ if (Globals.DEBUG)
13622
+ {
13623
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13624
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13625
+ }
13626
+
1306413627 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1306513628
1306613629 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13107,7 +13670,8 @@
1310713670 "\n" +
1310813671 "END\n";
1310913672
13110
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13673
+ if (Globals.DEBUG)
13674
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1311113675 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1311213676
1311313677 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13152,25 +13716,26 @@
1315213716 return out;
1315313717 }
1315413718
13155
- String TextureFetch(String dest, String src, String unit)
13719
+ // Also does frustum culling
13720
+ String ShadowTextureFetch(String dest, String src, String unit)
1315613721 {
1315713722 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1315813723 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1315913724 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13725
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13726
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1316013727 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13161
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13162
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13163
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13164
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13728
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13729
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1316513730 //"SWZ buffer, temp, w,w,w,w;";
13166
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13731
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1316713732 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1316813733 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1316913734 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13170
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13735
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317113736
13172
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13173
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13737
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13738
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1317413739 }
1317513740
1317613741 String Shadow(String depth, String shadow)
....@@ -13217,7 +13782,7 @@
1321713782 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1321813783 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1321913784
13220
- // No shadow when out of frustrum
13785
+ // No shadow when out of frustum
1322113786 "SGE temp.x, " + depth + ".z, one.z;" +
1322213787 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1322313788 "";
....@@ -13364,7 +13929,7 @@
1336413929 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1336513930 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1336613931 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13367
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13932
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1336813933
1336913934 //Object3D.cVector2[] vector2buffer;
1337013935
....@@ -13531,7 +14096,7 @@
1353114096 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1353214097 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1353314098 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13534
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
14099
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1353514100 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1353614101 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1353714102 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13592,7 +14157,7 @@
1359214157 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1359314158 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1359414159 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13595
- //"MOV result.texcoord, vertex.texcoord;" +
14160
+ //"MOV result.texcoord, vertex.fogcoord;" +
1359614161 "MOV result.texcoord, temp;" +
1359714162 // border fade
1359814163 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13639,7 +14204,9 @@
1363914204
1364014205 //"ADD temp.z, temp.z, one;" +
1364114206
13642
- "MOV result.color, temp;"
14207
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14208
+
14209
+ "MOV result.color, temp;" // Normal
1364314210 : "MOV result.color, vertex.color;") +
1364414211 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1364514212 : "") +
....@@ -13774,10 +14341,13 @@
1377414341 public void mouseClicked(MouseEvent e)
1377514342 {
1377614343 System.out.println("mouseClicked: " + e);
14344
+ System.exit(0);
1377714345 }
1377814346
1377914347 public void mousePressed(MouseEvent e)
1378014348 {
14349
+ RigidBody.justclicked = true;
14350
+ System.out.println("justclicked: " + e);
1378114351 //System.out.println("mousePressed: " + e);
1378214352 clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1378314353 }
....@@ -13812,10 +14382,12 @@
1381214382 return;
1381314383 }
1381414384
13815
- boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14385
+ //boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14386
+
14387
+ boolean vr = capsLocked && !lightMode;
1381614388
1381714389 // TIMER
13818
- if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14390
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !vr) // VR
1381914391 {
1382014392 keepboxmode = BOXMODE;
1382114393 keepsupport = SUPPORT;
....@@ -13856,7 +14428,7 @@
1385614428 //}
1385714429
1385814430 SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
13859
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
14431
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, e.getModifiers(), e.getModifiersEx());
1386014432 anchorX = ax;
1386114433 anchorY = ay;
1386214434 prevX = px;
....@@ -13951,8 +14523,9 @@
1395114523 // fev 2014???
1395214524 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
1395314525 object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
13954
- pingthread.StepToTarget(true); // true);
14526
+ pingthread.StepToTarget(); // true);
1395514527 }
14528
+
1395614529 // if (!LIVE)
1395714530 super.repaint();
1395814531 }
....@@ -14015,14 +14588,15 @@
1401514588 drag = false;
1401614589 //System.out.println("Mouse DOWN");
1401714590 editObj = false;
14018
- ClickInfo info = new ClickInfo();
14019
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14020
- info.pane = this;
14021
- info.camera = renderCamera;
14022
- info.x = x;
14023
- info.y = y;
14024
- info.modifiers = modifiersex;
14025
- editObj = object.doEditClick(info, 0);
14591
+ //ClickInfo info = new ClickInfo();
14592
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14593
+ object.clickInfo.pane = this;
14594
+ object.clickInfo.camera = renderCamera;
14595
+ object.clickInfo.x = x;
14596
+ object.clickInfo.y = y;
14597
+ object.clickInfo.modifiers = modifiersex;
14598
+ editObj = object.doEditClick(//info,
14599
+ 0);
1402614600 if (!editObj)
1402714601 {
1402814602 hasMarquee = true;
....@@ -14046,8 +14620,8 @@
1404614620
1404714621 //if (drawing)
1404814622 //return;
14049
- if ((e.getModifiersEx() & CTRL) != 0
14050
- || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
14623
+ if ((e.getModifiersEx() & CTRL) != 0 ||
14624
+ (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1405114625 {
1405214626 //System.out.println("mouseDragged: " + e);
1405314627 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
....@@ -14071,9 +14645,17 @@
1407114645 return targetLookAt;
1407214646 }
1407314647
14648
+ javax.vecmath.Point3d eye = new javax.vecmath.Point3d();
14649
+ javax.vecmath.Point3d eye2 = new javax.vecmath.Point3d();
14650
+ javax.vecmath.Vector3d dir = new javax.vecmath.Vector3d();
14651
+
14652
+
1407414653 class PingThread extends Thread
1407514654 {
1407614655 boolean jump;
14656
+ boolean live;
14657
+
14658
+ boolean mute;
1407714659
1407814660 // void JumpToTarget()
1407914661 // {
....@@ -14089,6 +14671,88 @@
1408914671 // only one thread!? synchronized
1409014672 void StepToTarget(boolean jump)
1409114673 {
14674
+ RigidBody.pos.x = 0;
14675
+ RigidBody.pos.y = 0;
14676
+ RigidBody.pos.z = 0;
14677
+ if (RigidBody.justclicked)
14678
+ {
14679
+ RigidBody.pos.x = (float)manipCamera.lookAt.x;
14680
+ RigidBody.pos.y = (float)manipCamera.lookAt.y;
14681
+ RigidBody.pos.z = (float)manipCamera.lookAt.z;
14682
+ RigidBody.wind.set(RigidBody.pos);
14683
+ RigidBody.wind.x -= (float)manipCamera.location.x;
14684
+ RigidBody.wind.y -= (float)manipCamera.location.y;
14685
+ RigidBody.wind.z -= (float)manipCamera.location.z;
14686
+ RigidBody.wind.normalize();
14687
+ }
14688
+
14689
+ if (mute)
14690
+ return;
14691
+
14692
+ if (capsLocked && manipCamera.viewCode == 0)
14693
+ {
14694
+ eye.x = manipCamera.location.x;
14695
+ eye.y = manipCamera.location.y + 0.25;
14696
+ eye.z = manipCamera.location.z;
14697
+
14698
+ dir.y = -1;
14699
+
14700
+ Ray ray = new Ray(eye, dir);
14701
+
14702
+ IntersectResult res = new IntersectResult();
14703
+ res.t = Double.POSITIVE_INFINITY;
14704
+
14705
+ tmp.set(targetLookAt);
14706
+ tmp.sub(manipCamera.location);
14707
+
14708
+ double dist = tmp.length();
14709
+
14710
+ tmp.normalize();
14711
+
14712
+ eye2.x = manipCamera.location.x + tmp.x * 0.25;
14713
+ eye2.y = manipCamera.location.y + 0.25;
14714
+ eye2.z = manipCamera.location.z + tmp.z * 0.25;
14715
+
14716
+ Ray ray2 = new Ray(eye2, dir);
14717
+
14718
+ IntersectResult res2 = new IntersectResult();
14719
+ res2.t = Double.POSITIVE_INFINITY;
14720
+
14721
+ if (object.intersect(ray, res) && object.intersect(ray2, res2) && Math.abs(res.t - res2.t) < 0.25)
14722
+ {
14723
+ //tmp.set(manipCamera.location);
14724
+
14725
+ manipCamera.location.x = ray.eyePoint.x + ray.viewDirection.x * res.t;
14726
+ manipCamera.location.y = ray.eyePoint.y + ray.viewDirection.y * res.t + 0.5;
14727
+ manipCamera.location.z = ray.eyePoint.z + ray.viewDirection.z * res.t;
14728
+
14729
+ //tmp.sub(manipCamera.location);
14730
+
14731
+ targetLookAt.x = ray2.eyePoint.x + ray2.viewDirection.x * res2.t;
14732
+ targetLookAt.y = ray2.eyePoint.y + ray2.viewDirection.y * res2.t + 0.5;
14733
+ targetLookAt.z = ray2.eyePoint.z + ray2.viewDirection.z * res2.t;
14734
+
14735
+ targetLookAt.sub(manipCamera.location);
14736
+ targetLookAt.normalize();
14737
+ targetLookAt.mul(dist);
14738
+ targetLookAt.add(manipCamera.location);
14739
+
14740
+ //if (tmp.dot(tmp) > 0.000001)
14741
+ // System.out.println("INTERSECTION " + manipCamera.location);
14742
+
14743
+ manipCamera.lookAt.set(targetLookAt);
14744
+
14745
+ tmp.x = res.n.x;
14746
+ tmp.y = res.n.y;
14747
+ tmp.z = res.n.z;
14748
+ tmp.x += res2.n.x;
14749
+ tmp.y += res2.n.y;
14750
+ tmp.z += res2.n.z;
14751
+ tmp.normalize();
14752
+ manipCamera.UP.set(tmp);
14753
+ }
14754
+ }
14755
+
1409214756 tmp.set(targetLookAt);
1409314757 tmp.sub(manipCamera.lookAt); // june 2014
1409414758
....@@ -14126,7 +14790,7 @@
1412614790
1412714791 if (tmp.dot(tmp) > 1) // may 2014. far away: jump to target
1412814792 {
14129
- jump = true; // step = 1;
14793
+ // sep 2019 jump = true; // step = 1;
1413014794 }
1413114795
1413214796 if (OEILONCE && OEIL)
....@@ -14161,7 +14825,10 @@
1416114825 if (tmp.dot(tmp) < 0.00001)
1416214826 {
1416314827 zoomonce = false;
14828
+ live = false;
1416414829 }
14830
+ else
14831
+ live = true;
1416514832
1416614833 tmp.mul(step > step2 ? step : step2);
1416714834 }
....@@ -14188,7 +14855,7 @@
1418814855 {
1418914856 if (LOOKAT)
1419014857 manipCamera.lookAt.add(tmp);
14191
- if (OEIL)
14858
+ if (OEIL && !capsLocked)
1419214859 manipCamera.location.add(tmp);
1419314860
1419414861 {
....@@ -14203,7 +14870,10 @@
1420314870 lightCamera.computeTransform();
1420414871 }
1420514872 }
14206
- manipCamera.computeTransform();
14873
+ if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0)
14874
+ {
14875
+ manipCamera.computeTransform();
14876
+ }
1420714877 }
1420814878 // ?????? mouseDown = true;
1420914879 //System.out.println("---------------- ---------- Paint " + tmp.length2());
....@@ -14296,49 +14966,107 @@
1429614966 }
1429714967 }
1429814968 }
14969
+
1429914970 PingThread pingthread = new PingThread();
14300
- int delta = 5;
14301
- int speed = 5;
14971
+ int delta = 1;
14972
+ int speed = 1;
14973
+ int walk = 8;
1430214974 boolean autorepeat = false;
1430314975
14976
+ void Walk()
14977
+ {
14978
+ manipCamera.BackForth(0, walk, 1000);
14979
+
14980
+ targetLookAt.set(manipCamera.lookAt);
14981
+ }
14982
+
14983
+ void ViewAngle(float dy)
14984
+ {
14985
+ double factor = Math.exp(-dy/300.0); // (1 + dy/100);
14986
+
14987
+ if (manipCamera.shaper_fovy * factor > 1 &&
14988
+ manipCamera.shaper_fovy * factor < 150)
14989
+ {
14990
+ manipCamera.shaper_fovy *= factor;
14991
+ //System.out.println("fovy = " + shaper_fovy);
14992
+ }
14993
+ }
14994
+
1430414995 void GoDown(int mod)
1430514996 {
1430614997 MODIFIERS |= COMMAND;
14998
+ boolean isVR = (mouseMode&VR)!=0;
1430714999 /**/
1430815000 if((mod&SHIFT) == SHIFT)
14309
- manipCamera.RotatePosition(0, -speed);
14310
- else
14311
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14312
- /**/
14313
- if ((mod & SHIFT) == SHIFT)
1431415001 {
14315
- mouseMode = mouseMode; // VR??
14316
- } else
14317
- {
14318
- mouseMode |= BACKFORTH;
15002
+// if (isVR)
15003
+// manipCamera.RotateInterest(0, speed);
15004
+// else
15005
+ if (isVR)
15006
+ ViewAngle(-speed*delta);
15007
+ else
15008
+ manipCamera.Translate(0, -speed*delta, getWidth());
1431915009 }
15010
+ else
15011
+ {
15012
+ if (isVR)
15013
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
15014
+ else
15015
+ manipCamera.RotatePosition(0, -speed);
15016
+ }
15017
+
15018
+ /**/
15019
+// if ((mod & SHIFT) == SHIFT)
15020
+// {
15021
+// mouseMode = mouseMode; // VR??
15022
+// } else
15023
+// {
15024
+// mouseMode |= BACKFORTH;
15025
+// }
1432015026
15027
+ targetLookAt.set(manipCamera.lookAt);
15028
+
1432115029 //prevX = X = anchorX;
1432215030 prevY = Y = anchorY - (int) (renderCamera.Distance());
1432315031 }
1432415032
1432515033 void GoUp(int mod)
1432615034 {
15035
+ RigidBody.justclicked = true;
15036
+
1432715037 MODIFIERS |= COMMAND;
1432815038 /**/
15039
+ boolean isVR = (mouseMode&VR)!=0;
15040
+
1432915041 if((mod&SHIFT) == SHIFT)
14330
- manipCamera.RotatePosition(0, speed);
14331
- else
14332
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14333
- /**/
14334
- if ((mod & SHIFT) == SHIFT)
1433515042 {
14336
- mouseMode = mouseMode;
14337
- } else
14338
- {
14339
- mouseMode |= BACKFORTH;
15043
+// if (isVR)
15044
+// manipCamera.RotateInterest(0, -speed);
15045
+// else
15046
+ if (isVR)
15047
+ ViewAngle(speed*delta);
15048
+ else
15049
+ manipCamera.Translate(0, speed*delta, getWidth());
1434015050 }
15051
+ else
15052
+ {
15053
+ if (isVR)
15054
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
15055
+ else
15056
+ manipCamera.RotatePosition(0, speed);
15057
+ }
15058
+
15059
+ /**/
15060
+// if ((mod & SHIFT) == SHIFT)
15061
+// {
15062
+// mouseMode = mouseMode;
15063
+// } else
15064
+// {
15065
+// mouseMode |= BACKFORTH;
15066
+// }
1434115067
15068
+ targetLookAt.set(manipCamera.lookAt);
15069
+
1434215070 //prevX = X = anchorX;
1434315071 prevY = Y = anchorY + (int) (renderCamera.Distance());
1434415072 }
....@@ -14348,18 +15076,29 @@
1434815076 MODIFIERS |= COMMAND;
1434915077 /**/
1435015078 if((mod&SHIFT) == SHIFT)
14351
- manipCamera.Translate(speed*delta, 0, getWidth());
15079
+ manipCamera.Translate(speed, 0, getWidth());
1435215080 else
14353
- manipCamera.RotatePosition(speed, 0);
15081
+ {
15082
+ if ((mouseMode&VR)!=0)
15083
+ manipCamera.RotateInterest(-speed*manipCamera.shaper_fovy/90, 0);
15084
+ else
15085
+ manipCamera.RotatePosition(speed*manipCamera.shaper_fovy/90, 0);
15086
+ }
15087
+
1435415088 /**/
14355
- if ((mod & SHIFT) == SHIFT)
14356
- {
14357
- mouseMode = mouseMode;
14358
- } else
14359
- {
14360
- mouseMode |= ROTATE;
14361
- } // TRANSLATE;
15089
+// if ((mod & SHIFT) == SHIFT)
15090
+// {
15091
+// mouseMode = mouseMode;
15092
+// } else
15093
+// {
15094
+// mouseMode |= ROTATE;
15095
+// } // TRANSLATE;
1436215096
15097
+ //System.err.println("lookAt = " + manipCamera.lookAt);
15098
+ //System.err.println("location = " + manipCamera.location);
15099
+
15100
+ targetLookAt.set(manipCamera.lookAt);
15101
+
1436315102 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1436415103 prevY = Y = anchorY;
1436515104 }
....@@ -14369,18 +15108,26 @@
1436915108 MODIFIERS |= COMMAND;
1437015109 /**/
1437115110 if((mod&SHIFT) == SHIFT)
14372
- manipCamera.Translate(-speed*delta, 0, getWidth());
15111
+ manipCamera.Translate(-speed, 0, getWidth());
1437315112 else
14374
- manipCamera.RotatePosition(-speed, 0);
15113
+ {
15114
+ if ((mouseMode&VR)!=0)
15115
+ manipCamera.RotateInterest(speed*manipCamera.shaper_fovy/90, 0);
15116
+ else
15117
+ manipCamera.RotatePosition(-speed*manipCamera.shaper_fovy/90, 0);
15118
+ }
15119
+
1437515120 /**/
14376
- if ((mod & SHIFT) == SHIFT)
14377
- {
14378
- mouseMode = mouseMode;
14379
- } else
14380
- {
14381
- mouseMode |= ROTATE;
14382
- } // TRANSLATE;
15121
+// if ((mod & SHIFT) == SHIFT)
15122
+// {
15123
+// mouseMode = mouseMode;
15124
+// } else
15125
+// {
15126
+// mouseMode |= ROTATE;
15127
+// } // TRANSLATE;
1438315128
15129
+ targetLookAt.set(manipCamera.lookAt);
15130
+
1438415131 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1438515132 prevY = Y = anchorY;
1438615133 }
....@@ -14422,15 +15169,16 @@
1442215169 if (editObj)
1442315170 {
1442415171 drag = true;
14425
- ClickInfo info = new ClickInfo();
14426
- info.bounds.setBounds(0, 0,
15172
+ //ClickInfo info = new ClickInfo();
15173
+ object.clickInfo.bounds.setBounds(0, 0,
1442715174 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14428
- info.pane = this;
14429
- info.camera = renderCamera;
14430
- info.x = x;
14431
- info.y = y;
14432
- object.GetWindow().copy
14433
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
15175
+ object.clickInfo.pane = this;
15176
+ object.clickInfo.camera = renderCamera;
15177
+ object.clickInfo.x = x;
15178
+ object.clickInfo.y = y;
15179
+ object //.GetWindow().copy
15180
+ .doEditDrag(//info,
15181
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1443415182 } else
1443515183 {
1443615184 if (x < startX)
....@@ -14513,6 +15261,11 @@
1451315261 if ((mouseMode & ZOOM) != 0)
1451415262 {
1451515263 //if ((mouseMode & BACKFORTH) != 0)
15264
+ if ((modifiersex & SHIFT) == SHIFT)
15265
+ {
15266
+ ViewAngle(dy);
15267
+ }
15268
+ else
1451615269 if ((mouseMode & VR) != 0)
1451715270 manipCamera.BackForth(dx, dy, getWidth());
1451815271 else
....@@ -14579,24 +15332,30 @@
1457915332 }
1458015333 }
1458115334
15335
+// ClickInfo clickInfo = new ClickInfo();
15336
+
1458215337 public void mouseMoved(MouseEvent e)
1458315338 {
15339
+//object.editWindow.frame.
15340
+ setCursor(Cursor.getDefaultCursor());
15341
+
1458415342 //System.out.println("mouseMoved: " + e);
1458515343 if (isRenderer)
1458615344 return;
1458715345
14588
- ClickInfo ci = new ClickInfo();
14589
- ci.x = e.getX();
14590
- ci.y = e.getY();
14591
- ci.modifiers = e.getModifiersEx();
14592
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14593
- ci.pane = this;
14594
- ci.camera = renderCamera;
15346
+ // Mouse cursor feedback
15347
+ object.clickInfo.x = e.getX();
15348
+ object.clickInfo.y = e.getY();
15349
+ object.clickInfo.modifiers = e.getModifiersEx();
15350
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15351
+ object.clickInfo.pane = this;
15352
+ object.clickInfo.camera = renderCamera;
1459515353 if (!isRenderer)
1459615354 {
1459715355 //ObjEditor editWindow = object.editWindow;
1459815356 //Object3D copy = editWindow.copy;
14599
- if (object.doEditClick(ci, 0))
15357
+ if (object.doEditClick(//clickInfo,
15358
+ 0))
1460015359 {
1460115360 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1460215361 } else
....@@ -14764,8 +15523,10 @@
1476415523 mouseMode |= ZOOM;
1476515524 }
1476615525
14767
- boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
14768
- if (capsLocked) // || (modifiers & META) == META)
15526
+ //boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15527
+ boolean vr = capsLocked && !lightMode;
15528
+
15529
+ if (vr) // || (modifiers & META) == META)
1476915530 {
1477015531 mouseMode |= VR; // BACKFORTH;
1477115532 }
....@@ -14777,7 +15538,8 @@
1477715538 {
1477815539 mouseMode |= SELECT;
1477915540 }
14780
- if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15541
+ if (//(modifiersex & SHIFT) == SHIFT ||
15542
+ forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1478115543 {
1478215544 mouseMode &= ~VR;
1478315545 mouseMode |= TRANSLATE;
....@@ -14821,8 +15583,18 @@
1482115583 float SATPOW = 1; // 2; // 0.5f;
1482215584 float BRIPOW = 1; // 0.5f; // 0.5f;
1482315585
15586
+static BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
15587
+
15588
+// Create a new blank cursor.
15589
+static Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
15590
+ cursorImg, new Point(0, 0), "blank cursor");
15591
+
1482415592 public void keyPressed(int key)
1482515593 {
15594
+// Set the blank cursor to the JFrame.
15595
+//object.editWindow.frame.
15596
+ setCursor(blankCursor);
15597
+
1482615598 if (key >= '0' && key <= '5')
1482715599 clampbit = (key-'0');
1482815600
....@@ -14868,7 +15640,8 @@
1486815640 // break;
1486915641 case 'T':
1487015642 CACHETEXTURE ^= true;
14871
- textures.clear();
15643
+ texturepigment.clear();
15644
+ texturebump.clear();
1487215645 // repaint();
1487315646 break;
1487415647 case 'Y':
....@@ -14878,8 +15651,8 @@
1487815651 case 'K':
1487915652 KOMPACTTEXTURE ^= true;
1488015653 //textures.clear();
14881
- break;
14882
- case 'P': // Texture Projection macros
15654
+ // break;
15655
+ //case 'P': // Texture Projection macros
1488315656 // SAVETEXTURE ^= true;
1488415657 macromode = true;
1488515658 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -14980,8 +15753,8 @@
1498015753 RevertCamera();
1498115754 repaint();
1498215755 break;
14983
- case 'l':
14984
- //case 'L':
15756
+ //case 'l':
15757
+ case 'L':
1498515758 if (lightMode)
1498615759 {
1498715760 lightMode = false;
....@@ -15000,7 +15773,7 @@
1500015773 targetLookAt.set(manipCamera.lookAt);
1500115774 repaint();
1500215775 break;
15003
- case 'p':
15776
+ case 'P': // p':
1500415777 // c'est quoi ca au juste? spherical ^= true;
1500515778 Skinshader ^= true; programInitialized = false;
1500615779 repaint();
....@@ -15011,7 +15784,8 @@
1501115784 break;
1501215785 case 'm':
1501315786 {
15014
- PrintMemory();
15787
+ //PrintMemory();
15788
+ ToggleImageFlip();
1501515789 break;
1501615790 }
1501715791 case 'M':
....@@ -15038,27 +15812,31 @@
1503815812 repaint();
1503915813 break;
1504015814 case 'O':
15041
- Globals.drawMode = OCCLUSION; // WARNING
15042
- repaint();
15043
- break;
15815
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
15816
+ //repaint();
15817
+ //break;
1504415818 case 'o':
1504515819 OCCLUSION_CULLING ^= true;
1504615820 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1504715821 break;
15048
- case '0': envyoff ^= true; repaint(); break;
15822
+ //case '0': envyoff ^= true; repaint(); break;
1504915823 case '1':
1505015824 case '2':
1505115825 case '3':
1505215826 case '4':
1505315827 case '5':
15054
- newenvy = Character.getNumericValue(key);
15055
- repaint();
15056
- break;
1505715828 case '6':
1505815829 case '7':
1505915830 case '8':
1506015831 case '9':
15061
- BGcolor = (key - '6')/3.f;
15832
+ if (true) // envyoff)
15833
+ {
15834
+ BGcolor = (key - '1')/8.f;
15835
+ }
15836
+ else
15837
+ {
15838
+ //newenvy = Character.getNumericValue(key);
15839
+ }
1506215840 repaint();
1506315841 break;
1506415842 case '!':
....@@ -15128,7 +15906,21 @@
1512815906 // kompactbit = 6;
1512915907 // break;
1513015908 case ' ':
15909
+ capsLocked ^= true;
15910
+ repaint();
15911
+ break;
15912
+ case 'l':
1513115913 lightMode ^= true;
15914
+ if (lightMode)
15915
+ {
15916
+ keepshadow = Globals.RENDERSHADOW;
15917
+ Globals.RENDERSHADOW = false;
15918
+ }
15919
+ else
15920
+ {
15921
+ Globals.RENDERSHADOW = keepshadow;
15922
+ }
15923
+
1513215924 Globals.lighttouched = true;
1513315925 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1513415926 targetLookAt.set(manipCamera.lookAt);
....@@ -15136,6 +15928,10 @@
1513615928 break;
1513715929 //case '`' :
1513815930 case ESC:
15931
+ if (FULLSCREEN)
15932
+ object.editWindow.ToggleFullScreen();
15933
+ break;
15934
+ case 'p':
1513915935 RENDERPROGRAM += 1;
1514015936 RENDERPROGRAM %= 3;
1514115937
....@@ -15174,6 +15970,10 @@
1517415970 case ENTER:
1517515971 // object.editWindow.ScreenFit(); // Edit();
1517615972 ToggleLive();
15973
+ if (capsLocked)
15974
+ {
15975
+ Globals.WALK ^= true;
15976
+ }
1517715977 break;
1517815978 case DELETE:
1517915979 ClearSelection();
....@@ -15210,17 +16010,23 @@
1521016010 object.GetWindow().refreshContents(true);
1521116011 break;
1521216012 case '{':
15213
- manipCamera.shaper_fovy /= 1.1;
16013
+ double factor = 1.1;
16014
+ if (manipCamera.shaper_fovy / factor > 0.1)
16015
+ manipCamera.shaper_fovy /= factor;
1521416016 System.out.println("FOV = " + manipCamera.shaper_fovy);
1521516017 repaint();
1521616018 break;
1521716019 case '}':
15218
- manipCamera.shaper_fovy *= 1.1;
16020
+ factor = 1.1;
16021
+ if (manipCamera.shaper_fovy * factor < 150)
16022
+ manipCamera.shaper_fovy *= factor;
1521916023 System.out.println("FOV = " + manipCamera.shaper_fovy);
1522016024 repaint();
1522116025 break;
1522216026 case '[':
15223
- manipCamera.shaper_fovy /= 1.01;
16027
+ factor = 1.01;
16028
+ if (manipCamera.shaper_fovy / factor > 0.1)
16029
+ manipCamera.shaper_fovy /= factor;
1522416030 if (false) //manipCamera.hAspect == 0)
1522516031 {
1522616032 double x = Math.tan(manipCamera.shaper_fovy * Math.PI / 180 / 2);
....@@ -15236,7 +16042,9 @@
1523616042 break;
1523716043 case ']':
1523816044 //manipCamera.shaper_fovy += (180 - manipCamera.shaper_fovy)*0.1;
15239
- manipCamera.shaper_fovy *= 1.01;
16045
+ factor = 1.01;
16046
+ if (manipCamera.shaper_fovy * factor < 150)
16047
+ manipCamera.shaper_fovy *= factor;
1524016048 if (false) //manipCamera.hAspect == 0)
1524116049 {
1524216050 double x = Math.tan(manipCamera.shaper_fovy * Math.PI / 180 / 2);
....@@ -15274,98 +16082,113 @@
1527416082 }
1527516083 }
1527616084
16085
+ boolean keys[] = new boolean[256];
16086
+ int speedkey[] = new int[256];
16087
+ int modifiers = 0;
16088
+
1527716089 public void processKeyEvent(KeyEvent e)
1527816090 {
1527916091 switch (e.getID())
1528016092 {
1528116093 case KeyEvent.KEY_PRESSED:
15282
- if (!autorepeat)
15283
- {
15284
- //System.out.println("processKeyEvent: " + KeyEvent.getKeyText(e.getKeyCode()));
15285
- keyPressed(e.getKeyChar(), e.getModifiersEx());
15286
- }
15287
- if (manipCamera == lightCamera)
15288
- {
15289
- switch (e.getKeyCode())
15290
- {
15291
- case DOWN_ARROW:
15292
- lightCamera.DECAL /= 2;
15293
- repaint();
15294
- break;
15295
- case UP_ARROW:
15296
- lightCamera.DECAL *= 2;
15297
- repaint();
15298
- break;
15299
- case LEFT_ARROW:
15300
- lightCamera.SCALE /= 2;
15301
- repaint();
15302
- break;
15303
- case RIGHT_ARROW:
15304
- lightCamera.SCALE *= 2;
15305
- repaint();
15306
- break;
15307
- default:
15308
- break;
15309
- }
15310
-
15311
- System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE);
15312
- } else
15313
- {
15314
- if (true) // !autorepeat)
15315
- {
15316
- boolean reset = true;
15317
-
15318
- switch (e.getKeyCode())
15319
- {
15320
- case DOWN_ARROW:
15321
- GoDown(e.getModifiersEx());
15322
- repaint();
15323
- break;
15324
- case UP_ARROW:
15325
- GoUp(e.getModifiersEx());
15326
- repaint();
15327
- break;
15328
- case LEFT_ARROW:
15329
- GoLeft(e.getModifiersEx());
15330
- repaint();
15331
- break;
15332
- case RIGHT_ARROW:
15333
- GoRight(e.getModifiersEx());
15334
- repaint();
15335
- break;
15336
- default:
15337
- reset = false;
15338
- break;
15339
- }
15340
-
15341
- if (reset)
15342
- {
15343
- autorepeat = true;
15344
-
15345
- targetLookAt.set(manipCamera.lookAt);
15346
- }
15347
- }
15348
- }
16094
+ keys[e.getKeyCode()] = true;
16095
+ modifiers = e.getModifiersEx();
16096
+ keyPressed(e.getKeyChar(), modifiers);
16097
+ //Globals.theRenderer.keyPressed(e.getKeyChar());
16098
+ repaint();
1534916099 break;
15350
- case KeyEvent.KEY_TYPED:
15351
- break;
16100
+// if (!autorepeat)
16101
+// {
16102
+// //System.out.println("processKeyEvent: " + KeyEvent.getKeyText(e.getKeyCode()));
16103
+// keyPressed(e.getKeyChar(), e.getModifiersEx());
16104
+// }
16105
+// if (manipCamera == lightCamera)
16106
+// {
16107
+// switch (e.getKeyCode())
16108
+// {
16109
+// case DOWN_ARROW:
16110
+// lightCamera.DECAL /= 2;
16111
+// repaint();
16112
+// break;
16113
+// case UP_ARROW:
16114
+// lightCamera.DECAL *= 2;
16115
+// repaint();
16116
+// break;
16117
+// case LEFT_ARROW:
16118
+// lightCamera.SCALE /= 2;
16119
+// repaint();
16120
+// break;
16121
+// case RIGHT_ARROW:
16122
+// lightCamera.SCALE *= 2;
16123
+// repaint();
16124
+// break;
16125
+// default:
16126
+// break;
16127
+// }
16128
+//
16129
+// System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE);
16130
+// } else
16131
+// {
16132
+// if (true) // !autorepeat)
16133
+// {
16134
+// boolean reset = true;
16135
+//
16136
+// switch (e.getKeyCode())
16137
+// {
16138
+// case DOWN_ARROW:
16139
+// GoDown(e.getModifiersEx());
16140
+// repaint();
16141
+// break;
16142
+// case UP_ARROW:
16143
+// GoUp(e.getModifiersEx());
16144
+// repaint();
16145
+// break;
16146
+// case LEFT_ARROW:
16147
+// GoLeft(e.getModifiersEx());
16148
+// repaint();
16149
+// break;
16150
+// case RIGHT_ARROW:
16151
+// GoRight(e.getModifiersEx());
16152
+// repaint();
16153
+// break;
16154
+// default:
16155
+// reset = false;
16156
+// break;
16157
+// }
16158
+//
16159
+// if (reset)
16160
+// {
16161
+// autorepeat = true;
16162
+//
16163
+// targetLookAt.set(manipCamera.lookAt);
16164
+// }
16165
+// }
16166
+// }
16167
+// break;
16168
+// case KeyEvent.KEY_TYPED:
16169
+// break;
1535216170 case KeyEvent.KEY_RELEASED:
15353
- {
15354
- switch (e.getKeyCode())
15355
- {
15356
- case DOWN_ARROW:
15357
- case UP_ARROW:
15358
- case LEFT_ARROW:
15359
- case RIGHT_ARROW:
15360
- MODIFIERS &= ~COMMAND;
15361
- autorepeat = false;
15362
- break;
15363
- default:
15364
- break;
15365
- }
16171
+ keys[e.getKeyCode()] = false;
16172
+ modifiers = e.getModifiersEx();
1536616173 keyReleased(e.getKeyChar(), e.getModifiersEx());
16174
+ repaint();
1536716175 break;
15368
- }
16176
+// {
16177
+// switch (e.getKeyCode())
16178
+// {
16179
+// case DOWN_ARROW:
16180
+// case UP_ARROW:
16181
+// case LEFT_ARROW:
16182
+// case RIGHT_ARROW:
16183
+// MODIFIERS &= ~COMMAND;
16184
+// autorepeat = false;
16185
+// break;
16186
+// default:
16187
+// break;
16188
+// }
16189
+// keyReleased(e.getKeyChar(), e.getModifiersEx());
16190
+// break;
16191
+// }
1536916192 default:
1537016193 break;
1537116194 }
....@@ -15621,8 +16444,6 @@
1562116444
1562216445 int width = getBounds().width;
1562316446 int height = getBounds().height;
15624
- ClickInfo info = new ClickInfo();
15625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1562616447 //Image img = CreateImage(width, height);
1562716448 //System.out.println("width = " + width + "; height = " + height + "\n");
1562816449
....@@ -15699,31 +16520,37 @@
1569916520 }
1570016521 if (object != null && !hasMarquee)
1570116522 {
16523
+ if (object.clickInfo == null)
16524
+ object.clickInfo = new ClickInfo();
16525
+ ClickInfo info = object.clickInfo;
16526
+ //ClickInfo info = new ClickInfo();
16527
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16528
+
1570216529 if (isRenderer)
1570316530 {
15704
- info.flags++;
16531
+ object.clickInfo.flags++;
1570516532 double frameAspect = (double) width / (double) height;
1570616533 if (frameAspect > renderCamera.aspect)
1570716534 {
1570816535 int desired = (int) ((double) height * renderCamera.aspect);
15709
- info.bounds.width -= width - desired;
15710
- info.bounds.x += (width - desired) / 2;
16536
+ object.clickInfo.bounds.width -= width - desired;
16537
+ object.clickInfo.bounds.x += (width - desired) / 2;
1571116538 } else
1571216539 {
1571316540 int desired = (int) ((double) width / renderCamera.aspect);
15714
- info.bounds.height -= height - desired;
15715
- info.bounds.y += (height - desired) / 2;
16541
+ object.clickInfo.bounds.height -= height - desired;
16542
+ object.clickInfo.bounds.y += (height - desired) / 2;
1571616543 }
1571716544 }
1571816545
15719
- info.g = gr;
15720
- info.camera = renderCamera;
16546
+ object.clickInfo.g = gr;
16547
+ object.clickInfo.camera = renderCamera;
1572116548 /*
1572216549 // Memory intensive (brep.verticescopy)
1572316550 if (!(object instanceof Composite))
1572416551 object.draw(info, 0, false); // SLOW :
1572516552 */
15726
- if (!isRenderer)
16553
+ if (!isRenderer) // && drag)
1572716554 {
1572816555 Grafreed.Assert(object != null);
1572916556 Grafreed.Assert(object.selection != null);
....@@ -15731,9 +16558,9 @@
1573116558 {
1573216559 int hitSomething = object.selection.get(0).hitSomething;
1573316560
15734
- info.DX = 0;
15735
- info.DY = 0;
15736
- info.W = 1;
16561
+ object.clickInfo.DX = 0;
16562
+ object.clickInfo.DY = 0;
16563
+ object.clickInfo.W = 1;
1573716564 if (hitSomething == Object3D.hitCenter)
1573816565 {
1573916566 info.DX = X;
....@@ -15745,13 +16572,14 @@
1574516572 info.DY -= info.bounds.height/2;
1574616573 }
1574716574
15748
- object.drawEditHandles(info, 0);
16575
+ object.drawEditHandles(//info,
16576
+ 0);
1574916577
1575016578 if (drag && (X != 0 || Y != 0))
1575116579 {
1575216580 switch (hitSomething)
1575316581 {
15754
- case Object3D.hitCenter: gr.setColor(Color.pink);
16582
+ case Object3D.hitCenter: gr.setColor(Color.white);
1575516583 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1575616584 break;
1575716585 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -15777,7 +16605,7 @@
1577716605 if (hasMarquee)
1577816606 {
1577916607 gr.setXORMode(Color.white);
15780
- gr.setColor(Color.red);
16608
+ gr.setColor(Color.white);
1578116609 if (!firstime)
1578216610 {
1578316611 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -15936,7 +16764,8 @@
1593616764
1593716765 public boolean mouseDrag(Event evt, int x, int y)
1593816766 {
15939
- //System.out.println("mouseDrag: " + evt);
16767
+ System.out.println("mouseDrag: " + evt);
16768
+ System.exit(0);
1594016769 /*
1594116770 drag = true;
1594216771 //System.out.println("Mouse DRAG");
....@@ -16055,6 +16884,7 @@
1605516884 public boolean mouseUp(Event evt, int x, int y)
1605616885 {
1605716886 System.out.println("mouseUp: " + evt);
16887
+ System.exit(0);
1605816888 /*
1605916889 locked = false;
1606016890 if (isRenderer)
....@@ -16244,6 +17074,8 @@
1624417074 private /*static*/ boolean firstime;
1624517075 private /*static*/ cVector newView = new cVector();
1624617076 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
17077
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
17078
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1624717079 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1624817080 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1624917081 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16256,29 +17088,67 @@
1625617088 {
1625717089 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1625817090
17091
+ int usedsuf = 0;
17092
+
1625917093 for (int i = 0; i < suffixes.length; i++)
1626017094 {
16261
- String resourceName = basename + suffixes[i] + "." + suffix;
16262
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16263
- mipmapped,
16264
- FileUtil.getFileSuffix(resourceName));
16265
- if (data == null)
17095
+ String[] suffixe = suffixes;
17096
+ String[] fallback = suffixes2;
17097
+ String[] fallfallback = suffixes3;
17098
+
17099
+ for (int c=usedsuf; --c>=0;)
1626617100 {
16267
- throw new IOException("Unable to load texture " + resourceName);
17101
+// String[] temp = suffixe;
17102
+// suffixe = fallback;
17103
+// fallback = fallfallback;
17104
+// fallfallback = temp;
1626817105 }
17106
+
17107
+ String resourceName = basename + suffixe[i] + "." + suffix;
17108
+ TextureData data;
17109
+
17110
+ try
17111
+ {
17112
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
17113
+ mipmapped,
17114
+ FileUtil.getFileSuffix(resourceName));
17115
+ }
17116
+ catch (Exception e)
17117
+ {
17118
+ try
17119
+ {
17120
+ resourceName = basename + fallback[i] + "." + suffix;
17121
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
17122
+ mipmapped,
17123
+ FileUtil.getFileSuffix(resourceName));
17124
+ }
17125
+ catch (Exception e2)
17126
+ {
17127
+ resourceName = basename + fallfallback[i] + "." + suffix;
17128
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
17129
+ mipmapped,
17130
+ FileUtil.getFileSuffix(resourceName));
17131
+ }
17132
+ }
17133
+
1626917134 //System.out.println("Target = " + targets[i]);
1627017135 cubemap.updateImage(data, targets[i]);
1627117136 }
1627217137
1627317138 return cubemap;
1627417139 }
17140
+
1627517141 int bigsphere = -1;
1627617142
1627717143 float BGcolor = 0.5f;
1627817144
16279
- private void DrawSkyBox(GL gl)
17145
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
17146
+
17147
+ private void DrawSkyBox(GL gl, float ratio)
1628017148 {
16281
- if (envyoff || cubemap == null)
17149
+ if (//envyoff ||
17150
+ WIREFRAME ||
17151
+ cubemap == null)
1628217152 {
1628317153 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1628417154 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16293,7 +17163,17 @@
1629317163 // Compensates for ExaminerViewer's modification of modelview matrix
1629417164 gl.glMatrixMode(GL.GL_MODELVIEW);
1629517165 gl.glLoadIdentity();
17166
+ gl.glScalef(1,ratio,1);
1629617167
17168
+// colorV[0] = 2;
17169
+// colorV[1] = 2;
17170
+// colorV[2] = 2;
17171
+// colorV[3] = 1;
17172
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
17173
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
17174
+//
17175
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
17176
+
1629717177 //gl.glActiveTexture(GL.GL_TEXTURE1);
1629817178 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1629917179
....@@ -16325,6 +17205,7 @@
1632517205 {
1632617206 gl.glScalef(1.0f, -1.0f, 1.0f);
1632717207 }
17208
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1632817209 gl.glMultMatrixd(viewrot_1, 0);
1632917210 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1633017211 //viewer.updateInverseRotation(gl);
....@@ -16365,7 +17246,8 @@
1636517246 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1636617247
1636717248 cubemap.disable();
16368
- ////cubemap.unbind();
17249
+ //cubemap.dispose();
17250
+
1636917251 if (CULLFACE)
1637017252 {
1637117253 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16421,7 +17303,7 @@
1642117303 gl.glScalef(1.0f, -1.0f, 1.0f);
1642217304 }
1642317305
16424
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
17306
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1642517307
1642617308 float step = 2; // 0.1666f; //0.25f;
1642717309 float stepv = 2; // step * 1652 / 998;
....@@ -16583,7 +17465,7 @@
1658317465 //new Exception().printStackTrace();
1658417466 System.out.println("select buffer init");
1658517467 // Use debug pipeline
16586
- drawable.setGL(new DebugGL(drawable.getGL()));
17468
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1658717469
1658817470 GL gl = drawable.getGL();
1658917471
....@@ -16710,7 +17592,7 @@
1671017592
1671117593 float depth = depths[y * TEX_SIZE + x];
1671217594
16713
- if (pointselection && mouseMode == SELECT && depth != 0 && depth != 1)
17595
+ if (pointselection && (mouseMode & SELECT) == SELECT && depth != 0 && depth != 1)
1671417596 {
1671517597 pointselection = false;
1671617598
....@@ -16901,6 +17783,7 @@
1690117783
1690217784 public void init(GLAutoDrawable drawable)
1690317785 {
17786
+ if (Globals.DEBUG)
1690417787 System.out.println("shadow buffer init");
1690517788
1690617789 GL gl = drawable.getGL();
....@@ -17129,10 +18012,14 @@
1712918012 gl.glFlush();
1713018013
1713118014 /**/
17132
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
18015
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1713318016
17134
- float[] pixels = occlusionsizebuffer.array();
18017
+ float[] depths = occlusiondepthbuffer.array();
1713518018
18019
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
18020
+
18021
+ int[] pixels = selectsizebuffer.array();
18022
+
1713618023 double r = 0, g = 0, b = 0;
1713718024
1713818025 double count = 0;
....@@ -17143,7 +18030,7 @@
1714318030
1714418031 double FACTOR = 1;
1714518032
17146
- for (int i = 0; i < pixels.length; i++)
18033
+ for (int i = 0; i < depths.length; i++)
1714718034 {
1714818035 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1714918036 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17226,7 +18113,7 @@
1722618113
1722718114 double scale = ray.z; // 1; // cos
1722818115
17229
- float depth = pixels[newindex];
18116
+ float depth = depths[newindex];
1723018117
1723118118 /*
1723218119 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17369,6 +18256,11 @@
1736918256 static boolean DEBUG_SELECTION = false;
1737018257 boolean OCCLUSION_CULLING = false; //true;
1737118258 public boolean lightMode = false;
18259
+
18260
+ private boolean keepshadow;
18261
+
18262
+ static public boolean capsLocked = false; // VR
18263
+
1737218264 static public int indexcount = 0;
1737318265 /*static*/ cColor vertexOcclusion = new cColor();
1737418266 //private int selection_view = -1;
....@@ -17423,11 +18315,14 @@
1742318315 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1742418316 static IntBuffer bigAAbuffer;
1742518317 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17426
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
18318
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1742718319 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1742818320 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1742918321 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17430
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
18322
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
18323
+
18324
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
18325
+
1743118326 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1743218327 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1743318328 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();