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,11 +2438,26 @@
7592438
7602439 GL currentGL;
7612440
762
- GL GetGL()
2441
+ public GL GetGL() // INTERFACE
7632442 {
7642443 return currentGL;
7652444 }
766
-
2445
+
2446
+ static private BufferedImage CreateBim(TextureData texturedata)
2447
+ {
2448
+ Grafreed.Assert(texturedata != null);
2449
+
2450
+ int width = texturedata.getWidth();
2451
+ int height = texturedata.getHeight();
2452
+
2453
+ Buffer buffer = texturedata.getBuffer();
2454
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2455
+
2456
+ byte[] bytes = bytebuf.array();
2457
+
2458
+ return CreateBim(bytes, width, height);
2459
+ }
2460
+
7672461 /**/
7682462 class CacheTexture
7692463 {
....@@ -772,28 +2466,31 @@
7722466
7732467 int resolution;
7742468
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2469
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762470 {
777
- texture = tex;
2471
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2472
+ texturedata = texdata;
7782473 resolution = res;
7792474 }
7802475 }
7812476 /**/
7822477
7832478 // TEXTURE static Texture texture;
784
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
785
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
786
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2481
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2482
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2483
+
7872484 int pigmentdepth = 0;
7882485 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892486 int bumpdepth = 0;
7902487 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912488 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922489 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2490
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942491 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952492
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2493
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972494 {
7982495 TextureData texturedata = null;
7992496
....@@ -812,13 +2509,34 @@
8122509 if (bump)
8132510 texturedata = ConvertBump(texturedata, false);
8142511
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2512
+// com.sun.opengl.util.texture.Texture texture =
2513
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172514
818
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
819
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2516
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202517
821
- return texture;
2518
+ return texturedata;
2519
+ }
2520
+
2521
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2522
+ {
2523
+ TextureData texturedata = null;
2524
+
2525
+ try
2526
+ {
2527
+ texturedata =
2528
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2529
+ bim,
2530
+ true);
2531
+ } catch (Exception e)
2532
+ {
2533
+ throw new javax.media.opengl.GLException(e);
2534
+ }
2535
+
2536
+ if (bump)
2537
+ texturedata = ConvertBump(texturedata, false);
2538
+
2539
+ return texturedata;
8222540 }
8232541
8242542 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3609,8 @@
18913609
18923610 System.out.println("LOADING TEXTURE : " + name);
18933611
3612
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3613
+
18943614 //
18953615 if (false) // compressbit > 0)
18963616 {
....@@ -2000,10 +3720,12 @@
20003720 */
20013721 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20023722 {
3723
+ int pixelformat = texturedata.getPixelFormat();
3724
+
20033725 int stride = 1;
2004
- 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)
20053727 stride = 3;
2006
- 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)
20073729 stride = 4;
20083730
20093731 int width = texturedata.getWidth();
....@@ -2593,6 +4315,7 @@
25934315
25944316 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25954317 {
4318
+ new Exception().printStackTrace();
25964319 System.exit(0);
25974320 com.sun.opengl.util.texture.Texture texture = null;
25984321
....@@ -6269,7 +7992,7 @@
62697992 return null;
62707993 }
62717994
6272
- void ReleaseTextures(cTexture tex)
7995
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62737996 {
62747997 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62757998 {
....@@ -6286,7 +8009,7 @@
62868009 String pigment = Object3D.GetPigment(tex);
62878010 String bump = Object3D.GetBump(tex);
62888011
6289
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8012
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62908013 {
62918014 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62928015 // System.out.println("; bump = " + bump);
....@@ -6301,13 +8024,71 @@
63018024 pigment = null;
63028025 }
63038026
6304
- ReleaseTexture(bump, true);
6305
- ReleaseTexture(pigment, false);
8027
+ ReleaseTexture(tex, true);
8028
+ ReleaseTexture(tex, false);
63068029 }
63078030
6308
- void ReleaseTexture(String tex, boolean bump)
8031
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63098032 {
6310
- 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 ||*/
63118092 ambientOcclusion ) // || !textureon)
63128093 {
63138094 return;
....@@ -6316,7 +8097,7 @@
63168097 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63178098
63188099 if (tex != null)
6319
- texture = textures.get(tex);
8100
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63208101
63218102 // //assert( texture != null );
63228103 // if (texture == null)
....@@ -6333,7 +8114,7 @@
63338114 {
63348115 bumpdepth--;
63358116
6336
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8117
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63378118 if (bumpstack[bumpdepth] != (texture!=null?texture.texture:null))
63388119 {
63398120 // assert (bumpstack[bumpdepth] == texture);
....@@ -6363,7 +8144,7 @@
63638144 {
63648145 pigmentdepth--;
63658146
6366
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8147
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63678148 if (pigmentstack[pigmentdepth] != (texture!=null?texture.texture:null))
63688149 {
63698150 // assert (pigmentstack[pigmentdepth] == texture);
....@@ -6408,9 +8189,57 @@
64088189 }
64098190 }
64108191
6411
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8192
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64128193 {
6413
- 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 ||*/
64148243 ambientOcclusion ) // || !textureon)
64158244 {
64168245 return; // false;
....@@ -6419,17 +8248,47 @@
64198248 if (tex == null)
64208249 {
64218250 BindTexture(null,false,resolution);
6422
- BindTexture(null,true,resolution);
64238251 return;
64248252 }
64258253
64268254 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
+
64278287 String bump = Object3D.GetBump(tex);
64288288
6429
- usedtextures.put(pigment, pigment);
6430
- usedtextures.put(bump, bump);
8289
+ usedtextures.add(tex);
64318290
6432
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8291
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64338292 {
64348293 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64358294 // System.out.println("; bump = " + bump);
....@@ -6439,43 +8298,94 @@
64398298 {
64408299 bump = null;
64418300 }
6442
- if (pigment.equals(""))
6443
- {
6444
- pigment = null;
6445
- }
64468301
6447
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6448
- BindTexture(pigment, false, resolution);
64498302 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6450
- BindTexture(bump, true, resolution);
8303
+ BindTexture(tex, true, resolution);
64518304 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6452
-
6453
- return; // true;
64548305 }
64558306
6456
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8307
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8308
+
8309
+ private boolean FileExists(String tex)
64578310 {
6458
- 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;
64598330
64608331 if (tex != null)
64618332 {
6462
- String texname = tex;
8333
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8334
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64638335
6464
- String[] split = tex.split("Textures");
6465
- if (split.length > 1)
6466
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6467
- else
6468
- if (!texname.startsWith("/"))
6469
- texname = "/Users/nbriere/Textures/" + texname;
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
+ }
64708353
64718354 if (CACHETEXTURE)
6472
- texture = textures.get(texname); // TEXTURE CACHE
6473
-
6474
- TextureData texturedata = null;
6475
-
6476
- if (texture == null || texture.resolution < resolution)
64778355 {
6478
- 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(""))
64798389 {
64808390 assert(!bump);
64818391 // if (bump)
....@@ -6486,19 +8396,23 @@
64868396 // }
64878397 // else
64888398 // {
6489
- texture = textures.get(tex);
6490
- if (texture == null)
8399
+ // texturecache = textures.get(texname); // suspicious
8400
+ if (texturecache == null)
64918401 {
6492
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8402
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64938403 }
8404
+ else
8405
+ new Exception().printStackTrace();
64948406 // }
64958407 } else
6496
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8408
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64978409 {
64988410 assert(bump);
6499
- texture = textures.get(tex);
6500
- if (texture == null)
6501
- 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();
65028416 } else
65038417 {
65048418 //if (tex.equals("IMMORTAL"))
....@@ -6506,11 +8420,13 @@
65068420 // texture = GetResourceTexture("default.png");
65078421 //} else
65088422 //{
6509
- if (tex.equals("WHITE_NOISE"))
8423
+ if (texname.endsWith("WHITE_NOISE"))
65108424 {
6511
- texture = textures.get(tex);
6512
- if (texture == null)
6513
- 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();
65148430 } else
65158431 {
65168432 if (textureon)
....@@ -6535,7 +8451,7 @@
65358451 }
65368452
65378453 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6538
- if (!new File(cachename).exists())
8454
+ if (!FileExists(cachename))
65398455 cachename = texname;
65408456 else
65418457 processbump = false; // don't process bump map again
....@@ -6557,7 +8473,7 @@
65578473 }
65588474
65598475 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6560
- if (!new File(cachename).exists())
8476
+ if (!FileExists(cachename))
65618477 cachename = texname;
65628478 else
65638479 processbump = false; // don't process bump map again
....@@ -6566,20 +8482,22 @@
65668482 texturedata = GetFileTexture(cachename, processbump, resolution);
65678483
65688484
6569
- if (texturedata != null)
6570
- 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);
65718489 //texture = GetTexture(tex, bump);
65728490 }
65738491 }
65748492 //}
65758493 }
65768494
6577
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8495
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65788496 {
65798497 //return false;
65808498
65818499 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6582
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8500
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65838501 {
65848502 // String ext = "_highres";
65858503 // if (REDUCETEXTURE)
....@@ -6596,52 +8514,17 @@
65968514 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65978515 if (!cachefile.exists())
65988516 {
6599
- // cache to disk
6600
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6601
- //buffers[0].
6602
-
6603
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6604
- int[] pixels = new int[bytebuf.capacity()/3];
6605
-
6606
- // squared size heuristic...
6607
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8517
+ //if (texturedata.getWidth() == texturedata.getHeight())
66088518 {
6609
- for (int i=pixels.length; --i>=0;)
6610
- {
6611
- int i3 = i*3;
6612
- pixels[i] = 0xFF;
6613
- pixels[i] <<= 8;
6614
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6617
- pixels[i] <<= 8;
6618
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6619
- }
6620
-
6621
- /*
6622
- int r=0,g=0,b=0,a=0;
6623
- for (int i=0; i<width; i++)
6624
- for (int j=0; j<height; j++)
6625
- {
6626
- int index = j*width+i;
6627
- int p = pixels[index];
6628
- a = ((p>>24) & 0xFF);
6629
- r = ((p>>16) & 0xFF);
6630
- g = ((p>>8) & 0xFF);
6631
- b = (p & 0xFF);
6632
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6633
- }
6634
- /**/
6635
- int width = (int)Math.sqrt(pixels.length); // squared
6636
- int height = width;
6637
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6638
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8519
+ BufferedImage rendImage = CreateBim(texturedata);
8520
+
66398521 ImageWriter writer = null;
66408522 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66418523 if (iter.hasNext()) {
66428524 writer = (ImageWriter)iter.next();
66438525 }
6644
- float compressionQuality = 0.9f;
8526
+
8527
+ float compressionQuality = 0.85f;
66458528 try
66468529 {
66478530 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6658,18 +8541,20 @@
66588541 }
66598542 }
66608543 }
6661
-
8544
+
8545
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8546
+
66628547 //System.out.println("Texture = " + tex);
6663
- if (textures.containsKey(texname))
8548
+ if (textures.containsKey(tex))
66648549 {
6665
- CacheTexture thetex = textures.get(texname);
8550
+ CacheTexture thetex = textures.get(tex);
66668551 thetex.texture.disable();
66678552 thetex.texture.dispose();
6668
- textures.remove(texname);
8553
+ textures.remove(tex);
66698554 }
66708555
6671
- texture.texturedata = texturedata;
6672
- textures.put(texname, texture);
8556
+ //texture.texturedata = texturedata;
8557
+ textures.put(tex, texturecache);
66738558
66748559 // newtex = true;
66758560 }
....@@ -6685,42 +8570,76 @@
66858570 }
66868571 }
66878572
6688
- return texture;
8573
+ return texturecache;
66898574 }
66908575
6691
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8576
+ static void EmbedTextures(cTexture tex)
8577
+ {
8578
+ if (tex.pigmentdata == null)
8579
+ {
8580
+ //String texname = Object3D.GetPigment(tex);
8581
+
8582
+ CacheTexture texturecache = texturepigment.get(tex);
8583
+
8584
+ if (texturecache != null)
8585
+ {
8586
+ tex.pw = texturecache.texturedata.getWidth();
8587
+ tex.ph = texturecache.texturedata.getHeight();
8588
+ tex.pigmentdata = //CompressJPEG(CreateBim
8589
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8590
+ ;
8591
+ //, tex.pw, tex.ph), 0.5f);
8592
+ }
8593
+ }
8594
+
8595
+ if (tex.bumpdata == null)
8596
+ {
8597
+ //String texname = Object3D.GetBump(tex);
8598
+
8599
+ CacheTexture texturecache = texturebump.get(tex);
8600
+
8601
+ if (texturecache != null)
8602
+ {
8603
+ tex.bw = texturecache.texturedata.getWidth();
8604
+ tex.bh = texturecache.texturedata.getHeight();
8605
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8606
+ }
8607
+ }
8608
+ }
8609
+
8610
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66928611 {
66938612 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66948613
66958614 if (bump)
66968615 {
6697
- // GraphreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
8616
+ // GrafreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
66988617 bumpstack[bumpdepth++] = texture!=null?texture.texture:null;
66998618 }
67008619 else
67018620 {
6702
- // GraphreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
8621
+ // GrafreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
67038622 pigmentstack[pigmentdepth++] = texture!=null?texture.texture:null;
67048623 }
67058624
67068625 return texture!=null?texture.texture:null;
67078626 }
67088627
6709
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8628
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67108629 {
67118630 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67128631
67138632 return texture!=null?texture.texturedata:null;
67148633 }
67158634
6716
- boolean BindTexture(String tex, boolean bump, int resolution)
8635
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67178636 {
67188637 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67198638 {
67208639 return false;
67218640 }
67228641
6723
- boolean newtex = false;
8642
+ //boolean newtex = false;
67248643
67258644 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67268645
....@@ -6752,9 +8671,75 @@
67528671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67538672 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67548673
6755
- return newtex;
8674
+ return true; // Warning: not used.
67568675 }
67578676
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
+
67588743 ShadowBuffer shadowPBuf;
67598744 AntialiasBuffer antialiasPBuf;
67608745 int MAXSTACK;
....@@ -7310,9 +9295,9 @@
73109295 static boolean occlusionInitialized = false;
73119296 boolean selection = false;
73129297 boolean pointselection = false;
7313
- /*static*/ boolean lighttouched = true;
9298
+ ///*static*/ boolean lighttouched = true;
73149299 boolean deselect;
7315
- boolean ambientOcclusion = false;
9300
+ private boolean ambientOcclusion = false;
73169301 static boolean flash = false;
73179302 /*static*/ boolean wait = false;
73189303 boolean displaydone = false; // after repaint() calls
....@@ -7442,6 +9427,8 @@
74429427 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74439428 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74449429 double scale = lightCamera.SCALE / lightCamera.Distance();
9430
+// PATCH FILLE AUX JEANS
9431
+ //scale *= lightCamera.shaper_fovy / 25;
74459432 gl.glScaled(2 * scale, 2 * scale, -scale);
74469433 gl.glTranslated(0, 0, lightCamera.DECAL);
74479434
....@@ -7588,17 +9575,40 @@
75889575 jy8[3] = 0.5f;
75899576 }
75909577
7591
- 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
75929579 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
7593
- float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
9580
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9581
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75949582
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
+
75959607 static int imagecount = 0; // movie generation
75969608
75979609 static int jitter = 0;
75989610
75999611 boolean restartframe = false;
7600
-
7601
- static int framecount = 0; // general-purpose global count
76029612
76039613 void displayAntiAliased(javax.media.opengl.GL gl)
76049614 {
....@@ -7628,14 +9638,14 @@
76289638
76299639 //System.out.println("start frame");
76309640 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
7631
- 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)
76329642 {
7633
- framecount++;
9643
+ Globals.framecount++;
76349644
76359645 if (CameraPane.tickcount > 0)
76369646 CameraPane.tickcount--;
76379647
7638
-// 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)
76399649 // restartframe = true;
76409650 if (options1[2] > 100 && (jitter%2==0))
76419651 {
....@@ -7668,7 +9678,7 @@
76689678
76699679 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76709680 */
7671
- lighttouched = true;
9681
+ Globals.lighttouched = true;
76729682 //System.err.println(" shadowbuffer: " + jitter);
76739683 shadowbuffer.display();
76749684
....@@ -7689,8 +9699,8 @@
76899699 assert (parentcam != renderCamera);
76909700
76919701 if (renderCamera != lightCamera)
7692
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7693
- LA.matConcat(parentcam.toParent, matrix, matrix);
9702
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76949704
76959705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76969706
....@@ -7705,8 +9715,8 @@
77059715 LA.matCopy(renderCamera.fromScreen, matrix);
77069716
77079717 if (renderCamera != lightCamera)
7708
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7709
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9718
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77109720
77119721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77129722
....@@ -7778,7 +9788,7 @@
77789788 //gl.glFlush();
77799789 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77809790
7781
- if (ANIMATION && ABORTED)
9791
+ if (Globals.ANIMATION && ABORTED)
77829792 {
77839793 System.err.println(" ABORTED FRAME");
77849794 break;
....@@ -7808,7 +9818,7 @@
78089818 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78099819
78109820 // save image
7811
- if (ANIMATION && !ABORTED)
9821
+ if (Globals.ANIMATION && !ABORTED)
78129822 {
78139823 VPwidth = viewport[2];
78149824 VPheight = viewport[3];
....@@ -7919,11 +9929,11 @@
79199929
79209930 // imagecount++;
79219931
7922
- 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;
79239933
79249934 if (!BOXMODE)
79259935 {
7926
- System.out.println("image: " + fullname + " (" + (GraphreeD.wav.cursor / 735 / 4) + ")");
9936
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79279937 }
79289938
79299939 if (!BOXMODE)
....@@ -7951,7 +9961,7 @@
79519961 {
79529962 if (ACSIZE > 1)
79539963 {
7954
- // System.err.println("image #" + (GraphreeD.wav.cursor / 735 / 4));
9964
+ // System.err.println("image #" + (GrafreeD.wav.cursor / 735 / 4));
79559965 }
79569966 }
79579967
....@@ -7961,7 +9971,7 @@
79619971 ABORTED = false;
79629972 }
79639973 else
7964
- GraphreeD.wav.cursor += 735 * ACSIZE;
9974
+ Grafreed.wav.cursor += 735 * ACSIZE;
79659975
79669976 if (false)
79679977 {
....@@ -8615,13 +10625,6 @@
861510625 }
861610626 }
861710627
8618
- boolean IsFrozen()
8619
- {
8620
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8621
-
8622
- return !selectmode && cameracount == 0; // != 0;
8623
- }
8624
-
862510628 boolean niceon = false;
862610629 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
862710630 boolean currentlydrawing = false;
....@@ -8631,16 +10634,16 @@
863110634
863210635 public void display(GLAutoDrawable drawable)
863310636 {
8634
- if (GraphreeD.savesound && GraphreeD.hassound)
10637
+ if (Grafreed.savesound && Grafreed.hassound)
863510638 {
8636
- GraphreeD.wav.save();
8637
- GraphreeD.savesound = false;
8638
- GraphreeD.hassound = false;
10639
+ Grafreed.wav.save();
10640
+ Grafreed.savesound = false;
10641
+ Grafreed.hassound = false;
863910642 }
864010643 // if (DEBUG_SELECTION)
864110644 // {
8642
-// if (drawMode != SELECTION)
8643
-// drawMode = SELECTION;
10645
+// if (DrawMode() != SELECTION)
10646
+// DrawMode() = SELECTION;
864410647 // }
864510648
864610649 if (!isRenderer)
....@@ -8696,9 +10699,9 @@
869610699
869710700 //ANTIALIAS = 0;
869810701
8699
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10702
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870010703 {
8701
- if (niceon || isLIVE())
10704
+ if (niceon || Globals.isLIVE())
870210705 {
870310706 //if(active == 0)
870410707 // antialiaser = null;
....@@ -8711,6 +10714,7 @@
871110714 ANTIALIAS = 0;
871210715 //System.out.println("RESTART");
871310716 AAtimer.restart();
10717
+ Globals.TIMERRUNNING = true;
871410718 }
871510719 }
871610720 }
....@@ -8723,7 +10727,7 @@
872310727 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872410728 */
872510729
8726
- if (drawMode == DEFAULT)
10730
+ if (DrawMode() == DEFAULT)
872710731 {
872810732 currentlydrawing = true;
872910733 }
....@@ -8754,18 +10758,18 @@
875410758
875510759 // if(Applet3D.clipboard != null)
875610760 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8757
-//drawMode = SELECTION;
10761
+//DrawMode() = SELECTION;
875810762 indexcount = 0;
875910763
8760
- if (drawMode == OCCLUSION)
10764
+ if (DrawMode() == OCCLUSION)
876110765 {
8762
- drawMode = DEFAULT;
10766
+ Globals.drawMode = DEFAULT; // WARNING
876310767 ambientOcclusion = true;
876410768 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876510769 Object3D theobject = object;
876610770 Object3D theparent = object.parent;
876710771 object.parent = null;
8768
- object = (Object3D)GraphreeD.clone(object);
10772
+ object = (Object3D)Grafreed.clone(object);
876910773 object.Stripify();
877010774 if (theobject.selection == null || theobject.selection.Size() == 0)
877110775 theobject.PreprocessOcclusion(this);
....@@ -8778,19 +10782,20 @@
877810782 ambientOcclusion = false;
877910783 }
878010784
8781
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10785
+ if (//Globals.lighttouched &&
10786
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878210787 {
878310788 //if (RENDERSHADOW) // ?
878410789 if (!IsFrozen())
878510790 {
878610791 // dec 2012
8787
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10792
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
878810793 {
8789
- framecount++;
10794
+ Globals.framecount++;
879010795 shadowbuffer.display();
879110796 }
879210797 }
8793
- lighttouched = false; // ??
10798
+ Globals.lighttouched = false; // ??
879410799 //drawing = true;
879510800 //lighttouched = true;
879610801 }
....@@ -8811,9 +10816,9 @@
881110816 //eyeCamera.shaper_fovy = 1;
881210817 }
881310818
8814
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10819
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881510820 {
8816
- //System.out.println("drawMode = " + drawMode);
10821
+ //System.out.println("DrawMode() = " + DrawMode());
881710822 vertexMode |= VP_PASS;
881810823 //vertexMode |= VP_PROJECTION;
881910824 if (!ambientOcclusion)
....@@ -8873,7 +10878,7 @@
887310878 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887410879 //Camera lightcam = new Camera(light0);
887510880
8876
- if (drawMode == SHADOW)
10881
+ if (DrawMode() == SHADOW)
887710882 {
887810883 /*
887910884 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8911,8 +10916,8 @@
891110916
891210917 // if (parentcam != renderCamera) // not a light
891310918 if (cam != lightCamera)
8914
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8915
- LA.matConcat(parentcam.toParent, matrix, matrix);
10919
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891610921
891710922 for (int j = 0; j < 4; j++)
891810923 {
....@@ -8926,8 +10931,8 @@
892610931
892710932 // if (parentcam != renderCamera) // not a light
892810933 if (cam != lightCamera)
8929
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8930
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10934
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893110936
893210937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893310938
....@@ -8963,7 +10968,7 @@
896310968 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896410969 } else
896510970 {
8966
- if (drawMode != DEFAULT)
10971
+ if (DrawMode() != DEFAULT)
896710972 {
896810973 gl.glClearColor(1, 1, 1, 0);
896910974 } // 1);
....@@ -9028,7 +11033,7 @@
902811033
902911034 fast &= !ambientOcclusion;
903011035
9031
- if (drawMode == DEFAULT)
11036
+ if (DrawMode() == DEFAULT)
903211037 {
903311038 //gl.glEnable(gl.GL_ALPHA_TEST);
903411039 //gl.glActiveTexture(GL.GL_TEXTURE0);
....@@ -9089,6 +11094,8 @@
908911094 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909011095 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909111096 double scale = lightCamera.SCALE / lightCamera.Distance();
11097
+// PATCH FILLE AUX JEANS
11098
+ //scale *= lightCamera.shaper_fovy / 25;
909211099 gl.glScaled(2 * scale, 2 * scale, -scale);
909311100 gl.glTranslated(0, 0, lightCamera.DECAL);
909411101
....@@ -9184,7 +11191,16 @@
918411191 // Bump noise
918511192 gl.glActiveTexture(GL.GL_TEXTURE6);
918611193 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9187
- 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
+
918811204
918911205 gl.glActiveTexture(GL.GL_TEXTURE0);
919011206 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9207,9 +11223,9 @@
920711223
920811224 gl.glMatrixMode(GL.GL_MODELVIEW);
920911225
9210
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9211
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9212
-//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);
921311229 } else
921411230 {
921511231 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9220,14 +11236,16 @@
922011236 //System.out.println("BLENDING ON");
922111237 gl.glEnable(GL.GL_BLEND);
922211238 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9223
-
11239
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922411240 gl.glMatrixMode(gl.GL_PROJECTION);
922511241 gl.glLoadIdentity();
922611242
9227
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11243
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
922811244 {
922911245 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923011246 double scale = lightCamera.SCALE / lightCamera.Distance();
11247
+// PATCH FILLE AUX JEANS
11248
+ //scale *= lightCamera.shaper_fovy / 25;
923111249 gl.glScaled(2 * scale, 2 * scale, -scale);
923211250 gl.glTranslated(0, 0, lightCamera.DECAL);
923311251 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9280,7 +11298,7 @@
928011298 //gl.glPushMatrix();
928111299 gl.glLoadIdentity();
928211300
9283
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11301
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928411302 {
928511303 //LA.xformPos(light0, lightCamera.fromScreen, light);
928611304 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9307,8 +11325,8 @@
930711325 System.err.println("parentcam != renderCamera");
930811326
930911327 // if (cam != lightCamera)
9310
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9311
- 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
931211330 }
931311331
931411332 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9329,8 +11347,8 @@
932911347 if (true) // TODO
933011348 {
933111349 if (cam != lightCamera)
9332
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9333
- 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
933411352 }
933511353
933611354 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9367,7 +11385,7 @@
936711385 }
936811386
936911387 /**/
9370
- if (true) // drawMode == SELECTION) // != DEFAULT)
11388
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937111389 gl.glDisable(gl.GL_LIGHTING);
937211390 else
937311391 gl.glEnable(gl.GL_LIGHTING);
....@@ -9379,12 +11397,13 @@
937911397
938011398 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
938111399 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11400
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
938211401
938311402 options2[0] *= renderCamera.Distance();
938411403
938511404 lightslot = 64;
938611405
9387
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11406
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
938811407 {
938911408 DrawLights(object);
939011409 }
....@@ -9395,7 +11414,7 @@
939511414 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
939611415 //System.out.println("fragmentMode = " + fragmentMode);
939711416
9398
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11417
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
939911418 {
940011419 /*
940111420 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9428,7 +11447,7 @@
942811447 }
942911448 }
943011449
9431
- if (drawMode == DEFAULT)
11450
+ if (DrawMode() == DEFAULT)
943211451 {
943311452 if (WIREFRAME && !ambientOcclusion)
943411453 {
....@@ -9446,7 +11465,7 @@
944611465 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
944711466 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
944811467
9449
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11468
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945011469 {
945111470 if (vertexMode != 0) // && !fast)
945211471 {
....@@ -9466,7 +11485,7 @@
946611485 }
946711486 }
946811487
9469
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11488
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947011489 {
947111490 //gl.glDepthFunc(GL.GL_LEQUAL);
947211491 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9474,27 +11493,24 @@
947411493
947511494 boolean texon = textureon;
947611495
9477
- if (RENDERPROGRAM > 0)
9478
- {
9479
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9480
- textureon = false;
9481
- }
11496
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11497
+ textureon = false;
11498
+
948211499 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948311500 //System.out.println("ALLO");
948411501 gl.glColorMask(false, false, false, false);
948511502 DrawObject(gl);
9486
- if (RENDERPROGRAM > 0)
9487
- {
9488
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9489
- textureon = texon;
9490
- }
11503
+
11504
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11505
+ textureon = texon;
11506
+
949111507 gl.glColorMask(true, true, true, true);
949211508
949311509 gl.glDepthFunc(GL.GL_EQUAL);
9494
- //gl.glDepthMask(false);
11510
+ gl.glDepthMask(false);
949511511 }
949611512
9497
- if (false) // drawMode == SHADOW)
11513
+ if (false) // DrawMode() == SHADOW)
949811514 {
949911515 //SetColumnMajorData(cameraInverseTransform, view_1);
950011516 //System.out.println("light = " + cameraInverseTransform);
....@@ -9508,16 +11524,16 @@
950811524 //System.out.println("object = " + object);
950911525 if (!frozen && !imageLocked)
951011526 {
9511
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11527
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951211528 {
951311529 displayAntiAliased(gl);
951411530 } else
951511531 {
951611532 programcount = 0;
9517
- int keepmode = drawMode;
11533
+ int keepmode = DrawMode();
951811534 // if (DEBUG_SELECTION)
951911535 // {
9520
-// drawMode = SELECTION;
11536
+// DrawMode() = SELECTION;
952111537 // }
952211538 // for point selection
952311539 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9527,10 +11543,10 @@
952711543 DrawObject(gl);
952811544
952911545 // jan 2013 System.err.println("RESET ABORT (display)");
9530
- // if (drawMode == DEFAULT)
11546
+ // if (DrawMode() == DEFAULT)
953111547 // ABORTED = false;
953211548 fullreset = false;
9533
- drawMode = keepmode;
11549
+ Globals.drawMode = keepmode; // WARNING
953411550 //System.out.println("PROGRAM SWITCH " + programcount);
953511551 }
953611552 }
....@@ -9538,11 +11554,11 @@
953811554 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
953911555 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954011556
9541
- if (drawMode == DEFAULT)
11557
+ if (DrawMode() == DEFAULT)
954211558 {
954311559 ReleaseTexture(NOISE_TEXTURE, false);
954411560 }
9545
- //if (drawMode == DEFAULT)
11561
+ //if (DrawMode() == DEFAULT)
954611562 {
954711563
954811564 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9554,7 +11570,7 @@
955411570 //else
955511571 //gl.glDisable(gl.GL_TEXTURE_2D);
955611572 //gl.glPopMatrix();
9557
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11573
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
955811574 {
955911575 //new Exception().printStackTrace();
956011576 //System.out.println("Draw image " + width + ", " + height);
....@@ -9596,7 +11612,7 @@
959611612 //gl.glFlush();
959711613 }
959811614
9599
- if (flash && drawMode == DEFAULT)
11615
+ if (flash && DrawMode() == DEFAULT)
960011616 {
960111617 flash = false;
960211618 wait = true;
....@@ -9604,9 +11620,9 @@
960411620 }
960511621
960611622 //drawing = false;
9607
- //if(drawMode == DEFAULT)
11623
+ //if(DrawMode() == DEFAULT)
960811624 // niceon = false;
9609
- if (drawMode == DEFAULT)
11625
+ if (DrawMode() == DEFAULT)
961011626 {
961111627 currentlydrawing = false;
961211628 }
....@@ -9626,7 +11642,7 @@
962611642 repaint();
962711643 }
962811644
9629
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11645
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963011646 repaint();
963111647
963211648 displaydone = true;
....@@ -9645,8 +11661,14 @@
964511661 {
964611662 renderpass++;
964711663 // System.out.println("Draw object... ");
11664
+ STEP = 1;
964811665 if (FAST) // in case there is no script
9649
- STEP = 16;
11666
+ STEP = 8;
11667
+
11668
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11669
+ {
11670
+ STEP *= 4;
11671
+ }
965011672
965111673 //object.FullInvariants();
965211674
....@@ -9660,23 +11682,44 @@
966011682 e.printStackTrace();
966111683 }
966211684
9663
- if (GraphreeD.RENDERME > 0)
9664
- GraphreeD.RENDERME--; // mechante magouille
11685
+ if (Grafreed.RENDERME > 0)
11686
+ Grafreed.RENDERME--; // mechante magouille
966511687
9666
- ONESTEP = false;
11688
+ Globals.ONESTEP = false;
966711689 }
966811690
966911691 static boolean zoomonce = false;
967011692
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
+
967111711 void DrawObject(GL gl, boolean draw)
967211712 {
11713
+ // To clear camera values
11714
+ ResetOptions();
11715
+
967311716 //System.out.println("DRAW OBJECT " + mouseDown);
9674
-// drawMode = SELECTION;
11717
+// DrawMode() = SELECTION;
967511718 //GL gl = getGL();
967611719 if ((TRACK || SHADOWTRACK) || zoomonce)
967711720 {
9678
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9679
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11722
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968011723 pingthread.StepToTarget(true); // true);
968111724 // zoomonce = false;
968211725 }
....@@ -9696,9 +11739,9 @@
969611739 callist = gl.glGenLists(1);
969711740 }
969811741
9699
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11742
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970011743
9701
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11744
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970211745
970311746 if (!mainDL || !active || touched)
970411747 {
....@@ -9725,24 +11768,32 @@
972511768 PushMatrix(ClickInfo.matbuffer);
972611769 }
972711770
9728
- if (drawMode == 0)
11771
+ if (DrawMode() == 0)
972911772 {
973011773 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973111774
973211775 usedtextures.clear();
973311776
9734
- 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
+ }
973511785 }
973611786 //System.out.println("--> " + stackdepth);
9737
-// GraphreeD.traceon();
11787
+// GrafreeD.traceon();
973811788
973911789 // DRAW
974011790 object.draw(this, /*(Composite)*/ object, false, false);
974111791
9742
- if (drawMode == DEFAULT)
11792
+ if (DrawMode() == DEFAULT)
974311793 {
9744
- if (DEBUG)
11794
+ if (Globals.DEBUG)
974511795 {
11796
+ CreateSelectedPoint();
974611797 float radius = 0.05f;
974711798 if (selectedpoint.radius != radius)
974811799 {
....@@ -9750,69 +11801,104 @@
975011801 selectedpoint.radius = radius;
975111802 selectedpoint.recalculate();
975211803 selectedpoint.material = new cMaterial();
9753
- selectedpoint.material.color = 0.25f;
11804
+ selectedpoint.material.color = 0.15f; // Yellow
975411805 selectedpoint.material.modulation = 0.75f;
975511806
9756
- debugpoint.radius = radius;
9757
- debugpoint.recalculate();
9758
- debugpoint.material = new cMaterial();
9759
- debugpoint.material.color = 0.25f;
9760
- 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;
976111812
9762
- debugpoint2.radius = radius;
9763
- debugpoint2.recalculate();
9764
- debugpoint2.material = new cMaterial();
9765
- debugpoint2.material.color = 0.75f;
9766
- 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;
976711830
976811831 InitPoints(radius);
976911832 }
977011833 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9771
- //debugpoint.draw(this, /*(Composite)*/ null, false);
9772
- //debugpoint2.draw(this, /*(Composite)*/ null, false);
9773
- 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);
977411839 }
977511840
977611841 // debugstuff.draw(this, /*(Composite)*/ null, false);
977711842 }
9778
-// GraphreeD.traceoff();
11843
+// GrafreeD.traceoff();
977911844 //System.out.println(stackdepth);
9780
- if (drawMode == 0)
11845
+ if (DrawMode() == 0)
978111846 {
978211847 ReleaseTextures(DEFAULT_TEXTURES);
978311848
978411849 if (CLEANCACHE)
9785
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11850
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
978611851 {
9787
- String tex = e.nextElement();
11852
+ cTexture tex = e.nextElement();
978811853
978911854 // System.out.println("Texture --------- " + tex);
979011855
9791
- if (tex.equals("WHITE_NOISE"))
11856
+ if (tex.equals("WHITE_NOISE:"))
979211857 continue;
979311858
9794
- if (!usedtextures.containsKey(tex))
11859
+ if (!usedtextures.contains(tex))
979511860 {
11861
+ CacheTexture gettex = texturepigment.get(tex);
979611862 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9797
- textures.get(tex).texture.dispose();
9798
- 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
+ }
979911876 }
980011877 }
980111878 }
980211879
980311880 checker = null;
980411881
9805
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11882
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
980611883 FindChecker(object);
980711884
9808
- if (checker != null && drawMode == DEFAULT)
11885
+ if (checker != null && DrawMode() == DEFAULT)
980911886 {
9810
- // 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
+ }
981111896 // NEAREST
981211897 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
981311898 DrawChecker(gl);
981411899 //checker.Draw(this, null, false);
981511900 // ReleaseTexture(IMMORTAL_TEXTURE);
11901
+ ReleaseTextures(checker.GetTextures());
981611902 }
981711903
981811904 if (object.parent != null)
....@@ -9825,7 +11911,7 @@
982511911 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
982611912 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
982711913
9828
- if (DISPLAYTEXT && drawMode == DEFAULT)
11914
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
982911915 {
983011916 // Draw it once, then use the raster
983111917 Balloon(gl, balloon.createGraphics());
....@@ -9881,14 +11967,14 @@
988111967 int[] xs = new int[3];
988211968 int[] ys = new int[3];
988311969
9884
- void DrawString(Object3D obj) // String string)
11970
+ public void DrawString(Object3D obj) // String string) // INTERFACE
988511971 {
9886
- if (!DISPLAYTEXT || drawMode != DEFAULT)
11972
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
988711973 {
988811974 return;
988911975 }
989011976
9891
- String string = obj.GetToolTip();
11977
+ String string = obj.toString(); //.GetToolTip();
989211978
989311979 GL gl = GetGL();
989411980
....@@ -10205,8 +12291,8 @@
1020512291 //obj.TransformToWorld(light, light);
1020612292 for (int i = tp.size(); --i >= 0;)
1020712293 {
10208
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10209
- 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);
1021012296 }
1021112297
1021212298
....@@ -10223,8 +12309,8 @@
1022312309 parentcam = cameras[0];
1022412310 }
1022512311
10226
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10227
- 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
1022812314
1022912315 LA.xformPos(light, renderCamera.toScreen, light);
1023012316
....@@ -10315,7 +12401,74 @@
1031512401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1031612402
1031712403 String program =
12404
+ // Min shader
1031812405 "!!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
+
1031912472 //"OPTION ARB_fragment_program_shadow;" +
1032012473 "PARAM light2cam0 = program.env[10];" +
1032112474 "PARAM light2cam1 = program.env[11];" +
....@@ -10343,11 +12496,13 @@
1034312496 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1034412497 "PARAM params7 = program.env[7];" + // noise power, opacity power
1034512498 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10346
- "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
1034712501 "PARAM pointlight = program.env[127];" + // ...
1034812502 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1034912503 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1035012504 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12505
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1035112506 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1035212507 "PARAM ten = { 10, 10, 10, 1.0 };" +
1035312508 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10368,6 +12523,7 @@
1036812523 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1036912524 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1037012525 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12526
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1037112527 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1037212528 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1037312529 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10408,6 +12564,10 @@
1040812564 "TEMP R1;" +
1040912565 "TEMP R2;" +
1041012566 "TEMP R3;" +
12567
+ "TEMP min;" +
12568
+ "TEMP max;" +
12569
+ "TEMP average;" +
12570
+ "TEMP saturation;" +
1041112571 "TEMP keep1;" +
1041212572 "TEMP keep2;" +
1041312573 "TEMP keep3;" +
....@@ -10423,8 +12583,7 @@
1042312583 "TEMP shininess;" +
1042412584 "\n" +
1042512585 "MOV texSamp, one;" +
10426
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10427
-
12586
+
1042812587 "MOV mapgrid.x, one2048th.x;" +
1042912588 "MOV temp, fragment.texcoord[1];" +
1043012589 /*
....@@ -10445,20 +12604,20 @@
1044512604 "MUL temp, floor, mapgrid.x;" +
1044612605 //"TEX depth0, temp, texture[1], 2D;" +
1044712606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10448
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1044912608 "") +
1045012609 "ADD temp.x, temp.x, mapgrid.x;" +
1045112610 //"TEX depth1, temp, texture[1], 2D;" +
1045212611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10453
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1045412613 "") +
1045512614 "ADD temp.y, temp.y, mapgrid.x;" +
1045612615 //"TEX depth2, temp, texture[1], 2D;" +
10457
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1045812617 "SUB temp.x, temp.x, mapgrid.x;" +
1045912618 //"TEX depth3, temp, texture[1], 2D;" +
1046012619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10461
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1046212621 "") +
1046312622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1046412623 //"MOV params, material;" +
....@@ -10829,10 +12988,10 @@
1082912988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1083012989 "") +
1083112990
10832
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1083312992 "SUB temp.x, half.x, shadow.x;" +
10834
- "MOV temp.y, -params6.x;" +
10835
- "SLT temp.z, temp.y, zero.x;" +
12993
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12994
+ "SLT temp.z, temp.y, -one2048th.x;" +
1083612995 "SUB temp.y, one.x, temp.z;" +
1083712996 "MUL temp.x, temp.x, temp.y;" +
1083812997 "KIL temp.x;" +
....@@ -10938,10 +13097,42 @@
1093813097
1093913098 // skin?
1094013099 // Saturation for skin
10941
- /**/ // c'est ici
10942
- (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;" +
1094313133 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10944
- "SUB temp, final,R2;" +
13134
+ "SUB temp, final, R2;" +
13135
+
1094513136 // using light angle
1094613137 "DP3 ndotl.x, normald,light;" +
1094713138 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10954,7 +13145,6 @@
1095413145 // using light intensity
1095513146 "MOV ndotl.z, R2.x;" +
1095613147 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10957
-
1095813148 // june 2014
1095913149 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1096013150 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10966,6 +13156,7 @@
1096613156 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1096713157
1096813158 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13159
+/**/
1096913160
1097013161 // "ADD final, R2,temp;" +
1097113162 "MOV final, temp;"
....@@ -11055,7 +13246,7 @@
1105513246 /**/
1105613247 // HDR
1105713248 "MOV temp.z, final.a;" +
11058
- "MUL final, final,options1.w;" +
13249
+ "MUL final, final,options2.x;" +
1105913250 "MOV final.a, temp.z;" +
1106013251 /**/
1106113252
....@@ -11092,10 +13283,17 @@
1109213283 "MOV final.z, zero.x;" +
1109313284 "MOV final.a, one.w;":""
1109413285 ) +
13286
+ /*
1109513287 (NORMALdebug?"MOV final.x, normal.x;" +
1109613288 "MOV final.y, normal.y;" +
1109713289 "MOV final.z, normal.z;" +
1109813290 "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;":""
1109913297 ) +
1110013298 // "MOV final, bumpmap;" +
1110113299 "MOV result.color, final;" +
....@@ -11124,7 +13322,7 @@
1112413322 //once = true;
1112513323 }
1112613324
11127
- System.out.print("Program #" + mode + "; length = " + program.length());
13325
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1112813326 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1112913327 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1113013328
....@@ -11217,30 +13415,32 @@
1121713415 return out;
1121813416 }
1121913417
11220
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1122113420 {
1122213421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1122313422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1122413423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1122513426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11226
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11227
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11228
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11229
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1123013429 //"SWZ buffer, temp, w,w,w,w;";
11231
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1123213431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1123313432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1123413433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11235
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1123613435
11237
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11238
- //"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;";
1123913438 }
1124013439
1124113440 String Shadow(String depth, String shadow)
1124213441 {
1124313442 return "MAX temp.x, ndotl.x, one64th.x;" +
13443
+ "MIN temp.x, temp.x, ninetenth.x;" +
1124413444 /**/
1124513445 // Sine
1124613446 "MUL temp.y, temp.x, temp.x;" +
....@@ -11256,12 +13456,16 @@
1125613456
1125713457 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1125813458 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13459
+
13460
+ // Compare fragment depth in light space with shadowmap.
1125913461 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1126013462 "SGE temp.y, temp.x, zero.x;" +
11261
- "SUB " + shadow + ".y, one.x, temp.y;" +
13463
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13464
+
13465
+ // Reverse comparison
1126213466 "SUB temp.x, one.x, temp.x;" +
1126313467 "MUL " + shadow + ".x, temp.x, temp.y;" +
11264
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13468
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1126513469 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1126613470
1126713471 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11275,6 +13479,10 @@
1127513479 // No shadow for backface
1127613480 "DP3 temp.x, normal, lightd;" +
1127713481 "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;" +
1127813486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1127913487 "";
1128013488 }
....@@ -11421,7 +13629,8 @@
1142113629 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1142213630 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1142313631 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11424
- Object3D.cVector2[] vector2buffer;
13632
+
13633
+ //Object3D.cVector2[] vector2buffer;
1142513634
1142613635 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1142713636 // OUT : diff, spec
....@@ -11437,9 +13646,10 @@
1143713646 "DP3 " + dest + ".z," + "normals," + "eye;" +
1143813647 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1143913648 //"MOV " + dest + ".w," + "normal.z;" +
11440
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11441
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11442
- //"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
1144313653 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1144413654 "RCP " + dest + ".w," + dest + ".w;" +
1144513655 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11833,7 +14043,7 @@
1183314043 public void mousePressed(MouseEvent e)
1183414044 {
1183514045 //System.out.println("mousePressed: " + e);
11836
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14046
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1183714047 }
1183814048
1183914049 static long prevtime = 0;
....@@ -11860,14 +14070,16 @@
1186014070
1186114071 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1186214072
14073
+ if (BUTTONLESSWHEEL)
1186314074 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1186414075 {
1186514076 return;
1186614077 }
1186714078
14079
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1186814080
1186914081 // TIMER
11870
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14082
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1187114083 {
1187214084 keepboxmode = BOXMODE;
1187314085 keepsupport = SUPPORT;
....@@ -11907,8 +14119,8 @@
1190714119 // mode |= META;
1190814120 //}
1190914121
11910
- SetMouseMode(WHEEL | e.getModifiersEx());
11911
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14122
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14123
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1191214124 anchorX = ax;
1191314125 anchorY = ay;
1191414126 prevX = px;
....@@ -11942,6 +14154,7 @@
1194214154 else
1194314155 if (evt.getSource() == AAtimer)
1194414156 {
14157
+ Globals.TIMERRUNNING = false;
1194514158 if (mouseDown)
1194614159 {
1194714160 //new Exception().printStackTrace();
....@@ -11967,6 +14180,10 @@
1196714180 // LIVE = waslive;
1196814181 // wasliveok = true;
1196914182 // waslive = false;
14183
+
14184
+ // May 2019 Forget it:
14185
+ if (true)
14186
+ return;
1197014187
1197114188 // source == timer
1197214189 if (mouseDown)
....@@ -11996,8 +14213,8 @@
1199614213 // ObjEditor.tweenManager.update(1f / 60f);
1199714214
1199814215 // fev 2014???
11999
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12000
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14216
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14217
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1200114218 pingthread.StepToTarget(true); // true);
1200214219 }
1200314220 // if (!LIVE)
....@@ -12006,12 +14223,13 @@
1200614223
1200714224 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1200814225
12009
- void clickStart(int x, int y, int modifiers)
14226
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1201014227 {
1201114228 if (!wasliveok)
1201214229 return;
1201314230
1201414231 AAtimer.restart(); //
14232
+ Globals.TIMERRUNNING = true;
1201514233
1201614234 // waslive = LIVE;
1201714235 // LIVE = false;
....@@ -12023,7 +14241,7 @@
1202314241 // touched = true; // main DL
1202414242 if (isRenderer)
1202514243 {
12026
- SetMouseMode(modifiers);
14244
+ SetMouseMode(modifiers, modifiersex);
1202714245 }
1202814246
1202914247 selectX = anchorX = x;
....@@ -12036,7 +14254,7 @@
1203614254 clicked = true;
1203714255 hold = false;
1203814256
12039
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14257
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1204014258 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1204114259 {
1204214260 // System.out.println("RESTART II " + modifiers);
....@@ -12061,14 +14279,15 @@
1206114279 drag = false;
1206214280 //System.out.println("Mouse DOWN");
1206314281 editObj = false;
12064
- ClickInfo info = new ClickInfo();
12065
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12066
- info.pane = this;
12067
- info.camera = renderCamera;
12068
- info.x = x;
12069
- info.y = y;
12070
- info.modifiers = modifiers;
12071
- 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);
1207214291 if (!editObj)
1207314292 {
1207414293 hasMarquee = true;
....@@ -12084,11 +14303,14 @@
1208414303
1208514304 public void mouseDragged(MouseEvent e)
1208614305 {
14306
+ Globals.MOUSEDRAGGED = true;
14307
+
14308
+ //System.out.println("mouseDragged: " + e);
1208714309 if (isRenderer)
1208814310 movingcamera = true;
14311
+
1208914312 //if (drawing)
1209014313 //return;
12091
- //System.out.println("mouseDragged: " + e);
1209214314 if ((e.getModifiersEx() & CTRL) != 0
1209314315 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1209414316 {
....@@ -12096,7 +14318,7 @@
1209614318 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1209714319 }
1209814320 else
12099
- drag(e.getX(), e.getY(), e.getModifiersEx());
14321
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1210014322
1210114323 //try { Thread.sleep(1); } catch (Exception ex) {}
1210214324 }
....@@ -12108,6 +14330,11 @@
1210814330 cVector tmp = new cVector();
1210914331 cVector tmp2 = new cVector();
1211014332 boolean isMoving;
14333
+
14334
+ public cVector TargetLookAt()
14335
+ {
14336
+ return targetLookAt;
14337
+ }
1211114338
1211214339 class PingThread extends Thread
1211314340 {
....@@ -12247,7 +14474,7 @@
1224714474 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1224814475 if (lightMode)
1224914476 {
12250
- lighttouched = true;
14477
+ Globals.lighttouched = true;
1225114478 }
1225214479
1225314480 if (OEILONCE && OEIL)
....@@ -12264,6 +14491,7 @@
1226414491
1226514492 public void run()
1226614493 {
14494
+ new Exception().printStackTrace();
1226714495 System.exit(0);
1226814496 for (;;)
1226914497 {
....@@ -12305,7 +14533,7 @@
1230514533 mouseDown = false;
1230614534 if (lightMode)
1230714535 {
12308
- lighttouched = true;
14536
+ Globals.lighttouched = true;
1230914537 }
1231014538 repaint();
1231114539 alreadypainted = true;
....@@ -12313,7 +14541,7 @@
1231314541 isMoving = false;
1231414542 } //??
1231514543
12316
- if (isLIVE() && !alreadypainted)
14544
+ if (Globals.isLIVE() && !alreadypainted)
1231714545 {
1231814546 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1231914547 repaint();
....@@ -12325,9 +14553,9 @@
1232514553 {
1232614554 if (lightMode)
1232714555 {
12328
- lighttouched = true;
14556
+ Globals.lighttouched = true;
1232914557 }
12330
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14558
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1233114559 }
1233214560 //else
1233314561 }
....@@ -12341,12 +14569,12 @@
1234114569 void GoDown(int mod)
1234214570 {
1234314571 MODIFIERS |= COMMAND;
12344
- /*
14572
+ /**/
1234514573 if((mod&SHIFT) == SHIFT)
1234614574 manipCamera.RotatePosition(0, -speed);
1234714575 else
12348
- manipCamera.BackForth(0, -speed*delta, getWidth());
12349
- */
14576
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14577
+ /**/
1235014578 if ((mod & SHIFT) == SHIFT)
1235114579 {
1235214580 mouseMode = mouseMode; // VR??
....@@ -12362,12 +14590,12 @@
1236214590 void GoUp(int mod)
1236314591 {
1236414592 MODIFIERS |= COMMAND;
12365
- /*
14593
+ /**/
1236614594 if((mod&SHIFT) == SHIFT)
1236714595 manipCamera.RotatePosition(0, speed);
1236814596 else
12369
- manipCamera.BackForth(0, speed*delta, getWidth());
12370
- */
14597
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14598
+ /**/
1237114599 if ((mod & SHIFT) == SHIFT)
1237214600 {
1237314601 mouseMode = mouseMode;
....@@ -12383,12 +14611,12 @@
1238314611 void GoLeft(int mod)
1238414612 {
1238514613 MODIFIERS |= COMMAND;
12386
- /*
14614
+ /**/
1238714615 if((mod&SHIFT) == SHIFT)
12388
- manipCamera.RotatePosition(speed, 0);
12389
- else
1239014616 manipCamera.Translate(speed*delta, 0, getWidth());
12391
- */
14617
+ else
14618
+ manipCamera.RotatePosition(speed, 0);
14619
+ /**/
1239214620 if ((mod & SHIFT) == SHIFT)
1239314621 {
1239414622 mouseMode = mouseMode;
....@@ -12404,12 +14632,12 @@
1240414632 void GoRight(int mod)
1240514633 {
1240614634 MODIFIERS |= COMMAND;
12407
- /*
14635
+ /**/
1240814636 if((mod&SHIFT) == SHIFT)
12409
- manipCamera.RotatePosition(-speed, 0);
12410
- else
1241114637 manipCamera.Translate(-speed*delta, 0, getWidth());
12412
- */
14638
+ else
14639
+ manipCamera.RotatePosition(-speed, 0);
14640
+ /**/
1241314641 if ((mod & SHIFT) == SHIFT)
1241414642 {
1241514643 mouseMode = mouseMode;
....@@ -12427,7 +14655,7 @@
1242714655 int X, Y;
1242814656 boolean SX, SY;
1242914657
12430
- void drag(int x, int y, int modifiers)
14658
+ void drag(int x, int y, int modifiers, int modifiersex)
1243114659 {
1243214660 if (IsFrozen())
1243314661 {
....@@ -12436,17 +14664,17 @@
1243614664
1243714665 drag = true; // NEW
1243814666
12439
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14667
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1244014668
1244114669 X = x;
1244214670 Y = y;
1244314671 // floating state for animation
12444
- MODIFIERS = modifiers;
12445
- modifiers &= ~1024;
14672
+ MODIFIERS = modifiersex;
14673
+ modifiersex &= ~1024;
1244614674 if (false) // modifiers != 0)
1244714675 {
1244814676 //new Exception().printStackTrace();
12449
- System.out.println("mouseDragged: " + modifiers);
14677
+ System.out.println("mouseDragged: " + modifiersex);
1245014678 System.out.println("SHIFT = " + SHIFT);
1245114679 System.out.println("CONTROL = " + COMMAND);
1245214680 System.out.println("META = " + META);
....@@ -12459,14 +14687,16 @@
1245914687 if (editObj)
1246014688 {
1246114689 drag = true;
12462
- ClickInfo info = new ClickInfo();
12463
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1246414692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12465
- info.pane = this;
12466
- info.camera = renderCamera;
12467
- info.x = x;
12468
- info.y = y;
12469
- 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);
1247014700 } else
1247114701 {
1247214702 if (x < startX)
....@@ -12568,6 +14798,7 @@
1256814798 {
1256914799 manipCamera.Translate(dx, dy, getWidth());
1257014800 }
14801
+ else
1257114802 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1257214803 {
1257314804 manipCamera.RotateInterest(dx, dy);
....@@ -12578,7 +14809,7 @@
1257814809
1257914810 if (manipCamera == lightCamera)
1258014811 {
12581
- lighttouched = true;
14812
+ Globals.lighttouched = true;
1258214813 }
1258314814 /*
1258414815 switch (mode)
....@@ -12614,23 +14845,27 @@
1261414845 }
1261514846 }
1261614847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1261714850 public void mouseMoved(MouseEvent e)
1261814851 {
1261914852 //System.out.println("mouseMoved: " + e);
12620
-
1262114853 if (isRenderer)
1262214854 return;
1262314855
12624
- ClickInfo ci = new ClickInfo();
12625
- ci.x = e.getX();
12626
- ci.y = e.getY();
12627
- ci.modifiers = e.getModifiersEx();
12628
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12629
- ci.pane = this;
12630
- 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;
1263114863 if (!isRenderer)
1263214864 {
12633
- if (object.editWindow.copy.doEditClick(ci, 0))
14865
+ //ObjEditor editWindow = object.editWindow;
14866
+ //Object3D copy = editWindow.copy;
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1263414869 {
1263514870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1263614871 } else
....@@ -12642,7 +14877,11 @@
1264214877
1264314878 public void mouseReleased(MouseEvent e)
1264414879 {
14880
+ Globals.MOUSEDRAGGED = false;
14881
+
1264514882 movingcamera = false;
14883
+ X = 0; // getBounds().width/2;
14884
+ Y = 0; // getBounds().height/2;
1264614885 //System.out.println("mouseReleased: " + e);
1264714886 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1264814887 }
....@@ -12665,9 +14904,9 @@
1266514904 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1266614905 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1266714906
12668
- if (control || command || IsFrozen())
14907
+// No delay if (control || command || IsFrozen())
1266914908 timeout = true;
12670
- else
14909
+// ?? May 2019 else
1267114910 // timer.setDelay((modifiers & 128) != 0?0:350);
1267214911 mouseDown = false;
1267314912 if (!control && !command) // june 2013
....@@ -12777,7 +15016,7 @@
1277715016 System.out.println("keyReleased: " + e);
1277815017 }
1277915018
12780
- void SetMouseMode(int modifiers)
15019
+ void SetMouseMode(int modifiers, int modifiersex)
1278115020 {
1278215021 //System.out.println("SetMouseMode = " + modifiers);
1278315022 //modifiers &= ~1024;
....@@ -12789,24 +15028,27 @@
1278915028 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1279015029 // return;
1279115030 //System.out.println("SetMode = " + modifiers);
12792
- if ((modifiers & WHEEL) == WHEEL)
15031
+ if ((modifiersex & WHEEL) == WHEEL)
1279315032 {
1279415033 mouseMode |= ZOOM;
1279515034 }
12796
- if ((modifiers & META) == META)
15035
+
15036
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15037
+ if (capsLocked) // || (modifiers & META) == META)
1279715038 {
1279815039 mouseMode |= VR; // BACKFORTH;
1279915040 }
12800
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12801
- {
12802
- mouseMode |= SELECT; // BACKFORTH;
12803
- }
12804
- if ((modifiers & COMMAND) == COMMAND)
15041
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1280515042 {
1280615043 mouseMode |= SELECT;
1280715044 }
12808
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15045
+ if ((modifiersex & COMMAND) == COMMAND)
1280915046 {
15047
+ mouseMode |= SELECT;
15048
+ }
15049
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15050
+ {
15051
+ mouseMode &= ~VR;
1281015052 mouseMode |= TRANSLATE;
1281115053 }
1281215054 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12833,10 +15075,10 @@
1283315075
1283415076 if (isRenderer) //
1283515077 {
12836
- SetMouseMode(modifiers);
15078
+ SetMouseMode(0, modifiers);
1283715079 }
1283815080
12839
- theRenderer.keyPressed(key);
15081
+ Globals.theRenderer.keyPressed(key);
1284015082 }
1284115083
1284215084 int kompactbit = 4; // power bit
....@@ -12848,7 +15090,7 @@
1284815090 float SATPOW = 1; // 2; // 0.5f;
1284915091 float BRIPOW = 1; // 0.5f; // 0.5f;
1285015092
12851
- void keyPressed(int key)
15093
+ public void keyPressed(int key)
1285215094 {
1285315095 if (key >= '0' && key <= '5')
1285415096 clampbit = (key-'0');
....@@ -12895,7 +15137,8 @@
1289515137 // break;
1289615138 case 'T':
1289715139 CACHETEXTURE ^= true;
12898
- textures.clear();
15140
+ texturepigment.clear();
15141
+ texturebump.clear();
1289915142 // repaint();
1290015143 break;
1290115144 case 'Y':
....@@ -12963,7 +15206,7 @@
1296315206 case 'B':
1296415207 BRISMOOTH ^= true;
1296515208 SHADOWCULLFACE ^= true;
12966
- lighttouched = true;
15209
+ Globals.lighttouched = true;
1296715210 repaint();
1296815211 break;
1296915212 case 'b':
....@@ -12980,7 +15223,9 @@
1298015223 case 'E' : COMPACT ^= true;
1298115224 repaint();
1298215225 break;
12983
- case 'W' : DEBUGHSB ^= true;
15226
+ case 'W' : // Wide Window (fullscreen)
15227
+ //DEBUGHSB ^= true;
15228
+ ObjEditor.theFrame.ToggleFullScreen();
1298415229 repaint();
1298515230 break;
1298615231 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13005,8 +15250,8 @@
1300515250 RevertCamera();
1300615251 repaint();
1300715252 break;
13008
- case 'L':
1300915253 case 'l':
15254
+ //case 'L':
1301015255 if (lightMode)
1301115256 {
1301215257 lightMode = false;
....@@ -13063,7 +15308,7 @@
1306315308 repaint();
1306415309 break;
1306515310 case 'O':
13066
- drawMode = OCCLUSION;
15311
+ Globals.drawMode = OCCLUSION; // WARNING
1306715312 repaint();
1306815313 break;
1306915314 case 'o':
....@@ -13149,12 +15394,12 @@
1314915394 case '_':
1315015395 kompactbit = 5;
1315115396 break;
13152
- case '+':
13153
- kompactbit = 6;
13154
- break;
15397
+// case '+':
15398
+// kompactbit = 6;
15399
+// break;
1315515400 case ' ':
1315615401 lightMode ^= true;
13157
- lighttouched = true;
15402
+ Globals.lighttouched = true;
1315815403 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1315915404 targetLookAt.set(manipCamera.lookAt);
1316015405 repaint();
....@@ -13163,14 +15408,15 @@
1316315408 case ESC:
1316415409 RENDERPROGRAM += 1;
1316515410 RENDERPROGRAM %= 3;
15411
+
1316615412 repaint();
1316715413 break;
1316815414 case 'Z':
13169
- RESIZETEXTURE ^= true;
13170
- break;
15415
+ //RESIZETEXTURE ^= true;
15416
+ //break;
1317115417 case 'z':
13172
- RENDERSHADOW ^= true;
13173
- lighttouched = true;
15418
+ Globals.RENDERSHADOW ^= true;
15419
+ Globals.lighttouched = true;
1317415420 repaint();
1317515421 break;
1317615422 //case UP:
....@@ -13196,13 +15442,15 @@
1319615442 FlipTransform();
1319715443 break;
1319815444 case ENTER:
13199
- object.editWindow.ScreenFit(); // Edit();
15445
+ // object.editWindow.ScreenFit(); // Edit();
15446
+ ToggleLive();
1320015447 break;
1320115448 case DELETE:
1320215449 ClearSelection();
1320315450 break;
13204
- /*
1320515451 case '+':
15452
+
15453
+ /*
1320615454 //fontsize += 1;
1320715455 bbzoom *= 2;
1320815456 repaint();
....@@ -13219,17 +15467,17 @@
1321915467 case '=':
1322015468 IncDepth();
1322115469 //fontsize += 1;
13222
- object.editWindow.refreshContents(true);
15470
+ object.GetWindow().refreshContents(true);
1322315471 maskbit = 6;
1322415472 break;
1322515473 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1322615474 DecDepth();
1322715475 maskbit = 5;
1322815476 //if(fontsize > 1) fontsize -= 1;
13229
- if (object.editWindow == null)
13230
- new Exception().printStackTrace();
13231
- else
13232
- object.editWindow.refreshContents(true);
15477
+// if (object.editWindow == null)
15478
+// new Exception().printStackTrace();
15479
+// else
15480
+ object.GetWindow().refreshContents(true);
1323315481 break;
1323415482 case '{':
1323515483 manipCamera.shaper_fovy /= 1.1;
....@@ -13284,6 +15532,7 @@
1328415532 }
1328515533 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1328615534 }
15535
+
1328715536 static double OCCLUSIONBOOST = 1; // 0.5;
1328815537
1328915538 void keyReleased(int key, int modifiers)
....@@ -13291,11 +15540,11 @@
1329115540 //mode = ROTATE;
1329215541 if ((MODIFIERS & COMMAND) == 0) // VR??
1329315542 {
13294
- SetMouseMode(modifiers);
15543
+ SetMouseMode(0, modifiers);
1329515544 }
1329615545 }
1329715546
13298
- protected void processKeyEvent(KeyEvent e)
15547
+ public void processKeyEvent(KeyEvent e)
1329915548 {
1330015549 switch (e.getID())
1330115550 {
....@@ -13425,8 +15674,9 @@
1342515674
1342615675 protected void processMouseMotionEvent(MouseEvent e)
1342715676 {
13428
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13429
- 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)
1343015680 {
1343115681 mouseMoved(e);
1343215682 } else
....@@ -13451,11 +15701,12 @@
1345115701 }
1345215702 */
1345315703
13454
- object.editWindow.EditSelection();
15704
+ object.GetWindow().EditSelection(false);
1345515705 }
1345615706
1345715707 void SelectParent()
1345815708 {
15709
+ new Exception().printStackTrace();
1345915710 System.exit(0);
1346015711 Composite group = (Composite) object;
1346115712 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13467,10 +15718,10 @@
1346715718 {
1346815719 //selectees.remove(i);
1346915720 System.out.println("select parent of " + elem);
13470
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15721
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1347115722 } else
1347215723 {
13473
- group.editWindow.Select(elem.GetTreePath(), first, true);
15724
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1347415725 }
1347515726
1347615727 first = false;
....@@ -13479,6 +15730,7 @@
1347915730
1348015731 void SelectChildren()
1348115732 {
15733
+ new Exception().printStackTrace();
1348215734 System.exit(0);
1348315735 /*
1348415736 Composite group = (Composite) object;
....@@ -13511,12 +15763,12 @@
1351115763 for (int j = 0; j < group.children.size(); j++)
1351215764 {
1351315765 elem = (Object3D) group.children.elementAt(j);
13514
- object.editWindow.Select(elem.GetTreePath(), first, true);
15766
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1351515767 first = false;
1351615768 }
1351715769 } else
1351815770 {
13519
- object.editWindow.Select(elem.GetTreePath(), first, true);
15771
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1352015772 }
1352115773
1352215774 first = false;
....@@ -13527,21 +15779,21 @@
1352715779 {
1352815780 //Composite group = (Composite) object;
1352915781 Object3D group = object;
13530
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15782
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1353115783 }
1353215784
1353315785 void ResetTransform(int mask)
1353415786 {
1353515787 //Composite group = (Composite) object;
1353615788 Object3D group = object;
13537
- group.editWindow.ResetTransform(mask);
15789
+ group.GetWindow().ResetTransform(mask);
1353815790 }
1353915791
1354015792 void FlipTransform()
1354115793 {
1354215794 //Composite group = (Composite) object;
1354315795 Object3D group = object;
13544
- group.editWindow.FlipTransform();
15796
+ group.GetWindow().FlipTransform();
1354515797 // group.editWindow.ReduceMesh(true);
1354615798 }
1354715799
....@@ -13549,7 +15801,7 @@
1354915801 {
1355015802 //Composite group = (Composite) object;
1355115803 Object3D group = object;
13552
- group.editWindow.PrintMemory();
15804
+ group.GetWindow().PrintMemory();
1355315805 // group.editWindow.ReduceMesh(true);
1355415806 }
1355515807
....@@ -13557,7 +15809,7 @@
1355715809 {
1355815810 //Composite group = (Composite) object;
1355915811 Object3D group = object;
13560
- group.editWindow.ResetCentroid();
15812
+ group.GetWindow().ResetCentroid();
1356115813 }
1356215814
1356315815 void IncDepth()
....@@ -13639,11 +15891,11 @@
1363915891
1364015892 int width = getBounds().width;
1364115893 int height = getBounds().height;
13642
- ClickInfo info = new ClickInfo();
13643
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1364415894 //Image img = CreateImage(width, height);
1364515895 //System.out.println("width = " + width + "; height = " + height + "\n");
15896
+
1364615897 Graphics gr = g; // img.getGraphics();
15898
+
1364715899 if (!hasMarquee)
1364815900 {
1364915901 if (Xmin < Xmax) // !locked)
....@@ -13715,40 +15967,88 @@
1371515967 }
1371615968 if (object != null && !hasMarquee)
1371715969 {
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
+
1371815976 if (isRenderer)
1371915977 {
13720
- info.flags++;
15978
+ object.clickInfo.flags++;
1372115979 double frameAspect = (double) width / (double) height;
1372215980 if (frameAspect > renderCamera.aspect)
1372315981 {
1372415982 int desired = (int) ((double) height * renderCamera.aspect);
13725
- info.bounds.width -= width - desired;
13726
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1372715985 } else
1372815986 {
1372915987 int desired = (int) ((double) width / renderCamera.aspect);
13730
- info.bounds.height -= height - desired;
13731
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1373215990 }
1373315991 }
13734
- info.g = gr;
13735
- info.camera = renderCamera;
15992
+
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1373615995 /*
1373715996 // Memory intensive (brep.verticescopy)
1373815997 if (!(object instanceof Composite))
1373915998 object.draw(info, 0, false); // SLOW :
1374015999 */
13741
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1374216001 {
13743
- 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
+ }
1374416042 }
1374516043 }
16044
+
1374616045 if (isRenderer)
1374716046 {
1374816047 //gr.setColor(Color.black);
1374916048 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1375016049 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1375116050 }
16051
+
1375216052 if (hasMarquee)
1375316053 {
1375416054 gr.setXORMode(Color.white);
....@@ -13771,6 +16071,7 @@
1377116071 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1377216072 }
1377316073
16074
+ // To avoid clear.
1377416075 public void update(Graphics g)
1377516076 {
1377616077 paint(g);
....@@ -13860,6 +16161,7 @@
1386016161 public boolean mouseDown(Event evt, int x, int y)
1386116162 {
1386216163 System.out.println("mouseDown: " + evt);
16164
+ System.exit(0);
1386316165 /*
1386416166 locked = true;
1386516167 drag = false;
....@@ -13903,7 +16205,7 @@
1390316205 {
1390416206 keyPressed(0, modifiers);
1390516207 }
13906
- clickStart(x, y, modifiers);
16208
+ // clickStart(x, y, modifiers);
1390716209 return true;
1390816210 }
1390916211
....@@ -14021,7 +16323,7 @@
1402116323 {
1402216324 keyReleased(0, 0);
1402316325 }
14024
- drag(x, y, modifiers);
16326
+ drag(x, y, 0, modifiers);
1402516327 return true;
1402616328 }
1402716329
....@@ -14153,7 +16455,7 @@
1415316455 Object3D object;
1415416456 static Object3D trackedobject;
1415516457 Camera renderCamera; // Light or Eye (or Occlusion)
14156
- /*static*/ Camera manipCamera; // Light or Eye
16458
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1415716459 /*static*/ Camera eyeCamera;
1415816460 /*static*/ Camera lightCamera;
1415916461 int cameracount;
....@@ -14373,7 +16675,7 @@
1437316675 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1437416676 gl.glPushMatrix();
1437516677 gl.glLoadIdentity();
14376
- PushMatrix(checker.toParent);
16678
+ //PushMatrix(checker.toParent);
1437716679
1437816680 gl.glMatrixMode(GL.GL_TEXTURE);
1437916681 gl.glPushMatrix();
....@@ -14396,8 +16698,8 @@
1439616698
1439716699 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1439816700
14399
- float step = 0.1666f; //0.25f;
14400
- float stepv = step * 1652 / 998;
16701
+ float step = 2; // 0.1666f; //0.25f;
16702
+ float stepv = 2; // step * 1652 / 998;
1440116703
1440216704 int i0 = 0;
1440316705 /*
....@@ -14433,20 +16735,21 @@
1443316735 /**/
1443416736 //checker.GetMaterial().opacity = 1.1f;
1443516737 ////checker.GetMaterial().ambient = 0.99f;
14436
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14437
- Object3D.selectedstack[Object3D.materialdepth] = false;
14438
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16738
+ materialstack[materialdepth] = checker.material;
16739
+ selectedstack[materialdepth] = false;
16740
+ cStatic.objectstack[materialdepth++] = checker;
1443916741 //System.out.println("material " + material);
1444016742 //Applet3D.tracein(this, selected);
14441
- vector2buffer = checker.projectedVertices;
16743
+ //vector2buffer = checker.projectedVertices;
1444216744
14443
- checker.GetMaterial().Draw(this, false); // true);
16745
+ //checker.GetMaterial().Draw(this, false); // true);
16746
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1444416747
14445
- Object3D.materialdepth -= 1;
14446
- if (Object3D.materialdepth > 0)
16748
+ materialdepth -= 1;
16749
+ if (materialdepth > 0)
1444716750 {
14448
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14449
- 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);
1445016753 }
1445116754 //checker.GetMaterial().opacity = 1f;
1445216755 ////checker.GetMaterial().ambient = 1f;
....@@ -14467,15 +16770,27 @@
1446716770
1446816771 //float u = (i+1)/2;
1446916772 //float v = (j+1)/2;
14470
- 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);
1447116777 gl.glVertex3f(i, j, -0.5f);
1447216778
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
1447316782 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1447416783 gl.glVertex3f(i + step, j, -0.5f);
1447516784
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
1447616788 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1447716789 gl.glVertex3f(i + step, j + stepv, -0.5f);
1447816790
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
1447916794 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1448016795 gl.glVertex3f(i, j + stepv, -0.5f);
1448116796 }
....@@ -14487,7 +16802,7 @@
1448716802 gl.glMatrixMode(GL.GL_PROJECTION);
1448816803 gl.glPopMatrix();
1448916804 gl.glMatrixMode(GL.GL_MODELVIEW);
14490
- PopMatrix(null); // checker.toParent); // null);
16805
+ //PopMatrix(null); // checker.toParent); // null);
1449116806 gl.glPopMatrix();
1449216807 PopTextureMatrix(checker.toParent);
1449316808 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14520,6 +16835,14 @@
1452016835 }
1452116836 }
1452216837
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
+
1452316846 class SelectBuffer implements GLEventListener
1452416847 {
1452516848
....@@ -14578,6 +16901,7 @@
1457816901 {
1457916902 if (!selection)
1458016903 {
16904
+ new Exception().printStackTrace();
1458116905 System.exit(0);
1458216906 return;
1458316907 }
....@@ -14598,17 +16922,39 @@
1459816922
1459916923 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1460016924
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
+
1460116936 //int tmp = selection_view;
1460216937 //selection_view = -1;
14603
- int temp = drawMode;
14604
- drawMode = SELECTION;
16938
+ int temp = DrawMode();
16939
+ Globals.drawMode = SELECTION; // WARNING
1460516940 indexcount = 0;
1460616941 parent.display(drawable);
1460716942 //selection_view = tmp;
1460816943 //if (temp == SELECTION)
1460916944 // temp = DEFAULT; // patch for selection debug
14610
- drawMode = temp;
16945
+ Globals.drawMode = temp; // WARNING
1461116946
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
+
1461216958 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1461316959
1461416960 // trying different ways of getting the depth info over
....@@ -14657,6 +17003,13 @@
1465717003 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1465817004 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1465917005
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
+
1466017013 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1466117014
1466217015 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14700,34 +17053,36 @@
1470017053 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]));
1470117054 }
1470217055
14703
- previousselectedpoint = (Sphere) GraphreeD.clone(selectedpoint);
17056
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1470417057 }
1470517058 }
1470617059
1470717060 if (!movingcamera && !PAINTMODE)
14708
- object.editWindow.ScreenFitPoint(); // fev 2014
17061
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1470917062
14710
- 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)
1471117064 {
14712
- 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);
1471317066
14714
- Object3D group = new Object3D("inst" + paintcount++);
17067
+ if (object.GetWindow().copy.selection.Size() > 0)
17068
+ {
17069
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1471517070
14716
- group.CreateMaterial(); // use a void leaf to select instances
14717
-
14718
- group.add(paintobj); // link
14719
-
14720
- object.editWindow.SnapObject(group);
14721
-
14722
- Object3D folder = object.editWindow.copy;
14723
-
14724
- if (object.editWindow.copy.selection.Size() > 0)
14725
- folder = object.editWindow.copy.selection.elementAt(0);
14726
-
14727
- folder.add(group);
14728
-
14729
- object.editWindow.ResetModel();
14730
- 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
+ }
1473117086 }
1473217087 else
1473317088 paintcount = 0;
....@@ -14766,6 +17121,11 @@
1476617121 //System.out.println("objects[color] = " + objects[color]);
1476717122 //objects[color].Select();
1476817123 indexcount = 0;
17124
+ ObjEditor window = object.GetWindow();
17125
+ if (window != null && deselect)
17126
+ {
17127
+ window.Select(null, deselect, true);
17128
+ }
1476917129 object.Select(color, deselect);
1477017130 }
1477117131
....@@ -14865,7 +17225,7 @@
1486517225 gl.glDisable(gl.GL_CULL_FACE);
1486617226 }
1486717227
14868
- if (!RENDERSHADOW)
17228
+ if (!Globals.RENDERSHADOW)
1486917229 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1487017230
1487117231 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14875,14 +17235,14 @@
1487517235 //gl.glColorMask(false, false, false, false);
1487617236
1487717237 //render_scene_from_light_view(gl, drawable, 0, 0);
14878
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17238
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1487917239 {
1488017240 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1488117241
14882
- int temp = drawMode;
14883
- drawMode = SHADOW;
17242
+ int temp = DrawMode();
17243
+ Globals.drawMode = SHADOW; // WARNING
1488417244 parent.display(drawable);
14885
- drawMode = temp;
17245
+ Globals.drawMode = temp; // WARNING
1488617246 }
1488717247
1488817248 gl.glCullFace(gl.GL_BACK);
....@@ -14935,7 +17295,6 @@
1493517295
1493617296 class AntialiasBuffer implements GLEventListener
1493717297 {
14938
-
1493917298 CameraPane parent = null;
1494017299
1494117300 AntialiasBuffer(CameraPane p)
....@@ -15045,13 +17404,19 @@
1504517404 gl.glFlush();
1504617405
1504717406 /**/
15048
- 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);
1504917408
15050
- int[] pixels = occlusionsizebuffer.array();
17409
+ float[] pixels = occlusionsizebuffer.array();
1505117410
1505217411 double r = 0, g = 0, b = 0;
1505317412
1505417413 double count = 0;
17414
+
17415
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17416
+
17417
+ float mindepth = 1;
17418
+
17419
+ double FACTOR = 1;
1505517420
1505617421 for (int i = 0; i < pixels.length; i++)
1505717422 {
....@@ -15136,7 +17501,7 @@
1513617501
1513717502 double scale = ray.z; // 1; // cos
1513817503
15139
- int p = pixels[newindex];
17504
+ float depth = pixels[newindex];
1514017505
1514117506 /*
1514217507 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15160,10 +17525,23 @@
1516017525 scale = (1 - modu) * modv;
1516117526 */
1516217527
15163
- r += ((p >> 16) & 0xFF) * scale / 255;
15164
- g += ((p >> 8) & 0xFF) * scale / 255;
15165
- 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
+ }
1516617536
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
+
1516717545 count += scale;
1516817546 }
1516917547
....@@ -15261,12 +17639,6 @@
1526117639 GLUT glut = new GLUT();
1526217640
1526317641
15264
- static final public int DEFAULT = 0;
15265
- static final public int SELECTION = 1;
15266
- static final public int SHADOW = 2;
15267
- static final public int OCCLUSION = 3;
15268
- static
15269
- public int drawMode = DEFAULT;
1527017642 public boolean spherical = false;
1527117643 static boolean DEBUG_OCCLUSION = false;
1527217644 static boolean DEBUG_SELECTION = false;
....@@ -15279,21 +17651,15 @@
1527917651 int AAbuffersize = 0;
1528017652
1528117653 //double[] selectedpoint = new double[3];
15282
- static Sphere selectedpoint = new Sphere();
17654
+ static Superellipsoid selectedpoint;
1528317655 static Sphere previousselectedpoint = null;
15284
- static Sphere debugpoint = new Sphere();
15285
- static Sphere debugpoint2 = new Sphere();
17656
+ static Sphere debugpointG;
17657
+ static Sphere debugpointP;
17658
+ static Sphere debugpointC;
17659
+ static Sphere debugpointR;
1528617660
1528717661 static Sphere debugpoints[] = new Sphere[8];
1528817662
15289
- static
15290
- {
15291
- for (int i=0; i<8; i++)
15292
- {
15293
- debugpoints[i] = new Sphere();
15294
- }
15295
- }
15296
-
1529717663 static void InitPoints(float radius)
1529817664 {
1529917665 for (int i=0; i<8; i++)
....@@ -15313,7 +17679,7 @@
1531317679 }
1531417680 }
1531517681
15316
- static void DrawPoints(CameraPane cpane)
17682
+ static void DrawPoints(iCameraPane cpane)
1531717683 {
1531817684 for (int i=0; i<8; i++) // first and last are red
1531917685 {
....@@ -15335,7 +17701,8 @@
1533517701 static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1533617702 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1533717703 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15338
- 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);
1533917706 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1534017707 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1534117708 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15344,10 +17711,11 @@
1534417711 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1534517712 // Depth buffer format
1534617713 //private int depth_format;
15347
- static public void NextIndex(Object3D o, GL gl)
17714
+
17715
+ public void NextIndex()
1534817716 {
1534917717 indexcount+=16;
15350
- 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);
1535117719 //objects[indexcount] = o;
1535217720 //System.out.println("indexcount = " + indexcount);
1535317721 }