Normand Briere
2019-07-27 1af7d3700724834e40ad8636bc9a56cdc3b19b15
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,13 @@
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;
174195 }
175196
176197 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -185,7 +206,8 @@
185206
186207 SetCamera(cam);
187208
188
- SetLight(new Camera(new cVector(10, 10, -20)));
209
+ // Warning: not used.
210
+ SetLight(new Camera(new cVector(15, 10, -20)));
189211
190212 object = o;
191213
....@@ -206,12 +228,53 @@
206228 return CURRENTANTIALIAS > 0;
207229 }
208230
209
- void ClearDepth()
231
+ /// INTERFACE
232
+
233
+ public javax.media.opengl.GL GetGL0()
234
+ {
235
+ return null;
236
+ }
237
+
238
+ public int GenList()
239
+ {
240
+ javax.media.opengl.GL gl = GetGL();
241
+ return gl.glGenLists(1);
242
+ }
243
+
244
+ public void NewList(int id)
245
+ {
246
+ javax.media.opengl.GL gl = GetGL();
247
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
248
+ }
249
+
250
+ public void CallList(int id)
251
+ {
252
+ javax.media.opengl.GL gl = GetGL();
253
+ gl.glCallList(id);
254
+ }
255
+
256
+ public void EndList()
257
+ {
258
+ javax.media.opengl.GL gl = GetGL();
259
+ gl.glEndList();
260
+ }
261
+
262
+ public boolean IsBoxMode()
263
+ {
264
+ return BOXMODE;
265
+ }
266
+
267
+ public boolean IsZoomBoxMode()
268
+ {
269
+ return ZOOMBOXMODE;
270
+ }
271
+
272
+ public void ClearDepth()
210273 {
211274 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
212275 }
213276
214
- void DepthTest(boolean depthtest)
277
+ public void DepthTest(boolean depthtest)
215278 {
216279 if (depthtest)
217280 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -219,7 +282,7 @@
219282 GetGL().glDepthFunc(GL.GL_ALWAYS);
220283 }
221284
222
- void DepthWrite(boolean depthwrite)
285
+ public void DepthWrite(boolean depthwrite)
223286 {
224287 if (depthwrite)
225288 GetGL().glDepthMask(true);
....@@ -227,12 +290,1616 @@
227290 GetGL().glDepthMask(false);
228291 }
229292
230
- void BackFaceCull(boolean bfc)
293
+ public void BackFaceCull(boolean bfc)
231294 {
232295 if (bfc)
233296 GetGL().glEnable(GetGL().GL_CULL_FACE);
234297 else
235298 GetGL().glDisable(GetGL().GL_CULL_FACE);
299
+ }
300
+
301
+ public boolean BackFaceCullMode()
302
+ {
303
+ return this.CULLFACE;
304
+ }
305
+
306
+ public boolean IsAmbientOcclusionOn()
307
+ {
308
+ return this.ambientOcclusion;
309
+ }
310
+
311
+ public boolean IsDebugSelection()
312
+ {
313
+ return DEBUG_SELECTION;
314
+ }
315
+
316
+ public boolean IsFrozen()
317
+ {
318
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
319
+
320
+ return !selectmode && cameracount == 0; // != 0;
321
+ }
322
+
323
+ // Currently in Globals
324
+ public int DrawMode()
325
+ {
326
+ return Globals.DrawMode();
327
+ }
328
+
329
+ public Camera EyeCamera()
330
+ {
331
+ return eyeCamera;
332
+ }
333
+
334
+ public Camera LightCamera()
335
+ {
336
+ return lightCamera;
337
+ }
338
+
339
+ public Camera ManipCamera()
340
+ {
341
+ return manipCamera;
342
+ }
343
+
344
+ public Camera RenderCamera()
345
+ {
346
+ return renderCamera;
347
+ }
348
+
349
+ public Camera[] Cameras()
350
+ {
351
+ return cameras;
352
+ }
353
+
354
+ public void PushMaterial(Object3D obj, boolean selected)
355
+ {
356
+ CameraPane display = this;
357
+ javax.media.opengl.GL gl = display.GetGL();
358
+ cMaterial material = obj.material;
359
+
360
+ if (material != null)
361
+ {
362
+ materialstack[materialdepth] = material;
363
+ selectedstack[materialdepth] = selected;
364
+ cStatic.objectstack[materialdepth++] = obj;
365
+ //System.out.println("material " + material);
366
+ //Applet3D.tracein(this, selected);
367
+ //display.vector2buffer = obj.projectedVertices;
368
+ if (obj instanceof Camera)
369
+ {
370
+ display.options1[0] = material.shift;
371
+ //System.out.println("shift " + material.shift);
372
+ display.options1[1] = material.lightarea;
373
+ display.options1[2] = material.shadowbias;
374
+ display.options1[3] = material.aniso;
375
+ display.options1[4] = material.anisoV;
376
+// System.out.println("display.options1[0] " + display.options1[0]);
377
+// System.out.println("display.options1[1] " + display.options1[1]);
378
+// System.out.println("display.options1[2] " + display.options1[2]);
379
+// System.out.println("display.options1[3] " + display.options1[3]);
380
+// System.out.println("display.options1[4] " + display.options1[4]);
381
+ display.options2[0] = material.opacity;
382
+ display.options2[1] = material.diffuse;
383
+ display.options2[2] = material.factor;
384
+// System.out.println("display.options2[0] " + display.options2[0]);
385
+// System.out.println("display.options2[1] " + display.options2[1]);
386
+// System.out.println("display.options2[2] " + display.options2[2]);
387
+
388
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
389
+// System.out.println("display.options3[0] " + display.options3[0]);
390
+// System.out.println("display.options3[1] " + display.options3[1]);
391
+// System.out.println("display.options3[2] " + display.options3[2]);
392
+ display.options4[0] = material.cameralight/0.2f;
393
+ display.options4[1] = material.subsurface;
394
+ display.options4[2] = material.sheen;
395
+// System.out.println("display.options4[0] " + display.options4[0]);
396
+// System.out.println("display.options4[1] " + display.options4[1]);
397
+// System.out.println("display.options4[2] " + display.options4[2]);
398
+
399
+ // if (display.CURRENTANTIALIAS > 0)
400
+ // display.options3[3] /= 4;
401
+
402
+ /*
403
+ System.out.println("Focus = " + display.options1[0]);
404
+ System.out.println("Aperture = " + display.options1[1]);
405
+ System.out.println("ShadowBlur = " + display.options1[2]);
406
+ System.out.println("Antialiasing = " + display.options1[3]);
407
+ System.out.println("Fog = " + display.options2[0]);
408
+ System.out.println("Intensity = " + display.options2[1]);
409
+ System.out.println("Elevation = " + display.options2[2]);
410
+ /**/
411
+ } else
412
+ {
413
+ DrawMaterial(material, selected, obj.projectedVertices);
414
+ }
415
+ } else
416
+ {
417
+ if (selected && CameraPane.flash)
418
+ {
419
+ display.modelParams4[1] = 100;
420
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
421
+ }
422
+ }
423
+ }
424
+
425
+ public void PushMaterial2(Object3D obj, boolean selected)
426
+ {
427
+ CameraPane display = this;
428
+ cMaterial material = obj.material;
429
+
430
+ if (material != null)
431
+ {
432
+ materialstack[materialdepth] = material;
433
+ selectedstack[materialdepth] = selected;
434
+ cStatic.objectstack[materialdepth++] = obj;
435
+ //System.out.println("material " + material);
436
+ //Applet3D.tracein("selected ", selected);
437
+ //display.vector2buffer = obj.projectedVertices;
438
+ display.DrawMaterial(material, selected, obj.projectedVertices);
439
+ }
440
+ }
441
+
442
+ public void PopMaterial(Object3D obj, boolean selected)
443
+ {
444
+ CameraPane display = this;
445
+ javax.media.opengl.GL gl = display.GetGL();
446
+ cMaterial material = obj.material;
447
+
448
+ //if (parent != null && parent.GetMaterial() != null)
449
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
450
+ if (material != null)
451
+ {
452
+ materialdepth -= 1;
453
+ if (materialdepth > 0)
454
+ {
455
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
456
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
457
+ }
458
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
459
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
460
+ {
461
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
462
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
463
+ }
464
+ }
465
+
466
+ public void PopMaterial2(Object3D obj)
467
+ {
468
+ CameraPane display = this;
469
+ cMaterial material = obj.material;
470
+
471
+ if (material != null)
472
+ {
473
+ materialdepth -= 1;
474
+ if (materialdepth > 0)
475
+ {
476
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
477
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
478
+ }
479
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
480
+ //else
481
+ //material.Draw(display, false);
482
+ }
483
+ }
484
+
485
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
486
+ {
487
+ CameraPane display = this;
488
+
489
+ if (pv.y == -10000 ||
490
+ qv.y == -10000 ||
491
+ rv.y == -10000)
492
+ return;
493
+
494
+// float b = f.nbiterations & 1;
495
+// float g = (f.nbiterations>>1) & 1;
496
+// float r = (f.nbiterations>>2) & 1;
497
+//
498
+// //if (f.weight == 10000)
499
+// //{
500
+// // r = 1; g = b = 0;
501
+// //}
502
+// //else
503
+// //{
504
+// // assert(f.weight < 10000);
505
+// r = g = b = (float)bRep.FaceWeight(f)*100;
506
+// if (r<0)
507
+// assert(r>=0);
508
+// //}
509
+
510
+ javax.media.opengl.GL gl = display.GetGL();
511
+
512
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
513
+
514
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
515
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
516
+ {
517
+ //gl.glBegin(gl.GL_TRIANGLES);
518
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
519
+ // TEST LIVE NORMALS && !obj.dontselect
520
+ ;
521
+ if (!hasnorm)
522
+ {
523
+ // System.out.println("Mesh normal");
524
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
525
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
526
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
527
+ LA.vecNormalize(obj.v2);
528
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
529
+ }
530
+
531
+ // P
532
+ float x = (float)pv.x;
533
+ float y = (float)pv.y;
534
+ float z = (float)pv.z;
535
+
536
+ if (hasnorm)
537
+ {
538
+// if (!pv.norm.normalized())
539
+// assert(pv.norm.normalized());
540
+
541
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
542
+ float nx = (float)pv.norm.x;
543
+ float ny = (float)pv.norm.y;
544
+ float nz = (float)pv.norm.z;
545
+
546
+ x += nx * obj.NORMALPUSH;
547
+ y += ny * obj.NORMALPUSH;
548
+ z += nz * obj.NORMALPUSH;
549
+
550
+ gl.glNormal3f(nx, ny, nz);
551
+ }
552
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
553
+ SetColor(obj, pv);
554
+ //gl.glColor4f(r, g, b, 1);
555
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
556
+ if (obj.flipV)
557
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
558
+ else
559
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
560
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
561
+
562
+ gl.glVertex3f(x, y, z);
563
+
564
+ // Q
565
+ x = (float)qv.x;
566
+ y = (float)qv.y;
567
+ z = (float)qv.z;
568
+
569
+// Print(pv);
570
+ if (hasnorm)
571
+ {
572
+// assert(qv.norm.normalized());
573
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
574
+ float nx = (float)qv.norm.x;
575
+ float ny = (float)qv.norm.y;
576
+ float nz = (float)qv.norm.z;
577
+
578
+ x += nx * obj.NORMALPUSH;
579
+ y += ny * obj.NORMALPUSH;
580
+ z += nz * obj.NORMALPUSH;
581
+
582
+ gl.glNormal3f(nx, ny, nz);
583
+ }
584
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
585
+ // boolean locked = false;
586
+ // float eps = 0.1f;
587
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
588
+
589
+ // int dot = 0; //*/ (int)f.dot;
590
+
591
+ // if ((dot&1) == 0)
592
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
593
+
594
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
595
+ if (obj.flipV)
596
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
597
+ else
598
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
599
+ // else
600
+ // {
601
+ // locked = true;
602
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
603
+ // }
604
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
605
+ SetColor(obj, qv);
606
+
607
+ gl.glVertex3f(x, y, z);
608
+ //gl.glColor4f(r, g, b, 1);
609
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
610
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
611
+// Print(qv);
612
+
613
+ // R
614
+ x = (float)rv.x;
615
+ y = (float)rv.y;
616
+ z = (float)rv.z;
617
+
618
+ if (hasnorm)
619
+ {
620
+// assert(rv.norm.normalized());
621
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
622
+ float nx = (float)rv.norm.x;
623
+ float ny = (float)rv.norm.y;
624
+ float nz = (float)rv.norm.z;
625
+
626
+ x += nx * obj.NORMALPUSH;
627
+ y += ny * obj.NORMALPUSH;
628
+ z += nz * obj.NORMALPUSH;
629
+
630
+ gl.glNormal3f(nx, ny, nz);
631
+ }
632
+
633
+ // if ((dot&4) == 0)
634
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
635
+
636
+ // if (wrap || !locked && (dot&8) != 0)
637
+ if (obj.flipV)
638
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
639
+ else
640
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
641
+ // else
642
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
643
+
644
+ // f.dot = dot;
645
+
646
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
647
+ SetColor(obj, rv);
648
+ //gl.glColor4f(r, g, b, 1);
649
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
650
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
651
+ gl.glVertex3f(x, y, z);
652
+// Print(rv);
653
+ //gl.glEnd();
654
+ }
655
+ else
656
+ {
657
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
658
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
659
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
660
+
661
+ }
662
+
663
+ if (false) // (attributes & WIREFRAME) != 0)
664
+ {
665
+ gl.glDisable(gl.GL_LIGHTING);
666
+
667
+ gl.glBegin(gl.GL_LINE_LOOP);
668
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
669
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
670
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
671
+ gl.glEnd();
672
+
673
+ gl.glEnable(gl.GL_LIGHTING);
674
+ }
675
+ }
676
+
677
+ /**
678
+ * <code>draw</code> renders a <code>TriMesh</code> object including
679
+ * it's normals, colors, textures and vertices.
680
+ *
681
+ * @see Renderer#draw(TriMesh)
682
+ * @param tris
683
+ * the mesh to render.
684
+ */
685
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
686
+ {
687
+ CameraPane display = this;
688
+
689
+ float r = display.modelParams0[0];
690
+ float g = display.modelParams0[1];
691
+ float b = display.modelParams0[2];
692
+ float opacity = display.modelParams5[1];
693
+
694
+ //final GL gl = GLU.getCurrentGL();
695
+ GL gl = display.GetGL(); // getGL();
696
+
697
+ FloatBuffer vertBuf = geo.vertBuf;
698
+
699
+ int v = vertBuf.capacity();
700
+
701
+ int count = 0;
702
+
703
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
704
+ gl.glEnable(gl.GL_CULL_FACE);
705
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
706
+ for (int i=0; i<v/3; i++)
707
+ {
708
+ int index3 = i*3;
709
+
710
+ if (geo.sizeBuf.get(index3+1) == 0)
711
+ continue;
712
+
713
+ count++;
714
+
715
+ int index4 = i*4;
716
+
717
+ float tx = vertBuf.get(index3);
718
+ float ty = vertBuf.get(index3+1);
719
+ float tz = vertBuf.get(index3+2);
720
+
721
+ // if (tx == 0 && ty == 0 && tz == 0)
722
+ // continue;
723
+
724
+ gl.glMatrixMode(gl.GL_TEXTURE);
725
+ gl.glPushMatrix();
726
+
727
+ float[] texmat = geo.texmat;
728
+ texmat[12] = texmat[13] = texmat[14] = i;
729
+
730
+ gl.glMultMatrixf(texmat, 0);
731
+
732
+ gl.glMatrixMode(gl.GL_MODELVIEW);
733
+ gl.glPushMatrix();
734
+
735
+ gl.glTranslatef(tx,ty,tz);
736
+
737
+ if (rotate)
738
+ gl.glRotatef(i, 0, 1, 0);
739
+
740
+ float size = geo.sizeBuf.get(index3) / 100;
741
+ gl.glScalef(size,size,size);
742
+
743
+ float cr = geo.colorBuf.get(index4);
744
+ float cg = geo.colorBuf.get(index4+1);
745
+ float cb = geo.colorBuf.get(index4+2);
746
+ float ca = geo.colorBuf.get(index4+3);
747
+
748
+ display.modelParams0[0] = r * cr;
749
+ display.modelParams0[1] = g * cg;
750
+ display.modelParams0[2] = b * cb;
751
+
752
+ display.modelParams5[1] = opacity * ca;
753
+
754
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
755
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
756
+
757
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
758
+ RandomNode.globalseed2 = RandomNode.globalseed;
759
+
760
+// gl.glColor4f(cr,cg,cb,ca);
761
+ // gl.glScalef(1024/16,1024/16,1024/16);
762
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
763
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
764
+ //gl.glTranslatef(-tx,-ty,-tz);
765
+ gl.glPopMatrix();
766
+
767
+ gl.glMatrixMode(gl.GL_TEXTURE);
768
+ gl.glPopMatrix();
769
+ }
770
+ // gl.glScalef(1024,1024,1024);
771
+ if (!cf)
772
+ gl.glDisable(gl.GL_CULL_FACE);
773
+
774
+ display.modelParams0[0] = r;
775
+ display.modelParams0[1] = g;
776
+ display.modelParams0[2] = b;
777
+
778
+ display.modelParams5[1] = opacity;
779
+
780
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
781
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
782
+
783
+ gl.glMatrixMode(gl.GL_MODELVIEW);
784
+
785
+// System.err.println("total = " + v/3 + "; displayed = " + count);
786
+ if (true)
787
+ return;
788
+
789
+//// if (!tris.predraw(this))
790
+//// {
791
+//// return;
792
+//// }
793
+//// if (Debug.stats)
794
+//// {
795
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
796
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
797
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
798
+//// }
799
+////
800
+//// if (tris.getDisplayListID() != -1)
801
+//// {
802
+//// renderDisplayList(tris);
803
+//// return;
804
+//// }
805
+////
806
+//// if (!generatingDisplayList)
807
+//// {
808
+//// applyStates(tris.states, tris);
809
+//// }
810
+//// if (Debug.stats)
811
+//// {
812
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
813
+//// }
814
+//// boolean transformed = doTransforms(tris);
815
+//
816
+// int glMode = GL.GL_TRIANGLES;
817
+// switch (getMode())
818
+// {
819
+// case Triangles:
820
+// glMode = GL.GL_TRIANGLES;
821
+// break;
822
+// case Strip:
823
+// glMode = GL.GL_TRIANGLE_STRIP;
824
+// break;
825
+// case Fan:
826
+// glMode = GL.GL_TRIANGLE_FAN;
827
+// break;
828
+// }
829
+//
830
+// if (!predrawGeometry(gl))
831
+// {
832
+// // make sure only the necessary indices are sent through on old
833
+// // cards.
834
+// IntBuffer indices = this.getIndexBuffer();
835
+// if (indices == null)
836
+// {
837
+// logger.severe("missing indices on geometry object: " + this.toString());
838
+// } else
839
+// {
840
+// indices.rewind();
841
+// indices.limit(this.getMaxIndex());
842
+//
843
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
844
+//
845
+// indices.clear();
846
+// }
847
+// } else
848
+// {
849
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
850
+// GL.GL_UNSIGNED_INT, 0);
851
+// }
852
+//
853
+//// postdrawGeometry(tris);
854
+//// if (transformed)
855
+//// {
856
+//// undoTransforms(tris);
857
+//// }
858
+////
859
+//// if (Debug.stats)
860
+//// {
861
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
862
+//// }
863
+//// tris.postdraw(this);
864
+ }
865
+
866
+ static Camera localcamera = new Camera();
867
+ static cVector from = new cVector();
868
+ static cVector to = new cVector();
869
+
870
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
871
+ {
872
+ CameraPane cp = this;
873
+
874
+ Camera keep = cp.RenderCamera();
875
+ cp.renderCamera = localcamera;
876
+
877
+ if (br.trimmed)
878
+ {
879
+ float[] colors = new float[br.positions.length / 3];
880
+
881
+ int i3 = 0;
882
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
883
+ {
884
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
885
+ continue;
886
+
887
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
888
+ to.set(br.positions[i3] + br.normals[i3],
889
+ br.positions[i3 + 1] + br.normals[i3 + 1],
890
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
891
+ LA.xformPos(from, transform, from);
892
+ LA.xformPos(to, transform, to); // RIGID ONLY
893
+ localcamera.setAim(from, to);
894
+
895
+ CameraPane.occlusionbuffer.display();
896
+
897
+ if (CameraPane.DEBUG_OCCLUSION)
898
+ cp.display(); // debug
899
+
900
+ colors[i] = cp.vertexOcclusion.r;
901
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
902
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
903
+
904
+ if ((i % 100) == 0 && i != 0)
905
+ {
906
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
907
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
908
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
909
+ }
910
+ }
911
+
912
+ br.colors = colors;
913
+ }
914
+ else
915
+ {
916
+ for (int i = 0; i < br.VertexCount(); i++)
917
+ {
918
+ Vertex v = br.GetVertex(i);
919
+
920
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
921
+ continue;
922
+
923
+ from.set(v.x, v.y, v.z);
924
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
925
+ LA.xformPos(from, transform, from);
926
+ LA.xformPos(to, transform, to); // RIGID ONLY
927
+ localcamera.setAim(from, to);
928
+
929
+ CameraPane.occlusionbuffer.display();
930
+
931
+ if (CameraPane.DEBUG_OCCLUSION)
932
+ cp.display(); // debug
933
+
934
+ v.AO = cp.vertexOcclusion.r;
935
+
936
+ if ((i % 100) == 0 && i != 0)
937
+ {
938
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
939
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
940
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
941
+ }
942
+ }
943
+ }
944
+
945
+ //System.out.println("done.");
946
+
947
+ cp.renderCamera = keep;
948
+ }
949
+
950
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
951
+ {
952
+ CameraPane display = this;
953
+ pointFlow.CreateHT();
954
+
955
+ float r = display.modelParams0[0];
956
+ float g = display.modelParams0[1];
957
+ float b = display.modelParams0[2];
958
+ float opacity = display.modelParams5[1];
959
+
960
+ //final GL gl = GLU.getCurrentGL();
961
+ GL gl = display.GetGL(); // getGL();
962
+
963
+ int s = pointFlow.points.size();
964
+
965
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
966
+ gl.glEnable(gl.GL_CULL_FACE);
967
+
968
+ for (int i=s; --i>=0;)
969
+ //for (int i=0; i<s; i++)
970
+ {
971
+ cVector v = pointFlow.points.get(i);
972
+
973
+ double mindist = Double.MAX_VALUE;
974
+
975
+ double size = pointFlow.minimumSize;
976
+
977
+ double distancenext = 0;
978
+
979
+ if (i > 0)
980
+ {
981
+ cVector w = pointFlow.points.get(i-1);
982
+
983
+ double dist = w.distance(v);
984
+
985
+ distancenext = dist;
986
+
987
+ if (mindist > dist)
988
+ {
989
+ mindist = dist;
990
+ size = mindist*pointFlow.resizefactor;
991
+ }
992
+ }
993
+
994
+ if (i < s-1)
995
+ {
996
+ cVector w = pointFlow.points.get(i+1);
997
+
998
+ double dist = w.distance(v);
999
+
1000
+ if (mindist > dist)
1001
+ {
1002
+ mindist = dist;
1003
+ size = mindist*pointFlow.resizefactor;
1004
+ }
1005
+ }
1006
+
1007
+ if (size < pointFlow.minimumSize)
1008
+ size = pointFlow.minimumSize;
1009
+ if (size > pointFlow.maximumSize)
1010
+ size = pointFlow.maximumSize;
1011
+
1012
+ double tx = v.x;
1013
+ double ty = v.y;
1014
+ double tz = v.z;
1015
+
1016
+ // if (tx == 0 && ty == 0 && tz == 0)
1017
+ // continue;
1018
+
1019
+ gl.glMatrixMode(gl.GL_TEXTURE);
1020
+ gl.glPushMatrix();
1021
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1022
+
1023
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1024
+
1025
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1026
+ gl.glPushMatrix();
1027
+
1028
+ gl.glTranslated(tx,ty,tz);
1029
+
1030
+ gl.glScaled(size,size,size);
1031
+
1032
+// float cr = colorBuf.get(index4);
1033
+// float cg = colorBuf.get(index4+1);
1034
+// float cb = colorBuf.get(index4+2);
1035
+// float ca = colorBuf.get(index4+3);
1036
+//
1037
+// display.modelParams0[0] = r * cr;
1038
+// display.modelParams0[1] = g * cg;
1039
+// display.modelParams0[2] = b * cb;
1040
+//
1041
+// display.modelParams5[1] = opacity * ca;
1042
+//
1043
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1044
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1045
+//
1046
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1047
+// RandomNode.globalseed2 = RandomNode.globalseed;
1048
+//
1049
+//// gl.glColor4f(cr,cg,cb,ca);
1050
+// // gl.glScalef(1024/16,1024/16,1024/16);
1051
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1052
+
1053
+ gl.glPopMatrix();
1054
+
1055
+ double step = size/4; //
1056
+
1057
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1058
+ continue;
1059
+
1060
+ int nbsteps = (int)(distancenext/step);
1061
+
1062
+ step = distancenext/nbsteps;
1063
+
1064
+ cVector next = pointFlow.points.get(i-1);
1065
+
1066
+ tmp.set(next);
1067
+ tmp.sub(v);
1068
+ tmp.normalize();
1069
+ tmp.mul(step);
1070
+
1071
+ // calculate next size
1072
+ mindist = Double.MAX_VALUE;
1073
+
1074
+ double nextsize = pointFlow.minimumSize;
1075
+
1076
+ if (i > 1)
1077
+ {
1078
+ cVector w = pointFlow.points.get(i-2);
1079
+
1080
+ double dist = w.distance(next);
1081
+
1082
+ if (mindist > dist)
1083
+ {
1084
+ mindist = dist;
1085
+ nextsize = mindist*pointFlow.resizefactor;
1086
+ }
1087
+ }
1088
+
1089
+ double dist = v.distance(next);
1090
+
1091
+ if (mindist > dist)
1092
+ {
1093
+ mindist = dist;
1094
+ nextsize = mindist*pointFlow.resizefactor;
1095
+ }
1096
+
1097
+ if (nextsize < pointFlow.minimumSize)
1098
+ nextsize = pointFlow.minimumSize;
1099
+ if (nextsize > pointFlow.maximumSize)
1100
+ nextsize = pointFlow.maximumSize;
1101
+ //
1102
+
1103
+ double count = 0;
1104
+
1105
+ while (distancenext > 0.000000001) // step
1106
+ {
1107
+ gl.glPushMatrix();
1108
+
1109
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1110
+
1111
+ double K = count/nbsteps;
1112
+
1113
+ double intersize = K*nextsize + (1-K)*size;
1114
+
1115
+ gl.glScaled(intersize,intersize,intersize);
1116
+
1117
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1118
+
1119
+ count++;
1120
+
1121
+ distancenext -= step;
1122
+
1123
+ gl.glPopMatrix();
1124
+ }
1125
+
1126
+ if (count != nbsteps)
1127
+ assert(count == nbsteps);
1128
+
1129
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1130
+ //gl.glTranslatef(-tx,-ty,-tz);
1131
+
1132
+ gl.glMatrixMode(gl.GL_TEXTURE);
1133
+ gl.glPopMatrix();
1134
+ }
1135
+
1136
+ if (!cf)
1137
+ gl.glDisable(gl.GL_CULL_FACE);
1138
+
1139
+// display.modelParams0[0] = r;
1140
+// display.modelParams0[1] = g;
1141
+// display.modelParams0[2] = b;
1142
+//
1143
+// display.modelParams5[1] = opacity;
1144
+//
1145
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1146
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1147
+
1148
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1149
+ }
1150
+
1151
+ public void DrawBox(cVector min, cVector max)
1152
+ {
1153
+ javax.media.opengl.GL gl = GetGL();
1154
+ gl.glBegin(gl.GL_LINES);
1155
+
1156
+ gl.glVertex3d(min.x, min.y, min.z);
1157
+ gl.glVertex3d(min.x, min.y, max.z);
1158
+ gl.glVertex3d(min.x, min.y, min.z);
1159
+ gl.glVertex3d(min.x, max.y, min.z);
1160
+ gl.glVertex3d(min.x, min.y, min.z);
1161
+ gl.glVertex3d(max.x, min.y, min.z);
1162
+
1163
+ gl.glVertex3d(max.x, max.y, max.z);
1164
+ gl.glVertex3d(min.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, max.y, max.z);
1166
+ gl.glVertex3d(max.x, min.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, max.z);
1168
+ gl.glVertex3d(max.x, max.y, min.z);
1169
+
1170
+ gl.glEnd();
1171
+ }
1172
+
1173
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1174
+ {
1175
+ int[] strips = bRep.getRawIndices();
1176
+
1177
+ javax.media.opengl.GL gl = GetGL();
1178
+
1179
+ // TRIANGLE STRIP ARRAY
1180
+ if (bRep.trimmed)
1181
+ {
1182
+ float[] v = bRep.getRawVertices();
1183
+ float[] n = bRep.getRawNormals();
1184
+ float[] c = bRep.getRawColors();
1185
+ float[] uv = bRep.getRawUVMap();
1186
+
1187
+ int count2 = 0;
1188
+ int count3 = 0;
1189
+
1190
+ if (n.length > 0)
1191
+ {
1192
+ for (int i = 0; i < strips.length; i++)
1193
+ {
1194
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1195
+
1196
+ /*
1197
+ boolean locked = false;
1198
+ float eps = 0.1f;
1199
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1200
+
1201
+ int dot = 0;
1202
+
1203
+ if ((dot&1) == 0)
1204
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1205
+
1206
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1207
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1208
+ else
1209
+ {
1210
+ locked = true;
1211
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1212
+ }
1213
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1214
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1215
+ if (hasnorm)
1216
+ {
1217
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1218
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1219
+ }
1220
+
1221
+ if ((dot&4) == 0)
1222
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1223
+
1224
+ if (wrap || !locked && (dot&8) != 0)
1225
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1226
+ else
1227
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1228
+
1229
+ f.dot = dot;
1230
+ */
1231
+
1232
+ if (!selectmode)
1233
+ {
1234
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1235
+ {
1236
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1237
+ } else
1238
+ {
1239
+ gl.glNormal3f(0, 0, 1);
1240
+ }
1241
+
1242
+ if (c != null)
1243
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1244
+ {
1245
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1246
+ }
1247
+ }
1248
+
1249
+ if (flipV)
1250
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1251
+ else
1252
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1253
+
1254
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1255
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1256
+
1257
+ count2 += 2;
1258
+ count3 += 3;
1259
+ if (!selectmode)
1260
+ {
1261
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1262
+ {
1263
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1264
+ } else
1265
+ {
1266
+ gl.glNormal3f(0, 0, 1);
1267
+ }
1268
+ if (c != null)
1269
+ {
1270
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1271
+ }
1272
+ }
1273
+
1274
+ if (flipV)
1275
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1276
+ else
1277
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1278
+
1279
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1280
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1281
+
1282
+ count2 += 2;
1283
+ count3 += 3;
1284
+ for (int j = 0; j < strips[i] - 2; j++)
1285
+ {
1286
+ //gl.glTexCoord2d(...);
1287
+ if (!selectmode)
1288
+ {
1289
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1290
+ {
1291
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1292
+ } else
1293
+ {
1294
+ gl.glNormal3f(0, 0, 1);
1295
+ }
1296
+ if (c != null)
1297
+ {
1298
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1299
+ }
1300
+ }
1301
+
1302
+ if (flipV)
1303
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1304
+ else
1305
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1306
+
1307
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1308
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1309
+
1310
+ count2 += 2;
1311
+ count3 += 3;
1312
+ }
1313
+
1314
+ gl.glEnd();
1315
+ }
1316
+ }
1317
+
1318
+ assert count3 == v.length;
1319
+ }
1320
+ else // !trimmed
1321
+ {
1322
+ int count = 0;
1323
+ for (int i = 0; i < strips.length; i++)
1324
+ {
1325
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1326
+
1327
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1328
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1329
+
1330
+ drawVertex(gl, p, flipV, selectmode);
1331
+ drawVertex(gl, q, flipV, selectmode);
1332
+
1333
+ for (int j = 0; j < strips[i] - 2; j++)
1334
+ {
1335
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1336
+
1337
+ // if (j%2 == 0)
1338
+ // drawFace(p, q, r, display, null);
1339
+ // else
1340
+ // drawFace(p, r, q, display, null);
1341
+
1342
+ // p = q;
1343
+ // q = r;
1344
+ drawVertex(gl, r, flipV, selectmode);
1345
+ }
1346
+
1347
+ gl.glEnd();
1348
+ }
1349
+ }
1350
+ }
1351
+
1352
+ static cSpring.Point3D temp = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1354
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1355
+
1356
+ public void DrawDynamicMesh(cMesh mesh)
1357
+ {
1358
+ GL gl = GetGL(); // getGL();
1359
+
1360
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1361
+
1362
+ gl.glDisable(gl.GL_LIGHTING);
1363
+
1364
+ gl.glLineWidth(1);
1365
+ gl.glColor3f(1,1,1);
1366
+ gl.glBegin(gl.GL_LINES);
1367
+ double scale = 0;
1368
+ int count = 0;
1369
+ for (int s=0; s<Phys.allSprings.size(); s++)
1370
+ {
1371
+ cSpring.Spring spring = Phys.allSprings.get(s);
1372
+ if(s == 0)
1373
+ {
1374
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1375
+ }
1376
+ if (mesh.showsprings)
1377
+ {
1378
+ temp.set(spring.a.position);
1379
+ temp.add(spring.b.position);
1380
+ temp.mul(0.5);
1381
+ temp2.set(spring.a.position);
1382
+ temp2.sub(spring.b.position);
1383
+ temp2.mul(spring.restLength/2);
1384
+ temp.sub(temp2);
1385
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1386
+ temp.add(temp2);
1387
+ temp.add(temp2);
1388
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1389
+ }
1390
+
1391
+ if (spring.isHandle)
1392
+ continue;
1393
+
1394
+ //if (scale < spring.restLength)
1395
+ scale += spring.restLength;
1396
+ count++;
1397
+ }
1398
+ gl.glEnd();
1399
+
1400
+ if (count == 0)
1401
+ scale = 0.01;
1402
+ else
1403
+ scale /= count * 3;
1404
+
1405
+ //scale = 0.25;
1406
+
1407
+ if (mesh.ShowInfo())
1408
+ {
1409
+ gl.glLineWidth(4);
1410
+ for (int s=0; s<Phys.allNodes.size(); s++)
1411
+ {
1412
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1413
+ if (node.mass == 0)
1414
+ continue;
1415
+
1416
+ int i = node.springs==null?-1:node.springs.size();
1417
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1418
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1419
+ //temp.normalize();
1420
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1421
+ gl.glBegin(gl.GL_LINES);
1422
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1423
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1424
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1425
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1426
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1427
+ gl.glEnd();
1428
+ }
1429
+
1430
+ gl.glLineWidth(8);
1431
+ for (int s=0; s<Phys.allNodes.size(); s++)
1432
+ {
1433
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1434
+
1435
+ if (node.springs != null)
1436
+ {
1437
+ for (int i=0; i<node.springs.size(); i+=1)
1438
+ {
1439
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1440
+
1441
+ int c = i+1;
1442
+ // c = node.springs.get(i).nbcopies;
1443
+
1444
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1445
+ gl.glBegin(gl.GL_LINES);
1446
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1447
+ 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);
1448
+ gl.glEnd();
1449
+ }
1450
+ }
1451
+ }
1452
+
1453
+ gl.glLineWidth(1);
1454
+ }
1455
+
1456
+ gl.glEnable(gl.GL_LIGHTING);
1457
+ }
1458
+
1459
+ /// INTERFACE
1460
+
1461
+ public void StartTriangles()
1462
+ {
1463
+ javax.media.opengl.GL gl = GetGL();
1464
+ gl.glBegin(gl.GL_TRIANGLES);
1465
+ }
1466
+
1467
+ public void EndTriangles()
1468
+ {
1469
+ GetGL().glEnd();
1470
+ }
1471
+
1472
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1473
+ {
1474
+ if (!selectmode)
1475
+ {
1476
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1477
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1478
+
1479
+ if (flipV)
1480
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1481
+ else
1482
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1483
+ }
1484
+
1485
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1486
+ }
1487
+
1488
+ void SetColor(Object3D obj, Vertex p0)
1489
+ {
1490
+ CameraPane display = this;
1491
+ BoundaryRep bRep = obj.bRep;
1492
+
1493
+ if (RENDERPROGRAM == 0)
1494
+ {
1495
+ float r = 0;
1496
+ if (bRep != null)
1497
+ {
1498
+ if (bRep.stripified)
1499
+ {
1500
+ r = 1;
1501
+ }
1502
+ }
1503
+ float g = 0;
1504
+ if (bRep != null)
1505
+ {
1506
+ if (bRep.trimmed)
1507
+ {
1508
+ g = 1;
1509
+ }
1510
+ }
1511
+ float b = 0;
1512
+ if (obj.support != null && obj.link2master)
1513
+ {
1514
+ b = 1;
1515
+ }
1516
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1517
+ return;
1518
+ }
1519
+
1520
+ if (display.DrawMode() != CameraPane.SHADOW)
1521
+ return;
1522
+
1523
+ javax.media.opengl.GL gl = display.GetGL();
1524
+// if (true) return;
1525
+// float ao = p.AO;
1526
+//
1527
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1528
+// // ao = 1;
1529
+//
1530
+// gl.glColor4f(ao, ao, ao, 1);
1531
+
1532
+// CameraPane.selectedpoint.
1533
+// getAverage(cStatic.point1, true);
1534
+ if (CameraPane.pointflow == null) // !random) // live)
1535
+ {
1536
+ return;
1537
+ }
1538
+
1539
+ cStatic.point1.set(0,0,0);
1540
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1541
+
1542
+ cStatic.point1.sub(p0);
1543
+
1544
+
1545
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1546
+// {
1547
+// return;
1548
+// }
1549
+
1550
+ //if (true)
1551
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1552
+ {
1553
+ return;
1554
+ }
1555
+
1556
+ float[] colorV = new float[3];
1557
+
1558
+ if (false) // marked)
1559
+ {
1560
+ // debug rigging weights
1561
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1562
+ {
1563
+ float weight = p0.weights[object] / p0.totalweight;
1564
+
1565
+ // if (weight < 0.1)
1566
+ // {
1567
+ // assert(weight == 0);
1568
+ // continue;
1569
+ // }
1570
+
1571
+ if (p0.vertexlinks[object] == -1)
1572
+ continue;
1573
+
1574
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1575
+
1576
+ int color = //1 << object; //
1577
+ //p.vertexlinks.length;
1578
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1579
+ colorV[2] += (color & 1) * weight;
1580
+ colorV[1] += ((color & 2) >> 1) * weight;
1581
+ colorV[0] += ((color & 4) >> 2) * weight;
1582
+ }
1583
+ }
1584
+ else
1585
+ {
1586
+ if (obj.drawingstarted)
1587
+ {
1588
+ // find next point
1589
+ if (bRep.GetVertex(0).faceindices == null)
1590
+ {
1591
+ bRep.InitFaceIndices();
1592
+ }
1593
+
1594
+ double ymin = p0.y;
1595
+
1596
+ Vertex newp = p0;
1597
+
1598
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1599
+ {
1600
+ int fi = p0.faceindices[fii];
1601
+
1602
+ if (fi == -1)
1603
+ break;
1604
+
1605
+ Face f = bRep.GetFace(fi);
1606
+
1607
+ Vertex p = bRep.GetVertex(f.p);
1608
+ Vertex q = bRep.GetVertex(f.q);
1609
+ Vertex r = bRep.GetVertex(f.r);
1610
+
1611
+ int swap = (int)(Math.random()*3);
1612
+
1613
+// for (int s=swap; --s>=0;)
1614
+// {
1615
+// Vertex t = p;
1616
+// p = q;
1617
+// q = r;
1618
+// r = t;
1619
+// }
1620
+ if (ymin > p.y)
1621
+ {
1622
+ ymin = p.y;
1623
+ newp = p;
1624
+// break;
1625
+ }
1626
+ if (ymin > q.y)
1627
+ {
1628
+ ymin = q.y;
1629
+ newp = q;
1630
+// break;
1631
+ }
1632
+ if (ymin > r.y)
1633
+ {
1634
+ ymin = r.y;
1635
+ newp = r;
1636
+// break;
1637
+ }
1638
+ }
1639
+
1640
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1641
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1642
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1643
+
1644
+ obj.drawingstarted = false;
1645
+
1646
+ // return;
1647
+ }
1648
+
1649
+ if (false) // CameraPane.DRAW
1650
+ {
1651
+ p0.AO = colorV[0] = 2;
1652
+ colorV[1] = 2;
1653
+ colorV[2] = 2;
1654
+ }
1655
+
1656
+ CameraPane.pointflow.add(p0);
1657
+ CameraPane.pointflow.Touch();
1658
+ }
1659
+
1660
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1661
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1662
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1663
+ }
1664
+
1665
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1666
+ {
1667
+ CameraPane display = this;
1668
+ //new Exception().printStackTrace();
1669
+
1670
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1671
+ {
1672
+ return;
1673
+ }
1674
+
1675
+ javax.media.opengl.GL gl = display.GetGL();
1676
+
1677
+ //Color col = Color.getHSBColor(color,modulation,1);
1678
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1679
+ if (!material.multiply)
1680
+ {
1681
+ display.color = material.color;
1682
+ display.saturation = material.modulation;
1683
+ }
1684
+ else
1685
+ {
1686
+ display.color *= material.color*2;
1687
+ display.saturation *= material.modulation*2;
1688
+ }
1689
+
1690
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1691
+
1692
+ float[] colorV = Grafreed.colorV;
1693
+
1694
+ /**/
1695
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1696
+ {
1697
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1698
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1699
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1700
+ colorV[3] = 1; // material.opacity;
1701
+
1702
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1703
+ //System.out.println("Opacity = " + opacity);
1704
+
1705
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1706
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1707
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1708
+
1709
+ float amb = material.ambient;
1710
+ if (amb < material.cameralight)
1711
+ {
1712
+ amb = material.cameralight;
1713
+ }
1714
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1715
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1716
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1717
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1718
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1719
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1720
+
1721
+ /**/
1722
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1723
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1724
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1725
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1726
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1727
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1728
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1729
+ //System.out.println("shininess = " + colorV[0]);
1730
+ if (colorV[0] > 128)
1731
+ {
1732
+ colorV[0] = 128;
1733
+ }
1734
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1735
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1736
+ /**/
1737
+ }
1738
+ /**/
1739
+
1740
+ //selected = false;
1741
+ selected = selected && display.flash;
1742
+
1743
+ //display.modelParams0[0] = 0; // pigment.r;
1744
+ //display.modelParams0[1] = 0; // pigment.g;
1745
+ //display.modelParams0[2] = 0; // pigment.b;
1746
+ if (!material.multiply)
1747
+ {
1748
+ display.modelParams0[3] = material.metalness;
1749
+ display.modelParams1[0] = material.diffuse;
1750
+ display.modelParams1[1] = material.specular;
1751
+ display.modelParams1[2] = 1 / material.shininess;
1752
+ display.modelParams1[3] = material.shift;
1753
+ display.modelParams2[0] = material.ambient;
1754
+ display.modelParams2[1] = material.lightarea;
1755
+ //System.out.println("light area = " + lightarea);
1756
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1757
+ display.modelParams2[3] = material.velvet;
1758
+ display.modelParams3[0] = material.sheen;
1759
+ display.modelParams3[1] = material.subsurface;
1760
+ display.modelParams3[2] = material.bump; // backlit
1761
+ display.modelParams3[3] = material.aniso;
1762
+ display.modelParams4[0] = material.anisoV;
1763
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1764
+ //System.out.println("selected = " + selected);
1765
+ display.modelParams4[2] = material.diffuseness;
1766
+ display.modelParams4[3] = material.shadow;
1767
+ display.modelParams5[0] = material.texture;
1768
+ display.modelParams5[1] = material.opacity;
1769
+ display.modelParams5[2] = material.fakedepth;
1770
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1771
+ }
1772
+ else
1773
+ {
1774
+ display.modelParams0[3] *= material.metalness*2;
1775
+ display.modelParams1[0] *= material.diffuse*2;
1776
+ display.modelParams1[1] *= material.specular*2;
1777
+ display.modelParams1[2] *= material.shininess*2;
1778
+ display.modelParams1[3] *= material.shift*2;
1779
+ display.modelParams2[0] *= material.ambient*2;
1780
+ display.modelParams2[1] *= material.lightarea*2;
1781
+ display.modelParams2[2] *= material.factor*2;
1782
+ display.modelParams2[3] *= material.velvet*2;
1783
+ display.modelParams3[0] *= material.sheen*2;
1784
+ display.modelParams3[1] *= material.subsurface*2;
1785
+ display.modelParams3[2] *= material.bump*2;
1786
+ display.modelParams3[3] *= material.aniso*2;
1787
+ display.modelParams4[0] *= material.anisoV*2;
1788
+ display.modelParams4[1] *= material.cameralight*2;
1789
+ //System.out.println("selected = " + selected);
1790
+ display.modelParams4[2] *= material.diffuseness*2;
1791
+ display.modelParams4[3] *= material.shadow*2;
1792
+ display.modelParams5[0] *= material.texture*2;
1793
+ display.modelParams5[1] *= material.opacity*2;
1794
+ display.modelParams5[2] *= material.fakedepth*2;
1795
+ display.modelParams5[3] *= material.shadowbias*2;
1796
+ }
1797
+
1798
+ display.modelParams6[0] = 0;
1799
+ display.modelParams6[1] = 0;
1800
+ display.modelParams6[2] = 0;
1801
+ display.modelParams6[3] = 0;
1802
+
1803
+ display.modelParams7[0] = 0;
1804
+ display.modelParams7[1] = 1000;
1805
+ display.modelParams7[2] = 0;
1806
+ display.modelParams7[3] = 0;
1807
+
1808
+ //display.modelParams6[0] = 100; // criss de bug de bump
1809
+
1810
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1811
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1812
+ {
1813
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1814
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1815
+ if (extparams.length > 1)
1816
+ {
1817
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1818
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1819
+ if (extparams.length > 2)
1820
+ {
1821
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1822
+ float x = extparams[2].y / 1000.0f;
1823
+ //if (x == 0)
1824
+ // x = 1f;
1825
+ 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
1826
+ if (extparams[2].y > 0)
1827
+ {
1828
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1829
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1830
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1831
+ }
1832
+ }
1833
+ }
1834
+ }
1835
+
1836
+ //if (display.modelParams6[2] != 0)
1837
+ /*
1838
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1839
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1840
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1841
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1842
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1843
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1844
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1845
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1846
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1847
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1848
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1849
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1850
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1851
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1852
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1853
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1854
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1855
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1856
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1857
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1858
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1859
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1860
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1861
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1862
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1863
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1864
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1865
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1866
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1867
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1868
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1869
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1870
+ /**/
1871
+ //assert (display.modelParams6[2] == 0);
1872
+
1873
+ //System.out.println("noise power = " + display.modelParams7[0]);
1874
+ //System.out.println("shadowbias = " + shadowbias);
1875
+
1876
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1877
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1878
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1879
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1880
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1881
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1882
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1883
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1884
+
1885
+ int mode = display.FP_SHADER;
1886
+
1887
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1888
+ {
1889
+ mode |= display.FP_ANISO;
1890
+ }
1891
+
1892
+ display.EnableProgram(mode);
1893
+
1894
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1895
+
1896
+ if (!material.multiply)
1897
+ {
1898
+ if (Globals.drawMode == CameraPane.SHADOW)
1899
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1900
+ else
1901
+ gl.glDepthMask(material.opacity >= 0.99);
1902
+ }
2361903 }
2371904
2381905 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -253,7 +1920,7 @@
2531920 currentGL.glMultMatrixd(model, 0);
2541921 }
2551922
256
- void PushMatrix(double[][] matrix, int count)
1923
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2571924 {
2581925 matrixdepth++;
2591926 // GrafreeD.tracein(matrix);
....@@ -282,7 +1949,7 @@
2821949 void PushMatrix(double[][] matrix)
2831950 {
2841951 // GrafreeD.tracein(matrix);
285
- PushMatrix(matrix,1);
1952
+ PushMatrix(matrix, 1);
2861953 }
2871954
2881955 void PushMatrix()
....@@ -298,7 +1965,7 @@
2981965
2991966 double[][] tmpmat = new double[4][4];
3001967
301
- void PopMatrix(double[][] inverse)
1968
+ public void PopMatrix(double[][] inverse) // INTERFACE
3021969 {
3031970 --matrixdepth;
3041971
....@@ -338,7 +2005,7 @@
3382005 PushTextureMatrix(matrix, 1);
3392006 }
3402007
341
- void PushTextureMatrix(double[][] matrix, int count)
2008
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3422009 {
3432010 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3442011
....@@ -352,7 +2019,7 @@
3522019 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3532020 }
3542021
355
- void PopTextureMatrix(double[][] inverse)
2022
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3562023 {
3572024 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3582025 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -379,15 +2046,15 @@
3792046
3802047 static int camerachangeframe;
3812048
382
- boolean SetCamera(Camera cam)
2049
+ public boolean SetCamera(Camera cam)
3832050 {
3842051 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3852052 // return false;
3862053
387
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2054
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3882055 {
3892056 // check for last change
390
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2057
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3912058 {
3922059 // refuse the camera change
3932060 System.err.println("Camera " + cam + " REFUSED");
....@@ -395,7 +2062,7 @@
3952062 }
3962063 }
3972064
398
- camerachangeframe = framecount;
2065
+ camerachangeframe = Globals.framecount;
3992066
4002067 cam.hAspect = -1; // Read only
4012068
....@@ -426,7 +2093,7 @@
4262093 {
4272094 //System.err.println("Oeil on");
4282095 TRACK = true;
429
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2096
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4302097 // object.editWindow.ScreenFit(trackedobject);
4312098 //pingthread.StepToTarget(true);
4322099 }
....@@ -435,8 +2102,8 @@
4352102 {
4362103 //System.err.println("Oeil on");
4372104 OEIL = true;
438
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
439
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2106
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4402107 //pingthread.StepToTarget(true);
4412108 }
4422109
....@@ -499,39 +2166,12 @@
4992166 {
5002167 frozen ^= true;
5012168 // Weird...
502
- lighttouched = true;
2169
+ Globals.lighttouched = true;
5032170 }
5042171
5052172 void ToggleDL()
5062173 {
5072174 mainDL ^= true;
508
- }
509
-
510
- void ToggleTexture()
511
- {
512
- textureon ^= true;
513
- }
514
-
515
- void ToggleLive()
516
- {
517
- setLIVE(isLIVE() ^ true);
518
-
519
- System.err.println("LIVE = " + isLIVE());
520
-
521
- if (!isLIVE()) // save sound
522
- GrafreeD.savesound = true; // wav.save();
523
- // else
524
- repaint(); // start loop // may 2013
525
- }
526
-
527
- void ToggleSupport()
528
- {
529
- SUPPORT ^= true;
530
- }
531
-
532
- void ToggleAbort()
533
- {
534
- ABORTMODE ^= true;
5352175 }
5362176
5372177 void ToggleFullScreen()
....@@ -541,12 +2181,7 @@
5412181
5422182 void ToggleCrowd()
5432183 {
544
- CROWD ^= true;
545
- }
546
-
547
- void ToggleInertia()
548
- {
549
- INERTIA ^= true;
2184
+ Globals.CROWD ^= true;
5502185 }
5512186
5522187 void ToggleLocal()
....@@ -554,62 +2189,89 @@
5542189 LOCALTRANSFORM ^= true;
5552190 }
5562191
557
- void ToggleFast()
2192
+ public void ToggleTexture()
2193
+ {
2194
+ textureon ^= true;
2195
+ }
2196
+
2197
+ public void ToggleLive()
2198
+ {
2199
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2200
+
2201
+ System.err.println("LIVE = " + Globals.isLIVE());
2202
+
2203
+ if (!Globals.isLIVE()) // save sound
2204
+ Grafreed.savesound = true; // wav.save();
2205
+ // else
2206
+ repaint(); // start loop // may 2013
2207
+ }
2208
+
2209
+ public void ToggleSupport()
2210
+ {
2211
+ SUPPORT ^= true;
2212
+ }
2213
+
2214
+ public void ToggleAbort()
2215
+ {
2216
+ ABORTMODE ^= true;
2217
+ }
2218
+
2219
+ public void ToggleInertia()
2220
+ {
2221
+ INERTIA ^= true;
2222
+ }
2223
+
2224
+ public void ToggleFast()
5582225 {
5592226 FAST ^= true;
5602227 }
5612228
562
- void ToggleSlowPose()
2229
+ public void ToggleSlowPose()
5632230 {
5642231 SLOWPOSE ^= true;
5652232 }
5662233
567
- void ToggleFootContact()
568
- {
569
- FOOTCONTACT ^= true;
570
- }
571
-
572
- void ToggleBoxMode()
2234
+ public void ToggleBoxMode()
5732235 {
5742236 BOXMODE ^= true;
5752237 }
5762238
577
- void ToggleSmoothFocus()
2239
+ public void ToggleZoomBoxMode()
2240
+ {
2241
+ ZOOMBOXMODE ^= true;
2242
+ }
2243
+
2244
+ public void ToggleSmoothFocus()
5782245 {
5792246 SMOOTHFOCUS ^= true;
5802247 }
5812248
582
- void ToggleImageFlip()
2249
+ public void ToggleImageFlip()
5832250 {
5842251 IMAGEFLIP ^= true;
5852252 }
5862253
587
- void ToggleSpeakerMocap()
2254
+ public void ToggleSpeakerMocap()
5882255 {
5892256 SPEAKERMOCAP ^= true;
5902257 }
5912258
592
- void ToggleSpeakerCamera()
2259
+ public void ToggleSpeakerCamera()
5932260 {
5942261 SPEAKERCAMERA ^= true;
5952262 }
5962263
597
- void ToggleSpeakerFocus()
2264
+ public void ToggleSpeakerFocus()
5982265 {
5992266 SPEAKERFOCUS ^= true;
6002267 }
6012268
602
- void ToggleDebug()
603
- {
604
- DEBUG ^= true;
605
- }
606
-
607
- void ToggleFrustum()
2269
+ public void ToggleFrustum()
6082270 {
6092271 FRUSTUM ^= true;
6102272 }
6112273
612
- void ToggleTrack()
2274
+ public void ToggleTrack()
6132275 {
6142276 TRACK ^= true;
6152277 if (TRACK)
....@@ -628,25 +2290,35 @@
6282290 repaint();
6292291 }
6302292
631
- void ToggleTrackOnce()
2293
+ public void ToggleTrackOnce()
6322294 {
6332295 TRACKONCE ^= true;
6342296 }
6352297
636
- void ToggleShadowTrack()
2298
+ public void ToggleShadowTrack()
6372299 {
6382300 SHADOWTRACK ^= true;
6392301 repaint();
6402302 }
6412303
642
- void ToggleOeil()
2304
+ public void ToggleOeil()
6432305 {
6442306 OEIL ^= true;
6452307 }
6462308
647
- void ToggleOeilOnce()
2309
+ public void ToggleOeilOnce()
6482310 {
6492311 OEILONCE ^= true;
2312
+ }
2313
+
2314
+ void ToggleFootContact()
2315
+ {
2316
+ FOOTCONTACT ^= true;
2317
+ }
2318
+
2319
+ void ToggleDebug()
2320
+ {
2321
+ Globals.DEBUG ^= true;
6502322 }
6512323
6522324 void ToggleLookAt()
....@@ -654,9 +2326,9 @@
6542326 LOOKAT ^= true;
6552327 }
6562328
657
- void ToggleRandom()
2329
+ void ToggleSwitch()
6582330 {
659
- RANDOM ^= true;
2331
+ SWITCH ^= true;
6602332 }
6612333
6622334 void ToggleHandles()
....@@ -664,10 +2336,17 @@
6642336 HANDLES ^= true;
6652337 }
6662338
2339
+ Object3D paintFolder;
2340
+
6672341 void TogglePaint()
6682342 {
6692343 PAINTMODE ^= true;
6702344 paintcount = 0;
2345
+
2346
+ if (PAINTMODE)
2347
+ {
2348
+ paintFolder = GetFolder();
2349
+ }
6712350 }
6722351
6732352 void SwapCamera(int a, int b)
....@@ -759,11 +2438,26 @@
7592438
7602439 GL currentGL;
7612440
762
- GL GetGL()
2441
+ public GL GetGL() // INTERFACE
7632442 {
7642443 return currentGL;
7652444 }
766
-
2445
+
2446
+ static private BufferedImage CreateBim(TextureData texturedata)
2447
+ {
2448
+ Grafreed.Assert(texturedata != null);
2449
+
2450
+ int width = texturedata.getWidth();
2451
+ int height = texturedata.getHeight();
2452
+
2453
+ Buffer buffer = texturedata.getBuffer();
2454
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2455
+
2456
+ byte[] bytes = bytebuf.array();
2457
+
2458
+ return CreateBim(bytes, width, height);
2459
+ }
2460
+
7672461 /**/
7682462 class CacheTexture
7692463 {
....@@ -772,28 +2466,31 @@
7722466
7732467 int resolution;
7742468
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762470 {
777
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
7782473 resolution = res;
7792474 }
7802475 }
7812476 /**/
7822477
7832478 // 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>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2481
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2482
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2483
+
7872484 int pigmentdepth = 0;
7882485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892486 int bumpdepth = 0;
7902487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952492
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972494 {
7982495 TextureData texturedata = null;
7992496
....@@ -812,13 +2509,34 @@
8122509 if (bump)
8132510 texturedata = ConvertBump(texturedata, false);
8142511
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2512
+// com.sun.opengl.util.texture.Texture texture =
2513
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172514
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);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2516
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202517
821
- return texture;
2518
+ return texturedata;
2519
+ }
2520
+
2521
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2522
+ {
2523
+ TextureData texturedata = null;
2524
+
2525
+ try
2526
+ {
2527
+ texturedata =
2528
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2529
+ bim,
2530
+ true);
2531
+ } catch (Exception e)
2532
+ {
2533
+ throw new javax.media.opengl.GLException(e);
2534
+ }
2535
+
2536
+ if (bump)
2537
+ texturedata = ConvertBump(texturedata, false);
2538
+
2539
+ return texturedata;
8222540 }
8232541
8242542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3609,8 @@
18913609
18923610 System.out.println("LOADING TEXTURE : " + name);
18933611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
18943614 //
18953615 if (false) // compressbit > 0)
18963616 {
....@@ -2595,6 +4315,7 @@
25954315
25964316 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25974317 {
4318
+ new Exception().printStackTrace();
25984319 System.exit(0);
25994320 com.sun.opengl.util.texture.Texture texture = null;
26004321
....@@ -6271,7 +7992,7 @@
62717992 return null;
62727993 }
62737994
6274
- void ReleaseTextures(cTexture tex)
7995
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62757996 {
62767997 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62777998 {
....@@ -6288,7 +8009,7 @@
62888009 String pigment = Object3D.GetPigment(tex);
62898010 String bump = Object3D.GetBump(tex);
62908011
6291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62928013 {
62938014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62948015 // System.out.println("; bump = " + bump);
....@@ -6303,13 +8024,71 @@
63038024 pigment = null;
63048025 }
63058026
6306
- ReleaseTexture(bump, true);
6307
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
63088029 }
63098030
6310
- void ReleaseTexture(String tex, boolean bump)
8031
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63118032 {
6312
- if (// drawMode != 0 || /*tex == null ||*/
8033
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8034
+ {
8035
+ return;
8036
+ }
8037
+
8038
+ if (tex == null)
8039
+ {
8040
+ ReleaseTexture(null, false);
8041
+ return;
8042
+ }
8043
+
8044
+ String pigment = Object3D.GetPigment(tex);
8045
+
8046
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8047
+ {
8048
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8049
+ // System.out.println("; bump = " + bump);
8050
+ }
8051
+
8052
+ if (pigment.equals(""))
8053
+ {
8054
+ pigment = null;
8055
+ }
8056
+
8057
+ ReleaseTexture(tex, false);
8058
+ }
8059
+
8060
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8061
+ {
8062
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8063
+ {
8064
+ return;
8065
+ }
8066
+
8067
+ if (tex == null)
8068
+ {
8069
+ ReleaseTexture(null, true);
8070
+ return;
8071
+ }
8072
+
8073
+ String bump = Object3D.GetBump(tex);
8074
+
8075
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ {
8077
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8078
+ // System.out.println("; bump = " + bump);
8079
+ }
8080
+
8081
+ if (bump.equals(""))
8082
+ {
8083
+ bump = null;
8084
+ }
8085
+
8086
+ ReleaseTexture(tex, true);
8087
+ }
8088
+
8089
+ void ReleaseTexture(cTexture tex, boolean bump)
8090
+ {
8091
+ if (// DrawMode() != 0 || /*tex == null ||*/
63138092 ambientOcclusion ) // || !textureon)
63148093 {
63158094 return;
....@@ -6318,7 +8097,7 @@
63188097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63198098
63208099 if (tex != null)
6321
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63228101
63238102 // //assert( texture != null );
63248103 // if (texture == null)
....@@ -6410,9 +8189,57 @@
64108189 }
64118190 }
64128191
6413
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8192
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64148193 {
6415
- if (// drawMode != 0 || /*tex == null ||*/
8194
+// if (// DrawMode() != 0 || /*tex == null ||*/
8195
+// ambientOcclusion ) // || !textureon)
8196
+// {
8197
+// return; // false;
8198
+// }
8199
+//
8200
+// if (tex == null)
8201
+// {
8202
+// BindTexture(null,false,resolution);
8203
+// BindTexture(null,true,resolution);
8204
+// return;
8205
+// }
8206
+//
8207
+// String pigment = Object3D.GetPigment(tex);
8208
+// String bump = Object3D.GetBump(tex);
8209
+//
8210
+// usedtextures.add(pigment);
8211
+// usedtextures.add(bump);
8212
+//
8213
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8214
+// {
8215
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8216
+// // System.out.println("; bump = " + bump);
8217
+// }
8218
+//
8219
+// if (bump.equals(""))
8220
+// {
8221
+// bump = null;
8222
+// }
8223
+// if (pigment.equals(""))
8224
+// {
8225
+// pigment = null;
8226
+// }
8227
+//
8228
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8229
+// BindTexture(pigment, false, resolution);
8230
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8231
+// BindTexture(bump, true, resolution);
8232
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8233
+//
8234
+// return; // true;
8235
+
8236
+ BindPigmentTexture(tex, resolution);
8237
+ BindBumpTexture(tex, resolution);
8238
+ }
8239
+
8240
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8241
+ {
8242
+ if (// DrawMode() != 0 || /*tex == null ||*/
64168243 ambientOcclusion ) // || !textureon)
64178244 {
64188245 return; // false;
....@@ -6421,17 +8248,47 @@
64218248 if (tex == null)
64228249 {
64238250 BindTexture(null,false,resolution);
6424
- BindTexture(null,true,resolution);
64258251 return;
64268252 }
64278253
64288254 String pigment = Object3D.GetPigment(tex);
8255
+
8256
+ usedtextures.add(tex);
8257
+
8258
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8259
+ {
8260
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8261
+ // System.out.println("; bump = " + bump);
8262
+ }
8263
+
8264
+ if (pigment.equals(""))
8265
+ {
8266
+ pigment = null;
8267
+ }
8268
+
8269
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8270
+ BindTexture(tex, false, resolution);
8271
+ }
8272
+
8273
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8274
+ {
8275
+ if (// DrawMode() != 0 || /*tex == null ||*/
8276
+ ambientOcclusion ) // || !textureon)
8277
+ {
8278
+ return; // false;
8279
+ }
8280
+
8281
+ if (tex == null)
8282
+ {
8283
+ BindTexture(null,true,resolution);
8284
+ return;
8285
+ }
8286
+
64298287 String bump = Object3D.GetBump(tex);
64308288
6431
- usedtextures.put(pigment, pigment);
6432
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
64338290
6434
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64358292 {
64368293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64378294 // System.out.println("; bump = " + bump);
....@@ -6441,43 +8298,94 @@
64418298 {
64428299 bump = null;
64438300 }
6444
- if (pigment.equals(""))
6445
- {
6446
- pigment = null;
6447
- }
64488301
6449
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
- BindTexture(pigment, false, resolution);
64518302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6452
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
64538304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6454
-
6455
- return; // true;
64568305 }
64578306
6458
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8307
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8308
+
8309
+ private boolean FileExists(String tex)
64598310 {
6460
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8311
+ if (missingTextures.contains(tex))
8312
+ {
8313
+ return false;
8314
+ }
8315
+
8316
+ boolean fileExists = new File(tex).exists();
8317
+
8318
+ if (!fileExists)
8319
+ {
8320
+ // If file exists, the "new File()" is not executed sgain
8321
+ missingTextures.add(tex);
8322
+ }
8323
+
8324
+ return fileExists;
8325
+ }
8326
+
8327
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8328
+ {
8329
+ CacheTexture texturecache = null;
64618330
64628331 if (tex != null)
64638332 {
6464
- String texname = tex;
8333
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8334
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64658335
6466
- String[] split = tex.split("Textures");
6467
- if (split.length > 1)
6468
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6469
- else
6470
- if (!texname.startsWith("/"))
6471
- texname = "/Users/nbriere/Textures/" + texname;
8336
+ if (texname.equals("") && texdata == null)
8337
+ {
8338
+ return null;
8339
+ }
8340
+
8341
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8342
+
8343
+// String[] split = tex.split("Textures");
8344
+// if (split.length > 1)
8345
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8346
+// else
8347
+// if (!texname.startsWith("/"))
8348
+// texname = "/Users/nbriere/Textures/" + texname;
8349
+ if (!FileExists(texname))
8350
+ {
8351
+ texname = fallbackTextureName;
8352
+ }
64728353
64738354 if (CACHETEXTURE)
6474
- texture = textures.get(texname); // TEXTURE CACHE
6475
-
6476
- TextureData texturedata = null;
6477
-
6478
- if (texture == null || texture.resolution < resolution)
64798355 {
6480
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8356
+ if (texdata == null)
8357
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8358
+ else
8359
+ texturecache = bimtextures.get(texdata);
8360
+ }
8361
+
8362
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8363
+ {
8364
+ TextureData texturedata = null;
8365
+
8366
+ if (texdata != null && textureon)
8367
+ {
8368
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8369
+
8370
+ try
8371
+ {
8372
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8373
+ }
8374
+ catch (Exception e)
8375
+ {
8376
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8377
+ }
8378
+
8379
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8380
+ bimtextures.put(texdata, texturecache);
8381
+
8382
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8383
+
8384
+ //Object bim2 = CreateBim(texturecache.texturedata);
8385
+ //bim2 = bim;
8386
+ }
8387
+ else
8388
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64818389 {
64828390 assert(!bump);
64838391 // if (bump)
....@@ -6488,19 +8396,23 @@
64888396 // }
64898397 // else
64908398 // {
6491
- texture = textures.get(tex);
6492
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
64938401 {
6494
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64958403 }
8404
+ else
8405
+ new Exception().printStackTrace();
64968406 // }
64978407 } else
6498
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64998409 {
65008410 assert(bump);
6501
- texture = textures.get(tex);
6502
- if (texture == null)
6503
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
8413
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ else
8415
+ new Exception().printStackTrace();
65048416 } else
65058417 {
65068418 //if (tex.equals("IMMORTAL"))
....@@ -6508,11 +8420,13 @@
65088420 // texture = GetResourceTexture("default.png");
65098421 //} else
65108422 //{
6511
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
65128424 {
6513
- texture = textures.get(tex);
6514
- if (texture == null)
6515
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8425
+ // texturecache = textures.get(texname); // suspicious
8426
+ if (texturecache == null)
8427
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8428
+ else
8429
+ new Exception().printStackTrace();
65168430 } else
65178431 {
65188432 if (textureon)
....@@ -6537,7 +8451,7 @@
65378451 }
65388452
65398453 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6540
- if (!new File(cachename).exists())
8454
+ if (!FileExists(cachename))
65418455 cachename = texname;
65428456 else
65438457 processbump = false; // don't process bump map again
....@@ -6559,7 +8473,7 @@
65598473 }
65608474
65618475 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6562
- if (!new File(cachename).exists())
8476
+ if (!FileExists(cachename))
65638477 cachename = texname;
65648478 else
65658479 processbump = false; // don't process bump map again
....@@ -6568,20 +8482,22 @@
65688482 texturedata = GetFileTexture(cachename, processbump, resolution);
65698483
65708484
6571
- if (texturedata != null)
6572
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8485
+ if (texturedata == null)
8486
+ throw new Exception();
8487
+
8488
+ texturecache = new CacheTexture(texturedata,resolution);
65738489 //texture = GetTexture(tex, bump);
65748490 }
65758491 }
65768492 //}
65778493 }
65788494
6579
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65808496 {
65818497 //return false;
65828498
65838499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6584
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65858501 {
65868502 // String ext = "_highres";
65878503 // if (REDUCETEXTURE)
....@@ -6598,52 +8514,17 @@
65988514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65998515 if (!cachefile.exists())
66008516 {
6601
- // cache to disk
6602
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6603
- //buffers[0].
6604
-
6605
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6606
- int[] pixels = new int[bytebuf.capacity()/3];
6607
-
6608
- // squared size heuristic...
6609
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
66108518 {
6611
- for (int i=pixels.length; --i>=0;)
6612
- {
6613
- int i3 = i*3;
6614
- pixels[i] = 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6617
- pixels[i] <<= 8;
6618
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6619
- pixels[i] <<= 8;
6620
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6621
- }
6622
-
6623
- /*
6624
- int r=0,g=0,b=0,a=0;
6625
- for (int i=0; i<width; i++)
6626
- for (int j=0; j<height; j++)
6627
- {
6628
- int index = j*width+i;
6629
- int p = pixels[index];
6630
- a = ((p>>24) & 0xFF);
6631
- r = ((p>>16) & 0xFF);
6632
- g = ((p>>8) & 0xFF);
6633
- b = (p & 0xFF);
6634
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6635
- }
6636
- /**/
6637
- int width = (int)Math.sqrt(pixels.length); // squared
6638
- int height = width;
6639
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6640
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
66418521 ImageWriter writer = null;
66428522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66438523 if (iter.hasNext()) {
66448524 writer = (ImageWriter)iter.next();
66458525 }
6646
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
66478528 try
66488529 {
66498530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6660,18 +8541,20 @@
66608541 }
66618542 }
66628543 }
6663
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
66648547 //System.out.println("Texture = " + tex);
6665
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
66668549 {
6667
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
66688551 thetex.texture.disable();
66698552 thetex.texture.dispose();
6670
- textures.remove(texname);
8553
+ textures.remove(tex);
66718554 }
66728555
6673
- texture.texturedata = texturedata;
6674
- textures.put(texname, texture);
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
66758558
66768559 // newtex = true;
66778560 }
....@@ -6687,10 +8570,44 @@
66878570 }
66888571 }
66898572
6690
- return texture;
8573
+ return texturecache;
66918574 }
66928575
6693
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8576
+ static void EmbedTextures(cTexture tex)
8577
+ {
8578
+ if (tex.pigmentdata == null)
8579
+ {
8580
+ //String texname = Object3D.GetPigment(tex);
8581
+
8582
+ CacheTexture texturecache = texturepigment.get(tex);
8583
+
8584
+ if (texturecache != null)
8585
+ {
8586
+ tex.pw = texturecache.texturedata.getWidth();
8587
+ tex.ph = texturecache.texturedata.getHeight();
8588
+ tex.pigmentdata = //CompressJPEG(CreateBim
8589
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8590
+ ;
8591
+ //, tex.pw, tex.ph), 0.5f);
8592
+ }
8593
+ }
8594
+
8595
+ if (tex.bumpdata == null)
8596
+ {
8597
+ //String texname = Object3D.GetBump(tex);
8598
+
8599
+ CacheTexture texturecache = texturebump.get(tex);
8600
+
8601
+ if (texturecache != null)
8602
+ {
8603
+ tex.bw = texturecache.texturedata.getWidth();
8604
+ tex.bh = texturecache.texturedata.getHeight();
8605
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8606
+ }
8607
+ }
8608
+ }
8609
+
8610
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66948611 {
66958612 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66968613
....@@ -6708,21 +8625,21 @@
67088625 return texture!=null?texture.texture:null;
67098626 }
67108627
6711
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8628
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67128629 {
67138630 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67148631
67158632 return texture!=null?texture.texturedata:null;
67168633 }
67178634
6718
- boolean BindTexture(String tex, boolean bump, int resolution)
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67198636 {
67208637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67218638 {
67228639 return false;
67238640 }
67248641
6725
- boolean newtex = false;
8642
+ //boolean newtex = false;
67268643
67278644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67288645
....@@ -6754,9 +8671,75 @@
67548671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67558672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67568673
6757
- return newtex;
8674
+ return true; // Warning: not used.
67588675 }
67598676
8677
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8678
+ {
8679
+ try
8680
+ {
8681
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8682
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8683
+ ImageWriter writer = writers.next();
8684
+
8685
+ ImageWriteParam param = writer.getDefaultWriteParam();
8686
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8687
+ param.setCompressionQuality(quality);
8688
+
8689
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8690
+ writer.setOutput(ios);
8691
+ writer.write(null, new IIOImage(image, null, null), param);
8692
+
8693
+ byte[] data = baos.toByteArray();
8694
+ writer.dispose();
8695
+ return data;
8696
+ }
8697
+ catch (Exception e)
8698
+ {
8699
+ e.printStackTrace();
8700
+ return null;
8701
+ }
8702
+ }
8703
+
8704
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8705
+ {
8706
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8707
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8708
+ ImageReader reader = writers.next();
8709
+
8710
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8711
+
8712
+ ImageReadParam param = reader.getDefaultReadParam();
8713
+ param.setDestination(bim);
8714
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8715
+
8716
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8717
+ reader.setInput(ios);
8718
+ BufferedImage bim2 = reader.read(0, param);
8719
+ reader.dispose();
8720
+
8721
+// WritableRaster raster = bim2.getRaster();
8722
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8723
+// byte[] bytes = data.getData();
8724
+//
8725
+// int[] pixels = new int[bytes.length/3];
8726
+// for (int i=pixels.length; --i>=0;)
8727
+// {
8728
+// int i3 = i*3;
8729
+// pixels[i] = 0xFF;
8730
+// pixels[i] <<= 8;
8731
+// pixels[i] |= bytes[i3+2] & 0xFF;
8732
+// pixels[i] <<= 8;
8733
+// pixels[i] |= bytes[i3+1] & 0xFF;
8734
+// pixels[i] <<= 8;
8735
+// pixels[i] |= bytes[i3] & 0xFF;
8736
+// }
8737
+//
8738
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8739
+
8740
+ return bim;
8741
+ }
8742
+
67608743 ShadowBuffer shadowPBuf;
67618744 AntialiasBuffer antialiasPBuf;
67628745 int MAXSTACK;
....@@ -7312,9 +9295,9 @@
73129295 static boolean occlusionInitialized = false;
73139296 boolean selection = false;
73149297 boolean pointselection = false;
7315
- /*static*/ boolean lighttouched = true;
9298
+ ///*static*/ boolean lighttouched = true;
73169299 boolean deselect;
7317
- boolean ambientOcclusion = false;
9300
+ private boolean ambientOcclusion = false;
73189301 static boolean flash = false;
73199302 /*static*/ boolean wait = false;
73209303 boolean displaydone = false; // after repaint() calls
....@@ -7592,18 +9575,40 @@
75929575 jy8[3] = 0.5f;
75939576 }
75949577
7595
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9578
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75969579 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
75979580 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
75989581 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75999582
9583
+ void ResetOptions()
9584
+ {
9585
+ options1[0] = 100;
9586
+ options1[1] = 0.025f;
9587
+ options1[2] = 0.01f;
9588
+ options1[3] = 0;
9589
+ options1[4] = 0;
9590
+
9591
+ options2[0] = 0;
9592
+ options2[1] = 0.75f;
9593
+ options2[2] = 0;
9594
+ options2[3] = 0;
9595
+
9596
+ options3[0] = 1;
9597
+ options3[1] = 1;
9598
+ options3[2] = 1;
9599
+ options3[3] = 0;
9600
+
9601
+ options4[0] = 1;
9602
+ options4[1] = 0;
9603
+ options4[2] = 1;
9604
+ options4[3] = 0;
9605
+ }
9606
+
76009607 static int imagecount = 0; // movie generation
76019608
76029609 static int jitter = 0;
76039610
76049611 boolean restartframe = false;
7605
-
7606
- static int framecount = 0; // general-purpose global count
76079612
76089613 void displayAntiAliased(javax.media.opengl.GL gl)
76099614 {
....@@ -7635,7 +9640,7 @@
76359640 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76369641 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76379642 {
7638
- framecount++;
9643
+ Globals.framecount++;
76399644
76409645 if (CameraPane.tickcount > 0)
76419646 CameraPane.tickcount--;
....@@ -7673,7 +9678,7 @@
76739678
76749679 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76759680 */
7676
- lighttouched = true;
9681
+ Globals.lighttouched = true;
76779682 //System.err.println(" shadowbuffer: " + jitter);
76789683 shadowbuffer.display();
76799684
....@@ -7694,8 +9699,8 @@
76949699 assert (parentcam != renderCamera);
76959700
76969701 if (renderCamera != lightCamera)
7697
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7698
- LA.matConcat(matrix, parentcam.toParent, matrix);
9702
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76999704
77009705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
77019706
....@@ -7710,8 +9715,8 @@
77109715 LA.matCopy(renderCamera.fromScreen, matrix);
77119716
77129717 if (renderCamera != lightCamera)
7713
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7714
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9718
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77159720
77169721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77179722
....@@ -7783,7 +9788,7 @@
77839788 //gl.glFlush();
77849789 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77859790
7786
- if (ANIMATION && ABORTED)
9791
+ if (Globals.ANIMATION && ABORTED)
77879792 {
77889793 System.err.println(" ABORTED FRAME");
77899794 break;
....@@ -7813,7 +9818,7 @@
78139818 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78149819
78159820 // save image
7816
- if (ANIMATION && !ABORTED)
9821
+ if (Globals.ANIMATION && !ABORTED)
78179822 {
78189823 VPwidth = viewport[2];
78199824 VPheight = viewport[3];
....@@ -7924,11 +9929,11 @@
79249929
79259930 // imagecount++;
79269931
7927
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9932
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79289933
79299934 if (!BOXMODE)
79309935 {
7931
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9936
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79329937 }
79339938
79349939 if (!BOXMODE)
....@@ -7966,7 +9971,7 @@
79669971 ABORTED = false;
79679972 }
79689973 else
7969
- GrafreeD.wav.cursor += 735 * ACSIZE;
9974
+ Grafreed.wav.cursor += 735 * ACSIZE;
79709975
79719976 if (false)
79729977 {
....@@ -8620,13 +10625,6 @@
862010625 }
862110626 }
862210627
8623
- boolean IsFrozen()
8624
- {
8625
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8626
-
8627
- return !selectmode && cameracount == 0; // != 0;
8628
- }
8629
-
863010628 boolean niceon = false;
863110629 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
863210630 boolean currentlydrawing = false;
....@@ -8636,16 +10634,16 @@
863610634
863710635 public void display(GLAutoDrawable drawable)
863810636 {
8639
- if (GrafreeD.savesound && GrafreeD.hassound)
10637
+ if (Grafreed.savesound && Grafreed.hassound)
864010638 {
8641
- GrafreeD.wav.save();
8642
- GrafreeD.savesound = false;
8643
- GrafreeD.hassound = false;
10639
+ Grafreed.wav.save();
10640
+ Grafreed.savesound = false;
10641
+ Grafreed.hassound = false;
864410642 }
864510643 // if (DEBUG_SELECTION)
864610644 // {
8647
-// if (drawMode != SELECTION)
8648
-// drawMode = SELECTION;
10645
+// if (DrawMode() != SELECTION)
10646
+// DrawMode() = SELECTION;
864910647 // }
865010648
865110649 if (!isRenderer)
....@@ -8701,9 +10699,9 @@
870110699
870210700 //ANTIALIAS = 0;
870310701
8704
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10702
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870510703 {
8706
- if (niceon || isLIVE())
10704
+ if (niceon || Globals.isLIVE())
870710705 {
870810706 //if(active == 0)
870910707 // antialiaser = null;
....@@ -8716,6 +10714,7 @@
871610714 ANTIALIAS = 0;
871710715 //System.out.println("RESTART");
871810716 AAtimer.restart();
10717
+ Globals.TIMERRUNNING = true;
871910718 }
872010719 }
872110720 }
....@@ -8728,7 +10727,7 @@
872810727 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872910728 */
873010729
8731
- if (drawMode == DEFAULT)
10730
+ if (DrawMode() == DEFAULT)
873210731 {
873310732 currentlydrawing = true;
873410733 }
....@@ -8759,18 +10758,18 @@
875910758
876010759 // if(Applet3D.clipboard != null)
876110760 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8762
-//drawMode = SELECTION;
10761
+//DrawMode() = SELECTION;
876310762 indexcount = 0;
876410763
8765
- if (drawMode == OCCLUSION)
10764
+ if (DrawMode() == OCCLUSION)
876610765 {
8767
- drawMode = DEFAULT;
10766
+ Globals.drawMode = DEFAULT; // WARNING
876810767 ambientOcclusion = true;
876910768 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
877010769 Object3D theobject = object;
877110770 Object3D theparent = object.parent;
877210771 object.parent = null;
8773
- object = (Object3D)GrafreeD.clone(object);
10772
+ object = (Object3D)Grafreed.clone(object);
877410773 object.Stripify();
877510774 if (theobject.selection == null || theobject.selection.Size() == 0)
877610775 theobject.PreprocessOcclusion(this);
....@@ -8783,19 +10782,20 @@
878310782 ambientOcclusion = false;
878410783 }
878510784
8786
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10785
+ if (//Globals.lighttouched &&
10786
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878710787 {
878810788 //if (RENDERSHADOW) // ?
878910789 if (!IsFrozen())
879010790 {
879110791 // dec 2012
8792
- if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10792
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
879310793 {
8794
- framecount++;
10794
+ Globals.framecount++;
879510795 shadowbuffer.display();
879610796 }
879710797 }
8798
- lighttouched = false; // ??
10798
+ Globals.lighttouched = false; // ??
879910799 //drawing = true;
880010800 //lighttouched = true;
880110801 }
....@@ -8816,9 +10816,9 @@
881610816 //eyeCamera.shaper_fovy = 1;
881710817 }
881810818
8819
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10819
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
882010820 {
8821
- //System.out.println("drawMode = " + drawMode);
10821
+ //System.out.println("DrawMode() = " + DrawMode());
882210822 vertexMode |= VP_PASS;
882310823 //vertexMode |= VP_PROJECTION;
882410824 if (!ambientOcclusion)
....@@ -8878,7 +10878,7 @@
887810878 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887910879 //Camera lightcam = new Camera(light0);
888010880
8881
- if (drawMode == SHADOW)
10881
+ if (DrawMode() == SHADOW)
888210882 {
888310883 /*
888410884 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8916,8 +10916,8 @@
891610916
891710917 // if (parentcam != renderCamera) // not a light
891810918 if (cam != lightCamera)
8919
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8920
- LA.matConcat(matrix, parentcam.toParent, matrix);
10919
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
892110921
892210922 for (int j = 0; j < 4; j++)
892310923 {
....@@ -8931,8 +10931,8 @@
893110931
893210932 // if (parentcam != renderCamera) // not a light
893310933 if (cam != lightCamera)
8934
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8935
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10934
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893610936
893710937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893810938
....@@ -8968,7 +10968,7 @@
896810968 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896910969 } else
897010970 {
8971
- if (drawMode != DEFAULT)
10971
+ if (DrawMode() != DEFAULT)
897210972 {
897310973 gl.glClearColor(1, 1, 1, 0);
897410974 } // 1);
....@@ -9033,7 +11033,7 @@
903311033
903411034 fast &= !ambientOcclusion;
903511035
9036
- if (drawMode == DEFAULT)
11036
+ if (DrawMode() == DEFAULT)
903711037 {
903811038 //gl.glEnable(gl.GL_ALPHA_TEST);
903911039 //gl.glActiveTexture(GL.GL_TEXTURE0);
....@@ -9191,7 +11191,16 @@
919111191 // Bump noise
919211192 gl.glActiveTexture(GL.GL_TEXTURE6);
919311193 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9194
- BindTexture(NOISE_TEXTURE, false, 2);
11194
+
11195
+ try
11196
+ {
11197
+ BindTexture(NOISE_TEXTURE, false, 2);
11198
+ }
11199
+ catch (Exception e)
11200
+ {
11201
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11202
+ }
11203
+
919511204
919611205 gl.glActiveTexture(GL.GL_TEXTURE0);
919711206 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9214,9 +11223,9 @@
921411223
921511224 gl.glMatrixMode(GL.GL_MODELVIEW);
921611225
9217
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9218
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9219
-//gl.glEnable(gl.GL_MULTISAMPLE);
11226
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11227
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11228
+gl.glEnable(gl.GL_MULTISAMPLE);
922011229 } else
922111230 {
922211231 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9227,11 +11236,11 @@
922711236 //System.out.println("BLENDING ON");
922811237 gl.glEnable(GL.GL_BLEND);
922911238 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9230
-
11239
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
923111240 gl.glMatrixMode(gl.GL_PROJECTION);
923211241 gl.glLoadIdentity();
923311242
9234
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11243
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
923511244 {
923611245 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923711246 double scale = lightCamera.SCALE / lightCamera.Distance();
....@@ -9289,7 +11298,7 @@
928911298 //gl.glPushMatrix();
929011299 gl.glLoadIdentity();
929111300
9292
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11301
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
929311302 {
929411303 //LA.xformPos(light0, lightCamera.fromScreen, light);
929511304 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9316,8 +11325,8 @@
931611325 System.err.println("parentcam != renderCamera");
931711326
931811327 // if (cam != lightCamera)
9319
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9320
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11328
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11329
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
932111330 }
932211331
932311332 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9338,8 +11347,8 @@
933811347 if (true) // TODO
933911348 {
934011349 if (cam != lightCamera)
9341
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9342
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11350
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11351
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
934311352 }
934411353
934511354 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9376,7 +11385,7 @@
937611385 }
937711386
937811387 /**/
9379
- if (true) // drawMode == SELECTION) // != DEFAULT)
11388
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
938011389 gl.glDisable(gl.GL_LIGHTING);
938111390 else
938211391 gl.glEnable(gl.GL_LIGHTING);
....@@ -9394,7 +11403,7 @@
939411403
939511404 lightslot = 64;
939611405
9397
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11406
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
939811407 {
939911408 DrawLights(object);
940011409 }
....@@ -9405,7 +11414,7 @@
940511414 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
940611415 //System.out.println("fragmentMode = " + fragmentMode);
940711416
9408
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11417
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
940911418 {
941011419 /*
941111420 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9438,7 +11447,7 @@
943811447 }
943911448 }
944011449
9441
- if (drawMode == DEFAULT)
11450
+ if (DrawMode() == DEFAULT)
944211451 {
944311452 if (WIREFRAME && !ambientOcclusion)
944411453 {
....@@ -9456,7 +11465,7 @@
945611465 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
945711466 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
945811467
9459
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11468
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
946011469 {
946111470 if (vertexMode != 0) // && !fast)
946211471 {
....@@ -9476,7 +11485,7 @@
947611485 }
947711486 }
947811487
9479
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11488
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
948011489 {
948111490 //gl.glDepthFunc(GL.GL_LEQUAL);
948211491 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9484,27 +11493,24 @@
948411493
948511494 boolean texon = textureon;
948611495
9487
- if (RENDERPROGRAM > 0)
9488
- {
9489
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9490
- textureon = false;
9491
- }
11496
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11497
+ textureon = false;
11498
+
949211499 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
949311500 //System.out.println("ALLO");
949411501 gl.glColorMask(false, false, false, false);
949511502 DrawObject(gl);
9496
- if (RENDERPROGRAM > 0)
9497
- {
9498
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9499
- textureon = texon;
9500
- }
11503
+
11504
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11505
+ textureon = texon;
11506
+
950111507 gl.glColorMask(true, true, true, true);
950211508
950311509 gl.glDepthFunc(GL.GL_EQUAL);
9504
- //gl.glDepthMask(false);
11510
+ gl.glDepthMask(false);
950511511 }
950611512
9507
- if (false) // drawMode == SHADOW)
11513
+ if (false) // DrawMode() == SHADOW)
950811514 {
950911515 //SetColumnMajorData(cameraInverseTransform, view_1);
951011516 //System.out.println("light = " + cameraInverseTransform);
....@@ -9518,16 +11524,16 @@
951811524 //System.out.println("object = " + object);
951911525 if (!frozen && !imageLocked)
952011526 {
9521
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11527
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
952211528 {
952311529 displayAntiAliased(gl);
952411530 } else
952511531 {
952611532 programcount = 0;
9527
- int keepmode = drawMode;
11533
+ int keepmode = DrawMode();
952811534 // if (DEBUG_SELECTION)
952911535 // {
9530
-// drawMode = SELECTION;
11536
+// DrawMode() = SELECTION;
953111537 // }
953211538 // for point selection
953311539 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9537,10 +11543,10 @@
953711543 DrawObject(gl);
953811544
953911545 // jan 2013 System.err.println("RESET ABORT (display)");
9540
- // if (drawMode == DEFAULT)
11546
+ // if (DrawMode() == DEFAULT)
954111547 // ABORTED = false;
954211548 fullreset = false;
9543
- drawMode = keepmode;
11549
+ Globals.drawMode = keepmode; // WARNING
954411550 //System.out.println("PROGRAM SWITCH " + programcount);
954511551 }
954611552 }
....@@ -9548,11 +11554,11 @@
954811554 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
954911555 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
955011556
9551
- if (drawMode == DEFAULT)
11557
+ if (DrawMode() == DEFAULT)
955211558 {
955311559 ReleaseTexture(NOISE_TEXTURE, false);
955411560 }
9555
- //if (drawMode == DEFAULT)
11561
+ //if (DrawMode() == DEFAULT)
955611562 {
955711563
955811564 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9564,7 +11570,7 @@
956411570 //else
956511571 //gl.glDisable(gl.GL_TEXTURE_2D);
956611572 //gl.glPopMatrix();
9567
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11573
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
956811574 {
956911575 //new Exception().printStackTrace();
957011576 //System.out.println("Draw image " + width + ", " + height);
....@@ -9606,7 +11612,7 @@
960611612 //gl.glFlush();
960711613 }
960811614
9609
- if (flash && drawMode == DEFAULT)
11615
+ if (flash && DrawMode() == DEFAULT)
961011616 {
961111617 flash = false;
961211618 wait = true;
....@@ -9614,9 +11620,9 @@
961411620 }
961511621
961611622 //drawing = false;
9617
- //if(drawMode == DEFAULT)
11623
+ //if(DrawMode() == DEFAULT)
961811624 // niceon = false;
9619
- if (drawMode == DEFAULT)
11625
+ if (DrawMode() == DEFAULT)
962011626 {
962111627 currentlydrawing = false;
962211628 }
....@@ -9636,7 +11642,7 @@
963611642 repaint();
963711643 }
963811644
9639
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11645
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
964011646 repaint();
964111647
964211648 displaydone = true;
....@@ -9655,8 +11661,14 @@
965511661 {
965611662 renderpass++;
965711663 // System.out.println("Draw object... ");
11664
+ STEP = 1;
965811665 if (FAST) // in case there is no script
9659
- STEP = 16;
11666
+ STEP = 8;
11667
+
11668
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11669
+ {
11670
+ STEP *= 4;
11671
+ }
966011672
966111673 //object.FullInvariants();
966211674
....@@ -9670,23 +11682,44 @@
967011682 e.printStackTrace();
967111683 }
967211684
9673
- if (GrafreeD.RENDERME > 0)
9674
- GrafreeD.RENDERME--; // mechante magouille
11685
+ if (Grafreed.RENDERME > 0)
11686
+ Grafreed.RENDERME--; // mechante magouille
967511687
9676
- ONESTEP = false;
11688
+ Globals.ONESTEP = false;
967711689 }
967811690
967911691 static boolean zoomonce = false;
968011692
11693
+ static void CreateSelectedPoint()
11694
+ {
11695
+ if (selectedpoint == null)
11696
+ {
11697
+ debugpointG = new Sphere();
11698
+ debugpointP = new Sphere();
11699
+ debugpointC = new Sphere();
11700
+ debugpointR = new Sphere();
11701
+
11702
+ selectedpoint = new Superellipsoid();
11703
+
11704
+ for (int i=0; i<8; i++)
11705
+ {
11706
+ debugpoints[i] = new Sphere();
11707
+ }
11708
+ }
11709
+ }
11710
+
968111711 void DrawObject(GL gl, boolean draw)
968211712 {
11713
+ // To clear camera values
11714
+ ResetOptions();
11715
+
968311716 //System.out.println("DRAW OBJECT " + mouseDown);
9684
-// drawMode = SELECTION;
11717
+// DrawMode() = SELECTION;
968511718 //GL gl = getGL();
968611719 if ((TRACK || SHADOWTRACK) || zoomonce)
968711720 {
9688
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9689
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11722
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
969011723 pingthread.StepToTarget(true); // true);
969111724 // zoomonce = false;
969211725 }
....@@ -9706,9 +11739,9 @@
970611739 callist = gl.glGenLists(1);
970711740 }
970811741
9709
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11742
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
971011743
9711
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11744
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
971211745
971311746 if (!mainDL || !active || touched)
971411747 {
....@@ -9735,13 +11768,20 @@
973511768 PushMatrix(ClickInfo.matbuffer);
973611769 }
973711770
9738
- if (drawMode == 0)
11771
+ if (DrawMode() == 0)
973911772 {
974011773 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
974111774
974211775 usedtextures.clear();
974311776
9744
- BindTextures(DEFAULT_TEXTURES, 2);
11777
+ try
11778
+ {
11779
+ BindTextures(DEFAULT_TEXTURES, 2);
11780
+ }
11781
+ catch (Exception e)
11782
+ {
11783
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11784
+ }
974511785 }
974611786 //System.out.println("--> " + stackdepth);
974711787 // GrafreeD.traceon();
....@@ -9749,10 +11789,11 @@
974911789 // DRAW
975011790 object.draw(this, /*(Composite)*/ object, false, false);
975111791
9752
- if (drawMode == DEFAULT)
11792
+ if (DrawMode() == DEFAULT)
975311793 {
9754
- if (DEBUG)
11794
+ if (Globals.DEBUG)
975511795 {
11796
+ CreateSelectedPoint();
975611797 float radius = 0.05f;
975711798 if (selectedpoint.radius != radius)
975811799 {
....@@ -9801,38 +11842,57 @@
980111842 }
980211843 // GrafreeD.traceoff();
980311844 //System.out.println(stackdepth);
9804
- if (drawMode == 0)
11845
+ if (DrawMode() == 0)
980511846 {
980611847 ReleaseTextures(DEFAULT_TEXTURES);
980711848
980811849 if (CLEANCACHE)
9809
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
981011851 {
9811
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
981211853
981311854 // System.out.println("Texture --------- " + tex);
981411855
9815
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
981611857 continue;
981711858
9818
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
981911860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
982011862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9821
- textures.get(tex).texture.dispose();
9822
- textures.remove(tex);
11863
+ if (gettex != null)
11864
+ {
11865
+ gettex.texture.dispose();
11866
+ texturepigment.remove(tex);
11867
+ }
11868
+
11869
+ gettex = texturebump.get(tex);
11870
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11871
+ if (gettex != null)
11872
+ {
11873
+ gettex.texture.dispose();
11874
+ texturebump.remove(tex);
11875
+ }
982311876 }
982411877 }
982511878 }
982611879
982711880 checker = null;
982811881
9829
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11882
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
983011883 FindChecker(object);
983111884
9832
- if (checker != null && drawMode == DEFAULT)
11885
+ if (checker != null && DrawMode() == DEFAULT)
983311886 {
983411887 //BindTexture(IMMORTAL_TEXTURE);
9835
- BindTextures(checker.GetTextures(), checker.texres);
11888
+ try
11889
+ {
11890
+ BindTextures(checker.GetTextures(), checker.texres);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + checker.GetTextures());
11895
+ }
983611896 // NEAREST
983711897 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
983811898 DrawChecker(gl);
....@@ -9851,7 +11911,7 @@
985111911 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
985211912 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
985311913
9854
- if (DISPLAYTEXT && drawMode == DEFAULT)
11914
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
985511915 {
985611916 // Draw it once, then use the raster
985711917 Balloon(gl, balloon.createGraphics());
....@@ -9907,14 +11967,14 @@
990711967 int[] xs = new int[3];
990811968 int[] ys = new int[3];
990911969
9910
- void DrawString(Object3D obj) // String string)
11970
+ public void DrawString(Object3D obj) // String string) // INTERFACE
991111971 {
9912
- if (!DISPLAYTEXT || drawMode != DEFAULT)
11972
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
991311973 {
991411974 return;
991511975 }
991611976
9917
- String string = obj.GetToolTip();
11977
+ String string = obj.toString(); //.GetToolTip();
991811978
991911979 GL gl = GetGL();
992011980
....@@ -10231,8 +12291,8 @@
1023112291 //obj.TransformToWorld(light, light);
1023212292 for (int i = tp.size(); --i >= 0;)
1023312293 {
10234
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10235
- LA.xformPos(light, tp.get(i).toParent, light);
12294
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12295
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1023612296 }
1023712297
1023812298
....@@ -10249,8 +12309,8 @@
1024912309 parentcam = cameras[0];
1025012310 }
1025112311
10252
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10253
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12312
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12313
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1025412314
1025512315 LA.xformPos(light, renderCamera.toScreen, light);
1025612316
....@@ -10341,7 +12401,74 @@
1034112401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1034212402
1034312403 String program =
12404
+ // Min shader
1034412405 "!!ARBfp1.0\n" +
12406
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12407
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12408
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12409
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12410
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12411
+ "PARAM light2cam0 = program.env[10];" +
12412
+ "PARAM light2cam1 = program.env[11];" +
12413
+ "PARAM light2cam2 = program.env[12];" +
12414
+ "TEMP temp;" +
12415
+ "TEMP light;" +
12416
+ "TEMP ndotl;" +
12417
+ "TEMP normal;" +
12418
+ "TEMP depth;" +
12419
+ "TEMP eye;" +
12420
+ "TEMP pos;" +
12421
+
12422
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12423
+ Normalize("normal") +
12424
+ "MOV light, state.light[0].position;" +
12425
+ "DP3 ndotl.x, light, normal;" +
12426
+
12427
+ // shadow
12428
+ "MOV pos, fragment.texcoord[1];" +
12429
+ "MOV temp, pos;" +
12430
+ ShadowTextureFetch("depth", "temp", "1") +
12431
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12432
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12433
+
12434
+ // No shadow when out of frustum
12435
+ //"SGE temp.y, depth.z, zero123.y;" +
12436
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12437
+
12438
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12439
+
12440
+ // Backlit
12441
+ "MOV pos.w, zero123.y;" +
12442
+ "DP4 eye.x, pos, light2cam0;" +
12443
+ "DP4 eye.y, pos, light2cam1;" +
12444
+ "DP4 eye.z, pos, light2cam2;" +
12445
+ Normalize("eye") +
12446
+
12447
+ "DP3 ndotl.y, -eye, normal;" +
12448
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12449
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12450
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12451
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12452
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12453
+
12454
+ "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12455
+
12456
+ // Pigment
12457
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12458
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12459
+ "MUL temp, temp, ndotl.x;" +
12460
+
12461
+ "MUL temp, temp, zero123.z;" +
12462
+
12463
+ //"MUL temp, temp, ndotl.y;" +
12464
+
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
12466
+ "MOV result.color, temp;" +
12467
+ "END";
12468
+
12469
+ String program2 =
12470
+ "!!ARBfp1.0\n" +
12471
+
1034512472 //"OPTION ARB_fragment_program_shadow;" +
1034612473 "PARAM light2cam0 = program.env[10];" +
1034712474 "PARAM light2cam1 = program.env[11];" +
....@@ -10456,8 +12583,7 @@
1045612583 "TEMP shininess;" +
1045712584 "\n" +
1045812585 "MOV texSamp, one;" +
10459
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10460
-
12586
+
1046112587 "MOV mapgrid.x, one2048th.x;" +
1046212588 "MOV temp, fragment.texcoord[1];" +
1046312589 /*
....@@ -10478,20 +12604,20 @@
1047812604 "MUL temp, floor, mapgrid.x;" +
1047912605 //"TEX depth0, temp, texture[1], 2D;" +
1048012606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10481
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1048212608 "") +
1048312609 "ADD temp.x, temp.x, mapgrid.x;" +
1048412610 //"TEX depth1, temp, texture[1], 2D;" +
1048512611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10486
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1048712613 "") +
1048812614 "ADD temp.y, temp.y, mapgrid.x;" +
1048912615 //"TEX depth2, temp, texture[1], 2D;" +
10490
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1049112617 "SUB temp.x, temp.x, mapgrid.x;" +
1049212618 //"TEX depth3, temp, texture[1], 2D;" +
1049312619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10494
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1049512621 "") +
1049612622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1049712623 //"MOV params, material;" +
....@@ -10862,10 +12988,10 @@
1086212988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1086312989 "") +
1086412990
10865
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1086612992 "SUB temp.x, half.x, shadow.x;" +
10867
- "MOV temp.y, -params6.x;" +
10868
- "SLT temp.z, temp.y, zero.x;" +
12993
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12994
+ "SLT temp.z, temp.y, -one2048th.x;" +
1086912995 "SUB temp.y, one.x, temp.z;" +
1087012996 "MUL temp.x, temp.x, temp.y;" +
1087112997 "KIL temp.x;" +
....@@ -10994,8 +13120,10 @@
1099413120 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1099513121
1099613122 "SUB temp.x, one.x, ndotl.x;" +
10997
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
10998
- "ADD temp.y, one.y, options2.y;" + // sursurface
13123
+ // Tuning for default skin
13124
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13125
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13126
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1099913127 "MUL temp.x, temp.x, temp.y;" +
1100013128
1100113129 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11194,7 +13322,7 @@
1119413322 //once = true;
1119513323 }
1119613324
11197
- System.out.print("Program #" + mode + "; length = " + program.length());
13325
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1119813326 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1119913327 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1120013328
....@@ -11287,25 +13415,26 @@
1128713415 return out;
1128813416 }
1128913417
11290
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1129113420 {
1129213421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1129313422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1129413423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1129513426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11296
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11297
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11298
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11299
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1130013429 //"SWZ buffer, temp, w,w,w,w;";
11301
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1130213431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1130313432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1130413433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11305
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130613435
11307
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11308
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13436
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13437
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130913438 }
1131013439
1131113440 String Shadow(String depth, String shadow)
....@@ -11327,12 +13456,16 @@
1132713456
1132813457 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1132913458 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13459
+
13460
+ // Compare fragment depth in light space with shadowmap.
1133013461 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1133113462 "SGE temp.y, temp.x, zero.x;" +
11332
- "SUB " + shadow + ".y, one.x, temp.y;" +
13463
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13464
+
13465
+ // Reverse comparison
1133313466 "SUB temp.x, one.x, temp.x;" +
1133413467 "MUL " + shadow + ".x, temp.x, temp.y;" +
11335
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13468
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1133613469 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1133713470
1133813471 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11346,6 +13479,10 @@
1134613479 // No shadow for backface
1134713480 "DP3 temp.x, normal, lightd;" +
1134813481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13482
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13483
+
13484
+ // No shadow when out of frustum
13485
+ "SGE temp.x, " + depth + ".z, one.z;" +
1134913486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1135013487 "";
1135113488 }
....@@ -11492,7 +13629,8 @@
1149213629 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1149313630 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1149413631 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11495
- Object3D.cVector2[] vector2buffer;
13632
+
13633
+ //Object3D.cVector2[] vector2buffer;
1149613634
1149713635 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1149813636 // OUT : diff, spec
....@@ -11508,9 +13646,10 @@
1150813646 "DP3 " + dest + ".z," + "normals," + "eye;" +
1150913647 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1151013648 //"MOV " + dest + ".w," + "normal.z;" +
11511
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11512
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11513
- //"MOV " + dest + ".z," + "params2.w;" +
13649
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13650
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13651
+
13652
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1151413653 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1151513654 "RCP " + dest + ".w," + dest + ".w;" +
1151613655 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11904,7 +14043,7 @@
1190414043 public void mousePressed(MouseEvent e)
1190514044 {
1190614045 //System.out.println("mousePressed: " + e);
11907
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14046
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1190814047 }
1190914048
1191014049 static long prevtime = 0;
....@@ -11931,14 +14070,16 @@
1193114070
1193214071 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1193314072
14073
+ if (BUTTONLESSWHEEL)
1193414074 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1193514075 {
1193614076 return;
1193714077 }
1193814078
14079
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1193914080
1194014081 // TIMER
11941
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14082
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1194214083 {
1194314084 keepboxmode = BOXMODE;
1194414085 keepsupport = SUPPORT;
....@@ -11978,8 +14119,8 @@
1197814119 // mode |= META;
1197914120 //}
1198014121
11981
- SetMouseMode(WHEEL | e.getModifiersEx());
11982
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14122
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14123
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1198314124 anchorX = ax;
1198414125 anchorY = ay;
1198514126 prevX = px;
....@@ -12013,6 +14154,7 @@
1201314154 else
1201414155 if (evt.getSource() == AAtimer)
1201514156 {
14157
+ Globals.TIMERRUNNING = false;
1201614158 if (mouseDown)
1201714159 {
1201814160 //new Exception().printStackTrace();
....@@ -12038,6 +14180,10 @@
1203814180 // LIVE = waslive;
1203914181 // wasliveok = true;
1204014182 // waslive = false;
14183
+
14184
+ // May 2019 Forget it:
14185
+ if (true)
14186
+ return;
1204114187
1204214188 // source == timer
1204314189 if (mouseDown)
....@@ -12067,8 +14213,8 @@
1206714213 // ObjEditor.tweenManager.update(1f / 60f);
1206814214
1206914215 // fev 2014???
12070
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12071
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14216
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14217
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1207214218 pingthread.StepToTarget(true); // true);
1207314219 }
1207414220 // if (!LIVE)
....@@ -12077,12 +14223,13 @@
1207714223
1207814224 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1207914225
12080
- void clickStart(int x, int y, int modifiers)
14226
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1208114227 {
1208214228 if (!wasliveok)
1208314229 return;
1208414230
1208514231 AAtimer.restart(); //
14232
+ Globals.TIMERRUNNING = true;
1208614233
1208714234 // waslive = LIVE;
1208814235 // LIVE = false;
....@@ -12094,7 +14241,7 @@
1209414241 // touched = true; // main DL
1209514242 if (isRenderer)
1209614243 {
12097
- SetMouseMode(modifiers);
14244
+ SetMouseMode(modifiers, modifiersex);
1209814245 }
1209914246
1210014247 selectX = anchorX = x;
....@@ -12107,7 +14254,7 @@
1210714254 clicked = true;
1210814255 hold = false;
1210914256
12110
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14257
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1211114258 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1211214259 {
1211314260 // System.out.println("RESTART II " + modifiers);
....@@ -12132,14 +14279,15 @@
1213214279 drag = false;
1213314280 //System.out.println("Mouse DOWN");
1213414281 editObj = false;
12135
- ClickInfo info = new ClickInfo();
12136
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12137
- info.pane = this;
12138
- info.camera = renderCamera;
12139
- info.x = x;
12140
- info.y = y;
12141
- info.modifiers = modifiers;
12142
- editObj = object.doEditClick(info, 0);
14282
+ //ClickInfo info = new ClickInfo();
14283
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14284
+ object.clickInfo.pane = this;
14285
+ object.clickInfo.camera = renderCamera;
14286
+ object.clickInfo.x = x;
14287
+ object.clickInfo.y = y;
14288
+ object.clickInfo.modifiers = modifiersex;
14289
+ editObj = object.doEditClick(//info,
14290
+ 0);
1214314291 if (!editObj)
1214414292 {
1214514293 hasMarquee = true;
....@@ -12155,11 +14303,14 @@
1215514303
1215614304 public void mouseDragged(MouseEvent e)
1215714305 {
14306
+ Globals.MOUSEDRAGGED = true;
14307
+
14308
+ //System.out.println("mouseDragged: " + e);
1215814309 if (isRenderer)
1215914310 movingcamera = true;
14311
+
1216014312 //if (drawing)
1216114313 //return;
12162
- //System.out.println("mouseDragged: " + e);
1216314314 if ((e.getModifiersEx() & CTRL) != 0
1216414315 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1216514316 {
....@@ -12167,7 +14318,7 @@
1216714318 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1216814319 }
1216914320 else
12170
- drag(e.getX(), e.getY(), e.getModifiersEx());
14321
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1217114322
1217214323 //try { Thread.sleep(1); } catch (Exception ex) {}
1217314324 }
....@@ -12179,6 +14330,11 @@
1217914330 cVector tmp = new cVector();
1218014331 cVector tmp2 = new cVector();
1218114332 boolean isMoving;
14333
+
14334
+ public cVector TargetLookAt()
14335
+ {
14336
+ return targetLookAt;
14337
+ }
1218214338
1218314339 class PingThread extends Thread
1218414340 {
....@@ -12318,7 +14474,7 @@
1231814474 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1231914475 if (lightMode)
1232014476 {
12321
- lighttouched = true;
14477
+ Globals.lighttouched = true;
1232214478 }
1232314479
1232414480 if (OEILONCE && OEIL)
....@@ -12335,6 +14491,7 @@
1233514491
1233614492 public void run()
1233714493 {
14494
+ new Exception().printStackTrace();
1233814495 System.exit(0);
1233914496 for (;;)
1234014497 {
....@@ -12376,7 +14533,7 @@
1237614533 mouseDown = false;
1237714534 if (lightMode)
1237814535 {
12379
- lighttouched = true;
14536
+ Globals.lighttouched = true;
1238014537 }
1238114538 repaint();
1238214539 alreadypainted = true;
....@@ -12384,7 +14541,7 @@
1238414541 isMoving = false;
1238514542 } //??
1238614543
12387
- if (isLIVE() && !alreadypainted)
14544
+ if (Globals.isLIVE() && !alreadypainted)
1238814545 {
1238914546 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1239014547 repaint();
....@@ -12396,9 +14553,9 @@
1239614553 {
1239714554 if (lightMode)
1239814555 {
12399
- lighttouched = true;
14556
+ Globals.lighttouched = true;
1240014557 }
12401
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14558
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1240214559 }
1240314560 //else
1240414561 }
....@@ -12412,12 +14569,12 @@
1241214569 void GoDown(int mod)
1241314570 {
1241414571 MODIFIERS |= COMMAND;
12415
- /*
14572
+ /**/
1241614573 if((mod&SHIFT) == SHIFT)
1241714574 manipCamera.RotatePosition(0, -speed);
1241814575 else
12419
- manipCamera.BackForth(0, -speed*delta, getWidth());
12420
- */
14576
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14577
+ /**/
1242114578 if ((mod & SHIFT) == SHIFT)
1242214579 {
1242314580 mouseMode = mouseMode; // VR??
....@@ -12433,12 +14590,12 @@
1243314590 void GoUp(int mod)
1243414591 {
1243514592 MODIFIERS |= COMMAND;
12436
- /*
14593
+ /**/
1243714594 if((mod&SHIFT) == SHIFT)
1243814595 manipCamera.RotatePosition(0, speed);
1243914596 else
12440
- manipCamera.BackForth(0, speed*delta, getWidth());
12441
- */
14597
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14598
+ /**/
1244214599 if ((mod & SHIFT) == SHIFT)
1244314600 {
1244414601 mouseMode = mouseMode;
....@@ -12454,12 +14611,12 @@
1245414611 void GoLeft(int mod)
1245514612 {
1245614613 MODIFIERS |= COMMAND;
12457
- /*
14614
+ /**/
1245814615 if((mod&SHIFT) == SHIFT)
12459
- manipCamera.RotatePosition(speed, 0);
12460
- else
1246114616 manipCamera.Translate(speed*delta, 0, getWidth());
12462
- */
14617
+ else
14618
+ manipCamera.RotatePosition(speed, 0);
14619
+ /**/
1246314620 if ((mod & SHIFT) == SHIFT)
1246414621 {
1246514622 mouseMode = mouseMode;
....@@ -12475,12 +14632,12 @@
1247514632 void GoRight(int mod)
1247614633 {
1247714634 MODIFIERS |= COMMAND;
12478
- /*
14635
+ /**/
1247914636 if((mod&SHIFT) == SHIFT)
12480
- manipCamera.RotatePosition(-speed, 0);
12481
- else
1248214637 manipCamera.Translate(-speed*delta, 0, getWidth());
12483
- */
14638
+ else
14639
+ manipCamera.RotatePosition(-speed, 0);
14640
+ /**/
1248414641 if ((mod & SHIFT) == SHIFT)
1248514642 {
1248614643 mouseMode = mouseMode;
....@@ -12498,7 +14655,7 @@
1249814655 int X, Y;
1249914656 boolean SX, SY;
1250014657
12501
- void drag(int x, int y, int modifiers)
14658
+ void drag(int x, int y, int modifiers, int modifiersex)
1250214659 {
1250314660 if (IsFrozen())
1250414661 {
....@@ -12507,17 +14664,17 @@
1250714664
1250814665 drag = true; // NEW
1250914666
12510
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14667
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1251114668
1251214669 X = x;
1251314670 Y = y;
1251414671 // floating state for animation
12515
- MODIFIERS = modifiers;
12516
- modifiers &= ~1024;
14672
+ MODIFIERS = modifiersex;
14673
+ modifiersex &= ~1024;
1251714674 if (false) // modifiers != 0)
1251814675 {
1251914676 //new Exception().printStackTrace();
12520
- System.out.println("mouseDragged: " + modifiers);
14677
+ System.out.println("mouseDragged: " + modifiersex);
1252114678 System.out.println("SHIFT = " + SHIFT);
1252214679 System.out.println("CONTROL = " + COMMAND);
1252314680 System.out.println("META = " + META);
....@@ -12530,14 +14687,16 @@
1253014687 if (editObj)
1253114688 {
1253214689 drag = true;
12533
- ClickInfo info = new ClickInfo();
12534
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1253514692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12536
- info.pane = this;
12537
- info.camera = renderCamera;
12538
- info.x = x;
12539
- info.y = y;
12540
- object.editWindow.copy.doEditDrag(info);
14693
+ object.clickInfo.pane = this;
14694
+ object.clickInfo.camera = renderCamera;
14695
+ object.clickInfo.x = x;
14696
+ object.clickInfo.y = y;
14697
+ object //.GetWindow().copy
14698
+ .doEditDrag(//info,
14699
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1254114700 } else
1254214701 {
1254314702 if (x < startX)
....@@ -12639,6 +14798,7 @@
1263914798 {
1264014799 manipCamera.Translate(dx, dy, getWidth());
1264114800 }
14801
+ else
1264214802 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1264314803 {
1264414804 manipCamera.RotateInterest(dx, dy);
....@@ -12649,7 +14809,7 @@
1264914809
1265014810 if (manipCamera == lightCamera)
1265114811 {
12652
- lighttouched = true;
14812
+ Globals.lighttouched = true;
1265314813 }
1265414814 /*
1265514815 switch (mode)
....@@ -12685,23 +14845,27 @@
1268514845 }
1268614846 }
1268714847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1268814850 public void mouseMoved(MouseEvent e)
1268914851 {
1269014852 //System.out.println("mouseMoved: " + e);
12691
-
1269214853 if (isRenderer)
1269314854 return;
1269414855
12695
- ClickInfo ci = new ClickInfo();
12696
- ci.x = e.getX();
12697
- ci.y = e.getY();
12698
- ci.modifiers = e.getModifiersEx();
12699
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12700
- ci.pane = this;
12701
- ci.camera = renderCamera;
14856
+ // Mouse cursor feedback
14857
+ object.clickInfo.x = e.getX();
14858
+ object.clickInfo.y = e.getY();
14859
+ object.clickInfo.modifiers = e.getModifiersEx();
14860
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14861
+ object.clickInfo.pane = this;
14862
+ object.clickInfo.camera = renderCamera;
1270214863 if (!isRenderer)
1270314864 {
12704
- if (object.editWindow.copy.doEditClick(ci, 0))
14865
+ //ObjEditor editWindow = object.editWindow;
14866
+ //Object3D copy = editWindow.copy;
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1270514869 {
1270614870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1270714871 } else
....@@ -12713,7 +14877,11 @@
1271314877
1271414878 public void mouseReleased(MouseEvent e)
1271514879 {
14880
+ Globals.MOUSEDRAGGED = false;
14881
+
1271614882 movingcamera = false;
14883
+ X = 0; // getBounds().width/2;
14884
+ Y = 0; // getBounds().height/2;
1271714885 //System.out.println("mouseReleased: " + e);
1271814886 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1271914887 }
....@@ -12736,9 +14904,9 @@
1273614904 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1273714905 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1273814906
12739
- if (control || command || IsFrozen())
14907
+// No delay if (control || command || IsFrozen())
1274014908 timeout = true;
12741
- else
14909
+// ?? May 2019 else
1274214910 // timer.setDelay((modifiers & 128) != 0?0:350);
1274314911 mouseDown = false;
1274414912 if (!control && !command) // june 2013
....@@ -12848,7 +15016,7 @@
1284815016 System.out.println("keyReleased: " + e);
1284915017 }
1285015018
12851
- void SetMouseMode(int modifiers)
15019
+ void SetMouseMode(int modifiers, int modifiersex)
1285215020 {
1285315021 //System.out.println("SetMouseMode = " + modifiers);
1285415022 //modifiers &= ~1024;
....@@ -12860,25 +15028,25 @@
1286015028 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1286115029 // return;
1286215030 //System.out.println("SetMode = " + modifiers);
12863
- if ((modifiers & WHEEL) == WHEEL)
15031
+ if ((modifiersex & WHEEL) == WHEEL)
1286415032 {
1286515033 mouseMode |= ZOOM;
1286615034 }
1286715035
1286815036 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
12869
- if (capsLocked || (modifiers & META) == META)
15037
+ if (capsLocked) // || (modifiers & META) == META)
1287015038 {
1287115039 mouseMode |= VR; // BACKFORTH;
1287215040 }
12873
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12874
- {
12875
- mouseMode |= SELECT; // BACKFORTH;
12876
- }
12877
- if ((modifiers & COMMAND) == COMMAND)
15041
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1287815042 {
1287915043 mouseMode |= SELECT;
1288015044 }
12881
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15045
+ if ((modifiersex & COMMAND) == COMMAND)
15046
+ {
15047
+ mouseMode |= SELECT;
15048
+ }
15049
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1288215050 {
1288315051 mouseMode &= ~VR;
1288415052 mouseMode |= TRANSLATE;
....@@ -12907,10 +15075,10 @@
1290715075
1290815076 if (isRenderer) //
1290915077 {
12910
- SetMouseMode(modifiers);
15078
+ SetMouseMode(0, modifiers);
1291115079 }
1291215080
12913
- theRenderer.keyPressed(key);
15081
+ Globals.theRenderer.keyPressed(key);
1291415082 }
1291515083
1291615084 int kompactbit = 4; // power bit
....@@ -12922,7 +15090,7 @@
1292215090 float SATPOW = 1; // 2; // 0.5f;
1292315091 float BRIPOW = 1; // 0.5f; // 0.5f;
1292415092
12925
- void keyPressed(int key)
15093
+ public void keyPressed(int key)
1292615094 {
1292715095 if (key >= '0' && key <= '5')
1292815096 clampbit = (key-'0');
....@@ -12969,7 +15137,8 @@
1296915137 // break;
1297015138 case 'T':
1297115139 CACHETEXTURE ^= true;
12972
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1297315142 // repaint();
1297415143 break;
1297515144 case 'Y':
....@@ -13037,7 +15206,7 @@
1303715206 case 'B':
1303815207 BRISMOOTH ^= true;
1303915208 SHADOWCULLFACE ^= true;
13040
- lighttouched = true;
15209
+ Globals.lighttouched = true;
1304115210 repaint();
1304215211 break;
1304315212 case 'b':
....@@ -13054,7 +15223,9 @@
1305415223 case 'E' : COMPACT ^= true;
1305515224 repaint();
1305615225 break;
13057
- case 'W' : DEBUGHSB ^= true;
15226
+ case 'W' : // Wide Window (fullscreen)
15227
+ //DEBUGHSB ^= true;
15228
+ ObjEditor.theFrame.ToggleFullScreen();
1305815229 repaint();
1305915230 break;
1306015231 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13079,8 +15250,8 @@
1307915250 RevertCamera();
1308015251 repaint();
1308115252 break;
13082
- case 'L':
1308315253 case 'l':
15254
+ //case 'L':
1308415255 if (lightMode)
1308515256 {
1308615257 lightMode = false;
....@@ -13137,7 +15308,7 @@
1313715308 repaint();
1313815309 break;
1313915310 case 'O':
13140
- drawMode = OCCLUSION;
15311
+ Globals.drawMode = OCCLUSION; // WARNING
1314115312 repaint();
1314215313 break;
1314315314 case 'o':
....@@ -13223,12 +15394,12 @@
1322315394 case '_':
1322415395 kompactbit = 5;
1322515396 break;
13226
- case '+':
13227
- kompactbit = 6;
13228
- break;
15397
+// case '+':
15398
+// kompactbit = 6;
15399
+// break;
1322915400 case ' ':
1323015401 lightMode ^= true;
13231
- lighttouched = true;
15402
+ Globals.lighttouched = true;
1323215403 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1323315404 targetLookAt.set(manipCamera.lookAt);
1323415405 repaint();
....@@ -13237,14 +15408,15 @@
1323715408 case ESC:
1323815409 RENDERPROGRAM += 1;
1323915410 RENDERPROGRAM %= 3;
15411
+
1324015412 repaint();
1324115413 break;
1324215414 case 'Z':
13243
- RESIZETEXTURE ^= true;
13244
- break;
15415
+ //RESIZETEXTURE ^= true;
15416
+ //break;
1324515417 case 'z':
13246
- RENDERSHADOW ^= true;
13247
- lighttouched = true;
15418
+ Globals.RENDERSHADOW ^= true;
15419
+ Globals.lighttouched = true;
1324815420 repaint();
1324915421 break;
1325015422 //case UP:
....@@ -13276,8 +15448,9 @@
1327615448 case DELETE:
1327715449 ClearSelection();
1327815450 break;
13279
- /*
1328015451 case '+':
15452
+
15453
+ /*
1328115454 //fontsize += 1;
1328215455 bbzoom *= 2;
1328315456 repaint();
....@@ -13294,17 +15467,17 @@
1329415467 case '=':
1329515468 IncDepth();
1329615469 //fontsize += 1;
13297
- object.editWindow.refreshContents(true);
15470
+ object.GetWindow().refreshContents(true);
1329815471 maskbit = 6;
1329915472 break;
1330015473 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1330115474 DecDepth();
1330215475 maskbit = 5;
1330315476 //if(fontsize > 1) fontsize -= 1;
13304
- if (object.editWindow == null)
13305
- new Exception().printStackTrace();
13306
- else
13307
- object.editWindow.refreshContents(true);
15477
+// if (object.editWindow == null)
15478
+// new Exception().printStackTrace();
15479
+// else
15480
+ object.GetWindow().refreshContents(true);
1330815481 break;
1330915482 case '{':
1331015483 manipCamera.shaper_fovy /= 1.1;
....@@ -13359,6 +15532,7 @@
1335915532 }
1336015533 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1336115534 }
15535
+
1336215536 static double OCCLUSIONBOOST = 1; // 0.5;
1336315537
1336415538 void keyReleased(int key, int modifiers)
....@@ -13366,11 +15540,11 @@
1336615540 //mode = ROTATE;
1336715541 if ((MODIFIERS & COMMAND) == 0) // VR??
1336815542 {
13369
- SetMouseMode(modifiers);
15543
+ SetMouseMode(0, modifiers);
1337015544 }
1337115545 }
1337215546
13373
- protected void processKeyEvent(KeyEvent e)
15547
+ public void processKeyEvent(KeyEvent e)
1337415548 {
1337515549 switch (e.getID())
1337615550 {
....@@ -13500,8 +15674,9 @@
1350015674
1350115675 protected void processMouseMotionEvent(MouseEvent e)
1350215676 {
13503
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13504
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15677
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15678
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15679
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1350515680 {
1350615681 mouseMoved(e);
1350715682 } else
....@@ -13526,11 +15701,12 @@
1352615701 }
1352715702 */
1352815703
13529
- object.editWindow.EditSelection();
15704
+ object.GetWindow().EditSelection(false);
1353015705 }
1353115706
1353215707 void SelectParent()
1353315708 {
15709
+ new Exception().printStackTrace();
1353415710 System.exit(0);
1353515711 Composite group = (Composite) object;
1353615712 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13542,10 +15718,10 @@
1354215718 {
1354315719 //selectees.remove(i);
1354415720 System.out.println("select parent of " + elem);
13545
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15721
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1354615722 } else
1354715723 {
13548
- group.editWindow.Select(elem.GetTreePath(), first, true);
15724
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1354915725 }
1355015726
1355115727 first = false;
....@@ -13554,6 +15730,7 @@
1355415730
1355515731 void SelectChildren()
1355615732 {
15733
+ new Exception().printStackTrace();
1355715734 System.exit(0);
1355815735 /*
1355915736 Composite group = (Composite) object;
....@@ -13586,12 +15763,12 @@
1358615763 for (int j = 0; j < group.children.size(); j++)
1358715764 {
1358815765 elem = (Object3D) group.children.elementAt(j);
13589
- object.editWindow.Select(elem.GetTreePath(), first, true);
15766
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1359015767 first = false;
1359115768 }
1359215769 } else
1359315770 {
13594
- object.editWindow.Select(elem.GetTreePath(), first, true);
15771
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1359515772 }
1359615773
1359715774 first = false;
....@@ -13602,21 +15779,21 @@
1360215779 {
1360315780 //Composite group = (Composite) object;
1360415781 Object3D group = object;
13605
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15782
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1360615783 }
1360715784
1360815785 void ResetTransform(int mask)
1360915786 {
1361015787 //Composite group = (Composite) object;
1361115788 Object3D group = object;
13612
- group.editWindow.ResetTransform(mask);
15789
+ group.GetWindow().ResetTransform(mask);
1361315790 }
1361415791
1361515792 void FlipTransform()
1361615793 {
1361715794 //Composite group = (Composite) object;
1361815795 Object3D group = object;
13619
- group.editWindow.FlipTransform();
15796
+ group.GetWindow().FlipTransform();
1362015797 // group.editWindow.ReduceMesh(true);
1362115798 }
1362215799
....@@ -13624,7 +15801,7 @@
1362415801 {
1362515802 //Composite group = (Composite) object;
1362615803 Object3D group = object;
13627
- group.editWindow.PrintMemory();
15804
+ group.GetWindow().PrintMemory();
1362815805 // group.editWindow.ReduceMesh(true);
1362915806 }
1363015807
....@@ -13632,7 +15809,7 @@
1363215809 {
1363315810 //Composite group = (Composite) object;
1363415811 Object3D group = object;
13635
- group.editWindow.ResetCentroid();
15812
+ group.GetWindow().ResetCentroid();
1363615813 }
1363715814
1363815815 void IncDepth()
....@@ -13714,11 +15891,11 @@
1371415891
1371515892 int width = getBounds().width;
1371615893 int height = getBounds().height;
13717
- ClickInfo info = new ClickInfo();
13718
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1371915894 //Image img = CreateImage(width, height);
1372015895 //System.out.println("width = " + width + "; height = " + height + "\n");
15896
+
1372115897 Graphics gr = g; // img.getGraphics();
15898
+
1372215899 if (!hasMarquee)
1372315900 {
1372415901 if (Xmin < Xmax) // !locked)
....@@ -13790,40 +15967,88 @@
1379015967 }
1379115968 if (object != null && !hasMarquee)
1379215969 {
15970
+ if (object.clickInfo == null)
15971
+ object.clickInfo = new ClickInfo();
15972
+ ClickInfo info = object.clickInfo;
15973
+ //ClickInfo info = new ClickInfo();
15974
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15975
+
1379315976 if (isRenderer)
1379415977 {
13795
- info.flags++;
15978
+ object.clickInfo.flags++;
1379615979 double frameAspect = (double) width / (double) height;
1379715980 if (frameAspect > renderCamera.aspect)
1379815981 {
1379915982 int desired = (int) ((double) height * renderCamera.aspect);
13800
- info.bounds.width -= width - desired;
13801
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1380215985 } else
1380315986 {
1380415987 int desired = (int) ((double) width / renderCamera.aspect);
13805
- info.bounds.height -= height - desired;
13806
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1380715990 }
1380815991 }
13809
- info.g = gr;
13810
- info.camera = renderCamera;
15992
+
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1381115995 /*
1381215996 // Memory intensive (brep.verticescopy)
1381315997 if (!(object instanceof Composite))
1381415998 object.draw(info, 0, false); // SLOW :
1381515999 */
13816
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1381716001 {
13818
- object.drawEditHandles(info, 0);
16002
+ Grafreed.Assert(object != null);
16003
+ Grafreed.Assert(object.selection != null);
16004
+ if (object.selection.Size() > 0)
16005
+ {
16006
+ int hitSomething = object.selection.get(0).hitSomething;
16007
+
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
16011
+ if (hitSomething == Object3D.hitCenter)
16012
+ {
16013
+ info.DX = X;
16014
+ if (X != 0)
16015
+ info.DX -= info.bounds.width/2;
16016
+
16017
+ info.DY = Y;
16018
+ if (Y != 0)
16019
+ info.DY -= info.bounds.height/2;
16020
+ }
16021
+
16022
+ object.drawEditHandles(//info,
16023
+ 0);
16024
+
16025
+ if (drag && (X != 0 || Y != 0))
16026
+ {
16027
+ switch (hitSomething)
16028
+ {
16029
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16030
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16031
+ break;
16032
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16033
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16034
+ break;
16035
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16036
+ gr.drawLine(X, Y, 0, 0);
16037
+ break;
16038
+ }
16039
+
16040
+ }
16041
+ }
1381916042 }
1382016043 }
16044
+
1382116045 if (isRenderer)
1382216046 {
1382316047 //gr.setColor(Color.black);
1382416048 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1382516049 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1382616050 }
16051
+
1382716052 if (hasMarquee)
1382816053 {
1382916054 gr.setXORMode(Color.white);
....@@ -13846,6 +16071,7 @@
1384616071 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1384716072 }
1384816073
16074
+ // To avoid clear.
1384916075 public void update(Graphics g)
1385016076 {
1385116077 paint(g);
....@@ -13935,6 +16161,7 @@
1393516161 public boolean mouseDown(Event evt, int x, int y)
1393616162 {
1393716163 System.out.println("mouseDown: " + evt);
16164
+ System.exit(0);
1393816165 /*
1393916166 locked = true;
1394016167 drag = false;
....@@ -13978,7 +16205,7 @@
1397816205 {
1397916206 keyPressed(0, modifiers);
1398016207 }
13981
- clickStart(x, y, modifiers);
16208
+ // clickStart(x, y, modifiers);
1398216209 return true;
1398316210 }
1398416211
....@@ -14096,7 +16323,7 @@
1409616323 {
1409716324 keyReleased(0, 0);
1409816325 }
14099
- drag(x, y, modifiers);
16326
+ drag(x, y, 0, modifiers);
1410016327 return true;
1410116328 }
1410216329
....@@ -14228,7 +16455,7 @@
1422816455 Object3D object;
1422916456 static Object3D trackedobject;
1423016457 Camera renderCamera; // Light or Eye (or Occlusion)
14231
- /*static*/ Camera manipCamera; // Light or Eye
16458
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1423216459 /*static*/ Camera eyeCamera;
1423316460 /*static*/ Camera lightCamera;
1423416461 int cameracount;
....@@ -14508,20 +16735,21 @@
1450816735 /**/
1450916736 //checker.GetMaterial().opacity = 1.1f;
1451016737 ////checker.GetMaterial().ambient = 0.99f;
14511
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14512
- Object3D.selectedstack[Object3D.materialdepth] = false;
14513
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16738
+ materialstack[materialdepth] = checker.material;
16739
+ selectedstack[materialdepth] = false;
16740
+ cStatic.objectstack[materialdepth++] = checker;
1451416741 //System.out.println("material " + material);
1451516742 //Applet3D.tracein(this, selected);
14516
- vector2buffer = checker.projectedVertices;
16743
+ //vector2buffer = checker.projectedVertices;
1451716744
14518
- checker.GetMaterial().Draw(this, false); // true);
16745
+ //checker.GetMaterial().Draw(this, false); // true);
16746
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1451916747
14520
- Object3D.materialdepth -= 1;
14521
- if (Object3D.materialdepth > 0)
16748
+ materialdepth -= 1;
16749
+ if (materialdepth > 0)
1452216750 {
14523
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14524
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16751
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16752
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1452516753 }
1452616754 //checker.GetMaterial().opacity = 1f;
1452716755 ////checker.GetMaterial().ambient = 1f;
....@@ -14607,6 +16835,14 @@
1460716835 }
1460816836 }
1460916837
16838
+ private Object3D GetFolder()
16839
+ {
16840
+ Object3D folder = object.GetWindow().copy;
16841
+ if (object.GetWindow().copy.selection.Size() > 0)
16842
+ folder = object.GetWindow().copy.selection.elementAt(0);
16843
+ return folder;
16844
+ }
16845
+
1461016846 class SelectBuffer implements GLEventListener
1461116847 {
1461216848
....@@ -14665,6 +16901,7 @@
1466516901 {
1466616902 if (!selection)
1466716903 {
16904
+ new Exception().printStackTrace();
1466816905 System.exit(0);
1466916906 return;
1467016907 }
....@@ -14685,17 +16922,39 @@
1468516922
1468616923 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1468716924
16925
+ if (PAINTMODE)
16926
+ {
16927
+ if (object.GetWindow().copy.selection.Size() > 0)
16928
+ {
16929
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16930
+
16931
+ // Make what you paint not selectable.
16932
+ paintobj.ResetSelectable();
16933
+ }
16934
+ }
16935
+
1468816936 //int tmp = selection_view;
1468916937 //selection_view = -1;
14690
- int temp = drawMode;
14691
- drawMode = SELECTION;
16938
+ int temp = DrawMode();
16939
+ Globals.drawMode = SELECTION; // WARNING
1469216940 indexcount = 0;
1469316941 parent.display(drawable);
1469416942 //selection_view = tmp;
1469516943 //if (temp == SELECTION)
1469616944 // temp = DEFAULT; // patch for selection debug
14697
- drawMode = temp;
16945
+ Globals.drawMode = temp; // WARNING
1469816946
16947
+ if (PAINTMODE)
16948
+ {
16949
+ if (object.GetWindow().copy.selection.Size() > 0)
16950
+ {
16951
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16952
+
16953
+ // Revert.
16954
+ paintobj.RestoreSelectable();
16955
+ }
16956
+ }
16957
+
1469916958 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1470016959
1470116960 // trying different ways of getting the depth info over
....@@ -14743,6 +17002,8 @@
1474317002 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1474417003 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1474517004 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17005
+
17006
+ CreateSelectedPoint();
1474617007
1474717008 // Will fit the mesh !!!
1474817009 selectedpoint.toParent[0][0] = 0.0001;
....@@ -14792,34 +17053,36 @@
1479217053 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]));
1479317054 }
1479417055
14795
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17056
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1479617057 }
1479717058 }
1479817059
1479917060 if (!movingcamera && !PAINTMODE)
14800
- object.editWindow.ScreenFitPoint(); // fev 2014
17061
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1480117062
14802
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17063
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1480317064 {
14804
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17065
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1480517066
14806
- Object3D group = new Object3D("inst" + paintcount++);
17067
+ if (object.GetWindow().copy.selection.Size() > 0)
17068
+ {
17069
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1480717070
14808
- group.CreateMaterial(); // use a void leaf to select instances
14809
-
14810
- group.add(paintobj); // link
14811
-
14812
- object.editWindow.SnapObject(group);
14813
-
14814
- Object3D folder = object.editWindow.copy;
14815
-
14816
- if (object.editWindow.copy.selection.Size() > 0)
14817
- folder = object.editWindow.copy.selection.elementAt(0);
14818
-
14819
- folder.add(group);
14820
-
14821
- object.editWindow.ResetModel();
14822
- object.editWindow.refreshContents();
17071
+ Object3D inst = new Object3D("inst" + paintcount++);
17072
+
17073
+ inst.CreateMaterial(); // use a void leaf to select instances
17074
+
17075
+ inst.add(paintobj); // link
17076
+
17077
+ object.GetWindow().SnapObject(inst);
17078
+
17079
+ Object3D folder = paintFolder; // GetFolder();
17080
+
17081
+ folder.add(inst);
17082
+
17083
+ object.GetWindow().ResetModel();
17084
+ object.GetWindow().refreshContents();
17085
+ }
1482317086 }
1482417087 else
1482517088 paintcount = 0;
....@@ -14858,6 +17121,11 @@
1485817121 //System.out.println("objects[color] = " + objects[color]);
1485917122 //objects[color].Select();
1486017123 indexcount = 0;
17124
+ ObjEditor window = object.GetWindow();
17125
+ if (window != null && deselect)
17126
+ {
17127
+ window.Select(null, deselect, true);
17128
+ }
1486117129 object.Select(color, deselect);
1486217130 }
1486317131
....@@ -14957,7 +17225,7 @@
1495717225 gl.glDisable(gl.GL_CULL_FACE);
1495817226 }
1495917227
14960
- if (!RENDERSHADOW)
17228
+ if (!Globals.RENDERSHADOW)
1496117229 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1496217230
1496317231 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14967,14 +17235,14 @@
1496717235 //gl.glColorMask(false, false, false, false);
1496817236
1496917237 //render_scene_from_light_view(gl, drawable, 0, 0);
14970
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17238
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1497117239 {
1497217240 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1497317241
14974
- int temp = drawMode;
14975
- drawMode = SHADOW;
17242
+ int temp = DrawMode();
17243
+ Globals.drawMode = SHADOW; // WARNING
1497617244 parent.display(drawable);
14977
- drawMode = temp;
17245
+ Globals.drawMode = temp; // WARNING
1497817246 }
1497917247
1498017248 gl.glCullFace(gl.GL_BACK);
....@@ -15027,7 +17295,6 @@
1502717295
1502817296 class AntialiasBuffer implements GLEventListener
1502917297 {
15030
-
1503117298 CameraPane parent = null;
1503217299
1503317300 AntialiasBuffer(CameraPane p)
....@@ -15372,12 +17639,6 @@
1537217639 GLUT glut = new GLUT();
1537317640
1537417641
15375
- static final public int DEFAULT = 0;
15376
- static final public int SELECTION = 1;
15377
- static final public int SHADOW = 2;
15378
- static final public int OCCLUSION = 3;
15379
- static
15380
- public int drawMode = DEFAULT;
1538117642 public boolean spherical = false;
1538217643 static boolean DEBUG_OCCLUSION = false;
1538317644 static boolean DEBUG_SELECTION = false;
....@@ -15390,23 +17651,15 @@
1539017651 int AAbuffersize = 0;
1539117652
1539217653 //double[] selectedpoint = new double[3];
15393
- static Superellipsoid selectedpoint = new Superellipsoid();
17654
+ static Superellipsoid selectedpoint;
1539417655 static Sphere previousselectedpoint = null;
15395
- static Sphere debugpointG = new Sphere();
15396
- static Sphere debugpointP = new Sphere();
15397
- static Sphere debugpointC = new Sphere();
15398
- static Sphere debugpointR = new Sphere();
17656
+ static Sphere debugpointG;
17657
+ static Sphere debugpointP;
17658
+ static Sphere debugpointC;
17659
+ static Sphere debugpointR;
1539917660
1540017661 static Sphere debugpoints[] = new Sphere[8];
1540117662
15402
- static
15403
- {
15404
- for (int i=0; i<8; i++)
15405
- {
15406
- debugpoints[i] = new Sphere();
15407
- }
15408
- }
15409
-
1541017663 static void InitPoints(float radius)
1541117664 {
1541217665 for (int i=0; i<8; i++)
....@@ -15426,7 +17679,7 @@
1542617679 }
1542717680 }
1542817681
15429
- static void DrawPoints(CameraPane cpane)
17682
+ static void DrawPoints(iCameraPane cpane)
1543017683 {
1543117684 for (int i=0; i<8; i++) // first and last are red
1543217685 {
....@@ -15458,10 +17711,11 @@
1545817711 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1545917712 // Depth buffer format
1546017713 //private int depth_format;
15461
- static public void NextIndex(Object3D o, GL gl)
17714
+
17715
+ public void NextIndex()
1546217716 {
1546317717 indexcount+=16;
15464
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17718
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1546517719 //objects[indexcount] = o;
1546617720 //System.out.println("indexcount = " + indexcount);
1546717721 }