Normand Briere
2019-07-27 1af7d3700724834e40ad8636bc9a56cdc3b19b15
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,10 +33,14 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
34
-class CameraPane extends GLCanvas implements Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
38
+class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
36
- static boolean DEBUG = false;
40
+ static cMaterial[] materialstack = new cMaterial[65536];
41
+ static boolean[] selectedstack = new boolean[65536];
42
+ static int materialdepth = 0;
43
+
3744 static boolean FRUSTUM = false; // still bogus true; // frustum culling
3845
3946 // camera change fix
....@@ -42,25 +49,40 @@
4249
4350 static int STEP = 1;
4451
45
- static boolean ONESTEP = false; // do LIVE once
46
-
47
- /**
48
- * @return the LIVE
49
- */
50
- public static boolean isLIVE()
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
5153 {
52
- return LIVE || ONESTEP;
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
5383 }
5484
55
- /**
56
- * @param aLIVE the LIVE to set
57
- */
58
- public static void setLIVE(boolean aLIVE)
59
- {
60
- LIVE = aLIVE;
61
- }
62
-
63
- /*static*/ boolean CULLFACE = false; // true;
85
+ /*static*/ private boolean CULLFACE = false; // true;
6486 /*static*/ boolean NEAREST = false; // true;
6587 /*static*/ boolean WIREFRAME = false; // true;
6688
....@@ -70,14 +92,12 @@
7092 static int CURRENTANTIALIAS = 0; // 1;
7193 /*static*/ boolean RENDERSHADOW = true;
7294 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
73
- static boolean ANIMATION = false;
74
- static String filename;
7595
7696 boolean DISPLAYTEXT = false;
7797 //boolean REDUCETEXTURE = true;
7898 boolean CACHETEXTURE = true;
7999 boolean CLEANCACHE = false; // true;
80
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
81101 boolean COMPRESSTEXTURE = false;
82102 boolean KOMPACTTEXTURE = false; // true;
83103 boolean RESIZETEXTURE = false;
....@@ -97,10 +117,8 @@
97117
98118 static boolean textureon = true;
99119 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101120 static boolean FULLSCREEN = false;
102121 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104122 static boolean INERTIA = true;
105123 static boolean FAST = false;
106124 static boolean SLOWPOSE = false;
....@@ -108,6 +126,8 @@
108126
109127 static int tickcount = 0; // slow pose issue
110128
129
+static boolean BUTTONLESSWHEEL = false;
130
+static boolean ZOOMBOXMODE = false;
111131 static boolean BOXMODE = false;
112132 static boolean IMAGEFLIP = false;
113133 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +142,7 @@
122142 static boolean OEIL = true;
123143 static boolean OEILONCE = false; // do oeilon then oeiloff
124144 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
126146 static boolean HANDLES = false; // selection doesn't work!!
127147 static boolean PAINTMODE = false;
128148
....@@ -165,12 +185,42 @@
165185 defaultcaps.setAccumBlueBits(16);
166186 defaultcaps.setAccumAlphaBits(16);
167187 }
168
- static CameraPane theRenderer;
169
-
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
170191 void SetAsGLRenderer(boolean b)
171192 {
172193 isRenderer = b;
173
- theRenderer = this;
194
+ Globals.theRenderer = this;
195
+ }
196
+
197
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
198
+ {
199
+ super(defaultcaps, null, withcontext?glcontext:null, null);
200
+
201
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
202
+ glcontext = getContext();
203
+
204
+ cameras = new Camera[2];
205
+ targetLookAts = new cVector[2];
206
+
207
+ SetCamera(cam);
208
+
209
+ // Warning: not used.
210
+ SetLight(new Camera(new cVector(15, 10, -20)));
211
+
212
+ object = o;
213
+
214
+ setBackground(Color.white);
215
+
216
+ addKeyListener(this);
217
+ addMouseListener(this);
218
+ addMouseMotionListener(this);
219
+ addMouseWheelListener(this);
220
+ //System.out.println("addGLEventListener: " + this);
221
+ addGLEventListener(this);
222
+
223
+// pingthread.start(); // may 2013
174224 }
175225
176226 static boolean AntialiasingEnabled()
....@@ -178,12 +228,53 @@
178228 return CURRENTANTIALIAS > 0;
179229 }
180230
181
- void ClearDepth()
231
+ /// INTERFACE
232
+
233
+ public javax.media.opengl.GL GetGL0()
234
+ {
235
+ return null;
236
+ }
237
+
238
+ public int GenList()
239
+ {
240
+ javax.media.opengl.GL gl = GetGL();
241
+ return gl.glGenLists(1);
242
+ }
243
+
244
+ public void NewList(int id)
245
+ {
246
+ javax.media.opengl.GL gl = GetGL();
247
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
248
+ }
249
+
250
+ public void CallList(int id)
251
+ {
252
+ javax.media.opengl.GL gl = GetGL();
253
+ gl.glCallList(id);
254
+ }
255
+
256
+ public void EndList()
257
+ {
258
+ javax.media.opengl.GL gl = GetGL();
259
+ gl.glEndList();
260
+ }
261
+
262
+ public boolean IsBoxMode()
263
+ {
264
+ return BOXMODE;
265
+ }
266
+
267
+ public boolean IsZoomBoxMode()
268
+ {
269
+ return ZOOMBOXMODE;
270
+ }
271
+
272
+ public void ClearDepth()
182273 {
183274 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184275 }
185276
186
- void DepthTest(boolean depthtest)
277
+ public void DepthTest(boolean depthtest)
187278 {
188279 if (depthtest)
189280 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +282,7 @@
191282 GetGL().glDepthFunc(GL.GL_ALWAYS);
192283 }
193284
194
- void DepthWrite(boolean depthwrite)
285
+ public void DepthWrite(boolean depthwrite)
195286 {
196287 if (depthwrite)
197288 GetGL().glDepthMask(true);
....@@ -199,12 +290,1616 @@
199290 GetGL().glDepthMask(false);
200291 }
201292
202
- void BackFaceCull(boolean bfc)
293
+ public void BackFaceCull(boolean bfc)
203294 {
204295 if (bfc)
205296 GetGL().glEnable(GetGL().GL_CULL_FACE);
206297 else
207298 GetGL().glDisable(GetGL().GL_CULL_FACE);
299
+ }
300
+
301
+ public boolean BackFaceCullMode()
302
+ {
303
+ return this.CULLFACE;
304
+ }
305
+
306
+ public boolean IsAmbientOcclusionOn()
307
+ {
308
+ return this.ambientOcclusion;
309
+ }
310
+
311
+ public boolean IsDebugSelection()
312
+ {
313
+ return DEBUG_SELECTION;
314
+ }
315
+
316
+ public boolean IsFrozen()
317
+ {
318
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
319
+
320
+ return !selectmode && cameracount == 0; // != 0;
321
+ }
322
+
323
+ // Currently in Globals
324
+ public int DrawMode()
325
+ {
326
+ return Globals.DrawMode();
327
+ }
328
+
329
+ public Camera EyeCamera()
330
+ {
331
+ return eyeCamera;
332
+ }
333
+
334
+ public Camera LightCamera()
335
+ {
336
+ return lightCamera;
337
+ }
338
+
339
+ public Camera ManipCamera()
340
+ {
341
+ return manipCamera;
342
+ }
343
+
344
+ public Camera RenderCamera()
345
+ {
346
+ return renderCamera;
347
+ }
348
+
349
+ public Camera[] Cameras()
350
+ {
351
+ return cameras;
352
+ }
353
+
354
+ public void PushMaterial(Object3D obj, boolean selected)
355
+ {
356
+ CameraPane display = this;
357
+ javax.media.opengl.GL gl = display.GetGL();
358
+ cMaterial material = obj.material;
359
+
360
+ if (material != null)
361
+ {
362
+ materialstack[materialdepth] = material;
363
+ selectedstack[materialdepth] = selected;
364
+ cStatic.objectstack[materialdepth++] = obj;
365
+ //System.out.println("material " + material);
366
+ //Applet3D.tracein(this, selected);
367
+ //display.vector2buffer = obj.projectedVertices;
368
+ if (obj instanceof Camera)
369
+ {
370
+ display.options1[0] = material.shift;
371
+ //System.out.println("shift " + material.shift);
372
+ display.options1[1] = material.lightarea;
373
+ display.options1[2] = material.shadowbias;
374
+ display.options1[3] = material.aniso;
375
+ display.options1[4] = material.anisoV;
376
+// System.out.println("display.options1[0] " + display.options1[0]);
377
+// System.out.println("display.options1[1] " + display.options1[1]);
378
+// System.out.println("display.options1[2] " + display.options1[2]);
379
+// System.out.println("display.options1[3] " + display.options1[3]);
380
+// System.out.println("display.options1[4] " + display.options1[4]);
381
+ display.options2[0] = material.opacity;
382
+ display.options2[1] = material.diffuse;
383
+ display.options2[2] = material.factor;
384
+// System.out.println("display.options2[0] " + display.options2[0]);
385
+// System.out.println("display.options2[1] " + display.options2[1]);
386
+// System.out.println("display.options2[2] " + display.options2[2]);
387
+
388
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
389
+// System.out.println("display.options3[0] " + display.options3[0]);
390
+// System.out.println("display.options3[1] " + display.options3[1]);
391
+// System.out.println("display.options3[2] " + display.options3[2]);
392
+ display.options4[0] = material.cameralight/0.2f;
393
+ display.options4[1] = material.subsurface;
394
+ display.options4[2] = material.sheen;
395
+// System.out.println("display.options4[0] " + display.options4[0]);
396
+// System.out.println("display.options4[1] " + display.options4[1]);
397
+// System.out.println("display.options4[2] " + display.options4[2]);
398
+
399
+ // if (display.CURRENTANTIALIAS > 0)
400
+ // display.options3[3] /= 4;
401
+
402
+ /*
403
+ System.out.println("Focus = " + display.options1[0]);
404
+ System.out.println("Aperture = " + display.options1[1]);
405
+ System.out.println("ShadowBlur = " + display.options1[2]);
406
+ System.out.println("Antialiasing = " + display.options1[3]);
407
+ System.out.println("Fog = " + display.options2[0]);
408
+ System.out.println("Intensity = " + display.options2[1]);
409
+ System.out.println("Elevation = " + display.options2[2]);
410
+ /**/
411
+ } else
412
+ {
413
+ DrawMaterial(material, selected, obj.projectedVertices);
414
+ }
415
+ } else
416
+ {
417
+ if (selected && CameraPane.flash)
418
+ {
419
+ display.modelParams4[1] = 100;
420
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
421
+ }
422
+ }
423
+ }
424
+
425
+ public void PushMaterial2(Object3D obj, boolean selected)
426
+ {
427
+ CameraPane display = this;
428
+ cMaterial material = obj.material;
429
+
430
+ if (material != null)
431
+ {
432
+ materialstack[materialdepth] = material;
433
+ selectedstack[materialdepth] = selected;
434
+ cStatic.objectstack[materialdepth++] = obj;
435
+ //System.out.println("material " + material);
436
+ //Applet3D.tracein("selected ", selected);
437
+ //display.vector2buffer = obj.projectedVertices;
438
+ display.DrawMaterial(material, selected, obj.projectedVertices);
439
+ }
440
+ }
441
+
442
+ public void PopMaterial(Object3D obj, boolean selected)
443
+ {
444
+ CameraPane display = this;
445
+ javax.media.opengl.GL gl = display.GetGL();
446
+ cMaterial material = obj.material;
447
+
448
+ //if (parent != null && parent.GetMaterial() != null)
449
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
450
+ if (material != null)
451
+ {
452
+ materialdepth -= 1;
453
+ if (materialdepth > 0)
454
+ {
455
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
456
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
457
+ }
458
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
459
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
460
+ {
461
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
462
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
463
+ }
464
+ }
465
+
466
+ public void PopMaterial2(Object3D obj)
467
+ {
468
+ CameraPane display = this;
469
+ cMaterial material = obj.material;
470
+
471
+ if (material != null)
472
+ {
473
+ materialdepth -= 1;
474
+ if (materialdepth > 0)
475
+ {
476
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
477
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
478
+ }
479
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
480
+ //else
481
+ //material.Draw(display, false);
482
+ }
483
+ }
484
+
485
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
486
+ {
487
+ CameraPane display = this;
488
+
489
+ if (pv.y == -10000 ||
490
+ qv.y == -10000 ||
491
+ rv.y == -10000)
492
+ return;
493
+
494
+// float b = f.nbiterations & 1;
495
+// float g = (f.nbiterations>>1) & 1;
496
+// float r = (f.nbiterations>>2) & 1;
497
+//
498
+// //if (f.weight == 10000)
499
+// //{
500
+// // r = 1; g = b = 0;
501
+// //}
502
+// //else
503
+// //{
504
+// // assert(f.weight < 10000);
505
+// r = g = b = (float)bRep.FaceWeight(f)*100;
506
+// if (r<0)
507
+// assert(r>=0);
508
+// //}
509
+
510
+ javax.media.opengl.GL gl = display.GetGL();
511
+
512
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
513
+
514
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
515
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
516
+ {
517
+ //gl.glBegin(gl.GL_TRIANGLES);
518
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
519
+ // TEST LIVE NORMALS && !obj.dontselect
520
+ ;
521
+ if (!hasnorm)
522
+ {
523
+ // System.out.println("Mesh normal");
524
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
525
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
526
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
527
+ LA.vecNormalize(obj.v2);
528
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
529
+ }
530
+
531
+ // P
532
+ float x = (float)pv.x;
533
+ float y = (float)pv.y;
534
+ float z = (float)pv.z;
535
+
536
+ if (hasnorm)
537
+ {
538
+// if (!pv.norm.normalized())
539
+// assert(pv.norm.normalized());
540
+
541
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
542
+ float nx = (float)pv.norm.x;
543
+ float ny = (float)pv.norm.y;
544
+ float nz = (float)pv.norm.z;
545
+
546
+ x += nx * obj.NORMALPUSH;
547
+ y += ny * obj.NORMALPUSH;
548
+ z += nz * obj.NORMALPUSH;
549
+
550
+ gl.glNormal3f(nx, ny, nz);
551
+ }
552
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
553
+ SetColor(obj, pv);
554
+ //gl.glColor4f(r, g, b, 1);
555
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
556
+ if (obj.flipV)
557
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
558
+ else
559
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
560
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
561
+
562
+ gl.glVertex3f(x, y, z);
563
+
564
+ // Q
565
+ x = (float)qv.x;
566
+ y = (float)qv.y;
567
+ z = (float)qv.z;
568
+
569
+// Print(pv);
570
+ if (hasnorm)
571
+ {
572
+// assert(qv.norm.normalized());
573
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
574
+ float nx = (float)qv.norm.x;
575
+ float ny = (float)qv.norm.y;
576
+ float nz = (float)qv.norm.z;
577
+
578
+ x += nx * obj.NORMALPUSH;
579
+ y += ny * obj.NORMALPUSH;
580
+ z += nz * obj.NORMALPUSH;
581
+
582
+ gl.glNormal3f(nx, ny, nz);
583
+ }
584
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
585
+ // boolean locked = false;
586
+ // float eps = 0.1f;
587
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
588
+
589
+ // int dot = 0; //*/ (int)f.dot;
590
+
591
+ // if ((dot&1) == 0)
592
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
593
+
594
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
595
+ if (obj.flipV)
596
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
597
+ else
598
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
599
+ // else
600
+ // {
601
+ // locked = true;
602
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
603
+ // }
604
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
605
+ SetColor(obj, qv);
606
+
607
+ gl.glVertex3f(x, y, z);
608
+ //gl.glColor4f(r, g, b, 1);
609
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
610
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
611
+// Print(qv);
612
+
613
+ // R
614
+ x = (float)rv.x;
615
+ y = (float)rv.y;
616
+ z = (float)rv.z;
617
+
618
+ if (hasnorm)
619
+ {
620
+// assert(rv.norm.normalized());
621
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
622
+ float nx = (float)rv.norm.x;
623
+ float ny = (float)rv.norm.y;
624
+ float nz = (float)rv.norm.z;
625
+
626
+ x += nx * obj.NORMALPUSH;
627
+ y += ny * obj.NORMALPUSH;
628
+ z += nz * obj.NORMALPUSH;
629
+
630
+ gl.glNormal3f(nx, ny, nz);
631
+ }
632
+
633
+ // if ((dot&4) == 0)
634
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
635
+
636
+ // if (wrap || !locked && (dot&8) != 0)
637
+ if (obj.flipV)
638
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
639
+ else
640
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
641
+ // else
642
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
643
+
644
+ // f.dot = dot;
645
+
646
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
647
+ SetColor(obj, rv);
648
+ //gl.glColor4f(r, g, b, 1);
649
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
650
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
651
+ gl.glVertex3f(x, y, z);
652
+// Print(rv);
653
+ //gl.glEnd();
654
+ }
655
+ else
656
+ {
657
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
658
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
659
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
660
+
661
+ }
662
+
663
+ if (false) // (attributes & WIREFRAME) != 0)
664
+ {
665
+ gl.glDisable(gl.GL_LIGHTING);
666
+
667
+ gl.glBegin(gl.GL_LINE_LOOP);
668
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
669
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
670
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
671
+ gl.glEnd();
672
+
673
+ gl.glEnable(gl.GL_LIGHTING);
674
+ }
675
+ }
676
+
677
+ /**
678
+ * <code>draw</code> renders a <code>TriMesh</code> object including
679
+ * it's normals, colors, textures and vertices.
680
+ *
681
+ * @see Renderer#draw(TriMesh)
682
+ * @param tris
683
+ * the mesh to render.
684
+ */
685
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
686
+ {
687
+ CameraPane display = this;
688
+
689
+ float r = display.modelParams0[0];
690
+ float g = display.modelParams0[1];
691
+ float b = display.modelParams0[2];
692
+ float opacity = display.modelParams5[1];
693
+
694
+ //final GL gl = GLU.getCurrentGL();
695
+ GL gl = display.GetGL(); // getGL();
696
+
697
+ FloatBuffer vertBuf = geo.vertBuf;
698
+
699
+ int v = vertBuf.capacity();
700
+
701
+ int count = 0;
702
+
703
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
704
+ gl.glEnable(gl.GL_CULL_FACE);
705
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
706
+ for (int i=0; i<v/3; i++)
707
+ {
708
+ int index3 = i*3;
709
+
710
+ if (geo.sizeBuf.get(index3+1) == 0)
711
+ continue;
712
+
713
+ count++;
714
+
715
+ int index4 = i*4;
716
+
717
+ float tx = vertBuf.get(index3);
718
+ float ty = vertBuf.get(index3+1);
719
+ float tz = vertBuf.get(index3+2);
720
+
721
+ // if (tx == 0 && ty == 0 && tz == 0)
722
+ // continue;
723
+
724
+ gl.glMatrixMode(gl.GL_TEXTURE);
725
+ gl.glPushMatrix();
726
+
727
+ float[] texmat = geo.texmat;
728
+ texmat[12] = texmat[13] = texmat[14] = i;
729
+
730
+ gl.glMultMatrixf(texmat, 0);
731
+
732
+ gl.glMatrixMode(gl.GL_MODELVIEW);
733
+ gl.glPushMatrix();
734
+
735
+ gl.glTranslatef(tx,ty,tz);
736
+
737
+ if (rotate)
738
+ gl.glRotatef(i, 0, 1, 0);
739
+
740
+ float size = geo.sizeBuf.get(index3) / 100;
741
+ gl.glScalef(size,size,size);
742
+
743
+ float cr = geo.colorBuf.get(index4);
744
+ float cg = geo.colorBuf.get(index4+1);
745
+ float cb = geo.colorBuf.get(index4+2);
746
+ float ca = geo.colorBuf.get(index4+3);
747
+
748
+ display.modelParams0[0] = r * cr;
749
+ display.modelParams0[1] = g * cg;
750
+ display.modelParams0[2] = b * cb;
751
+
752
+ display.modelParams5[1] = opacity * ca;
753
+
754
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
755
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
756
+
757
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
758
+ RandomNode.globalseed2 = RandomNode.globalseed;
759
+
760
+// gl.glColor4f(cr,cg,cb,ca);
761
+ // gl.glScalef(1024/16,1024/16,1024/16);
762
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
763
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
764
+ //gl.glTranslatef(-tx,-ty,-tz);
765
+ gl.glPopMatrix();
766
+
767
+ gl.glMatrixMode(gl.GL_TEXTURE);
768
+ gl.glPopMatrix();
769
+ }
770
+ // gl.glScalef(1024,1024,1024);
771
+ if (!cf)
772
+ gl.glDisable(gl.GL_CULL_FACE);
773
+
774
+ display.modelParams0[0] = r;
775
+ display.modelParams0[1] = g;
776
+ display.modelParams0[2] = b;
777
+
778
+ display.modelParams5[1] = opacity;
779
+
780
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
781
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
782
+
783
+ gl.glMatrixMode(gl.GL_MODELVIEW);
784
+
785
+// System.err.println("total = " + v/3 + "; displayed = " + count);
786
+ if (true)
787
+ return;
788
+
789
+//// if (!tris.predraw(this))
790
+//// {
791
+//// return;
792
+//// }
793
+//// if (Debug.stats)
794
+//// {
795
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
796
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
797
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
798
+//// }
799
+////
800
+//// if (tris.getDisplayListID() != -1)
801
+//// {
802
+//// renderDisplayList(tris);
803
+//// return;
804
+//// }
805
+////
806
+//// if (!generatingDisplayList)
807
+//// {
808
+//// applyStates(tris.states, tris);
809
+//// }
810
+//// if (Debug.stats)
811
+//// {
812
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
813
+//// }
814
+//// boolean transformed = doTransforms(tris);
815
+//
816
+// int glMode = GL.GL_TRIANGLES;
817
+// switch (getMode())
818
+// {
819
+// case Triangles:
820
+// glMode = GL.GL_TRIANGLES;
821
+// break;
822
+// case Strip:
823
+// glMode = GL.GL_TRIANGLE_STRIP;
824
+// break;
825
+// case Fan:
826
+// glMode = GL.GL_TRIANGLE_FAN;
827
+// break;
828
+// }
829
+//
830
+// if (!predrawGeometry(gl))
831
+// {
832
+// // make sure only the necessary indices are sent through on old
833
+// // cards.
834
+// IntBuffer indices = this.getIndexBuffer();
835
+// if (indices == null)
836
+// {
837
+// logger.severe("missing indices on geometry object: " + this.toString());
838
+// } else
839
+// {
840
+// indices.rewind();
841
+// indices.limit(this.getMaxIndex());
842
+//
843
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
844
+//
845
+// indices.clear();
846
+// }
847
+// } else
848
+// {
849
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
850
+// GL.GL_UNSIGNED_INT, 0);
851
+// }
852
+//
853
+//// postdrawGeometry(tris);
854
+//// if (transformed)
855
+//// {
856
+//// undoTransforms(tris);
857
+//// }
858
+////
859
+//// if (Debug.stats)
860
+//// {
861
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
862
+//// }
863
+//// tris.postdraw(this);
864
+ }
865
+
866
+ static Camera localcamera = new Camera();
867
+ static cVector from = new cVector();
868
+ static cVector to = new cVector();
869
+
870
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
871
+ {
872
+ CameraPane cp = this;
873
+
874
+ Camera keep = cp.RenderCamera();
875
+ cp.renderCamera = localcamera;
876
+
877
+ if (br.trimmed)
878
+ {
879
+ float[] colors = new float[br.positions.length / 3];
880
+
881
+ int i3 = 0;
882
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
883
+ {
884
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
885
+ continue;
886
+
887
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
888
+ to.set(br.positions[i3] + br.normals[i3],
889
+ br.positions[i3 + 1] + br.normals[i3 + 1],
890
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
891
+ LA.xformPos(from, transform, from);
892
+ LA.xformPos(to, transform, to); // RIGID ONLY
893
+ localcamera.setAim(from, to);
894
+
895
+ CameraPane.occlusionbuffer.display();
896
+
897
+ if (CameraPane.DEBUG_OCCLUSION)
898
+ cp.display(); // debug
899
+
900
+ colors[i] = cp.vertexOcclusion.r;
901
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
902
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
903
+
904
+ if ((i % 100) == 0 && i != 0)
905
+ {
906
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
907
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
908
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
909
+ }
910
+ }
911
+
912
+ br.colors = colors;
913
+ }
914
+ else
915
+ {
916
+ for (int i = 0; i < br.VertexCount(); i++)
917
+ {
918
+ Vertex v = br.GetVertex(i);
919
+
920
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
921
+ continue;
922
+
923
+ from.set(v.x, v.y, v.z);
924
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
925
+ LA.xformPos(from, transform, from);
926
+ LA.xformPos(to, transform, to); // RIGID ONLY
927
+ localcamera.setAim(from, to);
928
+
929
+ CameraPane.occlusionbuffer.display();
930
+
931
+ if (CameraPane.DEBUG_OCCLUSION)
932
+ cp.display(); // debug
933
+
934
+ v.AO = cp.vertexOcclusion.r;
935
+
936
+ if ((i % 100) == 0 && i != 0)
937
+ {
938
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
939
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
940
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
941
+ }
942
+ }
943
+ }
944
+
945
+ //System.out.println("done.");
946
+
947
+ cp.renderCamera = keep;
948
+ }
949
+
950
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
951
+ {
952
+ CameraPane display = this;
953
+ pointFlow.CreateHT();
954
+
955
+ float r = display.modelParams0[0];
956
+ float g = display.modelParams0[1];
957
+ float b = display.modelParams0[2];
958
+ float opacity = display.modelParams5[1];
959
+
960
+ //final GL gl = GLU.getCurrentGL();
961
+ GL gl = display.GetGL(); // getGL();
962
+
963
+ int s = pointFlow.points.size();
964
+
965
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
966
+ gl.glEnable(gl.GL_CULL_FACE);
967
+
968
+ for (int i=s; --i>=0;)
969
+ //for (int i=0; i<s; i++)
970
+ {
971
+ cVector v = pointFlow.points.get(i);
972
+
973
+ double mindist = Double.MAX_VALUE;
974
+
975
+ double size = pointFlow.minimumSize;
976
+
977
+ double distancenext = 0;
978
+
979
+ if (i > 0)
980
+ {
981
+ cVector w = pointFlow.points.get(i-1);
982
+
983
+ double dist = w.distance(v);
984
+
985
+ distancenext = dist;
986
+
987
+ if (mindist > dist)
988
+ {
989
+ mindist = dist;
990
+ size = mindist*pointFlow.resizefactor;
991
+ }
992
+ }
993
+
994
+ if (i < s-1)
995
+ {
996
+ cVector w = pointFlow.points.get(i+1);
997
+
998
+ double dist = w.distance(v);
999
+
1000
+ if (mindist > dist)
1001
+ {
1002
+ mindist = dist;
1003
+ size = mindist*pointFlow.resizefactor;
1004
+ }
1005
+ }
1006
+
1007
+ if (size < pointFlow.minimumSize)
1008
+ size = pointFlow.minimumSize;
1009
+ if (size > pointFlow.maximumSize)
1010
+ size = pointFlow.maximumSize;
1011
+
1012
+ double tx = v.x;
1013
+ double ty = v.y;
1014
+ double tz = v.z;
1015
+
1016
+ // if (tx == 0 && ty == 0 && tz == 0)
1017
+ // continue;
1018
+
1019
+ gl.glMatrixMode(gl.GL_TEXTURE);
1020
+ gl.glPushMatrix();
1021
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1022
+
1023
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1024
+
1025
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1026
+ gl.glPushMatrix();
1027
+
1028
+ gl.glTranslated(tx,ty,tz);
1029
+
1030
+ gl.glScaled(size,size,size);
1031
+
1032
+// float cr = colorBuf.get(index4);
1033
+// float cg = colorBuf.get(index4+1);
1034
+// float cb = colorBuf.get(index4+2);
1035
+// float ca = colorBuf.get(index4+3);
1036
+//
1037
+// display.modelParams0[0] = r * cr;
1038
+// display.modelParams0[1] = g * cg;
1039
+// display.modelParams0[2] = b * cb;
1040
+//
1041
+// display.modelParams5[1] = opacity * ca;
1042
+//
1043
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1044
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1045
+//
1046
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1047
+// RandomNode.globalseed2 = RandomNode.globalseed;
1048
+//
1049
+//// gl.glColor4f(cr,cg,cb,ca);
1050
+// // gl.glScalef(1024/16,1024/16,1024/16);
1051
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1052
+
1053
+ gl.glPopMatrix();
1054
+
1055
+ double step = size/4; //
1056
+
1057
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1058
+ continue;
1059
+
1060
+ int nbsteps = (int)(distancenext/step);
1061
+
1062
+ step = distancenext/nbsteps;
1063
+
1064
+ cVector next = pointFlow.points.get(i-1);
1065
+
1066
+ tmp.set(next);
1067
+ tmp.sub(v);
1068
+ tmp.normalize();
1069
+ tmp.mul(step);
1070
+
1071
+ // calculate next size
1072
+ mindist = Double.MAX_VALUE;
1073
+
1074
+ double nextsize = pointFlow.minimumSize;
1075
+
1076
+ if (i > 1)
1077
+ {
1078
+ cVector w = pointFlow.points.get(i-2);
1079
+
1080
+ double dist = w.distance(next);
1081
+
1082
+ if (mindist > dist)
1083
+ {
1084
+ mindist = dist;
1085
+ nextsize = mindist*pointFlow.resizefactor;
1086
+ }
1087
+ }
1088
+
1089
+ double dist = v.distance(next);
1090
+
1091
+ if (mindist > dist)
1092
+ {
1093
+ mindist = dist;
1094
+ nextsize = mindist*pointFlow.resizefactor;
1095
+ }
1096
+
1097
+ if (nextsize < pointFlow.minimumSize)
1098
+ nextsize = pointFlow.minimumSize;
1099
+ if (nextsize > pointFlow.maximumSize)
1100
+ nextsize = pointFlow.maximumSize;
1101
+ //
1102
+
1103
+ double count = 0;
1104
+
1105
+ while (distancenext > 0.000000001) // step
1106
+ {
1107
+ gl.glPushMatrix();
1108
+
1109
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1110
+
1111
+ double K = count/nbsteps;
1112
+
1113
+ double intersize = K*nextsize + (1-K)*size;
1114
+
1115
+ gl.glScaled(intersize,intersize,intersize);
1116
+
1117
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1118
+
1119
+ count++;
1120
+
1121
+ distancenext -= step;
1122
+
1123
+ gl.glPopMatrix();
1124
+ }
1125
+
1126
+ if (count != nbsteps)
1127
+ assert(count == nbsteps);
1128
+
1129
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1130
+ //gl.glTranslatef(-tx,-ty,-tz);
1131
+
1132
+ gl.glMatrixMode(gl.GL_TEXTURE);
1133
+ gl.glPopMatrix();
1134
+ }
1135
+
1136
+ if (!cf)
1137
+ gl.glDisable(gl.GL_CULL_FACE);
1138
+
1139
+// display.modelParams0[0] = r;
1140
+// display.modelParams0[1] = g;
1141
+// display.modelParams0[2] = b;
1142
+//
1143
+// display.modelParams5[1] = opacity;
1144
+//
1145
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1146
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1147
+
1148
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1149
+ }
1150
+
1151
+ public void DrawBox(cVector min, cVector max)
1152
+ {
1153
+ javax.media.opengl.GL gl = GetGL();
1154
+ gl.glBegin(gl.GL_LINES);
1155
+
1156
+ gl.glVertex3d(min.x, min.y, min.z);
1157
+ gl.glVertex3d(min.x, min.y, max.z);
1158
+ gl.glVertex3d(min.x, min.y, min.z);
1159
+ gl.glVertex3d(min.x, max.y, min.z);
1160
+ gl.glVertex3d(min.x, min.y, min.z);
1161
+ gl.glVertex3d(max.x, min.y, min.z);
1162
+
1163
+ gl.glVertex3d(max.x, max.y, max.z);
1164
+ gl.glVertex3d(min.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, max.y, max.z);
1166
+ gl.glVertex3d(max.x, min.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, max.z);
1168
+ gl.glVertex3d(max.x, max.y, min.z);
1169
+
1170
+ gl.glEnd();
1171
+ }
1172
+
1173
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1174
+ {
1175
+ int[] strips = bRep.getRawIndices();
1176
+
1177
+ javax.media.opengl.GL gl = GetGL();
1178
+
1179
+ // TRIANGLE STRIP ARRAY
1180
+ if (bRep.trimmed)
1181
+ {
1182
+ float[] v = bRep.getRawVertices();
1183
+ float[] n = bRep.getRawNormals();
1184
+ float[] c = bRep.getRawColors();
1185
+ float[] uv = bRep.getRawUVMap();
1186
+
1187
+ int count2 = 0;
1188
+ int count3 = 0;
1189
+
1190
+ if (n.length > 0)
1191
+ {
1192
+ for (int i = 0; i < strips.length; i++)
1193
+ {
1194
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1195
+
1196
+ /*
1197
+ boolean locked = false;
1198
+ float eps = 0.1f;
1199
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1200
+
1201
+ int dot = 0;
1202
+
1203
+ if ((dot&1) == 0)
1204
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1205
+
1206
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1207
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1208
+ else
1209
+ {
1210
+ locked = true;
1211
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1212
+ }
1213
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1214
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1215
+ if (hasnorm)
1216
+ {
1217
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1218
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1219
+ }
1220
+
1221
+ if ((dot&4) == 0)
1222
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1223
+
1224
+ if (wrap || !locked && (dot&8) != 0)
1225
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1226
+ else
1227
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1228
+
1229
+ f.dot = dot;
1230
+ */
1231
+
1232
+ if (!selectmode)
1233
+ {
1234
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1235
+ {
1236
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1237
+ } else
1238
+ {
1239
+ gl.glNormal3f(0, 0, 1);
1240
+ }
1241
+
1242
+ if (c != null)
1243
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1244
+ {
1245
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1246
+ }
1247
+ }
1248
+
1249
+ if (flipV)
1250
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1251
+ else
1252
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1253
+
1254
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1255
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1256
+
1257
+ count2 += 2;
1258
+ count3 += 3;
1259
+ if (!selectmode)
1260
+ {
1261
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1262
+ {
1263
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1264
+ } else
1265
+ {
1266
+ gl.glNormal3f(0, 0, 1);
1267
+ }
1268
+ if (c != null)
1269
+ {
1270
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1271
+ }
1272
+ }
1273
+
1274
+ if (flipV)
1275
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1276
+ else
1277
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1278
+
1279
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1280
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1281
+
1282
+ count2 += 2;
1283
+ count3 += 3;
1284
+ for (int j = 0; j < strips[i] - 2; j++)
1285
+ {
1286
+ //gl.glTexCoord2d(...);
1287
+ if (!selectmode)
1288
+ {
1289
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1290
+ {
1291
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1292
+ } else
1293
+ {
1294
+ gl.glNormal3f(0, 0, 1);
1295
+ }
1296
+ if (c != null)
1297
+ {
1298
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1299
+ }
1300
+ }
1301
+
1302
+ if (flipV)
1303
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1304
+ else
1305
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1306
+
1307
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1308
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1309
+
1310
+ count2 += 2;
1311
+ count3 += 3;
1312
+ }
1313
+
1314
+ gl.glEnd();
1315
+ }
1316
+ }
1317
+
1318
+ assert count3 == v.length;
1319
+ }
1320
+ else // !trimmed
1321
+ {
1322
+ int count = 0;
1323
+ for (int i = 0; i < strips.length; i++)
1324
+ {
1325
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1326
+
1327
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1328
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1329
+
1330
+ drawVertex(gl, p, flipV, selectmode);
1331
+ drawVertex(gl, q, flipV, selectmode);
1332
+
1333
+ for (int j = 0; j < strips[i] - 2; j++)
1334
+ {
1335
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1336
+
1337
+ // if (j%2 == 0)
1338
+ // drawFace(p, q, r, display, null);
1339
+ // else
1340
+ // drawFace(p, r, q, display, null);
1341
+
1342
+ // p = q;
1343
+ // q = r;
1344
+ drawVertex(gl, r, flipV, selectmode);
1345
+ }
1346
+
1347
+ gl.glEnd();
1348
+ }
1349
+ }
1350
+ }
1351
+
1352
+ static cSpring.Point3D temp = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1354
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1355
+
1356
+ public void DrawDynamicMesh(cMesh mesh)
1357
+ {
1358
+ GL gl = GetGL(); // getGL();
1359
+
1360
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1361
+
1362
+ gl.glDisable(gl.GL_LIGHTING);
1363
+
1364
+ gl.glLineWidth(1);
1365
+ gl.glColor3f(1,1,1);
1366
+ gl.glBegin(gl.GL_LINES);
1367
+ double scale = 0;
1368
+ int count = 0;
1369
+ for (int s=0; s<Phys.allSprings.size(); s++)
1370
+ {
1371
+ cSpring.Spring spring = Phys.allSprings.get(s);
1372
+ if(s == 0)
1373
+ {
1374
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1375
+ }
1376
+ if (mesh.showsprings)
1377
+ {
1378
+ temp.set(spring.a.position);
1379
+ temp.add(spring.b.position);
1380
+ temp.mul(0.5);
1381
+ temp2.set(spring.a.position);
1382
+ temp2.sub(spring.b.position);
1383
+ temp2.mul(spring.restLength/2);
1384
+ temp.sub(temp2);
1385
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1386
+ temp.add(temp2);
1387
+ temp.add(temp2);
1388
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1389
+ }
1390
+
1391
+ if (spring.isHandle)
1392
+ continue;
1393
+
1394
+ //if (scale < spring.restLength)
1395
+ scale += spring.restLength;
1396
+ count++;
1397
+ }
1398
+ gl.glEnd();
1399
+
1400
+ if (count == 0)
1401
+ scale = 0.01;
1402
+ else
1403
+ scale /= count * 3;
1404
+
1405
+ //scale = 0.25;
1406
+
1407
+ if (mesh.ShowInfo())
1408
+ {
1409
+ gl.glLineWidth(4);
1410
+ for (int s=0; s<Phys.allNodes.size(); s++)
1411
+ {
1412
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1413
+ if (node.mass == 0)
1414
+ continue;
1415
+
1416
+ int i = node.springs==null?-1:node.springs.size();
1417
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1418
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1419
+ //temp.normalize();
1420
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1421
+ gl.glBegin(gl.GL_LINES);
1422
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1423
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1424
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1425
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1426
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1427
+ gl.glEnd();
1428
+ }
1429
+
1430
+ gl.glLineWidth(8);
1431
+ for (int s=0; s<Phys.allNodes.size(); s++)
1432
+ {
1433
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1434
+
1435
+ if (node.springs != null)
1436
+ {
1437
+ for (int i=0; i<node.springs.size(); i+=1)
1438
+ {
1439
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1440
+
1441
+ int c = i+1;
1442
+ // c = node.springs.get(i).nbcopies;
1443
+
1444
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1445
+ gl.glBegin(gl.GL_LINES);
1446
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1447
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1448
+ gl.glEnd();
1449
+ }
1450
+ }
1451
+ }
1452
+
1453
+ gl.glLineWidth(1);
1454
+ }
1455
+
1456
+ gl.glEnable(gl.GL_LIGHTING);
1457
+ }
1458
+
1459
+ /// INTERFACE
1460
+
1461
+ public void StartTriangles()
1462
+ {
1463
+ javax.media.opengl.GL gl = GetGL();
1464
+ gl.glBegin(gl.GL_TRIANGLES);
1465
+ }
1466
+
1467
+ public void EndTriangles()
1468
+ {
1469
+ GetGL().glEnd();
1470
+ }
1471
+
1472
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1473
+ {
1474
+ if (!selectmode)
1475
+ {
1476
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1477
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1478
+
1479
+ if (flipV)
1480
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1481
+ else
1482
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1483
+ }
1484
+
1485
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1486
+ }
1487
+
1488
+ void SetColor(Object3D obj, Vertex p0)
1489
+ {
1490
+ CameraPane display = this;
1491
+ BoundaryRep bRep = obj.bRep;
1492
+
1493
+ if (RENDERPROGRAM == 0)
1494
+ {
1495
+ float r = 0;
1496
+ if (bRep != null)
1497
+ {
1498
+ if (bRep.stripified)
1499
+ {
1500
+ r = 1;
1501
+ }
1502
+ }
1503
+ float g = 0;
1504
+ if (bRep != null)
1505
+ {
1506
+ if (bRep.trimmed)
1507
+ {
1508
+ g = 1;
1509
+ }
1510
+ }
1511
+ float b = 0;
1512
+ if (obj.support != null && obj.link2master)
1513
+ {
1514
+ b = 1;
1515
+ }
1516
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1517
+ return;
1518
+ }
1519
+
1520
+ if (display.DrawMode() != CameraPane.SHADOW)
1521
+ return;
1522
+
1523
+ javax.media.opengl.GL gl = display.GetGL();
1524
+// if (true) return;
1525
+// float ao = p.AO;
1526
+//
1527
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1528
+// // ao = 1;
1529
+//
1530
+// gl.glColor4f(ao, ao, ao, 1);
1531
+
1532
+// CameraPane.selectedpoint.
1533
+// getAverage(cStatic.point1, true);
1534
+ if (CameraPane.pointflow == null) // !random) // live)
1535
+ {
1536
+ return;
1537
+ }
1538
+
1539
+ cStatic.point1.set(0,0,0);
1540
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1541
+
1542
+ cStatic.point1.sub(p0);
1543
+
1544
+
1545
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1546
+// {
1547
+// return;
1548
+// }
1549
+
1550
+ //if (true)
1551
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1552
+ {
1553
+ return;
1554
+ }
1555
+
1556
+ float[] colorV = new float[3];
1557
+
1558
+ if (false) // marked)
1559
+ {
1560
+ // debug rigging weights
1561
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1562
+ {
1563
+ float weight = p0.weights[object] / p0.totalweight;
1564
+
1565
+ // if (weight < 0.1)
1566
+ // {
1567
+ // assert(weight == 0);
1568
+ // continue;
1569
+ // }
1570
+
1571
+ if (p0.vertexlinks[object] == -1)
1572
+ continue;
1573
+
1574
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1575
+
1576
+ int color = //1 << object; //
1577
+ //p.vertexlinks.length;
1578
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1579
+ colorV[2] += (color & 1) * weight;
1580
+ colorV[1] += ((color & 2) >> 1) * weight;
1581
+ colorV[0] += ((color & 4) >> 2) * weight;
1582
+ }
1583
+ }
1584
+ else
1585
+ {
1586
+ if (obj.drawingstarted)
1587
+ {
1588
+ // find next point
1589
+ if (bRep.GetVertex(0).faceindices == null)
1590
+ {
1591
+ bRep.InitFaceIndices();
1592
+ }
1593
+
1594
+ double ymin = p0.y;
1595
+
1596
+ Vertex newp = p0;
1597
+
1598
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1599
+ {
1600
+ int fi = p0.faceindices[fii];
1601
+
1602
+ if (fi == -1)
1603
+ break;
1604
+
1605
+ Face f = bRep.GetFace(fi);
1606
+
1607
+ Vertex p = bRep.GetVertex(f.p);
1608
+ Vertex q = bRep.GetVertex(f.q);
1609
+ Vertex r = bRep.GetVertex(f.r);
1610
+
1611
+ int swap = (int)(Math.random()*3);
1612
+
1613
+// for (int s=swap; --s>=0;)
1614
+// {
1615
+// Vertex t = p;
1616
+// p = q;
1617
+// q = r;
1618
+// r = t;
1619
+// }
1620
+ if (ymin > p.y)
1621
+ {
1622
+ ymin = p.y;
1623
+ newp = p;
1624
+// break;
1625
+ }
1626
+ if (ymin > q.y)
1627
+ {
1628
+ ymin = q.y;
1629
+ newp = q;
1630
+// break;
1631
+ }
1632
+ if (ymin > r.y)
1633
+ {
1634
+ ymin = r.y;
1635
+ newp = r;
1636
+// break;
1637
+ }
1638
+ }
1639
+
1640
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1641
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1642
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1643
+
1644
+ obj.drawingstarted = false;
1645
+
1646
+ // return;
1647
+ }
1648
+
1649
+ if (false) // CameraPane.DRAW
1650
+ {
1651
+ p0.AO = colorV[0] = 2;
1652
+ colorV[1] = 2;
1653
+ colorV[2] = 2;
1654
+ }
1655
+
1656
+ CameraPane.pointflow.add(p0);
1657
+ CameraPane.pointflow.Touch();
1658
+ }
1659
+
1660
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1661
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1662
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1663
+ }
1664
+
1665
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1666
+ {
1667
+ CameraPane display = this;
1668
+ //new Exception().printStackTrace();
1669
+
1670
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1671
+ {
1672
+ return;
1673
+ }
1674
+
1675
+ javax.media.opengl.GL gl = display.GetGL();
1676
+
1677
+ //Color col = Color.getHSBColor(color,modulation,1);
1678
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1679
+ if (!material.multiply)
1680
+ {
1681
+ display.color = material.color;
1682
+ display.saturation = material.modulation;
1683
+ }
1684
+ else
1685
+ {
1686
+ display.color *= material.color*2;
1687
+ display.saturation *= material.modulation*2;
1688
+ }
1689
+
1690
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1691
+
1692
+ float[] colorV = Grafreed.colorV;
1693
+
1694
+ /**/
1695
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1696
+ {
1697
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1698
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1699
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1700
+ colorV[3] = 1; // material.opacity;
1701
+
1702
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1703
+ //System.out.println("Opacity = " + opacity);
1704
+
1705
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1706
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1707
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1708
+
1709
+ float amb = material.ambient;
1710
+ if (amb < material.cameralight)
1711
+ {
1712
+ amb = material.cameralight;
1713
+ }
1714
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1715
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1716
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1717
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1718
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1719
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1720
+
1721
+ /**/
1722
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1723
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1724
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1725
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1726
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1727
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1728
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1729
+ //System.out.println("shininess = " + colorV[0]);
1730
+ if (colorV[0] > 128)
1731
+ {
1732
+ colorV[0] = 128;
1733
+ }
1734
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1735
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1736
+ /**/
1737
+ }
1738
+ /**/
1739
+
1740
+ //selected = false;
1741
+ selected = selected && display.flash;
1742
+
1743
+ //display.modelParams0[0] = 0; // pigment.r;
1744
+ //display.modelParams0[1] = 0; // pigment.g;
1745
+ //display.modelParams0[2] = 0; // pigment.b;
1746
+ if (!material.multiply)
1747
+ {
1748
+ display.modelParams0[3] = material.metalness;
1749
+ display.modelParams1[0] = material.diffuse;
1750
+ display.modelParams1[1] = material.specular;
1751
+ display.modelParams1[2] = 1 / material.shininess;
1752
+ display.modelParams1[3] = material.shift;
1753
+ display.modelParams2[0] = material.ambient;
1754
+ display.modelParams2[1] = material.lightarea;
1755
+ //System.out.println("light area = " + lightarea);
1756
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1757
+ display.modelParams2[3] = material.velvet;
1758
+ display.modelParams3[0] = material.sheen;
1759
+ display.modelParams3[1] = material.subsurface;
1760
+ display.modelParams3[2] = material.bump; // backlit
1761
+ display.modelParams3[3] = material.aniso;
1762
+ display.modelParams4[0] = material.anisoV;
1763
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1764
+ //System.out.println("selected = " + selected);
1765
+ display.modelParams4[2] = material.diffuseness;
1766
+ display.modelParams4[3] = material.shadow;
1767
+ display.modelParams5[0] = material.texture;
1768
+ display.modelParams5[1] = material.opacity;
1769
+ display.modelParams5[2] = material.fakedepth;
1770
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1771
+ }
1772
+ else
1773
+ {
1774
+ display.modelParams0[3] *= material.metalness*2;
1775
+ display.modelParams1[0] *= material.diffuse*2;
1776
+ display.modelParams1[1] *= material.specular*2;
1777
+ display.modelParams1[2] *= material.shininess*2;
1778
+ display.modelParams1[3] *= material.shift*2;
1779
+ display.modelParams2[0] *= material.ambient*2;
1780
+ display.modelParams2[1] *= material.lightarea*2;
1781
+ display.modelParams2[2] *= material.factor*2;
1782
+ display.modelParams2[3] *= material.velvet*2;
1783
+ display.modelParams3[0] *= material.sheen*2;
1784
+ display.modelParams3[1] *= material.subsurface*2;
1785
+ display.modelParams3[2] *= material.bump*2;
1786
+ display.modelParams3[3] *= material.aniso*2;
1787
+ display.modelParams4[0] *= material.anisoV*2;
1788
+ display.modelParams4[1] *= material.cameralight*2;
1789
+ //System.out.println("selected = " + selected);
1790
+ display.modelParams4[2] *= material.diffuseness*2;
1791
+ display.modelParams4[3] *= material.shadow*2;
1792
+ display.modelParams5[0] *= material.texture*2;
1793
+ display.modelParams5[1] *= material.opacity*2;
1794
+ display.modelParams5[2] *= material.fakedepth*2;
1795
+ display.modelParams5[3] *= material.shadowbias*2;
1796
+ }
1797
+
1798
+ display.modelParams6[0] = 0;
1799
+ display.modelParams6[1] = 0;
1800
+ display.modelParams6[2] = 0;
1801
+ display.modelParams6[3] = 0;
1802
+
1803
+ display.modelParams7[0] = 0;
1804
+ display.modelParams7[1] = 1000;
1805
+ display.modelParams7[2] = 0;
1806
+ display.modelParams7[3] = 0;
1807
+
1808
+ //display.modelParams6[0] = 100; // criss de bug de bump
1809
+
1810
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1811
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1812
+ {
1813
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1814
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1815
+ if (extparams.length > 1)
1816
+ {
1817
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1818
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1819
+ if (extparams.length > 2)
1820
+ {
1821
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1822
+ float x = extparams[2].y / 1000.0f;
1823
+ //if (x == 0)
1824
+ // x = 1f;
1825
+ display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power
1826
+ if (extparams[2].y > 0)
1827
+ {
1828
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1829
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1830
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1831
+ }
1832
+ }
1833
+ }
1834
+ }
1835
+
1836
+ //if (display.modelParams6[2] != 0)
1837
+ /*
1838
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1839
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1840
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1841
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1842
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1843
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1844
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1845
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1846
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1847
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1848
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1849
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1850
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1851
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1852
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1853
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1854
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1855
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1856
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1857
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1858
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1859
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1860
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1861
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1862
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1863
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1864
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1865
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1866
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1867
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1868
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1869
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1870
+ /**/
1871
+ //assert (display.modelParams6[2] == 0);
1872
+
1873
+ //System.out.println("noise power = " + display.modelParams7[0]);
1874
+ //System.out.println("shadowbias = " + shadowbias);
1875
+
1876
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1877
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1878
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1879
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1880
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1881
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1882
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1883
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1884
+
1885
+ int mode = display.FP_SHADER;
1886
+
1887
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1888
+ {
1889
+ mode |= display.FP_ANISO;
1890
+ }
1891
+
1892
+ display.EnableProgram(mode);
1893
+
1894
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1895
+
1896
+ if (!material.multiply)
1897
+ {
1898
+ if (Globals.drawMode == CameraPane.SHADOW)
1899
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1900
+ else
1901
+ gl.glDepthMask(material.opacity >= 0.99);
1902
+ }
2081903 }
2091904
2101905 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,10 +1920,10 @@
2251920 currentGL.glMultMatrixd(model, 0);
2261921 }
2271922
228
- void PushMatrix(double[][] matrix, int count)
1923
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291924 {
2301925 matrixdepth++;
231
- // GraphreeD.tracein(matrix);
1926
+ // GrafreeD.tracein(matrix);
2321927 if (matrix == null)
2331928 return; // Identity
2341929
....@@ -253,13 +1948,13 @@
2531948
2541949 void PushMatrix(double[][] matrix)
2551950 {
256
- // GraphreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1951
+ // GrafreeD.tracein(matrix);
1952
+ PushMatrix(matrix, 1);
2581953 }
2591954
2601955 void PushMatrix()
2611956 {
262
- // GraphreeD.tracein(null);
1957
+ // GrafreeD.tracein(null);
2631958 if (matrixdepth++ < MAXSTACK - 1)
2641959 {
2651960 currentGL.glPushMatrix();
....@@ -270,11 +1965,11 @@
2701965
2711966 double[][] tmpmat = new double[4][4];
2721967
273
- void PopMatrix(double[][] inverse)
1968
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741969 {
2751970 --matrixdepth;
2761971
277
- // GraphreeD.traceout(inverse);
1972
+ // GrafreeD.traceout(inverse);
2781973 if (inverse == null)
2791974 return; // Identity
2801975
....@@ -292,7 +1987,7 @@
2921987
2931988 void PopMatrix()
2941989 {
295
- // GraphreeD.traceout(null);
1990
+ // GrafreeD.traceout(null);
2961991 // inverse == null??
2971992 if (--matrixdepth < MAXSTACK - 1)
2981993 {
....@@ -310,7 +2005,7 @@
3102005 PushTextureMatrix(matrix, 1);
3112006 }
3122007
313
- void PushTextureMatrix(double[][] matrix, int count)
2008
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142009 {
3152010 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162011
....@@ -324,7 +2019,7 @@
3242019 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252020 }
3262021
327
- void PopTextureMatrix(double[][] inverse)
2022
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282023 {
3292024 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302025 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2046,15 @@
3512046
3522047 static int camerachangeframe;
3532048
354
- boolean SetCamera(Camera cam)
2049
+ public boolean SetCamera(Camera cam)
3552050 {
3562051 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572052 // return false;
3582053
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2054
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602055 {
3612056 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2057
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632058 {
3642059 // refuse the camera change
3652060 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2062,7 @@
3672062 }
3682063 }
3692064
370
- camerachangeframe = framecount;
2065
+ camerachangeframe = Globals.framecount;
3712066
3722067 cam.hAspect = -1; // Read only
3732068
....@@ -398,7 +2093,7 @@
3982093 {
3992094 //System.err.println("Oeil on");
4002095 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2096
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022097 // object.editWindow.ScreenFit(trackedobject);
4032098 //pingthread.StepToTarget(true);
4042099 }
....@@ -407,8 +2102,8 @@
4072102 {
4082103 //System.err.println("Oeil on");
4092104 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2106
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122107 //pingthread.StepToTarget(true);
4132108 }
4142109
....@@ -471,39 +2166,12 @@
4712166 {
4722167 frozen ^= true;
4732168 // Weird...
474
- lighttouched = true;
2169
+ Globals.lighttouched = true;
4752170 }
4762171
4772172 void ToggleDL()
4782173 {
4792174 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GraphreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072175 }
5082176
5092177 void ToggleFullScreen()
....@@ -513,12 +2181,7 @@
5132181
5142182 void ToggleCrowd()
5152183 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2184
+ Globals.CROWD ^= true;
5222185 }
5232186
5242187 void ToggleLocal()
....@@ -526,62 +2189,89 @@
5262189 LOCALTRANSFORM ^= true;
5272190 }
5282191
529
- void ToggleFast()
2192
+ public void ToggleTexture()
2193
+ {
2194
+ textureon ^= true;
2195
+ }
2196
+
2197
+ public void ToggleLive()
2198
+ {
2199
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2200
+
2201
+ System.err.println("LIVE = " + Globals.isLIVE());
2202
+
2203
+ if (!Globals.isLIVE()) // save sound
2204
+ Grafreed.savesound = true; // wav.save();
2205
+ // else
2206
+ repaint(); // start loop // may 2013
2207
+ }
2208
+
2209
+ public void ToggleSupport()
2210
+ {
2211
+ SUPPORT ^= true;
2212
+ }
2213
+
2214
+ public void ToggleAbort()
2215
+ {
2216
+ ABORTMODE ^= true;
2217
+ }
2218
+
2219
+ public void ToggleInertia()
2220
+ {
2221
+ INERTIA ^= true;
2222
+ }
2223
+
2224
+ public void ToggleFast()
5302225 {
5312226 FAST ^= true;
5322227 }
5332228
534
- void ToggleSlowPose()
2229
+ public void ToggleSlowPose()
5352230 {
5362231 SLOWPOSE ^= true;
5372232 }
5382233
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2234
+ public void ToggleBoxMode()
5452235 {
5462236 BOXMODE ^= true;
5472237 }
5482238
549
- void ToggleSmoothFocus()
2239
+ public void ToggleZoomBoxMode()
2240
+ {
2241
+ ZOOMBOXMODE ^= true;
2242
+ }
2243
+
2244
+ public void ToggleSmoothFocus()
5502245 {
5512246 SMOOTHFOCUS ^= true;
5522247 }
5532248
554
- void ToggleImageFlip()
2249
+ public void ToggleImageFlip()
5552250 {
5562251 IMAGEFLIP ^= true;
5572252 }
5582253
559
- void ToggleSpeakerMocap()
2254
+ public void ToggleSpeakerMocap()
5602255 {
5612256 SPEAKERMOCAP ^= true;
5622257 }
5632258
564
- void ToggleSpeakerCamera()
2259
+ public void ToggleSpeakerCamera()
5652260 {
5662261 SPEAKERCAMERA ^= true;
5672262 }
5682263
569
- void ToggleSpeakerFocus()
2264
+ public void ToggleSpeakerFocus()
5702265 {
5712266 SPEAKERFOCUS ^= true;
5722267 }
5732268
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2269
+ public void ToggleFrustum()
5802270 {
5812271 FRUSTUM ^= true;
5822272 }
5832273
584
- void ToggleTrack()
2274
+ public void ToggleTrack()
5852275 {
5862276 TRACK ^= true;
5872277 if (TRACK)
....@@ -600,25 +2290,35 @@
6002290 repaint();
6012291 }
6022292
603
- void ToggleTrackOnce()
2293
+ public void ToggleTrackOnce()
6042294 {
6052295 TRACKONCE ^= true;
6062296 }
6072297
608
- void ToggleShadowTrack()
2298
+ public void ToggleShadowTrack()
6092299 {
6102300 SHADOWTRACK ^= true;
6112301 repaint();
6122302 }
6132303
614
- void ToggleOeil()
2304
+ public void ToggleOeil()
6152305 {
6162306 OEIL ^= true;
6172307 }
6182308
619
- void ToggleOeilOnce()
2309
+ public void ToggleOeilOnce()
6202310 {
6212311 OEILONCE ^= true;
2312
+ }
2313
+
2314
+ void ToggleFootContact()
2315
+ {
2316
+ FOOTCONTACT ^= true;
2317
+ }
2318
+
2319
+ void ToggleDebug()
2320
+ {
2321
+ Globals.DEBUG ^= true;
6222322 }
6232323
6242324 void ToggleLookAt()
....@@ -626,9 +2326,9 @@
6262326 LOOKAT ^= true;
6272327 }
6282328
629
- void ToggleRandom()
2329
+ void ToggleSwitch()
6302330 {
631
- RANDOM ^= true;
2331
+ SWITCH ^= true;
6322332 }
6332333
6342334 void ToggleHandles()
....@@ -636,10 +2336,17 @@
6362336 HANDLES ^= true;
6372337 }
6382338
2339
+ Object3D paintFolder;
2340
+
6392341 void TogglePaint()
6402342 {
6412343 PAINTMODE ^= true;
6422344 paintcount = 0;
2345
+
2346
+ if (PAINTMODE)
2347
+ {
2348
+ paintFolder = GetFolder();
2349
+ }
6432350 }
6442351
6452352 void SwapCamera(int a, int b)
....@@ -672,34 +2379,6 @@
6722379 //assert (cam.hAspect == 0);
6732380 cam.hAspect = 0;
6742381 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
7032382 }
7042383
7052384 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,39 +2438,59 @@
7592438
7602439 GL currentGL;
7612440
762
- GL GetGL()
2441
+ public GL GetGL() // INTERFACE
7632442 {
7642443 return currentGL;
7652444 }
766
-
2445
+
2446
+ static private BufferedImage CreateBim(TextureData texturedata)
2447
+ {
2448
+ Grafreed.Assert(texturedata != null);
2449
+
2450
+ int width = texturedata.getWidth();
2451
+ int height = texturedata.getHeight();
2452
+
2453
+ Buffer buffer = texturedata.getBuffer();
2454
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2455
+
2456
+ byte[] bytes = bytebuf.array();
2457
+
2458
+ return CreateBim(bytes, width, height);
2459
+ }
2460
+
7672461 /**/
7682462 class CacheTexture
7692463 {
7702464 com.sun.opengl.util.texture.Texture texture;
2465
+ com.sun.opengl.util.texture.TextureData texturedata;
2466
+
7712467 int resolution;
7722468
773
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7742470 {
775
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
7762473 resolution = res;
7772474 }
7782475 }
7792476 /**/
7802477
7812478 // TEXTURE static Texture texture;
782
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
783
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
784
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2481
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2482
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2483
+
7852484 int pigmentdepth = 0;
7862485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7872486 int bumpdepth = 0;
7882487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7892488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7902489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
791
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7922491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7932492
794
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7952494 {
7962495 TextureData texturedata = null;
7972496
....@@ -810,13 +2509,34 @@
8102509 if (bump)
8112510 texturedata = ConvertBump(texturedata, false);
8122511
813
- com.sun.opengl.util.texture.Texture texture =
814
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2512
+// com.sun.opengl.util.texture.Texture texture =
2513
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8152514
816
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
817
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2516
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8182517
819
- return texture;
2518
+ return texturedata;
2519
+ }
2520
+
2521
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2522
+ {
2523
+ TextureData texturedata = null;
2524
+
2525
+ try
2526
+ {
2527
+ texturedata =
2528
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2529
+ bim,
2530
+ true);
2531
+ } catch (Exception e)
2532
+ {
2533
+ throw new javax.media.opengl.GLException(e);
2534
+ }
2535
+
2536
+ if (bump)
2537
+ texturedata = ConvertBump(texturedata, false);
2538
+
2539
+ return texturedata;
8202540 }
8212541
8222542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1889,6 +3609,8 @@
18893609
18903610 System.out.println("LOADING TEXTURE : " + name);
18913611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
18923614 //
18933615 if (false) // compressbit > 0)
18943616 {
....@@ -1998,10 +3720,12 @@
19983720 */
19993721 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20003722 {
3723
+ int pixelformat = texturedata.getPixelFormat();
3724
+
20013725 int stride = 1;
2002
- if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
3726
+ if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
20033727 stride = 3;
2004
- if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
3728
+ if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
20053729 stride = 4;
20063730
20073731 int width = texturedata.getWidth();
....@@ -2591,6 +4315,7 @@
25914315
25924316 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25934317 {
4318
+ new Exception().printStackTrace();
25944319 System.exit(0);
25954320 com.sun.opengl.util.texture.Texture texture = null;
25964321
....@@ -6267,7 +7992,7 @@
62677992 return null;
62687993 }
62697994
6270
- void ReleaseTextures(cTexture tex)
7995
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62717996 {
62727997 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62737998 {
....@@ -6284,7 +8009,7 @@
62848009 String pigment = Object3D.GetPigment(tex);
62858010 String bump = Object3D.GetBump(tex);
62868011
6287
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62888013 {
62898014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62908015 // System.out.println("; bump = " + bump);
....@@ -6299,13 +8024,71 @@
62998024 pigment = null;
63008025 }
63018026
6302
- ReleaseTexture(bump, true);
6303
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
63048029 }
63058030
6306
- void ReleaseTexture(String tex, boolean bump)
8031
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63078032 {
6308
- if (// drawMode != 0 || /*tex == null ||*/
8033
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8034
+ {
8035
+ return;
8036
+ }
8037
+
8038
+ if (tex == null)
8039
+ {
8040
+ ReleaseTexture(null, false);
8041
+ return;
8042
+ }
8043
+
8044
+ String pigment = Object3D.GetPigment(tex);
8045
+
8046
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8047
+ {
8048
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8049
+ // System.out.println("; bump = " + bump);
8050
+ }
8051
+
8052
+ if (pigment.equals(""))
8053
+ {
8054
+ pigment = null;
8055
+ }
8056
+
8057
+ ReleaseTexture(tex, false);
8058
+ }
8059
+
8060
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8061
+ {
8062
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8063
+ {
8064
+ return;
8065
+ }
8066
+
8067
+ if (tex == null)
8068
+ {
8069
+ ReleaseTexture(null, true);
8070
+ return;
8071
+ }
8072
+
8073
+ String bump = Object3D.GetBump(tex);
8074
+
8075
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8076
+ {
8077
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8078
+ // System.out.println("; bump = " + bump);
8079
+ }
8080
+
8081
+ if (bump.equals(""))
8082
+ {
8083
+ bump = null;
8084
+ }
8085
+
8086
+ ReleaseTexture(tex, true);
8087
+ }
8088
+
8089
+ void ReleaseTexture(cTexture tex, boolean bump)
8090
+ {
8091
+ if (// DrawMode() != 0 || /*tex == null ||*/
63098092 ambientOcclusion ) // || !textureon)
63108093 {
63118094 return;
....@@ -6314,7 +8097,7 @@
63148097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63158098
63168099 if (tex != null)
6317
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63188101
63198102 // //assert( texture != null );
63208103 // if (texture == null)
....@@ -6331,7 +8114,7 @@
63318114 {
63328115 bumpdepth--;
63338116
6334
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8117
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63358118 if (bumpstack[bumpdepth] != (texture!=null?texture.texture:null))
63368119 {
63378120 // assert (bumpstack[bumpdepth] == texture);
....@@ -6361,7 +8144,7 @@
63618144 {
63628145 pigmentdepth--;
63638146
6364
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8147
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63658148 if (pigmentstack[pigmentdepth] != (texture!=null?texture.texture:null))
63668149 {
63678150 // assert (pigmentstack[pigmentdepth] == texture);
....@@ -6406,9 +8189,57 @@
64068189 }
64078190 }
64088191
6409
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8192
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64108193 {
6411
- if (// drawMode != 0 || /*tex == null ||*/
8194
+// if (// DrawMode() != 0 || /*tex == null ||*/
8195
+// ambientOcclusion ) // || !textureon)
8196
+// {
8197
+// return; // false;
8198
+// }
8199
+//
8200
+// if (tex == null)
8201
+// {
8202
+// BindTexture(null,false,resolution);
8203
+// BindTexture(null,true,resolution);
8204
+// return;
8205
+// }
8206
+//
8207
+// String pigment = Object3D.GetPigment(tex);
8208
+// String bump = Object3D.GetBump(tex);
8209
+//
8210
+// usedtextures.add(pigment);
8211
+// usedtextures.add(bump);
8212
+//
8213
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8214
+// {
8215
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8216
+// // System.out.println("; bump = " + bump);
8217
+// }
8218
+//
8219
+// if (bump.equals(""))
8220
+// {
8221
+// bump = null;
8222
+// }
8223
+// if (pigment.equals(""))
8224
+// {
8225
+// pigment = null;
8226
+// }
8227
+//
8228
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8229
+// BindTexture(pigment, false, resolution);
8230
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8231
+// BindTexture(bump, true, resolution);
8232
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8233
+//
8234
+// return; // true;
8235
+
8236
+ BindPigmentTexture(tex, resolution);
8237
+ BindBumpTexture(tex, resolution);
8238
+ }
8239
+
8240
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8241
+ {
8242
+ if (// DrawMode() != 0 || /*tex == null ||*/
64128243 ambientOcclusion ) // || !textureon)
64138244 {
64148245 return; // false;
....@@ -6417,17 +8248,47 @@
64178248 if (tex == null)
64188249 {
64198250 BindTexture(null,false,resolution);
6420
- BindTexture(null,true,resolution);
64218251 return;
64228252 }
64238253
64248254 String pigment = Object3D.GetPigment(tex);
8255
+
8256
+ usedtextures.add(tex);
8257
+
8258
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8259
+ {
8260
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8261
+ // System.out.println("; bump = " + bump);
8262
+ }
8263
+
8264
+ if (pigment.equals(""))
8265
+ {
8266
+ pigment = null;
8267
+ }
8268
+
8269
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8270
+ BindTexture(tex, false, resolution);
8271
+ }
8272
+
8273
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8274
+ {
8275
+ if (// DrawMode() != 0 || /*tex == null ||*/
8276
+ ambientOcclusion ) // || !textureon)
8277
+ {
8278
+ return; // false;
8279
+ }
8280
+
8281
+ if (tex == null)
8282
+ {
8283
+ BindTexture(null,true,resolution);
8284
+ return;
8285
+ }
8286
+
64258287 String bump = Object3D.GetBump(tex);
64268288
6427
- usedtextures.put(pigment, pigment);
6428
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
64298290
6430
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64318292 {
64328293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64338294 // System.out.println("; bump = " + bump);
....@@ -6437,43 +8298,94 @@
64378298 {
64388299 bump = null;
64398300 }
6440
- if (pigment.equals(""))
6441
- {
6442
- pigment = null;
6443
- }
64448301
6445
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6446
- BindTexture(pigment, false, resolution);
64478302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6448
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
64498304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
-
6451
- return; // true;
64528305 }
64538306
6454
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8307
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8308
+
8309
+ private boolean FileExists(String tex)
64558310 {
6456
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8311
+ if (missingTextures.contains(tex))
8312
+ {
8313
+ return false;
8314
+ }
8315
+
8316
+ boolean fileExists = new File(tex).exists();
8317
+
8318
+ if (!fileExists)
8319
+ {
8320
+ // If file exists, the "new File()" is not executed sgain
8321
+ missingTextures.add(tex);
8322
+ }
8323
+
8324
+ return fileExists;
8325
+ }
8326
+
8327
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8328
+ {
8329
+ CacheTexture texturecache = null;
64578330
64588331 if (tex != null)
64598332 {
6460
- String texname = tex;
8333
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8334
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64618335
6462
- String[] split = tex.split("Textures");
6463
- if (split.length > 1)
6464
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6465
- else
6466
- if (!texname.startsWith("/"))
6467
- texname = "/Users/nbriere/Textures/" + texname;
8336
+ if (texname.equals("") && texdata == null)
8337
+ {
8338
+ return null;
8339
+ }
8340
+
8341
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8342
+
8343
+// String[] split = tex.split("Textures");
8344
+// if (split.length > 1)
8345
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8346
+// else
8347
+// if (!texname.startsWith("/"))
8348
+// texname = "/Users/nbriere/Textures/" + texname;
8349
+ if (!FileExists(texname))
8350
+ {
8351
+ texname = fallbackTextureName;
8352
+ }
64688353
64698354 if (CACHETEXTURE)
6470
- texture = textures.get(texname); // TEXTURE CACHE
6471
-
6472
- TextureData texturedata = null;
6473
-
6474
- if (texture == null || texture.resolution < resolution)
64758355 {
6476
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8356
+ if (texdata == null)
8357
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8358
+ else
8359
+ texturecache = bimtextures.get(texdata);
8360
+ }
8361
+
8362
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8363
+ {
8364
+ TextureData texturedata = null;
8365
+
8366
+ if (texdata != null && textureon)
8367
+ {
8368
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8369
+
8370
+ try
8371
+ {
8372
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8373
+ }
8374
+ catch (Exception e)
8375
+ {
8376
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8377
+ }
8378
+
8379
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8380
+ bimtextures.put(texdata, texturecache);
8381
+
8382
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8383
+
8384
+ //Object bim2 = CreateBim(texturecache.texturedata);
8385
+ //bim2 = bim;
8386
+ }
8387
+ else
8388
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64778389 {
64788390 assert(!bump);
64798391 // if (bump)
....@@ -6484,19 +8396,23 @@
64848396 // }
64858397 // else
64868398 // {
6487
- texture = textures.get(tex);
6488
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
64898401 {
6490
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64918403 }
8404
+ else
8405
+ new Exception().printStackTrace();
64928406 // }
64938407 } else
6494
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64958409 {
64968410 assert(bump);
6497
- texture = textures.get(tex);
6498
- if (texture == null)
6499
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
8413
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ else
8415
+ new Exception().printStackTrace();
65008416 } else
65018417 {
65028418 //if (tex.equals("IMMORTAL"))
....@@ -6504,11 +8420,13 @@
65048420 // texture = GetResourceTexture("default.png");
65058421 //} else
65068422 //{
6507
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
65088424 {
6509
- texture = textures.get(tex);
6510
- if (texture == null)
6511
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8425
+ // texturecache = textures.get(texname); // suspicious
8426
+ if (texturecache == null)
8427
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8428
+ else
8429
+ new Exception().printStackTrace();
65128430 } else
65138431 {
65148432 if (textureon)
....@@ -6533,7 +8451,7 @@
65338451 }
65348452
65358453 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6536
- if (!new File(cachename).exists())
8454
+ if (!FileExists(cachename))
65378455 cachename = texname;
65388456 else
65398457 processbump = false; // don't process bump map again
....@@ -6555,7 +8473,7 @@
65558473 }
65568474
65578475 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6558
- if (!new File(cachename).exists())
8476
+ if (!FileExists(cachename))
65598477 cachename = texname;
65608478 else
65618479 processbump = false; // don't process bump map again
....@@ -6564,20 +8482,22 @@
65648482 texturedata = GetFileTexture(cachename, processbump, resolution);
65658483
65668484
6567
- if (texturedata != null)
6568
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8485
+ if (texturedata == null)
8486
+ throw new Exception();
8487
+
8488
+ texturecache = new CacheTexture(texturedata,resolution);
65698489 //texture = GetTexture(tex, bump);
65708490 }
65718491 }
65728492 //}
65738493 }
65748494
6575
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65768496 {
65778497 //return false;
65788498
65798499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6580
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65818501 {
65828502 // String ext = "_highres";
65838503 // if (REDUCETEXTURE)
....@@ -6594,52 +8514,17 @@
65948514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65958515 if (!cachefile.exists())
65968516 {
6597
- // cache to disk
6598
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6599
- //buffers[0].
6600
-
6601
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6602
- int[] pixels = new int[bytebuf.capacity()/3];
6603
-
6604
- // squared size heuristic...
6605
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
66068518 {
6607
- for (int i=pixels.length; --i>=0;)
6608
- {
6609
- int i3 = i*3;
6610
- pixels[i] = 0xFF;
6611
- pixels[i] <<= 8;
6612
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6613
- pixels[i] <<= 8;
6614
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6617
- }
6618
-
6619
- /*
6620
- int r=0,g=0,b=0,a=0;
6621
- for (int i=0; i<width; i++)
6622
- for (int j=0; j<height; j++)
6623
- {
6624
- int index = j*width+i;
6625
- int p = pixels[index];
6626
- a = ((p>>24) & 0xFF);
6627
- r = ((p>>16) & 0xFF);
6628
- g = ((p>>8) & 0xFF);
6629
- b = (p & 0xFF);
6630
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6631
- }
6632
- /**/
6633
- int width = (int)Math.sqrt(pixels.length); // squared
6634
- int height = width;
6635
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6636
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
66378521 ImageWriter writer = null;
66388522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66398523 if (iter.hasNext()) {
66408524 writer = (ImageWriter)iter.next();
66418525 }
6642
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
66438528 try
66448529 {
66458530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6656,16 +8541,20 @@
66568541 }
66578542 }
66588543 }
6659
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
66608547 //System.out.println("Texture = " + tex);
6661
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
66628549 {
6663
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
66648551 thetex.texture.disable();
66658552 thetex.texture.dispose();
6666
- textures.remove(texname);
8553
+ textures.remove(tex);
66678554 }
6668
- textures.put(texname, texture);
8555
+
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
66698558
66708559 // newtex = true;
66718560 }
....@@ -6681,28 +8570,76 @@
66818570 }
66828571 }
66838572
8573
+ return texturecache;
8574
+ }
8575
+
8576
+ static void EmbedTextures(cTexture tex)
8577
+ {
8578
+ if (tex.pigmentdata == null)
8579
+ {
8580
+ //String texname = Object3D.GetPigment(tex);
8581
+
8582
+ CacheTexture texturecache = texturepigment.get(tex);
8583
+
8584
+ if (texturecache != null)
8585
+ {
8586
+ tex.pw = texturecache.texturedata.getWidth();
8587
+ tex.ph = texturecache.texturedata.getHeight();
8588
+ tex.pigmentdata = //CompressJPEG(CreateBim
8589
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8590
+ ;
8591
+ //, tex.pw, tex.ph), 0.5f);
8592
+ }
8593
+ }
8594
+
8595
+ if (tex.bumpdata == null)
8596
+ {
8597
+ //String texname = Object3D.GetBump(tex);
8598
+
8599
+ CacheTexture texturecache = texturebump.get(tex);
8600
+
8601
+ if (texturecache != null)
8602
+ {
8603
+ tex.bw = texturecache.texturedata.getWidth();
8604
+ tex.bh = texturecache.texturedata.getHeight();
8605
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8606
+ }
8607
+ }
8608
+ }
8609
+
8610
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
8611
+ {
8612
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8613
+
66848614 if (bump)
66858615 {
6686
- // GraphreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
8616
+ // GrafreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
66878617 bumpstack[bumpdepth++] = texture!=null?texture.texture:null;
66888618 }
66898619 else
66908620 {
6691
- // GraphreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
8621
+ // GrafreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
66928622 pigmentstack[pigmentdepth++] = texture!=null?texture.texture:null;
66938623 }
66948624
66958625 return texture!=null?texture.texture:null;
66968626 }
66978627
6698
- boolean BindTexture(String tex, boolean bump, int resolution)
8628
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
8629
+ {
8630
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8631
+
8632
+ return texture!=null?texture.texturedata:null;
8633
+ }
8634
+
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
66998636 {
67008637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67018638 {
67028639 return false;
67038640 }
67048641
6705
- boolean newtex = false;
8642
+ //boolean newtex = false;
67068643
67078644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67088645
....@@ -6734,9 +8671,75 @@
67348671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67358672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67368673
6737
- return newtex;
8674
+ return true; // Warning: not used.
67388675 }
67398676
8677
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8678
+ {
8679
+ try
8680
+ {
8681
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8682
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8683
+ ImageWriter writer = writers.next();
8684
+
8685
+ ImageWriteParam param = writer.getDefaultWriteParam();
8686
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8687
+ param.setCompressionQuality(quality);
8688
+
8689
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8690
+ writer.setOutput(ios);
8691
+ writer.write(null, new IIOImage(image, null, null), param);
8692
+
8693
+ byte[] data = baos.toByteArray();
8694
+ writer.dispose();
8695
+ return data;
8696
+ }
8697
+ catch (Exception e)
8698
+ {
8699
+ e.printStackTrace();
8700
+ return null;
8701
+ }
8702
+ }
8703
+
8704
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8705
+ {
8706
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8707
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8708
+ ImageReader reader = writers.next();
8709
+
8710
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8711
+
8712
+ ImageReadParam param = reader.getDefaultReadParam();
8713
+ param.setDestination(bim);
8714
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8715
+
8716
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8717
+ reader.setInput(ios);
8718
+ BufferedImage bim2 = reader.read(0, param);
8719
+ reader.dispose();
8720
+
8721
+// WritableRaster raster = bim2.getRaster();
8722
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8723
+// byte[] bytes = data.getData();
8724
+//
8725
+// int[] pixels = new int[bytes.length/3];
8726
+// for (int i=pixels.length; --i>=0;)
8727
+// {
8728
+// int i3 = i*3;
8729
+// pixels[i] = 0xFF;
8730
+// pixels[i] <<= 8;
8731
+// pixels[i] |= bytes[i3+2] & 0xFF;
8732
+// pixels[i] <<= 8;
8733
+// pixels[i] |= bytes[i3+1] & 0xFF;
8734
+// pixels[i] <<= 8;
8735
+// pixels[i] |= bytes[i3] & 0xFF;
8736
+// }
8737
+//
8738
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8739
+
8740
+ return bim;
8741
+ }
8742
+
67408743 ShadowBuffer shadowPBuf;
67418744 AntialiasBuffer antialiasPBuf;
67428745 int MAXSTACK;
....@@ -7292,9 +9295,9 @@
72929295 static boolean occlusionInitialized = false;
72939296 boolean selection = false;
72949297 boolean pointselection = false;
7295
- /*static*/ boolean lighttouched = true;
9298
+ ///*static*/ boolean lighttouched = true;
72969299 boolean deselect;
7297
- boolean ambientOcclusion = false;
9300
+ private boolean ambientOcclusion = false;
72989301 static boolean flash = false;
72999302 /*static*/ boolean wait = false;
73009303 boolean displaydone = false; // after repaint() calls
....@@ -7424,6 +9427,8 @@
74249427 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74259428 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74269429 double scale = lightCamera.SCALE / lightCamera.Distance();
9430
+// PATCH FILLE AUX JEANS
9431
+ //scale *= lightCamera.shaper_fovy / 25;
74279432 gl.glScaled(2 * scale, 2 * scale, -scale);
74289433 gl.glTranslated(0, 0, lightCamera.DECAL);
74299434
....@@ -7570,17 +9575,40 @@
75709575 jy8[3] = 0.5f;
75719576 }
75729577
7573
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9578
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75749579 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
7575
- float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
9580
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9581
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75769582
9583
+ void ResetOptions()
9584
+ {
9585
+ options1[0] = 100;
9586
+ options1[1] = 0.025f;
9587
+ options1[2] = 0.01f;
9588
+ options1[3] = 0;
9589
+ options1[4] = 0;
9590
+
9591
+ options2[0] = 0;
9592
+ options2[1] = 0.75f;
9593
+ options2[2] = 0;
9594
+ options2[3] = 0;
9595
+
9596
+ options3[0] = 1;
9597
+ options3[1] = 1;
9598
+ options3[2] = 1;
9599
+ options3[3] = 0;
9600
+
9601
+ options4[0] = 1;
9602
+ options4[1] = 0;
9603
+ options4[2] = 1;
9604
+ options4[3] = 0;
9605
+ }
9606
+
75779607 static int imagecount = 0; // movie generation
75789608
75799609 static int jitter = 0;
75809610
75819611 boolean restartframe = false;
7582
-
7583
- static int framecount = 0; // general-purpose global count
75849612
75859613 void displayAntiAliased(javax.media.opengl.GL gl)
75869614 {
....@@ -7610,14 +9638,14 @@
76109638
76119639 //System.out.println("start frame");
76129640 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
7613
- for (jitter = 0; jitter < ACSIZE; jitter++) //, GraphreeD.wav.cursor += LIVE ? 735 : 0)
9641
+ for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76149642 {
7615
- framecount++;
9643
+ Globals.framecount++;
76169644
76179645 if (CameraPane.tickcount > 0)
76189646 CameraPane.tickcount--;
76199647
7620
-// GraphreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
9648
+// GrafreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
76219649 // restartframe = true;
76229650 if (options1[2] > 100 && (jitter%2==0))
76239651 {
....@@ -7650,7 +9678,7 @@
76509678
76519679 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76529680 */
7653
- lighttouched = true;
9681
+ Globals.lighttouched = true;
76549682 //System.err.println(" shadowbuffer: " + jitter);
76559683 shadowbuffer.display();
76569684
....@@ -7671,8 +9699,8 @@
76719699 assert (parentcam != renderCamera);
76729700
76739701 if (renderCamera != lightCamera)
7674
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7675
- LA.matConcat(parentcam.toParent, matrix, matrix);
9702
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76769704
76779705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76789706
....@@ -7687,8 +9715,8 @@
76879715 LA.matCopy(renderCamera.fromScreen, matrix);
76889716
76899717 if (renderCamera != lightCamera)
7690
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7691
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9718
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
76929720
76939721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
76949722
....@@ -7760,7 +9788,7 @@
77609788 //gl.glFlush();
77619789 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77629790
7763
- if (ANIMATION && ABORTED)
9791
+ if (Globals.ANIMATION && ABORTED)
77649792 {
77659793 System.err.println(" ABORTED FRAME");
77669794 break;
....@@ -7790,7 +9818,7 @@
77909818 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
77919819
77929820 // save image
7793
- if (ANIMATION && !ABORTED)
9821
+ if (Globals.ANIMATION && !ABORTED)
77949822 {
77959823 VPwidth = viewport[2];
77969824 VPheight = viewport[3];
....@@ -7901,11 +9929,11 @@
79019929
79029930 // imagecount++;
79039931
7904
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9932
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79059933
79069934 if (!BOXMODE)
79079935 {
7908
- System.out.println("image: " + fullname + " (" + (GraphreeD.wav.cursor / 735 / 4) + ")");
9936
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79099937 }
79109938
79119939 if (!BOXMODE)
....@@ -7933,7 +9961,7 @@
79339961 {
79349962 if (ACSIZE > 1)
79359963 {
7936
- // System.err.println("image #" + (GraphreeD.wav.cursor / 735 / 4));
9964
+ // System.err.println("image #" + (GrafreeD.wav.cursor / 735 / 4));
79379965 }
79389966 }
79399967
....@@ -7943,7 +9971,7 @@
79439971 ABORTED = false;
79449972 }
79459973 else
7946
- GraphreeD.wav.cursor += 735 * ACSIZE;
9974
+ Grafreed.wav.cursor += 735 * ACSIZE;
79479975
79489976 if (false)
79499977 {
....@@ -8597,13 +10625,6 @@
859710625 }
859810626 }
859910627
8600
- boolean IsFrozen()
8601
- {
8602
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8603
-
8604
- return !selectmode && cameracount == 0; // != 0;
8605
- }
8606
-
860710628 boolean niceon = false;
860810629 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
860910630 boolean currentlydrawing = false;
....@@ -8613,16 +10634,16 @@
861310634
861410635 public void display(GLAutoDrawable drawable)
861510636 {
8616
- if (GraphreeD.savesound && GraphreeD.hassound)
10637
+ if (Grafreed.savesound && Grafreed.hassound)
861710638 {
8618
- GraphreeD.wav.save();
8619
- GraphreeD.savesound = false;
8620
- GraphreeD.hassound = false;
10639
+ Grafreed.wav.save();
10640
+ Grafreed.savesound = false;
10641
+ Grafreed.hassound = false;
862110642 }
862210643 // if (DEBUG_SELECTION)
862310644 // {
8624
-// if (drawMode != SELECTION)
8625
-// drawMode = SELECTION;
10645
+// if (DrawMode() != SELECTION)
10646
+// DrawMode() = SELECTION;
862610647 // }
862710648
862810649 if (!isRenderer)
....@@ -8678,9 +10699,9 @@
867810699
867910700 //ANTIALIAS = 0;
868010701
8681
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10702
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
868210703 {
8683
- if (niceon || isLIVE())
10704
+ if (niceon || Globals.isLIVE())
868410705 {
868510706 //if(active == 0)
868610707 // antialiaser = null;
....@@ -8693,6 +10714,7 @@
869310714 ANTIALIAS = 0;
869410715 //System.out.println("RESTART");
869510716 AAtimer.restart();
10717
+ Globals.TIMERRUNNING = true;
869610718 }
869710719 }
869810720 }
....@@ -8705,7 +10727,7 @@
870510727 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
870610728 */
870710729
8708
- if (drawMode == DEFAULT)
10730
+ if (DrawMode() == DEFAULT)
870910731 {
871010732 currentlydrawing = true;
871110733 }
....@@ -8736,18 +10758,18 @@
873610758
873710759 // if(Applet3D.clipboard != null)
873810760 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8739
-//drawMode = SELECTION;
10761
+//DrawMode() = SELECTION;
874010762 indexcount = 0;
874110763
8742
- if (drawMode == OCCLUSION)
10764
+ if (DrawMode() == OCCLUSION)
874310765 {
8744
- drawMode = DEFAULT;
10766
+ Globals.drawMode = DEFAULT; // WARNING
874510767 ambientOcclusion = true;
874610768 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
874710769 Object3D theobject = object;
874810770 Object3D theparent = object.parent;
874910771 object.parent = null;
8750
- object = (Object3D)GraphreeD.clone(object);
10772
+ object = (Object3D)Grafreed.clone(object);
875110773 object.Stripify();
875210774 if (theobject.selection == null || theobject.selection.Size() == 0)
875310775 theobject.PreprocessOcclusion(this);
....@@ -8760,19 +10782,20 @@
876010782 ambientOcclusion = false;
876110783 }
876210784
8763
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10785
+ if (//Globals.lighttouched &&
10786
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
876410787 {
876510788 //if (RENDERSHADOW) // ?
876610789 if (!IsFrozen())
876710790 {
876810791 // dec 2012
8769
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10792
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
877010793 {
8771
- framecount++;
10794
+ Globals.framecount++;
877210795 shadowbuffer.display();
877310796 }
877410797 }
8775
- lighttouched = false; // ??
10798
+ Globals.lighttouched = false; // ??
877610799 //drawing = true;
877710800 //lighttouched = true;
877810801 }
....@@ -8793,9 +10816,9 @@
879310816 //eyeCamera.shaper_fovy = 1;
879410817 }
879510818
8796
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10819
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
879710820 {
8798
- //System.out.println("drawMode = " + drawMode);
10821
+ //System.out.println("DrawMode() = " + DrawMode());
879910822 vertexMode |= VP_PASS;
880010823 //vertexMode |= VP_PROJECTION;
880110824 if (!ambientOcclusion)
....@@ -8855,7 +10878,7 @@
885510878 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
885610879 //Camera lightcam = new Camera(light0);
885710880
8858
- if (drawMode == SHADOW)
10881
+ if (DrawMode() == SHADOW)
885910882 {
886010883 /*
886110884 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8893,8 +10916,8 @@
889310916
889410917 // if (parentcam != renderCamera) // not a light
889510918 if (cam != lightCamera)
8896
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8897
- LA.matConcat(parentcam.toParent, matrix, matrix);
10919
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
889810921
889910922 for (int j = 0; j < 4; j++)
890010923 {
....@@ -8908,8 +10931,8 @@
890810931
890910932 // if (parentcam != renderCamera) // not a light
891010933 if (cam != lightCamera)
8911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8912
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10934
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
891310936
891410937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
891510938
....@@ -8945,7 +10968,7 @@
894510968 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
894610969 } else
894710970 {
8948
- if (drawMode != DEFAULT)
10971
+ if (DrawMode() != DEFAULT)
894910972 {
895010973 gl.glClearColor(1, 1, 1, 0);
895110974 } // 1);
....@@ -9010,7 +11033,7 @@
901011033
901111034 fast &= !ambientOcclusion;
901211035
9013
- if (drawMode == DEFAULT)
11036
+ if (DrawMode() == DEFAULT)
901411037 {
901511038 //gl.glEnable(gl.GL_ALPHA_TEST);
901611039 //gl.glActiveTexture(GL.GL_TEXTURE0);
....@@ -9071,6 +11094,8 @@
907111094 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
907211095 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
907311096 double scale = lightCamera.SCALE / lightCamera.Distance();
11097
+// PATCH FILLE AUX JEANS
11098
+ //scale *= lightCamera.shaper_fovy / 25;
907411099 gl.glScaled(2 * scale, 2 * scale, -scale);
907511100 gl.glTranslated(0, 0, lightCamera.DECAL);
907611101
....@@ -9166,7 +11191,16 @@
916611191 // Bump noise
916711192 gl.glActiveTexture(GL.GL_TEXTURE6);
916811193 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9169
- BindTexture(NOISE_TEXTURE, false, 2);
11194
+
11195
+ try
11196
+ {
11197
+ BindTexture(NOISE_TEXTURE, false, 2);
11198
+ }
11199
+ catch (Exception e)
11200
+ {
11201
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11202
+ }
11203
+
917011204
917111205 gl.glActiveTexture(GL.GL_TEXTURE0);
917211206 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9189,9 +11223,9 @@
918911223
919011224 gl.glMatrixMode(GL.GL_MODELVIEW);
919111225
9192
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9193
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9194
-//gl.glEnable(gl.GL_MULTISAMPLE);
11226
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11227
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11228
+gl.glEnable(gl.GL_MULTISAMPLE);
919511229 } else
919611230 {
919711231 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9202,14 +11236,16 @@
920211236 //System.out.println("BLENDING ON");
920311237 gl.glEnable(GL.GL_BLEND);
920411238 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9205
-
11239
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
920611240 gl.glMatrixMode(gl.GL_PROJECTION);
920711241 gl.glLoadIdentity();
920811242
9209
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11243
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
921011244 {
921111245 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
921211246 double scale = lightCamera.SCALE / lightCamera.Distance();
11247
+// PATCH FILLE AUX JEANS
11248
+ //scale *= lightCamera.shaper_fovy / 25;
921311249 gl.glScaled(2 * scale, 2 * scale, -scale);
921411250 gl.glTranslated(0, 0, lightCamera.DECAL);
921511251 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9262,7 +11298,7 @@
926211298 //gl.glPushMatrix();
926311299 gl.glLoadIdentity();
926411300
9265
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11301
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
926611302 {
926711303 //LA.xformPos(light0, lightCamera.fromScreen, light);
926811304 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9289,8 +11325,8 @@
928911325 System.err.println("parentcam != renderCamera");
929011326
929111327 // if (cam != lightCamera)
9292
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9293
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11328
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11329
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
929411330 }
929511331
929611332 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9311,8 +11347,8 @@
931111347 if (true) // TODO
931211348 {
931311349 if (cam != lightCamera)
9314
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9315
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11350
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11351
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
931611352 }
931711353
931811354 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9349,7 +11385,7 @@
934911385 }
935011386
935111387 /**/
9352
- if (true) // drawMode == SELECTION) // != DEFAULT)
11388
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
935311389 gl.glDisable(gl.GL_LIGHTING);
935411390 else
935511391 gl.glEnable(gl.GL_LIGHTING);
....@@ -9361,12 +11397,13 @@
936111397
936211398 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
936311399 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11400
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
936411401
936511402 options2[0] *= renderCamera.Distance();
936611403
936711404 lightslot = 64;
936811405
9369
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11406
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
937011407 {
937111408 DrawLights(object);
937211409 }
....@@ -9377,7 +11414,7 @@
937711414 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
937811415 //System.out.println("fragmentMode = " + fragmentMode);
937911416
9380
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11417
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
938111418 {
938211419 /*
938311420 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9410,7 +11447,7 @@
941011447 }
941111448 }
941211449
9413
- if (drawMode == DEFAULT)
11450
+ if (DrawMode() == DEFAULT)
941411451 {
941511452 if (WIREFRAME && !ambientOcclusion)
941611453 {
....@@ -9428,7 +11465,7 @@
942811465 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
942911466 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
943011467
9431
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11468
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
943211469 {
943311470 if (vertexMode != 0) // && !fast)
943411471 {
....@@ -9448,7 +11485,7 @@
944811485 }
944911486 }
945011487
9451
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11488
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
945211489 {
945311490 //gl.glDepthFunc(GL.GL_LEQUAL);
945411491 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9456,27 +11493,24 @@
945611493
945711494 boolean texon = textureon;
945811495
9459
- if (RENDERPROGRAM > 0)
9460
- {
9461
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9462
- textureon = false;
9463
- }
11496
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11497
+ textureon = false;
11498
+
946411499 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
946511500 //System.out.println("ALLO");
946611501 gl.glColorMask(false, false, false, false);
946711502 DrawObject(gl);
9468
- if (RENDERPROGRAM > 0)
9469
- {
9470
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9471
- textureon = texon;
9472
- }
11503
+
11504
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11505
+ textureon = texon;
11506
+
947311507 gl.glColorMask(true, true, true, true);
947411508
947511509 gl.glDepthFunc(GL.GL_EQUAL);
9476
- //gl.glDepthMask(false);
11510
+ gl.glDepthMask(false);
947711511 }
947811512
9479
- if (false) // drawMode == SHADOW)
11513
+ if (false) // DrawMode() == SHADOW)
948011514 {
948111515 //SetColumnMajorData(cameraInverseTransform, view_1);
948211516 //System.out.println("light = " + cameraInverseTransform);
....@@ -9490,16 +11524,16 @@
949011524 //System.out.println("object = " + object);
949111525 if (!frozen && !imageLocked)
949211526 {
9493
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11527
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
949411528 {
949511529 displayAntiAliased(gl);
949611530 } else
949711531 {
949811532 programcount = 0;
9499
- int keepmode = drawMode;
11533
+ int keepmode = DrawMode();
950011534 // if (DEBUG_SELECTION)
950111535 // {
9502
-// drawMode = SELECTION;
11536
+// DrawMode() = SELECTION;
950311537 // }
950411538 // for point selection
950511539 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9509,10 +11543,10 @@
950911543 DrawObject(gl);
951011544
951111545 // jan 2013 System.err.println("RESET ABORT (display)");
9512
- // if (drawMode == DEFAULT)
11546
+ // if (DrawMode() == DEFAULT)
951311547 // ABORTED = false;
951411548 fullreset = false;
9515
- drawMode = keepmode;
11549
+ Globals.drawMode = keepmode; // WARNING
951611550 //System.out.println("PROGRAM SWITCH " + programcount);
951711551 }
951811552 }
....@@ -9520,11 +11554,11 @@
952011554 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
952111555 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
952211556
9523
- if (drawMode == DEFAULT)
11557
+ if (DrawMode() == DEFAULT)
952411558 {
952511559 ReleaseTexture(NOISE_TEXTURE, false);
952611560 }
9527
- //if (drawMode == DEFAULT)
11561
+ //if (DrawMode() == DEFAULT)
952811562 {
952911563
953011564 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9536,7 +11570,7 @@
953611570 //else
953711571 //gl.glDisable(gl.GL_TEXTURE_2D);
953811572 //gl.glPopMatrix();
9539
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11573
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
954011574 {
954111575 //new Exception().printStackTrace();
954211576 //System.out.println("Draw image " + width + ", " + height);
....@@ -9578,7 +11612,7 @@
957811612 //gl.glFlush();
957911613 }
958011614
9581
- if (flash && drawMode == DEFAULT)
11615
+ if (flash && DrawMode() == DEFAULT)
958211616 {
958311617 flash = false;
958411618 wait = true;
....@@ -9586,9 +11620,9 @@
958611620 }
958711621
958811622 //drawing = false;
9589
- //if(drawMode == DEFAULT)
11623
+ //if(DrawMode() == DEFAULT)
959011624 // niceon = false;
9591
- if (drawMode == DEFAULT)
11625
+ if (DrawMode() == DEFAULT)
959211626 {
959311627 currentlydrawing = false;
959411628 }
....@@ -9608,7 +11642,7 @@
960811642 repaint();
960911643 }
961011644
9611
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11645
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
961211646 repaint();
961311647
961411648 displaydone = true;
....@@ -9627,8 +11661,14 @@
962711661 {
962811662 renderpass++;
962911663 // System.out.println("Draw object... ");
11664
+ STEP = 1;
963011665 if (FAST) // in case there is no script
9631
- STEP = 16;
11666
+ STEP = 8;
11667
+
11668
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11669
+ {
11670
+ STEP *= 4;
11671
+ }
963211672
963311673 //object.FullInvariants();
963411674
....@@ -9642,23 +11682,44 @@
964211682 e.printStackTrace();
964311683 }
964411684
9645
- if (GraphreeD.RENDERME > 0)
9646
- GraphreeD.RENDERME--; // mechante magouille
11685
+ if (Grafreed.RENDERME > 0)
11686
+ Grafreed.RENDERME--; // mechante magouille
964711687
9648
- ONESTEP = false;
11688
+ Globals.ONESTEP = false;
964911689 }
965011690
965111691 static boolean zoomonce = false;
965211692
11693
+ static void CreateSelectedPoint()
11694
+ {
11695
+ if (selectedpoint == null)
11696
+ {
11697
+ debugpointG = new Sphere();
11698
+ debugpointP = new Sphere();
11699
+ debugpointC = new Sphere();
11700
+ debugpointR = new Sphere();
11701
+
11702
+ selectedpoint = new Superellipsoid();
11703
+
11704
+ for (int i=0; i<8; i++)
11705
+ {
11706
+ debugpoints[i] = new Sphere();
11707
+ }
11708
+ }
11709
+ }
11710
+
965311711 void DrawObject(GL gl, boolean draw)
965411712 {
11713
+ // To clear camera values
11714
+ ResetOptions();
11715
+
965511716 //System.out.println("DRAW OBJECT " + mouseDown);
9656
-// drawMode = SELECTION;
11717
+// DrawMode() = SELECTION;
965711718 //GL gl = getGL();
965811719 if ((TRACK || SHADOWTRACK) || zoomonce)
965911720 {
9660
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9661
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11722
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
966211723 pingthread.StepToTarget(true); // true);
966311724 // zoomonce = false;
966411725 }
....@@ -9678,9 +11739,9 @@
967811739 callist = gl.glGenLists(1);
967911740 }
968011741
9681
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11742
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
968211743
9683
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11744
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
968411745
968511746 if (!mainDL || !active || touched)
968611747 {
....@@ -9707,24 +11768,32 @@
970711768 PushMatrix(ClickInfo.matbuffer);
970811769 }
970911770
9710
- if (drawMode == 0)
11771
+ if (DrawMode() == 0)
971111772 {
971211773 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
971311774
971411775 usedtextures.clear();
971511776
9716
- BindTextures(DEFAULT_TEXTURES, 2);
11777
+ try
11778
+ {
11779
+ BindTextures(DEFAULT_TEXTURES, 2);
11780
+ }
11781
+ catch (Exception e)
11782
+ {
11783
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11784
+ }
971711785 }
971811786 //System.out.println("--> " + stackdepth);
9719
-// GraphreeD.traceon();
11787
+// GrafreeD.traceon();
972011788
972111789 // DRAW
972211790 object.draw(this, /*(Composite)*/ object, false, false);
972311791
9724
- if (drawMode == DEFAULT)
11792
+ if (DrawMode() == DEFAULT)
972511793 {
9726
- if (DEBUG)
11794
+ if (Globals.DEBUG)
972711795 {
11796
+ CreateSelectedPoint();
972811797 float radius = 0.05f;
972911798 if (selectedpoint.radius != radius)
973011799 {
....@@ -9732,69 +11801,104 @@
973211801 selectedpoint.radius = radius;
973311802 selectedpoint.recalculate();
973411803 selectedpoint.material = new cMaterial();
9735
- selectedpoint.material.color = 0.25f;
11804
+ selectedpoint.material.color = 0.15f; // Yellow
973611805 selectedpoint.material.modulation = 0.75f;
973711806
9738
- debugpoint.radius = radius;
9739
- debugpoint.recalculate();
9740
- debugpoint.material = new cMaterial();
9741
- debugpoint.material.color = 0.25f;
9742
- debugpoint.material.modulation = 0.75f;
11807
+ debugpointG.radius = radius;
11808
+ debugpointG.recalculate();
11809
+ debugpointG.material = new cMaterial();
11810
+ debugpointG.material.color = 0.25f; // Green
11811
+ debugpointG.material.modulation = 0.75f;
974311812
9744
- debugpoint2.radius = radius;
9745
- debugpoint2.recalculate();
9746
- debugpoint2.material = new cMaterial();
9747
- debugpoint2.material.color = 0.75f;
9748
- debugpoint2.material.modulation = 0.75f;
11813
+ debugpointP.radius = radius;
11814
+ debugpointP.recalculate();
11815
+ debugpointP.material = new cMaterial();
11816
+ debugpointP.material.color = 0.75f; // Purple
11817
+ debugpointP.material.modulation = 0.75f;
11818
+
11819
+ debugpointC.radius = radius;
11820
+ debugpointC.recalculate();
11821
+ debugpointC.material = new cMaterial();
11822
+ debugpointC.material.color = 0.5f; // Cyan
11823
+ debugpointC.material.modulation = 0.75f;
11824
+
11825
+ debugpointR.radius = radius;
11826
+ debugpointR.recalculate();
11827
+ debugpointR.material = new cMaterial();
11828
+ debugpointR.material.color = 0f; // Red
11829
+ debugpointR.material.modulation = 0.75f;
974911830
975011831 InitPoints(radius);
975111832 }
975211833 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9753
- //debugpoint.draw(this, /*(Composite)*/ null, false);
9754
- //debugpoint2.draw(this, /*(Composite)*/ null, false);
9755
- DrawPoints(this);
11834
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11835
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11836
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11837
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
11838
+ // DrawPoints(this);
975611839 }
975711840
975811841 // debugstuff.draw(this, /*(Composite)*/ null, false);
975911842 }
9760
-// GraphreeD.traceoff();
11843
+// GrafreeD.traceoff();
976111844 //System.out.println(stackdepth);
9762
- if (drawMode == 0)
11845
+ if (DrawMode() == 0)
976311846 {
976411847 ReleaseTextures(DEFAULT_TEXTURES);
976511848
976611849 if (CLEANCACHE)
9767
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
976811851 {
9769
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
977011853
977111854 // System.out.println("Texture --------- " + tex);
977211855
9773
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
977411857 continue;
977511858
9776
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
977711860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
977811862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9779
- textures.get(tex).texture.dispose();
9780
- textures.remove(tex);
11863
+ if (gettex != null)
11864
+ {
11865
+ gettex.texture.dispose();
11866
+ texturepigment.remove(tex);
11867
+ }
11868
+
11869
+ gettex = texturebump.get(tex);
11870
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11871
+ if (gettex != null)
11872
+ {
11873
+ gettex.texture.dispose();
11874
+ texturebump.remove(tex);
11875
+ }
978111876 }
978211877 }
978311878 }
978411879
978511880 checker = null;
978611881
9787
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11882
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
978811883 FindChecker(object);
978911884
9790
- if (checker != null && drawMode == DEFAULT)
11885
+ if (checker != null && DrawMode() == DEFAULT)
979111886 {
9792
- // BindTexture(IMMORTAL_TEXTURE);
11887
+ //BindTexture(IMMORTAL_TEXTURE);
11888
+ try
11889
+ {
11890
+ BindTextures(checker.GetTextures(), checker.texres);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + checker.GetTextures());
11895
+ }
979311896 // NEAREST
979411897 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
979511898 DrawChecker(gl);
979611899 //checker.Draw(this, null, false);
979711900 // ReleaseTexture(IMMORTAL_TEXTURE);
11901
+ ReleaseTextures(checker.GetTextures());
979811902 }
979911903
980011904 if (object.parent != null)
....@@ -9807,7 +11911,7 @@
980711911 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
980811912 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
980911913
9810
- if (DISPLAYTEXT && drawMode == DEFAULT)
11914
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
981111915 {
981211916 // Draw it once, then use the raster
981311917 Balloon(gl, balloon.createGraphics());
....@@ -9863,14 +11967,14 @@
986311967 int[] xs = new int[3];
986411968 int[] ys = new int[3];
986511969
9866
- void DrawString(Object3D obj) // String string)
11970
+ public void DrawString(Object3D obj) // String string) // INTERFACE
986711971 {
9868
- if (!DISPLAYTEXT || drawMode != DEFAULT)
11972
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
986911973 {
987011974 return;
987111975 }
987211976
9873
- String string = obj.GetToolTip();
11977
+ String string = obj.toString(); //.GetToolTip();
987411978
987511979 GL gl = GetGL();
987611980
....@@ -10187,8 +12291,8 @@
1018712291 //obj.TransformToWorld(light, light);
1018812292 for (int i = tp.size(); --i >= 0;)
1018912293 {
10190
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10191
- LA.xformPos(light, tp.get(i).toParent, light);
12294
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12295
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1019212296 }
1019312297
1019412298
....@@ -10205,8 +12309,8 @@
1020512309 parentcam = cameras[0];
1020612310 }
1020712311
10208
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10209
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12312
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12313
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1021012314
1021112315 LA.xformPos(light, renderCamera.toScreen, light);
1021212316
....@@ -10253,7 +12357,7 @@
1025312357 return;
1025412358 }
1025512359
10256
- if (obj instanceof CheckerIG)
12360
+ if (obj instanceof Checker)
1025712361 {
1025812362 checker = obj;
1025912363
....@@ -10297,7 +12401,74 @@
1029712401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1029812402
1029912403 String program =
12404
+ // Min shader
1030012405 "!!ARBfp1.0\n" +
12406
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12407
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12408
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12409
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12410
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12411
+ "PARAM light2cam0 = program.env[10];" +
12412
+ "PARAM light2cam1 = program.env[11];" +
12413
+ "PARAM light2cam2 = program.env[12];" +
12414
+ "TEMP temp;" +
12415
+ "TEMP light;" +
12416
+ "TEMP ndotl;" +
12417
+ "TEMP normal;" +
12418
+ "TEMP depth;" +
12419
+ "TEMP eye;" +
12420
+ "TEMP pos;" +
12421
+
12422
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12423
+ Normalize("normal") +
12424
+ "MOV light, state.light[0].position;" +
12425
+ "DP3 ndotl.x, light, normal;" +
12426
+
12427
+ // shadow
12428
+ "MOV pos, fragment.texcoord[1];" +
12429
+ "MOV temp, pos;" +
12430
+ ShadowTextureFetch("depth", "temp", "1") +
12431
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12432
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12433
+
12434
+ // No shadow when out of frustum
12435
+ //"SGE temp.y, depth.z, zero123.y;" +
12436
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12437
+
12438
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12439
+
12440
+ // Backlit
12441
+ "MOV pos.w, zero123.y;" +
12442
+ "DP4 eye.x, pos, light2cam0;" +
12443
+ "DP4 eye.y, pos, light2cam1;" +
12444
+ "DP4 eye.z, pos, light2cam2;" +
12445
+ Normalize("eye") +
12446
+
12447
+ "DP3 ndotl.y, -eye, normal;" +
12448
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12449
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12450
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12451
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12452
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12453
+
12454
+ "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12455
+
12456
+ // Pigment
12457
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12458
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12459
+ "MUL temp, temp, ndotl.x;" +
12460
+
12461
+ "MUL temp, temp, zero123.z;" +
12462
+
12463
+ //"MUL temp, temp, ndotl.y;" +
12464
+
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
12466
+ "MOV result.color, temp;" +
12467
+ "END";
12468
+
12469
+ String program2 =
12470
+ "!!ARBfp1.0\n" +
12471
+
1030112472 //"OPTION ARB_fragment_program_shadow;" +
1030212473 "PARAM light2cam0 = program.env[10];" +
1030312474 "PARAM light2cam1 = program.env[11];" +
....@@ -10325,11 +12496,13 @@
1032512496 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1032612497 "PARAM params7 = program.env[7];" + // noise power, opacity power
1032712498 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10328
- "PARAM options1 = program.env[62];" + // fog rgb color, image intensity
12499
+ "PARAM options1 = program.env[62];" + // fog rgb color
12500
+ "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
1032912501 "PARAM pointlight = program.env[127];" + // ...
1033012502 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1033112503 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1033212504 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12505
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1033312506 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1033412507 "PARAM ten = { 10, 10, 10, 1.0 };" +
1033512508 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10350,6 +12523,7 @@
1035012523 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1035112524 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1035212525 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12526
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1035312527 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1035412528 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1035512529 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10390,6 +12564,10 @@
1039012564 "TEMP R1;" +
1039112565 "TEMP R2;" +
1039212566 "TEMP R3;" +
12567
+ "TEMP min;" +
12568
+ "TEMP max;" +
12569
+ "TEMP average;" +
12570
+ "TEMP saturation;" +
1039312571 "TEMP keep1;" +
1039412572 "TEMP keep2;" +
1039512573 "TEMP keep3;" +
....@@ -10405,8 +12583,7 @@
1040512583 "TEMP shininess;" +
1040612584 "\n" +
1040712585 "MOV texSamp, one;" +
10408
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10409
-
12586
+
1041012587 "MOV mapgrid.x, one2048th.x;" +
1041112588 "MOV temp, fragment.texcoord[1];" +
1041212589 /*
....@@ -10427,20 +12604,20 @@
1042712604 "MUL temp, floor, mapgrid.x;" +
1042812605 //"TEX depth0, temp, texture[1], 2D;" +
1042912606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10430
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1043112608 "") +
1043212609 "ADD temp.x, temp.x, mapgrid.x;" +
1043312610 //"TEX depth1, temp, texture[1], 2D;" +
1043412611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10435
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1043612613 "") +
1043712614 "ADD temp.y, temp.y, mapgrid.x;" +
1043812615 //"TEX depth2, temp, texture[1], 2D;" +
10439
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1044012617 "SUB temp.x, temp.x, mapgrid.x;" +
1044112618 //"TEX depth3, temp, texture[1], 2D;" +
1044212619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10443
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1044412621 "") +
1044512622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1044612623 //"MOV params, material;" +
....@@ -10811,10 +12988,10 @@
1081112988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1081212989 "") +
1081312990
10814
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1081512992 "SUB temp.x, half.x, shadow.x;" +
10816
- "MOV temp.y, -params6.x;" +
10817
- "SLT temp.z, temp.y, zero.x;" +
12993
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12994
+ "SLT temp.z, temp.y, -one2048th.x;" +
1081812995 "SUB temp.y, one.x, temp.z;" +
1081912996 "MUL temp.x, temp.x, temp.y;" +
1082012997 "KIL temp.x;" +
....@@ -10920,10 +13097,42 @@
1092013097
1092113098 // skin?
1092213099 // Saturation for skin
10923
- /**/ // c'est ici
10924
- (Skinshader? "DP3 temp.x, final,one;" +
13100
+ /**/
13101
+ (Skinshader?
13102
+ "DP3 average.x, final,one;" +
13103
+ "MUL average, one3rd.xxxx,average.xxxx;" +
13104
+
13105
+ "MIN min.x, final.x,final.y;" +
13106
+ "MIN min.x, min.x,final.z;" +
13107
+
13108
+ "MAX max.x, final.x,final.y;" +
13109
+ "MAX max.x, max.x,final.z;" +
13110
+ "MOV max, max.xxxx;" +
13111
+
13112
+ "SUB saturation, max, final;" +
13113
+
13114
+ "ADD temp.x, max.x, one10th.x;" +
13115
+ "RCP temp.x, temp.x;" +
13116
+ "MUL temp.x, temp.x, half.x;" +
13117
+ "MUL saturation, saturation, temp.xxxx;" +
13118
+
13119
+ "DP3 ndotl.x, normald, light;" +
13120
+ "MAX ndotl.x, ndotl.x, -ndotl.x;" +
13121
+
13122
+ "SUB temp.x, one.x, ndotl.x;" +
13123
+ // Tuning for default skin
13124
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13125
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13126
+ "ADD temp.y, one.y, options2.y;" + // subsurface
13127
+ "MUL temp.x, temp.x, temp.y;" +
13128
+
13129
+ "MUL saturation, saturation, temp.xxxx;" +
13130
+ "SUB_SAT temp, max, saturation;" +
13131
+/**
13132
+ "DP3 temp.x, final,one;" +
1092513133 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10926
- "SUB temp, final,R2;" +
13134
+ "SUB temp, final, R2;" +
13135
+
1092713136 // using light angle
1092813137 "DP3 ndotl.x, normald,light;" +
1092913138 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10936,7 +13145,6 @@
1093613145 // using light intensity
1093713146 "MOV ndotl.z, R2.x;" +
1093813147 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10939
-
1094013148 // june 2014
1094113149 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1094213150 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10948,6 +13156,7 @@
1094813156 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1094913157
1095013158 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13159
+/**/
1095113160
1095213161 // "ADD final, R2,temp;" +
1095313162 "MOV final, temp;"
....@@ -11037,7 +13246,7 @@
1103713246 /**/
1103813247 // HDR
1103913248 "MOV temp.z, final.a;" +
11040
- "MUL final, final,options1.w;" +
13249
+ "MUL final, final,options2.x;" +
1104113250 "MOV final.a, temp.z;" +
1104213251 /**/
1104313252
....@@ -11074,10 +13283,17 @@
1107413283 "MOV final.z, zero.x;" +
1107513284 "MOV final.a, one.w;":""
1107613285 ) +
13286
+ /*
1107713287 (NORMALdebug?"MOV final.x, normal.x;" +
1107813288 "MOV final.y, normal.y;" +
1107913289 "MOV final.z, normal.z;" +
1108013290 "MOV final.a, one.w;":""
13291
+ ) +
13292
+ */
13293
+ (NORMALdebug?"SUB final.x, one.x, final.x;" +
13294
+ "SUB final.y, one.x, final.y;" +
13295
+ "SUB final.z, one.x, final.z;" +
13296
+ "MOV final.a, final.a;":""
1108113297 ) +
1108213298 // "MOV final, bumpmap;" +
1108313299 "MOV result.color, final;" +
....@@ -11106,7 +13322,7 @@
1110613322 //once = true;
1110713323 }
1110813324
11109
- System.out.print("Program #" + mode + "; length = " + program.length());
13325
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1111013326 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1111113327 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1111213328
....@@ -11199,30 +13415,32 @@
1119913415 return out;
1120013416 }
1120113417
11202
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1120313420 {
1120413421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1120513422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1120613423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1120713426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11208
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11209
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11210
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11211
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1121213429 //"SWZ buffer, temp, w,w,w,w;";
11213
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1121413431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1121513432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1121613433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11217
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1121813435
11219
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11220
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13436
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13437
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1122113438 }
1122213439
1122313440 String Shadow(String depth, String shadow)
1122413441 {
1122513442 return "MAX temp.x, ndotl.x, one64th.x;" +
13443
+ "MIN temp.x, temp.x, ninetenth.x;" +
1122613444 /**/
1122713445 // Sine
1122813446 "MUL temp.y, temp.x, temp.x;" +
....@@ -11238,12 +13456,16 @@
1123813456
1123913457 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1124013458 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13459
+
13460
+ // Compare fragment depth in light space with shadowmap.
1124113461 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1124213462 "SGE temp.y, temp.x, zero.x;" +
11243
- "SUB " + shadow + ".y, one.x, temp.y;" +
13463
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13464
+
13465
+ // Reverse comparison
1124413466 "SUB temp.x, one.x, temp.x;" +
1124513467 "MUL " + shadow + ".x, temp.x, temp.y;" +
11246
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13468
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1124713469 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1124813470
1124913471 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11257,6 +13479,10 @@
1125713479 // No shadow for backface
1125813480 "DP3 temp.x, normal, lightd;" +
1125913481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13482
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13483
+
13484
+ // No shadow when out of frustum
13485
+ "SGE temp.x, " + depth + ".z, one.z;" +
1126013486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1126113487 "";
1126213488 }
....@@ -11403,7 +13629,8 @@
1140313629 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1140413630 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1140513631 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11406
- Object3D.cVector2[] vector2buffer;
13632
+
13633
+ //Object3D.cVector2[] vector2buffer;
1140713634
1140813635 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1140913636 // OUT : diff, spec
....@@ -11419,9 +13646,10 @@
1141913646 "DP3 " + dest + ".z," + "normals," + "eye;" +
1142013647 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1142113648 //"MOV " + dest + ".w," + "normal.z;" +
11422
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11423
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11424
- //"MOV " + dest + ".z," + "params2.w;" +
13649
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13650
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13651
+
13652
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1142513653 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1142613654 "RCP " + dest + ".w," + dest + ".w;" +
1142713655 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11815,7 +14043,7 @@
1181514043 public void mousePressed(MouseEvent e)
1181614044 {
1181714045 //System.out.println("mousePressed: " + e);
11818
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14046
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1181914047 }
1182014048
1182114049 static long prevtime = 0;
....@@ -11842,14 +14070,16 @@
1184214070
1184314071 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1184414072
14073
+ if (BUTTONLESSWHEEL)
1184514074 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1184614075 {
1184714076 return;
1184814077 }
1184914078
14079
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1185014080
1185114081 // TIMER
11852
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14082
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1185314083 {
1185414084 keepboxmode = BOXMODE;
1185514085 keepsupport = SUPPORT;
....@@ -11889,8 +14119,8 @@
1188914119 // mode |= META;
1189014120 //}
1189114121
11892
- SetMouseMode(WHEEL | e.getModifiersEx());
11893
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14122
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14123
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1189414124 anchorX = ax;
1189514125 anchorY = ay;
1189614126 prevX = px;
....@@ -11924,6 +14154,7 @@
1192414154 else
1192514155 if (evt.getSource() == AAtimer)
1192614156 {
14157
+ Globals.TIMERRUNNING = false;
1192714158 if (mouseDown)
1192814159 {
1192914160 //new Exception().printStackTrace();
....@@ -11949,6 +14180,10 @@
1194914180 // LIVE = waslive;
1195014181 // wasliveok = true;
1195114182 // waslive = false;
14183
+
14184
+ // May 2019 Forget it:
14185
+ if (true)
14186
+ return;
1195214187
1195314188 // source == timer
1195414189 if (mouseDown)
....@@ -11978,8 +14213,8 @@
1197814213 // ObjEditor.tweenManager.update(1f / 60f);
1197914214
1198014215 // fev 2014???
11981
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
11982
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14216
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14217
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1198314218 pingthread.StepToTarget(true); // true);
1198414219 }
1198514220 // if (!LIVE)
....@@ -11988,12 +14223,13 @@
1198814223
1198914224 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1199014225
11991
- void clickStart(int x, int y, int modifiers)
14226
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1199214227 {
1199314228 if (!wasliveok)
1199414229 return;
1199514230
1199614231 AAtimer.restart(); //
14232
+ Globals.TIMERRUNNING = true;
1199714233
1199814234 // waslive = LIVE;
1199914235 // LIVE = false;
....@@ -12005,7 +14241,7 @@
1200514241 // touched = true; // main DL
1200614242 if (isRenderer)
1200714243 {
12008
- SetMouseMode(modifiers);
14244
+ SetMouseMode(modifiers, modifiersex);
1200914245 }
1201014246
1201114247 selectX = anchorX = x;
....@@ -12018,7 +14254,7 @@
1201814254 clicked = true;
1201914255 hold = false;
1202014256
12021
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14257
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1202214258 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1202314259 {
1202414260 // System.out.println("RESTART II " + modifiers);
....@@ -12043,14 +14279,15 @@
1204314279 drag = false;
1204414280 //System.out.println("Mouse DOWN");
1204514281 editObj = false;
12046
- ClickInfo info = new ClickInfo();
12047
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12048
- info.pane = this;
12049
- info.camera = renderCamera;
12050
- info.x = x;
12051
- info.y = y;
12052
- info.modifiers = modifiers;
12053
- editObj = object.doEditClick(info, 0);
14282
+ //ClickInfo info = new ClickInfo();
14283
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14284
+ object.clickInfo.pane = this;
14285
+ object.clickInfo.camera = renderCamera;
14286
+ object.clickInfo.x = x;
14287
+ object.clickInfo.y = y;
14288
+ object.clickInfo.modifiers = modifiersex;
14289
+ editObj = object.doEditClick(//info,
14290
+ 0);
1205414291 if (!editObj)
1205514292 {
1205614293 hasMarquee = true;
....@@ -12066,11 +14303,14 @@
1206614303
1206714304 public void mouseDragged(MouseEvent e)
1206814305 {
14306
+ Globals.MOUSEDRAGGED = true;
14307
+
14308
+ //System.out.println("mouseDragged: " + e);
1206914309 if (isRenderer)
1207014310 movingcamera = true;
14311
+
1207114312 //if (drawing)
1207214313 //return;
12073
- //System.out.println("mouseDragged: " + e);
1207414314 if ((e.getModifiersEx() & CTRL) != 0
1207514315 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1207614316 {
....@@ -12078,7 +14318,7 @@
1207814318 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1207914319 }
1208014320 else
12081
- drag(e.getX(), e.getY(), e.getModifiersEx());
14321
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1208214322
1208314323 //try { Thread.sleep(1); } catch (Exception ex) {}
1208414324 }
....@@ -12090,6 +14330,11 @@
1209014330 cVector tmp = new cVector();
1209114331 cVector tmp2 = new cVector();
1209214332 boolean isMoving;
14333
+
14334
+ public cVector TargetLookAt()
14335
+ {
14336
+ return targetLookAt;
14337
+ }
1209314338
1209414339 class PingThread extends Thread
1209514340 {
....@@ -12229,7 +14474,7 @@
1222914474 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1223014475 if (lightMode)
1223114476 {
12232
- lighttouched = true;
14477
+ Globals.lighttouched = true;
1223314478 }
1223414479
1223514480 if (OEILONCE && OEIL)
....@@ -12246,6 +14491,7 @@
1224614491
1224714492 public void run()
1224814493 {
14494
+ new Exception().printStackTrace();
1224914495 System.exit(0);
1225014496 for (;;)
1225114497 {
....@@ -12287,7 +14533,7 @@
1228714533 mouseDown = false;
1228814534 if (lightMode)
1228914535 {
12290
- lighttouched = true;
14536
+ Globals.lighttouched = true;
1229114537 }
1229214538 repaint();
1229314539 alreadypainted = true;
....@@ -12295,7 +14541,7 @@
1229514541 isMoving = false;
1229614542 } //??
1229714543
12298
- if (isLIVE() && !alreadypainted)
14544
+ if (Globals.isLIVE() && !alreadypainted)
1229914545 {
1230014546 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1230114547 repaint();
....@@ -12307,9 +14553,9 @@
1230714553 {
1230814554 if (lightMode)
1230914555 {
12310
- lighttouched = true;
14556
+ Globals.lighttouched = true;
1231114557 }
12312
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14558
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1231314559 }
1231414560 //else
1231514561 }
....@@ -12323,12 +14569,12 @@
1232314569 void GoDown(int mod)
1232414570 {
1232514571 MODIFIERS |= COMMAND;
12326
- /*
14572
+ /**/
1232714573 if((mod&SHIFT) == SHIFT)
1232814574 manipCamera.RotatePosition(0, -speed);
1232914575 else
12330
- manipCamera.BackForth(0, -speed*delta, getWidth());
12331
- */
14576
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14577
+ /**/
1233214578 if ((mod & SHIFT) == SHIFT)
1233314579 {
1233414580 mouseMode = mouseMode; // VR??
....@@ -12344,12 +14590,12 @@
1234414590 void GoUp(int mod)
1234514591 {
1234614592 MODIFIERS |= COMMAND;
12347
- /*
14593
+ /**/
1234814594 if((mod&SHIFT) == SHIFT)
1234914595 manipCamera.RotatePosition(0, speed);
1235014596 else
12351
- manipCamera.BackForth(0, speed*delta, getWidth());
12352
- */
14597
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14598
+ /**/
1235314599 if ((mod & SHIFT) == SHIFT)
1235414600 {
1235514601 mouseMode = mouseMode;
....@@ -12365,12 +14611,12 @@
1236514611 void GoLeft(int mod)
1236614612 {
1236714613 MODIFIERS |= COMMAND;
12368
- /*
14614
+ /**/
1236914615 if((mod&SHIFT) == SHIFT)
12370
- manipCamera.RotatePosition(speed, 0);
12371
- else
1237214616 manipCamera.Translate(speed*delta, 0, getWidth());
12373
- */
14617
+ else
14618
+ manipCamera.RotatePosition(speed, 0);
14619
+ /**/
1237414620 if ((mod & SHIFT) == SHIFT)
1237514621 {
1237614622 mouseMode = mouseMode;
....@@ -12386,12 +14632,12 @@
1238614632 void GoRight(int mod)
1238714633 {
1238814634 MODIFIERS |= COMMAND;
12389
- /*
14635
+ /**/
1239014636 if((mod&SHIFT) == SHIFT)
12391
- manipCamera.RotatePosition(-speed, 0);
12392
- else
1239314637 manipCamera.Translate(-speed*delta, 0, getWidth());
12394
- */
14638
+ else
14639
+ manipCamera.RotatePosition(-speed, 0);
14640
+ /**/
1239514641 if ((mod & SHIFT) == SHIFT)
1239614642 {
1239714643 mouseMode = mouseMode;
....@@ -12409,7 +14655,7 @@
1240914655 int X, Y;
1241014656 boolean SX, SY;
1241114657
12412
- void drag(int x, int y, int modifiers)
14658
+ void drag(int x, int y, int modifiers, int modifiersex)
1241314659 {
1241414660 if (IsFrozen())
1241514661 {
....@@ -12418,17 +14664,17 @@
1241814664
1241914665 drag = true; // NEW
1242014666
12421
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14667
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1242214668
1242314669 X = x;
1242414670 Y = y;
1242514671 // floating state for animation
12426
- MODIFIERS = modifiers;
12427
- modifiers &= ~1024;
14672
+ MODIFIERS = modifiersex;
14673
+ modifiersex &= ~1024;
1242814674 if (false) // modifiers != 0)
1242914675 {
1243014676 //new Exception().printStackTrace();
12431
- System.out.println("mouseDragged: " + modifiers);
14677
+ System.out.println("mouseDragged: " + modifiersex);
1243214678 System.out.println("SHIFT = " + SHIFT);
1243314679 System.out.println("CONTROL = " + COMMAND);
1243414680 System.out.println("META = " + META);
....@@ -12441,14 +14687,16 @@
1244114687 if (editObj)
1244214688 {
1244314689 drag = true;
12444
- ClickInfo info = new ClickInfo();
12445
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1244614692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12447
- info.pane = this;
12448
- info.camera = renderCamera;
12449
- info.x = x;
12450
- info.y = y;
12451
- object.editWindow.copy.doEditDrag(info);
14693
+ object.clickInfo.pane = this;
14694
+ object.clickInfo.camera = renderCamera;
14695
+ object.clickInfo.x = x;
14696
+ object.clickInfo.y = y;
14697
+ object //.GetWindow().copy
14698
+ .doEditDrag(//info,
14699
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1245214700 } else
1245314701 {
1245414702 if (x < startX)
....@@ -12550,6 +14798,7 @@
1255014798 {
1255114799 manipCamera.Translate(dx, dy, getWidth());
1255214800 }
14801
+ else
1255314802 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1255414803 {
1255514804 manipCamera.RotateInterest(dx, dy);
....@@ -12560,7 +14809,7 @@
1256014809
1256114810 if (manipCamera == lightCamera)
1256214811 {
12563
- lighttouched = true;
14812
+ Globals.lighttouched = true;
1256414813 }
1256514814 /*
1256614815 switch (mode)
....@@ -12596,23 +14845,27 @@
1259614845 }
1259714846 }
1259814847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1259914850 public void mouseMoved(MouseEvent e)
1260014851 {
1260114852 //System.out.println("mouseMoved: " + e);
12602
-
1260314853 if (isRenderer)
1260414854 return;
1260514855
12606
- ClickInfo ci = new ClickInfo();
12607
- ci.x = e.getX();
12608
- ci.y = e.getY();
12609
- ci.modifiers = e.getModifiersEx();
12610
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12611
- ci.pane = this;
12612
- ci.camera = renderCamera;
14856
+ // Mouse cursor feedback
14857
+ object.clickInfo.x = e.getX();
14858
+ object.clickInfo.y = e.getY();
14859
+ object.clickInfo.modifiers = e.getModifiersEx();
14860
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14861
+ object.clickInfo.pane = this;
14862
+ object.clickInfo.camera = renderCamera;
1261314863 if (!isRenderer)
1261414864 {
12615
- if (object.editWindow.copy.doEditClick(ci, 0))
14865
+ //ObjEditor editWindow = object.editWindow;
14866
+ //Object3D copy = editWindow.copy;
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1261614869 {
1261714870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1261814871 } else
....@@ -12624,7 +14877,11 @@
1262414877
1262514878 public void mouseReleased(MouseEvent e)
1262614879 {
14880
+ Globals.MOUSEDRAGGED = false;
14881
+
1262714882 movingcamera = false;
14883
+ X = 0; // getBounds().width/2;
14884
+ Y = 0; // getBounds().height/2;
1262814885 //System.out.println("mouseReleased: " + e);
1262914886 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1263014887 }
....@@ -12647,9 +14904,9 @@
1264714904 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1264814905 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1264914906
12650
- if (control || command || IsFrozen())
14907
+// No delay if (control || command || IsFrozen())
1265114908 timeout = true;
12652
- else
14909
+// ?? May 2019 else
1265314910 // timer.setDelay((modifiers & 128) != 0?0:350);
1265414911 mouseDown = false;
1265514912 if (!control && !command) // june 2013
....@@ -12759,7 +15016,7 @@
1275915016 System.out.println("keyReleased: " + e);
1276015017 }
1276115018
12762
- void SetMouseMode(int modifiers)
15019
+ void SetMouseMode(int modifiers, int modifiersex)
1276315020 {
1276415021 //System.out.println("SetMouseMode = " + modifiers);
1276515022 //modifiers &= ~1024;
....@@ -12771,24 +15028,27 @@
1277115028 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1277215029 // return;
1277315030 //System.out.println("SetMode = " + modifiers);
12774
- if ((modifiers & WHEEL) == WHEEL)
15031
+ if ((modifiersex & WHEEL) == WHEEL)
1277515032 {
1277615033 mouseMode |= ZOOM;
1277715034 }
12778
- if ((modifiers & META) == META)
15035
+
15036
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15037
+ if (capsLocked) // || (modifiers & META) == META)
1277915038 {
1278015039 mouseMode |= VR; // BACKFORTH;
1278115040 }
12782
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12783
- {
12784
- mouseMode |= SELECT; // BACKFORTH;
12785
- }
12786
- if ((modifiers & COMMAND) == COMMAND)
15041
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1278715042 {
1278815043 mouseMode |= SELECT;
1278915044 }
12790
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15045
+ if ((modifiersex & COMMAND) == COMMAND)
1279115046 {
15047
+ mouseMode |= SELECT;
15048
+ }
15049
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15050
+ {
15051
+ mouseMode &= ~VR;
1279215052 mouseMode |= TRANSLATE;
1279315053 }
1279415054 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12815,10 +15075,10 @@
1281515075
1281615076 if (isRenderer) //
1281715077 {
12818
- SetMouseMode(modifiers);
15078
+ SetMouseMode(0, modifiers);
1281915079 }
1282015080
12821
- theRenderer.keyPressed(key);
15081
+ Globals.theRenderer.keyPressed(key);
1282215082 }
1282315083
1282415084 int kompactbit = 4; // power bit
....@@ -12830,7 +15090,7 @@
1283015090 float SATPOW = 1; // 2; // 0.5f;
1283115091 float BRIPOW = 1; // 0.5f; // 0.5f;
1283215092
12833
- void keyPressed(int key)
15093
+ public void keyPressed(int key)
1283415094 {
1283515095 if (key >= '0' && key <= '5')
1283615096 clampbit = (key-'0');
....@@ -12877,7 +15137,8 @@
1287715137 // break;
1287815138 case 'T':
1287915139 CACHETEXTURE ^= true;
12880
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1288115142 // repaint();
1288215143 break;
1288315144 case 'Y':
....@@ -12945,7 +15206,7 @@
1294515206 case 'B':
1294615207 BRISMOOTH ^= true;
1294715208 SHADOWCULLFACE ^= true;
12948
- lighttouched = true;
15209
+ Globals.lighttouched = true;
1294915210 repaint();
1295015211 break;
1295115212 case 'b':
....@@ -12962,7 +15223,9 @@
1296215223 case 'E' : COMPACT ^= true;
1296315224 repaint();
1296415225 break;
12965
- case 'W' : DEBUGHSB ^= true;
15226
+ case 'W' : // Wide Window (fullscreen)
15227
+ //DEBUGHSB ^= true;
15228
+ ObjEditor.theFrame.ToggleFullScreen();
1296615229 repaint();
1296715230 break;
1296815231 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -12987,8 +15250,8 @@
1298715250 RevertCamera();
1298815251 repaint();
1298915252 break;
12990
- case 'L':
1299115253 case 'l':
15254
+ //case 'L':
1299215255 if (lightMode)
1299315256 {
1299415257 lightMode = false;
....@@ -13045,7 +15308,7 @@
1304515308 repaint();
1304615309 break;
1304715310 case 'O':
13048
- drawMode = OCCLUSION;
15311
+ Globals.drawMode = OCCLUSION; // WARNING
1304915312 repaint();
1305015313 break;
1305115314 case 'o':
....@@ -13131,12 +15394,12 @@
1313115394 case '_':
1313215395 kompactbit = 5;
1313315396 break;
13134
- case '+':
13135
- kompactbit = 6;
13136
- break;
15397
+// case '+':
15398
+// kompactbit = 6;
15399
+// break;
1313715400 case ' ':
1313815401 lightMode ^= true;
13139
- lighttouched = true;
15402
+ Globals.lighttouched = true;
1314015403 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1314115404 targetLookAt.set(manipCamera.lookAt);
1314215405 repaint();
....@@ -13145,14 +15408,15 @@
1314515408 case ESC:
1314615409 RENDERPROGRAM += 1;
1314715410 RENDERPROGRAM %= 3;
15411
+
1314815412 repaint();
1314915413 break;
1315015414 case 'Z':
13151
- RESIZETEXTURE ^= true;
13152
- break;
15415
+ //RESIZETEXTURE ^= true;
15416
+ //break;
1315315417 case 'z':
13154
- RENDERSHADOW ^= true;
13155
- lighttouched = true;
15418
+ Globals.RENDERSHADOW ^= true;
15419
+ Globals.lighttouched = true;
1315615420 repaint();
1315715421 break;
1315815422 //case UP:
....@@ -13178,13 +15442,15 @@
1317815442 FlipTransform();
1317915443 break;
1318015444 case ENTER:
13181
- object.editWindow.ScreenFit(); // Edit();
15445
+ // object.editWindow.ScreenFit(); // Edit();
15446
+ ToggleLive();
1318215447 break;
1318315448 case DELETE:
1318415449 ClearSelection();
1318515450 break;
13186
- /*
1318715451 case '+':
15452
+
15453
+ /*
1318815454 //fontsize += 1;
1318915455 bbzoom *= 2;
1319015456 repaint();
....@@ -13201,17 +15467,17 @@
1320115467 case '=':
1320215468 IncDepth();
1320315469 //fontsize += 1;
13204
- object.editWindow.refreshContents(true);
15470
+ object.GetWindow().refreshContents(true);
1320515471 maskbit = 6;
1320615472 break;
1320715473 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1320815474 DecDepth();
1320915475 maskbit = 5;
1321015476 //if(fontsize > 1) fontsize -= 1;
13211
- if (object.editWindow == null)
13212
- new Exception().printStackTrace();
13213
- else
13214
- object.editWindow.refreshContents(true);
15477
+// if (object.editWindow == null)
15478
+// new Exception().printStackTrace();
15479
+// else
15480
+ object.GetWindow().refreshContents(true);
1321515481 break;
1321615482 case '{':
1321715483 manipCamera.shaper_fovy /= 1.1;
....@@ -13266,6 +15532,7 @@
1326615532 }
1326715533 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1326815534 }
15535
+
1326915536 static double OCCLUSIONBOOST = 1; // 0.5;
1327015537
1327115538 void keyReleased(int key, int modifiers)
....@@ -13273,11 +15540,11 @@
1327315540 //mode = ROTATE;
1327415541 if ((MODIFIERS & COMMAND) == 0) // VR??
1327515542 {
13276
- SetMouseMode(modifiers);
15543
+ SetMouseMode(0, modifiers);
1327715544 }
1327815545 }
1327915546
13280
- protected void processKeyEvent(KeyEvent e)
15547
+ public void processKeyEvent(KeyEvent e)
1328115548 {
1328215549 switch (e.getID())
1328315550 {
....@@ -13407,8 +15674,9 @@
1340715674
1340815675 protected void processMouseMotionEvent(MouseEvent e)
1340915676 {
13410
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13411
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15677
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15678
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15679
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1341215680 {
1341315681 mouseMoved(e);
1341415682 } else
....@@ -13433,11 +15701,12 @@
1343315701 }
1343415702 */
1343515703
13436
- object.editWindow.EditSelection();
15704
+ object.GetWindow().EditSelection(false);
1343715705 }
1343815706
1343915707 void SelectParent()
1344015708 {
15709
+ new Exception().printStackTrace();
1344115710 System.exit(0);
1344215711 Composite group = (Composite) object;
1344315712 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13449,10 +15718,10 @@
1344915718 {
1345015719 //selectees.remove(i);
1345115720 System.out.println("select parent of " + elem);
13452
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15721
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1345315722 } else
1345415723 {
13455
- group.editWindow.Select(elem.GetTreePath(), first, true);
15724
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1345615725 }
1345715726
1345815727 first = false;
....@@ -13461,6 +15730,7 @@
1346115730
1346215731 void SelectChildren()
1346315732 {
15733
+ new Exception().printStackTrace();
1346415734 System.exit(0);
1346515735 /*
1346615736 Composite group = (Composite) object;
....@@ -13493,12 +15763,12 @@
1349315763 for (int j = 0; j < group.children.size(); j++)
1349415764 {
1349515765 elem = (Object3D) group.children.elementAt(j);
13496
- object.editWindow.Select(elem.GetTreePath(), first, true);
15766
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1349715767 first = false;
1349815768 }
1349915769 } else
1350015770 {
13501
- object.editWindow.Select(elem.GetTreePath(), first, true);
15771
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1350215772 }
1350315773
1350415774 first = false;
....@@ -13509,21 +15779,21 @@
1350915779 {
1351015780 //Composite group = (Composite) object;
1351115781 Object3D group = object;
13512
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15782
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1351315783 }
1351415784
1351515785 void ResetTransform(int mask)
1351615786 {
1351715787 //Composite group = (Composite) object;
1351815788 Object3D group = object;
13519
- group.editWindow.ResetTransform(mask);
15789
+ group.GetWindow().ResetTransform(mask);
1352015790 }
1352115791
1352215792 void FlipTransform()
1352315793 {
1352415794 //Composite group = (Composite) object;
1352515795 Object3D group = object;
13526
- group.editWindow.FlipTransform();
15796
+ group.GetWindow().FlipTransform();
1352715797 // group.editWindow.ReduceMesh(true);
1352815798 }
1352915799
....@@ -13531,7 +15801,7 @@
1353115801 {
1353215802 //Composite group = (Composite) object;
1353315803 Object3D group = object;
13534
- group.editWindow.PrintMemory();
15804
+ group.GetWindow().PrintMemory();
1353515805 // group.editWindow.ReduceMesh(true);
1353615806 }
1353715807
....@@ -13539,7 +15809,7 @@
1353915809 {
1354015810 //Composite group = (Composite) object;
1354115811 Object3D group = object;
13542
- group.editWindow.ResetCentroid();
15812
+ group.GetWindow().ResetCentroid();
1354315813 }
1354415814
1354515815 void IncDepth()
....@@ -13621,11 +15891,11 @@
1362115891
1362215892 int width = getBounds().width;
1362315893 int height = getBounds().height;
13624
- ClickInfo info = new ClickInfo();
13625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1362615894 //Image img = CreateImage(width, height);
1362715895 //System.out.println("width = " + width + "; height = " + height + "\n");
15896
+
1362815897 Graphics gr = g; // img.getGraphics();
15898
+
1362915899 if (!hasMarquee)
1363015900 {
1363115901 if (Xmin < Xmax) // !locked)
....@@ -13697,40 +15967,88 @@
1369715967 }
1369815968 if (object != null && !hasMarquee)
1369915969 {
15970
+ if (object.clickInfo == null)
15971
+ object.clickInfo = new ClickInfo();
15972
+ ClickInfo info = object.clickInfo;
15973
+ //ClickInfo info = new ClickInfo();
15974
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15975
+
1370015976 if (isRenderer)
1370115977 {
13702
- info.flags++;
15978
+ object.clickInfo.flags++;
1370315979 double frameAspect = (double) width / (double) height;
1370415980 if (frameAspect > renderCamera.aspect)
1370515981 {
1370615982 int desired = (int) ((double) height * renderCamera.aspect);
13707
- info.bounds.width -= width - desired;
13708
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1370915985 } else
1371015986 {
1371115987 int desired = (int) ((double) width / renderCamera.aspect);
13712
- info.bounds.height -= height - desired;
13713
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1371415990 }
1371515991 }
13716
- info.g = gr;
13717
- info.camera = renderCamera;
15992
+
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1371815995 /*
1371915996 // Memory intensive (brep.verticescopy)
1372015997 if (!(object instanceof Composite))
1372115998 object.draw(info, 0, false); // SLOW :
1372215999 */
13723
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1372416001 {
13725
- object.drawEditHandles(info, 0);
16002
+ Grafreed.Assert(object != null);
16003
+ Grafreed.Assert(object.selection != null);
16004
+ if (object.selection.Size() > 0)
16005
+ {
16006
+ int hitSomething = object.selection.get(0).hitSomething;
16007
+
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
16011
+ if (hitSomething == Object3D.hitCenter)
16012
+ {
16013
+ info.DX = X;
16014
+ if (X != 0)
16015
+ info.DX -= info.bounds.width/2;
16016
+
16017
+ info.DY = Y;
16018
+ if (Y != 0)
16019
+ info.DY -= info.bounds.height/2;
16020
+ }
16021
+
16022
+ object.drawEditHandles(//info,
16023
+ 0);
16024
+
16025
+ if (drag && (X != 0 || Y != 0))
16026
+ {
16027
+ switch (hitSomething)
16028
+ {
16029
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16030
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16031
+ break;
16032
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16033
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16034
+ break;
16035
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16036
+ gr.drawLine(X, Y, 0, 0);
16037
+ break;
16038
+ }
16039
+
16040
+ }
16041
+ }
1372616042 }
1372716043 }
16044
+
1372816045 if (isRenderer)
1372916046 {
1373016047 //gr.setColor(Color.black);
1373116048 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1373216049 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1373316050 }
16051
+
1373416052 if (hasMarquee)
1373516053 {
1373616054 gr.setXORMode(Color.white);
....@@ -13753,6 +16071,7 @@
1375316071 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1375416072 }
1375516073
16074
+ // To avoid clear.
1375616075 public void update(Graphics g)
1375716076 {
1375816077 paint(g);
....@@ -13842,6 +16161,7 @@
1384216161 public boolean mouseDown(Event evt, int x, int y)
1384316162 {
1384416163 System.out.println("mouseDown: " + evt);
16164
+ System.exit(0);
1384516165 /*
1384616166 locked = true;
1384716167 drag = false;
....@@ -13885,7 +16205,7 @@
1388516205 {
1388616206 keyPressed(0, modifiers);
1388716207 }
13888
- clickStart(x, y, modifiers);
16208
+ // clickStart(x, y, modifiers);
1388916209 return true;
1389016210 }
1389116211
....@@ -14003,7 +16323,7 @@
1400316323 {
1400416324 keyReleased(0, 0);
1400516325 }
14006
- drag(x, y, modifiers);
16326
+ drag(x, y, 0, modifiers);
1400716327 return true;
1400816328 }
1400916329
....@@ -14135,7 +16455,7 @@
1413516455 Object3D object;
1413616456 static Object3D trackedobject;
1413716457 Camera renderCamera; // Light or Eye (or Occlusion)
14138
- /*static*/ Camera manipCamera; // Light or Eye
16458
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1413916459 /*static*/ Camera eyeCamera;
1414016460 /*static*/ Camera lightCamera;
1414116461 int cameracount;
....@@ -14355,7 +16675,7 @@
1435516675 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1435616676 gl.glPushMatrix();
1435716677 gl.glLoadIdentity();
14358
- PushMatrix(checker.toParent);
16678
+ //PushMatrix(checker.toParent);
1435916679
1436016680 gl.glMatrixMode(GL.GL_TEXTURE);
1436116681 gl.glPushMatrix();
....@@ -14378,8 +16698,8 @@
1437816698
1437916699 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1438016700
14381
- float step = 0.1666f; //0.25f;
14382
- float stepv = step * 1652 / 998;
16701
+ float step = 2; // 0.1666f; //0.25f;
16702
+ float stepv = 2; // step * 1652 / 998;
1438316703
1438416704 int i0 = 0;
1438516705 /*
....@@ -14415,20 +16735,21 @@
1441516735 /**/
1441616736 //checker.GetMaterial().opacity = 1.1f;
1441716737 ////checker.GetMaterial().ambient = 0.99f;
14418
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14419
- Object3D.selectedstack[Object3D.materialdepth] = false;
14420
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16738
+ materialstack[materialdepth] = checker.material;
16739
+ selectedstack[materialdepth] = false;
16740
+ cStatic.objectstack[materialdepth++] = checker;
1442116741 //System.out.println("material " + material);
1442216742 //Applet3D.tracein(this, selected);
14423
- vector2buffer = checker.projectedVertices;
16743
+ //vector2buffer = checker.projectedVertices;
1442416744
14425
- checker.GetMaterial().Draw(this, false); // true);
16745
+ //checker.GetMaterial().Draw(this, false); // true);
16746
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1442616747
14427
- Object3D.materialdepth -= 1;
14428
- if (Object3D.materialdepth > 0)
16748
+ materialdepth -= 1;
16749
+ if (materialdepth > 0)
1442916750 {
14430
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14431
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16751
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16752
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1443216753 }
1443316754 //checker.GetMaterial().opacity = 1f;
1443416755 ////checker.GetMaterial().ambient = 1f;
....@@ -14449,15 +16770,27 @@
1444916770
1445016771 //float u = (i+1)/2;
1445116772 //float v = (j+1)/2;
14452
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16773
+ if (checker.flipV)
16774
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16775
+ else
16776
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1445316777 gl.glVertex3f(i, j, -0.5f);
1445416778
16779
+ if (checker.flipV)
16780
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16781
+ else
1445516782 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1445616783 gl.glVertex3f(i + step, j, -0.5f);
1445716784
16785
+ if (checker.flipV)
16786
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16787
+ else
1445816788 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1445916789 gl.glVertex3f(i + step, j + stepv, -0.5f);
1446016790
16791
+ if (checker.flipV)
16792
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16793
+ else
1446116794 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1446216795 gl.glVertex3f(i, j + stepv, -0.5f);
1446316796 }
....@@ -14469,7 +16802,7 @@
1446916802 gl.glMatrixMode(GL.GL_PROJECTION);
1447016803 gl.glPopMatrix();
1447116804 gl.glMatrixMode(GL.GL_MODELVIEW);
14472
- PopMatrix(null); // checker.toParent); // null);
16805
+ //PopMatrix(null); // checker.toParent); // null);
1447316806 gl.glPopMatrix();
1447416807 PopTextureMatrix(checker.toParent);
1447516808 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14502,6 +16835,14 @@
1450216835 }
1450316836 }
1450416837
16838
+ private Object3D GetFolder()
16839
+ {
16840
+ Object3D folder = object.GetWindow().copy;
16841
+ if (object.GetWindow().copy.selection.Size() > 0)
16842
+ folder = object.GetWindow().copy.selection.elementAt(0);
16843
+ return folder;
16844
+ }
16845
+
1450516846 class SelectBuffer implements GLEventListener
1450616847 {
1450716848
....@@ -14560,6 +16901,7 @@
1456016901 {
1456116902 if (!selection)
1456216903 {
16904
+ new Exception().printStackTrace();
1456316905 System.exit(0);
1456416906 return;
1456516907 }
....@@ -14580,17 +16922,39 @@
1458016922
1458116923 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1458216924
16925
+ if (PAINTMODE)
16926
+ {
16927
+ if (object.GetWindow().copy.selection.Size() > 0)
16928
+ {
16929
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16930
+
16931
+ // Make what you paint not selectable.
16932
+ paintobj.ResetSelectable();
16933
+ }
16934
+ }
16935
+
1458316936 //int tmp = selection_view;
1458416937 //selection_view = -1;
14585
- int temp = drawMode;
14586
- drawMode = SELECTION;
16938
+ int temp = DrawMode();
16939
+ Globals.drawMode = SELECTION; // WARNING
1458716940 indexcount = 0;
1458816941 parent.display(drawable);
1458916942 //selection_view = tmp;
1459016943 //if (temp == SELECTION)
1459116944 // temp = DEFAULT; // patch for selection debug
14592
- drawMode = temp;
16945
+ Globals.drawMode = temp; // WARNING
1459316946
16947
+ if (PAINTMODE)
16948
+ {
16949
+ if (object.GetWindow().copy.selection.Size() > 0)
16950
+ {
16951
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16952
+
16953
+ // Revert.
16954
+ paintobj.RestoreSelectable();
16955
+ }
16956
+ }
16957
+
1459416958 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1459516959
1459616960 // trying different ways of getting the depth info over
....@@ -14639,6 +17003,13 @@
1463917003 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1464017004 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1464117005
17006
+ CreateSelectedPoint();
17007
+
17008
+ // Will fit the mesh !!!
17009
+ selectedpoint.toParent[0][0] = 0.0001;
17010
+ selectedpoint.toParent[1][1] = 0.0001;
17011
+ selectedpoint.toParent[2][2] = 0.0001;
17012
+
1464217013 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1464317014
1464417015 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14682,34 +17053,36 @@
1468217053 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]));
1468317054 }
1468417055
14685
- previousselectedpoint = (Sphere) GraphreeD.clone(selectedpoint);
17056
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1468617057 }
1468717058 }
1468817059
1468917060 if (!movingcamera && !PAINTMODE)
14690
- object.editWindow.ScreenFitPoint(); // fev 2014
17061
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1469117062
14692
- if (PAINTMODE && GraphreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17063
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1469317064 {
14694
- Object3D paintobj = GraphreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17065
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1469517066
14696
- Object3D group = new Object3D("inst" + paintcount++);
17067
+ if (object.GetWindow().copy.selection.Size() > 0)
17068
+ {
17069
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1469717070
14698
- group.CreateMaterial(); // use a void leaf to select instances
14699
-
14700
- group.add(paintobj); // link
14701
-
14702
- object.editWindow.SnapObject(group);
14703
-
14704
- Object3D folder = object.editWindow.copy;
14705
-
14706
- if (object.editWindow.copy.selection.Size() > 0)
14707
- folder = object.editWindow.copy.selection.elementAt(0);
14708
-
14709
- folder.add(group);
14710
-
14711
- object.editWindow.ResetModel();
14712
- object.editWindow.refreshContents();
17071
+ Object3D inst = new Object3D("inst" + paintcount++);
17072
+
17073
+ inst.CreateMaterial(); // use a void leaf to select instances
17074
+
17075
+ inst.add(paintobj); // link
17076
+
17077
+ object.GetWindow().SnapObject(inst);
17078
+
17079
+ Object3D folder = paintFolder; // GetFolder();
17080
+
17081
+ folder.add(inst);
17082
+
17083
+ object.GetWindow().ResetModel();
17084
+ object.GetWindow().refreshContents();
17085
+ }
1471317086 }
1471417087 else
1471517088 paintcount = 0;
....@@ -14748,6 +17121,11 @@
1474817121 //System.out.println("objects[color] = " + objects[color]);
1474917122 //objects[color].Select();
1475017123 indexcount = 0;
17124
+ ObjEditor window = object.GetWindow();
17125
+ if (window != null && deselect)
17126
+ {
17127
+ window.Select(null, deselect, true);
17128
+ }
1475117129 object.Select(color, deselect);
1475217130 }
1475317131
....@@ -14847,7 +17225,7 @@
1484717225 gl.glDisable(gl.GL_CULL_FACE);
1484817226 }
1484917227
14850
- if (!RENDERSHADOW)
17228
+ if (!Globals.RENDERSHADOW)
1485117229 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1485217230
1485317231 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14857,14 +17235,14 @@
1485717235 //gl.glColorMask(false, false, false, false);
1485817236
1485917237 //render_scene_from_light_view(gl, drawable, 0, 0);
14860
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17238
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1486117239 {
1486217240 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1486317241
14864
- int temp = drawMode;
14865
- drawMode = SHADOW;
17242
+ int temp = DrawMode();
17243
+ Globals.drawMode = SHADOW; // WARNING
1486617244 parent.display(drawable);
14867
- drawMode = temp;
17245
+ Globals.drawMode = temp; // WARNING
1486817246 }
1486917247
1487017248 gl.glCullFace(gl.GL_BACK);
....@@ -14917,7 +17295,6 @@
1491717295
1491817296 class AntialiasBuffer implements GLEventListener
1491917297 {
14920
-
1492117298 CameraPane parent = null;
1492217299
1492317300 AntialiasBuffer(CameraPane p)
....@@ -15027,13 +17404,19 @@
1502717404 gl.glFlush();
1502817405
1502917406 /**/
15030
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17407
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
1503117408
15032
- int[] pixels = occlusionsizebuffer.array();
17409
+ float[] pixels = occlusionsizebuffer.array();
1503317410
1503417411 double r = 0, g = 0, b = 0;
1503517412
1503617413 double count = 0;
17414
+
17415
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17416
+
17417
+ float mindepth = 1;
17418
+
17419
+ double FACTOR = 1;
1503717420
1503817421 for (int i = 0; i < pixels.length; i++)
1503917422 {
....@@ -15118,7 +17501,7 @@
1511817501
1511917502 double scale = ray.z; // 1; // cos
1512017503
15121
- int p = pixels[newindex];
17504
+ float depth = pixels[newindex];
1512217505
1512317506 /*
1512417507 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15142,10 +17525,23 @@
1514217525 scale = (1 - modu) * modv;
1514317526 */
1514417527
15145
- r += ((p >> 16) & 0xFF) * scale / 255;
15146
- g += ((p >> 8) & 0xFF) * scale / 255;
15147
- b += (p & 0xFF) * scale / 255;
17528
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17529
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17530
+ //b += (p & 0xFF) * scale / 255;
17531
+
17532
+ if (mindepth > depth)
17533
+ {
17534
+ mindepth = depth;
17535
+ }
1514817536
17537
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17538
+
17539
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17540
+
17541
+ r += factor * scale;
17542
+ g += factor * scale;
17543
+ b += factor * scale;
17544
+
1514917545 count += scale;
1515017546 }
1515117547
....@@ -15243,12 +17639,6 @@
1524317639 GLUT glut = new GLUT();
1524417640
1524517641
15246
- static final public int DEFAULT = 0;
15247
- static final public int SELECTION = 1;
15248
- static final public int SHADOW = 2;
15249
- static final public int OCCLUSION = 3;
15250
- static
15251
- public int drawMode = DEFAULT;
1525217642 public boolean spherical = false;
1525317643 static boolean DEBUG_OCCLUSION = false;
1525417644 static boolean DEBUG_SELECTION = false;
....@@ -15261,21 +17651,15 @@
1526117651 int AAbuffersize = 0;
1526217652
1526317653 //double[] selectedpoint = new double[3];
15264
- static Sphere selectedpoint = new Sphere();
17654
+ static Superellipsoid selectedpoint;
1526517655 static Sphere previousselectedpoint = null;
15266
- static Sphere debugpoint = new Sphere();
15267
- static Sphere debugpoint2 = new Sphere();
17656
+ static Sphere debugpointG;
17657
+ static Sphere debugpointP;
17658
+ static Sphere debugpointC;
17659
+ static Sphere debugpointR;
1526817660
1526917661 static Sphere debugpoints[] = new Sphere[8];
1527017662
15271
- static
15272
- {
15273
- for (int i=0; i<8; i++)
15274
- {
15275
- debugpoints[i] = new Sphere();
15276
- }
15277
- }
15278
-
1527917663 static void InitPoints(float radius)
1528017664 {
1528117665 for (int i=0; i<8; i++)
....@@ -15295,7 +17679,7 @@
1529517679 }
1529617680 }
1529717681
15298
- static void DrawPoints(CameraPane cpane)
17682
+ static void DrawPoints(iCameraPane cpane)
1529917683 {
1530017684 for (int i=0; i<8; i++) // first and last are red
1530117685 {
....@@ -15317,7 +17701,8 @@
1531717701 static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1531817702 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1531917703 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15320
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17704
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17705
+ static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
1532117706 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1532217707 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1532317708 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15326,10 +17711,11 @@
1532617711 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1532717712 // Depth buffer format
1532817713 //private int depth_format;
15329
- static public void NextIndex(Object3D o, GL gl)
17714
+
17715
+ public void NextIndex()
1533017716 {
1533117717 indexcount+=16;
15332
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17718
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1533317719 //objects[indexcount] = o;
1533417720 //System.out.println("indexcount = " + indexcount);
1533517721 }