Normand Briere
2019-08-22 6a145f6c81dfcbe0653eda27d042efb48daa7512
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,10 +33,14 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
34
-class CameraPane extends GLCanvas implements Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
38
+class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
36
- static boolean DEBUG = false;
40
+ static cMaterial[] materialstack = new cMaterial[65536];
41
+ static boolean[] selectedstack = new boolean[65536];
42
+ static int materialdepth = 0;
43
+
3744 static boolean FRUSTUM = false; // still bogus true; // frustum culling
3845
3946 // camera change fix
....@@ -42,25 +49,40 @@
4249
4350 static int STEP = 1;
4451
45
- static boolean ONESTEP = false; // do LIVE once
46
-
47
- /**
48
- * @return the LIVE
49
- */
50
- public static boolean isLIVE()
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
5153 {
52
- return LIVE || ONESTEP;
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
5383 }
5484
55
- /**
56
- * @param aLIVE the LIVE to set
57
- */
58
- public static void setLIVE(boolean aLIVE)
59
- {
60
- LIVE = aLIVE;
61
- }
62
-
63
- /*static*/ boolean CULLFACE = false; // true;
85
+ /*static*/ private boolean CULLFACE = false; // true;
6486 /*static*/ boolean NEAREST = false; // true;
6587 /*static*/ boolean WIREFRAME = false; // true;
6688
....@@ -70,14 +92,12 @@
7092 static int CURRENTANTIALIAS = 0; // 1;
7193 /*static*/ boolean RENDERSHADOW = true;
7294 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
73
- static boolean ANIMATION = false;
74
- static String filename;
7595
7696 boolean DISPLAYTEXT = false;
7797 //boolean REDUCETEXTURE = true;
7898 boolean CACHETEXTURE = true;
7999 boolean CLEANCACHE = false; // true;
80
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
81101 boolean COMPRESSTEXTURE = false;
82102 boolean KOMPACTTEXTURE = false; // true;
83103 boolean RESIZETEXTURE = false;
....@@ -90,17 +110,19 @@
90110 //private Mat4f spotlightTransform = new Mat4f();
91111 //private Mat4f spotlightInverseTransform = new Mat4f();
92112 static GLContext glcontext = null;
93
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
94118 boolean reverseUP = false;
95119 static boolean frozen = false;
96120 boolean enablebackspace = false; // patch for back buffer refresh
97121
98122 static boolean textureon = true;
99123 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101124 static boolean FULLSCREEN = false;
102125 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104126 static boolean INERTIA = true;
105127 static boolean FAST = false;
106128 static boolean SLOWPOSE = false;
....@@ -108,6 +130,8 @@
108130
109131 static int tickcount = 0; // slow pose issue
110132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
111135 static boolean BOXMODE = false;
112136 static boolean IMAGEFLIP = false;
113137 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +146,7 @@
122146 static boolean OEIL = true;
123147 static boolean OEILONCE = false; // do oeilon then oeiloff
124148 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
126150 static boolean HANDLES = false; // selection doesn't work!!
127151 static boolean PAINTMODE = false;
128152
....@@ -144,7 +168,7 @@
144168
145169
146170 // OPTIONS
147
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
148172 boolean cameraLight = false;
149173 boolean UVdebug = false;
150174 boolean Udebug = false;
....@@ -153,7 +177,7 @@
153177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
154178 boolean anisotropy = true;
155179 boolean softshadow = true; // slower but better false;
156
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
157181
158182 boolean macromode = false;
159183
....@@ -165,12 +189,55 @@
165189 defaultcaps.setAccumBlueBits(16);
166190 defaultcaps.setAccumAlphaBits(16);
167191 }
168
- static CameraPane theRenderer;
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
169194
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
207
+
170208 void SetAsGLRenderer(boolean b)
171209 {
172210 isRenderer = b;
173
- theRenderer = this;
211
+ Globals.theRenderer = this;
212
+ }
213
+
214
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
215
+ {
216
+ super(defaultcaps, null, withcontext?glcontext:null, null);
217
+
218
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
219
+ glcontext = getContext();
220
+
221
+ cameras = new Camera[2];
222
+ targetLookAts = new cVector[2];
223
+
224
+ SetCamera(cam);
225
+
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
228
+
229
+ object = o;
230
+
231
+ setBackground(Color.white);
232
+
233
+ addKeyListener(this);
234
+ addMouseListener(this);
235
+ addMouseMotionListener(this);
236
+ addMouseWheelListener(this);
237
+ //System.out.println("addGLEventListener: " + this);
238
+ addGLEventListener(this);
239
+
240
+// pingthread.start(); // may 2013
174241 }
175242
176243 static boolean AntialiasingEnabled()
....@@ -178,12 +245,53 @@
178245 return CURRENTANTIALIAS > 0;
179246 }
180247
181
- void ClearDepth()
248
+ /// INTERFACE
249
+
250
+ public javax.media.opengl.GL GetGL0()
251
+ {
252
+ return null;
253
+ }
254
+
255
+ public int GenList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ return gl.glGenLists(1);
259
+ }
260
+
261
+ public void NewList(int id)
262
+ {
263
+ javax.media.opengl.GL gl = GetGL();
264
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
265
+ }
266
+
267
+ public void CallList(int id)
268
+ {
269
+ javax.media.opengl.GL gl = GetGL();
270
+ gl.glCallList(id);
271
+ }
272
+
273
+ public void EndList()
274
+ {
275
+ javax.media.opengl.GL gl = GetGL();
276
+ gl.glEndList();
277
+ }
278
+
279
+ public boolean IsBoxMode()
280
+ {
281
+ return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
287
+ }
288
+
289
+ public void ClearDepth()
182290 {
183291 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184292 }
185293
186
- void DepthTest(boolean depthtest)
294
+ public void DepthTest(boolean depthtest)
187295 {
188296 if (depthtest)
189297 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +299,7 @@
191299 GetGL().glDepthFunc(GL.GL_ALWAYS);
192300 }
193301
194
- void DepthWrite(boolean depthwrite)
302
+ public void DepthWrite(boolean depthwrite)
195303 {
196304 if (depthwrite)
197305 GetGL().glDepthMask(true);
....@@ -199,12 +307,1617 @@
199307 GetGL().glDepthMask(false);
200308 }
201309
202
- void BackFaceCull(boolean bfc)
310
+ public void BackFaceCull(boolean bfc)
203311 {
204312 if (bfc)
205313 GetGL().glEnable(GetGL().GL_CULL_FACE);
206314 else
207315 GetGL().glDisable(GetGL().GL_CULL_FACE);
316
+ }
317
+
318
+ public boolean BackFaceCullMode()
319
+ {
320
+ return this.CULLFACE;
321
+ }
322
+
323
+ public boolean IsAmbientOcclusionOn()
324
+ {
325
+ return this.ambientOcclusion;
326
+ }
327
+
328
+ public boolean IsDebugSelection()
329
+ {
330
+ return DEBUG_SELECTION;
331
+ }
332
+
333
+ public boolean IsFrozen()
334
+ {
335
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
336
+
337
+ return !selectmode && cameracount == 0; // != 0;
338
+ }
339
+
340
+ // Currently in Globals
341
+ public int DrawMode()
342
+ {
343
+ return Globals.DrawMode();
344
+ }
345
+
346
+ public Camera EyeCamera()
347
+ {
348
+ return eyeCamera;
349
+ }
350
+
351
+ public Camera LightCamera()
352
+ {
353
+ return lightCamera;
354
+ }
355
+
356
+ public Camera ManipCamera()
357
+ {
358
+ return manipCamera;
359
+ }
360
+
361
+ public Camera RenderCamera()
362
+ {
363
+ return renderCamera;
364
+ }
365
+
366
+ public Camera[] Cameras()
367
+ {
368
+ return cameras;
369
+ }
370
+
371
+ public void PushMaterial(Object3D obj, boolean selected)
372
+ {
373
+ CameraPane display = this;
374
+ javax.media.opengl.GL gl = display.GetGL();
375
+ cMaterial material = obj.material;
376
+
377
+ if (material != null)
378
+ {
379
+ materialstack[materialdepth] = material;
380
+ selectedstack[materialdepth] = selected;
381
+ cStatic.objectstack[materialdepth++] = obj;
382
+ //System.out.println("material " + material);
383
+ //Applet3D.tracein(this, selected);
384
+ //display.vector2buffer = obj.projectedVertices;
385
+ if (obj instanceof Camera)
386
+ {
387
+ display.options1[0] = material.shift;
388
+ //System.out.println("shift " + material.shift);
389
+ display.options1[1] = material.lightarea;
390
+ display.options1[2] = material.shadowbias;
391
+ display.options1[3] = material.aniso;
392
+ display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
398
+ display.options2[0] = material.opacity;
399
+ display.options2[1] = material.diffuse;
400
+ display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
404
+
405
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
409
+ display.options4[0] = material.cameralight/0.2f;
410
+ display.options4[1] = material.subsurface;
411
+ display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
415
+
416
+ // if (display.CURRENTANTIALIAS > 0)
417
+ // display.options3[3] /= 4;
418
+
419
+ /*
420
+ System.out.println("Focus = " + display.options1[0]);
421
+ System.out.println("Aperture = " + display.options1[1]);
422
+ System.out.println("ShadowBlur = " + display.options1[2]);
423
+ System.out.println("Antialiasing = " + display.options1[3]);
424
+ System.out.println("Fog = " + display.options2[0]);
425
+ System.out.println("Intensity = " + display.options2[1]);
426
+ System.out.println("Elevation = " + display.options2[2]);
427
+ /**/
428
+ } else
429
+ {
430
+ DrawMaterial(material, selected, obj.projectedVertices);
431
+ }
432
+ } else
433
+ {
434
+ if (selected && CameraPane.flash)
435
+ {
436
+ display.modelParams4[1] = 100;
437
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
438
+ }
439
+ }
440
+ }
441
+
442
+ public void PushMaterial2(Object3D obj, boolean selected)
443
+ {
444
+ CameraPane display = this;
445
+ cMaterial material = obj.material;
446
+
447
+ if (material != null)
448
+ {
449
+ materialstack[materialdepth] = material;
450
+ selectedstack[materialdepth] = selected;
451
+ cStatic.objectstack[materialdepth++] = obj;
452
+ //System.out.println("material " + material);
453
+ //Applet3D.tracein("selected ", selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
456
+ }
457
+ }
458
+
459
+ public void PopMaterial(Object3D obj, boolean selected)
460
+ {
461
+ CameraPane display = this;
462
+ javax.media.opengl.GL gl = display.GetGL();
463
+ cMaterial material = obj.material;
464
+
465
+ //if (parent != null && parent.GetMaterial() != null)
466
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
467
+ if (material != null)
468
+ {
469
+ materialdepth -= 1;
470
+ if (materialdepth > 0)
471
+ {
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
474
+ }
475
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
476
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
477
+ {
478
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
479
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
480
+ }
481
+ }
482
+
483
+ public void PopMaterial2(Object3D obj)
484
+ {
485
+ CameraPane display = this;
486
+ cMaterial material = obj.material;
487
+
488
+ if (material != null)
489
+ {
490
+ materialdepth -= 1;
491
+ if (materialdepth > 0)
492
+ {
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
495
+ }
496
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
497
+ //else
498
+ //material.Draw(display, false);
499
+ }
500
+ }
501
+
502
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
503
+ {
504
+ CameraPane display = this;
505
+
506
+ if (pv.y == -10000 ||
507
+ qv.y == -10000 ||
508
+ rv.y == -10000)
509
+ return;
510
+
511
+// float b = f.nbiterations & 1;
512
+// float g = (f.nbiterations>>1) & 1;
513
+// float r = (f.nbiterations>>2) & 1;
514
+//
515
+// //if (f.weight == 10000)
516
+// //{
517
+// // r = 1; g = b = 0;
518
+// //}
519
+// //else
520
+// //{
521
+// // assert(f.weight < 10000);
522
+// r = g = b = (float)bRep.FaceWeight(f)*100;
523
+// if (r<0)
524
+// assert(r>=0);
525
+// //}
526
+
527
+ javax.media.opengl.GL gl = display.GetGL();
528
+
529
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
530
+
531
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
532
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
533
+ {
534
+ //gl.glBegin(gl.GL_TRIANGLES);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
538
+ if (!hasnorm)
539
+ {
540
+ // System.out.println("Mesh normal");
541
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
542
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
543
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
544
+ LA.vecNormalize(obj.v2);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
547
+ }
548
+
549
+ // P
550
+ float x = (float)pv.x;
551
+ float y = (float)pv.y;
552
+ float z = (float)pv.z;
553
+
554
+ if (hasnorm)
555
+ {
556
+// if (!pv.norm.normalized())
557
+// assert(pv.norm.normalized());
558
+
559
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
560
+ float nx = (float)pv.norm.x;
561
+ float ny = (float)pv.norm.y;
562
+ float nz = (float)pv.norm.z;
563
+
564
+ x += nx * obj.NORMALPUSH;
565
+ y += ny * obj.NORMALPUSH;
566
+ z += nz * obj.NORMALPUSH;
567
+
568
+ SetGLNormal(gl, nx, ny, nz);
569
+ }
570
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
571
+ SetColor(obj, pv);
572
+ //gl.glColor4f(r, g, b, 1);
573
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
574
+ if (obj.flipV)
575
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
576
+ else
577
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
578
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
579
+
580
+ gl.glVertex3f(x, y, z);
581
+
582
+ // Q
583
+ x = (float)qv.x;
584
+ y = (float)qv.y;
585
+ z = (float)qv.z;
586
+
587
+// Print(pv);
588
+ if (hasnorm)
589
+ {
590
+// assert(qv.norm.normalized());
591
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
592
+ float nx = (float)qv.norm.x;
593
+ float ny = (float)qv.norm.y;
594
+ float nz = (float)qv.norm.z;
595
+
596
+ x += nx * obj.NORMALPUSH;
597
+ y += ny * obj.NORMALPUSH;
598
+ z += nz * obj.NORMALPUSH;
599
+
600
+ SetGLNormal(gl, nx, ny, nz);
601
+ }
602
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
603
+ // boolean locked = false;
604
+ // float eps = 0.1f;
605
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
606
+
607
+ // int dot = 0; //*/ (int)f.dot;
608
+
609
+ // if ((dot&1) == 0)
610
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
611
+
612
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
613
+ if (obj.flipV)
614
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
615
+ else
616
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
617
+ // else
618
+ // {
619
+ // locked = true;
620
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
621
+ // }
622
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
623
+ SetColor(obj, qv);
624
+
625
+ gl.glVertex3f(x, y, z);
626
+ //gl.glColor4f(r, g, b, 1);
627
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
628
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
629
+// Print(qv);
630
+
631
+ // R
632
+ x = (float)rv.x;
633
+ y = (float)rv.y;
634
+ z = (float)rv.z;
635
+
636
+ if (hasnorm)
637
+ {
638
+// assert(rv.norm.normalized());
639
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
640
+ float nx = (float)rv.norm.x;
641
+ float ny = (float)rv.norm.y;
642
+ float nz = (float)rv.norm.z;
643
+
644
+ x += nx * obj.NORMALPUSH;
645
+ y += ny * obj.NORMALPUSH;
646
+ z += nz * obj.NORMALPUSH;
647
+
648
+ SetGLNormal(gl, nx, ny, nz);
649
+ }
650
+
651
+ // if ((dot&4) == 0)
652
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
653
+
654
+ // if (wrap || !locked && (dot&8) != 0)
655
+ if (obj.flipV)
656
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
657
+ else
658
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
659
+ // else
660
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
661
+
662
+ // f.dot = dot;
663
+
664
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
665
+ SetColor(obj, rv);
666
+ //gl.glColor4f(r, g, b, 1);
667
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
668
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
669
+ gl.glVertex3f(x, y, z);
670
+// Print(rv);
671
+ //gl.glEnd();
672
+ }
673
+ else
674
+ {
675
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
676
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
677
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
678
+
679
+ }
680
+
681
+ if (false) // (attributes & WIREFRAME) != 0)
682
+ {
683
+ gl.glDisable(gl.GL_LIGHTING);
684
+
685
+ gl.glBegin(gl.GL_LINE_LOOP);
686
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
687
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
688
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
689
+ gl.glEnd();
690
+
691
+ gl.glEnable(gl.GL_LIGHTING);
692
+ }
693
+ }
694
+
695
+ /**
696
+ * <code>draw</code> renders a <code>TriMesh</code> object including
697
+ * it's normals, colors, textures and vertices.
698
+ *
699
+ * @see Renderer#draw(TriMesh)
700
+ * @param tris
701
+ * the mesh to render.
702
+ */
703
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
704
+ {
705
+ CameraPane display = this;
706
+
707
+ float r = display.modelParams0[0];
708
+ float g = display.modelParams0[1];
709
+ float b = display.modelParams0[2];
710
+ float opacity = display.modelParams5[1];
711
+
712
+ //final GL gl = GLU.getCurrentGL();
713
+ GL gl = display.GetGL(); // getGL();
714
+
715
+ FloatBuffer vertBuf = geo.vertBuf;
716
+
717
+ int v = vertBuf.capacity();
718
+
719
+ int count = 0;
720
+
721
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
722
+ gl.glEnable(gl.GL_CULL_FACE);
723
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
724
+ for (int i=0; i<v/3; i++)
725
+ {
726
+ int index3 = i*3;
727
+
728
+ if (geo.sizeBuf.get(index3+1) == 0)
729
+ continue;
730
+
731
+ count++;
732
+
733
+ int index4 = i*4;
734
+
735
+ float tx = vertBuf.get(index3);
736
+ float ty = vertBuf.get(index3+1);
737
+ float tz = vertBuf.get(index3+2);
738
+
739
+ // if (tx == 0 && ty == 0 && tz == 0)
740
+ // continue;
741
+
742
+ gl.glMatrixMode(gl.GL_TEXTURE);
743
+ gl.glPushMatrix();
744
+
745
+ float[] texmat = geo.texmat;
746
+ texmat[12] = texmat[13] = texmat[14] = i;
747
+
748
+ gl.glMultMatrixf(texmat, 0);
749
+
750
+ gl.glMatrixMode(gl.GL_MODELVIEW);
751
+ gl.glPushMatrix();
752
+
753
+ gl.glTranslatef(tx,ty,tz);
754
+
755
+ if (rotate)
756
+ gl.glRotatef(i, 0, 1, 0);
757
+
758
+ float size = geo.sizeBuf.get(index3) / 100;
759
+ gl.glScalef(size,size,size);
760
+
761
+ float cr = geo.colorBuf.get(index4);
762
+ float cg = geo.colorBuf.get(index4+1);
763
+ float cb = geo.colorBuf.get(index4+2);
764
+ float ca = geo.colorBuf.get(index4+3);
765
+
766
+ display.modelParams0[0] = r * cr;
767
+ display.modelParams0[1] = g * cg;
768
+ display.modelParams0[2] = b * cb;
769
+
770
+ display.modelParams5[1] = opacity * ca;
771
+
772
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
773
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
774
+
775
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
776
+ RandomNode.globalseed2 = RandomNode.globalseed;
777
+
778
+// gl.glColor4f(cr,cg,cb,ca);
779
+ // gl.glScalef(1024/16,1024/16,1024/16);
780
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
781
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
782
+ //gl.glTranslatef(-tx,-ty,-tz);
783
+ gl.glPopMatrix();
784
+
785
+ gl.glMatrixMode(gl.GL_TEXTURE);
786
+ gl.glPopMatrix();
787
+ }
788
+ // gl.glScalef(1024,1024,1024);
789
+ if (!cf)
790
+ gl.glDisable(gl.GL_CULL_FACE);
791
+
792
+ display.modelParams0[0] = r;
793
+ display.modelParams0[1] = g;
794
+ display.modelParams0[2] = b;
795
+
796
+ display.modelParams5[1] = opacity;
797
+
798
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
799
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
800
+
801
+ gl.glMatrixMode(gl.GL_MODELVIEW);
802
+
803
+// System.err.println("total = " + v/3 + "; displayed = " + count);
804
+ if (true)
805
+ return;
806
+
807
+//// if (!tris.predraw(this))
808
+//// {
809
+//// return;
810
+//// }
811
+//// if (Debug.stats)
812
+//// {
813
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
814
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
815
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
816
+//// }
817
+////
818
+//// if (tris.getDisplayListID() != -1)
819
+//// {
820
+//// renderDisplayList(tris);
821
+//// return;
822
+//// }
823
+////
824
+//// if (!generatingDisplayList)
825
+//// {
826
+//// applyStates(tris.states, tris);
827
+//// }
828
+//// if (Debug.stats)
829
+//// {
830
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
831
+//// }
832
+//// boolean transformed = doTransforms(tris);
833
+//
834
+// int glMode = GL.GL_TRIANGLES;
835
+// switch (getMode())
836
+// {
837
+// case Triangles:
838
+// glMode = GL.GL_TRIANGLES;
839
+// break;
840
+// case Strip:
841
+// glMode = GL.GL_TRIANGLE_STRIP;
842
+// break;
843
+// case Fan:
844
+// glMode = GL.GL_TRIANGLE_FAN;
845
+// break;
846
+// }
847
+//
848
+// if (!predrawGeometry(gl))
849
+// {
850
+// // make sure only the necessary indices are sent through on old
851
+// // cards.
852
+// IntBuffer indices = this.getIndexBuffer();
853
+// if (indices == null)
854
+// {
855
+// logger.severe("missing indices on geometry object: " + this.toString());
856
+// } else
857
+// {
858
+// indices.rewind();
859
+// indices.limit(this.getMaxIndex());
860
+//
861
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
862
+//
863
+// indices.clear();
864
+// }
865
+// } else
866
+// {
867
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
868
+// GL.GL_UNSIGNED_INT, 0);
869
+// }
870
+//
871
+//// postdrawGeometry(tris);
872
+//// if (transformed)
873
+//// {
874
+//// undoTransforms(tris);
875
+//// }
876
+////
877
+//// if (Debug.stats)
878
+//// {
879
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
880
+//// }
881
+//// tris.postdraw(this);
882
+ }
883
+
884
+ static Camera localcamera = new Camera();
885
+ static cVector from = new cVector();
886
+ static cVector to = new cVector();
887
+
888
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
889
+ {
890
+ CameraPane cp = this;
891
+
892
+ Camera keep = cp.RenderCamera();
893
+ cp.renderCamera = localcamera;
894
+
895
+ if (br.trimmed)
896
+ {
897
+ float[] colors = new float[br.positions.length / 3];
898
+
899
+ int i3 = 0;
900
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
901
+ {
902
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
903
+ continue;
904
+
905
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
906
+ to.set(br.positions[i3] + br.normals[i3],
907
+ br.positions[i3 + 1] + br.normals[i3 + 1],
908
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
909
+ LA.xformPos(from, transform, from);
910
+ LA.xformPos(to, transform, to); // RIGID ONLY
911
+ localcamera.setAim(from, to);
912
+
913
+ CameraPane.occlusionbuffer.display();
914
+
915
+ if (CameraPane.DEBUG_OCCLUSION)
916
+ cp.display(); // debug
917
+
918
+ colors[i] = cp.vertexOcclusion.r;
919
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
920
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
921
+
922
+ if ((i % 100) == 0 && i != 0)
923
+ {
924
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
925
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
926
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
927
+ }
928
+ }
929
+
930
+ br.colors = colors;
931
+ }
932
+ else
933
+ {
934
+ for (int i = 0; i < br.VertexCount(); i++)
935
+ {
936
+ Vertex v = br.GetVertex(i);
937
+
938
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
939
+ continue;
940
+
941
+ from.set(v.x, v.y, v.z);
942
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
943
+ LA.xformPos(from, transform, from);
944
+ LA.xformPos(to, transform, to); // RIGID ONLY
945
+ localcamera.setAim(from, to);
946
+
947
+ CameraPane.occlusionbuffer.display();
948
+
949
+ if (CameraPane.DEBUG_OCCLUSION)
950
+ cp.display(); // debug
951
+
952
+ v.AO = cp.vertexOcclusion.r;
953
+
954
+ if ((i % 100) == 0 && i != 0)
955
+ {
956
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
957
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
958
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
959
+ }
960
+ }
961
+ }
962
+
963
+ //System.out.println("done.");
964
+
965
+ cp.renderCamera = keep;
966
+ }
967
+
968
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
969
+ {
970
+ CameraPane display = this;
971
+ pointFlow.CreateHT();
972
+
973
+ float r = display.modelParams0[0];
974
+ float g = display.modelParams0[1];
975
+ float b = display.modelParams0[2];
976
+ float opacity = display.modelParams5[1];
977
+
978
+ //final GL gl = GLU.getCurrentGL();
979
+ GL gl = display.GetGL(); // getGL();
980
+
981
+ int s = pointFlow.points.size();
982
+
983
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
984
+ gl.glEnable(gl.GL_CULL_FACE);
985
+
986
+ for (int i=s; --i>=0;)
987
+ //for (int i=0; i<s; i++)
988
+ {
989
+ cVector v = pointFlow.points.get(i);
990
+
991
+ double mindist = Double.MAX_VALUE;
992
+
993
+ double size = pointFlow.minimumSize;
994
+
995
+ double distancenext = 0;
996
+
997
+ if (i > 0)
998
+ {
999
+ cVector w = pointFlow.points.get(i-1);
1000
+
1001
+ double dist = w.distance(v);
1002
+
1003
+ distancenext = dist;
1004
+
1005
+ if (mindist > dist)
1006
+ {
1007
+ mindist = dist;
1008
+ size = mindist*pointFlow.resizefactor;
1009
+ }
1010
+ }
1011
+
1012
+ if (i < s-1)
1013
+ {
1014
+ cVector w = pointFlow.points.get(i+1);
1015
+
1016
+ double dist = w.distance(v);
1017
+
1018
+ if (mindist > dist)
1019
+ {
1020
+ mindist = dist;
1021
+ size = mindist*pointFlow.resizefactor;
1022
+ }
1023
+ }
1024
+
1025
+ if (size < pointFlow.minimumSize)
1026
+ size = pointFlow.minimumSize;
1027
+ if (size > pointFlow.maximumSize)
1028
+ size = pointFlow.maximumSize;
1029
+
1030
+ double tx = v.x;
1031
+ double ty = v.y;
1032
+ double tz = v.z;
1033
+
1034
+ // if (tx == 0 && ty == 0 && tz == 0)
1035
+ // continue;
1036
+
1037
+ gl.glMatrixMode(gl.GL_TEXTURE);
1038
+ gl.glPushMatrix();
1039
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1040
+
1041
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1042
+
1043
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1044
+ gl.glPushMatrix();
1045
+
1046
+ gl.glTranslated(tx,ty,tz);
1047
+
1048
+ gl.glScaled(size,size,size);
1049
+
1050
+// float cr = colorBuf.get(index4);
1051
+// float cg = colorBuf.get(index4+1);
1052
+// float cb = colorBuf.get(index4+2);
1053
+// float ca = colorBuf.get(index4+3);
1054
+//
1055
+// display.modelParams0[0] = r * cr;
1056
+// display.modelParams0[1] = g * cg;
1057
+// display.modelParams0[2] = b * cb;
1058
+//
1059
+// display.modelParams5[1] = opacity * ca;
1060
+//
1061
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1062
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1063
+//
1064
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1065
+// RandomNode.globalseed2 = RandomNode.globalseed;
1066
+//
1067
+//// gl.glColor4f(cr,cg,cb,ca);
1068
+// // gl.glScalef(1024/16,1024/16,1024/16);
1069
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1070
+
1071
+ gl.glPopMatrix();
1072
+
1073
+ double step = size/4; //
1074
+
1075
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1076
+ continue;
1077
+
1078
+ int nbsteps = (int)(distancenext/step);
1079
+
1080
+ step = distancenext/nbsteps;
1081
+
1082
+ cVector next = pointFlow.points.get(i-1);
1083
+
1084
+ tmp.set(next);
1085
+ tmp.sub(v);
1086
+ tmp.normalize();
1087
+ tmp.mul(step);
1088
+
1089
+ // calculate next size
1090
+ mindist = Double.MAX_VALUE;
1091
+
1092
+ double nextsize = pointFlow.minimumSize;
1093
+
1094
+ if (i > 1)
1095
+ {
1096
+ cVector w = pointFlow.points.get(i-2);
1097
+
1098
+ double dist = w.distance(next);
1099
+
1100
+ if (mindist > dist)
1101
+ {
1102
+ mindist = dist;
1103
+ nextsize = mindist*pointFlow.resizefactor;
1104
+ }
1105
+ }
1106
+
1107
+ double dist = v.distance(next);
1108
+
1109
+ if (mindist > dist)
1110
+ {
1111
+ mindist = dist;
1112
+ nextsize = mindist*pointFlow.resizefactor;
1113
+ }
1114
+
1115
+ if (nextsize < pointFlow.minimumSize)
1116
+ nextsize = pointFlow.minimumSize;
1117
+ if (nextsize > pointFlow.maximumSize)
1118
+ nextsize = pointFlow.maximumSize;
1119
+ //
1120
+
1121
+ double count = 0;
1122
+
1123
+ while (distancenext > 0.000000001) // step
1124
+ {
1125
+ gl.glPushMatrix();
1126
+
1127
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1128
+
1129
+ double K = count/nbsteps;
1130
+
1131
+ double intersize = K*nextsize + (1-K)*size;
1132
+
1133
+ gl.glScaled(intersize,intersize,intersize);
1134
+
1135
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1136
+
1137
+ count++;
1138
+
1139
+ distancenext -= step;
1140
+
1141
+ gl.glPopMatrix();
1142
+ }
1143
+
1144
+ if (count != nbsteps)
1145
+ assert(count == nbsteps);
1146
+
1147
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1148
+ //gl.glTranslatef(-tx,-ty,-tz);
1149
+
1150
+ gl.glMatrixMode(gl.GL_TEXTURE);
1151
+ gl.glPopMatrix();
1152
+ }
1153
+
1154
+ if (!cf)
1155
+ gl.glDisable(gl.GL_CULL_FACE);
1156
+
1157
+// display.modelParams0[0] = r;
1158
+// display.modelParams0[1] = g;
1159
+// display.modelParams0[2] = b;
1160
+//
1161
+// display.modelParams5[1] = opacity;
1162
+//
1163
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1164
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1165
+
1166
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1167
+ }
1168
+
1169
+ public void DrawBox(cVector min, cVector max)
1170
+ {
1171
+ javax.media.opengl.GL gl = GetGL();
1172
+ gl.glBegin(gl.GL_LINES);
1173
+
1174
+ gl.glVertex3d(min.x, min.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, max.z);
1176
+ gl.glVertex3d(min.x, min.y, min.z);
1177
+ gl.glVertex3d(min.x, max.y, min.z);
1178
+ gl.glVertex3d(min.x, min.y, min.z);
1179
+ gl.glVertex3d(max.x, min.y, min.z);
1180
+
1181
+ gl.glVertex3d(max.x, max.y, max.z);
1182
+ gl.glVertex3d(min.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, max.z);
1184
+ gl.glVertex3d(max.x, min.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, max.z);
1186
+ gl.glVertex3d(max.x, max.y, min.z);
1187
+
1188
+ gl.glEnd();
1189
+ }
1190
+
1191
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1192
+ {
1193
+ int[] strips = bRep.getRawIndices();
1194
+
1195
+ javax.media.opengl.GL gl = GetGL();
1196
+
1197
+ // TRIANGLE STRIP ARRAY
1198
+ if (bRep.trimmed)
1199
+ {
1200
+ float[] v = bRep.getRawVertices();
1201
+ float[] n = bRep.getRawNormals();
1202
+ float[] c = bRep.getRawColors();
1203
+ float[] uv = bRep.getRawUVMap();
1204
+
1205
+ int count2 = 0;
1206
+ int count3 = 0;
1207
+
1208
+ if (n.length > 0)
1209
+ {
1210
+ for (int i = 0; i < strips.length; i++)
1211
+ {
1212
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1213
+
1214
+ /*
1215
+ boolean locked = false;
1216
+ float eps = 0.1f;
1217
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1218
+
1219
+ int dot = 0;
1220
+
1221
+ if ((dot&1) == 0)
1222
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1223
+
1224
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1225
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1226
+ else
1227
+ {
1228
+ locked = true;
1229
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1230
+ }
1231
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1232
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1233
+ if (hasnorm)
1234
+ {
1235
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1236
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1237
+ }
1238
+
1239
+ if ((dot&4) == 0)
1240
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1241
+
1242
+ if (wrap || !locked && (dot&8) != 0)
1243
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1244
+ else
1245
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1246
+
1247
+ f.dot = dot;
1248
+ */
1249
+
1250
+ if (!selectmode)
1251
+ {
1252
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1253
+ {
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1255
+ } else
1256
+ {
1257
+ SetGLNormal(gl, 0, 0, 1);
1258
+ }
1259
+
1260
+ if (c != null)
1261
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1262
+ {
1263
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1264
+ }
1265
+ }
1266
+
1267
+ if (flipV)
1268
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1269
+ else
1270
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
1272
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1273
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1274
+
1275
+ count2 += 2;
1276
+ count3 += 3;
1277
+ if (!selectmode)
1278
+ {
1279
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1280
+ {
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1282
+ } else
1283
+ {
1284
+ SetGLNormal(gl, 0, 0, 1);
1285
+ }
1286
+ if (c != null)
1287
+ {
1288
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1289
+ }
1290
+ }
1291
+
1292
+ if (flipV)
1293
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1294
+ else
1295
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
1297
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1298
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1299
+
1300
+ count2 += 2;
1301
+ count3 += 3;
1302
+ for (int j = 0; j < strips[i] - 2; j++)
1303
+ {
1304
+ //gl.glTexCoord2d(...);
1305
+ if (!selectmode)
1306
+ {
1307
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1308
+ {
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1310
+ } else
1311
+ {
1312
+ SetGLNormal(gl, 0, 0, 1);
1313
+ }
1314
+ if (c != null)
1315
+ {
1316
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1317
+ }
1318
+ }
1319
+
1320
+ if (flipV)
1321
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1322
+ else
1323
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
1325
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1326
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
1328
+ count2 += 2;
1329
+ count3 += 3;
1330
+ }
1331
+
1332
+ gl.glEnd();
1333
+ }
1334
+ }
1335
+
1336
+ assert count3 == v.length;
1337
+ }
1338
+ else // !trimmed
1339
+ {
1340
+ int count = 0;
1341
+ for (int i = 0; i < strips.length; i++)
1342
+ {
1343
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1344
+
1345
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1346
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1347
+
1348
+ drawVertex(gl, p, flipV, selectmode);
1349
+ drawVertex(gl, q, flipV, selectmode);
1350
+
1351
+ for (int j = 0; j < strips[i] - 2; j++)
1352
+ {
1353
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1354
+
1355
+ // if (j%2 == 0)
1356
+ // drawFace(p, q, r, display, null);
1357
+ // else
1358
+ // drawFace(p, r, q, display, null);
1359
+
1360
+ // p = q;
1361
+ // q = r;
1362
+ drawVertex(gl, r, flipV, selectmode);
1363
+ }
1364
+
1365
+ gl.glEnd();
1366
+ }
1367
+ }
1368
+ }
1369
+
1370
+ static cSpring.Point3D temp = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1372
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1373
+
1374
+ public void DrawDynamicMesh(cMesh mesh)
1375
+ {
1376
+ GL gl = GetGL(); // getGL();
1377
+
1378
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1379
+
1380
+ gl.glDisable(gl.GL_LIGHTING);
1381
+
1382
+ gl.glLineWidth(1);
1383
+ gl.glColor3f(1,1,1);
1384
+ gl.glBegin(gl.GL_LINES);
1385
+ double scale = 0;
1386
+ int count = 0;
1387
+ for (int s=0; s<Phys.allSprings.size(); s++)
1388
+ {
1389
+ cSpring.Spring spring = Phys.allSprings.get(s);
1390
+ if(s == 0)
1391
+ {
1392
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1393
+ }
1394
+ if (mesh.showsprings)
1395
+ {
1396
+ temp.set(spring.a.position);
1397
+ temp.add(spring.b.position);
1398
+ temp.mul(0.5);
1399
+ temp2.set(spring.a.position);
1400
+ temp2.sub(spring.b.position);
1401
+ temp2.mul(spring.restLength/2);
1402
+ temp.sub(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ temp.add(temp2);
1405
+ temp.add(temp2);
1406
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1407
+ }
1408
+
1409
+ if (spring.isHandle)
1410
+ continue;
1411
+
1412
+ //if (scale < spring.restLength)
1413
+ scale += spring.restLength;
1414
+ count++;
1415
+ }
1416
+ gl.glEnd();
1417
+
1418
+ if (count == 0)
1419
+ scale = 0.01;
1420
+ else
1421
+ scale /= count * 3;
1422
+
1423
+ //scale = 0.25;
1424
+
1425
+ if (mesh.ShowInfo())
1426
+ {
1427
+ gl.glLineWidth(4);
1428
+ for (int s=0; s<Phys.allNodes.size(); s++)
1429
+ {
1430
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1431
+ if (node.mass == 0)
1432
+ continue;
1433
+
1434
+ int i = node.springs==null?-1:node.springs.size();
1435
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1436
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1437
+ //temp.normalize();
1438
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1439
+ gl.glBegin(gl.GL_LINES);
1440
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1441
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1442
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1443
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1444
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1445
+ gl.glEnd();
1446
+ }
1447
+
1448
+ gl.glLineWidth(8);
1449
+ for (int s=0; s<Phys.allNodes.size(); s++)
1450
+ {
1451
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1452
+
1453
+ if (node.springs != null)
1454
+ {
1455
+ for (int i=0; i<node.springs.size(); i+=1)
1456
+ {
1457
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1458
+
1459
+ int c = i+1;
1460
+ // c = node.springs.get(i).nbcopies;
1461
+
1462
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1463
+ gl.glBegin(gl.GL_LINES);
1464
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1465
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1466
+ gl.glEnd();
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+ gl.glLineWidth(1);
1472
+ }
1473
+
1474
+ gl.glEnable(gl.GL_LIGHTING);
1475
+ }
1476
+
1477
+ /// INTERFACE
1478
+
1479
+ public void StartTriangles()
1480
+ {
1481
+ javax.media.opengl.GL gl = GetGL();
1482
+ gl.glBegin(gl.GL_TRIANGLES);
1483
+ }
1484
+
1485
+ public void EndTriangles()
1486
+ {
1487
+ GetGL().glEnd();
1488
+ }
1489
+
1490
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1491
+ {
1492
+ if (!selectmode)
1493
+ {
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1495
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1496
+
1497
+ if (flipV)
1498
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1499
+ else
1500
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1501
+ }
1502
+
1503
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1504
+ }
1505
+
1506
+ float[] colorV = new float[4];
1507
+
1508
+ void SetColor(Object3D obj, Vertex p0)
1509
+ {
1510
+ CameraPane display = this;
1511
+ BoundaryRep bRep = obj.bRep;
1512
+
1513
+ if (RENDERPROGRAM == 0)
1514
+ {
1515
+ float r = 0;
1516
+ if (bRep != null)
1517
+ {
1518
+ if (bRep.stripified)
1519
+ {
1520
+ r = 1;
1521
+ }
1522
+ }
1523
+ float g = 0;
1524
+ if (bRep != null)
1525
+ {
1526
+ if (bRep.trimmed)
1527
+ {
1528
+ g = 1;
1529
+ }
1530
+ }
1531
+ float b = 0;
1532
+ if (obj.support != null && obj.link2master)
1533
+ {
1534
+ b = 1;
1535
+ }
1536
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1537
+ return;
1538
+ }
1539
+
1540
+ if (display.DrawMode() != CameraPane.SHADOW)
1541
+ return;
1542
+
1543
+ javax.media.opengl.GL gl = display.GetGL();
1544
+// if (true) return;
1545
+// float ao = p.AO;
1546
+//
1547
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1548
+// // ao = 1;
1549
+//
1550
+// gl.glColor4f(ao, ao, ao, 1);
1551
+
1552
+// CameraPane.selectedpoint.
1553
+// getAverage(cStatic.point1, true);
1554
+ if (CameraPane.pointflow == null) // !random) // live)
1555
+ {
1556
+ return;
1557
+ }
1558
+
1559
+ cStatic.point1.set(0,0,0);
1560
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1561
+
1562
+ cStatic.point1.sub(p0);
1563
+
1564
+
1565
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1566
+// {
1567
+// return;
1568
+// }
1569
+
1570
+ //if (true)
1571
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1572
+ {
1573
+ return;
1574
+ }
1575
+
1576
+ if (false) // marked)
1577
+ {
1578
+ // debug rigging weights
1579
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1580
+ {
1581
+ float weight = p0.weights[object] / p0.totalweight;
1582
+
1583
+ // if (weight < 0.1)
1584
+ // {
1585
+ // assert(weight == 0);
1586
+ // continue;
1587
+ // }
1588
+
1589
+ if (p0.vertexlinks[object] == -1)
1590
+ continue;
1591
+
1592
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1593
+
1594
+ int color = //1 << object; //
1595
+ //p.vertexlinks.length;
1596
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1597
+ colorV[2] += (color & 1) * weight;
1598
+ colorV[1] += ((color & 2) >> 1) * weight;
1599
+ colorV[0] += ((color & 4) >> 2) * weight;
1600
+ }
1601
+ }
1602
+ else
1603
+ {
1604
+ if (obj.drawingstarted)
1605
+ {
1606
+ // find next point
1607
+ if (bRep.GetVertex(0).faceindices == null)
1608
+ {
1609
+ bRep.InitFaceIndices();
1610
+ }
1611
+
1612
+ double ymin = p0.y;
1613
+
1614
+ Vertex newp = p0;
1615
+
1616
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1617
+ {
1618
+ int fi = p0.faceindices[fii];
1619
+
1620
+ if (fi == -1)
1621
+ break;
1622
+
1623
+ Face f = bRep.GetFace(fi);
1624
+
1625
+ Vertex p = bRep.GetVertex(f.p);
1626
+ Vertex q = bRep.GetVertex(f.q);
1627
+ Vertex r = bRep.GetVertex(f.r);
1628
+
1629
+ int swap = (int)(Math.random()*3);
1630
+
1631
+// for (int s=swap; --s>=0;)
1632
+// {
1633
+// Vertex t = p;
1634
+// p = q;
1635
+// q = r;
1636
+// r = t;
1637
+// }
1638
+ if (ymin > p.y)
1639
+ {
1640
+ ymin = p.y;
1641
+ newp = p;
1642
+// break;
1643
+ }
1644
+ if (ymin > q.y)
1645
+ {
1646
+ ymin = q.y;
1647
+ newp = q;
1648
+// break;
1649
+ }
1650
+ if (ymin > r.y)
1651
+ {
1652
+ ymin = r.y;
1653
+ newp = r;
1654
+// break;
1655
+ }
1656
+ }
1657
+
1658
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1659
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1660
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1661
+
1662
+ obj.drawingstarted = false;
1663
+
1664
+ // return;
1665
+ }
1666
+
1667
+ if (false) // CameraPane.DRAW
1668
+ {
1669
+ p0.AO = colorV[0] = 2;
1670
+ colorV[1] = 2;
1671
+ colorV[2] = 2;
1672
+ }
1673
+
1674
+ CameraPane.pointflow.add(p0);
1675
+ CameraPane.pointflow.Touch();
1676
+ }
1677
+
1678
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1679
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1680
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1681
+ }
1682
+
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1684
+ {
1685
+ CameraPane display = this;
1686
+ //new Exception().printStackTrace();
1687
+
1688
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1689
+ {
1690
+ return;
1691
+ }
1692
+
1693
+ javax.media.opengl.GL gl = display.GetGL();
1694
+
1695
+ //Color col = Color.getHSBColor(color,modulation,1);
1696
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1697
+ if (!material.multiply)
1698
+ {
1699
+ display.color = material.color;
1700
+ display.saturation = material.modulation;
1701
+ }
1702
+ else
1703
+ {
1704
+ display.color *= material.color*2;
1705
+ display.saturation *= material.modulation*2;
1706
+ }
1707
+
1708
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1709
+
1710
+ float[] colorV = Grafreed.colorV;
1711
+
1712
+ /**/
1713
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1714
+ {
1715
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1716
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1717
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1718
+ colorV[3] = 1; // material.opacity;
1719
+
1720
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1721
+ //System.out.println("Opacity = " + opacity);
1722
+
1723
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1724
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1725
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1726
+
1727
+ float amb = material.ambient;
1728
+ if (amb < material.cameralight)
1729
+ {
1730
+ amb = material.cameralight;
1731
+ }
1732
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1733
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1734
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1735
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1736
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1737
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1738
+
1739
+ /**/
1740
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1741
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1742
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1743
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1744
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1745
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1746
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1747
+ //System.out.println("shininess = " + colorV[0]);
1748
+ if (colorV[0] > 128)
1749
+ {
1750
+ colorV[0] = 128;
1751
+ }
1752
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1753
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1754
+ /**/
1755
+ }
1756
+ /**/
1757
+
1758
+ //selected = false;
1759
+ selected = selected && display.flash;
1760
+
1761
+ //display.modelParams0[0] = 0; // pigment.r;
1762
+ //display.modelParams0[1] = 0; // pigment.g;
1763
+ //display.modelParams0[2] = 0; // pigment.b;
1764
+ if (!material.multiply)
1765
+ {
1766
+ display.modelParams0[3] = material.metalness;
1767
+ display.modelParams1[0] = material.diffuse;
1768
+ display.modelParams1[1] = material.specular;
1769
+ display.modelParams1[2] = 1 / material.shininess;
1770
+ display.modelParams1[3] = material.shift;
1771
+ display.modelParams2[0] = material.ambient;
1772
+ display.modelParams2[1] = material.lightarea;
1773
+ //System.out.println("light area = " + lightarea);
1774
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1775
+ display.modelParams2[3] = material.velvet;
1776
+ display.modelParams3[0] = material.sheen;
1777
+ display.modelParams3[1] = material.subsurface;
1778
+ display.modelParams3[2] = material.bump; // backlit
1779
+ display.modelParams3[3] = material.aniso;
1780
+ display.modelParams4[0] = material.anisoV;
1781
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1782
+ //System.out.println("selected = " + selected);
1783
+ display.modelParams4[2] = material.diffuseness;
1784
+ display.modelParams4[3] = material.shadow;
1785
+ display.modelParams5[0] = material.texture;
1786
+ display.modelParams5[1] = material.opacity;
1787
+ display.modelParams5[2] = material.fakedepth;
1788
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1789
+ }
1790
+ else
1791
+ {
1792
+ display.modelParams0[3] *= material.metalness*2;
1793
+ display.modelParams1[0] *= material.diffuse*2;
1794
+ display.modelParams1[1] *= material.specular*2;
1795
+ display.modelParams1[2] *= material.shininess*2;
1796
+ display.modelParams1[3] *= material.shift*2;
1797
+ display.modelParams2[0] *= material.ambient*2;
1798
+ display.modelParams2[1] *= material.lightarea*2;
1799
+ display.modelParams2[2] *= material.factor*2;
1800
+ display.modelParams2[3] *= material.velvet*2;
1801
+ display.modelParams3[0] *= material.sheen*2;
1802
+ display.modelParams3[1] *= material.subsurface*2;
1803
+ display.modelParams3[2] *= material.bump*2;
1804
+ display.modelParams3[3] *= material.aniso*2;
1805
+ display.modelParams4[0] *= material.anisoV*2;
1806
+ display.modelParams4[1] *= material.cameralight*2;
1807
+ //System.out.println("selected = " + selected);
1808
+ display.modelParams4[2] *= material.diffuseness*2;
1809
+ display.modelParams4[3] *= material.shadow*2;
1810
+ display.modelParams5[0] *= material.texture*2;
1811
+ display.modelParams5[1] *= material.opacity*2;
1812
+ display.modelParams5[2] *= material.fakedepth*2;
1813
+ display.modelParams5[3] *= material.shadowbias*2;
1814
+ }
1815
+
1816
+ display.modelParams6[0] = 0;
1817
+ display.modelParams6[1] = 0;
1818
+ display.modelParams6[2] = 0;
1819
+ display.modelParams6[3] = 0;
1820
+
1821
+ display.modelParams7[0] = 0;
1822
+ display.modelParams7[1] = 1000;
1823
+ display.modelParams7[2] = material.parallax;
1824
+ display.modelParams7[3] = 0;
1825
+
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
1827
+
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1829
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1830
+ {
1831
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1832
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1833
+ if (extparams.length > 1)
1834
+ {
1835
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1836
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1837
+ if (extparams.length > 2)
1838
+ {
1839
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1840
+ float x = extparams[2].y / 1000.0f;
1841
+ //if (x == 0)
1842
+ // x = 1f;
1843
+ display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power
1844
+ if (extparams[2].y > 0)
1845
+ {
1846
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1847
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1848
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1849
+ }
1850
+ }
1851
+ }
1852
+ }
1853
+
1854
+ //if (display.modelParams6[2] != 0)
1855
+ /*
1856
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1857
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1858
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1859
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1860
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1861
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1862
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1863
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1864
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1865
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1866
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1867
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1868
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1869
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1870
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1871
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1872
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1873
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1874
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1875
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1876
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1877
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1878
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1879
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1880
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1881
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1882
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1883
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1884
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1885
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1886
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1887
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1888
+ /**/
1889
+ //assert (display.modelParams6[2] == 0);
1890
+
1891
+ //System.out.println("noise power = " + display.modelParams7[0]);
1892
+ //System.out.println("shadowbias = " + shadowbias);
1893
+
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1896
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1897
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1898
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1899
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1900
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1901
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1902
+
1903
+ int mode = display.FP_SHADER;
1904
+
1905
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1906
+ {
1907
+ mode |= display.FP_ANISO;
1908
+ }
1909
+
1910
+ display.EnableProgram(mode);
1911
+
1912
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1913
+
1914
+ if (!material.multiply)
1915
+ {
1916
+ if (Globals.drawMode == CameraPane.SHADOW)
1917
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1918
+ else
1919
+ gl.glDepthMask(material.opacity >= 0.99);
1920
+ }
2081921 }
2091922
2101923 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1938,7 @@
2251938 currentGL.glMultMatrixd(model, 0);
2261939 }
2271940
228
- void PushMatrix(double[][] matrix, int count)
1941
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291942 {
2301943 matrixdepth++;
2311944 // GrafreeD.tracein(matrix);
....@@ -254,7 +1967,7 @@
2541967 void PushMatrix(double[][] matrix)
2551968 {
2561969 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
2581971 }
2591972
2601973 void PushMatrix()
....@@ -270,7 +1983,7 @@
2701983
2711984 double[][] tmpmat = new double[4][4];
2721985
273
- void PopMatrix(double[][] inverse)
1986
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741987 {
2751988 --matrixdepth;
2761989
....@@ -310,7 +2023,7 @@
3102023 PushTextureMatrix(matrix, 1);
3112024 }
3122025
313
- void PushTextureMatrix(double[][] matrix, int count)
2026
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142027 {
3152028 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162029
....@@ -324,7 +2037,7 @@
3242037 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252038 }
3262039
327
- void PopTextureMatrix(double[][] inverse)
2040
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282041 {
3292042 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302043 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -340,9 +2053,9 @@
3402053 switch(viewcode)
3412054 {
3422055 case 0: return "main";
343
- case 1: return "one";
344
- case 2: return "two";
345
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
3462059 case 4: return "light";
3472060 }
3482061
....@@ -351,15 +2064,15 @@
3512064
3522065 static int camerachangeframe;
3532066
354
- boolean SetCamera(Camera cam)
2067
+ public boolean SetCamera(Camera cam)
3552068 {
3562069 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572070 // return false;
3582071
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2072
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602073 {
3612074 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2075
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632076 {
3642077 // refuse the camera change
3652078 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2080,7 @@
3672080 }
3682081 }
3692082
370
- camerachangeframe = framecount;
2083
+ camerachangeframe = Globals.framecount;
3712084
3722085 cam.hAspect = -1; // Read only
3732086
....@@ -398,7 +2111,7 @@
3982111 {
3992112 //System.err.println("Oeil on");
4002113 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2114
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022115 // object.editWindow.ScreenFit(trackedobject);
4032116 //pingthread.StepToTarget(true);
4042117 }
....@@ -407,8 +2120,8 @@
4072120 {
4082121 //System.err.println("Oeil on");
4092122 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122125 //pingthread.StepToTarget(true);
4132126 }
4142127
....@@ -471,39 +2184,12 @@
4712184 {
4722185 frozen ^= true;
4732186 // Weird...
474
- lighttouched = true;
2187
+ Globals.lighttouched = true;
4752188 }
4762189
4772190 void ToggleDL()
4782191 {
4792192 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GrafreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072193 }
5082194
5092195 void ToggleFullScreen()
....@@ -513,12 +2199,7 @@
5132199
5142200 void ToggleCrowd()
5152201 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2202
+ Globals.CROWD ^= true;
5222203 }
5232204
5242205 void ToggleLocal()
....@@ -526,62 +2207,89 @@
5262207 LOCALTRANSFORM ^= true;
5272208 }
5282209
529
- void ToggleFast()
2210
+ public void ToggleTexture()
2211
+ {
2212
+ textureon ^= true;
2213
+ }
2214
+
2215
+ public void ToggleLive()
2216
+ {
2217
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2218
+
2219
+ System.err.println("LIVE = " + Globals.isLIVE());
2220
+
2221
+ if (!Globals.isLIVE()) // save sound
2222
+ Grafreed.savesound = true; // wav.save();
2223
+ // else
2224
+ repaint(); // start loop // may 2013
2225
+ }
2226
+
2227
+ public void ToggleSupport()
2228
+ {
2229
+ SUPPORT ^= true;
2230
+ }
2231
+
2232
+ public void ToggleAbort()
2233
+ {
2234
+ ABORTMODE ^= true;
2235
+ }
2236
+
2237
+ public void ToggleInertia()
2238
+ {
2239
+ INERTIA ^= true;
2240
+ }
2241
+
2242
+ public void ToggleFast()
5302243 {
5312244 FAST ^= true;
5322245 }
5332246
534
- void ToggleSlowPose()
2247
+ public void ToggleSlowPose()
5352248 {
5362249 SLOWPOSE ^= true;
5372250 }
5382251
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2252
+ public void ToggleBoxMode()
5452253 {
5462254 BOXMODE ^= true;
5472255 }
5482256
549
- void ToggleSmoothFocus()
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
2260
+ }
2261
+
2262
+ public void ToggleSmoothFocus()
5502263 {
5512264 SMOOTHFOCUS ^= true;
5522265 }
5532266
554
- void ToggleImageFlip()
2267
+ public void ToggleImageFlip()
5552268 {
5562269 IMAGEFLIP ^= true;
5572270 }
5582271
559
- void ToggleSpeakerMocap()
2272
+ public void ToggleSpeakerMocap()
5602273 {
5612274 SPEAKERMOCAP ^= true;
5622275 }
5632276
564
- void ToggleSpeakerCamera()
2277
+ public void ToggleSpeakerCamera()
5652278 {
5662279 SPEAKERCAMERA ^= true;
5672280 }
5682281
569
- void ToggleSpeakerFocus()
2282
+ public void ToggleSpeakerFocus()
5702283 {
5712284 SPEAKERFOCUS ^= true;
5722285 }
5732286
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2287
+ public void ToggleFrustum()
5802288 {
5812289 FRUSTUM ^= true;
5822290 }
5832291
584
- void ToggleTrack()
2292
+ public void ToggleTrack()
5852293 {
5862294 TRACK ^= true;
5872295 if (TRACK)
....@@ -600,25 +2308,35 @@
6002308 repaint();
6012309 }
6022310
603
- void ToggleTrackOnce()
2311
+ public void ToggleTrackOnce()
6042312 {
6052313 TRACKONCE ^= true;
6062314 }
6072315
608
- void ToggleShadowTrack()
2316
+ public void ToggleShadowTrack()
6092317 {
6102318 SHADOWTRACK ^= true;
6112319 repaint();
6122320 }
6132321
614
- void ToggleOeil()
2322
+ public void ToggleOeil()
6152323 {
6162324 OEIL ^= true;
6172325 }
6182326
619
- void ToggleOeilOnce()
2327
+ public void ToggleOeilOnce()
6202328 {
6212329 OEILONCE ^= true;
2330
+ }
2331
+
2332
+ void ToggleFootContact()
2333
+ {
2334
+ FOOTCONTACT ^= true;
2335
+ }
2336
+
2337
+ void ToggleDebug()
2338
+ {
2339
+ Globals.DEBUG ^= true;
6222340 }
6232341
6242342 void ToggleLookAt()
....@@ -626,9 +2344,9 @@
6262344 LOOKAT ^= true;
6272345 }
6282346
629
- void ToggleRandom()
2347
+ void ToggleSwitch()
6302348 {
631
- RANDOM ^= true;
2349
+ SWITCH ^= true;
6322350 }
6332351
6342352 void ToggleHandles()
....@@ -636,10 +2354,17 @@
6362354 HANDLES ^= true;
6372355 }
6382356
2357
+ Object3D paintFolder;
2358
+
6392359 void TogglePaint()
6402360 {
6412361 PAINTMODE ^= true;
6422362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
6432368 }
6442369
6452370 void SwapCamera(int a, int b)
....@@ -672,34 +2397,6 @@
6722397 //assert (cam.hAspect == 0);
6732398 cam.hAspect = 0;
6742399 lightCamera = cam;
675
- }
676
-
677
- CameraPane(Object3D o, Camera cam, boolean withcontext)
678
- {
679
- super(defaultcaps, null, withcontext?glcontext:null, null);
680
-
681
- //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
682
- glcontext = getContext();
683
-
684
- cameras = new Camera[2];
685
- targetLookAts = new cVector[2];
686
-
687
- SetCamera(cam);
688
-
689
- SetLight(new Camera(new cVector(10, 10, -20)));
690
-
691
- object = o;
692
-
693
- setBackground(Color.white);
694
-
695
- addKeyListener(this);
696
- addMouseListener(this);
697
- addMouseMotionListener(this);
698
- addMouseWheelListener(this);
699
- //System.out.println("addGLEventListener: " + this);
700
- addGLEventListener(this);
701
-
702
-// pingthread.start(); // may 2013
7032400 }
7042401
7052402 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2456,38 @@
7592456
7602457 GL currentGL;
7612458
762
- GL GetGL()
2459
+ public GL GetGL() // INTERFACE
7632460 {
7642461 return currentGL;
7652462 }
766
-
2463
+
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
7672491 /**/
7682492 class CacheTexture
7692493 {
....@@ -772,28 +2496,31 @@
7722496
7732497 int resolution;
7742498
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762500 {
777
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
7782503 resolution = res;
7792504 }
7802505 }
7812506 /**/
7822507
7832508 // TEXTURE static Texture texture;
784
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
785
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
786
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
7872514 int pigmentdepth = 0;
7882515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892516 int bumpdepth = 0;
7902517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952522
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972524 {
7982525 TextureData texturedata = null;
7992526
....@@ -803,7 +2530,7 @@
8032530 com.sun.opengl.util.texture.TextureIO.newTextureData(
8042531 getClass().getClassLoader().getResourceAsStream(name),
8052532 true,
806
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
8072534 } catch (java.io.IOException e)
8082535 {
8092536 throw new javax.media.opengl.GLException(e);
....@@ -812,13 +2539,34 @@
8122539 if (bump)
8132540 texturedata = ConvertBump(texturedata, false);
8142541
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172544
818
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
819
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202547
821
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
8222570 }
8232571
8242572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3639,8 @@
18913639
18923640 System.out.println("LOADING TEXTURE : " + name);
18933641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
18943644 //
18953645 if (false) // compressbit > 0)
18963646 {
....@@ -2595,6 +4345,7 @@
25954345
25964346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25974347 {
4348
+ new Exception().printStackTrace();
25984349 System.exit(0);
25994350 com.sun.opengl.util.texture.Texture texture = null;
26004351
....@@ -6271,7 +8022,7 @@
62718022 return null;
62728023 }
62738024
6274
- void ReleaseTextures(cTexture tex)
8025
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62758026 {
62768027 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62778028 {
....@@ -6288,7 +8039,7 @@
62888039 String pigment = Object3D.GetPigment(tex);
62898040 String bump = Object3D.GetBump(tex);
62908041
6291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62928043 {
62938044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62948045 // System.out.println("; bump = " + bump);
....@@ -6303,13 +8054,71 @@
63038054 pigment = null;
63048055 }
63058056
6306
- ReleaseTexture(bump, true);
6307
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
63088059 }
63098060
6310
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63118062 {
6312
- if (// drawMode != 0 || /*tex == null ||*/
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
8120
+ {
8121
+ if (// DrawMode() != 0 || /*tex == null ||*/
63138122 ambientOcclusion ) // || !textureon)
63148123 {
63158124 return;
....@@ -6318,7 +8127,7 @@
63188127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63198128
63208129 if (tex != null)
6321
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63228131
63238132 // //assert( texture != null );
63248133 // if (texture == null)
....@@ -6410,9 +8219,57 @@
64108219 }
64118220 }
64128221
6413
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8222
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64148223 {
6415
- if (// drawMode != 0 || /*tex == null ||*/
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
8265
+
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
8268
+ }
8269
+
8270
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8271
+ {
8272
+ if (// DrawMode() != 0 || /*tex == null ||*/
64168273 ambientOcclusion ) // || !textureon)
64178274 {
64188275 return; // false;
....@@ -6421,17 +8278,47 @@
64218278 if (tex == null)
64228279 {
64238280 BindTexture(null,false,resolution);
6424
- BindTexture(null,true,resolution);
64258281 return;
64268282 }
64278283
64288284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
64298317 String bump = Object3D.GetBump(tex);
64308318
6431
- usedtextures.put(pigment, pigment);
6432
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
64338320
6434
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64358322 {
64368323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64378324 // System.out.println("; bump = " + bump);
....@@ -6441,43 +8328,94 @@
64418328 {
64428329 bump = null;
64438330 }
6444
- if (pigment.equals(""))
6445
- {
6446
- pigment = null;
6447
- }
64488331
6449
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
- BindTexture(pigment, false, resolution);
64518332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6452
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
64538334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6454
-
6455
- return; // true;
64568335 }
64578336
6458
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
64598340 {
6460
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
64618360
64628361 if (tex != null)
64638362 {
6464
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64658365
6466
- String[] split = tex.split("Textures");
6467
- if (split.length > 1)
6468
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6469
- else
6470
- if (!texname.startsWith("/"))
6471
- texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
8373
+// String[] split = tex.split("Textures");
8374
+// if (split.length > 1)
8375
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8376
+// else
8377
+// if (!texname.startsWith("/"))
8378
+// texname = "/Users/nbriere/Textures/" + texname;
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
8380
+ {
8381
+ texname = fallbackTextureName;
8382
+ }
64728383
64738384 if (CACHETEXTURE)
6474
- texture = textures.get(texname); // TEXTURE CACHE
6475
-
6476
- TextureData texturedata = null;
6477
-
6478
- if (texture == null || texture.resolution < resolution)
64798385 {
6480
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64818419 {
64828420 assert(!bump);
64838421 // if (bump)
....@@ -6488,19 +8426,23 @@
64888426 // }
64898427 // else
64908428 // {
6491
- texture = textures.get(tex);
6492
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
64938431 {
6494
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64958433 }
8434
+ else
8435
+ new Exception().printStackTrace();
64968436 // }
64978437 } else
6498
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64998439 {
65008440 assert(bump);
6501
- texture = textures.get(tex);
6502
- if (texture == null)
6503
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
65048446 } else
65058447 {
65068448 //if (tex.equals("IMMORTAL"))
....@@ -6508,11 +8450,22 @@
65088450 // texture = GetResourceTexture("default.png");
65098451 //} else
65108452 //{
6511
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
65128454 {
6513
- texture = textures.get(tex);
6514
- if (texture == null)
6515
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
65168469 } else
65178470 {
65188471 if (textureon)
....@@ -6537,7 +8490,7 @@
65378490 }
65388491
65398492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6540
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
65418494 cachename = texname;
65428495 else
65438496 processbump = false; // don't process bump map again
....@@ -6559,7 +8512,7 @@
65598512 }
65608513
65618514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6562
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
65638516 cachename = texname;
65648517 else
65658518 processbump = false; // don't process bump map again
....@@ -6568,20 +8521,23 @@
65688521 texturedata = GetFileTexture(cachename, processbump, resolution);
65698522
65708523
6571
- if (texturedata != null)
6572
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8524
+ if (texturedata == null)
8525
+ throw new Exception();
8526
+
8527
+ texturecache = new CacheTexture(texturedata,resolution);
65738528 //texture = GetTexture(tex, bump);
65748529 }
8530
+ }
65758531 }
65768532 //}
65778533 }
65788534
6579
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65808536 {
65818537 //return false;
65828538
65838539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6584
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65858541 {
65868542 // String ext = "_highres";
65878543 // if (REDUCETEXTURE)
....@@ -6598,52 +8554,17 @@
65988554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65998555 if (!cachefile.exists())
66008556 {
6601
- // cache to disk
6602
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6603
- //buffers[0].
6604
-
6605
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6606
- int[] pixels = new int[bytebuf.capacity()/3];
6607
-
6608
- // squared size heuristic...
6609
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
66108558 {
6611
- for (int i=pixels.length; --i>=0;)
6612
- {
6613
- int i3 = i*3;
6614
- pixels[i] = 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6617
- pixels[i] <<= 8;
6618
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6619
- pixels[i] <<= 8;
6620
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6621
- }
6622
-
6623
- /*
6624
- int r=0,g=0,b=0,a=0;
6625
- for (int i=0; i<width; i++)
6626
- for (int j=0; j<height; j++)
6627
- {
6628
- int index = j*width+i;
6629
- int p = pixels[index];
6630
- a = ((p>>24) & 0xFF);
6631
- r = ((p>>16) & 0xFF);
6632
- g = ((p>>8) & 0xFF);
6633
- b = (p & 0xFF);
6634
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6635
- }
6636
- /**/
6637
- int width = (int)Math.sqrt(pixels.length); // squared
6638
- int height = width;
6639
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6640
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
66418561 ImageWriter writer = null;
66428562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66438563 if (iter.hasNext()) {
66448564 writer = (ImageWriter)iter.next();
66458565 }
6646
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
66478568 try
66488569 {
66498570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6660,18 +8581,20 @@
66608581 }
66618582 }
66628583 }
6663
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
66648587 //System.out.println("Texture = " + tex);
6665
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
66668589 {
6667
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
66688591 thetex.texture.disable();
66698592 thetex.texture.dispose();
6670
- textures.remove(texname);
8593
+ textures.remove(tex);
66718594 }
66728595
6673
- texture.texturedata = texturedata;
6674
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
66758598
66768599 // newtex = true;
66778600 }
....@@ -6687,10 +8610,44 @@
66878610 }
66888611 }
66898612
6690
- return texture;
8613
+ return texturecache;
66918614 }
66928615
6693
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), 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
66948651 {
66958652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66968653
....@@ -6708,21 +8665,21 @@
67088665 return texture!=null?texture.texture:null;
67098666 }
67108667
6711
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67128669 {
67138670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67148671
67158672 return texture!=null?texture.texturedata:null;
67168673 }
67178674
6718
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67198676 {
67208677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67218678 {
67228679 return false;
67238680 }
67248681
6725
- boolean newtex = false;
8682
+ //boolean newtex = false;
67268683
67278684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67288685
....@@ -6754,9 +8711,75 @@
67548711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67558712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67568713
6757
- return newtex;
8714
+ return true; // Warning: not used.
67588715 }
67598716
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
+
67608783 ShadowBuffer shadowPBuf;
67618784 AntialiasBuffer antialiasPBuf;
67628785 int MAXSTACK;
....@@ -6773,10 +8796,12 @@
67738796
67748797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67758798 MAXSTACK = temp[0];
6776
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67778801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67788802 MAXSTACK = temp[0];
6779
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67808805
67818806 // Use debug pipeline
67828807 //drawable.setGL(new DebugGL(gl)); //
....@@ -6784,7 +8809,8 @@
67848809 gl = drawable.getGL(); //
67858810
67868811 GL gl3 = getGL();
6787
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67888814
67898815
67908816 //float pos[] = { 100, 100, 100, 0 };
....@@ -6949,7 +8975,7 @@
69498975
69508976 if (cubemap == null)
69518977 {
6952
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
69538979 }
69548980
69558981 //cubemap.enable();
....@@ -7225,6 +9251,8 @@
72259251
72269252 void LoadEnvy(int which)
72279253 {
9254
+ assert(false);
9255
+
72289256 String name;
72299257 String ext;
72309258
....@@ -7236,37 +9264,58 @@
72369264 cubemap = null;
72379265 return;
72389266 case 1:
7239
- name = "cubemaps/box_";
7240
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
72419269 reverseUP = false;
72429270 break;
72439271 case 2:
7244
- name = "cubemaps/uffizi_";
7245
- ext = "png";
7246
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
72479276 case 3:
7248
- name = "cubemaps/CloudyHills_";
7249
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
72509279 reverseUP = false;
72519280 break;
72529281 case 4:
7253
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
72549283 ext = "png";
72559284 reverseUP = false;
72569285 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;
72579311 default:
7258
- name = "cubemaps/rgb_";
7259
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
72609315 break;
72619316 }
7262
-
7263
- try
7264
- {
7265
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7266
- } catch (IOException e)
7267
- {
7268
- throw new RuntimeException(e);
7269
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
72709319 }
72719320
72729321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7298,8 +9347,12 @@
72989347 static double[] model = new double[16];
72999348 double[] camera2light = new double[16];
73009349 double[] light2camera = new double[16];
7301
- int newenvy = -1;
7302
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
73039356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73049357 //float[] light0 = { 0,0,0 };
73059358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7312,9 +9365,9 @@
73129365 static boolean occlusionInitialized = false;
73139366 boolean selection = false;
73149367 boolean pointselection = false;
7315
- /*static*/ boolean lighttouched = true;
9368
+ ///*static*/ boolean lighttouched = true;
73169369 boolean deselect;
7317
- boolean ambientOcclusion = false;
9370
+ private boolean ambientOcclusion = false;
73189371 static boolean flash = false;
73199372 /*static*/ boolean wait = false;
73209373 boolean displaydone = false; // after repaint() calls
....@@ -7444,6 +9497,8 @@
74449497 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74459498 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74469499 double scale = lightCamera.SCALE / lightCamera.Distance();
9500
+// PATCH FILLE AUX JEANS
9501
+ //scale *= lightCamera.shaper_fovy / 25;
74479502 gl.glScaled(2 * scale, 2 * scale, -scale);
74489503 gl.glTranslated(0, 0, lightCamera.DECAL);
74499504
....@@ -7590,18 +9645,40 @@
75909645 jy8[3] = 0.5f;
75919646 }
75929647
7593
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75949649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
75959650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
75969651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75979652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
75989677 static int imagecount = 0; // movie generation
75999678
76009679 static int jitter = 0;
76019680
76029681 boolean restartframe = false;
7603
-
7604
- static int framecount = 0; // general-purpose global count
76059682
76069683 void displayAntiAliased(javax.media.opengl.GL gl)
76079684 {
....@@ -7633,7 +9710,7 @@
76339710 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76349711 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76359712 {
7636
- framecount++;
9713
+ Globals.framecount++;
76379714
76389715 if (CameraPane.tickcount > 0)
76399716 CameraPane.tickcount--;
....@@ -7671,7 +9748,7 @@
76719748
76729749 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76739750 */
7674
- lighttouched = true;
9751
+ Globals.lighttouched = true;
76759752 //System.err.println(" shadowbuffer: " + jitter);
76769753 shadowbuffer.display();
76779754
....@@ -7692,8 +9769,8 @@
76929769 assert (parentcam != renderCamera);
76939770
76949771 if (renderCamera != lightCamera)
7695
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7696
- LA.matConcat(parentcam.toParent, matrix, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76979774
76989775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76999776
....@@ -7708,8 +9785,8 @@
77089785 LA.matCopy(renderCamera.fromScreen, matrix);
77099786
77109787 if (renderCamera != lightCamera)
7711
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7712
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77139790
77149791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77159792
....@@ -7755,10 +9832,12 @@
77559832 rati = 1 / rati;
77569833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77579834 }
7758
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
77599838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77609839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7761
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
77629841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77639842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77649843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7781,7 +9860,7 @@
77819860 //gl.glFlush();
77829861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77839862
7784
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
77859864 {
77869865 System.err.println(" ABORTED FRAME");
77879866 break;
....@@ -7811,7 +9890,7 @@
78119890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78129891
78139892 // save image
7814
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
78159894 {
78169895 VPwidth = viewport[2];
78179896 VPheight = viewport[3];
....@@ -7922,11 +10001,11 @@
792210001
792310002 // imagecount++;
792410003
7925
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
10004
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
792610005
792710006 if (!BOXMODE)
792810007 {
7929
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
10008
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
793010009 }
793110010
793210011 if (!BOXMODE)
....@@ -7964,7 +10043,7 @@
796410043 ABORTED = false;
796510044 }
796610045 else
7967
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
796810047
796910048 if (false)
797010049 {
....@@ -8618,32 +10697,34 @@
861810697 }
861910698 }
862010699
8621
- boolean IsFrozen()
8622
- {
8623
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8624
-
8625
- return !selectmode && cameracount == 0; // != 0;
8626
- }
8627
-
862810700 boolean niceon = false;
862910701 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
863010702 boolean currentlydrawing = false;
863110703 static boolean init = false;
863210704
863310705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
863410709
863510710 public void display(GLAutoDrawable drawable)
863610711 {
8637
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
863810713 {
8639
- GrafreeD.wav.save();
8640
- GrafreeD.savesound = false;
8641
- GrafreeD.hassound = false;
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
10718
+ if (Grafreed.savesound && Grafreed.hassound)
10719
+ {
10720
+ Grafreed.wav.save();
10721
+ Grafreed.savesound = false;
10722
+ Grafreed.hassound = false;
864210723 }
864310724 // if (DEBUG_SELECTION)
864410725 // {
8645
-// if (drawMode != SELECTION)
8646
-// drawMode = SELECTION;
10726
+// if (DrawMode() != SELECTION)
10727
+// DrawMode() = SELECTION;
864710728 // }
864810729
864910730 if (!isRenderer)
....@@ -8699,9 +10780,9 @@
869910780
870010781 //ANTIALIAS = 0;
870110782
8702
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10783
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870310784 {
8704
- if (niceon || isLIVE())
10785
+ if (niceon || Globals.isLIVE())
870510786 {
870610787 //if(active == 0)
870710788 // antialiaser = null;
....@@ -8714,6 +10795,7 @@
871410795 ANTIALIAS = 0;
871510796 //System.out.println("RESTART");
871610797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
871710799 }
871810800 }
871910801 }
....@@ -8726,7 +10808,7 @@
872610808 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872710809 */
872810810
8729
- if (drawMode == DEFAULT)
10811
+ if (DrawMode() == DEFAULT)
873010812 {
873110813 currentlydrawing = true;
873210814 }
....@@ -8757,18 +10839,18 @@
875710839
875810840 // if(Applet3D.clipboard != null)
875910841 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8760
-//drawMode = SELECTION;
10842
+//DrawMode() = SELECTION;
876110843 indexcount = 0;
876210844
8763
- if (drawMode == OCCLUSION)
10845
+ if (DrawMode() == OCCLUSION)
876410846 {
8765
- drawMode = DEFAULT;
10847
+ Globals.drawMode = DEFAULT; // WARNING
876610848 ambientOcclusion = true;
876710849 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876810850 Object3D theobject = object;
876910851 Object3D theparent = object.parent;
877010852 object.parent = null;
8771
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
877210854 object.Stripify();
877310855 if (theobject.selection == null || theobject.selection.Size() == 0)
877410856 theobject.PreprocessOcclusion(this);
....@@ -8781,26 +10863,27 @@
878110863 ambientOcclusion = false;
878210864 }
878310865
8784
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878510868 {
878610869 //if (RENDERSHADOW) // ?
878710870 if (!IsFrozen())
878810871 {
878910872 // dec 2012
8790
- if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
879110874 {
8792
- framecount++;
10875
+ Globals.framecount++;
879310876 shadowbuffer.display();
879410877 }
879510878 }
8796
- lighttouched = false; // ??
10879
+ Globals.lighttouched = false; // ??
879710880 //drawing = true;
879810881 //lighttouched = true;
879910882 }
880010883
880110884 if (wait)
880210885 {
8803
- Sleep(500);
10886
+ Sleep(200); // blocks everything
880410887
880510888 wait = false;
880610889 }
....@@ -8814,9 +10897,9 @@
881410897 //eyeCamera.shaper_fovy = 1;
881510898 }
881610899
8817
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10900
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881810901 {
8819
- //System.out.println("drawMode = " + drawMode);
10902
+ //System.out.println("DrawMode() = " + DrawMode());
882010903 vertexMode |= VP_PASS;
882110904 //vertexMode |= VP_PROJECTION;
882210905 if (!ambientOcclusion)
....@@ -8876,7 +10959,7 @@
887610959 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887710960 //Camera lightcam = new Camera(light0);
887810961
8879
- if (drawMode == SHADOW)
10962
+ if (DrawMode() == SHADOW)
888010963 {
888110964 /*
888210965 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8914,8 +10997,8 @@
891410997
891510998 // if (parentcam != renderCamera) // not a light
891610999 if (cam != lightCamera)
8917
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8918
- LA.matConcat(parentcam.toParent, matrix, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891911002
892011003 for (int j = 0; j < 4; j++)
892111004 {
....@@ -8929,8 +11012,8 @@
892911012
893011013 // if (parentcam != renderCamera) // not a light
893111014 if (cam != lightCamera)
8932
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8933
- LA.matConcat(matrix, parentcam.fromParent, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893411017
893511018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893611019
....@@ -8966,7 +11049,7 @@
896611049 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896711050 } else
896811051 {
8969
- if (drawMode != DEFAULT)
11052
+ if (DrawMode() != DEFAULT)
897011053 {
897111054 gl.glClearColor(1, 1, 1, 0);
897211055 } // 1);
....@@ -9016,13 +11099,43 @@
901611099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901711100 }
901811101
9019
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
902011110 {
9021
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
902211117 }
9023
-
9024
- newenvy = -1;
9025
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
902611139 ratio = ((double) getWidth()) / getHeight();
902711140 //System.out.println("ratio = " + ratio);
902811141
....@@ -9031,14 +11144,14 @@
903111144
903211145 fast &= !ambientOcclusion;
903311146
9034
- if (drawMode == DEFAULT)
11147
+ if (DrawMode() == DEFAULT)
903511148 {
903611149 //gl.glEnable(gl.GL_ALPHA_TEST);
903711150 //gl.glActiveTexture(GL.GL_TEXTURE0);
903811151
903911152 if (!IsFrozen() && !ambientOcclusion)
904011153 {
9041
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
904211155 }
904311156
904411157 //if (selection_view == -1)
....@@ -9092,6 +11205,8 @@
909211205 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909311206 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909411207 double scale = lightCamera.SCALE / lightCamera.Distance();
11208
+// PATCH FILLE AUX JEANS
11209
+ //scale *= lightCamera.shaper_fovy / 25;
909511210 gl.glScaled(2 * scale, 2 * scale, -scale);
909611211 gl.glTranslated(0, 0, lightCamera.DECAL);
909711212
....@@ -9187,7 +11302,16 @@
918711302 // Bump noise
918811303 gl.glActiveTexture(GL.GL_TEXTURE6);
918911304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9190
- BindTexture(NOISE_TEXTURE, false, 2);
11305
+
11306
+ try
11307
+ {
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
11309
+ }
11310
+ catch (Exception e)
11311
+ {
11312
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11313
+ }
11314
+
919111315
919211316 gl.glActiveTexture(GL.GL_TEXTURE0);
919311317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9210,9 +11334,9 @@
921011334
921111335 gl.glMatrixMode(GL.GL_MODELVIEW);
921211336
9213
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9214
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9215
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
921611340 } else
921711341 {
921811342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9223,14 +11347,16 @@
922311347 //System.out.println("BLENDING ON");
922411348 gl.glEnable(GL.GL_BLEND);
922511349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9226
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922711351 gl.glMatrixMode(gl.GL_PROJECTION);
922811352 gl.glLoadIdentity();
922911353
9230
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11354
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
923111355 {
923211356 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923311357 double scale = lightCamera.SCALE / lightCamera.Distance();
11358
+// PATCH FILLE AUX JEANS
11359
+ //scale *= lightCamera.shaper_fovy / 25;
923411360 gl.glScaled(2 * scale, 2 * scale, -scale);
923511361 gl.glTranslated(0, 0, lightCamera.DECAL);
923611362 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9283,7 +11409,7 @@
928311409 //gl.glPushMatrix();
928411410 gl.glLoadIdentity();
928511411
9286
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11412
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928711413 {
928811414 //LA.xformPos(light0, lightCamera.fromScreen, light);
928911415 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9310,8 +11436,8 @@
931011436 System.err.println("parentcam != renderCamera");
931111437
931211438 // if (cam != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
931511441 }
931611442
931711443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9332,8 +11458,8 @@
933211458 if (true) // TODO
933311459 {
933411460 if (cam != lightCamera)
9335
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9336
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933711463 }
933811464
933911465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9370,7 +11496,7 @@
937011496 }
937111497
937211498 /**/
9373
- if (true) // drawMode == SELECTION) // != DEFAULT)
11499
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937411500 gl.glDisable(gl.GL_LIGHTING);
937511501 else
937611502 gl.glEnable(gl.GL_LIGHTING);
....@@ -9388,7 +11514,7 @@
938811514
938911515 lightslot = 64;
939011516
9391
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11517
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
939211518 {
939311519 DrawLights(object);
939411520 }
....@@ -9399,7 +11525,7 @@
939911525 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
940011526 //System.out.println("fragmentMode = " + fragmentMode);
940111527
9402
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11528
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
940311529 {
940411530 /*
940511531 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9432,7 +11558,7 @@
943211558 }
943311559 }
943411560
9435
- if (drawMode == DEFAULT)
11561
+ if (DrawMode() == DEFAULT)
943611562 {
943711563 if (WIREFRAME && !ambientOcclusion)
943811564 {
....@@ -9450,7 +11576,7 @@
945011576 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
945111577 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
945211578
9453
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11579
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945411580 {
945511581 if (vertexMode != 0) // && !fast)
945611582 {
....@@ -9470,7 +11596,7 @@
947011596 }
947111597 }
947211598
9473
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947411600 {
947511601 //gl.glDepthFunc(GL.GL_LEQUAL);
947611602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9478,27 +11604,24 @@
947811604
947911605 boolean texon = textureon;
948011606
9481
- if (RENDERPROGRAM > 0)
9482
- {
9483
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9484
- textureon = false;
9485
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
948611610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948711611 //System.out.println("ALLO");
948811612 gl.glColorMask(false, false, false, false);
948911613 DrawObject(gl);
9490
- if (RENDERPROGRAM > 0)
9491
- {
9492
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9493
- textureon = texon;
9494
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
949511618 gl.glColorMask(true, true, true, true);
949611619
949711620 gl.glDepthFunc(GL.GL_EQUAL);
9498
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
949911622 }
950011623
9501
- if (false) // drawMode == SHADOW)
11624
+ if (false) // DrawMode() == SHADOW)
950211625 {
950311626 //SetColumnMajorData(cameraInverseTransform, view_1);
950411627 //System.out.println("light = " + cameraInverseTransform);
....@@ -9512,16 +11635,16 @@
951211635 //System.out.println("object = " + object);
951311636 if (!frozen && !imageLocked)
951411637 {
9515
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11638
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951611639 {
951711640 displayAntiAliased(gl);
951811641 } else
951911642 {
952011643 programcount = 0;
9521
- int keepmode = drawMode;
11644
+ int keepmode = DrawMode();
952211645 // if (DEBUG_SELECTION)
952311646 // {
9524
-// drawMode = SELECTION;
11647
+// DrawMode() = SELECTION;
952511648 // }
952611649 // for point selection
952711650 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9531,10 +11654,10 @@
953111654 DrawObject(gl);
953211655
953311656 // jan 2013 System.err.println("RESET ABORT (display)");
9534
- // if (drawMode == DEFAULT)
11657
+ // if (DrawMode() == DEFAULT)
953511658 // ABORTED = false;
953611659 fullreset = false;
9537
- drawMode = keepmode;
11660
+ Globals.drawMode = keepmode; // WARNING
953811661 //System.out.println("PROGRAM SWITCH " + programcount);
953911662 }
954011663 }
....@@ -9542,11 +11665,11 @@
954211665 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
954311666 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954411667
9545
- if (drawMode == DEFAULT)
11668
+ if (DrawMode() == DEFAULT)
954611669 {
954711670 ReleaseTexture(NOISE_TEXTURE, false);
954811671 }
9549
- //if (drawMode == DEFAULT)
11672
+ //if (DrawMode() == DEFAULT)
955011673 {
955111674
955211675 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9558,7 +11681,7 @@
955811681 //else
955911682 //gl.glDisable(gl.GL_TEXTURE_2D);
956011683 //gl.glPopMatrix();
9561
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11684
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
956211685 {
956311686 //new Exception().printStackTrace();
956411687 //System.out.println("Draw image " + width + ", " + height);
....@@ -9600,7 +11723,7 @@
960011723 //gl.glFlush();
960111724 }
960211725
9603
- if (flash && drawMode == DEFAULT)
11726
+ if (flash && DrawMode() == DEFAULT)
960411727 {
960511728 flash = false;
960611729 wait = true;
....@@ -9608,9 +11731,9 @@
960811731 }
960911732
961011733 //drawing = false;
9611
- //if(drawMode == DEFAULT)
11734
+ //if(DrawMode() == DEFAULT)
961211735 // niceon = false;
9613
- if (drawMode == DEFAULT)
11736
+ if (DrawMode() == DEFAULT)
961411737 {
961511738 currentlydrawing = false;
961611739 }
....@@ -9630,7 +11753,7 @@
963011753 repaint();
963111754 }
963211755
9633
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11756
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963411757 repaint();
963511758
963611759 displaydone = true;
....@@ -9649,8 +11772,14 @@
964911772 {
965011773 renderpass++;
965111774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
965211776 if (FAST) // in case there is no script
9653
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
965411783
965511784 //object.FullInvariants();
965611785
....@@ -9664,23 +11793,44 @@
966411793 e.printStackTrace();
966511794 }
966611795
9667
- if (GrafreeD.RENDERME > 0)
9668
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
966911798
9670
- ONESTEP = false;
11799
+ Globals.ONESTEP = false;
967111800 }
967211801
967311802 static boolean zoomonce = false;
967411803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
967511822 void DrawObject(GL gl, boolean draw)
967611823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
967711827 //System.out.println("DRAW OBJECT " + mouseDown);
9678
-// drawMode = SELECTION;
11828
+// DrawMode() = SELECTION;
967911829 //GL gl = getGL();
968011830 if ((TRACK || SHADOWTRACK) || zoomonce)
968111831 {
9682
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9683
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11832
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968411834 pingthread.StepToTarget(true); // true);
968511835 // zoomonce = false;
968611836 }
....@@ -9700,9 +11850,9 @@
970011850 callist = gl.glGenLists(1);
970111851 }
970211852
9703
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11853
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970411854
9705
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11855
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970611856
970711857 if (!mainDL || !active || touched)
970811858 {
....@@ -9729,13 +11879,20 @@
972911879 PushMatrix(ClickInfo.matbuffer);
973011880 }
973111881
9732
- if (drawMode == 0)
11882
+ if (DrawMode() == 0)
973311883 {
973411884 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973511885
973611886 usedtextures.clear();
973711887
9738
- BindTextures(DEFAULT_TEXTURES, 2);
11888
+ try
11889
+ {
11890
+ BindTextures(DEFAULT_TEXTURES, 2);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11895
+ }
973911896 }
974011897 //System.out.println("--> " + stackdepth);
974111898 // GrafreeD.traceon();
....@@ -9743,10 +11900,11 @@
974311900 // DRAW
974411901 object.draw(this, /*(Composite)*/ object, false, false);
974511902
9746
- if (drawMode == DEFAULT)
11903
+ if (DrawMode() == DEFAULT)
974711904 {
9748
- if (DEBUG)
11905
+ if (Globals.DEBUG)
974911906 {
11907
+ CreateSelectedPoint();
975011908 float radius = 0.05f;
975111909 if (selectedpoint.radius != radius)
975211910 {
....@@ -9754,40 +11912,40 @@
975411912 selectedpoint.radius = radius;
975511913 selectedpoint.recalculate();
975611914 selectedpoint.material = new cMaterial();
9757
- selectedpoint.material.color = 0.25f;
11915
+ selectedpoint.material.color = 0.15f; // Yellow
975811916 selectedpoint.material.modulation = 0.75f;
975911917
9760
- debugpoint.radius = radius;
9761
- debugpoint.recalculate();
9762
- debugpoint.material = new cMaterial();
9763
- debugpoint.material.color = 0.25f;
9764
- debugpoint.material.modulation = 0.75f;
11918
+ debugpointG.radius = radius;
11919
+ debugpointG.recalculate();
11920
+ debugpointG.material = new cMaterial();
11921
+ debugpointG.material.color = 0.25f; // Green
11922
+ debugpointG.material.modulation = 0.75f;
976511923
9766
- debugpoint2.radius = radius;
9767
- debugpoint2.recalculate();
9768
- debugpoint2.material = new cMaterial();
9769
- debugpoint2.material.color = 0.75f;
9770
- debugpoint2.material.modulation = 0.75f;
11924
+ debugpointP.radius = radius;
11925
+ debugpointP.recalculate();
11926
+ debugpointP.material = new cMaterial();
11927
+ debugpointP.material.color = 0.75f; // Purple
11928
+ debugpointP.material.modulation = 0.75f;
977111929
9772
- debugpoint3.radius = radius;
9773
- debugpoint3.recalculate();
9774
- debugpoint3.material = new cMaterial();
9775
- debugpoint3.material.color = 0.5f;
9776
- debugpoint3.material.modulation = 0.75f;
11930
+ debugpointC.radius = radius;
11931
+ debugpointC.recalculate();
11932
+ debugpointC.material = new cMaterial();
11933
+ debugpointC.material.color = 0.5f; // Cyan
11934
+ debugpointC.material.modulation = 0.75f;
977711935
9778
- debugpoint4.radius = radius;
9779
- debugpoint4.recalculate();
9780
- debugpoint4.material = new cMaterial();
9781
- debugpoint4.material.color = 0f;
9782
- debugpoint4.material.modulation = 0.75f;
11936
+ debugpointR.radius = radius;
11937
+ debugpointR.recalculate();
11938
+ debugpointR.material = new cMaterial();
11939
+ debugpointR.material.color = 0f; // Red
11940
+ debugpointR.material.modulation = 0.75f;
978311941
978411942 InitPoints(radius);
978511943 }
978611944 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9787
- debugpoint.draw(this, /*(Composite)*/ null, false,false);
9788
- debugpoint2.draw(this, /*(Composite)*/ null, false,false);
9789
- debugpoint3.draw(this, /*(Composite)*/ null, false,false);
9790
- debugpoint4.draw(this, /*(Composite)*/ null, false,false);
11945
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11946
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11947
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11948
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
979111949 // DrawPoints(this);
979211950 }
979311951
....@@ -9795,42 +11953,63 @@
979511953 }
979611954 // GrafreeD.traceoff();
979711955 //System.out.println(stackdepth);
9798
- if (drawMode == 0)
11956
+ if (DrawMode() == 0)
979911957 {
980011958 ReleaseTextures(DEFAULT_TEXTURES);
980111959
980211960 if (CLEANCACHE)
9803
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
980411962 {
9805
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
980611964
980711965 // System.out.println("Texture --------- " + tex);
980811966
9809
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
981011968 continue;
981111969
9812
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
981311971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
981411973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9815
- textures.get(tex).texture.dispose();
9816
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
981711987 }
981811988 }
981911989 }
982011990
982111991 checker = null;
982211992
9823
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11993
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
982411994 FindChecker(object);
982511995
9826
- if (checker != null && drawMode == DEFAULT)
11996
+ if (checker != null && DrawMode() == DEFAULT)
982711997 {
9828
- // BindTexture(IMMORTAL_TEXTURE);
11998
+ //BindTexture(IMMORTAL_TEXTURE);
11999
+ try
12000
+ {
12001
+ BindTextures(checker.GetTextures(), checker.texres);
12002
+ }
12003
+ catch (Exception e)
12004
+ {
12005
+ System.err.println("FAILED: " + checker.GetTextures());
12006
+ }
982912007 // NEAREST
983012008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
983112009 DrawChecker(gl);
983212010 //checker.Draw(this, null, false);
983312011 // ReleaseTexture(IMMORTAL_TEXTURE);
12012
+ ReleaseTextures(checker.GetTextures());
983412013 }
983512014
983612015 if (object.parent != null)
....@@ -9843,7 +12022,7 @@
984312022 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
984412023 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
984512024
9846
- if (DISPLAYTEXT && drawMode == DEFAULT)
12025
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
984712026 {
984812027 // Draw it once, then use the raster
984912028 Balloon(gl, balloon.createGraphics());
....@@ -9899,14 +12078,14 @@
989912078 int[] xs = new int[3];
990012079 int[] ys = new int[3];
990112080
9902
- void DrawString(Object3D obj) // String string)
12081
+ public void DrawString(Object3D obj) // String string) // INTERFACE
990312082 {
9904
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12083
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
990512084 {
990612085 return;
990712086 }
990812087
9909
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
991012089
991112090 GL gl = GetGL();
991212091
....@@ -10223,8 +12402,8 @@
1022312402 //obj.TransformToWorld(light, light);
1022412403 for (int i = tp.size(); --i >= 0;)
1022512404 {
10226
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10227
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1022812407 }
1022912408
1023012409
....@@ -10241,8 +12420,8 @@
1024112420 parentcam = cameras[0];
1024212421 }
1024312422
10244
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10245
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1024612425
1024712426 LA.xformPos(light, renderCamera.toScreen, light);
1024812427
....@@ -10332,8 +12511,76 @@
1033212511
1033312512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1033412513
10335
- String program =
12514
+ String programmin =
12515
+ // Min shader
1033612516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1033712584 //"OPTION ARB_fragment_program_shadow;" +
1033812585 "PARAM light2cam0 = program.env[10];" +
1033912586 "PARAM light2cam1 = program.env[11];" +
....@@ -10359,7 +12606,7 @@
1035912606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1036012607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1036112608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
10362
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1036312610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1036412611 "PARAM options1 = program.env[62];" + // fog rgb color
1036512612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -10388,6 +12635,7 @@
1038812635 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1038912636 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1039012637 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12638
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1039112639 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1039212640 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1039312641 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10447,8 +12695,7 @@
1044712695 "TEMP shininess;" +
1044812696 "\n" +
1044912697 "MOV texSamp, one;" +
10450
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10451
-
12698
+
1045212699 "MOV mapgrid.x, one2048th.x;" +
1045312700 "MOV temp, fragment.texcoord[1];" +
1045412701 /*
....@@ -10469,20 +12716,20 @@
1046912716 "MUL temp, floor, mapgrid.x;" +
1047012717 //"TEX depth0, temp, texture[1], 2D;" +
1047112718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10472
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1047312720 "") +
1047412721 "ADD temp.x, temp.x, mapgrid.x;" +
1047512722 //"TEX depth1, temp, texture[1], 2D;" +
1047612723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10477
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1047812725 "") +
1047912726 "ADD temp.y, temp.y, mapgrid.x;" +
1048012727 //"TEX depth2, temp, texture[1], 2D;" +
10481
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1048212729 "SUB temp.x, temp.x, mapgrid.x;" +
1048312730 //"TEX depth3, temp, texture[1], 2D;" +
1048412731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10485
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1048612733 "") +
1048712734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1048812735 //"MOV params, material;" +
....@@ -10604,7 +12851,7 @@
1060412851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1060512852 // mar 2013 ??? "KIL alpha.a;" +
1060612853 "MOV alpha, texSamp.aaaa;" + // y;" +
10607
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1060812855 /*
1060912856 "MUL temp.xy, temp, two;" +
1061012857 "TXB bump, temp, texture[0], 2D;" +
....@@ -10690,11 +12937,6 @@
1069012937 "SUB bump0, bump0, half;" +
1069112938 "ADD bump, bump, bump0;" +
1069212939
10693
- "MOV temp.x, texSamp.a;" +
10694
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
10695
- //"LRP texSamp0, params5.x, texSamp0, one;" +
10696
- "MOV texSamp.a, temp.x;" +
10697
-
1069812940 // double-sided
1069912941 /**/
1070012942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -10711,19 +12953,62 @@
1071112953 "MOV normald, normal;" +
1071212954 "MOV normals, normal;" +
1071312955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1071412958 // UV base
1071512959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1071612960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1071712961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
10718
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
10719
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
10720
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1072112967 "XPD V, normal, UP;" +
1072212968 Normalize("V") +
1072312969 "XPD U, V, normal;" +
1072412970 Normalize("U") +
1072512971
1072612972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1072713012
1072813013 //"MOV temp, fragment.texcoord[0];" +
1072913014 //
....@@ -10853,10 +13138,10 @@
1085313138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1085413139 "") +
1085513140
10856
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1085713142 "SUB temp.x, half.x, shadow.x;" +
10858
- "MOV temp.y, -params6.x;" +
10859
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1086013145 "SUB temp.y, one.x, temp.z;" +
1086113146 "MUL temp.x, temp.x, temp.y;" +
1086213147 "KIL temp.x;" +
....@@ -10985,8 +13270,10 @@
1098513270 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1098613271
1098713272 "SUB temp.x, one.x, ndotl.x;" +
10988
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
10989
- "ADD temp.y, one.y, options2.y;" + // sursurface
13273
+ // Tuning for default skin
13274
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13275
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13276
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1099013277 "MUL temp.x, temp.x, temp.y;" +
1099113278
1099213279 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11185,8 +13472,19 @@
1118513472 //once = true;
1118613473 }
1118713474
11188
- System.out.print("Program #" + mode + "; length = " + program.length());
11189
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1119013488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1119113489
1119213490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11233,7 +13531,8 @@
1123313531 "\n" +
1123413532 "END\n";
1123513533
11236
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1123713536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1123813537
1123913538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11278,30 +13577,32 @@
1127813577 return out;
1127913578 }
1128013579
11281
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1128213582 {
1128313583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1128413584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1128513585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1128613588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11287
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11288
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11289
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11290
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1129113591 //"SWZ buffer, temp, w,w,w,w;";
11292
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1129313593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1129413594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1129513595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11296
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1129713597
11298
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11299
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130013600 }
1130113601
1130213602 String Shadow(String depth, String shadow)
1130313603 {
1130413604 return "MAX temp.x, ndotl.x, one64th.x;" +
13605
+ "MIN temp.x, temp.x, ninetenth.x;" +
1130513606 /**/
1130613607 // Sine
1130713608 "MUL temp.y, temp.x, temp.x;" +
....@@ -11317,12 +13618,16 @@
1131713618
1131813619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1131913620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1132013623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1132113624 "SGE temp.y, temp.x, zero.x;" +
11322
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1132313628 "SUB temp.x, one.x, temp.x;" +
1132413629 "MUL " + shadow + ".x, temp.x, temp.y;" +
11325
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1132613631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1132713632
1132813633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11336,6 +13641,10 @@
1133613641 // No shadow for backface
1133713642 "DP3 temp.x, normal, lightd;" +
1133813643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13644
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13645
+
13646
+ // No shadow when out of frustum
13647
+ "SGE temp.x, " + depth + ".z, one.z;" +
1133913648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1134013649 "";
1134113650 }
....@@ -11481,8 +13790,9 @@
1148113790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1148213791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1148313792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
11484
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11485
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1148613796
1148713797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1148813798 // OUT : diff, spec
....@@ -11498,9 +13808,10 @@
1149813808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1149913809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1150013810 //"MOV " + dest + ".w," + "normal.z;" +
11501
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11502
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11503
- //"MOV " + dest + ".z," + "params2.w;" +
13811
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13812
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13813
+
13814
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1150413815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1150513816 "RCP " + dest + ".w," + dest + ".w;" +
1150613817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11646,7 +13957,7 @@
1164613957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1164713958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1164813959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
11649
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1165013961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1165113962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1165213963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -11707,7 +14018,7 @@
1170714018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1170814019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1170914020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
11710
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1171114022 "MOV result.texcoord, temp;" +
1171214023 // border fade
1171314024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -11754,7 +14065,9 @@
1175414065
1175514066 //"ADD temp.z, temp.z, one;" +
1175614067
11757
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1175814071 : "MOV result.color, vertex.color;") +
1175914072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1176014073 : "") +
....@@ -11894,7 +14207,7 @@
1189414207 public void mousePressed(MouseEvent e)
1189514208 {
1189614209 //System.out.println("mousePressed: " + e);
11897
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1189814211 }
1189914212
1190014213 static long prevtime = 0;
....@@ -11921,14 +14234,16 @@
1192114234
1192214235 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1192314236
14237
+ if (BUTTONLESSWHEEL)
1192414238 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1192514239 {
1192614240 return;
1192714241 }
1192814242
14243
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1192914244
1193014245 // TIMER
11931
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14246
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1193214247 {
1193314248 keepboxmode = BOXMODE;
1193414249 keepsupport = SUPPORT;
....@@ -11968,8 +14283,8 @@
1196814283 // mode |= META;
1196914284 //}
1197014285
11971
- SetMouseMode(WHEEL | e.getModifiersEx());
11972
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1197314288 anchorX = ax;
1197414289 anchorY = ay;
1197514290 prevX = px;
....@@ -12003,6 +14318,7 @@
1200314318 else
1200414319 if (evt.getSource() == AAtimer)
1200514320 {
14321
+ Globals.TIMERRUNNING = false;
1200614322 if (mouseDown)
1200714323 {
1200814324 //new Exception().printStackTrace();
....@@ -12028,6 +14344,10 @@
1202814344 // LIVE = waslive;
1202914345 // wasliveok = true;
1203014346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1203114351
1203214352 // source == timer
1203314353 if (mouseDown)
....@@ -12057,8 +14377,8 @@
1205714377 // ObjEditor.tweenManager.update(1f / 60f);
1205814378
1205914379 // fev 2014???
12060
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12061
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14380
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1206214382 pingthread.StepToTarget(true); // true);
1206314383 }
1206414384 // if (!LIVE)
....@@ -12067,12 +14387,13 @@
1206714387
1206814388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1206914389
12070
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1207114391 {
1207214392 if (!wasliveok)
1207314393 return;
1207414394
1207514395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1207614397
1207714398 // waslive = LIVE;
1207814399 // LIVE = false;
....@@ -12084,7 +14405,7 @@
1208414405 // touched = true; // main DL
1208514406 if (isRenderer)
1208614407 {
12087
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1208814409 }
1208914410
1209014411 selectX = anchorX = x;
....@@ -12097,7 +14418,7 @@
1209714418 clicked = true;
1209814419 hold = false;
1209914420
12100
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1210114422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1210214423 {
1210314424 // System.out.println("RESTART II " + modifiers);
....@@ -12122,14 +14443,15 @@
1212214443 drag = false;
1212314444 //System.out.println("Mouse DOWN");
1212414445 editObj = false;
12125
- ClickInfo info = new ClickInfo();
12126
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12127
- info.pane = this;
12128
- info.camera = renderCamera;
12129
- info.x = x;
12130
- info.y = y;
12131
- info.modifiers = modifiers;
12132
- editObj = object.doEditClick(info, 0);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1213314455 if (!editObj)
1213414456 {
1213514457 hasMarquee = true;
....@@ -12145,11 +14467,14 @@
1214514467
1214614468 public void mouseDragged(MouseEvent e)
1214714469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
14472
+ //System.out.println("mouseDragged: " + e);
1214814473 if (isRenderer)
1214914474 movingcamera = true;
14475
+
1215014476 //if (drawing)
1215114477 //return;
12152
- //System.out.println("mouseDragged: " + e);
1215314478 if ((e.getModifiersEx() & CTRL) != 0
1215414479 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1215514480 {
....@@ -12157,7 +14482,7 @@
1215714482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1215814483 }
1215914484 else
12160
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1216114486
1216214487 //try { Thread.sleep(1); } catch (Exception ex) {}
1216314488 }
....@@ -12169,6 +14494,11 @@
1216914494 cVector tmp = new cVector();
1217014495 cVector tmp2 = new cVector();
1217114496 boolean isMoving;
14497
+
14498
+ public cVector TargetLookAt()
14499
+ {
14500
+ return targetLookAt;
14501
+ }
1217214502
1217314503 class PingThread extends Thread
1217414504 {
....@@ -12308,7 +14638,7 @@
1230814638 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1230914639 if (lightMode)
1231014640 {
12311
- lighttouched = true;
14641
+ Globals.lighttouched = true;
1231214642 }
1231314643
1231414644 if (OEILONCE && OEIL)
....@@ -12325,6 +14655,7 @@
1232514655
1232614656 public void run()
1232714657 {
14658
+ new Exception().printStackTrace();
1232814659 System.exit(0);
1232914660 for (;;)
1233014661 {
....@@ -12366,7 +14697,7 @@
1236614697 mouseDown = false;
1236714698 if (lightMode)
1236814699 {
12369
- lighttouched = true;
14700
+ Globals.lighttouched = true;
1237014701 }
1237114702 repaint();
1237214703 alreadypainted = true;
....@@ -12374,7 +14705,7 @@
1237414705 isMoving = false;
1237514706 } //??
1237614707
12377
- if (isLIVE() && !alreadypainted)
14708
+ if (Globals.isLIVE() && !alreadypainted)
1237814709 {
1237914710 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1238014711 repaint();
....@@ -12386,9 +14717,9 @@
1238614717 {
1238714718 if (lightMode)
1238814719 {
12389
- lighttouched = true;
14720
+ Globals.lighttouched = true;
1239014721 }
12391
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1239214723 }
1239314724 //else
1239414725 }
....@@ -12402,12 +14733,18 @@
1240214733 void GoDown(int mod)
1240314734 {
1240414735 MODIFIERS |= COMMAND;
12405
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1240614738 if((mod&SHIFT) == SHIFT)
12407
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1240814745 else
12409
- manipCamera.BackForth(0, -speed*delta, getWidth());
12410
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1241114748 if ((mod & SHIFT) == SHIFT)
1241214749 {
1241314750 mouseMode = mouseMode; // VR??
....@@ -12416,6 +14753,8 @@
1241614753 mouseMode |= BACKFORTH;
1241714754 }
1241814755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1241914758 //prevX = X = anchorX;
1242014759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1242114760 }
....@@ -12423,12 +14762,19 @@
1242314762 void GoUp(int mod)
1242414763 {
1242514764 MODIFIERS |= COMMAND;
12426
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1242714768 if((mod&SHIFT) == SHIFT)
12428
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1242914775 else
12430
- manipCamera.BackForth(0, speed*delta, getWidth());
12431
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1243214778 if ((mod & SHIFT) == SHIFT)
1243314779 {
1243414780 mouseMode = mouseMode;
....@@ -12437,6 +14783,8 @@
1243714783 mouseMode |= BACKFORTH;
1243814784 }
1243914785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1244014788 //prevX = X = anchorX;
1244114789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1244214790 }
....@@ -12444,12 +14792,17 @@
1244414792 void GoLeft(int mod)
1244514793 {
1244614794 MODIFIERS |= COMMAND;
12447
- /*
14795
+ /**/
1244814796 if((mod&SHIFT) == SHIFT)
12449
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1245014798 else
12451
- manipCamera.Translate(speed*delta, 0, getWidth());
12452
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1245314806 if ((mod & SHIFT) == SHIFT)
1245414807 {
1245514808 mouseMode = mouseMode;
....@@ -12458,6 +14811,8 @@
1245814811 mouseMode |= ROTATE;
1245914812 } // TRANSLATE;
1246014813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1246114816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1246214817 prevY = Y = anchorY;
1246314818 }
....@@ -12465,12 +14820,18 @@
1246514820 void GoRight(int mod)
1246614821 {
1246714822 MODIFIERS |= COMMAND;
12468
- /*
14823
+ /**/
1246914824 if((mod&SHIFT) == SHIFT)
12470
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1247114826 else
12472
- manipCamera.Translate(-speed*delta, 0, getWidth());
12473
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1247414835 if ((mod & SHIFT) == SHIFT)
1247514836 {
1247614837 mouseMode = mouseMode;
....@@ -12479,6 +14840,8 @@
1247914840 mouseMode |= ROTATE;
1248014841 } // TRANSLATE;
1248114842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1248214845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1248314846 prevY = Y = anchorY;
1248414847 }
....@@ -12488,7 +14851,7 @@
1248814851 int X, Y;
1248914852 boolean SX, SY;
1249014853
12491
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1249214855 {
1249314856 if (IsFrozen())
1249414857 {
....@@ -12497,17 +14860,17 @@
1249714860
1249814861 drag = true; // NEW
1249914862
12500
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1250114864
1250214865 X = x;
1250314866 Y = y;
1250414867 // floating state for animation
12505
- MODIFIERS = modifiers;
12506
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1250714870 if (false) // modifiers != 0)
1250814871 {
1250914872 //new Exception().printStackTrace();
12510
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1251114874 System.out.println("SHIFT = " + SHIFT);
1251214875 System.out.println("CONTROL = " + COMMAND);
1251314876 System.out.println("META = " + META);
....@@ -12520,14 +14883,16 @@
1252014883 if (editObj)
1252114884 {
1252214885 drag = true;
12523
- ClickInfo info = new ClickInfo();
12524
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1252514888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12526
- info.pane = this;
12527
- info.camera = renderCamera;
12528
- info.x = x;
12529
- info.y = y;
12530
- object.editWindow.copy.doEditDrag(info);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1253114896 } else
1253214897 {
1253314898 if (x < startX)
....@@ -12629,6 +14994,7 @@
1262914994 {
1263014995 manipCamera.Translate(dx, dy, getWidth());
1263114996 }
14997
+ else
1263214998 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1263314999 {
1263415000 manipCamera.RotateInterest(dx, dy);
....@@ -12639,7 +15005,7 @@
1263915005
1264015006 if (manipCamera == lightCamera)
1264115007 {
12642
- lighttouched = true;
15008
+ Globals.lighttouched = true;
1264315009 }
1264415010 /*
1264515011 switch (mode)
....@@ -12675,23 +15041,27 @@
1267515041 }
1267615042 }
1267715043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1267815046 public void mouseMoved(MouseEvent e)
1267915047 {
1268015048 //System.out.println("mouseMoved: " + e);
12681
-
1268215049 if (isRenderer)
1268315050 return;
1268415051
12685
- ClickInfo ci = new ClickInfo();
12686
- ci.x = e.getX();
12687
- ci.y = e.getY();
12688
- ci.modifiers = e.getModifiersEx();
12689
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12690
- ci.pane = this;
12691
- ci.camera = renderCamera;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1269215059 if (!isRenderer)
1269315060 {
12694
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1269515065 {
1269615066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1269715067 } else
....@@ -12703,7 +15073,11 @@
1270315073
1270415074 public void mouseReleased(MouseEvent e)
1270515075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1270615078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1270715081 //System.out.println("mouseReleased: " + e);
1270815082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1270915083 }
....@@ -12726,9 +15100,9 @@
1272615100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1272715101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1272815102
12729
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1273015104 timeout = true;
12731
- else
15105
+// ?? May 2019 else
1273215106 // timer.setDelay((modifiers & 128) != 0?0:350);
1273315107 mouseDown = false;
1273415108 if (!control && !command) // june 2013
....@@ -12838,7 +15212,7 @@
1283815212 System.out.println("keyReleased: " + e);
1283915213 }
1284015214
12841
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1284215216 {
1284315217 //System.out.println("SetMouseMode = " + modifiers);
1284415218 //modifiers &= ~1024;
....@@ -12850,24 +15224,27 @@
1285015224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1285115225 // return;
1285215226 //System.out.println("SetMode = " + modifiers);
12853
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1285415228 {
1285515229 mouseMode |= ZOOM;
1285615230 }
12857
- if ((modifiers & META) == META)
15231
+
15232
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15233
+ if (capsLocked) // || (modifiers & META) == META)
1285815234 {
1285915235 mouseMode |= VR; // BACKFORTH;
1286015236 }
12861
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12862
- {
12863
- mouseMode |= SELECT; // BACKFORTH;
12864
- }
12865
- if ((modifiers & COMMAND) == COMMAND)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1286615238 {
1286715239 mouseMode |= SELECT;
1286815240 }
12869
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
1287015242 {
15243
+ mouseMode |= SELECT;
15244
+ }
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15246
+ {
15247
+ mouseMode &= ~VR;
1287115248 mouseMode |= TRANSLATE;
1287215249 }
1287315250 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12894,10 +15271,10 @@
1289415271
1289515272 if (isRenderer) //
1289615273 {
12897
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1289815275 }
1289915276
12900
- theRenderer.keyPressed(key);
15277
+ Globals.theRenderer.keyPressed(key);
1290115278 }
1290215279
1290315280 int kompactbit = 4; // power bit
....@@ -12909,7 +15286,7 @@
1290915286 float SATPOW = 1; // 2; // 0.5f;
1291015287 float BRIPOW = 1; // 0.5f; // 0.5f;
1291115288
12912
- void keyPressed(int key)
15289
+ public void keyPressed(int key)
1291315290 {
1291415291 if (key >= '0' && key <= '5')
1291515292 clampbit = (key-'0');
....@@ -12956,7 +15333,8 @@
1295615333 // break;
1295715334 case 'T':
1295815335 CACHETEXTURE ^= true;
12959
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1296015338 // repaint();
1296115339 break;
1296215340 case 'Y':
....@@ -12966,8 +15344,8 @@
1296615344 case 'K':
1296715345 KOMPACTTEXTURE ^= true;
1296815346 //textures.clear();
12969
- break;
12970
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1297115349 // SAVETEXTURE ^= true;
1297215350 macromode = true;
1297315351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -13024,7 +15402,7 @@
1302415402 case 'B':
1302515403 BRISMOOTH ^= true;
1302615404 SHADOWCULLFACE ^= true;
13027
- lighttouched = true;
15405
+ Globals.lighttouched = true;
1302815406 repaint();
1302915407 break;
1303015408 case 'b':
....@@ -13041,7 +15419,9 @@
1304115419 case 'E' : COMPACT ^= true;
1304215420 repaint();
1304315421 break;
13044
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1304515425 repaint();
1304615426 break;
1304715427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13066,8 +15446,8 @@
1306615446 RevertCamera();
1306715447 repaint();
1306815448 break;
13069
- case 'L':
1307015449 case 'l':
15450
+ //case 'L':
1307115451 if (lightMode)
1307215452 {
1307315453 lightMode = false;
....@@ -13086,7 +15466,7 @@
1308615466 targetLookAt.set(manipCamera.lookAt);
1308715467 repaint();
1308815468 break;
13089
- case 'p':
15469
+ case 'P': // p':
1309015470 // c'est quoi ca au juste? spherical ^= true;
1309115471 Skinshader ^= true; programInitialized = false;
1309215472 repaint();
....@@ -13124,27 +15504,31 @@
1312415504 repaint();
1312515505 break;
1312615506 case 'O':
13127
- drawMode = OCCLUSION;
15507
+ Globals.drawMode = OCCLUSION; // WARNING
1312815508 repaint();
1312915509 break;
1313015510 case 'o':
1313115511 OCCLUSION_CULLING ^= true;
1313215512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1313315513 break;
13134
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1313515515 case '1':
1313615516 case '2':
1313715517 case '3':
1313815518 case '4':
1313915519 case '5':
13140
- newenvy = Character.getNumericValue(key);
13141
- repaint();
13142
- break;
1314315520 case '6':
1314415521 case '7':
1314515522 case '8':
1314615523 case '9':
13147
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1314815532 repaint();
1314915533 break;
1315015534 case '!':
....@@ -13210,12 +15594,12 @@
1321015594 case '_':
1321115595 kompactbit = 5;
1321215596 break;
13213
- case '+':
13214
- kompactbit = 6;
13215
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1321615600 case ' ':
1321715601 lightMode ^= true;
13218
- lighttouched = true;
15602
+ Globals.lighttouched = true;
1321915603 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1322015604 targetLookAt.set(manipCamera.lookAt);
1322115605 repaint();
....@@ -13224,14 +15608,15 @@
1322415608 case ESC:
1322515609 RENDERPROGRAM += 1;
1322615610 RENDERPROGRAM %= 3;
15611
+
1322715612 repaint();
1322815613 break;
1322915614 case 'Z':
13230
- RESIZETEXTURE ^= true;
13231
- break;
15615
+ //RESIZETEXTURE ^= true;
15616
+ //break;
1323215617 case 'z':
13233
- RENDERSHADOW ^= true;
13234
- lighttouched = true;
15618
+ Globals.RENDERSHADOW ^= true;
15619
+ Globals.lighttouched = true;
1323515620 repaint();
1323615621 break;
1323715622 //case UP:
....@@ -13257,13 +15642,15 @@
1325715642 FlipTransform();
1325815643 break;
1325915644 case ENTER:
13260
- object.editWindow.ScreenFit(); // Edit();
15645
+ // object.editWindow.ScreenFit(); // Edit();
15646
+ ToggleLive();
1326115647 break;
1326215648 case DELETE:
1326315649 ClearSelection();
1326415650 break;
13265
- /*
1326615651 case '+':
15652
+
15653
+ /*
1326715654 //fontsize += 1;
1326815655 bbzoom *= 2;
1326915656 repaint();
....@@ -13280,17 +15667,17 @@
1328015667 case '=':
1328115668 IncDepth();
1328215669 //fontsize += 1;
13283
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1328415671 maskbit = 6;
1328515672 break;
1328615673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1328715674 DecDepth();
1328815675 maskbit = 5;
1328915676 //if(fontsize > 1) fontsize -= 1;
13290
- if (object.editWindow == null)
13291
- new Exception().printStackTrace();
13292
- else
13293
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1329415681 break;
1329515682 case '{':
1329615683 manipCamera.shaper_fovy /= 1.1;
....@@ -13345,6 +15732,7 @@
1334515732 }
1334615733 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1334715734 }
15735
+
1334815736 static double OCCLUSIONBOOST = 1; // 0.5;
1334915737
1335015738 void keyReleased(int key, int modifiers)
....@@ -13352,11 +15740,11 @@
1335215740 //mode = ROTATE;
1335315741 if ((MODIFIERS & COMMAND) == 0) // VR??
1335415742 {
13355
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1335615744 }
1335715745 }
1335815746
13359
- protected void processKeyEvent(KeyEvent e)
15747
+ public void processKeyEvent(KeyEvent e)
1336015748 {
1336115749 switch (e.getID())
1336215750 {
....@@ -13486,8 +15874,9 @@
1348615874
1348715875 protected void processMouseMotionEvent(MouseEvent e)
1348815876 {
13489
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13490
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15877
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15878
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1349115880 {
1349215881 mouseMoved(e);
1349315882 } else
....@@ -13512,11 +15901,12 @@
1351215901 }
1351315902 */
1351415903
13515
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1351615905 }
1351715906
1351815907 void SelectParent()
1351915908 {
15909
+ new Exception().printStackTrace();
1352015910 System.exit(0);
1352115911 Composite group = (Composite) object;
1352215912 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13528,10 +15918,10 @@
1352815918 {
1352915919 //selectees.remove(i);
1353015920 System.out.println("select parent of " + elem);
13531
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1353215922 } else
1353315923 {
13534
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1353515925 }
1353615926
1353715927 first = false;
....@@ -13540,6 +15930,7 @@
1354015930
1354115931 void SelectChildren()
1354215932 {
15933
+ new Exception().printStackTrace();
1354315934 System.exit(0);
1354415935 /*
1354515936 Composite group = (Composite) object;
....@@ -13572,12 +15963,12 @@
1357215963 for (int j = 0; j < group.children.size(); j++)
1357315964 {
1357415965 elem = (Object3D) group.children.elementAt(j);
13575
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1357615967 first = false;
1357715968 }
1357815969 } else
1357915970 {
13580
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1358115972 }
1358215973
1358315974 first = false;
....@@ -13588,21 +15979,21 @@
1358815979 {
1358915980 //Composite group = (Composite) object;
1359015981 Object3D group = object;
13591
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1359215983 }
1359315984
1359415985 void ResetTransform(int mask)
1359515986 {
1359615987 //Composite group = (Composite) object;
1359715988 Object3D group = object;
13598
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1359915990 }
1360015991
1360115992 void FlipTransform()
1360215993 {
1360315994 //Composite group = (Composite) object;
1360415995 Object3D group = object;
13605
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1360615997 // group.editWindow.ReduceMesh(true);
1360715998 }
1360815999
....@@ -13610,7 +16001,7 @@
1361016001 {
1361116002 //Composite group = (Composite) object;
1361216003 Object3D group = object;
13613
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1361416005 // group.editWindow.ReduceMesh(true);
1361516006 }
1361616007
....@@ -13618,7 +16009,7 @@
1361816009 {
1361916010 //Composite group = (Composite) object;
1362016011 Object3D group = object;
13621
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1362216013 }
1362316014
1362416015 void IncDepth()
....@@ -13700,11 +16091,11 @@
1370016091
1370116092 int width = getBounds().width;
1370216093 int height = getBounds().height;
13703
- ClickInfo info = new ClickInfo();
13704
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1370516094 //Image img = CreateImage(width, height);
1370616095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1370716097 Graphics gr = g; // img.getGraphics();
16098
+
1370816099 if (!hasMarquee)
1370916100 {
1371016101 if (Xmin < Xmax) // !locked)
....@@ -13776,44 +16167,92 @@
1377616167 }
1377716168 if (object != null && !hasMarquee)
1377816169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1377916176 if (isRenderer)
1378016177 {
13781
- info.flags++;
16178
+ object.clickInfo.flags++;
1378216179 double frameAspect = (double) width / (double) height;
1378316180 if (frameAspect > renderCamera.aspect)
1378416181 {
1378516182 int desired = (int) ((double) height * renderCamera.aspect);
13786
- info.bounds.width -= width - desired;
13787
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1378816185 } else
1378916186 {
1379016187 int desired = (int) ((double) width / renderCamera.aspect);
13791
- info.bounds.height -= height - desired;
13792
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1379316190 }
1379416191 }
13795
- info.g = gr;
13796
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1379716195 /*
1379816196 // Memory intensive (brep.verticescopy)
1379916197 if (!(object instanceof Composite))
1380016198 object.draw(info, 0, false); // SLOW :
1380116199 */
13802
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1380316201 {
13804
- object.drawEditHandles(info, 0);
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
16205
+ {
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
16212
+ {
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
16220
+ }
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
16241
+ }
1380516242 }
1380616243 }
16244
+
1380716245 if (isRenderer)
1380816246 {
1380916247 //gr.setColor(Color.black);
1381016248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1381116249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1381216250 }
16251
+
1381316252 if (hasMarquee)
1381416253 {
1381516254 gr.setXORMode(Color.white);
13816
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1381716256 if (!firstime)
1381816257 {
1381916258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -13832,6 +16271,7 @@
1383216271 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1383316272 }
1383416273
16274
+ // To avoid clear.
1383516275 public void update(Graphics g)
1383616276 {
1383716277 paint(g);
....@@ -13921,6 +16361,7 @@
1392116361 public boolean mouseDown(Event evt, int x, int y)
1392216362 {
1392316363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1392416365 /*
1392516366 locked = true;
1392616367 drag = false;
....@@ -13964,7 +16405,7 @@
1396416405 {
1396516406 keyPressed(0, modifiers);
1396616407 }
13967
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1396816409 return true;
1396916410 }
1397016411
....@@ -14082,7 +16523,7 @@
1408216523 {
1408316524 keyReleased(0, 0);
1408416525 }
14085
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1408616527 return true;
1408716528 }
1408816529
....@@ -14214,7 +16655,7 @@
1421416655 Object3D object;
1421516656 static Object3D trackedobject;
1421616657 Camera renderCamera; // Light or Eye (or Occlusion)
14217
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1421816659 /*static*/ Camera eyeCamera;
1421916660 /*static*/ Camera lightCamera;
1422016661 int cameracount;
....@@ -14278,6 +16719,8 @@
1427816719 private /*static*/ boolean firstime;
1427916720 private /*static*/ cVector newView = new cVector();
1428016721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1428116724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1428216725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1428316726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14290,29 +16733,67 @@
1429016733 {
1429116734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1429216735
16736
+ int usedsuf = 0;
16737
+
1429316738 for (int i = 0; i < suffixes.length; i++)
1429416739 {
14295
- String resourceName = basename + suffixes[i] + "." + suffix;
14296
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14297
- mipmapped,
14298
- FileUtil.getFileSuffix(resourceName));
14299
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1430016745 {
14301
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1430216750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1430316779 //System.out.println("Target = " + targets[i]);
1430416780 cubemap.updateImage(data, targets[i]);
1430516781 }
1430616782
1430716783 return cubemap;
1430816784 }
16785
+
1430916786 int bigsphere = -1;
1431016787
1431116788 float BGcolor = 0.5f;
1431216789
14313
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1431416793 {
14315
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1431616797 {
1431716798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1431816799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14327,7 +16808,17 @@
1432716808 // Compensates for ExaminerViewer's modification of modelview matrix
1432816809 gl.glMatrixMode(GL.GL_MODELVIEW);
1432916810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1433016812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1433116822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1433216823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1433316824
....@@ -14359,6 +16850,7 @@
1435916850 {
1436016851 gl.glScalef(1.0f, -1.0f, 1.0f);
1436116852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1436216854 gl.glMultMatrixd(viewrot_1, 0);
1436316855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1436416856 //viewer.updateInverseRotation(gl);
....@@ -14399,7 +16891,8 @@
1439916891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1440016892
1440116893 cubemap.disable();
14402
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1440316896 if (CULLFACE)
1440416897 {
1440516898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -14434,7 +16927,7 @@
1443416927 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1443516928 gl.glPushMatrix();
1443616929 gl.glLoadIdentity();
14437
- PushMatrix(checker.toParent);
16930
+ //PushMatrix(checker.toParent);
1443816931
1443916932 gl.glMatrixMode(GL.GL_TEXTURE);
1444016933 gl.glPushMatrix();
....@@ -14455,10 +16948,10 @@
1445516948 gl.glScalef(1.0f, -1.0f, 1.0f);
1445616949 }
1445716950
14458
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1445916952
14460
- float step = 0.1666f; //0.25f;
14461
- float stepv = step * 1652 / 998;
16953
+ float step = 2; // 0.1666f; //0.25f;
16954
+ float stepv = 2; // step * 1652 / 998;
1446216955
1446316956 int i0 = 0;
1446416957 /*
....@@ -14494,20 +16987,21 @@
1449416987 /**/
1449516988 //checker.GetMaterial().opacity = 1.1f;
1449616989 ////checker.GetMaterial().ambient = 0.99f;
14497
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14498
- Object3D.selectedstack[Object3D.materialdepth] = false;
14499
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16990
+ materialstack[materialdepth] = checker.material;
16991
+ selectedstack[materialdepth] = false;
16992
+ cStatic.objectstack[materialdepth++] = checker;
1450016993 //System.out.println("material " + material);
1450116994 //Applet3D.tracein(this, selected);
14502
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1450316996
14504
- checker.GetMaterial().Draw(this, false); // true);
16997
+ //checker.GetMaterial().Draw(this, false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1450516999
14506
- Object3D.materialdepth -= 1;
14507
- if (Object3D.materialdepth > 0)
17000
+ materialdepth -= 1;
17001
+ if (materialdepth > 0)
1450817002 {
14509
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14510
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
17003
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17004
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1451117005 }
1451217006 //checker.GetMaterial().opacity = 1f;
1451317007 ////checker.GetMaterial().ambient = 1f;
....@@ -14528,15 +17022,27 @@
1452817022
1452917023 //float u = (i+1)/2;
1453017024 //float v = (j+1)/2;
14531
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
17025
+ if (checker.flipV)
17026
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
17027
+ else
17028
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1453217029 gl.glVertex3f(i, j, -0.5f);
1453317030
17031
+ if (checker.flipV)
17032
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
17033
+ else
1453417034 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1453517035 gl.glVertex3f(i + step, j, -0.5f);
1453617036
17037
+ if (checker.flipV)
17038
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
17039
+ else
1453717040 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1453817041 gl.glVertex3f(i + step, j + stepv, -0.5f);
1453917042
17043
+ if (checker.flipV)
17044
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
17045
+ else
1454017046 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1454117047 gl.glVertex3f(i, j + stepv, -0.5f);
1454217048 }
....@@ -14548,7 +17054,7 @@
1454817054 gl.glMatrixMode(GL.GL_PROJECTION);
1454917055 gl.glPopMatrix();
1455017056 gl.glMatrixMode(GL.GL_MODELVIEW);
14551
- PopMatrix(null); // checker.toParent); // null);
17057
+ //PopMatrix(null); // checker.toParent); // null);
1455217058 gl.glPopMatrix();
1455317059 PopTextureMatrix(checker.toParent);
1455417060 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14581,6 +17087,14 @@
1458117087 }
1458217088 }
1458317089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1458417098 class SelectBuffer implements GLEventListener
1458517099 {
1458617100
....@@ -14596,7 +17110,7 @@
1459617110 //new Exception().printStackTrace();
1459717111 System.out.println("select buffer init");
1459817112 // Use debug pipeline
14599
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1460017114
1460117115 GL gl = drawable.getGL();
1460217116
....@@ -14639,6 +17153,7 @@
1463917153 {
1464017154 if (!selection)
1464117155 {
17156
+ new Exception().printStackTrace();
1464217157 System.exit(0);
1464317158 return;
1464417159 }
....@@ -14659,17 +17174,39 @@
1465917174
1466017175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1466117176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1466217188 //int tmp = selection_view;
1466317189 //selection_view = -1;
14664
- int temp = drawMode;
14665
- drawMode = SELECTION;
17190
+ int temp = DrawMode();
17191
+ Globals.drawMode = SELECTION; // WARNING
1466617192 indexcount = 0;
1466717193 parent.display(drawable);
1466817194 //selection_view = tmp;
1466917195 //if (temp == SELECTION)
1467017196 // temp = DEFAULT; // patch for selection debug
14671
- drawMode = temp;
17197
+ Globals.drawMode = temp; // WARNING
1467217198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1467317210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1467417211
1467517212 // trying different ways of getting the depth info over
....@@ -14718,6 +17255,13 @@
1471817255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1471917256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1472017257
17258
+ CreateSelectedPoint();
17259
+
17260
+ // Will fit the mesh !!!
17261
+ selectedpoint.toParent[0][0] = 0.0001;
17262
+ selectedpoint.toParent[1][1] = 0.0001;
17263
+ selectedpoint.toParent[2][2] = 0.0001;
17264
+
1472117265 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1472217266
1472317267 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14761,34 +17305,36 @@
1476117305 System.out.println("; fromto " + sel + " " + Trunk(previousselectedpoint.toParent[3][0]) + " " + Trunk(previousselectedpoint.toParent[3][2]) + " " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][2]));
1476217306 }
1476317307
14764
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1476517309 }
1476617310 }
1476717311
1476817312 if (!movingcamera && !PAINTMODE)
14769
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1477017314
14771
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1477217316 {
14773
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1477417318
14775
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1477617322
14777
- group.CreateMaterial(); // use a void leaf to select instances
14778
-
14779
- group.add(paintobj); // link
14780
-
14781
- object.editWindow.SnapObject(group);
14782
-
14783
- Object3D folder = object.editWindow.copy;
14784
-
14785
- if (object.editWindow.copy.selection.Size() > 0)
14786
- folder = object.editWindow.copy.selection.elementAt(0);
14787
-
14788
- folder.add(group);
14789
-
14790
- object.editWindow.ResetModel();
14791
- object.editWindow.refreshContents();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1479217338 }
1479317339 else
1479417340 paintcount = 0;
....@@ -14827,6 +17373,11 @@
1482717373 //System.out.println("objects[color] = " + objects[color]);
1482817374 //objects[color].Select();
1482917375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1483017381 object.Select(color, deselect);
1483117382 }
1483217383
....@@ -14877,6 +17428,7 @@
1487717428
1487817429 public void init(GLAutoDrawable drawable)
1487917430 {
17431
+ if (Globals.DEBUG)
1488017432 System.out.println("shadow buffer init");
1488117433
1488217434 GL gl = drawable.getGL();
....@@ -14926,7 +17478,7 @@
1492617478 gl.glDisable(gl.GL_CULL_FACE);
1492717479 }
1492817480
14929
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1493017482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1493117483
1493217484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14936,14 +17488,14 @@
1493617488 //gl.glColorMask(false, false, false, false);
1493717489
1493817490 //render_scene_from_light_view(gl, drawable, 0, 0);
14939
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1494017492 {
1494117493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1494217494
14943
- int temp = drawMode;
14944
- drawMode = SHADOW;
17495
+ int temp = DrawMode();
17496
+ Globals.drawMode = SHADOW; // WARNING
1494517497 parent.display(drawable);
14946
- drawMode = temp;
17498
+ Globals.drawMode = temp; // WARNING
1494717499 }
1494817500
1494917501 gl.glCullFace(gl.GL_BACK);
....@@ -14996,7 +17548,6 @@
1499617548
1499717549 class AntialiasBuffer implements GLEventListener
1499817550 {
14999
-
1500017551 CameraPane parent = null;
1500117552
1500217553 AntialiasBuffer(CameraPane p)
....@@ -15106,15 +17657,25 @@
1510617657 gl.glFlush();
1510717658
1510817659 /**/
15109
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1511017661
15111
- int[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1511217663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1511317668 double r = 0, g = 0, b = 0;
1511417669
1511517670 double count = 0;
17671
+
17672
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17673
+
17674
+ float mindepth = 1;
17675
+
17676
+ double FACTOR = 1;
1511617677
15117
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1511817679 {
1511917680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1512017681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15197,7 +17758,7 @@
1519717758
1519817759 double scale = ray.z; // 1; // cos
1519917760
15200
- int p = pixels[newindex];
17761
+ float depth = depths[newindex];
1520117762
1520217763 /*
1520317764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15221,10 +17782,23 @@
1522117782 scale = (1 - modu) * modv;
1522217783 */
1522317784
15224
- r += ((p >> 16) & 0xFF) * scale / 255;
15225
- g += ((p >> 8) & 0xFF) * scale / 255;
15226
- b += (p & 0xFF) * scale / 255;
17785
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17786
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17787
+ //b += (p & 0xFF) * scale / 255;
17788
+
17789
+ if (mindepth > depth)
17790
+ {
17791
+ mindepth = depth;
17792
+ }
1522717793
17794
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17795
+
17796
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17797
+
17798
+ r += factor * scale;
17799
+ g += factor * scale;
17800
+ b += factor * scale;
17801
+
1522817802 count += scale;
1522917803 }
1523017804
....@@ -15322,12 +17896,6 @@
1532217896 GLUT glut = new GLUT();
1532317897
1532417898
15325
- static final public int DEFAULT = 0;
15326
- static final public int SELECTION = 1;
15327
- static final public int SHADOW = 2;
15328
- static final public int OCCLUSION = 3;
15329
- static
15330
- public int drawMode = DEFAULT;
1533117899 public boolean spherical = false;
1533217900 static boolean DEBUG_OCCLUSION = false;
1533317901 static boolean DEBUG_SELECTION = false;
....@@ -15340,23 +17908,15 @@
1534017908 int AAbuffersize = 0;
1534117909
1534217910 //double[] selectedpoint = new double[3];
15343
- static Sphere selectedpoint = new Sphere();
17911
+ static Superellipsoid selectedpoint;
1534417912 static Sphere previousselectedpoint = null;
15345
- static Sphere debugpoint = new Sphere();
15346
- static Sphere debugpoint2 = new Sphere();
15347
- static Sphere debugpoint3 = new Sphere();
15348
- static Sphere debugpoint4 = new Sphere();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1534917917
1535017918 static Sphere debugpoints[] = new Sphere[8];
1535117919
15352
- static
15353
- {
15354
- for (int i=0; i<8; i++)
15355
- {
15356
- debugpoints[i] = new Sphere();
15357
- }
15358
- }
15359
-
1536017920 static void InitPoints(float radius)
1536117921 {
1536217922 for (int i=0; i<8; i++)
....@@ -15376,7 +17936,7 @@
1537617936 }
1537717937 }
1537817938
15379
- static void DrawPoints(CameraPane cpane)
17939
+ static void DrawPoints(iCameraPane cpane)
1538017940 {
1538117941 for (int i=0; i<8; i++) // first and last are red
1538217942 {
....@@ -15395,10 +17955,14 @@
1539517955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1539617956 static IntBuffer bigAAbuffer;
1539717957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15398
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1539917959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1540017960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15401
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17961
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1540217966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1540317967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1540417968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15407,10 +17971,11 @@
1540717971 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1540817972 // Depth buffer format
1540917973 //private int depth_format;
15410
- static public void NextIndex(Object3D o, GL gl)
17974
+
17975
+ public void NextIndex()
1541117976 {
1541217977 indexcount+=16;
15413
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17978
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1541417979 //objects[indexcount] = o;
1541517980 //System.out.println("indexcount = " + indexcount);
1541617981 }