Normand Briere
2019-07-23 cf7cfa1c792eebba606a48aa648893f6e4873263
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)
....@@ -206,12 +227,53 @@
206227 return CURRENTANTIALIAS > 0;
207228 }
208229
209
- void ClearDepth()
230
+ /// INTERFACE
231
+
232
+ public javax.media.opengl.GL GetGL0()
233
+ {
234
+ return null;
235
+ }
236
+
237
+ public int GenList()
238
+ {
239
+ javax.media.opengl.GL gl = GetGL();
240
+ return gl.glGenLists(1);
241
+ }
242
+
243
+ public void NewList(int id)
244
+ {
245
+ javax.media.opengl.GL gl = GetGL();
246
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
247
+ }
248
+
249
+ public void CallList(int id)
250
+ {
251
+ javax.media.opengl.GL gl = GetGL();
252
+ gl.glCallList(id);
253
+ }
254
+
255
+ public void EndList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ gl.glEndList();
259
+ }
260
+
261
+ public boolean IsBoxMode()
262
+ {
263
+ return BOXMODE;
264
+ }
265
+
266
+ public boolean IsZoomBoxMode()
267
+ {
268
+ return ZOOMBOXMODE;
269
+ }
270
+
271
+ public void ClearDepth()
210272 {
211273 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
212274 }
213275
214
- void DepthTest(boolean depthtest)
276
+ public void DepthTest(boolean depthtest)
215277 {
216278 if (depthtest)
217279 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -219,7 +281,7 @@
219281 GetGL().glDepthFunc(GL.GL_ALWAYS);
220282 }
221283
222
- void DepthWrite(boolean depthwrite)
284
+ public void DepthWrite(boolean depthwrite)
223285 {
224286 if (depthwrite)
225287 GetGL().glDepthMask(true);
....@@ -227,12 +289,1616 @@
227289 GetGL().glDepthMask(false);
228290 }
229291
230
- void BackFaceCull(boolean bfc)
292
+ public void BackFaceCull(boolean bfc)
231293 {
232294 if (bfc)
233295 GetGL().glEnable(GetGL().GL_CULL_FACE);
234296 else
235297 GetGL().glDisable(GetGL().GL_CULL_FACE);
298
+ }
299
+
300
+ public boolean BackFaceCullMode()
301
+ {
302
+ return this.CULLFACE;
303
+ }
304
+
305
+ public boolean IsAmbientOcclusionOn()
306
+ {
307
+ return this.ambientOcclusion;
308
+ }
309
+
310
+ public boolean IsDebugSelection()
311
+ {
312
+ return DEBUG_SELECTION;
313
+ }
314
+
315
+ public boolean IsFrozen()
316
+ {
317
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
318
+
319
+ return !selectmode && cameracount == 0; // != 0;
320
+ }
321
+
322
+ // Currently in Globals
323
+ public int DrawMode()
324
+ {
325
+ return Globals.DrawMode();
326
+ }
327
+
328
+ public Camera EyeCamera()
329
+ {
330
+ return eyeCamera;
331
+ }
332
+
333
+ public Camera LightCamera()
334
+ {
335
+ return lightCamera;
336
+ }
337
+
338
+ public Camera ManipCamera()
339
+ {
340
+ return manipCamera;
341
+ }
342
+
343
+ public Camera RenderCamera()
344
+ {
345
+ return renderCamera;
346
+ }
347
+
348
+ public Camera[] Cameras()
349
+ {
350
+ return cameras;
351
+ }
352
+
353
+ public void PushMaterial(Object3D obj, boolean selected)
354
+ {
355
+ CameraPane display = this;
356
+ javax.media.opengl.GL gl = display.GetGL();
357
+ cMaterial material = obj.material;
358
+
359
+ if (material != null)
360
+ {
361
+ materialstack[materialdepth] = material;
362
+ selectedstack[materialdepth] = selected;
363
+ cStatic.objectstack[materialdepth++] = obj;
364
+ //System.out.println("material " + material);
365
+ //Applet3D.tracein(this, selected);
366
+ //display.vector2buffer = obj.projectedVertices;
367
+ if (obj instanceof Camera)
368
+ {
369
+ display.options1[0] = material.shift;
370
+ //System.out.println("shift " + material.shift);
371
+ display.options1[1] = material.lightarea;
372
+ display.options1[2] = material.shadowbias;
373
+ display.options1[3] = material.aniso;
374
+ display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
380
+ display.options2[0] = material.opacity;
381
+ display.options2[1] = material.diffuse;
382
+ display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
386
+
387
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
391
+ display.options4[0] = material.cameralight/0.2f;
392
+ display.options4[1] = material.subsurface;
393
+ display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
397
+
398
+ // if (display.CURRENTANTIALIAS > 0)
399
+ // display.options3[3] /= 4;
400
+
401
+ /*
402
+ System.out.println("Focus = " + display.options1[0]);
403
+ System.out.println("Aperture = " + display.options1[1]);
404
+ System.out.println("ShadowBlur = " + display.options1[2]);
405
+ System.out.println("Antialiasing = " + display.options1[3]);
406
+ System.out.println("Fog = " + display.options2[0]);
407
+ System.out.println("Intensity = " + display.options2[1]);
408
+ System.out.println("Elevation = " + display.options2[2]);
409
+ /**/
410
+ } else
411
+ {
412
+ DrawMaterial(material, selected, obj.projectedVertices);
413
+ }
414
+ } else
415
+ {
416
+ if (selected && CameraPane.flash)
417
+ {
418
+ display.modelParams4[1] = 100;
419
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
420
+ }
421
+ }
422
+ }
423
+
424
+ public void PushMaterial2(Object3D obj, boolean selected)
425
+ {
426
+ CameraPane display = this;
427
+ cMaterial material = obj.material;
428
+
429
+ if (material != null)
430
+ {
431
+ materialstack[materialdepth] = material;
432
+ selectedstack[materialdepth] = selected;
433
+ cStatic.objectstack[materialdepth++] = obj;
434
+ //System.out.println("material " + material);
435
+ //Applet3D.tracein("selected ", selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
438
+ }
439
+ }
440
+
441
+ public void PopMaterial(Object3D obj, boolean selected)
442
+ {
443
+ CameraPane display = this;
444
+ javax.media.opengl.GL gl = display.GetGL();
445
+ cMaterial material = obj.material;
446
+
447
+ //if (parent != null && parent.GetMaterial() != null)
448
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
449
+ if (material != null)
450
+ {
451
+ materialdepth -= 1;
452
+ if (materialdepth > 0)
453
+ {
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
456
+ }
457
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
458
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
459
+ {
460
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
461
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
462
+ }
463
+ }
464
+
465
+ public void PopMaterial2(Object3D obj)
466
+ {
467
+ CameraPane display = this;
468
+ cMaterial material = obj.material;
469
+
470
+ if (material != null)
471
+ {
472
+ materialdepth -= 1;
473
+ if (materialdepth > 0)
474
+ {
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
477
+ }
478
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
479
+ //else
480
+ //material.Draw(display, false);
481
+ }
482
+ }
483
+
484
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
485
+ {
486
+ CameraPane display = this;
487
+
488
+ if (pv.y == -10000 ||
489
+ qv.y == -10000 ||
490
+ rv.y == -10000)
491
+ return;
492
+
493
+// float b = f.nbiterations & 1;
494
+// float g = (f.nbiterations>>1) & 1;
495
+// float r = (f.nbiterations>>2) & 1;
496
+//
497
+// //if (f.weight == 10000)
498
+// //{
499
+// // r = 1; g = b = 0;
500
+// //}
501
+// //else
502
+// //{
503
+// // assert(f.weight < 10000);
504
+// r = g = b = (float)bRep.FaceWeight(f)*100;
505
+// if (r<0)
506
+// assert(r>=0);
507
+// //}
508
+
509
+ javax.media.opengl.GL gl = display.GetGL();
510
+
511
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
512
+
513
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
514
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
515
+ {
516
+ //gl.glBegin(gl.GL_TRIANGLES);
517
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
518
+ // TEST LIVE NORMALS && !obj.dontselect
519
+ ;
520
+ if (!hasnorm)
521
+ {
522
+ // System.out.println("Mesh normal");
523
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
524
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
525
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
526
+ LA.vecNormalize(obj.v2);
527
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
528
+ }
529
+
530
+ // P
531
+ float x = (float)pv.x;
532
+ float y = (float)pv.y;
533
+ float z = (float)pv.z;
534
+
535
+ if (hasnorm)
536
+ {
537
+// if (!pv.norm.normalized())
538
+// assert(pv.norm.normalized());
539
+
540
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
541
+ float nx = (float)pv.norm.x;
542
+ float ny = (float)pv.norm.y;
543
+ float nz = (float)pv.norm.z;
544
+
545
+ x += nx * obj.NORMALPUSH;
546
+ y += ny * obj.NORMALPUSH;
547
+ z += nz * obj.NORMALPUSH;
548
+
549
+ gl.glNormal3f(nx, ny, nz);
550
+ }
551
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
552
+ SetColor(obj, pv);
553
+ //gl.glColor4f(r, g, b, 1);
554
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
555
+ if (obj.flipV)
556
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
557
+ else
558
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
559
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
560
+
561
+ gl.glVertex3f(x, y, z);
562
+
563
+ // Q
564
+ x = (float)qv.x;
565
+ y = (float)qv.y;
566
+ z = (float)qv.z;
567
+
568
+// Print(pv);
569
+ if (hasnorm)
570
+ {
571
+// assert(qv.norm.normalized());
572
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
573
+ float nx = (float)qv.norm.x;
574
+ float ny = (float)qv.norm.y;
575
+ float nz = (float)qv.norm.z;
576
+
577
+ x += nx * obj.NORMALPUSH;
578
+ y += ny * obj.NORMALPUSH;
579
+ z += nz * obj.NORMALPUSH;
580
+
581
+ gl.glNormal3f(nx, ny, nz);
582
+ }
583
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
584
+ // boolean locked = false;
585
+ // float eps = 0.1f;
586
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
587
+
588
+ // int dot = 0; //*/ (int)f.dot;
589
+
590
+ // if ((dot&1) == 0)
591
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
592
+
593
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
594
+ if (obj.flipV)
595
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
596
+ else
597
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
598
+ // else
599
+ // {
600
+ // locked = true;
601
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
602
+ // }
603
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
604
+ SetColor(obj, qv);
605
+
606
+ gl.glVertex3f(x, y, z);
607
+ //gl.glColor4f(r, g, b, 1);
608
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
609
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
610
+// Print(qv);
611
+
612
+ // R
613
+ x = (float)rv.x;
614
+ y = (float)rv.y;
615
+ z = (float)rv.z;
616
+
617
+ if (hasnorm)
618
+ {
619
+// assert(rv.norm.normalized());
620
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
621
+ float nx = (float)rv.norm.x;
622
+ float ny = (float)rv.norm.y;
623
+ float nz = (float)rv.norm.z;
624
+
625
+ x += nx * obj.NORMALPUSH;
626
+ y += ny * obj.NORMALPUSH;
627
+ z += nz * obj.NORMALPUSH;
628
+
629
+ gl.glNormal3f(nx, ny, nz);
630
+ }
631
+
632
+ // if ((dot&4) == 0)
633
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
634
+
635
+ // if (wrap || !locked && (dot&8) != 0)
636
+ if (obj.flipV)
637
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
638
+ else
639
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
640
+ // else
641
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
642
+
643
+ // f.dot = dot;
644
+
645
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
646
+ SetColor(obj, rv);
647
+ //gl.glColor4f(r, g, b, 1);
648
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
649
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
650
+ gl.glVertex3f(x, y, z);
651
+// Print(rv);
652
+ //gl.glEnd();
653
+ }
654
+ else
655
+ {
656
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
657
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
658
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
659
+
660
+ }
661
+
662
+ if (false) // (attributes & WIREFRAME) != 0)
663
+ {
664
+ gl.glDisable(gl.GL_LIGHTING);
665
+
666
+ gl.glBegin(gl.GL_LINE_LOOP);
667
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
668
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
669
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
670
+ gl.glEnd();
671
+
672
+ gl.glEnable(gl.GL_LIGHTING);
673
+ }
674
+ }
675
+
676
+ /**
677
+ * <code>draw</code> renders a <code>TriMesh</code> object including
678
+ * it's normals, colors, textures and vertices.
679
+ *
680
+ * @see Renderer#draw(TriMesh)
681
+ * @param tris
682
+ * the mesh to render.
683
+ */
684
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
685
+ {
686
+ CameraPane display = this;
687
+
688
+ float r = display.modelParams0[0];
689
+ float g = display.modelParams0[1];
690
+ float b = display.modelParams0[2];
691
+ float opacity = display.modelParams5[1];
692
+
693
+ //final GL gl = GLU.getCurrentGL();
694
+ GL gl = display.GetGL(); // getGL();
695
+
696
+ FloatBuffer vertBuf = geo.vertBuf;
697
+
698
+ int v = vertBuf.capacity();
699
+
700
+ int count = 0;
701
+
702
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
703
+ gl.glEnable(gl.GL_CULL_FACE);
704
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
705
+ for (int i=0; i<v/3; i++)
706
+ {
707
+ int index3 = i*3;
708
+
709
+ if (geo.sizeBuf.get(index3+1) == 0)
710
+ continue;
711
+
712
+ count++;
713
+
714
+ int index4 = i*4;
715
+
716
+ float tx = vertBuf.get(index3);
717
+ float ty = vertBuf.get(index3+1);
718
+ float tz = vertBuf.get(index3+2);
719
+
720
+ // if (tx == 0 && ty == 0 && tz == 0)
721
+ // continue;
722
+
723
+ gl.glMatrixMode(gl.GL_TEXTURE);
724
+ gl.glPushMatrix();
725
+
726
+ float[] texmat = geo.texmat;
727
+ texmat[12] = texmat[13] = texmat[14] = i;
728
+
729
+ gl.glMultMatrixf(texmat, 0);
730
+
731
+ gl.glMatrixMode(gl.GL_MODELVIEW);
732
+ gl.glPushMatrix();
733
+
734
+ gl.glTranslatef(tx,ty,tz);
735
+
736
+ if (rotate)
737
+ gl.glRotatef(i, 0, 1, 0);
738
+
739
+ float size = geo.sizeBuf.get(index3) / 100;
740
+ gl.glScalef(size,size,size);
741
+
742
+ float cr = geo.colorBuf.get(index4);
743
+ float cg = geo.colorBuf.get(index4+1);
744
+ float cb = geo.colorBuf.get(index4+2);
745
+ float ca = geo.colorBuf.get(index4+3);
746
+
747
+ display.modelParams0[0] = r * cr;
748
+ display.modelParams0[1] = g * cg;
749
+ display.modelParams0[2] = b * cb;
750
+
751
+ display.modelParams5[1] = opacity * ca;
752
+
753
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
754
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
755
+
756
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
757
+ RandomNode.globalseed2 = RandomNode.globalseed;
758
+
759
+// gl.glColor4f(cr,cg,cb,ca);
760
+ // gl.glScalef(1024/16,1024/16,1024/16);
761
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
762
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
763
+ //gl.glTranslatef(-tx,-ty,-tz);
764
+ gl.glPopMatrix();
765
+
766
+ gl.glMatrixMode(gl.GL_TEXTURE);
767
+ gl.glPopMatrix();
768
+ }
769
+ // gl.glScalef(1024,1024,1024);
770
+ if (!cf)
771
+ gl.glDisable(gl.GL_CULL_FACE);
772
+
773
+ display.modelParams0[0] = r;
774
+ display.modelParams0[1] = g;
775
+ display.modelParams0[2] = b;
776
+
777
+ display.modelParams5[1] = opacity;
778
+
779
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
780
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
781
+
782
+ gl.glMatrixMode(gl.GL_MODELVIEW);
783
+
784
+// System.err.println("total = " + v/3 + "; displayed = " + count);
785
+ if (true)
786
+ return;
787
+
788
+//// if (!tris.predraw(this))
789
+//// {
790
+//// return;
791
+//// }
792
+//// if (Debug.stats)
793
+//// {
794
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
795
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
796
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
797
+//// }
798
+////
799
+//// if (tris.getDisplayListID() != -1)
800
+//// {
801
+//// renderDisplayList(tris);
802
+//// return;
803
+//// }
804
+////
805
+//// if (!generatingDisplayList)
806
+//// {
807
+//// applyStates(tris.states, tris);
808
+//// }
809
+//// if (Debug.stats)
810
+//// {
811
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
812
+//// }
813
+//// boolean transformed = doTransforms(tris);
814
+//
815
+// int glMode = GL.GL_TRIANGLES;
816
+// switch (getMode())
817
+// {
818
+// case Triangles:
819
+// glMode = GL.GL_TRIANGLES;
820
+// break;
821
+// case Strip:
822
+// glMode = GL.GL_TRIANGLE_STRIP;
823
+// break;
824
+// case Fan:
825
+// glMode = GL.GL_TRIANGLE_FAN;
826
+// break;
827
+// }
828
+//
829
+// if (!predrawGeometry(gl))
830
+// {
831
+// // make sure only the necessary indices are sent through on old
832
+// // cards.
833
+// IntBuffer indices = this.getIndexBuffer();
834
+// if (indices == null)
835
+// {
836
+// logger.severe("missing indices on geometry object: " + this.toString());
837
+// } else
838
+// {
839
+// indices.rewind();
840
+// indices.limit(this.getMaxIndex());
841
+//
842
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
843
+//
844
+// indices.clear();
845
+// }
846
+// } else
847
+// {
848
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
849
+// GL.GL_UNSIGNED_INT, 0);
850
+// }
851
+//
852
+//// postdrawGeometry(tris);
853
+//// if (transformed)
854
+//// {
855
+//// undoTransforms(tris);
856
+//// }
857
+////
858
+//// if (Debug.stats)
859
+//// {
860
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
861
+//// }
862
+//// tris.postdraw(this);
863
+ }
864
+
865
+ static Camera localcamera = new Camera();
866
+ static cVector from = new cVector();
867
+ static cVector to = new cVector();
868
+
869
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
870
+ {
871
+ CameraPane cp = this;
872
+
873
+ Camera keep = cp.RenderCamera();
874
+ cp.renderCamera = localcamera;
875
+
876
+ if (br.trimmed)
877
+ {
878
+ float[] colors = new float[br.positions.length / 3];
879
+
880
+ int i3 = 0;
881
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
882
+ {
883
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
884
+ continue;
885
+
886
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
887
+ to.set(br.positions[i3] + br.normals[i3],
888
+ br.positions[i3 + 1] + br.normals[i3 + 1],
889
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
890
+ LA.xformPos(from, transform, from);
891
+ LA.xformPos(to, transform, to); // RIGID ONLY
892
+ localcamera.setAim(from, to);
893
+
894
+ CameraPane.occlusionbuffer.display();
895
+
896
+ if (CameraPane.DEBUG_OCCLUSION)
897
+ cp.display(); // debug
898
+
899
+ colors[i] = cp.vertexOcclusion.r;
900
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
901
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
902
+
903
+ if ((i % 100) == 0 && i != 0)
904
+ {
905
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
906
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
907
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
908
+ }
909
+ }
910
+
911
+ br.colors = colors;
912
+ }
913
+ else
914
+ {
915
+ for (int i = 0; i < br.VertexCount(); i++)
916
+ {
917
+ Vertex v = br.GetVertex(i);
918
+
919
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
920
+ continue;
921
+
922
+ from.set(v.x, v.y, v.z);
923
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
924
+ LA.xformPos(from, transform, from);
925
+ LA.xformPos(to, transform, to); // RIGID ONLY
926
+ localcamera.setAim(from, to);
927
+
928
+ CameraPane.occlusionbuffer.display();
929
+
930
+ if (CameraPane.DEBUG_OCCLUSION)
931
+ cp.display(); // debug
932
+
933
+ v.AO = cp.vertexOcclusion.r;
934
+
935
+ if ((i % 100) == 0 && i != 0)
936
+ {
937
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
938
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
939
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
940
+ }
941
+ }
942
+ }
943
+
944
+ //System.out.println("done.");
945
+
946
+ cp.renderCamera = keep;
947
+ }
948
+
949
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
950
+ {
951
+ CameraPane display = this;
952
+ pointFlow.CreateHT();
953
+
954
+ float r = display.modelParams0[0];
955
+ float g = display.modelParams0[1];
956
+ float b = display.modelParams0[2];
957
+ float opacity = display.modelParams5[1];
958
+
959
+ //final GL gl = GLU.getCurrentGL();
960
+ GL gl = display.GetGL(); // getGL();
961
+
962
+ int s = pointFlow.points.size();
963
+
964
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
965
+ gl.glEnable(gl.GL_CULL_FACE);
966
+
967
+ for (int i=s; --i>=0;)
968
+ //for (int i=0; i<s; i++)
969
+ {
970
+ cVector v = pointFlow.points.get(i);
971
+
972
+ double mindist = Double.MAX_VALUE;
973
+
974
+ double size = pointFlow.minimumSize;
975
+
976
+ double distancenext = 0;
977
+
978
+ if (i > 0)
979
+ {
980
+ cVector w = pointFlow.points.get(i-1);
981
+
982
+ double dist = w.distance(v);
983
+
984
+ distancenext = dist;
985
+
986
+ if (mindist > dist)
987
+ {
988
+ mindist = dist;
989
+ size = mindist*pointFlow.resizefactor;
990
+ }
991
+ }
992
+
993
+ if (i < s-1)
994
+ {
995
+ cVector w = pointFlow.points.get(i+1);
996
+
997
+ double dist = w.distance(v);
998
+
999
+ if (mindist > dist)
1000
+ {
1001
+ mindist = dist;
1002
+ size = mindist*pointFlow.resizefactor;
1003
+ }
1004
+ }
1005
+
1006
+ if (size < pointFlow.minimumSize)
1007
+ size = pointFlow.minimumSize;
1008
+ if (size > pointFlow.maximumSize)
1009
+ size = pointFlow.maximumSize;
1010
+
1011
+ double tx = v.x;
1012
+ double ty = v.y;
1013
+ double tz = v.z;
1014
+
1015
+ // if (tx == 0 && ty == 0 && tz == 0)
1016
+ // continue;
1017
+
1018
+ gl.glMatrixMode(gl.GL_TEXTURE);
1019
+ gl.glPushMatrix();
1020
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1021
+
1022
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1023
+
1024
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1025
+ gl.glPushMatrix();
1026
+
1027
+ gl.glTranslated(tx,ty,tz);
1028
+
1029
+ gl.glScaled(size,size,size);
1030
+
1031
+// float cr = colorBuf.get(index4);
1032
+// float cg = colorBuf.get(index4+1);
1033
+// float cb = colorBuf.get(index4+2);
1034
+// float ca = colorBuf.get(index4+3);
1035
+//
1036
+// display.modelParams0[0] = r * cr;
1037
+// display.modelParams0[1] = g * cg;
1038
+// display.modelParams0[2] = b * cb;
1039
+//
1040
+// display.modelParams5[1] = opacity * ca;
1041
+//
1042
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1043
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1044
+//
1045
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1046
+// RandomNode.globalseed2 = RandomNode.globalseed;
1047
+//
1048
+//// gl.glColor4f(cr,cg,cb,ca);
1049
+// // gl.glScalef(1024/16,1024/16,1024/16);
1050
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1051
+
1052
+ gl.glPopMatrix();
1053
+
1054
+ double step = size/4; //
1055
+
1056
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1057
+ continue;
1058
+
1059
+ int nbsteps = (int)(distancenext/step);
1060
+
1061
+ step = distancenext/nbsteps;
1062
+
1063
+ cVector next = pointFlow.points.get(i-1);
1064
+
1065
+ tmp.set(next);
1066
+ tmp.sub(v);
1067
+ tmp.normalize();
1068
+ tmp.mul(step);
1069
+
1070
+ // calculate next size
1071
+ mindist = Double.MAX_VALUE;
1072
+
1073
+ double nextsize = pointFlow.minimumSize;
1074
+
1075
+ if (i > 1)
1076
+ {
1077
+ cVector w = pointFlow.points.get(i-2);
1078
+
1079
+ double dist = w.distance(next);
1080
+
1081
+ if (mindist > dist)
1082
+ {
1083
+ mindist = dist;
1084
+ nextsize = mindist*pointFlow.resizefactor;
1085
+ }
1086
+ }
1087
+
1088
+ double dist = v.distance(next);
1089
+
1090
+ if (mindist > dist)
1091
+ {
1092
+ mindist = dist;
1093
+ nextsize = mindist*pointFlow.resizefactor;
1094
+ }
1095
+
1096
+ if (nextsize < pointFlow.minimumSize)
1097
+ nextsize = pointFlow.minimumSize;
1098
+ if (nextsize > pointFlow.maximumSize)
1099
+ nextsize = pointFlow.maximumSize;
1100
+ //
1101
+
1102
+ double count = 0;
1103
+
1104
+ while (distancenext > 0.000000001) // step
1105
+ {
1106
+ gl.glPushMatrix();
1107
+
1108
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1109
+
1110
+ double K = count/nbsteps;
1111
+
1112
+ double intersize = K*nextsize + (1-K)*size;
1113
+
1114
+ gl.glScaled(intersize,intersize,intersize);
1115
+
1116
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1117
+
1118
+ count++;
1119
+
1120
+ distancenext -= step;
1121
+
1122
+ gl.glPopMatrix();
1123
+ }
1124
+
1125
+ if (count != nbsteps)
1126
+ assert(count == nbsteps);
1127
+
1128
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1129
+ //gl.glTranslatef(-tx,-ty,-tz);
1130
+
1131
+ gl.glMatrixMode(gl.GL_TEXTURE);
1132
+ gl.glPopMatrix();
1133
+ }
1134
+
1135
+ if (!cf)
1136
+ gl.glDisable(gl.GL_CULL_FACE);
1137
+
1138
+// display.modelParams0[0] = r;
1139
+// display.modelParams0[1] = g;
1140
+// display.modelParams0[2] = b;
1141
+//
1142
+// display.modelParams5[1] = opacity;
1143
+//
1144
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1145
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1146
+
1147
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1148
+ }
1149
+
1150
+ public void DrawBox(cVector min, cVector max)
1151
+ {
1152
+ javax.media.opengl.GL gl = GetGL();
1153
+ gl.glBegin(gl.GL_LINES);
1154
+
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(min.x, min.y, max.z);
1157
+ gl.glVertex3d(min.x, min.y, min.z);
1158
+ gl.glVertex3d(min.x, max.y, min.z);
1159
+ gl.glVertex3d(min.x, min.y, min.z);
1160
+ gl.glVertex3d(max.x, min.y, min.z);
1161
+
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(min.x, max.y, max.z);
1164
+ gl.glVertex3d(max.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, min.y, max.z);
1166
+ gl.glVertex3d(max.x, max.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, min.z);
1168
+
1169
+ gl.glEnd();
1170
+ }
1171
+
1172
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1173
+ {
1174
+ int[] strips = bRep.getRawIndices();
1175
+
1176
+ javax.media.opengl.GL gl = GetGL();
1177
+
1178
+ // TRIANGLE STRIP ARRAY
1179
+ if (bRep.trimmed)
1180
+ {
1181
+ float[] v = bRep.getRawVertices();
1182
+ float[] n = bRep.getRawNormals();
1183
+ float[] c = bRep.getRawColors();
1184
+ float[] uv = bRep.getRawUVMap();
1185
+
1186
+ int count2 = 0;
1187
+ int count3 = 0;
1188
+
1189
+ if (n.length > 0)
1190
+ {
1191
+ for (int i = 0; i < strips.length; i++)
1192
+ {
1193
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1194
+
1195
+ /*
1196
+ boolean locked = false;
1197
+ float eps = 0.1f;
1198
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1199
+
1200
+ int dot = 0;
1201
+
1202
+ if ((dot&1) == 0)
1203
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1204
+
1205
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1206
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1207
+ else
1208
+ {
1209
+ locked = true;
1210
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1211
+ }
1212
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1213
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1214
+ if (hasnorm)
1215
+ {
1216
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1217
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1218
+ }
1219
+
1220
+ if ((dot&4) == 0)
1221
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1222
+
1223
+ if (wrap || !locked && (dot&8) != 0)
1224
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1225
+ else
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+
1228
+ f.dot = dot;
1229
+ */
1230
+
1231
+ if (!selectmode)
1232
+ {
1233
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1234
+ {
1235
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1236
+ } else
1237
+ {
1238
+ gl.glNormal3f(0, 0, 1);
1239
+ }
1240
+
1241
+ if (c != null)
1242
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1243
+ {
1244
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1245
+ }
1246
+ }
1247
+
1248
+ if (flipV)
1249
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1250
+ else
1251
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
1253
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1254
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1255
+
1256
+ count2 += 2;
1257
+ count3 += 3;
1258
+ if (!selectmode)
1259
+ {
1260
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1261
+ {
1262
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1263
+ } else
1264
+ {
1265
+ gl.glNormal3f(0, 0, 1);
1266
+ }
1267
+ if (c != null)
1268
+ {
1269
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1270
+ }
1271
+ }
1272
+
1273
+ if (flipV)
1274
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1275
+ else
1276
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
1278
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1279
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1280
+
1281
+ count2 += 2;
1282
+ count3 += 3;
1283
+ for (int j = 0; j < strips[i] - 2; j++)
1284
+ {
1285
+ //gl.glTexCoord2d(...);
1286
+ if (!selectmode)
1287
+ {
1288
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1289
+ {
1290
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1291
+ } else
1292
+ {
1293
+ gl.glNormal3f(0, 0, 1);
1294
+ }
1295
+ if (c != null)
1296
+ {
1297
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1298
+ }
1299
+ }
1300
+
1301
+ if (flipV)
1302
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1303
+ else
1304
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
1306
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1307
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
1309
+ count2 += 2;
1310
+ count3 += 3;
1311
+ }
1312
+
1313
+ gl.glEnd();
1314
+ }
1315
+ }
1316
+
1317
+ assert count3 == v.length;
1318
+ }
1319
+ else // !trimmed
1320
+ {
1321
+ int count = 0;
1322
+ for (int i = 0; i < strips.length; i++)
1323
+ {
1324
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1325
+
1326
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1327
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1328
+
1329
+ drawVertex(gl, p, flipV, selectmode);
1330
+ drawVertex(gl, q, flipV, selectmode);
1331
+
1332
+ for (int j = 0; j < strips[i] - 2; j++)
1333
+ {
1334
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1335
+
1336
+ // if (j%2 == 0)
1337
+ // drawFace(p, q, r, display, null);
1338
+ // else
1339
+ // drawFace(p, r, q, display, null);
1340
+
1341
+ // p = q;
1342
+ // q = r;
1343
+ drawVertex(gl, r, flipV, selectmode);
1344
+ }
1345
+
1346
+ gl.glEnd();
1347
+ }
1348
+ }
1349
+ }
1350
+
1351
+ static cSpring.Point3D temp = new cSpring.Point3D();
1352
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1354
+
1355
+ public void DrawDynamicMesh(cMesh mesh)
1356
+ {
1357
+ GL gl = GetGL(); // getGL();
1358
+
1359
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1360
+
1361
+ gl.glDisable(gl.GL_LIGHTING);
1362
+
1363
+ gl.glLineWidth(1);
1364
+ gl.glColor3f(1,1,1);
1365
+ gl.glBegin(gl.GL_LINES);
1366
+ double scale = 0;
1367
+ int count = 0;
1368
+ for (int s=0; s<Phys.allSprings.size(); s++)
1369
+ {
1370
+ cSpring.Spring spring = Phys.allSprings.get(s);
1371
+ if(s == 0)
1372
+ {
1373
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1374
+ }
1375
+ if (mesh.showsprings)
1376
+ {
1377
+ temp.set(spring.a.position);
1378
+ temp.add(spring.b.position);
1379
+ temp.mul(0.5);
1380
+ temp2.set(spring.a.position);
1381
+ temp2.sub(spring.b.position);
1382
+ temp2.mul(spring.restLength/2);
1383
+ temp.sub(temp2);
1384
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1385
+ temp.add(temp2);
1386
+ temp.add(temp2);
1387
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1388
+ }
1389
+
1390
+ if (spring.isHandle)
1391
+ continue;
1392
+
1393
+ //if (scale < spring.restLength)
1394
+ scale += spring.restLength;
1395
+ count++;
1396
+ }
1397
+ gl.glEnd();
1398
+
1399
+ if (count == 0)
1400
+ scale = 0.01;
1401
+ else
1402
+ scale /= count * 3;
1403
+
1404
+ //scale = 0.25;
1405
+
1406
+ if (mesh.ShowInfo())
1407
+ {
1408
+ gl.glLineWidth(4);
1409
+ for (int s=0; s<Phys.allNodes.size(); s++)
1410
+ {
1411
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1412
+ if (node.mass == 0)
1413
+ continue;
1414
+
1415
+ int i = node.springs==null?-1:node.springs.size();
1416
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1417
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1418
+ //temp.normalize();
1419
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1420
+ gl.glBegin(gl.GL_LINES);
1421
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1422
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1423
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1424
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1425
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1426
+ gl.glEnd();
1427
+ }
1428
+
1429
+ gl.glLineWidth(8);
1430
+ for (int s=0; s<Phys.allNodes.size(); s++)
1431
+ {
1432
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1433
+
1434
+ if (node.springs != null)
1435
+ {
1436
+ for (int i=0; i<node.springs.size(); i+=1)
1437
+ {
1438
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1439
+
1440
+ int c = i+1;
1441
+ // c = node.springs.get(i).nbcopies;
1442
+
1443
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1444
+ gl.glBegin(gl.GL_LINES);
1445
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1446
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1447
+ gl.glEnd();
1448
+ }
1449
+ }
1450
+ }
1451
+
1452
+ gl.glLineWidth(1);
1453
+ }
1454
+
1455
+ gl.glEnable(gl.GL_LIGHTING);
1456
+ }
1457
+
1458
+ /// INTERFACE
1459
+
1460
+ public void StartTriangles()
1461
+ {
1462
+ javax.media.opengl.GL gl = GetGL();
1463
+ gl.glBegin(gl.GL_TRIANGLES);
1464
+ }
1465
+
1466
+ public void EndTriangles()
1467
+ {
1468
+ GetGL().glEnd();
1469
+ }
1470
+
1471
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1472
+ {
1473
+ if (!selectmode)
1474
+ {
1475
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1476
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1477
+
1478
+ if (flipV)
1479
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1480
+ else
1481
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1482
+ }
1483
+
1484
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1485
+ }
1486
+
1487
+ void SetColor(Object3D obj, Vertex p0)
1488
+ {
1489
+ CameraPane display = this;
1490
+ BoundaryRep bRep = obj.bRep;
1491
+
1492
+ if (RENDERPROGRAM == 0)
1493
+ {
1494
+ float r = 0;
1495
+ if (bRep != null)
1496
+ {
1497
+ if (bRep.stripified)
1498
+ {
1499
+ r = 1;
1500
+ }
1501
+ }
1502
+ float g = 0;
1503
+ if (bRep != null)
1504
+ {
1505
+ if (bRep.trimmed)
1506
+ {
1507
+ g = 1;
1508
+ }
1509
+ }
1510
+ float b = 0;
1511
+ if (obj.support != null && obj.link2master)
1512
+ {
1513
+ b = 1;
1514
+ }
1515
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1516
+ return;
1517
+ }
1518
+
1519
+ if (display.DrawMode() != CameraPane.SHADOW)
1520
+ return;
1521
+
1522
+ javax.media.opengl.GL gl = display.GetGL();
1523
+// if (true) return;
1524
+// float ao = p.AO;
1525
+//
1526
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1527
+// // ao = 1;
1528
+//
1529
+// gl.glColor4f(ao, ao, ao, 1);
1530
+
1531
+// CameraPane.selectedpoint.
1532
+// getAverage(cStatic.point1, true);
1533
+ if (CameraPane.pointflow == null) // !random) // live)
1534
+ {
1535
+ return;
1536
+ }
1537
+
1538
+ cStatic.point1.set(0,0,0);
1539
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1540
+
1541
+ cStatic.point1.sub(p0);
1542
+
1543
+
1544
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1545
+// {
1546
+// return;
1547
+// }
1548
+
1549
+ //if (true)
1550
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1551
+ {
1552
+ return;
1553
+ }
1554
+
1555
+ float[] colorV = new float[3];
1556
+
1557
+ if (false) // marked)
1558
+ {
1559
+ // debug rigging weights
1560
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1561
+ {
1562
+ float weight = p0.weights[object] / p0.totalweight;
1563
+
1564
+ // if (weight < 0.1)
1565
+ // {
1566
+ // assert(weight == 0);
1567
+ // continue;
1568
+ // }
1569
+
1570
+ if (p0.vertexlinks[object] == -1)
1571
+ continue;
1572
+
1573
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1574
+
1575
+ int color = //1 << object; //
1576
+ //p.vertexlinks.length;
1577
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1578
+ colorV[2] += (color & 1) * weight;
1579
+ colorV[1] += ((color & 2) >> 1) * weight;
1580
+ colorV[0] += ((color & 4) >> 2) * weight;
1581
+ }
1582
+ }
1583
+ else
1584
+ {
1585
+ if (obj.drawingstarted)
1586
+ {
1587
+ // find next point
1588
+ if (bRep.GetVertex(0).faceindices == null)
1589
+ {
1590
+ bRep.InitFaceIndices();
1591
+ }
1592
+
1593
+ double ymin = p0.y;
1594
+
1595
+ Vertex newp = p0;
1596
+
1597
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1598
+ {
1599
+ int fi = p0.faceindices[fii];
1600
+
1601
+ if (fi == -1)
1602
+ break;
1603
+
1604
+ Face f = bRep.GetFace(fi);
1605
+
1606
+ Vertex p = bRep.GetVertex(f.p);
1607
+ Vertex q = bRep.GetVertex(f.q);
1608
+ Vertex r = bRep.GetVertex(f.r);
1609
+
1610
+ int swap = (int)(Math.random()*3);
1611
+
1612
+// for (int s=swap; --s>=0;)
1613
+// {
1614
+// Vertex t = p;
1615
+// p = q;
1616
+// q = r;
1617
+// r = t;
1618
+// }
1619
+ if (ymin > p.y)
1620
+ {
1621
+ ymin = p.y;
1622
+ newp = p;
1623
+// break;
1624
+ }
1625
+ if (ymin > q.y)
1626
+ {
1627
+ ymin = q.y;
1628
+ newp = q;
1629
+// break;
1630
+ }
1631
+ if (ymin > r.y)
1632
+ {
1633
+ ymin = r.y;
1634
+ newp = r;
1635
+// break;
1636
+ }
1637
+ }
1638
+
1639
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1640
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1641
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1642
+
1643
+ obj.drawingstarted = false;
1644
+
1645
+ // return;
1646
+ }
1647
+
1648
+ if (false) // CameraPane.DRAW
1649
+ {
1650
+ p0.AO = colorV[0] = 2;
1651
+ colorV[1] = 2;
1652
+ colorV[2] = 2;
1653
+ }
1654
+
1655
+ CameraPane.pointflow.add(p0);
1656
+ CameraPane.pointflow.Touch();
1657
+ }
1658
+
1659
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1660
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1661
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1662
+ }
1663
+
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1665
+ {
1666
+ CameraPane display = this;
1667
+ //new Exception().printStackTrace();
1668
+
1669
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1670
+ {
1671
+ return;
1672
+ }
1673
+
1674
+ javax.media.opengl.GL gl = display.GetGL();
1675
+
1676
+ //Color col = Color.getHSBColor(color,modulation,1);
1677
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1678
+ if (!material.multiply)
1679
+ {
1680
+ display.color = material.color;
1681
+ display.saturation = material.modulation;
1682
+ }
1683
+ else
1684
+ {
1685
+ display.color *= material.color*2;
1686
+ display.saturation *= material.modulation*2;
1687
+ }
1688
+
1689
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1690
+
1691
+ float[] colorV = Grafreed.colorV;
1692
+
1693
+ /**/
1694
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1695
+ {
1696
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1697
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1698
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1699
+ colorV[3] = 1; // material.opacity;
1700
+
1701
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1702
+ //System.out.println("Opacity = " + opacity);
1703
+
1704
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1705
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1706
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1707
+
1708
+ float amb = material.ambient;
1709
+ if (amb < material.cameralight)
1710
+ {
1711
+ amb = material.cameralight;
1712
+ }
1713
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1714
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1715
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1716
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1717
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1718
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1719
+
1720
+ /**/
1721
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1722
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1723
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1724
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1725
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1726
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1727
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1728
+ //System.out.println("shininess = " + colorV[0]);
1729
+ if (colorV[0] > 128)
1730
+ {
1731
+ colorV[0] = 128;
1732
+ }
1733
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1734
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1735
+ /**/
1736
+ }
1737
+ /**/
1738
+
1739
+ //selected = false;
1740
+ selected = selected && display.flash;
1741
+
1742
+ //display.modelParams0[0] = 0; // pigment.r;
1743
+ //display.modelParams0[1] = 0; // pigment.g;
1744
+ //display.modelParams0[2] = 0; // pigment.b;
1745
+ if (!material.multiply)
1746
+ {
1747
+ display.modelParams0[3] = material.metalness;
1748
+ display.modelParams1[0] = material.diffuse;
1749
+ display.modelParams1[1] = material.specular;
1750
+ display.modelParams1[2] = 1 / material.shininess;
1751
+ display.modelParams1[3] = material.shift;
1752
+ display.modelParams2[0] = material.ambient;
1753
+ display.modelParams2[1] = material.lightarea;
1754
+ //System.out.println("light area = " + lightarea);
1755
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1756
+ display.modelParams2[3] = material.velvet;
1757
+ display.modelParams3[0] = material.sheen;
1758
+ display.modelParams3[1] = material.subsurface;
1759
+ display.modelParams3[2] = material.bump; // backlit
1760
+ display.modelParams3[3] = material.aniso;
1761
+ display.modelParams4[0] = material.anisoV;
1762
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1763
+ //System.out.println("selected = " + selected);
1764
+ display.modelParams4[2] = material.diffuseness;
1765
+ display.modelParams4[3] = material.shadow;
1766
+ display.modelParams5[0] = material.texture;
1767
+ display.modelParams5[1] = material.opacity;
1768
+ display.modelParams5[2] = material.fakedepth;
1769
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1770
+ }
1771
+ else
1772
+ {
1773
+ display.modelParams0[3] *= material.metalness*2;
1774
+ display.modelParams1[0] *= material.diffuse*2;
1775
+ display.modelParams1[1] *= material.specular*2;
1776
+ display.modelParams1[2] *= material.shininess*2;
1777
+ display.modelParams1[3] *= material.shift*2;
1778
+ display.modelParams2[0] *= material.ambient*2;
1779
+ display.modelParams2[1] *= material.lightarea*2;
1780
+ display.modelParams2[2] *= material.factor*2;
1781
+ display.modelParams2[3] *= material.velvet*2;
1782
+ display.modelParams3[0] *= material.sheen*2;
1783
+ display.modelParams3[1] *= material.subsurface*2;
1784
+ display.modelParams3[2] *= material.bump*2;
1785
+ display.modelParams3[3] *= material.aniso*2;
1786
+ display.modelParams4[0] *= material.anisoV*2;
1787
+ display.modelParams4[1] *= material.cameralight*2;
1788
+ //System.out.println("selected = " + selected);
1789
+ display.modelParams4[2] *= material.diffuseness*2;
1790
+ display.modelParams4[3] *= material.shadow*2;
1791
+ display.modelParams5[0] *= material.texture*2;
1792
+ display.modelParams5[1] *= material.opacity*2;
1793
+ display.modelParams5[2] *= material.fakedepth*2;
1794
+ display.modelParams5[3] *= material.shadowbias*2;
1795
+ }
1796
+
1797
+ display.modelParams6[0] = 0;
1798
+ display.modelParams6[1] = 0;
1799
+ display.modelParams6[2] = 0;
1800
+ display.modelParams6[3] = 0;
1801
+
1802
+ display.modelParams7[0] = 0;
1803
+ display.modelParams7[1] = 1000;
1804
+ display.modelParams7[2] = 0;
1805
+ display.modelParams7[3] = 0;
1806
+
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
1808
+
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1810
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1811
+ {
1812
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1813
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1814
+ if (extparams.length > 1)
1815
+ {
1816
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1817
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1818
+ if (extparams.length > 2)
1819
+ {
1820
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1821
+ float x = extparams[2].y / 1000.0f;
1822
+ //if (x == 0)
1823
+ // x = 1f;
1824
+ display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power
1825
+ if (extparams[2].y > 0)
1826
+ {
1827
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1828
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1829
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1830
+ }
1831
+ }
1832
+ }
1833
+ }
1834
+
1835
+ //if (display.modelParams6[2] != 0)
1836
+ /*
1837
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1838
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1839
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1840
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1841
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1842
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1843
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1844
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1845
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1846
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1847
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1848
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1849
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1850
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1851
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1852
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1853
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1854
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1855
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1856
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1857
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1858
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1859
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1860
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1861
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1862
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1863
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1864
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1865
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1866
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1867
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1868
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1869
+ /**/
1870
+ //assert (display.modelParams6[2] == 0);
1871
+
1872
+ //System.out.println("noise power = " + display.modelParams7[0]);
1873
+ //System.out.println("shadowbias = " + shadowbias);
1874
+
1875
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1876
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1877
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1878
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1879
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1880
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1881
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1882
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1883
+
1884
+ int mode = display.FP_SHADER;
1885
+
1886
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1887
+ {
1888
+ mode |= display.FP_ANISO;
1889
+ }
1890
+
1891
+ display.EnableProgram(mode);
1892
+
1893
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1894
+
1895
+ if (!material.multiply)
1896
+ {
1897
+ if (Globals.drawMode == CameraPane.SHADOW)
1898
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1899
+ else
1900
+ gl.glDepthMask(material.opacity >= 0.99);
1901
+ }
2361902 }
2371903
2381904 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -253,7 +1919,7 @@
2531919 currentGL.glMultMatrixd(model, 0);
2541920 }
2551921
256
- void PushMatrix(double[][] matrix, int count)
1922
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2571923 {
2581924 matrixdepth++;
2591925 // GrafreeD.tracein(matrix);
....@@ -282,7 +1948,7 @@
2821948 void PushMatrix(double[][] matrix)
2831949 {
2841950 // GrafreeD.tracein(matrix);
285
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
2861952 }
2871953
2881954 void PushMatrix()
....@@ -298,7 +1964,7 @@
2981964
2991965 double[][] tmpmat = new double[4][4];
3001966
301
- void PopMatrix(double[][] inverse)
1967
+ public void PopMatrix(double[][] inverse) // INTERFACE
3021968 {
3031969 --matrixdepth;
3041970
....@@ -338,7 +2004,7 @@
3382004 PushTextureMatrix(matrix, 1);
3392005 }
3402006
341
- void PushTextureMatrix(double[][] matrix, int count)
2007
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3422008 {
3432009 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3442010
....@@ -352,7 +2018,7 @@
3522018 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3532019 }
3542020
355
- void PopTextureMatrix(double[][] inverse)
2021
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3562022 {
3572023 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3582024 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -379,15 +2045,15 @@
3792045
3802046 static int camerachangeframe;
3812047
382
- boolean SetCamera(Camera cam)
2048
+ public boolean SetCamera(Camera cam)
3832049 {
3842050 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3852051 // return false;
3862052
387
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2053
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3882054 {
3892055 // check for last change
390
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2056
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3912057 {
3922058 // refuse the camera change
3932059 System.err.println("Camera " + cam + " REFUSED");
....@@ -395,7 +2061,7 @@
3952061 }
3962062 }
3972063
398
- camerachangeframe = framecount;
2064
+ camerachangeframe = Globals.framecount;
3992065
4002066 cam.hAspect = -1; // Read only
4012067
....@@ -426,7 +2092,7 @@
4262092 {
4272093 //System.err.println("Oeil on");
4282094 TRACK = true;
429
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2095
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4302096 // object.editWindow.ScreenFit(trackedobject);
4312097 //pingthread.StepToTarget(true);
4322098 }
....@@ -435,8 +2101,8 @@
4352101 {
4362102 //System.err.println("Oeil on");
4372103 OEIL = true;
438
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
439
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2104
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4402106 //pingthread.StepToTarget(true);
4412107 }
4422108
....@@ -499,39 +2165,12 @@
4992165 {
5002166 frozen ^= true;
5012167 // Weird...
502
- lighttouched = true;
2168
+ Globals.lighttouched = true;
5032169 }
5042170
5052171 void ToggleDL()
5062172 {
5072173 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;
5352174 }
5362175
5372176 void ToggleFullScreen()
....@@ -541,12 +2180,7 @@
5412180
5422181 void ToggleCrowd()
5432182 {
544
- CROWD ^= true;
545
- }
546
-
547
- void ToggleInertia()
548
- {
549
- INERTIA ^= true;
2183
+ Globals.CROWD ^= true;
5502184 }
5512185
5522186 void ToggleLocal()
....@@ -554,62 +2188,89 @@
5542188 LOCALTRANSFORM ^= true;
5552189 }
5562190
557
- void ToggleFast()
2191
+ public void ToggleTexture()
2192
+ {
2193
+ textureon ^= true;
2194
+ }
2195
+
2196
+ public void ToggleLive()
2197
+ {
2198
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2199
+
2200
+ System.err.println("LIVE = " + Globals.isLIVE());
2201
+
2202
+ if (!Globals.isLIVE()) // save sound
2203
+ Grafreed.savesound = true; // wav.save();
2204
+ // else
2205
+ repaint(); // start loop // may 2013
2206
+ }
2207
+
2208
+ public void ToggleSupport()
2209
+ {
2210
+ SUPPORT ^= true;
2211
+ }
2212
+
2213
+ public void ToggleAbort()
2214
+ {
2215
+ ABORTMODE ^= true;
2216
+ }
2217
+
2218
+ public void ToggleInertia()
2219
+ {
2220
+ INERTIA ^= true;
2221
+ }
2222
+
2223
+ public void ToggleFast()
5582224 {
5592225 FAST ^= true;
5602226 }
5612227
562
- void ToggleSlowPose()
2228
+ public void ToggleSlowPose()
5632229 {
5642230 SLOWPOSE ^= true;
5652231 }
5662232
567
- void ToggleFootContact()
568
- {
569
- FOOTCONTACT ^= true;
570
- }
571
-
572
- void ToggleBoxMode()
2233
+ public void ToggleBoxMode()
5732234 {
5742235 BOXMODE ^= true;
5752236 }
5762237
577
- void ToggleSmoothFocus()
2238
+ public void ToggleZoomBoxMode()
2239
+ {
2240
+ ZOOMBOXMODE ^= true;
2241
+ }
2242
+
2243
+ public void ToggleSmoothFocus()
5782244 {
5792245 SMOOTHFOCUS ^= true;
5802246 }
5812247
582
- void ToggleImageFlip()
2248
+ public void ToggleImageFlip()
5832249 {
5842250 IMAGEFLIP ^= true;
5852251 }
5862252
587
- void ToggleSpeakerMocap()
2253
+ public void ToggleSpeakerMocap()
5882254 {
5892255 SPEAKERMOCAP ^= true;
5902256 }
5912257
592
- void ToggleSpeakerCamera()
2258
+ public void ToggleSpeakerCamera()
5932259 {
5942260 SPEAKERCAMERA ^= true;
5952261 }
5962262
597
- void ToggleSpeakerFocus()
2263
+ public void ToggleSpeakerFocus()
5982264 {
5992265 SPEAKERFOCUS ^= true;
6002266 }
6012267
602
- void ToggleDebug()
603
- {
604
- DEBUG ^= true;
605
- }
606
-
607
- void ToggleFrustum()
2268
+ public void ToggleFrustum()
6082269 {
6092270 FRUSTUM ^= true;
6102271 }
6112272
612
- void ToggleTrack()
2273
+ public void ToggleTrack()
6132274 {
6142275 TRACK ^= true;
6152276 if (TRACK)
....@@ -628,25 +2289,35 @@
6282289 repaint();
6292290 }
6302291
631
- void ToggleTrackOnce()
2292
+ public void ToggleTrackOnce()
6322293 {
6332294 TRACKONCE ^= true;
6342295 }
6352296
636
- void ToggleShadowTrack()
2297
+ public void ToggleShadowTrack()
6372298 {
6382299 SHADOWTRACK ^= true;
6392300 repaint();
6402301 }
6412302
642
- void ToggleOeil()
2303
+ public void ToggleOeil()
6432304 {
6442305 OEIL ^= true;
6452306 }
6462307
647
- void ToggleOeilOnce()
2308
+ public void ToggleOeilOnce()
6482309 {
6492310 OEILONCE ^= true;
2311
+ }
2312
+
2313
+ void ToggleFootContact()
2314
+ {
2315
+ FOOTCONTACT ^= true;
2316
+ }
2317
+
2318
+ void ToggleDebug()
2319
+ {
2320
+ Globals.DEBUG ^= true;
6502321 }
6512322
6522323 void ToggleLookAt()
....@@ -654,9 +2325,9 @@
6542325 LOOKAT ^= true;
6552326 }
6562327
657
- void ToggleRandom()
2328
+ void ToggleSwitch()
6582329 {
659
- RANDOM ^= true;
2330
+ SWITCH ^= true;
6602331 }
6612332
6622333 void ToggleHandles()
....@@ -664,10 +2335,17 @@
6642335 HANDLES ^= true;
6652336 }
6662337
2338
+ Object3D paintFolder;
2339
+
6672340 void TogglePaint()
6682341 {
6692342 PAINTMODE ^= true;
6702343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
6712349 }
6722350
6732351 void SwapCamera(int a, int b)
....@@ -759,11 +2437,26 @@
7592437
7602438 GL currentGL;
7612439
762
- GL GetGL()
2440
+ public GL GetGL() // INTERFACE
7632441 {
7642442 return currentGL;
7652443 }
766
-
2444
+
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
7672460 /**/
7682461 class CacheTexture
7692462 {
....@@ -772,28 +2465,31 @@
7722465
7732466 int resolution;
7742467
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762469 {
777
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
7782472 resolution = res;
7792473 }
7802474 }
7812475 /**/
7822476
7832477 // TEXTURE static Texture texture;
784
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
785
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
786
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
7872483 int pigmentdepth = 0;
7882484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892485 int bumpdepth = 0;
7902486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952491
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972493 {
7982494 TextureData texturedata = null;
7992495
....@@ -812,13 +2508,34 @@
8122508 if (bump)
8132509 texturedata = ConvertBump(texturedata, false);
8142510
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172513
818
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
819
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202516
821
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
8222539 }
8232540
8242541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3608,8 @@
18913608
18923609 System.out.println("LOADING TEXTURE : " + name);
18933610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
18943613 //
18953614 if (false) // compressbit > 0)
18963615 {
....@@ -2595,6 +4314,7 @@
25954314
25964315 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25974316 {
4317
+ new Exception().printStackTrace();
25984318 System.exit(0);
25994319 com.sun.opengl.util.texture.Texture texture = null;
26004320
....@@ -6271,7 +7991,7 @@
62717991 return null;
62727992 }
62737993
6274
- void ReleaseTextures(cTexture tex)
7994
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62757995 {
62767996 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62777997 {
....@@ -6288,7 +8008,7 @@
62888008 String pigment = Object3D.GetPigment(tex);
62898009 String bump = Object3D.GetBump(tex);
62908010
6291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62928012 {
62938013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62948014 // System.out.println("; bump = " + bump);
....@@ -6303,13 +8023,71 @@
63038023 pigment = null;
63048024 }
63058025
6306
- ReleaseTexture(bump, true);
6307
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
63088028 }
63098029
6310
- void ReleaseTexture(String tex, boolean bump)
8030
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63118031 {
6312
- if (// drawMode != 0 || /*tex == null ||*/
8032
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8033
+ {
8034
+ return;
8035
+ }
8036
+
8037
+ if (tex == null)
8038
+ {
8039
+ ReleaseTexture(null, false);
8040
+ return;
8041
+ }
8042
+
8043
+ String pigment = Object3D.GetPigment(tex);
8044
+
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ {
8047
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8048
+ // System.out.println("; bump = " + bump);
8049
+ }
8050
+
8051
+ if (pigment.equals(""))
8052
+ {
8053
+ pigment = null;
8054
+ }
8055
+
8056
+ ReleaseTexture(tex, false);
8057
+ }
8058
+
8059
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8060
+ {
8061
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8062
+ {
8063
+ return;
8064
+ }
8065
+
8066
+ if (tex == null)
8067
+ {
8068
+ ReleaseTexture(null, true);
8069
+ return;
8070
+ }
8071
+
8072
+ String bump = Object3D.GetBump(tex);
8073
+
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ {
8076
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8077
+ // System.out.println("; bump = " + bump);
8078
+ }
8079
+
8080
+ if (bump.equals(""))
8081
+ {
8082
+ bump = null;
8083
+ }
8084
+
8085
+ ReleaseTexture(tex, true);
8086
+ }
8087
+
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
8089
+ {
8090
+ if (// DrawMode() != 0 || /*tex == null ||*/
63138091 ambientOcclusion ) // || !textureon)
63148092 {
63158093 return;
....@@ -6318,7 +8096,7 @@
63188096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63198097
63208098 if (tex != null)
6321
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63228100
63238101 // //assert( texture != null );
63248102 // if (texture == null)
....@@ -6410,9 +8188,57 @@
64108188 }
64118189 }
64128190
6413
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8191
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64148192 {
6415
- if (// drawMode != 0 || /*tex == null ||*/
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
8234
+
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
8237
+ }
8238
+
8239
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8240
+ {
8241
+ if (// DrawMode() != 0 || /*tex == null ||*/
64168242 ambientOcclusion ) // || !textureon)
64178243 {
64188244 return; // false;
....@@ -6421,17 +8247,47 @@
64218247 if (tex == null)
64228248 {
64238249 BindTexture(null,false,resolution);
6424
- BindTexture(null,true,resolution);
64258250 return;
64268251 }
64278252
64288253 String pigment = Object3D.GetPigment(tex);
8254
+
8255
+ usedtextures.add(tex);
8256
+
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ {
8259
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8260
+ // System.out.println("; bump = " + bump);
8261
+ }
8262
+
8263
+ if (pigment.equals(""))
8264
+ {
8265
+ pigment = null;
8266
+ }
8267
+
8268
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
+ BindTexture(tex, false, resolution);
8270
+ }
8271
+
8272
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8273
+ {
8274
+ if (// DrawMode() != 0 || /*tex == null ||*/
8275
+ ambientOcclusion ) // || !textureon)
8276
+ {
8277
+ return; // false;
8278
+ }
8279
+
8280
+ if (tex == null)
8281
+ {
8282
+ BindTexture(null,true,resolution);
8283
+ return;
8284
+ }
8285
+
64298286 String bump = Object3D.GetBump(tex);
64308287
6431
- usedtextures.put(pigment, pigment);
6432
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
64338289
6434
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64358291 {
64368292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64378293 // System.out.println("; bump = " + bump);
....@@ -6441,43 +8297,94 @@
64418297 {
64428298 bump = null;
64438299 }
6444
- if (pigment.equals(""))
6445
- {
6446
- pigment = null;
6447
- }
64488300
6449
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
- BindTexture(pigment, false, resolution);
64518301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6452
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
64538303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6454
-
6455
- return; // true;
64568304 }
64578305
6458
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8306
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8307
+
8308
+ private boolean FileExists(String tex)
64598309 {
6460
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8310
+ if (missingTextures.contains(tex))
8311
+ {
8312
+ return false;
8313
+ }
8314
+
8315
+ boolean fileExists = new File(tex).exists();
8316
+
8317
+ if (!fileExists)
8318
+ {
8319
+ // If file exists, the "new File()" is not executed sgain
8320
+ missingTextures.add(tex);
8321
+ }
8322
+
8323
+ return fileExists;
8324
+ }
8325
+
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8327
+ {
8328
+ CacheTexture texturecache = null;
64618329
64628330 if (tex != null)
64638331 {
6464
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64658334
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;
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
8339
+
8340
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8341
+
8342
+// String[] split = tex.split("Textures");
8343
+// if (split.length > 1)
8344
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8345
+// else
8346
+// if (!texname.startsWith("/"))
8347
+// texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (!FileExists(texname))
8349
+ {
8350
+ texname = fallbackTextureName;
8351
+ }
64728352
64738353 if (CACHETEXTURE)
6474
- texture = textures.get(texname); // TEXTURE CACHE
6475
-
6476
- TextureData texturedata = null;
6477
-
6478
- if (texture == null || texture.resolution < resolution)
64798354 {
6480
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64818388 {
64828389 assert(!bump);
64838390 // if (bump)
....@@ -6488,19 +8395,23 @@
64888395 // }
64898396 // else
64908397 // {
6491
- texture = textures.get(tex);
6492
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
64938400 {
6494
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64958402 }
8403
+ else
8404
+ new Exception().printStackTrace();
64968405 // }
64978406 } else
6498
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64998408 {
65008409 assert(bump);
6501
- texture = textures.get(tex);
6502
- if (texture == null)
6503
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
65048415 } else
65058416 {
65068417 //if (tex.equals("IMMORTAL"))
....@@ -6508,11 +8419,13 @@
65088419 // texture = GetResourceTexture("default.png");
65098420 //} else
65108421 //{
6511
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
65128423 {
6513
- texture = textures.get(tex);
6514
- if (texture == null)
6515
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
65168429 } else
65178430 {
65188431 if (textureon)
....@@ -6537,7 +8450,7 @@
65378450 }
65388451
65398452 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6540
- if (!new File(cachename).exists())
8453
+ if (!FileExists(cachename))
65418454 cachename = texname;
65428455 else
65438456 processbump = false; // don't process bump map again
....@@ -6559,7 +8472,7 @@
65598472 }
65608473
65618474 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6562
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
65638476 cachename = texname;
65648477 else
65658478 processbump = false; // don't process bump map again
....@@ -6568,20 +8481,22 @@
65688481 texturedata = GetFileTexture(cachename, processbump, resolution);
65698482
65708483
6571
- if (texturedata != null)
6572
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8484
+ if (texturedata == null)
8485
+ throw new Exception();
8486
+
8487
+ texturecache = new CacheTexture(texturedata,resolution);
65738488 //texture = GetTexture(tex, bump);
65748489 }
65758490 }
65768491 //}
65778492 }
65788493
6579
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65808495 {
65818496 //return false;
65828497
65838498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6584
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65858500 {
65868501 // String ext = "_highres";
65878502 // if (REDUCETEXTURE)
....@@ -6598,52 +8513,17 @@
65988513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65998514 if (!cachefile.exists())
66008515 {
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))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
66108517 {
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);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
66418520 ImageWriter writer = null;
66428521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66438522 if (iter.hasNext()) {
66448523 writer = (ImageWriter)iter.next();
66458524 }
6646
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
66478527 try
66488528 {
66498529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6660,18 +8540,20 @@
66608540 }
66618541 }
66628542 }
6663
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
66648546 //System.out.println("Texture = " + tex);
6665
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
66668548 {
6667
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
66688550 thetex.texture.disable();
66698551 thetex.texture.dispose();
6670
- textures.remove(texname);
8552
+ textures.remove(tex);
66718553 }
66728554
6673
- texture.texturedata = texturedata;
6674
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
66758557
66768558 // newtex = true;
66778559 }
....@@ -6687,10 +8569,44 @@
66878569 }
66888570 }
66898571
6690
- return texture;
8572
+ return texturecache;
66918573 }
66928574
6693
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66948610 {
66958611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66968612
....@@ -6708,21 +8624,21 @@
67088624 return texture!=null?texture.texture:null;
67098625 }
67108626
6711
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67128628 {
67138629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67148630
67158631 return texture!=null?texture.texturedata:null;
67168632 }
67178633
6718
- boolean BindTexture(String tex, boolean bump, int resolution)
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67198635 {
67208636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67218637 {
67228638 return false;
67238639 }
67248640
6725
- boolean newtex = false;
8641
+ //boolean newtex = false;
67268642
67278643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67288644
....@@ -6754,9 +8670,75 @@
67548670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67558671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67568672
6757
- return newtex;
8673
+ return true; // Warning: not used.
67588674 }
67598675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
67608742 ShadowBuffer shadowPBuf;
67618743 AntialiasBuffer antialiasPBuf;
67628744 int MAXSTACK;
....@@ -7312,9 +9294,9 @@
73129294 static boolean occlusionInitialized = false;
73139295 boolean selection = false;
73149296 boolean pointselection = false;
7315
- /*static*/ boolean lighttouched = true;
9297
+ ///*static*/ boolean lighttouched = true;
73169298 boolean deselect;
7317
- boolean ambientOcclusion = false;
9299
+ private boolean ambientOcclusion = false;
73189300 static boolean flash = false;
73199301 /*static*/ boolean wait = false;
73209302 boolean displaydone = false; // after repaint() calls
....@@ -7592,18 +9574,40 @@
75929574 jy8[3] = 0.5f;
75939575 }
75949576
7595
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75969578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
75979579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
75989580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75999581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
76009606 static int imagecount = 0; // movie generation
76019607
76029608 static int jitter = 0;
76039609
76049610 boolean restartframe = false;
7605
-
7606
- static int framecount = 0; // general-purpose global count
76079611
76089612 void displayAntiAliased(javax.media.opengl.GL gl)
76099613 {
....@@ -7635,7 +9639,7 @@
76359639 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76369640 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76379641 {
7638
- framecount++;
9642
+ Globals.framecount++;
76399643
76409644 if (CameraPane.tickcount > 0)
76419645 CameraPane.tickcount--;
....@@ -7673,7 +9677,7 @@
76739677
76749678 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76759679 */
7676
- lighttouched = true;
9680
+ Globals.lighttouched = true;
76779681 //System.err.println(" shadowbuffer: " + jitter);
76789682 shadowbuffer.display();
76799683
....@@ -7694,8 +9698,8 @@
76949698 assert (parentcam != renderCamera);
76959699
76969700 if (renderCamera != lightCamera)
7697
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7698
- LA.matConcat(matrix, parentcam.toParent, matrix);
9701
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
76999703
77009704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
77019705
....@@ -7710,8 +9714,8 @@
77109714 LA.matCopy(renderCamera.fromScreen, matrix);
77119715
77129716 if (renderCamera != lightCamera)
7713
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7714
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9717
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
77159719
77169720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77179721
....@@ -7783,7 +9787,7 @@
77839787 //gl.glFlush();
77849788 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77859789
7786
- if (ANIMATION && ABORTED)
9790
+ if (Globals.ANIMATION && ABORTED)
77879791 {
77889792 System.err.println(" ABORTED FRAME");
77899793 break;
....@@ -7813,7 +9817,7 @@
78139817 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78149818
78159819 // save image
7816
- if (ANIMATION && !ABORTED)
9820
+ if (Globals.ANIMATION && !ABORTED)
78179821 {
78189822 VPwidth = viewport[2];
78199823 VPheight = viewport[3];
....@@ -7924,11 +9928,11 @@
79249928
79259929 // imagecount++;
79269930
7927
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9931
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79289932
79299933 if (!BOXMODE)
79309934 {
7931
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9935
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79329936 }
79339937
79349938 if (!BOXMODE)
....@@ -7966,7 +9970,7 @@
79669970 ABORTED = false;
79679971 }
79689972 else
7969
- GrafreeD.wav.cursor += 735 * ACSIZE;
9973
+ Grafreed.wav.cursor += 735 * ACSIZE;
79709974
79719975 if (false)
79729976 {
....@@ -8620,13 +10624,6 @@
862010624 }
862110625 }
862210626
8623
- boolean IsFrozen()
8624
- {
8625
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8626
-
8627
- return !selectmode && cameracount == 0; // != 0;
8628
- }
8629
-
863010627 boolean niceon = false;
863110628 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
863210629 boolean currentlydrawing = false;
....@@ -8636,16 +10633,16 @@
863610633
863710634 public void display(GLAutoDrawable drawable)
863810635 {
8639
- if (GrafreeD.savesound && GrafreeD.hassound)
10636
+ if (Grafreed.savesound && Grafreed.hassound)
864010637 {
8641
- GrafreeD.wav.save();
8642
- GrafreeD.savesound = false;
8643
- GrafreeD.hassound = false;
10638
+ Grafreed.wav.save();
10639
+ Grafreed.savesound = false;
10640
+ Grafreed.hassound = false;
864410641 }
864510642 // if (DEBUG_SELECTION)
864610643 // {
8647
-// if (drawMode != SELECTION)
8648
-// drawMode = SELECTION;
10644
+// if (DrawMode() != SELECTION)
10645
+// DrawMode() = SELECTION;
864910646 // }
865010647
865110648 if (!isRenderer)
....@@ -8701,9 +10698,9 @@
870110698
870210699 //ANTIALIAS = 0;
870310700
8704
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10701
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870510702 {
8706
- if (niceon || isLIVE())
10703
+ if (niceon || Globals.isLIVE())
870710704 {
870810705 //if(active == 0)
870910706 // antialiaser = null;
....@@ -8716,6 +10713,7 @@
871610713 ANTIALIAS = 0;
871710714 //System.out.println("RESTART");
871810715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
871910717 }
872010718 }
872110719 }
....@@ -8728,7 +10726,7 @@
872810726 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872910727 */
873010728
8731
- if (drawMode == DEFAULT)
10729
+ if (DrawMode() == DEFAULT)
873210730 {
873310731 currentlydrawing = true;
873410732 }
....@@ -8759,18 +10757,18 @@
875910757
876010758 // if(Applet3D.clipboard != null)
876110759 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8762
-//drawMode = SELECTION;
10760
+//DrawMode() = SELECTION;
876310761 indexcount = 0;
876410762
8765
- if (drawMode == OCCLUSION)
10763
+ if (DrawMode() == OCCLUSION)
876610764 {
8767
- drawMode = DEFAULT;
10765
+ Globals.drawMode = DEFAULT; // WARNING
876810766 ambientOcclusion = true;
876910767 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
877010768 Object3D theobject = object;
877110769 Object3D theparent = object.parent;
877210770 object.parent = null;
8773
- object = (Object3D)GrafreeD.clone(object);
10771
+ object = (Object3D)Grafreed.clone(object);
877410772 object.Stripify();
877510773 if (theobject.selection == null || theobject.selection.Size() == 0)
877610774 theobject.PreprocessOcclusion(this);
....@@ -8783,19 +10781,20 @@
878310781 ambientOcclusion = false;
878410782 }
878510783
8786
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878710786 {
878810787 //if (RENDERSHADOW) // ?
878910788 if (!IsFrozen())
879010789 {
879110790 // dec 2012
8792
- if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10791
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
879310792 {
8794
- framecount++;
10793
+ Globals.framecount++;
879510794 shadowbuffer.display();
879610795 }
879710796 }
8798
- lighttouched = false; // ??
10797
+ Globals.lighttouched = false; // ??
879910798 //drawing = true;
880010799 //lighttouched = true;
880110800 }
....@@ -8816,9 +10815,9 @@
881610815 //eyeCamera.shaper_fovy = 1;
881710816 }
881810817
8819
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10818
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
882010819 {
8821
- //System.out.println("drawMode = " + drawMode);
10820
+ //System.out.println("DrawMode() = " + DrawMode());
882210821 vertexMode |= VP_PASS;
882310822 //vertexMode |= VP_PROJECTION;
882410823 if (!ambientOcclusion)
....@@ -8878,7 +10877,7 @@
887810877 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887910878 //Camera lightcam = new Camera(light0);
888010879
8881
- if (drawMode == SHADOW)
10880
+ if (DrawMode() == SHADOW)
888210881 {
888310882 /*
888410883 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8916,8 +10915,8 @@
891610915
891710916 // if (parentcam != renderCamera) // not a light
891810917 if (cam != lightCamera)
8919
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8920
- LA.matConcat(matrix, parentcam.toParent, matrix);
10918
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
892110920
892210921 for (int j = 0; j < 4; j++)
892310922 {
....@@ -8931,8 +10930,8 @@
893110930
893210931 // if (parentcam != renderCamera) // not a light
893310932 if (cam != lightCamera)
8934
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8935
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10933
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
893610935
893710936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893810937
....@@ -8968,7 +10967,7 @@
896810967 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896910968 } else
897010969 {
8971
- if (drawMode != DEFAULT)
10970
+ if (DrawMode() != DEFAULT)
897210971 {
897310972 gl.glClearColor(1, 1, 1, 0);
897410973 } // 1);
....@@ -9033,7 +11032,7 @@
903311032
903411033 fast &= !ambientOcclusion;
903511034
9036
- if (drawMode == DEFAULT)
11035
+ if (DrawMode() == DEFAULT)
903711036 {
903811037 //gl.glEnable(gl.GL_ALPHA_TEST);
903911038 //gl.glActiveTexture(GL.GL_TEXTURE0);
....@@ -9191,7 +11190,16 @@
919111190 // Bump noise
919211191 gl.glActiveTexture(GL.GL_TEXTURE6);
919311192 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9194
- BindTexture(NOISE_TEXTURE, false, 2);
11193
+
11194
+ try
11195
+ {
11196
+ BindTexture(NOISE_TEXTURE, false, 2);
11197
+ }
11198
+ catch (Exception e)
11199
+ {
11200
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11201
+ }
11202
+
919511203
919611204 gl.glActiveTexture(GL.GL_TEXTURE0);
919711205 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9214,9 +11222,9 @@
921411222
921511223 gl.glMatrixMode(GL.GL_MODELVIEW);
921611224
9217
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9218
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9219
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
922011228 } else
922111229 {
922211230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9227,11 +11235,11 @@
922711235 //System.out.println("BLENDING ON");
922811236 gl.glEnable(GL.GL_BLEND);
922911237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9230
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
923111239 gl.glMatrixMode(gl.GL_PROJECTION);
923211240 gl.glLoadIdentity();
923311241
9234
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11242
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
923511243 {
923611244 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923711245 double scale = lightCamera.SCALE / lightCamera.Distance();
....@@ -9289,7 +11297,7 @@
928911297 //gl.glPushMatrix();
929011298 gl.glLoadIdentity();
929111299
9292
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11300
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
929311301 {
929411302 //LA.xformPos(light0, lightCamera.fromScreen, light);
929511303 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9316,8 +11324,8 @@
931611324 System.err.println("parentcam != renderCamera");
931711325
931811326 // if (cam != lightCamera)
9319
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9320
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11327
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
932111329 }
932211330
932311331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9338,8 +11346,8 @@
933811346 if (true) // TODO
933911347 {
934011348 if (cam != lightCamera)
9341
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9342
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11349
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11350
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
934311351 }
934411352
934511353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9376,7 +11384,7 @@
937611384 }
937711385
937811386 /**/
9379
- if (true) // drawMode == SELECTION) // != DEFAULT)
11387
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
938011388 gl.glDisable(gl.GL_LIGHTING);
938111389 else
938211390 gl.glEnable(gl.GL_LIGHTING);
....@@ -9394,7 +11402,7 @@
939411402
939511403 lightslot = 64;
939611404
9397
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11405
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
939811406 {
939911407 DrawLights(object);
940011408 }
....@@ -9405,7 +11413,7 @@
940511413 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
940611414 //System.out.println("fragmentMode = " + fragmentMode);
940711415
9408
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11416
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
940911417 {
941011418 /*
941111419 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9438,7 +11446,7 @@
943811446 }
943911447 }
944011448
9441
- if (drawMode == DEFAULT)
11449
+ if (DrawMode() == DEFAULT)
944211450 {
944311451 if (WIREFRAME && !ambientOcclusion)
944411452 {
....@@ -9456,7 +11464,7 @@
945611464 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
945711465 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
945811466
9459
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11467
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
946011468 {
946111469 if (vertexMode != 0) // && !fast)
946211470 {
....@@ -9476,7 +11484,7 @@
947611484 }
947711485 }
947811486
9479
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
948011488 {
948111489 //gl.glDepthFunc(GL.GL_LEQUAL);
948211490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9484,27 +11492,24 @@
948411492
948511493 boolean texon = textureon;
948611494
9487
- if (RENDERPROGRAM > 0)
9488
- {
9489
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9490
- textureon = false;
9491
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
949211498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
949311499 //System.out.println("ALLO");
949411500 gl.glColorMask(false, false, false, false);
949511501 DrawObject(gl);
9496
- if (RENDERPROGRAM > 0)
9497
- {
9498
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9499
- textureon = texon;
9500
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
950111506 gl.glColorMask(true, true, true, true);
950211507
950311508 gl.glDepthFunc(GL.GL_EQUAL);
9504
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
950511510 }
950611511
9507
- if (false) // drawMode == SHADOW)
11512
+ if (false) // DrawMode() == SHADOW)
950811513 {
950911514 //SetColumnMajorData(cameraInverseTransform, view_1);
951011515 //System.out.println("light = " + cameraInverseTransform);
....@@ -9518,16 +11523,16 @@
951811523 //System.out.println("object = " + object);
951911524 if (!frozen && !imageLocked)
952011525 {
9521
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11526
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
952211527 {
952311528 displayAntiAliased(gl);
952411529 } else
952511530 {
952611531 programcount = 0;
9527
- int keepmode = drawMode;
11532
+ int keepmode = DrawMode();
952811533 // if (DEBUG_SELECTION)
952911534 // {
9530
-// drawMode = SELECTION;
11535
+// DrawMode() = SELECTION;
953111536 // }
953211537 // for point selection
953311538 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9537,10 +11542,10 @@
953711542 DrawObject(gl);
953811543
953911544 // jan 2013 System.err.println("RESET ABORT (display)");
9540
- // if (drawMode == DEFAULT)
11545
+ // if (DrawMode() == DEFAULT)
954111546 // ABORTED = false;
954211547 fullreset = false;
9543
- drawMode = keepmode;
11548
+ Globals.drawMode = keepmode; // WARNING
954411549 //System.out.println("PROGRAM SWITCH " + programcount);
954511550 }
954611551 }
....@@ -9548,11 +11553,11 @@
954811553 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
954911554 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
955011555
9551
- if (drawMode == DEFAULT)
11556
+ if (DrawMode() == DEFAULT)
955211557 {
955311558 ReleaseTexture(NOISE_TEXTURE, false);
955411559 }
9555
- //if (drawMode == DEFAULT)
11560
+ //if (DrawMode() == DEFAULT)
955611561 {
955711562
955811563 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9564,7 +11569,7 @@
956411569 //else
956511570 //gl.glDisable(gl.GL_TEXTURE_2D);
956611571 //gl.glPopMatrix();
9567
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11572
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
956811573 {
956911574 //new Exception().printStackTrace();
957011575 //System.out.println("Draw image " + width + ", " + height);
....@@ -9606,7 +11611,7 @@
960611611 //gl.glFlush();
960711612 }
960811613
9609
- if (flash && drawMode == DEFAULT)
11614
+ if (flash && DrawMode() == DEFAULT)
961011615 {
961111616 flash = false;
961211617 wait = true;
....@@ -9614,9 +11619,9 @@
961411619 }
961511620
961611621 //drawing = false;
9617
- //if(drawMode == DEFAULT)
11622
+ //if(DrawMode() == DEFAULT)
961811623 // niceon = false;
9619
- if (drawMode == DEFAULT)
11624
+ if (DrawMode() == DEFAULT)
962011625 {
962111626 currentlydrawing = false;
962211627 }
....@@ -9636,7 +11641,7 @@
963611641 repaint();
963711642 }
963811643
9639
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11644
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
964011645 repaint();
964111646
964211647 displaydone = true;
....@@ -9655,8 +11660,14 @@
965511660 {
965611661 renderpass++;
965711662 // System.out.println("Draw object... ");
11663
+ STEP = 1;
965811664 if (FAST) // in case there is no script
9659
- STEP = 16;
11665
+ STEP = 8;
11666
+
11667
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11668
+ {
11669
+ STEP *= 4;
11670
+ }
966011671
966111672 //object.FullInvariants();
966211673
....@@ -9670,23 +11681,44 @@
967011681 e.printStackTrace();
967111682 }
967211683
9673
- if (GrafreeD.RENDERME > 0)
9674
- GrafreeD.RENDERME--; // mechante magouille
11684
+ if (Grafreed.RENDERME > 0)
11685
+ Grafreed.RENDERME--; // mechante magouille
967511686
9676
- ONESTEP = false;
11687
+ Globals.ONESTEP = false;
967711688 }
967811689
967911690 static boolean zoomonce = false;
968011691
11692
+ static void CreateSelectedPoint()
11693
+ {
11694
+ if (selectedpoint == null)
11695
+ {
11696
+ debugpointG = new Sphere();
11697
+ debugpointP = new Sphere();
11698
+ debugpointC = new Sphere();
11699
+ debugpointR = new Sphere();
11700
+
11701
+ selectedpoint = new Superellipsoid();
11702
+
11703
+ for (int i=0; i<8; i++)
11704
+ {
11705
+ debugpoints[i] = new Sphere();
11706
+ }
11707
+ }
11708
+ }
11709
+
968111710 void DrawObject(GL gl, boolean draw)
968211711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
968311715 //System.out.println("DRAW OBJECT " + mouseDown);
9684
-// drawMode = SELECTION;
11716
+// DrawMode() = SELECTION;
968511717 //GL gl = getGL();
968611718 if ((TRACK || SHADOWTRACK) || zoomonce)
968711719 {
9688
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9689
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11720
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
969011722 pingthread.StepToTarget(true); // true);
969111723 // zoomonce = false;
969211724 }
....@@ -9706,9 +11738,9 @@
970611738 callist = gl.glGenLists(1);
970711739 }
970811740
9709
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11741
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
971011742
9711
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11743
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
971211744
971311745 if (!mainDL || !active || touched)
971411746 {
....@@ -9735,13 +11767,20 @@
973511767 PushMatrix(ClickInfo.matbuffer);
973611768 }
973711769
9738
- if (drawMode == 0)
11770
+ if (DrawMode() == 0)
973911771 {
974011772 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
974111773
974211774 usedtextures.clear();
974311775
9744
- BindTextures(DEFAULT_TEXTURES, 2);
11776
+ try
11777
+ {
11778
+ BindTextures(DEFAULT_TEXTURES, 2);
11779
+ }
11780
+ catch (Exception e)
11781
+ {
11782
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11783
+ }
974511784 }
974611785 //System.out.println("--> " + stackdepth);
974711786 // GrafreeD.traceon();
....@@ -9749,10 +11788,11 @@
974911788 // DRAW
975011789 object.draw(this, /*(Composite)*/ object, false, false);
975111790
9752
- if (drawMode == DEFAULT)
11791
+ if (DrawMode() == DEFAULT)
975311792 {
9754
- if (DEBUG)
11793
+ if (Globals.DEBUG)
975511794 {
11795
+ CreateSelectedPoint();
975611796 float radius = 0.05f;
975711797 if (selectedpoint.radius != radius)
975811798 {
....@@ -9801,38 +11841,57 @@
980111841 }
980211842 // GrafreeD.traceoff();
980311843 //System.out.println(stackdepth);
9804
- if (drawMode == 0)
11844
+ if (DrawMode() == 0)
980511845 {
980611846 ReleaseTextures(DEFAULT_TEXTURES);
980711847
980811848 if (CLEANCACHE)
9809
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
981011850 {
9811
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
981211852
981311853 // System.out.println("Texture --------- " + tex);
981411854
9815
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
981611856 continue;
981711857
9818
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
981911859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
982011861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9821
- textures.get(tex).texture.dispose();
9822
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
982311875 }
982411876 }
982511877 }
982611878
982711879 checker = null;
982811880
9829
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11881
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
983011882 FindChecker(object);
983111883
9832
- if (checker != null && drawMode == DEFAULT)
11884
+ if (checker != null && DrawMode() == DEFAULT)
983311885 {
983411886 //BindTexture(IMMORTAL_TEXTURE);
9835
- BindTextures(checker.GetTextures(), checker.texres);
11887
+ try
11888
+ {
11889
+ BindTextures(checker.GetTextures(), checker.texres);
11890
+ }
11891
+ catch (Exception e)
11892
+ {
11893
+ System.err.println("FAILED: " + checker.GetTextures());
11894
+ }
983611895 // NEAREST
983711896 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
983811897 DrawChecker(gl);
....@@ -9851,7 +11910,7 @@
985111910 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
985211911 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
985311912
9854
- if (DISPLAYTEXT && drawMode == DEFAULT)
11913
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
985511914 {
985611915 // Draw it once, then use the raster
985711916 Balloon(gl, balloon.createGraphics());
....@@ -9907,14 +11966,14 @@
990711966 int[] xs = new int[3];
990811967 int[] ys = new int[3];
990911968
9910
- void DrawString(Object3D obj) // String string)
11969
+ public void DrawString(Object3D obj) // String string) // INTERFACE
991111970 {
9912
- if (!DISPLAYTEXT || drawMode != DEFAULT)
11971
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
991311972 {
991411973 return;
991511974 }
991611975
9917
- String string = obj.GetToolTip();
11976
+ String string = obj.toString(); //.GetToolTip();
991811977
991911978 GL gl = GetGL();
992011979
....@@ -10231,8 +12290,8 @@
1023112290 //obj.TransformToWorld(light, light);
1023212291 for (int i = tp.size(); --i >= 0;)
1023312292 {
10234
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10235
- LA.xformPos(light, tp.get(i).toParent, light);
12293
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12294
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1023612295 }
1023712296
1023812297
....@@ -10249,8 +12308,8 @@
1024912308 parentcam = cameras[0];
1025012309 }
1025112310
10252
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10253
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12311
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12312
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1025412313
1025512314 LA.xformPos(light, renderCamera.toScreen, light);
1025612315
....@@ -10864,8 +12923,8 @@
1086412923
1086512924 // display shadow only (bump == 0)
1086612925 "SUB temp.x, half.x, shadow.x;" +
10867
- "MOV temp.y, -params6.x;" +
10868
- "SLT temp.z, temp.y, zero.x;" +
12926
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12927
+ "SLT temp.z, temp.y, -one2048th.x;" +
1086912928 "SUB temp.y, one.x, temp.z;" +
1087012929 "MUL temp.x, temp.x, temp.y;" +
1087112930 "KIL temp.x;" +
....@@ -10994,8 +13053,10 @@
1099413053 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1099513054
1099613055 "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
13056
+ // Tuning for default skin
13057
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13058
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13059
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1099913060 "MUL temp.x, temp.x, temp.y;" +
1100013061
1100113062 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11194,7 +13255,7 @@
1119413255 //once = true;
1119513256 }
1119613257
11197
- System.out.print("Program #" + mode + "; length = " + program.length());
13258
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1119813259 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1119913260 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1120013261
....@@ -11327,12 +13388,16 @@
1132713388
1132813389 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1132913390 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13391
+
13392
+ // Compare fragment depth in light space with shadowmap.
1133013393 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1133113394 "SGE temp.y, temp.x, zero.x;" +
11332
- "SUB " + shadow + ".y, one.x, temp.y;" +
13395
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13396
+
13397
+ // Reverse comparison
1133313398 "SUB temp.x, one.x, temp.x;" +
1133413399 "MUL " + shadow + ".x, temp.x, temp.y;" +
11335
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13400
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1133613401 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1133713402
1133813403 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11346,6 +13411,10 @@
1134613411 // No shadow for backface
1134713412 "DP3 temp.x, normal, lightd;" +
1134813413 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13414
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13415
+
13416
+ // No shadow when out of frustrum
13417
+ "SGE temp.x, " + depth + ".z, one.z;" +
1134913418 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1135013419 "";
1135113420 }
....@@ -11492,7 +13561,8 @@
1149213561 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1149313562 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1149413563 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11495
- Object3D.cVector2[] vector2buffer;
13564
+
13565
+ //Object3D.cVector2[] vector2buffer;
1149613566
1149713567 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1149813568 // OUT : diff, spec
....@@ -11508,9 +13578,10 @@
1150813578 "DP3 " + dest + ".z," + "normals," + "eye;" +
1150913579 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1151013580 //"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;" +
13581
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13582
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13583
+
13584
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1151413585 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1151513586 "RCP " + dest + ".w," + dest + ".w;" +
1151613587 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11904,7 +13975,7 @@
1190413975 public void mousePressed(MouseEvent e)
1190513976 {
1190613977 //System.out.println("mousePressed: " + e);
11907
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
13978
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1190813979 }
1190913980
1191013981 static long prevtime = 0;
....@@ -11931,6 +14002,7 @@
1193114002
1193214003 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1193314004
14005
+ if (BUTTONLESSWHEEL)
1193414006 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1193514007 {
1193614008 return;
....@@ -11939,7 +14011,7 @@
1193914011 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1194014012
1194114013 // TIMER
11942
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14014
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1194314015 {
1194414016 keepboxmode = BOXMODE;
1194514017 keepsupport = SUPPORT;
....@@ -11979,8 +14051,8 @@
1197914051 // mode |= META;
1198014052 //}
1198114053
11982
- SetMouseMode(WHEEL | e.getModifiersEx());
11983
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14054
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14055
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1198414056 anchorX = ax;
1198514057 anchorY = ay;
1198614058 prevX = px;
....@@ -12014,6 +14086,7 @@
1201414086 else
1201514087 if (evt.getSource() == AAtimer)
1201614088 {
14089
+ Globals.TIMERRUNNING = false;
1201714090 if (mouseDown)
1201814091 {
1201914092 //new Exception().printStackTrace();
....@@ -12039,6 +14112,10 @@
1203914112 // LIVE = waslive;
1204014113 // wasliveok = true;
1204114114 // waslive = false;
14115
+
14116
+ // May 2019 Forget it:
14117
+ if (true)
14118
+ return;
1204214119
1204314120 // source == timer
1204414121 if (mouseDown)
....@@ -12068,8 +14145,8 @@
1206814145 // ObjEditor.tweenManager.update(1f / 60f);
1206914146
1207014147 // fev 2014???
12071
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12072
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14148
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14149
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1207314150 pingthread.StepToTarget(true); // true);
1207414151 }
1207514152 // if (!LIVE)
....@@ -12078,12 +14155,13 @@
1207814155
1207914156 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1208014157
12081
- void clickStart(int x, int y, int modifiers)
14158
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1208214159 {
1208314160 if (!wasliveok)
1208414161 return;
1208514162
1208614163 AAtimer.restart(); //
14164
+ Globals.TIMERRUNNING = true;
1208714165
1208814166 // waslive = LIVE;
1208914167 // LIVE = false;
....@@ -12095,7 +14173,7 @@
1209514173 // touched = true; // main DL
1209614174 if (isRenderer)
1209714175 {
12098
- SetMouseMode(modifiers);
14176
+ SetMouseMode(modifiers, modifiersex);
1209914177 }
1210014178
1210114179 selectX = anchorX = x;
....@@ -12108,7 +14186,7 @@
1210814186 clicked = true;
1210914187 hold = false;
1211014188
12111
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14189
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1211214190 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1211314191 {
1211414192 // System.out.println("RESTART II " + modifiers);
....@@ -12139,7 +14217,7 @@
1213914217 info.camera = renderCamera;
1214014218 info.x = x;
1214114219 info.y = y;
12142
- info.modifiers = modifiers;
14220
+ info.modifiers = modifiersex;
1214314221 editObj = object.doEditClick(info, 0);
1214414222 if (!editObj)
1214514223 {
....@@ -12156,11 +14234,14 @@
1215614234
1215714235 public void mouseDragged(MouseEvent e)
1215814236 {
14237
+ Globals.MOUSEDRAGGED = true;
14238
+
14239
+ //System.out.println("mouseDragged: " + e);
1215914240 if (isRenderer)
1216014241 movingcamera = true;
14242
+
1216114243 //if (drawing)
1216214244 //return;
12163
- //System.out.println("mouseDragged: " + e);
1216414245 if ((e.getModifiersEx() & CTRL) != 0
1216514246 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1216614247 {
....@@ -12168,7 +14249,7 @@
1216814249 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1216914250 }
1217014251 else
12171
- drag(e.getX(), e.getY(), e.getModifiersEx());
14252
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1217214253
1217314254 //try { Thread.sleep(1); } catch (Exception ex) {}
1217414255 }
....@@ -12180,6 +14261,11 @@
1218014261 cVector tmp = new cVector();
1218114262 cVector tmp2 = new cVector();
1218214263 boolean isMoving;
14264
+
14265
+ public cVector TargetLookAt()
14266
+ {
14267
+ return targetLookAt;
14268
+ }
1218314269
1218414270 class PingThread extends Thread
1218514271 {
....@@ -12319,7 +14405,7 @@
1231914405 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1232014406 if (lightMode)
1232114407 {
12322
- lighttouched = true;
14408
+ Globals.lighttouched = true;
1232314409 }
1232414410
1232514411 if (OEILONCE && OEIL)
....@@ -12336,6 +14422,7 @@
1233614422
1233714423 public void run()
1233814424 {
14425
+ new Exception().printStackTrace();
1233914426 System.exit(0);
1234014427 for (;;)
1234114428 {
....@@ -12377,7 +14464,7 @@
1237714464 mouseDown = false;
1237814465 if (lightMode)
1237914466 {
12380
- lighttouched = true;
14467
+ Globals.lighttouched = true;
1238114468 }
1238214469 repaint();
1238314470 alreadypainted = true;
....@@ -12385,7 +14472,7 @@
1238514472 isMoving = false;
1238614473 } //??
1238714474
12388
- if (isLIVE() && !alreadypainted)
14475
+ if (Globals.isLIVE() && !alreadypainted)
1238914476 {
1239014477 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1239114478 repaint();
....@@ -12397,9 +14484,9 @@
1239714484 {
1239814485 if (lightMode)
1239914486 {
12400
- lighttouched = true;
14487
+ Globals.lighttouched = true;
1240114488 }
12402
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14489
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1240314490 }
1240414491 //else
1240514492 }
....@@ -12413,12 +14500,12 @@
1241314500 void GoDown(int mod)
1241414501 {
1241514502 MODIFIERS |= COMMAND;
12416
- /*
14503
+ /**/
1241714504 if((mod&SHIFT) == SHIFT)
1241814505 manipCamera.RotatePosition(0, -speed);
1241914506 else
12420
- manipCamera.BackForth(0, -speed*delta, getWidth());
12421
- */
14507
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14508
+ /**/
1242214509 if ((mod & SHIFT) == SHIFT)
1242314510 {
1242414511 mouseMode = mouseMode; // VR??
....@@ -12434,12 +14521,12 @@
1243414521 void GoUp(int mod)
1243514522 {
1243614523 MODIFIERS |= COMMAND;
12437
- /*
14524
+ /**/
1243814525 if((mod&SHIFT) == SHIFT)
1243914526 manipCamera.RotatePosition(0, speed);
1244014527 else
12441
- manipCamera.BackForth(0, speed*delta, getWidth());
12442
- */
14528
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14529
+ /**/
1244314530 if ((mod & SHIFT) == SHIFT)
1244414531 {
1244514532 mouseMode = mouseMode;
....@@ -12455,12 +14542,12 @@
1245514542 void GoLeft(int mod)
1245614543 {
1245714544 MODIFIERS |= COMMAND;
12458
- /*
14545
+ /**/
1245914546 if((mod&SHIFT) == SHIFT)
12460
- manipCamera.RotatePosition(speed, 0);
12461
- else
1246214547 manipCamera.Translate(speed*delta, 0, getWidth());
12463
- */
14548
+ else
14549
+ manipCamera.RotatePosition(speed, 0);
14550
+ /**/
1246414551 if ((mod & SHIFT) == SHIFT)
1246514552 {
1246614553 mouseMode = mouseMode;
....@@ -12476,12 +14563,12 @@
1247614563 void GoRight(int mod)
1247714564 {
1247814565 MODIFIERS |= COMMAND;
12479
- /*
14566
+ /**/
1248014567 if((mod&SHIFT) == SHIFT)
12481
- manipCamera.RotatePosition(-speed, 0);
12482
- else
1248314568 manipCamera.Translate(-speed*delta, 0, getWidth());
12484
- */
14569
+ else
14570
+ manipCamera.RotatePosition(-speed, 0);
14571
+ /**/
1248514572 if ((mod & SHIFT) == SHIFT)
1248614573 {
1248714574 mouseMode = mouseMode;
....@@ -12499,7 +14586,7 @@
1249914586 int X, Y;
1250014587 boolean SX, SY;
1250114588
12502
- void drag(int x, int y, int modifiers)
14589
+ void drag(int x, int y, int modifiers, int modifiersex)
1250314590 {
1250414591 if (IsFrozen())
1250514592 {
....@@ -12508,17 +14595,17 @@
1250814595
1250914596 drag = true; // NEW
1251014597
12511
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14598
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1251214599
1251314600 X = x;
1251414601 Y = y;
1251514602 // floating state for animation
12516
- MODIFIERS = modifiers;
12517
- modifiers &= ~1024;
14603
+ MODIFIERS = modifiersex;
14604
+ modifiersex &= ~1024;
1251814605 if (false) // modifiers != 0)
1251914606 {
1252014607 //new Exception().printStackTrace();
12521
- System.out.println("mouseDragged: " + modifiers);
14608
+ System.out.println("mouseDragged: " + modifiersex);
1252214609 System.out.println("SHIFT = " + SHIFT);
1252314610 System.out.println("CONTROL = " + COMMAND);
1252414611 System.out.println("META = " + META);
....@@ -12538,7 +14625,8 @@
1253814625 info.camera = renderCamera;
1253914626 info.x = x;
1254014627 info.y = y;
12541
- object.editWindow.copy.doEditDrag(info);
14628
+ object.GetWindow().copy
14629
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1254214630 } else
1254314631 {
1254414632 if (x < startX)
....@@ -12651,7 +14739,7 @@
1265114739
1265214740 if (manipCamera == lightCamera)
1265314741 {
12654
- lighttouched = true;
14742
+ Globals.lighttouched = true;
1265514743 }
1265614744 /*
1265714745 switch (mode)
....@@ -12690,7 +14778,6 @@
1269014778 public void mouseMoved(MouseEvent e)
1269114779 {
1269214780 //System.out.println("mouseMoved: " + e);
12693
-
1269414781 if (isRenderer)
1269514782 return;
1269614783
....@@ -12703,7 +14790,9 @@
1270314790 ci.camera = renderCamera;
1270414791 if (!isRenderer)
1270514792 {
12706
- if (object.editWindow.copy.doEditClick(ci, 0))
14793
+ //ObjEditor editWindow = object.editWindow;
14794
+ //Object3D copy = editWindow.copy;
14795
+ if (object.doEditClick(ci, 0))
1270714796 {
1270814797 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1270914798 } else
....@@ -12715,7 +14804,11 @@
1271514804
1271614805 public void mouseReleased(MouseEvent e)
1271714806 {
14807
+ Globals.MOUSEDRAGGED = false;
14808
+
1271814809 movingcamera = false;
14810
+ X = 0; // getBounds().width/2;
14811
+ Y = 0; // getBounds().height/2;
1271914812 //System.out.println("mouseReleased: " + e);
1272014813 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1272114814 }
....@@ -12738,9 +14831,9 @@
1273814831 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1273914832 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1274014833
12741
- if (control || command || IsFrozen())
14834
+// No delay if (control || command || IsFrozen())
1274214835 timeout = true;
12743
- else
14836
+// ?? May 2019 else
1274414837 // timer.setDelay((modifiers & 128) != 0?0:350);
1274514838 mouseDown = false;
1274614839 if (!control && !command) // june 2013
....@@ -12850,7 +14943,7 @@
1285014943 System.out.println("keyReleased: " + e);
1285114944 }
1285214945
12853
- void SetMouseMode(int modifiers)
14946
+ void SetMouseMode(int modifiers, int modifiersex)
1285414947 {
1285514948 //System.out.println("SetMouseMode = " + modifiers);
1285614949 //modifiers &= ~1024;
....@@ -12862,25 +14955,25 @@
1286214955 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1286314956 // return;
1286414957 //System.out.println("SetMode = " + modifiers);
12865
- if ((modifiers & WHEEL) == WHEEL)
14958
+ if ((modifiersex & WHEEL) == WHEEL)
1286614959 {
1286714960 mouseMode |= ZOOM;
1286814961 }
1286914962
1287014963 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
12871
- if (capsLocked || (modifiers & META) == META)
14964
+ if (capsLocked) // || (modifiers & META) == META)
1287214965 {
1287314966 mouseMode |= VR; // BACKFORTH;
1287414967 }
12875
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
14968
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1287614969 {
1287714970 mouseMode |= SELECT;
1287814971 }
12879
- if ((modifiers & COMMAND) == COMMAND)
14972
+ if ((modifiersex & COMMAND) == COMMAND)
1288014973 {
1288114974 mouseMode |= SELECT;
1288214975 }
12883
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
14976
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1288414977 {
1288514978 mouseMode &= ~VR;
1288614979 mouseMode |= TRANSLATE;
....@@ -12909,10 +15002,10 @@
1290915002
1291015003 if (isRenderer) //
1291115004 {
12912
- SetMouseMode(modifiers);
15005
+ SetMouseMode(0, modifiers);
1291315006 }
1291415007
12915
- theRenderer.keyPressed(key);
15008
+ Globals.theRenderer.keyPressed(key);
1291615009 }
1291715010
1291815011 int kompactbit = 4; // power bit
....@@ -12924,7 +15017,7 @@
1292415017 float SATPOW = 1; // 2; // 0.5f;
1292515018 float BRIPOW = 1; // 0.5f; // 0.5f;
1292615019
12927
- void keyPressed(int key)
15020
+ public void keyPressed(int key)
1292815021 {
1292915022 if (key >= '0' && key <= '5')
1293015023 clampbit = (key-'0');
....@@ -12971,7 +15064,8 @@
1297115064 // break;
1297215065 case 'T':
1297315066 CACHETEXTURE ^= true;
12974
- textures.clear();
15067
+ texturepigment.clear();
15068
+ texturebump.clear();
1297515069 // repaint();
1297615070 break;
1297715071 case 'Y':
....@@ -13039,7 +15133,7 @@
1303915133 case 'B':
1304015134 BRISMOOTH ^= true;
1304115135 SHADOWCULLFACE ^= true;
13042
- lighttouched = true;
15136
+ Globals.lighttouched = true;
1304315137 repaint();
1304415138 break;
1304515139 case 'b':
....@@ -13056,7 +15150,9 @@
1305615150 case 'E' : COMPACT ^= true;
1305715151 repaint();
1305815152 break;
13059
- case 'W' : DEBUGHSB ^= true;
15153
+ case 'W' : // Wide Window (fullscreen)
15154
+ //DEBUGHSB ^= true;
15155
+ ObjEditor.theFrame.ToggleFullScreen();
1306015156 repaint();
1306115157 break;
1306215158 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13081,8 +15177,8 @@
1308115177 RevertCamera();
1308215178 repaint();
1308315179 break;
13084
- case 'L':
1308515180 case 'l':
15181
+ //case 'L':
1308615182 if (lightMode)
1308715183 {
1308815184 lightMode = false;
....@@ -13139,7 +15235,7 @@
1313915235 repaint();
1314015236 break;
1314115237 case 'O':
13142
- drawMode = OCCLUSION;
15238
+ Globals.drawMode = OCCLUSION; // WARNING
1314315239 repaint();
1314415240 break;
1314515241 case 'o':
....@@ -13225,12 +15321,12 @@
1322515321 case '_':
1322615322 kompactbit = 5;
1322715323 break;
13228
- case '+':
13229
- kompactbit = 6;
13230
- break;
15324
+// case '+':
15325
+// kompactbit = 6;
15326
+// break;
1323115327 case ' ':
1323215328 lightMode ^= true;
13233
- lighttouched = true;
15329
+ Globals.lighttouched = true;
1323415330 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1323515331 targetLookAt.set(manipCamera.lookAt);
1323615332 repaint();
....@@ -13239,14 +15335,15 @@
1323915335 case ESC:
1324015336 RENDERPROGRAM += 1;
1324115337 RENDERPROGRAM %= 3;
15338
+
1324215339 repaint();
1324315340 break;
1324415341 case 'Z':
1324515342 //RESIZETEXTURE ^= true;
1324615343 //break;
1324715344 case 'z':
13248
- RENDERSHADOW ^= true;
13249
- lighttouched = true;
15345
+ Globals.RENDERSHADOW ^= true;
15346
+ Globals.lighttouched = true;
1325015347 repaint();
1325115348 break;
1325215349 //case UP:
....@@ -13278,8 +15375,9 @@
1327815375 case DELETE:
1327915376 ClearSelection();
1328015377 break;
13281
- /*
1328215378 case '+':
15379
+
15380
+ /*
1328315381 //fontsize += 1;
1328415382 bbzoom *= 2;
1328515383 repaint();
....@@ -13296,17 +15394,17 @@
1329615394 case '=':
1329715395 IncDepth();
1329815396 //fontsize += 1;
13299
- object.editWindow.refreshContents(true);
15397
+ object.GetWindow().refreshContents(true);
1330015398 maskbit = 6;
1330115399 break;
1330215400 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1330315401 DecDepth();
1330415402 maskbit = 5;
1330515403 //if(fontsize > 1) fontsize -= 1;
13306
- if (object.editWindow == null)
13307
- new Exception().printStackTrace();
13308
- else
13309
- object.editWindow.refreshContents(true);
15404
+// if (object.editWindow == null)
15405
+// new Exception().printStackTrace();
15406
+// else
15407
+ object.GetWindow().refreshContents(true);
1331015408 break;
1331115409 case '{':
1331215410 manipCamera.shaper_fovy /= 1.1;
....@@ -13361,6 +15459,7 @@
1336115459 }
1336215460 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1336315461 }
15462
+
1336415463 static double OCCLUSIONBOOST = 1; // 0.5;
1336515464
1336615465 void keyReleased(int key, int modifiers)
....@@ -13368,11 +15467,11 @@
1336815467 //mode = ROTATE;
1336915468 if ((MODIFIERS & COMMAND) == 0) // VR??
1337015469 {
13371
- SetMouseMode(modifiers);
15470
+ SetMouseMode(0, modifiers);
1337215471 }
1337315472 }
1337415473
13375
- protected void processKeyEvent(KeyEvent e)
15474
+ public void processKeyEvent(KeyEvent e)
1337615475 {
1337715476 switch (e.getID())
1337815477 {
....@@ -13502,8 +15601,9 @@
1350215601
1350315602 protected void processMouseMotionEvent(MouseEvent e)
1350415603 {
13505
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13506
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15604
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15605
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15606
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1350715607 {
1350815608 mouseMoved(e);
1350915609 } else
....@@ -13528,11 +15628,12 @@
1352815628 }
1352915629 */
1353015630
13531
- object.editWindow.EditSelection();
15631
+ object.GetWindow().EditSelection(false);
1353215632 }
1353315633
1353415634 void SelectParent()
1353515635 {
15636
+ new Exception().printStackTrace();
1353615637 System.exit(0);
1353715638 Composite group = (Composite) object;
1353815639 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13544,10 +15645,10 @@
1354415645 {
1354515646 //selectees.remove(i);
1354615647 System.out.println("select parent of " + elem);
13547
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15648
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1354815649 } else
1354915650 {
13550
- group.editWindow.Select(elem.GetTreePath(), first, true);
15651
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1355115652 }
1355215653
1355315654 first = false;
....@@ -13556,6 +15657,7 @@
1355615657
1355715658 void SelectChildren()
1355815659 {
15660
+ new Exception().printStackTrace();
1355915661 System.exit(0);
1356015662 /*
1356115663 Composite group = (Composite) object;
....@@ -13588,12 +15690,12 @@
1358815690 for (int j = 0; j < group.children.size(); j++)
1358915691 {
1359015692 elem = (Object3D) group.children.elementAt(j);
13591
- object.editWindow.Select(elem.GetTreePath(), first, true);
15693
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1359215694 first = false;
1359315695 }
1359415696 } else
1359515697 {
13596
- object.editWindow.Select(elem.GetTreePath(), first, true);
15698
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1359715699 }
1359815700
1359915701 first = false;
....@@ -13604,21 +15706,21 @@
1360415706 {
1360515707 //Composite group = (Composite) object;
1360615708 Object3D group = object;
13607
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15709
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1360815710 }
1360915711
1361015712 void ResetTransform(int mask)
1361115713 {
1361215714 //Composite group = (Composite) object;
1361315715 Object3D group = object;
13614
- group.editWindow.ResetTransform(mask);
15716
+ group.GetWindow().ResetTransform(mask);
1361515717 }
1361615718
1361715719 void FlipTransform()
1361815720 {
1361915721 //Composite group = (Composite) object;
1362015722 Object3D group = object;
13621
- group.editWindow.FlipTransform();
15723
+ group.GetWindow().FlipTransform();
1362215724 // group.editWindow.ReduceMesh(true);
1362315725 }
1362415726
....@@ -13626,7 +15728,7 @@
1362615728 {
1362715729 //Composite group = (Composite) object;
1362815730 Object3D group = object;
13629
- group.editWindow.PrintMemory();
15731
+ group.GetWindow().PrintMemory();
1363015732 // group.editWindow.ReduceMesh(true);
1363115733 }
1363215734
....@@ -13634,7 +15736,7 @@
1363415736 {
1363515737 //Composite group = (Composite) object;
1363615738 Object3D group = object;
13637
- group.editWindow.ResetCentroid();
15739
+ group.GetWindow().ResetCentroid();
1363815740 }
1363915741
1364015742 void IncDepth()
....@@ -13720,7 +15822,9 @@
1372015822 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1372115823 //Image img = CreateImage(width, height);
1372215824 //System.out.println("width = " + width + "; height = " + height + "\n");
15825
+
1372315826 Graphics gr = g; // img.getGraphics();
15827
+
1372415828 if (!hasMarquee)
1372515829 {
1372615830 if (Xmin < Xmax) // !locked)
....@@ -13808,6 +15912,7 @@
1380815912 info.bounds.y += (height - desired) / 2;
1380915913 }
1381015914 }
15915
+
1381115916 info.g = gr;
1381215917 info.camera = renderCamera;
1381315918 /*
....@@ -13817,15 +15922,55 @@
1381715922 */
1381815923 if (!isRenderer)
1381915924 {
13820
- object.drawEditHandles(info, 0);
15925
+ Grafreed.Assert(object != null);
15926
+ Grafreed.Assert(object.selection != null);
15927
+ if (object.selection.Size() > 0)
15928
+ {
15929
+ int hitSomething = object.selection.get(0).hitSomething;
15930
+
15931
+ info.DX = 0;
15932
+ info.DY = 0;
15933
+ info.W = 1;
15934
+ if (hitSomething == Object3D.hitCenter)
15935
+ {
15936
+ info.DX = X;
15937
+ if (X != 0)
15938
+ info.DX -= info.bounds.width/2;
15939
+
15940
+ info.DY = Y;
15941
+ if (Y != 0)
15942
+ info.DY -= info.bounds.height/2;
15943
+ }
15944
+
15945
+ object.drawEditHandles(info, 0);
15946
+
15947
+ if (drag && (X != 0 || Y != 0))
15948
+ {
15949
+ switch (hitSomething)
15950
+ {
15951
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15952
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15953
+ break;
15954
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15955
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15956
+ break;
15957
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15958
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15959
+ break;
15960
+ }
15961
+
15962
+ }
15963
+ }
1382115964 }
1382215965 }
15966
+
1382315967 if (isRenderer)
1382415968 {
1382515969 //gr.setColor(Color.black);
1382615970 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1382715971 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1382815972 }
15973
+
1382915974 if (hasMarquee)
1383015975 {
1383115976 gr.setXORMode(Color.white);
....@@ -13848,6 +15993,7 @@
1384815993 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1384915994 }
1385015995
15996
+ // To avoid clear.
1385115997 public void update(Graphics g)
1385215998 {
1385315999 paint(g);
....@@ -13937,6 +16083,7 @@
1393716083 public boolean mouseDown(Event evt, int x, int y)
1393816084 {
1393916085 System.out.println("mouseDown: " + evt);
16086
+ System.exit(0);
1394016087 /*
1394116088 locked = true;
1394216089 drag = false;
....@@ -13980,7 +16127,7 @@
1398016127 {
1398116128 keyPressed(0, modifiers);
1398216129 }
13983
- clickStart(x, y, modifiers);
16130
+ // clickStart(x, y, modifiers);
1398416131 return true;
1398516132 }
1398616133
....@@ -14098,7 +16245,7 @@
1409816245 {
1409916246 keyReleased(0, 0);
1410016247 }
14101
- drag(x, y, modifiers);
16248
+ drag(x, y, 0, modifiers);
1410216249 return true;
1410316250 }
1410416251
....@@ -14230,7 +16377,7 @@
1423016377 Object3D object;
1423116378 static Object3D trackedobject;
1423216379 Camera renderCamera; // Light or Eye (or Occlusion)
14233
- /*static*/ Camera manipCamera; // Light or Eye
16380
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1423416381 /*static*/ Camera eyeCamera;
1423516382 /*static*/ Camera lightCamera;
1423616383 int cameracount;
....@@ -14510,20 +16657,21 @@
1451016657 /**/
1451116658 //checker.GetMaterial().opacity = 1.1f;
1451216659 ////checker.GetMaterial().ambient = 0.99f;
14513
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14514
- Object3D.selectedstack[Object3D.materialdepth] = false;
14515
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16660
+ materialstack[materialdepth] = checker.material;
16661
+ selectedstack[materialdepth] = false;
16662
+ cStatic.objectstack[materialdepth++] = checker;
1451616663 //System.out.println("material " + material);
1451716664 //Applet3D.tracein(this, selected);
14518
- vector2buffer = checker.projectedVertices;
16665
+ //vector2buffer = checker.projectedVertices;
1451916666
14520
- checker.GetMaterial().Draw(this, false); // true);
16667
+ //checker.GetMaterial().Draw(this, false); // true);
16668
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1452116669
14522
- Object3D.materialdepth -= 1;
14523
- if (Object3D.materialdepth > 0)
16670
+ materialdepth -= 1;
16671
+ if (materialdepth > 0)
1452416672 {
14525
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14526
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16673
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16674
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1452716675 }
1452816676 //checker.GetMaterial().opacity = 1f;
1452916677 ////checker.GetMaterial().ambient = 1f;
....@@ -14609,6 +16757,14 @@
1460916757 }
1461016758 }
1461116759
16760
+ private Object3D GetFolder()
16761
+ {
16762
+ Object3D folder = object.GetWindow().copy;
16763
+ if (object.GetWindow().copy.selection.Size() > 0)
16764
+ folder = object.GetWindow().copy.selection.elementAt(0);
16765
+ return folder;
16766
+ }
16767
+
1461216768 class SelectBuffer implements GLEventListener
1461316769 {
1461416770
....@@ -14667,6 +16823,7 @@
1466716823 {
1466816824 if (!selection)
1466916825 {
16826
+ new Exception().printStackTrace();
1467016827 System.exit(0);
1467116828 return;
1467216829 }
....@@ -14687,17 +16844,39 @@
1468716844
1468816845 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1468916846
16847
+ if (PAINTMODE)
16848
+ {
16849
+ if (object.GetWindow().copy.selection.Size() > 0)
16850
+ {
16851
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16852
+
16853
+ // Make what you paint not selectable.
16854
+ paintobj.ResetSelectable();
16855
+ }
16856
+ }
16857
+
1469016858 //int tmp = selection_view;
1469116859 //selection_view = -1;
14692
- int temp = drawMode;
14693
- drawMode = SELECTION;
16860
+ int temp = DrawMode();
16861
+ Globals.drawMode = SELECTION; // WARNING
1469416862 indexcount = 0;
1469516863 parent.display(drawable);
1469616864 //selection_view = tmp;
1469716865 //if (temp == SELECTION)
1469816866 // temp = DEFAULT; // patch for selection debug
14699
- drawMode = temp;
16867
+ Globals.drawMode = temp; // WARNING
1470016868
16869
+ if (PAINTMODE)
16870
+ {
16871
+ if (object.GetWindow().copy.selection.Size() > 0)
16872
+ {
16873
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16874
+
16875
+ // Revert.
16876
+ paintobj.RestoreSelectable();
16877
+ }
16878
+ }
16879
+
1470116880 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1470216881
1470316882 // trying different ways of getting the depth info over
....@@ -14745,6 +16924,8 @@
1474516924 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1474616925 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1474716926 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16927
+
16928
+ CreateSelectedPoint();
1474816929
1474916930 // Will fit the mesh !!!
1475016931 selectedpoint.toParent[0][0] = 0.0001;
....@@ -14794,34 +16975,36 @@
1479416975 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]));
1479516976 }
1479616977
14797
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
16978
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1479816979 }
1479916980 }
1480016981
1480116982 if (!movingcamera && !PAINTMODE)
14802
- object.editWindow.ScreenFitPoint(); // fev 2014
16983
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1480316984
14804
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16985
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1480516986 {
14806
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16987
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1480716988
14808
- Object3D group = new Object3D("inst" + paintcount++);
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ {
16991
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1480916992
14810
- group.CreateMaterial(); // use a void leaf to select instances
14811
-
14812
- group.add(paintobj); // link
14813
-
14814
- object.editWindow.SnapObject(group);
14815
-
14816
- Object3D folder = object.editWindow.copy;
14817
-
14818
- if (object.editWindow.copy.selection.Size() > 0)
14819
- folder = object.editWindow.copy.selection.elementAt(0);
14820
-
14821
- folder.add(group);
14822
-
14823
- object.editWindow.ResetModel();
14824
- object.editWindow.refreshContents();
16993
+ Object3D inst = new Object3D("inst" + paintcount++);
16994
+
16995
+ inst.CreateMaterial(); // use a void leaf to select instances
16996
+
16997
+ inst.add(paintobj); // link
16998
+
16999
+ object.GetWindow().SnapObject(inst);
17000
+
17001
+ Object3D folder = paintFolder; // GetFolder();
17002
+
17003
+ folder.add(inst);
17004
+
17005
+ object.GetWindow().ResetModel();
17006
+ object.GetWindow().refreshContents();
17007
+ }
1482517008 }
1482617009 else
1482717010 paintcount = 0;
....@@ -14860,6 +17043,11 @@
1486017043 //System.out.println("objects[color] = " + objects[color]);
1486117044 //objects[color].Select();
1486217045 indexcount = 0;
17046
+ ObjEditor window = object.GetWindow();
17047
+ if (window != null && deselect)
17048
+ {
17049
+ window.Select(null, deselect, true);
17050
+ }
1486317051 object.Select(color, deselect);
1486417052 }
1486517053
....@@ -14959,7 +17147,7 @@
1495917147 gl.glDisable(gl.GL_CULL_FACE);
1496017148 }
1496117149
14962
- if (!RENDERSHADOW)
17150
+ if (!Globals.RENDERSHADOW)
1496317151 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1496417152
1496517153 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14969,14 +17157,14 @@
1496917157 //gl.glColorMask(false, false, false, false);
1497017158
1497117159 //render_scene_from_light_view(gl, drawable, 0, 0);
14972
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17160
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1497317161 {
1497417162 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1497517163
14976
- int temp = drawMode;
14977
- drawMode = SHADOW;
17164
+ int temp = DrawMode();
17165
+ Globals.drawMode = SHADOW; // WARNING
1497817166 parent.display(drawable);
14979
- drawMode = temp;
17167
+ Globals.drawMode = temp; // WARNING
1498017168 }
1498117169
1498217170 gl.glCullFace(gl.GL_BACK);
....@@ -15029,7 +17217,6 @@
1502917217
1503017218 class AntialiasBuffer implements GLEventListener
1503117219 {
15032
-
1503317220 CameraPane parent = null;
1503417221
1503517222 AntialiasBuffer(CameraPane p)
....@@ -15374,12 +17561,6 @@
1537417561 GLUT glut = new GLUT();
1537517562
1537617563
15377
- static final public int DEFAULT = 0;
15378
- static final public int SELECTION = 1;
15379
- static final public int SHADOW = 2;
15380
- static final public int OCCLUSION = 3;
15381
- static
15382
- public int drawMode = DEFAULT;
1538317564 public boolean spherical = false;
1538417565 static boolean DEBUG_OCCLUSION = false;
1538517566 static boolean DEBUG_SELECTION = false;
....@@ -15392,23 +17573,15 @@
1539217573 int AAbuffersize = 0;
1539317574
1539417575 //double[] selectedpoint = new double[3];
15395
- static Superellipsoid selectedpoint = new Superellipsoid();
17576
+ static Superellipsoid selectedpoint;
1539617577 static Sphere previousselectedpoint = null;
15397
- static Sphere debugpointG = new Sphere();
15398
- static Sphere debugpointP = new Sphere();
15399
- static Sphere debugpointC = new Sphere();
15400
- static Sphere debugpointR = new Sphere();
17578
+ static Sphere debugpointG;
17579
+ static Sphere debugpointP;
17580
+ static Sphere debugpointC;
17581
+ static Sphere debugpointR;
1540117582
1540217583 static Sphere debugpoints[] = new Sphere[8];
1540317584
15404
- static
15405
- {
15406
- for (int i=0; i<8; i++)
15407
- {
15408
- debugpoints[i] = new Sphere();
15409
- }
15410
- }
15411
-
1541217585 static void InitPoints(float radius)
1541317586 {
1541417587 for (int i=0; i<8; i++)
....@@ -15428,7 +17601,7 @@
1542817601 }
1542917602 }
1543017603
15431
- static void DrawPoints(CameraPane cpane)
17604
+ static void DrawPoints(iCameraPane cpane)
1543217605 {
1543317606 for (int i=0; i<8; i++) // first and last are red
1543417607 {
....@@ -15460,10 +17633,11 @@
1546017633 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1546117634 // Depth buffer format
1546217635 //private int depth_format;
15463
- static public void NextIndex(Object3D o, GL gl)
17636
+
17637
+ public void NextIndex()
1546417638 {
1546517639 indexcount+=16;
15466
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17640
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1546717641 //objects[indexcount] = o;
1546817642 //System.out.println("indexcount = " + indexcount);
1546917643 }