Normand Briere
2019-07-28 a434119e65146fe53d612c28e1ee7af532d1b70a
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;
....@@ -97,10 +117,8 @@
97117
98118 static boolean textureon = true;
99119 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101120 static boolean FULLSCREEN = false;
102121 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104122 static boolean INERTIA = true;
105123 static boolean FAST = false;
106124 static boolean SLOWPOSE = false;
....@@ -108,6 +126,8 @@
108126
109127 static int tickcount = 0; // slow pose issue
110128
129
+static boolean BUTTONLESSWHEEL = false;
130
+static boolean ZOOMBOXMODE = false;
111131 static boolean BOXMODE = false;
112132 static boolean IMAGEFLIP = false;
113133 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +142,7 @@
122142 static boolean OEIL = true;
123143 static boolean OEILONCE = false; // do oeilon then oeiloff
124144 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
126146 static boolean HANDLES = false; // selection doesn't work!!
127147 static boolean PAINTMODE = false;
128148
....@@ -165,12 +185,54 @@
165185 defaultcaps.setAccumBlueBits(16);
166186 defaultcaps.setAccumAlphaBits(16);
167187 }
168
- static CameraPane theRenderer;
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
169190
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
202
+
170203 void SetAsGLRenderer(boolean b)
171204 {
172205 isRenderer = b;
173
- theRenderer = this;
206
+ Globals.theRenderer = this;
207
+ }
208
+
209
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
210
+ {
211
+ super(defaultcaps, null, withcontext?glcontext:null, null);
212
+
213
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
214
+ glcontext = getContext();
215
+
216
+ cameras = new Camera[2];
217
+ targetLookAts = new cVector[2];
218
+
219
+ SetCamera(cam);
220
+
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
223
+
224
+ object = o;
225
+
226
+ setBackground(Color.white);
227
+
228
+ addKeyListener(this);
229
+ addMouseListener(this);
230
+ addMouseMotionListener(this);
231
+ addMouseWheelListener(this);
232
+ //System.out.println("addGLEventListener: " + this);
233
+ addGLEventListener(this);
234
+
235
+// pingthread.start(); // may 2013
174236 }
175237
176238 static boolean AntialiasingEnabled()
....@@ -178,12 +240,53 @@
178240 return CURRENTANTIALIAS > 0;
179241 }
180242
181
- void ClearDepth()
243
+ /// INTERFACE
244
+
245
+ public javax.media.opengl.GL GetGL0()
246
+ {
247
+ return null;
248
+ }
249
+
250
+ public int GenList()
251
+ {
252
+ javax.media.opengl.GL gl = GetGL();
253
+ return gl.glGenLists(1);
254
+ }
255
+
256
+ public void NewList(int id)
257
+ {
258
+ javax.media.opengl.GL gl = GetGL();
259
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
260
+ }
261
+
262
+ public void CallList(int id)
263
+ {
264
+ javax.media.opengl.GL gl = GetGL();
265
+ gl.glCallList(id);
266
+ }
267
+
268
+ public void EndList()
269
+ {
270
+ javax.media.opengl.GL gl = GetGL();
271
+ gl.glEndList();
272
+ }
273
+
274
+ public boolean IsBoxMode()
275
+ {
276
+ return BOXMODE;
277
+ }
278
+
279
+ public boolean IsZoomBoxMode()
280
+ {
281
+ return ZOOMBOXMODE;
282
+ }
283
+
284
+ public void ClearDepth()
182285 {
183286 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184287 }
185288
186
- void DepthTest(boolean depthtest)
289
+ public void DepthTest(boolean depthtest)
187290 {
188291 if (depthtest)
189292 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +294,7 @@
191294 GetGL().glDepthFunc(GL.GL_ALWAYS);
192295 }
193296
194
- void DepthWrite(boolean depthwrite)
297
+ public void DepthWrite(boolean depthwrite)
195298 {
196299 if (depthwrite)
197300 GetGL().glDepthMask(true);
....@@ -199,12 +302,1616 @@
199302 GetGL().glDepthMask(false);
200303 }
201304
202
- void BackFaceCull(boolean bfc)
305
+ public void BackFaceCull(boolean bfc)
203306 {
204307 if (bfc)
205308 GetGL().glEnable(GetGL().GL_CULL_FACE);
206309 else
207310 GetGL().glDisable(GetGL().GL_CULL_FACE);
311
+ }
312
+
313
+ public boolean BackFaceCullMode()
314
+ {
315
+ return this.CULLFACE;
316
+ }
317
+
318
+ public boolean IsAmbientOcclusionOn()
319
+ {
320
+ return this.ambientOcclusion;
321
+ }
322
+
323
+ public boolean IsDebugSelection()
324
+ {
325
+ return DEBUG_SELECTION;
326
+ }
327
+
328
+ public boolean IsFrozen()
329
+ {
330
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
331
+
332
+ return !selectmode && cameracount == 0; // != 0;
333
+ }
334
+
335
+ // Currently in Globals
336
+ public int DrawMode()
337
+ {
338
+ return Globals.DrawMode();
339
+ }
340
+
341
+ public Camera EyeCamera()
342
+ {
343
+ return eyeCamera;
344
+ }
345
+
346
+ public Camera LightCamera()
347
+ {
348
+ return lightCamera;
349
+ }
350
+
351
+ public Camera ManipCamera()
352
+ {
353
+ return manipCamera;
354
+ }
355
+
356
+ public Camera RenderCamera()
357
+ {
358
+ return renderCamera;
359
+ }
360
+
361
+ public Camera[] Cameras()
362
+ {
363
+ return cameras;
364
+ }
365
+
366
+ public void PushMaterial(Object3D obj, boolean selected)
367
+ {
368
+ CameraPane display = this;
369
+ javax.media.opengl.GL gl = display.GetGL();
370
+ cMaterial material = obj.material;
371
+
372
+ if (material != null)
373
+ {
374
+ materialstack[materialdepth] = material;
375
+ selectedstack[materialdepth] = selected;
376
+ cStatic.objectstack[materialdepth++] = obj;
377
+ //System.out.println("material " + material);
378
+ //Applet3D.tracein(this, selected);
379
+ //display.vector2buffer = obj.projectedVertices;
380
+ if (obj instanceof Camera)
381
+ {
382
+ display.options1[0] = material.shift;
383
+ //System.out.println("shift " + material.shift);
384
+ display.options1[1] = material.lightarea;
385
+ display.options1[2] = material.shadowbias;
386
+ display.options1[3] = material.aniso;
387
+ display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
393
+ display.options2[0] = material.opacity;
394
+ display.options2[1] = material.diffuse;
395
+ display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
399
+
400
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
404
+ display.options4[0] = material.cameralight/0.2f;
405
+ display.options4[1] = material.subsurface;
406
+ display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
410
+
411
+ // if (display.CURRENTANTIALIAS > 0)
412
+ // display.options3[3] /= 4;
413
+
414
+ /*
415
+ System.out.println("Focus = " + display.options1[0]);
416
+ System.out.println("Aperture = " + display.options1[1]);
417
+ System.out.println("ShadowBlur = " + display.options1[2]);
418
+ System.out.println("Antialiasing = " + display.options1[3]);
419
+ System.out.println("Fog = " + display.options2[0]);
420
+ System.out.println("Intensity = " + display.options2[1]);
421
+ System.out.println("Elevation = " + display.options2[2]);
422
+ /**/
423
+ } else
424
+ {
425
+ DrawMaterial(material, selected, obj.projectedVertices);
426
+ }
427
+ } else
428
+ {
429
+ if (selected && CameraPane.flash)
430
+ {
431
+ display.modelParams4[1] = 100;
432
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
433
+ }
434
+ }
435
+ }
436
+
437
+ public void PushMaterial2(Object3D obj, boolean selected)
438
+ {
439
+ CameraPane display = this;
440
+ cMaterial material = obj.material;
441
+
442
+ if (material != null)
443
+ {
444
+ materialstack[materialdepth] = material;
445
+ selectedstack[materialdepth] = selected;
446
+ cStatic.objectstack[materialdepth++] = obj;
447
+ //System.out.println("material " + material);
448
+ //Applet3D.tracein("selected ", selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
451
+ }
452
+ }
453
+
454
+ public void PopMaterial(Object3D obj, boolean selected)
455
+ {
456
+ CameraPane display = this;
457
+ javax.media.opengl.GL gl = display.GetGL();
458
+ cMaterial material = obj.material;
459
+
460
+ //if (parent != null && parent.GetMaterial() != null)
461
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
462
+ if (material != null)
463
+ {
464
+ materialdepth -= 1;
465
+ if (materialdepth > 0)
466
+ {
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
469
+ }
470
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
471
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
472
+ {
473
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
474
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
475
+ }
476
+ }
477
+
478
+ public void PopMaterial2(Object3D obj)
479
+ {
480
+ CameraPane display = this;
481
+ cMaterial material = obj.material;
482
+
483
+ if (material != null)
484
+ {
485
+ materialdepth -= 1;
486
+ if (materialdepth > 0)
487
+ {
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
490
+ }
491
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
492
+ //else
493
+ //material.Draw(display, false);
494
+ }
495
+ }
496
+
497
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
498
+ {
499
+ CameraPane display = this;
500
+
501
+ if (pv.y == -10000 ||
502
+ qv.y == -10000 ||
503
+ rv.y == -10000)
504
+ return;
505
+
506
+// float b = f.nbiterations & 1;
507
+// float g = (f.nbiterations>>1) & 1;
508
+// float r = (f.nbiterations>>2) & 1;
509
+//
510
+// //if (f.weight == 10000)
511
+// //{
512
+// // r = 1; g = b = 0;
513
+// //}
514
+// //else
515
+// //{
516
+// // assert(f.weight < 10000);
517
+// r = g = b = (float)bRep.FaceWeight(f)*100;
518
+// if (r<0)
519
+// assert(r>=0);
520
+// //}
521
+
522
+ javax.media.opengl.GL gl = display.GetGL();
523
+
524
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
525
+
526
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
527
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
528
+ {
529
+ //gl.glBegin(gl.GL_TRIANGLES);
530
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
531
+ // TEST LIVE NORMALS && !obj.dontselect
532
+ ;
533
+ if (!hasnorm)
534
+ {
535
+ // System.out.println("Mesh normal");
536
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
537
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
538
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
539
+ LA.vecNormalize(obj.v2);
540
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
541
+ }
542
+
543
+ // P
544
+ float x = (float)pv.x;
545
+ float y = (float)pv.y;
546
+ float z = (float)pv.z;
547
+
548
+ if (hasnorm)
549
+ {
550
+// if (!pv.norm.normalized())
551
+// assert(pv.norm.normalized());
552
+
553
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
554
+ float nx = (float)pv.norm.x;
555
+ float ny = (float)pv.norm.y;
556
+ float nz = (float)pv.norm.z;
557
+
558
+ x += nx * obj.NORMALPUSH;
559
+ y += ny * obj.NORMALPUSH;
560
+ z += nz * obj.NORMALPUSH;
561
+
562
+ gl.glNormal3f(nx, ny, nz);
563
+ }
564
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
565
+ SetColor(obj, pv);
566
+ //gl.glColor4f(r, g, b, 1);
567
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
568
+ if (obj.flipV)
569
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
570
+ else
571
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
572
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
573
+
574
+ gl.glVertex3f(x, y, z);
575
+
576
+ // Q
577
+ x = (float)qv.x;
578
+ y = (float)qv.y;
579
+ z = (float)qv.z;
580
+
581
+// Print(pv);
582
+ if (hasnorm)
583
+ {
584
+// assert(qv.norm.normalized());
585
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
586
+ float nx = (float)qv.norm.x;
587
+ float ny = (float)qv.norm.y;
588
+ float nz = (float)qv.norm.z;
589
+
590
+ x += nx * obj.NORMALPUSH;
591
+ y += ny * obj.NORMALPUSH;
592
+ z += nz * obj.NORMALPUSH;
593
+
594
+ gl.glNormal3f(nx, ny, nz);
595
+ }
596
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
597
+ // boolean locked = false;
598
+ // float eps = 0.1f;
599
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
600
+
601
+ // int dot = 0; //*/ (int)f.dot;
602
+
603
+ // if ((dot&1) == 0)
604
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
605
+
606
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
607
+ if (obj.flipV)
608
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
609
+ else
610
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
611
+ // else
612
+ // {
613
+ // locked = true;
614
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
615
+ // }
616
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
617
+ SetColor(obj, qv);
618
+
619
+ gl.glVertex3f(x, y, z);
620
+ //gl.glColor4f(r, g, b, 1);
621
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
622
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
623
+// Print(qv);
624
+
625
+ // R
626
+ x = (float)rv.x;
627
+ y = (float)rv.y;
628
+ z = (float)rv.z;
629
+
630
+ if (hasnorm)
631
+ {
632
+// assert(rv.norm.normalized());
633
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
634
+ float nx = (float)rv.norm.x;
635
+ float ny = (float)rv.norm.y;
636
+ float nz = (float)rv.norm.z;
637
+
638
+ x += nx * obj.NORMALPUSH;
639
+ y += ny * obj.NORMALPUSH;
640
+ z += nz * obj.NORMALPUSH;
641
+
642
+ gl.glNormal3f(nx, ny, nz);
643
+ }
644
+
645
+ // if ((dot&4) == 0)
646
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
647
+
648
+ // if (wrap || !locked && (dot&8) != 0)
649
+ if (obj.flipV)
650
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
651
+ else
652
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
653
+ // else
654
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
655
+
656
+ // f.dot = dot;
657
+
658
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
659
+ SetColor(obj, rv);
660
+ //gl.glColor4f(r, g, b, 1);
661
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
662
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
663
+ gl.glVertex3f(x, y, z);
664
+// Print(rv);
665
+ //gl.glEnd();
666
+ }
667
+ else
668
+ {
669
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
670
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
671
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
672
+
673
+ }
674
+
675
+ if (false) // (attributes & WIREFRAME) != 0)
676
+ {
677
+ gl.glDisable(gl.GL_LIGHTING);
678
+
679
+ gl.glBegin(gl.GL_LINE_LOOP);
680
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
681
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
682
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
683
+ gl.glEnd();
684
+
685
+ gl.glEnable(gl.GL_LIGHTING);
686
+ }
687
+ }
688
+
689
+ /**
690
+ * <code>draw</code> renders a <code>TriMesh</code> object including
691
+ * it's normals, colors, textures and vertices.
692
+ *
693
+ * @see Renderer#draw(TriMesh)
694
+ * @param tris
695
+ * the mesh to render.
696
+ */
697
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
698
+ {
699
+ CameraPane display = this;
700
+
701
+ float r = display.modelParams0[0];
702
+ float g = display.modelParams0[1];
703
+ float b = display.modelParams0[2];
704
+ float opacity = display.modelParams5[1];
705
+
706
+ //final GL gl = GLU.getCurrentGL();
707
+ GL gl = display.GetGL(); // getGL();
708
+
709
+ FloatBuffer vertBuf = geo.vertBuf;
710
+
711
+ int v = vertBuf.capacity();
712
+
713
+ int count = 0;
714
+
715
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
716
+ gl.glEnable(gl.GL_CULL_FACE);
717
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
718
+ for (int i=0; i<v/3; i++)
719
+ {
720
+ int index3 = i*3;
721
+
722
+ if (geo.sizeBuf.get(index3+1) == 0)
723
+ continue;
724
+
725
+ count++;
726
+
727
+ int index4 = i*4;
728
+
729
+ float tx = vertBuf.get(index3);
730
+ float ty = vertBuf.get(index3+1);
731
+ float tz = vertBuf.get(index3+2);
732
+
733
+ // if (tx == 0 && ty == 0 && tz == 0)
734
+ // continue;
735
+
736
+ gl.glMatrixMode(gl.GL_TEXTURE);
737
+ gl.glPushMatrix();
738
+
739
+ float[] texmat = geo.texmat;
740
+ texmat[12] = texmat[13] = texmat[14] = i;
741
+
742
+ gl.glMultMatrixf(texmat, 0);
743
+
744
+ gl.glMatrixMode(gl.GL_MODELVIEW);
745
+ gl.glPushMatrix();
746
+
747
+ gl.glTranslatef(tx,ty,tz);
748
+
749
+ if (rotate)
750
+ gl.glRotatef(i, 0, 1, 0);
751
+
752
+ float size = geo.sizeBuf.get(index3) / 100;
753
+ gl.glScalef(size,size,size);
754
+
755
+ float cr = geo.colorBuf.get(index4);
756
+ float cg = geo.colorBuf.get(index4+1);
757
+ float cb = geo.colorBuf.get(index4+2);
758
+ float ca = geo.colorBuf.get(index4+3);
759
+
760
+ display.modelParams0[0] = r * cr;
761
+ display.modelParams0[1] = g * cg;
762
+ display.modelParams0[2] = b * cb;
763
+
764
+ display.modelParams5[1] = opacity * ca;
765
+
766
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
767
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
768
+
769
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
770
+ RandomNode.globalseed2 = RandomNode.globalseed;
771
+
772
+// gl.glColor4f(cr,cg,cb,ca);
773
+ // gl.glScalef(1024/16,1024/16,1024/16);
774
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
775
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
776
+ //gl.glTranslatef(-tx,-ty,-tz);
777
+ gl.glPopMatrix();
778
+
779
+ gl.glMatrixMode(gl.GL_TEXTURE);
780
+ gl.glPopMatrix();
781
+ }
782
+ // gl.glScalef(1024,1024,1024);
783
+ if (!cf)
784
+ gl.glDisable(gl.GL_CULL_FACE);
785
+
786
+ display.modelParams0[0] = r;
787
+ display.modelParams0[1] = g;
788
+ display.modelParams0[2] = b;
789
+
790
+ display.modelParams5[1] = opacity;
791
+
792
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
793
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
794
+
795
+ gl.glMatrixMode(gl.GL_MODELVIEW);
796
+
797
+// System.err.println("total = " + v/3 + "; displayed = " + count);
798
+ if (true)
799
+ return;
800
+
801
+//// if (!tris.predraw(this))
802
+//// {
803
+//// return;
804
+//// }
805
+//// if (Debug.stats)
806
+//// {
807
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
808
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
809
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
810
+//// }
811
+////
812
+//// if (tris.getDisplayListID() != -1)
813
+//// {
814
+//// renderDisplayList(tris);
815
+//// return;
816
+//// }
817
+////
818
+//// if (!generatingDisplayList)
819
+//// {
820
+//// applyStates(tris.states, tris);
821
+//// }
822
+//// if (Debug.stats)
823
+//// {
824
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
825
+//// }
826
+//// boolean transformed = doTransforms(tris);
827
+//
828
+// int glMode = GL.GL_TRIANGLES;
829
+// switch (getMode())
830
+// {
831
+// case Triangles:
832
+// glMode = GL.GL_TRIANGLES;
833
+// break;
834
+// case Strip:
835
+// glMode = GL.GL_TRIANGLE_STRIP;
836
+// break;
837
+// case Fan:
838
+// glMode = GL.GL_TRIANGLE_FAN;
839
+// break;
840
+// }
841
+//
842
+// if (!predrawGeometry(gl))
843
+// {
844
+// // make sure only the necessary indices are sent through on old
845
+// // cards.
846
+// IntBuffer indices = this.getIndexBuffer();
847
+// if (indices == null)
848
+// {
849
+// logger.severe("missing indices on geometry object: " + this.toString());
850
+// } else
851
+// {
852
+// indices.rewind();
853
+// indices.limit(this.getMaxIndex());
854
+//
855
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
856
+//
857
+// indices.clear();
858
+// }
859
+// } else
860
+// {
861
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
862
+// GL.GL_UNSIGNED_INT, 0);
863
+// }
864
+//
865
+//// postdrawGeometry(tris);
866
+//// if (transformed)
867
+//// {
868
+//// undoTransforms(tris);
869
+//// }
870
+////
871
+//// if (Debug.stats)
872
+//// {
873
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
874
+//// }
875
+//// tris.postdraw(this);
876
+ }
877
+
878
+ static Camera localcamera = new Camera();
879
+ static cVector from = new cVector();
880
+ static cVector to = new cVector();
881
+
882
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
883
+ {
884
+ CameraPane cp = this;
885
+
886
+ Camera keep = cp.RenderCamera();
887
+ cp.renderCamera = localcamera;
888
+
889
+ if (br.trimmed)
890
+ {
891
+ float[] colors = new float[br.positions.length / 3];
892
+
893
+ int i3 = 0;
894
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
895
+ {
896
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
897
+ continue;
898
+
899
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
900
+ to.set(br.positions[i3] + br.normals[i3],
901
+ br.positions[i3 + 1] + br.normals[i3 + 1],
902
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
903
+ LA.xformPos(from, transform, from);
904
+ LA.xformPos(to, transform, to); // RIGID ONLY
905
+ localcamera.setAim(from, to);
906
+
907
+ CameraPane.occlusionbuffer.display();
908
+
909
+ if (CameraPane.DEBUG_OCCLUSION)
910
+ cp.display(); // debug
911
+
912
+ colors[i] = cp.vertexOcclusion.r;
913
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
914
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
915
+
916
+ if ((i % 100) == 0 && i != 0)
917
+ {
918
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
919
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
920
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
921
+ }
922
+ }
923
+
924
+ br.colors = colors;
925
+ }
926
+ else
927
+ {
928
+ for (int i = 0; i < br.VertexCount(); i++)
929
+ {
930
+ Vertex v = br.GetVertex(i);
931
+
932
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
933
+ continue;
934
+
935
+ from.set(v.x, v.y, v.z);
936
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
937
+ LA.xformPos(from, transform, from);
938
+ LA.xformPos(to, transform, to); // RIGID ONLY
939
+ localcamera.setAim(from, to);
940
+
941
+ CameraPane.occlusionbuffer.display();
942
+
943
+ if (CameraPane.DEBUG_OCCLUSION)
944
+ cp.display(); // debug
945
+
946
+ v.AO = cp.vertexOcclusion.r;
947
+
948
+ if ((i % 100) == 0 && i != 0)
949
+ {
950
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
951
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
952
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
953
+ }
954
+ }
955
+ }
956
+
957
+ //System.out.println("done.");
958
+
959
+ cp.renderCamera = keep;
960
+ }
961
+
962
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
963
+ {
964
+ CameraPane display = this;
965
+ pointFlow.CreateHT();
966
+
967
+ float r = display.modelParams0[0];
968
+ float g = display.modelParams0[1];
969
+ float b = display.modelParams0[2];
970
+ float opacity = display.modelParams5[1];
971
+
972
+ //final GL gl = GLU.getCurrentGL();
973
+ GL gl = display.GetGL(); // getGL();
974
+
975
+ int s = pointFlow.points.size();
976
+
977
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
978
+ gl.glEnable(gl.GL_CULL_FACE);
979
+
980
+ for (int i=s; --i>=0;)
981
+ //for (int i=0; i<s; i++)
982
+ {
983
+ cVector v = pointFlow.points.get(i);
984
+
985
+ double mindist = Double.MAX_VALUE;
986
+
987
+ double size = pointFlow.minimumSize;
988
+
989
+ double distancenext = 0;
990
+
991
+ if (i > 0)
992
+ {
993
+ cVector w = pointFlow.points.get(i-1);
994
+
995
+ double dist = w.distance(v);
996
+
997
+ distancenext = dist;
998
+
999
+ if (mindist > dist)
1000
+ {
1001
+ mindist = dist;
1002
+ size = mindist*pointFlow.resizefactor;
1003
+ }
1004
+ }
1005
+
1006
+ if (i < s-1)
1007
+ {
1008
+ cVector w = pointFlow.points.get(i+1);
1009
+
1010
+ double dist = w.distance(v);
1011
+
1012
+ if (mindist > dist)
1013
+ {
1014
+ mindist = dist;
1015
+ size = mindist*pointFlow.resizefactor;
1016
+ }
1017
+ }
1018
+
1019
+ if (size < pointFlow.minimumSize)
1020
+ size = pointFlow.minimumSize;
1021
+ if (size > pointFlow.maximumSize)
1022
+ size = pointFlow.maximumSize;
1023
+
1024
+ double tx = v.x;
1025
+ double ty = v.y;
1026
+ double tz = v.z;
1027
+
1028
+ // if (tx == 0 && ty == 0 && tz == 0)
1029
+ // continue;
1030
+
1031
+ gl.glMatrixMode(gl.GL_TEXTURE);
1032
+ gl.glPushMatrix();
1033
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1034
+
1035
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1036
+
1037
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1038
+ gl.glPushMatrix();
1039
+
1040
+ gl.glTranslated(tx,ty,tz);
1041
+
1042
+ gl.glScaled(size,size,size);
1043
+
1044
+// float cr = colorBuf.get(index4);
1045
+// float cg = colorBuf.get(index4+1);
1046
+// float cb = colorBuf.get(index4+2);
1047
+// float ca = colorBuf.get(index4+3);
1048
+//
1049
+// display.modelParams0[0] = r * cr;
1050
+// display.modelParams0[1] = g * cg;
1051
+// display.modelParams0[2] = b * cb;
1052
+//
1053
+// display.modelParams5[1] = opacity * ca;
1054
+//
1055
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1056
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1057
+//
1058
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1059
+// RandomNode.globalseed2 = RandomNode.globalseed;
1060
+//
1061
+//// gl.glColor4f(cr,cg,cb,ca);
1062
+// // gl.glScalef(1024/16,1024/16,1024/16);
1063
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1064
+
1065
+ gl.glPopMatrix();
1066
+
1067
+ double step = size/4; //
1068
+
1069
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1070
+ continue;
1071
+
1072
+ int nbsteps = (int)(distancenext/step);
1073
+
1074
+ step = distancenext/nbsteps;
1075
+
1076
+ cVector next = pointFlow.points.get(i-1);
1077
+
1078
+ tmp.set(next);
1079
+ tmp.sub(v);
1080
+ tmp.normalize();
1081
+ tmp.mul(step);
1082
+
1083
+ // calculate next size
1084
+ mindist = Double.MAX_VALUE;
1085
+
1086
+ double nextsize = pointFlow.minimumSize;
1087
+
1088
+ if (i > 1)
1089
+ {
1090
+ cVector w = pointFlow.points.get(i-2);
1091
+
1092
+ double dist = w.distance(next);
1093
+
1094
+ if (mindist > dist)
1095
+ {
1096
+ mindist = dist;
1097
+ nextsize = mindist*pointFlow.resizefactor;
1098
+ }
1099
+ }
1100
+
1101
+ double dist = v.distance(next);
1102
+
1103
+ if (mindist > dist)
1104
+ {
1105
+ mindist = dist;
1106
+ nextsize = mindist*pointFlow.resizefactor;
1107
+ }
1108
+
1109
+ if (nextsize < pointFlow.minimumSize)
1110
+ nextsize = pointFlow.minimumSize;
1111
+ if (nextsize > pointFlow.maximumSize)
1112
+ nextsize = pointFlow.maximumSize;
1113
+ //
1114
+
1115
+ double count = 0;
1116
+
1117
+ while (distancenext > 0.000000001) // step
1118
+ {
1119
+ gl.glPushMatrix();
1120
+
1121
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1122
+
1123
+ double K = count/nbsteps;
1124
+
1125
+ double intersize = K*nextsize + (1-K)*size;
1126
+
1127
+ gl.glScaled(intersize,intersize,intersize);
1128
+
1129
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1130
+
1131
+ count++;
1132
+
1133
+ distancenext -= step;
1134
+
1135
+ gl.glPopMatrix();
1136
+ }
1137
+
1138
+ if (count != nbsteps)
1139
+ assert(count == nbsteps);
1140
+
1141
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1142
+ //gl.glTranslatef(-tx,-ty,-tz);
1143
+
1144
+ gl.glMatrixMode(gl.GL_TEXTURE);
1145
+ gl.glPopMatrix();
1146
+ }
1147
+
1148
+ if (!cf)
1149
+ gl.glDisable(gl.GL_CULL_FACE);
1150
+
1151
+// display.modelParams0[0] = r;
1152
+// display.modelParams0[1] = g;
1153
+// display.modelParams0[2] = b;
1154
+//
1155
+// display.modelParams5[1] = opacity;
1156
+//
1157
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1158
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1159
+
1160
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1161
+ }
1162
+
1163
+ public void DrawBox(cVector min, cVector max)
1164
+ {
1165
+ javax.media.opengl.GL gl = GetGL();
1166
+ gl.glBegin(gl.GL_LINES);
1167
+
1168
+ gl.glVertex3d(min.x, min.y, min.z);
1169
+ gl.glVertex3d(min.x, min.y, max.z);
1170
+ gl.glVertex3d(min.x, min.y, min.z);
1171
+ gl.glVertex3d(min.x, max.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, min.z);
1173
+ gl.glVertex3d(max.x, min.y, min.z);
1174
+
1175
+ gl.glVertex3d(max.x, max.y, max.z);
1176
+ gl.glVertex3d(min.x, max.y, max.z);
1177
+ gl.glVertex3d(max.x, max.y, max.z);
1178
+ gl.glVertex3d(max.x, min.y, max.z);
1179
+ gl.glVertex3d(max.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, min.z);
1181
+
1182
+ gl.glEnd();
1183
+ }
1184
+
1185
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1186
+ {
1187
+ int[] strips = bRep.getRawIndices();
1188
+
1189
+ javax.media.opengl.GL gl = GetGL();
1190
+
1191
+ // TRIANGLE STRIP ARRAY
1192
+ if (bRep.trimmed)
1193
+ {
1194
+ float[] v = bRep.getRawVertices();
1195
+ float[] n = bRep.getRawNormals();
1196
+ float[] c = bRep.getRawColors();
1197
+ float[] uv = bRep.getRawUVMap();
1198
+
1199
+ int count2 = 0;
1200
+ int count3 = 0;
1201
+
1202
+ if (n.length > 0)
1203
+ {
1204
+ for (int i = 0; i < strips.length; i++)
1205
+ {
1206
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1207
+
1208
+ /*
1209
+ boolean locked = false;
1210
+ float eps = 0.1f;
1211
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1212
+
1213
+ int dot = 0;
1214
+
1215
+ if ((dot&1) == 0)
1216
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1217
+
1218
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1219
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1220
+ else
1221
+ {
1222
+ locked = true;
1223
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1224
+ }
1225
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1226
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1227
+ if (hasnorm)
1228
+ {
1229
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1230
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1231
+ }
1232
+
1233
+ if ((dot&4) == 0)
1234
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1235
+
1236
+ if (wrap || !locked && (dot&8) != 0)
1237
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1238
+ else
1239
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1240
+
1241
+ f.dot = dot;
1242
+ */
1243
+
1244
+ if (!selectmode)
1245
+ {
1246
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1247
+ {
1248
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1249
+ } else
1250
+ {
1251
+ gl.glNormal3f(0, 0, 1);
1252
+ }
1253
+
1254
+ if (c != null)
1255
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1256
+ {
1257
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1258
+ }
1259
+ }
1260
+
1261
+ if (flipV)
1262
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1263
+ else
1264
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
1266
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1267
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1268
+
1269
+ count2 += 2;
1270
+ count3 += 3;
1271
+ if (!selectmode)
1272
+ {
1273
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1274
+ {
1275
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1276
+ } else
1277
+ {
1278
+ gl.glNormal3f(0, 0, 1);
1279
+ }
1280
+ if (c != null)
1281
+ {
1282
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1283
+ }
1284
+ }
1285
+
1286
+ if (flipV)
1287
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1288
+ else
1289
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
1291
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1292
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1293
+
1294
+ count2 += 2;
1295
+ count3 += 3;
1296
+ for (int j = 0; j < strips[i] - 2; j++)
1297
+ {
1298
+ //gl.glTexCoord2d(...);
1299
+ if (!selectmode)
1300
+ {
1301
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1302
+ {
1303
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1304
+ } else
1305
+ {
1306
+ gl.glNormal3f(0, 0, 1);
1307
+ }
1308
+ if (c != null)
1309
+ {
1310
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1311
+ }
1312
+ }
1313
+
1314
+ if (flipV)
1315
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1316
+ else
1317
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
1319
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1320
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
1322
+ count2 += 2;
1323
+ count3 += 3;
1324
+ }
1325
+
1326
+ gl.glEnd();
1327
+ }
1328
+ }
1329
+
1330
+ assert count3 == v.length;
1331
+ }
1332
+ else // !trimmed
1333
+ {
1334
+ int count = 0;
1335
+ for (int i = 0; i < strips.length; i++)
1336
+ {
1337
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1338
+
1339
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1340
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1341
+
1342
+ drawVertex(gl, p, flipV, selectmode);
1343
+ drawVertex(gl, q, flipV, selectmode);
1344
+
1345
+ for (int j = 0; j < strips[i] - 2; j++)
1346
+ {
1347
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1348
+
1349
+ // if (j%2 == 0)
1350
+ // drawFace(p, q, r, display, null);
1351
+ // else
1352
+ // drawFace(p, r, q, display, null);
1353
+
1354
+ // p = q;
1355
+ // q = r;
1356
+ drawVertex(gl, r, flipV, selectmode);
1357
+ }
1358
+
1359
+ gl.glEnd();
1360
+ }
1361
+ }
1362
+ }
1363
+
1364
+ static cSpring.Point3D temp = new cSpring.Point3D();
1365
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1366
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1367
+
1368
+ public void DrawDynamicMesh(cMesh mesh)
1369
+ {
1370
+ GL gl = GetGL(); // getGL();
1371
+
1372
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1373
+
1374
+ gl.glDisable(gl.GL_LIGHTING);
1375
+
1376
+ gl.glLineWidth(1);
1377
+ gl.glColor3f(1,1,1);
1378
+ gl.glBegin(gl.GL_LINES);
1379
+ double scale = 0;
1380
+ int count = 0;
1381
+ for (int s=0; s<Phys.allSprings.size(); s++)
1382
+ {
1383
+ cSpring.Spring spring = Phys.allSprings.get(s);
1384
+ if(s == 0)
1385
+ {
1386
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1387
+ }
1388
+ if (mesh.showsprings)
1389
+ {
1390
+ temp.set(spring.a.position);
1391
+ temp.add(spring.b.position);
1392
+ temp.mul(0.5);
1393
+ temp2.set(spring.a.position);
1394
+ temp2.sub(spring.b.position);
1395
+ temp2.mul(spring.restLength/2);
1396
+ temp.sub(temp2);
1397
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1398
+ temp.add(temp2);
1399
+ temp.add(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ }
1402
+
1403
+ if (spring.isHandle)
1404
+ continue;
1405
+
1406
+ //if (scale < spring.restLength)
1407
+ scale += spring.restLength;
1408
+ count++;
1409
+ }
1410
+ gl.glEnd();
1411
+
1412
+ if (count == 0)
1413
+ scale = 0.01;
1414
+ else
1415
+ scale /= count * 3;
1416
+
1417
+ //scale = 0.25;
1418
+
1419
+ if (mesh.ShowInfo())
1420
+ {
1421
+ gl.glLineWidth(4);
1422
+ for (int s=0; s<Phys.allNodes.size(); s++)
1423
+ {
1424
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1425
+ if (node.mass == 0)
1426
+ continue;
1427
+
1428
+ int i = node.springs==null?-1:node.springs.size();
1429
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1430
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1431
+ //temp.normalize();
1432
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1433
+ gl.glBegin(gl.GL_LINES);
1434
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1435
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1436
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1437
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1438
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1439
+ gl.glEnd();
1440
+ }
1441
+
1442
+ gl.glLineWidth(8);
1443
+ for (int s=0; s<Phys.allNodes.size(); s++)
1444
+ {
1445
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1446
+
1447
+ if (node.springs != null)
1448
+ {
1449
+ for (int i=0; i<node.springs.size(); i+=1)
1450
+ {
1451
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1452
+
1453
+ int c = i+1;
1454
+ // c = node.springs.get(i).nbcopies;
1455
+
1456
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1457
+ gl.glBegin(gl.GL_LINES);
1458
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1459
+ 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);
1460
+ gl.glEnd();
1461
+ }
1462
+ }
1463
+ }
1464
+
1465
+ gl.glLineWidth(1);
1466
+ }
1467
+
1468
+ gl.glEnable(gl.GL_LIGHTING);
1469
+ }
1470
+
1471
+ /// INTERFACE
1472
+
1473
+ public void StartTriangles()
1474
+ {
1475
+ javax.media.opengl.GL gl = GetGL();
1476
+ gl.glBegin(gl.GL_TRIANGLES);
1477
+ }
1478
+
1479
+ public void EndTriangles()
1480
+ {
1481
+ GetGL().glEnd();
1482
+ }
1483
+
1484
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1485
+ {
1486
+ if (!selectmode)
1487
+ {
1488
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1489
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1490
+
1491
+ if (flipV)
1492
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1493
+ else
1494
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1495
+ }
1496
+
1497
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1498
+ }
1499
+
1500
+ float[] colorV = new float[4];
1501
+
1502
+ void SetColor(Object3D obj, Vertex p0)
1503
+ {
1504
+ CameraPane display = this;
1505
+ BoundaryRep bRep = obj.bRep;
1506
+
1507
+ if (RENDERPROGRAM == 0)
1508
+ {
1509
+ float r = 0;
1510
+ if (bRep != null)
1511
+ {
1512
+ if (bRep.stripified)
1513
+ {
1514
+ r = 1;
1515
+ }
1516
+ }
1517
+ float g = 0;
1518
+ if (bRep != null)
1519
+ {
1520
+ if (bRep.trimmed)
1521
+ {
1522
+ g = 1;
1523
+ }
1524
+ }
1525
+ float b = 0;
1526
+ if (obj.support != null && obj.link2master)
1527
+ {
1528
+ b = 1;
1529
+ }
1530
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1531
+ return;
1532
+ }
1533
+
1534
+ if (display.DrawMode() != CameraPane.SHADOW)
1535
+ return;
1536
+
1537
+ javax.media.opengl.GL gl = display.GetGL();
1538
+// if (true) return;
1539
+// float ao = p.AO;
1540
+//
1541
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1542
+// // ao = 1;
1543
+//
1544
+// gl.glColor4f(ao, ao, ao, 1);
1545
+
1546
+// CameraPane.selectedpoint.
1547
+// getAverage(cStatic.point1, true);
1548
+ if (CameraPane.pointflow == null) // !random) // live)
1549
+ {
1550
+ return;
1551
+ }
1552
+
1553
+ cStatic.point1.set(0,0,0);
1554
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1555
+
1556
+ cStatic.point1.sub(p0);
1557
+
1558
+
1559
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1560
+// {
1561
+// return;
1562
+// }
1563
+
1564
+ //if (true)
1565
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1566
+ {
1567
+ return;
1568
+ }
1569
+
1570
+ if (false) // marked)
1571
+ {
1572
+ // debug rigging weights
1573
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1574
+ {
1575
+ float weight = p0.weights[object] / p0.totalweight;
1576
+
1577
+ // if (weight < 0.1)
1578
+ // {
1579
+ // assert(weight == 0);
1580
+ // continue;
1581
+ // }
1582
+
1583
+ if (p0.vertexlinks[object] == -1)
1584
+ continue;
1585
+
1586
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1587
+
1588
+ int color = //1 << object; //
1589
+ //p.vertexlinks.length;
1590
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1591
+ colorV[2] += (color & 1) * weight;
1592
+ colorV[1] += ((color & 2) >> 1) * weight;
1593
+ colorV[0] += ((color & 4) >> 2) * weight;
1594
+ }
1595
+ }
1596
+ else
1597
+ {
1598
+ if (obj.drawingstarted)
1599
+ {
1600
+ // find next point
1601
+ if (bRep.GetVertex(0).faceindices == null)
1602
+ {
1603
+ bRep.InitFaceIndices();
1604
+ }
1605
+
1606
+ double ymin = p0.y;
1607
+
1608
+ Vertex newp = p0;
1609
+
1610
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1611
+ {
1612
+ int fi = p0.faceindices[fii];
1613
+
1614
+ if (fi == -1)
1615
+ break;
1616
+
1617
+ Face f = bRep.GetFace(fi);
1618
+
1619
+ Vertex p = bRep.GetVertex(f.p);
1620
+ Vertex q = bRep.GetVertex(f.q);
1621
+ Vertex r = bRep.GetVertex(f.r);
1622
+
1623
+ int swap = (int)(Math.random()*3);
1624
+
1625
+// for (int s=swap; --s>=0;)
1626
+// {
1627
+// Vertex t = p;
1628
+// p = q;
1629
+// q = r;
1630
+// r = t;
1631
+// }
1632
+ if (ymin > p.y)
1633
+ {
1634
+ ymin = p.y;
1635
+ newp = p;
1636
+// break;
1637
+ }
1638
+ if (ymin > q.y)
1639
+ {
1640
+ ymin = q.y;
1641
+ newp = q;
1642
+// break;
1643
+ }
1644
+ if (ymin > r.y)
1645
+ {
1646
+ ymin = r.y;
1647
+ newp = r;
1648
+// break;
1649
+ }
1650
+ }
1651
+
1652
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1653
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1654
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1655
+
1656
+ obj.drawingstarted = false;
1657
+
1658
+ // return;
1659
+ }
1660
+
1661
+ if (false) // CameraPane.DRAW
1662
+ {
1663
+ p0.AO = colorV[0] = 2;
1664
+ colorV[1] = 2;
1665
+ colorV[2] = 2;
1666
+ }
1667
+
1668
+ CameraPane.pointflow.add(p0);
1669
+ CameraPane.pointflow.Touch();
1670
+ }
1671
+
1672
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1673
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1674
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1675
+ }
1676
+
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1678
+ {
1679
+ CameraPane display = this;
1680
+ //new Exception().printStackTrace();
1681
+
1682
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1683
+ {
1684
+ return;
1685
+ }
1686
+
1687
+ javax.media.opengl.GL gl = display.GetGL();
1688
+
1689
+ //Color col = Color.getHSBColor(color,modulation,1);
1690
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1691
+ if (!material.multiply)
1692
+ {
1693
+ display.color = material.color;
1694
+ display.saturation = material.modulation;
1695
+ }
1696
+ else
1697
+ {
1698
+ display.color *= material.color*2;
1699
+ display.saturation *= material.modulation*2;
1700
+ }
1701
+
1702
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1703
+
1704
+ float[] colorV = Grafreed.colorV;
1705
+
1706
+ /**/
1707
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1708
+ {
1709
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1710
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1711
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1712
+ colorV[3] = 1; // material.opacity;
1713
+
1714
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1715
+ //System.out.println("Opacity = " + opacity);
1716
+
1717
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1718
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1719
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1720
+
1721
+ float amb = material.ambient;
1722
+ if (amb < material.cameralight)
1723
+ {
1724
+ amb = material.cameralight;
1725
+ }
1726
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1727
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1728
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1729
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1730
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1731
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1732
+
1733
+ /**/
1734
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1735
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1736
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1737
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1738
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1739
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1740
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1741
+ //System.out.println("shininess = " + colorV[0]);
1742
+ if (colorV[0] > 128)
1743
+ {
1744
+ colorV[0] = 128;
1745
+ }
1746
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1747
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1748
+ /**/
1749
+ }
1750
+ /**/
1751
+
1752
+ //selected = false;
1753
+ selected = selected && display.flash;
1754
+
1755
+ //display.modelParams0[0] = 0; // pigment.r;
1756
+ //display.modelParams0[1] = 0; // pigment.g;
1757
+ //display.modelParams0[2] = 0; // pigment.b;
1758
+ if (!material.multiply)
1759
+ {
1760
+ display.modelParams0[3] = material.metalness;
1761
+ display.modelParams1[0] = material.diffuse;
1762
+ display.modelParams1[1] = material.specular;
1763
+ display.modelParams1[2] = 1 / material.shininess;
1764
+ display.modelParams1[3] = material.shift;
1765
+ display.modelParams2[0] = material.ambient;
1766
+ display.modelParams2[1] = material.lightarea;
1767
+ //System.out.println("light area = " + lightarea);
1768
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1769
+ display.modelParams2[3] = material.velvet;
1770
+ display.modelParams3[0] = material.sheen;
1771
+ display.modelParams3[1] = material.subsurface;
1772
+ display.modelParams3[2] = material.bump; // backlit
1773
+ display.modelParams3[3] = material.aniso;
1774
+ display.modelParams4[0] = material.anisoV;
1775
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1776
+ //System.out.println("selected = " + selected);
1777
+ display.modelParams4[2] = material.diffuseness;
1778
+ display.modelParams4[3] = material.shadow;
1779
+ display.modelParams5[0] = material.texture;
1780
+ display.modelParams5[1] = material.opacity;
1781
+ display.modelParams5[2] = material.fakedepth;
1782
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1783
+ }
1784
+ else
1785
+ {
1786
+ display.modelParams0[3] *= material.metalness*2;
1787
+ display.modelParams1[0] *= material.diffuse*2;
1788
+ display.modelParams1[1] *= material.specular*2;
1789
+ display.modelParams1[2] *= material.shininess*2;
1790
+ display.modelParams1[3] *= material.shift*2;
1791
+ display.modelParams2[0] *= material.ambient*2;
1792
+ display.modelParams2[1] *= material.lightarea*2;
1793
+ display.modelParams2[2] *= material.factor*2;
1794
+ display.modelParams2[3] *= material.velvet*2;
1795
+ display.modelParams3[0] *= material.sheen*2;
1796
+ display.modelParams3[1] *= material.subsurface*2;
1797
+ display.modelParams3[2] *= material.bump*2;
1798
+ display.modelParams3[3] *= material.aniso*2;
1799
+ display.modelParams4[0] *= material.anisoV*2;
1800
+ display.modelParams4[1] *= material.cameralight*2;
1801
+ //System.out.println("selected = " + selected);
1802
+ display.modelParams4[2] *= material.diffuseness*2;
1803
+ display.modelParams4[3] *= material.shadow*2;
1804
+ display.modelParams5[0] *= material.texture*2;
1805
+ display.modelParams5[1] *= material.opacity*2;
1806
+ display.modelParams5[2] *= material.fakedepth*2;
1807
+ display.modelParams5[3] *= material.shadowbias*2;
1808
+ }
1809
+
1810
+ display.modelParams6[0] = 0;
1811
+ display.modelParams6[1] = 0;
1812
+ display.modelParams6[2] = 0;
1813
+ display.modelParams6[3] = 0;
1814
+
1815
+ display.modelParams7[0] = 0;
1816
+ display.modelParams7[1] = 1000;
1817
+ display.modelParams7[2] = 0;
1818
+ display.modelParams7[3] = 0;
1819
+
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
1821
+
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1823
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1824
+ {
1825
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1826
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1827
+ if (extparams.length > 1)
1828
+ {
1829
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1830
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1831
+ if (extparams.length > 2)
1832
+ {
1833
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1834
+ float x = extparams[2].y / 1000.0f;
1835
+ //if (x == 0)
1836
+ // x = 1f;
1837
+ 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
1838
+ if (extparams[2].y > 0)
1839
+ {
1840
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1841
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1842
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1843
+ }
1844
+ }
1845
+ }
1846
+ }
1847
+
1848
+ //if (display.modelParams6[2] != 0)
1849
+ /*
1850
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1851
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1852
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1853
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1854
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1855
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1856
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1857
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1858
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1859
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1860
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1861
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1862
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1863
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1864
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1865
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1866
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1867
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1868
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1869
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1870
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1871
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1872
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1873
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1874
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1875
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1876
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1877
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1878
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1879
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1880
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1881
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1882
+ /**/
1883
+ //assert (display.modelParams6[2] == 0);
1884
+
1885
+ //System.out.println("noise power = " + display.modelParams7[0]);
1886
+ //System.out.println("shadowbias = " + shadowbias);
1887
+
1888
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1889
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1890
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1891
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1892
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1893
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1896
+
1897
+ int mode = display.FP_SHADER;
1898
+
1899
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1900
+ {
1901
+ mode |= display.FP_ANISO;
1902
+ }
1903
+
1904
+ display.EnableProgram(mode);
1905
+
1906
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1907
+
1908
+ if (!material.multiply)
1909
+ {
1910
+ if (Globals.drawMode == CameraPane.SHADOW)
1911
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1912
+ else
1913
+ gl.glDepthMask(material.opacity >= 0.99);
1914
+ }
2081915 }
2091916
2101917 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,10 +1932,10 @@
2251932 currentGL.glMultMatrixd(model, 0);
2261933 }
2271934
228
- void PushMatrix(double[][] matrix, int count)
1935
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291936 {
2301937 matrixdepth++;
231
- // GraphreeD.tracein(matrix);
1938
+ // GrafreeD.tracein(matrix);
2321939 if (matrix == null)
2331940 return; // Identity
2341941
....@@ -253,13 +1960,13 @@
2531960
2541961 void PushMatrix(double[][] matrix)
2551962 {
256
- // GraphreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1963
+ // GrafreeD.tracein(matrix);
1964
+ PushMatrix(matrix, 1);
2581965 }
2591966
2601967 void PushMatrix()
2611968 {
262
- // GraphreeD.tracein(null);
1969
+ // GrafreeD.tracein(null);
2631970 if (matrixdepth++ < MAXSTACK - 1)
2641971 {
2651972 currentGL.glPushMatrix();
....@@ -270,11 +1977,11 @@
2701977
2711978 double[][] tmpmat = new double[4][4];
2721979
273
- void PopMatrix(double[][] inverse)
1980
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741981 {
2751982 --matrixdepth;
2761983
277
- // GraphreeD.traceout(inverse);
1984
+ // GrafreeD.traceout(inverse);
2781985 if (inverse == null)
2791986 return; // Identity
2801987
....@@ -292,7 +1999,7 @@
2921999
2932000 void PopMatrix()
2942001 {
295
- // GraphreeD.traceout(null);
2002
+ // GrafreeD.traceout(null);
2962003 // inverse == null??
2972004 if (--matrixdepth < MAXSTACK - 1)
2982005 {
....@@ -310,7 +2017,7 @@
3102017 PushTextureMatrix(matrix, 1);
3112018 }
3122019
313
- void PushTextureMatrix(double[][] matrix, int count)
2020
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142021 {
3152022 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162023
....@@ -324,7 +2031,7 @@
3242031 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252032 }
3262033
327
- void PopTextureMatrix(double[][] inverse)
2034
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282035 {
3292036 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302037 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2058,15 @@
3512058
3522059 static int camerachangeframe;
3532060
354
- boolean SetCamera(Camera cam)
2061
+ public boolean SetCamera(Camera cam)
3552062 {
3562063 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572064 // return false;
3582065
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2066
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602067 {
3612068 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2069
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632070 {
3642071 // refuse the camera change
3652072 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2074,7 @@
3672074 }
3682075 }
3692076
370
- camerachangeframe = framecount;
2077
+ camerachangeframe = Globals.framecount;
3712078
3722079 cam.hAspect = -1; // Read only
3732080
....@@ -398,7 +2105,7 @@
3982105 {
3992106 //System.err.println("Oeil on");
4002107 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2108
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022109 // object.editWindow.ScreenFit(trackedobject);
4032110 //pingthread.StepToTarget(true);
4042111 }
....@@ -407,8 +2114,8 @@
4072114 {
4082115 //System.err.println("Oeil on");
4092116 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2117
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122119 //pingthread.StepToTarget(true);
4132120 }
4142121
....@@ -471,39 +2178,12 @@
4712178 {
4722179 frozen ^= true;
4732180 // Weird...
474
- lighttouched = true;
2181
+ Globals.lighttouched = true;
4752182 }
4762183
4772184 void ToggleDL()
4782185 {
4792186 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
- GraphreeD.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;
5072187 }
5082188
5092189 void ToggleFullScreen()
....@@ -513,12 +2193,7 @@
5132193
5142194 void ToggleCrowd()
5152195 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2196
+ Globals.CROWD ^= true;
5222197 }
5232198
5242199 void ToggleLocal()
....@@ -526,62 +2201,89 @@
5262201 LOCALTRANSFORM ^= true;
5272202 }
5282203
529
- void ToggleFast()
2204
+ public void ToggleTexture()
2205
+ {
2206
+ textureon ^= true;
2207
+ }
2208
+
2209
+ public void ToggleLive()
2210
+ {
2211
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2212
+
2213
+ System.err.println("LIVE = " + Globals.isLIVE());
2214
+
2215
+ if (!Globals.isLIVE()) // save sound
2216
+ Grafreed.savesound = true; // wav.save();
2217
+ // else
2218
+ repaint(); // start loop // may 2013
2219
+ }
2220
+
2221
+ public void ToggleSupport()
2222
+ {
2223
+ SUPPORT ^= true;
2224
+ }
2225
+
2226
+ public void ToggleAbort()
2227
+ {
2228
+ ABORTMODE ^= true;
2229
+ }
2230
+
2231
+ public void ToggleInertia()
2232
+ {
2233
+ INERTIA ^= true;
2234
+ }
2235
+
2236
+ public void ToggleFast()
5302237 {
5312238 FAST ^= true;
5322239 }
5332240
534
- void ToggleSlowPose()
2241
+ public void ToggleSlowPose()
5352242 {
5362243 SLOWPOSE ^= true;
5372244 }
5382245
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2246
+ public void ToggleBoxMode()
5452247 {
5462248 BOXMODE ^= true;
5472249 }
5482250
549
- void ToggleSmoothFocus()
2251
+ public void ToggleZoomBoxMode()
2252
+ {
2253
+ ZOOMBOXMODE ^= true;
2254
+ }
2255
+
2256
+ public void ToggleSmoothFocus()
5502257 {
5512258 SMOOTHFOCUS ^= true;
5522259 }
5532260
554
- void ToggleImageFlip()
2261
+ public void ToggleImageFlip()
5552262 {
5562263 IMAGEFLIP ^= true;
5572264 }
5582265
559
- void ToggleSpeakerMocap()
2266
+ public void ToggleSpeakerMocap()
5602267 {
5612268 SPEAKERMOCAP ^= true;
5622269 }
5632270
564
- void ToggleSpeakerCamera()
2271
+ public void ToggleSpeakerCamera()
5652272 {
5662273 SPEAKERCAMERA ^= true;
5672274 }
5682275
569
- void ToggleSpeakerFocus()
2276
+ public void ToggleSpeakerFocus()
5702277 {
5712278 SPEAKERFOCUS ^= true;
5722279 }
5732280
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2281
+ public void ToggleFrustum()
5802282 {
5812283 FRUSTUM ^= true;
5822284 }
5832285
584
- void ToggleTrack()
2286
+ public void ToggleTrack()
5852287 {
5862288 TRACK ^= true;
5872289 if (TRACK)
....@@ -600,25 +2302,35 @@
6002302 repaint();
6012303 }
6022304
603
- void ToggleTrackOnce()
2305
+ public void ToggleTrackOnce()
6042306 {
6052307 TRACKONCE ^= true;
6062308 }
6072309
608
- void ToggleShadowTrack()
2310
+ public void ToggleShadowTrack()
6092311 {
6102312 SHADOWTRACK ^= true;
6112313 repaint();
6122314 }
6132315
614
- void ToggleOeil()
2316
+ public void ToggleOeil()
6152317 {
6162318 OEIL ^= true;
6172319 }
6182320
619
- void ToggleOeilOnce()
2321
+ public void ToggleOeilOnce()
6202322 {
6212323 OEILONCE ^= true;
2324
+ }
2325
+
2326
+ void ToggleFootContact()
2327
+ {
2328
+ FOOTCONTACT ^= true;
2329
+ }
2330
+
2331
+ void ToggleDebug()
2332
+ {
2333
+ Globals.DEBUG ^= true;
6222334 }
6232335
6242336 void ToggleLookAt()
....@@ -626,9 +2338,9 @@
6262338 LOOKAT ^= true;
6272339 }
6282340
629
- void ToggleRandom()
2341
+ void ToggleSwitch()
6302342 {
631
- RANDOM ^= true;
2343
+ SWITCH ^= true;
6322344 }
6332345
6342346 void ToggleHandles()
....@@ -636,10 +2348,17 @@
6362348 HANDLES ^= true;
6372349 }
6382350
2351
+ Object3D paintFolder;
2352
+
6392353 void TogglePaint()
6402354 {
6412355 PAINTMODE ^= true;
6422356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
6432362 }
6442363
6452364 void SwapCamera(int a, int b)
....@@ -672,34 +2391,6 @@
6722391 //assert (cam.hAspect == 0);
6732392 cam.hAspect = 0;
6742393 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
7032394 }
7042395
7052396 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2450,26 @@
7592450
7602451 GL currentGL;
7612452
762
- GL GetGL()
2453
+ public GL GetGL() // INTERFACE
7632454 {
7642455 return currentGL;
7652456 }
766
-
2457
+
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
7672473 /**/
7682474 class CacheTexture
7692475 {
....@@ -772,28 +2478,31 @@
7722478
7732479 int resolution;
7742480
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762482 {
777
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
7782485 resolution = res;
7792486 }
7802487 }
7812488 /**/
7822489
7832490 // 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>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
7872496 int pigmentdepth = 0;
7882497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892498 int bumpdepth = 0;
7902499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952504
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972506 {
7982507 TextureData texturedata = null;
7992508
....@@ -812,13 +2521,34 @@
8122521 if (bump)
8132522 texturedata = ConvertBump(texturedata, false);
8142523
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172526
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);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202529
821
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
8222552 }
8232553
8242554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3621,8 @@
18913621
18923622 System.out.println("LOADING TEXTURE : " + name);
18933623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
18943626 //
18953627 if (false) // compressbit > 0)
18963628 {
....@@ -2000,10 +3732,12 @@
20003732 */
20013733 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20023734 {
3735
+ int pixelformat = texturedata.getPixelFormat();
3736
+
20033737 int stride = 1;
2004
- if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
3738
+ if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
20053739 stride = 3;
2006
- if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
3740
+ if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
20073741 stride = 4;
20083742
20093743 int width = texturedata.getWidth();
....@@ -2593,6 +4327,7 @@
25934327
25944328 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25954329 {
4330
+ new Exception().printStackTrace();
25964331 System.exit(0);
25974332 com.sun.opengl.util.texture.Texture texture = null;
25984333
....@@ -6269,7 +8004,7 @@
62698004 return null;
62708005 }
62718006
6272
- void ReleaseTextures(cTexture tex)
8007
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62738008 {
62748009 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62758010 {
....@@ -6286,7 +8021,7 @@
62868021 String pigment = Object3D.GetPigment(tex);
62878022 String bump = Object3D.GetBump(tex);
62888023
6289
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62908025 {
62918026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62928027 // System.out.println("; bump = " + bump);
....@@ -6301,13 +8036,71 @@
63018036 pigment = null;
63028037 }
63038038
6304
- ReleaseTexture(bump, true);
6305
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
63068041 }
63078042
6308
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63098044 {
6310
- if (// drawMode != 0 || /*tex == null ||*/
8045
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8046
+ {
8047
+ return;
8048
+ }
8049
+
8050
+ if (tex == null)
8051
+ {
8052
+ ReleaseTexture(null, false);
8053
+ return;
8054
+ }
8055
+
8056
+ String pigment = Object3D.GetPigment(tex);
8057
+
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8059
+ {
8060
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8061
+ // System.out.println("; bump = " + bump);
8062
+ }
8063
+
8064
+ if (pigment.equals(""))
8065
+ {
8066
+ pigment = null;
8067
+ }
8068
+
8069
+ ReleaseTexture(tex, false);
8070
+ }
8071
+
8072
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8073
+ {
8074
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8075
+ {
8076
+ return;
8077
+ }
8078
+
8079
+ if (tex == null)
8080
+ {
8081
+ ReleaseTexture(null, true);
8082
+ return;
8083
+ }
8084
+
8085
+ String bump = Object3D.GetBump(tex);
8086
+
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8088
+ {
8089
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8090
+ // System.out.println("; bump = " + bump);
8091
+ }
8092
+
8093
+ if (bump.equals(""))
8094
+ {
8095
+ bump = null;
8096
+ }
8097
+
8098
+ ReleaseTexture(tex, true);
8099
+ }
8100
+
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
8102
+ {
8103
+ if (// DrawMode() != 0 || /*tex == null ||*/
63118104 ambientOcclusion ) // || !textureon)
63128105 {
63138106 return;
....@@ -6316,7 +8109,7 @@
63168109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63178110
63188111 if (tex != null)
6319
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63208113
63218114 // //assert( texture != null );
63228115 // if (texture == null)
....@@ -6333,7 +8126,7 @@
63338126 {
63348127 bumpdepth--;
63358128
6336
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8129
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63378130 if (bumpstack[bumpdepth] != (texture!=null?texture.texture:null))
63388131 {
63398132 // assert (bumpstack[bumpdepth] == texture);
....@@ -6363,7 +8156,7 @@
63638156 {
63648157 pigmentdepth--;
63658158
6366
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8159
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63678160 if (pigmentstack[pigmentdepth] != (texture!=null?texture.texture:null))
63688161 {
63698162 // assert (pigmentstack[pigmentdepth] == texture);
....@@ -6408,9 +8201,57 @@
64088201 }
64098202 }
64108203
6411
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8204
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64128205 {
6413
- if (// drawMode != 0 || /*tex == null ||*/
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
8247
+
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
8250
+ }
8251
+
8252
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8253
+ {
8254
+ if (// DrawMode() != 0 || /*tex == null ||*/
64148255 ambientOcclusion ) // || !textureon)
64158256 {
64168257 return; // false;
....@@ -6419,17 +8260,47 @@
64198260 if (tex == null)
64208261 {
64218262 BindTexture(null,false,resolution);
6422
- BindTexture(null,true,resolution);
64238263 return;
64248264 }
64258265
64268266 String pigment = Object3D.GetPigment(tex);
8267
+
8268
+ usedtextures.add(tex);
8269
+
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8271
+ {
8272
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8273
+ // System.out.println("; bump = " + bump);
8274
+ }
8275
+
8276
+ if (pigment.equals(""))
8277
+ {
8278
+ pigment = null;
8279
+ }
8280
+
8281
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8282
+ BindTexture(tex, false, resolution);
8283
+ }
8284
+
8285
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8286
+ {
8287
+ if (// DrawMode() != 0 || /*tex == null ||*/
8288
+ ambientOcclusion ) // || !textureon)
8289
+ {
8290
+ return; // false;
8291
+ }
8292
+
8293
+ if (tex == null)
8294
+ {
8295
+ BindTexture(null,true,resolution);
8296
+ return;
8297
+ }
8298
+
64278299 String bump = Object3D.GetBump(tex);
64288300
6429
- usedtextures.put(pigment, pigment);
6430
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
64318302
6432
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64338304 {
64348305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64358306 // System.out.println("; bump = " + bump);
....@@ -6439,43 +8310,94 @@
64398310 {
64408311 bump = null;
64418312 }
6442
- if (pigment.equals(""))
6443
- {
6444
- pigment = null;
6445
- }
64468313
6447
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6448
- BindTexture(pigment, false, resolution);
64498314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6450
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
64518316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6452
-
6453
- return; // true;
64548317 }
64558318
6456
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
64578322 {
6458
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8323
+ if (missingTextures.contains(tex))
8324
+ {
8325
+ return false;
8326
+ }
8327
+
8328
+ boolean fileExists = new File(tex).exists();
8329
+
8330
+ if (!fileExists)
8331
+ {
8332
+ // If file exists, the "new File()" is not executed sgain
8333
+ missingTextures.add(tex);
8334
+ }
8335
+
8336
+ return fileExists;
8337
+ }
8338
+
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8340
+ {
8341
+ CacheTexture texturecache = null;
64598342
64608343 if (tex != null)
64618344 {
6462
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64638347
6464
- String[] split = tex.split("Textures");
6465
- if (split.length > 1)
6466
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6467
- else
6468
- if (!texname.startsWith("/"))
6469
- texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
8352
+
8353
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8354
+
8355
+// String[] split = tex.split("Textures");
8356
+// if (split.length > 1)
8357
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8358
+// else
8359
+// if (!texname.startsWith("/"))
8360
+// texname = "/Users/nbriere/Textures/" + texname;
8361
+ if (!FileExists(texname))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
64708365
64718366 if (CACHETEXTURE)
6472
- texture = textures.get(texname); // TEXTURE CACHE
6473
-
6474
- TextureData texturedata = null;
6475
-
6476
- if (texture == null || texture.resolution < resolution)
64778367 {
6478
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64798401 {
64808402 assert(!bump);
64818403 // if (bump)
....@@ -6486,19 +8408,23 @@
64868408 // }
64878409 // else
64888410 // {
6489
- texture = textures.get(tex);
6490
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
64918413 {
6492
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64938415 }
8416
+ else
8417
+ new Exception().printStackTrace();
64948418 // }
64958419 } else
6496
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64978421 {
64988422 assert(bump);
6499
- texture = textures.get(tex);
6500
- if (texture == null)
6501
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
65028428 } else
65038429 {
65048430 //if (tex.equals("IMMORTAL"))
....@@ -6506,11 +8432,13 @@
65068432 // texture = GetResourceTexture("default.png");
65078433 //} else
65088434 //{
6509
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
65108436 {
6511
- texture = textures.get(tex);
6512
- if (texture == null)
6513
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
65148442 } else
65158443 {
65168444 if (textureon)
....@@ -6535,7 +8463,7 @@
65358463 }
65368464
65378465 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6538
- if (!new File(cachename).exists())
8466
+ if (!FileExists(cachename))
65398467 cachename = texname;
65408468 else
65418469 processbump = false; // don't process bump map again
....@@ -6557,7 +8485,7 @@
65578485 }
65588486
65598487 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6560
- if (!new File(cachename).exists())
8488
+ if (!FileExists(cachename))
65618489 cachename = texname;
65628490 else
65638491 processbump = false; // don't process bump map again
....@@ -6566,20 +8494,22 @@
65668494 texturedata = GetFileTexture(cachename, processbump, resolution);
65678495
65688496
6569
- if (texturedata != null)
6570
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8497
+ if (texturedata == null)
8498
+ throw new Exception();
8499
+
8500
+ texturecache = new CacheTexture(texturedata,resolution);
65718501 //texture = GetTexture(tex, bump);
65728502 }
65738503 }
65748504 //}
65758505 }
65768506
6577
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8507
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65788508 {
65798509 //return false;
65808510
65818511 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6582
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8512
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65838513 {
65848514 // String ext = "_highres";
65858515 // if (REDUCETEXTURE)
....@@ -6596,52 +8526,17 @@
65968526 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65978527 if (!cachefile.exists())
65988528 {
6599
- // cache to disk
6600
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6601
- //buffers[0].
6602
-
6603
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6604
- int[] pixels = new int[bytebuf.capacity()/3];
6605
-
6606
- // squared size heuristic...
6607
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8529
+ //if (texturedata.getWidth() == texturedata.getHeight())
66088530 {
6609
- for (int i=pixels.length; --i>=0;)
6610
- {
6611
- int i3 = i*3;
6612
- pixels[i] = 0xFF;
6613
- pixels[i] <<= 8;
6614
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6617
- pixels[i] <<= 8;
6618
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6619
- }
6620
-
6621
- /*
6622
- int r=0,g=0,b=0,a=0;
6623
- for (int i=0; i<width; i++)
6624
- for (int j=0; j<height; j++)
6625
- {
6626
- int index = j*width+i;
6627
- int p = pixels[index];
6628
- a = ((p>>24) & 0xFF);
6629
- r = ((p>>16) & 0xFF);
6630
- g = ((p>>8) & 0xFF);
6631
- b = (p & 0xFF);
6632
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6633
- }
6634
- /**/
6635
- int width = (int)Math.sqrt(pixels.length); // squared
6636
- int height = width;
6637
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6638
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8531
+ BufferedImage rendImage = CreateBim(texturedata);
8532
+
66398533 ImageWriter writer = null;
66408534 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66418535 if (iter.hasNext()) {
66428536 writer = (ImageWriter)iter.next();
66438537 }
6644
- float compressionQuality = 0.9f;
8538
+
8539
+ float compressionQuality = 0.85f;
66458540 try
66468541 {
66478542 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6658,18 +8553,20 @@
66588553 }
66598554 }
66608555 }
6661
-
8556
+
8557
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8558
+
66628559 //System.out.println("Texture = " + tex);
6663
- if (textures.containsKey(texname))
8560
+ if (textures.containsKey(tex))
66648561 {
6665
- CacheTexture thetex = textures.get(texname);
8562
+ CacheTexture thetex = textures.get(tex);
66668563 thetex.texture.disable();
66678564 thetex.texture.dispose();
6668
- textures.remove(texname);
8565
+ textures.remove(tex);
66698566 }
66708567
6671
- texture.texturedata = texturedata;
6672
- textures.put(texname, texture);
8568
+ //texture.texturedata = texturedata;
8569
+ textures.put(tex, texturecache);
66738570
66748571 // newtex = true;
66758572 }
....@@ -6685,42 +8582,76 @@
66858582 }
66868583 }
66878584
6688
- return texture;
8585
+ return texturecache;
66898586 }
66908587
6691
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8588
+ static void EmbedTextures(cTexture tex)
8589
+ {
8590
+ if (tex.pigmentdata == null)
8591
+ {
8592
+ //String texname = Object3D.GetPigment(tex);
8593
+
8594
+ CacheTexture texturecache = texturepigment.get(tex);
8595
+
8596
+ if (texturecache != null)
8597
+ {
8598
+ tex.pw = texturecache.texturedata.getWidth();
8599
+ tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
8604
+ }
8605
+ }
8606
+
8607
+ if (tex.bumpdata == null)
8608
+ {
8609
+ //String texname = Object3D.GetBump(tex);
8610
+
8611
+ CacheTexture texturecache = texturebump.get(tex);
8612
+
8613
+ if (texturecache != null)
8614
+ {
8615
+ tex.bw = texturecache.texturedata.getWidth();
8616
+ tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8618
+ }
8619
+ }
8620
+ }
8621
+
8622
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66928623 {
66938624 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66948625
66958626 if (bump)
66968627 {
6697
- // GraphreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
8628
+ // GrafreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
66988629 bumpstack[bumpdepth++] = texture!=null?texture.texture:null;
66998630 }
67008631 else
67018632 {
6702
- // GraphreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
8633
+ // GrafreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
67038634 pigmentstack[pigmentdepth++] = texture!=null?texture.texture:null;
67048635 }
67058636
67068637 return texture!=null?texture.texture:null;
67078638 }
67088639
6709
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8640
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67108641 {
67118642 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67128643
67138644 return texture!=null?texture.texturedata:null;
67148645 }
67158646
6716
- boolean BindTexture(String tex, boolean bump, int resolution)
8647
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67178648 {
67188649 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67198650 {
67208651 return false;
67218652 }
67228653
6723
- boolean newtex = false;
8654
+ //boolean newtex = false;
67248655
67258656 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67268657
....@@ -6752,9 +8683,75 @@
67528683 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67538684 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67548685
6755
- return newtex;
8686
+ return true; // Warning: not used.
67568687 }
67578688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
67588755 ShadowBuffer shadowPBuf;
67598756 AntialiasBuffer antialiasPBuf;
67608757 int MAXSTACK;
....@@ -6947,7 +8944,7 @@
69478944
69488945 if (cubemap == null)
69498946 {
6950
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
69518948 }
69528949
69538950 //cubemap.enable();
....@@ -7234,37 +9231,58 @@
72349231 cubemap = null;
72359232 return;
72369233 case 1:
7237
- name = "cubemaps/box_";
7238
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
72399236 reverseUP = false;
72409237 break;
72419238 case 2:
7242
- name = "cubemaps/uffizi_";
7243
- ext = "png";
7244
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
72459243 case 3:
7246
- name = "cubemaps/CloudyHills_";
7247
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
72489246 reverseUP = false;
72499247 break;
72509248 case 4:
7251
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
72529250 ext = "png";
72539251 reverseUP = false;
72549252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
72559278 default:
7256
- name = "cubemaps/rgb_";
7257
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
72589282 break;
72599283 }
7260
-
7261
- try
7262
- {
7263
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7264
- } catch (IOException e)
7265
- {
7266
- throw new RuntimeException(e);
7267
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
72689286 }
72699287
72709288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7296,8 +9314,13 @@
72969314 static double[] model = new double[16];
72979315 double[] camera2light = new double[16];
72989316 double[] light2camera = new double[16];
7299
- int newenvy = -1;
9317
+
9318
+ //int newenvy = -1;
73009319 boolean envyoff = true; // false;
9320
+ String skyboxname = "";
9321
+ String skyboxext;
9322
+ String loadedskyboxname = "";
9323
+
73019324 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73029325 //float[] light0 = { 0,0,0 };
73039326 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7310,9 +9333,9 @@
73109333 static boolean occlusionInitialized = false;
73119334 boolean selection = false;
73129335 boolean pointselection = false;
7313
- /*static*/ boolean lighttouched = true;
9336
+ ///*static*/ boolean lighttouched = true;
73149337 boolean deselect;
7315
- boolean ambientOcclusion = false;
9338
+ private boolean ambientOcclusion = false;
73169339 static boolean flash = false;
73179340 /*static*/ boolean wait = false;
73189341 boolean displaydone = false; // after repaint() calls
....@@ -7442,6 +9465,8 @@
74429465 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74439466 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74449467 double scale = lightCamera.SCALE / lightCamera.Distance();
9468
+// PATCH FILLE AUX JEANS
9469
+ //scale *= lightCamera.shaper_fovy / 25;
74459470 gl.glScaled(2 * scale, 2 * scale, -scale);
74469471 gl.glTranslated(0, 0, lightCamera.DECAL);
74479472
....@@ -7588,17 +9613,40 @@
75889613 jy8[3] = 0.5f;
75899614 }
75909615
7591
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9616
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75929617 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
7593
- float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
9618
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9619
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75949620
9621
+ void ResetOptions()
9622
+ {
9623
+ options1[0] = 100;
9624
+ options1[1] = 0.025f;
9625
+ options1[2] = 0.01f;
9626
+ options1[3] = 0;
9627
+ options1[4] = 0;
9628
+
9629
+ options2[0] = 0;
9630
+ options2[1] = 0.75f;
9631
+ options2[2] = 0;
9632
+ options2[3] = 0;
9633
+
9634
+ options3[0] = 1;
9635
+ options3[1] = 1;
9636
+ options3[2] = 1;
9637
+ options3[3] = 0;
9638
+
9639
+ options4[0] = 1;
9640
+ options4[1] = 0;
9641
+ options4[2] = 1;
9642
+ options4[3] = 0;
9643
+ }
9644
+
75959645 static int imagecount = 0; // movie generation
75969646
75979647 static int jitter = 0;
75989648
75999649 boolean restartframe = false;
7600
-
7601
- static int framecount = 0; // general-purpose global count
76029650
76039651 void displayAntiAliased(javax.media.opengl.GL gl)
76049652 {
....@@ -7628,14 +9676,14 @@
76289676
76299677 //System.out.println("start frame");
76309678 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
7631
- for (jitter = 0; jitter < ACSIZE; jitter++) //, GraphreeD.wav.cursor += LIVE ? 735 : 0)
9679
+ for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76329680 {
7633
- framecount++;
9681
+ Globals.framecount++;
76349682
76359683 if (CameraPane.tickcount > 0)
76369684 CameraPane.tickcount--;
76379685
7638
-// GraphreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
9686
+// GrafreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
76399687 // restartframe = true;
76409688 if (options1[2] > 100 && (jitter%2==0))
76419689 {
....@@ -7668,7 +9716,7 @@
76689716
76699717 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76709718 */
7671
- lighttouched = true;
9719
+ Globals.lighttouched = true;
76729720 //System.err.println(" shadowbuffer: " + jitter);
76739721 shadowbuffer.display();
76749722
....@@ -7689,8 +9737,8 @@
76899737 assert (parentcam != renderCamera);
76909738
76919739 if (renderCamera != lightCamera)
7692
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7693
- LA.matConcat(parentcam.toParent, matrix, matrix);
9740
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9741
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76949742
76959743 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76969744
....@@ -7705,8 +9753,8 @@
77059753 LA.matCopy(renderCamera.fromScreen, matrix);
77069754
77079755 if (renderCamera != lightCamera)
7708
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7709
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9756
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9757
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77109758
77119759 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77129760
....@@ -7752,10 +9800,12 @@
77529800 rati = 1 / rati;
77539801 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77549802 }
7755
- assert (newenvy == -1);
9803
+
9804
+ //assert (newenvy == -1);
9805
+
77569806 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77579807 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7758
- DrawSkyBox(gl);
9808
+ DrawSkyBox(gl, (float)rati);
77599809 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77609810 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77619811 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7778,7 +9828,7 @@
77789828 //gl.glFlush();
77799829 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77809830
7781
- if (ANIMATION && ABORTED)
9831
+ if (Globals.ANIMATION && ABORTED)
77829832 {
77839833 System.err.println(" ABORTED FRAME");
77849834 break;
....@@ -7808,7 +9858,7 @@
78089858 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78099859
78109860 // save image
7811
- if (ANIMATION && !ABORTED)
9861
+ if (Globals.ANIMATION && !ABORTED)
78129862 {
78139863 VPwidth = viewport[2];
78149864 VPheight = viewport[3];
....@@ -7919,11 +9969,11 @@
79199969
79209970 // imagecount++;
79219971
7922
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9972
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79239973
79249974 if (!BOXMODE)
79259975 {
7926
- System.out.println("image: " + fullname + " (" + (GraphreeD.wav.cursor / 735 / 4) + ")");
9976
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79279977 }
79289978
79299979 if (!BOXMODE)
....@@ -7951,7 +10001,7 @@
795110001 {
795210002 if (ACSIZE > 1)
795310003 {
7954
- // System.err.println("image #" + (GraphreeD.wav.cursor / 735 / 4));
10004
+ // System.err.println("image #" + (GrafreeD.wav.cursor / 735 / 4));
795510005 }
795610006 }
795710007
....@@ -7961,7 +10011,7 @@
796110011 ABORTED = false;
796210012 }
796310013 else
7964
- GraphreeD.wav.cursor += 735 * ACSIZE;
10014
+ Grafreed.wav.cursor += 735 * ACSIZE;
796510015
796610016 if (false)
796710017 {
....@@ -8615,13 +10665,6 @@
861510665 }
861610666 }
861710667
8618
- boolean IsFrozen()
8619
- {
8620
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8621
-
8622
- return !selectmode && cameracount == 0; // != 0;
8623
- }
8624
-
862510668 boolean niceon = false;
862610669 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
862710670 boolean currentlydrawing = false;
....@@ -8631,16 +10674,16 @@
863110674
863210675 public void display(GLAutoDrawable drawable)
863310676 {
8634
- if (GraphreeD.savesound && GraphreeD.hassound)
10677
+ if (Grafreed.savesound && Grafreed.hassound)
863510678 {
8636
- GraphreeD.wav.save();
8637
- GraphreeD.savesound = false;
8638
- GraphreeD.hassound = false;
10679
+ Grafreed.wav.save();
10680
+ Grafreed.savesound = false;
10681
+ Grafreed.hassound = false;
863910682 }
864010683 // if (DEBUG_SELECTION)
864110684 // {
8642
-// if (drawMode != SELECTION)
8643
-// drawMode = SELECTION;
10685
+// if (DrawMode() != SELECTION)
10686
+// DrawMode() = SELECTION;
864410687 // }
864510688
864610689 if (!isRenderer)
....@@ -8696,9 +10739,9 @@
869610739
869710740 //ANTIALIAS = 0;
869810741
8699
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10742
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870010743 {
8701
- if (niceon || isLIVE())
10744
+ if (niceon || Globals.isLIVE())
870210745 {
870310746 //if(active == 0)
870410747 // antialiaser = null;
....@@ -8711,6 +10754,7 @@
871110754 ANTIALIAS = 0;
871210755 //System.out.println("RESTART");
871310756 AAtimer.restart();
10757
+ Globals.TIMERRUNNING = true;
871410758 }
871510759 }
871610760 }
....@@ -8723,7 +10767,7 @@
872310767 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872410768 */
872510769
8726
- if (drawMode == DEFAULT)
10770
+ if (DrawMode() == DEFAULT)
872710771 {
872810772 currentlydrawing = true;
872910773 }
....@@ -8754,18 +10798,18 @@
875410798
875510799 // if(Applet3D.clipboard != null)
875610800 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8757
-//drawMode = SELECTION;
10801
+//DrawMode() = SELECTION;
875810802 indexcount = 0;
875910803
8760
- if (drawMode == OCCLUSION)
10804
+ if (DrawMode() == OCCLUSION)
876110805 {
8762
- drawMode = DEFAULT;
10806
+ Globals.drawMode = DEFAULT; // WARNING
876310807 ambientOcclusion = true;
876410808 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876510809 Object3D theobject = object;
876610810 Object3D theparent = object.parent;
876710811 object.parent = null;
8768
- object = (Object3D)GraphreeD.clone(object);
10812
+ object = (Object3D)Grafreed.clone(object);
876910813 object.Stripify();
877010814 if (theobject.selection == null || theobject.selection.Size() == 0)
877110815 theobject.PreprocessOcclusion(this);
....@@ -8778,19 +10822,20 @@
877810822 ambientOcclusion = false;
877910823 }
878010824
8781
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10825
+ if (//Globals.lighttouched &&
10826
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878210827 {
878310828 //if (RENDERSHADOW) // ?
878410829 if (!IsFrozen())
878510830 {
878610831 // dec 2012
8787
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10832
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
878810833 {
8789
- framecount++;
10834
+ Globals.framecount++;
879010835 shadowbuffer.display();
879110836 }
879210837 }
8793
- lighttouched = false; // ??
10838
+ Globals.lighttouched = false; // ??
879410839 //drawing = true;
879510840 //lighttouched = true;
879610841 }
....@@ -8811,9 +10856,9 @@
881110856 //eyeCamera.shaper_fovy = 1;
881210857 }
881310858
8814
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10859
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881510860 {
8816
- //System.out.println("drawMode = " + drawMode);
10861
+ //System.out.println("DrawMode() = " + DrawMode());
881710862 vertexMode |= VP_PASS;
881810863 //vertexMode |= VP_PROJECTION;
881910864 if (!ambientOcclusion)
....@@ -8873,7 +10918,7 @@
887310918 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887410919 //Camera lightcam = new Camera(light0);
887510920
8876
- if (drawMode == SHADOW)
10921
+ if (DrawMode() == SHADOW)
887710922 {
887810923 /*
887910924 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8911,8 +10956,8 @@
891110956
891210957 // if (parentcam != renderCamera) // not a light
891310958 if (cam != lightCamera)
8914
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8915
- LA.matConcat(parentcam.toParent, matrix, matrix);
10959
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891610961
891710962 for (int j = 0; j < 4; j++)
891810963 {
....@@ -8926,8 +10971,8 @@
892610971
892710972 // if (parentcam != renderCamera) // not a light
892810973 if (cam != lightCamera)
8929
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8930
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10974
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10975
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893110976
893210977 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893310978
....@@ -8963,7 +11008,7 @@
896311008 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896411009 } else
896511010 {
8966
- if (drawMode != DEFAULT)
11011
+ if (DrawMode() != DEFAULT)
896711012 {
896811013 gl.glClearColor(1, 1, 1, 0);
896911014 } // 1);
....@@ -9013,13 +11058,19 @@
901311058 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901411059 }
901511060
9016
- if (newenvy > -1)
11061
+// if (newenvy > -1)
11062
+// {
11063
+// LoadEnvy(newenvy);
11064
+// }
11065
+//
11066
+// newenvy = -1;
11067
+
11068
+ if (!skyboxname.equals(this.loadedskyboxname))
901711069 {
9018
- LoadEnvy(newenvy);
11070
+ LoadSkybox(skyboxname + "/", skyboxext, false);
11071
+ loadedskyboxname = skyboxname;
901911072 }
9020
-
9021
- newenvy = -1;
9022
-
11073
+
902311074 ratio = ((double) getWidth()) / getHeight();
902411075 //System.out.println("ratio = " + ratio);
902511076
....@@ -9028,14 +11079,14 @@
902811079
902911080 fast &= !ambientOcclusion;
903011081
9031
- if (drawMode == DEFAULT)
11082
+ if (DrawMode() == DEFAULT)
903211083 {
903311084 //gl.glEnable(gl.GL_ALPHA_TEST);
903411085 //gl.glActiveTexture(GL.GL_TEXTURE0);
903511086
903611087 if (!IsFrozen() && !ambientOcclusion)
903711088 {
9038
- DrawSkyBox(gl);
11089
+ DrawSkyBox(gl, (float)ratio);
903911090 }
904011091
904111092 //if (selection_view == -1)
....@@ -9089,6 +11140,8 @@
908911140 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909011141 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909111142 double scale = lightCamera.SCALE / lightCamera.Distance();
11143
+// PATCH FILLE AUX JEANS
11144
+ //scale *= lightCamera.shaper_fovy / 25;
909211145 gl.glScaled(2 * scale, 2 * scale, -scale);
909311146 gl.glTranslated(0, 0, lightCamera.DECAL);
909411147
....@@ -9184,7 +11237,16 @@
918411237 // Bump noise
918511238 gl.glActiveTexture(GL.GL_TEXTURE6);
918611239 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9187
- BindTexture(NOISE_TEXTURE, false, 2);
11240
+
11241
+ try
11242
+ {
11243
+ BindTexture(NOISE_TEXTURE, false, 2);
11244
+ }
11245
+ catch (Exception e)
11246
+ {
11247
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11248
+ }
11249
+
918811250
918911251 gl.glActiveTexture(GL.GL_TEXTURE0);
919011252 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9207,9 +11269,9 @@
920711269
920811270 gl.glMatrixMode(GL.GL_MODELVIEW);
920911271
9210
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9211
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9212
-//gl.glEnable(gl.GL_MULTISAMPLE);
11272
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11273
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11274
+gl.glEnable(gl.GL_MULTISAMPLE);
921311275 } else
921411276 {
921511277 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9220,14 +11282,16 @@
922011282 //System.out.println("BLENDING ON");
922111283 gl.glEnable(GL.GL_BLEND);
922211284 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9223
-
11285
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922411286 gl.glMatrixMode(gl.GL_PROJECTION);
922511287 gl.glLoadIdentity();
922611288
9227
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11289
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
922811290 {
922911291 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923011292 double scale = lightCamera.SCALE / lightCamera.Distance();
11293
+// PATCH FILLE AUX JEANS
11294
+ //scale *= lightCamera.shaper_fovy / 25;
923111295 gl.glScaled(2 * scale, 2 * scale, -scale);
923211296 gl.glTranslated(0, 0, lightCamera.DECAL);
923311297 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9280,7 +11344,7 @@
928011344 //gl.glPushMatrix();
928111345 gl.glLoadIdentity();
928211346
9283
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11347
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928411348 {
928511349 //LA.xformPos(light0, lightCamera.fromScreen, light);
928611350 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9307,8 +11371,8 @@
930711371 System.err.println("parentcam != renderCamera");
930811372
930911373 // if (cam != lightCamera)
9310
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9311
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11374
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11375
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
931211376 }
931311377
931411378 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9329,8 +11393,8 @@
932911393 if (true) // TODO
933011394 {
933111395 if (cam != lightCamera)
9332
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9333
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11396
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11397
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933411398 }
933511399
933611400 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9367,7 +11431,7 @@
936711431 }
936811432
936911433 /**/
9370
- if (true) // drawMode == SELECTION) // != DEFAULT)
11434
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937111435 gl.glDisable(gl.GL_LIGHTING);
937211436 else
937311437 gl.glEnable(gl.GL_LIGHTING);
....@@ -9379,12 +11443,13 @@
937911443
938011444 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
938111445 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11446
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
938211447
938311448 options2[0] *= renderCamera.Distance();
938411449
938511450 lightslot = 64;
938611451
9387
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11452
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
938811453 {
938911454 DrawLights(object);
939011455 }
....@@ -9395,7 +11460,7 @@
939511460 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
939611461 //System.out.println("fragmentMode = " + fragmentMode);
939711462
9398
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11463
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
939911464 {
940011465 /*
940111466 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9428,7 +11493,7 @@
942811493 }
942911494 }
943011495
9431
- if (drawMode == DEFAULT)
11496
+ if (DrawMode() == DEFAULT)
943211497 {
943311498 if (WIREFRAME && !ambientOcclusion)
943411499 {
....@@ -9446,7 +11511,7 @@
944611511 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
944711512 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
944811513
9449
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11514
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945011515 {
945111516 if (vertexMode != 0) // && !fast)
945211517 {
....@@ -9466,7 +11531,7 @@
946611531 }
946711532 }
946811533
9469
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11534
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947011535 {
947111536 //gl.glDepthFunc(GL.GL_LEQUAL);
947211537 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9474,27 +11539,24 @@
947411539
947511540 boolean texon = textureon;
947611541
9477
- if (RENDERPROGRAM > 0)
9478
- {
9479
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9480
- textureon = false;
9481
- }
11542
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11543
+ textureon = false;
11544
+
948211545 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948311546 //System.out.println("ALLO");
948411547 gl.glColorMask(false, false, false, false);
948511548 DrawObject(gl);
9486
- if (RENDERPROGRAM > 0)
9487
- {
9488
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9489
- textureon = texon;
9490
- }
11549
+
11550
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11551
+ textureon = texon;
11552
+
949111553 gl.glColorMask(true, true, true, true);
949211554
949311555 gl.glDepthFunc(GL.GL_EQUAL);
9494
- //gl.glDepthMask(false);
11556
+ gl.glDepthMask(false);
949511557 }
949611558
9497
- if (false) // drawMode == SHADOW)
11559
+ if (false) // DrawMode() == SHADOW)
949811560 {
949911561 //SetColumnMajorData(cameraInverseTransform, view_1);
950011562 //System.out.println("light = " + cameraInverseTransform);
....@@ -9508,16 +11570,16 @@
950811570 //System.out.println("object = " + object);
950911571 if (!frozen && !imageLocked)
951011572 {
9511
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11573
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951211574 {
951311575 displayAntiAliased(gl);
951411576 } else
951511577 {
951611578 programcount = 0;
9517
- int keepmode = drawMode;
11579
+ int keepmode = DrawMode();
951811580 // if (DEBUG_SELECTION)
951911581 // {
9520
-// drawMode = SELECTION;
11582
+// DrawMode() = SELECTION;
952111583 // }
952211584 // for point selection
952311585 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9527,10 +11589,10 @@
952711589 DrawObject(gl);
952811590
952911591 // jan 2013 System.err.println("RESET ABORT (display)");
9530
- // if (drawMode == DEFAULT)
11592
+ // if (DrawMode() == DEFAULT)
953111593 // ABORTED = false;
953211594 fullreset = false;
9533
- drawMode = keepmode;
11595
+ Globals.drawMode = keepmode; // WARNING
953411596 //System.out.println("PROGRAM SWITCH " + programcount);
953511597 }
953611598 }
....@@ -9538,11 +11600,11 @@
953811600 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
953911601 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954011602
9541
- if (drawMode == DEFAULT)
11603
+ if (DrawMode() == DEFAULT)
954211604 {
954311605 ReleaseTexture(NOISE_TEXTURE, false);
954411606 }
9545
- //if (drawMode == DEFAULT)
11607
+ //if (DrawMode() == DEFAULT)
954611608 {
954711609
954811610 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9554,7 +11616,7 @@
955411616 //else
955511617 //gl.glDisable(gl.GL_TEXTURE_2D);
955611618 //gl.glPopMatrix();
9557
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11619
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
955811620 {
955911621 //new Exception().printStackTrace();
956011622 //System.out.println("Draw image " + width + ", " + height);
....@@ -9596,7 +11658,7 @@
959611658 //gl.glFlush();
959711659 }
959811660
9599
- if (flash && drawMode == DEFAULT)
11661
+ if (flash && DrawMode() == DEFAULT)
960011662 {
960111663 flash = false;
960211664 wait = true;
....@@ -9604,9 +11666,9 @@
960411666 }
960511667
960611668 //drawing = false;
9607
- //if(drawMode == DEFAULT)
11669
+ //if(DrawMode() == DEFAULT)
960811670 // niceon = false;
9609
- if (drawMode == DEFAULT)
11671
+ if (DrawMode() == DEFAULT)
961011672 {
961111673 currentlydrawing = false;
961211674 }
....@@ -9626,7 +11688,7 @@
962611688 repaint();
962711689 }
962811690
9629
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11691
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963011692 repaint();
963111693
963211694 displaydone = true;
....@@ -9645,8 +11707,14 @@
964511707 {
964611708 renderpass++;
964711709 // System.out.println("Draw object... ");
11710
+ STEP = 1;
964811711 if (FAST) // in case there is no script
9649
- STEP = 16;
11712
+ STEP = 8;
11713
+
11714
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11715
+ {
11716
+ STEP *= 4;
11717
+ }
965011718
965111719 //object.FullInvariants();
965211720
....@@ -9660,23 +11728,44 @@
966011728 e.printStackTrace();
966111729 }
966211730
9663
- if (GraphreeD.RENDERME > 0)
9664
- GraphreeD.RENDERME--; // mechante magouille
11731
+ if (Grafreed.RENDERME > 0)
11732
+ Grafreed.RENDERME--; // mechante magouille
966511733
9666
- ONESTEP = false;
11734
+ Globals.ONESTEP = false;
966711735 }
966811736
966911737 static boolean zoomonce = false;
967011738
11739
+ static void CreateSelectedPoint()
11740
+ {
11741
+ if (selectedpoint == null)
11742
+ {
11743
+ debugpointG = new Sphere();
11744
+ debugpointP = new Sphere();
11745
+ debugpointC = new Sphere();
11746
+ debugpointR = new Sphere();
11747
+
11748
+ selectedpoint = new Superellipsoid();
11749
+
11750
+ for (int i=0; i<8; i++)
11751
+ {
11752
+ debugpoints[i] = new Sphere();
11753
+ }
11754
+ }
11755
+ }
11756
+
967111757 void DrawObject(GL gl, boolean draw)
967211758 {
11759
+ // To clear camera values
11760
+ ResetOptions();
11761
+
967311762 //System.out.println("DRAW OBJECT " + mouseDown);
9674
-// drawMode = SELECTION;
11763
+// DrawMode() = SELECTION;
967511764 //GL gl = getGL();
967611765 if ((TRACK || SHADOWTRACK) || zoomonce)
967711766 {
9678
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9679
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11767
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11768
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968011769 pingthread.StepToTarget(true); // true);
968111770 // zoomonce = false;
968211771 }
....@@ -9696,9 +11785,9 @@
969611785 callist = gl.glGenLists(1);
969711786 }
969811787
9699
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11788
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970011789
9701
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11790
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970211791
970311792 if (!mainDL || !active || touched)
970411793 {
....@@ -9725,24 +11814,32 @@
972511814 PushMatrix(ClickInfo.matbuffer);
972611815 }
972711816
9728
- if (drawMode == 0)
11817
+ if (DrawMode() == 0)
972911818 {
973011819 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973111820
973211821 usedtextures.clear();
973311822
9734
- BindTextures(DEFAULT_TEXTURES, 2);
11823
+ try
11824
+ {
11825
+ BindTextures(DEFAULT_TEXTURES, 2);
11826
+ }
11827
+ catch (Exception e)
11828
+ {
11829
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11830
+ }
973511831 }
973611832 //System.out.println("--> " + stackdepth);
9737
-// GraphreeD.traceon();
11833
+// GrafreeD.traceon();
973811834
973911835 // DRAW
974011836 object.draw(this, /*(Composite)*/ object, false, false);
974111837
9742
- if (drawMode == DEFAULT)
11838
+ if (DrawMode() == DEFAULT)
974311839 {
9744
- if (DEBUG)
11840
+ if (Globals.DEBUG)
974511841 {
11842
+ CreateSelectedPoint();
974611843 float radius = 0.05f;
974711844 if (selectedpoint.radius != radius)
974811845 {
....@@ -9750,69 +11847,104 @@
975011847 selectedpoint.radius = radius;
975111848 selectedpoint.recalculate();
975211849 selectedpoint.material = new cMaterial();
9753
- selectedpoint.material.color = 0.25f;
11850
+ selectedpoint.material.color = 0.15f; // Yellow
975411851 selectedpoint.material.modulation = 0.75f;
975511852
9756
- debugpoint.radius = radius;
9757
- debugpoint.recalculate();
9758
- debugpoint.material = new cMaterial();
9759
- debugpoint.material.color = 0.25f;
9760
- debugpoint.material.modulation = 0.75f;
11853
+ debugpointG.radius = radius;
11854
+ debugpointG.recalculate();
11855
+ debugpointG.material = new cMaterial();
11856
+ debugpointG.material.color = 0.25f; // Green
11857
+ debugpointG.material.modulation = 0.75f;
976111858
9762
- debugpoint2.radius = radius;
9763
- debugpoint2.recalculate();
9764
- debugpoint2.material = new cMaterial();
9765
- debugpoint2.material.color = 0.75f;
9766
- debugpoint2.material.modulation = 0.75f;
11859
+ debugpointP.radius = radius;
11860
+ debugpointP.recalculate();
11861
+ debugpointP.material = new cMaterial();
11862
+ debugpointP.material.color = 0.75f; // Purple
11863
+ debugpointP.material.modulation = 0.75f;
11864
+
11865
+ debugpointC.radius = radius;
11866
+ debugpointC.recalculate();
11867
+ debugpointC.material = new cMaterial();
11868
+ debugpointC.material.color = 0.5f; // Cyan
11869
+ debugpointC.material.modulation = 0.75f;
11870
+
11871
+ debugpointR.radius = radius;
11872
+ debugpointR.recalculate();
11873
+ debugpointR.material = new cMaterial();
11874
+ debugpointR.material.color = 0f; // Red
11875
+ debugpointR.material.modulation = 0.75f;
976711876
976811877 InitPoints(radius);
976911878 }
977011879 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9771
- //debugpoint.draw(this, /*(Composite)*/ null, false);
9772
- //debugpoint2.draw(this, /*(Composite)*/ null, false);
9773
- DrawPoints(this);
11880
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11881
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11882
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11883
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
11884
+ // DrawPoints(this);
977411885 }
977511886
977611887 // debugstuff.draw(this, /*(Composite)*/ null, false);
977711888 }
9778
-// GraphreeD.traceoff();
11889
+// GrafreeD.traceoff();
977911890 //System.out.println(stackdepth);
9780
- if (drawMode == 0)
11891
+ if (DrawMode() == 0)
978111892 {
978211893 ReleaseTextures(DEFAULT_TEXTURES);
978311894
978411895 if (CLEANCACHE)
9785
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11896
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
978611897 {
9787
- String tex = e.nextElement();
11898
+ cTexture tex = e.nextElement();
978811899
978911900 // System.out.println("Texture --------- " + tex);
979011901
9791
- if (tex.equals("WHITE_NOISE"))
11902
+ if (tex.equals("WHITE_NOISE:"))
979211903 continue;
979311904
9794
- if (!usedtextures.containsKey(tex))
11905
+ if (!usedtextures.contains(tex))
979511906 {
11907
+ CacheTexture gettex = texturepigment.get(tex);
979611908 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9797
- textures.get(tex).texture.dispose();
9798
- textures.remove(tex);
11909
+ if (gettex != null)
11910
+ {
11911
+ gettex.texture.dispose();
11912
+ texturepigment.remove(tex);
11913
+ }
11914
+
11915
+ gettex = texturebump.get(tex);
11916
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11917
+ if (gettex != null)
11918
+ {
11919
+ gettex.texture.dispose();
11920
+ texturebump.remove(tex);
11921
+ }
979911922 }
980011923 }
980111924 }
980211925
980311926 checker = null;
980411927
9805
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11928
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
980611929 FindChecker(object);
980711930
9808
- if (checker != null && drawMode == DEFAULT)
11931
+ if (checker != null && DrawMode() == DEFAULT)
980911932 {
9810
- // BindTexture(IMMORTAL_TEXTURE);
11933
+ //BindTexture(IMMORTAL_TEXTURE);
11934
+ try
11935
+ {
11936
+ BindTextures(checker.GetTextures(), checker.texres);
11937
+ }
11938
+ catch (Exception e)
11939
+ {
11940
+ System.err.println("FAILED: " + checker.GetTextures());
11941
+ }
981111942 // NEAREST
981211943 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
981311944 DrawChecker(gl);
981411945 //checker.Draw(this, null, false);
981511946 // ReleaseTexture(IMMORTAL_TEXTURE);
11947
+ ReleaseTextures(checker.GetTextures());
981611948 }
981711949
981811950 if (object.parent != null)
....@@ -9825,7 +11957,7 @@
982511957 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
982611958 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
982711959
9828
- if (DISPLAYTEXT && drawMode == DEFAULT)
11960
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
982911961 {
983011962 // Draw it once, then use the raster
983111963 Balloon(gl, balloon.createGraphics());
....@@ -9881,14 +12013,14 @@
988112013 int[] xs = new int[3];
988212014 int[] ys = new int[3];
988312015
9884
- void DrawString(Object3D obj) // String string)
12016
+ public void DrawString(Object3D obj) // String string) // INTERFACE
988512017 {
9886
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12018
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
988712019 {
988812020 return;
988912021 }
989012022
9891
- String string = obj.GetToolTip();
12023
+ String string = obj.toString(); //.GetToolTip();
989212024
989312025 GL gl = GetGL();
989412026
....@@ -10205,8 +12337,8 @@
1020512337 //obj.TransformToWorld(light, light);
1020612338 for (int i = tp.size(); --i >= 0;)
1020712339 {
10208
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10209
- LA.xformPos(light, tp.get(i).toParent, light);
12340
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12341
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1021012342 }
1021112343
1021212344
....@@ -10223,8 +12355,8 @@
1022312355 parentcam = cameras[0];
1022412356 }
1022512357
10226
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10227
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12358
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12359
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1022812360
1022912361 LA.xformPos(light, renderCamera.toScreen, light);
1023012362
....@@ -10314,8 +12446,76 @@
1031412446
1031512447 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1031612448
12449
+ String program0 =
12450
+ // Min shader
12451
+ "!!ARBfp1.0\n" +
12452
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12453
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12454
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12455
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12456
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12457
+ "PARAM light2cam0 = program.env[10];" +
12458
+ "PARAM light2cam1 = program.env[11];" +
12459
+ "PARAM light2cam2 = program.env[12];" +
12460
+ "TEMP temp;" +
12461
+ "TEMP light;" +
12462
+ "TEMP ndotl;" +
12463
+ "TEMP normal;" +
12464
+ "TEMP depth;" +
12465
+ "TEMP eye;" +
12466
+ "TEMP pos;" +
12467
+
12468
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12469
+ Normalize("normal") +
12470
+ "MOV light, state.light[0].position;" +
12471
+ "DP3 ndotl.x, light, normal;" +
12472
+
12473
+ // shadow
12474
+ "MOV pos, fragment.texcoord[1];" +
12475
+ "MOV temp, pos;" +
12476
+ ShadowTextureFetch("depth", "temp", "1") +
12477
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12478
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12479
+
12480
+ // No shadow when out of frustum
12481
+ //"SGE temp.y, depth.z, zero123.y;" +
12482
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12483
+
12484
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12485
+
12486
+ // Backlit
12487
+ "MOV pos.w, zero123.y;" +
12488
+ "DP4 eye.x, pos, light2cam0;" +
12489
+ "DP4 eye.y, pos, light2cam1;" +
12490
+ "DP4 eye.z, pos, light2cam2;" +
12491
+ Normalize("eye") +
12492
+
12493
+ "DP3 ndotl.y, -eye, normal;" +
12494
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12495
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12496
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12497
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12498
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12499
+
12500
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12501
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12502
+
12503
+ // Pigment
12504
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12505
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12506
+ "MUL temp, temp, ndotl.x;" +
12507
+
12508
+ "MUL temp, temp, zero123.z;" +
12509
+
12510
+ //"MUL temp, temp, ndotl.y;" +
12511
+
12512
+ "MOV temp.w, zero123.y;" + // reset alpha
12513
+ "MOV result.color, temp;" +
12514
+ "END";
12515
+
1031712516 String program =
1031812517 "!!ARBfp1.0\n" +
12518
+
1031912519 //"OPTION ARB_fragment_program_shadow;" +
1032012520 "PARAM light2cam0 = program.env[10];" +
1032112521 "PARAM light2cam1 = program.env[11];" +
....@@ -10343,11 +12543,13 @@
1034312543 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1034412544 "PARAM params7 = program.env[7];" + // noise power, opacity power
1034512545 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10346
- "PARAM options1 = program.env[62];" + // fog rgb color, image intensity
12546
+ "PARAM options1 = program.env[62];" + // fog rgb color
12547
+ "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
1034712548 "PARAM pointlight = program.env[127];" + // ...
1034812549 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1034912550 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1035012551 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12552
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1035112553 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1035212554 "PARAM ten = { 10, 10, 10, 1.0 };" +
1035312555 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10368,6 +12570,7 @@
1036812570 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1036912571 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1037012572 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12573
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1037112574 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1037212575 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1037312576 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10408,6 +12611,10 @@
1040812611 "TEMP R1;" +
1040912612 "TEMP R2;" +
1041012613 "TEMP R3;" +
12614
+ "TEMP min;" +
12615
+ "TEMP max;" +
12616
+ "TEMP average;" +
12617
+ "TEMP saturation;" +
1041112618 "TEMP keep1;" +
1041212619 "TEMP keep2;" +
1041312620 "TEMP keep3;" +
....@@ -10423,8 +12630,7 @@
1042312630 "TEMP shininess;" +
1042412631 "\n" +
1042512632 "MOV texSamp, one;" +
10426
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10427
-
12633
+
1042812634 "MOV mapgrid.x, one2048th.x;" +
1042912635 "MOV temp, fragment.texcoord[1];" +
1043012636 /*
....@@ -10445,20 +12651,20 @@
1044512651 "MUL temp, floor, mapgrid.x;" +
1044612652 //"TEX depth0, temp, texture[1], 2D;" +
1044712653 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10448
- TextureFetch("depth0", "temp", "1") +
12654
+ ShadowTextureFetch("depth0", "temp", "1") +
1044912655 "") +
1045012656 "ADD temp.x, temp.x, mapgrid.x;" +
1045112657 //"TEX depth1, temp, texture[1], 2D;" +
1045212658 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10453
- TextureFetch("depth1", "temp", "1") +
12659
+ ShadowTextureFetch("depth1", "temp", "1") +
1045412660 "") +
1045512661 "ADD temp.y, temp.y, mapgrid.x;" +
1045612662 //"TEX depth2, temp, texture[1], 2D;" +
10457
- TextureFetch("depth2", "temp", "1") +
12663
+ ShadowTextureFetch("depth2", "temp", "1") +
1045812664 "SUB temp.x, temp.x, mapgrid.x;" +
1045912665 //"TEX depth3, temp, texture[1], 2D;" +
1046012666 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10461
- TextureFetch("depth3", "temp", "1") +
12667
+ ShadowTextureFetch("depth3", "temp", "1") +
1046212668 "") +
1046312669 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1046412670 //"MOV params, material;" +
....@@ -10829,10 +13035,10 @@
1082913035 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1083013036 "") +
1083113037
10832
- // display shadow only (bump == 0)
13038
+ // display shadow only (fakedepth == 0)
1083313039 "SUB temp.x, half.x, shadow.x;" +
10834
- "MOV temp.y, -params6.x;" +
10835
- "SLT temp.z, temp.y, zero.x;" +
13040
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13041
+ "SLT temp.z, temp.y, -one2048th.x;" +
1083613042 "SUB temp.y, one.x, temp.z;" +
1083713043 "MUL temp.x, temp.x, temp.y;" +
1083813044 "KIL temp.x;" +
....@@ -10938,10 +13144,42 @@
1093813144
1093913145 // skin?
1094013146 // Saturation for skin
10941
- /**/ // c'est ici
10942
- (Skinshader? "DP3 temp.x, final,one;" +
13147
+ /**/
13148
+ (Skinshader?
13149
+ "DP3 average.x, final,one;" +
13150
+ "MUL average, one3rd.xxxx,average.xxxx;" +
13151
+
13152
+ "MIN min.x, final.x,final.y;" +
13153
+ "MIN min.x, min.x,final.z;" +
13154
+
13155
+ "MAX max.x, final.x,final.y;" +
13156
+ "MAX max.x, max.x,final.z;" +
13157
+ "MOV max, max.xxxx;" +
13158
+
13159
+ "SUB saturation, max, final;" +
13160
+
13161
+ "ADD temp.x, max.x, one10th.x;" +
13162
+ "RCP temp.x, temp.x;" +
13163
+ "MUL temp.x, temp.x, half.x;" +
13164
+ "MUL saturation, saturation, temp.xxxx;" +
13165
+
13166
+ "DP3 ndotl.x, normald, light;" +
13167
+ "MAX ndotl.x, ndotl.x, -ndotl.x;" +
13168
+
13169
+ "SUB temp.x, one.x, ndotl.x;" +
13170
+ // Tuning for default skin
13171
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13172
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13173
+ "ADD temp.y, one.y, options2.y;" + // subsurface
13174
+ "MUL temp.x, temp.x, temp.y;" +
13175
+
13176
+ "MUL saturation, saturation, temp.xxxx;" +
13177
+ "SUB_SAT temp, max, saturation;" +
13178
+/**
13179
+ "DP3 temp.x, final,one;" +
1094313180 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10944
- "SUB temp, final,R2;" +
13181
+ "SUB temp, final, R2;" +
13182
+
1094513183 // using light angle
1094613184 "DP3 ndotl.x, normald,light;" +
1094713185 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10954,7 +13192,6 @@
1095413192 // using light intensity
1095513193 "MOV ndotl.z, R2.x;" +
1095613194 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10957
-
1095813195 // june 2014
1095913196 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1096013197 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10966,6 +13203,7 @@
1096613203 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1096713204
1096813205 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13206
+/**/
1096913207
1097013208 // "ADD final, R2,temp;" +
1097113209 "MOV final, temp;"
....@@ -11055,7 +13293,7 @@
1105513293 /**/
1105613294 // HDR
1105713295 "MOV temp.z, final.a;" +
11058
- "MUL final, final,options1.w;" +
13296
+ "MUL final, final,options2.x;" +
1105913297 "MOV final.a, temp.z;" +
1106013298 /**/
1106113299
....@@ -11092,10 +13330,17 @@
1109213330 "MOV final.z, zero.x;" +
1109313331 "MOV final.a, one.w;":""
1109413332 ) +
13333
+ /*
1109513334 (NORMALdebug?"MOV final.x, normal.x;" +
1109613335 "MOV final.y, normal.y;" +
1109713336 "MOV final.z, normal.z;" +
1109813337 "MOV final.a, one.w;":""
13338
+ ) +
13339
+ */
13340
+ (NORMALdebug?"SUB final.x, one.x, final.x;" +
13341
+ "SUB final.y, one.x, final.y;" +
13342
+ "SUB final.z, one.x, final.z;" +
13343
+ "MOV final.a, final.a;":""
1109913344 ) +
1110013345 // "MOV final, bumpmap;" +
1110113346 "MOV result.color, final;" +
....@@ -11124,7 +13369,7 @@
1112413369 //once = true;
1112513370 }
1112613371
11127
- System.out.print("Program #" + mode + "; length = " + program.length());
13372
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1112813373 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1112913374 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1113013375
....@@ -11217,30 +13462,32 @@
1121713462 return out;
1121813463 }
1121913464
11220
- String TextureFetch(String dest, String src, String unit)
13465
+ // Also does frustum culling
13466
+ String ShadowTextureFetch(String dest, String src, String unit)
1122113467 {
1122213468 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1122313469 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1122413470 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13471
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13472
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1122513473 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11226
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11227
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11228
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11229
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13474
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13475
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1123013476 //"SWZ buffer, temp, w,w,w,w;";
11231
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13477
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1123213478 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1123313479 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1123413480 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11235
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13481
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1123613482
11237
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11238
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13483
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13484
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1123913485 }
1124013486
1124113487 String Shadow(String depth, String shadow)
1124213488 {
1124313489 return "MAX temp.x, ndotl.x, one64th.x;" +
13490
+ "MIN temp.x, temp.x, ninetenth.x;" +
1124413491 /**/
1124513492 // Sine
1124613493 "MUL temp.y, temp.x, temp.x;" +
....@@ -11256,12 +13503,16 @@
1125613503
1125713504 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1125813505 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13506
+
13507
+ // Compare fragment depth in light space with shadowmap.
1125913508 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1126013509 "SGE temp.y, temp.x, zero.x;" +
11261
- "SUB " + shadow + ".y, one.x, temp.y;" +
13510
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13511
+
13512
+ // Reverse comparison
1126213513 "SUB temp.x, one.x, temp.x;" +
1126313514 "MUL " + shadow + ".x, temp.x, temp.y;" +
11264
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13515
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1126513516 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1126613517
1126713518 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11275,6 +13526,10 @@
1127513526 // No shadow for backface
1127613527 "DP3 temp.x, normal, lightd;" +
1127713528 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13529
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13530
+
13531
+ // No shadow when out of frustum
13532
+ "SGE temp.x, " + depth + ".z, one.z;" +
1127813533 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1127913534 "";
1128013535 }
....@@ -11421,7 +13676,8 @@
1142113676 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1142213677 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1142313678 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11424
- Object3D.cVector2[] vector2buffer;
13679
+
13680
+ //Object3D.cVector2[] vector2buffer;
1142513681
1142613682 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1142713683 // OUT : diff, spec
....@@ -11437,9 +13693,10 @@
1143713693 "DP3 " + dest + ".z," + "normals," + "eye;" +
1143813694 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1143913695 //"MOV " + dest + ".w," + "normal.z;" +
11440
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11441
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11442
- //"MOV " + dest + ".z," + "params2.w;" +
13696
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13697
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13698
+
13699
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1144313700 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1144413701 "RCP " + dest + ".w," + dest + ".w;" +
1144513702 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11833,7 +14090,7 @@
1183314090 public void mousePressed(MouseEvent e)
1183414091 {
1183514092 //System.out.println("mousePressed: " + e);
11836
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14093
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1183714094 }
1183814095
1183914096 static long prevtime = 0;
....@@ -11860,14 +14117,16 @@
1186014117
1186114118 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1186214119
14120
+ if (BUTTONLESSWHEEL)
1186314121 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1186414122 {
1186514123 return;
1186614124 }
1186714125
14126
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1186814127
1186914128 // TIMER
11870
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14129
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1187114130 {
1187214131 keepboxmode = BOXMODE;
1187314132 keepsupport = SUPPORT;
....@@ -11907,8 +14166,8 @@
1190714166 // mode |= META;
1190814167 //}
1190914168
11910
- SetMouseMode(WHEEL | e.getModifiersEx());
11911
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14169
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14170
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1191214171 anchorX = ax;
1191314172 anchorY = ay;
1191414173 prevX = px;
....@@ -11942,6 +14201,7 @@
1194214201 else
1194314202 if (evt.getSource() == AAtimer)
1194414203 {
14204
+ Globals.TIMERRUNNING = false;
1194514205 if (mouseDown)
1194614206 {
1194714207 //new Exception().printStackTrace();
....@@ -11967,6 +14227,10 @@
1196714227 // LIVE = waslive;
1196814228 // wasliveok = true;
1196914229 // waslive = false;
14230
+
14231
+ // May 2019 Forget it:
14232
+ if (true)
14233
+ return;
1197014234
1197114235 // source == timer
1197214236 if (mouseDown)
....@@ -11996,8 +14260,8 @@
1199614260 // ObjEditor.tweenManager.update(1f / 60f);
1199714261
1199814262 // fev 2014???
11999
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12000
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14263
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14264
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1200114265 pingthread.StepToTarget(true); // true);
1200214266 }
1200314267 // if (!LIVE)
....@@ -12006,12 +14270,13 @@
1200614270
1200714271 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1200814272
12009
- void clickStart(int x, int y, int modifiers)
14273
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1201014274 {
1201114275 if (!wasliveok)
1201214276 return;
1201314277
1201414278 AAtimer.restart(); //
14279
+ Globals.TIMERRUNNING = true;
1201514280
1201614281 // waslive = LIVE;
1201714282 // LIVE = false;
....@@ -12023,7 +14288,7 @@
1202314288 // touched = true; // main DL
1202414289 if (isRenderer)
1202514290 {
12026
- SetMouseMode(modifiers);
14291
+ SetMouseMode(modifiers, modifiersex);
1202714292 }
1202814293
1202914294 selectX = anchorX = x;
....@@ -12036,7 +14301,7 @@
1203614301 clicked = true;
1203714302 hold = false;
1203814303
12039
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14304
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1204014305 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1204114306 {
1204214307 // System.out.println("RESTART II " + modifiers);
....@@ -12061,14 +14326,15 @@
1206114326 drag = false;
1206214327 //System.out.println("Mouse DOWN");
1206314328 editObj = false;
12064
- ClickInfo info = new ClickInfo();
12065
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12066
- info.pane = this;
12067
- info.camera = renderCamera;
12068
- info.x = x;
12069
- info.y = y;
12070
- info.modifiers = modifiers;
12071
- editObj = object.doEditClick(info, 0);
14329
+ //ClickInfo info = new ClickInfo();
14330
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14331
+ object.clickInfo.pane = this;
14332
+ object.clickInfo.camera = renderCamera;
14333
+ object.clickInfo.x = x;
14334
+ object.clickInfo.y = y;
14335
+ object.clickInfo.modifiers = modifiersex;
14336
+ editObj = object.doEditClick(//info,
14337
+ 0);
1207214338 if (!editObj)
1207314339 {
1207414340 hasMarquee = true;
....@@ -12084,11 +14350,14 @@
1208414350
1208514351 public void mouseDragged(MouseEvent e)
1208614352 {
14353
+ Globals.MOUSEDRAGGED = true;
14354
+
14355
+ //System.out.println("mouseDragged: " + e);
1208714356 if (isRenderer)
1208814357 movingcamera = true;
14358
+
1208914359 //if (drawing)
1209014360 //return;
12091
- //System.out.println("mouseDragged: " + e);
1209214361 if ((e.getModifiersEx() & CTRL) != 0
1209314362 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1209414363 {
....@@ -12096,7 +14365,7 @@
1209614365 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1209714366 }
1209814367 else
12099
- drag(e.getX(), e.getY(), e.getModifiersEx());
14368
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1210014369
1210114370 //try { Thread.sleep(1); } catch (Exception ex) {}
1210214371 }
....@@ -12108,6 +14377,11 @@
1210814377 cVector tmp = new cVector();
1210914378 cVector tmp2 = new cVector();
1211014379 boolean isMoving;
14380
+
14381
+ public cVector TargetLookAt()
14382
+ {
14383
+ return targetLookAt;
14384
+ }
1211114385
1211214386 class PingThread extends Thread
1211314387 {
....@@ -12247,7 +14521,7 @@
1224714521 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1224814522 if (lightMode)
1224914523 {
12250
- lighttouched = true;
14524
+ Globals.lighttouched = true;
1225114525 }
1225214526
1225314527 if (OEILONCE && OEIL)
....@@ -12264,6 +14538,7 @@
1226414538
1226514539 public void run()
1226614540 {
14541
+ new Exception().printStackTrace();
1226714542 System.exit(0);
1226814543 for (;;)
1226914544 {
....@@ -12305,7 +14580,7 @@
1230514580 mouseDown = false;
1230614581 if (lightMode)
1230714582 {
12308
- lighttouched = true;
14583
+ Globals.lighttouched = true;
1230914584 }
1231014585 repaint();
1231114586 alreadypainted = true;
....@@ -12313,7 +14588,7 @@
1231314588 isMoving = false;
1231414589 } //??
1231514590
12316
- if (isLIVE() && !alreadypainted)
14591
+ if (Globals.isLIVE() && !alreadypainted)
1231714592 {
1231814593 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1231914594 repaint();
....@@ -12325,9 +14600,9 @@
1232514600 {
1232614601 if (lightMode)
1232714602 {
12328
- lighttouched = true;
14603
+ Globals.lighttouched = true;
1232914604 }
12330
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14605
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1233114606 }
1233214607 //else
1233314608 }
....@@ -12341,12 +14616,12 @@
1234114616 void GoDown(int mod)
1234214617 {
1234314618 MODIFIERS |= COMMAND;
12344
- /*
14619
+ /**/
1234514620 if((mod&SHIFT) == SHIFT)
1234614621 manipCamera.RotatePosition(0, -speed);
1234714622 else
12348
- manipCamera.BackForth(0, -speed*delta, getWidth());
12349
- */
14623
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14624
+ /**/
1235014625 if ((mod & SHIFT) == SHIFT)
1235114626 {
1235214627 mouseMode = mouseMode; // VR??
....@@ -12362,12 +14637,12 @@
1236214637 void GoUp(int mod)
1236314638 {
1236414639 MODIFIERS |= COMMAND;
12365
- /*
14640
+ /**/
1236614641 if((mod&SHIFT) == SHIFT)
1236714642 manipCamera.RotatePosition(0, speed);
1236814643 else
12369
- manipCamera.BackForth(0, speed*delta, getWidth());
12370
- */
14644
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14645
+ /**/
1237114646 if ((mod & SHIFT) == SHIFT)
1237214647 {
1237314648 mouseMode = mouseMode;
....@@ -12383,12 +14658,12 @@
1238314658 void GoLeft(int mod)
1238414659 {
1238514660 MODIFIERS |= COMMAND;
12386
- /*
14661
+ /**/
1238714662 if((mod&SHIFT) == SHIFT)
12388
- manipCamera.RotatePosition(speed, 0);
12389
- else
1239014663 manipCamera.Translate(speed*delta, 0, getWidth());
12391
- */
14664
+ else
14665
+ manipCamera.RotatePosition(speed, 0);
14666
+ /**/
1239214667 if ((mod & SHIFT) == SHIFT)
1239314668 {
1239414669 mouseMode = mouseMode;
....@@ -12404,12 +14679,12 @@
1240414679 void GoRight(int mod)
1240514680 {
1240614681 MODIFIERS |= COMMAND;
12407
- /*
14682
+ /**/
1240814683 if((mod&SHIFT) == SHIFT)
12409
- manipCamera.RotatePosition(-speed, 0);
12410
- else
1241114684 manipCamera.Translate(-speed*delta, 0, getWidth());
12412
- */
14685
+ else
14686
+ manipCamera.RotatePosition(-speed, 0);
14687
+ /**/
1241314688 if ((mod & SHIFT) == SHIFT)
1241414689 {
1241514690 mouseMode = mouseMode;
....@@ -12427,7 +14702,7 @@
1242714702 int X, Y;
1242814703 boolean SX, SY;
1242914704
12430
- void drag(int x, int y, int modifiers)
14705
+ void drag(int x, int y, int modifiers, int modifiersex)
1243114706 {
1243214707 if (IsFrozen())
1243314708 {
....@@ -12436,17 +14711,17 @@
1243614711
1243714712 drag = true; // NEW
1243814713
12439
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14714
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1244014715
1244114716 X = x;
1244214717 Y = y;
1244314718 // floating state for animation
12444
- MODIFIERS = modifiers;
12445
- modifiers &= ~1024;
14719
+ MODIFIERS = modifiersex;
14720
+ modifiersex &= ~1024;
1244614721 if (false) // modifiers != 0)
1244714722 {
1244814723 //new Exception().printStackTrace();
12449
- System.out.println("mouseDragged: " + modifiers);
14724
+ System.out.println("mouseDragged: " + modifiersex);
1245014725 System.out.println("SHIFT = " + SHIFT);
1245114726 System.out.println("CONTROL = " + COMMAND);
1245214727 System.out.println("META = " + META);
....@@ -12459,14 +14734,16 @@
1245914734 if (editObj)
1246014735 {
1246114736 drag = true;
12462
- ClickInfo info = new ClickInfo();
12463
- info.bounds.setBounds(0, 0,
14737
+ //ClickInfo info = new ClickInfo();
14738
+ object.clickInfo.bounds.setBounds(0, 0,
1246414739 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12465
- info.pane = this;
12466
- info.camera = renderCamera;
12467
- info.x = x;
12468
- info.y = y;
12469
- object.editWindow.copy.doEditDrag(info);
14740
+ object.clickInfo.pane = this;
14741
+ object.clickInfo.camera = renderCamera;
14742
+ object.clickInfo.x = x;
14743
+ object.clickInfo.y = y;
14744
+ object //.GetWindow().copy
14745
+ .doEditDrag(//info,
14746
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1247014747 } else
1247114748 {
1247214749 if (x < startX)
....@@ -12568,6 +14845,7 @@
1256814845 {
1256914846 manipCamera.Translate(dx, dy, getWidth());
1257014847 }
14848
+ else
1257114849 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1257214850 {
1257314851 manipCamera.RotateInterest(dx, dy);
....@@ -12578,7 +14856,7 @@
1257814856
1257914857 if (manipCamera == lightCamera)
1258014858 {
12581
- lighttouched = true;
14859
+ Globals.lighttouched = true;
1258214860 }
1258314861 /*
1258414862 switch (mode)
....@@ -12614,23 +14892,27 @@
1261414892 }
1261514893 }
1261614894
14895
+// ClickInfo clickInfo = new ClickInfo();
14896
+
1261714897 public void mouseMoved(MouseEvent e)
1261814898 {
1261914899 //System.out.println("mouseMoved: " + e);
12620
-
1262114900 if (isRenderer)
1262214901 return;
1262314902
12624
- ClickInfo ci = new ClickInfo();
12625
- ci.x = e.getX();
12626
- ci.y = e.getY();
12627
- ci.modifiers = e.getModifiersEx();
12628
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12629
- ci.pane = this;
12630
- ci.camera = renderCamera;
14903
+ // Mouse cursor feedback
14904
+ object.clickInfo.x = e.getX();
14905
+ object.clickInfo.y = e.getY();
14906
+ object.clickInfo.modifiers = e.getModifiersEx();
14907
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14908
+ object.clickInfo.pane = this;
14909
+ object.clickInfo.camera = renderCamera;
1263114910 if (!isRenderer)
1263214911 {
12633
- if (object.editWindow.copy.doEditClick(ci, 0))
14912
+ //ObjEditor editWindow = object.editWindow;
14913
+ //Object3D copy = editWindow.copy;
14914
+ if (object.doEditClick(//clickInfo,
14915
+ 0))
1263414916 {
1263514917 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1263614918 } else
....@@ -12642,7 +14924,11 @@
1264214924
1264314925 public void mouseReleased(MouseEvent e)
1264414926 {
14927
+ Globals.MOUSEDRAGGED = false;
14928
+
1264514929 movingcamera = false;
14930
+ X = 0; // getBounds().width/2;
14931
+ Y = 0; // getBounds().height/2;
1264614932 //System.out.println("mouseReleased: " + e);
1264714933 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1264814934 }
....@@ -12665,9 +14951,9 @@
1266514951 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1266614952 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1266714953
12668
- if (control || command || IsFrozen())
14954
+// No delay if (control || command || IsFrozen())
1266914955 timeout = true;
12670
- else
14956
+// ?? May 2019 else
1267114957 // timer.setDelay((modifiers & 128) != 0?0:350);
1267214958 mouseDown = false;
1267314959 if (!control && !command) // june 2013
....@@ -12777,7 +15063,7 @@
1277715063 System.out.println("keyReleased: " + e);
1277815064 }
1277915065
12780
- void SetMouseMode(int modifiers)
15066
+ void SetMouseMode(int modifiers, int modifiersex)
1278115067 {
1278215068 //System.out.println("SetMouseMode = " + modifiers);
1278315069 //modifiers &= ~1024;
....@@ -12789,24 +15075,27 @@
1278915075 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1279015076 // return;
1279115077 //System.out.println("SetMode = " + modifiers);
12792
- if ((modifiers & WHEEL) == WHEEL)
15078
+ if ((modifiersex & WHEEL) == WHEEL)
1279315079 {
1279415080 mouseMode |= ZOOM;
1279515081 }
12796
- if ((modifiers & META) == META)
15082
+
15083
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15084
+ if (capsLocked) // || (modifiers & META) == META)
1279715085 {
1279815086 mouseMode |= VR; // BACKFORTH;
1279915087 }
12800
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12801
- {
12802
- mouseMode |= SELECT; // BACKFORTH;
12803
- }
12804
- if ((modifiers & COMMAND) == COMMAND)
15088
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1280515089 {
1280615090 mouseMode |= SELECT;
1280715091 }
12808
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15092
+ if ((modifiersex & COMMAND) == COMMAND)
1280915093 {
15094
+ mouseMode |= SELECT;
15095
+ }
15096
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15097
+ {
15098
+ mouseMode &= ~VR;
1281015099 mouseMode |= TRANSLATE;
1281115100 }
1281215101 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12833,10 +15122,10 @@
1283315122
1283415123 if (isRenderer) //
1283515124 {
12836
- SetMouseMode(modifiers);
15125
+ SetMouseMode(0, modifiers);
1283715126 }
1283815127
12839
- theRenderer.keyPressed(key);
15128
+ Globals.theRenderer.keyPressed(key);
1284015129 }
1284115130
1284215131 int kompactbit = 4; // power bit
....@@ -12848,7 +15137,7 @@
1284815137 float SATPOW = 1; // 2; // 0.5f;
1284915138 float BRIPOW = 1; // 0.5f; // 0.5f;
1285015139
12851
- void keyPressed(int key)
15140
+ public void keyPressed(int key)
1285215141 {
1285315142 if (key >= '0' && key <= '5')
1285415143 clampbit = (key-'0');
....@@ -12895,7 +15184,8 @@
1289515184 // break;
1289615185 case 'T':
1289715186 CACHETEXTURE ^= true;
12898
- textures.clear();
15187
+ texturepigment.clear();
15188
+ texturebump.clear();
1289915189 // repaint();
1290015190 break;
1290115191 case 'Y':
....@@ -12963,7 +15253,7 @@
1296315253 case 'B':
1296415254 BRISMOOTH ^= true;
1296515255 SHADOWCULLFACE ^= true;
12966
- lighttouched = true;
15256
+ Globals.lighttouched = true;
1296715257 repaint();
1296815258 break;
1296915259 case 'b':
....@@ -12980,7 +15270,9 @@
1298015270 case 'E' : COMPACT ^= true;
1298115271 repaint();
1298215272 break;
12983
- case 'W' : DEBUGHSB ^= true;
15273
+ case 'W' : // Wide Window (fullscreen)
15274
+ //DEBUGHSB ^= true;
15275
+ ObjEditor.theFrame.ToggleFullScreen();
1298415276 repaint();
1298515277 break;
1298615278 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13005,8 +15297,8 @@
1300515297 RevertCamera();
1300615298 repaint();
1300715299 break;
13008
- case 'L':
1300915300 case 'l':
15301
+ //case 'L':
1301015302 if (lightMode)
1301115303 {
1301215304 lightMode = false;
....@@ -13063,7 +15355,7 @@
1306315355 repaint();
1306415356 break;
1306515357 case 'O':
13066
- drawMode = OCCLUSION;
15358
+ Globals.drawMode = OCCLUSION; // WARNING
1306715359 repaint();
1306815360 break;
1306915361 case 'o':
....@@ -13076,14 +15368,18 @@
1307615368 case '3':
1307715369 case '4':
1307815370 case '5':
13079
- newenvy = Character.getNumericValue(key);
13080
- repaint();
13081
- break;
1308215371 case '6':
1308315372 case '7':
1308415373 case '8':
1308515374 case '9':
13086
- BGcolor = (key - '6')/3.f;
15375
+ if (envyoff)
15376
+ {
15377
+ BGcolor = (key - '1')/8.f;
15378
+ }
15379
+ else
15380
+ {
15381
+ //newenvy = Character.getNumericValue(key);
15382
+ }
1308715383 repaint();
1308815384 break;
1308915385 case '!':
....@@ -13149,12 +15445,12 @@
1314915445 case '_':
1315015446 kompactbit = 5;
1315115447 break;
13152
- case '+':
13153
- kompactbit = 6;
13154
- break;
15448
+// case '+':
15449
+// kompactbit = 6;
15450
+// break;
1315515451 case ' ':
1315615452 lightMode ^= true;
13157
- lighttouched = true;
15453
+ Globals.lighttouched = true;
1315815454 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1315915455 targetLookAt.set(manipCamera.lookAt);
1316015456 repaint();
....@@ -13163,14 +15459,15 @@
1316315459 case ESC:
1316415460 RENDERPROGRAM += 1;
1316515461 RENDERPROGRAM %= 3;
15462
+
1316615463 repaint();
1316715464 break;
1316815465 case 'Z':
13169
- RESIZETEXTURE ^= true;
13170
- break;
15466
+ //RESIZETEXTURE ^= true;
15467
+ //break;
1317115468 case 'z':
13172
- RENDERSHADOW ^= true;
13173
- lighttouched = true;
15469
+ Globals.RENDERSHADOW ^= true;
15470
+ Globals.lighttouched = true;
1317415471 repaint();
1317515472 break;
1317615473 //case UP:
....@@ -13196,13 +15493,15 @@
1319615493 FlipTransform();
1319715494 break;
1319815495 case ENTER:
13199
- object.editWindow.ScreenFit(); // Edit();
15496
+ // object.editWindow.ScreenFit(); // Edit();
15497
+ ToggleLive();
1320015498 break;
1320115499 case DELETE:
1320215500 ClearSelection();
1320315501 break;
13204
- /*
1320515502 case '+':
15503
+
15504
+ /*
1320615505 //fontsize += 1;
1320715506 bbzoom *= 2;
1320815507 repaint();
....@@ -13219,17 +15518,17 @@
1321915518 case '=':
1322015519 IncDepth();
1322115520 //fontsize += 1;
13222
- object.editWindow.refreshContents(true);
15521
+ object.GetWindow().refreshContents(true);
1322315522 maskbit = 6;
1322415523 break;
1322515524 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1322615525 DecDepth();
1322715526 maskbit = 5;
1322815527 //if(fontsize > 1) fontsize -= 1;
13229
- if (object.editWindow == null)
13230
- new Exception().printStackTrace();
13231
- else
13232
- object.editWindow.refreshContents(true);
15528
+// if (object.editWindow == null)
15529
+// new Exception().printStackTrace();
15530
+// else
15531
+ object.GetWindow().refreshContents(true);
1323315532 break;
1323415533 case '{':
1323515534 manipCamera.shaper_fovy /= 1.1;
....@@ -13284,6 +15583,7 @@
1328415583 }
1328515584 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1328615585 }
15586
+
1328715587 static double OCCLUSIONBOOST = 1; // 0.5;
1328815588
1328915589 void keyReleased(int key, int modifiers)
....@@ -13291,11 +15591,11 @@
1329115591 //mode = ROTATE;
1329215592 if ((MODIFIERS & COMMAND) == 0) // VR??
1329315593 {
13294
- SetMouseMode(modifiers);
15594
+ SetMouseMode(0, modifiers);
1329515595 }
1329615596 }
1329715597
13298
- protected void processKeyEvent(KeyEvent e)
15598
+ public void processKeyEvent(KeyEvent e)
1329915599 {
1330015600 switch (e.getID())
1330115601 {
....@@ -13425,8 +15725,9 @@
1342515725
1342615726 protected void processMouseMotionEvent(MouseEvent e)
1342715727 {
13428
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13429
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15728
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15729
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15730
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1343015731 {
1343115732 mouseMoved(e);
1343215733 } else
....@@ -13451,11 +15752,12 @@
1345115752 }
1345215753 */
1345315754
13454
- object.editWindow.EditSelection();
15755
+ object.GetWindow().EditSelection(false);
1345515756 }
1345615757
1345715758 void SelectParent()
1345815759 {
15760
+ new Exception().printStackTrace();
1345915761 System.exit(0);
1346015762 Composite group = (Composite) object;
1346115763 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13467,10 +15769,10 @@
1346715769 {
1346815770 //selectees.remove(i);
1346915771 System.out.println("select parent of " + elem);
13470
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15772
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1347115773 } else
1347215774 {
13473
- group.editWindow.Select(elem.GetTreePath(), first, true);
15775
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1347415776 }
1347515777
1347615778 first = false;
....@@ -13479,6 +15781,7 @@
1347915781
1348015782 void SelectChildren()
1348115783 {
15784
+ new Exception().printStackTrace();
1348215785 System.exit(0);
1348315786 /*
1348415787 Composite group = (Composite) object;
....@@ -13511,12 +15814,12 @@
1351115814 for (int j = 0; j < group.children.size(); j++)
1351215815 {
1351315816 elem = (Object3D) group.children.elementAt(j);
13514
- object.editWindow.Select(elem.GetTreePath(), first, true);
15817
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1351515818 first = false;
1351615819 }
1351715820 } else
1351815821 {
13519
- object.editWindow.Select(elem.GetTreePath(), first, true);
15822
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1352015823 }
1352115824
1352215825 first = false;
....@@ -13527,21 +15830,21 @@
1352715830 {
1352815831 //Composite group = (Composite) object;
1352915832 Object3D group = object;
13530
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15833
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1353115834 }
1353215835
1353315836 void ResetTransform(int mask)
1353415837 {
1353515838 //Composite group = (Composite) object;
1353615839 Object3D group = object;
13537
- group.editWindow.ResetTransform(mask);
15840
+ group.GetWindow().ResetTransform(mask);
1353815841 }
1353915842
1354015843 void FlipTransform()
1354115844 {
1354215845 //Composite group = (Composite) object;
1354315846 Object3D group = object;
13544
- group.editWindow.FlipTransform();
15847
+ group.GetWindow().FlipTransform();
1354515848 // group.editWindow.ReduceMesh(true);
1354615849 }
1354715850
....@@ -13549,7 +15852,7 @@
1354915852 {
1355015853 //Composite group = (Composite) object;
1355115854 Object3D group = object;
13552
- group.editWindow.PrintMemory();
15855
+ group.GetWindow().PrintMemory();
1355315856 // group.editWindow.ReduceMesh(true);
1355415857 }
1355515858
....@@ -13557,7 +15860,7 @@
1355715860 {
1355815861 //Composite group = (Composite) object;
1355915862 Object3D group = object;
13560
- group.editWindow.ResetCentroid();
15863
+ group.GetWindow().ResetCentroid();
1356115864 }
1356215865
1356315866 void IncDepth()
....@@ -13639,11 +15942,11 @@
1363915942
1364015943 int width = getBounds().width;
1364115944 int height = getBounds().height;
13642
- ClickInfo info = new ClickInfo();
13643
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1364415945 //Image img = CreateImage(width, height);
1364515946 //System.out.println("width = " + width + "; height = " + height + "\n");
15947
+
1364615948 Graphics gr = g; // img.getGraphics();
15949
+
1364715950 if (!hasMarquee)
1364815951 {
1364915952 if (Xmin < Xmax) // !locked)
....@@ -13715,40 +16018,88 @@
1371516018 }
1371616019 if (object != null && !hasMarquee)
1371716020 {
16021
+ if (object.clickInfo == null)
16022
+ object.clickInfo = new ClickInfo();
16023
+ ClickInfo info = object.clickInfo;
16024
+ //ClickInfo info = new ClickInfo();
16025
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16026
+
1371816027 if (isRenderer)
1371916028 {
13720
- info.flags++;
16029
+ object.clickInfo.flags++;
1372116030 double frameAspect = (double) width / (double) height;
1372216031 if (frameAspect > renderCamera.aspect)
1372316032 {
1372416033 int desired = (int) ((double) height * renderCamera.aspect);
13725
- info.bounds.width -= width - desired;
13726
- info.bounds.x += (width - desired) / 2;
16034
+ object.clickInfo.bounds.width -= width - desired;
16035
+ object.clickInfo.bounds.x += (width - desired) / 2;
1372716036 } else
1372816037 {
1372916038 int desired = (int) ((double) width / renderCamera.aspect);
13730
- info.bounds.height -= height - desired;
13731
- info.bounds.y += (height - desired) / 2;
16039
+ object.clickInfo.bounds.height -= height - desired;
16040
+ object.clickInfo.bounds.y += (height - desired) / 2;
1373216041 }
1373316042 }
13734
- info.g = gr;
13735
- info.camera = renderCamera;
16043
+
16044
+ object.clickInfo.g = gr;
16045
+ object.clickInfo.camera = renderCamera;
1373616046 /*
1373716047 // Memory intensive (brep.verticescopy)
1373816048 if (!(object instanceof Composite))
1373916049 object.draw(info, 0, false); // SLOW :
1374016050 */
13741
- if (!isRenderer)
16051
+ if (!isRenderer) // && drag)
1374216052 {
13743
- object.drawEditHandles(info, 0);
16053
+ Grafreed.Assert(object != null);
16054
+ Grafreed.Assert(object.selection != null);
16055
+ if (object.selection.Size() > 0)
16056
+ {
16057
+ int hitSomething = object.selection.get(0).hitSomething;
16058
+
16059
+ object.clickInfo.DX = 0;
16060
+ object.clickInfo.DY = 0;
16061
+ object.clickInfo.W = 1;
16062
+ if (hitSomething == Object3D.hitCenter)
16063
+ {
16064
+ info.DX = X;
16065
+ if (X != 0)
16066
+ info.DX -= info.bounds.width/2;
16067
+
16068
+ info.DY = Y;
16069
+ if (Y != 0)
16070
+ info.DY -= info.bounds.height/2;
16071
+ }
16072
+
16073
+ object.drawEditHandles(//info,
16074
+ 0);
16075
+
16076
+ if (drag && (X != 0 || Y != 0))
16077
+ {
16078
+ switch (hitSomething)
16079
+ {
16080
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16081
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16082
+ break;
16083
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16084
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16085
+ break;
16086
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16087
+ gr.drawLine(X, Y, 0, 0);
16088
+ break;
16089
+ }
16090
+
16091
+ }
16092
+ }
1374416093 }
1374516094 }
16095
+
1374616096 if (isRenderer)
1374716097 {
1374816098 //gr.setColor(Color.black);
1374916099 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1375016100 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1375116101 }
16102
+
1375216103 if (hasMarquee)
1375316104 {
1375416105 gr.setXORMode(Color.white);
....@@ -13771,6 +16122,7 @@
1377116122 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1377216123 }
1377316124
16125
+ // To avoid clear.
1377416126 public void update(Graphics g)
1377516127 {
1377616128 paint(g);
....@@ -13860,6 +16212,7 @@
1386016212 public boolean mouseDown(Event evt, int x, int y)
1386116213 {
1386216214 System.out.println("mouseDown: " + evt);
16215
+ System.exit(0);
1386316216 /*
1386416217 locked = true;
1386516218 drag = false;
....@@ -13903,7 +16256,7 @@
1390316256 {
1390416257 keyPressed(0, modifiers);
1390516258 }
13906
- clickStart(x, y, modifiers);
16259
+ // clickStart(x, y, modifiers);
1390716260 return true;
1390816261 }
1390916262
....@@ -14021,7 +16374,7 @@
1402116374 {
1402216375 keyReleased(0, 0);
1402316376 }
14024
- drag(x, y, modifiers);
16377
+ drag(x, y, 0, modifiers);
1402516378 return true;
1402616379 }
1402716380
....@@ -14153,7 +16506,7 @@
1415316506 Object3D object;
1415416507 static Object3D trackedobject;
1415516508 Camera renderCamera; // Light or Eye (or Occlusion)
14156
- /*static*/ Camera manipCamera; // Light or Eye
16509
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1415716510 /*static*/ Camera eyeCamera;
1415816511 /*static*/ Camera lightCamera;
1415916512 int cameracount;
....@@ -14249,7 +16602,9 @@
1424916602
1425016603 float BGcolor = 0.5f;
1425116604
14252
- private void DrawSkyBox(GL gl)
16605
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16606
+
16607
+ private void DrawSkyBox(GL gl, float ratio)
1425316608 {
1425416609 if (envyoff || cubemap == null)
1425516610 {
....@@ -14266,7 +16621,17 @@
1426616621 // Compensates for ExaminerViewer's modification of modelview matrix
1426716622 gl.glMatrixMode(GL.GL_MODELVIEW);
1426816623 gl.glLoadIdentity();
16624
+ gl.glScalef(1,ratio,1);
1426916625
16626
+ colorV[0] = 2;
16627
+ colorV[1] = 2;
16628
+ colorV[2] = 2;
16629
+ colorV[3] = 1;
16630
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16631
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16632
+
16633
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16634
+
1427016635 //gl.glActiveTexture(GL.GL_TEXTURE1);
1427116636 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1427216637
....@@ -14279,7 +16644,7 @@
1427916644 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1428016645 // causes the normals to be sent down. Thanks to Ken Dyke.
1428116646 //gl.glEnable(GL.GL_LIGHTING);
14282
- gl.glDisable(GL.GL_LIGHTING);
16647
+ gl.glEnable(GL.GL_LIGHTING);
1428316648
1428416649 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1428516650 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -14373,7 +16738,7 @@
1437316738 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1437416739 gl.glPushMatrix();
1437516740 gl.glLoadIdentity();
14376
- PushMatrix(checker.toParent);
16741
+ //PushMatrix(checker.toParent);
1437716742
1437816743 gl.glMatrixMode(GL.GL_TEXTURE);
1437916744 gl.glPushMatrix();
....@@ -14396,8 +16761,8 @@
1439616761
1439716762 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1439816763
14399
- float step = 0.1666f; //0.25f;
14400
- float stepv = step * 1652 / 998;
16764
+ float step = 2; // 0.1666f; //0.25f;
16765
+ float stepv = 2; // step * 1652 / 998;
1440116766
1440216767 int i0 = 0;
1440316768 /*
....@@ -14433,20 +16798,21 @@
1443316798 /**/
1443416799 //checker.GetMaterial().opacity = 1.1f;
1443516800 ////checker.GetMaterial().ambient = 0.99f;
14436
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14437
- Object3D.selectedstack[Object3D.materialdepth] = false;
14438
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16801
+ materialstack[materialdepth] = checker.material;
16802
+ selectedstack[materialdepth] = false;
16803
+ cStatic.objectstack[materialdepth++] = checker;
1443916804 //System.out.println("material " + material);
1444016805 //Applet3D.tracein(this, selected);
14441
- vector2buffer = checker.projectedVertices;
16806
+ //vector2buffer = checker.projectedVertices;
1444216807
14443
- checker.GetMaterial().Draw(this, false); // true);
16808
+ //checker.GetMaterial().Draw(this, false); // true);
16809
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1444416810
14445
- Object3D.materialdepth -= 1;
14446
- if (Object3D.materialdepth > 0)
16811
+ materialdepth -= 1;
16812
+ if (materialdepth > 0)
1444716813 {
14448
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14449
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16814
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16815
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1445016816 }
1445116817 //checker.GetMaterial().opacity = 1f;
1445216818 ////checker.GetMaterial().ambient = 1f;
....@@ -14467,15 +16833,27 @@
1446716833
1446816834 //float u = (i+1)/2;
1446916835 //float v = (j+1)/2;
14470
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16836
+ if (checker.flipV)
16837
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16838
+ else
16839
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1447116840 gl.glVertex3f(i, j, -0.5f);
1447216841
16842
+ if (checker.flipV)
16843
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16844
+ else
1447316845 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1447416846 gl.glVertex3f(i + step, j, -0.5f);
1447516847
16848
+ if (checker.flipV)
16849
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16850
+ else
1447616851 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1447716852 gl.glVertex3f(i + step, j + stepv, -0.5f);
1447816853
16854
+ if (checker.flipV)
16855
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16856
+ else
1447916857 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1448016858 gl.glVertex3f(i, j + stepv, -0.5f);
1448116859 }
....@@ -14487,7 +16865,7 @@
1448716865 gl.glMatrixMode(GL.GL_PROJECTION);
1448816866 gl.glPopMatrix();
1448916867 gl.glMatrixMode(GL.GL_MODELVIEW);
14490
- PopMatrix(null); // checker.toParent); // null);
16868
+ //PopMatrix(null); // checker.toParent); // null);
1449116869 gl.glPopMatrix();
1449216870 PopTextureMatrix(checker.toParent);
1449316871 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14520,6 +16898,14 @@
1452016898 }
1452116899 }
1452216900
16901
+ private Object3D GetFolder()
16902
+ {
16903
+ Object3D folder = object.GetWindow().copy;
16904
+ if (object.GetWindow().copy.selection.Size() > 0)
16905
+ folder = object.GetWindow().copy.selection.elementAt(0);
16906
+ return folder;
16907
+ }
16908
+
1452316909 class SelectBuffer implements GLEventListener
1452416910 {
1452516911
....@@ -14535,7 +16921,7 @@
1453516921 //new Exception().printStackTrace();
1453616922 System.out.println("select buffer init");
1453716923 // Use debug pipeline
14538
- drawable.setGL(new DebugGL(drawable.getGL()));
16924
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1453916925
1454016926 GL gl = drawable.getGL();
1454116927
....@@ -14578,6 +16964,7 @@
1457816964 {
1457916965 if (!selection)
1458016966 {
16967
+ new Exception().printStackTrace();
1458116968 System.exit(0);
1458216969 return;
1458316970 }
....@@ -14598,17 +16985,39 @@
1459816985
1459916986 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1460016987
16988
+ if (PAINTMODE)
16989
+ {
16990
+ if (object.GetWindow().copy.selection.Size() > 0)
16991
+ {
16992
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16993
+
16994
+ // Make what you paint not selectable.
16995
+ paintobj.ResetSelectable();
16996
+ }
16997
+ }
16998
+
1460116999 //int tmp = selection_view;
1460217000 //selection_view = -1;
14603
- int temp = drawMode;
14604
- drawMode = SELECTION;
17001
+ int temp = DrawMode();
17002
+ Globals.drawMode = SELECTION; // WARNING
1460517003 indexcount = 0;
1460617004 parent.display(drawable);
1460717005 //selection_view = tmp;
1460817006 //if (temp == SELECTION)
1460917007 // temp = DEFAULT; // patch for selection debug
14610
- drawMode = temp;
17008
+ Globals.drawMode = temp; // WARNING
1461117009
17010
+ if (PAINTMODE)
17011
+ {
17012
+ if (object.GetWindow().copy.selection.Size() > 0)
17013
+ {
17014
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17015
+
17016
+ // Revert.
17017
+ paintobj.RestoreSelectable();
17018
+ }
17019
+ }
17020
+
1461217021 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1461317022
1461417023 // trying different ways of getting the depth info over
....@@ -14657,6 +17066,13 @@
1465717066 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1465817067 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1465917068
17069
+ CreateSelectedPoint();
17070
+
17071
+ // Will fit the mesh !!!
17072
+ selectedpoint.toParent[0][0] = 0.0001;
17073
+ selectedpoint.toParent[1][1] = 0.0001;
17074
+ selectedpoint.toParent[2][2] = 0.0001;
17075
+
1466017076 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1466117077
1466217078 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14700,34 +17116,36 @@
1470017116 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]));
1470117117 }
1470217118
14703
- previousselectedpoint = (Sphere) GraphreeD.clone(selectedpoint);
17119
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1470417120 }
1470517121 }
1470617122
1470717123 if (!movingcamera && !PAINTMODE)
14708
- object.editWindow.ScreenFitPoint(); // fev 2014
17124
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1470917125
14710
- if (PAINTMODE && GraphreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17126
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1471117127 {
14712
- Object3D paintobj = GraphreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17128
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1471317129
14714
- Object3D group = new Object3D("inst" + paintcount++);
17130
+ if (object.GetWindow().copy.selection.Size() > 0)
17131
+ {
17132
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1471517133
14716
- group.CreateMaterial(); // use a void leaf to select instances
14717
-
14718
- group.add(paintobj); // link
14719
-
14720
- object.editWindow.SnapObject(group);
14721
-
14722
- Object3D folder = object.editWindow.copy;
14723
-
14724
- if (object.editWindow.copy.selection.Size() > 0)
14725
- folder = object.editWindow.copy.selection.elementAt(0);
14726
-
14727
- folder.add(group);
14728
-
14729
- object.editWindow.ResetModel();
14730
- object.editWindow.refreshContents();
17134
+ Object3D inst = new Object3D("inst" + paintcount++);
17135
+
17136
+ inst.CreateMaterial(); // use a void leaf to select instances
17137
+
17138
+ inst.add(paintobj); // link
17139
+
17140
+ object.GetWindow().SnapObject(inst);
17141
+
17142
+ Object3D folder = paintFolder; // GetFolder();
17143
+
17144
+ folder.add(inst);
17145
+
17146
+ object.GetWindow().ResetModel();
17147
+ object.GetWindow().refreshContents();
17148
+ }
1473117149 }
1473217150 else
1473317151 paintcount = 0;
....@@ -14766,6 +17184,11 @@
1476617184 //System.out.println("objects[color] = " + objects[color]);
1476717185 //objects[color].Select();
1476817186 indexcount = 0;
17187
+ ObjEditor window = object.GetWindow();
17188
+ if (window != null && deselect)
17189
+ {
17190
+ window.Select(null, deselect, true);
17191
+ }
1476917192 object.Select(color, deselect);
1477017193 }
1477117194
....@@ -14865,7 +17288,7 @@
1486517288 gl.glDisable(gl.GL_CULL_FACE);
1486617289 }
1486717290
14868
- if (!RENDERSHADOW)
17291
+ if (!Globals.RENDERSHADOW)
1486917292 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1487017293
1487117294 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14875,14 +17298,14 @@
1487517298 //gl.glColorMask(false, false, false, false);
1487617299
1487717300 //render_scene_from_light_view(gl, drawable, 0, 0);
14878
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17301
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1487917302 {
1488017303 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1488117304
14882
- int temp = drawMode;
14883
- drawMode = SHADOW;
17305
+ int temp = DrawMode();
17306
+ Globals.drawMode = SHADOW; // WARNING
1488417307 parent.display(drawable);
14885
- drawMode = temp;
17308
+ Globals.drawMode = temp; // WARNING
1488617309 }
1488717310
1488817311 gl.glCullFace(gl.GL_BACK);
....@@ -14935,7 +17358,6 @@
1493517358
1493617359 class AntialiasBuffer implements GLEventListener
1493717360 {
14938
-
1493917361 CameraPane parent = null;
1494017362
1494117363 AntialiasBuffer(CameraPane p)
....@@ -15045,13 +17467,19 @@
1504517467 gl.glFlush();
1504617468
1504717469 /**/
15048
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17470
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
1504917471
15050
- int[] pixels = occlusionsizebuffer.array();
17472
+ float[] pixels = occlusionsizebuffer.array();
1505117473
1505217474 double r = 0, g = 0, b = 0;
1505317475
1505417476 double count = 0;
17477
+
17478
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17479
+
17480
+ float mindepth = 1;
17481
+
17482
+ double FACTOR = 1;
1505517483
1505617484 for (int i = 0; i < pixels.length; i++)
1505717485 {
....@@ -15136,7 +17564,7 @@
1513617564
1513717565 double scale = ray.z; // 1; // cos
1513817566
15139
- int p = pixels[newindex];
17567
+ float depth = pixels[newindex];
1514017568
1514117569 /*
1514217570 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15160,10 +17588,23 @@
1516017588 scale = (1 - modu) * modv;
1516117589 */
1516217590
15163
- r += ((p >> 16) & 0xFF) * scale / 255;
15164
- g += ((p >> 8) & 0xFF) * scale / 255;
15165
- b += (p & 0xFF) * scale / 255;
17591
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17592
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17593
+ //b += (p & 0xFF) * scale / 255;
17594
+
17595
+ if (mindepth > depth)
17596
+ {
17597
+ mindepth = depth;
17598
+ }
1516617599
17600
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17601
+
17602
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17603
+
17604
+ r += factor * scale;
17605
+ g += factor * scale;
17606
+ b += factor * scale;
17607
+
1516717608 count += scale;
1516817609 }
1516917610
....@@ -15261,12 +17702,6 @@
1526117702 GLUT glut = new GLUT();
1526217703
1526317704
15264
- static final public int DEFAULT = 0;
15265
- static final public int SELECTION = 1;
15266
- static final public int SHADOW = 2;
15267
- static final public int OCCLUSION = 3;
15268
- static
15269
- public int drawMode = DEFAULT;
1527017705 public boolean spherical = false;
1527117706 static boolean DEBUG_OCCLUSION = false;
1527217707 static boolean DEBUG_SELECTION = false;
....@@ -15279,21 +17714,15 @@
1527917714 int AAbuffersize = 0;
1528017715
1528117716 //double[] selectedpoint = new double[3];
15282
- static Sphere selectedpoint = new Sphere();
17717
+ static Superellipsoid selectedpoint;
1528317718 static Sphere previousselectedpoint = null;
15284
- static Sphere debugpoint = new Sphere();
15285
- static Sphere debugpoint2 = new Sphere();
17719
+ static Sphere debugpointG;
17720
+ static Sphere debugpointP;
17721
+ static Sphere debugpointC;
17722
+ static Sphere debugpointR;
1528617723
1528717724 static Sphere debugpoints[] = new Sphere[8];
1528817725
15289
- static
15290
- {
15291
- for (int i=0; i<8; i++)
15292
- {
15293
- debugpoints[i] = new Sphere();
15294
- }
15295
- }
15296
-
1529717726 static void InitPoints(float radius)
1529817727 {
1529917728 for (int i=0; i<8; i++)
....@@ -15313,7 +17742,7 @@
1531317742 }
1531417743 }
1531517744
15316
- static void DrawPoints(CameraPane cpane)
17745
+ static void DrawPoints(iCameraPane cpane)
1531717746 {
1531817747 for (int i=0; i<8; i++) // first and last are red
1531917748 {
....@@ -15335,7 +17764,8 @@
1533517764 static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1533617765 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1533717766 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15338
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17767
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17768
+ static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
1533917769 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1534017770 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1534117771 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15344,10 +17774,11 @@
1534417774 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1534517775 // Depth buffer format
1534617776 //private int depth_format;
15347
- static public void NextIndex(Object3D o, GL gl)
17777
+
17778
+ public void NextIndex()
1534817779 {
1534917780 indexcount+=16;
15350
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17781
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1535117782 //objects[indexcount] = o;
1535217783 //System.out.println("indexcount = " + indexcount);
1535317784 }