Normand Briere
2019-07-24 f555e2cacc4470c5b2217a14d40d2b39c4a57ba2
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,41 @@
165185 defaultcaps.setAccumBlueBits(16);
166186 defaultcaps.setAccumAlphaBits(16);
167187 }
168
- static CameraPane theRenderer;
169
-
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
170191 void SetAsGLRenderer(boolean b)
171192 {
172193 isRenderer = b;
173
- theRenderer = this;
194
+ Globals.theRenderer = this;
195
+ }
196
+
197
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
198
+ {
199
+ super(defaultcaps, null, withcontext?glcontext:null, null);
200
+
201
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
202
+ glcontext = getContext();
203
+
204
+ cameras = new Camera[2];
205
+ targetLookAts = new cVector[2];
206
+
207
+ SetCamera(cam);
208
+
209
+ SetLight(new Camera(new cVector(10, 10, -20)));
210
+
211
+ object = o;
212
+
213
+ setBackground(Color.white);
214
+
215
+ addKeyListener(this);
216
+ addMouseListener(this);
217
+ addMouseMotionListener(this);
218
+ addMouseWheelListener(this);
219
+ //System.out.println("addGLEventListener: " + this);
220
+ addGLEventListener(this);
221
+
222
+// pingthread.start(); // may 2013
174223 }
175224
176225 static boolean AntialiasingEnabled()
....@@ -178,12 +227,53 @@
178227 return CURRENTANTIALIAS > 0;
179228 }
180229
181
- void ClearDepth()
230
+ /// INTERFACE
231
+
232
+ public javax.media.opengl.GL GetGL0()
233
+ {
234
+ return null;
235
+ }
236
+
237
+ public int GenList()
238
+ {
239
+ javax.media.opengl.GL gl = GetGL();
240
+ return gl.glGenLists(1);
241
+ }
242
+
243
+ public void NewList(int id)
244
+ {
245
+ javax.media.opengl.GL gl = GetGL();
246
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
247
+ }
248
+
249
+ public void CallList(int id)
250
+ {
251
+ javax.media.opengl.GL gl = GetGL();
252
+ gl.glCallList(id);
253
+ }
254
+
255
+ public void EndList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ gl.glEndList();
259
+ }
260
+
261
+ public boolean IsBoxMode()
262
+ {
263
+ return BOXMODE;
264
+ }
265
+
266
+ public boolean IsZoomBoxMode()
267
+ {
268
+ return ZOOMBOXMODE;
269
+ }
270
+
271
+ public void ClearDepth()
182272 {
183273 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184274 }
185275
186
- void DepthTest(boolean depthtest)
276
+ public void DepthTest(boolean depthtest)
187277 {
188278 if (depthtest)
189279 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +281,7 @@
191281 GetGL().glDepthFunc(GL.GL_ALWAYS);
192282 }
193283
194
- void DepthWrite(boolean depthwrite)
284
+ public void DepthWrite(boolean depthwrite)
195285 {
196286 if (depthwrite)
197287 GetGL().glDepthMask(true);
....@@ -199,12 +289,1616 @@
199289 GetGL().glDepthMask(false);
200290 }
201291
202
- void BackFaceCull(boolean bfc)
292
+ public void BackFaceCull(boolean bfc)
203293 {
204294 if (bfc)
205295 GetGL().glEnable(GetGL().GL_CULL_FACE);
206296 else
207297 GetGL().glDisable(GetGL().GL_CULL_FACE);
298
+ }
299
+
300
+ public boolean BackFaceCullMode()
301
+ {
302
+ return this.CULLFACE;
303
+ }
304
+
305
+ public boolean IsAmbientOcclusionOn()
306
+ {
307
+ return this.ambientOcclusion;
308
+ }
309
+
310
+ public boolean IsDebugSelection()
311
+ {
312
+ return DEBUG_SELECTION;
313
+ }
314
+
315
+ public boolean IsFrozen()
316
+ {
317
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
318
+
319
+ return !selectmode && cameracount == 0; // != 0;
320
+ }
321
+
322
+ // Currently in Globals
323
+ public int DrawMode()
324
+ {
325
+ return Globals.DrawMode();
326
+ }
327
+
328
+ public Camera EyeCamera()
329
+ {
330
+ return eyeCamera;
331
+ }
332
+
333
+ public Camera LightCamera()
334
+ {
335
+ return lightCamera;
336
+ }
337
+
338
+ public Camera ManipCamera()
339
+ {
340
+ return manipCamera;
341
+ }
342
+
343
+ public Camera RenderCamera()
344
+ {
345
+ return renderCamera;
346
+ }
347
+
348
+ public Camera[] Cameras()
349
+ {
350
+ return cameras;
351
+ }
352
+
353
+ public void PushMaterial(Object3D obj, boolean selected)
354
+ {
355
+ CameraPane display = this;
356
+ javax.media.opengl.GL gl = display.GetGL();
357
+ cMaterial material = obj.material;
358
+
359
+ if (material != null)
360
+ {
361
+ materialstack[materialdepth] = material;
362
+ selectedstack[materialdepth] = selected;
363
+ cStatic.objectstack[materialdepth++] = obj;
364
+ //System.out.println("material " + material);
365
+ //Applet3D.tracein(this, selected);
366
+ //display.vector2buffer = obj.projectedVertices;
367
+ if (obj instanceof Camera)
368
+ {
369
+ display.options1[0] = material.shift;
370
+ //System.out.println("shift " + material.shift);
371
+ display.options1[1] = material.lightarea;
372
+ display.options1[2] = material.shadowbias;
373
+ display.options1[3] = material.aniso;
374
+ display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
380
+ display.options2[0] = material.opacity;
381
+ display.options2[1] = material.diffuse;
382
+ display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
386
+
387
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
391
+ display.options4[0] = material.cameralight/0.2f;
392
+ display.options4[1] = material.subsurface;
393
+ display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
397
+
398
+ // if (display.CURRENTANTIALIAS > 0)
399
+ // display.options3[3] /= 4;
400
+
401
+ /*
402
+ System.out.println("Focus = " + display.options1[0]);
403
+ System.out.println("Aperture = " + display.options1[1]);
404
+ System.out.println("ShadowBlur = " + display.options1[2]);
405
+ System.out.println("Antialiasing = " + display.options1[3]);
406
+ System.out.println("Fog = " + display.options2[0]);
407
+ System.out.println("Intensity = " + display.options2[1]);
408
+ System.out.println("Elevation = " + display.options2[2]);
409
+ /**/
410
+ } else
411
+ {
412
+ DrawMaterial(material, selected, obj.projectedVertices);
413
+ }
414
+ } else
415
+ {
416
+ if (selected && CameraPane.flash)
417
+ {
418
+ display.modelParams4[1] = 100;
419
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
420
+ }
421
+ }
422
+ }
423
+
424
+ public void PushMaterial2(Object3D obj, boolean selected)
425
+ {
426
+ CameraPane display = this;
427
+ cMaterial material = obj.material;
428
+
429
+ if (material != null)
430
+ {
431
+ materialstack[materialdepth] = material;
432
+ selectedstack[materialdepth] = selected;
433
+ cStatic.objectstack[materialdepth++] = obj;
434
+ //System.out.println("material " + material);
435
+ //Applet3D.tracein("selected ", selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
438
+ }
439
+ }
440
+
441
+ public void PopMaterial(Object3D obj, boolean selected)
442
+ {
443
+ CameraPane display = this;
444
+ javax.media.opengl.GL gl = display.GetGL();
445
+ cMaterial material = obj.material;
446
+
447
+ //if (parent != null && parent.GetMaterial() != null)
448
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
449
+ if (material != null)
450
+ {
451
+ materialdepth -= 1;
452
+ if (materialdepth > 0)
453
+ {
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
456
+ }
457
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
458
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
459
+ {
460
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
461
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
462
+ }
463
+ }
464
+
465
+ public void PopMaterial2(Object3D obj)
466
+ {
467
+ CameraPane display = this;
468
+ cMaterial material = obj.material;
469
+
470
+ if (material != null)
471
+ {
472
+ materialdepth -= 1;
473
+ if (materialdepth > 0)
474
+ {
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
477
+ }
478
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
479
+ //else
480
+ //material.Draw(display, false);
481
+ }
482
+ }
483
+
484
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
485
+ {
486
+ CameraPane display = this;
487
+
488
+ if (pv.y == -10000 ||
489
+ qv.y == -10000 ||
490
+ rv.y == -10000)
491
+ return;
492
+
493
+// float b = f.nbiterations & 1;
494
+// float g = (f.nbiterations>>1) & 1;
495
+// float r = (f.nbiterations>>2) & 1;
496
+//
497
+// //if (f.weight == 10000)
498
+// //{
499
+// // r = 1; g = b = 0;
500
+// //}
501
+// //else
502
+// //{
503
+// // assert(f.weight < 10000);
504
+// r = g = b = (float)bRep.FaceWeight(f)*100;
505
+// if (r<0)
506
+// assert(r>=0);
507
+// //}
508
+
509
+ javax.media.opengl.GL gl = display.GetGL();
510
+
511
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
512
+
513
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
514
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
515
+ {
516
+ //gl.glBegin(gl.GL_TRIANGLES);
517
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
518
+ // TEST LIVE NORMALS && !obj.dontselect
519
+ ;
520
+ if (!hasnorm)
521
+ {
522
+ // System.out.println("Mesh normal");
523
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
524
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
525
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
526
+ LA.vecNormalize(obj.v2);
527
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
528
+ }
529
+
530
+ // P
531
+ float x = (float)pv.x;
532
+ float y = (float)pv.y;
533
+ float z = (float)pv.z;
534
+
535
+ if (hasnorm)
536
+ {
537
+// if (!pv.norm.normalized())
538
+// assert(pv.norm.normalized());
539
+
540
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
541
+ float nx = (float)pv.norm.x;
542
+ float ny = (float)pv.norm.y;
543
+ float nz = (float)pv.norm.z;
544
+
545
+ x += nx * obj.NORMALPUSH;
546
+ y += ny * obj.NORMALPUSH;
547
+ z += nz * obj.NORMALPUSH;
548
+
549
+ gl.glNormal3f(nx, ny, nz);
550
+ }
551
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
552
+ SetColor(obj, pv);
553
+ //gl.glColor4f(r, g, b, 1);
554
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
555
+ if (obj.flipV)
556
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
557
+ else
558
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
559
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
560
+
561
+ gl.glVertex3f(x, y, z);
562
+
563
+ // Q
564
+ x = (float)qv.x;
565
+ y = (float)qv.y;
566
+ z = (float)qv.z;
567
+
568
+// Print(pv);
569
+ if (hasnorm)
570
+ {
571
+// assert(qv.norm.normalized());
572
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
573
+ float nx = (float)qv.norm.x;
574
+ float ny = (float)qv.norm.y;
575
+ float nz = (float)qv.norm.z;
576
+
577
+ x += nx * obj.NORMALPUSH;
578
+ y += ny * obj.NORMALPUSH;
579
+ z += nz * obj.NORMALPUSH;
580
+
581
+ gl.glNormal3f(nx, ny, nz);
582
+ }
583
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
584
+ // boolean locked = false;
585
+ // float eps = 0.1f;
586
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
587
+
588
+ // int dot = 0; //*/ (int)f.dot;
589
+
590
+ // if ((dot&1) == 0)
591
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
592
+
593
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
594
+ if (obj.flipV)
595
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
596
+ else
597
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
598
+ // else
599
+ // {
600
+ // locked = true;
601
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
602
+ // }
603
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
604
+ SetColor(obj, qv);
605
+
606
+ gl.glVertex3f(x, y, z);
607
+ //gl.glColor4f(r, g, b, 1);
608
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
609
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
610
+// Print(qv);
611
+
612
+ // R
613
+ x = (float)rv.x;
614
+ y = (float)rv.y;
615
+ z = (float)rv.z;
616
+
617
+ if (hasnorm)
618
+ {
619
+// assert(rv.norm.normalized());
620
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
621
+ float nx = (float)rv.norm.x;
622
+ float ny = (float)rv.norm.y;
623
+ float nz = (float)rv.norm.z;
624
+
625
+ x += nx * obj.NORMALPUSH;
626
+ y += ny * obj.NORMALPUSH;
627
+ z += nz * obj.NORMALPUSH;
628
+
629
+ gl.glNormal3f(nx, ny, nz);
630
+ }
631
+
632
+ // if ((dot&4) == 0)
633
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
634
+
635
+ // if (wrap || !locked && (dot&8) != 0)
636
+ if (obj.flipV)
637
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
638
+ else
639
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
640
+ // else
641
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
642
+
643
+ // f.dot = dot;
644
+
645
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
646
+ SetColor(obj, rv);
647
+ //gl.glColor4f(r, g, b, 1);
648
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
649
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
650
+ gl.glVertex3f(x, y, z);
651
+// Print(rv);
652
+ //gl.glEnd();
653
+ }
654
+ else
655
+ {
656
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
657
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
658
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
659
+
660
+ }
661
+
662
+ if (false) // (attributes & WIREFRAME) != 0)
663
+ {
664
+ gl.glDisable(gl.GL_LIGHTING);
665
+
666
+ gl.glBegin(gl.GL_LINE_LOOP);
667
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
668
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
669
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
670
+ gl.glEnd();
671
+
672
+ gl.glEnable(gl.GL_LIGHTING);
673
+ }
674
+ }
675
+
676
+ /**
677
+ * <code>draw</code> renders a <code>TriMesh</code> object including
678
+ * it's normals, colors, textures and vertices.
679
+ *
680
+ * @see Renderer#draw(TriMesh)
681
+ * @param tris
682
+ * the mesh to render.
683
+ */
684
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
685
+ {
686
+ CameraPane display = this;
687
+
688
+ float r = display.modelParams0[0];
689
+ float g = display.modelParams0[1];
690
+ float b = display.modelParams0[2];
691
+ float opacity = display.modelParams5[1];
692
+
693
+ //final GL gl = GLU.getCurrentGL();
694
+ GL gl = display.GetGL(); // getGL();
695
+
696
+ FloatBuffer vertBuf = geo.vertBuf;
697
+
698
+ int v = vertBuf.capacity();
699
+
700
+ int count = 0;
701
+
702
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
703
+ gl.glEnable(gl.GL_CULL_FACE);
704
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
705
+ for (int i=0; i<v/3; i++)
706
+ {
707
+ int index3 = i*3;
708
+
709
+ if (geo.sizeBuf.get(index3+1) == 0)
710
+ continue;
711
+
712
+ count++;
713
+
714
+ int index4 = i*4;
715
+
716
+ float tx = vertBuf.get(index3);
717
+ float ty = vertBuf.get(index3+1);
718
+ float tz = vertBuf.get(index3+2);
719
+
720
+ // if (tx == 0 && ty == 0 && tz == 0)
721
+ // continue;
722
+
723
+ gl.glMatrixMode(gl.GL_TEXTURE);
724
+ gl.glPushMatrix();
725
+
726
+ float[] texmat = geo.texmat;
727
+ texmat[12] = texmat[13] = texmat[14] = i;
728
+
729
+ gl.glMultMatrixf(texmat, 0);
730
+
731
+ gl.glMatrixMode(gl.GL_MODELVIEW);
732
+ gl.glPushMatrix();
733
+
734
+ gl.glTranslatef(tx,ty,tz);
735
+
736
+ if (rotate)
737
+ gl.glRotatef(i, 0, 1, 0);
738
+
739
+ float size = geo.sizeBuf.get(index3) / 100;
740
+ gl.glScalef(size,size,size);
741
+
742
+ float cr = geo.colorBuf.get(index4);
743
+ float cg = geo.colorBuf.get(index4+1);
744
+ float cb = geo.colorBuf.get(index4+2);
745
+ float ca = geo.colorBuf.get(index4+3);
746
+
747
+ display.modelParams0[0] = r * cr;
748
+ display.modelParams0[1] = g * cg;
749
+ display.modelParams0[2] = b * cb;
750
+
751
+ display.modelParams5[1] = opacity * ca;
752
+
753
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
754
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
755
+
756
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
757
+ RandomNode.globalseed2 = RandomNode.globalseed;
758
+
759
+// gl.glColor4f(cr,cg,cb,ca);
760
+ // gl.glScalef(1024/16,1024/16,1024/16);
761
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
762
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
763
+ //gl.glTranslatef(-tx,-ty,-tz);
764
+ gl.glPopMatrix();
765
+
766
+ gl.glMatrixMode(gl.GL_TEXTURE);
767
+ gl.glPopMatrix();
768
+ }
769
+ // gl.glScalef(1024,1024,1024);
770
+ if (!cf)
771
+ gl.glDisable(gl.GL_CULL_FACE);
772
+
773
+ display.modelParams0[0] = r;
774
+ display.modelParams0[1] = g;
775
+ display.modelParams0[2] = b;
776
+
777
+ display.modelParams5[1] = opacity;
778
+
779
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
780
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
781
+
782
+ gl.glMatrixMode(gl.GL_MODELVIEW);
783
+
784
+// System.err.println("total = " + v/3 + "; displayed = " + count);
785
+ if (true)
786
+ return;
787
+
788
+//// if (!tris.predraw(this))
789
+//// {
790
+//// return;
791
+//// }
792
+//// if (Debug.stats)
793
+//// {
794
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
795
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
796
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
797
+//// }
798
+////
799
+//// if (tris.getDisplayListID() != -1)
800
+//// {
801
+//// renderDisplayList(tris);
802
+//// return;
803
+//// }
804
+////
805
+//// if (!generatingDisplayList)
806
+//// {
807
+//// applyStates(tris.states, tris);
808
+//// }
809
+//// if (Debug.stats)
810
+//// {
811
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
812
+//// }
813
+//// boolean transformed = doTransforms(tris);
814
+//
815
+// int glMode = GL.GL_TRIANGLES;
816
+// switch (getMode())
817
+// {
818
+// case Triangles:
819
+// glMode = GL.GL_TRIANGLES;
820
+// break;
821
+// case Strip:
822
+// glMode = GL.GL_TRIANGLE_STRIP;
823
+// break;
824
+// case Fan:
825
+// glMode = GL.GL_TRIANGLE_FAN;
826
+// break;
827
+// }
828
+//
829
+// if (!predrawGeometry(gl))
830
+// {
831
+// // make sure only the necessary indices are sent through on old
832
+// // cards.
833
+// IntBuffer indices = this.getIndexBuffer();
834
+// if (indices == null)
835
+// {
836
+// logger.severe("missing indices on geometry object: " + this.toString());
837
+// } else
838
+// {
839
+// indices.rewind();
840
+// indices.limit(this.getMaxIndex());
841
+//
842
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
843
+//
844
+// indices.clear();
845
+// }
846
+// } else
847
+// {
848
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
849
+// GL.GL_UNSIGNED_INT, 0);
850
+// }
851
+//
852
+//// postdrawGeometry(tris);
853
+//// if (transformed)
854
+//// {
855
+//// undoTransforms(tris);
856
+//// }
857
+////
858
+//// if (Debug.stats)
859
+//// {
860
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
861
+//// }
862
+//// tris.postdraw(this);
863
+ }
864
+
865
+ static Camera localcamera = new Camera();
866
+ static cVector from = new cVector();
867
+ static cVector to = new cVector();
868
+
869
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
870
+ {
871
+ CameraPane cp = this;
872
+
873
+ Camera keep = cp.RenderCamera();
874
+ cp.renderCamera = localcamera;
875
+
876
+ if (br.trimmed)
877
+ {
878
+ float[] colors = new float[br.positions.length / 3];
879
+
880
+ int i3 = 0;
881
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
882
+ {
883
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
884
+ continue;
885
+
886
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
887
+ to.set(br.positions[i3] + br.normals[i3],
888
+ br.positions[i3 + 1] + br.normals[i3 + 1],
889
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
890
+ LA.xformPos(from, transform, from);
891
+ LA.xformPos(to, transform, to); // RIGID ONLY
892
+ localcamera.setAim(from, to);
893
+
894
+ CameraPane.occlusionbuffer.display();
895
+
896
+ if (CameraPane.DEBUG_OCCLUSION)
897
+ cp.display(); // debug
898
+
899
+ colors[i] = cp.vertexOcclusion.r;
900
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
901
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
902
+
903
+ if ((i % 100) == 0 && i != 0)
904
+ {
905
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
906
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
907
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
908
+ }
909
+ }
910
+
911
+ br.colors = colors;
912
+ }
913
+ else
914
+ {
915
+ for (int i = 0; i < br.VertexCount(); i++)
916
+ {
917
+ Vertex v = br.GetVertex(i);
918
+
919
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
920
+ continue;
921
+
922
+ from.set(v.x, v.y, v.z);
923
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
924
+ LA.xformPos(from, transform, from);
925
+ LA.xformPos(to, transform, to); // RIGID ONLY
926
+ localcamera.setAim(from, to);
927
+
928
+ CameraPane.occlusionbuffer.display();
929
+
930
+ if (CameraPane.DEBUG_OCCLUSION)
931
+ cp.display(); // debug
932
+
933
+ v.AO = cp.vertexOcclusion.r;
934
+
935
+ if ((i % 100) == 0 && i != 0)
936
+ {
937
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
938
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
939
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
940
+ }
941
+ }
942
+ }
943
+
944
+ //System.out.println("done.");
945
+
946
+ cp.renderCamera = keep;
947
+ }
948
+
949
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
950
+ {
951
+ CameraPane display = this;
952
+ pointFlow.CreateHT();
953
+
954
+ float r = display.modelParams0[0];
955
+ float g = display.modelParams0[1];
956
+ float b = display.modelParams0[2];
957
+ float opacity = display.modelParams5[1];
958
+
959
+ //final GL gl = GLU.getCurrentGL();
960
+ GL gl = display.GetGL(); // getGL();
961
+
962
+ int s = pointFlow.points.size();
963
+
964
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
965
+ gl.glEnable(gl.GL_CULL_FACE);
966
+
967
+ for (int i=s; --i>=0;)
968
+ //for (int i=0; i<s; i++)
969
+ {
970
+ cVector v = pointFlow.points.get(i);
971
+
972
+ double mindist = Double.MAX_VALUE;
973
+
974
+ double size = pointFlow.minimumSize;
975
+
976
+ double distancenext = 0;
977
+
978
+ if (i > 0)
979
+ {
980
+ cVector w = pointFlow.points.get(i-1);
981
+
982
+ double dist = w.distance(v);
983
+
984
+ distancenext = dist;
985
+
986
+ if (mindist > dist)
987
+ {
988
+ mindist = dist;
989
+ size = mindist*pointFlow.resizefactor;
990
+ }
991
+ }
992
+
993
+ if (i < s-1)
994
+ {
995
+ cVector w = pointFlow.points.get(i+1);
996
+
997
+ double dist = w.distance(v);
998
+
999
+ if (mindist > dist)
1000
+ {
1001
+ mindist = dist;
1002
+ size = mindist*pointFlow.resizefactor;
1003
+ }
1004
+ }
1005
+
1006
+ if (size < pointFlow.minimumSize)
1007
+ size = pointFlow.minimumSize;
1008
+ if (size > pointFlow.maximumSize)
1009
+ size = pointFlow.maximumSize;
1010
+
1011
+ double tx = v.x;
1012
+ double ty = v.y;
1013
+ double tz = v.z;
1014
+
1015
+ // if (tx == 0 && ty == 0 && tz == 0)
1016
+ // continue;
1017
+
1018
+ gl.glMatrixMode(gl.GL_TEXTURE);
1019
+ gl.glPushMatrix();
1020
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1021
+
1022
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1023
+
1024
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1025
+ gl.glPushMatrix();
1026
+
1027
+ gl.glTranslated(tx,ty,tz);
1028
+
1029
+ gl.glScaled(size,size,size);
1030
+
1031
+// float cr = colorBuf.get(index4);
1032
+// float cg = colorBuf.get(index4+1);
1033
+// float cb = colorBuf.get(index4+2);
1034
+// float ca = colorBuf.get(index4+3);
1035
+//
1036
+// display.modelParams0[0] = r * cr;
1037
+// display.modelParams0[1] = g * cg;
1038
+// display.modelParams0[2] = b * cb;
1039
+//
1040
+// display.modelParams5[1] = opacity * ca;
1041
+//
1042
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1043
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1044
+//
1045
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1046
+// RandomNode.globalseed2 = RandomNode.globalseed;
1047
+//
1048
+//// gl.glColor4f(cr,cg,cb,ca);
1049
+// // gl.glScalef(1024/16,1024/16,1024/16);
1050
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1051
+
1052
+ gl.glPopMatrix();
1053
+
1054
+ double step = size/4; //
1055
+
1056
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1057
+ continue;
1058
+
1059
+ int nbsteps = (int)(distancenext/step);
1060
+
1061
+ step = distancenext/nbsteps;
1062
+
1063
+ cVector next = pointFlow.points.get(i-1);
1064
+
1065
+ tmp.set(next);
1066
+ tmp.sub(v);
1067
+ tmp.normalize();
1068
+ tmp.mul(step);
1069
+
1070
+ // calculate next size
1071
+ mindist = Double.MAX_VALUE;
1072
+
1073
+ double nextsize = pointFlow.minimumSize;
1074
+
1075
+ if (i > 1)
1076
+ {
1077
+ cVector w = pointFlow.points.get(i-2);
1078
+
1079
+ double dist = w.distance(next);
1080
+
1081
+ if (mindist > dist)
1082
+ {
1083
+ mindist = dist;
1084
+ nextsize = mindist*pointFlow.resizefactor;
1085
+ }
1086
+ }
1087
+
1088
+ double dist = v.distance(next);
1089
+
1090
+ if (mindist > dist)
1091
+ {
1092
+ mindist = dist;
1093
+ nextsize = mindist*pointFlow.resizefactor;
1094
+ }
1095
+
1096
+ if (nextsize < pointFlow.minimumSize)
1097
+ nextsize = pointFlow.minimumSize;
1098
+ if (nextsize > pointFlow.maximumSize)
1099
+ nextsize = pointFlow.maximumSize;
1100
+ //
1101
+
1102
+ double count = 0;
1103
+
1104
+ while (distancenext > 0.000000001) // step
1105
+ {
1106
+ gl.glPushMatrix();
1107
+
1108
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1109
+
1110
+ double K = count/nbsteps;
1111
+
1112
+ double intersize = K*nextsize + (1-K)*size;
1113
+
1114
+ gl.glScaled(intersize,intersize,intersize);
1115
+
1116
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1117
+
1118
+ count++;
1119
+
1120
+ distancenext -= step;
1121
+
1122
+ gl.glPopMatrix();
1123
+ }
1124
+
1125
+ if (count != nbsteps)
1126
+ assert(count == nbsteps);
1127
+
1128
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1129
+ //gl.glTranslatef(-tx,-ty,-tz);
1130
+
1131
+ gl.glMatrixMode(gl.GL_TEXTURE);
1132
+ gl.glPopMatrix();
1133
+ }
1134
+
1135
+ if (!cf)
1136
+ gl.glDisable(gl.GL_CULL_FACE);
1137
+
1138
+// display.modelParams0[0] = r;
1139
+// display.modelParams0[1] = g;
1140
+// display.modelParams0[2] = b;
1141
+//
1142
+// display.modelParams5[1] = opacity;
1143
+//
1144
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1145
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1146
+
1147
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1148
+ }
1149
+
1150
+ public void DrawBox(cVector min, cVector max)
1151
+ {
1152
+ javax.media.opengl.GL gl = GetGL();
1153
+ gl.glBegin(gl.GL_LINES);
1154
+
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(min.x, min.y, max.z);
1157
+ gl.glVertex3d(min.x, min.y, min.z);
1158
+ gl.glVertex3d(min.x, max.y, min.z);
1159
+ gl.glVertex3d(min.x, min.y, min.z);
1160
+ gl.glVertex3d(max.x, min.y, min.z);
1161
+
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(min.x, max.y, max.z);
1164
+ gl.glVertex3d(max.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, min.y, max.z);
1166
+ gl.glVertex3d(max.x, max.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, min.z);
1168
+
1169
+ gl.glEnd();
1170
+ }
1171
+
1172
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1173
+ {
1174
+ int[] strips = bRep.getRawIndices();
1175
+
1176
+ javax.media.opengl.GL gl = GetGL();
1177
+
1178
+ // TRIANGLE STRIP ARRAY
1179
+ if (bRep.trimmed)
1180
+ {
1181
+ float[] v = bRep.getRawVertices();
1182
+ float[] n = bRep.getRawNormals();
1183
+ float[] c = bRep.getRawColors();
1184
+ float[] uv = bRep.getRawUVMap();
1185
+
1186
+ int count2 = 0;
1187
+ int count3 = 0;
1188
+
1189
+ if (n.length > 0)
1190
+ {
1191
+ for (int i = 0; i < strips.length; i++)
1192
+ {
1193
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1194
+
1195
+ /*
1196
+ boolean locked = false;
1197
+ float eps = 0.1f;
1198
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1199
+
1200
+ int dot = 0;
1201
+
1202
+ if ((dot&1) == 0)
1203
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1204
+
1205
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1206
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1207
+ else
1208
+ {
1209
+ locked = true;
1210
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1211
+ }
1212
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1213
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1214
+ if (hasnorm)
1215
+ {
1216
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1217
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1218
+ }
1219
+
1220
+ if ((dot&4) == 0)
1221
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1222
+
1223
+ if (wrap || !locked && (dot&8) != 0)
1224
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1225
+ else
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+
1228
+ f.dot = dot;
1229
+ */
1230
+
1231
+ if (!selectmode)
1232
+ {
1233
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1234
+ {
1235
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1236
+ } else
1237
+ {
1238
+ gl.glNormal3f(0, 0, 1);
1239
+ }
1240
+
1241
+ if (c != null)
1242
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1243
+ {
1244
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1245
+ }
1246
+ }
1247
+
1248
+ if (flipV)
1249
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1250
+ else
1251
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
1253
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1254
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1255
+
1256
+ count2 += 2;
1257
+ count3 += 3;
1258
+ if (!selectmode)
1259
+ {
1260
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1261
+ {
1262
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1263
+ } else
1264
+ {
1265
+ gl.glNormal3f(0, 0, 1);
1266
+ }
1267
+ if (c != null)
1268
+ {
1269
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1270
+ }
1271
+ }
1272
+
1273
+ if (flipV)
1274
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1275
+ else
1276
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
1278
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1279
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1280
+
1281
+ count2 += 2;
1282
+ count3 += 3;
1283
+ for (int j = 0; j < strips[i] - 2; j++)
1284
+ {
1285
+ //gl.glTexCoord2d(...);
1286
+ if (!selectmode)
1287
+ {
1288
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1289
+ {
1290
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1291
+ } else
1292
+ {
1293
+ gl.glNormal3f(0, 0, 1);
1294
+ }
1295
+ if (c != null)
1296
+ {
1297
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1298
+ }
1299
+ }
1300
+
1301
+ if (flipV)
1302
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1303
+ else
1304
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
1306
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1307
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
1309
+ count2 += 2;
1310
+ count3 += 3;
1311
+ }
1312
+
1313
+ gl.glEnd();
1314
+ }
1315
+ }
1316
+
1317
+ assert count3 == v.length;
1318
+ }
1319
+ else // !trimmed
1320
+ {
1321
+ int count = 0;
1322
+ for (int i = 0; i < strips.length; i++)
1323
+ {
1324
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1325
+
1326
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1327
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1328
+
1329
+ drawVertex(gl, p, flipV, selectmode);
1330
+ drawVertex(gl, q, flipV, selectmode);
1331
+
1332
+ for (int j = 0; j < strips[i] - 2; j++)
1333
+ {
1334
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1335
+
1336
+ // if (j%2 == 0)
1337
+ // drawFace(p, q, r, display, null);
1338
+ // else
1339
+ // drawFace(p, r, q, display, null);
1340
+
1341
+ // p = q;
1342
+ // q = r;
1343
+ drawVertex(gl, r, flipV, selectmode);
1344
+ }
1345
+
1346
+ gl.glEnd();
1347
+ }
1348
+ }
1349
+ }
1350
+
1351
+ static cSpring.Point3D temp = new cSpring.Point3D();
1352
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1354
+
1355
+ public void DrawDynamicMesh(cMesh mesh)
1356
+ {
1357
+ GL gl = GetGL(); // getGL();
1358
+
1359
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1360
+
1361
+ gl.glDisable(gl.GL_LIGHTING);
1362
+
1363
+ gl.glLineWidth(1);
1364
+ gl.glColor3f(1,1,1);
1365
+ gl.glBegin(gl.GL_LINES);
1366
+ double scale = 0;
1367
+ int count = 0;
1368
+ for (int s=0; s<Phys.allSprings.size(); s++)
1369
+ {
1370
+ cSpring.Spring spring = Phys.allSprings.get(s);
1371
+ if(s == 0)
1372
+ {
1373
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1374
+ }
1375
+ if (mesh.showsprings)
1376
+ {
1377
+ temp.set(spring.a.position);
1378
+ temp.add(spring.b.position);
1379
+ temp.mul(0.5);
1380
+ temp2.set(spring.a.position);
1381
+ temp2.sub(spring.b.position);
1382
+ temp2.mul(spring.restLength/2);
1383
+ temp.sub(temp2);
1384
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1385
+ temp.add(temp2);
1386
+ temp.add(temp2);
1387
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1388
+ }
1389
+
1390
+ if (spring.isHandle)
1391
+ continue;
1392
+
1393
+ //if (scale < spring.restLength)
1394
+ scale += spring.restLength;
1395
+ count++;
1396
+ }
1397
+ gl.glEnd();
1398
+
1399
+ if (count == 0)
1400
+ scale = 0.01;
1401
+ else
1402
+ scale /= count * 3;
1403
+
1404
+ //scale = 0.25;
1405
+
1406
+ if (mesh.ShowInfo())
1407
+ {
1408
+ gl.glLineWidth(4);
1409
+ for (int s=0; s<Phys.allNodes.size(); s++)
1410
+ {
1411
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1412
+ if (node.mass == 0)
1413
+ continue;
1414
+
1415
+ int i = node.springs==null?-1:node.springs.size();
1416
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1417
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1418
+ //temp.normalize();
1419
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1420
+ gl.glBegin(gl.GL_LINES);
1421
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1422
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1423
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1424
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1425
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1426
+ gl.glEnd();
1427
+ }
1428
+
1429
+ gl.glLineWidth(8);
1430
+ for (int s=0; s<Phys.allNodes.size(); s++)
1431
+ {
1432
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1433
+
1434
+ if (node.springs != null)
1435
+ {
1436
+ for (int i=0; i<node.springs.size(); i+=1)
1437
+ {
1438
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1439
+
1440
+ int c = i+1;
1441
+ // c = node.springs.get(i).nbcopies;
1442
+
1443
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1444
+ gl.glBegin(gl.GL_LINES);
1445
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1446
+ 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);
1447
+ gl.glEnd();
1448
+ }
1449
+ }
1450
+ }
1451
+
1452
+ gl.glLineWidth(1);
1453
+ }
1454
+
1455
+ gl.glEnable(gl.GL_LIGHTING);
1456
+ }
1457
+
1458
+ /// INTERFACE
1459
+
1460
+ public void StartTriangles()
1461
+ {
1462
+ javax.media.opengl.GL gl = GetGL();
1463
+ gl.glBegin(gl.GL_TRIANGLES);
1464
+ }
1465
+
1466
+ public void EndTriangles()
1467
+ {
1468
+ GetGL().glEnd();
1469
+ }
1470
+
1471
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1472
+ {
1473
+ if (!selectmode)
1474
+ {
1475
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1476
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1477
+
1478
+ if (flipV)
1479
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1480
+ else
1481
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1482
+ }
1483
+
1484
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1485
+ }
1486
+
1487
+ void SetColor(Object3D obj, Vertex p0)
1488
+ {
1489
+ CameraPane display = this;
1490
+ BoundaryRep bRep = obj.bRep;
1491
+
1492
+ if (RENDERPROGRAM == 0)
1493
+ {
1494
+ float r = 0;
1495
+ if (bRep != null)
1496
+ {
1497
+ if (bRep.stripified)
1498
+ {
1499
+ r = 1;
1500
+ }
1501
+ }
1502
+ float g = 0;
1503
+ if (bRep != null)
1504
+ {
1505
+ if (bRep.trimmed)
1506
+ {
1507
+ g = 1;
1508
+ }
1509
+ }
1510
+ float b = 0;
1511
+ if (obj.support != null && obj.link2master)
1512
+ {
1513
+ b = 1;
1514
+ }
1515
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1516
+ return;
1517
+ }
1518
+
1519
+ if (display.DrawMode() != CameraPane.SHADOW)
1520
+ return;
1521
+
1522
+ javax.media.opengl.GL gl = display.GetGL();
1523
+// if (true) return;
1524
+// float ao = p.AO;
1525
+//
1526
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1527
+// // ao = 1;
1528
+//
1529
+// gl.glColor4f(ao, ao, ao, 1);
1530
+
1531
+// CameraPane.selectedpoint.
1532
+// getAverage(cStatic.point1, true);
1533
+ if (CameraPane.pointflow == null) // !random) // live)
1534
+ {
1535
+ return;
1536
+ }
1537
+
1538
+ cStatic.point1.set(0,0,0);
1539
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1540
+
1541
+ cStatic.point1.sub(p0);
1542
+
1543
+
1544
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1545
+// {
1546
+// return;
1547
+// }
1548
+
1549
+ //if (true)
1550
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1551
+ {
1552
+ return;
1553
+ }
1554
+
1555
+ float[] colorV = new float[3];
1556
+
1557
+ if (false) // marked)
1558
+ {
1559
+ // debug rigging weights
1560
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1561
+ {
1562
+ float weight = p0.weights[object] / p0.totalweight;
1563
+
1564
+ // if (weight < 0.1)
1565
+ // {
1566
+ // assert(weight == 0);
1567
+ // continue;
1568
+ // }
1569
+
1570
+ if (p0.vertexlinks[object] == -1)
1571
+ continue;
1572
+
1573
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1574
+
1575
+ int color = //1 << object; //
1576
+ //p.vertexlinks.length;
1577
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1578
+ colorV[2] += (color & 1) * weight;
1579
+ colorV[1] += ((color & 2) >> 1) * weight;
1580
+ colorV[0] += ((color & 4) >> 2) * weight;
1581
+ }
1582
+ }
1583
+ else
1584
+ {
1585
+ if (obj.drawingstarted)
1586
+ {
1587
+ // find next point
1588
+ if (bRep.GetVertex(0).faceindices == null)
1589
+ {
1590
+ bRep.InitFaceIndices();
1591
+ }
1592
+
1593
+ double ymin = p0.y;
1594
+
1595
+ Vertex newp = p0;
1596
+
1597
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1598
+ {
1599
+ int fi = p0.faceindices[fii];
1600
+
1601
+ if (fi == -1)
1602
+ break;
1603
+
1604
+ Face f = bRep.GetFace(fi);
1605
+
1606
+ Vertex p = bRep.GetVertex(f.p);
1607
+ Vertex q = bRep.GetVertex(f.q);
1608
+ Vertex r = bRep.GetVertex(f.r);
1609
+
1610
+ int swap = (int)(Math.random()*3);
1611
+
1612
+// for (int s=swap; --s>=0;)
1613
+// {
1614
+// Vertex t = p;
1615
+// p = q;
1616
+// q = r;
1617
+// r = t;
1618
+// }
1619
+ if (ymin > p.y)
1620
+ {
1621
+ ymin = p.y;
1622
+ newp = p;
1623
+// break;
1624
+ }
1625
+ if (ymin > q.y)
1626
+ {
1627
+ ymin = q.y;
1628
+ newp = q;
1629
+// break;
1630
+ }
1631
+ if (ymin > r.y)
1632
+ {
1633
+ ymin = r.y;
1634
+ newp = r;
1635
+// break;
1636
+ }
1637
+ }
1638
+
1639
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1640
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1641
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1642
+
1643
+ obj.drawingstarted = false;
1644
+
1645
+ // return;
1646
+ }
1647
+
1648
+ if (false) // CameraPane.DRAW
1649
+ {
1650
+ p0.AO = colorV[0] = 2;
1651
+ colorV[1] = 2;
1652
+ colorV[2] = 2;
1653
+ }
1654
+
1655
+ CameraPane.pointflow.add(p0);
1656
+ CameraPane.pointflow.Touch();
1657
+ }
1658
+
1659
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1660
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1661
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1662
+ }
1663
+
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1665
+ {
1666
+ CameraPane display = this;
1667
+ //new Exception().printStackTrace();
1668
+
1669
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1670
+ {
1671
+ return;
1672
+ }
1673
+
1674
+ javax.media.opengl.GL gl = display.GetGL();
1675
+
1676
+ //Color col = Color.getHSBColor(color,modulation,1);
1677
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1678
+ if (!material.multiply)
1679
+ {
1680
+ display.color = material.color;
1681
+ display.saturation = material.modulation;
1682
+ }
1683
+ else
1684
+ {
1685
+ display.color *= material.color*2;
1686
+ display.saturation *= material.modulation*2;
1687
+ }
1688
+
1689
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1690
+
1691
+ float[] colorV = Grafreed.colorV;
1692
+
1693
+ /**/
1694
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1695
+ {
1696
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1697
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1698
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1699
+ colorV[3] = 1; // material.opacity;
1700
+
1701
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1702
+ //System.out.println("Opacity = " + opacity);
1703
+
1704
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1705
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1706
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1707
+
1708
+ float amb = material.ambient;
1709
+ if (amb < material.cameralight)
1710
+ {
1711
+ amb = material.cameralight;
1712
+ }
1713
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1714
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1715
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1716
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1717
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1718
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1719
+
1720
+ /**/
1721
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1722
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1723
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1724
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1725
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1726
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1727
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1728
+ //System.out.println("shininess = " + colorV[0]);
1729
+ if (colorV[0] > 128)
1730
+ {
1731
+ colorV[0] = 128;
1732
+ }
1733
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1734
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1735
+ /**/
1736
+ }
1737
+ /**/
1738
+
1739
+ //selected = false;
1740
+ selected = selected && display.flash;
1741
+
1742
+ //display.modelParams0[0] = 0; // pigment.r;
1743
+ //display.modelParams0[1] = 0; // pigment.g;
1744
+ //display.modelParams0[2] = 0; // pigment.b;
1745
+ if (!material.multiply)
1746
+ {
1747
+ display.modelParams0[3] = material.metalness;
1748
+ display.modelParams1[0] = material.diffuse;
1749
+ display.modelParams1[1] = material.specular;
1750
+ display.modelParams1[2] = 1 / material.shininess;
1751
+ display.modelParams1[3] = material.shift;
1752
+ display.modelParams2[0] = material.ambient;
1753
+ display.modelParams2[1] = material.lightarea;
1754
+ //System.out.println("light area = " + lightarea);
1755
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1756
+ display.modelParams2[3] = material.velvet;
1757
+ display.modelParams3[0] = material.sheen;
1758
+ display.modelParams3[1] = material.subsurface;
1759
+ display.modelParams3[2] = material.bump; // backlit
1760
+ display.modelParams3[3] = material.aniso;
1761
+ display.modelParams4[0] = material.anisoV;
1762
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1763
+ //System.out.println("selected = " + selected);
1764
+ display.modelParams4[2] = material.diffuseness;
1765
+ display.modelParams4[3] = material.shadow;
1766
+ display.modelParams5[0] = material.texture;
1767
+ display.modelParams5[1] = material.opacity;
1768
+ display.modelParams5[2] = material.fakedepth;
1769
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1770
+ }
1771
+ else
1772
+ {
1773
+ display.modelParams0[3] *= material.metalness*2;
1774
+ display.modelParams1[0] *= material.diffuse*2;
1775
+ display.modelParams1[1] *= material.specular*2;
1776
+ display.modelParams1[2] *= material.shininess*2;
1777
+ display.modelParams1[3] *= material.shift*2;
1778
+ display.modelParams2[0] *= material.ambient*2;
1779
+ display.modelParams2[1] *= material.lightarea*2;
1780
+ display.modelParams2[2] *= material.factor*2;
1781
+ display.modelParams2[3] *= material.velvet*2;
1782
+ display.modelParams3[0] *= material.sheen*2;
1783
+ display.modelParams3[1] *= material.subsurface*2;
1784
+ display.modelParams3[2] *= material.bump*2;
1785
+ display.modelParams3[3] *= material.aniso*2;
1786
+ display.modelParams4[0] *= material.anisoV*2;
1787
+ display.modelParams4[1] *= material.cameralight*2;
1788
+ //System.out.println("selected = " + selected);
1789
+ display.modelParams4[2] *= material.diffuseness*2;
1790
+ display.modelParams4[3] *= material.shadow*2;
1791
+ display.modelParams5[0] *= material.texture*2;
1792
+ display.modelParams5[1] *= material.opacity*2;
1793
+ display.modelParams5[2] *= material.fakedepth*2;
1794
+ display.modelParams5[3] *= material.shadowbias*2;
1795
+ }
1796
+
1797
+ display.modelParams6[0] = 0;
1798
+ display.modelParams6[1] = 0;
1799
+ display.modelParams6[2] = 0;
1800
+ display.modelParams6[3] = 0;
1801
+
1802
+ display.modelParams7[0] = 0;
1803
+ display.modelParams7[1] = 1000;
1804
+ display.modelParams7[2] = 0;
1805
+ display.modelParams7[3] = 0;
1806
+
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
1808
+
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1810
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1811
+ {
1812
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1813
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1814
+ if (extparams.length > 1)
1815
+ {
1816
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1817
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1818
+ if (extparams.length > 2)
1819
+ {
1820
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1821
+ float x = extparams[2].y / 1000.0f;
1822
+ //if (x == 0)
1823
+ // x = 1f;
1824
+ 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
1825
+ if (extparams[2].y > 0)
1826
+ {
1827
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1828
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1829
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1830
+ }
1831
+ }
1832
+ }
1833
+ }
1834
+
1835
+ //if (display.modelParams6[2] != 0)
1836
+ /*
1837
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1838
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1839
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1840
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1841
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1842
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1843
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1844
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1845
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1846
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1847
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1848
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1849
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1850
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1851
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1852
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1853
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1854
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1855
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1856
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1857
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1858
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1859
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1860
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1861
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1862
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1863
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1864
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1865
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1866
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1867
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1868
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1869
+ /**/
1870
+ //assert (display.modelParams6[2] == 0);
1871
+
1872
+ //System.out.println("noise power = " + display.modelParams7[0]);
1873
+ //System.out.println("shadowbias = " + shadowbias);
1874
+
1875
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1876
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1877
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1878
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1879
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1880
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1881
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1882
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1883
+
1884
+ int mode = display.FP_SHADER;
1885
+
1886
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1887
+ {
1888
+ mode |= display.FP_ANISO;
1889
+ }
1890
+
1891
+ display.EnableProgram(mode);
1892
+
1893
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1894
+
1895
+ if (!material.multiply)
1896
+ {
1897
+ if (Globals.drawMode == CameraPane.SHADOW)
1898
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1899
+ else
1900
+ gl.glDepthMask(material.opacity >= 0.99);
1901
+ }
2081902 }
2091903
2101904 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1919,7 @@
2251919 currentGL.glMultMatrixd(model, 0);
2261920 }
2271921
228
- void PushMatrix(double[][] matrix, int count)
1922
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291923 {
2301924 matrixdepth++;
2311925 // GrafreeD.tracein(matrix);
....@@ -254,7 +1948,7 @@
2541948 void PushMatrix(double[][] matrix)
2551949 {
2561950 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
2581952 }
2591953
2601954 void PushMatrix()
....@@ -270,7 +1964,7 @@
2701964
2711965 double[][] tmpmat = new double[4][4];
2721966
273
- void PopMatrix(double[][] inverse)
1967
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741968 {
2751969 --matrixdepth;
2761970
....@@ -310,7 +2004,7 @@
3102004 PushTextureMatrix(matrix, 1);
3112005 }
3122006
313
- void PushTextureMatrix(double[][] matrix, int count)
2007
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142008 {
3152009 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162010
....@@ -324,7 +2018,7 @@
3242018 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252019 }
3262020
327
- void PopTextureMatrix(double[][] inverse)
2021
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282022 {
3292023 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302024 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2045,15 @@
3512045
3522046 static int camerachangeframe;
3532047
354
- boolean SetCamera(Camera cam)
2048
+ public boolean SetCamera(Camera cam)
3552049 {
3562050 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572051 // return false;
3582052
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2053
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602054 {
3612055 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2056
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632057 {
3642058 // refuse the camera change
3652059 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2061,7 @@
3672061 }
3682062 }
3692063
370
- camerachangeframe = framecount;
2064
+ camerachangeframe = Globals.framecount;
3712065
3722066 cam.hAspect = -1; // Read only
3732067
....@@ -398,7 +2092,7 @@
3982092 {
3992093 //System.err.println("Oeil on");
4002094 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2095
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022096 // object.editWindow.ScreenFit(trackedobject);
4032097 //pingthread.StepToTarget(true);
4042098 }
....@@ -407,8 +2101,8 @@
4072101 {
4082102 //System.err.println("Oeil on");
4092103 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2104
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122106 //pingthread.StepToTarget(true);
4132107 }
4142108
....@@ -471,39 +2165,12 @@
4712165 {
4722166 frozen ^= true;
4732167 // Weird...
474
- lighttouched = true;
2168
+ Globals.lighttouched = true;
4752169 }
4762170
4772171 void ToggleDL()
4782172 {
4792173 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GrafreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072174 }
5082175
5092176 void ToggleFullScreen()
....@@ -513,12 +2180,7 @@
5132180
5142181 void ToggleCrowd()
5152182 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2183
+ Globals.CROWD ^= true;
5222184 }
5232185
5242186 void ToggleLocal()
....@@ -526,62 +2188,89 @@
5262188 LOCALTRANSFORM ^= true;
5272189 }
5282190
529
- void ToggleFast()
2191
+ public void ToggleTexture()
2192
+ {
2193
+ textureon ^= true;
2194
+ }
2195
+
2196
+ public void ToggleLive()
2197
+ {
2198
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2199
+
2200
+ System.err.println("LIVE = " + Globals.isLIVE());
2201
+
2202
+ if (!Globals.isLIVE()) // save sound
2203
+ Grafreed.savesound = true; // wav.save();
2204
+ // else
2205
+ repaint(); // start loop // may 2013
2206
+ }
2207
+
2208
+ public void ToggleSupport()
2209
+ {
2210
+ SUPPORT ^= true;
2211
+ }
2212
+
2213
+ public void ToggleAbort()
2214
+ {
2215
+ ABORTMODE ^= true;
2216
+ }
2217
+
2218
+ public void ToggleInertia()
2219
+ {
2220
+ INERTIA ^= true;
2221
+ }
2222
+
2223
+ public void ToggleFast()
5302224 {
5312225 FAST ^= true;
5322226 }
5332227
534
- void ToggleSlowPose()
2228
+ public void ToggleSlowPose()
5352229 {
5362230 SLOWPOSE ^= true;
5372231 }
5382232
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2233
+ public void ToggleBoxMode()
5452234 {
5462235 BOXMODE ^= true;
5472236 }
5482237
549
- void ToggleSmoothFocus()
2238
+ public void ToggleZoomBoxMode()
2239
+ {
2240
+ ZOOMBOXMODE ^= true;
2241
+ }
2242
+
2243
+ public void ToggleSmoothFocus()
5502244 {
5512245 SMOOTHFOCUS ^= true;
5522246 }
5532247
554
- void ToggleImageFlip()
2248
+ public void ToggleImageFlip()
5552249 {
5562250 IMAGEFLIP ^= true;
5572251 }
5582252
559
- void ToggleSpeakerMocap()
2253
+ public void ToggleSpeakerMocap()
5602254 {
5612255 SPEAKERMOCAP ^= true;
5622256 }
5632257
564
- void ToggleSpeakerCamera()
2258
+ public void ToggleSpeakerCamera()
5652259 {
5662260 SPEAKERCAMERA ^= true;
5672261 }
5682262
569
- void ToggleSpeakerFocus()
2263
+ public void ToggleSpeakerFocus()
5702264 {
5712265 SPEAKERFOCUS ^= true;
5722266 }
5732267
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2268
+ public void ToggleFrustum()
5802269 {
5812270 FRUSTUM ^= true;
5822271 }
5832272
584
- void ToggleTrack()
2273
+ public void ToggleTrack()
5852274 {
5862275 TRACK ^= true;
5872276 if (TRACK)
....@@ -600,25 +2289,35 @@
6002289 repaint();
6012290 }
6022291
603
- void ToggleTrackOnce()
2292
+ public void ToggleTrackOnce()
6042293 {
6052294 TRACKONCE ^= true;
6062295 }
6072296
608
- void ToggleShadowTrack()
2297
+ public void ToggleShadowTrack()
6092298 {
6102299 SHADOWTRACK ^= true;
6112300 repaint();
6122301 }
6132302
614
- void ToggleOeil()
2303
+ public void ToggleOeil()
6152304 {
6162305 OEIL ^= true;
6172306 }
6182307
619
- void ToggleOeilOnce()
2308
+ public void ToggleOeilOnce()
6202309 {
6212310 OEILONCE ^= true;
2311
+ }
2312
+
2313
+ void ToggleFootContact()
2314
+ {
2315
+ FOOTCONTACT ^= true;
2316
+ }
2317
+
2318
+ void ToggleDebug()
2319
+ {
2320
+ Globals.DEBUG ^= true;
6222321 }
6232322
6242323 void ToggleLookAt()
....@@ -626,9 +2325,9 @@
6262325 LOOKAT ^= true;
6272326 }
6282327
629
- void ToggleRandom()
2328
+ void ToggleSwitch()
6302329 {
631
- RANDOM ^= true;
2330
+ SWITCH ^= true;
6322331 }
6332332
6342333 void ToggleHandles()
....@@ -636,10 +2335,17 @@
6362335 HANDLES ^= true;
6372336 }
6382337
2338
+ Object3D paintFolder;
2339
+
6392340 void TogglePaint()
6402341 {
6412342 PAINTMODE ^= true;
6422343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
6432349 }
6442350
6452351 void SwapCamera(int a, int b)
....@@ -672,34 +2378,6 @@
6722378 //assert (cam.hAspect == 0);
6732379 cam.hAspect = 0;
6742380 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
7032381 }
7042382
7052383 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2437,26 @@
7592437
7602438 GL currentGL;
7612439
762
- GL GetGL()
2440
+ public GL GetGL() // INTERFACE
7632441 {
7642442 return currentGL;
7652443 }
766
-
2444
+
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
7672460 /**/
7682461 class CacheTexture
7692462 {
....@@ -772,28 +2465,31 @@
7722465
7732466 int resolution;
7742467
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762469 {
777
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
7782472 resolution = res;
7792473 }
7802474 }
7812475 /**/
7822476
7832477 // TEXTURE static Texture texture;
784
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
785
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
786
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
7872483 int pigmentdepth = 0;
7882484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892485 int bumpdepth = 0;
7902486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952491
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972493 {
7982494 TextureData texturedata = null;
7992495
....@@ -812,13 +2508,34 @@
8122508 if (bump)
8132509 texturedata = ConvertBump(texturedata, false);
8142510
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172513
818
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
819
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202516
821
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
8222539 }
8232540
8242541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3608,8 @@
18913608
18923609 System.out.println("LOADING TEXTURE : " + name);
18933610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
18943613 //
18953614 if (false) // compressbit > 0)
18963615 {
....@@ -2000,10 +3719,12 @@
20003719 */
20013720 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20023721 {
3722
+ int pixelformat = texturedata.getPixelFormat();
3723
+
20033724 int stride = 1;
2004
- if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
3725
+ if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
20053726 stride = 3;
2006
- if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
3727
+ if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
20073728 stride = 4;
20083729
20093730 int width = texturedata.getWidth();
....@@ -2593,6 +4314,7 @@
25934314
25944315 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25954316 {
4317
+ new Exception().printStackTrace();
25964318 System.exit(0);
25974319 com.sun.opengl.util.texture.Texture texture = null;
25984320
....@@ -6269,7 +7991,7 @@
62697991 return null;
62707992 }
62717993
6272
- void ReleaseTextures(cTexture tex)
7994
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62737995 {
62747996 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62757997 {
....@@ -6286,7 +8008,7 @@
62868008 String pigment = Object3D.GetPigment(tex);
62878009 String bump = Object3D.GetBump(tex);
62888010
6289
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62908012 {
62918013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62928014 // System.out.println("; bump = " + bump);
....@@ -6301,13 +8023,71 @@
63018023 pigment = null;
63028024 }
63038025
6304
- ReleaseTexture(bump, true);
6305
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
63068028 }
63078029
6308
- void ReleaseTexture(String tex, boolean bump)
8030
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63098031 {
6310
- if (// drawMode != 0 || /*tex == null ||*/
8032
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8033
+ {
8034
+ return;
8035
+ }
8036
+
8037
+ if (tex == null)
8038
+ {
8039
+ ReleaseTexture(null, false);
8040
+ return;
8041
+ }
8042
+
8043
+ String pigment = Object3D.GetPigment(tex);
8044
+
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ {
8047
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8048
+ // System.out.println("; bump = " + bump);
8049
+ }
8050
+
8051
+ if (pigment.equals(""))
8052
+ {
8053
+ pigment = null;
8054
+ }
8055
+
8056
+ ReleaseTexture(tex, false);
8057
+ }
8058
+
8059
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8060
+ {
8061
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8062
+ {
8063
+ return;
8064
+ }
8065
+
8066
+ if (tex == null)
8067
+ {
8068
+ ReleaseTexture(null, true);
8069
+ return;
8070
+ }
8071
+
8072
+ String bump = Object3D.GetBump(tex);
8073
+
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ {
8076
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8077
+ // System.out.println("; bump = " + bump);
8078
+ }
8079
+
8080
+ if (bump.equals(""))
8081
+ {
8082
+ bump = null;
8083
+ }
8084
+
8085
+ ReleaseTexture(tex, true);
8086
+ }
8087
+
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
8089
+ {
8090
+ if (// DrawMode() != 0 || /*tex == null ||*/
63118091 ambientOcclusion ) // || !textureon)
63128092 {
63138093 return;
....@@ -6316,7 +8096,7 @@
63168096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63178097
63188098 if (tex != null)
6319
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63208100
63218101 // //assert( texture != null );
63228102 // if (texture == null)
....@@ -6408,9 +8188,57 @@
64088188 }
64098189 }
64108190
6411
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8191
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64128192 {
6413
- if (// drawMode != 0 || /*tex == null ||*/
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
8234
+
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
8237
+ }
8238
+
8239
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8240
+ {
8241
+ if (// DrawMode() != 0 || /*tex == null ||*/
64148242 ambientOcclusion ) // || !textureon)
64158243 {
64168244 return; // false;
....@@ -6419,17 +8247,47 @@
64198247 if (tex == null)
64208248 {
64218249 BindTexture(null,false,resolution);
6422
- BindTexture(null,true,resolution);
64238250 return;
64248251 }
64258252
64268253 String pigment = Object3D.GetPigment(tex);
8254
+
8255
+ usedtextures.add(tex);
8256
+
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ {
8259
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8260
+ // System.out.println("; bump = " + bump);
8261
+ }
8262
+
8263
+ if (pigment.equals(""))
8264
+ {
8265
+ pigment = null;
8266
+ }
8267
+
8268
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
+ BindTexture(tex, false, resolution);
8270
+ }
8271
+
8272
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8273
+ {
8274
+ if (// DrawMode() != 0 || /*tex == null ||*/
8275
+ ambientOcclusion ) // || !textureon)
8276
+ {
8277
+ return; // false;
8278
+ }
8279
+
8280
+ if (tex == null)
8281
+ {
8282
+ BindTexture(null,true,resolution);
8283
+ return;
8284
+ }
8285
+
64278286 String bump = Object3D.GetBump(tex);
64288287
6429
- usedtextures.put(pigment, pigment);
6430
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
64318289
6432
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64338291 {
64348292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64358293 // System.out.println("; bump = " + bump);
....@@ -6439,43 +8297,94 @@
64398297 {
64408298 bump = null;
64418299 }
6442
- if (pigment.equals(""))
6443
- {
6444
- pigment = null;
6445
- }
64468300
6447
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6448
- BindTexture(pigment, false, resolution);
64498301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6450
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
64518303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6452
-
6453
- return; // true;
64548304 }
64558305
6456
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8306
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8307
+
8308
+ private boolean FileExists(String tex)
64578309 {
6458
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8310
+ if (missingTextures.contains(tex))
8311
+ {
8312
+ return false;
8313
+ }
8314
+
8315
+ boolean fileExists = new File(tex).exists();
8316
+
8317
+ if (!fileExists)
8318
+ {
8319
+ // If file exists, the "new File()" is not executed sgain
8320
+ missingTextures.add(tex);
8321
+ }
8322
+
8323
+ return fileExists;
8324
+ }
8325
+
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8327
+ {
8328
+ CacheTexture texturecache = null;
64598329
64608330 if (tex != null)
64618331 {
6462
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64638334
6464
- String[] split = tex.split("Textures");
6465
- if (split.length > 1)
6466
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6467
- else
6468
- if (!texname.startsWith("/"))
6469
- texname = "/Users/nbriere/Textures/" + texname;
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
8339
+
8340
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8341
+
8342
+// String[] split = tex.split("Textures");
8343
+// if (split.length > 1)
8344
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8345
+// else
8346
+// if (!texname.startsWith("/"))
8347
+// texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (!FileExists(texname))
8349
+ {
8350
+ texname = fallbackTextureName;
8351
+ }
64708352
64718353 if (CACHETEXTURE)
6472
- texture = textures.get(texname); // TEXTURE CACHE
6473
-
6474
- TextureData texturedata = null;
6475
-
6476
- if (texture == null || texture.resolution < resolution)
64778354 {
6478
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64798388 {
64808389 assert(!bump);
64818390 // if (bump)
....@@ -6486,19 +8395,23 @@
64868395 // }
64878396 // else
64888397 // {
6489
- texture = textures.get(tex);
6490
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
64918400 {
6492
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64938402 }
8403
+ else
8404
+ new Exception().printStackTrace();
64948405 // }
64958406 } else
6496
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64978408 {
64988409 assert(bump);
6499
- texture = textures.get(tex);
6500
- if (texture == null)
6501
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
65028415 } else
65038416 {
65048417 //if (tex.equals("IMMORTAL"))
....@@ -6506,11 +8419,13 @@
65068419 // texture = GetResourceTexture("default.png");
65078420 //} else
65088421 //{
6509
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
65108423 {
6511
- texture = textures.get(tex);
6512
- if (texture == null)
6513
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
65148429 } else
65158430 {
65168431 if (textureon)
....@@ -6535,7 +8450,7 @@
65358450 }
65368451
65378452 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6538
- if (!new File(cachename).exists())
8453
+ if (!FileExists(cachename))
65398454 cachename = texname;
65408455 else
65418456 processbump = false; // don't process bump map again
....@@ -6557,7 +8472,7 @@
65578472 }
65588473
65598474 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6560
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
65618476 cachename = texname;
65628477 else
65638478 processbump = false; // don't process bump map again
....@@ -6566,20 +8481,22 @@
65668481 texturedata = GetFileTexture(cachename, processbump, resolution);
65678482
65688483
6569
- if (texturedata != null)
6570
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8484
+ if (texturedata == null)
8485
+ throw new Exception();
8486
+
8487
+ texturecache = new CacheTexture(texturedata,resolution);
65718488 //texture = GetTexture(tex, bump);
65728489 }
65738490 }
65748491 //}
65758492 }
65768493
6577
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65788495 {
65798496 //return false;
65808497
65818498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6582
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65838500 {
65848501 // String ext = "_highres";
65858502 // if (REDUCETEXTURE)
....@@ -6596,52 +8513,17 @@
65968513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65978514 if (!cachefile.exists())
65988515 {
6599
- // cache to disk
6600
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6601
- //buffers[0].
6602
-
6603
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6604
- int[] pixels = new int[bytebuf.capacity()/3];
6605
-
6606
- // squared size heuristic...
6607
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
66088517 {
6609
- for (int i=pixels.length; --i>=0;)
6610
- {
6611
- int i3 = i*3;
6612
- pixels[i] = 0xFF;
6613
- pixels[i] <<= 8;
6614
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6617
- pixels[i] <<= 8;
6618
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6619
- }
6620
-
6621
- /*
6622
- int r=0,g=0,b=0,a=0;
6623
- for (int i=0; i<width; i++)
6624
- for (int j=0; j<height; j++)
6625
- {
6626
- int index = j*width+i;
6627
- int p = pixels[index];
6628
- a = ((p>>24) & 0xFF);
6629
- r = ((p>>16) & 0xFF);
6630
- g = ((p>>8) & 0xFF);
6631
- b = (p & 0xFF);
6632
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6633
- }
6634
- /**/
6635
- int width = (int)Math.sqrt(pixels.length); // squared
6636
- int height = width;
6637
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6638
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
66398520 ImageWriter writer = null;
66408521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66418522 if (iter.hasNext()) {
66428523 writer = (ImageWriter)iter.next();
66438524 }
6644
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
66458527 try
66468528 {
66478529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6658,18 +8540,20 @@
66588540 }
66598541 }
66608542 }
6661
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
66628546 //System.out.println("Texture = " + tex);
6663
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
66648548 {
6665
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
66668550 thetex.texture.disable();
66678551 thetex.texture.dispose();
6668
- textures.remove(texname);
8552
+ textures.remove(tex);
66698553 }
66708554
6671
- texture.texturedata = texturedata;
6672
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
66738557
66748558 // newtex = true;
66758559 }
....@@ -6685,10 +8569,44 @@
66858569 }
66868570 }
66878571
6688
- return texture;
8572
+ return texturecache;
66898573 }
66908574
6691
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66928610 {
66938611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66948612
....@@ -6706,21 +8624,21 @@
67068624 return texture!=null?texture.texture:null;
67078625 }
67088626
6709
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67108628 {
67118629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67128630
67138631 return texture!=null?texture.texturedata:null;
67148632 }
67158633
6716
- boolean BindTexture(String tex, boolean bump, int resolution)
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67178635 {
67188636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67198637 {
67208638 return false;
67218639 }
67228640
6723
- boolean newtex = false;
8641
+ //boolean newtex = false;
67248642
67258643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67268644
....@@ -6752,9 +8670,75 @@
67528670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67538671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67548672
6755
- return newtex;
8673
+ return true; // Warning: not used.
67568674 }
67578675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
67588742 ShadowBuffer shadowPBuf;
67598743 AntialiasBuffer antialiasPBuf;
67608744 int MAXSTACK;
....@@ -7310,9 +9294,9 @@
73109294 static boolean occlusionInitialized = false;
73119295 boolean selection = false;
73129296 boolean pointselection = false;
7313
- /*static*/ boolean lighttouched = true;
9297
+ ///*static*/ boolean lighttouched = true;
73149298 boolean deselect;
7315
- boolean ambientOcclusion = false;
9299
+ private boolean ambientOcclusion = false;
73169300 static boolean flash = false;
73179301 /*static*/ boolean wait = false;
73189302 boolean displaydone = false; // after repaint() calls
....@@ -7442,6 +9426,8 @@
74429426 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74439427 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74449428 double scale = lightCamera.SCALE / lightCamera.Distance();
9429
+// PATCH FILLE AUX JEANS
9430
+ //scale *= lightCamera.shaper_fovy / 25;
74459431 gl.glScaled(2 * scale, 2 * scale, -scale);
74469432 gl.glTranslated(0, 0, lightCamera.DECAL);
74479433
....@@ -7588,17 +9574,40 @@
75889574 jy8[3] = 0.5f;
75899575 }
75909576
7591
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75929578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
7593
- float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
9579
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9580
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75949581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
75959606 static int imagecount = 0; // movie generation
75969607
75979608 static int jitter = 0;
75989609
75999610 boolean restartframe = false;
7600
-
7601
- static int framecount = 0; // general-purpose global count
76029611
76039612 void displayAntiAliased(javax.media.opengl.GL gl)
76049613 {
....@@ -7630,7 +9639,7 @@
76309639 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76319640 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76329641 {
7633
- framecount++;
9642
+ Globals.framecount++;
76349643
76359644 if (CameraPane.tickcount > 0)
76369645 CameraPane.tickcount--;
....@@ -7668,7 +9677,7 @@
76689677
76699678 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76709679 */
7671
- lighttouched = true;
9680
+ Globals.lighttouched = true;
76729681 //System.err.println(" shadowbuffer: " + jitter);
76739682 shadowbuffer.display();
76749683
....@@ -7689,8 +9698,8 @@
76899698 assert (parentcam != renderCamera);
76909699
76919700 if (renderCamera != lightCamera)
7692
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7693
- LA.matConcat(parentcam.toParent, matrix, matrix);
9701
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
76949703
76959704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76969705
....@@ -7705,8 +9714,8 @@
77059714 LA.matCopy(renderCamera.fromScreen, matrix);
77069715
77079716 if (renderCamera != lightCamera)
7708
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7709
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9717
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
77109719
77119720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77129721
....@@ -7778,7 +9787,7 @@
77789787 //gl.glFlush();
77799788 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77809789
7781
- if (ANIMATION && ABORTED)
9790
+ if (Globals.ANIMATION && ABORTED)
77829791 {
77839792 System.err.println(" ABORTED FRAME");
77849793 break;
....@@ -7808,7 +9817,7 @@
78089817 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78099818
78109819 // save image
7811
- if (ANIMATION && !ABORTED)
9820
+ if (Globals.ANIMATION && !ABORTED)
78129821 {
78139822 VPwidth = viewport[2];
78149823 VPheight = viewport[3];
....@@ -7919,11 +9928,11 @@
79199928
79209929 // imagecount++;
79219930
7922
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9931
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79239932
79249933 if (!BOXMODE)
79259934 {
7926
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9935
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79279936 }
79289937
79299938 if (!BOXMODE)
....@@ -7961,7 +9970,7 @@
79619970 ABORTED = false;
79629971 }
79639972 else
7964
- GrafreeD.wav.cursor += 735 * ACSIZE;
9973
+ Grafreed.wav.cursor += 735 * ACSIZE;
79659974
79669975 if (false)
79679976 {
....@@ -8615,13 +10624,6 @@
861510624 }
861610625 }
861710626
8618
- boolean IsFrozen()
8619
- {
8620
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8621
-
8622
- return !selectmode && cameracount == 0; // != 0;
8623
- }
8624
-
862510627 boolean niceon = false;
862610628 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
862710629 boolean currentlydrawing = false;
....@@ -8631,16 +10633,16 @@
863110633
863210634 public void display(GLAutoDrawable drawable)
863310635 {
8634
- if (GrafreeD.savesound && GrafreeD.hassound)
10636
+ if (Grafreed.savesound && Grafreed.hassound)
863510637 {
8636
- GrafreeD.wav.save();
8637
- GrafreeD.savesound = false;
8638
- GrafreeD.hassound = false;
10638
+ Grafreed.wav.save();
10639
+ Grafreed.savesound = false;
10640
+ Grafreed.hassound = false;
863910641 }
864010642 // if (DEBUG_SELECTION)
864110643 // {
8642
-// if (drawMode != SELECTION)
8643
-// drawMode = SELECTION;
10644
+// if (DrawMode() != SELECTION)
10645
+// DrawMode() = SELECTION;
864410646 // }
864510647
864610648 if (!isRenderer)
....@@ -8696,9 +10698,9 @@
869610698
869710699 //ANTIALIAS = 0;
869810700
8699
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10701
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870010702 {
8701
- if (niceon || isLIVE())
10703
+ if (niceon || Globals.isLIVE())
870210704 {
870310705 //if(active == 0)
870410706 // antialiaser = null;
....@@ -8711,6 +10713,7 @@
871110713 ANTIALIAS = 0;
871210714 //System.out.println("RESTART");
871310715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
871410717 }
871510718 }
871610719 }
....@@ -8723,7 +10726,7 @@
872310726 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872410727 */
872510728
8726
- if (drawMode == DEFAULT)
10729
+ if (DrawMode() == DEFAULT)
872710730 {
872810731 currentlydrawing = true;
872910732 }
....@@ -8754,18 +10757,18 @@
875410757
875510758 // if(Applet3D.clipboard != null)
875610759 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8757
-//drawMode = SELECTION;
10760
+//DrawMode() = SELECTION;
875810761 indexcount = 0;
875910762
8760
- if (drawMode == OCCLUSION)
10763
+ if (DrawMode() == OCCLUSION)
876110764 {
8762
- drawMode = DEFAULT;
10765
+ Globals.drawMode = DEFAULT; // WARNING
876310766 ambientOcclusion = true;
876410767 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876510768 Object3D theobject = object;
876610769 Object3D theparent = object.parent;
876710770 object.parent = null;
8768
- object = (Object3D)GrafreeD.clone(object);
10771
+ object = (Object3D)Grafreed.clone(object);
876910772 object.Stripify();
877010773 if (theobject.selection == null || theobject.selection.Size() == 0)
877110774 theobject.PreprocessOcclusion(this);
....@@ -8778,19 +10781,20 @@
877810781 ambientOcclusion = false;
877910782 }
878010783
8781
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878210786 {
878310787 //if (RENDERSHADOW) // ?
878410788 if (!IsFrozen())
878510789 {
878610790 // dec 2012
8787
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10791
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
878810792 {
8789
- framecount++;
10793
+ Globals.framecount++;
879010794 shadowbuffer.display();
879110795 }
879210796 }
8793
- lighttouched = false; // ??
10797
+ Globals.lighttouched = false; // ??
879410798 //drawing = true;
879510799 //lighttouched = true;
879610800 }
....@@ -8811,9 +10815,9 @@
881110815 //eyeCamera.shaper_fovy = 1;
881210816 }
881310817
8814
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10818
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881510819 {
8816
- //System.out.println("drawMode = " + drawMode);
10820
+ //System.out.println("DrawMode() = " + DrawMode());
881710821 vertexMode |= VP_PASS;
881810822 //vertexMode |= VP_PROJECTION;
881910823 if (!ambientOcclusion)
....@@ -8873,7 +10877,7 @@
887310877 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887410878 //Camera lightcam = new Camera(light0);
887510879
8876
- if (drawMode == SHADOW)
10880
+ if (DrawMode() == SHADOW)
887710881 {
887810882 /*
887910883 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8911,8 +10915,8 @@
891110915
891210916 // if (parentcam != renderCamera) // not a light
891310917 if (cam != lightCamera)
8914
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8915
- LA.matConcat(parentcam.toParent, matrix, matrix);
10918
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
891610920
891710921 for (int j = 0; j < 4; j++)
891810922 {
....@@ -8926,8 +10930,8 @@
892610930
892710931 // if (parentcam != renderCamera) // not a light
892810932 if (cam != lightCamera)
8929
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8930
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10933
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
893110935
893210936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893310937
....@@ -8963,7 +10967,7 @@
896310967 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896410968 } else
896510969 {
8966
- if (drawMode != DEFAULT)
10970
+ if (DrawMode() != DEFAULT)
896710971 {
896810972 gl.glClearColor(1, 1, 1, 0);
896910973 } // 1);
....@@ -9028,7 +11032,7 @@
902811032
902911033 fast &= !ambientOcclusion;
903011034
9031
- if (drawMode == DEFAULT)
11035
+ if (DrawMode() == DEFAULT)
903211036 {
903311037 //gl.glEnable(gl.GL_ALPHA_TEST);
903411038 //gl.glActiveTexture(GL.GL_TEXTURE0);
....@@ -9089,6 +11093,8 @@
908911093 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909011094 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909111095 double scale = lightCamera.SCALE / lightCamera.Distance();
11096
+// PATCH FILLE AUX JEANS
11097
+ //scale *= lightCamera.shaper_fovy / 25;
909211098 gl.glScaled(2 * scale, 2 * scale, -scale);
909311099 gl.glTranslated(0, 0, lightCamera.DECAL);
909411100
....@@ -9184,7 +11190,16 @@
918411190 // Bump noise
918511191 gl.glActiveTexture(GL.GL_TEXTURE6);
918611192 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9187
- BindTexture(NOISE_TEXTURE, false, 2);
11193
+
11194
+ try
11195
+ {
11196
+ BindTexture(NOISE_TEXTURE, false, 2);
11197
+ }
11198
+ catch (Exception e)
11199
+ {
11200
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11201
+ }
11202
+
918811203
918911204 gl.glActiveTexture(GL.GL_TEXTURE0);
919011205 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9207,9 +11222,9 @@
920711222
920811223 gl.glMatrixMode(GL.GL_MODELVIEW);
920911224
9210
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9211
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9212
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
921311228 } else
921411229 {
921511230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9220,14 +11235,16 @@
922011235 //System.out.println("BLENDING ON");
922111236 gl.glEnable(GL.GL_BLEND);
922211237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9223
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922411239 gl.glMatrixMode(gl.GL_PROJECTION);
922511240 gl.glLoadIdentity();
922611241
9227
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11242
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
922811243 {
922911244 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923011245 double scale = lightCamera.SCALE / lightCamera.Distance();
11246
+// PATCH FILLE AUX JEANS
11247
+ //scale *= lightCamera.shaper_fovy / 25;
923111248 gl.glScaled(2 * scale, 2 * scale, -scale);
923211249 gl.glTranslated(0, 0, lightCamera.DECAL);
923311250 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9280,7 +11297,7 @@
928011297 //gl.glPushMatrix();
928111298 gl.glLoadIdentity();
928211299
9283
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11300
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928411301 {
928511302 //LA.xformPos(light0, lightCamera.fromScreen, light);
928611303 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9307,8 +11324,8 @@
930711324 System.err.println("parentcam != renderCamera");
930811325
930911326 // if (cam != lightCamera)
9310
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9311
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11327
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
931211329 }
931311330
931411331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9329,8 +11346,8 @@
932911346 if (true) // TODO
933011347 {
933111348 if (cam != lightCamera)
9332
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9333
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11349
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11350
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933411351 }
933511352
933611353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9367,7 +11384,7 @@
936711384 }
936811385
936911386 /**/
9370
- if (true) // drawMode == SELECTION) // != DEFAULT)
11387
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937111388 gl.glDisable(gl.GL_LIGHTING);
937211389 else
937311390 gl.glEnable(gl.GL_LIGHTING);
....@@ -9379,12 +11396,13 @@
937911396
938011397 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
938111398 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11399
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
938211400
938311401 options2[0] *= renderCamera.Distance();
938411402
938511403 lightslot = 64;
938611404
9387
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11405
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
938811406 {
938911407 DrawLights(object);
939011408 }
....@@ -9395,7 +11413,7 @@
939511413 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
939611414 //System.out.println("fragmentMode = " + fragmentMode);
939711415
9398
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11416
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
939911417 {
940011418 /*
940111419 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9428,7 +11446,7 @@
942811446 }
942911447 }
943011448
9431
- if (drawMode == DEFAULT)
11449
+ if (DrawMode() == DEFAULT)
943211450 {
943311451 if (WIREFRAME && !ambientOcclusion)
943411452 {
....@@ -9446,7 +11464,7 @@
944611464 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
944711465 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
944811466
9449
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11467
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945011468 {
945111469 if (vertexMode != 0) // && !fast)
945211470 {
....@@ -9466,7 +11484,7 @@
946611484 }
946711485 }
946811486
9469
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947011488 {
947111489 //gl.glDepthFunc(GL.GL_LEQUAL);
947211490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9474,27 +11492,24 @@
947411492
947511493 boolean texon = textureon;
947611494
9477
- if (RENDERPROGRAM > 0)
9478
- {
9479
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9480
- textureon = false;
9481
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
948211498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948311499 //System.out.println("ALLO");
948411500 gl.glColorMask(false, false, false, false);
948511501 DrawObject(gl);
9486
- if (RENDERPROGRAM > 0)
9487
- {
9488
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9489
- textureon = texon;
9490
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
949111506 gl.glColorMask(true, true, true, true);
949211507
949311508 gl.glDepthFunc(GL.GL_EQUAL);
9494
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
949511510 }
949611511
9497
- if (false) // drawMode == SHADOW)
11512
+ if (false) // DrawMode() == SHADOW)
949811513 {
949911514 //SetColumnMajorData(cameraInverseTransform, view_1);
950011515 //System.out.println("light = " + cameraInverseTransform);
....@@ -9508,16 +11523,16 @@
950811523 //System.out.println("object = " + object);
950911524 if (!frozen && !imageLocked)
951011525 {
9511
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11526
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951211527 {
951311528 displayAntiAliased(gl);
951411529 } else
951511530 {
951611531 programcount = 0;
9517
- int keepmode = drawMode;
11532
+ int keepmode = DrawMode();
951811533 // if (DEBUG_SELECTION)
951911534 // {
9520
-// drawMode = SELECTION;
11535
+// DrawMode() = SELECTION;
952111536 // }
952211537 // for point selection
952311538 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9527,10 +11542,10 @@
952711542 DrawObject(gl);
952811543
952911544 // jan 2013 System.err.println("RESET ABORT (display)");
9530
- // if (drawMode == DEFAULT)
11545
+ // if (DrawMode() == DEFAULT)
953111546 // ABORTED = false;
953211547 fullreset = false;
9533
- drawMode = keepmode;
11548
+ Globals.drawMode = keepmode; // WARNING
953411549 //System.out.println("PROGRAM SWITCH " + programcount);
953511550 }
953611551 }
....@@ -9538,11 +11553,11 @@
953811553 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
953911554 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954011555
9541
- if (drawMode == DEFAULT)
11556
+ if (DrawMode() == DEFAULT)
954211557 {
954311558 ReleaseTexture(NOISE_TEXTURE, false);
954411559 }
9545
- //if (drawMode == DEFAULT)
11560
+ //if (DrawMode() == DEFAULT)
954611561 {
954711562
954811563 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9554,7 +11569,7 @@
955411569 //else
955511570 //gl.glDisable(gl.GL_TEXTURE_2D);
955611571 //gl.glPopMatrix();
9557
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11572
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
955811573 {
955911574 //new Exception().printStackTrace();
956011575 //System.out.println("Draw image " + width + ", " + height);
....@@ -9596,7 +11611,7 @@
959611611 //gl.glFlush();
959711612 }
959811613
9599
- if (flash && drawMode == DEFAULT)
11614
+ if (flash && DrawMode() == DEFAULT)
960011615 {
960111616 flash = false;
960211617 wait = true;
....@@ -9604,9 +11619,9 @@
960411619 }
960511620
960611621 //drawing = false;
9607
- //if(drawMode == DEFAULT)
11622
+ //if(DrawMode() == DEFAULT)
960811623 // niceon = false;
9609
- if (drawMode == DEFAULT)
11624
+ if (DrawMode() == DEFAULT)
961011625 {
961111626 currentlydrawing = false;
961211627 }
....@@ -9626,7 +11641,7 @@
962611641 repaint();
962711642 }
962811643
9629
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11644
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963011645 repaint();
963111646
963211647 displaydone = true;
....@@ -9645,8 +11660,14 @@
964511660 {
964611661 renderpass++;
964711662 // System.out.println("Draw object... ");
11663
+ STEP = 1;
964811664 if (FAST) // in case there is no script
9649
- STEP = 16;
11665
+ STEP = 8;
11666
+
11667
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11668
+ {
11669
+ STEP *= 4;
11670
+ }
965011671
965111672 //object.FullInvariants();
965211673
....@@ -9660,23 +11681,44 @@
966011681 e.printStackTrace();
966111682 }
966211683
9663
- if (GrafreeD.RENDERME > 0)
9664
- GrafreeD.RENDERME--; // mechante magouille
11684
+ if (Grafreed.RENDERME > 0)
11685
+ Grafreed.RENDERME--; // mechante magouille
966511686
9666
- ONESTEP = false;
11687
+ Globals.ONESTEP = false;
966711688 }
966811689
966911690 static boolean zoomonce = false;
967011691
11692
+ static void CreateSelectedPoint()
11693
+ {
11694
+ if (selectedpoint == null)
11695
+ {
11696
+ debugpointG = new Sphere();
11697
+ debugpointP = new Sphere();
11698
+ debugpointC = new Sphere();
11699
+ debugpointR = new Sphere();
11700
+
11701
+ selectedpoint = new Superellipsoid();
11702
+
11703
+ for (int i=0; i<8; i++)
11704
+ {
11705
+ debugpoints[i] = new Sphere();
11706
+ }
11707
+ }
11708
+ }
11709
+
967111710 void DrawObject(GL gl, boolean draw)
967211711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
967311715 //System.out.println("DRAW OBJECT " + mouseDown);
9674
-// drawMode = SELECTION;
11716
+// DrawMode() = SELECTION;
967511717 //GL gl = getGL();
967611718 if ((TRACK || SHADOWTRACK) || zoomonce)
967711719 {
9678
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9679
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11720
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968011722 pingthread.StepToTarget(true); // true);
968111723 // zoomonce = false;
968211724 }
....@@ -9696,9 +11738,9 @@
969611738 callist = gl.glGenLists(1);
969711739 }
969811740
9699
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11741
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970011742
9701
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11743
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970211744
970311745 if (!mainDL || !active || touched)
970411746 {
....@@ -9725,13 +11767,20 @@
972511767 PushMatrix(ClickInfo.matbuffer);
972611768 }
972711769
9728
- if (drawMode == 0)
11770
+ if (DrawMode() == 0)
972911771 {
973011772 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973111773
973211774 usedtextures.clear();
973311775
9734
- BindTextures(DEFAULT_TEXTURES, 2);
11776
+ try
11777
+ {
11778
+ BindTextures(DEFAULT_TEXTURES, 2);
11779
+ }
11780
+ catch (Exception e)
11781
+ {
11782
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11783
+ }
973511784 }
973611785 //System.out.println("--> " + stackdepth);
973711786 // GrafreeD.traceon();
....@@ -9739,10 +11788,11 @@
973911788 // DRAW
974011789 object.draw(this, /*(Composite)*/ object, false, false);
974111790
9742
- if (drawMode == DEFAULT)
11791
+ if (DrawMode() == DEFAULT)
974311792 {
9744
- if (DEBUG)
11793
+ if (Globals.DEBUG)
974511794 {
11795
+ CreateSelectedPoint();
974611796 float radius = 0.05f;
974711797 if (selectedpoint.radius != radius)
974811798 {
....@@ -9750,40 +11800,40 @@
975011800 selectedpoint.radius = radius;
975111801 selectedpoint.recalculate();
975211802 selectedpoint.material = new cMaterial();
9753
- selectedpoint.material.color = 0.25f;
11803
+ selectedpoint.material.color = 0.15f; // Yellow
975411804 selectedpoint.material.modulation = 0.75f;
975511805
9756
- debugpoint.radius = radius;
9757
- debugpoint.recalculate();
9758
- debugpoint.material = new cMaterial();
9759
- debugpoint.material.color = 0.25f;
9760
- debugpoint.material.modulation = 0.75f;
11806
+ debugpointG.radius = radius;
11807
+ debugpointG.recalculate();
11808
+ debugpointG.material = new cMaterial();
11809
+ debugpointG.material.color = 0.25f; // Green
11810
+ debugpointG.material.modulation = 0.75f;
976111811
9762
- debugpoint2.radius = radius;
9763
- debugpoint2.recalculate();
9764
- debugpoint2.material = new cMaterial();
9765
- debugpoint2.material.color = 0.75f;
9766
- debugpoint2.material.modulation = 0.75f;
11812
+ debugpointP.radius = radius;
11813
+ debugpointP.recalculate();
11814
+ debugpointP.material = new cMaterial();
11815
+ debugpointP.material.color = 0.75f; // Purple
11816
+ debugpointP.material.modulation = 0.75f;
976711817
9768
- debugpoint3.radius = radius;
9769
- debugpoint3.recalculate();
9770
- debugpoint3.material = new cMaterial();
9771
- debugpoint3.material.color = 0.5f;
9772
- debugpoint3.material.modulation = 0.75f;
11818
+ debugpointC.radius = radius;
11819
+ debugpointC.recalculate();
11820
+ debugpointC.material = new cMaterial();
11821
+ debugpointC.material.color = 0.5f; // Cyan
11822
+ debugpointC.material.modulation = 0.75f;
977311823
9774
- debugpoint4.radius = radius;
9775
- debugpoint4.recalculate();
9776
- debugpoint4.material = new cMaterial();
9777
- debugpoint4.material.color = 0f;
9778
- debugpoint4.material.modulation = 0.75f;
11824
+ debugpointR.radius = radius;
11825
+ debugpointR.recalculate();
11826
+ debugpointR.material = new cMaterial();
11827
+ debugpointR.material.color = 0f; // Red
11828
+ debugpointR.material.modulation = 0.75f;
977911829
978011830 InitPoints(radius);
978111831 }
978211832 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9783
- debugpoint.draw(this, /*(Composite)*/ null, false,false);
9784
- debugpoint2.draw(this, /*(Composite)*/ null, false,false);
9785
- debugpoint3.draw(this, /*(Composite)*/ null, false,false);
9786
- debugpoint4.draw(this, /*(Composite)*/ null, false,false);
11833
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11834
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11835
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11836
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
978711837 // DrawPoints(this);
978811838 }
978911839
....@@ -9791,42 +11841,63 @@
979111841 }
979211842 // GrafreeD.traceoff();
979311843 //System.out.println(stackdepth);
9794
- if (drawMode == 0)
11844
+ if (DrawMode() == 0)
979511845 {
979611846 ReleaseTextures(DEFAULT_TEXTURES);
979711847
979811848 if (CLEANCACHE)
9799
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
980011850 {
9801
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
980211852
980311853 // System.out.println("Texture --------- " + tex);
980411854
9805
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
980611856 continue;
980711857
9808
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
980911859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
981011861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9811
- textures.get(tex).texture.dispose();
9812
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
981311875 }
981411876 }
981511877 }
981611878
981711879 checker = null;
981811880
9819
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11881
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
982011882 FindChecker(object);
982111883
9822
- if (checker != null && drawMode == DEFAULT)
11884
+ if (checker != null && DrawMode() == DEFAULT)
982311885 {
9824
- // BindTexture(IMMORTAL_TEXTURE);
11886
+ //BindTexture(IMMORTAL_TEXTURE);
11887
+ try
11888
+ {
11889
+ BindTextures(checker.GetTextures(), checker.texres);
11890
+ }
11891
+ catch (Exception e)
11892
+ {
11893
+ System.err.println("FAILED: " + checker.GetTextures());
11894
+ }
982511895 // NEAREST
982611896 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
982711897 DrawChecker(gl);
982811898 //checker.Draw(this, null, false);
982911899 // ReleaseTexture(IMMORTAL_TEXTURE);
11900
+ ReleaseTextures(checker.GetTextures());
983011901 }
983111902
983211903 if (object.parent != null)
....@@ -9839,7 +11910,7 @@
983911910 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
984011911 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
984111912
9842
- if (DISPLAYTEXT && drawMode == DEFAULT)
11913
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
984311914 {
984411915 // Draw it once, then use the raster
984511916 Balloon(gl, balloon.createGraphics());
....@@ -9895,14 +11966,14 @@
989511966 int[] xs = new int[3];
989611967 int[] ys = new int[3];
989711968
9898
- void DrawString(Object3D obj) // String string)
11969
+ public void DrawString(Object3D obj) // String string) // INTERFACE
989911970 {
9900
- if (!DISPLAYTEXT || drawMode != DEFAULT)
11971
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
990111972 {
990211973 return;
990311974 }
990411975
9905
- String string = obj.GetToolTip();
11976
+ String string = obj.toString(); //.GetToolTip();
990611977
990711978 GL gl = GetGL();
990811979
....@@ -10219,8 +12290,8 @@
1021912290 //obj.TransformToWorld(light, light);
1022012291 for (int i = tp.size(); --i >= 0;)
1022112292 {
10222
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10223
- LA.xformPos(light, tp.get(i).toParent, light);
12293
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12294
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1022412295 }
1022512296
1022612297
....@@ -10237,8 +12308,8 @@
1023712308 parentcam = cameras[0];
1023812309 }
1023912310
10240
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10241
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12311
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12312
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1024212313
1024312314 LA.xformPos(light, renderCamera.toScreen, light);
1024412315
....@@ -10329,7 +12400,52 @@
1032912400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1033012401
1033112402 String program =
12403
+ // Min shader
1033212404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1033312449 //"OPTION ARB_fragment_program_shadow;" +
1033412450 "PARAM light2cam0 = program.env[10];" +
1033512451 "PARAM light2cam1 = program.env[11];" +
....@@ -10357,11 +12473,13 @@
1035712473 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1035812474 "PARAM params7 = program.env[7];" + // noise power, opacity power
1035912475 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10360
- "PARAM options1 = program.env[62];" + // fog rgb color, image intensity
12476
+ "PARAM options1 = program.env[62];" + // fog rgb color
12477
+ "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
1036112478 "PARAM pointlight = program.env[127];" + // ...
1036212479 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1036312480 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1036412481 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12482
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1036512483 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1036612484 "PARAM ten = { 10, 10, 10, 1.0 };" +
1036712485 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10382,6 +12500,7 @@
1038212500 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1038312501 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1038412502 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12503
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1038512504 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1038612505 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1038712506 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10422,6 +12541,10 @@
1042212541 "TEMP R1;" +
1042312542 "TEMP R2;" +
1042412543 "TEMP R3;" +
12544
+ "TEMP min;" +
12545
+ "TEMP max;" +
12546
+ "TEMP average;" +
12547
+ "TEMP saturation;" +
1042512548 "TEMP keep1;" +
1042612549 "TEMP keep2;" +
1042712550 "TEMP keep3;" +
....@@ -10437,8 +12560,7 @@
1043712560 "TEMP shininess;" +
1043812561 "\n" +
1043912562 "MOV texSamp, one;" +
10440
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10441
-
12563
+
1044212564 "MOV mapgrid.x, one2048th.x;" +
1044312565 "MOV temp, fragment.texcoord[1];" +
1044412566 /*
....@@ -10843,10 +12965,10 @@
1084312965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1084412966 "") +
1084512967
10846
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1084712969 "SUB temp.x, half.x, shadow.x;" +
10848
- "MOV temp.y, -params6.x;" +
10849
- "SLT temp.z, temp.y, zero.x;" +
12970
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12971
+ "SLT temp.z, temp.y, -one2048th.x;" +
1085012972 "SUB temp.y, one.x, temp.z;" +
1085112973 "MUL temp.x, temp.x, temp.y;" +
1085212974 "KIL temp.x;" +
....@@ -10952,10 +13074,42 @@
1095213074
1095313075 // skin?
1095413076 // Saturation for skin
10955
- /**/ // c'est ici
10956
- (Skinshader? "DP3 temp.x, final,one;" +
13077
+ /**/
13078
+ (Skinshader?
13079
+ "DP3 average.x, final,one;" +
13080
+ "MUL average, one3rd.xxxx,average.xxxx;" +
13081
+
13082
+ "MIN min.x, final.x,final.y;" +
13083
+ "MIN min.x, min.x,final.z;" +
13084
+
13085
+ "MAX max.x, final.x,final.y;" +
13086
+ "MAX max.x, max.x,final.z;" +
13087
+ "MOV max, max.xxxx;" +
13088
+
13089
+ "SUB saturation, max, final;" +
13090
+
13091
+ "ADD temp.x, max.x, one10th.x;" +
13092
+ "RCP temp.x, temp.x;" +
13093
+ "MUL temp.x, temp.x, half.x;" +
13094
+ "MUL saturation, saturation, temp.xxxx;" +
13095
+
13096
+ "DP3 ndotl.x, normald, light;" +
13097
+ "MAX ndotl.x, ndotl.x, -ndotl.x;" +
13098
+
13099
+ "SUB temp.x, one.x, ndotl.x;" +
13100
+ // Tuning for default skin
13101
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13102
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13103
+ "ADD temp.y, one.y, options2.y;" + // subsurface
13104
+ "MUL temp.x, temp.x, temp.y;" +
13105
+
13106
+ "MUL saturation, saturation, temp.xxxx;" +
13107
+ "SUB_SAT temp, max, saturation;" +
13108
+/**
13109
+ "DP3 temp.x, final,one;" +
1095713110 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10958
- "SUB temp, final,R2;" +
13111
+ "SUB temp, final, R2;" +
13112
+
1095913113 // using light angle
1096013114 "DP3 ndotl.x, normald,light;" +
1096113115 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10968,7 +13122,6 @@
1096813122 // using light intensity
1096913123 "MOV ndotl.z, R2.x;" +
1097013124 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10971
-
1097213125 // june 2014
1097313126 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1097413127 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10980,6 +13133,7 @@
1098013133 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1098113134
1098213135 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13136
+/**/
1098313137
1098413138 // "ADD final, R2,temp;" +
1098513139 "MOV final, temp;"
....@@ -11069,7 +13223,7 @@
1106913223 /**/
1107013224 // HDR
1107113225 "MOV temp.z, final.a;" +
11072
- "MUL final, final,options1.w;" +
13226
+ "MUL final, final,options2.x;" +
1107313227 "MOV final.a, temp.z;" +
1107413228 /**/
1107513229
....@@ -11145,7 +13299,7 @@
1114513299 //once = true;
1114613300 }
1114713301
11148
- System.out.print("Program #" + mode + "; length = " + program.length());
13302
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1114913303 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1115013304 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1115113305
....@@ -11243,25 +13397,26 @@
1124313397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1124413398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1124513399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1124613402 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11247
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11248
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11249
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11250
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1125113405 //"SWZ buffer, temp, w,w,w,w;";
11252
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1125313407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1125413408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1125513409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11256
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1125713411
11258
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11259
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1126013414 }
1126113415
1126213416 String Shadow(String depth, String shadow)
1126313417 {
1126413418 return "MAX temp.x, ndotl.x, one64th.x;" +
13419
+ "MIN temp.x, temp.x, ninetenth.x;" +
1126513420 /**/
1126613421 // Sine
1126713422 "MUL temp.y, temp.x, temp.x;" +
....@@ -11277,12 +13432,16 @@
1127713432
1127813433 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1127913434 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13435
+
13436
+ // Compare fragment depth in light space with shadowmap.
1128013437 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1128113438 "SGE temp.y, temp.x, zero.x;" +
11282
- "SUB " + shadow + ".y, one.x, temp.y;" +
13439
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13440
+
13441
+ // Reverse comparison
1128313442 "SUB temp.x, one.x, temp.x;" +
1128413443 "MUL " + shadow + ".x, temp.x, temp.y;" +
11285
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13444
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1128613445 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1128713446
1128813447 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11296,6 +13455,10 @@
1129613455 // No shadow for backface
1129713456 "DP3 temp.x, normal, lightd;" +
1129813457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13458
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13459
+
13460
+ // No shadow when out of frustum
13461
+ "SGE temp.x, " + depth + ".z, one.z;" +
1129913462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1130013463 "";
1130113464 }
....@@ -11442,7 +13605,8 @@
1144213605 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1144313606 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1144413607 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11445
- Object3D.cVector2[] vector2buffer;
13608
+
13609
+ //Object3D.cVector2[] vector2buffer;
1144613610
1144713611 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1144813612 // OUT : diff, spec
....@@ -11458,9 +13622,10 @@
1145813622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1145913623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1146013624 //"MOV " + dest + ".w," + "normal.z;" +
11461
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11462
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11463
- //"MOV " + dest + ".z," + "params2.w;" +
13625
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13626
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13627
+
13628
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1146413629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1146513630 "RCP " + dest + ".w," + dest + ".w;" +
1146613631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11854,7 +14019,7 @@
1185414019 public void mousePressed(MouseEvent e)
1185514020 {
1185614021 //System.out.println("mousePressed: " + e);
11857
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14022
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1185814023 }
1185914024
1186014025 static long prevtime = 0;
....@@ -11881,14 +14046,16 @@
1188114046
1188214047 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1188314048
14049
+ if (BUTTONLESSWHEEL)
1188414050 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1188514051 {
1188614052 return;
1188714053 }
1188814054
14055
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1188914056
1189014057 // TIMER
11891
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14058
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1189214059 {
1189314060 keepboxmode = BOXMODE;
1189414061 keepsupport = SUPPORT;
....@@ -11928,8 +14095,8 @@
1192814095 // mode |= META;
1192914096 //}
1193014097
11931
- SetMouseMode(WHEEL | e.getModifiersEx());
11932
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14098
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14099
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1193314100 anchorX = ax;
1193414101 anchorY = ay;
1193514102 prevX = px;
....@@ -11963,6 +14130,7 @@
1196314130 else
1196414131 if (evt.getSource() == AAtimer)
1196514132 {
14133
+ Globals.TIMERRUNNING = false;
1196614134 if (mouseDown)
1196714135 {
1196814136 //new Exception().printStackTrace();
....@@ -11988,6 +14156,10 @@
1198814156 // LIVE = waslive;
1198914157 // wasliveok = true;
1199014158 // waslive = false;
14159
+
14160
+ // May 2019 Forget it:
14161
+ if (true)
14162
+ return;
1199114163
1199214164 // source == timer
1199314165 if (mouseDown)
....@@ -12017,8 +14189,8 @@
1201714189 // ObjEditor.tweenManager.update(1f / 60f);
1201814190
1201914191 // fev 2014???
12020
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12021
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14192
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1202214194 pingthread.StepToTarget(true); // true);
1202314195 }
1202414196 // if (!LIVE)
....@@ -12027,12 +14199,13 @@
1202714199
1202814200 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1202914201
12030
- void clickStart(int x, int y, int modifiers)
14202
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1203114203 {
1203214204 if (!wasliveok)
1203314205 return;
1203414206
1203514207 AAtimer.restart(); //
14208
+ Globals.TIMERRUNNING = true;
1203614209
1203714210 // waslive = LIVE;
1203814211 // LIVE = false;
....@@ -12044,7 +14217,7 @@
1204414217 // touched = true; // main DL
1204514218 if (isRenderer)
1204614219 {
12047
- SetMouseMode(modifiers);
14220
+ SetMouseMode(modifiers, modifiersex);
1204814221 }
1204914222
1205014223 selectX = anchorX = x;
....@@ -12057,7 +14230,7 @@
1205714230 clicked = true;
1205814231 hold = false;
1205914232
12060
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14233
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1206114234 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1206214235 {
1206314236 // System.out.println("RESTART II " + modifiers);
....@@ -12082,14 +14255,15 @@
1208214255 drag = false;
1208314256 //System.out.println("Mouse DOWN");
1208414257 editObj = false;
12085
- ClickInfo info = new ClickInfo();
12086
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12087
- info.pane = this;
12088
- info.camera = renderCamera;
12089
- info.x = x;
12090
- info.y = y;
12091
- info.modifiers = modifiers;
12092
- editObj = object.doEditClick(info, 0);
14258
+ //ClickInfo info = new ClickInfo();
14259
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
+ object.clickInfo.pane = this;
14261
+ object.clickInfo.camera = renderCamera;
14262
+ object.clickInfo.x = x;
14263
+ object.clickInfo.y = y;
14264
+ object.clickInfo.modifiers = modifiersex;
14265
+ editObj = object.doEditClick(//info,
14266
+ 0);
1209314267 if (!editObj)
1209414268 {
1209514269 hasMarquee = true;
....@@ -12105,11 +14279,14 @@
1210514279
1210614280 public void mouseDragged(MouseEvent e)
1210714281 {
14282
+ Globals.MOUSEDRAGGED = true;
14283
+
14284
+ //System.out.println("mouseDragged: " + e);
1210814285 if (isRenderer)
1210914286 movingcamera = true;
14287
+
1211014288 //if (drawing)
1211114289 //return;
12112
- //System.out.println("mouseDragged: " + e);
1211314290 if ((e.getModifiersEx() & CTRL) != 0
1211414291 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1211514292 {
....@@ -12117,7 +14294,7 @@
1211714294 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1211814295 }
1211914296 else
12120
- drag(e.getX(), e.getY(), e.getModifiersEx());
14297
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1212114298
1212214299 //try { Thread.sleep(1); } catch (Exception ex) {}
1212314300 }
....@@ -12129,6 +14306,11 @@
1212914306 cVector tmp = new cVector();
1213014307 cVector tmp2 = new cVector();
1213114308 boolean isMoving;
14309
+
14310
+ public cVector TargetLookAt()
14311
+ {
14312
+ return targetLookAt;
14313
+ }
1213214314
1213314315 class PingThread extends Thread
1213414316 {
....@@ -12268,7 +14450,7 @@
1226814450 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1226914451 if (lightMode)
1227014452 {
12271
- lighttouched = true;
14453
+ Globals.lighttouched = true;
1227214454 }
1227314455
1227414456 if (OEILONCE && OEIL)
....@@ -12285,6 +14467,7 @@
1228514467
1228614468 public void run()
1228714469 {
14470
+ new Exception().printStackTrace();
1228814471 System.exit(0);
1228914472 for (;;)
1229014473 {
....@@ -12326,7 +14509,7 @@
1232614509 mouseDown = false;
1232714510 if (lightMode)
1232814511 {
12329
- lighttouched = true;
14512
+ Globals.lighttouched = true;
1233014513 }
1233114514 repaint();
1233214515 alreadypainted = true;
....@@ -12334,7 +14517,7 @@
1233414517 isMoving = false;
1233514518 } //??
1233614519
12337
- if (isLIVE() && !alreadypainted)
14520
+ if (Globals.isLIVE() && !alreadypainted)
1233814521 {
1233914522 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1234014523 repaint();
....@@ -12346,9 +14529,9 @@
1234614529 {
1234714530 if (lightMode)
1234814531 {
12349
- lighttouched = true;
14532
+ Globals.lighttouched = true;
1235014533 }
12351
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14534
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1235214535 }
1235314536 //else
1235414537 }
....@@ -12362,12 +14545,12 @@
1236214545 void GoDown(int mod)
1236314546 {
1236414547 MODIFIERS |= COMMAND;
12365
- /*
14548
+ /**/
1236614549 if((mod&SHIFT) == SHIFT)
1236714550 manipCamera.RotatePosition(0, -speed);
1236814551 else
12369
- manipCamera.BackForth(0, -speed*delta, getWidth());
12370
- */
14552
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14553
+ /**/
1237114554 if ((mod & SHIFT) == SHIFT)
1237214555 {
1237314556 mouseMode = mouseMode; // VR??
....@@ -12383,12 +14566,12 @@
1238314566 void GoUp(int mod)
1238414567 {
1238514568 MODIFIERS |= COMMAND;
12386
- /*
14569
+ /**/
1238714570 if((mod&SHIFT) == SHIFT)
1238814571 manipCamera.RotatePosition(0, speed);
1238914572 else
12390
- manipCamera.BackForth(0, speed*delta, getWidth());
12391
- */
14573
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14574
+ /**/
1239214575 if ((mod & SHIFT) == SHIFT)
1239314576 {
1239414577 mouseMode = mouseMode;
....@@ -12404,12 +14587,12 @@
1240414587 void GoLeft(int mod)
1240514588 {
1240614589 MODIFIERS |= COMMAND;
12407
- /*
14590
+ /**/
1240814591 if((mod&SHIFT) == SHIFT)
12409
- manipCamera.RotatePosition(speed, 0);
12410
- else
1241114592 manipCamera.Translate(speed*delta, 0, getWidth());
12412
- */
14593
+ else
14594
+ manipCamera.RotatePosition(speed, 0);
14595
+ /**/
1241314596 if ((mod & SHIFT) == SHIFT)
1241414597 {
1241514598 mouseMode = mouseMode;
....@@ -12425,12 +14608,12 @@
1242514608 void GoRight(int mod)
1242614609 {
1242714610 MODIFIERS |= COMMAND;
12428
- /*
14611
+ /**/
1242914612 if((mod&SHIFT) == SHIFT)
12430
- manipCamera.RotatePosition(-speed, 0);
12431
- else
1243214613 manipCamera.Translate(-speed*delta, 0, getWidth());
12433
- */
14614
+ else
14615
+ manipCamera.RotatePosition(-speed, 0);
14616
+ /**/
1243414617 if ((mod & SHIFT) == SHIFT)
1243514618 {
1243614619 mouseMode = mouseMode;
....@@ -12448,7 +14631,7 @@
1244814631 int X, Y;
1244914632 boolean SX, SY;
1245014633
12451
- void drag(int x, int y, int modifiers)
14634
+ void drag(int x, int y, int modifiers, int modifiersex)
1245214635 {
1245314636 if (IsFrozen())
1245414637 {
....@@ -12457,17 +14640,17 @@
1245714640
1245814641 drag = true; // NEW
1245914642
12460
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14643
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1246114644
1246214645 X = x;
1246314646 Y = y;
1246414647 // floating state for animation
12465
- MODIFIERS = modifiers;
12466
- modifiers &= ~1024;
14648
+ MODIFIERS = modifiersex;
14649
+ modifiersex &= ~1024;
1246714650 if (false) // modifiers != 0)
1246814651 {
1246914652 //new Exception().printStackTrace();
12470
- System.out.println("mouseDragged: " + modifiers);
14653
+ System.out.println("mouseDragged: " + modifiersex);
1247114654 System.out.println("SHIFT = " + SHIFT);
1247214655 System.out.println("CONTROL = " + COMMAND);
1247314656 System.out.println("META = " + META);
....@@ -12480,14 +14663,16 @@
1248014663 if (editObj)
1248114664 {
1248214665 drag = true;
12483
- ClickInfo info = new ClickInfo();
12484
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1248514668 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12486
- info.pane = this;
12487
- info.camera = renderCamera;
12488
- info.x = x;
12489
- info.y = y;
12490
- object.editWindow.copy.doEditDrag(info);
14669
+ object.clickInfo.pane = this;
14670
+ object.clickInfo.camera = renderCamera;
14671
+ object.clickInfo.x = x;
14672
+ object.clickInfo.y = y;
14673
+ object //.GetWindow().copy
14674
+ .doEditDrag(//info,
14675
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1249114676 } else
1249214677 {
1249314678 if (x < startX)
....@@ -12589,6 +14774,7 @@
1258914774 {
1259014775 manipCamera.Translate(dx, dy, getWidth());
1259114776 }
14777
+ else
1259214778 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1259314779 {
1259414780 manipCamera.RotateInterest(dx, dy);
....@@ -12599,7 +14785,7 @@
1259914785
1260014786 if (manipCamera == lightCamera)
1260114787 {
12602
- lighttouched = true;
14788
+ Globals.lighttouched = true;
1260314789 }
1260414790 /*
1260514791 switch (mode)
....@@ -12635,23 +14821,27 @@
1263514821 }
1263614822 }
1263714823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1263814826 public void mouseMoved(MouseEvent e)
1263914827 {
1264014828 //System.out.println("mouseMoved: " + e);
12641
-
1264214829 if (isRenderer)
1264314830 return;
1264414831
12645
- ClickInfo ci = new ClickInfo();
12646
- ci.x = e.getX();
12647
- ci.y = e.getY();
12648
- ci.modifiers = e.getModifiersEx();
12649
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12650
- ci.pane = this;
12651
- ci.camera = renderCamera;
14832
+ // Mouse cursor feedback
14833
+ object.clickInfo.x = e.getX();
14834
+ object.clickInfo.y = e.getY();
14835
+ object.clickInfo.modifiers = e.getModifiersEx();
14836
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14837
+ object.clickInfo.pane = this;
14838
+ object.clickInfo.camera = renderCamera;
1265214839 if (!isRenderer)
1265314840 {
12654
- if (object.editWindow.copy.doEditClick(ci, 0))
14841
+ //ObjEditor editWindow = object.editWindow;
14842
+ //Object3D copy = editWindow.copy;
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1265514845 {
1265614846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1265714847 } else
....@@ -12663,7 +14853,11 @@
1266314853
1266414854 public void mouseReleased(MouseEvent e)
1266514855 {
14856
+ Globals.MOUSEDRAGGED = false;
14857
+
1266614858 movingcamera = false;
14859
+ X = 0; // getBounds().width/2;
14860
+ Y = 0; // getBounds().height/2;
1266714861 //System.out.println("mouseReleased: " + e);
1266814862 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1266914863 }
....@@ -12686,9 +14880,9 @@
1268614880 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1268714881 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1268814882
12689
- if (control || command || IsFrozen())
14883
+// No delay if (control || command || IsFrozen())
1269014884 timeout = true;
12691
- else
14885
+// ?? May 2019 else
1269214886 // timer.setDelay((modifiers & 128) != 0?0:350);
1269314887 mouseDown = false;
1269414888 if (!control && !command) // june 2013
....@@ -12798,7 +14992,7 @@
1279814992 System.out.println("keyReleased: " + e);
1279914993 }
1280014994
12801
- void SetMouseMode(int modifiers)
14995
+ void SetMouseMode(int modifiers, int modifiersex)
1280214996 {
1280314997 //System.out.println("SetMouseMode = " + modifiers);
1280414998 //modifiers &= ~1024;
....@@ -12810,24 +15004,27 @@
1281015004 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1281115005 // return;
1281215006 //System.out.println("SetMode = " + modifiers);
12813
- if ((modifiers & WHEEL) == WHEEL)
15007
+ if ((modifiersex & WHEEL) == WHEEL)
1281415008 {
1281515009 mouseMode |= ZOOM;
1281615010 }
12817
- if ((modifiers & META) == META)
15011
+
15012
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15013
+ if (capsLocked) // || (modifiers & META) == META)
1281815014 {
1281915015 mouseMode |= VR; // BACKFORTH;
1282015016 }
12821
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12822
- {
12823
- mouseMode |= SELECT; // BACKFORTH;
12824
- }
12825
- if ((modifiers & COMMAND) == COMMAND)
15017
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1282615018 {
1282715019 mouseMode |= SELECT;
1282815020 }
12829
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15021
+ if ((modifiersex & COMMAND) == COMMAND)
1283015022 {
15023
+ mouseMode |= SELECT;
15024
+ }
15025
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15026
+ {
15027
+ mouseMode &= ~VR;
1283115028 mouseMode |= TRANSLATE;
1283215029 }
1283315030 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12854,10 +15051,10 @@
1285415051
1285515052 if (isRenderer) //
1285615053 {
12857
- SetMouseMode(modifiers);
15054
+ SetMouseMode(0, modifiers);
1285815055 }
1285915056
12860
- theRenderer.keyPressed(key);
15057
+ Globals.theRenderer.keyPressed(key);
1286115058 }
1286215059
1286315060 int kompactbit = 4; // power bit
....@@ -12869,7 +15066,7 @@
1286915066 float SATPOW = 1; // 2; // 0.5f;
1287015067 float BRIPOW = 1; // 0.5f; // 0.5f;
1287115068
12872
- void keyPressed(int key)
15069
+ public void keyPressed(int key)
1287315070 {
1287415071 if (key >= '0' && key <= '5')
1287515072 clampbit = (key-'0');
....@@ -12916,7 +15113,8 @@
1291615113 // break;
1291715114 case 'T':
1291815115 CACHETEXTURE ^= true;
12919
- textures.clear();
15116
+ texturepigment.clear();
15117
+ texturebump.clear();
1292015118 // repaint();
1292115119 break;
1292215120 case 'Y':
....@@ -12984,7 +15182,7 @@
1298415182 case 'B':
1298515183 BRISMOOTH ^= true;
1298615184 SHADOWCULLFACE ^= true;
12987
- lighttouched = true;
15185
+ Globals.lighttouched = true;
1298815186 repaint();
1298915187 break;
1299015188 case 'b':
....@@ -13001,7 +15199,9 @@
1300115199 case 'E' : COMPACT ^= true;
1300215200 repaint();
1300315201 break;
13004
- case 'W' : DEBUGHSB ^= true;
15202
+ case 'W' : // Wide Window (fullscreen)
15203
+ //DEBUGHSB ^= true;
15204
+ ObjEditor.theFrame.ToggleFullScreen();
1300515205 repaint();
1300615206 break;
1300715207 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13026,8 +15226,8 @@
1302615226 RevertCamera();
1302715227 repaint();
1302815228 break;
13029
- case 'L':
1303015229 case 'l':
15230
+ //case 'L':
1303115231 if (lightMode)
1303215232 {
1303315233 lightMode = false;
....@@ -13084,7 +15284,7 @@
1308415284 repaint();
1308515285 break;
1308615286 case 'O':
13087
- drawMode = OCCLUSION;
15287
+ Globals.drawMode = OCCLUSION; // WARNING
1308815288 repaint();
1308915289 break;
1309015290 case 'o':
....@@ -13170,12 +15370,12 @@
1317015370 case '_':
1317115371 kompactbit = 5;
1317215372 break;
13173
- case '+':
13174
- kompactbit = 6;
13175
- break;
15373
+// case '+':
15374
+// kompactbit = 6;
15375
+// break;
1317615376 case ' ':
1317715377 lightMode ^= true;
13178
- lighttouched = true;
15378
+ Globals.lighttouched = true;
1317915379 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1318015380 targetLookAt.set(manipCamera.lookAt);
1318115381 repaint();
....@@ -13184,14 +15384,15 @@
1318415384 case ESC:
1318515385 RENDERPROGRAM += 1;
1318615386 RENDERPROGRAM %= 3;
15387
+
1318715388 repaint();
1318815389 break;
1318915390 case 'Z':
13190
- RESIZETEXTURE ^= true;
13191
- break;
15391
+ //RESIZETEXTURE ^= true;
15392
+ //break;
1319215393 case 'z':
13193
- RENDERSHADOW ^= true;
13194
- lighttouched = true;
15394
+ Globals.RENDERSHADOW ^= true;
15395
+ Globals.lighttouched = true;
1319515396 repaint();
1319615397 break;
1319715398 //case UP:
....@@ -13217,13 +15418,15 @@
1321715418 FlipTransform();
1321815419 break;
1321915420 case ENTER:
13220
- object.editWindow.ScreenFit(); // Edit();
15421
+ // object.editWindow.ScreenFit(); // Edit();
15422
+ ToggleLive();
1322115423 break;
1322215424 case DELETE:
1322315425 ClearSelection();
1322415426 break;
13225
- /*
1322615427 case '+':
15428
+
15429
+ /*
1322715430 //fontsize += 1;
1322815431 bbzoom *= 2;
1322915432 repaint();
....@@ -13240,17 +15443,17 @@
1324015443 case '=':
1324115444 IncDepth();
1324215445 //fontsize += 1;
13243
- object.editWindow.refreshContents(true);
15446
+ object.GetWindow().refreshContents(true);
1324415447 maskbit = 6;
1324515448 break;
1324615449 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1324715450 DecDepth();
1324815451 maskbit = 5;
1324915452 //if(fontsize > 1) fontsize -= 1;
13250
- if (object.editWindow == null)
13251
- new Exception().printStackTrace();
13252
- else
13253
- object.editWindow.refreshContents(true);
15453
+// if (object.editWindow == null)
15454
+// new Exception().printStackTrace();
15455
+// else
15456
+ object.GetWindow().refreshContents(true);
1325415457 break;
1325515458 case '{':
1325615459 manipCamera.shaper_fovy /= 1.1;
....@@ -13305,6 +15508,7 @@
1330515508 }
1330615509 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1330715510 }
15511
+
1330815512 static double OCCLUSIONBOOST = 1; // 0.5;
1330915513
1331015514 void keyReleased(int key, int modifiers)
....@@ -13312,11 +15516,11 @@
1331215516 //mode = ROTATE;
1331315517 if ((MODIFIERS & COMMAND) == 0) // VR??
1331415518 {
13315
- SetMouseMode(modifiers);
15519
+ SetMouseMode(0, modifiers);
1331615520 }
1331715521 }
1331815522
13319
- protected void processKeyEvent(KeyEvent e)
15523
+ public void processKeyEvent(KeyEvent e)
1332015524 {
1332115525 switch (e.getID())
1332215526 {
....@@ -13446,8 +15650,9 @@
1344615650
1344715651 protected void processMouseMotionEvent(MouseEvent e)
1344815652 {
13449
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13450
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15653
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15654
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15655
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1345115656 {
1345215657 mouseMoved(e);
1345315658 } else
....@@ -13472,11 +15677,12 @@
1347215677 }
1347315678 */
1347415679
13475
- object.editWindow.EditSelection();
15680
+ object.GetWindow().EditSelection(false);
1347615681 }
1347715682
1347815683 void SelectParent()
1347915684 {
15685
+ new Exception().printStackTrace();
1348015686 System.exit(0);
1348115687 Composite group = (Composite) object;
1348215688 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13488,10 +15694,10 @@
1348815694 {
1348915695 //selectees.remove(i);
1349015696 System.out.println("select parent of " + elem);
13491
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15697
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1349215698 } else
1349315699 {
13494
- group.editWindow.Select(elem.GetTreePath(), first, true);
15700
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1349515701 }
1349615702
1349715703 first = false;
....@@ -13500,6 +15706,7 @@
1350015706
1350115707 void SelectChildren()
1350215708 {
15709
+ new Exception().printStackTrace();
1350315710 System.exit(0);
1350415711 /*
1350515712 Composite group = (Composite) object;
....@@ -13532,12 +15739,12 @@
1353215739 for (int j = 0; j < group.children.size(); j++)
1353315740 {
1353415741 elem = (Object3D) group.children.elementAt(j);
13535
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1353615743 first = false;
1353715744 }
1353815745 } else
1353915746 {
13540
- object.editWindow.Select(elem.GetTreePath(), first, true);
15747
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1354115748 }
1354215749
1354315750 first = false;
....@@ -13548,21 +15755,21 @@
1354815755 {
1354915756 //Composite group = (Composite) object;
1355015757 Object3D group = object;
13551
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15758
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1355215759 }
1355315760
1355415761 void ResetTransform(int mask)
1355515762 {
1355615763 //Composite group = (Composite) object;
1355715764 Object3D group = object;
13558
- group.editWindow.ResetTransform(mask);
15765
+ group.GetWindow().ResetTransform(mask);
1355915766 }
1356015767
1356115768 void FlipTransform()
1356215769 {
1356315770 //Composite group = (Composite) object;
1356415771 Object3D group = object;
13565
- group.editWindow.FlipTransform();
15772
+ group.GetWindow().FlipTransform();
1356615773 // group.editWindow.ReduceMesh(true);
1356715774 }
1356815775
....@@ -13570,7 +15777,7 @@
1357015777 {
1357115778 //Composite group = (Composite) object;
1357215779 Object3D group = object;
13573
- group.editWindow.PrintMemory();
15780
+ group.GetWindow().PrintMemory();
1357415781 // group.editWindow.ReduceMesh(true);
1357515782 }
1357615783
....@@ -13578,7 +15785,7 @@
1357815785 {
1357915786 //Composite group = (Composite) object;
1358015787 Object3D group = object;
13581
- group.editWindow.ResetCentroid();
15788
+ group.GetWindow().ResetCentroid();
1358215789 }
1358315790
1358415791 void IncDepth()
....@@ -13660,11 +15867,11 @@
1366015867
1366115868 int width = getBounds().width;
1366215869 int height = getBounds().height;
13663
- ClickInfo info = new ClickInfo();
13664
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1366515870 //Image img = CreateImage(width, height);
1366615871 //System.out.println("width = " + width + "; height = " + height + "\n");
15872
+
1366715873 Graphics gr = g; // img.getGraphics();
15874
+
1366815875 if (!hasMarquee)
1366915876 {
1367015877 if (Xmin < Xmax) // !locked)
....@@ -13736,40 +15943,88 @@
1373615943 }
1373715944 if (object != null && !hasMarquee)
1373815945 {
15946
+ if (object.clickInfo == null)
15947
+ object.clickInfo = new ClickInfo();
15948
+ ClickInfo info = object.clickInfo;
15949
+ //ClickInfo info = new ClickInfo();
15950
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15951
+
1373915952 if (isRenderer)
1374015953 {
13741
- info.flags++;
15954
+ object.clickInfo.flags++;
1374215955 double frameAspect = (double) width / (double) height;
1374315956 if (frameAspect > renderCamera.aspect)
1374415957 {
1374515958 int desired = (int) ((double) height * renderCamera.aspect);
13746
- info.bounds.width -= width - desired;
13747
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1374815961 } else
1374915962 {
1375015963 int desired = (int) ((double) width / renderCamera.aspect);
13751
- info.bounds.height -= height - desired;
13752
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1375315966 }
1375415967 }
13755
- info.g = gr;
13756
- info.camera = renderCamera;
15968
+
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1375715971 /*
1375815972 // Memory intensive (brep.verticescopy)
1375915973 if (!(object instanceof Composite))
1376015974 object.draw(info, 0, false); // SLOW :
1376115975 */
13762
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1376315977 {
13764
- object.drawEditHandles(info, 0);
15978
+ Grafreed.Assert(object != null);
15979
+ Grafreed.Assert(object.selection != null);
15980
+ if (object.selection.Size() > 0)
15981
+ {
15982
+ int hitSomething = object.selection.get(0).hitSomething;
15983
+
15984
+ object.clickInfo.DX = 0;
15985
+ object.clickInfo.DY = 0;
15986
+ object.clickInfo.W = 1;
15987
+ if (hitSomething == Object3D.hitCenter)
15988
+ {
15989
+ info.DX = X;
15990
+ if (X != 0)
15991
+ info.DX -= info.bounds.width/2;
15992
+
15993
+ info.DY = Y;
15994
+ if (Y != 0)
15995
+ info.DY -= info.bounds.height/2;
15996
+ }
15997
+
15998
+ object.drawEditHandles(//info,
15999
+ 0);
16000
+
16001
+ if (drag && (X != 0 || Y != 0))
16002
+ {
16003
+ switch (hitSomething)
16004
+ {
16005
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16006
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16007
+ break;
16008
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16009
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16010
+ break;
16011
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16012
+ gr.drawLine(X, Y, 0, 0);
16013
+ break;
16014
+ }
16015
+
16016
+ }
16017
+ }
1376516018 }
1376616019 }
16020
+
1376716021 if (isRenderer)
1376816022 {
1376916023 //gr.setColor(Color.black);
1377016024 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1377116025 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1377216026 }
16027
+
1377316028 if (hasMarquee)
1377416029 {
1377516030 gr.setXORMode(Color.white);
....@@ -13792,6 +16047,7 @@
1379216047 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1379316048 }
1379416049
16050
+ // To avoid clear.
1379516051 public void update(Graphics g)
1379616052 {
1379716053 paint(g);
....@@ -13881,6 +16137,7 @@
1388116137 public boolean mouseDown(Event evt, int x, int y)
1388216138 {
1388316139 System.out.println("mouseDown: " + evt);
16140
+ System.exit(0);
1388416141 /*
1388516142 locked = true;
1388616143 drag = false;
....@@ -13924,7 +16181,7 @@
1392416181 {
1392516182 keyPressed(0, modifiers);
1392616183 }
13927
- clickStart(x, y, modifiers);
16184
+ // clickStart(x, y, modifiers);
1392816185 return true;
1392916186 }
1393016187
....@@ -14042,7 +16299,7 @@
1404216299 {
1404316300 keyReleased(0, 0);
1404416301 }
14045
- drag(x, y, modifiers);
16302
+ drag(x, y, 0, modifiers);
1404616303 return true;
1404716304 }
1404816305
....@@ -14174,7 +16431,7 @@
1417416431 Object3D object;
1417516432 static Object3D trackedobject;
1417616433 Camera renderCamera; // Light or Eye (or Occlusion)
14177
- /*static*/ Camera manipCamera; // Light or Eye
16434
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1417816435 /*static*/ Camera eyeCamera;
1417916436 /*static*/ Camera lightCamera;
1418016437 int cameracount;
....@@ -14394,7 +16651,7 @@
1439416651 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1439516652 gl.glPushMatrix();
1439616653 gl.glLoadIdentity();
14397
- PushMatrix(checker.toParent);
16654
+ //PushMatrix(checker.toParent);
1439816655
1439916656 gl.glMatrixMode(GL.GL_TEXTURE);
1440016657 gl.glPushMatrix();
....@@ -14417,8 +16674,8 @@
1441716674
1441816675 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1441916676
14420
- float step = 0.1666f; //0.25f;
14421
- float stepv = step * 1652 / 998;
16677
+ float step = 2; // 0.1666f; //0.25f;
16678
+ float stepv = 2; // step * 1652 / 998;
1442216679
1442316680 int i0 = 0;
1442416681 /*
....@@ -14454,20 +16711,21 @@
1445416711 /**/
1445516712 //checker.GetMaterial().opacity = 1.1f;
1445616713 ////checker.GetMaterial().ambient = 0.99f;
14457
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14458
- Object3D.selectedstack[Object3D.materialdepth] = false;
14459
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16714
+ materialstack[materialdepth] = checker.material;
16715
+ selectedstack[materialdepth] = false;
16716
+ cStatic.objectstack[materialdepth++] = checker;
1446016717 //System.out.println("material " + material);
1446116718 //Applet3D.tracein(this, selected);
14462
- vector2buffer = checker.projectedVertices;
16719
+ //vector2buffer = checker.projectedVertices;
1446316720
14464
- checker.GetMaterial().Draw(this, false); // true);
16721
+ //checker.GetMaterial().Draw(this, false); // true);
16722
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1446516723
14466
- Object3D.materialdepth -= 1;
14467
- if (Object3D.materialdepth > 0)
16724
+ materialdepth -= 1;
16725
+ if (materialdepth > 0)
1446816726 {
14469
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14470
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16727
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16728
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1447116729 }
1447216730 //checker.GetMaterial().opacity = 1f;
1447316731 ////checker.GetMaterial().ambient = 1f;
....@@ -14488,15 +16746,27 @@
1448816746
1448916747 //float u = (i+1)/2;
1449016748 //float v = (j+1)/2;
14491
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16749
+ if (checker.flipV)
16750
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16751
+ else
16752
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1449216753 gl.glVertex3f(i, j, -0.5f);
1449316754
16755
+ if (checker.flipV)
16756
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16757
+ else
1449416758 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1449516759 gl.glVertex3f(i + step, j, -0.5f);
1449616760
16761
+ if (checker.flipV)
16762
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16763
+ else
1449716764 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1449816765 gl.glVertex3f(i + step, j + stepv, -0.5f);
1449916766
16767
+ if (checker.flipV)
16768
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16769
+ else
1450016770 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1450116771 gl.glVertex3f(i, j + stepv, -0.5f);
1450216772 }
....@@ -14508,7 +16778,7 @@
1450816778 gl.glMatrixMode(GL.GL_PROJECTION);
1450916779 gl.glPopMatrix();
1451016780 gl.glMatrixMode(GL.GL_MODELVIEW);
14511
- PopMatrix(null); // checker.toParent); // null);
16781
+ //PopMatrix(null); // checker.toParent); // null);
1451216782 gl.glPopMatrix();
1451316783 PopTextureMatrix(checker.toParent);
1451416784 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14541,6 +16811,14 @@
1454116811 }
1454216812 }
1454316813
16814
+ private Object3D GetFolder()
16815
+ {
16816
+ Object3D folder = object.GetWindow().copy;
16817
+ if (object.GetWindow().copy.selection.Size() > 0)
16818
+ folder = object.GetWindow().copy.selection.elementAt(0);
16819
+ return folder;
16820
+ }
16821
+
1454416822 class SelectBuffer implements GLEventListener
1454516823 {
1454616824
....@@ -14599,6 +16877,7 @@
1459916877 {
1460016878 if (!selection)
1460116879 {
16880
+ new Exception().printStackTrace();
1460216881 System.exit(0);
1460316882 return;
1460416883 }
....@@ -14619,17 +16898,39 @@
1461916898
1462016899 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1462116900
16901
+ if (PAINTMODE)
16902
+ {
16903
+ if (object.GetWindow().copy.selection.Size() > 0)
16904
+ {
16905
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16906
+
16907
+ // Make what you paint not selectable.
16908
+ paintobj.ResetSelectable();
16909
+ }
16910
+ }
16911
+
1462216912 //int tmp = selection_view;
1462316913 //selection_view = -1;
14624
- int temp = drawMode;
14625
- drawMode = SELECTION;
16914
+ int temp = DrawMode();
16915
+ Globals.drawMode = SELECTION; // WARNING
1462616916 indexcount = 0;
1462716917 parent.display(drawable);
1462816918 //selection_view = tmp;
1462916919 //if (temp == SELECTION)
1463016920 // temp = DEFAULT; // patch for selection debug
14631
- drawMode = temp;
16921
+ Globals.drawMode = temp; // WARNING
1463216922
16923
+ if (PAINTMODE)
16924
+ {
16925
+ if (object.GetWindow().copy.selection.Size() > 0)
16926
+ {
16927
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16928
+
16929
+ // Revert.
16930
+ paintobj.RestoreSelectable();
16931
+ }
16932
+ }
16933
+
1463316934 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1463416935
1463516936 // trying different ways of getting the depth info over
....@@ -14678,6 +16979,13 @@
1467816979 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1467916980 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1468016981
16982
+ CreateSelectedPoint();
16983
+
16984
+ // Will fit the mesh !!!
16985
+ selectedpoint.toParent[0][0] = 0.0001;
16986
+ selectedpoint.toParent[1][1] = 0.0001;
16987
+ selectedpoint.toParent[2][2] = 0.0001;
16988
+
1468116989 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1468216990
1468316991 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14721,34 +17029,36 @@
1472117029 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]));
1472217030 }
1472317031
14724
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17032
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1472517033 }
1472617034 }
1472717035
1472817036 if (!movingcamera && !PAINTMODE)
14729
- object.editWindow.ScreenFitPoint(); // fev 2014
17037
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1473017038
14731
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17039
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1473217040 {
14733
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17041
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1473417042
14735
- Object3D group = new Object3D("inst" + paintcount++);
17043
+ if (object.GetWindow().copy.selection.Size() > 0)
17044
+ {
17045
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1473617046
14737
- group.CreateMaterial(); // use a void leaf to select instances
14738
-
14739
- group.add(paintobj); // link
14740
-
14741
- object.editWindow.SnapObject(group);
14742
-
14743
- Object3D folder = object.editWindow.copy;
14744
-
14745
- if (object.editWindow.copy.selection.Size() > 0)
14746
- folder = object.editWindow.copy.selection.elementAt(0);
14747
-
14748
- folder.add(group);
14749
-
14750
- object.editWindow.ResetModel();
14751
- object.editWindow.refreshContents();
17047
+ Object3D inst = new Object3D("inst" + paintcount++);
17048
+
17049
+ inst.CreateMaterial(); // use a void leaf to select instances
17050
+
17051
+ inst.add(paintobj); // link
17052
+
17053
+ object.GetWindow().SnapObject(inst);
17054
+
17055
+ Object3D folder = paintFolder; // GetFolder();
17056
+
17057
+ folder.add(inst);
17058
+
17059
+ object.GetWindow().ResetModel();
17060
+ object.GetWindow().refreshContents();
17061
+ }
1475217062 }
1475317063 else
1475417064 paintcount = 0;
....@@ -14787,6 +17097,11 @@
1478717097 //System.out.println("objects[color] = " + objects[color]);
1478817098 //objects[color].Select();
1478917099 indexcount = 0;
17100
+ ObjEditor window = object.GetWindow();
17101
+ if (window != null && deselect)
17102
+ {
17103
+ window.Select(null, deselect, true);
17104
+ }
1479017105 object.Select(color, deselect);
1479117106 }
1479217107
....@@ -14886,7 +17201,7 @@
1488617201 gl.glDisable(gl.GL_CULL_FACE);
1488717202 }
1488817203
14889
- if (!RENDERSHADOW)
17204
+ if (!Globals.RENDERSHADOW)
1489017205 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1489117206
1489217207 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14896,14 +17211,14 @@
1489617211 //gl.glColorMask(false, false, false, false);
1489717212
1489817213 //render_scene_from_light_view(gl, drawable, 0, 0);
14899
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17214
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1490017215 {
1490117216 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1490217217
14903
- int temp = drawMode;
14904
- drawMode = SHADOW;
17218
+ int temp = DrawMode();
17219
+ Globals.drawMode = SHADOW; // WARNING
1490517220 parent.display(drawable);
14906
- drawMode = temp;
17221
+ Globals.drawMode = temp; // WARNING
1490717222 }
1490817223
1490917224 gl.glCullFace(gl.GL_BACK);
....@@ -14956,7 +17271,6 @@
1495617271
1495717272 class AntialiasBuffer implements GLEventListener
1495817273 {
14959
-
1496017274 CameraPane parent = null;
1496117275
1496217276 AntialiasBuffer(CameraPane p)
....@@ -15066,13 +17380,19 @@
1506617380 gl.glFlush();
1506717381
1506817382 /**/
15069
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17383
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
1507017384
15071
- int[] pixels = occlusionsizebuffer.array();
17385
+ float[] pixels = occlusionsizebuffer.array();
1507217386
1507317387 double r = 0, g = 0, b = 0;
1507417388
1507517389 double count = 0;
17390
+
17391
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17392
+
17393
+ float mindepth = 1;
17394
+
17395
+ double FACTOR = 1;
1507617396
1507717397 for (int i = 0; i < pixels.length; i++)
1507817398 {
....@@ -15157,7 +17477,7 @@
1515717477
1515817478 double scale = ray.z; // 1; // cos
1515917479
15160
- int p = pixels[newindex];
17480
+ float depth = pixels[newindex];
1516117481
1516217482 /*
1516317483 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15181,10 +17501,23 @@
1518117501 scale = (1 - modu) * modv;
1518217502 */
1518317503
15184
- r += ((p >> 16) & 0xFF) * scale / 255;
15185
- g += ((p >> 8) & 0xFF) * scale / 255;
15186
- b += (p & 0xFF) * scale / 255;
17504
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17505
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17506
+ //b += (p & 0xFF) * scale / 255;
17507
+
17508
+ if (mindepth > depth)
17509
+ {
17510
+ mindepth = depth;
17511
+ }
1518717512
17513
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17514
+
17515
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17516
+
17517
+ r += factor * scale;
17518
+ g += factor * scale;
17519
+ b += factor * scale;
17520
+
1518817521 count += scale;
1518917522 }
1519017523
....@@ -15282,12 +17615,6 @@
1528217615 GLUT glut = new GLUT();
1528317616
1528417617
15285
- static final public int DEFAULT = 0;
15286
- static final public int SELECTION = 1;
15287
- static final public int SHADOW = 2;
15288
- static final public int OCCLUSION = 3;
15289
- static
15290
- public int drawMode = DEFAULT;
1529117618 public boolean spherical = false;
1529217619 static boolean DEBUG_OCCLUSION = false;
1529317620 static boolean DEBUG_SELECTION = false;
....@@ -15300,23 +17627,15 @@
1530017627 int AAbuffersize = 0;
1530117628
1530217629 //double[] selectedpoint = new double[3];
15303
- static Sphere selectedpoint = new Sphere();
17630
+ static Superellipsoid selectedpoint;
1530417631 static Sphere previousselectedpoint = null;
15305
- static Sphere debugpoint = new Sphere();
15306
- static Sphere debugpoint2 = new Sphere();
15307
- static Sphere debugpoint3 = new Sphere();
15308
- static Sphere debugpoint4 = new Sphere();
17632
+ static Sphere debugpointG;
17633
+ static Sphere debugpointP;
17634
+ static Sphere debugpointC;
17635
+ static Sphere debugpointR;
1530917636
1531017637 static Sphere debugpoints[] = new Sphere[8];
1531117638
15312
- static
15313
- {
15314
- for (int i=0; i<8; i++)
15315
- {
15316
- debugpoints[i] = new Sphere();
15317
- }
15318
- }
15319
-
1532017639 static void InitPoints(float radius)
1532117640 {
1532217641 for (int i=0; i<8; i++)
....@@ -15336,7 +17655,7 @@
1533617655 }
1533717656 }
1533817657
15339
- static void DrawPoints(CameraPane cpane)
17658
+ static void DrawPoints(iCameraPane cpane)
1534017659 {
1534117660 for (int i=0; i<8; i++) // first and last are red
1534217661 {
....@@ -15358,7 +17677,8 @@
1535817677 static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1535917678 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1536017679 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15361
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17680
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17681
+ static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
1536217682 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1536317683 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1536417684 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15367,10 +17687,11 @@
1536717687 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1536817688 // Depth buffer format
1536917689 //private int depth_format;
15370
- static public void NextIndex(Object3D o, GL gl)
17690
+
17691
+ public void NextIndex()
1537117692 {
1537217693 indexcount+=16;
15373
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17694
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1537417695 //objects[indexcount] = o;
1537517696 //System.out.println("indexcount = " + indexcount);
1537617697 }