Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
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,17 @@
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;
94116 boolean reverseUP = false;
95117 static boolean frozen = false;
96118 boolean enablebackspace = false; // patch for back buffer refresh
97119
98120 static boolean textureon = true;
99121 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101122 static boolean FULLSCREEN = false;
102123 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104124 static boolean INERTIA = true;
105125 static boolean FAST = false;
106126 static boolean SLOWPOSE = false;
....@@ -108,6 +128,8 @@
108128
109129 static int tickcount = 0; // slow pose issue
110130
131
+static boolean BUTTONLESSWHEEL = false;
132
+static boolean ZOOMBOXMODE = false;
111133 static boolean BOXMODE = false;
112134 static boolean IMAGEFLIP = false;
113135 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +144,7 @@
122144 static boolean OEIL = true;
123145 static boolean OEILONCE = false; // do oeilon then oeiloff
124146 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
147
+static boolean SWITCH = true; // false;
126148 static boolean HANDLES = false; // selection doesn't work!!
127149 static boolean PAINTMODE = false;
128150
....@@ -153,7 +175,7 @@
153175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
154176 boolean anisotropy = true;
155177 boolean softshadow = true; // slower but better false;
156
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
157179
158180 boolean macromode = false;
159181
....@@ -165,12 +187,55 @@
165187 defaultcaps.setAccumBlueBits(16);
166188 defaultcaps.setAccumAlphaBits(16);
167189 }
168
- static CameraPane theRenderer;
190
+
191
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
169192
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
205
+
170206 void SetAsGLRenderer(boolean b)
171207 {
172208 isRenderer = b;
173
- theRenderer = this;
209
+ Globals.theRenderer = this;
210
+ }
211
+
212
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
213
+ {
214
+ super(defaultcaps, null, withcontext?glcontext:null, null);
215
+
216
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
217
+ glcontext = getContext();
218
+
219
+ cameras = new Camera[2];
220
+ targetLookAts = new cVector[2];
221
+
222
+ SetCamera(cam);
223
+
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
226
+
227
+ object = o;
228
+
229
+ setBackground(Color.white);
230
+
231
+ addKeyListener(this);
232
+ addMouseListener(this);
233
+ addMouseMotionListener(this);
234
+ addMouseWheelListener(this);
235
+ //System.out.println("addGLEventListener: " + this);
236
+ addGLEventListener(this);
237
+
238
+// pingthread.start(); // may 2013
174239 }
175240
176241 static boolean AntialiasingEnabled()
....@@ -178,12 +243,53 @@
178243 return CURRENTANTIALIAS > 0;
179244 }
180245
181
- void ClearDepth()
246
+ /// INTERFACE
247
+
248
+ public javax.media.opengl.GL GetGL0()
249
+ {
250
+ return null;
251
+ }
252
+
253
+ public int GenList()
254
+ {
255
+ javax.media.opengl.GL gl = GetGL();
256
+ return gl.glGenLists(1);
257
+ }
258
+
259
+ public void NewList(int id)
260
+ {
261
+ javax.media.opengl.GL gl = GetGL();
262
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
263
+ }
264
+
265
+ public void CallList(int id)
266
+ {
267
+ javax.media.opengl.GL gl = GetGL();
268
+ gl.glCallList(id);
269
+ }
270
+
271
+ public void EndList()
272
+ {
273
+ javax.media.opengl.GL gl = GetGL();
274
+ gl.glEndList();
275
+ }
276
+
277
+ public boolean IsBoxMode()
278
+ {
279
+ return BOXMODE;
280
+ }
281
+
282
+ public boolean IsZoomBoxMode()
283
+ {
284
+ return ZOOMBOXMODE;
285
+ }
286
+
287
+ public void ClearDepth()
182288 {
183289 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184290 }
185291
186
- void DepthTest(boolean depthtest)
292
+ public void DepthTest(boolean depthtest)
187293 {
188294 if (depthtest)
189295 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +297,7 @@
191297 GetGL().glDepthFunc(GL.GL_ALWAYS);
192298 }
193299
194
- void DepthWrite(boolean depthwrite)
300
+ public void DepthWrite(boolean depthwrite)
195301 {
196302 if (depthwrite)
197303 GetGL().glDepthMask(true);
....@@ -199,12 +305,1616 @@
199305 GetGL().glDepthMask(false);
200306 }
201307
202
- void BackFaceCull(boolean bfc)
308
+ public void BackFaceCull(boolean bfc)
203309 {
204310 if (bfc)
205311 GetGL().glEnable(GetGL().GL_CULL_FACE);
206312 else
207313 GetGL().glDisable(GetGL().GL_CULL_FACE);
314
+ }
315
+
316
+ public boolean BackFaceCullMode()
317
+ {
318
+ return this.CULLFACE;
319
+ }
320
+
321
+ public boolean IsAmbientOcclusionOn()
322
+ {
323
+ return this.ambientOcclusion;
324
+ }
325
+
326
+ public boolean IsDebugSelection()
327
+ {
328
+ return DEBUG_SELECTION;
329
+ }
330
+
331
+ public boolean IsFrozen()
332
+ {
333
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
334
+
335
+ return !selectmode && cameracount == 0; // != 0;
336
+ }
337
+
338
+ // Currently in Globals
339
+ public int DrawMode()
340
+ {
341
+ return Globals.DrawMode();
342
+ }
343
+
344
+ public Camera EyeCamera()
345
+ {
346
+ return eyeCamera;
347
+ }
348
+
349
+ public Camera LightCamera()
350
+ {
351
+ return lightCamera;
352
+ }
353
+
354
+ public Camera ManipCamera()
355
+ {
356
+ return manipCamera;
357
+ }
358
+
359
+ public Camera RenderCamera()
360
+ {
361
+ return renderCamera;
362
+ }
363
+
364
+ public Camera[] Cameras()
365
+ {
366
+ return cameras;
367
+ }
368
+
369
+ public void PushMaterial(Object3D obj, boolean selected)
370
+ {
371
+ CameraPane display = this;
372
+ javax.media.opengl.GL gl = display.GetGL();
373
+ cMaterial material = obj.material;
374
+
375
+ if (material != null)
376
+ {
377
+ materialstack[materialdepth] = material;
378
+ selectedstack[materialdepth] = selected;
379
+ cStatic.objectstack[materialdepth++] = obj;
380
+ //System.out.println("material " + material);
381
+ //Applet3D.tracein(this, selected);
382
+ //display.vector2buffer = obj.projectedVertices;
383
+ if (obj instanceof Camera)
384
+ {
385
+ display.options1[0] = material.shift;
386
+ //System.out.println("shift " + material.shift);
387
+ display.options1[1] = material.lightarea;
388
+ display.options1[2] = material.shadowbias;
389
+ display.options1[3] = material.aniso;
390
+ display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
396
+ display.options2[0] = material.opacity;
397
+ display.options2[1] = material.diffuse;
398
+ display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
402
+
403
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
407
+ display.options4[0] = material.cameralight/0.2f;
408
+ display.options4[1] = material.subsurface;
409
+ display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
413
+
414
+ // if (display.CURRENTANTIALIAS > 0)
415
+ // display.options3[3] /= 4;
416
+
417
+ /*
418
+ System.out.println("Focus = " + display.options1[0]);
419
+ System.out.println("Aperture = " + display.options1[1]);
420
+ System.out.println("ShadowBlur = " + display.options1[2]);
421
+ System.out.println("Antialiasing = " + display.options1[3]);
422
+ System.out.println("Fog = " + display.options2[0]);
423
+ System.out.println("Intensity = " + display.options2[1]);
424
+ System.out.println("Elevation = " + display.options2[2]);
425
+ /**/
426
+ } else
427
+ {
428
+ DrawMaterial(material, selected, obj.projectedVertices);
429
+ }
430
+ } else
431
+ {
432
+ if (selected && CameraPane.flash)
433
+ {
434
+ display.modelParams4[1] = 100;
435
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
436
+ }
437
+ }
438
+ }
439
+
440
+ public void PushMaterial2(Object3D obj, boolean selected)
441
+ {
442
+ CameraPane display = this;
443
+ cMaterial material = obj.material;
444
+
445
+ if (material != null)
446
+ {
447
+ materialstack[materialdepth] = material;
448
+ selectedstack[materialdepth] = selected;
449
+ cStatic.objectstack[materialdepth++] = obj;
450
+ //System.out.println("material " + material);
451
+ //Applet3D.tracein("selected ", selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
454
+ }
455
+ }
456
+
457
+ public void PopMaterial(Object3D obj, boolean selected)
458
+ {
459
+ CameraPane display = this;
460
+ javax.media.opengl.GL gl = display.GetGL();
461
+ cMaterial material = obj.material;
462
+
463
+ //if (parent != null && parent.GetMaterial() != null)
464
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
465
+ if (material != null)
466
+ {
467
+ materialdepth -= 1;
468
+ if (materialdepth > 0)
469
+ {
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
472
+ }
473
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
474
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
475
+ {
476
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
477
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
478
+ }
479
+ }
480
+
481
+ public void PopMaterial2(Object3D obj)
482
+ {
483
+ CameraPane display = this;
484
+ cMaterial material = obj.material;
485
+
486
+ if (material != null)
487
+ {
488
+ materialdepth -= 1;
489
+ if (materialdepth > 0)
490
+ {
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
493
+ }
494
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
495
+ //else
496
+ //material.Draw(display, false);
497
+ }
498
+ }
499
+
500
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
501
+ {
502
+ CameraPane display = this;
503
+
504
+ if (pv.y == -10000 ||
505
+ qv.y == -10000 ||
506
+ rv.y == -10000)
507
+ return;
508
+
509
+// float b = f.nbiterations & 1;
510
+// float g = (f.nbiterations>>1) & 1;
511
+// float r = (f.nbiterations>>2) & 1;
512
+//
513
+// //if (f.weight == 10000)
514
+// //{
515
+// // r = 1; g = b = 0;
516
+// //}
517
+// //else
518
+// //{
519
+// // assert(f.weight < 10000);
520
+// r = g = b = (float)bRep.FaceWeight(f)*100;
521
+// if (r<0)
522
+// assert(r>=0);
523
+// //}
524
+
525
+ javax.media.opengl.GL gl = display.GetGL();
526
+
527
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
528
+
529
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
530
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
531
+ {
532
+ //gl.glBegin(gl.GL_TRIANGLES);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
536
+ if (!hasnorm)
537
+ {
538
+ // System.out.println("Mesh normal");
539
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
540
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
541
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
542
+ LA.vecNormalize(obj.v2);
543
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
544
+ }
545
+
546
+ // P
547
+ float x = (float)pv.x;
548
+ float y = (float)pv.y;
549
+ float z = (float)pv.z;
550
+
551
+ if (hasnorm)
552
+ {
553
+// if (!pv.norm.normalized())
554
+// assert(pv.norm.normalized());
555
+
556
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
557
+ float nx = (float)pv.norm.x;
558
+ float ny = (float)pv.norm.y;
559
+ float nz = (float)pv.norm.z;
560
+
561
+ x += nx * obj.NORMALPUSH;
562
+ y += ny * obj.NORMALPUSH;
563
+ z += nz * obj.NORMALPUSH;
564
+
565
+ gl.glNormal3f(nx, ny, nz);
566
+ }
567
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
568
+ SetColor(obj, pv);
569
+ //gl.glColor4f(r, g, b, 1);
570
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
571
+ if (obj.flipV)
572
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
573
+ else
574
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
575
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
576
+
577
+ gl.glVertex3f(x, y, z);
578
+
579
+ // Q
580
+ x = (float)qv.x;
581
+ y = (float)qv.y;
582
+ z = (float)qv.z;
583
+
584
+// Print(pv);
585
+ if (hasnorm)
586
+ {
587
+// assert(qv.norm.normalized());
588
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
589
+ float nx = (float)qv.norm.x;
590
+ float ny = (float)qv.norm.y;
591
+ float nz = (float)qv.norm.z;
592
+
593
+ x += nx * obj.NORMALPUSH;
594
+ y += ny * obj.NORMALPUSH;
595
+ z += nz * obj.NORMALPUSH;
596
+
597
+ gl.glNormal3f(nx, ny, nz);
598
+ }
599
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
600
+ // boolean locked = false;
601
+ // float eps = 0.1f;
602
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
603
+
604
+ // int dot = 0; //*/ (int)f.dot;
605
+
606
+ // if ((dot&1) == 0)
607
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
608
+
609
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
610
+ if (obj.flipV)
611
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
612
+ else
613
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
614
+ // else
615
+ // {
616
+ // locked = true;
617
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
618
+ // }
619
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
620
+ SetColor(obj, qv);
621
+
622
+ gl.glVertex3f(x, y, z);
623
+ //gl.glColor4f(r, g, b, 1);
624
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
625
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
626
+// Print(qv);
627
+
628
+ // R
629
+ x = (float)rv.x;
630
+ y = (float)rv.y;
631
+ z = (float)rv.z;
632
+
633
+ if (hasnorm)
634
+ {
635
+// assert(rv.norm.normalized());
636
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
637
+ float nx = (float)rv.norm.x;
638
+ float ny = (float)rv.norm.y;
639
+ float nz = (float)rv.norm.z;
640
+
641
+ x += nx * obj.NORMALPUSH;
642
+ y += ny * obj.NORMALPUSH;
643
+ z += nz * obj.NORMALPUSH;
644
+
645
+ gl.glNormal3f(nx, ny, nz);
646
+ }
647
+
648
+ // if ((dot&4) == 0)
649
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
650
+
651
+ // if (wrap || !locked && (dot&8) != 0)
652
+ if (obj.flipV)
653
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
654
+ else
655
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
656
+ // else
657
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
658
+
659
+ // f.dot = dot;
660
+
661
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
662
+ SetColor(obj, rv);
663
+ //gl.glColor4f(r, g, b, 1);
664
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
665
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
666
+ gl.glVertex3f(x, y, z);
667
+// Print(rv);
668
+ //gl.glEnd();
669
+ }
670
+ else
671
+ {
672
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
673
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
674
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
675
+
676
+ }
677
+
678
+ if (false) // (attributes & WIREFRAME) != 0)
679
+ {
680
+ gl.glDisable(gl.GL_LIGHTING);
681
+
682
+ gl.glBegin(gl.GL_LINE_LOOP);
683
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
684
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
685
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
686
+ gl.glEnd();
687
+
688
+ gl.glEnable(gl.GL_LIGHTING);
689
+ }
690
+ }
691
+
692
+ /**
693
+ * <code>draw</code> renders a <code>TriMesh</code> object including
694
+ * it's normals, colors, textures and vertices.
695
+ *
696
+ * @see Renderer#draw(TriMesh)
697
+ * @param tris
698
+ * the mesh to render.
699
+ */
700
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
701
+ {
702
+ CameraPane display = this;
703
+
704
+ float r = display.modelParams0[0];
705
+ float g = display.modelParams0[1];
706
+ float b = display.modelParams0[2];
707
+ float opacity = display.modelParams5[1];
708
+
709
+ //final GL gl = GLU.getCurrentGL();
710
+ GL gl = display.GetGL(); // getGL();
711
+
712
+ FloatBuffer vertBuf = geo.vertBuf;
713
+
714
+ int v = vertBuf.capacity();
715
+
716
+ int count = 0;
717
+
718
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
719
+ gl.glEnable(gl.GL_CULL_FACE);
720
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
721
+ for (int i=0; i<v/3; i++)
722
+ {
723
+ int index3 = i*3;
724
+
725
+ if (geo.sizeBuf.get(index3+1) == 0)
726
+ continue;
727
+
728
+ count++;
729
+
730
+ int index4 = i*4;
731
+
732
+ float tx = vertBuf.get(index3);
733
+ float ty = vertBuf.get(index3+1);
734
+ float tz = vertBuf.get(index3+2);
735
+
736
+ // if (tx == 0 && ty == 0 && tz == 0)
737
+ // continue;
738
+
739
+ gl.glMatrixMode(gl.GL_TEXTURE);
740
+ gl.glPushMatrix();
741
+
742
+ float[] texmat = geo.texmat;
743
+ texmat[12] = texmat[13] = texmat[14] = i;
744
+
745
+ gl.glMultMatrixf(texmat, 0);
746
+
747
+ gl.glMatrixMode(gl.GL_MODELVIEW);
748
+ gl.glPushMatrix();
749
+
750
+ gl.glTranslatef(tx,ty,tz);
751
+
752
+ if (rotate)
753
+ gl.glRotatef(i, 0, 1, 0);
754
+
755
+ float size = geo.sizeBuf.get(index3) / 100;
756
+ gl.glScalef(size,size,size);
757
+
758
+ float cr = geo.colorBuf.get(index4);
759
+ float cg = geo.colorBuf.get(index4+1);
760
+ float cb = geo.colorBuf.get(index4+2);
761
+ float ca = geo.colorBuf.get(index4+3);
762
+
763
+ display.modelParams0[0] = r * cr;
764
+ display.modelParams0[1] = g * cg;
765
+ display.modelParams0[2] = b * cb;
766
+
767
+ display.modelParams5[1] = opacity * ca;
768
+
769
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
770
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
771
+
772
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
773
+ RandomNode.globalseed2 = RandomNode.globalseed;
774
+
775
+// gl.glColor4f(cr,cg,cb,ca);
776
+ // gl.glScalef(1024/16,1024/16,1024/16);
777
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
778
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
779
+ //gl.glTranslatef(-tx,-ty,-tz);
780
+ gl.glPopMatrix();
781
+
782
+ gl.glMatrixMode(gl.GL_TEXTURE);
783
+ gl.glPopMatrix();
784
+ }
785
+ // gl.glScalef(1024,1024,1024);
786
+ if (!cf)
787
+ gl.glDisable(gl.GL_CULL_FACE);
788
+
789
+ display.modelParams0[0] = r;
790
+ display.modelParams0[1] = g;
791
+ display.modelParams0[2] = b;
792
+
793
+ display.modelParams5[1] = opacity;
794
+
795
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
796
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
797
+
798
+ gl.glMatrixMode(gl.GL_MODELVIEW);
799
+
800
+// System.err.println("total = " + v/3 + "; displayed = " + count);
801
+ if (true)
802
+ return;
803
+
804
+//// if (!tris.predraw(this))
805
+//// {
806
+//// return;
807
+//// }
808
+//// if (Debug.stats)
809
+//// {
810
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
811
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
812
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
813
+//// }
814
+////
815
+//// if (tris.getDisplayListID() != -1)
816
+//// {
817
+//// renderDisplayList(tris);
818
+//// return;
819
+//// }
820
+////
821
+//// if (!generatingDisplayList)
822
+//// {
823
+//// applyStates(tris.states, tris);
824
+//// }
825
+//// if (Debug.stats)
826
+//// {
827
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
828
+//// }
829
+//// boolean transformed = doTransforms(tris);
830
+//
831
+// int glMode = GL.GL_TRIANGLES;
832
+// switch (getMode())
833
+// {
834
+// case Triangles:
835
+// glMode = GL.GL_TRIANGLES;
836
+// break;
837
+// case Strip:
838
+// glMode = GL.GL_TRIANGLE_STRIP;
839
+// break;
840
+// case Fan:
841
+// glMode = GL.GL_TRIANGLE_FAN;
842
+// break;
843
+// }
844
+//
845
+// if (!predrawGeometry(gl))
846
+// {
847
+// // make sure only the necessary indices are sent through on old
848
+// // cards.
849
+// IntBuffer indices = this.getIndexBuffer();
850
+// if (indices == null)
851
+// {
852
+// logger.severe("missing indices on geometry object: " + this.toString());
853
+// } else
854
+// {
855
+// indices.rewind();
856
+// indices.limit(this.getMaxIndex());
857
+//
858
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
859
+//
860
+// indices.clear();
861
+// }
862
+// } else
863
+// {
864
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
865
+// GL.GL_UNSIGNED_INT, 0);
866
+// }
867
+//
868
+//// postdrawGeometry(tris);
869
+//// if (transformed)
870
+//// {
871
+//// undoTransforms(tris);
872
+//// }
873
+////
874
+//// if (Debug.stats)
875
+//// {
876
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
877
+//// }
878
+//// tris.postdraw(this);
879
+ }
880
+
881
+ static Camera localcamera = new Camera();
882
+ static cVector from = new cVector();
883
+ static cVector to = new cVector();
884
+
885
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
886
+ {
887
+ CameraPane cp = this;
888
+
889
+ Camera keep = cp.RenderCamera();
890
+ cp.renderCamera = localcamera;
891
+
892
+ if (br.trimmed)
893
+ {
894
+ float[] colors = new float[br.positions.length / 3];
895
+
896
+ int i3 = 0;
897
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
898
+ {
899
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
900
+ continue;
901
+
902
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
903
+ to.set(br.positions[i3] + br.normals[i3],
904
+ br.positions[i3 + 1] + br.normals[i3 + 1],
905
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
906
+ LA.xformPos(from, transform, from);
907
+ LA.xformPos(to, transform, to); // RIGID ONLY
908
+ localcamera.setAim(from, to);
909
+
910
+ CameraPane.occlusionbuffer.display();
911
+
912
+ if (CameraPane.DEBUG_OCCLUSION)
913
+ cp.display(); // debug
914
+
915
+ colors[i] = cp.vertexOcclusion.r;
916
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
917
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
918
+
919
+ if ((i % 100) == 0 && i != 0)
920
+ {
921
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
922
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
923
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
924
+ }
925
+ }
926
+
927
+ br.colors = colors;
928
+ }
929
+ else
930
+ {
931
+ for (int i = 0; i < br.VertexCount(); i++)
932
+ {
933
+ Vertex v = br.GetVertex(i);
934
+
935
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
936
+ continue;
937
+
938
+ from.set(v.x, v.y, v.z);
939
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
940
+ LA.xformPos(from, transform, from);
941
+ LA.xformPos(to, transform, to); // RIGID ONLY
942
+ localcamera.setAim(from, to);
943
+
944
+ CameraPane.occlusionbuffer.display();
945
+
946
+ if (CameraPane.DEBUG_OCCLUSION)
947
+ cp.display(); // debug
948
+
949
+ v.AO = cp.vertexOcclusion.r;
950
+
951
+ if ((i % 100) == 0 && i != 0)
952
+ {
953
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
954
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
955
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
956
+ }
957
+ }
958
+ }
959
+
960
+ //System.out.println("done.");
961
+
962
+ cp.renderCamera = keep;
963
+ }
964
+
965
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
966
+ {
967
+ CameraPane display = this;
968
+ pointFlow.CreateHT();
969
+
970
+ float r = display.modelParams0[0];
971
+ float g = display.modelParams0[1];
972
+ float b = display.modelParams0[2];
973
+ float opacity = display.modelParams5[1];
974
+
975
+ //final GL gl = GLU.getCurrentGL();
976
+ GL gl = display.GetGL(); // getGL();
977
+
978
+ int s = pointFlow.points.size();
979
+
980
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
981
+ gl.glEnable(gl.GL_CULL_FACE);
982
+
983
+ for (int i=s; --i>=0;)
984
+ //for (int i=0; i<s; i++)
985
+ {
986
+ cVector v = pointFlow.points.get(i);
987
+
988
+ double mindist = Double.MAX_VALUE;
989
+
990
+ double size = pointFlow.minimumSize;
991
+
992
+ double distancenext = 0;
993
+
994
+ if (i > 0)
995
+ {
996
+ cVector w = pointFlow.points.get(i-1);
997
+
998
+ double dist = w.distance(v);
999
+
1000
+ distancenext = dist;
1001
+
1002
+ if (mindist > dist)
1003
+ {
1004
+ mindist = dist;
1005
+ size = mindist*pointFlow.resizefactor;
1006
+ }
1007
+ }
1008
+
1009
+ if (i < s-1)
1010
+ {
1011
+ cVector w = pointFlow.points.get(i+1);
1012
+
1013
+ double dist = w.distance(v);
1014
+
1015
+ if (mindist > dist)
1016
+ {
1017
+ mindist = dist;
1018
+ size = mindist*pointFlow.resizefactor;
1019
+ }
1020
+ }
1021
+
1022
+ if (size < pointFlow.minimumSize)
1023
+ size = pointFlow.minimumSize;
1024
+ if (size > pointFlow.maximumSize)
1025
+ size = pointFlow.maximumSize;
1026
+
1027
+ double tx = v.x;
1028
+ double ty = v.y;
1029
+ double tz = v.z;
1030
+
1031
+ // if (tx == 0 && ty == 0 && tz == 0)
1032
+ // continue;
1033
+
1034
+ gl.glMatrixMode(gl.GL_TEXTURE);
1035
+ gl.glPushMatrix();
1036
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1037
+
1038
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1039
+
1040
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1041
+ gl.glPushMatrix();
1042
+
1043
+ gl.glTranslated(tx,ty,tz);
1044
+
1045
+ gl.glScaled(size,size,size);
1046
+
1047
+// float cr = colorBuf.get(index4);
1048
+// float cg = colorBuf.get(index4+1);
1049
+// float cb = colorBuf.get(index4+2);
1050
+// float ca = colorBuf.get(index4+3);
1051
+//
1052
+// display.modelParams0[0] = r * cr;
1053
+// display.modelParams0[1] = g * cg;
1054
+// display.modelParams0[2] = b * cb;
1055
+//
1056
+// display.modelParams5[1] = opacity * ca;
1057
+//
1058
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1059
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1060
+//
1061
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1062
+// RandomNode.globalseed2 = RandomNode.globalseed;
1063
+//
1064
+//// gl.glColor4f(cr,cg,cb,ca);
1065
+// // gl.glScalef(1024/16,1024/16,1024/16);
1066
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1067
+
1068
+ gl.glPopMatrix();
1069
+
1070
+ double step = size/4; //
1071
+
1072
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1073
+ continue;
1074
+
1075
+ int nbsteps = (int)(distancenext/step);
1076
+
1077
+ step = distancenext/nbsteps;
1078
+
1079
+ cVector next = pointFlow.points.get(i-1);
1080
+
1081
+ tmp.set(next);
1082
+ tmp.sub(v);
1083
+ tmp.normalize();
1084
+ tmp.mul(step);
1085
+
1086
+ // calculate next size
1087
+ mindist = Double.MAX_VALUE;
1088
+
1089
+ double nextsize = pointFlow.minimumSize;
1090
+
1091
+ if (i > 1)
1092
+ {
1093
+ cVector w = pointFlow.points.get(i-2);
1094
+
1095
+ double dist = w.distance(next);
1096
+
1097
+ if (mindist > dist)
1098
+ {
1099
+ mindist = dist;
1100
+ nextsize = mindist*pointFlow.resizefactor;
1101
+ }
1102
+ }
1103
+
1104
+ double dist = v.distance(next);
1105
+
1106
+ if (mindist > dist)
1107
+ {
1108
+ mindist = dist;
1109
+ nextsize = mindist*pointFlow.resizefactor;
1110
+ }
1111
+
1112
+ if (nextsize < pointFlow.minimumSize)
1113
+ nextsize = pointFlow.minimumSize;
1114
+ if (nextsize > pointFlow.maximumSize)
1115
+ nextsize = pointFlow.maximumSize;
1116
+ //
1117
+
1118
+ double count = 0;
1119
+
1120
+ while (distancenext > 0.000000001) // step
1121
+ {
1122
+ gl.glPushMatrix();
1123
+
1124
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1125
+
1126
+ double K = count/nbsteps;
1127
+
1128
+ double intersize = K*nextsize + (1-K)*size;
1129
+
1130
+ gl.glScaled(intersize,intersize,intersize);
1131
+
1132
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1133
+
1134
+ count++;
1135
+
1136
+ distancenext -= step;
1137
+
1138
+ gl.glPopMatrix();
1139
+ }
1140
+
1141
+ if (count != nbsteps)
1142
+ assert(count == nbsteps);
1143
+
1144
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1145
+ //gl.glTranslatef(-tx,-ty,-tz);
1146
+
1147
+ gl.glMatrixMode(gl.GL_TEXTURE);
1148
+ gl.glPopMatrix();
1149
+ }
1150
+
1151
+ if (!cf)
1152
+ gl.glDisable(gl.GL_CULL_FACE);
1153
+
1154
+// display.modelParams0[0] = r;
1155
+// display.modelParams0[1] = g;
1156
+// display.modelParams0[2] = b;
1157
+//
1158
+// display.modelParams5[1] = opacity;
1159
+//
1160
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1161
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1162
+
1163
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1164
+ }
1165
+
1166
+ public void DrawBox(cVector min, cVector max)
1167
+ {
1168
+ javax.media.opengl.GL gl = GetGL();
1169
+ gl.glBegin(gl.GL_LINES);
1170
+
1171
+ gl.glVertex3d(min.x, min.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, max.z);
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, max.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(max.x, min.y, min.z);
1177
+
1178
+ gl.glVertex3d(max.x, max.y, max.z);
1179
+ gl.glVertex3d(min.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(max.x, min.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, min.z);
1184
+
1185
+ gl.glEnd();
1186
+ }
1187
+
1188
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1189
+ {
1190
+ int[] strips = bRep.getRawIndices();
1191
+
1192
+ javax.media.opengl.GL gl = GetGL();
1193
+
1194
+ // TRIANGLE STRIP ARRAY
1195
+ if (bRep.trimmed)
1196
+ {
1197
+ float[] v = bRep.getRawVertices();
1198
+ float[] n = bRep.getRawNormals();
1199
+ float[] c = bRep.getRawColors();
1200
+ float[] uv = bRep.getRawUVMap();
1201
+
1202
+ int count2 = 0;
1203
+ int count3 = 0;
1204
+
1205
+ if (n.length > 0)
1206
+ {
1207
+ for (int i = 0; i < strips.length; i++)
1208
+ {
1209
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1210
+
1211
+ /*
1212
+ boolean locked = false;
1213
+ float eps = 0.1f;
1214
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1215
+
1216
+ int dot = 0;
1217
+
1218
+ if ((dot&1) == 0)
1219
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1220
+
1221
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1222
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1223
+ else
1224
+ {
1225
+ locked = true;
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+ }
1228
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1229
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1230
+ if (hasnorm)
1231
+ {
1232
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1233
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1234
+ }
1235
+
1236
+ if ((dot&4) == 0)
1237
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1238
+
1239
+ if (wrap || !locked && (dot&8) != 0)
1240
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1241
+ else
1242
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1243
+
1244
+ f.dot = dot;
1245
+ */
1246
+
1247
+ if (!selectmode)
1248
+ {
1249
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1250
+ {
1251
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1252
+ } else
1253
+ {
1254
+ gl.glNormal3f(0, 0, 1);
1255
+ }
1256
+
1257
+ if (c != null)
1258
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1259
+ {
1260
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1261
+ }
1262
+ }
1263
+
1264
+ if (flipV)
1265
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1266
+ else
1267
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
1269
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1270
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1271
+
1272
+ count2 += 2;
1273
+ count3 += 3;
1274
+ if (!selectmode)
1275
+ {
1276
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1277
+ {
1278
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1279
+ } else
1280
+ {
1281
+ gl.glNormal3f(0, 0, 1);
1282
+ }
1283
+ if (c != null)
1284
+ {
1285
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1286
+ }
1287
+ }
1288
+
1289
+ if (flipV)
1290
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1291
+ else
1292
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
1294
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1295
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1296
+
1297
+ count2 += 2;
1298
+ count3 += 3;
1299
+ for (int j = 0; j < strips[i] - 2; j++)
1300
+ {
1301
+ //gl.glTexCoord2d(...);
1302
+ if (!selectmode)
1303
+ {
1304
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1305
+ {
1306
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1307
+ } else
1308
+ {
1309
+ gl.glNormal3f(0, 0, 1);
1310
+ }
1311
+ if (c != null)
1312
+ {
1313
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1314
+ }
1315
+ }
1316
+
1317
+ if (flipV)
1318
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1319
+ else
1320
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
1322
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1323
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
1325
+ count2 += 2;
1326
+ count3 += 3;
1327
+ }
1328
+
1329
+ gl.glEnd();
1330
+ }
1331
+ }
1332
+
1333
+ assert count3 == v.length;
1334
+ }
1335
+ else // !trimmed
1336
+ {
1337
+ int count = 0;
1338
+ for (int i = 0; i < strips.length; i++)
1339
+ {
1340
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1341
+
1342
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1343
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1344
+
1345
+ drawVertex(gl, p, flipV, selectmode);
1346
+ drawVertex(gl, q, flipV, selectmode);
1347
+
1348
+ for (int j = 0; j < strips[i] - 2; j++)
1349
+ {
1350
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1351
+
1352
+ // if (j%2 == 0)
1353
+ // drawFace(p, q, r, display, null);
1354
+ // else
1355
+ // drawFace(p, r, q, display, null);
1356
+
1357
+ // p = q;
1358
+ // q = r;
1359
+ drawVertex(gl, r, flipV, selectmode);
1360
+ }
1361
+
1362
+ gl.glEnd();
1363
+ }
1364
+ }
1365
+ }
1366
+
1367
+ static cSpring.Point3D temp = new cSpring.Point3D();
1368
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1369
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1370
+
1371
+ public void DrawDynamicMesh(cMesh mesh)
1372
+ {
1373
+ GL gl = GetGL(); // getGL();
1374
+
1375
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1376
+
1377
+ gl.glDisable(gl.GL_LIGHTING);
1378
+
1379
+ gl.glLineWidth(1);
1380
+ gl.glColor3f(1,1,1);
1381
+ gl.glBegin(gl.GL_LINES);
1382
+ double scale = 0;
1383
+ int count = 0;
1384
+ for (int s=0; s<Phys.allSprings.size(); s++)
1385
+ {
1386
+ cSpring.Spring spring = Phys.allSprings.get(s);
1387
+ if(s == 0)
1388
+ {
1389
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1390
+ }
1391
+ if (mesh.showsprings)
1392
+ {
1393
+ temp.set(spring.a.position);
1394
+ temp.add(spring.b.position);
1395
+ temp.mul(0.5);
1396
+ temp2.set(spring.a.position);
1397
+ temp2.sub(spring.b.position);
1398
+ temp2.mul(spring.restLength/2);
1399
+ temp.sub(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ temp.add(temp2);
1402
+ temp.add(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ }
1405
+
1406
+ if (spring.isHandle)
1407
+ continue;
1408
+
1409
+ //if (scale < spring.restLength)
1410
+ scale += spring.restLength;
1411
+ count++;
1412
+ }
1413
+ gl.glEnd();
1414
+
1415
+ if (count == 0)
1416
+ scale = 0.01;
1417
+ else
1418
+ scale /= count * 3;
1419
+
1420
+ //scale = 0.25;
1421
+
1422
+ if (mesh.ShowInfo())
1423
+ {
1424
+ gl.glLineWidth(4);
1425
+ for (int s=0; s<Phys.allNodes.size(); s++)
1426
+ {
1427
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1428
+ if (node.mass == 0)
1429
+ continue;
1430
+
1431
+ int i = node.springs==null?-1:node.springs.size();
1432
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1433
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1434
+ //temp.normalize();
1435
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1436
+ gl.glBegin(gl.GL_LINES);
1437
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1438
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1439
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1440
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1441
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1442
+ gl.glEnd();
1443
+ }
1444
+
1445
+ gl.glLineWidth(8);
1446
+ for (int s=0; s<Phys.allNodes.size(); s++)
1447
+ {
1448
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1449
+
1450
+ if (node.springs != null)
1451
+ {
1452
+ for (int i=0; i<node.springs.size(); i+=1)
1453
+ {
1454
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1455
+
1456
+ int c = i+1;
1457
+ // c = node.springs.get(i).nbcopies;
1458
+
1459
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1460
+ gl.glBegin(gl.GL_LINES);
1461
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1462
+ 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);
1463
+ gl.glEnd();
1464
+ }
1465
+ }
1466
+ }
1467
+
1468
+ gl.glLineWidth(1);
1469
+ }
1470
+
1471
+ gl.glEnable(gl.GL_LIGHTING);
1472
+ }
1473
+
1474
+ /// INTERFACE
1475
+
1476
+ public void StartTriangles()
1477
+ {
1478
+ javax.media.opengl.GL gl = GetGL();
1479
+ gl.glBegin(gl.GL_TRIANGLES);
1480
+ }
1481
+
1482
+ public void EndTriangles()
1483
+ {
1484
+ GetGL().glEnd();
1485
+ }
1486
+
1487
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1488
+ {
1489
+ if (!selectmode)
1490
+ {
1491
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1492
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1493
+
1494
+ if (flipV)
1495
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1496
+ else
1497
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1498
+ }
1499
+
1500
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1501
+ }
1502
+
1503
+ float[] colorV = new float[4];
1504
+
1505
+ void SetColor(Object3D obj, Vertex p0)
1506
+ {
1507
+ CameraPane display = this;
1508
+ BoundaryRep bRep = obj.bRep;
1509
+
1510
+ if (RENDERPROGRAM == 0)
1511
+ {
1512
+ float r = 0;
1513
+ if (bRep != null)
1514
+ {
1515
+ if (bRep.stripified)
1516
+ {
1517
+ r = 1;
1518
+ }
1519
+ }
1520
+ float g = 0;
1521
+ if (bRep != null)
1522
+ {
1523
+ if (bRep.trimmed)
1524
+ {
1525
+ g = 1;
1526
+ }
1527
+ }
1528
+ float b = 0;
1529
+ if (obj.support != null && obj.link2master)
1530
+ {
1531
+ b = 1;
1532
+ }
1533
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1534
+ return;
1535
+ }
1536
+
1537
+ if (display.DrawMode() != CameraPane.SHADOW)
1538
+ return;
1539
+
1540
+ javax.media.opengl.GL gl = display.GetGL();
1541
+// if (true) return;
1542
+// float ao = p.AO;
1543
+//
1544
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1545
+// // ao = 1;
1546
+//
1547
+// gl.glColor4f(ao, ao, ao, 1);
1548
+
1549
+// CameraPane.selectedpoint.
1550
+// getAverage(cStatic.point1, true);
1551
+ if (CameraPane.pointflow == null) // !random) // live)
1552
+ {
1553
+ return;
1554
+ }
1555
+
1556
+ cStatic.point1.set(0,0,0);
1557
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1558
+
1559
+ cStatic.point1.sub(p0);
1560
+
1561
+
1562
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1563
+// {
1564
+// return;
1565
+// }
1566
+
1567
+ //if (true)
1568
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1569
+ {
1570
+ return;
1571
+ }
1572
+
1573
+ if (false) // marked)
1574
+ {
1575
+ // debug rigging weights
1576
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1577
+ {
1578
+ float weight = p0.weights[object] / p0.totalweight;
1579
+
1580
+ // if (weight < 0.1)
1581
+ // {
1582
+ // assert(weight == 0);
1583
+ // continue;
1584
+ // }
1585
+
1586
+ if (p0.vertexlinks[object] == -1)
1587
+ continue;
1588
+
1589
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1590
+
1591
+ int color = //1 << object; //
1592
+ //p.vertexlinks.length;
1593
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1594
+ colorV[2] += (color & 1) * weight;
1595
+ colorV[1] += ((color & 2) >> 1) * weight;
1596
+ colorV[0] += ((color & 4) >> 2) * weight;
1597
+ }
1598
+ }
1599
+ else
1600
+ {
1601
+ if (obj.drawingstarted)
1602
+ {
1603
+ // find next point
1604
+ if (bRep.GetVertex(0).faceindices == null)
1605
+ {
1606
+ bRep.InitFaceIndices();
1607
+ }
1608
+
1609
+ double ymin = p0.y;
1610
+
1611
+ Vertex newp = p0;
1612
+
1613
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1614
+ {
1615
+ int fi = p0.faceindices[fii];
1616
+
1617
+ if (fi == -1)
1618
+ break;
1619
+
1620
+ Face f = bRep.GetFace(fi);
1621
+
1622
+ Vertex p = bRep.GetVertex(f.p);
1623
+ Vertex q = bRep.GetVertex(f.q);
1624
+ Vertex r = bRep.GetVertex(f.r);
1625
+
1626
+ int swap = (int)(Math.random()*3);
1627
+
1628
+// for (int s=swap; --s>=0;)
1629
+// {
1630
+// Vertex t = p;
1631
+// p = q;
1632
+// q = r;
1633
+// r = t;
1634
+// }
1635
+ if (ymin > p.y)
1636
+ {
1637
+ ymin = p.y;
1638
+ newp = p;
1639
+// break;
1640
+ }
1641
+ if (ymin > q.y)
1642
+ {
1643
+ ymin = q.y;
1644
+ newp = q;
1645
+// break;
1646
+ }
1647
+ if (ymin > r.y)
1648
+ {
1649
+ ymin = r.y;
1650
+ newp = r;
1651
+// break;
1652
+ }
1653
+ }
1654
+
1655
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1656
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1657
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1658
+
1659
+ obj.drawingstarted = false;
1660
+
1661
+ // return;
1662
+ }
1663
+
1664
+ if (false) // CameraPane.DRAW
1665
+ {
1666
+ p0.AO = colorV[0] = 2;
1667
+ colorV[1] = 2;
1668
+ colorV[2] = 2;
1669
+ }
1670
+
1671
+ CameraPane.pointflow.add(p0);
1672
+ CameraPane.pointflow.Touch();
1673
+ }
1674
+
1675
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1676
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1677
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1678
+ }
1679
+
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1681
+ {
1682
+ CameraPane display = this;
1683
+ //new Exception().printStackTrace();
1684
+
1685
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1686
+ {
1687
+ return;
1688
+ }
1689
+
1690
+ javax.media.opengl.GL gl = display.GetGL();
1691
+
1692
+ //Color col = Color.getHSBColor(color,modulation,1);
1693
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1694
+ if (!material.multiply)
1695
+ {
1696
+ display.color = material.color;
1697
+ display.saturation = material.modulation;
1698
+ }
1699
+ else
1700
+ {
1701
+ display.color *= material.color*2;
1702
+ display.saturation *= material.modulation*2;
1703
+ }
1704
+
1705
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1706
+
1707
+ float[] colorV = Grafreed.colorV;
1708
+
1709
+ /**/
1710
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1711
+ {
1712
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1713
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1714
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1715
+ colorV[3] = 1; // material.opacity;
1716
+
1717
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1718
+ //System.out.println("Opacity = " + opacity);
1719
+
1720
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1721
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1722
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1723
+
1724
+ float amb = material.ambient;
1725
+ if (amb < material.cameralight)
1726
+ {
1727
+ amb = material.cameralight;
1728
+ }
1729
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1730
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1731
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1732
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1733
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1734
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1735
+
1736
+ /**/
1737
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1738
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1739
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1740
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1741
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1742
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1743
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1744
+ //System.out.println("shininess = " + colorV[0]);
1745
+ if (colorV[0] > 128)
1746
+ {
1747
+ colorV[0] = 128;
1748
+ }
1749
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1750
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1751
+ /**/
1752
+ }
1753
+ /**/
1754
+
1755
+ //selected = false;
1756
+ selected = selected && display.flash;
1757
+
1758
+ //display.modelParams0[0] = 0; // pigment.r;
1759
+ //display.modelParams0[1] = 0; // pigment.g;
1760
+ //display.modelParams0[2] = 0; // pigment.b;
1761
+ if (!material.multiply)
1762
+ {
1763
+ display.modelParams0[3] = material.metalness;
1764
+ display.modelParams1[0] = material.diffuse;
1765
+ display.modelParams1[1] = material.specular;
1766
+ display.modelParams1[2] = 1 / material.shininess;
1767
+ display.modelParams1[3] = material.shift;
1768
+ display.modelParams2[0] = material.ambient;
1769
+ display.modelParams2[1] = material.lightarea;
1770
+ //System.out.println("light area = " + lightarea);
1771
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1772
+ display.modelParams2[3] = material.velvet;
1773
+ display.modelParams3[0] = material.sheen;
1774
+ display.modelParams3[1] = material.subsurface;
1775
+ display.modelParams3[2] = material.bump; // backlit
1776
+ display.modelParams3[3] = material.aniso;
1777
+ display.modelParams4[0] = material.anisoV;
1778
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1779
+ //System.out.println("selected = " + selected);
1780
+ display.modelParams4[2] = material.diffuseness;
1781
+ display.modelParams4[3] = material.shadow;
1782
+ display.modelParams5[0] = material.texture;
1783
+ display.modelParams5[1] = material.opacity;
1784
+ display.modelParams5[2] = material.fakedepth;
1785
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1786
+ }
1787
+ else
1788
+ {
1789
+ display.modelParams0[3] *= material.metalness*2;
1790
+ display.modelParams1[0] *= material.diffuse*2;
1791
+ display.modelParams1[1] *= material.specular*2;
1792
+ display.modelParams1[2] *= material.shininess*2;
1793
+ display.modelParams1[3] *= material.shift*2;
1794
+ display.modelParams2[0] *= material.ambient*2;
1795
+ display.modelParams2[1] *= material.lightarea*2;
1796
+ display.modelParams2[2] *= material.factor*2;
1797
+ display.modelParams2[3] *= material.velvet*2;
1798
+ display.modelParams3[0] *= material.sheen*2;
1799
+ display.modelParams3[1] *= material.subsurface*2;
1800
+ display.modelParams3[2] *= material.bump*2;
1801
+ display.modelParams3[3] *= material.aniso*2;
1802
+ display.modelParams4[0] *= material.anisoV*2;
1803
+ display.modelParams4[1] *= material.cameralight*2;
1804
+ //System.out.println("selected = " + selected);
1805
+ display.modelParams4[2] *= material.diffuseness*2;
1806
+ display.modelParams4[3] *= material.shadow*2;
1807
+ display.modelParams5[0] *= material.texture*2;
1808
+ display.modelParams5[1] *= material.opacity*2;
1809
+ display.modelParams5[2] *= material.fakedepth*2;
1810
+ display.modelParams5[3] *= material.shadowbias*2;
1811
+ }
1812
+
1813
+ display.modelParams6[0] = 0;
1814
+ display.modelParams6[1] = 0;
1815
+ display.modelParams6[2] = 0;
1816
+ display.modelParams6[3] = 0;
1817
+
1818
+ display.modelParams7[0] = 0;
1819
+ display.modelParams7[1] = 1000;
1820
+ display.modelParams7[2] = 0;
1821
+ display.modelParams7[3] = 0;
1822
+
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
1824
+
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1826
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1827
+ {
1828
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1829
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1830
+ if (extparams.length > 1)
1831
+ {
1832
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1833
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1834
+ if (extparams.length > 2)
1835
+ {
1836
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1837
+ float x = extparams[2].y / 1000.0f;
1838
+ //if (x == 0)
1839
+ // x = 1f;
1840
+ 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
1841
+ if (extparams[2].y > 0)
1842
+ {
1843
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1844
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1845
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1846
+ }
1847
+ }
1848
+ }
1849
+ }
1850
+
1851
+ //if (display.modelParams6[2] != 0)
1852
+ /*
1853
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1854
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1855
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1856
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1857
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1858
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1859
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1860
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1861
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1862
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1863
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1864
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1865
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1866
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1867
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1868
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1869
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1870
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1871
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1872
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1873
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1874
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1875
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1876
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1877
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1878
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1879
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1880
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1881
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1882
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1883
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1884
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1885
+ /**/
1886
+ //assert (display.modelParams6[2] == 0);
1887
+
1888
+ //System.out.println("noise power = " + display.modelParams7[0]);
1889
+ //System.out.println("shadowbias = " + shadowbias);
1890
+
1891
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1892
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1893
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1896
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1897
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1898
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1899
+
1900
+ int mode = display.FP_SHADER;
1901
+
1902
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1903
+ {
1904
+ mode |= display.FP_ANISO;
1905
+ }
1906
+
1907
+ display.EnableProgram(mode);
1908
+
1909
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1910
+
1911
+ if (!material.multiply)
1912
+ {
1913
+ if (Globals.drawMode == CameraPane.SHADOW)
1914
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1915
+ else
1916
+ gl.glDepthMask(material.opacity >= 0.99);
1917
+ }
2081918 }
2091919
2101920 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1935,7 @@
2251935 currentGL.glMultMatrixd(model, 0);
2261936 }
2271937
228
- void PushMatrix(double[][] matrix, int count)
1938
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291939 {
2301940 matrixdepth++;
2311941 // GrafreeD.tracein(matrix);
....@@ -254,7 +1964,7 @@
2541964 void PushMatrix(double[][] matrix)
2551965 {
2561966 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
2581968 }
2591969
2601970 void PushMatrix()
....@@ -270,7 +1980,7 @@
2701980
2711981 double[][] tmpmat = new double[4][4];
2721982
273
- void PopMatrix(double[][] inverse)
1983
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741984 {
2751985 --matrixdepth;
2761986
....@@ -310,7 +2020,7 @@
3102020 PushTextureMatrix(matrix, 1);
3112021 }
3122022
313
- void PushTextureMatrix(double[][] matrix, int count)
2023
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142024 {
3152025 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162026
....@@ -324,7 +2034,7 @@
3242034 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252035 }
3262036
327
- void PopTextureMatrix(double[][] inverse)
2037
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282038 {
3292039 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302040 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2061,15 @@
3512061
3522062 static int camerachangeframe;
3532063
354
- boolean SetCamera(Camera cam)
2064
+ public boolean SetCamera(Camera cam)
3552065 {
3562066 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572067 // return false;
3582068
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2069
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602070 {
3612071 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2072
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632073 {
3642074 // refuse the camera change
3652075 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2077,7 @@
3672077 }
3682078 }
3692079
370
- camerachangeframe = framecount;
2080
+ camerachangeframe = Globals.framecount;
3712081
3722082 cam.hAspect = -1; // Read only
3732083
....@@ -398,7 +2108,7 @@
3982108 {
3992109 //System.err.println("Oeil on");
4002110 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2111
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022112 // object.editWindow.ScreenFit(trackedobject);
4032113 //pingthread.StepToTarget(true);
4042114 }
....@@ -407,8 +2117,8 @@
4072117 {
4082118 //System.err.println("Oeil on");
4092119 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2120
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122122 //pingthread.StepToTarget(true);
4132123 }
4142124
....@@ -471,39 +2181,12 @@
4712181 {
4722182 frozen ^= true;
4732183 // Weird...
474
- lighttouched = true;
2184
+ Globals.lighttouched = true;
4752185 }
4762186
4772187 void ToggleDL()
4782188 {
4792189 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;
5072190 }
5082191
5092192 void ToggleFullScreen()
....@@ -513,12 +2196,7 @@
5132196
5142197 void ToggleCrowd()
5152198 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2199
+ Globals.CROWD ^= true;
5222200 }
5232201
5242202 void ToggleLocal()
....@@ -526,62 +2204,89 @@
5262204 LOCALTRANSFORM ^= true;
5272205 }
5282206
529
- void ToggleFast()
2207
+ public void ToggleTexture()
2208
+ {
2209
+ textureon ^= true;
2210
+ }
2211
+
2212
+ public void ToggleLive()
2213
+ {
2214
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2215
+
2216
+ System.err.println("LIVE = " + Globals.isLIVE());
2217
+
2218
+ if (!Globals.isLIVE()) // save sound
2219
+ Grafreed.savesound = true; // wav.save();
2220
+ // else
2221
+ repaint(); // start loop // may 2013
2222
+ }
2223
+
2224
+ public void ToggleSupport()
2225
+ {
2226
+ SUPPORT ^= true;
2227
+ }
2228
+
2229
+ public void ToggleAbort()
2230
+ {
2231
+ ABORTMODE ^= true;
2232
+ }
2233
+
2234
+ public void ToggleInertia()
2235
+ {
2236
+ INERTIA ^= true;
2237
+ }
2238
+
2239
+ public void ToggleFast()
5302240 {
5312241 FAST ^= true;
5322242 }
5332243
534
- void ToggleSlowPose()
2244
+ public void ToggleSlowPose()
5352245 {
5362246 SLOWPOSE ^= true;
5372247 }
5382248
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2249
+ public void ToggleBoxMode()
5452250 {
5462251 BOXMODE ^= true;
5472252 }
5482253
549
- void ToggleSmoothFocus()
2254
+ public void ToggleZoomBoxMode()
2255
+ {
2256
+ ZOOMBOXMODE ^= true;
2257
+ }
2258
+
2259
+ public void ToggleSmoothFocus()
5502260 {
5512261 SMOOTHFOCUS ^= true;
5522262 }
5532263
554
- void ToggleImageFlip()
2264
+ public void ToggleImageFlip()
5552265 {
5562266 IMAGEFLIP ^= true;
5572267 }
5582268
559
- void ToggleSpeakerMocap()
2269
+ public void ToggleSpeakerMocap()
5602270 {
5612271 SPEAKERMOCAP ^= true;
5622272 }
5632273
564
- void ToggleSpeakerCamera()
2274
+ public void ToggleSpeakerCamera()
5652275 {
5662276 SPEAKERCAMERA ^= true;
5672277 }
5682278
569
- void ToggleSpeakerFocus()
2279
+ public void ToggleSpeakerFocus()
5702280 {
5712281 SPEAKERFOCUS ^= true;
5722282 }
5732283
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2284
+ public void ToggleFrustum()
5802285 {
5812286 FRUSTUM ^= true;
5822287 }
5832288
584
- void ToggleTrack()
2289
+ public void ToggleTrack()
5852290 {
5862291 TRACK ^= true;
5872292 if (TRACK)
....@@ -600,25 +2305,35 @@
6002305 repaint();
6012306 }
6022307
603
- void ToggleTrackOnce()
2308
+ public void ToggleTrackOnce()
6042309 {
6052310 TRACKONCE ^= true;
6062311 }
6072312
608
- void ToggleShadowTrack()
2313
+ public void ToggleShadowTrack()
6092314 {
6102315 SHADOWTRACK ^= true;
6112316 repaint();
6122317 }
6132318
614
- void ToggleOeil()
2319
+ public void ToggleOeil()
6152320 {
6162321 OEIL ^= true;
6172322 }
6182323
619
- void ToggleOeilOnce()
2324
+ public void ToggleOeilOnce()
6202325 {
6212326 OEILONCE ^= true;
2327
+ }
2328
+
2329
+ void ToggleFootContact()
2330
+ {
2331
+ FOOTCONTACT ^= true;
2332
+ }
2333
+
2334
+ void ToggleDebug()
2335
+ {
2336
+ Globals.DEBUG ^= true;
6222337 }
6232338
6242339 void ToggleLookAt()
....@@ -626,9 +2341,9 @@
6262341 LOOKAT ^= true;
6272342 }
6282343
629
- void ToggleRandom()
2344
+ void ToggleSwitch()
6302345 {
631
- RANDOM ^= true;
2346
+ SWITCH ^= true;
6322347 }
6332348
6342349 void ToggleHandles()
....@@ -636,10 +2351,17 @@
6362351 HANDLES ^= true;
6372352 }
6382353
2354
+ Object3D paintFolder;
2355
+
6392356 void TogglePaint()
6402357 {
6412358 PAINTMODE ^= true;
6422359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
6432365 }
6442366
6452367 void SwapCamera(int a, int b)
....@@ -672,34 +2394,6 @@
6722394 //assert (cam.hAspect == 0);
6732395 cam.hAspect = 0;
6742396 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
7032397 }
7042398
7052399 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2453,26 @@
7592453
7602454 GL currentGL;
7612455
762
- GL GetGL()
2456
+ public GL GetGL() // INTERFACE
7632457 {
7642458 return currentGL;
7652459 }
766
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
7672476 /**/
7682477 class CacheTexture
7692478 {
....@@ -772,28 +2481,31 @@
7722481
7732482 int resolution;
7742483
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762485 {
777
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
7782488 resolution = res;
7792489 }
7802490 }
7812491 /**/
7822492
7832493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
7872499 int pigmentdepth = 0;
7882500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892501 int bumpdepth = 0;
7902502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952507
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972509 {
7982510 TextureData texturedata = null;
7992511
....@@ -812,13 +2524,34 @@
8122524 if (bump)
8132525 texturedata = ConvertBump(texturedata, false);
8142526
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202532
821
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
8222555 }
8232556
8242557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3624,8 @@
18913624
18923625 System.out.println("LOADING TEXTURE : " + name);
18933626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
18943629 //
18953630 if (false) // compressbit > 0)
18963631 {
....@@ -2595,6 +4330,7 @@
25954330
25964331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25974332 {
4333
+ new Exception().printStackTrace();
25984334 System.exit(0);
25994335 com.sun.opengl.util.texture.Texture texture = null;
26004336
....@@ -6271,7 +8007,7 @@
62718007 return null;
62728008 }
62738009
6274
- void ReleaseTextures(cTexture tex)
8010
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62758011 {
62768012 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62778013 {
....@@ -6288,7 +8024,7 @@
62888024 String pigment = Object3D.GetPigment(tex);
62898025 String bump = Object3D.GetBump(tex);
62908026
6291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62928028 {
62938029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62948030 // System.out.println("; bump = " + bump);
....@@ -6303,13 +8039,71 @@
63038039 pigment = null;
63048040 }
63058041
6306
- ReleaseTexture(bump, true);
6307
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
63088044 }
63098045
6310
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63118047 {
6312
- if (// drawMode != 0 || /*tex == null ||*/
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
8105
+ {
8106
+ if (// DrawMode() != 0 || /*tex == null ||*/
63138107 ambientOcclusion ) // || !textureon)
63148108 {
63158109 return;
....@@ -6318,7 +8112,7 @@
63188112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63198113
63208114 if (tex != null)
6321
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63228116
63238117 // //assert( texture != null );
63248118 // if (texture == null)
....@@ -6410,9 +8204,57 @@
64108204 }
64118205 }
64128206
6413
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64148208 {
6415
- if (// drawMode != 0 || /*tex == null ||*/
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8256
+ {
8257
+ if (// DrawMode() != 0 || /*tex == null ||*/
64168258 ambientOcclusion ) // || !textureon)
64178259 {
64188260 return; // false;
....@@ -6421,17 +8263,47 @@
64218263 if (tex == null)
64228264 {
64238265 BindTexture(null,false,resolution);
6424
- BindTexture(null,true,resolution);
64258266 return;
64268267 }
64278268
64288269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
64298302 String bump = Object3D.GetBump(tex);
64308303
6431
- usedtextures.put(pigment, pigment);
6432
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
64338305
6434
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64358307 {
64368308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64378309 // System.out.println("; bump = " + bump);
....@@ -6441,43 +8313,94 @@
64418313 {
64428314 bump = null;
64438315 }
6444
- if (pigment.equals(""))
6445
- {
6446
- pigment = null;
6447
- }
64488316
6449
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
- BindTexture(pigment, false, resolution);
64518317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6452
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
64538319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6454
-
6455
- return; // true;
64568320 }
64578321
6458
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
64598325 {
6460
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
64618345
64628346 if (tex != null)
64638347 {
6464
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64658350
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;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
64728368
64738369 if (CACHETEXTURE)
6474
- texture = textures.get(texname); // TEXTURE CACHE
6475
-
6476
- TextureData texturedata = null;
6477
-
6478
- if (texture == null || texture.resolution < resolution)
64798370 {
6480
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64818404 {
64828405 assert(!bump);
64838406 // if (bump)
....@@ -6488,19 +8411,23 @@
64888411 // }
64898412 // else
64908413 // {
6491
- texture = textures.get(tex);
6492
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
64938416 {
6494
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64958418 }
8419
+ else
8420
+ new Exception().printStackTrace();
64968421 // }
64978422 } else
6498
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64998424 {
65008425 assert(bump);
6501
- texture = textures.get(tex);
6502
- if (texture == null)
6503
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
65048431 } else
65058432 {
65068433 //if (tex.equals("IMMORTAL"))
....@@ -6508,11 +8435,22 @@
65088435 // texture = GetResourceTexture("default.png");
65098436 //} else
65108437 //{
6511
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
65128439 {
6513
- texture = textures.get(tex);
6514
- if (texture == null)
6515
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
65168454 } else
65178455 {
65188456 if (textureon)
....@@ -6537,7 +8475,7 @@
65378475 }
65388476
65398477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6540
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
65418479 cachename = texname;
65428480 else
65438481 processbump = false; // don't process bump map again
....@@ -6559,7 +8497,7 @@
65598497 }
65608498
65618499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6562
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
65638501 cachename = texname;
65648502 else
65658503 processbump = false; // don't process bump map again
....@@ -6568,20 +8506,23 @@
65688506 texturedata = GetFileTexture(cachename, processbump, resolution);
65698507
65708508
6571
- if (texturedata != null)
6572
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
65738513 //texture = GetTexture(tex, bump);
65748514 }
8515
+ }
65758516 }
65768517 //}
65778518 }
65788519
6579
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65808521 {
65818522 //return false;
65828523
65838524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6584
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65858526 {
65868527 // String ext = "_highres";
65878528 // if (REDUCETEXTURE)
....@@ -6598,52 +8539,17 @@
65988539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65998540 if (!cachefile.exists())
66008541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
66108543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
66418546 ImageWriter writer = null;
66428547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66438548 if (iter.hasNext()) {
66448549 writer = (ImageWriter)iter.next();
66458550 }
6646
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
66478553 try
66488554 {
66498555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6660,18 +8566,20 @@
66608566 }
66618567 }
66628568 }
6663
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
66648572 //System.out.println("Texture = " + tex);
6665
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
66668574 {
6667
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
66688576 thetex.texture.disable();
66698577 thetex.texture.dispose();
6670
- textures.remove(texname);
8578
+ textures.remove(tex);
66718579 }
66728580
6673
- texture.texturedata = texturedata;
6674
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
66758583
66768584 // newtex = true;
66778585 }
....@@ -6687,10 +8595,44 @@
66878595 }
66888596 }
66898597
6690
- return texture;
8598
+ return texturecache;
66918599 }
66928600
6693
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66948636 {
66958637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66968638
....@@ -6708,21 +8650,21 @@
67088650 return texture!=null?texture.texture:null;
67098651 }
67108652
6711
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67128654 {
67138655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67148656
67158657 return texture!=null?texture.texturedata:null;
67168658 }
67178659
6718
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67198661 {
67208662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67218663 {
67228664 return false;
67238665 }
67248666
6725
- boolean newtex = false;
8667
+ //boolean newtex = false;
67268668
67278669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67288670
....@@ -6754,9 +8696,75 @@
67548696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67558697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67568698
6757
- return newtex;
8699
+ return true; // Warning: not used.
67588700 }
67598701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
67608768 ShadowBuffer shadowPBuf;
67618769 AntialiasBuffer antialiasPBuf;
67628770 int MAXSTACK;
....@@ -6773,10 +8781,12 @@
67738781
67748782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67758783 MAXSTACK = temp[0];
6776
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67778786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67788787 MAXSTACK = temp[0];
6779
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67808790
67818791 // Use debug pipeline
67828792 //drawable.setGL(new DebugGL(gl)); //
....@@ -6784,7 +8794,8 @@
67848794 gl = drawable.getGL(); //
67858795
67868796 GL gl3 = getGL();
6787
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67888799
67898800
67908801 //float pos[] = { 100, 100, 100, 0 };
....@@ -6949,7 +8960,7 @@
69498960
69508961 if (cubemap == null)
69518962 {
6952
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
69538964 }
69548965
69558966 //cubemap.enable();
....@@ -7225,6 +9236,8 @@
72259236
72269237 void LoadEnvy(int which)
72279238 {
9239
+ assert(false);
9240
+
72289241 String name;
72299242 String ext;
72309243
....@@ -7236,37 +9249,58 @@
72369249 cubemap = null;
72379250 return;
72389251 case 1:
7239
- name = "cubemaps/box_";
7240
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
72419254 reverseUP = false;
72429255 break;
72439256 case 2:
7244
- name = "cubemaps/uffizi_";
7245
- ext = "png";
7246
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
72479261 case 3:
7248
- name = "cubemaps/CloudyHills_";
7249
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
72509264 reverseUP = false;
72519265 break;
72529266 case 4:
7253
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
72549268 ext = "png";
72559269 reverseUP = false;
72569270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
72579296 default:
7258
- name = "cubemaps/rgb_";
7259
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
72609300 break;
72619301 }
7262
-
7263
- try
7264
- {
7265
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7266
- } catch (IOException e)
7267
- {
7268
- throw new RuntimeException(e);
7269
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
72709304 }
72719305
72729306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7298,8 +9332,12 @@
72989332 static double[] model = new double[16];
72999333 double[] camera2light = new double[16];
73009334 double[] light2camera = new double[16];
7301
- int newenvy = -1;
7302
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
73039341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73049342 //float[] light0 = { 0,0,0 };
73059343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7312,9 +9350,9 @@
73129350 static boolean occlusionInitialized = false;
73139351 boolean selection = false;
73149352 boolean pointselection = false;
7315
- /*static*/ boolean lighttouched = true;
9353
+ ///*static*/ boolean lighttouched = true;
73169354 boolean deselect;
7317
- boolean ambientOcclusion = false;
9355
+ private boolean ambientOcclusion = false;
73189356 static boolean flash = false;
73199357 /*static*/ boolean wait = false;
73209358 boolean displaydone = false; // after repaint() calls
....@@ -7444,6 +9482,8 @@
74449482 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74459483 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74469484 double scale = lightCamera.SCALE / lightCamera.Distance();
9485
+// PATCH FILLE AUX JEANS
9486
+ //scale *= lightCamera.shaper_fovy / 25;
74479487 gl.glScaled(2 * scale, 2 * scale, -scale);
74489488 gl.glTranslated(0, 0, lightCamera.DECAL);
74499489
....@@ -7590,18 +9630,40 @@
75909630 jy8[3] = 0.5f;
75919631 }
75929632
7593
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75949634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
75959635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
75969636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75979637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
75989662 static int imagecount = 0; // movie generation
75999663
76009664 static int jitter = 0;
76019665
76029666 boolean restartframe = false;
7603
-
7604
- static int framecount = 0; // general-purpose global count
76059667
76069668 void displayAntiAliased(javax.media.opengl.GL gl)
76079669 {
....@@ -7633,7 +9695,7 @@
76339695 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76349696 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76359697 {
7636
- framecount++;
9698
+ Globals.framecount++;
76379699
76389700 if (CameraPane.tickcount > 0)
76399701 CameraPane.tickcount--;
....@@ -7671,7 +9733,7 @@
76719733
76729734 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76739735 */
7674
- lighttouched = true;
9736
+ Globals.lighttouched = true;
76759737 //System.err.println(" shadowbuffer: " + jitter);
76769738 shadowbuffer.display();
76779739
....@@ -7692,8 +9754,8 @@
76929754 assert (parentcam != renderCamera);
76939755
76949756 if (renderCamera != lightCamera)
7695
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7696
- LA.matConcat(parentcam.toParent, matrix, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76979759
76989760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76999761
....@@ -7708,8 +9770,8 @@
77089770 LA.matCopy(renderCamera.fromScreen, matrix);
77099771
77109772 if (renderCamera != lightCamera)
7711
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7712
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77139775
77149776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77159777
....@@ -7755,10 +9817,12 @@
77559817 rati = 1 / rati;
77569818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77579819 }
7758
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
77599823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77609824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7761
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
77629826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77639827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77649828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7781,7 +9845,7 @@
77819845 //gl.glFlush();
77829846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77839847
7784
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
77859849 {
77869850 System.err.println(" ABORTED FRAME");
77879851 break;
....@@ -7811,7 +9875,7 @@
78119875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78129876
78139877 // save image
7814
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
78159879 {
78169880 VPwidth = viewport[2];
78179881 VPheight = viewport[3];
....@@ -7922,11 +9986,11 @@
79229986
79239987 // imagecount++;
79249988
7925
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79269990
79279991 if (!BOXMODE)
79289992 {
7929
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79309994 }
79319995
79329996 if (!BOXMODE)
....@@ -7964,7 +10028,7 @@
796410028 ABORTED = false;
796510029 }
796610030 else
7967
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
796810032
796910033 if (false)
797010034 {
....@@ -8618,13 +10682,6 @@
861810682 }
861910683 }
862010684
8621
- boolean IsFrozen()
8622
- {
8623
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8624
-
8625
- return !selectmode && cameracount == 0; // != 0;
8626
- }
8627
-
862810685 boolean niceon = false;
862910686 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
863010687 boolean currentlydrawing = false;
....@@ -8634,16 +10691,16 @@
863410691
863510692 public void display(GLAutoDrawable drawable)
863610693 {
8637
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
863810695 {
8639
- GrafreeD.wav.save();
8640
- GrafreeD.savesound = false;
8641
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
864210699 }
864310700 // if (DEBUG_SELECTION)
864410701 // {
8645
-// if (drawMode != SELECTION)
8646
-// drawMode = SELECTION;
10702
+// if (DrawMode() != SELECTION)
10703
+// DrawMode() = SELECTION;
864710704 // }
864810705
864910706 if (!isRenderer)
....@@ -8699,9 +10756,9 @@
869910756
870010757 //ANTIALIAS = 0;
870110758
8702
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10759
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870310760 {
8704
- if (niceon || isLIVE())
10761
+ if (niceon || Globals.isLIVE())
870510762 {
870610763 //if(active == 0)
870710764 // antialiaser = null;
....@@ -8714,6 +10771,7 @@
871410771 ANTIALIAS = 0;
871510772 //System.out.println("RESTART");
871610773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
871710775 }
871810776 }
871910777 }
....@@ -8726,7 +10784,7 @@
872610784 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872710785 */
872810786
8729
- if (drawMode == DEFAULT)
10787
+ if (DrawMode() == DEFAULT)
873010788 {
873110789 currentlydrawing = true;
873210790 }
....@@ -8757,18 +10815,18 @@
875710815
875810816 // if(Applet3D.clipboard != null)
875910817 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8760
-//drawMode = SELECTION;
10818
+//DrawMode() = SELECTION;
876110819 indexcount = 0;
876210820
8763
- if (drawMode == OCCLUSION)
10821
+ if (DrawMode() == OCCLUSION)
876410822 {
8765
- drawMode = DEFAULT;
10823
+ Globals.drawMode = DEFAULT; // WARNING
876610824 ambientOcclusion = true;
876710825 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876810826 Object3D theobject = object;
876910827 Object3D theparent = object.parent;
877010828 object.parent = null;
8771
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
877210830 object.Stripify();
877310831 if (theobject.selection == null || theobject.selection.Size() == 0)
877410832 theobject.PreprocessOcclusion(this);
....@@ -8781,26 +10839,27 @@
878110839 ambientOcclusion = false;
878210840 }
878310841
8784
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878510844 {
878610845 //if (RENDERSHADOW) // ?
878710846 if (!IsFrozen())
878810847 {
878910848 // dec 2012
8790
- if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
879110850 {
8792
- framecount++;
10851
+ Globals.framecount++;
879310852 shadowbuffer.display();
879410853 }
879510854 }
8796
- lighttouched = false; // ??
10855
+ Globals.lighttouched = false; // ??
879710856 //drawing = true;
879810857 //lighttouched = true;
879910858 }
880010859
880110860 if (wait)
880210861 {
8803
- Sleep(500);
10862
+ Sleep(200); // blocks everything
880410863
880510864 wait = false;
880610865 }
....@@ -8814,9 +10873,9 @@
881410873 //eyeCamera.shaper_fovy = 1;
881510874 }
881610875
8817
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10876
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881810877 {
8819
- //System.out.println("drawMode = " + drawMode);
10878
+ //System.out.println("DrawMode() = " + DrawMode());
882010879 vertexMode |= VP_PASS;
882110880 //vertexMode |= VP_PROJECTION;
882210881 if (!ambientOcclusion)
....@@ -8876,7 +10935,7 @@
887610935 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887710936 //Camera lightcam = new Camera(light0);
887810937
8879
- if (drawMode == SHADOW)
10938
+ if (DrawMode() == SHADOW)
888010939 {
888110940 /*
888210941 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8914,8 +10973,8 @@
891410973
891510974 // if (parentcam != renderCamera) // not a light
891610975 if (cam != lightCamera)
8917
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8918
- LA.matConcat(parentcam.toParent, matrix, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891910978
892010979 for (int j = 0; j < 4; j++)
892110980 {
....@@ -8929,8 +10988,8 @@
892910988
893010989 // if (parentcam != renderCamera) // not a light
893110990 if (cam != lightCamera)
8932
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8933
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893410993
893510994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893610995
....@@ -8966,7 +11025,7 @@
896611025 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896711026 } else
896811027 {
8969
- if (drawMode != DEFAULT)
11028
+ if (DrawMode() != DEFAULT)
897011029 {
897111030 gl.glClearColor(1, 1, 1, 0);
897211031 } // 1);
....@@ -9016,13 +11075,41 @@
901611075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901711076 }
901811077
9019
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
902011086 {
9021
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
902211093 }
9023
-
9024
- newenvy = -1;
9025
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
902611113 ratio = ((double) getWidth()) / getHeight();
902711114 //System.out.println("ratio = " + ratio);
902811115
....@@ -9031,14 +11118,14 @@
903111118
903211119 fast &= !ambientOcclusion;
903311120
9034
- if (drawMode == DEFAULT)
11121
+ if (DrawMode() == DEFAULT)
903511122 {
903611123 //gl.glEnable(gl.GL_ALPHA_TEST);
903711124 //gl.glActiveTexture(GL.GL_TEXTURE0);
903811125
903911126 if (!IsFrozen() && !ambientOcclusion)
904011127 {
9041
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
904211129 }
904311130
904411131 //if (selection_view == -1)
....@@ -9092,6 +11179,8 @@
909211179 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909311180 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909411181 double scale = lightCamera.SCALE / lightCamera.Distance();
11182
+// PATCH FILLE AUX JEANS
11183
+ //scale *= lightCamera.shaper_fovy / 25;
909511184 gl.glScaled(2 * scale, 2 * scale, -scale);
909611185 gl.glTranslated(0, 0, lightCamera.DECAL);
909711186
....@@ -9187,7 +11276,16 @@
918711276 // Bump noise
918811277 gl.glActiveTexture(GL.GL_TEXTURE6);
918911278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9190
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
919111289
919211290 gl.glActiveTexture(GL.GL_TEXTURE0);
919311291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9210,9 +11308,9 @@
921011308
921111309 gl.glMatrixMode(GL.GL_MODELVIEW);
921211310
9213
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9214
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9215
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
921611314 } else
921711315 {
921811316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9223,14 +11321,16 @@
922311321 //System.out.println("BLENDING ON");
922411322 gl.glEnable(GL.GL_BLEND);
922511323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9226
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922711325 gl.glMatrixMode(gl.GL_PROJECTION);
922811326 gl.glLoadIdentity();
922911327
9230
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11328
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
923111329 {
923211330 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923311331 double scale = lightCamera.SCALE / lightCamera.Distance();
11332
+// PATCH FILLE AUX JEANS
11333
+ //scale *= lightCamera.shaper_fovy / 25;
923411334 gl.glScaled(2 * scale, 2 * scale, -scale);
923511335 gl.glTranslated(0, 0, lightCamera.DECAL);
923611336 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9283,7 +11383,7 @@
928311383 //gl.glPushMatrix();
928411384 gl.glLoadIdentity();
928511385
9286
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11386
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928711387 {
928811388 //LA.xformPos(light0, lightCamera.fromScreen, light);
928911389 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9310,8 +11410,8 @@
931011410 System.err.println("parentcam != renderCamera");
931111411
931211412 // if (cam != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
931511415 }
931611416
931711417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9332,8 +11432,8 @@
933211432 if (true) // TODO
933311433 {
933411434 if (cam != lightCamera)
9335
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9336
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933711437 }
933811438
933911439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9370,7 +11470,7 @@
937011470 }
937111471
937211472 /**/
9373
- if (true) // drawMode == SELECTION) // != DEFAULT)
11473
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937411474 gl.glDisable(gl.GL_LIGHTING);
937511475 else
937611476 gl.glEnable(gl.GL_LIGHTING);
....@@ -9388,7 +11488,7 @@
938811488
938911489 lightslot = 64;
939011490
9391
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11491
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
939211492 {
939311493 DrawLights(object);
939411494 }
....@@ -9399,7 +11499,7 @@
939911499 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
940011500 //System.out.println("fragmentMode = " + fragmentMode);
940111501
9402
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11502
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
940311503 {
940411504 /*
940511505 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9432,7 +11532,7 @@
943211532 }
943311533 }
943411534
9435
- if (drawMode == DEFAULT)
11535
+ if (DrawMode() == DEFAULT)
943611536 {
943711537 if (WIREFRAME && !ambientOcclusion)
943811538 {
....@@ -9450,7 +11550,7 @@
945011550 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
945111551 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
945211552
9453
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11553
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945411554 {
945511555 if (vertexMode != 0) // && !fast)
945611556 {
....@@ -9470,7 +11570,7 @@
947011570 }
947111571 }
947211572
9473
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947411574 {
947511575 //gl.glDepthFunc(GL.GL_LEQUAL);
947611576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9478,27 +11578,24 @@
947811578
947911579 boolean texon = textureon;
948011580
9481
- if (RENDERPROGRAM > 0)
9482
- {
9483
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9484
- textureon = false;
9485
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
948611584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948711585 //System.out.println("ALLO");
948811586 gl.glColorMask(false, false, false, false);
948911587 DrawObject(gl);
9490
- if (RENDERPROGRAM > 0)
9491
- {
9492
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9493
- textureon = texon;
9494
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
949511592 gl.glColorMask(true, true, true, true);
949611593
949711594 gl.glDepthFunc(GL.GL_EQUAL);
9498
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
949911596 }
950011597
9501
- if (false) // drawMode == SHADOW)
11598
+ if (false) // DrawMode() == SHADOW)
950211599 {
950311600 //SetColumnMajorData(cameraInverseTransform, view_1);
950411601 //System.out.println("light = " + cameraInverseTransform);
....@@ -9512,16 +11609,16 @@
951211609 //System.out.println("object = " + object);
951311610 if (!frozen && !imageLocked)
951411611 {
9515
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11612
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951611613 {
951711614 displayAntiAliased(gl);
951811615 } else
951911616 {
952011617 programcount = 0;
9521
- int keepmode = drawMode;
11618
+ int keepmode = DrawMode();
952211619 // if (DEBUG_SELECTION)
952311620 // {
9524
-// drawMode = SELECTION;
11621
+// DrawMode() = SELECTION;
952511622 // }
952611623 // for point selection
952711624 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9531,10 +11628,10 @@
953111628 DrawObject(gl);
953211629
953311630 // jan 2013 System.err.println("RESET ABORT (display)");
9534
- // if (drawMode == DEFAULT)
11631
+ // if (DrawMode() == DEFAULT)
953511632 // ABORTED = false;
953611633 fullreset = false;
9537
- drawMode = keepmode;
11634
+ Globals.drawMode = keepmode; // WARNING
953811635 //System.out.println("PROGRAM SWITCH " + programcount);
953911636 }
954011637 }
....@@ -9542,11 +11639,11 @@
954211639 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
954311640 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954411641
9545
- if (drawMode == DEFAULT)
11642
+ if (DrawMode() == DEFAULT)
954611643 {
954711644 ReleaseTexture(NOISE_TEXTURE, false);
954811645 }
9549
- //if (drawMode == DEFAULT)
11646
+ //if (DrawMode() == DEFAULT)
955011647 {
955111648
955211649 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9558,7 +11655,7 @@
955811655 //else
955911656 //gl.glDisable(gl.GL_TEXTURE_2D);
956011657 //gl.glPopMatrix();
9561
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11658
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
956211659 {
956311660 //new Exception().printStackTrace();
956411661 //System.out.println("Draw image " + width + ", " + height);
....@@ -9600,7 +11697,7 @@
960011697 //gl.glFlush();
960111698 }
960211699
9603
- if (flash && drawMode == DEFAULT)
11700
+ if (flash && DrawMode() == DEFAULT)
960411701 {
960511702 flash = false;
960611703 wait = true;
....@@ -9608,9 +11705,9 @@
960811705 }
960911706
961011707 //drawing = false;
9611
- //if(drawMode == DEFAULT)
11708
+ //if(DrawMode() == DEFAULT)
961211709 // niceon = false;
9613
- if (drawMode == DEFAULT)
11710
+ if (DrawMode() == DEFAULT)
961411711 {
961511712 currentlydrawing = false;
961611713 }
....@@ -9630,7 +11727,7 @@
963011727 repaint();
963111728 }
963211729
9633
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11730
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963411731 repaint();
963511732
963611733 displaydone = true;
....@@ -9649,8 +11746,14 @@
964911746 {
965011747 renderpass++;
965111748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
965211750 if (FAST) // in case there is no script
9653
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
965411757
965511758 //object.FullInvariants();
965611759
....@@ -9664,23 +11767,44 @@
966411767 e.printStackTrace();
966511768 }
966611769
9667
- if (GrafreeD.RENDERME > 0)
9668
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
966911772
9670
- ONESTEP = false;
11773
+ Globals.ONESTEP = false;
967111774 }
967211775
967311776 static boolean zoomonce = false;
967411777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
967511796 void DrawObject(GL gl, boolean draw)
967611797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
967711801 //System.out.println("DRAW OBJECT " + mouseDown);
9678
-// drawMode = SELECTION;
11802
+// DrawMode() = SELECTION;
967911803 //GL gl = getGL();
968011804 if ((TRACK || SHADOWTRACK) || zoomonce)
968111805 {
9682
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9683
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11806
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968411808 pingthread.StepToTarget(true); // true);
968511809 // zoomonce = false;
968611810 }
....@@ -9700,9 +11824,9 @@
970011824 callist = gl.glGenLists(1);
970111825 }
970211826
9703
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11827
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970411828
9705
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11829
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970611830
970711831 if (!mainDL || !active || touched)
970811832 {
....@@ -9729,13 +11853,20 @@
972911853 PushMatrix(ClickInfo.matbuffer);
973011854 }
973111855
9732
- if (drawMode == 0)
11856
+ if (DrawMode() == 0)
973311857 {
973411858 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973511859
973611860 usedtextures.clear();
973711861
9738
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
973911870 }
974011871 //System.out.println("--> " + stackdepth);
974111872 // GrafreeD.traceon();
....@@ -9743,10 +11874,11 @@
974311874 // DRAW
974411875 object.draw(this, /*(Composite)*/ object, false, false);
974511876
9746
- if (drawMode == DEFAULT)
11877
+ if (DrawMode() == DEFAULT)
974711878 {
9748
- if (DEBUG)
11879
+ if (Globals.DEBUG)
974911880 {
11881
+ CreateSelectedPoint();
975011882 float radius = 0.05f;
975111883 if (selectedpoint.radius != radius)
975211884 {
....@@ -9754,40 +11886,40 @@
975411886 selectedpoint.radius = radius;
975511887 selectedpoint.recalculate();
975611888 selectedpoint.material = new cMaterial();
9757
- selectedpoint.material.color = 0.25f;
11889
+ selectedpoint.material.color = 0.15f; // Yellow
975811890 selectedpoint.material.modulation = 0.75f;
975911891
9760
- debugpoint.radius = radius;
9761
- debugpoint.recalculate();
9762
- debugpoint.material = new cMaterial();
9763
- debugpoint.material.color = 0.25f;
9764
- debugpoint.material.modulation = 0.75f;
11892
+ debugpointG.radius = radius;
11893
+ debugpointG.recalculate();
11894
+ debugpointG.material = new cMaterial();
11895
+ debugpointG.material.color = 0.25f; // Green
11896
+ debugpointG.material.modulation = 0.75f;
976511897
9766
- debugpoint2.radius = radius;
9767
- debugpoint2.recalculate();
9768
- debugpoint2.material = new cMaterial();
9769
- debugpoint2.material.color = 0.75f;
9770
- debugpoint2.material.modulation = 0.75f;
11898
+ debugpointP.radius = radius;
11899
+ debugpointP.recalculate();
11900
+ debugpointP.material = new cMaterial();
11901
+ debugpointP.material.color = 0.75f; // Purple
11902
+ debugpointP.material.modulation = 0.75f;
977111903
9772
- debugpoint3.radius = radius;
9773
- debugpoint3.recalculate();
9774
- debugpoint3.material = new cMaterial();
9775
- debugpoint3.material.color = 0.5f;
9776
- debugpoint3.material.modulation = 0.75f;
11904
+ debugpointC.radius = radius;
11905
+ debugpointC.recalculate();
11906
+ debugpointC.material = new cMaterial();
11907
+ debugpointC.material.color = 0.5f; // Cyan
11908
+ debugpointC.material.modulation = 0.75f;
977711909
9778
- debugpoint4.radius = radius;
9779
- debugpoint4.recalculate();
9780
- debugpoint4.material = new cMaterial();
9781
- debugpoint4.material.color = 0f;
9782
- debugpoint4.material.modulation = 0.75f;
11910
+ debugpointR.radius = radius;
11911
+ debugpointR.recalculate();
11912
+ debugpointR.material = new cMaterial();
11913
+ debugpointR.material.color = 0f; // Red
11914
+ debugpointR.material.modulation = 0.75f;
978311915
978411916 InitPoints(radius);
978511917 }
978611918 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);
11919
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11920
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11921
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11922
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
979111923 // DrawPoints(this);
979211924 }
979311925
....@@ -9795,42 +11927,63 @@
979511927 }
979611928 // GrafreeD.traceoff();
979711929 //System.out.println(stackdepth);
9798
- if (drawMode == 0)
11930
+ if (DrawMode() == 0)
979911931 {
980011932 ReleaseTextures(DEFAULT_TEXTURES);
980111933
980211934 if (CLEANCACHE)
9803
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
980411936 {
9805
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
980611938
980711939 // System.out.println("Texture --------- " + tex);
980811940
9809
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
981011942 continue;
981111943
9812
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
981311945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
981411947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9815
- textures.get(tex).texture.dispose();
9816
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
981711961 }
981811962 }
981911963 }
982011964
982111965 checker = null;
982211966
9823
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11967
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
982411968 FindChecker(object);
982511969
9826
- if (checker != null && drawMode == DEFAULT)
11970
+ if (checker != null && DrawMode() == DEFAULT)
982711971 {
9828
- // BindTexture(IMMORTAL_TEXTURE);
11972
+ //BindTexture(IMMORTAL_TEXTURE);
11973
+ try
11974
+ {
11975
+ BindTextures(checker.GetTextures(), checker.texres);
11976
+ }
11977
+ catch (Exception e)
11978
+ {
11979
+ System.err.println("FAILED: " + checker.GetTextures());
11980
+ }
982911981 // NEAREST
983011982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
983111983 DrawChecker(gl);
983211984 //checker.Draw(this, null, false);
983311985 // ReleaseTexture(IMMORTAL_TEXTURE);
11986
+ ReleaseTextures(checker.GetTextures());
983411987 }
983511988
983611989 if (object.parent != null)
....@@ -9843,7 +11996,7 @@
984311996 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
984411997 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
984511998
9846
- if (DISPLAYTEXT && drawMode == DEFAULT)
11999
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
984712000 {
984812001 // Draw it once, then use the raster
984912002 Balloon(gl, balloon.createGraphics());
....@@ -9899,14 +12052,14 @@
989912052 int[] xs = new int[3];
990012053 int[] ys = new int[3];
990112054
9902
- void DrawString(Object3D obj) // String string)
12055
+ public void DrawString(Object3D obj) // String string) // INTERFACE
990312056 {
9904
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12057
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
990512058 {
990612059 return;
990712060 }
990812061
9909
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
991012063
991112064 GL gl = GetGL();
991212065
....@@ -10223,8 +12376,8 @@
1022312376 //obj.TransformToWorld(light, light);
1022412377 for (int i = tp.size(); --i >= 0;)
1022512378 {
10226
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10227
- LA.xformPos(light, tp.get(i).toParent, light);
12379
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1022812381 }
1022912382
1023012383
....@@ -10241,8 +12394,8 @@
1024112394 parentcam = cameras[0];
1024212395 }
1024312396
10244
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10245
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12397
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1024612399
1024712400 LA.xformPos(light, renderCamera.toScreen, light);
1024812401
....@@ -10332,8 +12485,76 @@
1033212485
1033312486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1033412487
10335
- String program =
12488
+ String programmin =
12489
+ // Min shader
1033612490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1033712558 //"OPTION ARB_fragment_program_shadow;" +
1033812559 "PARAM light2cam0 = program.env[10];" +
1033912560 "PARAM light2cam1 = program.env[11];" +
....@@ -10388,6 +12609,7 @@
1038812609 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1038912610 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1039012611 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12612
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1039112613 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1039212614 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1039312615 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10447,8 +12669,7 @@
1044712669 "TEMP shininess;" +
1044812670 "\n" +
1044912671 "MOV texSamp, one;" +
10450
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10451
-
12672
+
1045212673 "MOV mapgrid.x, one2048th.x;" +
1045312674 "MOV temp, fragment.texcoord[1];" +
1045412675 /*
....@@ -10469,20 +12690,20 @@
1046912690 "MUL temp, floor, mapgrid.x;" +
1047012691 //"TEX depth0, temp, texture[1], 2D;" +
1047112692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10472
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1047312694 "") +
1047412695 "ADD temp.x, temp.x, mapgrid.x;" +
1047512696 //"TEX depth1, temp, texture[1], 2D;" +
1047612697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10477
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1047812699 "") +
1047912700 "ADD temp.y, temp.y, mapgrid.x;" +
1048012701 //"TEX depth2, temp, texture[1], 2D;" +
10481
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1048212703 "SUB temp.x, temp.x, mapgrid.x;" +
1048312704 //"TEX depth3, temp, texture[1], 2D;" +
1048412705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10485
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1048612707 "") +
1048712708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1048812709 //"MOV params, material;" +
....@@ -10853,10 +13074,10 @@
1085313074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1085413075 "") +
1085513076
10856
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1085713078 "SUB temp.x, half.x, shadow.x;" +
10858
- "MOV temp.y, -params6.x;" +
10859
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1086013081 "SUB temp.y, one.x, temp.z;" +
1086113082 "MUL temp.x, temp.x, temp.y;" +
1086213083 "KIL temp.x;" +
....@@ -10985,8 +13206,10 @@
1098513206 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1098613207
1098713208 "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
13209
+ // Tuning for default skin
13210
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13211
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13212
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1099013213 "MUL temp.x, temp.x, temp.y;" +
1099113214
1099213215 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11185,7 +13408,14 @@
1118513408 //once = true;
1118613409 }
1118713410
11188
- System.out.print("Program #" + mode + "; length = " + program.length());
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
13418
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1118913419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1119013420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1119113421
....@@ -11278,30 +13508,32 @@
1127813508 return out;
1127913509 }
1128013510
11281
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1128213513 {
1128313514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1128413515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1128513516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1128613519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1129113522 //"SWZ buffer, temp, w,w,w,w;";
11292
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1129313524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1129413525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1129513526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11296
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1129713528
11298
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11299
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130013531 }
1130113532
1130213533 String Shadow(String depth, String shadow)
1130313534 {
1130413535 return "MAX temp.x, ndotl.x, one64th.x;" +
13536
+ "MIN temp.x, temp.x, ninetenth.x;" +
1130513537 /**/
1130613538 // Sine
1130713539 "MUL temp.y, temp.x, temp.x;" +
....@@ -11317,12 +13549,16 @@
1131713549
1131813550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1131913551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1132013554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1132113555 "SGE temp.y, temp.x, zero.x;" +
11322
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1132313559 "SUB temp.x, one.x, temp.x;" +
1132413560 "MUL " + shadow + ".x, temp.x, temp.y;" +
11325
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1132613562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1132713563
1132813564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11336,6 +13572,10 @@
1133613572 // No shadow for backface
1133713573 "DP3 temp.x, normal, lightd;" +
1133813574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13575
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13576
+
13577
+ // No shadow when out of frustum
13578
+ "SGE temp.x, " + depth + ".z, one.z;" +
1133913579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1134013580 "";
1134113581 }
....@@ -11482,7 +13722,8 @@
1148213722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1148313723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1148413724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11485
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1148613727
1148713728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1148813729 // OUT : diff, spec
....@@ -11498,9 +13739,10 @@
1149813739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1149913740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1150013741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1150413746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1150513747 "RCP " + dest + ".w," + dest + ".w;" +
1150613748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11894,7 +14136,7 @@
1189414136 public void mousePressed(MouseEvent e)
1189514137 {
1189614138 //System.out.println("mousePressed: " + e);
11897
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1189814140 }
1189914141
1190014142 static long prevtime = 0;
....@@ -11921,14 +14163,16 @@
1192114163
1192214164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1192314165
14166
+ if (BUTTONLESSWHEEL)
1192414167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1192514168 {
1192614169 return;
1192714170 }
1192814171
14172
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1192914173
1193014174 // TIMER
11931
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1193214176 {
1193314177 keepboxmode = BOXMODE;
1193414178 keepsupport = SUPPORT;
....@@ -11968,8 +14212,8 @@
1196814212 // mode |= META;
1196914213 //}
1197014214
11971
- SetMouseMode(WHEEL | e.getModifiersEx());
11972
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1197314217 anchorX = ax;
1197414218 anchorY = ay;
1197514219 prevX = px;
....@@ -12003,6 +14247,7 @@
1200314247 else
1200414248 if (evt.getSource() == AAtimer)
1200514249 {
14250
+ Globals.TIMERRUNNING = false;
1200614251 if (mouseDown)
1200714252 {
1200814253 //new Exception().printStackTrace();
....@@ -12028,6 +14273,10 @@
1202814273 // LIVE = waslive;
1202914274 // wasliveok = true;
1203014275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1203114280
1203214281 // source == timer
1203314282 if (mouseDown)
....@@ -12057,8 +14306,8 @@
1205714306 // ObjEditor.tweenManager.update(1f / 60f);
1205814307
1205914308 // fev 2014???
12060
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12061
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14309
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1206214311 pingthread.StepToTarget(true); // true);
1206314312 }
1206414313 // if (!LIVE)
....@@ -12067,12 +14316,13 @@
1206714316
1206814317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1206914318
12070
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1207114320 {
1207214321 if (!wasliveok)
1207314322 return;
1207414323
1207514324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1207614326
1207714327 // waslive = LIVE;
1207814328 // LIVE = false;
....@@ -12084,7 +14334,7 @@
1208414334 // touched = true; // main DL
1208514335 if (isRenderer)
1208614336 {
12087
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1208814338 }
1208914339
1209014340 selectX = anchorX = x;
....@@ -12097,7 +14347,7 @@
1209714347 clicked = true;
1209814348 hold = false;
1209914349
12100
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1210114351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1210214352 {
1210314353 // System.out.println("RESTART II " + modifiers);
....@@ -12122,14 +14372,15 @@
1212214372 drag = false;
1212314373 //System.out.println("Mouse DOWN");
1212414374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1213314384 if (!editObj)
1213414385 {
1213514386 hasMarquee = true;
....@@ -12145,11 +14396,14 @@
1214514396
1214614397 public void mouseDragged(MouseEvent e)
1214714398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1214814402 if (isRenderer)
1214914403 movingcamera = true;
14404
+
1215014405 //if (drawing)
1215114406 //return;
12152
- //System.out.println("mouseDragged: " + e);
1215314407 if ((e.getModifiersEx() & CTRL) != 0
1215414408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1215514409 {
....@@ -12157,7 +14411,7 @@
1215714411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1215814412 }
1215914413 else
12160
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1216114415
1216214416 //try { Thread.sleep(1); } catch (Exception ex) {}
1216314417 }
....@@ -12169,6 +14423,11 @@
1216914423 cVector tmp = new cVector();
1217014424 cVector tmp2 = new cVector();
1217114425 boolean isMoving;
14426
+
14427
+ public cVector TargetLookAt()
14428
+ {
14429
+ return targetLookAt;
14430
+ }
1217214431
1217314432 class PingThread extends Thread
1217414433 {
....@@ -12308,7 +14567,7 @@
1230814567 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1230914568 if (lightMode)
1231014569 {
12311
- lighttouched = true;
14570
+ Globals.lighttouched = true;
1231214571 }
1231314572
1231414573 if (OEILONCE && OEIL)
....@@ -12325,6 +14584,7 @@
1232514584
1232614585 public void run()
1232714586 {
14587
+ new Exception().printStackTrace();
1232814588 System.exit(0);
1232914589 for (;;)
1233014590 {
....@@ -12366,7 +14626,7 @@
1236614626 mouseDown = false;
1236714627 if (lightMode)
1236814628 {
12369
- lighttouched = true;
14629
+ Globals.lighttouched = true;
1237014630 }
1237114631 repaint();
1237214632 alreadypainted = true;
....@@ -12374,7 +14634,7 @@
1237414634 isMoving = false;
1237514635 } //??
1237614636
12377
- if (isLIVE() && !alreadypainted)
14637
+ if (Globals.isLIVE() && !alreadypainted)
1237814638 {
1237914639 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1238014640 repaint();
....@@ -12386,9 +14646,9 @@
1238614646 {
1238714647 if (lightMode)
1238814648 {
12389
- lighttouched = true;
14649
+ Globals.lighttouched = true;
1239014650 }
12391
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1239214652 }
1239314653 //else
1239414654 }
....@@ -12402,12 +14662,12 @@
1240214662 void GoDown(int mod)
1240314663 {
1240414664 MODIFIERS |= COMMAND;
12405
- /*
14665
+ /**/
1240614666 if((mod&SHIFT) == SHIFT)
12407
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1240814668 else
12409
- manipCamera.BackForth(0, -speed*delta, getWidth());
12410
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1241114671 if ((mod & SHIFT) == SHIFT)
1241214672 {
1241314673 mouseMode = mouseMode; // VR??
....@@ -12423,12 +14683,12 @@
1242314683 void GoUp(int mod)
1242414684 {
1242514685 MODIFIERS |= COMMAND;
12426
- /*
14686
+ /**/
1242714687 if((mod&SHIFT) == SHIFT)
12428
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1242914689 else
12430
- manipCamera.BackForth(0, speed*delta, getWidth());
12431
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1243214692 if ((mod & SHIFT) == SHIFT)
1243314693 {
1243414694 mouseMode = mouseMode;
....@@ -12444,12 +14704,12 @@
1244414704 void GoLeft(int mod)
1244514705 {
1244614706 MODIFIERS |= COMMAND;
12447
- /*
14707
+ /**/
1244814708 if((mod&SHIFT) == SHIFT)
12449
- manipCamera.RotatePosition(speed, 0);
12450
- else
1245114709 manipCamera.Translate(speed*delta, 0, getWidth());
12452
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1245314713 if ((mod & SHIFT) == SHIFT)
1245414714 {
1245514715 mouseMode = mouseMode;
....@@ -12465,12 +14725,12 @@
1246514725 void GoRight(int mod)
1246614726 {
1246714727 MODIFIERS |= COMMAND;
12468
- /*
14728
+ /**/
1246914729 if((mod&SHIFT) == SHIFT)
12470
- manipCamera.RotatePosition(-speed, 0);
12471
- else
1247214730 manipCamera.Translate(-speed*delta, 0, getWidth());
12473
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1247414734 if ((mod & SHIFT) == SHIFT)
1247514735 {
1247614736 mouseMode = mouseMode;
....@@ -12488,7 +14748,7 @@
1248814748 int X, Y;
1248914749 boolean SX, SY;
1249014750
12491
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1249214752 {
1249314753 if (IsFrozen())
1249414754 {
....@@ -12497,17 +14757,17 @@
1249714757
1249814758 drag = true; // NEW
1249914759
12500
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1250114761
1250214762 X = x;
1250314763 Y = y;
1250414764 // floating state for animation
12505
- MODIFIERS = modifiers;
12506
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1250714767 if (false) // modifiers != 0)
1250814768 {
1250914769 //new Exception().printStackTrace();
12510
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1251114771 System.out.println("SHIFT = " + SHIFT);
1251214772 System.out.println("CONTROL = " + COMMAND);
1251314773 System.out.println("META = " + META);
....@@ -12520,14 +14780,16 @@
1252014780 if (editObj)
1252114781 {
1252214782 drag = true;
12523
- ClickInfo info = new ClickInfo();
12524
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1252514785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1253114793 } else
1253214794 {
1253314795 if (x < startX)
....@@ -12629,6 +14891,7 @@
1262914891 {
1263014892 manipCamera.Translate(dx, dy, getWidth());
1263114893 }
14894
+ else
1263214895 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1263314896 {
1263414897 manipCamera.RotateInterest(dx, dy);
....@@ -12639,7 +14902,7 @@
1263914902
1264014903 if (manipCamera == lightCamera)
1264114904 {
12642
- lighttouched = true;
14905
+ Globals.lighttouched = true;
1264314906 }
1264414907 /*
1264514908 switch (mode)
....@@ -12675,23 +14938,27 @@
1267514938 }
1267614939 }
1267714940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1267814943 public void mouseMoved(MouseEvent e)
1267914944 {
1268014945 //System.out.println("mouseMoved: " + e);
12681
-
1268214946 if (isRenderer)
1268314947 return;
1268414948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1269214956 if (!isRenderer)
1269314957 {
12694
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1269514962 {
1269614963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1269714964 } else
....@@ -12703,7 +14970,11 @@
1270314970
1270414971 public void mouseReleased(MouseEvent e)
1270514972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1270614975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1270714978 //System.out.println("mouseReleased: " + e);
1270814979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1270914980 }
....@@ -12726,9 +14997,9 @@
1272614997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1272714998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1272814999
12729
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1273015001 timeout = true;
12731
- else
15002
+// ?? May 2019 else
1273215003 // timer.setDelay((modifiers & 128) != 0?0:350);
1273315004 mouseDown = false;
1273415005 if (!control && !command) // june 2013
....@@ -12838,7 +15109,7 @@
1283815109 System.out.println("keyReleased: " + e);
1283915110 }
1284015111
12841
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1284215113 {
1284315114 //System.out.println("SetMouseMode = " + modifiers);
1284415115 //modifiers &= ~1024;
....@@ -12850,24 +15121,27 @@
1285015121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1285115122 // return;
1285215123 //System.out.println("SetMode = " + modifiers);
12853
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1285415125 {
1285515126 mouseMode |= ZOOM;
1285615127 }
12857
- if ((modifiers & META) == META)
15128
+
15129
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15130
+ if (capsLocked) // || (modifiers & META) == META)
1285815131 {
1285915132 mouseMode |= VR; // BACKFORTH;
1286015133 }
12861
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12862
- {
12863
- mouseMode |= SELECT; // BACKFORTH;
12864
- }
12865
- if ((modifiers & COMMAND) == COMMAND)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1286615135 {
1286715136 mouseMode |= SELECT;
1286815137 }
12869
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1287015139 {
15140
+ mouseMode |= SELECT;
15141
+ }
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15143
+ {
15144
+ mouseMode &= ~VR;
1287115145 mouseMode |= TRANSLATE;
1287215146 }
1287315147 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12894,10 +15168,10 @@
1289415168
1289515169 if (isRenderer) //
1289615170 {
12897
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1289815172 }
1289915173
12900
- theRenderer.keyPressed(key);
15174
+ Globals.theRenderer.keyPressed(key);
1290115175 }
1290215176
1290315177 int kompactbit = 4; // power bit
....@@ -12909,7 +15183,7 @@
1290915183 float SATPOW = 1; // 2; // 0.5f;
1291015184 float BRIPOW = 1; // 0.5f; // 0.5f;
1291115185
12912
- void keyPressed(int key)
15186
+ public void keyPressed(int key)
1291315187 {
1291415188 if (key >= '0' && key <= '5')
1291515189 clampbit = (key-'0');
....@@ -12956,7 +15230,8 @@
1295615230 // break;
1295715231 case 'T':
1295815232 CACHETEXTURE ^= true;
12959
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1296015235 // repaint();
1296115236 break;
1296215237 case 'Y':
....@@ -13024,7 +15299,7 @@
1302415299 case 'B':
1302515300 BRISMOOTH ^= true;
1302615301 SHADOWCULLFACE ^= true;
13027
- lighttouched = true;
15302
+ Globals.lighttouched = true;
1302815303 repaint();
1302915304 break;
1303015305 case 'b':
....@@ -13041,7 +15316,9 @@
1304115316 case 'E' : COMPACT ^= true;
1304215317 repaint();
1304315318 break;
13044
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1304515322 repaint();
1304615323 break;
1304715324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13066,8 +15343,8 @@
1306615343 RevertCamera();
1306715344 repaint();
1306815345 break;
13069
- case 'L':
1307015346 case 'l':
15347
+ //case 'L':
1307115348 if (lightMode)
1307215349 {
1307315350 lightMode = false;
....@@ -13124,27 +15401,31 @@
1312415401 repaint();
1312515402 break;
1312615403 case 'O':
13127
- drawMode = OCCLUSION;
15404
+ Globals.drawMode = OCCLUSION; // WARNING
1312815405 repaint();
1312915406 break;
1313015407 case 'o':
1313115408 OCCLUSION_CULLING ^= true;
1313215409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1313315410 break;
13134
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1313515412 case '1':
1313615413 case '2':
1313715414 case '3':
1313815415 case '4':
1313915416 case '5':
13140
- newenvy = Character.getNumericValue(key);
13141
- repaint();
13142
- break;
1314315417 case '6':
1314415418 case '7':
1314515419 case '8':
1314615420 case '9':
13147
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1314815429 repaint();
1314915430 break;
1315015431 case '!':
....@@ -13210,12 +15491,12 @@
1321015491 case '_':
1321115492 kompactbit = 5;
1321215493 break;
13213
- case '+':
13214
- kompactbit = 6;
13215
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1321615497 case ' ':
1321715498 lightMode ^= true;
13218
- lighttouched = true;
15499
+ Globals.lighttouched = true;
1321915500 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1322015501 targetLookAt.set(manipCamera.lookAt);
1322115502 repaint();
....@@ -13224,14 +15505,15 @@
1322415505 case ESC:
1322515506 RENDERPROGRAM += 1;
1322615507 RENDERPROGRAM %= 3;
15508
+
1322715509 repaint();
1322815510 break;
1322915511 case 'Z':
13230
- RESIZETEXTURE ^= true;
13231
- break;
15512
+ //RESIZETEXTURE ^= true;
15513
+ //break;
1323215514 case 'z':
13233
- RENDERSHADOW ^= true;
13234
- lighttouched = true;
15515
+ Globals.RENDERSHADOW ^= true;
15516
+ Globals.lighttouched = true;
1323515517 repaint();
1323615518 break;
1323715519 //case UP:
....@@ -13257,13 +15539,15 @@
1325715539 FlipTransform();
1325815540 break;
1325915541 case ENTER:
13260
- object.editWindow.ScreenFit(); // Edit();
15542
+ // object.editWindow.ScreenFit(); // Edit();
15543
+ ToggleLive();
1326115544 break;
1326215545 case DELETE:
1326315546 ClearSelection();
1326415547 break;
13265
- /*
1326615548 case '+':
15549
+
15550
+ /*
1326715551 //fontsize += 1;
1326815552 bbzoom *= 2;
1326915553 repaint();
....@@ -13280,17 +15564,17 @@
1328015564 case '=':
1328115565 IncDepth();
1328215566 //fontsize += 1;
13283
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1328415568 maskbit = 6;
1328515569 break;
1328615570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1328715571 DecDepth();
1328815572 maskbit = 5;
1328915573 //if(fontsize > 1) fontsize -= 1;
13290
- if (object.editWindow == null)
13291
- new Exception().printStackTrace();
13292
- else
13293
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1329415578 break;
1329515579 case '{':
1329615580 manipCamera.shaper_fovy /= 1.1;
....@@ -13345,6 +15629,7 @@
1334515629 }
1334615630 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1334715631 }
15632
+
1334815633 static double OCCLUSIONBOOST = 1; // 0.5;
1334915634
1335015635 void keyReleased(int key, int modifiers)
....@@ -13352,11 +15637,11 @@
1335215637 //mode = ROTATE;
1335315638 if ((MODIFIERS & COMMAND) == 0) // VR??
1335415639 {
13355
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1335615641 }
1335715642 }
1335815643
13359
- protected void processKeyEvent(KeyEvent e)
15644
+ public void processKeyEvent(KeyEvent e)
1336015645 {
1336115646 switch (e.getID())
1336215647 {
....@@ -13486,8 +15771,9 @@
1348615771
1348715772 protected void processMouseMotionEvent(MouseEvent e)
1348815773 {
13489
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13490
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15774
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15775
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1349115777 {
1349215778 mouseMoved(e);
1349315779 } else
....@@ -13512,11 +15798,12 @@
1351215798 }
1351315799 */
1351415800
13515
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1351615802 }
1351715803
1351815804 void SelectParent()
1351915805 {
15806
+ new Exception().printStackTrace();
1352015807 System.exit(0);
1352115808 Composite group = (Composite) object;
1352215809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13528,10 +15815,10 @@
1352815815 {
1352915816 //selectees.remove(i);
1353015817 System.out.println("select parent of " + elem);
13531
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1353215819 } else
1353315820 {
13534
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1353515822 }
1353615823
1353715824 first = false;
....@@ -13540,6 +15827,7 @@
1354015827
1354115828 void SelectChildren()
1354215829 {
15830
+ new Exception().printStackTrace();
1354315831 System.exit(0);
1354415832 /*
1354515833 Composite group = (Composite) object;
....@@ -13572,12 +15860,12 @@
1357215860 for (int j = 0; j < group.children.size(); j++)
1357315861 {
1357415862 elem = (Object3D) group.children.elementAt(j);
13575
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1357615864 first = false;
1357715865 }
1357815866 } else
1357915867 {
13580
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1358115869 }
1358215870
1358315871 first = false;
....@@ -13588,21 +15876,21 @@
1358815876 {
1358915877 //Composite group = (Composite) object;
1359015878 Object3D group = object;
13591
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1359215880 }
1359315881
1359415882 void ResetTransform(int mask)
1359515883 {
1359615884 //Composite group = (Composite) object;
1359715885 Object3D group = object;
13598
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1359915887 }
1360015888
1360115889 void FlipTransform()
1360215890 {
1360315891 //Composite group = (Composite) object;
1360415892 Object3D group = object;
13605
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1360615894 // group.editWindow.ReduceMesh(true);
1360715895 }
1360815896
....@@ -13610,7 +15898,7 @@
1361015898 {
1361115899 //Composite group = (Composite) object;
1361215900 Object3D group = object;
13613
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1361415902 // group.editWindow.ReduceMesh(true);
1361515903 }
1361615904
....@@ -13618,7 +15906,7 @@
1361815906 {
1361915907 //Composite group = (Composite) object;
1362015908 Object3D group = object;
13621
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1362215910 }
1362315911
1362415912 void IncDepth()
....@@ -13700,11 +15988,11 @@
1370015988
1370115989 int width = getBounds().width;
1370215990 int height = getBounds().height;
13703
- ClickInfo info = new ClickInfo();
13704
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1370515991 //Image img = CreateImage(width, height);
1370615992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1370715994 Graphics gr = g; // img.getGraphics();
15995
+
1370815996 if (!hasMarquee)
1370915997 {
1371015998 if (Xmin < Xmax) // !locked)
....@@ -13776,40 +16064,88 @@
1377616064 }
1377716065 if (object != null && !hasMarquee)
1377816066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1377916073 if (isRenderer)
1378016074 {
13781
- info.flags++;
16075
+ object.clickInfo.flags++;
1378216076 double frameAspect = (double) width / (double) height;
1378316077 if (frameAspect > renderCamera.aspect)
1378416078 {
1378516079 int desired = (int) ((double) height * renderCamera.aspect);
13786
- info.bounds.width -= width - desired;
13787
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1378816082 } else
1378916083 {
1379016084 int desired = (int) ((double) width / renderCamera.aspect);
13791
- info.bounds.height -= height - desired;
13792
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1379316087 }
1379416088 }
13795
- info.g = gr;
13796
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1379716092 /*
1379816093 // Memory intensive (brep.verticescopy)
1379916094 if (!(object instanceof Composite))
1380016095 object.draw(info, 0, false); // SLOW :
1380116096 */
13802
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1380316098 {
13804
- object.drawEditHandles(info, 0);
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
16102
+ {
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
16109
+ {
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
16117
+ }
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
16138
+ }
1380516139 }
1380616140 }
16141
+
1380716142 if (isRenderer)
1380816143 {
1380916144 //gr.setColor(Color.black);
1381016145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1381116146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1381216147 }
16148
+
1381316149 if (hasMarquee)
1381416150 {
1381516151 gr.setXORMode(Color.white);
....@@ -13832,6 +16168,7 @@
1383216168 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1383316169 }
1383416170
16171
+ // To avoid clear.
1383516172 public void update(Graphics g)
1383616173 {
1383716174 paint(g);
....@@ -13921,6 +16258,7 @@
1392116258 public boolean mouseDown(Event evt, int x, int y)
1392216259 {
1392316260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1392416262 /*
1392516263 locked = true;
1392616264 drag = false;
....@@ -13964,7 +16302,7 @@
1396416302 {
1396516303 keyPressed(0, modifiers);
1396616304 }
13967
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1396816306 return true;
1396916307 }
1397016308
....@@ -14082,7 +16420,7 @@
1408216420 {
1408316421 keyReleased(0, 0);
1408416422 }
14085
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1408616424 return true;
1408716425 }
1408816426
....@@ -14214,7 +16552,7 @@
1421416552 Object3D object;
1421516553 static Object3D trackedobject;
1421616554 Camera renderCamera; // Light or Eye (or Occlusion)
14217
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1421816556 /*static*/ Camera eyeCamera;
1421916557 /*static*/ Camera lightCamera;
1422016558 int cameracount;
....@@ -14278,6 +16616,8 @@
1427816616 private /*static*/ boolean firstime;
1427916617 private /*static*/ cVector newView = new cVector();
1428016618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1428116621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1428216622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1428316623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14290,29 +16630,67 @@
1429016630 {
1429116631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1429216632
16633
+ int usedsuf = 0;
16634
+
1429316635 for (int i = 0; i < suffixes.length; i++)
1429416636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1430016642 {
14301
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1430216647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1430316676 //System.out.println("Target = " + targets[i]);
1430416677 cubemap.updateImage(data, targets[i]);
1430516678 }
1430616679
1430716680 return cubemap;
1430816681 }
16682
+
1430916683 int bigsphere = -1;
1431016684
1431116685 float BGcolor = 0.5f;
1431216686
14313
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1431416690 {
14315
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1431616694 {
1431716695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1431816696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14327,7 +16705,17 @@
1432716705 // Compensates for ExaminerViewer's modification of modelview matrix
1432816706 gl.glMatrixMode(GL.GL_MODELVIEW);
1432916707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1433016709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1433116719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1433216720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1433316721
....@@ -14359,6 +16747,7 @@
1435916747 {
1436016748 gl.glScalef(1.0f, -1.0f, 1.0f);
1436116749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1436216751 gl.glMultMatrixd(viewrot_1, 0);
1436316752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1436416753 //viewer.updateInverseRotation(gl);
....@@ -14434,7 +16823,7 @@
1443416823 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1443516824 gl.glPushMatrix();
1443616825 gl.glLoadIdentity();
14437
- PushMatrix(checker.toParent);
16826
+ //PushMatrix(checker.toParent);
1443816827
1443916828 gl.glMatrixMode(GL.GL_TEXTURE);
1444016829 gl.glPushMatrix();
....@@ -14457,8 +16846,8 @@
1445716846
1445816847 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1445916848
14460
- float step = 0.1666f; //0.25f;
14461
- float stepv = step * 1652 / 998;
16849
+ float step = 2; // 0.1666f; //0.25f;
16850
+ float stepv = 2; // step * 1652 / 998;
1446216851
1446316852 int i0 = 0;
1446416853 /*
....@@ -14494,20 +16883,21 @@
1449416883 /**/
1449516884 //checker.GetMaterial().opacity = 1.1f;
1449616885 ////checker.GetMaterial().ambient = 0.99f;
14497
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14498
- Object3D.selectedstack[Object3D.materialdepth] = false;
14499
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16886
+ materialstack[materialdepth] = checker.material;
16887
+ selectedstack[materialdepth] = false;
16888
+ cStatic.objectstack[materialdepth++] = checker;
1450016889 //System.out.println("material " + material);
1450116890 //Applet3D.tracein(this, selected);
14502
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1450316892
14504
- checker.GetMaterial().Draw(this, false); // true);
16893
+ //checker.GetMaterial().Draw(this, false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1450516895
14506
- Object3D.materialdepth -= 1;
14507
- if (Object3D.materialdepth > 0)
16896
+ materialdepth -= 1;
16897
+ if (materialdepth > 0)
1450816898 {
14509
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14510
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1451116901 }
1451216902 //checker.GetMaterial().opacity = 1f;
1451316903 ////checker.GetMaterial().ambient = 1f;
....@@ -14528,15 +16918,27 @@
1452816918
1452916919 //float u = (i+1)/2;
1453016920 //float v = (j+1)/2;
14531
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16921
+ if (checker.flipV)
16922
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16923
+ else
16924
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1453216925 gl.glVertex3f(i, j, -0.5f);
1453316926
16927
+ if (checker.flipV)
16928
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16929
+ else
1453416930 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1453516931 gl.glVertex3f(i + step, j, -0.5f);
1453616932
16933
+ if (checker.flipV)
16934
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16935
+ else
1453716936 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1453816937 gl.glVertex3f(i + step, j + stepv, -0.5f);
1453916938
16939
+ if (checker.flipV)
16940
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16941
+ else
1454016942 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1454116943 gl.glVertex3f(i, j + stepv, -0.5f);
1454216944 }
....@@ -14548,7 +16950,7 @@
1454816950 gl.glMatrixMode(GL.GL_PROJECTION);
1454916951 gl.glPopMatrix();
1455016952 gl.glMatrixMode(GL.GL_MODELVIEW);
14551
- PopMatrix(null); // checker.toParent); // null);
16953
+ //PopMatrix(null); // checker.toParent); // null);
1455216954 gl.glPopMatrix();
1455316955 PopTextureMatrix(checker.toParent);
1455416956 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14581,6 +16983,14 @@
1458116983 }
1458216984 }
1458316985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1458416994 class SelectBuffer implements GLEventListener
1458516995 {
1458616996
....@@ -14596,7 +17006,7 @@
1459617006 //new Exception().printStackTrace();
1459717007 System.out.println("select buffer init");
1459817008 // Use debug pipeline
14599
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1460017010
1460117011 GL gl = drawable.getGL();
1460217012
....@@ -14639,6 +17049,7 @@
1463917049 {
1464017050 if (!selection)
1464117051 {
17052
+ new Exception().printStackTrace();
1464217053 System.exit(0);
1464317054 return;
1464417055 }
....@@ -14659,17 +17070,39 @@
1465917070
1466017071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1466117072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1466217084 //int tmp = selection_view;
1466317085 //selection_view = -1;
14664
- int temp = drawMode;
14665
- drawMode = SELECTION;
17086
+ int temp = DrawMode();
17087
+ Globals.drawMode = SELECTION; // WARNING
1466617088 indexcount = 0;
1466717089 parent.display(drawable);
1466817090 //selection_view = tmp;
1466917091 //if (temp == SELECTION)
1467017092 // temp = DEFAULT; // patch for selection debug
14671
- drawMode = temp;
17093
+ Globals.drawMode = temp; // WARNING
1467217094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1467317106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1467417107
1467517108 // trying different ways of getting the depth info over
....@@ -14718,6 +17151,13 @@
1471817151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1471917152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1472017153
17154
+ CreateSelectedPoint();
17155
+
17156
+ // Will fit the mesh !!!
17157
+ selectedpoint.toParent[0][0] = 0.0001;
17158
+ selectedpoint.toParent[1][1] = 0.0001;
17159
+ selectedpoint.toParent[2][2] = 0.0001;
17160
+
1472117161 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1472217162
1472317163 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14761,34 +17201,36 @@
1476117201 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]));
1476217202 }
1476317203
14764
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1476517205 }
1476617206 }
1476717207
1476817208 if (!movingcamera && !PAINTMODE)
14769
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1477017210
14771
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1477217212 {
14773
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1477417214
14775
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1477617218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1479217234 }
1479317235 else
1479417236 paintcount = 0;
....@@ -14827,6 +17269,11 @@
1482717269 //System.out.println("objects[color] = " + objects[color]);
1482817270 //objects[color].Select();
1482917271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1483017277 object.Select(color, deselect);
1483117278 }
1483217279
....@@ -14926,7 +17373,7 @@
1492617373 gl.glDisable(gl.GL_CULL_FACE);
1492717374 }
1492817375
14929
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1493017377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1493117378
1493217379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14936,14 +17383,14 @@
1493617383 //gl.glColorMask(false, false, false, false);
1493717384
1493817385 //render_scene_from_light_view(gl, drawable, 0, 0);
14939
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1494017387 {
1494117388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1494217389
14943
- int temp = drawMode;
14944
- drawMode = SHADOW;
17390
+ int temp = DrawMode();
17391
+ Globals.drawMode = SHADOW; // WARNING
1494517392 parent.display(drawable);
14946
- drawMode = temp;
17393
+ Globals.drawMode = temp; // WARNING
1494717394 }
1494817395
1494917396 gl.glCullFace(gl.GL_BACK);
....@@ -14996,7 +17443,6 @@
1499617443
1499717444 class AntialiasBuffer implements GLEventListener
1499817445 {
14999
-
1500017446 CameraPane parent = null;
1500117447
1500217448 AntialiasBuffer(CameraPane p)
....@@ -15106,15 +17552,25 @@
1510617552 gl.glFlush();
1510717553
1510817554 /**/
15109
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1511017556
15111
- int[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1511217558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1511317563 double r = 0, g = 0, b = 0;
1511417564
1511517565 double count = 0;
17566
+
17567
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17568
+
17569
+ float mindepth = 1;
17570
+
17571
+ double FACTOR = 1;
1511617572
15117
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1511817574 {
1511917575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1512017576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15197,7 +17653,7 @@
1519717653
1519817654 double scale = ray.z; // 1; // cos
1519917655
15200
- int p = pixels[newindex];
17656
+ float depth = depths[newindex];
1520117657
1520217658 /*
1520317659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15221,10 +17677,23 @@
1522117677 scale = (1 - modu) * modv;
1522217678 */
1522317679
15224
- r += ((p >> 16) & 0xFF) * scale / 255;
15225
- g += ((p >> 8) & 0xFF) * scale / 255;
15226
- b += (p & 0xFF) * scale / 255;
17680
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17681
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17682
+ //b += (p & 0xFF) * scale / 255;
17683
+
17684
+ if (mindepth > depth)
17685
+ {
17686
+ mindepth = depth;
17687
+ }
1522717688
17689
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17690
+
17691
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17692
+
17693
+ r += factor * scale;
17694
+ g += factor * scale;
17695
+ b += factor * scale;
17696
+
1522817697 count += scale;
1522917698 }
1523017699
....@@ -15322,12 +17791,6 @@
1532217791 GLUT glut = new GLUT();
1532317792
1532417793
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;
1533117794 public boolean spherical = false;
1533217795 static boolean DEBUG_OCCLUSION = false;
1533317796 static boolean DEBUG_SELECTION = false;
....@@ -15340,23 +17803,15 @@
1534017803 int AAbuffersize = 0;
1534117804
1534217805 //double[] selectedpoint = new double[3];
15343
- static Sphere selectedpoint = new Sphere();
17806
+ static Superellipsoid selectedpoint;
1534417807 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();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1534917812
1535017813 static Sphere debugpoints[] = new Sphere[8];
1535117814
15352
- static
15353
- {
15354
- for (int i=0; i<8; i++)
15355
- {
15356
- debugpoints[i] = new Sphere();
15357
- }
15358
- }
15359
-
1536017815 static void InitPoints(float radius)
1536117816 {
1536217817 for (int i=0; i<8; i++)
....@@ -15376,7 +17831,7 @@
1537617831 }
1537717832 }
1537817833
15379
- static void DrawPoints(CameraPane cpane)
17834
+ static void DrawPoints(iCameraPane cpane)
1538017835 {
1538117836 for (int i=0; i<8; i++) // first and last are red
1538217837 {
....@@ -15395,10 +17850,14 @@
1539517850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1539617851 static IntBuffer bigAAbuffer;
1539717852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15398
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1539917854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1540017855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15401
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17856
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1540217861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1540317862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1540417863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15407,10 +17866,11 @@
1540717866 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1540817867 // Depth buffer format
1540917868 //private int depth_format;
15410
- static public void NextIndex(Object3D o, GL gl)
17869
+
17870
+ public void NextIndex()
1541117871 {
1541217872 indexcount+=16;
15413
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17873
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1541417874 //objects[indexcount] = o;
1541517875 //System.out.println("indexcount = " + indexcount);
1541617876 }