Normand Briere
2019-07-22 c570e1e38f2ff8622a71f81436654bad01cfdd5b
CameraPane.java
....@@ -31,9 +31,12 @@
3131
3232 import gleem.linalg.Mat4f;
3333
34
-class CameraPane extends GLCanvas implements Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
34
+class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3535 {
36
- static boolean DEBUG = false;
36
+ static cMaterial[] materialstack = new cMaterial[65536];
37
+ static boolean[] selectedstack = new boolean[65536];
38
+ static int materialdepth = 0;
39
+
3740 static boolean FRUSTUM = false; // still bogus true; // frustum culling
3841
3942 // camera change fix
....@@ -42,25 +45,40 @@
4245
4346 static int STEP = 1;
4447
45
- static boolean ONESTEP = false; // do LIVE once
46
-
47
- /**
48
- * @return the LIVE
49
- */
50
- public static boolean isLIVE()
48
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
5149 {
52
- return LIVE || ONESTEP;
50
+ int[] pixels = new int[bytes.length/3];
51
+ for (int i=pixels.length; --i>=0;)
52
+ {
53
+ int i3 = i*3;
54
+ pixels[i] = 0xFF;
55
+ pixels[i] <<= 8;
56
+ pixels[i] |= bytes[i3+2] & 0xFF;
57
+ pixels[i] <<= 8;
58
+ pixels[i] |= bytes[i3+1] & 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3] & 0xFF;
61
+ }
62
+ /*
63
+ int r=0,g=0,b=0,a=0;
64
+ for (int i=0; i<width; i++)
65
+ for (int j=0; j<height; j++)
66
+ {
67
+ int index = j*width+i;
68
+ int p = pixels[index];
69
+ a = ((p>>24) & 0xFF);
70
+ r = ((p>>16) & 0xFF);
71
+ g = ((p>>8) & 0xFF);
72
+ b = (p & 0xFF);
73
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
74
+ }
75
+ /**/
76
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
77
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
78
+ return rendImage;
5379 }
5480
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;
81
+ /*static*/ private boolean CULLFACE = false; // true;
6482 /*static*/ boolean NEAREST = false; // true;
6583 /*static*/ boolean WIREFRAME = false; // true;
6684
....@@ -70,14 +88,12 @@
7088 static int CURRENTANTIALIAS = 0; // 1;
7189 /*static*/ boolean RENDERSHADOW = true;
7290 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
73
- static boolean ANIMATION = false;
74
- static String filename;
7591
7692 boolean DISPLAYTEXT = false;
7793 //boolean REDUCETEXTURE = true;
7894 boolean CACHETEXTURE = true;
7995 boolean CLEANCACHE = false; // true;
80
- boolean MIPMAP = false; // true;
96
+ boolean MIPMAP = true; // false; // true;
8197 boolean COMPRESSTEXTURE = false;
8298 boolean KOMPACTTEXTURE = false; // true;
8399 boolean RESIZETEXTURE = false;
....@@ -97,10 +113,8 @@
97113
98114 static boolean textureon = true;
99115 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101116 static boolean FULLSCREEN = false;
102117 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104118 static boolean INERTIA = true;
105119 static boolean FAST = false;
106120 static boolean SLOWPOSE = false;
....@@ -108,6 +122,8 @@
108122
109123 static int tickcount = 0; // slow pose issue
110124
125
+static boolean BUTTONLESSWHEEL = false;
126
+static boolean ZOOMBOXMODE = false;
111127 static boolean BOXMODE = false;
112128 static boolean IMAGEFLIP = false;
113129 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +138,7 @@
122138 static boolean OEIL = true;
123139 static boolean OEILONCE = false; // do oeilon then oeiloff
124140 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
141
+static boolean SWITCH = true; // false;
126142 static boolean HANDLES = false; // selection doesn't work!!
127143 static boolean PAINTMODE = false;
128144
....@@ -165,12 +181,41 @@
165181 defaultcaps.setAccumBlueBits(16);
166182 defaultcaps.setAccumAlphaBits(16);
167183 }
168
- static CameraPane theRenderer;
169
-
184
+
185
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
186
+
170187 void SetAsGLRenderer(boolean b)
171188 {
172189 isRenderer = b;
173
- theRenderer = this;
190
+ Globals.theRenderer = this;
191
+ }
192
+
193
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
194
+ {
195
+ super(defaultcaps, null, withcontext?glcontext:null, null);
196
+
197
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
198
+ glcontext = getContext();
199
+
200
+ cameras = new Camera[2];
201
+ targetLookAts = new cVector[2];
202
+
203
+ SetCamera(cam);
204
+
205
+ SetLight(new Camera(new cVector(10, 10, -20)));
206
+
207
+ object = o;
208
+
209
+ setBackground(Color.white);
210
+
211
+ addKeyListener(this);
212
+ addMouseListener(this);
213
+ addMouseMotionListener(this);
214
+ addMouseWheelListener(this);
215
+ //System.out.println("addGLEventListener: " + this);
216
+ addGLEventListener(this);
217
+
218
+// pingthread.start(); // may 2013
174219 }
175220
176221 static boolean AntialiasingEnabled()
....@@ -178,12 +223,53 @@
178223 return CURRENTANTIALIAS > 0;
179224 }
180225
181
- void ClearDepth()
226
+ /// INTERFACE
227
+
228
+ public javax.media.opengl.GL GetGL0()
229
+ {
230
+ return null;
231
+ }
232
+
233
+ public int GenList()
234
+ {
235
+ javax.media.opengl.GL gl = GetGL();
236
+ return gl.glGenLists(1);
237
+ }
238
+
239
+ public void NewList(int id)
240
+ {
241
+ javax.media.opengl.GL gl = GetGL();
242
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
243
+ }
244
+
245
+ public void CallList(int id)
246
+ {
247
+ javax.media.opengl.GL gl = GetGL();
248
+ gl.glCallList(id);
249
+ }
250
+
251
+ public void EndList()
252
+ {
253
+ javax.media.opengl.GL gl = GetGL();
254
+ gl.glEndList();
255
+ }
256
+
257
+ public boolean IsBoxMode()
258
+ {
259
+ return BOXMODE;
260
+ }
261
+
262
+ public boolean IsZoomBoxMode()
263
+ {
264
+ return ZOOMBOXMODE;
265
+ }
266
+
267
+ public void ClearDepth()
182268 {
183269 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184270 }
185271
186
- void DepthTest(boolean depthtest)
272
+ public void DepthTest(boolean depthtest)
187273 {
188274 if (depthtest)
189275 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +277,7 @@
191277 GetGL().glDepthFunc(GL.GL_ALWAYS);
192278 }
193279
194
- void DepthWrite(boolean depthwrite)
280
+ public void DepthWrite(boolean depthwrite)
195281 {
196282 if (depthwrite)
197283 GetGL().glDepthMask(true);
....@@ -199,12 +285,1616 @@
199285 GetGL().glDepthMask(false);
200286 }
201287
202
- void BackFaceCull(boolean bfc)
288
+ public void BackFaceCull(boolean bfc)
203289 {
204290 if (bfc)
205291 GetGL().glEnable(GetGL().GL_CULL_FACE);
206292 else
207293 GetGL().glDisable(GetGL().GL_CULL_FACE);
294
+ }
295
+
296
+ public boolean BackFaceCullMode()
297
+ {
298
+ return this.CULLFACE;
299
+ }
300
+
301
+ public boolean IsAmbientOcclusionOn()
302
+ {
303
+ return this.ambientOcclusion;
304
+ }
305
+
306
+ public boolean IsDebugSelection()
307
+ {
308
+ return DEBUG_SELECTION;
309
+ }
310
+
311
+ public boolean IsFrozen()
312
+ {
313
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
314
+
315
+ return !selectmode && cameracount == 0; // != 0;
316
+ }
317
+
318
+ // Currently in Globals
319
+ public int DrawMode()
320
+ {
321
+ return Globals.DrawMode();
322
+ }
323
+
324
+ public Camera EyeCamera()
325
+ {
326
+ return eyeCamera;
327
+ }
328
+
329
+ public Camera LightCamera()
330
+ {
331
+ return lightCamera;
332
+ }
333
+
334
+ public Camera ManipCamera()
335
+ {
336
+ return manipCamera;
337
+ }
338
+
339
+ public Camera RenderCamera()
340
+ {
341
+ return renderCamera;
342
+ }
343
+
344
+ public Camera[] Cameras()
345
+ {
346
+ return cameras;
347
+ }
348
+
349
+ public void PushMaterial(Object3D obj, boolean selected)
350
+ {
351
+ CameraPane display = this;
352
+ javax.media.opengl.GL gl = display.GetGL();
353
+ cMaterial material = obj.material;
354
+
355
+ if (material != null)
356
+ {
357
+ materialstack[materialdepth] = material;
358
+ selectedstack[materialdepth] = selected;
359
+ cStatic.objectstack[materialdepth++] = obj;
360
+ //System.out.println("material " + material);
361
+ //Applet3D.tracein(this, selected);
362
+ //display.vector2buffer = obj.projectedVertices;
363
+ if (obj instanceof Camera)
364
+ {
365
+ display.options1[0] = material.shift;
366
+ //System.out.println("shift " + material.shift);
367
+ display.options1[1] = material.lightarea;
368
+ display.options1[2] = material.shadowbias;
369
+ display.options1[3] = material.aniso;
370
+ display.options1[4] = material.anisoV;
371
+// System.out.println("display.options1[0] " + display.options1[0]);
372
+// System.out.println("display.options1[1] " + display.options1[1]);
373
+// System.out.println("display.options1[2] " + display.options1[2]);
374
+// System.out.println("display.options1[3] " + display.options1[3]);
375
+// System.out.println("display.options1[4] " + display.options1[4]);
376
+ display.options2[0] = material.opacity;
377
+ display.options2[1] = material.diffuse;
378
+ display.options2[2] = material.factor;
379
+// System.out.println("display.options2[0] " + display.options2[0]);
380
+// System.out.println("display.options2[1] " + display.options2[1]);
381
+// System.out.println("display.options2[2] " + display.options2[2]);
382
+
383
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
384
+// System.out.println("display.options3[0] " + display.options3[0]);
385
+// System.out.println("display.options3[1] " + display.options3[1]);
386
+// System.out.println("display.options3[2] " + display.options3[2]);
387
+ display.options4[0] = material.cameralight/0.2f;
388
+ display.options4[1] = material.subsurface;
389
+ display.options4[2] = material.sheen;
390
+// System.out.println("display.options4[0] " + display.options4[0]);
391
+// System.out.println("display.options4[1] " + display.options4[1]);
392
+// System.out.println("display.options4[2] " + display.options4[2]);
393
+
394
+ // if (display.CURRENTANTIALIAS > 0)
395
+ // display.options3[3] /= 4;
396
+
397
+ /*
398
+ System.out.println("Focus = " + display.options1[0]);
399
+ System.out.println("Aperture = " + display.options1[1]);
400
+ System.out.println("ShadowBlur = " + display.options1[2]);
401
+ System.out.println("Antialiasing = " + display.options1[3]);
402
+ System.out.println("Fog = " + display.options2[0]);
403
+ System.out.println("Intensity = " + display.options2[1]);
404
+ System.out.println("Elevation = " + display.options2[2]);
405
+ /**/
406
+ } else
407
+ {
408
+ DrawMaterial(material, selected, obj.projectedVertices);
409
+ }
410
+ } else
411
+ {
412
+ if (selected && CameraPane.flash)
413
+ {
414
+ display.modelParams4[1] = 100;
415
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
416
+ }
417
+ }
418
+ }
419
+
420
+ public void PushMaterial2(Object3D obj, boolean selected)
421
+ {
422
+ CameraPane display = this;
423
+ cMaterial material = obj.material;
424
+
425
+ if (material != null)
426
+ {
427
+ materialstack[materialdepth] = material;
428
+ selectedstack[materialdepth] = selected;
429
+ cStatic.objectstack[materialdepth++] = obj;
430
+ //System.out.println("material " + material);
431
+ //Applet3D.tracein("selected ", selected);
432
+ //display.vector2buffer = obj.projectedVertices;
433
+ display.DrawMaterial(material, selected, obj.projectedVertices);
434
+ }
435
+ }
436
+
437
+ public void PopMaterial(Object3D obj, boolean selected)
438
+ {
439
+ CameraPane display = this;
440
+ javax.media.opengl.GL gl = display.GetGL();
441
+ cMaterial material = obj.material;
442
+
443
+ //if (parent != null && parent.GetMaterial() != null)
444
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
445
+ if (material != null)
446
+ {
447
+ materialdepth -= 1;
448
+ if (materialdepth > 0)
449
+ {
450
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
451
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
452
+ }
453
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
454
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
455
+ {
456
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
457
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
458
+ }
459
+ }
460
+
461
+ public void PopMaterial2(Object3D obj)
462
+ {
463
+ CameraPane display = this;
464
+ cMaterial material = obj.material;
465
+
466
+ if (material != null)
467
+ {
468
+ materialdepth -= 1;
469
+ if (materialdepth > 0)
470
+ {
471
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
472
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
473
+ }
474
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
475
+ //else
476
+ //material.Draw(display, false);
477
+ }
478
+ }
479
+
480
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
481
+ {
482
+ CameraPane display = this;
483
+
484
+ if (pv.y == -10000 ||
485
+ qv.y == -10000 ||
486
+ rv.y == -10000)
487
+ return;
488
+
489
+// float b = f.nbiterations & 1;
490
+// float g = (f.nbiterations>>1) & 1;
491
+// float r = (f.nbiterations>>2) & 1;
492
+//
493
+// //if (f.weight == 10000)
494
+// //{
495
+// // r = 1; g = b = 0;
496
+// //}
497
+// //else
498
+// //{
499
+// // assert(f.weight < 10000);
500
+// r = g = b = (float)bRep.FaceWeight(f)*100;
501
+// if (r<0)
502
+// assert(r>=0);
503
+// //}
504
+
505
+ javax.media.opengl.GL gl = display.GetGL();
506
+
507
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
508
+
509
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
510
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
511
+ {
512
+ //gl.glBegin(gl.GL_TRIANGLES);
513
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
514
+ // TEST LIVE NORMALS && !obj.dontselect
515
+ ;
516
+ if (!hasnorm)
517
+ {
518
+ // System.out.println("Mesh normal");
519
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
520
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
521
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
522
+ LA.vecNormalize(obj.v2);
523
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
524
+ }
525
+
526
+ // P
527
+ float x = (float)pv.x;
528
+ float y = (float)pv.y;
529
+ float z = (float)pv.z;
530
+
531
+ if (hasnorm)
532
+ {
533
+// if (!pv.norm.normalized())
534
+// assert(pv.norm.normalized());
535
+
536
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
537
+ float nx = (float)pv.norm.x;
538
+ float ny = (float)pv.norm.y;
539
+ float nz = (float)pv.norm.z;
540
+
541
+ x += nx * obj.NORMALPUSH;
542
+ y += ny * obj.NORMALPUSH;
543
+ z += nz * obj.NORMALPUSH;
544
+
545
+ gl.glNormal3f(nx, ny, nz);
546
+ }
547
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
548
+ SetColor(obj, pv);
549
+ //gl.glColor4f(r, g, b, 1);
550
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
551
+ if (obj.flipV)
552
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
553
+ else
554
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
555
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
556
+
557
+ gl.glVertex3f(x, y, z);
558
+
559
+ // Q
560
+ x = (float)qv.x;
561
+ y = (float)qv.y;
562
+ z = (float)qv.z;
563
+
564
+// Print(pv);
565
+ if (hasnorm)
566
+ {
567
+// assert(qv.norm.normalized());
568
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
569
+ float nx = (float)qv.norm.x;
570
+ float ny = (float)qv.norm.y;
571
+ float nz = (float)qv.norm.z;
572
+
573
+ x += nx * obj.NORMALPUSH;
574
+ y += ny * obj.NORMALPUSH;
575
+ z += nz * obj.NORMALPUSH;
576
+
577
+ gl.glNormal3f(nx, ny, nz);
578
+ }
579
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
580
+ // boolean locked = false;
581
+ // float eps = 0.1f;
582
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
583
+
584
+ // int dot = 0; //*/ (int)f.dot;
585
+
586
+ // if ((dot&1) == 0)
587
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
588
+
589
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
590
+ if (obj.flipV)
591
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
592
+ else
593
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
594
+ // else
595
+ // {
596
+ // locked = true;
597
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
598
+ // }
599
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
600
+ SetColor(obj, qv);
601
+
602
+ gl.glVertex3f(x, y, z);
603
+ //gl.glColor4f(r, g, b, 1);
604
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
605
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
606
+// Print(qv);
607
+
608
+ // R
609
+ x = (float)rv.x;
610
+ y = (float)rv.y;
611
+ z = (float)rv.z;
612
+
613
+ if (hasnorm)
614
+ {
615
+// assert(rv.norm.normalized());
616
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
617
+ float nx = (float)rv.norm.x;
618
+ float ny = (float)rv.norm.y;
619
+ float nz = (float)rv.norm.z;
620
+
621
+ x += nx * obj.NORMALPUSH;
622
+ y += ny * obj.NORMALPUSH;
623
+ z += nz * obj.NORMALPUSH;
624
+
625
+ gl.glNormal3f(nx, ny, nz);
626
+ }
627
+
628
+ // if ((dot&4) == 0)
629
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
630
+
631
+ // if (wrap || !locked && (dot&8) != 0)
632
+ if (obj.flipV)
633
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
634
+ else
635
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
636
+ // else
637
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
638
+
639
+ // f.dot = dot;
640
+
641
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
642
+ SetColor(obj, rv);
643
+ //gl.glColor4f(r, g, b, 1);
644
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
645
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
646
+ gl.glVertex3f(x, y, z);
647
+// Print(rv);
648
+ //gl.glEnd();
649
+ }
650
+ else
651
+ {
652
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
653
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
654
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
655
+
656
+ }
657
+
658
+ if (false) // (attributes & WIREFRAME) != 0)
659
+ {
660
+ gl.glDisable(gl.GL_LIGHTING);
661
+
662
+ gl.glBegin(gl.GL_LINE_LOOP);
663
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
664
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
665
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
666
+ gl.glEnd();
667
+
668
+ gl.glEnable(gl.GL_LIGHTING);
669
+ }
670
+ }
671
+
672
+ /**
673
+ * <code>draw</code> renders a <code>TriMesh</code> object including
674
+ * it's normals, colors, textures and vertices.
675
+ *
676
+ * @see Renderer#draw(TriMesh)
677
+ * @param tris
678
+ * the mesh to render.
679
+ */
680
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
681
+ {
682
+ CameraPane display = this;
683
+
684
+ float r = display.modelParams0[0];
685
+ float g = display.modelParams0[1];
686
+ float b = display.modelParams0[2];
687
+ float opacity = display.modelParams5[1];
688
+
689
+ //final GL gl = GLU.getCurrentGL();
690
+ GL gl = display.GetGL(); // getGL();
691
+
692
+ FloatBuffer vertBuf = geo.vertBuf;
693
+
694
+ int v = vertBuf.capacity();
695
+
696
+ int count = 0;
697
+
698
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
699
+ gl.glEnable(gl.GL_CULL_FACE);
700
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
701
+ for (int i=0; i<v/3; i++)
702
+ {
703
+ int index3 = i*3;
704
+
705
+ if (geo.sizeBuf.get(index3+1) == 0)
706
+ continue;
707
+
708
+ count++;
709
+
710
+ int index4 = i*4;
711
+
712
+ float tx = vertBuf.get(index3);
713
+ float ty = vertBuf.get(index3+1);
714
+ float tz = vertBuf.get(index3+2);
715
+
716
+ // if (tx == 0 && ty == 0 && tz == 0)
717
+ // continue;
718
+
719
+ gl.glMatrixMode(gl.GL_TEXTURE);
720
+ gl.glPushMatrix();
721
+
722
+ float[] texmat = geo.texmat;
723
+ texmat[12] = texmat[13] = texmat[14] = i;
724
+
725
+ gl.glMultMatrixf(texmat, 0);
726
+
727
+ gl.glMatrixMode(gl.GL_MODELVIEW);
728
+ gl.glPushMatrix();
729
+
730
+ gl.glTranslatef(tx,ty,tz);
731
+
732
+ if (rotate)
733
+ gl.glRotatef(i, 0, 1, 0);
734
+
735
+ float size = geo.sizeBuf.get(index3) / 100;
736
+ gl.glScalef(size,size,size);
737
+
738
+ float cr = geo.colorBuf.get(index4);
739
+ float cg = geo.colorBuf.get(index4+1);
740
+ float cb = geo.colorBuf.get(index4+2);
741
+ float ca = geo.colorBuf.get(index4+3);
742
+
743
+ display.modelParams0[0] = r * cr;
744
+ display.modelParams0[1] = g * cg;
745
+ display.modelParams0[2] = b * cb;
746
+
747
+ display.modelParams5[1] = opacity * ca;
748
+
749
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
750
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
751
+
752
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
753
+ RandomNode.globalseed2 = RandomNode.globalseed;
754
+
755
+// gl.glColor4f(cr,cg,cb,ca);
756
+ // gl.glScalef(1024/16,1024/16,1024/16);
757
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
758
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
759
+ //gl.glTranslatef(-tx,-ty,-tz);
760
+ gl.glPopMatrix();
761
+
762
+ gl.glMatrixMode(gl.GL_TEXTURE);
763
+ gl.glPopMatrix();
764
+ }
765
+ // gl.glScalef(1024,1024,1024);
766
+ if (!cf)
767
+ gl.glDisable(gl.GL_CULL_FACE);
768
+
769
+ display.modelParams0[0] = r;
770
+ display.modelParams0[1] = g;
771
+ display.modelParams0[2] = b;
772
+
773
+ display.modelParams5[1] = opacity;
774
+
775
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
776
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
777
+
778
+ gl.glMatrixMode(gl.GL_MODELVIEW);
779
+
780
+// System.err.println("total = " + v/3 + "; displayed = " + count);
781
+ if (true)
782
+ return;
783
+
784
+//// if (!tris.predraw(this))
785
+//// {
786
+//// return;
787
+//// }
788
+//// if (Debug.stats)
789
+//// {
790
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
791
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
792
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
793
+//// }
794
+////
795
+//// if (tris.getDisplayListID() != -1)
796
+//// {
797
+//// renderDisplayList(tris);
798
+//// return;
799
+//// }
800
+////
801
+//// if (!generatingDisplayList)
802
+//// {
803
+//// applyStates(tris.states, tris);
804
+//// }
805
+//// if (Debug.stats)
806
+//// {
807
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
808
+//// }
809
+//// boolean transformed = doTransforms(tris);
810
+//
811
+// int glMode = GL.GL_TRIANGLES;
812
+// switch (getMode())
813
+// {
814
+// case Triangles:
815
+// glMode = GL.GL_TRIANGLES;
816
+// break;
817
+// case Strip:
818
+// glMode = GL.GL_TRIANGLE_STRIP;
819
+// break;
820
+// case Fan:
821
+// glMode = GL.GL_TRIANGLE_FAN;
822
+// break;
823
+// }
824
+//
825
+// if (!predrawGeometry(gl))
826
+// {
827
+// // make sure only the necessary indices are sent through on old
828
+// // cards.
829
+// IntBuffer indices = this.getIndexBuffer();
830
+// if (indices == null)
831
+// {
832
+// logger.severe("missing indices on geometry object: " + this.toString());
833
+// } else
834
+// {
835
+// indices.rewind();
836
+// indices.limit(this.getMaxIndex());
837
+//
838
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
839
+//
840
+// indices.clear();
841
+// }
842
+// } else
843
+// {
844
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
845
+// GL.GL_UNSIGNED_INT, 0);
846
+// }
847
+//
848
+//// postdrawGeometry(tris);
849
+//// if (transformed)
850
+//// {
851
+//// undoTransforms(tris);
852
+//// }
853
+////
854
+//// if (Debug.stats)
855
+//// {
856
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
857
+//// }
858
+//// tris.postdraw(this);
859
+ }
860
+
861
+ static Camera localcamera = new Camera();
862
+ static cVector from = new cVector();
863
+ static cVector to = new cVector();
864
+
865
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
866
+ {
867
+ CameraPane cp = this;
868
+
869
+ Camera keep = cp.RenderCamera();
870
+ cp.renderCamera = localcamera;
871
+
872
+ if (br.trimmed)
873
+ {
874
+ float[] colors = new float[br.positions.length / 3];
875
+
876
+ int i3 = 0;
877
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
878
+ {
879
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
880
+ continue;
881
+
882
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
883
+ to.set(br.positions[i3] + br.normals[i3],
884
+ br.positions[i3 + 1] + br.normals[i3 + 1],
885
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
886
+ LA.xformPos(from, transform, from);
887
+ LA.xformPos(to, transform, to); // RIGID ONLY
888
+ localcamera.setAim(from, to);
889
+
890
+ CameraPane.occlusionbuffer.display();
891
+
892
+ if (CameraPane.DEBUG_OCCLUSION)
893
+ cp.display(); // debug
894
+
895
+ colors[i] = cp.vertexOcclusion.r;
896
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
897
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
898
+
899
+ if ((i % 100) == 0 && i != 0)
900
+ {
901
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
902
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
903
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
904
+ }
905
+ }
906
+
907
+ br.colors = colors;
908
+ }
909
+ else
910
+ {
911
+ for (int i = 0; i < br.VertexCount(); i++)
912
+ {
913
+ Vertex v = br.GetVertex(i);
914
+
915
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
916
+ continue;
917
+
918
+ from.set(v.x, v.y, v.z);
919
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
920
+ LA.xformPos(from, transform, from);
921
+ LA.xformPos(to, transform, to); // RIGID ONLY
922
+ localcamera.setAim(from, to);
923
+
924
+ CameraPane.occlusionbuffer.display();
925
+
926
+ if (CameraPane.DEBUG_OCCLUSION)
927
+ cp.display(); // debug
928
+
929
+ v.AO = cp.vertexOcclusion.r;
930
+
931
+ if ((i % 100) == 0 && i != 0)
932
+ {
933
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
934
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
935
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
936
+ }
937
+ }
938
+ }
939
+
940
+ //System.out.println("done.");
941
+
942
+ cp.renderCamera = keep;
943
+ }
944
+
945
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
946
+ {
947
+ CameraPane display = this;
948
+ pointFlow.CreateHT();
949
+
950
+ float r = display.modelParams0[0];
951
+ float g = display.modelParams0[1];
952
+ float b = display.modelParams0[2];
953
+ float opacity = display.modelParams5[1];
954
+
955
+ //final GL gl = GLU.getCurrentGL();
956
+ GL gl = display.GetGL(); // getGL();
957
+
958
+ int s = pointFlow.points.size();
959
+
960
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
961
+ gl.glEnable(gl.GL_CULL_FACE);
962
+
963
+ for (int i=s; --i>=0;)
964
+ //for (int i=0; i<s; i++)
965
+ {
966
+ cVector v = pointFlow.points.get(i);
967
+
968
+ double mindist = Double.MAX_VALUE;
969
+
970
+ double size = pointFlow.minimumSize;
971
+
972
+ double distancenext = 0;
973
+
974
+ if (i > 0)
975
+ {
976
+ cVector w = pointFlow.points.get(i-1);
977
+
978
+ double dist = w.distance(v);
979
+
980
+ distancenext = dist;
981
+
982
+ if (mindist > dist)
983
+ {
984
+ mindist = dist;
985
+ size = mindist*pointFlow.resizefactor;
986
+ }
987
+ }
988
+
989
+ if (i < s-1)
990
+ {
991
+ cVector w = pointFlow.points.get(i+1);
992
+
993
+ double dist = w.distance(v);
994
+
995
+ if (mindist > dist)
996
+ {
997
+ mindist = dist;
998
+ size = mindist*pointFlow.resizefactor;
999
+ }
1000
+ }
1001
+
1002
+ if (size < pointFlow.minimumSize)
1003
+ size = pointFlow.minimumSize;
1004
+ if (size > pointFlow.maximumSize)
1005
+ size = pointFlow.maximumSize;
1006
+
1007
+ double tx = v.x;
1008
+ double ty = v.y;
1009
+ double tz = v.z;
1010
+
1011
+ // if (tx == 0 && ty == 0 && tz == 0)
1012
+ // continue;
1013
+
1014
+ gl.glMatrixMode(gl.GL_TEXTURE);
1015
+ gl.glPushMatrix();
1016
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1017
+
1018
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1019
+
1020
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1021
+ gl.glPushMatrix();
1022
+
1023
+ gl.glTranslated(tx,ty,tz);
1024
+
1025
+ gl.glScaled(size,size,size);
1026
+
1027
+// float cr = colorBuf.get(index4);
1028
+// float cg = colorBuf.get(index4+1);
1029
+// float cb = colorBuf.get(index4+2);
1030
+// float ca = colorBuf.get(index4+3);
1031
+//
1032
+// display.modelParams0[0] = r * cr;
1033
+// display.modelParams0[1] = g * cg;
1034
+// display.modelParams0[2] = b * cb;
1035
+//
1036
+// display.modelParams5[1] = opacity * ca;
1037
+//
1038
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1039
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1040
+//
1041
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1042
+// RandomNode.globalseed2 = RandomNode.globalseed;
1043
+//
1044
+//// gl.glColor4f(cr,cg,cb,ca);
1045
+// // gl.glScalef(1024/16,1024/16,1024/16);
1046
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1047
+
1048
+ gl.glPopMatrix();
1049
+
1050
+ double step = size/4; //
1051
+
1052
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1053
+ continue;
1054
+
1055
+ int nbsteps = (int)(distancenext/step);
1056
+
1057
+ step = distancenext/nbsteps;
1058
+
1059
+ cVector next = pointFlow.points.get(i-1);
1060
+
1061
+ tmp.set(next);
1062
+ tmp.sub(v);
1063
+ tmp.normalize();
1064
+ tmp.mul(step);
1065
+
1066
+ // calculate next size
1067
+ mindist = Double.MAX_VALUE;
1068
+
1069
+ double nextsize = pointFlow.minimumSize;
1070
+
1071
+ if (i > 1)
1072
+ {
1073
+ cVector w = pointFlow.points.get(i-2);
1074
+
1075
+ double dist = w.distance(next);
1076
+
1077
+ if (mindist > dist)
1078
+ {
1079
+ mindist = dist;
1080
+ nextsize = mindist*pointFlow.resizefactor;
1081
+ }
1082
+ }
1083
+
1084
+ double dist = v.distance(next);
1085
+
1086
+ if (mindist > dist)
1087
+ {
1088
+ mindist = dist;
1089
+ nextsize = mindist*pointFlow.resizefactor;
1090
+ }
1091
+
1092
+ if (nextsize < pointFlow.minimumSize)
1093
+ nextsize = pointFlow.minimumSize;
1094
+ if (nextsize > pointFlow.maximumSize)
1095
+ nextsize = pointFlow.maximumSize;
1096
+ //
1097
+
1098
+ double count = 0;
1099
+
1100
+ while (distancenext > 0.000000001) // step
1101
+ {
1102
+ gl.glPushMatrix();
1103
+
1104
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1105
+
1106
+ double K = count/nbsteps;
1107
+
1108
+ double intersize = K*nextsize + (1-K)*size;
1109
+
1110
+ gl.glScaled(intersize,intersize,intersize);
1111
+
1112
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1113
+
1114
+ count++;
1115
+
1116
+ distancenext -= step;
1117
+
1118
+ gl.glPopMatrix();
1119
+ }
1120
+
1121
+ if (count != nbsteps)
1122
+ assert(count == nbsteps);
1123
+
1124
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1125
+ //gl.glTranslatef(-tx,-ty,-tz);
1126
+
1127
+ gl.glMatrixMode(gl.GL_TEXTURE);
1128
+ gl.glPopMatrix();
1129
+ }
1130
+
1131
+ if (!cf)
1132
+ gl.glDisable(gl.GL_CULL_FACE);
1133
+
1134
+// display.modelParams0[0] = r;
1135
+// display.modelParams0[1] = g;
1136
+// display.modelParams0[2] = b;
1137
+//
1138
+// display.modelParams5[1] = opacity;
1139
+//
1140
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1141
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1142
+
1143
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1144
+ }
1145
+
1146
+ public void DrawBox(cVector min, cVector max)
1147
+ {
1148
+ javax.media.opengl.GL gl = GetGL();
1149
+ gl.glBegin(gl.GL_LINES);
1150
+
1151
+ gl.glVertex3d(min.x, min.y, min.z);
1152
+ gl.glVertex3d(min.x, min.y, max.z);
1153
+ gl.glVertex3d(min.x, min.y, min.z);
1154
+ gl.glVertex3d(min.x, max.y, min.z);
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(max.x, min.y, min.z);
1157
+
1158
+ gl.glVertex3d(max.x, max.y, max.z);
1159
+ gl.glVertex3d(min.x, max.y, max.z);
1160
+ gl.glVertex3d(max.x, max.y, max.z);
1161
+ gl.glVertex3d(max.x, min.y, max.z);
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(max.x, max.y, min.z);
1164
+
1165
+ gl.glEnd();
1166
+ }
1167
+
1168
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1169
+ {
1170
+ int[] strips = bRep.getRawIndices();
1171
+
1172
+ javax.media.opengl.GL gl = GetGL();
1173
+
1174
+ // TRIANGLE STRIP ARRAY
1175
+ if (bRep.trimmed)
1176
+ {
1177
+ float[] v = bRep.getRawVertices();
1178
+ float[] n = bRep.getRawNormals();
1179
+ float[] c = bRep.getRawColors();
1180
+ float[] uv = bRep.getRawUVMap();
1181
+
1182
+ int count2 = 0;
1183
+ int count3 = 0;
1184
+
1185
+ if (n.length > 0)
1186
+ {
1187
+ for (int i = 0; i < strips.length; i++)
1188
+ {
1189
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1190
+
1191
+ /*
1192
+ boolean locked = false;
1193
+ float eps = 0.1f;
1194
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1195
+
1196
+ int dot = 0;
1197
+
1198
+ if ((dot&1) == 0)
1199
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1200
+
1201
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1202
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1203
+ else
1204
+ {
1205
+ locked = true;
1206
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1207
+ }
1208
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1209
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1210
+ if (hasnorm)
1211
+ {
1212
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1213
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1214
+ }
1215
+
1216
+ if ((dot&4) == 0)
1217
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1218
+
1219
+ if (wrap || !locked && (dot&8) != 0)
1220
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1221
+ else
1222
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1223
+
1224
+ f.dot = dot;
1225
+ */
1226
+
1227
+ if (!selectmode)
1228
+ {
1229
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1230
+ {
1231
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1232
+ } else
1233
+ {
1234
+ gl.glNormal3f(0, 0, 1);
1235
+ }
1236
+
1237
+ if (c != null)
1238
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1239
+ {
1240
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1241
+ }
1242
+ }
1243
+
1244
+ if (flipV)
1245
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1246
+ else
1247
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1248
+
1249
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1250
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1251
+
1252
+ count2 += 2;
1253
+ count3 += 3;
1254
+ if (!selectmode)
1255
+ {
1256
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1257
+ {
1258
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1259
+ } else
1260
+ {
1261
+ gl.glNormal3f(0, 0, 1);
1262
+ }
1263
+ if (c != null)
1264
+ {
1265
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1266
+ }
1267
+ }
1268
+
1269
+ if (flipV)
1270
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1271
+ else
1272
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1273
+
1274
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1275
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1276
+
1277
+ count2 += 2;
1278
+ count3 += 3;
1279
+ for (int j = 0; j < strips[i] - 2; j++)
1280
+ {
1281
+ //gl.glTexCoord2d(...);
1282
+ if (!selectmode)
1283
+ {
1284
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1285
+ {
1286
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1287
+ } else
1288
+ {
1289
+ gl.glNormal3f(0, 0, 1);
1290
+ }
1291
+ if (c != null)
1292
+ {
1293
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1294
+ }
1295
+ }
1296
+
1297
+ if (flipV)
1298
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1299
+ else
1300
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1301
+
1302
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1303
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1304
+
1305
+ count2 += 2;
1306
+ count3 += 3;
1307
+ }
1308
+
1309
+ gl.glEnd();
1310
+ }
1311
+ }
1312
+
1313
+ assert count3 == v.length;
1314
+ }
1315
+ else // !trimmed
1316
+ {
1317
+ int count = 0;
1318
+ for (int i = 0; i < strips.length; i++)
1319
+ {
1320
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1321
+
1322
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1323
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1324
+
1325
+ drawVertex(gl, p, flipV, selectmode);
1326
+ drawVertex(gl, q, flipV, selectmode);
1327
+
1328
+ for (int j = 0; j < strips[i] - 2; j++)
1329
+ {
1330
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1331
+
1332
+ // if (j%2 == 0)
1333
+ // drawFace(p, q, r, display, null);
1334
+ // else
1335
+ // drawFace(p, r, q, display, null);
1336
+
1337
+ // p = q;
1338
+ // q = r;
1339
+ drawVertex(gl, r, flipV, selectmode);
1340
+ }
1341
+
1342
+ gl.glEnd();
1343
+ }
1344
+ }
1345
+ }
1346
+
1347
+ static cSpring.Point3D temp = new cSpring.Point3D();
1348
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1349
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1350
+
1351
+ public void DrawDynamicMesh(cMesh mesh)
1352
+ {
1353
+ GL gl = GetGL(); // getGL();
1354
+
1355
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1356
+
1357
+ gl.glDisable(gl.GL_LIGHTING);
1358
+
1359
+ gl.glLineWidth(1);
1360
+ gl.glColor3f(1,1,1);
1361
+ gl.glBegin(gl.GL_LINES);
1362
+ double scale = 0;
1363
+ int count = 0;
1364
+ for (int s=0; s<Phys.allSprings.size(); s++)
1365
+ {
1366
+ cSpring.Spring spring = Phys.allSprings.get(s);
1367
+ if(s == 0)
1368
+ {
1369
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1370
+ }
1371
+ if (mesh.showsprings)
1372
+ {
1373
+ temp.set(spring.a.position);
1374
+ temp.add(spring.b.position);
1375
+ temp.mul(0.5);
1376
+ temp2.set(spring.a.position);
1377
+ temp2.sub(spring.b.position);
1378
+ temp2.mul(spring.restLength/2);
1379
+ temp.sub(temp2);
1380
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1381
+ temp.add(temp2);
1382
+ temp.add(temp2);
1383
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1384
+ }
1385
+
1386
+ if (spring.isHandle)
1387
+ continue;
1388
+
1389
+ //if (scale < spring.restLength)
1390
+ scale += spring.restLength;
1391
+ count++;
1392
+ }
1393
+ gl.glEnd();
1394
+
1395
+ if (count == 0)
1396
+ scale = 0.01;
1397
+ else
1398
+ scale /= count * 3;
1399
+
1400
+ //scale = 0.25;
1401
+
1402
+ if (mesh.ShowInfo())
1403
+ {
1404
+ gl.glLineWidth(4);
1405
+ for (int s=0; s<Phys.allNodes.size(); s++)
1406
+ {
1407
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1408
+ if (node.mass == 0)
1409
+ continue;
1410
+
1411
+ int i = node.springs==null?-1:node.springs.size();
1412
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1413
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1414
+ //temp.normalize();
1415
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1416
+ gl.glBegin(gl.GL_LINES);
1417
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1418
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1419
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1420
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1421
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1422
+ gl.glEnd();
1423
+ }
1424
+
1425
+ gl.glLineWidth(8);
1426
+ for (int s=0; s<Phys.allNodes.size(); s++)
1427
+ {
1428
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1429
+
1430
+ if (node.springs != null)
1431
+ {
1432
+ for (int i=0; i<node.springs.size(); i+=1)
1433
+ {
1434
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1435
+
1436
+ int c = i+1;
1437
+ // c = node.springs.get(i).nbcopies;
1438
+
1439
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1440
+ gl.glBegin(gl.GL_LINES);
1441
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1442
+ 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);
1443
+ gl.glEnd();
1444
+ }
1445
+ }
1446
+ }
1447
+
1448
+ gl.glLineWidth(1);
1449
+ }
1450
+
1451
+ gl.glEnable(gl.GL_LIGHTING);
1452
+ }
1453
+
1454
+ /// INTERFACE
1455
+
1456
+ public void StartTriangles()
1457
+ {
1458
+ javax.media.opengl.GL gl = GetGL();
1459
+ gl.glBegin(gl.GL_TRIANGLES);
1460
+ }
1461
+
1462
+ public void EndTriangles()
1463
+ {
1464
+ GetGL().glEnd();
1465
+ }
1466
+
1467
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1468
+ {
1469
+ if (!selectmode)
1470
+ {
1471
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1472
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1473
+
1474
+ if (flipV)
1475
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1476
+ else
1477
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1478
+ }
1479
+
1480
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1481
+ }
1482
+
1483
+ void SetColor(Object3D obj, Vertex p0)
1484
+ {
1485
+ CameraPane display = this;
1486
+ BoundaryRep bRep = obj.bRep;
1487
+
1488
+ if (RENDERPROGRAM == 0)
1489
+ {
1490
+ float r = 0;
1491
+ if (bRep != null)
1492
+ {
1493
+ if (bRep.stripified)
1494
+ {
1495
+ r = 1;
1496
+ }
1497
+ }
1498
+ float g = 0;
1499
+ if (bRep != null)
1500
+ {
1501
+ if (bRep.trimmed)
1502
+ {
1503
+ g = 1;
1504
+ }
1505
+ }
1506
+ float b = 0;
1507
+ if (obj.support != null && obj.link2master)
1508
+ {
1509
+ b = 1;
1510
+ }
1511
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1512
+ return;
1513
+ }
1514
+
1515
+ if (display.DrawMode() != CameraPane.SHADOW)
1516
+ return;
1517
+
1518
+ javax.media.opengl.GL gl = display.GetGL();
1519
+// if (true) return;
1520
+// float ao = p.AO;
1521
+//
1522
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1523
+// // ao = 1;
1524
+//
1525
+// gl.glColor4f(ao, ao, ao, 1);
1526
+
1527
+// CameraPane.selectedpoint.
1528
+// getAverage(cStatic.point1, true);
1529
+ if (CameraPane.pointflow == null) // !random) // live)
1530
+ {
1531
+ return;
1532
+ }
1533
+
1534
+ cStatic.point1.set(0,0,0);
1535
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1536
+
1537
+ cStatic.point1.sub(p0);
1538
+
1539
+
1540
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1541
+// {
1542
+// return;
1543
+// }
1544
+
1545
+ //if (true)
1546
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1547
+ {
1548
+ return;
1549
+ }
1550
+
1551
+ float[] colorV = new float[3];
1552
+
1553
+ if (false) // marked)
1554
+ {
1555
+ // debug rigging weights
1556
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1557
+ {
1558
+ float weight = p0.weights[object] / p0.totalweight;
1559
+
1560
+ // if (weight < 0.1)
1561
+ // {
1562
+ // assert(weight == 0);
1563
+ // continue;
1564
+ // }
1565
+
1566
+ if (p0.vertexlinks[object] == -1)
1567
+ continue;
1568
+
1569
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1570
+
1571
+ int color = //1 << object; //
1572
+ //p.vertexlinks.length;
1573
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1574
+ colorV[2] += (color & 1) * weight;
1575
+ colorV[1] += ((color & 2) >> 1) * weight;
1576
+ colorV[0] += ((color & 4) >> 2) * weight;
1577
+ }
1578
+ }
1579
+ else
1580
+ {
1581
+ if (obj.drawingstarted)
1582
+ {
1583
+ // find next point
1584
+ if (bRep.GetVertex(0).faceindices == null)
1585
+ {
1586
+ bRep.InitFaceIndices();
1587
+ }
1588
+
1589
+ double ymin = p0.y;
1590
+
1591
+ Vertex newp = p0;
1592
+
1593
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1594
+ {
1595
+ int fi = p0.faceindices[fii];
1596
+
1597
+ if (fi == -1)
1598
+ break;
1599
+
1600
+ Face f = bRep.GetFace(fi);
1601
+
1602
+ Vertex p = bRep.GetVertex(f.p);
1603
+ Vertex q = bRep.GetVertex(f.q);
1604
+ Vertex r = bRep.GetVertex(f.r);
1605
+
1606
+ int swap = (int)(Math.random()*3);
1607
+
1608
+// for (int s=swap; --s>=0;)
1609
+// {
1610
+// Vertex t = p;
1611
+// p = q;
1612
+// q = r;
1613
+// r = t;
1614
+// }
1615
+ if (ymin > p.y)
1616
+ {
1617
+ ymin = p.y;
1618
+ newp = p;
1619
+// break;
1620
+ }
1621
+ if (ymin > q.y)
1622
+ {
1623
+ ymin = q.y;
1624
+ newp = q;
1625
+// break;
1626
+ }
1627
+ if (ymin > r.y)
1628
+ {
1629
+ ymin = r.y;
1630
+ newp = r;
1631
+// break;
1632
+ }
1633
+ }
1634
+
1635
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1636
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1637
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1638
+
1639
+ obj.drawingstarted = false;
1640
+
1641
+ // return;
1642
+ }
1643
+
1644
+ if (false) // CameraPane.DRAW
1645
+ {
1646
+ p0.AO = colorV[0] = 2;
1647
+ colorV[1] = 2;
1648
+ colorV[2] = 2;
1649
+ }
1650
+
1651
+ CameraPane.pointflow.add(p0);
1652
+ CameraPane.pointflow.Touch();
1653
+ }
1654
+
1655
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1656
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1657
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1658
+ }
1659
+
1660
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1661
+ {
1662
+ CameraPane display = this;
1663
+ //new Exception().printStackTrace();
1664
+
1665
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1666
+ {
1667
+ return;
1668
+ }
1669
+
1670
+ javax.media.opengl.GL gl = display.GetGL();
1671
+
1672
+ //Color col = Color.getHSBColor(color,modulation,1);
1673
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1674
+ if (!material.multiply)
1675
+ {
1676
+ display.color = material.color;
1677
+ display.saturation = material.modulation;
1678
+ }
1679
+ else
1680
+ {
1681
+ display.color *= material.color*2;
1682
+ display.saturation *= material.modulation*2;
1683
+ }
1684
+
1685
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1686
+
1687
+ float[] colorV = Grafreed.colorV;
1688
+
1689
+ /**/
1690
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1691
+ {
1692
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1693
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1694
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1695
+ colorV[3] = 1; // material.opacity;
1696
+
1697
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1698
+ //System.out.println("Opacity = " + opacity);
1699
+
1700
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1701
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1702
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1703
+
1704
+ float amb = material.ambient;
1705
+ if (amb < material.cameralight)
1706
+ {
1707
+ amb = material.cameralight;
1708
+ }
1709
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1710
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1711
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1712
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1713
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1714
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1715
+
1716
+ /**/
1717
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1718
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1719
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1720
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1721
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1722
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1723
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1724
+ //System.out.println("shininess = " + colorV[0]);
1725
+ if (colorV[0] > 128)
1726
+ {
1727
+ colorV[0] = 128;
1728
+ }
1729
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1730
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1731
+ /**/
1732
+ }
1733
+ /**/
1734
+
1735
+ //selected = false;
1736
+ selected = selected && display.flash;
1737
+
1738
+ //display.modelParams0[0] = 0; // pigment.r;
1739
+ //display.modelParams0[1] = 0; // pigment.g;
1740
+ //display.modelParams0[2] = 0; // pigment.b;
1741
+ if (!material.multiply)
1742
+ {
1743
+ display.modelParams0[3] = material.metalness;
1744
+ display.modelParams1[0] = material.diffuse;
1745
+ display.modelParams1[1] = material.specular;
1746
+ display.modelParams1[2] = 1 / material.shininess;
1747
+ display.modelParams1[3] = material.shift;
1748
+ display.modelParams2[0] = material.ambient;
1749
+ display.modelParams2[1] = material.lightarea;
1750
+ //System.out.println("light area = " + lightarea);
1751
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1752
+ display.modelParams2[3] = material.velvet;
1753
+ display.modelParams3[0] = material.sheen;
1754
+ display.modelParams3[1] = material.subsurface;
1755
+ display.modelParams3[2] = material.bump; // backlit
1756
+ display.modelParams3[3] = material.aniso;
1757
+ display.modelParams4[0] = material.anisoV;
1758
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1759
+ //System.out.println("selected = " + selected);
1760
+ display.modelParams4[2] = material.diffuseness;
1761
+ display.modelParams4[3] = material.shadow;
1762
+ display.modelParams5[0] = material.texture;
1763
+ display.modelParams5[1] = material.opacity;
1764
+ display.modelParams5[2] = material.fakedepth;
1765
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1766
+ }
1767
+ else
1768
+ {
1769
+ display.modelParams0[3] *= material.metalness*2;
1770
+ display.modelParams1[0] *= material.diffuse*2;
1771
+ display.modelParams1[1] *= material.specular*2;
1772
+ display.modelParams1[2] *= material.shininess*2;
1773
+ display.modelParams1[3] *= material.shift*2;
1774
+ display.modelParams2[0] *= material.ambient*2;
1775
+ display.modelParams2[1] *= material.lightarea*2;
1776
+ display.modelParams2[2] *= material.factor*2;
1777
+ display.modelParams2[3] *= material.velvet*2;
1778
+ display.modelParams3[0] *= material.sheen*2;
1779
+ display.modelParams3[1] *= material.subsurface*2;
1780
+ display.modelParams3[2] *= material.bump*2;
1781
+ display.modelParams3[3] *= material.aniso*2;
1782
+ display.modelParams4[0] *= material.anisoV*2;
1783
+ display.modelParams4[1] *= material.cameralight*2;
1784
+ //System.out.println("selected = " + selected);
1785
+ display.modelParams4[2] *= material.diffuseness*2;
1786
+ display.modelParams4[3] *= material.shadow*2;
1787
+ display.modelParams5[0] *= material.texture*2;
1788
+ display.modelParams5[1] *= material.opacity*2;
1789
+ display.modelParams5[2] *= material.fakedepth*2;
1790
+ display.modelParams5[3] *= material.shadowbias*2;
1791
+ }
1792
+
1793
+ display.modelParams6[0] = 0;
1794
+ display.modelParams6[1] = 0;
1795
+ display.modelParams6[2] = 0;
1796
+ display.modelParams6[3] = 0;
1797
+
1798
+ display.modelParams7[0] = 0;
1799
+ display.modelParams7[1] = 1000;
1800
+ display.modelParams7[2] = 0;
1801
+ display.modelParams7[3] = 0;
1802
+
1803
+ //display.modelParams6[0] = 100; // criss de bug de bump
1804
+
1805
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1806
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1807
+ {
1808
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1809
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1810
+ if (extparams.length > 1)
1811
+ {
1812
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1813
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1814
+ if (extparams.length > 2)
1815
+ {
1816
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1817
+ float x = extparams[2].y / 1000.0f;
1818
+ //if (x == 0)
1819
+ // x = 1f;
1820
+ 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
1821
+ if (extparams[2].y > 0)
1822
+ {
1823
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1824
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1825
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1826
+ }
1827
+ }
1828
+ }
1829
+ }
1830
+
1831
+ //if (display.modelParams6[2] != 0)
1832
+ /*
1833
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1834
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1835
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1836
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1837
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1838
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1839
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1840
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1841
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1842
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1843
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1844
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1845
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1846
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1847
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1848
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1849
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1850
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1851
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1852
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1853
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1854
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1855
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1856
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1857
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1858
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1859
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1860
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1861
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1862
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1863
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1864
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1865
+ /**/
1866
+ //assert (display.modelParams6[2] == 0);
1867
+
1868
+ //System.out.println("noise power = " + display.modelParams7[0]);
1869
+ //System.out.println("shadowbias = " + shadowbias);
1870
+
1871
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1872
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1873
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1874
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1875
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1876
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1877
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1878
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1879
+
1880
+ int mode = display.FP_SHADER;
1881
+
1882
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1883
+ {
1884
+ mode |= display.FP_ANISO;
1885
+ }
1886
+
1887
+ display.EnableProgram(mode);
1888
+
1889
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1890
+
1891
+ if (!material.multiply)
1892
+ {
1893
+ if (Globals.drawMode == CameraPane.SHADOW)
1894
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1895
+ else
1896
+ gl.glDepthMask(material.opacity >= 0.99);
1897
+ }
2081898 }
2091899
2101900 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1915,7 @@
2251915 currentGL.glMultMatrixd(model, 0);
2261916 }
2271917
228
- void PushMatrix(double[][] matrix, int count)
1918
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291919 {
2301920 matrixdepth++;
2311921 // GrafreeD.tracein(matrix);
....@@ -254,7 +1944,7 @@
2541944 void PushMatrix(double[][] matrix)
2551945 {
2561946 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1947
+ PushMatrix(matrix, 1);
2581948 }
2591949
2601950 void PushMatrix()
....@@ -270,7 +1960,7 @@
2701960
2711961 double[][] tmpmat = new double[4][4];
2721962
273
- void PopMatrix(double[][] inverse)
1963
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741964 {
2751965 --matrixdepth;
2761966
....@@ -310,7 +2000,7 @@
3102000 PushTextureMatrix(matrix, 1);
3112001 }
3122002
313
- void PushTextureMatrix(double[][] matrix, int count)
2003
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142004 {
3152005 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162006
....@@ -324,7 +2014,7 @@
3242014 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252015 }
3262016
327
- void PopTextureMatrix(double[][] inverse)
2017
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282018 {
3292019 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302020 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2041,15 @@
3512041
3522042 static int camerachangeframe;
3532043
354
- boolean SetCamera(Camera cam)
2044
+ public boolean SetCamera(Camera cam)
3552045 {
3562046 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572047 // return false;
3582048
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2049
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602050 {
3612051 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2052
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632053 {
3642054 // refuse the camera change
3652055 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2057,7 @@
3672057 }
3682058 }
3692059
370
- camerachangeframe = framecount;
2060
+ camerachangeframe = Globals.framecount;
3712061
3722062 cam.hAspect = -1; // Read only
3732063
....@@ -398,7 +2088,7 @@
3982088 {
3992089 //System.err.println("Oeil on");
4002090 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2091
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022092 // object.editWindow.ScreenFit(trackedobject);
4032093 //pingthread.StepToTarget(true);
4042094 }
....@@ -407,8 +2097,8 @@
4072097 {
4082098 //System.err.println("Oeil on");
4092099 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2100
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2101
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122102 //pingthread.StepToTarget(true);
4132103 }
4142104
....@@ -471,39 +2161,12 @@
4712161 {
4722162 frozen ^= true;
4732163 // Weird...
474
- lighttouched = true;
2164
+ Globals.lighttouched = true;
4752165 }
4762166
4772167 void ToggleDL()
4782168 {
4792169 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GrafreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072170 }
5082171
5092172 void ToggleFullScreen()
....@@ -513,12 +2176,7 @@
5132176
5142177 void ToggleCrowd()
5152178 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2179
+ Globals.CROWD ^= true;
5222180 }
5232181
5242182 void ToggleLocal()
....@@ -526,62 +2184,89 @@
5262184 LOCALTRANSFORM ^= true;
5272185 }
5282186
529
- void ToggleFast()
2187
+ public void ToggleTexture()
2188
+ {
2189
+ textureon ^= true;
2190
+ }
2191
+
2192
+ public void ToggleLive()
2193
+ {
2194
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2195
+
2196
+ System.err.println("LIVE = " + Globals.isLIVE());
2197
+
2198
+ if (!Globals.isLIVE()) // save sound
2199
+ Grafreed.savesound = true; // wav.save();
2200
+ // else
2201
+ repaint(); // start loop // may 2013
2202
+ }
2203
+
2204
+ public void ToggleSupport()
2205
+ {
2206
+ SUPPORT ^= true;
2207
+ }
2208
+
2209
+ public void ToggleAbort()
2210
+ {
2211
+ ABORTMODE ^= true;
2212
+ }
2213
+
2214
+ public void ToggleInertia()
2215
+ {
2216
+ INERTIA ^= true;
2217
+ }
2218
+
2219
+ public void ToggleFast()
5302220 {
5312221 FAST ^= true;
5322222 }
5332223
534
- void ToggleSlowPose()
2224
+ public void ToggleSlowPose()
5352225 {
5362226 SLOWPOSE ^= true;
5372227 }
5382228
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2229
+ public void ToggleBoxMode()
5452230 {
5462231 BOXMODE ^= true;
5472232 }
5482233
549
- void ToggleSmoothFocus()
2234
+ public void ToggleZoomBoxMode()
2235
+ {
2236
+ ZOOMBOXMODE ^= true;
2237
+ }
2238
+
2239
+ public void ToggleSmoothFocus()
5502240 {
5512241 SMOOTHFOCUS ^= true;
5522242 }
5532243
554
- void ToggleImageFlip()
2244
+ public void ToggleImageFlip()
5552245 {
5562246 IMAGEFLIP ^= true;
5572247 }
5582248
559
- void ToggleSpeakerMocap()
2249
+ public void ToggleSpeakerMocap()
5602250 {
5612251 SPEAKERMOCAP ^= true;
5622252 }
5632253
564
- void ToggleSpeakerCamera()
2254
+ public void ToggleSpeakerCamera()
5652255 {
5662256 SPEAKERCAMERA ^= true;
5672257 }
5682258
569
- void ToggleSpeakerFocus()
2259
+ public void ToggleSpeakerFocus()
5702260 {
5712261 SPEAKERFOCUS ^= true;
5722262 }
5732263
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2264
+ public void ToggleFrustum()
5802265 {
5812266 FRUSTUM ^= true;
5822267 }
5832268
584
- void ToggleTrack()
2269
+ public void ToggleTrack()
5852270 {
5862271 TRACK ^= true;
5872272 if (TRACK)
....@@ -600,25 +2285,35 @@
6002285 repaint();
6012286 }
6022287
603
- void ToggleTrackOnce()
2288
+ public void ToggleTrackOnce()
6042289 {
6052290 TRACKONCE ^= true;
6062291 }
6072292
608
- void ToggleShadowTrack()
2293
+ public void ToggleShadowTrack()
6092294 {
6102295 SHADOWTRACK ^= true;
6112296 repaint();
6122297 }
6132298
614
- void ToggleOeil()
2299
+ public void ToggleOeil()
6152300 {
6162301 OEIL ^= true;
6172302 }
6182303
619
- void ToggleOeilOnce()
2304
+ public void ToggleOeilOnce()
6202305 {
6212306 OEILONCE ^= true;
2307
+ }
2308
+
2309
+ void ToggleFootContact()
2310
+ {
2311
+ FOOTCONTACT ^= true;
2312
+ }
2313
+
2314
+ void ToggleDebug()
2315
+ {
2316
+ Globals.DEBUG ^= true;
6222317 }
6232318
6242319 void ToggleLookAt()
....@@ -626,9 +2321,9 @@
6262321 LOOKAT ^= true;
6272322 }
6282323
629
- void ToggleRandom()
2324
+ void ToggleSwitch()
6302325 {
631
- RANDOM ^= true;
2326
+ SWITCH ^= true;
6322327 }
6332328
6342329 void ToggleHandles()
....@@ -636,10 +2331,17 @@
6362331 HANDLES ^= true;
6372332 }
6382333
2334
+ Object3D paintFolder;
2335
+
6392336 void TogglePaint()
6402337 {
6412338 PAINTMODE ^= true;
6422339 paintcount = 0;
2340
+
2341
+ if (PAINTMODE)
2342
+ {
2343
+ paintFolder = GetFolder();
2344
+ }
6432345 }
6442346
6452347 void SwapCamera(int a, int b)
....@@ -672,34 +2374,6 @@
6722374 //assert (cam.hAspect == 0);
6732375 cam.hAspect = 0;
6742376 lightCamera = cam;
675
- }
676
-
677
- CameraPane(Object3D o, Camera cam, boolean withcontext)
678
- {
679
- super(defaultcaps, null, withcontext?glcontext:null, null);
680
-
681
- //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
682
- glcontext = getContext();
683
-
684
- cameras = new Camera[2];
685
- targetLookAts = new cVector[2];
686
-
687
- SetCamera(cam);
688
-
689
- SetLight(new Camera(new cVector(10, 10, -20)));
690
-
691
- object = o;
692
-
693
- setBackground(Color.white);
694
-
695
- addKeyListener(this);
696
- addMouseListener(this);
697
- addMouseMotionListener(this);
698
- addMouseWheelListener(this);
699
- //System.out.println("addGLEventListener: " + this);
700
- addGLEventListener(this);
701
-
702
-// pingthread.start(); // may 2013
7032377 }
7042378
7052379 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2433,26 @@
7592433
7602434 GL currentGL;
7612435
762
- GL GetGL()
2436
+ public GL GetGL() // INTERFACE
7632437 {
7642438 return currentGL;
7652439 }
766
-
2440
+
2441
+ static private BufferedImage CreateBim(TextureData texturedata)
2442
+ {
2443
+ Grafreed.Assert(texturedata != null);
2444
+
2445
+ int width = texturedata.getWidth();
2446
+ int height = texturedata.getHeight();
2447
+
2448
+ Buffer buffer = texturedata.getBuffer();
2449
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2450
+
2451
+ byte[] bytes = bytebuf.array();
2452
+
2453
+ return CreateBim(bytes, width, height);
2454
+ }
2455
+
7672456 /**/
7682457 class CacheTexture
7692458 {
....@@ -772,28 +2461,31 @@
7722461
7732462 int resolution;
7742463
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2464
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762465 {
777
- texture = tex;
2466
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2467
+ texturedata = texdata;
7782468 resolution = res;
7792469 }
7802470 }
7812471 /**/
7822472
7832473 // 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>();
2474
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2475
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2476
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2477
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2478
+
7872479 int pigmentdepth = 0;
7882480 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892481 int bumpdepth = 0;
7902482 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912483 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922484 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2485
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942486 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952487
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2488
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972489 {
7982490 TextureData texturedata = null;
7992491
....@@ -812,13 +2504,34 @@
8122504 if (bump)
8132505 texturedata = ConvertBump(texturedata, false);
8142506
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2507
+// com.sun.opengl.util.texture.Texture texture =
2508
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172509
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);
2510
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2511
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202512
821
- return texture;
2513
+ return texturedata;
2514
+ }
2515
+
2516
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2517
+ {
2518
+ TextureData texturedata = null;
2519
+
2520
+ try
2521
+ {
2522
+ texturedata =
2523
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2524
+ bim,
2525
+ true);
2526
+ } catch (Exception e)
2527
+ {
2528
+ throw new javax.media.opengl.GLException(e);
2529
+ }
2530
+
2531
+ if (bump)
2532
+ texturedata = ConvertBump(texturedata, false);
2533
+
2534
+ return texturedata;
8222535 }
8232536
8242537 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3604,8 @@
18913604
18923605 System.out.println("LOADING TEXTURE : " + name);
18933606
3607
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3608
+
18943609 //
18953610 if (false) // compressbit > 0)
18963611 {
....@@ -2595,6 +4310,7 @@
25954310
25964311 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25974312 {
4313
+ new Exception().printStackTrace();
25984314 System.exit(0);
25994315 com.sun.opengl.util.texture.Texture texture = null;
26004316
....@@ -6271,7 +7987,7 @@
62717987 return null;
62727988 }
62737989
6274
- void ReleaseTextures(cTexture tex)
7990
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62757991 {
62767992 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62777993 {
....@@ -6288,7 +8004,7 @@
62888004 String pigment = Object3D.GetPigment(tex);
62898005 String bump = Object3D.GetBump(tex);
62908006
6291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8007
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62928008 {
62938009 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62948010 // System.out.println("; bump = " + bump);
....@@ -6303,13 +8019,71 @@
63038019 pigment = null;
63048020 }
63058021
6306
- ReleaseTexture(bump, true);
6307
- ReleaseTexture(pigment, false);
8022
+ ReleaseTexture(tex, true);
8023
+ ReleaseTexture(tex, false);
63088024 }
63098025
6310
- void ReleaseTexture(String tex, boolean bump)
8026
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63118027 {
6312
- if (// drawMode != 0 || /*tex == null ||*/
8028
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8029
+ {
8030
+ return;
8031
+ }
8032
+
8033
+ if (tex == null)
8034
+ {
8035
+ ReleaseTexture(null, false);
8036
+ return;
8037
+ }
8038
+
8039
+ String pigment = Object3D.GetPigment(tex);
8040
+
8041
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ {
8043
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8044
+ // System.out.println("; bump = " + bump);
8045
+ }
8046
+
8047
+ if (pigment.equals(""))
8048
+ {
8049
+ pigment = null;
8050
+ }
8051
+
8052
+ ReleaseTexture(tex, false);
8053
+ }
8054
+
8055
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8056
+ {
8057
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8058
+ {
8059
+ return;
8060
+ }
8061
+
8062
+ if (tex == null)
8063
+ {
8064
+ ReleaseTexture(null, true);
8065
+ return;
8066
+ }
8067
+
8068
+ String bump = Object3D.GetBump(tex);
8069
+
8070
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8071
+ {
8072
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8073
+ // System.out.println("; bump = " + bump);
8074
+ }
8075
+
8076
+ if (bump.equals(""))
8077
+ {
8078
+ bump = null;
8079
+ }
8080
+
8081
+ ReleaseTexture(tex, true);
8082
+ }
8083
+
8084
+ void ReleaseTexture(cTexture tex, boolean bump)
8085
+ {
8086
+ if (// DrawMode() != 0 || /*tex == null ||*/
63138087 ambientOcclusion ) // || !textureon)
63148088 {
63158089 return;
....@@ -6318,7 +8092,7 @@
63188092 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63198093
63208094 if (tex != null)
6321
- texture = textures.get(tex);
8095
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63228096
63238097 // //assert( texture != null );
63248098 // if (texture == null)
....@@ -6410,9 +8184,57 @@
64108184 }
64118185 }
64128186
6413
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8187
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64148188 {
6415
- if (// drawMode != 0 || /*tex == null ||*/
8189
+// if (// DrawMode() != 0 || /*tex == null ||*/
8190
+// ambientOcclusion ) // || !textureon)
8191
+// {
8192
+// return; // false;
8193
+// }
8194
+//
8195
+// if (tex == null)
8196
+// {
8197
+// BindTexture(null,false,resolution);
8198
+// BindTexture(null,true,resolution);
8199
+// return;
8200
+// }
8201
+//
8202
+// String pigment = Object3D.GetPigment(tex);
8203
+// String bump = Object3D.GetBump(tex);
8204
+//
8205
+// usedtextures.add(pigment);
8206
+// usedtextures.add(bump);
8207
+//
8208
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8209
+// {
8210
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8211
+// // System.out.println("; bump = " + bump);
8212
+// }
8213
+//
8214
+// if (bump.equals(""))
8215
+// {
8216
+// bump = null;
8217
+// }
8218
+// if (pigment.equals(""))
8219
+// {
8220
+// pigment = null;
8221
+// }
8222
+//
8223
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8224
+// BindTexture(pigment, false, resolution);
8225
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8226
+// BindTexture(bump, true, resolution);
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+//
8229
+// return; // true;
8230
+
8231
+ BindPigmentTexture(tex, resolution);
8232
+ BindBumpTexture(tex, resolution);
8233
+ }
8234
+
8235
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8236
+ {
8237
+ if (// DrawMode() != 0 || /*tex == null ||*/
64168238 ambientOcclusion ) // || !textureon)
64178239 {
64188240 return; // false;
....@@ -6421,17 +8243,47 @@
64218243 if (tex == null)
64228244 {
64238245 BindTexture(null,false,resolution);
6424
- BindTexture(null,true,resolution);
64258246 return;
64268247 }
64278248
64288249 String pigment = Object3D.GetPigment(tex);
8250
+
8251
+ usedtextures.add(tex);
8252
+
8253
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8254
+ {
8255
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8256
+ // System.out.println("; bump = " + bump);
8257
+ }
8258
+
8259
+ if (pigment.equals(""))
8260
+ {
8261
+ pigment = null;
8262
+ }
8263
+
8264
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8265
+ BindTexture(tex, false, resolution);
8266
+ }
8267
+
8268
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8269
+ {
8270
+ if (// DrawMode() != 0 || /*tex == null ||*/
8271
+ ambientOcclusion ) // || !textureon)
8272
+ {
8273
+ return; // false;
8274
+ }
8275
+
8276
+ if (tex == null)
8277
+ {
8278
+ BindTexture(null,true,resolution);
8279
+ return;
8280
+ }
8281
+
64298282 String bump = Object3D.GetBump(tex);
64308283
6431
- usedtextures.put(pigment, pigment);
6432
- usedtextures.put(bump, bump);
8284
+ usedtextures.add(tex);
64338285
6434
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64358287 {
64368288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64378289 // System.out.println("; bump = " + bump);
....@@ -6441,43 +8293,82 @@
64418293 {
64428294 bump = null;
64438295 }
6444
- if (pigment.equals(""))
6445
- {
6446
- pigment = null;
6447
- }
64488296
6449
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
- BindTexture(pigment, false, resolution);
64518297 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6452
- BindTexture(bump, true, resolution);
8298
+ BindTexture(tex, true, resolution);
64538299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6454
-
6455
- return; // true;
64568300 }
64578301
6458
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8302
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8303
+
8304
+ private boolean FileExists(String tex)
64598305 {
6460
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8306
+ if (missingTextures.contains(tex))
8307
+ {
8308
+ return false;
8309
+ }
8310
+
8311
+ boolean fileExists = new File(tex).exists();
8312
+
8313
+ if (!fileExists)
8314
+ {
8315
+ // If file exists, the "new File()" is not executed sgain
8316
+ missingTextures.add(tex);
8317
+ }
8318
+
8319
+ return fileExists;
8320
+ }
8321
+
8322
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8323
+ {
8324
+ CacheTexture texturecache = null;
64618325
64628326 if (tex != null)
64638327 {
6464
- String texname = tex;
8328
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8329
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64658330
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;
8331
+ if (texname.equals("") && texdata == null)
8332
+ {
8333
+ return null;
8334
+ }
8335
+
8336
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8337
+
8338
+// String[] split = tex.split("Textures");
8339
+// if (split.length > 1)
8340
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8341
+// else
8342
+// if (!texname.startsWith("/"))
8343
+// texname = "/Users/nbriere/Textures/" + texname;
8344
+ if (!FileExists(texname))
8345
+ {
8346
+ texname = fallbackTextureName;
8347
+ }
64728348
64738349 if (CACHETEXTURE)
6474
- texture = textures.get(texname); // TEXTURE CACHE
6475
-
6476
- TextureData texturedata = null;
6477
-
6478
- if (texture == null || texture.resolution < resolution)
64798350 {
6480
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8351
+ if (texdata == null)
8352
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8353
+ else
8354
+ texturecache = bimtextures.get(texdata);
8355
+ }
8356
+
8357
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8358
+ {
8359
+ TextureData texturedata = null;
8360
+
8361
+ if (texdata != null)
8362
+ {
8363
+ BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8364
+
8365
+ CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8366
+
8367
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8368
+ bimtextures.put(texdata, texturecache);
8369
+ }
8370
+ else
8371
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64818372 {
64828373 assert(!bump);
64838374 // if (bump)
....@@ -6488,19 +8379,23 @@
64888379 // }
64898380 // else
64908381 // {
6491
- texture = textures.get(tex);
6492
- if (texture == null)
8382
+ // texturecache = textures.get(texname); // suspicious
8383
+ if (texturecache == null)
64938384 {
6494
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8385
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64958386 }
8387
+ else
8388
+ new Exception().printStackTrace();
64968389 // }
64978390 } else
6498
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8391
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64998392 {
65008393 assert(bump);
6501
- texture = textures.get(tex);
6502
- if (texture == null)
6503
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8394
+ // texturecache = textures.get(texname); // suspicious
8395
+ if (texturecache == null)
8396
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8397
+ else
8398
+ new Exception().printStackTrace();
65048399 } else
65058400 {
65068401 //if (tex.equals("IMMORTAL"))
....@@ -6508,11 +8403,13 @@
65088403 // texture = GetResourceTexture("default.png");
65098404 //} else
65108405 //{
6511
- if (tex.equals("WHITE_NOISE"))
8406
+ if (texname.endsWith("WHITE_NOISE"))
65128407 {
6513
- texture = textures.get(tex);
6514
- if (texture == null)
6515
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8408
+ // texturecache = textures.get(texname); // suspicious
8409
+ if (texturecache == null)
8410
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8411
+ else
8412
+ new Exception().printStackTrace();
65168413 } else
65178414 {
65188415 if (textureon)
....@@ -6537,7 +8434,7 @@
65378434 }
65388435
65398436 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6540
- if (!new File(cachename).exists())
8437
+ if (!FileExists(cachename))
65418438 cachename = texname;
65428439 else
65438440 processbump = false; // don't process bump map again
....@@ -6559,7 +8456,7 @@
65598456 }
65608457
65618458 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6562
- if (!new File(cachename).exists())
8459
+ if (!FileExists(cachename))
65638460 cachename = texname;
65648461 else
65658462 processbump = false; // don't process bump map again
....@@ -6568,20 +8465,22 @@
65688465 texturedata = GetFileTexture(cachename, processbump, resolution);
65698466
65708467
6571
- if (texturedata != null)
6572
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8468
+ if (texturedata == null)
8469
+ throw new Exception();
8470
+
8471
+ texturecache = new CacheTexture(texturedata,resolution);
65738472 //texture = GetTexture(tex, bump);
65748473 }
65758474 }
65768475 //}
65778476 }
65788477
6579
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8478
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65808479 {
65818480 //return false;
65828481
65838482 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6584
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8483
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65858484 {
65868485 // String ext = "_highres";
65878486 // if (REDUCETEXTURE)
....@@ -6598,52 +8497,17 @@
65988497 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65998498 if (!cachefile.exists())
66008499 {
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))
8500
+ //if (texturedata.getWidth() == texturedata.getHeight())
66108501 {
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);
8502
+ BufferedImage rendImage = CreateBim(texturedata);
8503
+
66418504 ImageWriter writer = null;
66428505 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66438506 if (iter.hasNext()) {
66448507 writer = (ImageWriter)iter.next();
66458508 }
6646
- float compressionQuality = 0.9f;
8509
+
8510
+ float compressionQuality = 0.85f;
66478511 try
66488512 {
66498513 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6660,18 +8524,20 @@
66608524 }
66618525 }
66628526 }
6663
-
8527
+
8528
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8529
+
66648530 //System.out.println("Texture = " + tex);
6665
- if (textures.containsKey(texname))
8531
+ if (textures.containsKey(tex))
66668532 {
6667
- CacheTexture thetex = textures.get(texname);
8533
+ CacheTexture thetex = textures.get(tex);
66688534 thetex.texture.disable();
66698535 thetex.texture.dispose();
6670
- textures.remove(texname);
8536
+ textures.remove(tex);
66718537 }
66728538
6673
- texture.texturedata = texturedata;
6674
- textures.put(texname, texture);
8539
+ //texture.texturedata = texturedata;
8540
+ textures.put(tex, texturecache);
66758541
66768542 // newtex = true;
66778543 }
....@@ -6687,10 +8553,41 @@
66878553 }
66888554 }
66898555
6690
- return texture;
8556
+ return texturecache;
66918557 }
66928558
6693
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8559
+ static void EmbedTextures(cTexture tex)
8560
+ {
8561
+ if (tex.pigmentdata == null)
8562
+ {
8563
+ String texname = Object3D.GetPigment(tex);
8564
+
8565
+ CacheTexture texturecache = texturepigment.get(tex);
8566
+
8567
+ if (texturecache != null)
8568
+ {
8569
+ tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8570
+ tex.pw = texturecache.texturedata.getWidth();
8571
+ tex.ph = texturecache.texturedata.getHeight();
8572
+ }
8573
+ }
8574
+
8575
+ if (tex.bumpdata == null)
8576
+ {
8577
+ String texname = Object3D.GetBump(tex);
8578
+
8579
+ CacheTexture texturecache = texturebump.get(tex);
8580
+
8581
+ if (texturecache != null)
8582
+ {
8583
+ tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8584
+ tex.bw = texturecache.texturedata.getWidth();
8585
+ tex.bh = texturecache.texturedata.getHeight();
8586
+ }
8587
+ }
8588
+ }
8589
+
8590
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66948591 {
66958592 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66968593
....@@ -6708,21 +8605,21 @@
67088605 return texture!=null?texture.texture:null;
67098606 }
67108607
6711
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8608
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67128609 {
67138610 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67148611
67158612 return texture!=null?texture.texturedata:null;
67168613 }
67178614
6718
- boolean BindTexture(String tex, boolean bump, int resolution)
8615
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67198616 {
67208617 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67218618 {
67228619 return false;
67238620 }
67248621
6725
- boolean newtex = false;
8622
+ //boolean newtex = false;
67268623
67278624 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67288625
....@@ -6754,7 +8651,7 @@
67548651 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67558652 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67568653
6757
- return newtex;
8654
+ return true; // Warning: not used.
67588655 }
67598656
67608657 ShadowBuffer shadowPBuf;
....@@ -7312,9 +9209,9 @@
73129209 static boolean occlusionInitialized = false;
73139210 boolean selection = false;
73149211 boolean pointselection = false;
7315
- /*static*/ boolean lighttouched = true;
9212
+ ///*static*/ boolean lighttouched = true;
73169213 boolean deselect;
7317
- boolean ambientOcclusion = false;
9214
+ private boolean ambientOcclusion = false;
73189215 static boolean flash = false;
73199216 /*static*/ boolean wait = false;
73209217 boolean displaydone = false; // after repaint() calls
....@@ -7444,6 +9341,8 @@
74449341 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74459342 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74469343 double scale = lightCamera.SCALE / lightCamera.Distance();
9344
+// PATCH FILLE AUX JEANS
9345
+ //scale *= lightCamera.shaper_fovy / 25;
74479346 gl.glScaled(2 * scale, 2 * scale, -scale);
74489347 gl.glTranslated(0, 0, lightCamera.DECAL);
74499348
....@@ -7590,18 +9489,40 @@
75909489 jy8[3] = 0.5f;
75919490 }
75929491
7593
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9492
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75949493 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
75959494 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
75969495 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75979496
9497
+ void ResetOptions()
9498
+ {
9499
+ options1[0] = 100;
9500
+ options1[1] = 0.025f;
9501
+ options1[2] = 0.01f;
9502
+ options1[3] = 0;
9503
+ options1[4] = 0;
9504
+
9505
+ options2[0] = 0;
9506
+ options2[1] = 0.75f;
9507
+ options2[2] = 0;
9508
+ options2[3] = 0;
9509
+
9510
+ options3[0] = 1;
9511
+ options3[1] = 1;
9512
+ options3[2] = 1;
9513
+ options3[3] = 0;
9514
+
9515
+ options4[0] = 1;
9516
+ options4[1] = 0;
9517
+ options4[2] = 1;
9518
+ options4[3] = 0;
9519
+ }
9520
+
75989521 static int imagecount = 0; // movie generation
75999522
76009523 static int jitter = 0;
76019524
76029525 boolean restartframe = false;
7603
-
7604
- static int framecount = 0; // general-purpose global count
76059526
76069527 void displayAntiAliased(javax.media.opengl.GL gl)
76079528 {
....@@ -7633,7 +9554,7 @@
76339554 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76349555 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76359556 {
7636
- framecount++;
9557
+ Globals.framecount++;
76379558
76389559 if (CameraPane.tickcount > 0)
76399560 CameraPane.tickcount--;
....@@ -7671,7 +9592,7 @@
76719592
76729593 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76739594 */
7674
- lighttouched = true;
9595
+ Globals.lighttouched = true;
76759596 //System.err.println(" shadowbuffer: " + jitter);
76769597 shadowbuffer.display();
76779598
....@@ -7692,8 +9613,8 @@
76929613 assert (parentcam != renderCamera);
76939614
76949615 if (renderCamera != lightCamera)
7695
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7696
- LA.matConcat(parentcam.toParent, matrix, matrix);
9616
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9617
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
76979618
76989619 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76999620
....@@ -7708,8 +9629,8 @@
77089629 LA.matCopy(renderCamera.fromScreen, matrix);
77099630
77109631 if (renderCamera != lightCamera)
7711
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7712
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9632
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9633
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
77139634
77149635 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77159636
....@@ -7781,7 +9702,7 @@
77819702 //gl.glFlush();
77829703 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77839704
7784
- if (ANIMATION && ABORTED)
9705
+ if (Globals.ANIMATION && ABORTED)
77859706 {
77869707 System.err.println(" ABORTED FRAME");
77879708 break;
....@@ -7811,7 +9732,7 @@
78119732 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78129733
78139734 // save image
7814
- if (ANIMATION && !ABORTED)
9735
+ if (Globals.ANIMATION && !ABORTED)
78159736 {
78169737 VPwidth = viewport[2];
78179738 VPheight = viewport[3];
....@@ -7922,11 +9843,11 @@
79229843
79239844 // imagecount++;
79249845
7925
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9846
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79269847
79279848 if (!BOXMODE)
79289849 {
7929
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9850
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79309851 }
79319852
79329853 if (!BOXMODE)
....@@ -7964,7 +9885,7 @@
79649885 ABORTED = false;
79659886 }
79669887 else
7967
- GrafreeD.wav.cursor += 735 * ACSIZE;
9888
+ Grafreed.wav.cursor += 735 * ACSIZE;
79689889
79699890 if (false)
79709891 {
....@@ -8618,13 +10539,6 @@
861810539 }
861910540 }
862010541
8621
- boolean IsFrozen()
8622
- {
8623
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8624
-
8625
- return !selectmode && cameracount == 0; // != 0;
8626
- }
8627
-
862810542 boolean niceon = false;
862910543 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
863010544 boolean currentlydrawing = false;
....@@ -8634,16 +10548,16 @@
863410548
863510549 public void display(GLAutoDrawable drawable)
863610550 {
8637
- if (GrafreeD.savesound && GrafreeD.hassound)
10551
+ if (Grafreed.savesound && Grafreed.hassound)
863810552 {
8639
- GrafreeD.wav.save();
8640
- GrafreeD.savesound = false;
8641
- GrafreeD.hassound = false;
10553
+ Grafreed.wav.save();
10554
+ Grafreed.savesound = false;
10555
+ Grafreed.hassound = false;
864210556 }
864310557 // if (DEBUG_SELECTION)
864410558 // {
8645
-// if (drawMode != SELECTION)
8646
-// drawMode = SELECTION;
10559
+// if (DrawMode() != SELECTION)
10560
+// DrawMode() = SELECTION;
864710561 // }
864810562
864910563 if (!isRenderer)
....@@ -8699,9 +10613,9 @@
869910613
870010614 //ANTIALIAS = 0;
870110615
8702
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10616
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870310617 {
8704
- if (niceon || isLIVE())
10618
+ if (niceon || Globals.isLIVE())
870510619 {
870610620 //if(active == 0)
870710621 // antialiaser = null;
....@@ -8714,6 +10628,7 @@
871410628 ANTIALIAS = 0;
871510629 //System.out.println("RESTART");
871610630 AAtimer.restart();
10631
+ Globals.TIMERRUNNING = true;
871710632 }
871810633 }
871910634 }
....@@ -8726,7 +10641,7 @@
872610641 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872710642 */
872810643
8729
- if (drawMode == DEFAULT)
10644
+ if (DrawMode() == DEFAULT)
873010645 {
873110646 currentlydrawing = true;
873210647 }
....@@ -8757,18 +10672,18 @@
875710672
875810673 // if(Applet3D.clipboard != null)
875910674 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8760
-//drawMode = SELECTION;
10675
+//DrawMode() = SELECTION;
876110676 indexcount = 0;
876210677
8763
- if (drawMode == OCCLUSION)
10678
+ if (DrawMode() == OCCLUSION)
876410679 {
8765
- drawMode = DEFAULT;
10680
+ Globals.drawMode = DEFAULT; // WARNING
876610681 ambientOcclusion = true;
876710682 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876810683 Object3D theobject = object;
876910684 Object3D theparent = object.parent;
877010685 object.parent = null;
8771
- object = (Object3D)GrafreeD.clone(object);
10686
+ object = (Object3D)Grafreed.clone(object);
877210687 object.Stripify();
877310688 if (theobject.selection == null || theobject.selection.Size() == 0)
877410689 theobject.PreprocessOcclusion(this);
....@@ -8781,19 +10696,20 @@
878110696 ambientOcclusion = false;
878210697 }
878310698
8784
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10699
+ if (//Globals.lighttouched &&
10700
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878510701 {
878610702 //if (RENDERSHADOW) // ?
878710703 if (!IsFrozen())
878810704 {
878910705 // dec 2012
8790
- if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10706
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
879110707 {
8792
- framecount++;
10708
+ Globals.framecount++;
879310709 shadowbuffer.display();
879410710 }
879510711 }
8796
- lighttouched = false; // ??
10712
+ Globals.lighttouched = false; // ??
879710713 //drawing = true;
879810714 //lighttouched = true;
879910715 }
....@@ -8814,9 +10730,9 @@
881410730 //eyeCamera.shaper_fovy = 1;
881510731 }
881610732
8817
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10733
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881810734 {
8819
- //System.out.println("drawMode = " + drawMode);
10735
+ //System.out.println("DrawMode() = " + DrawMode());
882010736 vertexMode |= VP_PASS;
882110737 //vertexMode |= VP_PROJECTION;
882210738 if (!ambientOcclusion)
....@@ -8876,7 +10792,7 @@
887610792 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887710793 //Camera lightcam = new Camera(light0);
887810794
8879
- if (drawMode == SHADOW)
10795
+ if (DrawMode() == SHADOW)
888010796 {
888110797 /*
888210798 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8914,8 +10830,8 @@
891410830
891510831 // if (parentcam != renderCamera) // not a light
891610832 if (cam != lightCamera)
8917
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8918
- LA.matConcat(parentcam.toParent, matrix, matrix);
10833
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10834
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
891910835
892010836 for (int j = 0; j < 4; j++)
892110837 {
....@@ -8929,8 +10845,8 @@
892910845
893010846 // if (parentcam != renderCamera) // not a light
893110847 if (cam != lightCamera)
8932
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8933
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10848
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10849
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
893410850
893510851 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893610852
....@@ -8966,7 +10882,7 @@
896610882 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896710883 } else
896810884 {
8969
- if (drawMode != DEFAULT)
10885
+ if (DrawMode() != DEFAULT)
897010886 {
897110887 gl.glClearColor(1, 1, 1, 0);
897210888 } // 1);
....@@ -9031,7 +10947,7 @@
903110947
903210948 fast &= !ambientOcclusion;
903310949
9034
- if (drawMode == DEFAULT)
10950
+ if (DrawMode() == DEFAULT)
903510951 {
903610952 //gl.glEnable(gl.GL_ALPHA_TEST);
903710953 //gl.glActiveTexture(GL.GL_TEXTURE0);
....@@ -9092,6 +11008,8 @@
909211008 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909311009 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909411010 double scale = lightCamera.SCALE / lightCamera.Distance();
11011
+// PATCH FILLE AUX JEANS
11012
+ //scale *= lightCamera.shaper_fovy / 25;
909511013 gl.glScaled(2 * scale, 2 * scale, -scale);
909611014 gl.glTranslated(0, 0, lightCamera.DECAL);
909711015
....@@ -9187,7 +11105,16 @@
918711105 // Bump noise
918811106 gl.glActiveTexture(GL.GL_TEXTURE6);
918911107 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9190
- BindTexture(NOISE_TEXTURE, false, 2);
11108
+
11109
+ try
11110
+ {
11111
+ BindTexture(NOISE_TEXTURE, false, 2);
11112
+ }
11113
+ catch (Exception e)
11114
+ {
11115
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11116
+ }
11117
+
919111118
919211119 gl.glActiveTexture(GL.GL_TEXTURE0);
919311120 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9210,9 +11137,9 @@
921011137
921111138 gl.glMatrixMode(GL.GL_MODELVIEW);
921211139
9213
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9214
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9215
-//gl.glEnable(gl.GL_MULTISAMPLE);
11140
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11141
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11142
+gl.glEnable(gl.GL_MULTISAMPLE);
921611143 } else
921711144 {
921811145 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9223,14 +11150,16 @@
922311150 //System.out.println("BLENDING ON");
922411151 gl.glEnable(GL.GL_BLEND);
922511152 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9226
-
11153
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922711154 gl.glMatrixMode(gl.GL_PROJECTION);
922811155 gl.glLoadIdentity();
922911156
9230
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11157
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
923111158 {
923211159 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923311160 double scale = lightCamera.SCALE / lightCamera.Distance();
11161
+// PATCH FILLE AUX JEANS
11162
+ //scale *= lightCamera.shaper_fovy / 25;
923411163 gl.glScaled(2 * scale, 2 * scale, -scale);
923511164 gl.glTranslated(0, 0, lightCamera.DECAL);
923611165 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9283,7 +11212,7 @@
928311212 //gl.glPushMatrix();
928411213 gl.glLoadIdentity();
928511214
9286
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11215
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928711216 {
928811217 //LA.xformPos(light0, lightCamera.fromScreen, light);
928911218 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9310,8 +11239,8 @@
931011239 System.err.println("parentcam != renderCamera");
931111240
931211241 // if (cam != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11242
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11243
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
931511244 }
931611245
931711246 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9332,8 +11261,8 @@
933211261 if (true) // TODO
933311262 {
933411263 if (cam != lightCamera)
9335
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9336
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11264
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11265
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933711266 }
933811267
933911268 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9370,7 +11299,7 @@
937011299 }
937111300
937211301 /**/
9373
- if (true) // drawMode == SELECTION) // != DEFAULT)
11302
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937411303 gl.glDisable(gl.GL_LIGHTING);
937511304 else
937611305 gl.glEnable(gl.GL_LIGHTING);
....@@ -9388,7 +11317,7 @@
938811317
938911318 lightslot = 64;
939011319
9391
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11320
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
939211321 {
939311322 DrawLights(object);
939411323 }
....@@ -9399,7 +11328,7 @@
939911328 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
940011329 //System.out.println("fragmentMode = " + fragmentMode);
940111330
9402
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11331
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
940311332 {
940411333 /*
940511334 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9432,7 +11361,7 @@
943211361 }
943311362 }
943411363
9435
- if (drawMode == DEFAULT)
11364
+ if (DrawMode() == DEFAULT)
943611365 {
943711366 if (WIREFRAME && !ambientOcclusion)
943811367 {
....@@ -9450,7 +11379,7 @@
945011379 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
945111380 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
945211381
9453
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11382
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945411383 {
945511384 if (vertexMode != 0) // && !fast)
945611385 {
....@@ -9470,7 +11399,7 @@
947011399 }
947111400 }
947211401
9473
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11402
+ if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947411403 {
947511404 //gl.glDepthFunc(GL.GL_LEQUAL);
947611405 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9498,7 +11427,7 @@
949811427 //gl.glDepthMask(false);
949911428 }
950011429
9501
- if (false) // drawMode == SHADOW)
11430
+ if (false) // DrawMode() == SHADOW)
950211431 {
950311432 //SetColumnMajorData(cameraInverseTransform, view_1);
950411433 //System.out.println("light = " + cameraInverseTransform);
....@@ -9512,16 +11441,16 @@
951211441 //System.out.println("object = " + object);
951311442 if (!frozen && !imageLocked)
951411443 {
9515
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11444
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951611445 {
951711446 displayAntiAliased(gl);
951811447 } else
951911448 {
952011449 programcount = 0;
9521
- int keepmode = drawMode;
11450
+ int keepmode = DrawMode();
952211451 // if (DEBUG_SELECTION)
952311452 // {
9524
-// drawMode = SELECTION;
11453
+// DrawMode() = SELECTION;
952511454 // }
952611455 // for point selection
952711456 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9531,10 +11460,10 @@
953111460 DrawObject(gl);
953211461
953311462 // jan 2013 System.err.println("RESET ABORT (display)");
9534
- // if (drawMode == DEFAULT)
11463
+ // if (DrawMode() == DEFAULT)
953511464 // ABORTED = false;
953611465 fullreset = false;
9537
- drawMode = keepmode;
11466
+ Globals.drawMode = keepmode; // WARNING
953811467 //System.out.println("PROGRAM SWITCH " + programcount);
953911468 }
954011469 }
....@@ -9542,11 +11471,11 @@
954211471 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
954311472 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954411473
9545
- if (drawMode == DEFAULT)
11474
+ if (DrawMode() == DEFAULT)
954611475 {
954711476 ReleaseTexture(NOISE_TEXTURE, false);
954811477 }
9549
- //if (drawMode == DEFAULT)
11478
+ //if (DrawMode() == DEFAULT)
955011479 {
955111480
955211481 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9558,7 +11487,7 @@
955811487 //else
955911488 //gl.glDisable(gl.GL_TEXTURE_2D);
956011489 //gl.glPopMatrix();
9561
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11490
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
956211491 {
956311492 //new Exception().printStackTrace();
956411493 //System.out.println("Draw image " + width + ", " + height);
....@@ -9600,7 +11529,7 @@
960011529 //gl.glFlush();
960111530 }
960211531
9603
- if (flash && drawMode == DEFAULT)
11532
+ if (flash && DrawMode() == DEFAULT)
960411533 {
960511534 flash = false;
960611535 wait = true;
....@@ -9608,9 +11537,9 @@
960811537 }
960911538
961011539 //drawing = false;
9611
- //if(drawMode == DEFAULT)
11540
+ //if(DrawMode() == DEFAULT)
961211541 // niceon = false;
9613
- if (drawMode == DEFAULT)
11542
+ if (DrawMode() == DEFAULT)
961411543 {
961511544 currentlydrawing = false;
961611545 }
....@@ -9630,7 +11559,7 @@
963011559 repaint();
963111560 }
963211561
9633
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11562
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963411563 repaint();
963511564
963611565 displaydone = true;
....@@ -9649,8 +11578,14 @@
964911578 {
965011579 renderpass++;
965111580 // System.out.println("Draw object... ");
11581
+ STEP = 1;
965211582 if (FAST) // in case there is no script
9653
- STEP = 16;
11583
+ STEP = 8;
11584
+
11585
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11586
+ {
11587
+ STEP *= 4;
11588
+ }
965411589
965511590 //object.FullInvariants();
965611591
....@@ -9664,23 +11599,44 @@
966411599 e.printStackTrace();
966511600 }
966611601
9667
- if (GrafreeD.RENDERME > 0)
9668
- GrafreeD.RENDERME--; // mechante magouille
11602
+ if (Grafreed.RENDERME > 0)
11603
+ Grafreed.RENDERME--; // mechante magouille
966911604
9670
- ONESTEP = false;
11605
+ Globals.ONESTEP = false;
967111606 }
967211607
967311608 static boolean zoomonce = false;
967411609
11610
+ static void CreateSelectedPoint()
11611
+ {
11612
+ if (selectedpoint == null)
11613
+ {
11614
+ debugpointG = new Sphere();
11615
+ debugpointP = new Sphere();
11616
+ debugpointC = new Sphere();
11617
+ debugpointR = new Sphere();
11618
+
11619
+ selectedpoint = new Superellipsoid();
11620
+
11621
+ for (int i=0; i<8; i++)
11622
+ {
11623
+ debugpoints[i] = new Sphere();
11624
+ }
11625
+ }
11626
+ }
11627
+
967511628 void DrawObject(GL gl, boolean draw)
967611629 {
11630
+ // To clear camera values
11631
+ ResetOptions();
11632
+
967711633 //System.out.println("DRAW OBJECT " + mouseDown);
9678
-// drawMode = SELECTION;
11634
+// DrawMode() = SELECTION;
967911635 //GL gl = getGL();
968011636 if ((TRACK || SHADOWTRACK) || zoomonce)
968111637 {
9682
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9683
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11638
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11639
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968411640 pingthread.StepToTarget(true); // true);
968511641 // zoomonce = false;
968611642 }
....@@ -9700,9 +11656,9 @@
970011656 callist = gl.glGenLists(1);
970111657 }
970211658
9703
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11659
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970411660
9705
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11661
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970611662
970711663 if (!mainDL || !active || touched)
970811664 {
....@@ -9729,13 +11685,20 @@
972911685 PushMatrix(ClickInfo.matbuffer);
973011686 }
973111687
9732
- if (drawMode == 0)
11688
+ if (DrawMode() == 0)
973311689 {
973411690 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973511691
973611692 usedtextures.clear();
973711693
9738
- BindTextures(DEFAULT_TEXTURES, 2);
11694
+ try
11695
+ {
11696
+ BindTextures(DEFAULT_TEXTURES, 2);
11697
+ }
11698
+ catch (Exception e)
11699
+ {
11700
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11701
+ }
973911702 }
974011703 //System.out.println("--> " + stackdepth);
974111704 // GrafreeD.traceon();
....@@ -9743,10 +11706,11 @@
974311706 // DRAW
974411707 object.draw(this, /*(Composite)*/ object, false, false);
974511708
9746
- if (drawMode == DEFAULT)
11709
+ if (DrawMode() == DEFAULT)
974711710 {
9748
- if (DEBUG)
11711
+ if (Globals.DEBUG)
974911712 {
11713
+ CreateSelectedPoint();
975011714 float radius = 0.05f;
975111715 if (selectedpoint.radius != radius)
975211716 {
....@@ -9754,40 +11718,40 @@
975411718 selectedpoint.radius = radius;
975511719 selectedpoint.recalculate();
975611720 selectedpoint.material = new cMaterial();
9757
- selectedpoint.material.color = 0.15f;
11721
+ selectedpoint.material.color = 0.15f; // Yellow
975811722 selectedpoint.material.modulation = 0.75f;
975911723
9760
- debugpoint.radius = radius;
9761
- debugpoint.recalculate();
9762
- debugpoint.material = new cMaterial();
9763
- debugpoint.material.color = 0.25f;
9764
- debugpoint.material.modulation = 0.75f;
11724
+ debugpointG.radius = radius;
11725
+ debugpointG.recalculate();
11726
+ debugpointG.material = new cMaterial();
11727
+ debugpointG.material.color = 0.25f; // Green
11728
+ debugpointG.material.modulation = 0.75f;
976511729
9766
- debugpoint2.radius = radius;
9767
- debugpoint2.recalculate();
9768
- debugpoint2.material = new cMaterial();
9769
- debugpoint2.material.color = 0.75f;
9770
- debugpoint2.material.modulation = 0.75f;
11730
+ debugpointP.radius = radius;
11731
+ debugpointP.recalculate();
11732
+ debugpointP.material = new cMaterial();
11733
+ debugpointP.material.color = 0.75f; // Purple
11734
+ debugpointP.material.modulation = 0.75f;
977111735
9772
- debugpoint3.radius = radius;
9773
- debugpoint3.recalculate();
9774
- debugpoint3.material = new cMaterial();
9775
- debugpoint3.material.color = 0.5f;
9776
- debugpoint3.material.modulation = 0.75f;
11736
+ debugpointC.radius = radius;
11737
+ debugpointC.recalculate();
11738
+ debugpointC.material = new cMaterial();
11739
+ debugpointC.material.color = 0.5f; // Cyan
11740
+ debugpointC.material.modulation = 0.75f;
977711741
9778
- debugpoint4.radius = radius;
9779
- debugpoint4.recalculate();
9780
- debugpoint4.material = new cMaterial();
9781
- debugpoint4.material.color = 0f;
9782
- debugpoint4.material.modulation = 0.75f;
11742
+ debugpointR.radius = radius;
11743
+ debugpointR.recalculate();
11744
+ debugpointR.material = new cMaterial();
11745
+ debugpointR.material.color = 0f; // Red
11746
+ debugpointR.material.modulation = 0.75f;
978311747
978411748 InitPoints(radius);
978511749 }
978611750 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9787
- debugpoint.draw(this, /*(Composite)*/ null, false,false);
9788
- debugpoint2.draw(this, /*(Composite)*/ null, false,false);
9789
- debugpoint3.draw(this, /*(Composite)*/ null, false,false);
9790
- debugpoint4.draw(this, /*(Composite)*/ null, false,false);
11751
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11752
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11753
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11754
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
979111755 // DrawPoints(this);
979211756 }
979311757
....@@ -9795,42 +11759,63 @@
979511759 }
979611760 // GrafreeD.traceoff();
979711761 //System.out.println(stackdepth);
9798
- if (drawMode == 0)
11762
+ if (DrawMode() == 0)
979911763 {
980011764 ReleaseTextures(DEFAULT_TEXTURES);
980111765
980211766 if (CLEANCACHE)
9803
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11767
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
980411768 {
9805
- String tex = e.nextElement();
11769
+ cTexture tex = e.nextElement();
980611770
980711771 // System.out.println("Texture --------- " + tex);
980811772
9809
- if (tex.equals("WHITE_NOISE"))
11773
+ if (tex.equals("WHITE_NOISE:"))
981011774 continue;
981111775
9812
- if (!usedtextures.containsKey(tex))
11776
+ if (!usedtextures.contains(tex))
981311777 {
11778
+ CacheTexture gettex = texturepigment.get(tex);
981411779 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9815
- textures.get(tex).texture.dispose();
9816
- textures.remove(tex);
11780
+ if (gettex != null)
11781
+ {
11782
+ gettex.texture.dispose();
11783
+ texturepigment.remove(tex);
11784
+ }
11785
+
11786
+ gettex = texturebump.get(tex);
11787
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11788
+ if (gettex != null)
11789
+ {
11790
+ gettex.texture.dispose();
11791
+ texturebump.remove(tex);
11792
+ }
981711793 }
981811794 }
981911795 }
982011796
982111797 checker = null;
982211798
9823
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11799
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
982411800 FindChecker(object);
982511801
9826
- if (checker != null && drawMode == DEFAULT)
11802
+ if (checker != null && DrawMode() == DEFAULT)
982711803 {
9828
- // BindTexture(IMMORTAL_TEXTURE);
11804
+ //BindTexture(IMMORTAL_TEXTURE);
11805
+ try
11806
+ {
11807
+ BindTextures(checker.GetTextures(), checker.texres);
11808
+ }
11809
+ catch (Exception e)
11810
+ {
11811
+ System.err.println("FAILED: " + checker.GetTextures());
11812
+ }
982911813 // NEAREST
983011814 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
983111815 DrawChecker(gl);
983211816 //checker.Draw(this, null, false);
983311817 // ReleaseTexture(IMMORTAL_TEXTURE);
11818
+ ReleaseTextures(checker.GetTextures());
983411819 }
983511820
983611821 if (object.parent != null)
....@@ -9843,7 +11828,7 @@
984311828 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
984411829 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
984511830
9846
- if (DISPLAYTEXT && drawMode == DEFAULT)
11831
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
984711832 {
984811833 // Draw it once, then use the raster
984911834 Balloon(gl, balloon.createGraphics());
....@@ -9899,14 +11884,14 @@
989911884 int[] xs = new int[3];
990011885 int[] ys = new int[3];
990111886
9902
- void DrawString(Object3D obj) // String string)
11887
+ public void DrawString(Object3D obj) // String string) // INTERFACE
990311888 {
9904
- if (!DISPLAYTEXT || drawMode != DEFAULT)
11889
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
990511890 {
990611891 return;
990711892 }
990811893
9909
- String string = obj.GetToolTip();
11894
+ String string = obj.toString(); //.GetToolTip();
991011895
991111896 GL gl = GetGL();
991211897
....@@ -10223,8 +12208,8 @@
1022312208 //obj.TransformToWorld(light, light);
1022412209 for (int i = tp.size(); --i >= 0;)
1022512210 {
10226
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10227
- LA.xformPos(light, tp.get(i).toParent, light);
12211
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12212
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1022812213 }
1022912214
1023012215
....@@ -10241,8 +12226,8 @@
1024112226 parentcam = cameras[0];
1024212227 }
1024312228
10244
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10245
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12229
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12230
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1024612231
1024712232 LA.xformPos(light, renderCamera.toScreen, light);
1024812233
....@@ -10388,6 +12373,7 @@
1038812373 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1038912374 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1039012375 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12376
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1039112377 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1039212378 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1039312379 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10855,8 +12841,8 @@
1085512841
1085612842 // display shadow only (bump == 0)
1085712843 "SUB temp.x, half.x, shadow.x;" +
10858
- "MOV temp.y, -params6.x;" +
10859
- "SLT temp.z, temp.y, zero.x;" +
12844
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12845
+ "SLT temp.z, temp.y, -one2048th.x;" +
1086012846 "SUB temp.y, one.x, temp.z;" +
1086112847 "MUL temp.x, temp.x, temp.y;" +
1086212848 "KIL temp.x;" +
....@@ -10985,8 +12971,10 @@
1098512971 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1098612972
1098712973 "SUB temp.x, one.x, ndotl.x;" +
10988
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
10989
- "ADD temp.y, one.y, options2.y;" + // sursurface
12974
+ // Tuning for default skin
12975
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
12976
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
12977
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1099012978 "MUL temp.x, temp.x, temp.y;" +
1099112979
1099212980 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11185,7 +13173,7 @@
1118513173 //once = true;
1118613174 }
1118713175
11188
- System.out.print("Program #" + mode + "; length = " + program.length());
13176
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1118913177 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1119013178 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1119113179
....@@ -11302,6 +13290,7 @@
1130213290 String Shadow(String depth, String shadow)
1130313291 {
1130413292 return "MAX temp.x, ndotl.x, one64th.x;" +
13293
+ "MIN temp.x, temp.x, ninetenth.x;" +
1130513294 /**/
1130613295 // Sine
1130713296 "MUL temp.y, temp.x, temp.x;" +
....@@ -11317,12 +13306,16 @@
1131713306
1131813307 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1131913308 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13309
+
13310
+ // Compare fragment depth in light space with shadowmap.
1132013311 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1132113312 "SGE temp.y, temp.x, zero.x;" +
11322
- "SUB " + shadow + ".y, one.x, temp.y;" +
13313
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13314
+
13315
+ // Reverse comparison
1132313316 "SUB temp.x, one.x, temp.x;" +
1132413317 "MUL " + shadow + ".x, temp.x, temp.y;" +
11325
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13318
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1132613319 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1132713320
1132813321 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11336,6 +13329,10 @@
1133613329 // No shadow for backface
1133713330 "DP3 temp.x, normal, lightd;" +
1133813331 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13332
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13333
+
13334
+ // No shadow when out of frustrum
13335
+ "SGE temp.x, " + depth + ".z, one.z;" +
1133913336 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1134013337 "";
1134113338 }
....@@ -11482,7 +13479,8 @@
1148213479 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1148313480 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1148413481 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11485
- Object3D.cVector2[] vector2buffer;
13482
+
13483
+ //Object3D.cVector2[] vector2buffer;
1148613484
1148713485 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1148813486 // OUT : diff, spec
....@@ -11498,9 +13496,10 @@
1149813496 "DP3 " + dest + ".z," + "normals," + "eye;" +
1149913497 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1150013498 //"MOV " + dest + ".w," + "normal.z;" +
11501
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11502
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11503
- //"MOV " + dest + ".z," + "params2.w;" +
13499
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13500
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13501
+
13502
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1150413503 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1150513504 "RCP " + dest + ".w," + dest + ".w;" +
1150613505 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11894,7 +13893,7 @@
1189413893 public void mousePressed(MouseEvent e)
1189513894 {
1189613895 //System.out.println("mousePressed: " + e);
11897
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
13896
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1189813897 }
1189913898
1190013899 static long prevtime = 0;
....@@ -11921,14 +13920,16 @@
1192113920
1192213921 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1192313922
13923
+ if (BUTTONLESSWHEEL)
1192413924 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1192513925 {
1192613926 return;
1192713927 }
1192813928
13929
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1192913930
1193013931 // TIMER
11931
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
13932
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1193213933 {
1193313934 keepboxmode = BOXMODE;
1193413935 keepsupport = SUPPORT;
....@@ -11968,8 +13969,8 @@
1196813969 // mode |= META;
1196913970 //}
1197013971
11971
- SetMouseMode(WHEEL | e.getModifiersEx());
11972
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
13972
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
13973
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1197313974 anchorX = ax;
1197413975 anchorY = ay;
1197513976 prevX = px;
....@@ -12003,6 +14004,7 @@
1200314004 else
1200414005 if (evt.getSource() == AAtimer)
1200514006 {
14007
+ Globals.TIMERRUNNING = false;
1200614008 if (mouseDown)
1200714009 {
1200814010 //new Exception().printStackTrace();
....@@ -12028,6 +14030,10 @@
1202814030 // LIVE = waslive;
1202914031 // wasliveok = true;
1203014032 // waslive = false;
14033
+
14034
+ // May 2019 Forget it:
14035
+ if (true)
14036
+ return;
1203114037
1203214038 // source == timer
1203314039 if (mouseDown)
....@@ -12057,8 +14063,8 @@
1205714063 // ObjEditor.tweenManager.update(1f / 60f);
1205814064
1205914065 // fev 2014???
12060
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12061
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14066
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14067
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1206214068 pingthread.StepToTarget(true); // true);
1206314069 }
1206414070 // if (!LIVE)
....@@ -12067,12 +14073,13 @@
1206714073
1206814074 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1206914075
12070
- void clickStart(int x, int y, int modifiers)
14076
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1207114077 {
1207214078 if (!wasliveok)
1207314079 return;
1207414080
1207514081 AAtimer.restart(); //
14082
+ Globals.TIMERRUNNING = true;
1207614083
1207714084 // waslive = LIVE;
1207814085 // LIVE = false;
....@@ -12084,7 +14091,7 @@
1208414091 // touched = true; // main DL
1208514092 if (isRenderer)
1208614093 {
12087
- SetMouseMode(modifiers);
14094
+ SetMouseMode(modifiers, modifiersex);
1208814095 }
1208914096
1209014097 selectX = anchorX = x;
....@@ -12097,7 +14104,7 @@
1209714104 clicked = true;
1209814105 hold = false;
1209914106
12100
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14107
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1210114108 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1210214109 {
1210314110 // System.out.println("RESTART II " + modifiers);
....@@ -12128,7 +14135,7 @@
1212814135 info.camera = renderCamera;
1212914136 info.x = x;
1213014137 info.y = y;
12131
- info.modifiers = modifiers;
14138
+ info.modifiers = modifiersex;
1213214139 editObj = object.doEditClick(info, 0);
1213314140 if (!editObj)
1213414141 {
....@@ -12145,11 +14152,14 @@
1214514152
1214614153 public void mouseDragged(MouseEvent e)
1214714154 {
14155
+ Globals.MOUSEDRAGGED = true;
14156
+
14157
+ //System.out.println("mouseDragged: " + e);
1214814158 if (isRenderer)
1214914159 movingcamera = true;
14160
+
1215014161 //if (drawing)
1215114162 //return;
12152
- //System.out.println("mouseDragged: " + e);
1215314163 if ((e.getModifiersEx() & CTRL) != 0
1215414164 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1215514165 {
....@@ -12157,7 +14167,7 @@
1215714167 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1215814168 }
1215914169 else
12160
- drag(e.getX(), e.getY(), e.getModifiersEx());
14170
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1216114171
1216214172 //try { Thread.sleep(1); } catch (Exception ex) {}
1216314173 }
....@@ -12169,6 +14179,11 @@
1216914179 cVector tmp = new cVector();
1217014180 cVector tmp2 = new cVector();
1217114181 boolean isMoving;
14182
+
14183
+ public cVector TargetLookAt()
14184
+ {
14185
+ return targetLookAt;
14186
+ }
1217214187
1217314188 class PingThread extends Thread
1217414189 {
....@@ -12308,7 +14323,7 @@
1230814323 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1230914324 if (lightMode)
1231014325 {
12311
- lighttouched = true;
14326
+ Globals.lighttouched = true;
1231214327 }
1231314328
1231414329 if (OEILONCE && OEIL)
....@@ -12325,6 +14340,7 @@
1232514340
1232614341 public void run()
1232714342 {
14343
+ new Exception().printStackTrace();
1232814344 System.exit(0);
1232914345 for (;;)
1233014346 {
....@@ -12366,7 +14382,7 @@
1236614382 mouseDown = false;
1236714383 if (lightMode)
1236814384 {
12369
- lighttouched = true;
14385
+ Globals.lighttouched = true;
1237014386 }
1237114387 repaint();
1237214388 alreadypainted = true;
....@@ -12374,7 +14390,7 @@
1237414390 isMoving = false;
1237514391 } //??
1237614392
12377
- if (isLIVE() && !alreadypainted)
14393
+ if (Globals.isLIVE() && !alreadypainted)
1237814394 {
1237914395 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1238014396 repaint();
....@@ -12386,9 +14402,9 @@
1238614402 {
1238714403 if (lightMode)
1238814404 {
12389
- lighttouched = true;
14405
+ Globals.lighttouched = true;
1239014406 }
12391
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14407
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1239214408 }
1239314409 //else
1239414410 }
....@@ -12402,12 +14418,12 @@
1240214418 void GoDown(int mod)
1240314419 {
1240414420 MODIFIERS |= COMMAND;
12405
- /*
14421
+ /**/
1240614422 if((mod&SHIFT) == SHIFT)
1240714423 manipCamera.RotatePosition(0, -speed);
1240814424 else
12409
- manipCamera.BackForth(0, -speed*delta, getWidth());
12410
- */
14425
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14426
+ /**/
1241114427 if ((mod & SHIFT) == SHIFT)
1241214428 {
1241314429 mouseMode = mouseMode; // VR??
....@@ -12423,12 +14439,12 @@
1242314439 void GoUp(int mod)
1242414440 {
1242514441 MODIFIERS |= COMMAND;
12426
- /*
14442
+ /**/
1242714443 if((mod&SHIFT) == SHIFT)
1242814444 manipCamera.RotatePosition(0, speed);
1242914445 else
12430
- manipCamera.BackForth(0, speed*delta, getWidth());
12431
- */
14446
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14447
+ /**/
1243214448 if ((mod & SHIFT) == SHIFT)
1243314449 {
1243414450 mouseMode = mouseMode;
....@@ -12444,12 +14460,12 @@
1244414460 void GoLeft(int mod)
1244514461 {
1244614462 MODIFIERS |= COMMAND;
12447
- /*
14463
+ /**/
1244814464 if((mod&SHIFT) == SHIFT)
12449
- manipCamera.RotatePosition(speed, 0);
12450
- else
1245114465 manipCamera.Translate(speed*delta, 0, getWidth());
12452
- */
14466
+ else
14467
+ manipCamera.RotatePosition(speed, 0);
14468
+ /**/
1245314469 if ((mod & SHIFT) == SHIFT)
1245414470 {
1245514471 mouseMode = mouseMode;
....@@ -12465,12 +14481,12 @@
1246514481 void GoRight(int mod)
1246614482 {
1246714483 MODIFIERS |= COMMAND;
12468
- /*
14484
+ /**/
1246914485 if((mod&SHIFT) == SHIFT)
12470
- manipCamera.RotatePosition(-speed, 0);
12471
- else
1247214486 manipCamera.Translate(-speed*delta, 0, getWidth());
12473
- */
14487
+ else
14488
+ manipCamera.RotatePosition(-speed, 0);
14489
+ /**/
1247414490 if ((mod & SHIFT) == SHIFT)
1247514491 {
1247614492 mouseMode = mouseMode;
....@@ -12488,7 +14504,7 @@
1248814504 int X, Y;
1248914505 boolean SX, SY;
1249014506
12491
- void drag(int x, int y, int modifiers)
14507
+ void drag(int x, int y, int modifiers, int modifiersex)
1249214508 {
1249314509 if (IsFrozen())
1249414510 {
....@@ -12497,17 +14513,17 @@
1249714513
1249814514 drag = true; // NEW
1249914515
12500
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14516
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1250114517
1250214518 X = x;
1250314519 Y = y;
1250414520 // floating state for animation
12505
- MODIFIERS = modifiers;
12506
- modifiers &= ~1024;
14521
+ MODIFIERS = modifiersex;
14522
+ modifiersex &= ~1024;
1250714523 if (false) // modifiers != 0)
1250814524 {
1250914525 //new Exception().printStackTrace();
12510
- System.out.println("mouseDragged: " + modifiers);
14526
+ System.out.println("mouseDragged: " + modifiersex);
1251114527 System.out.println("SHIFT = " + SHIFT);
1251214528 System.out.println("CONTROL = " + COMMAND);
1251314529 System.out.println("META = " + META);
....@@ -12527,7 +14543,8 @@
1252714543 info.camera = renderCamera;
1252814544 info.x = x;
1252914545 info.y = y;
12530
- object.editWindow.copy.doEditDrag(info);
14546
+ object.GetWindow().copy
14547
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1253114548 } else
1253214549 {
1253314550 if (x < startX)
....@@ -12629,6 +14646,7 @@
1262914646 {
1263014647 manipCamera.Translate(dx, dy, getWidth());
1263114648 }
14649
+ else
1263214650 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1263314651 {
1263414652 manipCamera.RotateInterest(dx, dy);
....@@ -12639,7 +14657,7 @@
1263914657
1264014658 if (manipCamera == lightCamera)
1264114659 {
12642
- lighttouched = true;
14660
+ Globals.lighttouched = true;
1264314661 }
1264414662 /*
1264514663 switch (mode)
....@@ -12678,7 +14696,6 @@
1267814696 public void mouseMoved(MouseEvent e)
1267914697 {
1268014698 //System.out.println("mouseMoved: " + e);
12681
-
1268214699 if (isRenderer)
1268314700 return;
1268414701
....@@ -12691,7 +14708,9 @@
1269114708 ci.camera = renderCamera;
1269214709 if (!isRenderer)
1269314710 {
12694
- if (object.editWindow.copy.doEditClick(ci, 0))
14711
+ //ObjEditor editWindow = object.editWindow;
14712
+ //Object3D copy = editWindow.copy;
14713
+ if (object.doEditClick(ci, 0))
1269514714 {
1269614715 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1269714716 } else
....@@ -12703,7 +14722,11 @@
1270314722
1270414723 public void mouseReleased(MouseEvent e)
1270514724 {
14725
+ Globals.MOUSEDRAGGED = false;
14726
+
1270614727 movingcamera = false;
14728
+ X = 0; // getBounds().width/2;
14729
+ Y = 0; // getBounds().height/2;
1270714730 //System.out.println("mouseReleased: " + e);
1270814731 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1270914732 }
....@@ -12726,9 +14749,9 @@
1272614749 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1272714750 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1272814751
12729
- if (control || command || IsFrozen())
14752
+// No delay if (control || command || IsFrozen())
1273014753 timeout = true;
12731
- else
14754
+// ?? May 2019 else
1273214755 // timer.setDelay((modifiers & 128) != 0?0:350);
1273314756 mouseDown = false;
1273414757 if (!control && !command) // june 2013
....@@ -12838,7 +14861,7 @@
1283814861 System.out.println("keyReleased: " + e);
1283914862 }
1284014863
12841
- void SetMouseMode(int modifiers)
14864
+ void SetMouseMode(int modifiers, int modifiersex)
1284214865 {
1284314866 //System.out.println("SetMouseMode = " + modifiers);
1284414867 //modifiers &= ~1024;
....@@ -12850,25 +14873,25 @@
1285014873 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1285114874 // return;
1285214875 //System.out.println("SetMode = " + modifiers);
12853
- if ((modifiers & WHEEL) == WHEEL)
14876
+ if ((modifiersex & WHEEL) == WHEEL)
1285414877 {
1285514878 mouseMode |= ZOOM;
1285614879 }
1285714880
1285814881 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
12859
- if (capsLocked || (modifiers & META) == META)
14882
+ if (capsLocked) // || (modifiers & META) == META)
1286014883 {
1286114884 mouseMode |= VR; // BACKFORTH;
1286214885 }
12863
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12864
- {
12865
- mouseMode |= SELECT; // BACKFORTH;
12866
- }
12867
- if ((modifiers & COMMAND) == COMMAND)
14886
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1286814887 {
1286914888 mouseMode |= SELECT;
1287014889 }
12871
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
14890
+ if ((modifiersex & COMMAND) == COMMAND)
14891
+ {
14892
+ mouseMode |= SELECT;
14893
+ }
14894
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1287214895 {
1287314896 mouseMode &= ~VR;
1287414897 mouseMode |= TRANSLATE;
....@@ -12897,10 +14920,10 @@
1289714920
1289814921 if (isRenderer) //
1289914922 {
12900
- SetMouseMode(modifiers);
14923
+ SetMouseMode(0, modifiers);
1290114924 }
1290214925
12903
- theRenderer.keyPressed(key);
14926
+ Globals.theRenderer.keyPressed(key);
1290414927 }
1290514928
1290614929 int kompactbit = 4; // power bit
....@@ -12912,7 +14935,7 @@
1291214935 float SATPOW = 1; // 2; // 0.5f;
1291314936 float BRIPOW = 1; // 0.5f; // 0.5f;
1291414937
12915
- void keyPressed(int key)
14938
+ public void keyPressed(int key)
1291614939 {
1291714940 if (key >= '0' && key <= '5')
1291814941 clampbit = (key-'0');
....@@ -12959,7 +14982,8 @@
1295914982 // break;
1296014983 case 'T':
1296114984 CACHETEXTURE ^= true;
12962
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1296314987 // repaint();
1296414988 break;
1296514989 case 'Y':
....@@ -13027,7 +15051,7 @@
1302715051 case 'B':
1302815052 BRISMOOTH ^= true;
1302915053 SHADOWCULLFACE ^= true;
13030
- lighttouched = true;
15054
+ Globals.lighttouched = true;
1303115055 repaint();
1303215056 break;
1303315057 case 'b':
....@@ -13044,7 +15068,9 @@
1304415068 case 'E' : COMPACT ^= true;
1304515069 repaint();
1304615070 break;
13047
- case 'W' : DEBUGHSB ^= true;
15071
+ case 'W' : // Wide Window (fullscreen)
15072
+ //DEBUGHSB ^= true;
15073
+ ObjEditor.theFrame.ToggleFullScreen();
1304815074 repaint();
1304915075 break;
1305015076 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13069,8 +15095,8 @@
1306915095 RevertCamera();
1307015096 repaint();
1307115097 break;
13072
- case 'L':
1307315098 case 'l':
15099
+ //case 'L':
1307415100 if (lightMode)
1307515101 {
1307615102 lightMode = false;
....@@ -13127,7 +15153,7 @@
1312715153 repaint();
1312815154 break;
1312915155 case 'O':
13130
- drawMode = OCCLUSION;
15156
+ Globals.drawMode = OCCLUSION; // WARNING
1313115157 repaint();
1313215158 break;
1313315159 case 'o':
....@@ -13213,12 +15239,12 @@
1321315239 case '_':
1321415240 kompactbit = 5;
1321515241 break;
13216
- case '+':
13217
- kompactbit = 6;
13218
- break;
15242
+// case '+':
15243
+// kompactbit = 6;
15244
+// break;
1321915245 case ' ':
1322015246 lightMode ^= true;
13221
- lighttouched = true;
15247
+ Globals.lighttouched = true;
1322215248 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1322315249 targetLookAt.set(manipCamera.lookAt);
1322415250 repaint();
....@@ -13227,14 +15253,15 @@
1322715253 case ESC:
1322815254 RENDERPROGRAM += 1;
1322915255 RENDERPROGRAM %= 3;
15256
+
1323015257 repaint();
1323115258 break;
1323215259 case 'Z':
13233
- RESIZETEXTURE ^= true;
13234
- break;
15260
+ //RESIZETEXTURE ^= true;
15261
+ //break;
1323515262 case 'z':
13236
- RENDERSHADOW ^= true;
13237
- lighttouched = true;
15263
+ Globals.RENDERSHADOW ^= true;
15264
+ Globals.lighttouched = true;
1323815265 repaint();
1323915266 break;
1324015267 //case UP:
....@@ -13266,8 +15293,9 @@
1326615293 case DELETE:
1326715294 ClearSelection();
1326815295 break;
13269
- /*
1327015296 case '+':
15297
+
15298
+ /*
1327115299 //fontsize += 1;
1327215300 bbzoom *= 2;
1327315301 repaint();
....@@ -13284,17 +15312,17 @@
1328415312 case '=':
1328515313 IncDepth();
1328615314 //fontsize += 1;
13287
- object.editWindow.refreshContents(true);
15315
+ object.GetWindow().refreshContents(true);
1328815316 maskbit = 6;
1328915317 break;
1329015318 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1329115319 DecDepth();
1329215320 maskbit = 5;
1329315321 //if(fontsize > 1) fontsize -= 1;
13294
- if (object.editWindow == null)
13295
- new Exception().printStackTrace();
13296
- else
13297
- object.editWindow.refreshContents(true);
15322
+// if (object.editWindow == null)
15323
+// new Exception().printStackTrace();
15324
+// else
15325
+ object.GetWindow().refreshContents(true);
1329815326 break;
1329915327 case '{':
1330015328 manipCamera.shaper_fovy /= 1.1;
....@@ -13349,6 +15377,7 @@
1334915377 }
1335015378 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1335115379 }
15380
+
1335215381 static double OCCLUSIONBOOST = 1; // 0.5;
1335315382
1335415383 void keyReleased(int key, int modifiers)
....@@ -13356,11 +15385,11 @@
1335615385 //mode = ROTATE;
1335715386 if ((MODIFIERS & COMMAND) == 0) // VR??
1335815387 {
13359
- SetMouseMode(modifiers);
15388
+ SetMouseMode(0, modifiers);
1336015389 }
1336115390 }
1336215391
13363
- protected void processKeyEvent(KeyEvent e)
15392
+ public void processKeyEvent(KeyEvent e)
1336415393 {
1336515394 switch (e.getID())
1336615395 {
....@@ -13490,8 +15519,9 @@
1349015519
1349115520 protected void processMouseMotionEvent(MouseEvent e)
1349215521 {
13493
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13494
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15522
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15523
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15524
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1349515525 {
1349615526 mouseMoved(e);
1349715527 } else
....@@ -13516,11 +15546,12 @@
1351615546 }
1351715547 */
1351815548
13519
- object.editWindow.EditSelection();
15549
+ object.GetWindow().EditSelection(false);
1352015550 }
1352115551
1352215552 void SelectParent()
1352315553 {
15554
+ new Exception().printStackTrace();
1352415555 System.exit(0);
1352515556 Composite group = (Composite) object;
1352615557 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13532,10 +15563,10 @@
1353215563 {
1353315564 //selectees.remove(i);
1353415565 System.out.println("select parent of " + elem);
13535
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15566
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1353615567 } else
1353715568 {
13538
- group.editWindow.Select(elem.GetTreePath(), first, true);
15569
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1353915570 }
1354015571
1354115572 first = false;
....@@ -13544,6 +15575,7 @@
1354415575
1354515576 void SelectChildren()
1354615577 {
15578
+ new Exception().printStackTrace();
1354715579 System.exit(0);
1354815580 /*
1354915581 Composite group = (Composite) object;
....@@ -13576,12 +15608,12 @@
1357615608 for (int j = 0; j < group.children.size(); j++)
1357715609 {
1357815610 elem = (Object3D) group.children.elementAt(j);
13579
- object.editWindow.Select(elem.GetTreePath(), first, true);
15611
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1358015612 first = false;
1358115613 }
1358215614 } else
1358315615 {
13584
- object.editWindow.Select(elem.GetTreePath(), first, true);
15616
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1358515617 }
1358615618
1358715619 first = false;
....@@ -13592,21 +15624,21 @@
1359215624 {
1359315625 //Composite group = (Composite) object;
1359415626 Object3D group = object;
13595
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15627
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1359615628 }
1359715629
1359815630 void ResetTransform(int mask)
1359915631 {
1360015632 //Composite group = (Composite) object;
1360115633 Object3D group = object;
13602
- group.editWindow.ResetTransform(mask);
15634
+ group.GetWindow().ResetTransform(mask);
1360315635 }
1360415636
1360515637 void FlipTransform()
1360615638 {
1360715639 //Composite group = (Composite) object;
1360815640 Object3D group = object;
13609
- group.editWindow.FlipTransform();
15641
+ group.GetWindow().FlipTransform();
1361015642 // group.editWindow.ReduceMesh(true);
1361115643 }
1361215644
....@@ -13614,7 +15646,7 @@
1361415646 {
1361515647 //Composite group = (Composite) object;
1361615648 Object3D group = object;
13617
- group.editWindow.PrintMemory();
15649
+ group.GetWindow().PrintMemory();
1361815650 // group.editWindow.ReduceMesh(true);
1361915651 }
1362015652
....@@ -13622,7 +15654,7 @@
1362215654 {
1362315655 //Composite group = (Composite) object;
1362415656 Object3D group = object;
13625
- group.editWindow.ResetCentroid();
15657
+ group.GetWindow().ResetCentroid();
1362615658 }
1362715659
1362815660 void IncDepth()
....@@ -13708,7 +15740,9 @@
1370815740 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1370915741 //Image img = CreateImage(width, height);
1371015742 //System.out.println("width = " + width + "; height = " + height + "\n");
15743
+
1371115744 Graphics gr = g; // img.getGraphics();
15745
+
1371215746 if (!hasMarquee)
1371315747 {
1371415748 if (Xmin < Xmax) // !locked)
....@@ -13796,6 +15830,7 @@
1379615830 info.bounds.y += (height - desired) / 2;
1379715831 }
1379815832 }
15833
+
1379915834 info.g = gr;
1380015835 info.camera = renderCamera;
1380115836 /*
....@@ -13805,15 +15840,55 @@
1380515840 */
1380615841 if (!isRenderer)
1380715842 {
13808
- object.drawEditHandles(info, 0);
15843
+ Grafreed.Assert(object != null);
15844
+ Grafreed.Assert(object.selection != null);
15845
+ if (object.selection.Size() > 0)
15846
+ {
15847
+ int hitSomething = object.selection.get(0).hitSomething;
15848
+
15849
+ info.DX = 0;
15850
+ info.DY = 0;
15851
+ info.W = 1;
15852
+ if (hitSomething == Object3D.hitCenter)
15853
+ {
15854
+ info.DX = X;
15855
+ if (X != 0)
15856
+ info.DX -= info.bounds.width/2;
15857
+
15858
+ info.DY = Y;
15859
+ if (Y != 0)
15860
+ info.DY -= info.bounds.height/2;
15861
+ }
15862
+
15863
+ object.drawEditHandles(info, 0);
15864
+
15865
+ if (drag && (X != 0 || Y != 0))
15866
+ {
15867
+ switch (hitSomething)
15868
+ {
15869
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15870
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15871
+ break;
15872
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15873
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15874
+ break;
15875
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15876
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15877
+ break;
15878
+ }
15879
+
15880
+ }
15881
+ }
1380915882 }
1381015883 }
15884
+
1381115885 if (isRenderer)
1381215886 {
1381315887 //gr.setColor(Color.black);
1381415888 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1381515889 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1381615890 }
15891
+
1381715892 if (hasMarquee)
1381815893 {
1381915894 gr.setXORMode(Color.white);
....@@ -13836,6 +15911,7 @@
1383615911 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1383715912 }
1383815913
15914
+ // To avoid clear.
1383915915 public void update(Graphics g)
1384015916 {
1384115917 paint(g);
....@@ -13925,6 +16001,7 @@
1392516001 public boolean mouseDown(Event evt, int x, int y)
1392616002 {
1392716003 System.out.println("mouseDown: " + evt);
16004
+ System.exit(0);
1392816005 /*
1392916006 locked = true;
1393016007 drag = false;
....@@ -13968,7 +16045,7 @@
1396816045 {
1396916046 keyPressed(0, modifiers);
1397016047 }
13971
- clickStart(x, y, modifiers);
16048
+ // clickStart(x, y, modifiers);
1397216049 return true;
1397316050 }
1397416051
....@@ -14086,7 +16163,7 @@
1408616163 {
1408716164 keyReleased(0, 0);
1408816165 }
14089
- drag(x, y, modifiers);
16166
+ drag(x, y, 0, modifiers);
1409016167 return true;
1409116168 }
1409216169
....@@ -14218,7 +16295,7 @@
1421816295 Object3D object;
1421916296 static Object3D trackedobject;
1422016297 Camera renderCamera; // Light or Eye (or Occlusion)
14221
- /*static*/ Camera manipCamera; // Light or Eye
16298
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1422216299 /*static*/ Camera eyeCamera;
1422316300 /*static*/ Camera lightCamera;
1422416301 int cameracount;
....@@ -14438,7 +16515,7 @@
1443816515 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1443916516 gl.glPushMatrix();
1444016517 gl.glLoadIdentity();
14441
- PushMatrix(checker.toParent);
16518
+ //PushMatrix(checker.toParent);
1444216519
1444316520 gl.glMatrixMode(GL.GL_TEXTURE);
1444416521 gl.glPushMatrix();
....@@ -14461,8 +16538,8 @@
1446116538
1446216539 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1446316540
14464
- float step = 0.1666f; //0.25f;
14465
- float stepv = step * 1652 / 998;
16541
+ float step = 2; // 0.1666f; //0.25f;
16542
+ float stepv = 2; // step * 1652 / 998;
1446616543
1446716544 int i0 = 0;
1446816545 /*
....@@ -14498,20 +16575,21 @@
1449816575 /**/
1449916576 //checker.GetMaterial().opacity = 1.1f;
1450016577 ////checker.GetMaterial().ambient = 0.99f;
14501
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14502
- Object3D.selectedstack[Object3D.materialdepth] = false;
14503
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16578
+ materialstack[materialdepth] = checker.material;
16579
+ selectedstack[materialdepth] = false;
16580
+ cStatic.objectstack[materialdepth++] = checker;
1450416581 //System.out.println("material " + material);
1450516582 //Applet3D.tracein(this, selected);
14506
- vector2buffer = checker.projectedVertices;
16583
+ //vector2buffer = checker.projectedVertices;
1450716584
14508
- checker.GetMaterial().Draw(this, false); // true);
16585
+ //checker.GetMaterial().Draw(this, false); // true);
16586
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1450916587
14510
- Object3D.materialdepth -= 1;
14511
- if (Object3D.materialdepth > 0)
16588
+ materialdepth -= 1;
16589
+ if (materialdepth > 0)
1451216590 {
14513
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14514
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16591
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16592
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1451516593 }
1451616594 //checker.GetMaterial().opacity = 1f;
1451716595 ////checker.GetMaterial().ambient = 1f;
....@@ -14532,15 +16610,27 @@
1453216610
1453316611 //float u = (i+1)/2;
1453416612 //float v = (j+1)/2;
14535
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16613
+ if (checker.flipV)
16614
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16615
+ else
16616
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1453616617 gl.glVertex3f(i, j, -0.5f);
1453716618
16619
+ if (checker.flipV)
16620
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16621
+ else
1453816622 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1453916623 gl.glVertex3f(i + step, j, -0.5f);
1454016624
16625
+ if (checker.flipV)
16626
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16627
+ else
1454116628 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1454216629 gl.glVertex3f(i + step, j + stepv, -0.5f);
1454316630
16631
+ if (checker.flipV)
16632
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16633
+ else
1454416634 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1454516635 gl.glVertex3f(i, j + stepv, -0.5f);
1454616636 }
....@@ -14552,7 +16642,7 @@
1455216642 gl.glMatrixMode(GL.GL_PROJECTION);
1455316643 gl.glPopMatrix();
1455416644 gl.glMatrixMode(GL.GL_MODELVIEW);
14555
- PopMatrix(null); // checker.toParent); // null);
16645
+ //PopMatrix(null); // checker.toParent); // null);
1455616646 gl.glPopMatrix();
1455716647 PopTextureMatrix(checker.toParent);
1455816648 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14585,6 +16675,14 @@
1458516675 }
1458616676 }
1458716677
16678
+ private Object3D GetFolder()
16679
+ {
16680
+ Object3D folder = object.GetWindow().copy;
16681
+ if (object.GetWindow().copy.selection.Size() > 0)
16682
+ folder = object.GetWindow().copy.selection.elementAt(0);
16683
+ return folder;
16684
+ }
16685
+
1458816686 class SelectBuffer implements GLEventListener
1458916687 {
1459016688
....@@ -14643,6 +16741,7 @@
1464316741 {
1464416742 if (!selection)
1464516743 {
16744
+ new Exception().printStackTrace();
1464616745 System.exit(0);
1464716746 return;
1464816747 }
....@@ -14663,17 +16762,39 @@
1466316762
1466416763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1466516764
16765
+ if (PAINTMODE)
16766
+ {
16767
+ if (object.GetWindow().copy.selection.Size() > 0)
16768
+ {
16769
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16770
+
16771
+ // Make what you paint not selectable.
16772
+ paintobj.ResetSelectable();
16773
+ }
16774
+ }
16775
+
1466616776 //int tmp = selection_view;
1466716777 //selection_view = -1;
14668
- int temp = drawMode;
14669
- drawMode = SELECTION;
16778
+ int temp = DrawMode();
16779
+ Globals.drawMode = SELECTION; // WARNING
1467016780 indexcount = 0;
1467116781 parent.display(drawable);
1467216782 //selection_view = tmp;
1467316783 //if (temp == SELECTION)
1467416784 // temp = DEFAULT; // patch for selection debug
14675
- drawMode = temp;
16785
+ Globals.drawMode = temp; // WARNING
1467616786
16787
+ if (PAINTMODE)
16788
+ {
16789
+ if (object.GetWindow().copy.selection.Size() > 0)
16790
+ {
16791
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16792
+
16793
+ // Revert.
16794
+ paintobj.RestoreSelectable();
16795
+ }
16796
+ }
16797
+
1467716798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1467816799
1467916800 // trying different ways of getting the depth info over
....@@ -14721,6 +16842,8 @@
1472116842 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1472216843 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1472316844 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16845
+
16846
+ CreateSelectedPoint();
1472416847
1472516848 // Will fit the mesh !!!
1472616849 selectedpoint.toParent[0][0] = 0.0001;
....@@ -14770,34 +16893,36 @@
1477016893 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]));
1477116894 }
1477216895
14773
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
16896
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1477416897 }
1477516898 }
1477616899
1477716900 if (!movingcamera && !PAINTMODE)
14778
- object.editWindow.ScreenFitPoint(); // fev 2014
16901
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1477916902
14780
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16903
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1478116904 {
14782
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16905
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1478316906
14784
- Object3D group = new Object3D("inst" + paintcount++);
16907
+ if (object.GetWindow().copy.selection.Size() > 0)
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1478516910
14786
- group.CreateMaterial(); // use a void leaf to select instances
14787
-
14788
- group.add(paintobj); // link
14789
-
14790
- object.editWindow.SnapObject(group);
14791
-
14792
- Object3D folder = object.editWindow.copy;
14793
-
14794
- if (object.editWindow.copy.selection.Size() > 0)
14795
- folder = object.editWindow.copy.selection.elementAt(0);
14796
-
14797
- folder.add(group);
14798
-
14799
- object.editWindow.ResetModel();
14800
- object.editWindow.refreshContents();
16911
+ Object3D inst = new Object3D("inst" + paintcount++);
16912
+
16913
+ inst.CreateMaterial(); // use a void leaf to select instances
16914
+
16915
+ inst.add(paintobj); // link
16916
+
16917
+ object.GetWindow().SnapObject(inst);
16918
+
16919
+ Object3D folder = paintFolder; // GetFolder();
16920
+
16921
+ folder.add(inst);
16922
+
16923
+ object.GetWindow().ResetModel();
16924
+ object.GetWindow().refreshContents();
16925
+ }
1480116926 }
1480216927 else
1480316928 paintcount = 0;
....@@ -14836,6 +16961,11 @@
1483616961 //System.out.println("objects[color] = " + objects[color]);
1483716962 //objects[color].Select();
1483816963 indexcount = 0;
16964
+ ObjEditor window = object.GetWindow();
16965
+ if (window != null && deselect)
16966
+ {
16967
+ window.Select(null, deselect, true);
16968
+ }
1483916969 object.Select(color, deselect);
1484016970 }
1484116971
....@@ -14935,7 +17065,7 @@
1493517065 gl.glDisable(gl.GL_CULL_FACE);
1493617066 }
1493717067
14938
- if (!RENDERSHADOW)
17068
+ if (!Globals.RENDERSHADOW)
1493917069 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1494017070
1494117071 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14945,14 +17075,14 @@
1494517075 //gl.glColorMask(false, false, false, false);
1494617076
1494717077 //render_scene_from_light_view(gl, drawable, 0, 0);
14948
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17078
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1494917079 {
1495017080 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1495117081
14952
- int temp = drawMode;
14953
- drawMode = SHADOW;
17082
+ int temp = DrawMode();
17083
+ Globals.drawMode = SHADOW; // WARNING
1495417084 parent.display(drawable);
14955
- drawMode = temp;
17085
+ Globals.drawMode = temp; // WARNING
1495617086 }
1495717087
1495817088 gl.glCullFace(gl.GL_BACK);
....@@ -15005,7 +17135,6 @@
1500517135
1500617136 class AntialiasBuffer implements GLEventListener
1500717137 {
15008
-
1500917138 CameraPane parent = null;
1501017139
1501117140 AntialiasBuffer(CameraPane p)
....@@ -15115,13 +17244,19 @@
1511517244 gl.glFlush();
1511617245
1511717246 /**/
15118
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17247
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
1511917248
15120
- int[] pixels = occlusionsizebuffer.array();
17249
+ float[] pixels = occlusionsizebuffer.array();
1512117250
1512217251 double r = 0, g = 0, b = 0;
1512317252
1512417253 double count = 0;
17254
+
17255
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17256
+
17257
+ float mindepth = 1;
17258
+
17259
+ double FACTOR = 1;
1512517260
1512617261 for (int i = 0; i < pixels.length; i++)
1512717262 {
....@@ -15206,7 +17341,7 @@
1520617341
1520717342 double scale = ray.z; // 1; // cos
1520817343
15209
- int p = pixels[newindex];
17344
+ float depth = pixels[newindex];
1521017345
1521117346 /*
1521217347 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15230,10 +17365,23 @@
1523017365 scale = (1 - modu) * modv;
1523117366 */
1523217367
15233
- r += ((p >> 16) & 0xFF) * scale / 255;
15234
- g += ((p >> 8) & 0xFF) * scale / 255;
15235
- b += (p & 0xFF) * scale / 255;
17368
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17369
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17370
+ //b += (p & 0xFF) * scale / 255;
17371
+
17372
+ if (mindepth > depth)
17373
+ {
17374
+ mindepth = depth;
17375
+ }
1523617376
17377
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17378
+
17379
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17380
+
17381
+ r += factor * scale;
17382
+ g += factor * scale;
17383
+ b += factor * scale;
17384
+
1523717385 count += scale;
1523817386 }
1523917387
....@@ -15331,12 +17479,6 @@
1533117479 GLUT glut = new GLUT();
1533217480
1533317481
15334
- static final public int DEFAULT = 0;
15335
- static final public int SELECTION = 1;
15336
- static final public int SHADOW = 2;
15337
- static final public int OCCLUSION = 3;
15338
- static
15339
- public int drawMode = DEFAULT;
1534017482 public boolean spherical = false;
1534117483 static boolean DEBUG_OCCLUSION = false;
1534217484 static boolean DEBUG_SELECTION = false;
....@@ -15349,23 +17491,15 @@
1534917491 int AAbuffersize = 0;
1535017492
1535117493 //double[] selectedpoint = new double[3];
15352
- static Superellipsoid selectedpoint = new Superellipsoid();
17494
+ static Superellipsoid selectedpoint;
1535317495 static Sphere previousselectedpoint = null;
15354
- static Sphere debugpoint = new Sphere();
15355
- static Sphere debugpoint2 = new Sphere();
15356
- static Sphere debugpoint3 = new Sphere();
15357
- static Sphere debugpoint4 = new Sphere();
17496
+ static Sphere debugpointG;
17497
+ static Sphere debugpointP;
17498
+ static Sphere debugpointC;
17499
+ static Sphere debugpointR;
1535817500
1535917501 static Sphere debugpoints[] = new Sphere[8];
1536017502
15361
- static
15362
- {
15363
- for (int i=0; i<8; i++)
15364
- {
15365
- debugpoints[i] = new Sphere();
15366
- }
15367
- }
15368
-
1536917503 static void InitPoints(float radius)
1537017504 {
1537117505 for (int i=0; i<8; i++)
....@@ -15385,7 +17519,7 @@
1538517519 }
1538617520 }
1538717521
15388
- static void DrawPoints(CameraPane cpane)
17522
+ static void DrawPoints(iCameraPane cpane)
1538917523 {
1539017524 for (int i=0; i<8; i++) // first and last are red
1539117525 {
....@@ -15407,7 +17541,8 @@
1540717541 static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1540817542 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1540917543 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15410
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17544
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17545
+ static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
1541117546 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1541217547 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1541317548 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15416,10 +17551,11 @@
1541617551 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1541717552 // Depth buffer format
1541817553 //private int depth_format;
15419
- static public void NextIndex(Object3D o, GL gl)
17554
+
17555
+ public void NextIndex()
1542017556 {
1542117557 indexcount+=16;
15422
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17558
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1542317559 //objects[indexcount] = o;
1542417560 //System.out.println("indexcount = " + indexcount);
1542517561 }