Normand Briere
2019-08-12 b1d79b74514041a059b454a9f6fc3970773c0cb8
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,39 +2450,59 @@
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 {
7702476 com.sun.opengl.util.texture.Texture texture;
2477
+ com.sun.opengl.util.texture.TextureData texturedata;
2478
+
7712479 int resolution;
7722480
773
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7742482 {
775
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
7762485 resolution = res;
7772486 }
7782487 }
7792488 /**/
7802489
7812490 // TEXTURE static Texture texture;
782
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
783
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
784
- 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
+
7852496 int pigmentdepth = 0;
7862497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7872498 int bumpdepth = 0;
7882499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7892500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7902501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
791
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7922503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7932504
794
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7952506 {
7962507 TextureData texturedata = null;
7972508
....@@ -810,13 +2521,34 @@
8102521 if (bump)
8112522 texturedata = ConvertBump(texturedata, false);
8122523
813
- com.sun.opengl.util.texture.Texture texture =
814
- 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);
8152526
816
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
817
- 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);
8182529
819
- 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;
8202552 }
8212553
8222554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1889,6 +3621,8 @@
18893621
18903622 System.out.println("LOADING TEXTURE : " + name);
18913623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
18923626 //
18933627 if (false) // compressbit > 0)
18943628 {
....@@ -1998,10 +3732,12 @@
19983732 */
19993733 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20003734 {
3735
+ int pixelformat = texturedata.getPixelFormat();
3736
+
20013737 int stride = 1;
2002
- 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)
20033739 stride = 3;
2004
- 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)
20053741 stride = 4;
20063742
20073743 int width = texturedata.getWidth();
....@@ -2591,6 +4327,7 @@
25914327
25924328 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25934329 {
4330
+ new Exception().printStackTrace();
25944331 System.exit(0);
25954332 com.sun.opengl.util.texture.Texture texture = null;
25964333
....@@ -6267,7 +8004,7 @@
62678004 return null;
62688005 }
62698006
6270
- void ReleaseTextures(cTexture tex)
8007
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62718008 {
62728009 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62738010 {
....@@ -6284,7 +8021,7 @@
62848021 String pigment = Object3D.GetPigment(tex);
62858022 String bump = Object3D.GetBump(tex);
62868023
6287
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62888025 {
62898026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62908027 // System.out.println("; bump = " + bump);
....@@ -6299,13 +8036,71 @@
62998036 pigment = null;
63008037 }
63018038
6302
- ReleaseTexture(bump, true);
6303
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
63048041 }
63058042
6306
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63078044 {
6308
- 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 ||*/
63098104 ambientOcclusion ) // || !textureon)
63108105 {
63118106 return;
....@@ -6314,7 +8109,7 @@
63148109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63158110
63168111 if (tex != null)
6317
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63188113
63198114 // //assert( texture != null );
63208115 // if (texture == null)
....@@ -6331,7 +8126,7 @@
63318126 {
63328127 bumpdepth--;
63338128
6334
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8129
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63358130 if (bumpstack[bumpdepth] != (texture!=null?texture.texture:null))
63368131 {
63378132 // assert (bumpstack[bumpdepth] == texture);
....@@ -6361,7 +8156,7 @@
63618156 {
63628157 pigmentdepth--;
63638158
6364
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8159
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63658160 if (pigmentstack[pigmentdepth] != (texture!=null?texture.texture:null))
63668161 {
63678162 // assert (pigmentstack[pigmentdepth] == texture);
....@@ -6406,9 +8201,57 @@
64068201 }
64078202 }
64088203
6409
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8204
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64108205 {
6411
- 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 ||*/
64128255 ambientOcclusion ) // || !textureon)
64138256 {
64148257 return; // false;
....@@ -6417,17 +8260,47 @@
64178260 if (tex == null)
64188261 {
64198262 BindTexture(null,false,resolution);
6420
- BindTexture(null,true,resolution);
64218263 return;
64228264 }
64238265
64248266 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
+
64258299 String bump = Object3D.GetBump(tex);
64268300
6427
- usedtextures.put(pigment, pigment);
6428
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
64298302
6430
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64318304 {
64328305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64338306 // System.out.println("; bump = " + bump);
....@@ -6437,43 +8310,94 @@
64378310 {
64388311 bump = null;
64398312 }
6440
- if (pigment.equals(""))
6441
- {
6442
- pigment = null;
6443
- }
64448313
6445
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6446
- BindTexture(pigment, false, resolution);
64478314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6448
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
64498316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
-
6451
- return; // true;
64528317 }
64538318
6454
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
64558322 {
6456
- 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;
64578342
64588343 if (tex != null)
64598344 {
6460
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64618347
6462
- String[] split = tex.split("Textures");
6463
- if (split.length > 1)
6464
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6465
- else
6466
- if (!texname.startsWith("/"))
6467
- 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) && !texname.startsWith("@"))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
64688365
64698366 if (CACHETEXTURE)
6470
- texture = textures.get(texname); // TEXTURE CACHE
6471
-
6472
- TextureData texturedata = null;
6473
-
6474
- if (texture == null || texture.resolution < resolution)
64758367 {
6476
- 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(""))
64778401 {
64788402 assert(!bump);
64798403 // if (bump)
....@@ -6484,19 +8408,23 @@
64848408 // }
64858409 // else
64868410 // {
6487
- texture = textures.get(tex);
6488
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
64898413 {
6490
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64918415 }
8416
+ else
8417
+ new Exception().printStackTrace();
64928418 // }
64938419 } else
6494
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64958421 {
64968422 assert(bump);
6497
- texture = textures.get(tex);
6498
- if (texture == null)
6499
- 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();
65008428 } else
65018429 {
65028430 //if (tex.equals("IMMORTAL"))
....@@ -6504,11 +8432,22 @@
65048432 // texture = GetResourceTexture("default.png");
65058433 //} else
65068434 //{
6507
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
65088436 {
6509
- texture = textures.get(tex);
6510
- if (texture == null)
6511
- 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();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
65128451 } else
65138452 {
65148453 if (textureon)
....@@ -6533,7 +8472,7 @@
65338472 }
65348473
65358474 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6536
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
65378476 cachename = texname;
65388477 else
65398478 processbump = false; // don't process bump map again
....@@ -6555,7 +8494,7 @@
65558494 }
65568495
65578496 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6558
- if (!new File(cachename).exists())
8497
+ if (!FileExists(cachename))
65598498 cachename = texname;
65608499 else
65618500 processbump = false; // don't process bump map again
....@@ -6564,20 +8503,23 @@
65648503 texturedata = GetFileTexture(cachename, processbump, resolution);
65658504
65668505
6567
- if (texturedata != null)
6568
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8506
+ if (texturedata == null)
8507
+ throw new Exception();
8508
+
8509
+ texturecache = new CacheTexture(texturedata,resolution);
65698510 //texture = GetTexture(tex, bump);
65708511 }
8512
+ }
65718513 }
65728514 //}
65738515 }
65748516
6575
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65768518 {
65778519 //return false;
65788520
65798521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6580
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65818523 {
65828524 // String ext = "_highres";
65838525 // if (REDUCETEXTURE)
....@@ -6594,52 +8536,17 @@
65948536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65958537 if (!cachefile.exists())
65968538 {
6597
- // cache to disk
6598
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6599
- //buffers[0].
6600
-
6601
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6602
- int[] pixels = new int[bytebuf.capacity()/3];
6603
-
6604
- // squared size heuristic...
6605
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
66068540 {
6607
- for (int i=pixels.length; --i>=0;)
6608
- {
6609
- int i3 = i*3;
6610
- pixels[i] = 0xFF;
6611
- pixels[i] <<= 8;
6612
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6613
- pixels[i] <<= 8;
6614
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6617
- }
6618
-
6619
- /*
6620
- int r=0,g=0,b=0,a=0;
6621
- for (int i=0; i<width; i++)
6622
- for (int j=0; j<height; j++)
6623
- {
6624
- int index = j*width+i;
6625
- int p = pixels[index];
6626
- a = ((p>>24) & 0xFF);
6627
- r = ((p>>16) & 0xFF);
6628
- g = ((p>>8) & 0xFF);
6629
- b = (p & 0xFF);
6630
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6631
- }
6632
- /**/
6633
- int width = (int)Math.sqrt(pixels.length); // squared
6634
- int height = width;
6635
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6636
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
66378543 ImageWriter writer = null;
66388544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66398545 if (iter.hasNext()) {
66408546 writer = (ImageWriter)iter.next();
66418547 }
6642
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
66438550 try
66448551 {
66458552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6656,16 +8563,20 @@
66568563 }
66578564 }
66588565 }
6659
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
66608569 //System.out.println("Texture = " + tex);
6661
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
66628571 {
6663
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
66648573 thetex.texture.disable();
66658574 thetex.texture.dispose();
6666
- textures.remove(texname);
8575
+ textures.remove(tex);
66678576 }
6668
- textures.put(texname, texture);
8577
+
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
66698580
66708581 // newtex = true;
66718582 }
....@@ -6681,28 +8592,76 @@
66818592 }
66828593 }
66838594
8595
+ return texturecache;
8596
+ }
8597
+
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
8633
+ {
8634
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8635
+
66848636 if (bump)
66858637 {
6686
- // GraphreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
8638
+ // GrafreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
66878639 bumpstack[bumpdepth++] = texture!=null?texture.texture:null;
66888640 }
66898641 else
66908642 {
6691
- // GraphreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
8643
+ // GrafreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
66928644 pigmentstack[pigmentdepth++] = texture!=null?texture.texture:null;
66938645 }
66948646
66958647 return texture!=null?texture.texture:null;
66968648 }
66978649
6698
- boolean BindTexture(String tex, boolean bump, int resolution)
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
8651
+ {
8652
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8653
+
8654
+ return texture!=null?texture.texturedata:null;
8655
+ }
8656
+
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
66998658 {
67008659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67018660 {
67028661 return false;
67038662 }
67048663
6705
- boolean newtex = false;
8664
+ //boolean newtex = false;
67068665
67078666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67088667
....@@ -6734,9 +8693,75 @@
67348693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67358694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67368695
6737
- return newtex;
8696
+ return true; // Warning: not used.
67388697 }
67398698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
67408765 ShadowBuffer shadowPBuf;
67418766 AntialiasBuffer antialiasPBuf;
67428767 int MAXSTACK;
....@@ -6929,7 +8954,7 @@
69298954
69308955 if (cubemap == null)
69318956 {
6932
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
69338958 }
69348959
69358960 //cubemap.enable();
....@@ -7216,37 +9241,58 @@
72169241 cubemap = null;
72179242 return;
72189243 case 1:
7219
- name = "cubemaps/box_";
7220
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
72219246 reverseUP = false;
72229247 break;
72239248 case 2:
7224
- name = "cubemaps/uffizi_";
7225
- ext = "png";
7226
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
72279253 case 3:
7228
- name = "cubemaps/CloudyHills_";
7229
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
72309256 reverseUP = false;
72319257 break;
72329258 case 4:
7233
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
72349260 ext = "png";
72359261 reverseUP = false;
72369262 break;
9263
+ case 5:
9264
+ name = "cubemaps/skycube/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 6:
9269
+ name = "cubemaps/SaintLazarusChurch3/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 7:
9274
+ name = "cubemaps/Sodermalmsallen/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 8:
9279
+ name = "cubemaps/Sodermalmsallen2/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 9:
9284
+ name = "cubemaps/UnionSquare/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
72379288 default:
7238
- name = "cubemaps/rgb_";
7239
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
72409292 break;
72419293 }
7242
-
7243
- try
7244
- {
7245
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7246
- } catch (IOException e)
7247
- {
7248
- throw new RuntimeException(e);
7249
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
72509296 }
72519297
72529298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7278,8 +9324,12 @@
72789324 static double[] model = new double[16];
72799325 double[] camera2light = new double[16];
72809326 double[] light2camera = new double[16];
7281
- int newenvy = -1;
7282
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
72839333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
72849334 //float[] light0 = { 0,0,0 };
72859335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7292,9 +9342,9 @@
72929342 static boolean occlusionInitialized = false;
72939343 boolean selection = false;
72949344 boolean pointselection = false;
7295
- /*static*/ boolean lighttouched = true;
9345
+ ///*static*/ boolean lighttouched = true;
72969346 boolean deselect;
7297
- boolean ambientOcclusion = false;
9347
+ private boolean ambientOcclusion = false;
72989348 static boolean flash = false;
72999349 /*static*/ boolean wait = false;
73009350 boolean displaydone = false; // after repaint() calls
....@@ -7424,6 +9474,8 @@
74249474 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74259475 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74269476 double scale = lightCamera.SCALE / lightCamera.Distance();
9477
+// PATCH FILLE AUX JEANS
9478
+ //scale *= lightCamera.shaper_fovy / 25;
74279479 gl.glScaled(2 * scale, 2 * scale, -scale);
74289480 gl.glTranslated(0, 0, lightCamera.DECAL);
74299481
....@@ -7570,17 +9622,40 @@
75709622 jy8[3] = 0.5f;
75719623 }
75729624
7573
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9625
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75749626 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
7575
- float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
9627
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9628
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75769629
9630
+ void ResetOptions()
9631
+ {
9632
+ options1[0] = 100;
9633
+ options1[1] = 0.025f;
9634
+ options1[2] = 0.01f;
9635
+ options1[3] = 0;
9636
+ options1[4] = 0;
9637
+
9638
+ options2[0] = 0;
9639
+ options2[1] = 0.75f;
9640
+ options2[2] = 0;
9641
+ options2[3] = 0;
9642
+
9643
+ options3[0] = 1;
9644
+ options3[1] = 1;
9645
+ options3[2] = 1;
9646
+ options3[3] = 0;
9647
+
9648
+ options4[0] = 1;
9649
+ options4[1] = 0;
9650
+ options4[2] = 1;
9651
+ options4[3] = 0;
9652
+ }
9653
+
75779654 static int imagecount = 0; // movie generation
75789655
75799656 static int jitter = 0;
75809657
75819658 boolean restartframe = false;
7582
-
7583
- static int framecount = 0; // general-purpose global count
75849659
75859660 void displayAntiAliased(javax.media.opengl.GL gl)
75869661 {
....@@ -7610,14 +9685,14 @@
76109685
76119686 //System.out.println("start frame");
76129687 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
7613
- for (jitter = 0; jitter < ACSIZE; jitter++) //, GraphreeD.wav.cursor += LIVE ? 735 : 0)
9688
+ for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76149689 {
7615
- framecount++;
9690
+ Globals.framecount++;
76169691
76179692 if (CameraPane.tickcount > 0)
76189693 CameraPane.tickcount--;
76199694
7620
-// GraphreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
9695
+// GrafreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
76219696 // restartframe = true;
76229697 if (options1[2] > 100 && (jitter%2==0))
76239698 {
....@@ -7650,7 +9725,7 @@
76509725
76519726 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76529727 */
7653
- lighttouched = true;
9728
+ Globals.lighttouched = true;
76549729 //System.err.println(" shadowbuffer: " + jitter);
76559730 shadowbuffer.display();
76569731
....@@ -7671,8 +9746,8 @@
76719746 assert (parentcam != renderCamera);
76729747
76739748 if (renderCamera != lightCamera)
7674
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7675
- LA.matConcat(parentcam.toParent, matrix, matrix);
9749
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9750
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76769751
76779752 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76789753
....@@ -7687,8 +9762,8 @@
76879762 LA.matCopy(renderCamera.fromScreen, matrix);
76889763
76899764 if (renderCamera != lightCamera)
7690
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7691
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9765
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9766
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
76929767
76939768 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
76949769
....@@ -7734,10 +9809,12 @@
77349809 rati = 1 / rati;
77359810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77369811 }
7737
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
77389815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77399816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7740
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
77419818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77429819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77439820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7760,7 +9837,7 @@
77609837 //gl.glFlush();
77619838 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77629839
7763
- if (ANIMATION && ABORTED)
9840
+ if (Globals.ANIMATION && ABORTED)
77649841 {
77659842 System.err.println(" ABORTED FRAME");
77669843 break;
....@@ -7790,7 +9867,7 @@
77909867 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
77919868
77929869 // save image
7793
- if (ANIMATION && !ABORTED)
9870
+ if (Globals.ANIMATION && !ABORTED)
77949871 {
77959872 VPwidth = viewport[2];
77969873 VPheight = viewport[3];
....@@ -7901,11 +9978,11 @@
79019978
79029979 // imagecount++;
79039980
7904
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9981
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79059982
79069983 if (!BOXMODE)
79079984 {
7908
- System.out.println("image: " + fullname + " (" + (GraphreeD.wav.cursor / 735 / 4) + ")");
9985
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79099986 }
79109987
79119988 if (!BOXMODE)
....@@ -7933,7 +10010,7 @@
793310010 {
793410011 if (ACSIZE > 1)
793510012 {
7936
- // System.err.println("image #" + (GraphreeD.wav.cursor / 735 / 4));
10013
+ // System.err.println("image #" + (GrafreeD.wav.cursor / 735 / 4));
793710014 }
793810015 }
793910016
....@@ -7943,7 +10020,7 @@
794310020 ABORTED = false;
794410021 }
794510022 else
7946
- GraphreeD.wav.cursor += 735 * ACSIZE;
10023
+ Grafreed.wav.cursor += 735 * ACSIZE;
794710024
794810025 if (false)
794910026 {
....@@ -8597,13 +10674,6 @@
859710674 }
859810675 }
859910676
8600
- boolean IsFrozen()
8601
- {
8602
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8603
-
8604
- return !selectmode && cameracount == 0; // != 0;
8605
- }
8606
-
860710677 boolean niceon = false;
860810678 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
860910679 boolean currentlydrawing = false;
....@@ -8613,16 +10683,16 @@
861310683
861410684 public void display(GLAutoDrawable drawable)
861510685 {
8616
- if (GraphreeD.savesound && GraphreeD.hassound)
10686
+ if (Grafreed.savesound && Grafreed.hassound)
861710687 {
8618
- GraphreeD.wav.save();
8619
- GraphreeD.savesound = false;
8620
- GraphreeD.hassound = false;
10688
+ Grafreed.wav.save();
10689
+ Grafreed.savesound = false;
10690
+ Grafreed.hassound = false;
862110691 }
862210692 // if (DEBUG_SELECTION)
862310693 // {
8624
-// if (drawMode != SELECTION)
8625
-// drawMode = SELECTION;
10694
+// if (DrawMode() != SELECTION)
10695
+// DrawMode() = SELECTION;
862610696 // }
862710697
862810698 if (!isRenderer)
....@@ -8678,9 +10748,9 @@
867810748
867910749 //ANTIALIAS = 0;
868010750
8681
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10751
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
868210752 {
8683
- if (niceon || isLIVE())
10753
+ if (niceon || Globals.isLIVE())
868410754 {
868510755 //if(active == 0)
868610756 // antialiaser = null;
....@@ -8693,6 +10763,7 @@
869310763 ANTIALIAS = 0;
869410764 //System.out.println("RESTART");
869510765 AAtimer.restart();
10766
+ Globals.TIMERRUNNING = true;
869610767 }
869710768 }
869810769 }
....@@ -8705,7 +10776,7 @@
870510776 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
870610777 */
870710778
8708
- if (drawMode == DEFAULT)
10779
+ if (DrawMode() == DEFAULT)
870910780 {
871010781 currentlydrawing = true;
871110782 }
....@@ -8736,18 +10807,18 @@
873610807
873710808 // if(Applet3D.clipboard != null)
873810809 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8739
-//drawMode = SELECTION;
10810
+//DrawMode() = SELECTION;
874010811 indexcount = 0;
874110812
8742
- if (drawMode == OCCLUSION)
10813
+ if (DrawMode() == OCCLUSION)
874310814 {
8744
- drawMode = DEFAULT;
10815
+ Globals.drawMode = DEFAULT; // WARNING
874510816 ambientOcclusion = true;
874610817 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
874710818 Object3D theobject = object;
874810819 Object3D theparent = object.parent;
874910820 object.parent = null;
8750
- object = (Object3D)GraphreeD.clone(object);
10821
+ object = (Object3D)Grafreed.clone(object);
875110822 object.Stripify();
875210823 if (theobject.selection == null || theobject.selection.Size() == 0)
875310824 theobject.PreprocessOcclusion(this);
....@@ -8760,26 +10831,27 @@
876010831 ambientOcclusion = false;
876110832 }
876210833
8763
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10834
+ if (//Globals.lighttouched &&
10835
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
876410836 {
876510837 //if (RENDERSHADOW) // ?
876610838 if (!IsFrozen())
876710839 {
876810840 // dec 2012
8769
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10841
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
877010842 {
8771
- framecount++;
10843
+ Globals.framecount++;
877210844 shadowbuffer.display();
877310845 }
877410846 }
8775
- lighttouched = false; // ??
10847
+ Globals.lighttouched = false; // ??
877610848 //drawing = true;
877710849 //lighttouched = true;
877810850 }
877910851
878010852 if (wait)
878110853 {
8782
- Sleep(500);
10854
+ Sleep(200); // blocks everything
878310855
878410856 wait = false;
878510857 }
....@@ -8793,9 +10865,9 @@
879310865 //eyeCamera.shaper_fovy = 1;
879410866 }
879510867
8796
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10868
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
879710869 {
8798
- //System.out.println("drawMode = " + drawMode);
10870
+ //System.out.println("DrawMode() = " + DrawMode());
879910871 vertexMode |= VP_PASS;
880010872 //vertexMode |= VP_PROJECTION;
880110873 if (!ambientOcclusion)
....@@ -8855,7 +10927,7 @@
885510927 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
885610928 //Camera lightcam = new Camera(light0);
885710929
8858
- if (drawMode == SHADOW)
10930
+ if (DrawMode() == SHADOW)
885910931 {
886010932 /*
886110933 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8893,8 +10965,8 @@
889310965
889410966 // if (parentcam != renderCamera) // not a light
889510967 if (cam != lightCamera)
8896
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8897
- LA.matConcat(parentcam.toParent, matrix, matrix);
10968
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10969
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
889810970
889910971 for (int j = 0; j < 4; j++)
890010972 {
....@@ -8908,8 +10980,8 @@
890810980
890910981 // if (parentcam != renderCamera) // not a light
891010982 if (cam != lightCamera)
8911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8912
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10983
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
891310985
891410986 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
891510987
....@@ -8945,7 +11017,7 @@
894511017 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
894611018 } else
894711019 {
8948
- if (drawMode != DEFAULT)
11020
+ if (DrawMode() != DEFAULT)
894911021 {
895011022 gl.glClearColor(1, 1, 1, 0);
895111023 } // 1);
....@@ -8995,13 +11067,27 @@
899511067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
899611068 }
899711069
8998
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
899911078 {
9000
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
900111084 }
9002
-
9003
- newenvy = -1;
9004
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
900511091 ratio = ((double) getWidth()) / getHeight();
900611092 //System.out.println("ratio = " + ratio);
900711093
....@@ -9010,14 +11096,14 @@
901011096
901111097 fast &= !ambientOcclusion;
901211098
9013
- if (drawMode == DEFAULT)
11099
+ if (DrawMode() == DEFAULT)
901411100 {
901511101 //gl.glEnable(gl.GL_ALPHA_TEST);
901611102 //gl.glActiveTexture(GL.GL_TEXTURE0);
901711103
901811104 if (!IsFrozen() && !ambientOcclusion)
901911105 {
9020
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
902111107 }
902211108
902311109 //if (selection_view == -1)
....@@ -9071,6 +11157,8 @@
907111157 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
907211158 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
907311159 double scale = lightCamera.SCALE / lightCamera.Distance();
11160
+// PATCH FILLE AUX JEANS
11161
+ //scale *= lightCamera.shaper_fovy / 25;
907411162 gl.glScaled(2 * scale, 2 * scale, -scale);
907511163 gl.glTranslated(0, 0, lightCamera.DECAL);
907611164
....@@ -9166,7 +11254,16 @@
916611254 // Bump noise
916711255 gl.glActiveTexture(GL.GL_TEXTURE6);
916811256 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9169
- BindTexture(NOISE_TEXTURE, false, 2);
11257
+
11258
+ try
11259
+ {
11260
+ BindTexture(NOISE_TEXTURE, false, 2);
11261
+ }
11262
+ catch (Exception e)
11263
+ {
11264
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11265
+ }
11266
+
917011267
917111268 gl.glActiveTexture(GL.GL_TEXTURE0);
917211269 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9189,9 +11286,9 @@
918911286
919011287 gl.glMatrixMode(GL.GL_MODELVIEW);
919111288
9192
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9193
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9194
-//gl.glEnable(gl.GL_MULTISAMPLE);
11289
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11290
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11291
+gl.glEnable(gl.GL_MULTISAMPLE);
919511292 } else
919611293 {
919711294 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9202,14 +11299,16 @@
920211299 //System.out.println("BLENDING ON");
920311300 gl.glEnable(GL.GL_BLEND);
920411301 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9205
-
11302
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
920611303 gl.glMatrixMode(gl.GL_PROJECTION);
920711304 gl.glLoadIdentity();
920811305
9209
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11306
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
921011307 {
921111308 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
921211309 double scale = lightCamera.SCALE / lightCamera.Distance();
11310
+// PATCH FILLE AUX JEANS
11311
+ //scale *= lightCamera.shaper_fovy / 25;
921311312 gl.glScaled(2 * scale, 2 * scale, -scale);
921411313 gl.glTranslated(0, 0, lightCamera.DECAL);
921511314 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9262,7 +11361,7 @@
926211361 //gl.glPushMatrix();
926311362 gl.glLoadIdentity();
926411363
9265
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11364
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
926611365 {
926711366 //LA.xformPos(light0, lightCamera.fromScreen, light);
926811367 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9289,8 +11388,8 @@
928911388 System.err.println("parentcam != renderCamera");
929011389
929111390 // if (cam != lightCamera)
9292
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9293
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11391
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
929411393 }
929511394
929611395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9311,8 +11410,8 @@
931111410 if (true) // TODO
931211411 {
931311412 if (cam != lightCamera)
9314
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9315
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
931611415 }
931711416
931811417 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9349,7 +11448,7 @@
934911448 }
935011449
935111450 /**/
9352
- if (true) // drawMode == SELECTION) // != DEFAULT)
11451
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
935311452 gl.glDisable(gl.GL_LIGHTING);
935411453 else
935511454 gl.glEnable(gl.GL_LIGHTING);
....@@ -9361,12 +11460,13 @@
936111460
936211461 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
936311462 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11463
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
936411464
936511465 options2[0] *= renderCamera.Distance();
936611466
936711467 lightslot = 64;
936811468
9369
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11469
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
937011470 {
937111471 DrawLights(object);
937211472 }
....@@ -9377,7 +11477,7 @@
937711477 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
937811478 //System.out.println("fragmentMode = " + fragmentMode);
937911479
9380
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11480
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
938111481 {
938211482 /*
938311483 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9410,7 +11510,7 @@
941011510 }
941111511 }
941211512
9413
- if (drawMode == DEFAULT)
11513
+ if (DrawMode() == DEFAULT)
941411514 {
941511515 if (WIREFRAME && !ambientOcclusion)
941611516 {
....@@ -9428,7 +11528,7 @@
942811528 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
942911529 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
943011530
9431
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11531
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
943211532 {
943311533 if (vertexMode != 0) // && !fast)
943411534 {
....@@ -9448,7 +11548,7 @@
944811548 }
944911549 }
945011550
9451
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11551
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
945211552 {
945311553 //gl.glDepthFunc(GL.GL_LEQUAL);
945411554 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9456,27 +11556,24 @@
945611556
945711557 boolean texon = textureon;
945811558
9459
- if (RENDERPROGRAM > 0)
9460
- {
9461
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9462
- textureon = false;
9463
- }
11559
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11560
+ textureon = false;
11561
+
946411562 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
946511563 //System.out.println("ALLO");
946611564 gl.glColorMask(false, false, false, false);
946711565 DrawObject(gl);
9468
- if (RENDERPROGRAM > 0)
9469
- {
9470
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9471
- textureon = texon;
9472
- }
11566
+
11567
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11568
+ textureon = texon;
11569
+
947311570 gl.glColorMask(true, true, true, true);
947411571
947511572 gl.glDepthFunc(GL.GL_EQUAL);
9476
- //gl.glDepthMask(false);
11573
+ gl.glDepthMask(false);
947711574 }
947811575
9479
- if (false) // drawMode == SHADOW)
11576
+ if (false) // DrawMode() == SHADOW)
948011577 {
948111578 //SetColumnMajorData(cameraInverseTransform, view_1);
948211579 //System.out.println("light = " + cameraInverseTransform);
....@@ -9490,16 +11587,16 @@
949011587 //System.out.println("object = " + object);
949111588 if (!frozen && !imageLocked)
949211589 {
9493
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11590
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
949411591 {
949511592 displayAntiAliased(gl);
949611593 } else
949711594 {
949811595 programcount = 0;
9499
- int keepmode = drawMode;
11596
+ int keepmode = DrawMode();
950011597 // if (DEBUG_SELECTION)
950111598 // {
9502
-// drawMode = SELECTION;
11599
+// DrawMode() = SELECTION;
950311600 // }
950411601 // for point selection
950511602 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9509,10 +11606,10 @@
950911606 DrawObject(gl);
951011607
951111608 // jan 2013 System.err.println("RESET ABORT (display)");
9512
- // if (drawMode == DEFAULT)
11609
+ // if (DrawMode() == DEFAULT)
951311610 // ABORTED = false;
951411611 fullreset = false;
9515
- drawMode = keepmode;
11612
+ Globals.drawMode = keepmode; // WARNING
951611613 //System.out.println("PROGRAM SWITCH " + programcount);
951711614 }
951811615 }
....@@ -9520,11 +11617,11 @@
952011617 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
952111618 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
952211619
9523
- if (drawMode == DEFAULT)
11620
+ if (DrawMode() == DEFAULT)
952411621 {
952511622 ReleaseTexture(NOISE_TEXTURE, false);
952611623 }
9527
- //if (drawMode == DEFAULT)
11624
+ //if (DrawMode() == DEFAULT)
952811625 {
952911626
953011627 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9536,7 +11633,7 @@
953611633 //else
953711634 //gl.glDisable(gl.GL_TEXTURE_2D);
953811635 //gl.glPopMatrix();
9539
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11636
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
954011637 {
954111638 //new Exception().printStackTrace();
954211639 //System.out.println("Draw image " + width + ", " + height);
....@@ -9578,7 +11675,7 @@
957811675 //gl.glFlush();
957911676 }
958011677
9581
- if (flash && drawMode == DEFAULT)
11678
+ if (flash && DrawMode() == DEFAULT)
958211679 {
958311680 flash = false;
958411681 wait = true;
....@@ -9586,9 +11683,9 @@
958611683 }
958711684
958811685 //drawing = false;
9589
- //if(drawMode == DEFAULT)
11686
+ //if(DrawMode() == DEFAULT)
959011687 // niceon = false;
9591
- if (drawMode == DEFAULT)
11688
+ if (DrawMode() == DEFAULT)
959211689 {
959311690 currentlydrawing = false;
959411691 }
....@@ -9608,7 +11705,7 @@
960811705 repaint();
960911706 }
961011707
9611
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11708
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
961211709 repaint();
961311710
961411711 displaydone = true;
....@@ -9627,8 +11724,14 @@
962711724 {
962811725 renderpass++;
962911726 // System.out.println("Draw object... ");
11727
+ STEP = 1;
963011728 if (FAST) // in case there is no script
9631
- STEP = 16;
11729
+ STEP = 8;
11730
+
11731
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11732
+ {
11733
+ STEP *= 4;
11734
+ }
963211735
963311736 //object.FullInvariants();
963411737
....@@ -9642,23 +11745,44 @@
964211745 e.printStackTrace();
964311746 }
964411747
9645
- if (GraphreeD.RENDERME > 0)
9646
- GraphreeD.RENDERME--; // mechante magouille
11748
+ if (Grafreed.RENDERME > 0)
11749
+ Grafreed.RENDERME--; // mechante magouille
964711750
9648
- ONESTEP = false;
11751
+ Globals.ONESTEP = false;
964911752 }
965011753
965111754 static boolean zoomonce = false;
965211755
11756
+ static void CreateSelectedPoint()
11757
+ {
11758
+ if (selectedpoint == null)
11759
+ {
11760
+ debugpointG = new Sphere();
11761
+ debugpointP = new Sphere();
11762
+ debugpointC = new Sphere();
11763
+ debugpointR = new Sphere();
11764
+
11765
+ selectedpoint = new Superellipsoid();
11766
+
11767
+ for (int i=0; i<8; i++)
11768
+ {
11769
+ debugpoints[i] = new Sphere();
11770
+ }
11771
+ }
11772
+ }
11773
+
965311774 void DrawObject(GL gl, boolean draw)
965411775 {
11776
+ // To clear camera values
11777
+ ResetOptions();
11778
+
965511779 //System.out.println("DRAW OBJECT " + mouseDown);
9656
-// drawMode = SELECTION;
11780
+// DrawMode() = SELECTION;
965711781 //GL gl = getGL();
965811782 if ((TRACK || SHADOWTRACK) || zoomonce)
965911783 {
9660
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9661
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11784
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11785
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
966211786 pingthread.StepToTarget(true); // true);
966311787 // zoomonce = false;
966411788 }
....@@ -9678,9 +11802,9 @@
967811802 callist = gl.glGenLists(1);
967911803 }
968011804
9681
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11805
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
968211806
9683
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11807
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
968411808
968511809 if (!mainDL || !active || touched)
968611810 {
....@@ -9707,24 +11831,32 @@
970711831 PushMatrix(ClickInfo.matbuffer);
970811832 }
970911833
9710
- if (drawMode == 0)
11834
+ if (DrawMode() == 0)
971111835 {
971211836 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
971311837
971411838 usedtextures.clear();
971511839
9716
- BindTextures(DEFAULT_TEXTURES, 2);
11840
+ try
11841
+ {
11842
+ BindTextures(DEFAULT_TEXTURES, 2);
11843
+ }
11844
+ catch (Exception e)
11845
+ {
11846
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11847
+ }
971711848 }
971811849 //System.out.println("--> " + stackdepth);
9719
-// GraphreeD.traceon();
11850
+// GrafreeD.traceon();
972011851
972111852 // DRAW
972211853 object.draw(this, /*(Composite)*/ object, false, false);
972311854
9724
- if (drawMode == DEFAULT)
11855
+ if (DrawMode() == DEFAULT)
972511856 {
9726
- if (DEBUG)
11857
+ if (Globals.DEBUG)
972711858 {
11859
+ CreateSelectedPoint();
972811860 float radius = 0.05f;
972911861 if (selectedpoint.radius != radius)
973011862 {
....@@ -9732,69 +11864,104 @@
973211864 selectedpoint.radius = radius;
973311865 selectedpoint.recalculate();
973411866 selectedpoint.material = new cMaterial();
9735
- selectedpoint.material.color = 0.25f;
11867
+ selectedpoint.material.color = 0.15f; // Yellow
973611868 selectedpoint.material.modulation = 0.75f;
973711869
9738
- debugpoint.radius = radius;
9739
- debugpoint.recalculate();
9740
- debugpoint.material = new cMaterial();
9741
- debugpoint.material.color = 0.25f;
9742
- debugpoint.material.modulation = 0.75f;
11870
+ debugpointG.radius = radius;
11871
+ debugpointG.recalculate();
11872
+ debugpointG.material = new cMaterial();
11873
+ debugpointG.material.color = 0.25f; // Green
11874
+ debugpointG.material.modulation = 0.75f;
974311875
9744
- debugpoint2.radius = radius;
9745
- debugpoint2.recalculate();
9746
- debugpoint2.material = new cMaterial();
9747
- debugpoint2.material.color = 0.75f;
9748
- debugpoint2.material.modulation = 0.75f;
11876
+ debugpointP.radius = radius;
11877
+ debugpointP.recalculate();
11878
+ debugpointP.material = new cMaterial();
11879
+ debugpointP.material.color = 0.75f; // Purple
11880
+ debugpointP.material.modulation = 0.75f;
11881
+
11882
+ debugpointC.radius = radius;
11883
+ debugpointC.recalculate();
11884
+ debugpointC.material = new cMaterial();
11885
+ debugpointC.material.color = 0.5f; // Cyan
11886
+ debugpointC.material.modulation = 0.75f;
11887
+
11888
+ debugpointR.radius = radius;
11889
+ debugpointR.recalculate();
11890
+ debugpointR.material = new cMaterial();
11891
+ debugpointR.material.color = 0f; // Red
11892
+ debugpointR.material.modulation = 0.75f;
974911893
975011894 InitPoints(radius);
975111895 }
975211896 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9753
- //debugpoint.draw(this, /*(Composite)*/ null, false);
9754
- //debugpoint2.draw(this, /*(Composite)*/ null, false);
9755
- DrawPoints(this);
11897
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11898
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11899
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11900
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
11901
+ // DrawPoints(this);
975611902 }
975711903
975811904 // debugstuff.draw(this, /*(Composite)*/ null, false);
975911905 }
9760
-// GraphreeD.traceoff();
11906
+// GrafreeD.traceoff();
976111907 //System.out.println(stackdepth);
9762
- if (drawMode == 0)
11908
+ if (DrawMode() == 0)
976311909 {
976411910 ReleaseTextures(DEFAULT_TEXTURES);
976511911
976611912 if (CLEANCACHE)
9767
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11913
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
976811914 {
9769
- String tex = e.nextElement();
11915
+ cTexture tex = e.nextElement();
977011916
977111917 // System.out.println("Texture --------- " + tex);
977211918
9773
- if (tex.equals("WHITE_NOISE"))
11919
+ if (tex.equals("WHITE_NOISE:"))
977411920 continue;
977511921
9776
- if (!usedtextures.containsKey(tex))
11922
+ if (!usedtextures.contains(tex))
977711923 {
11924
+ CacheTexture gettex = texturepigment.get(tex);
977811925 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9779
- textures.get(tex).texture.dispose();
9780
- textures.remove(tex);
11926
+ if (gettex != null)
11927
+ {
11928
+ gettex.texture.dispose();
11929
+ texturepigment.remove(tex);
11930
+ }
11931
+
11932
+ gettex = texturebump.get(tex);
11933
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11934
+ if (gettex != null)
11935
+ {
11936
+ gettex.texture.dispose();
11937
+ texturebump.remove(tex);
11938
+ }
978111939 }
978211940 }
978311941 }
978411942
978511943 checker = null;
978611944
9787
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11945
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
978811946 FindChecker(object);
978911947
9790
- if (checker != null && drawMode == DEFAULT)
11948
+ if (checker != null && DrawMode() == DEFAULT)
979111949 {
9792
- // BindTexture(IMMORTAL_TEXTURE);
11950
+ //BindTexture(IMMORTAL_TEXTURE);
11951
+ try
11952
+ {
11953
+ BindTextures(checker.GetTextures(), checker.texres);
11954
+ }
11955
+ catch (Exception e)
11956
+ {
11957
+ System.err.println("FAILED: " + checker.GetTextures());
11958
+ }
979311959 // NEAREST
979411960 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
979511961 DrawChecker(gl);
979611962 //checker.Draw(this, null, false);
979711963 // ReleaseTexture(IMMORTAL_TEXTURE);
11964
+ ReleaseTextures(checker.GetTextures());
979811965 }
979911966
980011967 if (object.parent != null)
....@@ -9807,7 +11974,7 @@
980711974 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
980811975 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
980911976
9810
- if (DISPLAYTEXT && drawMode == DEFAULT)
11977
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
981111978 {
981211979 // Draw it once, then use the raster
981311980 Balloon(gl, balloon.createGraphics());
....@@ -9863,14 +12030,14 @@
986312030 int[] xs = new int[3];
986412031 int[] ys = new int[3];
986512032
9866
- void DrawString(Object3D obj) // String string)
12033
+ public void DrawString(Object3D obj) // String string) // INTERFACE
986712034 {
9868
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12035
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
986912036 {
987012037 return;
987112038 }
987212039
9873
- String string = obj.GetToolTip();
12040
+ String string = obj.toString(); //.GetToolTip();
987412041
987512042 GL gl = GetGL();
987612043
....@@ -10187,8 +12354,8 @@
1018712354 //obj.TransformToWorld(light, light);
1018812355 for (int i = tp.size(); --i >= 0;)
1018912356 {
10190
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10191
- LA.xformPos(light, tp.get(i).toParent, light);
12357
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12358
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1019212359 }
1019312360
1019412361
....@@ -10205,8 +12372,8 @@
1020512372 parentcam = cameras[0];
1020612373 }
1020712374
10208
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10209
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12375
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12376
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1021012377
1021112378 LA.xformPos(light, renderCamera.toScreen, light);
1021212379
....@@ -10253,7 +12420,7 @@
1025312420 return;
1025412421 }
1025512422
10256
- if (obj instanceof CheckerIG)
12423
+ if (obj instanceof Checker)
1025712424 {
1025812425 checker = obj;
1025912426
....@@ -10296,8 +12463,76 @@
1029612463
1029712464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1029812465
10299
- String program =
12466
+ String programmin =
12467
+ // Min shader
1030012468 "!!ARBfp1.0\n" +
12469
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12470
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12471
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12472
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12473
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12474
+ "PARAM light2cam0 = program.env[10];" +
12475
+ "PARAM light2cam1 = program.env[11];" +
12476
+ "PARAM light2cam2 = program.env[12];" +
12477
+ "TEMP temp;" +
12478
+ "TEMP light;" +
12479
+ "TEMP ndotl;" +
12480
+ "TEMP normal;" +
12481
+ "TEMP depth;" +
12482
+ "TEMP eye;" +
12483
+ "TEMP pos;" +
12484
+
12485
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12486
+ Normalize("normal") +
12487
+ "MOV light, state.light[0].position;" +
12488
+ "DP3 ndotl.x, light, normal;" +
12489
+
12490
+ // shadow
12491
+ "MOV pos, fragment.texcoord[1];" +
12492
+ "MOV temp, pos;" +
12493
+ ShadowTextureFetch("depth", "temp", "1") +
12494
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12495
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12496
+
12497
+ // No shadow when out of frustum
12498
+ //"SGE temp.y, depth.z, zero123.y;" +
12499
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12500
+
12501
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12502
+
12503
+ // Backlit
12504
+ "MOV pos.w, zero123.y;" +
12505
+ "DP4 eye.x, pos, light2cam0;" +
12506
+ "DP4 eye.y, pos, light2cam1;" +
12507
+ "DP4 eye.z, pos, light2cam2;" +
12508
+ Normalize("eye") +
12509
+
12510
+ "DP3 ndotl.y, -eye, normal;" +
12511
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12512
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12513
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12514
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12515
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12516
+
12517
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12518
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12519
+
12520
+ // Pigment
12521
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12522
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12523
+ "MUL temp, temp, ndotl.x;" +
12524
+
12525
+ "MUL temp, temp, zero123.z;" +
12526
+
12527
+ //"MUL temp, temp, ndotl.y;" +
12528
+
12529
+ "MOV temp.w, zero123.y;" + // reset alpha
12530
+ "MOV result.color, temp;" +
12531
+ "END";
12532
+
12533
+ String programmax =
12534
+ "!!ARBfp1.0\n" +
12535
+
1030112536 //"OPTION ARB_fragment_program_shadow;" +
1030212537 "PARAM light2cam0 = program.env[10];" +
1030312538 "PARAM light2cam1 = program.env[11];" +
....@@ -10325,11 +12560,13 @@
1032512560 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1032612561 "PARAM params7 = program.env[7];" + // noise power, opacity power
1032712562 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10328
- "PARAM options1 = program.env[62];" + // fog rgb color, image intensity
12563
+ "PARAM options1 = program.env[62];" + // fog rgb color
12564
+ "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
1032912565 "PARAM pointlight = program.env[127];" + // ...
1033012566 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1033112567 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1033212568 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12569
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1033312570 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1033412571 "PARAM ten = { 10, 10, 10, 1.0 };" +
1033512572 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10350,6 +12587,7 @@
1035012587 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1035112588 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1035212589 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12590
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1035312591 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1035412592 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1035512593 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10390,6 +12628,10 @@
1039012628 "TEMP R1;" +
1039112629 "TEMP R2;" +
1039212630 "TEMP R3;" +
12631
+ "TEMP min;" +
12632
+ "TEMP max;" +
12633
+ "TEMP average;" +
12634
+ "TEMP saturation;" +
1039312635 "TEMP keep1;" +
1039412636 "TEMP keep2;" +
1039512637 "TEMP keep3;" +
....@@ -10405,8 +12647,7 @@
1040512647 "TEMP shininess;" +
1040612648 "\n" +
1040712649 "MOV texSamp, one;" +
10408
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10409
-
12650
+
1041012651 "MOV mapgrid.x, one2048th.x;" +
1041112652 "MOV temp, fragment.texcoord[1];" +
1041212653 /*
....@@ -10427,20 +12668,20 @@
1042712668 "MUL temp, floor, mapgrid.x;" +
1042812669 //"TEX depth0, temp, texture[1], 2D;" +
1042912670 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10430
- TextureFetch("depth0", "temp", "1") +
12671
+ ShadowTextureFetch("depth0", "temp", "1") +
1043112672 "") +
1043212673 "ADD temp.x, temp.x, mapgrid.x;" +
1043312674 //"TEX depth1, temp, texture[1], 2D;" +
1043412675 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10435
- TextureFetch("depth1", "temp", "1") +
12676
+ ShadowTextureFetch("depth1", "temp", "1") +
1043612677 "") +
1043712678 "ADD temp.y, temp.y, mapgrid.x;" +
1043812679 //"TEX depth2, temp, texture[1], 2D;" +
10439
- TextureFetch("depth2", "temp", "1") +
12680
+ ShadowTextureFetch("depth2", "temp", "1") +
1044012681 "SUB temp.x, temp.x, mapgrid.x;" +
1044112682 //"TEX depth3, temp, texture[1], 2D;" +
1044212683 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10443
- TextureFetch("depth3", "temp", "1") +
12684
+ ShadowTextureFetch("depth3", "temp", "1") +
1044412685 "") +
1044512686 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1044612687 //"MOV params, material;" +
....@@ -10811,10 +13052,10 @@
1081113052 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1081213053 "") +
1081313054
10814
- // display shadow only (bump == 0)
13055
+ // display shadow only (fakedepth == 0)
1081513056 "SUB temp.x, half.x, shadow.x;" +
10816
- "MOV temp.y, -params6.x;" +
10817
- "SLT temp.z, temp.y, zero.x;" +
13057
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1081813059 "SUB temp.y, one.x, temp.z;" +
1081913060 "MUL temp.x, temp.x, temp.y;" +
1082013061 "KIL temp.x;" +
....@@ -10920,10 +13161,42 @@
1092013161
1092113162 // skin?
1092213163 // Saturation for skin
10923
- /**/ // c'est ici
10924
- (Skinshader? "DP3 temp.x, final,one;" +
13164
+ /**/
13165
+ (Skinshader?
13166
+ "DP3 average.x, final,one;" +
13167
+ "MUL average, one3rd.xxxx,average.xxxx;" +
13168
+
13169
+ "MIN min.x, final.x,final.y;" +
13170
+ "MIN min.x, min.x,final.z;" +
13171
+
13172
+ "MAX max.x, final.x,final.y;" +
13173
+ "MAX max.x, max.x,final.z;" +
13174
+ "MOV max, max.xxxx;" +
13175
+
13176
+ "SUB saturation, max, final;" +
13177
+
13178
+ "ADD temp.x, max.x, one10th.x;" +
13179
+ "RCP temp.x, temp.x;" +
13180
+ "MUL temp.x, temp.x, half.x;" +
13181
+ "MUL saturation, saturation, temp.xxxx;" +
13182
+
13183
+ "DP3 ndotl.x, normald, light;" +
13184
+ "MAX ndotl.x, ndotl.x, -ndotl.x;" +
13185
+
13186
+ "SUB temp.x, one.x, ndotl.x;" +
13187
+ // Tuning for default skin
13188
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13189
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13190
+ "ADD temp.y, one.y, options2.y;" + // subsurface
13191
+ "MUL temp.x, temp.x, temp.y;" +
13192
+
13193
+ "MUL saturation, saturation, temp.xxxx;" +
13194
+ "SUB_SAT temp, max, saturation;" +
13195
+/**
13196
+ "DP3 temp.x, final,one;" +
1092513197 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10926
- "SUB temp, final,R2;" +
13198
+ "SUB temp, final, R2;" +
13199
+
1092713200 // using light angle
1092813201 "DP3 ndotl.x, normald,light;" +
1092913202 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10936,7 +13209,6 @@
1093613209 // using light intensity
1093713210 "MOV ndotl.z, R2.x;" +
1093813211 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10939
-
1094013212 // june 2014
1094113213 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1094213214 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10948,6 +13220,7 @@
1094813220 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1094913221
1095013222 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13223
+/**/
1095113224
1095213225 // "ADD final, R2,temp;" +
1095313226 "MOV final, temp;"
....@@ -11037,7 +13310,7 @@
1103713310 /**/
1103813311 // HDR
1103913312 "MOV temp.z, final.a;" +
11040
- "MUL final, final,options1.w;" +
13313
+ "MUL final, final,options2.x;" +
1104113314 "MOV final.a, temp.z;" +
1104213315 /**/
1104313316
....@@ -11074,10 +13347,17 @@
1107413347 "MOV final.z, zero.x;" +
1107513348 "MOV final.a, one.w;":""
1107613349 ) +
13350
+ /*
1107713351 (NORMALdebug?"MOV final.x, normal.x;" +
1107813352 "MOV final.y, normal.y;" +
1107913353 "MOV final.z, normal.z;" +
1108013354 "MOV final.a, one.w;":""
13355
+ ) +
13356
+ */
13357
+ (NORMALdebug?"SUB final.x, one.x, final.x;" +
13358
+ "SUB final.y, one.x, final.y;" +
13359
+ "SUB final.z, one.x, final.z;" +
13360
+ "MOV final.a, final.a;":""
1108113361 ) +
1108213362 // "MOV final, bumpmap;" +
1108313363 "MOV result.color, final;" +
....@@ -11106,7 +13386,14 @@
1110613386 //once = true;
1110713387 }
1110813388
11109
- System.out.print("Program #" + mode + "; length = " + program.length());
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
13396
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1111013397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1111113398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1111213399
....@@ -11199,30 +13486,32 @@
1119913486 return out;
1120013487 }
1120113488
11202
- String TextureFetch(String dest, String src, String unit)
13489
+ // Also does frustum culling
13490
+ String ShadowTextureFetch(String dest, String src, String unit)
1120313491 {
1120413492 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1120513493 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1120613494 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13495
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13496
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1120713497 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11208
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11209
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11210
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11211
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13498
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13499
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1121213500 //"SWZ buffer, temp, w,w,w,w;";
11213
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13501
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1121413502 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1121513503 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1121613504 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11217
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13505
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1121813506
11219
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11220
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13507
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13508
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1122113509 }
1122213510
1122313511 String Shadow(String depth, String shadow)
1122413512 {
1122513513 return "MAX temp.x, ndotl.x, one64th.x;" +
13514
+ "MIN temp.x, temp.x, ninetenth.x;" +
1122613515 /**/
1122713516 // Sine
1122813517 "MUL temp.y, temp.x, temp.x;" +
....@@ -11238,12 +13527,16 @@
1123813527
1123913528 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1124013529 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13530
+
13531
+ // Compare fragment depth in light space with shadowmap.
1124113532 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1124213533 "SGE temp.y, temp.x, zero.x;" +
11243
- "SUB " + shadow + ".y, one.x, temp.y;" +
13534
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13535
+
13536
+ // Reverse comparison
1124413537 "SUB temp.x, one.x, temp.x;" +
1124513538 "MUL " + shadow + ".x, temp.x, temp.y;" +
11246
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13539
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1124713540 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1124813541
1124913542 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11257,6 +13550,10 @@
1125713550 // No shadow for backface
1125813551 "DP3 temp.x, normal, lightd;" +
1125913552 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13553
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13554
+
13555
+ // No shadow when out of frustum
13556
+ "SGE temp.x, " + depth + ".z, one.z;" +
1126013557 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1126113558 "";
1126213559 }
....@@ -11403,7 +13700,8 @@
1140313700 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1140413701 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1140513702 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11406
- Object3D.cVector2[] vector2buffer;
13703
+
13704
+ //Object3D.cVector2[] vector2buffer;
1140713705
1140813706 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1140913707 // OUT : diff, spec
....@@ -11419,9 +13717,10 @@
1141913717 "DP3 " + dest + ".z," + "normals," + "eye;" +
1142013718 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1142113719 //"MOV " + dest + ".w," + "normal.z;" +
11422
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11423
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11424
- //"MOV " + dest + ".z," + "params2.w;" +
13720
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13721
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13722
+
13723
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1142513724 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1142613725 "RCP " + dest + ".w," + dest + ".w;" +
1142713726 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11815,7 +14114,7 @@
1181514114 public void mousePressed(MouseEvent e)
1181614115 {
1181714116 //System.out.println("mousePressed: " + e);
11818
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14117
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1181914118 }
1182014119
1182114120 static long prevtime = 0;
....@@ -11842,14 +14141,16 @@
1184214141
1184314142 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1184414143
14144
+ if (BUTTONLESSWHEEL)
1184514145 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1184614146 {
1184714147 return;
1184814148 }
1184914149
14150
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1185014151
1185114152 // TIMER
11852
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14153
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1185314154 {
1185414155 keepboxmode = BOXMODE;
1185514156 keepsupport = SUPPORT;
....@@ -11889,8 +14190,8 @@
1188914190 // mode |= META;
1189014191 //}
1189114192
11892
- SetMouseMode(WHEEL | e.getModifiersEx());
11893
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14193
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14194
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1189414195 anchorX = ax;
1189514196 anchorY = ay;
1189614197 prevX = px;
....@@ -11924,6 +14225,7 @@
1192414225 else
1192514226 if (evt.getSource() == AAtimer)
1192614227 {
14228
+ Globals.TIMERRUNNING = false;
1192714229 if (mouseDown)
1192814230 {
1192914231 //new Exception().printStackTrace();
....@@ -11949,6 +14251,10 @@
1194914251 // LIVE = waslive;
1195014252 // wasliveok = true;
1195114253 // waslive = false;
14254
+
14255
+ // May 2019 Forget it:
14256
+ if (true)
14257
+ return;
1195214258
1195314259 // source == timer
1195414260 if (mouseDown)
....@@ -11978,8 +14284,8 @@
1197814284 // ObjEditor.tweenManager.update(1f / 60f);
1197914285
1198014286 // fev 2014???
11981
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
11982
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14287
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14288
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1198314289 pingthread.StepToTarget(true); // true);
1198414290 }
1198514291 // if (!LIVE)
....@@ -11988,12 +14294,13 @@
1198814294
1198914295 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1199014296
11991
- void clickStart(int x, int y, int modifiers)
14297
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1199214298 {
1199314299 if (!wasliveok)
1199414300 return;
1199514301
1199614302 AAtimer.restart(); //
14303
+ Globals.TIMERRUNNING = true;
1199714304
1199814305 // waslive = LIVE;
1199914306 // LIVE = false;
....@@ -12005,7 +14312,7 @@
1200514312 // touched = true; // main DL
1200614313 if (isRenderer)
1200714314 {
12008
- SetMouseMode(modifiers);
14315
+ SetMouseMode(modifiers, modifiersex);
1200914316 }
1201014317
1201114318 selectX = anchorX = x;
....@@ -12018,7 +14325,7 @@
1201814325 clicked = true;
1201914326 hold = false;
1202014327
12021
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14328
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1202214329 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1202314330 {
1202414331 // System.out.println("RESTART II " + modifiers);
....@@ -12043,14 +14350,15 @@
1204314350 drag = false;
1204414351 //System.out.println("Mouse DOWN");
1204514352 editObj = false;
12046
- ClickInfo info = new ClickInfo();
12047
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12048
- info.pane = this;
12049
- info.camera = renderCamera;
12050
- info.x = x;
12051
- info.y = y;
12052
- info.modifiers = modifiers;
12053
- editObj = object.doEditClick(info, 0);
14353
+ //ClickInfo info = new ClickInfo();
14354
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14355
+ object.clickInfo.pane = this;
14356
+ object.clickInfo.camera = renderCamera;
14357
+ object.clickInfo.x = x;
14358
+ object.clickInfo.y = y;
14359
+ object.clickInfo.modifiers = modifiersex;
14360
+ editObj = object.doEditClick(//info,
14361
+ 0);
1205414362 if (!editObj)
1205514363 {
1205614364 hasMarquee = true;
....@@ -12066,11 +14374,14 @@
1206614374
1206714375 public void mouseDragged(MouseEvent e)
1206814376 {
14377
+ Globals.MOUSEDRAGGED = true;
14378
+
14379
+ //System.out.println("mouseDragged: " + e);
1206914380 if (isRenderer)
1207014381 movingcamera = true;
14382
+
1207114383 //if (drawing)
1207214384 //return;
12073
- //System.out.println("mouseDragged: " + e);
1207414385 if ((e.getModifiersEx() & CTRL) != 0
1207514386 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1207614387 {
....@@ -12078,7 +14389,7 @@
1207814389 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1207914390 }
1208014391 else
12081
- drag(e.getX(), e.getY(), e.getModifiersEx());
14392
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1208214393
1208314394 //try { Thread.sleep(1); } catch (Exception ex) {}
1208414395 }
....@@ -12090,6 +14401,11 @@
1209014401 cVector tmp = new cVector();
1209114402 cVector tmp2 = new cVector();
1209214403 boolean isMoving;
14404
+
14405
+ public cVector TargetLookAt()
14406
+ {
14407
+ return targetLookAt;
14408
+ }
1209314409
1209414410 class PingThread extends Thread
1209514411 {
....@@ -12229,7 +14545,7 @@
1222914545 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1223014546 if (lightMode)
1223114547 {
12232
- lighttouched = true;
14548
+ Globals.lighttouched = true;
1223314549 }
1223414550
1223514551 if (OEILONCE && OEIL)
....@@ -12246,6 +14562,7 @@
1224614562
1224714563 public void run()
1224814564 {
14565
+ new Exception().printStackTrace();
1224914566 System.exit(0);
1225014567 for (;;)
1225114568 {
....@@ -12287,7 +14604,7 @@
1228714604 mouseDown = false;
1228814605 if (lightMode)
1228914606 {
12290
- lighttouched = true;
14607
+ Globals.lighttouched = true;
1229114608 }
1229214609 repaint();
1229314610 alreadypainted = true;
....@@ -12295,7 +14612,7 @@
1229514612 isMoving = false;
1229614613 } //??
1229714614
12298
- if (isLIVE() && !alreadypainted)
14615
+ if (Globals.isLIVE() && !alreadypainted)
1229914616 {
1230014617 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1230114618 repaint();
....@@ -12307,9 +14624,9 @@
1230714624 {
1230814625 if (lightMode)
1230914626 {
12310
- lighttouched = true;
14627
+ Globals.lighttouched = true;
1231114628 }
12312
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14629
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1231314630 }
1231414631 //else
1231514632 }
....@@ -12323,12 +14640,12 @@
1232314640 void GoDown(int mod)
1232414641 {
1232514642 MODIFIERS |= COMMAND;
12326
- /*
14643
+ /**/
1232714644 if((mod&SHIFT) == SHIFT)
12328
- manipCamera.RotatePosition(0, -speed);
14645
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1232914646 else
12330
- manipCamera.BackForth(0, -speed*delta, getWidth());
12331
- */
14647
+ manipCamera.RotatePosition(0, -speed);
14648
+ /**/
1233214649 if ((mod & SHIFT) == SHIFT)
1233314650 {
1233414651 mouseMode = mouseMode; // VR??
....@@ -12344,12 +14661,12 @@
1234414661 void GoUp(int mod)
1234514662 {
1234614663 MODIFIERS |= COMMAND;
12347
- /*
14664
+ /**/
1234814665 if((mod&SHIFT) == SHIFT)
12349
- manipCamera.RotatePosition(0, speed);
14666
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1235014667 else
12351
- manipCamera.BackForth(0, speed*delta, getWidth());
12352
- */
14668
+ manipCamera.RotatePosition(0, speed);
14669
+ /**/
1235314670 if ((mod & SHIFT) == SHIFT)
1235414671 {
1235514672 mouseMode = mouseMode;
....@@ -12365,12 +14682,12 @@
1236514682 void GoLeft(int mod)
1236614683 {
1236714684 MODIFIERS |= COMMAND;
12368
- /*
14685
+ /**/
1236914686 if((mod&SHIFT) == SHIFT)
12370
- manipCamera.RotatePosition(speed, 0);
12371
- else
1237214687 manipCamera.Translate(speed*delta, 0, getWidth());
12373
- */
14688
+ else
14689
+ manipCamera.RotatePosition(speed, 0);
14690
+ /**/
1237414691 if ((mod & SHIFT) == SHIFT)
1237514692 {
1237614693 mouseMode = mouseMode;
....@@ -12386,12 +14703,12 @@
1238614703 void GoRight(int mod)
1238714704 {
1238814705 MODIFIERS |= COMMAND;
12389
- /*
14706
+ /**/
1239014707 if((mod&SHIFT) == SHIFT)
12391
- manipCamera.RotatePosition(-speed, 0);
12392
- else
1239314708 manipCamera.Translate(-speed*delta, 0, getWidth());
12394
- */
14709
+ else
14710
+ manipCamera.RotatePosition(-speed, 0);
14711
+ /**/
1239514712 if ((mod & SHIFT) == SHIFT)
1239614713 {
1239714714 mouseMode = mouseMode;
....@@ -12409,7 +14726,7 @@
1240914726 int X, Y;
1241014727 boolean SX, SY;
1241114728
12412
- void drag(int x, int y, int modifiers)
14729
+ void drag(int x, int y, int modifiers, int modifiersex)
1241314730 {
1241414731 if (IsFrozen())
1241514732 {
....@@ -12418,17 +14735,17 @@
1241814735
1241914736 drag = true; // NEW
1242014737
12421
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14738
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1242214739
1242314740 X = x;
1242414741 Y = y;
1242514742 // floating state for animation
12426
- MODIFIERS = modifiers;
12427
- modifiers &= ~1024;
14743
+ MODIFIERS = modifiersex;
14744
+ modifiersex &= ~1024;
1242814745 if (false) // modifiers != 0)
1242914746 {
1243014747 //new Exception().printStackTrace();
12431
- System.out.println("mouseDragged: " + modifiers);
14748
+ System.out.println("mouseDragged: " + modifiersex);
1243214749 System.out.println("SHIFT = " + SHIFT);
1243314750 System.out.println("CONTROL = " + COMMAND);
1243414751 System.out.println("META = " + META);
....@@ -12441,14 +14758,16 @@
1244114758 if (editObj)
1244214759 {
1244314760 drag = true;
12444
- ClickInfo info = new ClickInfo();
12445
- info.bounds.setBounds(0, 0,
14761
+ //ClickInfo info = new ClickInfo();
14762
+ object.clickInfo.bounds.setBounds(0, 0,
1244614763 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12447
- info.pane = this;
12448
- info.camera = renderCamera;
12449
- info.x = x;
12450
- info.y = y;
12451
- object.editWindow.copy.doEditDrag(info);
14764
+ object.clickInfo.pane = this;
14765
+ object.clickInfo.camera = renderCamera;
14766
+ object.clickInfo.x = x;
14767
+ object.clickInfo.y = y;
14768
+ object //.GetWindow().copy
14769
+ .doEditDrag(//info,
14770
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1245214771 } else
1245314772 {
1245414773 if (x < startX)
....@@ -12550,6 +14869,7 @@
1255014869 {
1255114870 manipCamera.Translate(dx, dy, getWidth());
1255214871 }
14872
+ else
1255314873 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1255414874 {
1255514875 manipCamera.RotateInterest(dx, dy);
....@@ -12560,7 +14880,7 @@
1256014880
1256114881 if (manipCamera == lightCamera)
1256214882 {
12563
- lighttouched = true;
14883
+ Globals.lighttouched = true;
1256414884 }
1256514885 /*
1256614886 switch (mode)
....@@ -12596,23 +14916,27 @@
1259614916 }
1259714917 }
1259814918
14919
+// ClickInfo clickInfo = new ClickInfo();
14920
+
1259914921 public void mouseMoved(MouseEvent e)
1260014922 {
1260114923 //System.out.println("mouseMoved: " + e);
12602
-
1260314924 if (isRenderer)
1260414925 return;
1260514926
12606
- ClickInfo ci = new ClickInfo();
12607
- ci.x = e.getX();
12608
- ci.y = e.getY();
12609
- ci.modifiers = e.getModifiersEx();
12610
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12611
- ci.pane = this;
12612
- ci.camera = renderCamera;
14927
+ // Mouse cursor feedback
14928
+ object.clickInfo.x = e.getX();
14929
+ object.clickInfo.y = e.getY();
14930
+ object.clickInfo.modifiers = e.getModifiersEx();
14931
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14932
+ object.clickInfo.pane = this;
14933
+ object.clickInfo.camera = renderCamera;
1261314934 if (!isRenderer)
1261414935 {
12615
- if (object.editWindow.copy.doEditClick(ci, 0))
14936
+ //ObjEditor editWindow = object.editWindow;
14937
+ //Object3D copy = editWindow.copy;
14938
+ if (object.doEditClick(//clickInfo,
14939
+ 0))
1261614940 {
1261714941 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1261814942 } else
....@@ -12624,7 +14948,11 @@
1262414948
1262514949 public void mouseReleased(MouseEvent e)
1262614950 {
14951
+ Globals.MOUSEDRAGGED = false;
14952
+
1262714953 movingcamera = false;
14954
+ X = 0; // getBounds().width/2;
14955
+ Y = 0; // getBounds().height/2;
1262814956 //System.out.println("mouseReleased: " + e);
1262914957 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1263014958 }
....@@ -12647,9 +14975,9 @@
1264714975 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1264814976 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1264914977
12650
- if (control || command || IsFrozen())
14978
+// No delay if (control || command || IsFrozen())
1265114979 timeout = true;
12652
- else
14980
+// ?? May 2019 else
1265314981 // timer.setDelay((modifiers & 128) != 0?0:350);
1265414982 mouseDown = false;
1265514983 if (!control && !command) // june 2013
....@@ -12759,7 +15087,7 @@
1275915087 System.out.println("keyReleased: " + e);
1276015088 }
1276115089
12762
- void SetMouseMode(int modifiers)
15090
+ void SetMouseMode(int modifiers, int modifiersex)
1276315091 {
1276415092 //System.out.println("SetMouseMode = " + modifiers);
1276515093 //modifiers &= ~1024;
....@@ -12771,24 +15099,27 @@
1277115099 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1277215100 // return;
1277315101 //System.out.println("SetMode = " + modifiers);
12774
- if ((modifiers & WHEEL) == WHEEL)
15102
+ if ((modifiersex & WHEEL) == WHEEL)
1277515103 {
1277615104 mouseMode |= ZOOM;
1277715105 }
12778
- if ((modifiers & META) == META)
15106
+
15107
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15108
+ if (capsLocked) // || (modifiers & META) == META)
1277915109 {
1278015110 mouseMode |= VR; // BACKFORTH;
1278115111 }
12782
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12783
- {
12784
- mouseMode |= SELECT; // BACKFORTH;
12785
- }
12786
- if ((modifiers & COMMAND) == COMMAND)
15112
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1278715113 {
1278815114 mouseMode |= SELECT;
1278915115 }
12790
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15116
+ if ((modifiersex & COMMAND) == COMMAND)
1279115117 {
15118
+ mouseMode |= SELECT;
15119
+ }
15120
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15121
+ {
15122
+ mouseMode &= ~VR;
1279215123 mouseMode |= TRANSLATE;
1279315124 }
1279415125 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12815,10 +15146,10 @@
1281515146
1281615147 if (isRenderer) //
1281715148 {
12818
- SetMouseMode(modifiers);
15149
+ SetMouseMode(0, modifiers);
1281915150 }
1282015151
12821
- theRenderer.keyPressed(key);
15152
+ Globals.theRenderer.keyPressed(key);
1282215153 }
1282315154
1282415155 int kompactbit = 4; // power bit
....@@ -12830,7 +15161,7 @@
1283015161 float SATPOW = 1; // 2; // 0.5f;
1283115162 float BRIPOW = 1; // 0.5f; // 0.5f;
1283215163
12833
- void keyPressed(int key)
15164
+ public void keyPressed(int key)
1283415165 {
1283515166 if (key >= '0' && key <= '5')
1283615167 clampbit = (key-'0');
....@@ -12877,7 +15208,8 @@
1287715208 // break;
1287815209 case 'T':
1287915210 CACHETEXTURE ^= true;
12880
- textures.clear();
15211
+ texturepigment.clear();
15212
+ texturebump.clear();
1288115213 // repaint();
1288215214 break;
1288315215 case 'Y':
....@@ -12945,7 +15277,7 @@
1294515277 case 'B':
1294615278 BRISMOOTH ^= true;
1294715279 SHADOWCULLFACE ^= true;
12948
- lighttouched = true;
15280
+ Globals.lighttouched = true;
1294915281 repaint();
1295015282 break;
1295115283 case 'b':
....@@ -12962,7 +15294,9 @@
1296215294 case 'E' : COMPACT ^= true;
1296315295 repaint();
1296415296 break;
12965
- case 'W' : DEBUGHSB ^= true;
15297
+ case 'W' : // Wide Window (fullscreen)
15298
+ //DEBUGHSB ^= true;
15299
+ ObjEditor.theFrame.ToggleFullScreen();
1296615300 repaint();
1296715301 break;
1296815302 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -12987,8 +15321,8 @@
1298715321 RevertCamera();
1298815322 repaint();
1298915323 break;
12990
- case 'L':
1299115324 case 'l':
15325
+ //case 'L':
1299215326 if (lightMode)
1299315327 {
1299415328 lightMode = false;
....@@ -13045,27 +15379,31 @@
1304515379 repaint();
1304615380 break;
1304715381 case 'O':
13048
- drawMode = OCCLUSION;
15382
+ Globals.drawMode = OCCLUSION; // WARNING
1304915383 repaint();
1305015384 break;
1305115385 case 'o':
1305215386 OCCLUSION_CULLING ^= true;
1305315387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1305415388 break;
13055
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1305615390 case '1':
1305715391 case '2':
1305815392 case '3':
1305915393 case '4':
1306015394 case '5':
13061
- newenvy = Character.getNumericValue(key);
13062
- repaint();
13063
- break;
1306415395 case '6':
1306515396 case '7':
1306615397 case '8':
1306715398 case '9':
13068
- BGcolor = (key - '6')/3.f;
15399
+ if (true) // envyoff)
15400
+ {
15401
+ BGcolor = (key - '1')/8.f;
15402
+ }
15403
+ else
15404
+ {
15405
+ //newenvy = Character.getNumericValue(key);
15406
+ }
1306915407 repaint();
1307015408 break;
1307115409 case '!':
....@@ -13131,12 +15469,12 @@
1313115469 case '_':
1313215470 kompactbit = 5;
1313315471 break;
13134
- case '+':
13135
- kompactbit = 6;
13136
- break;
15472
+// case '+':
15473
+// kompactbit = 6;
15474
+// break;
1313715475 case ' ':
1313815476 lightMode ^= true;
13139
- lighttouched = true;
15477
+ Globals.lighttouched = true;
1314015478 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1314115479 targetLookAt.set(manipCamera.lookAt);
1314215480 repaint();
....@@ -13145,14 +15483,15 @@
1314515483 case ESC:
1314615484 RENDERPROGRAM += 1;
1314715485 RENDERPROGRAM %= 3;
15486
+
1314815487 repaint();
1314915488 break;
1315015489 case 'Z':
13151
- RESIZETEXTURE ^= true;
13152
- break;
15490
+ //RESIZETEXTURE ^= true;
15491
+ //break;
1315315492 case 'z':
13154
- RENDERSHADOW ^= true;
13155
- lighttouched = true;
15493
+ Globals.RENDERSHADOW ^= true;
15494
+ Globals.lighttouched = true;
1315615495 repaint();
1315715496 break;
1315815497 //case UP:
....@@ -13178,13 +15517,15 @@
1317815517 FlipTransform();
1317915518 break;
1318015519 case ENTER:
13181
- object.editWindow.ScreenFit(); // Edit();
15520
+ // object.editWindow.ScreenFit(); // Edit();
15521
+ ToggleLive();
1318215522 break;
1318315523 case DELETE:
1318415524 ClearSelection();
1318515525 break;
13186
- /*
1318715526 case '+':
15527
+
15528
+ /*
1318815529 //fontsize += 1;
1318915530 bbzoom *= 2;
1319015531 repaint();
....@@ -13201,17 +15542,17 @@
1320115542 case '=':
1320215543 IncDepth();
1320315544 //fontsize += 1;
13204
- object.editWindow.refreshContents(true);
15545
+ object.GetWindow().refreshContents(true);
1320515546 maskbit = 6;
1320615547 break;
1320715548 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1320815549 DecDepth();
1320915550 maskbit = 5;
1321015551 //if(fontsize > 1) fontsize -= 1;
13211
- if (object.editWindow == null)
13212
- new Exception().printStackTrace();
13213
- else
13214
- object.editWindow.refreshContents(true);
15552
+// if (object.editWindow == null)
15553
+// new Exception().printStackTrace();
15554
+// else
15555
+ object.GetWindow().refreshContents(true);
1321515556 break;
1321615557 case '{':
1321715558 manipCamera.shaper_fovy /= 1.1;
....@@ -13266,6 +15607,7 @@
1326615607 }
1326715608 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1326815609 }
15610
+
1326915611 static double OCCLUSIONBOOST = 1; // 0.5;
1327015612
1327115613 void keyReleased(int key, int modifiers)
....@@ -13273,11 +15615,11 @@
1327315615 //mode = ROTATE;
1327415616 if ((MODIFIERS & COMMAND) == 0) // VR??
1327515617 {
13276
- SetMouseMode(modifiers);
15618
+ SetMouseMode(0, modifiers);
1327715619 }
1327815620 }
1327915621
13280
- protected void processKeyEvent(KeyEvent e)
15622
+ public void processKeyEvent(KeyEvent e)
1328115623 {
1328215624 switch (e.getID())
1328315625 {
....@@ -13407,8 +15749,9 @@
1340715749
1340815750 protected void processMouseMotionEvent(MouseEvent e)
1340915751 {
13410
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13411
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15752
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15753
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15754
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1341215755 {
1341315756 mouseMoved(e);
1341415757 } else
....@@ -13433,11 +15776,12 @@
1343315776 }
1343415777 */
1343515778
13436
- object.editWindow.EditSelection();
15779
+ object.GetWindow().EditSelection(false);
1343715780 }
1343815781
1343915782 void SelectParent()
1344015783 {
15784
+ new Exception().printStackTrace();
1344115785 System.exit(0);
1344215786 Composite group = (Composite) object;
1344315787 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13449,10 +15793,10 @@
1344915793 {
1345015794 //selectees.remove(i);
1345115795 System.out.println("select parent of " + elem);
13452
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15796
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1345315797 } else
1345415798 {
13455
- group.editWindow.Select(elem.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1345615800 }
1345715801
1345815802 first = false;
....@@ -13461,6 +15805,7 @@
1346115805
1346215806 void SelectChildren()
1346315807 {
15808
+ new Exception().printStackTrace();
1346415809 System.exit(0);
1346515810 /*
1346615811 Composite group = (Composite) object;
....@@ -13493,12 +15838,12 @@
1349315838 for (int j = 0; j < group.children.size(); j++)
1349415839 {
1349515840 elem = (Object3D) group.children.elementAt(j);
13496
- object.editWindow.Select(elem.GetTreePath(), first, true);
15841
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1349715842 first = false;
1349815843 }
1349915844 } else
1350015845 {
13501
- object.editWindow.Select(elem.GetTreePath(), first, true);
15846
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1350215847 }
1350315848
1350415849 first = false;
....@@ -13509,21 +15854,21 @@
1350915854 {
1351015855 //Composite group = (Composite) object;
1351115856 Object3D group = object;
13512
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15857
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1351315858 }
1351415859
1351515860 void ResetTransform(int mask)
1351615861 {
1351715862 //Composite group = (Composite) object;
1351815863 Object3D group = object;
13519
- group.editWindow.ResetTransform(mask);
15864
+ group.GetWindow().ResetTransform(mask);
1352015865 }
1352115866
1352215867 void FlipTransform()
1352315868 {
1352415869 //Composite group = (Composite) object;
1352515870 Object3D group = object;
13526
- group.editWindow.FlipTransform();
15871
+ group.GetWindow().FlipTransform();
1352715872 // group.editWindow.ReduceMesh(true);
1352815873 }
1352915874
....@@ -13531,7 +15876,7 @@
1353115876 {
1353215877 //Composite group = (Composite) object;
1353315878 Object3D group = object;
13534
- group.editWindow.PrintMemory();
15879
+ group.GetWindow().PrintMemory();
1353515880 // group.editWindow.ReduceMesh(true);
1353615881 }
1353715882
....@@ -13539,7 +15884,7 @@
1353915884 {
1354015885 //Composite group = (Composite) object;
1354115886 Object3D group = object;
13542
- group.editWindow.ResetCentroid();
15887
+ group.GetWindow().ResetCentroid();
1354315888 }
1354415889
1354515890 void IncDepth()
....@@ -13621,11 +15966,11 @@
1362115966
1362215967 int width = getBounds().width;
1362315968 int height = getBounds().height;
13624
- ClickInfo info = new ClickInfo();
13625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1362615969 //Image img = CreateImage(width, height);
1362715970 //System.out.println("width = " + width + "; height = " + height + "\n");
15971
+
1362815972 Graphics gr = g; // img.getGraphics();
15973
+
1362915974 if (!hasMarquee)
1363015975 {
1363115976 if (Xmin < Xmax) // !locked)
....@@ -13697,40 +16042,88 @@
1369716042 }
1369816043 if (object != null && !hasMarquee)
1369916044 {
16045
+ if (object.clickInfo == null)
16046
+ object.clickInfo = new ClickInfo();
16047
+ ClickInfo info = object.clickInfo;
16048
+ //ClickInfo info = new ClickInfo();
16049
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16050
+
1370016051 if (isRenderer)
1370116052 {
13702
- info.flags++;
16053
+ object.clickInfo.flags++;
1370316054 double frameAspect = (double) width / (double) height;
1370416055 if (frameAspect > renderCamera.aspect)
1370516056 {
1370616057 int desired = (int) ((double) height * renderCamera.aspect);
13707
- info.bounds.width -= width - desired;
13708
- info.bounds.x += (width - desired) / 2;
16058
+ object.clickInfo.bounds.width -= width - desired;
16059
+ object.clickInfo.bounds.x += (width - desired) / 2;
1370916060 } else
1371016061 {
1371116062 int desired = (int) ((double) width / renderCamera.aspect);
13712
- info.bounds.height -= height - desired;
13713
- info.bounds.y += (height - desired) / 2;
16063
+ object.clickInfo.bounds.height -= height - desired;
16064
+ object.clickInfo.bounds.y += (height - desired) / 2;
1371416065 }
1371516066 }
13716
- info.g = gr;
13717
- info.camera = renderCamera;
16067
+
16068
+ object.clickInfo.g = gr;
16069
+ object.clickInfo.camera = renderCamera;
1371816070 /*
1371916071 // Memory intensive (brep.verticescopy)
1372016072 if (!(object instanceof Composite))
1372116073 object.draw(info, 0, false); // SLOW :
1372216074 */
13723
- if (!isRenderer)
16075
+ if (!isRenderer) // && drag)
1372416076 {
13725
- object.drawEditHandles(info, 0);
16077
+ Grafreed.Assert(object != null);
16078
+ Grafreed.Assert(object.selection != null);
16079
+ if (object.selection.Size() > 0)
16080
+ {
16081
+ int hitSomething = object.selection.get(0).hitSomething;
16082
+
16083
+ object.clickInfo.DX = 0;
16084
+ object.clickInfo.DY = 0;
16085
+ object.clickInfo.W = 1;
16086
+ if (hitSomething == Object3D.hitCenter)
16087
+ {
16088
+ info.DX = X;
16089
+ if (X != 0)
16090
+ info.DX -= info.bounds.width/2;
16091
+
16092
+ info.DY = Y;
16093
+ if (Y != 0)
16094
+ info.DY -= info.bounds.height/2;
16095
+ }
16096
+
16097
+ object.drawEditHandles(//info,
16098
+ 0);
16099
+
16100
+ if (drag && (X != 0 || Y != 0))
16101
+ {
16102
+ switch (hitSomething)
16103
+ {
16104
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16105
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16106
+ break;
16107
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ }
16114
+
16115
+ }
16116
+ }
1372616117 }
1372716118 }
16119
+
1372816120 if (isRenderer)
1372916121 {
1373016122 //gr.setColor(Color.black);
1373116123 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1373216124 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1373316125 }
16126
+
1373416127 if (hasMarquee)
1373516128 {
1373616129 gr.setXORMode(Color.white);
....@@ -13753,6 +16146,7 @@
1375316146 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1375416147 }
1375516148
16149
+ // To avoid clear.
1375616150 public void update(Graphics g)
1375716151 {
1375816152 paint(g);
....@@ -13842,6 +16236,7 @@
1384216236 public boolean mouseDown(Event evt, int x, int y)
1384316237 {
1384416238 System.out.println("mouseDown: " + evt);
16239
+ System.exit(0);
1384516240 /*
1384616241 locked = true;
1384716242 drag = false;
....@@ -13885,7 +16280,7 @@
1388516280 {
1388616281 keyPressed(0, modifiers);
1388716282 }
13888
- clickStart(x, y, modifiers);
16283
+ // clickStart(x, y, modifiers);
1388916284 return true;
1389016285 }
1389116286
....@@ -14003,7 +16398,7 @@
1400316398 {
1400416399 keyReleased(0, 0);
1400516400 }
14006
- drag(x, y, modifiers);
16401
+ drag(x, y, 0, modifiers);
1400716402 return true;
1400816403 }
1400916404
....@@ -14135,7 +16530,7 @@
1413516530 Object3D object;
1413616531 static Object3D trackedobject;
1413716532 Camera renderCamera; // Light or Eye (or Occlusion)
14138
- /*static*/ Camera manipCamera; // Light or Eye
16533
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1413916534 /*static*/ Camera eyeCamera;
1414016535 /*static*/ Camera lightCamera;
1414116536 int cameracount;
....@@ -14199,6 +16594,8 @@
1419916594 private /*static*/ boolean firstime;
1420016595 private /*static*/ cVector newView = new cVector();
1420116596 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16597
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16598
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1420216599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1420316600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1420416601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14211,29 +16608,67 @@
1421116608 {
1421216609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1421316610
16611
+ int usedsuf = 0;
16612
+
1421416613 for (int i = 0; i < suffixes.length; i++)
1421516614 {
14216
- String resourceName = basename + suffixes[i] + "." + suffix;
14217
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14218
- mipmapped,
14219
- FileUtil.getFileSuffix(resourceName));
14220
- if (data == null)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1422116620 {
14222
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1422316625 }
16626
+
16627
+ String resourceName = basename + suffixe[i] + "." + suffix;
16628
+ TextureData data;
16629
+
16630
+ try
16631
+ {
16632
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16633
+ mipmapped,
16634
+ FileUtil.getFileSuffix(resourceName));
16635
+ }
16636
+ catch (Exception e)
16637
+ {
16638
+ try
16639
+ {
16640
+ resourceName = basename + fallback[i] + "." + suffix;
16641
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16642
+ mipmapped,
16643
+ FileUtil.getFileSuffix(resourceName));
16644
+ }
16645
+ catch (Exception e2)
16646
+ {
16647
+ resourceName = basename + fallfallback[i] + "." + suffix;
16648
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16649
+ mipmapped,
16650
+ FileUtil.getFileSuffix(resourceName));
16651
+ }
16652
+ }
16653
+
1422416654 //System.out.println("Target = " + targets[i]);
1422516655 cubemap.updateImage(data, targets[i]);
1422616656 }
1422716657
1422816658 return cubemap;
1422916659 }
16660
+
1423016661 int bigsphere = -1;
1423116662
1423216663 float BGcolor = 0.5f;
1423316664
14234
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1423516668 {
14236
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1423716672 {
1423816673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1423916674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14248,7 +16683,17 @@
1424816683 // Compensates for ExaminerViewer's modification of modelview matrix
1424916684 gl.glMatrixMode(GL.GL_MODELVIEW);
1425016685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1425116687
16688
+// colorV[0] = 2;
16689
+// colorV[1] = 2;
16690
+// colorV[2] = 2;
16691
+// colorV[3] = 1;
16692
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16693
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16694
+//
16695
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16696
+
1425216697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1425316698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1425416699
....@@ -14280,6 +16725,7 @@
1428016725 {
1428116726 gl.glScalef(1.0f, -1.0f, 1.0f);
1428216727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1428316729 gl.glMultMatrixd(viewrot_1, 0);
1428416730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1428516731 //viewer.updateInverseRotation(gl);
....@@ -14355,7 +16801,7 @@
1435516801 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1435616802 gl.glPushMatrix();
1435716803 gl.glLoadIdentity();
14358
- PushMatrix(checker.toParent);
16804
+ //PushMatrix(checker.toParent);
1435916805
1436016806 gl.glMatrixMode(GL.GL_TEXTURE);
1436116807 gl.glPushMatrix();
....@@ -14378,8 +16824,8 @@
1437816824
1437916825 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1438016826
14381
- float step = 0.1666f; //0.25f;
14382
- float stepv = step * 1652 / 998;
16827
+ float step = 2; // 0.1666f; //0.25f;
16828
+ float stepv = 2; // step * 1652 / 998;
1438316829
1438416830 int i0 = 0;
1438516831 /*
....@@ -14415,20 +16861,21 @@
1441516861 /**/
1441616862 //checker.GetMaterial().opacity = 1.1f;
1441716863 ////checker.GetMaterial().ambient = 0.99f;
14418
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14419
- Object3D.selectedstack[Object3D.materialdepth] = false;
14420
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16864
+ materialstack[materialdepth] = checker.material;
16865
+ selectedstack[materialdepth] = false;
16866
+ cStatic.objectstack[materialdepth++] = checker;
1442116867 //System.out.println("material " + material);
1442216868 //Applet3D.tracein(this, selected);
14423
- vector2buffer = checker.projectedVertices;
16869
+ //vector2buffer = checker.projectedVertices;
1442416870
14425
- checker.GetMaterial().Draw(this, false); // true);
16871
+ //checker.GetMaterial().Draw(this, false); // true);
16872
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1442616873
14427
- Object3D.materialdepth -= 1;
14428
- if (Object3D.materialdepth > 0)
16874
+ materialdepth -= 1;
16875
+ if (materialdepth > 0)
1442916876 {
14430
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14431
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16877
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16878
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1443216879 }
1443316880 //checker.GetMaterial().opacity = 1f;
1443416881 ////checker.GetMaterial().ambient = 1f;
....@@ -14449,15 +16896,27 @@
1444916896
1445016897 //float u = (i+1)/2;
1445116898 //float v = (j+1)/2;
14452
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16899
+ if (checker.flipV)
16900
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16901
+ else
16902
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1445316903 gl.glVertex3f(i, j, -0.5f);
1445416904
16905
+ if (checker.flipV)
16906
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16907
+ else
1445516908 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1445616909 gl.glVertex3f(i + step, j, -0.5f);
1445716910
16911
+ if (checker.flipV)
16912
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16913
+ else
1445816914 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1445916915 gl.glVertex3f(i + step, j + stepv, -0.5f);
1446016916
16917
+ if (checker.flipV)
16918
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16919
+ else
1446116920 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1446216921 gl.glVertex3f(i, j + stepv, -0.5f);
1446316922 }
....@@ -14469,7 +16928,7 @@
1446916928 gl.glMatrixMode(GL.GL_PROJECTION);
1447016929 gl.glPopMatrix();
1447116930 gl.glMatrixMode(GL.GL_MODELVIEW);
14472
- PopMatrix(null); // checker.toParent); // null);
16931
+ //PopMatrix(null); // checker.toParent); // null);
1447316932 gl.glPopMatrix();
1447416933 PopTextureMatrix(checker.toParent);
1447516934 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14502,6 +16961,14 @@
1450216961 }
1450316962 }
1450416963
16964
+ private Object3D GetFolder()
16965
+ {
16966
+ Object3D folder = object.GetWindow().copy;
16967
+ if (object.GetWindow().copy.selection.Size() > 0)
16968
+ folder = object.GetWindow().copy.selection.elementAt(0);
16969
+ return folder;
16970
+ }
16971
+
1450516972 class SelectBuffer implements GLEventListener
1450616973 {
1450716974
....@@ -14517,7 +16984,7 @@
1451716984 //new Exception().printStackTrace();
1451816985 System.out.println("select buffer init");
1451916986 // Use debug pipeline
14520
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1452116988
1452216989 GL gl = drawable.getGL();
1452316990
....@@ -14560,6 +17027,7 @@
1456017027 {
1456117028 if (!selection)
1456217029 {
17030
+ new Exception().printStackTrace();
1456317031 System.exit(0);
1456417032 return;
1456517033 }
....@@ -14580,17 +17048,39 @@
1458017048
1458117049 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1458217050
17051
+ if (PAINTMODE)
17052
+ {
17053
+ if (object.GetWindow().copy.selection.Size() > 0)
17054
+ {
17055
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17056
+
17057
+ // Make what you paint not selectable.
17058
+ paintobj.ResetSelectable();
17059
+ }
17060
+ }
17061
+
1458317062 //int tmp = selection_view;
1458417063 //selection_view = -1;
14585
- int temp = drawMode;
14586
- drawMode = SELECTION;
17064
+ int temp = DrawMode();
17065
+ Globals.drawMode = SELECTION; // WARNING
1458717066 indexcount = 0;
1458817067 parent.display(drawable);
1458917068 //selection_view = tmp;
1459017069 //if (temp == SELECTION)
1459117070 // temp = DEFAULT; // patch for selection debug
14592
- drawMode = temp;
17071
+ Globals.drawMode = temp; // WARNING
1459317072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Revert.
17080
+ paintobj.RestoreSelectable();
17081
+ }
17082
+ }
17083
+
1459417084 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1459517085
1459617086 // trying different ways of getting the depth info over
....@@ -14639,6 +17129,13 @@
1463917129 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1464017130 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1464117131
17132
+ CreateSelectedPoint();
17133
+
17134
+ // Will fit the mesh !!!
17135
+ selectedpoint.toParent[0][0] = 0.0001;
17136
+ selectedpoint.toParent[1][1] = 0.0001;
17137
+ selectedpoint.toParent[2][2] = 0.0001;
17138
+
1464217139 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1464317140
1464417141 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14682,34 +17179,36 @@
1468217179 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]));
1468317180 }
1468417181
14685
- previousselectedpoint = (Sphere) GraphreeD.clone(selectedpoint);
17182
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1468617183 }
1468717184 }
1468817185
1468917186 if (!movingcamera && !PAINTMODE)
14690
- object.editWindow.ScreenFitPoint(); // fev 2014
17187
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1469117188
14692
- if (PAINTMODE && GraphreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17189
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1469317190 {
14694
- Object3D paintobj = GraphreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17191
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1469517192
14696
- Object3D group = new Object3D("inst" + paintcount++);
17193
+ if (object.GetWindow().copy.selection.Size() > 0)
17194
+ {
17195
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1469717196
14698
- group.CreateMaterial(); // use a void leaf to select instances
14699
-
14700
- group.add(paintobj); // link
14701
-
14702
- object.editWindow.SnapObject(group);
14703
-
14704
- Object3D folder = object.editWindow.copy;
14705
-
14706
- if (object.editWindow.copy.selection.Size() > 0)
14707
- folder = object.editWindow.copy.selection.elementAt(0);
14708
-
14709
- folder.add(group);
14710
-
14711
- object.editWindow.ResetModel();
14712
- object.editWindow.refreshContents();
17197
+ Object3D inst = new Object3D("inst" + paintcount++);
17198
+
17199
+ inst.CreateMaterial(); // use a void leaf to select instances
17200
+
17201
+ inst.add(paintobj); // link
17202
+
17203
+ object.GetWindow().SnapObject(inst);
17204
+
17205
+ Object3D folder = paintFolder; // GetFolder();
17206
+
17207
+ folder.add(inst);
17208
+
17209
+ object.GetWindow().ResetModel();
17210
+ object.GetWindow().refreshContents();
17211
+ }
1471317212 }
1471417213 else
1471517214 paintcount = 0;
....@@ -14748,6 +17247,11 @@
1474817247 //System.out.println("objects[color] = " + objects[color]);
1474917248 //objects[color].Select();
1475017249 indexcount = 0;
17250
+ ObjEditor window = object.GetWindow();
17251
+ if (window != null && deselect)
17252
+ {
17253
+ window.Select(null, deselect, true);
17254
+ }
1475117255 object.Select(color, deselect);
1475217256 }
1475317257
....@@ -14847,7 +17351,7 @@
1484717351 gl.glDisable(gl.GL_CULL_FACE);
1484817352 }
1484917353
14850
- if (!RENDERSHADOW)
17354
+ if (!Globals.RENDERSHADOW)
1485117355 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1485217356
1485317357 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14857,14 +17361,14 @@
1485717361 //gl.glColorMask(false, false, false, false);
1485817362
1485917363 //render_scene_from_light_view(gl, drawable, 0, 0);
14860
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17364
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1486117365 {
1486217366 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1486317367
14864
- int temp = drawMode;
14865
- drawMode = SHADOW;
17368
+ int temp = DrawMode();
17369
+ Globals.drawMode = SHADOW; // WARNING
1486617370 parent.display(drawable);
14867
- drawMode = temp;
17371
+ Globals.drawMode = temp; // WARNING
1486817372 }
1486917373
1487017374 gl.glCullFace(gl.GL_BACK);
....@@ -14917,7 +17421,6 @@
1491717421
1491817422 class AntialiasBuffer implements GLEventListener
1491917423 {
14920
-
1492117424 CameraPane parent = null;
1492217425
1492317426 AntialiasBuffer(CameraPane p)
....@@ -15027,13 +17530,19 @@
1502717530 gl.glFlush();
1502817531
1502917532 /**/
15030
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17533
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
1503117534
15032
- int[] pixels = occlusionsizebuffer.array();
17535
+ float[] pixels = occlusionsizebuffer.array();
1503317536
1503417537 double r = 0, g = 0, b = 0;
1503517538
1503617539 double count = 0;
17540
+
17541
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17542
+
17543
+ float mindepth = 1;
17544
+
17545
+ double FACTOR = 1;
1503717546
1503817547 for (int i = 0; i < pixels.length; i++)
1503917548 {
....@@ -15118,7 +17627,7 @@
1511817627
1511917628 double scale = ray.z; // 1; // cos
1512017629
15121
- int p = pixels[newindex];
17630
+ float depth = pixels[newindex];
1512217631
1512317632 /*
1512417633 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15142,10 +17651,23 @@
1514217651 scale = (1 - modu) * modv;
1514317652 */
1514417653
15145
- r += ((p >> 16) & 0xFF) * scale / 255;
15146
- g += ((p >> 8) & 0xFF) * scale / 255;
15147
- b += (p & 0xFF) * scale / 255;
17654
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17655
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17656
+ //b += (p & 0xFF) * scale / 255;
17657
+
17658
+ if (mindepth > depth)
17659
+ {
17660
+ mindepth = depth;
17661
+ }
1514817662
17663
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17664
+
17665
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17666
+
17667
+ r += factor * scale;
17668
+ g += factor * scale;
17669
+ b += factor * scale;
17670
+
1514917671 count += scale;
1515017672 }
1515117673
....@@ -15243,12 +17765,6 @@
1524317765 GLUT glut = new GLUT();
1524417766
1524517767
15246
- static final public int DEFAULT = 0;
15247
- static final public int SELECTION = 1;
15248
- static final public int SHADOW = 2;
15249
- static final public int OCCLUSION = 3;
15250
- static
15251
- public int drawMode = DEFAULT;
1525217768 public boolean spherical = false;
1525317769 static boolean DEBUG_OCCLUSION = false;
1525417770 static boolean DEBUG_SELECTION = false;
....@@ -15261,21 +17777,15 @@
1526117777 int AAbuffersize = 0;
1526217778
1526317779 //double[] selectedpoint = new double[3];
15264
- static Sphere selectedpoint = new Sphere();
17780
+ static Superellipsoid selectedpoint;
1526517781 static Sphere previousselectedpoint = null;
15266
- static Sphere debugpoint = new Sphere();
15267
- static Sphere debugpoint2 = new Sphere();
17782
+ static Sphere debugpointG;
17783
+ static Sphere debugpointP;
17784
+ static Sphere debugpointC;
17785
+ static Sphere debugpointR;
1526817786
1526917787 static Sphere debugpoints[] = new Sphere[8];
1527017788
15271
- static
15272
- {
15273
- for (int i=0; i<8; i++)
15274
- {
15275
- debugpoints[i] = new Sphere();
15276
- }
15277
- }
15278
-
1527917789 static void InitPoints(float radius)
1528017790 {
1528117791 for (int i=0; i<8; i++)
....@@ -15295,7 +17805,7 @@
1529517805 }
1529617806 }
1529717807
15298
- static void DrawPoints(CameraPane cpane)
17808
+ static void DrawPoints(iCameraPane cpane)
1529917809 {
1530017810 for (int i=0; i<8; i++) // first and last are red
1530117811 {
....@@ -15317,7 +17827,8 @@
1531717827 static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1531817828 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1531917829 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15320
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17830
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17831
+ static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
1532117832 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1532217833 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1532317834 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15326,10 +17837,11 @@
1532617837 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1532717838 // Depth buffer format
1532817839 //private int depth_format;
15329
- static public void NextIndex(Object3D o, GL gl)
17840
+
17841
+ public void NextIndex()
1533017842 {
1533117843 indexcount+=16;
15332
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17844
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1533317845 //objects[indexcount] = o;
1533417846 //System.out.println("indexcount = " + indexcount);
1533517847 }