Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
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,54 @@
165185 defaultcaps.setAccumBlueBits(16);
166186 defaultcaps.setAccumAlphaBits(16);
167187 }
168
- static CameraPane theRenderer;
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
169190
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
202
+
170203 void SetAsGLRenderer(boolean b)
171204 {
172205 isRenderer = b;
173
- theRenderer = this;
206
+ Globals.theRenderer = this;
207
+ }
208
+
209
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
210
+ {
211
+ super(defaultcaps, null, withcontext?glcontext:null, null);
212
+
213
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
214
+ glcontext = getContext();
215
+
216
+ cameras = new Camera[2];
217
+ targetLookAts = new cVector[2];
218
+
219
+ SetCamera(cam);
220
+
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
223
+
224
+ object = o;
225
+
226
+ setBackground(Color.white);
227
+
228
+ addKeyListener(this);
229
+ addMouseListener(this);
230
+ addMouseMotionListener(this);
231
+ addMouseWheelListener(this);
232
+ //System.out.println("addGLEventListener: " + this);
233
+ addGLEventListener(this);
234
+
235
+// pingthread.start(); // may 2013
174236 }
175237
176238 static boolean AntialiasingEnabled()
....@@ -178,12 +240,53 @@
178240 return CURRENTANTIALIAS > 0;
179241 }
180242
181
- void ClearDepth()
243
+ /// INTERFACE
244
+
245
+ public javax.media.opengl.GL GetGL0()
246
+ {
247
+ return null;
248
+ }
249
+
250
+ public int GenList()
251
+ {
252
+ javax.media.opengl.GL gl = GetGL();
253
+ return gl.glGenLists(1);
254
+ }
255
+
256
+ public void NewList(int id)
257
+ {
258
+ javax.media.opengl.GL gl = GetGL();
259
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
260
+ }
261
+
262
+ public void CallList(int id)
263
+ {
264
+ javax.media.opengl.GL gl = GetGL();
265
+ gl.glCallList(id);
266
+ }
267
+
268
+ public void EndList()
269
+ {
270
+ javax.media.opengl.GL gl = GetGL();
271
+ gl.glEndList();
272
+ }
273
+
274
+ public boolean IsBoxMode()
275
+ {
276
+ return BOXMODE;
277
+ }
278
+
279
+ public boolean IsZoomBoxMode()
280
+ {
281
+ return ZOOMBOXMODE;
282
+ }
283
+
284
+ public void ClearDepth()
182285 {
183286 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184287 }
185288
186
- void DepthTest(boolean depthtest)
289
+ public void DepthTest(boolean depthtest)
187290 {
188291 if (depthtest)
189292 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +294,7 @@
191294 GetGL().glDepthFunc(GL.GL_ALWAYS);
192295 }
193296
194
- void DepthWrite(boolean depthwrite)
297
+ public void DepthWrite(boolean depthwrite)
195298 {
196299 if (depthwrite)
197300 GetGL().glDepthMask(true);
....@@ -199,12 +302,1616 @@
199302 GetGL().glDepthMask(false);
200303 }
201304
202
- void BackFaceCull(boolean bfc)
305
+ public void BackFaceCull(boolean bfc)
203306 {
204307 if (bfc)
205308 GetGL().glEnable(GetGL().GL_CULL_FACE);
206309 else
207310 GetGL().glDisable(GetGL().GL_CULL_FACE);
311
+ }
312
+
313
+ public boolean BackFaceCullMode()
314
+ {
315
+ return this.CULLFACE;
316
+ }
317
+
318
+ public boolean IsAmbientOcclusionOn()
319
+ {
320
+ return this.ambientOcclusion;
321
+ }
322
+
323
+ public boolean IsDebugSelection()
324
+ {
325
+ return DEBUG_SELECTION;
326
+ }
327
+
328
+ public boolean IsFrozen()
329
+ {
330
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
331
+
332
+ return !selectmode && cameracount == 0; // != 0;
333
+ }
334
+
335
+ // Currently in Globals
336
+ public int DrawMode()
337
+ {
338
+ return Globals.DrawMode();
339
+ }
340
+
341
+ public Camera EyeCamera()
342
+ {
343
+ return eyeCamera;
344
+ }
345
+
346
+ public Camera LightCamera()
347
+ {
348
+ return lightCamera;
349
+ }
350
+
351
+ public Camera ManipCamera()
352
+ {
353
+ return manipCamera;
354
+ }
355
+
356
+ public Camera RenderCamera()
357
+ {
358
+ return renderCamera;
359
+ }
360
+
361
+ public Camera[] Cameras()
362
+ {
363
+ return cameras;
364
+ }
365
+
366
+ public void PushMaterial(Object3D obj, boolean selected)
367
+ {
368
+ CameraPane display = this;
369
+ javax.media.opengl.GL gl = display.GetGL();
370
+ cMaterial material = obj.material;
371
+
372
+ if (material != null)
373
+ {
374
+ materialstack[materialdepth] = material;
375
+ selectedstack[materialdepth] = selected;
376
+ cStatic.objectstack[materialdepth++] = obj;
377
+ //System.out.println("material " + material);
378
+ //Applet3D.tracein(this, selected);
379
+ //display.vector2buffer = obj.projectedVertices;
380
+ if (obj instanceof Camera)
381
+ {
382
+ display.options1[0] = material.shift;
383
+ //System.out.println("shift " + material.shift);
384
+ display.options1[1] = material.lightarea;
385
+ display.options1[2] = material.shadowbias;
386
+ display.options1[3] = material.aniso;
387
+ display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
393
+ display.options2[0] = material.opacity;
394
+ display.options2[1] = material.diffuse;
395
+ display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
399
+
400
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
404
+ display.options4[0] = material.cameralight/0.2f;
405
+ display.options4[1] = material.subsurface;
406
+ display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
410
+
411
+ // if (display.CURRENTANTIALIAS > 0)
412
+ // display.options3[3] /= 4;
413
+
414
+ /*
415
+ System.out.println("Focus = " + display.options1[0]);
416
+ System.out.println("Aperture = " + display.options1[1]);
417
+ System.out.println("ShadowBlur = " + display.options1[2]);
418
+ System.out.println("Antialiasing = " + display.options1[3]);
419
+ System.out.println("Fog = " + display.options2[0]);
420
+ System.out.println("Intensity = " + display.options2[1]);
421
+ System.out.println("Elevation = " + display.options2[2]);
422
+ /**/
423
+ } else
424
+ {
425
+ DrawMaterial(material, selected, obj.projectedVertices);
426
+ }
427
+ } else
428
+ {
429
+ if (selected && CameraPane.flash)
430
+ {
431
+ display.modelParams4[1] = 100;
432
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
433
+ }
434
+ }
435
+ }
436
+
437
+ public void PushMaterial2(Object3D obj, boolean selected)
438
+ {
439
+ CameraPane display = this;
440
+ cMaterial material = obj.material;
441
+
442
+ if (material != null)
443
+ {
444
+ materialstack[materialdepth] = material;
445
+ selectedstack[materialdepth] = selected;
446
+ cStatic.objectstack[materialdepth++] = obj;
447
+ //System.out.println("material " + material);
448
+ //Applet3D.tracein("selected ", selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
451
+ }
452
+ }
453
+
454
+ public void PopMaterial(Object3D obj, boolean selected)
455
+ {
456
+ CameraPane display = this;
457
+ javax.media.opengl.GL gl = display.GetGL();
458
+ cMaterial material = obj.material;
459
+
460
+ //if (parent != null && parent.GetMaterial() != null)
461
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
462
+ if (material != null)
463
+ {
464
+ materialdepth -= 1;
465
+ if (materialdepth > 0)
466
+ {
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
469
+ }
470
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
471
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
472
+ {
473
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
474
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
475
+ }
476
+ }
477
+
478
+ public void PopMaterial2(Object3D obj)
479
+ {
480
+ CameraPane display = this;
481
+ cMaterial material = obj.material;
482
+
483
+ if (material != null)
484
+ {
485
+ materialdepth -= 1;
486
+ if (materialdepth > 0)
487
+ {
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
490
+ }
491
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
492
+ //else
493
+ //material.Draw(display, false);
494
+ }
495
+ }
496
+
497
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
498
+ {
499
+ CameraPane display = this;
500
+
501
+ if (pv.y == -10000 ||
502
+ qv.y == -10000 ||
503
+ rv.y == -10000)
504
+ return;
505
+
506
+// float b = f.nbiterations & 1;
507
+// float g = (f.nbiterations>>1) & 1;
508
+// float r = (f.nbiterations>>2) & 1;
509
+//
510
+// //if (f.weight == 10000)
511
+// //{
512
+// // r = 1; g = b = 0;
513
+// //}
514
+// //else
515
+// //{
516
+// // assert(f.weight < 10000);
517
+// r = g = b = (float)bRep.FaceWeight(f)*100;
518
+// if (r<0)
519
+// assert(r>=0);
520
+// //}
521
+
522
+ javax.media.opengl.GL gl = display.GetGL();
523
+
524
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
525
+
526
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
527
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
528
+ {
529
+ //gl.glBegin(gl.GL_TRIANGLES);
530
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
531
+ // TEST LIVE NORMALS && !obj.dontselect
532
+ ;
533
+ if (!hasnorm)
534
+ {
535
+ // System.out.println("Mesh normal");
536
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
537
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
538
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
539
+ LA.vecNormalize(obj.v2);
540
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
541
+ }
542
+
543
+ // P
544
+ float x = (float)pv.x;
545
+ float y = (float)pv.y;
546
+ float z = (float)pv.z;
547
+
548
+ if (hasnorm)
549
+ {
550
+// if (!pv.norm.normalized())
551
+// assert(pv.norm.normalized());
552
+
553
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
554
+ float nx = (float)pv.norm.x;
555
+ float ny = (float)pv.norm.y;
556
+ float nz = (float)pv.norm.z;
557
+
558
+ x += nx * obj.NORMALPUSH;
559
+ y += ny * obj.NORMALPUSH;
560
+ z += nz * obj.NORMALPUSH;
561
+
562
+ gl.glNormal3f(nx, ny, nz);
563
+ }
564
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
565
+ SetColor(obj, pv);
566
+ //gl.glColor4f(r, g, b, 1);
567
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
568
+ if (obj.flipV)
569
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
570
+ else
571
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
572
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
573
+
574
+ gl.glVertex3f(x, y, z);
575
+
576
+ // Q
577
+ x = (float)qv.x;
578
+ y = (float)qv.y;
579
+ z = (float)qv.z;
580
+
581
+// Print(pv);
582
+ if (hasnorm)
583
+ {
584
+// assert(qv.norm.normalized());
585
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
586
+ float nx = (float)qv.norm.x;
587
+ float ny = (float)qv.norm.y;
588
+ float nz = (float)qv.norm.z;
589
+
590
+ x += nx * obj.NORMALPUSH;
591
+ y += ny * obj.NORMALPUSH;
592
+ z += nz * obj.NORMALPUSH;
593
+
594
+ gl.glNormal3f(nx, ny, nz);
595
+ }
596
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
597
+ // boolean locked = false;
598
+ // float eps = 0.1f;
599
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
600
+
601
+ // int dot = 0; //*/ (int)f.dot;
602
+
603
+ // if ((dot&1) == 0)
604
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
605
+
606
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
607
+ if (obj.flipV)
608
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
609
+ else
610
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
611
+ // else
612
+ // {
613
+ // locked = true;
614
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
615
+ // }
616
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
617
+ SetColor(obj, qv);
618
+
619
+ gl.glVertex3f(x, y, z);
620
+ //gl.glColor4f(r, g, b, 1);
621
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
622
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
623
+// Print(qv);
624
+
625
+ // R
626
+ x = (float)rv.x;
627
+ y = (float)rv.y;
628
+ z = (float)rv.z;
629
+
630
+ if (hasnorm)
631
+ {
632
+// assert(rv.norm.normalized());
633
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
634
+ float nx = (float)rv.norm.x;
635
+ float ny = (float)rv.norm.y;
636
+ float nz = (float)rv.norm.z;
637
+
638
+ x += nx * obj.NORMALPUSH;
639
+ y += ny * obj.NORMALPUSH;
640
+ z += nz * obj.NORMALPUSH;
641
+
642
+ gl.glNormal3f(nx, ny, nz);
643
+ }
644
+
645
+ // if ((dot&4) == 0)
646
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
647
+
648
+ // if (wrap || !locked && (dot&8) != 0)
649
+ if (obj.flipV)
650
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
651
+ else
652
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
653
+ // else
654
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
655
+
656
+ // f.dot = dot;
657
+
658
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
659
+ SetColor(obj, rv);
660
+ //gl.glColor4f(r, g, b, 1);
661
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
662
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
663
+ gl.glVertex3f(x, y, z);
664
+// Print(rv);
665
+ //gl.glEnd();
666
+ }
667
+ else
668
+ {
669
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
670
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
671
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
672
+
673
+ }
674
+
675
+ if (false) // (attributes & WIREFRAME) != 0)
676
+ {
677
+ gl.glDisable(gl.GL_LIGHTING);
678
+
679
+ gl.glBegin(gl.GL_LINE_LOOP);
680
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
681
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
682
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
683
+ gl.glEnd();
684
+
685
+ gl.glEnable(gl.GL_LIGHTING);
686
+ }
687
+ }
688
+
689
+ /**
690
+ * <code>draw</code> renders a <code>TriMesh</code> object including
691
+ * it's normals, colors, textures and vertices.
692
+ *
693
+ * @see Renderer#draw(TriMesh)
694
+ * @param tris
695
+ * the mesh to render.
696
+ */
697
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
698
+ {
699
+ CameraPane display = this;
700
+
701
+ float r = display.modelParams0[0];
702
+ float g = display.modelParams0[1];
703
+ float b = display.modelParams0[2];
704
+ float opacity = display.modelParams5[1];
705
+
706
+ //final GL gl = GLU.getCurrentGL();
707
+ GL gl = display.GetGL(); // getGL();
708
+
709
+ FloatBuffer vertBuf = geo.vertBuf;
710
+
711
+ int v = vertBuf.capacity();
712
+
713
+ int count = 0;
714
+
715
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
716
+ gl.glEnable(gl.GL_CULL_FACE);
717
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
718
+ for (int i=0; i<v/3; i++)
719
+ {
720
+ int index3 = i*3;
721
+
722
+ if (geo.sizeBuf.get(index3+1) == 0)
723
+ continue;
724
+
725
+ count++;
726
+
727
+ int index4 = i*4;
728
+
729
+ float tx = vertBuf.get(index3);
730
+ float ty = vertBuf.get(index3+1);
731
+ float tz = vertBuf.get(index3+2);
732
+
733
+ // if (tx == 0 && ty == 0 && tz == 0)
734
+ // continue;
735
+
736
+ gl.glMatrixMode(gl.GL_TEXTURE);
737
+ gl.glPushMatrix();
738
+
739
+ float[] texmat = geo.texmat;
740
+ texmat[12] = texmat[13] = texmat[14] = i;
741
+
742
+ gl.glMultMatrixf(texmat, 0);
743
+
744
+ gl.glMatrixMode(gl.GL_MODELVIEW);
745
+ gl.glPushMatrix();
746
+
747
+ gl.glTranslatef(tx,ty,tz);
748
+
749
+ if (rotate)
750
+ gl.glRotatef(i, 0, 1, 0);
751
+
752
+ float size = geo.sizeBuf.get(index3) / 100;
753
+ gl.glScalef(size,size,size);
754
+
755
+ float cr = geo.colorBuf.get(index4);
756
+ float cg = geo.colorBuf.get(index4+1);
757
+ float cb = geo.colorBuf.get(index4+2);
758
+ float ca = geo.colorBuf.get(index4+3);
759
+
760
+ display.modelParams0[0] = r * cr;
761
+ display.modelParams0[1] = g * cg;
762
+ display.modelParams0[2] = b * cb;
763
+
764
+ display.modelParams5[1] = opacity * ca;
765
+
766
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
767
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
768
+
769
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
770
+ RandomNode.globalseed2 = RandomNode.globalseed;
771
+
772
+// gl.glColor4f(cr,cg,cb,ca);
773
+ // gl.glScalef(1024/16,1024/16,1024/16);
774
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
775
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
776
+ //gl.glTranslatef(-tx,-ty,-tz);
777
+ gl.glPopMatrix();
778
+
779
+ gl.glMatrixMode(gl.GL_TEXTURE);
780
+ gl.glPopMatrix();
781
+ }
782
+ // gl.glScalef(1024,1024,1024);
783
+ if (!cf)
784
+ gl.glDisable(gl.GL_CULL_FACE);
785
+
786
+ display.modelParams0[0] = r;
787
+ display.modelParams0[1] = g;
788
+ display.modelParams0[2] = b;
789
+
790
+ display.modelParams5[1] = opacity;
791
+
792
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
793
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
794
+
795
+ gl.glMatrixMode(gl.GL_MODELVIEW);
796
+
797
+// System.err.println("total = " + v/3 + "; displayed = " + count);
798
+ if (true)
799
+ return;
800
+
801
+//// if (!tris.predraw(this))
802
+//// {
803
+//// return;
804
+//// }
805
+//// if (Debug.stats)
806
+//// {
807
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
808
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
809
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
810
+//// }
811
+////
812
+//// if (tris.getDisplayListID() != -1)
813
+//// {
814
+//// renderDisplayList(tris);
815
+//// return;
816
+//// }
817
+////
818
+//// if (!generatingDisplayList)
819
+//// {
820
+//// applyStates(tris.states, tris);
821
+//// }
822
+//// if (Debug.stats)
823
+//// {
824
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
825
+//// }
826
+//// boolean transformed = doTransforms(tris);
827
+//
828
+// int glMode = GL.GL_TRIANGLES;
829
+// switch (getMode())
830
+// {
831
+// case Triangles:
832
+// glMode = GL.GL_TRIANGLES;
833
+// break;
834
+// case Strip:
835
+// glMode = GL.GL_TRIANGLE_STRIP;
836
+// break;
837
+// case Fan:
838
+// glMode = GL.GL_TRIANGLE_FAN;
839
+// break;
840
+// }
841
+//
842
+// if (!predrawGeometry(gl))
843
+// {
844
+// // make sure only the necessary indices are sent through on old
845
+// // cards.
846
+// IntBuffer indices = this.getIndexBuffer();
847
+// if (indices == null)
848
+// {
849
+// logger.severe("missing indices on geometry object: " + this.toString());
850
+// } else
851
+// {
852
+// indices.rewind();
853
+// indices.limit(this.getMaxIndex());
854
+//
855
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
856
+//
857
+// indices.clear();
858
+// }
859
+// } else
860
+// {
861
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
862
+// GL.GL_UNSIGNED_INT, 0);
863
+// }
864
+//
865
+//// postdrawGeometry(tris);
866
+//// if (transformed)
867
+//// {
868
+//// undoTransforms(tris);
869
+//// }
870
+////
871
+//// if (Debug.stats)
872
+//// {
873
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
874
+//// }
875
+//// tris.postdraw(this);
876
+ }
877
+
878
+ static Camera localcamera = new Camera();
879
+ static cVector from = new cVector();
880
+ static cVector to = new cVector();
881
+
882
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
883
+ {
884
+ CameraPane cp = this;
885
+
886
+ Camera keep = cp.RenderCamera();
887
+ cp.renderCamera = localcamera;
888
+
889
+ if (br.trimmed)
890
+ {
891
+ float[] colors = new float[br.positions.length / 3];
892
+
893
+ int i3 = 0;
894
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
895
+ {
896
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
897
+ continue;
898
+
899
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
900
+ to.set(br.positions[i3] + br.normals[i3],
901
+ br.positions[i3 + 1] + br.normals[i3 + 1],
902
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
903
+ LA.xformPos(from, transform, from);
904
+ LA.xformPos(to, transform, to); // RIGID ONLY
905
+ localcamera.setAim(from, to);
906
+
907
+ CameraPane.occlusionbuffer.display();
908
+
909
+ if (CameraPane.DEBUG_OCCLUSION)
910
+ cp.display(); // debug
911
+
912
+ colors[i] = cp.vertexOcclusion.r;
913
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
914
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
915
+
916
+ if ((i % 100) == 0 && i != 0)
917
+ {
918
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
919
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
920
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
921
+ }
922
+ }
923
+
924
+ br.colors = colors;
925
+ }
926
+ else
927
+ {
928
+ for (int i = 0; i < br.VertexCount(); i++)
929
+ {
930
+ Vertex v = br.GetVertex(i);
931
+
932
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
933
+ continue;
934
+
935
+ from.set(v.x, v.y, v.z);
936
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
937
+ LA.xformPos(from, transform, from);
938
+ LA.xformPos(to, transform, to); // RIGID ONLY
939
+ localcamera.setAim(from, to);
940
+
941
+ CameraPane.occlusionbuffer.display();
942
+
943
+ if (CameraPane.DEBUG_OCCLUSION)
944
+ cp.display(); // debug
945
+
946
+ v.AO = cp.vertexOcclusion.r;
947
+
948
+ if ((i % 100) == 0 && i != 0)
949
+ {
950
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
951
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
952
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
953
+ }
954
+ }
955
+ }
956
+
957
+ //System.out.println("done.");
958
+
959
+ cp.renderCamera = keep;
960
+ }
961
+
962
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
963
+ {
964
+ CameraPane display = this;
965
+ pointFlow.CreateHT();
966
+
967
+ float r = display.modelParams0[0];
968
+ float g = display.modelParams0[1];
969
+ float b = display.modelParams0[2];
970
+ float opacity = display.modelParams5[1];
971
+
972
+ //final GL gl = GLU.getCurrentGL();
973
+ GL gl = display.GetGL(); // getGL();
974
+
975
+ int s = pointFlow.points.size();
976
+
977
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
978
+ gl.glEnable(gl.GL_CULL_FACE);
979
+
980
+ for (int i=s; --i>=0;)
981
+ //for (int i=0; i<s; i++)
982
+ {
983
+ cVector v = pointFlow.points.get(i);
984
+
985
+ double mindist = Double.MAX_VALUE;
986
+
987
+ double size = pointFlow.minimumSize;
988
+
989
+ double distancenext = 0;
990
+
991
+ if (i > 0)
992
+ {
993
+ cVector w = pointFlow.points.get(i-1);
994
+
995
+ double dist = w.distance(v);
996
+
997
+ distancenext = dist;
998
+
999
+ if (mindist > dist)
1000
+ {
1001
+ mindist = dist;
1002
+ size = mindist*pointFlow.resizefactor;
1003
+ }
1004
+ }
1005
+
1006
+ if (i < s-1)
1007
+ {
1008
+ cVector w = pointFlow.points.get(i+1);
1009
+
1010
+ double dist = w.distance(v);
1011
+
1012
+ if (mindist > dist)
1013
+ {
1014
+ mindist = dist;
1015
+ size = mindist*pointFlow.resizefactor;
1016
+ }
1017
+ }
1018
+
1019
+ if (size < pointFlow.minimumSize)
1020
+ size = pointFlow.minimumSize;
1021
+ if (size > pointFlow.maximumSize)
1022
+ size = pointFlow.maximumSize;
1023
+
1024
+ double tx = v.x;
1025
+ double ty = v.y;
1026
+ double tz = v.z;
1027
+
1028
+ // if (tx == 0 && ty == 0 && tz == 0)
1029
+ // continue;
1030
+
1031
+ gl.glMatrixMode(gl.GL_TEXTURE);
1032
+ gl.glPushMatrix();
1033
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1034
+
1035
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1036
+
1037
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1038
+ gl.glPushMatrix();
1039
+
1040
+ gl.glTranslated(tx,ty,tz);
1041
+
1042
+ gl.glScaled(size,size,size);
1043
+
1044
+// float cr = colorBuf.get(index4);
1045
+// float cg = colorBuf.get(index4+1);
1046
+// float cb = colorBuf.get(index4+2);
1047
+// float ca = colorBuf.get(index4+3);
1048
+//
1049
+// display.modelParams0[0] = r * cr;
1050
+// display.modelParams0[1] = g * cg;
1051
+// display.modelParams0[2] = b * cb;
1052
+//
1053
+// display.modelParams5[1] = opacity * ca;
1054
+//
1055
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1056
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1057
+//
1058
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1059
+// RandomNode.globalseed2 = RandomNode.globalseed;
1060
+//
1061
+//// gl.glColor4f(cr,cg,cb,ca);
1062
+// // gl.glScalef(1024/16,1024/16,1024/16);
1063
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1064
+
1065
+ gl.glPopMatrix();
1066
+
1067
+ double step = size/4; //
1068
+
1069
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1070
+ continue;
1071
+
1072
+ int nbsteps = (int)(distancenext/step);
1073
+
1074
+ step = distancenext/nbsteps;
1075
+
1076
+ cVector next = pointFlow.points.get(i-1);
1077
+
1078
+ tmp.set(next);
1079
+ tmp.sub(v);
1080
+ tmp.normalize();
1081
+ tmp.mul(step);
1082
+
1083
+ // calculate next size
1084
+ mindist = Double.MAX_VALUE;
1085
+
1086
+ double nextsize = pointFlow.minimumSize;
1087
+
1088
+ if (i > 1)
1089
+ {
1090
+ cVector w = pointFlow.points.get(i-2);
1091
+
1092
+ double dist = w.distance(next);
1093
+
1094
+ if (mindist > dist)
1095
+ {
1096
+ mindist = dist;
1097
+ nextsize = mindist*pointFlow.resizefactor;
1098
+ }
1099
+ }
1100
+
1101
+ double dist = v.distance(next);
1102
+
1103
+ if (mindist > dist)
1104
+ {
1105
+ mindist = dist;
1106
+ nextsize = mindist*pointFlow.resizefactor;
1107
+ }
1108
+
1109
+ if (nextsize < pointFlow.minimumSize)
1110
+ nextsize = pointFlow.minimumSize;
1111
+ if (nextsize > pointFlow.maximumSize)
1112
+ nextsize = pointFlow.maximumSize;
1113
+ //
1114
+
1115
+ double count = 0;
1116
+
1117
+ while (distancenext > 0.000000001) // step
1118
+ {
1119
+ gl.glPushMatrix();
1120
+
1121
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1122
+
1123
+ double K = count/nbsteps;
1124
+
1125
+ double intersize = K*nextsize + (1-K)*size;
1126
+
1127
+ gl.glScaled(intersize,intersize,intersize);
1128
+
1129
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1130
+
1131
+ count++;
1132
+
1133
+ distancenext -= step;
1134
+
1135
+ gl.glPopMatrix();
1136
+ }
1137
+
1138
+ if (count != nbsteps)
1139
+ assert(count == nbsteps);
1140
+
1141
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1142
+ //gl.glTranslatef(-tx,-ty,-tz);
1143
+
1144
+ gl.glMatrixMode(gl.GL_TEXTURE);
1145
+ gl.glPopMatrix();
1146
+ }
1147
+
1148
+ if (!cf)
1149
+ gl.glDisable(gl.GL_CULL_FACE);
1150
+
1151
+// display.modelParams0[0] = r;
1152
+// display.modelParams0[1] = g;
1153
+// display.modelParams0[2] = b;
1154
+//
1155
+// display.modelParams5[1] = opacity;
1156
+//
1157
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1158
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1159
+
1160
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1161
+ }
1162
+
1163
+ public void DrawBox(cVector min, cVector max)
1164
+ {
1165
+ javax.media.opengl.GL gl = GetGL();
1166
+ gl.glBegin(gl.GL_LINES);
1167
+
1168
+ gl.glVertex3d(min.x, min.y, min.z);
1169
+ gl.glVertex3d(min.x, min.y, max.z);
1170
+ gl.glVertex3d(min.x, min.y, min.z);
1171
+ gl.glVertex3d(min.x, max.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, min.z);
1173
+ gl.glVertex3d(max.x, min.y, min.z);
1174
+
1175
+ gl.glVertex3d(max.x, max.y, max.z);
1176
+ gl.glVertex3d(min.x, max.y, max.z);
1177
+ gl.glVertex3d(max.x, max.y, max.z);
1178
+ gl.glVertex3d(max.x, min.y, max.z);
1179
+ gl.glVertex3d(max.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, min.z);
1181
+
1182
+ gl.glEnd();
1183
+ }
1184
+
1185
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1186
+ {
1187
+ int[] strips = bRep.getRawIndices();
1188
+
1189
+ javax.media.opengl.GL gl = GetGL();
1190
+
1191
+ // TRIANGLE STRIP ARRAY
1192
+ if (bRep.trimmed)
1193
+ {
1194
+ float[] v = bRep.getRawVertices();
1195
+ float[] n = bRep.getRawNormals();
1196
+ float[] c = bRep.getRawColors();
1197
+ float[] uv = bRep.getRawUVMap();
1198
+
1199
+ int count2 = 0;
1200
+ int count3 = 0;
1201
+
1202
+ if (n.length > 0)
1203
+ {
1204
+ for (int i = 0; i < strips.length; i++)
1205
+ {
1206
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1207
+
1208
+ /*
1209
+ boolean locked = false;
1210
+ float eps = 0.1f;
1211
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1212
+
1213
+ int dot = 0;
1214
+
1215
+ if ((dot&1) == 0)
1216
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1217
+
1218
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1219
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1220
+ else
1221
+ {
1222
+ locked = true;
1223
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1224
+ }
1225
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1226
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1227
+ if (hasnorm)
1228
+ {
1229
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1230
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1231
+ }
1232
+
1233
+ if ((dot&4) == 0)
1234
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1235
+
1236
+ if (wrap || !locked && (dot&8) != 0)
1237
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1238
+ else
1239
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1240
+
1241
+ f.dot = dot;
1242
+ */
1243
+
1244
+ if (!selectmode)
1245
+ {
1246
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1247
+ {
1248
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1249
+ } else
1250
+ {
1251
+ gl.glNormal3f(0, 0, 1);
1252
+ }
1253
+
1254
+ if (c != null)
1255
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1256
+ {
1257
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1258
+ }
1259
+ }
1260
+
1261
+ if (flipV)
1262
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1263
+ else
1264
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
1266
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1267
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1268
+
1269
+ count2 += 2;
1270
+ count3 += 3;
1271
+ if (!selectmode)
1272
+ {
1273
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1274
+ {
1275
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1276
+ } else
1277
+ {
1278
+ gl.glNormal3f(0, 0, 1);
1279
+ }
1280
+ if (c != null)
1281
+ {
1282
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1283
+ }
1284
+ }
1285
+
1286
+ if (flipV)
1287
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1288
+ else
1289
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
1291
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1292
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1293
+
1294
+ count2 += 2;
1295
+ count3 += 3;
1296
+ for (int j = 0; j < strips[i] - 2; j++)
1297
+ {
1298
+ //gl.glTexCoord2d(...);
1299
+ if (!selectmode)
1300
+ {
1301
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1302
+ {
1303
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1304
+ } else
1305
+ {
1306
+ gl.glNormal3f(0, 0, 1);
1307
+ }
1308
+ if (c != null)
1309
+ {
1310
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1311
+ }
1312
+ }
1313
+
1314
+ if (flipV)
1315
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1316
+ else
1317
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
1319
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1320
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
1322
+ count2 += 2;
1323
+ count3 += 3;
1324
+ }
1325
+
1326
+ gl.glEnd();
1327
+ }
1328
+ }
1329
+
1330
+ assert count3 == v.length;
1331
+ }
1332
+ else // !trimmed
1333
+ {
1334
+ int count = 0;
1335
+ for (int i = 0; i < strips.length; i++)
1336
+ {
1337
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1338
+
1339
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1340
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1341
+
1342
+ drawVertex(gl, p, flipV, selectmode);
1343
+ drawVertex(gl, q, flipV, selectmode);
1344
+
1345
+ for (int j = 0; j < strips[i] - 2; j++)
1346
+ {
1347
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1348
+
1349
+ // if (j%2 == 0)
1350
+ // drawFace(p, q, r, display, null);
1351
+ // else
1352
+ // drawFace(p, r, q, display, null);
1353
+
1354
+ // p = q;
1355
+ // q = r;
1356
+ drawVertex(gl, r, flipV, selectmode);
1357
+ }
1358
+
1359
+ gl.glEnd();
1360
+ }
1361
+ }
1362
+ }
1363
+
1364
+ static cSpring.Point3D temp = new cSpring.Point3D();
1365
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1366
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1367
+
1368
+ public void DrawDynamicMesh(cMesh mesh)
1369
+ {
1370
+ GL gl = GetGL(); // getGL();
1371
+
1372
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1373
+
1374
+ gl.glDisable(gl.GL_LIGHTING);
1375
+
1376
+ gl.glLineWidth(1);
1377
+ gl.glColor3f(1,1,1);
1378
+ gl.glBegin(gl.GL_LINES);
1379
+ double scale = 0;
1380
+ int count = 0;
1381
+ for (int s=0; s<Phys.allSprings.size(); s++)
1382
+ {
1383
+ cSpring.Spring spring = Phys.allSprings.get(s);
1384
+ if(s == 0)
1385
+ {
1386
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1387
+ }
1388
+ if (mesh.showsprings)
1389
+ {
1390
+ temp.set(spring.a.position);
1391
+ temp.add(spring.b.position);
1392
+ temp.mul(0.5);
1393
+ temp2.set(spring.a.position);
1394
+ temp2.sub(spring.b.position);
1395
+ temp2.mul(spring.restLength/2);
1396
+ temp.sub(temp2);
1397
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1398
+ temp.add(temp2);
1399
+ temp.add(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ }
1402
+
1403
+ if (spring.isHandle)
1404
+ continue;
1405
+
1406
+ //if (scale < spring.restLength)
1407
+ scale += spring.restLength;
1408
+ count++;
1409
+ }
1410
+ gl.glEnd();
1411
+
1412
+ if (count == 0)
1413
+ scale = 0.01;
1414
+ else
1415
+ scale /= count * 3;
1416
+
1417
+ //scale = 0.25;
1418
+
1419
+ if (mesh.ShowInfo())
1420
+ {
1421
+ gl.glLineWidth(4);
1422
+ for (int s=0; s<Phys.allNodes.size(); s++)
1423
+ {
1424
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1425
+ if (node.mass == 0)
1426
+ continue;
1427
+
1428
+ int i = node.springs==null?-1:node.springs.size();
1429
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1430
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1431
+ //temp.normalize();
1432
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1433
+ gl.glBegin(gl.GL_LINES);
1434
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1435
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1436
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1437
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1438
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1439
+ gl.glEnd();
1440
+ }
1441
+
1442
+ gl.glLineWidth(8);
1443
+ for (int s=0; s<Phys.allNodes.size(); s++)
1444
+ {
1445
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1446
+
1447
+ if (node.springs != null)
1448
+ {
1449
+ for (int i=0; i<node.springs.size(); i+=1)
1450
+ {
1451
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1452
+
1453
+ int c = i+1;
1454
+ // c = node.springs.get(i).nbcopies;
1455
+
1456
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1457
+ gl.glBegin(gl.GL_LINES);
1458
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1459
+ 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);
1460
+ gl.glEnd();
1461
+ }
1462
+ }
1463
+ }
1464
+
1465
+ gl.glLineWidth(1);
1466
+ }
1467
+
1468
+ gl.glEnable(gl.GL_LIGHTING);
1469
+ }
1470
+
1471
+ /// INTERFACE
1472
+
1473
+ public void StartTriangles()
1474
+ {
1475
+ javax.media.opengl.GL gl = GetGL();
1476
+ gl.glBegin(gl.GL_TRIANGLES);
1477
+ }
1478
+
1479
+ public void EndTriangles()
1480
+ {
1481
+ GetGL().glEnd();
1482
+ }
1483
+
1484
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1485
+ {
1486
+ if (!selectmode)
1487
+ {
1488
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1489
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1490
+
1491
+ if (flipV)
1492
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1493
+ else
1494
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1495
+ }
1496
+
1497
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1498
+ }
1499
+
1500
+ float[] colorV = new float[4];
1501
+
1502
+ void SetColor(Object3D obj, Vertex p0)
1503
+ {
1504
+ CameraPane display = this;
1505
+ BoundaryRep bRep = obj.bRep;
1506
+
1507
+ if (RENDERPROGRAM == 0)
1508
+ {
1509
+ float r = 0;
1510
+ if (bRep != null)
1511
+ {
1512
+ if (bRep.stripified)
1513
+ {
1514
+ r = 1;
1515
+ }
1516
+ }
1517
+ float g = 0;
1518
+ if (bRep != null)
1519
+ {
1520
+ if (bRep.trimmed)
1521
+ {
1522
+ g = 1;
1523
+ }
1524
+ }
1525
+ float b = 0;
1526
+ if (obj.support != null && obj.link2master)
1527
+ {
1528
+ b = 1;
1529
+ }
1530
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1531
+ return;
1532
+ }
1533
+
1534
+ if (display.DrawMode() != CameraPane.SHADOW)
1535
+ return;
1536
+
1537
+ javax.media.opengl.GL gl = display.GetGL();
1538
+// if (true) return;
1539
+// float ao = p.AO;
1540
+//
1541
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1542
+// // ao = 1;
1543
+//
1544
+// gl.glColor4f(ao, ao, ao, 1);
1545
+
1546
+// CameraPane.selectedpoint.
1547
+// getAverage(cStatic.point1, true);
1548
+ if (CameraPane.pointflow == null) // !random) // live)
1549
+ {
1550
+ return;
1551
+ }
1552
+
1553
+ cStatic.point1.set(0,0,0);
1554
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1555
+
1556
+ cStatic.point1.sub(p0);
1557
+
1558
+
1559
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1560
+// {
1561
+// return;
1562
+// }
1563
+
1564
+ //if (true)
1565
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1566
+ {
1567
+ return;
1568
+ }
1569
+
1570
+ if (false) // marked)
1571
+ {
1572
+ // debug rigging weights
1573
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1574
+ {
1575
+ float weight = p0.weights[object] / p0.totalweight;
1576
+
1577
+ // if (weight < 0.1)
1578
+ // {
1579
+ // assert(weight == 0);
1580
+ // continue;
1581
+ // }
1582
+
1583
+ if (p0.vertexlinks[object] == -1)
1584
+ continue;
1585
+
1586
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1587
+
1588
+ int color = //1 << object; //
1589
+ //p.vertexlinks.length;
1590
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1591
+ colorV[2] += (color & 1) * weight;
1592
+ colorV[1] += ((color & 2) >> 1) * weight;
1593
+ colorV[0] += ((color & 4) >> 2) * weight;
1594
+ }
1595
+ }
1596
+ else
1597
+ {
1598
+ if (obj.drawingstarted)
1599
+ {
1600
+ // find next point
1601
+ if (bRep.GetVertex(0).faceindices == null)
1602
+ {
1603
+ bRep.InitFaceIndices();
1604
+ }
1605
+
1606
+ double ymin = p0.y;
1607
+
1608
+ Vertex newp = p0;
1609
+
1610
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1611
+ {
1612
+ int fi = p0.faceindices[fii];
1613
+
1614
+ if (fi == -1)
1615
+ break;
1616
+
1617
+ Face f = bRep.GetFace(fi);
1618
+
1619
+ Vertex p = bRep.GetVertex(f.p);
1620
+ Vertex q = bRep.GetVertex(f.q);
1621
+ Vertex r = bRep.GetVertex(f.r);
1622
+
1623
+ int swap = (int)(Math.random()*3);
1624
+
1625
+// for (int s=swap; --s>=0;)
1626
+// {
1627
+// Vertex t = p;
1628
+// p = q;
1629
+// q = r;
1630
+// r = t;
1631
+// }
1632
+ if (ymin > p.y)
1633
+ {
1634
+ ymin = p.y;
1635
+ newp = p;
1636
+// break;
1637
+ }
1638
+ if (ymin > q.y)
1639
+ {
1640
+ ymin = q.y;
1641
+ newp = q;
1642
+// break;
1643
+ }
1644
+ if (ymin > r.y)
1645
+ {
1646
+ ymin = r.y;
1647
+ newp = r;
1648
+// break;
1649
+ }
1650
+ }
1651
+
1652
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1653
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1654
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1655
+
1656
+ obj.drawingstarted = false;
1657
+
1658
+ // return;
1659
+ }
1660
+
1661
+ if (false) // CameraPane.DRAW
1662
+ {
1663
+ p0.AO = colorV[0] = 2;
1664
+ colorV[1] = 2;
1665
+ colorV[2] = 2;
1666
+ }
1667
+
1668
+ CameraPane.pointflow.add(p0);
1669
+ CameraPane.pointflow.Touch();
1670
+ }
1671
+
1672
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1673
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1674
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1675
+ }
1676
+
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1678
+ {
1679
+ CameraPane display = this;
1680
+ //new Exception().printStackTrace();
1681
+
1682
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1683
+ {
1684
+ return;
1685
+ }
1686
+
1687
+ javax.media.opengl.GL gl = display.GetGL();
1688
+
1689
+ //Color col = Color.getHSBColor(color,modulation,1);
1690
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1691
+ if (!material.multiply)
1692
+ {
1693
+ display.color = material.color;
1694
+ display.saturation = material.modulation;
1695
+ }
1696
+ else
1697
+ {
1698
+ display.color *= material.color*2;
1699
+ display.saturation *= material.modulation*2;
1700
+ }
1701
+
1702
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1703
+
1704
+ float[] colorV = Grafreed.colorV;
1705
+
1706
+ /**/
1707
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1708
+ {
1709
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1710
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1711
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1712
+ colorV[3] = 1; // material.opacity;
1713
+
1714
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1715
+ //System.out.println("Opacity = " + opacity);
1716
+
1717
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1718
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1719
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1720
+
1721
+ float amb = material.ambient;
1722
+ if (amb < material.cameralight)
1723
+ {
1724
+ amb = material.cameralight;
1725
+ }
1726
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1727
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1728
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1729
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1730
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1731
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1732
+
1733
+ /**/
1734
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1735
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1736
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1737
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1738
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1739
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1740
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1741
+ //System.out.println("shininess = " + colorV[0]);
1742
+ if (colorV[0] > 128)
1743
+ {
1744
+ colorV[0] = 128;
1745
+ }
1746
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1747
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1748
+ /**/
1749
+ }
1750
+ /**/
1751
+
1752
+ //selected = false;
1753
+ selected = selected && display.flash;
1754
+
1755
+ //display.modelParams0[0] = 0; // pigment.r;
1756
+ //display.modelParams0[1] = 0; // pigment.g;
1757
+ //display.modelParams0[2] = 0; // pigment.b;
1758
+ if (!material.multiply)
1759
+ {
1760
+ display.modelParams0[3] = material.metalness;
1761
+ display.modelParams1[0] = material.diffuse;
1762
+ display.modelParams1[1] = material.specular;
1763
+ display.modelParams1[2] = 1 / material.shininess;
1764
+ display.modelParams1[3] = material.shift;
1765
+ display.modelParams2[0] = material.ambient;
1766
+ display.modelParams2[1] = material.lightarea;
1767
+ //System.out.println("light area = " + lightarea);
1768
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1769
+ display.modelParams2[3] = material.velvet;
1770
+ display.modelParams3[0] = material.sheen;
1771
+ display.modelParams3[1] = material.subsurface;
1772
+ display.modelParams3[2] = material.bump; // backlit
1773
+ display.modelParams3[3] = material.aniso;
1774
+ display.modelParams4[0] = material.anisoV;
1775
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1776
+ //System.out.println("selected = " + selected);
1777
+ display.modelParams4[2] = material.diffuseness;
1778
+ display.modelParams4[3] = material.shadow;
1779
+ display.modelParams5[0] = material.texture;
1780
+ display.modelParams5[1] = material.opacity;
1781
+ display.modelParams5[2] = material.fakedepth;
1782
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1783
+ }
1784
+ else
1785
+ {
1786
+ display.modelParams0[3] *= material.metalness*2;
1787
+ display.modelParams1[0] *= material.diffuse*2;
1788
+ display.modelParams1[1] *= material.specular*2;
1789
+ display.modelParams1[2] *= material.shininess*2;
1790
+ display.modelParams1[3] *= material.shift*2;
1791
+ display.modelParams2[0] *= material.ambient*2;
1792
+ display.modelParams2[1] *= material.lightarea*2;
1793
+ display.modelParams2[2] *= material.factor*2;
1794
+ display.modelParams2[3] *= material.velvet*2;
1795
+ display.modelParams3[0] *= material.sheen*2;
1796
+ display.modelParams3[1] *= material.subsurface*2;
1797
+ display.modelParams3[2] *= material.bump*2;
1798
+ display.modelParams3[3] *= material.aniso*2;
1799
+ display.modelParams4[0] *= material.anisoV*2;
1800
+ display.modelParams4[1] *= material.cameralight*2;
1801
+ //System.out.println("selected = " + selected);
1802
+ display.modelParams4[2] *= material.diffuseness*2;
1803
+ display.modelParams4[3] *= material.shadow*2;
1804
+ display.modelParams5[0] *= material.texture*2;
1805
+ display.modelParams5[1] *= material.opacity*2;
1806
+ display.modelParams5[2] *= material.fakedepth*2;
1807
+ display.modelParams5[3] *= material.shadowbias*2;
1808
+ }
1809
+
1810
+ display.modelParams6[0] = 0;
1811
+ display.modelParams6[1] = 0;
1812
+ display.modelParams6[2] = 0;
1813
+ display.modelParams6[3] = 0;
1814
+
1815
+ display.modelParams7[0] = 0;
1816
+ display.modelParams7[1] = 1000;
1817
+ display.modelParams7[2] = 0;
1818
+ display.modelParams7[3] = 0;
1819
+
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
1821
+
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1823
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1824
+ {
1825
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1826
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1827
+ if (extparams.length > 1)
1828
+ {
1829
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1830
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1831
+ if (extparams.length > 2)
1832
+ {
1833
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1834
+ float x = extparams[2].y / 1000.0f;
1835
+ //if (x == 0)
1836
+ // x = 1f;
1837
+ 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
1838
+ if (extparams[2].y > 0)
1839
+ {
1840
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1841
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1842
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1843
+ }
1844
+ }
1845
+ }
1846
+ }
1847
+
1848
+ //if (display.modelParams6[2] != 0)
1849
+ /*
1850
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1851
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1852
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1853
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1854
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1855
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1856
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1857
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1858
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1859
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1860
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1861
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1862
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1863
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1864
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1865
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1866
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1867
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1868
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1869
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1870
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1871
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1872
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1873
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1874
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1875
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1876
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1877
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1878
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1879
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1880
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1881
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1882
+ /**/
1883
+ //assert (display.modelParams6[2] == 0);
1884
+
1885
+ //System.out.println("noise power = " + display.modelParams7[0]);
1886
+ //System.out.println("shadowbias = " + shadowbias);
1887
+
1888
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1889
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1890
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1891
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1892
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1893
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1896
+
1897
+ int mode = display.FP_SHADER;
1898
+
1899
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1900
+ {
1901
+ mode |= display.FP_ANISO;
1902
+ }
1903
+
1904
+ display.EnableProgram(mode);
1905
+
1906
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1907
+
1908
+ if (!material.multiply)
1909
+ {
1910
+ if (Globals.drawMode == CameraPane.SHADOW)
1911
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1912
+ else
1913
+ gl.glDepthMask(material.opacity >= 0.99);
1914
+ }
2081915 }
2091916
2101917 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1932,7 @@
2251932 currentGL.glMultMatrixd(model, 0);
2261933 }
2271934
228
- void PushMatrix(double[][] matrix, int count)
1935
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291936 {
2301937 matrixdepth++;
2311938 // GrafreeD.tracein(matrix);
....@@ -254,7 +1961,7 @@
2541961 void PushMatrix(double[][] matrix)
2551962 {
2561963 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
2581965 }
2591966
2601967 void PushMatrix()
....@@ -270,7 +1977,7 @@
2701977
2711978 double[][] tmpmat = new double[4][4];
2721979
273
- void PopMatrix(double[][] inverse)
1980
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741981 {
2751982 --matrixdepth;
2761983
....@@ -310,7 +2017,7 @@
3102017 PushTextureMatrix(matrix, 1);
3112018 }
3122019
313
- void PushTextureMatrix(double[][] matrix, int count)
2020
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142021 {
3152022 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162023
....@@ -324,7 +2031,7 @@
3242031 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252032 }
3262033
327
- void PopTextureMatrix(double[][] inverse)
2034
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282035 {
3292036 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302037 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2058,15 @@
3512058
3522059 static int camerachangeframe;
3532060
354
- boolean SetCamera(Camera cam)
2061
+ public boolean SetCamera(Camera cam)
3552062 {
3562063 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572064 // return false;
3582065
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2066
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602067 {
3612068 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2069
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632070 {
3642071 // refuse the camera change
3652072 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2074,7 @@
3672074 }
3682075 }
3692076
370
- camerachangeframe = framecount;
2077
+ camerachangeframe = Globals.framecount;
3712078
3722079 cam.hAspect = -1; // Read only
3732080
....@@ -398,7 +2105,7 @@
3982105 {
3992106 //System.err.println("Oeil on");
4002107 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2108
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022109 // object.editWindow.ScreenFit(trackedobject);
4032110 //pingthread.StepToTarget(true);
4042111 }
....@@ -407,8 +2114,8 @@
4072114 {
4082115 //System.err.println("Oeil on");
4092116 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2117
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122119 //pingthread.StepToTarget(true);
4132120 }
4142121
....@@ -471,39 +2178,12 @@
4712178 {
4722179 frozen ^= true;
4732180 // Weird...
474
- lighttouched = true;
2181
+ Globals.lighttouched = true;
4752182 }
4762183
4772184 void ToggleDL()
4782185 {
4792186 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GrafreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072187 }
5082188
5092189 void ToggleFullScreen()
....@@ -513,12 +2193,7 @@
5132193
5142194 void ToggleCrowd()
5152195 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2196
+ Globals.CROWD ^= true;
5222197 }
5232198
5242199 void ToggleLocal()
....@@ -526,62 +2201,89 @@
5262201 LOCALTRANSFORM ^= true;
5272202 }
5282203
529
- void ToggleFast()
2204
+ public void ToggleTexture()
2205
+ {
2206
+ textureon ^= true;
2207
+ }
2208
+
2209
+ public void ToggleLive()
2210
+ {
2211
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2212
+
2213
+ System.err.println("LIVE = " + Globals.isLIVE());
2214
+
2215
+ if (!Globals.isLIVE()) // save sound
2216
+ Grafreed.savesound = true; // wav.save();
2217
+ // else
2218
+ repaint(); // start loop // may 2013
2219
+ }
2220
+
2221
+ public void ToggleSupport()
2222
+ {
2223
+ SUPPORT ^= true;
2224
+ }
2225
+
2226
+ public void ToggleAbort()
2227
+ {
2228
+ ABORTMODE ^= true;
2229
+ }
2230
+
2231
+ public void ToggleInertia()
2232
+ {
2233
+ INERTIA ^= true;
2234
+ }
2235
+
2236
+ public void ToggleFast()
5302237 {
5312238 FAST ^= true;
5322239 }
5332240
534
- void ToggleSlowPose()
2241
+ public void ToggleSlowPose()
5352242 {
5362243 SLOWPOSE ^= true;
5372244 }
5382245
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2246
+ public void ToggleBoxMode()
5452247 {
5462248 BOXMODE ^= true;
5472249 }
5482250
549
- void ToggleSmoothFocus()
2251
+ public void ToggleZoomBoxMode()
2252
+ {
2253
+ ZOOMBOXMODE ^= true;
2254
+ }
2255
+
2256
+ public void ToggleSmoothFocus()
5502257 {
5512258 SMOOTHFOCUS ^= true;
5522259 }
5532260
554
- void ToggleImageFlip()
2261
+ public void ToggleImageFlip()
5552262 {
5562263 IMAGEFLIP ^= true;
5572264 }
5582265
559
- void ToggleSpeakerMocap()
2266
+ public void ToggleSpeakerMocap()
5602267 {
5612268 SPEAKERMOCAP ^= true;
5622269 }
5632270
564
- void ToggleSpeakerCamera()
2271
+ public void ToggleSpeakerCamera()
5652272 {
5662273 SPEAKERCAMERA ^= true;
5672274 }
5682275
569
- void ToggleSpeakerFocus()
2276
+ public void ToggleSpeakerFocus()
5702277 {
5712278 SPEAKERFOCUS ^= true;
5722279 }
5732280
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2281
+ public void ToggleFrustum()
5802282 {
5812283 FRUSTUM ^= true;
5822284 }
5832285
584
- void ToggleTrack()
2286
+ public void ToggleTrack()
5852287 {
5862288 TRACK ^= true;
5872289 if (TRACK)
....@@ -600,25 +2302,35 @@
6002302 repaint();
6012303 }
6022304
603
- void ToggleTrackOnce()
2305
+ public void ToggleTrackOnce()
6042306 {
6052307 TRACKONCE ^= true;
6062308 }
6072309
608
- void ToggleShadowTrack()
2310
+ public void ToggleShadowTrack()
6092311 {
6102312 SHADOWTRACK ^= true;
6112313 repaint();
6122314 }
6132315
614
- void ToggleOeil()
2316
+ public void ToggleOeil()
6152317 {
6162318 OEIL ^= true;
6172319 }
6182320
619
- void ToggleOeilOnce()
2321
+ public void ToggleOeilOnce()
6202322 {
6212323 OEILONCE ^= true;
2324
+ }
2325
+
2326
+ void ToggleFootContact()
2327
+ {
2328
+ FOOTCONTACT ^= true;
2329
+ }
2330
+
2331
+ void ToggleDebug()
2332
+ {
2333
+ Globals.DEBUG ^= true;
6222334 }
6232335
6242336 void ToggleLookAt()
....@@ -626,9 +2338,9 @@
6262338 LOOKAT ^= true;
6272339 }
6282340
629
- void ToggleRandom()
2341
+ void ToggleSwitch()
6302342 {
631
- RANDOM ^= true;
2343
+ SWITCH ^= true;
6322344 }
6332345
6342346 void ToggleHandles()
....@@ -636,10 +2348,17 @@
6362348 HANDLES ^= true;
6372349 }
6382350
2351
+ Object3D paintFolder;
2352
+
6392353 void TogglePaint()
6402354 {
6412355 PAINTMODE ^= true;
6422356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
6432362 }
6442363
6452364 void SwapCamera(int a, int b)
....@@ -672,34 +2391,6 @@
6722391 //assert (cam.hAspect == 0);
6732392 cam.hAspect = 0;
6742393 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
7032394 }
7042395
7052396 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2450,26 @@
7592450
7602451 GL currentGL;
7612452
762
- GL GetGL()
2453
+ public GL GetGL() // INTERFACE
7632454 {
7642455 return currentGL;
7652456 }
766
-
2457
+
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
7672473 /**/
7682474 class CacheTexture
7692475 {
....@@ -772,28 +2478,31 @@
7722478
7732479 int resolution;
7742480
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762482 {
777
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
7782485 resolution = res;
7792486 }
7802487 }
7812488 /**/
7822489
7832490 // 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>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
7872496 int pigmentdepth = 0;
7882497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892498 int bumpdepth = 0;
7902499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952504
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972506 {
7982507 TextureData texturedata = null;
7992508
....@@ -812,13 +2521,34 @@
8122521 if (bump)
8132522 texturedata = ConvertBump(texturedata, false);
8142523
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172526
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);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202529
821
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
8222552 }
8232553
8242554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3621,8 @@
18913621
18923622 System.out.println("LOADING TEXTURE : " + name);
18933623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
18943626 //
18953627 if (false) // compressbit > 0)
18963628 {
....@@ -2000,10 +3732,12 @@
20003732 */
20013733 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20023734 {
3735
+ int pixelformat = texturedata.getPixelFormat();
3736
+
20033737 int stride = 1;
2004
- if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
3738
+ if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
20053739 stride = 3;
2006
- if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
3740
+ if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
20073741 stride = 4;
20083742
20093743 int width = texturedata.getWidth();
....@@ -2593,6 +4327,7 @@
25934327
25944328 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25954329 {
4330
+ new Exception().printStackTrace();
25964331 System.exit(0);
25974332 com.sun.opengl.util.texture.Texture texture = null;
25984333
....@@ -6269,7 +8004,7 @@
62698004 return null;
62708005 }
62718006
6272
- void ReleaseTextures(cTexture tex)
8007
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62738008 {
62748009 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62758010 {
....@@ -6286,7 +8021,7 @@
62868021 String pigment = Object3D.GetPigment(tex);
62878022 String bump = Object3D.GetBump(tex);
62888023
6289
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62908025 {
62918026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62928027 // System.out.println("; bump = " + bump);
....@@ -6301,13 +8036,71 @@
63018036 pigment = null;
63028037 }
63038038
6304
- ReleaseTexture(bump, true);
6305
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
63068041 }
63078042
6308
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63098044 {
6310
- if (// drawMode != 0 || /*tex == null ||*/
8045
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8046
+ {
8047
+ return;
8048
+ }
8049
+
8050
+ if (tex == null)
8051
+ {
8052
+ ReleaseTexture(null, false);
8053
+ return;
8054
+ }
8055
+
8056
+ String pigment = Object3D.GetPigment(tex);
8057
+
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8059
+ {
8060
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8061
+ // System.out.println("; bump = " + bump);
8062
+ }
8063
+
8064
+ if (pigment.equals(""))
8065
+ {
8066
+ pigment = null;
8067
+ }
8068
+
8069
+ ReleaseTexture(tex, false);
8070
+ }
8071
+
8072
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8073
+ {
8074
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8075
+ {
8076
+ return;
8077
+ }
8078
+
8079
+ if (tex == null)
8080
+ {
8081
+ ReleaseTexture(null, true);
8082
+ return;
8083
+ }
8084
+
8085
+ String bump = Object3D.GetBump(tex);
8086
+
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8088
+ {
8089
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8090
+ // System.out.println("; bump = " + bump);
8091
+ }
8092
+
8093
+ if (bump.equals(""))
8094
+ {
8095
+ bump = null;
8096
+ }
8097
+
8098
+ ReleaseTexture(tex, true);
8099
+ }
8100
+
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
8102
+ {
8103
+ if (// DrawMode() != 0 || /*tex == null ||*/
63118104 ambientOcclusion ) // || !textureon)
63128105 {
63138106 return;
....@@ -6316,7 +8109,7 @@
63168109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63178110
63188111 if (tex != null)
6319
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63208113
63218114 // //assert( texture != null );
63228115 // if (texture == null)
....@@ -6408,9 +8201,57 @@
64088201 }
64098202 }
64108203
6411
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8204
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64128205 {
6413
- if (// drawMode != 0 || /*tex == null ||*/
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
8247
+
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
8250
+ }
8251
+
8252
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8253
+ {
8254
+ if (// DrawMode() != 0 || /*tex == null ||*/
64148255 ambientOcclusion ) // || !textureon)
64158256 {
64168257 return; // false;
....@@ -6419,17 +8260,47 @@
64198260 if (tex == null)
64208261 {
64218262 BindTexture(null,false,resolution);
6422
- BindTexture(null,true,resolution);
64238263 return;
64248264 }
64258265
64268266 String pigment = Object3D.GetPigment(tex);
8267
+
8268
+ usedtextures.add(tex);
8269
+
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8271
+ {
8272
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8273
+ // System.out.println("; bump = " + bump);
8274
+ }
8275
+
8276
+ if (pigment.equals(""))
8277
+ {
8278
+ pigment = null;
8279
+ }
8280
+
8281
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8282
+ BindTexture(tex, false, resolution);
8283
+ }
8284
+
8285
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8286
+ {
8287
+ if (// DrawMode() != 0 || /*tex == null ||*/
8288
+ ambientOcclusion ) // || !textureon)
8289
+ {
8290
+ return; // false;
8291
+ }
8292
+
8293
+ if (tex == null)
8294
+ {
8295
+ BindTexture(null,true,resolution);
8296
+ return;
8297
+ }
8298
+
64278299 String bump = Object3D.GetBump(tex);
64288300
6429
- usedtextures.put(pigment, pigment);
6430
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
64318302
6432
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64338304 {
64348305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64358306 // System.out.println("; bump = " + bump);
....@@ -6439,43 +8310,94 @@
64398310 {
64408311 bump = null;
64418312 }
6442
- if (pigment.equals(""))
6443
- {
6444
- pigment = null;
6445
- }
64468313
6447
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6448
- BindTexture(pigment, false, resolution);
64498314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6450
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
64518316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6452
-
6453
- return; // true;
64548317 }
64558318
6456
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
64578322 {
6458
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8323
+ if (missingTextures.contains(tex))
8324
+ {
8325
+ return false;
8326
+ }
8327
+
8328
+ boolean fileExists = new File(tex).exists();
8329
+
8330
+ if (!fileExists)
8331
+ {
8332
+ // If file exists, the "new File()" is not executed sgain
8333
+ missingTextures.add(tex);
8334
+ }
8335
+
8336
+ return fileExists;
8337
+ }
8338
+
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8340
+ {
8341
+ CacheTexture texturecache = null;
64598342
64608343 if (tex != null)
64618344 {
6462
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64638347
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;
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
8352
+
8353
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8354
+
8355
+// String[] split = tex.split("Textures");
8356
+// if (split.length > 1)
8357
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8358
+// else
8359
+// if (!texname.startsWith("/"))
8360
+// texname = "/Users/nbriere/Textures/" + texname;
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
64708365
64718366 if (CACHETEXTURE)
6472
- texture = textures.get(texname); // TEXTURE CACHE
6473
-
6474
- TextureData texturedata = null;
6475
-
6476
- if (texture == null || texture.resolution < resolution)
64778367 {
6478
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64798401 {
64808402 assert(!bump);
64818403 // if (bump)
....@@ -6486,19 +8408,23 @@
64868408 // }
64878409 // else
64888410 // {
6489
- texture = textures.get(tex);
6490
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
64918413 {
6492
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64938415 }
8416
+ else
8417
+ new Exception().printStackTrace();
64948418 // }
64958419 } else
6496
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64978421 {
64988422 assert(bump);
6499
- texture = textures.get(tex);
6500
- if (texture == null)
6501
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
65028428 } else
65038429 {
65048430 //if (tex.equals("IMMORTAL"))
....@@ -6506,11 +8432,22 @@
65068432 // texture = GetResourceTexture("default.png");
65078433 //} else
65088434 //{
6509
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
65108436 {
6511
- texture = textures.get(tex);
6512
- if (texture == null)
6513
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
65148451 } else
65158452 {
65168453 if (textureon)
....@@ -6535,7 +8472,7 @@
65358472 }
65368473
65378474 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6538
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
65398476 cachename = texname;
65408477 else
65418478 processbump = false; // don't process bump map again
....@@ -6557,7 +8494,7 @@
65578494 }
65588495
65598496 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6560
- if (!new File(cachename).exists())
8497
+ if (!FileExists(cachename))
65618498 cachename = texname;
65628499 else
65638500 processbump = false; // don't process bump map again
....@@ -6566,20 +8503,23 @@
65668503 texturedata = GetFileTexture(cachename, processbump, resolution);
65678504
65688505
6569
- if (texturedata != null)
6570
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8506
+ if (texturedata == null)
8507
+ throw new Exception();
8508
+
8509
+ texturecache = new CacheTexture(texturedata,resolution);
65718510 //texture = GetTexture(tex, bump);
65728511 }
8512
+ }
65738513 }
65748514 //}
65758515 }
65768516
6577
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65788518 {
65798519 //return false;
65808520
65818521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6582
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65838523 {
65848524 // String ext = "_highres";
65858525 // if (REDUCETEXTURE)
....@@ -6596,52 +8536,17 @@
65968536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65978537 if (!cachefile.exists())
65988538 {
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))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
66088540 {
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);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
66398543 ImageWriter writer = null;
66408544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66418545 if (iter.hasNext()) {
66428546 writer = (ImageWriter)iter.next();
66438547 }
6644
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
66458550 try
66468551 {
66478552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6658,18 +8563,20 @@
66588563 }
66598564 }
66608565 }
6661
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
66628569 //System.out.println("Texture = " + tex);
6663
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
66648571 {
6665
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
66668573 thetex.texture.disable();
66678574 thetex.texture.dispose();
6668
- textures.remove(texname);
8575
+ textures.remove(tex);
66698576 }
66708577
6671
- texture.texturedata = texturedata;
6672
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
66738580
66748581 // newtex = true;
66758582 }
....@@ -6685,10 +8592,44 @@
66858592 }
66868593 }
66878594
6688
- return texture;
8595
+ return texturecache;
66898596 }
66908597
6691
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66928633 {
66938634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66948635
....@@ -6706,21 +8647,21 @@
67068647 return texture!=null?texture.texture:null;
67078648 }
67088649
6709
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67108651 {
67118652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67128653
67138654 return texture!=null?texture.texturedata:null;
67148655 }
67158656
6716
- boolean BindTexture(String tex, boolean bump, int resolution)
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67178658 {
67188659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67198660 {
67208661 return false;
67218662 }
67228663
6723
- boolean newtex = false;
8664
+ //boolean newtex = false;
67248665
67258666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67268667
....@@ -6752,9 +8693,75 @@
67528693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67538694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67548695
6755
- return newtex;
8696
+ return true; // Warning: not used.
67568697 }
67578698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
67588765 ShadowBuffer shadowPBuf;
67598766 AntialiasBuffer antialiasPBuf;
67608767 int MAXSTACK;
....@@ -6771,10 +8778,12 @@
67718778
67728779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67738780 MAXSTACK = temp[0];
6774
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67758783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67768784 MAXSTACK = temp[0];
6777
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67788787
67798788 // Use debug pipeline
67808789 //drawable.setGL(new DebugGL(gl)); //
....@@ -6782,7 +8791,8 @@
67828791 gl = drawable.getGL(); //
67838792
67848793 GL gl3 = getGL();
6785
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67868796
67878797
67888798 //float pos[] = { 100, 100, 100, 0 };
....@@ -6947,7 +8957,7 @@
69478957
69488958 if (cubemap == null)
69498959 {
6950
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
69518961 }
69528962
69538963 //cubemap.enable();
....@@ -7234,37 +9244,58 @@
72349244 cubemap = null;
72359245 return;
72369246 case 1:
7237
- name = "cubemaps/box_";
7238
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
72399249 reverseUP = false;
72409250 break;
72419251 case 2:
7242
- name = "cubemaps/uffizi_";
7243
- ext = "png";
7244
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
72459256 case 3:
7246
- name = "cubemaps/CloudyHills_";
7247
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
72489259 reverseUP = false;
72499260 break;
72509261 case 4:
7251
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
72529263 ext = "png";
72539264 reverseUP = false;
72549265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
72559291 default:
7256
- name = "cubemaps/rgb_";
7257
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
72589295 break;
72599296 }
7260
-
7261
- try
7262
- {
7263
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7264
- } catch (IOException e)
7265
- {
7266
- throw new RuntimeException(e);
7267
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
72689299 }
72699300
72709301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7296,8 +9327,12 @@
72969327 static double[] model = new double[16];
72979328 double[] camera2light = new double[16];
72989329 double[] light2camera = new double[16];
7299
- int newenvy = -1;
7300
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
73019336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73029337 //float[] light0 = { 0,0,0 };
73039338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7310,9 +9345,9 @@
73109345 static boolean occlusionInitialized = false;
73119346 boolean selection = false;
73129347 boolean pointselection = false;
7313
- /*static*/ boolean lighttouched = true;
9348
+ ///*static*/ boolean lighttouched = true;
73149349 boolean deselect;
7315
- boolean ambientOcclusion = false;
9350
+ private boolean ambientOcclusion = false;
73169351 static boolean flash = false;
73179352 /*static*/ boolean wait = false;
73189353 boolean displaydone = false; // after repaint() calls
....@@ -7442,6 +9477,8 @@
74429477 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74439478 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74449479 double scale = lightCamera.SCALE / lightCamera.Distance();
9480
+// PATCH FILLE AUX JEANS
9481
+ //scale *= lightCamera.shaper_fovy / 25;
74459482 gl.glScaled(2 * scale, 2 * scale, -scale);
74469483 gl.glTranslated(0, 0, lightCamera.DECAL);
74479484
....@@ -7588,17 +9625,40 @@
75889625 jy8[3] = 0.5f;
75899626 }
75909627
7591
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9628
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75929629 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
9630
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9631
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75949632
9633
+ void ResetOptions()
9634
+ {
9635
+ options1[0] = 100;
9636
+ options1[1] = 0.025f;
9637
+ options1[2] = 0.01f;
9638
+ options1[3] = 0;
9639
+ options1[4] = 0;
9640
+
9641
+ options2[0] = 0;
9642
+ options2[1] = 0.75f;
9643
+ options2[2] = 0;
9644
+ options2[3] = 0;
9645
+
9646
+ options3[0] = 1;
9647
+ options3[1] = 1;
9648
+ options3[2] = 1;
9649
+ options3[3] = 0;
9650
+
9651
+ options4[0] = 1;
9652
+ options4[1] = 0;
9653
+ options4[2] = 1;
9654
+ options4[3] = 0;
9655
+ }
9656
+
75959657 static int imagecount = 0; // movie generation
75969658
75979659 static int jitter = 0;
75989660
75999661 boolean restartframe = false;
7600
-
7601
- static int framecount = 0; // general-purpose global count
76029662
76039663 void displayAntiAliased(javax.media.opengl.GL gl)
76049664 {
....@@ -7630,7 +9690,7 @@
76309690 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76319691 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76329692 {
7633
- framecount++;
9693
+ Globals.framecount++;
76349694
76359695 if (CameraPane.tickcount > 0)
76369696 CameraPane.tickcount--;
....@@ -7668,7 +9728,7 @@
76689728
76699729 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76709730 */
7671
- lighttouched = true;
9731
+ Globals.lighttouched = true;
76729732 //System.err.println(" shadowbuffer: " + jitter);
76739733 shadowbuffer.display();
76749734
....@@ -7689,8 +9749,8 @@
76899749 assert (parentcam != renderCamera);
76909750
76919751 if (renderCamera != lightCamera)
7692
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7693
- LA.matConcat(parentcam.toParent, matrix, matrix);
9752
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76949754
76959755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76969756
....@@ -7705,8 +9765,8 @@
77059765 LA.matCopy(renderCamera.fromScreen, matrix);
77069766
77079767 if (renderCamera != lightCamera)
7708
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7709
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9768
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77109770
77119771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77129772
....@@ -7752,10 +9812,12 @@
77529812 rati = 1 / rati;
77539813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77549814 }
7755
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
77569818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77579819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7758
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
77599821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77609822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77619823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7778,7 +9840,7 @@
77789840 //gl.glFlush();
77799841 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77809842
7781
- if (ANIMATION && ABORTED)
9843
+ if (Globals.ANIMATION && ABORTED)
77829844 {
77839845 System.err.println(" ABORTED FRAME");
77849846 break;
....@@ -7808,7 +9870,7 @@
78089870 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78099871
78109872 // save image
7811
- if (ANIMATION && !ABORTED)
9873
+ if (Globals.ANIMATION && !ABORTED)
78129874 {
78139875 VPwidth = viewport[2];
78149876 VPheight = viewport[3];
....@@ -7919,11 +9981,11 @@
79199981
79209982 // imagecount++;
79219983
7922
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9984
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79239985
79249986 if (!BOXMODE)
79259987 {
7926
- System.out.println("image: " + fullname + " (" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9988
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79279989 }
79289990
79299991 if (!BOXMODE)
....@@ -7961,7 +10023,7 @@
796110023 ABORTED = false;
796210024 }
796310025 else
7964
- GrafreeD.wav.cursor += 735 * ACSIZE;
10026
+ Grafreed.wav.cursor += 735 * ACSIZE;
796510027
796610028 if (false)
796710029 {
....@@ -8615,13 +10677,6 @@
861510677 }
861610678 }
861710679
8618
- boolean IsFrozen()
8619
- {
8620
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8621
-
8622
- return !selectmode && cameracount == 0; // != 0;
8623
- }
8624
-
862510680 boolean niceon = false;
862610681 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
862710682 boolean currentlydrawing = false;
....@@ -8631,16 +10686,16 @@
863110686
863210687 public void display(GLAutoDrawable drawable)
863310688 {
8634
- if (GrafreeD.savesound && GrafreeD.hassound)
10689
+ if (Grafreed.savesound && Grafreed.hassound)
863510690 {
8636
- GrafreeD.wav.save();
8637
- GrafreeD.savesound = false;
8638
- GrafreeD.hassound = false;
10691
+ Grafreed.wav.save();
10692
+ Grafreed.savesound = false;
10693
+ Grafreed.hassound = false;
863910694 }
864010695 // if (DEBUG_SELECTION)
864110696 // {
8642
-// if (drawMode != SELECTION)
8643
-// drawMode = SELECTION;
10697
+// if (DrawMode() != SELECTION)
10698
+// DrawMode() = SELECTION;
864410699 // }
864510700
864610701 if (!isRenderer)
....@@ -8696,9 +10751,9 @@
869610751
869710752 //ANTIALIAS = 0;
869810753
8699
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10754
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870010755 {
8701
- if (niceon || isLIVE())
10756
+ if (niceon || Globals.isLIVE())
870210757 {
870310758 //if(active == 0)
870410759 // antialiaser = null;
....@@ -8711,6 +10766,7 @@
871110766 ANTIALIAS = 0;
871210767 //System.out.println("RESTART");
871310768 AAtimer.restart();
10769
+ Globals.TIMERRUNNING = true;
871410770 }
871510771 }
871610772 }
....@@ -8723,7 +10779,7 @@
872310779 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872410780 */
872510781
8726
- if (drawMode == DEFAULT)
10782
+ if (DrawMode() == DEFAULT)
872710783 {
872810784 currentlydrawing = true;
872910785 }
....@@ -8754,18 +10810,18 @@
875410810
875510811 // if(Applet3D.clipboard != null)
875610812 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8757
-//drawMode = SELECTION;
10813
+//DrawMode() = SELECTION;
875810814 indexcount = 0;
875910815
8760
- if (drawMode == OCCLUSION)
10816
+ if (DrawMode() == OCCLUSION)
876110817 {
8762
- drawMode = DEFAULT;
10818
+ Globals.drawMode = DEFAULT; // WARNING
876310819 ambientOcclusion = true;
876410820 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876510821 Object3D theobject = object;
876610822 Object3D theparent = object.parent;
876710823 object.parent = null;
8768
- object = (Object3D)GrafreeD.clone(object);
10824
+ object = (Object3D)Grafreed.clone(object);
876910825 object.Stripify();
877010826 if (theobject.selection == null || theobject.selection.Size() == 0)
877110827 theobject.PreprocessOcclusion(this);
....@@ -8778,26 +10834,27 @@
877810834 ambientOcclusion = false;
877910835 }
878010836
8781
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10837
+ if (//Globals.lighttouched &&
10838
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878210839 {
878310840 //if (RENDERSHADOW) // ?
878410841 if (!IsFrozen())
878510842 {
878610843 // dec 2012
8787
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10844
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
878810845 {
8789
- framecount++;
10846
+ Globals.framecount++;
879010847 shadowbuffer.display();
879110848 }
879210849 }
8793
- lighttouched = false; // ??
10850
+ Globals.lighttouched = false; // ??
879410851 //drawing = true;
879510852 //lighttouched = true;
879610853 }
879710854
879810855 if (wait)
879910856 {
8800
- Sleep(500);
10857
+ Sleep(200); // blocks everything
880110858
880210859 wait = false;
880310860 }
....@@ -8811,9 +10868,9 @@
881110868 //eyeCamera.shaper_fovy = 1;
881210869 }
881310870
8814
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10871
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881510872 {
8816
- //System.out.println("drawMode = " + drawMode);
10873
+ //System.out.println("DrawMode() = " + DrawMode());
881710874 vertexMode |= VP_PASS;
881810875 //vertexMode |= VP_PROJECTION;
881910876 if (!ambientOcclusion)
....@@ -8873,7 +10930,7 @@
887310930 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887410931 //Camera lightcam = new Camera(light0);
887510932
8876
- if (drawMode == SHADOW)
10933
+ if (DrawMode() == SHADOW)
887710934 {
887810935 /*
887910936 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8911,8 +10968,8 @@
891110968
891210969 // if (parentcam != renderCamera) // not a light
891310970 if (cam != lightCamera)
8914
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8915
- LA.matConcat(parentcam.toParent, matrix, matrix);
10971
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891610973
891710974 for (int j = 0; j < 4; j++)
891810975 {
....@@ -8926,8 +10983,8 @@
892610983
892710984 // if (parentcam != renderCamera) // not a light
892810985 if (cam != lightCamera)
8929
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8930
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10986
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893110988
893210989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893310990
....@@ -8963,7 +11020,7 @@
896311020 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896411021 } else
896511022 {
8966
- if (drawMode != DEFAULT)
11023
+ if (DrawMode() != DEFAULT)
896711024 {
896811025 gl.glClearColor(1, 1, 1, 0);
896911026 } // 1);
....@@ -9013,13 +11070,27 @@
901311070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901411071 }
901511072
9016
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
901711081 {
9018
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
901911087 }
9020
-
9021
- newenvy = -1;
9022
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
902311094 ratio = ((double) getWidth()) / getHeight();
902411095 //System.out.println("ratio = " + ratio);
902511096
....@@ -9028,14 +11099,14 @@
902811099
902911100 fast &= !ambientOcclusion;
903011101
9031
- if (drawMode == DEFAULT)
11102
+ if (DrawMode() == DEFAULT)
903211103 {
903311104 //gl.glEnable(gl.GL_ALPHA_TEST);
903411105 //gl.glActiveTexture(GL.GL_TEXTURE0);
903511106
903611107 if (!IsFrozen() && !ambientOcclusion)
903711108 {
9038
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
903911110 }
904011111
904111112 //if (selection_view == -1)
....@@ -9089,6 +11160,8 @@
908911160 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909011161 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909111162 double scale = lightCamera.SCALE / lightCamera.Distance();
11163
+// PATCH FILLE AUX JEANS
11164
+ //scale *= lightCamera.shaper_fovy / 25;
909211165 gl.glScaled(2 * scale, 2 * scale, -scale);
909311166 gl.glTranslated(0, 0, lightCamera.DECAL);
909411167
....@@ -9184,7 +11257,16 @@
918411257 // Bump noise
918511258 gl.glActiveTexture(GL.GL_TEXTURE6);
918611259 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9187
- BindTexture(NOISE_TEXTURE, false, 2);
11260
+
11261
+ try
11262
+ {
11263
+ BindTexture(NOISE_TEXTURE, false, 2);
11264
+ }
11265
+ catch (Exception e)
11266
+ {
11267
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11268
+ }
11269
+
918811270
918911271 gl.glActiveTexture(GL.GL_TEXTURE0);
919011272 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9207,9 +11289,9 @@
920711289
920811290 gl.glMatrixMode(GL.GL_MODELVIEW);
920911291
9210
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9211
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9212
-//gl.glEnable(gl.GL_MULTISAMPLE);
11292
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11293
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11294
+gl.glEnable(gl.GL_MULTISAMPLE);
921311295 } else
921411296 {
921511297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9220,14 +11302,16 @@
922011302 //System.out.println("BLENDING ON");
922111303 gl.glEnable(GL.GL_BLEND);
922211304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9223
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922411306 gl.glMatrixMode(gl.GL_PROJECTION);
922511307 gl.glLoadIdentity();
922611308
9227
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11309
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
922811310 {
922911311 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923011312 double scale = lightCamera.SCALE / lightCamera.Distance();
11313
+// PATCH FILLE AUX JEANS
11314
+ //scale *= lightCamera.shaper_fovy / 25;
923111315 gl.glScaled(2 * scale, 2 * scale, -scale);
923211316 gl.glTranslated(0, 0, lightCamera.DECAL);
923311317 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9280,7 +11364,7 @@
928011364 //gl.glPushMatrix();
928111365 gl.glLoadIdentity();
928211366
9283
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11367
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928411368 {
928511369 //LA.xformPos(light0, lightCamera.fromScreen, light);
928611370 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9307,8 +11391,8 @@
930711391 System.err.println("parentcam != renderCamera");
930811392
930911393 // if (cam != lightCamera)
9310
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9311
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11394
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
931211396 }
931311397
931411398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9329,8 +11413,8 @@
932911413 if (true) // TODO
933011414 {
933111415 if (cam != lightCamera)
9332
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9333
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11416
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11417
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933411418 }
933511419
933611420 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9367,7 +11451,7 @@
936711451 }
936811452
936911453 /**/
9370
- if (true) // drawMode == SELECTION) // != DEFAULT)
11454
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937111455 gl.glDisable(gl.GL_LIGHTING);
937211456 else
937311457 gl.glEnable(gl.GL_LIGHTING);
....@@ -9379,12 +11463,13 @@
937911463
938011464 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
938111465 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11466
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
938211467
938311468 options2[0] *= renderCamera.Distance();
938411469
938511470 lightslot = 64;
938611471
9387
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11472
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
938811473 {
938911474 DrawLights(object);
939011475 }
....@@ -9395,7 +11480,7 @@
939511480 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
939611481 //System.out.println("fragmentMode = " + fragmentMode);
939711482
9398
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11483
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
939911484 {
940011485 /*
940111486 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9428,7 +11513,7 @@
942811513 }
942911514 }
943011515
9431
- if (drawMode == DEFAULT)
11516
+ if (DrawMode() == DEFAULT)
943211517 {
943311518 if (WIREFRAME && !ambientOcclusion)
943411519 {
....@@ -9446,7 +11531,7 @@
944611531 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
944711532 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
944811533
9449
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11534
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945011535 {
945111536 if (vertexMode != 0) // && !fast)
945211537 {
....@@ -9466,7 +11551,7 @@
946611551 }
946711552 }
946811553
9469
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947011555 {
947111556 //gl.glDepthFunc(GL.GL_LEQUAL);
947211557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9474,27 +11559,24 @@
947411559
947511560 boolean texon = textureon;
947611561
9477
- if (RENDERPROGRAM > 0)
9478
- {
9479
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9480
- textureon = false;
9481
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
948211565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948311566 //System.out.println("ALLO");
948411567 gl.glColorMask(false, false, false, false);
948511568 DrawObject(gl);
9486
- if (RENDERPROGRAM > 0)
9487
- {
9488
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9489
- textureon = texon;
9490
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
949111573 gl.glColorMask(true, true, true, true);
949211574
949311575 gl.glDepthFunc(GL.GL_EQUAL);
9494
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
949511577 }
949611578
9497
- if (false) // drawMode == SHADOW)
11579
+ if (false) // DrawMode() == SHADOW)
949811580 {
949911581 //SetColumnMajorData(cameraInverseTransform, view_1);
950011582 //System.out.println("light = " + cameraInverseTransform);
....@@ -9508,16 +11590,16 @@
950811590 //System.out.println("object = " + object);
950911591 if (!frozen && !imageLocked)
951011592 {
9511
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11593
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951211594 {
951311595 displayAntiAliased(gl);
951411596 } else
951511597 {
951611598 programcount = 0;
9517
- int keepmode = drawMode;
11599
+ int keepmode = DrawMode();
951811600 // if (DEBUG_SELECTION)
951911601 // {
9520
-// drawMode = SELECTION;
11602
+// DrawMode() = SELECTION;
952111603 // }
952211604 // for point selection
952311605 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9527,10 +11609,10 @@
952711609 DrawObject(gl);
952811610
952911611 // jan 2013 System.err.println("RESET ABORT (display)");
9530
- // if (drawMode == DEFAULT)
11612
+ // if (DrawMode() == DEFAULT)
953111613 // ABORTED = false;
953211614 fullreset = false;
9533
- drawMode = keepmode;
11615
+ Globals.drawMode = keepmode; // WARNING
953411616 //System.out.println("PROGRAM SWITCH " + programcount);
953511617 }
953611618 }
....@@ -9538,11 +11620,11 @@
953811620 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
953911621 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954011622
9541
- if (drawMode == DEFAULT)
11623
+ if (DrawMode() == DEFAULT)
954211624 {
954311625 ReleaseTexture(NOISE_TEXTURE, false);
954411626 }
9545
- //if (drawMode == DEFAULT)
11627
+ //if (DrawMode() == DEFAULT)
954611628 {
954711629
954811630 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9554,7 +11636,7 @@
955411636 //else
955511637 //gl.glDisable(gl.GL_TEXTURE_2D);
955611638 //gl.glPopMatrix();
9557
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11639
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
955811640 {
955911641 //new Exception().printStackTrace();
956011642 //System.out.println("Draw image " + width + ", " + height);
....@@ -9596,7 +11678,7 @@
959611678 //gl.glFlush();
959711679 }
959811680
9599
- if (flash && drawMode == DEFAULT)
11681
+ if (flash && DrawMode() == DEFAULT)
960011682 {
960111683 flash = false;
960211684 wait = true;
....@@ -9604,9 +11686,9 @@
960411686 }
960511687
960611688 //drawing = false;
9607
- //if(drawMode == DEFAULT)
11689
+ //if(DrawMode() == DEFAULT)
960811690 // niceon = false;
9609
- if (drawMode == DEFAULT)
11691
+ if (DrawMode() == DEFAULT)
961011692 {
961111693 currentlydrawing = false;
961211694 }
....@@ -9626,7 +11708,7 @@
962611708 repaint();
962711709 }
962811710
9629
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11711
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963011712 repaint();
963111713
963211714 displaydone = true;
....@@ -9645,8 +11727,14 @@
964511727 {
964611728 renderpass++;
964711729 // System.out.println("Draw object... ");
11730
+ STEP = 1;
964811731 if (FAST) // in case there is no script
9649
- STEP = 16;
11732
+ STEP = 8;
11733
+
11734
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11735
+ {
11736
+ STEP *= 4;
11737
+ }
965011738
965111739 //object.FullInvariants();
965211740
....@@ -9660,23 +11748,44 @@
966011748 e.printStackTrace();
966111749 }
966211750
9663
- if (GrafreeD.RENDERME > 0)
9664
- GrafreeD.RENDERME--; // mechante magouille
11751
+ if (Grafreed.RENDERME > 0)
11752
+ Grafreed.RENDERME--; // mechante magouille
966511753
9666
- ONESTEP = false;
11754
+ Globals.ONESTEP = false;
966711755 }
966811756
966911757 static boolean zoomonce = false;
967011758
11759
+ static void CreateSelectedPoint()
11760
+ {
11761
+ if (selectedpoint == null)
11762
+ {
11763
+ debugpointG = new Sphere();
11764
+ debugpointP = new Sphere();
11765
+ debugpointC = new Sphere();
11766
+ debugpointR = new Sphere();
11767
+
11768
+ selectedpoint = new Superellipsoid();
11769
+
11770
+ for (int i=0; i<8; i++)
11771
+ {
11772
+ debugpoints[i] = new Sphere();
11773
+ }
11774
+ }
11775
+ }
11776
+
967111777 void DrawObject(GL gl, boolean draw)
967211778 {
11779
+ // To clear camera values
11780
+ ResetOptions();
11781
+
967311782 //System.out.println("DRAW OBJECT " + mouseDown);
9674
-// drawMode = SELECTION;
11783
+// DrawMode() = SELECTION;
967511784 //GL gl = getGL();
967611785 if ((TRACK || SHADOWTRACK) || zoomonce)
967711786 {
9678
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9679
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11787
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11788
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968011789 pingthread.StepToTarget(true); // true);
968111790 // zoomonce = false;
968211791 }
....@@ -9696,9 +11805,9 @@
969611805 callist = gl.glGenLists(1);
969711806 }
969811807
9699
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11808
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970011809
9701
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11810
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970211811
970311812 if (!mainDL || !active || touched)
970411813 {
....@@ -9725,13 +11834,20 @@
972511834 PushMatrix(ClickInfo.matbuffer);
972611835 }
972711836
9728
- if (drawMode == 0)
11837
+ if (DrawMode() == 0)
972911838 {
973011839 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973111840
973211841 usedtextures.clear();
973311842
9734
- BindTextures(DEFAULT_TEXTURES, 2);
11843
+ try
11844
+ {
11845
+ BindTextures(DEFAULT_TEXTURES, 2);
11846
+ }
11847
+ catch (Exception e)
11848
+ {
11849
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11850
+ }
973511851 }
973611852 //System.out.println("--> " + stackdepth);
973711853 // GrafreeD.traceon();
....@@ -9739,10 +11855,11 @@
973911855 // DRAW
974011856 object.draw(this, /*(Composite)*/ object, false, false);
974111857
9742
- if (drawMode == DEFAULT)
11858
+ if (DrawMode() == DEFAULT)
974311859 {
9744
- if (DEBUG)
11860
+ if (Globals.DEBUG)
974511861 {
11862
+ CreateSelectedPoint();
974611863 float radius = 0.05f;
974711864 if (selectedpoint.radius != radius)
974811865 {
....@@ -9750,40 +11867,40 @@
975011867 selectedpoint.radius = radius;
975111868 selectedpoint.recalculate();
975211869 selectedpoint.material = new cMaterial();
9753
- selectedpoint.material.color = 0.25f;
11870
+ selectedpoint.material.color = 0.15f; // Yellow
975411871 selectedpoint.material.modulation = 0.75f;
975511872
9756
- debugpoint.radius = radius;
9757
- debugpoint.recalculate();
9758
- debugpoint.material = new cMaterial();
9759
- debugpoint.material.color = 0.25f;
9760
- debugpoint.material.modulation = 0.75f;
11873
+ debugpointG.radius = radius;
11874
+ debugpointG.recalculate();
11875
+ debugpointG.material = new cMaterial();
11876
+ debugpointG.material.color = 0.25f; // Green
11877
+ debugpointG.material.modulation = 0.75f;
976111878
9762
- debugpoint2.radius = radius;
9763
- debugpoint2.recalculate();
9764
- debugpoint2.material = new cMaterial();
9765
- debugpoint2.material.color = 0.75f;
9766
- debugpoint2.material.modulation = 0.75f;
11879
+ debugpointP.radius = radius;
11880
+ debugpointP.recalculate();
11881
+ debugpointP.material = new cMaterial();
11882
+ debugpointP.material.color = 0.75f; // Purple
11883
+ debugpointP.material.modulation = 0.75f;
976711884
9768
- debugpoint3.radius = radius;
9769
- debugpoint3.recalculate();
9770
- debugpoint3.material = new cMaterial();
9771
- debugpoint3.material.color = 0.5f;
9772
- debugpoint3.material.modulation = 0.75f;
11885
+ debugpointC.radius = radius;
11886
+ debugpointC.recalculate();
11887
+ debugpointC.material = new cMaterial();
11888
+ debugpointC.material.color = 0.5f; // Cyan
11889
+ debugpointC.material.modulation = 0.75f;
977311890
9774
- debugpoint4.radius = radius;
9775
- debugpoint4.recalculate();
9776
- debugpoint4.material = new cMaterial();
9777
- debugpoint4.material.color = 0f;
9778
- debugpoint4.material.modulation = 0.75f;
11891
+ debugpointR.radius = radius;
11892
+ debugpointR.recalculate();
11893
+ debugpointR.material = new cMaterial();
11894
+ debugpointR.material.color = 0f; // Red
11895
+ debugpointR.material.modulation = 0.75f;
977911896
978011897 InitPoints(radius);
978111898 }
978211899 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9783
- debugpoint.draw(this, /*(Composite)*/ null, false,false);
9784
- debugpoint2.draw(this, /*(Composite)*/ null, false,false);
9785
- debugpoint3.draw(this, /*(Composite)*/ null, false,false);
9786
- debugpoint4.draw(this, /*(Composite)*/ null, false,false);
11900
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11901
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11902
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11903
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
978711904 // DrawPoints(this);
978811905 }
978911906
....@@ -9791,42 +11908,63 @@
979111908 }
979211909 // GrafreeD.traceoff();
979311910 //System.out.println(stackdepth);
9794
- if (drawMode == 0)
11911
+ if (DrawMode() == 0)
979511912 {
979611913 ReleaseTextures(DEFAULT_TEXTURES);
979711914
979811915 if (CLEANCACHE)
9799
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
980011917 {
9801
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
980211919
980311920 // System.out.println("Texture --------- " + tex);
980411921
9805
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
980611923 continue;
980711924
9808
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
980911926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
981011928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9811
- textures.get(tex).texture.dispose();
9812
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
981311942 }
981411943 }
981511944 }
981611945
981711946 checker = null;
981811947
9819
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11948
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
982011949 FindChecker(object);
982111950
9822
- if (checker != null && drawMode == DEFAULT)
11951
+ if (checker != null && DrawMode() == DEFAULT)
982311952 {
9824
- // BindTexture(IMMORTAL_TEXTURE);
11953
+ //BindTexture(IMMORTAL_TEXTURE);
11954
+ try
11955
+ {
11956
+ BindTextures(checker.GetTextures(), checker.texres);
11957
+ }
11958
+ catch (Exception e)
11959
+ {
11960
+ System.err.println("FAILED: " + checker.GetTextures());
11961
+ }
982511962 // NEAREST
982611963 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
982711964 DrawChecker(gl);
982811965 //checker.Draw(this, null, false);
982911966 // ReleaseTexture(IMMORTAL_TEXTURE);
11967
+ ReleaseTextures(checker.GetTextures());
983011968 }
983111969
983211970 if (object.parent != null)
....@@ -9839,7 +11977,7 @@
983911977 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
984011978 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
984111979
9842
- if (DISPLAYTEXT && drawMode == DEFAULT)
11980
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
984311981 {
984411982 // Draw it once, then use the raster
984511983 Balloon(gl, balloon.createGraphics());
....@@ -9895,14 +12033,14 @@
989512033 int[] xs = new int[3];
989612034 int[] ys = new int[3];
989712035
9898
- void DrawString(Object3D obj) // String string)
12036
+ public void DrawString(Object3D obj) // String string) // INTERFACE
989912037 {
9900
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12038
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
990112039 {
990212040 return;
990312041 }
990412042
9905
- String string = obj.GetToolTip();
12043
+ String string = obj.toString(); //.GetToolTip();
990612044
990712045 GL gl = GetGL();
990812046
....@@ -10219,8 +12357,8 @@
1021912357 //obj.TransformToWorld(light, light);
1022012358 for (int i = tp.size(); --i >= 0;)
1022112359 {
10222
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10223
- LA.xformPos(light, tp.get(i).toParent, light);
12360
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12361
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1022412362 }
1022512363
1022612364
....@@ -10237,8 +12375,8 @@
1023712375 parentcam = cameras[0];
1023812376 }
1023912377
10240
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10241
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12378
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12379
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1024212380
1024312381 LA.xformPos(light, renderCamera.toScreen, light);
1024412382
....@@ -10328,8 +12466,76 @@
1032812466
1032912467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1033012468
10331
- String program =
12469
+ String programmin =
12470
+ // Min shader
1033212471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1033312539 //"OPTION ARB_fragment_program_shadow;" +
1033412540 "PARAM light2cam0 = program.env[10];" +
1033512541 "PARAM light2cam1 = program.env[11];" +
....@@ -10357,11 +12563,13 @@
1035712563 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1035812564 "PARAM params7 = program.env[7];" + // noise power, opacity power
1035912565 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10360
- "PARAM options1 = program.env[62];" + // fog rgb color, image intensity
12566
+ "PARAM options1 = program.env[62];" + // fog rgb color
12567
+ "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
1036112568 "PARAM pointlight = program.env[127];" + // ...
1036212569 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1036312570 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1036412571 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12572
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1036512573 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1036612574 "PARAM ten = { 10, 10, 10, 1.0 };" +
1036712575 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10382,6 +12590,7 @@
1038212590 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1038312591 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1038412592 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12593
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1038512594 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1038612595 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1038712596 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10422,6 +12631,10 @@
1042212631 "TEMP R1;" +
1042312632 "TEMP R2;" +
1042412633 "TEMP R3;" +
12634
+ "TEMP min;" +
12635
+ "TEMP max;" +
12636
+ "TEMP average;" +
12637
+ "TEMP saturation;" +
1042512638 "TEMP keep1;" +
1042612639 "TEMP keep2;" +
1042712640 "TEMP keep3;" +
....@@ -10437,8 +12650,7 @@
1043712650 "TEMP shininess;" +
1043812651 "\n" +
1043912652 "MOV texSamp, one;" +
10440
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10441
-
12653
+
1044212654 "MOV mapgrid.x, one2048th.x;" +
1044312655 "MOV temp, fragment.texcoord[1];" +
1044412656 /*
....@@ -10459,20 +12671,20 @@
1045912671 "MUL temp, floor, mapgrid.x;" +
1046012672 //"TEX depth0, temp, texture[1], 2D;" +
1046112673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10462
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1046312675 "") +
1046412676 "ADD temp.x, temp.x, mapgrid.x;" +
1046512677 //"TEX depth1, temp, texture[1], 2D;" +
1046612678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10467
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1046812680 "") +
1046912681 "ADD temp.y, temp.y, mapgrid.x;" +
1047012682 //"TEX depth2, temp, texture[1], 2D;" +
10471
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1047212684 "SUB temp.x, temp.x, mapgrid.x;" +
1047312685 //"TEX depth3, temp, texture[1], 2D;" +
1047412686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10475
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1047612688 "") +
1047712689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1047812690 //"MOV params, material;" +
....@@ -10843,10 +13055,10 @@
1084313055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1084413056 "") +
1084513057
10846
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1084713059 "SUB temp.x, half.x, shadow.x;" +
10848
- "MOV temp.y, -params6.x;" +
10849
- "SLT temp.z, temp.y, zero.x;" +
13060
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1085013062 "SUB temp.y, one.x, temp.z;" +
1085113063 "MUL temp.x, temp.x, temp.y;" +
1085213064 "KIL temp.x;" +
....@@ -10952,10 +13164,42 @@
1095213164
1095313165 // skin?
1095413166 // Saturation for skin
10955
- /**/ // c'est ici
10956
- (Skinshader? "DP3 temp.x, final,one;" +
13167
+ /**/
13168
+ (Skinshader?
13169
+ "DP3 average.x, final,one;" +
13170
+ "MUL average, one3rd.xxxx,average.xxxx;" +
13171
+
13172
+ "MIN min.x, final.x,final.y;" +
13173
+ "MIN min.x, min.x,final.z;" +
13174
+
13175
+ "MAX max.x, final.x,final.y;" +
13176
+ "MAX max.x, max.x,final.z;" +
13177
+ "MOV max, max.xxxx;" +
13178
+
13179
+ "SUB saturation, max, final;" +
13180
+
13181
+ "ADD temp.x, max.x, one10th.x;" +
13182
+ "RCP temp.x, temp.x;" +
13183
+ "MUL temp.x, temp.x, half.x;" +
13184
+ "MUL saturation, saturation, temp.xxxx;" +
13185
+
13186
+ "DP3 ndotl.x, normald, light;" +
13187
+ "MAX ndotl.x, ndotl.x, -ndotl.x;" +
13188
+
13189
+ "SUB temp.x, one.x, ndotl.x;" +
13190
+ // Tuning for default skin
13191
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13192
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13193
+ "ADD temp.y, one.y, options2.y;" + // subsurface
13194
+ "MUL temp.x, temp.x, temp.y;" +
13195
+
13196
+ "MUL saturation, saturation, temp.xxxx;" +
13197
+ "SUB_SAT temp, max, saturation;" +
13198
+/**
13199
+ "DP3 temp.x, final,one;" +
1095713200 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10958
- "SUB temp, final,R2;" +
13201
+ "SUB temp, final, R2;" +
13202
+
1095913203 // using light angle
1096013204 "DP3 ndotl.x, normald,light;" +
1096113205 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10968,7 +13212,6 @@
1096813212 // using light intensity
1096913213 "MOV ndotl.z, R2.x;" +
1097013214 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10971
-
1097213215 // june 2014
1097313216 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1097413217 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10980,6 +13223,7 @@
1098013223 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1098113224
1098213225 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13226
+/**/
1098313227
1098413228 // "ADD final, R2,temp;" +
1098513229 "MOV final, temp;"
....@@ -11069,7 +13313,7 @@
1106913313 /**/
1107013314 // HDR
1107113315 "MOV temp.z, final.a;" +
11072
- "MUL final, final,options1.w;" +
13316
+ "MUL final, final,options2.x;" +
1107313317 "MOV final.a, temp.z;" +
1107413318 /**/
1107513319
....@@ -11145,7 +13389,14 @@
1114513389 //once = true;
1114613390 }
1114713391
11148
- System.out.print("Program #" + mode + "; length = " + program.length());
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
13399
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1114913400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1115013401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1115113402
....@@ -11238,30 +13489,32 @@
1123813489 return out;
1123913490 }
1124013491
11241
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1124213494 {
1124313495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1124413496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1124513497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1124613500 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11247
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11248
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11249
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11250
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1125113503 //"SWZ buffer, temp, w,w,w,w;";
11252
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1125313505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1125413506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1125513507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11256
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1125713509
11258
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11259
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1126013512 }
1126113513
1126213514 String Shadow(String depth, String shadow)
1126313515 {
1126413516 return "MAX temp.x, ndotl.x, one64th.x;" +
13517
+ "MIN temp.x, temp.x, ninetenth.x;" +
1126513518 /**/
1126613519 // Sine
1126713520 "MUL temp.y, temp.x, temp.x;" +
....@@ -11277,12 +13530,16 @@
1127713530
1127813531 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1127913532 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13533
+
13534
+ // Compare fragment depth in light space with shadowmap.
1128013535 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1128113536 "SGE temp.y, temp.x, zero.x;" +
11282
- "SUB " + shadow + ".y, one.x, temp.y;" +
13537
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13538
+
13539
+ // Reverse comparison
1128313540 "SUB temp.x, one.x, temp.x;" +
1128413541 "MUL " + shadow + ".x, temp.x, temp.y;" +
11285
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13542
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1128613543 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1128713544
1128813545 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11296,6 +13553,10 @@
1129613553 // No shadow for backface
1129713554 "DP3 temp.x, normal, lightd;" +
1129813555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13556
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13557
+
13558
+ // No shadow when out of frustum
13559
+ "SGE temp.x, " + depth + ".z, one.z;" +
1129913560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1130013561 "";
1130113562 }
....@@ -11442,7 +13703,8 @@
1144213703 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1144313704 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1144413705 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11445
- Object3D.cVector2[] vector2buffer;
13706
+
13707
+ //Object3D.cVector2[] vector2buffer;
1144613708
1144713709 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1144813710 // OUT : diff, spec
....@@ -11458,9 +13720,10 @@
1145813720 "DP3 " + dest + ".z," + "normals," + "eye;" +
1145913721 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1146013722 //"MOV " + dest + ".w," + "normal.z;" +
11461
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11462
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11463
- //"MOV " + dest + ".z," + "params2.w;" +
13723
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13724
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13725
+
13726
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1146413727 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1146513728 "RCP " + dest + ".w," + dest + ".w;" +
1146613729 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11854,7 +14117,7 @@
1185414117 public void mousePressed(MouseEvent e)
1185514118 {
1185614119 //System.out.println("mousePressed: " + e);
11857
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14120
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1185814121 }
1185914122
1186014123 static long prevtime = 0;
....@@ -11881,14 +14144,16 @@
1188114144
1188214145 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1188314146
14147
+ if (BUTTONLESSWHEEL)
1188414148 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1188514149 {
1188614150 return;
1188714151 }
1188814152
14153
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1188914154
1189014155 // TIMER
11891
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14156
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1189214157 {
1189314158 keepboxmode = BOXMODE;
1189414159 keepsupport = SUPPORT;
....@@ -11928,8 +14193,8 @@
1192814193 // mode |= META;
1192914194 //}
1193014195
11931
- SetMouseMode(WHEEL | e.getModifiersEx());
11932
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14196
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14197
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1193314198 anchorX = ax;
1193414199 anchorY = ay;
1193514200 prevX = px;
....@@ -11963,6 +14228,7 @@
1196314228 else
1196414229 if (evt.getSource() == AAtimer)
1196514230 {
14231
+ Globals.TIMERRUNNING = false;
1196614232 if (mouseDown)
1196714233 {
1196814234 //new Exception().printStackTrace();
....@@ -11988,6 +14254,10 @@
1198814254 // LIVE = waslive;
1198914255 // wasliveok = true;
1199014256 // waslive = false;
14257
+
14258
+ // May 2019 Forget it:
14259
+ if (true)
14260
+ return;
1199114261
1199214262 // source == timer
1199314263 if (mouseDown)
....@@ -12017,8 +14287,8 @@
1201714287 // ObjEditor.tweenManager.update(1f / 60f);
1201814288
1201914289 // fev 2014???
12020
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12021
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14290
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14291
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1202214292 pingthread.StepToTarget(true); // true);
1202314293 }
1202414294 // if (!LIVE)
....@@ -12027,12 +14297,13 @@
1202714297
1202814298 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1202914299
12030
- void clickStart(int x, int y, int modifiers)
14300
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1203114301 {
1203214302 if (!wasliveok)
1203314303 return;
1203414304
1203514305 AAtimer.restart(); //
14306
+ Globals.TIMERRUNNING = true;
1203614307
1203714308 // waslive = LIVE;
1203814309 // LIVE = false;
....@@ -12044,7 +14315,7 @@
1204414315 // touched = true; // main DL
1204514316 if (isRenderer)
1204614317 {
12047
- SetMouseMode(modifiers);
14318
+ SetMouseMode(modifiers, modifiersex);
1204814319 }
1204914320
1205014321 selectX = anchorX = x;
....@@ -12057,7 +14328,7 @@
1205714328 clicked = true;
1205814329 hold = false;
1205914330
12060
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14331
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1206114332 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1206214333 {
1206314334 // System.out.println("RESTART II " + modifiers);
....@@ -12082,14 +14353,15 @@
1208214353 drag = false;
1208314354 //System.out.println("Mouse DOWN");
1208414355 editObj = false;
12085
- ClickInfo info = new ClickInfo();
12086
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12087
- info.pane = this;
12088
- info.camera = renderCamera;
12089
- info.x = x;
12090
- info.y = y;
12091
- info.modifiers = modifiers;
12092
- editObj = object.doEditClick(info, 0);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1209314365 if (!editObj)
1209414366 {
1209514367 hasMarquee = true;
....@@ -12105,11 +14377,14 @@
1210514377
1210614378 public void mouseDragged(MouseEvent e)
1210714379 {
14380
+ Globals.MOUSEDRAGGED = true;
14381
+
14382
+ //System.out.println("mouseDragged: " + e);
1210814383 if (isRenderer)
1210914384 movingcamera = true;
14385
+
1211014386 //if (drawing)
1211114387 //return;
12112
- //System.out.println("mouseDragged: " + e);
1211314388 if ((e.getModifiersEx() & CTRL) != 0
1211414389 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1211514390 {
....@@ -12117,7 +14392,7 @@
1211714392 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1211814393 }
1211914394 else
12120
- drag(e.getX(), e.getY(), e.getModifiersEx());
14395
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1212114396
1212214397 //try { Thread.sleep(1); } catch (Exception ex) {}
1212314398 }
....@@ -12129,6 +14404,11 @@
1212914404 cVector tmp = new cVector();
1213014405 cVector tmp2 = new cVector();
1213114406 boolean isMoving;
14407
+
14408
+ public cVector TargetLookAt()
14409
+ {
14410
+ return targetLookAt;
14411
+ }
1213214412
1213314413 class PingThread extends Thread
1213414414 {
....@@ -12268,7 +14548,7 @@
1226814548 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1226914549 if (lightMode)
1227014550 {
12271
- lighttouched = true;
14551
+ Globals.lighttouched = true;
1227214552 }
1227314553
1227414554 if (OEILONCE && OEIL)
....@@ -12285,6 +14565,7 @@
1228514565
1228614566 public void run()
1228714567 {
14568
+ new Exception().printStackTrace();
1228814569 System.exit(0);
1228914570 for (;;)
1229014571 {
....@@ -12326,7 +14607,7 @@
1232614607 mouseDown = false;
1232714608 if (lightMode)
1232814609 {
12329
- lighttouched = true;
14610
+ Globals.lighttouched = true;
1233014611 }
1233114612 repaint();
1233214613 alreadypainted = true;
....@@ -12334,7 +14615,7 @@
1233414615 isMoving = false;
1233514616 } //??
1233614617
12337
- if (isLIVE() && !alreadypainted)
14618
+ if (Globals.isLIVE() && !alreadypainted)
1233814619 {
1233914620 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1234014621 repaint();
....@@ -12346,9 +14627,9 @@
1234614627 {
1234714628 if (lightMode)
1234814629 {
12349
- lighttouched = true;
14630
+ Globals.lighttouched = true;
1235014631 }
12351
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14632
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1235214633 }
1235314634 //else
1235414635 }
....@@ -12362,12 +14643,12 @@
1236214643 void GoDown(int mod)
1236314644 {
1236414645 MODIFIERS |= COMMAND;
12365
- /*
14646
+ /**/
1236614647 if((mod&SHIFT) == SHIFT)
12367
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1236814649 else
12369
- manipCamera.BackForth(0, -speed*delta, getWidth());
12370
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1237114652 if ((mod & SHIFT) == SHIFT)
1237214653 {
1237314654 mouseMode = mouseMode; // VR??
....@@ -12383,12 +14664,12 @@
1238314664 void GoUp(int mod)
1238414665 {
1238514666 MODIFIERS |= COMMAND;
12386
- /*
14667
+ /**/
1238714668 if((mod&SHIFT) == SHIFT)
12388
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1238914670 else
12390
- manipCamera.BackForth(0, speed*delta, getWidth());
12391
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1239214673 if ((mod & SHIFT) == SHIFT)
1239314674 {
1239414675 mouseMode = mouseMode;
....@@ -12404,12 +14685,12 @@
1240414685 void GoLeft(int mod)
1240514686 {
1240614687 MODIFIERS |= COMMAND;
12407
- /*
14688
+ /**/
1240814689 if((mod&SHIFT) == SHIFT)
12409
- manipCamera.RotatePosition(speed, 0);
12410
- else
1241114690 manipCamera.Translate(speed*delta, 0, getWidth());
12412
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1241314694 if ((mod & SHIFT) == SHIFT)
1241414695 {
1241514696 mouseMode = mouseMode;
....@@ -12425,12 +14706,12 @@
1242514706 void GoRight(int mod)
1242614707 {
1242714708 MODIFIERS |= COMMAND;
12428
- /*
14709
+ /**/
1242914710 if((mod&SHIFT) == SHIFT)
12430
- manipCamera.RotatePosition(-speed, 0);
12431
- else
1243214711 manipCamera.Translate(-speed*delta, 0, getWidth());
12433
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1243414715 if ((mod & SHIFT) == SHIFT)
1243514716 {
1243614717 mouseMode = mouseMode;
....@@ -12448,7 +14729,7 @@
1244814729 int X, Y;
1244914730 boolean SX, SY;
1245014731
12451
- void drag(int x, int y, int modifiers)
14732
+ void drag(int x, int y, int modifiers, int modifiersex)
1245214733 {
1245314734 if (IsFrozen())
1245414735 {
....@@ -12457,17 +14738,17 @@
1245714738
1245814739 drag = true; // NEW
1245914740
12460
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14741
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1246114742
1246214743 X = x;
1246314744 Y = y;
1246414745 // floating state for animation
12465
- MODIFIERS = modifiers;
12466
- modifiers &= ~1024;
14746
+ MODIFIERS = modifiersex;
14747
+ modifiersex &= ~1024;
1246714748 if (false) // modifiers != 0)
1246814749 {
1246914750 //new Exception().printStackTrace();
12470
- System.out.println("mouseDragged: " + modifiers);
14751
+ System.out.println("mouseDragged: " + modifiersex);
1247114752 System.out.println("SHIFT = " + SHIFT);
1247214753 System.out.println("CONTROL = " + COMMAND);
1247314754 System.out.println("META = " + META);
....@@ -12480,14 +14761,16 @@
1248014761 if (editObj)
1248114762 {
1248214763 drag = true;
12483
- ClickInfo info = new ClickInfo();
12484
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1248514766 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12486
- info.pane = this;
12487
- info.camera = renderCamera;
12488
- info.x = x;
12489
- info.y = y;
12490
- object.editWindow.copy.doEditDrag(info);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1249114774 } else
1249214775 {
1249314776 if (x < startX)
....@@ -12589,6 +14872,7 @@
1258914872 {
1259014873 manipCamera.Translate(dx, dy, getWidth());
1259114874 }
14875
+ else
1259214876 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1259314877 {
1259414878 manipCamera.RotateInterest(dx, dy);
....@@ -12599,7 +14883,7 @@
1259914883
1260014884 if (manipCamera == lightCamera)
1260114885 {
12602
- lighttouched = true;
14886
+ Globals.lighttouched = true;
1260314887 }
1260414888 /*
1260514889 switch (mode)
....@@ -12635,23 +14919,27 @@
1263514919 }
1263614920 }
1263714921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1263814924 public void mouseMoved(MouseEvent e)
1263914925 {
1264014926 //System.out.println("mouseMoved: " + e);
12641
-
1264214927 if (isRenderer)
1264314928 return;
1264414929
12645
- ClickInfo ci = new ClickInfo();
12646
- ci.x = e.getX();
12647
- ci.y = e.getY();
12648
- ci.modifiers = e.getModifiersEx();
12649
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12650
- ci.pane = this;
12651
- ci.camera = renderCamera;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1265214937 if (!isRenderer)
1265314938 {
12654
- if (object.editWindow.copy.doEditClick(ci, 0))
14939
+ //ObjEditor editWindow = object.editWindow;
14940
+ //Object3D copy = editWindow.copy;
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1265514943 {
1265614944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1265714945 } else
....@@ -12663,7 +14951,11 @@
1266314951
1266414952 public void mouseReleased(MouseEvent e)
1266514953 {
14954
+ Globals.MOUSEDRAGGED = false;
14955
+
1266614956 movingcamera = false;
14957
+ X = 0; // getBounds().width/2;
14958
+ Y = 0; // getBounds().height/2;
1266714959 //System.out.println("mouseReleased: " + e);
1266814960 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1266914961 }
....@@ -12686,9 +14978,9 @@
1268614978 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1268714979 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1268814980
12689
- if (control || command || IsFrozen())
14981
+// No delay if (control || command || IsFrozen())
1269014982 timeout = true;
12691
- else
14983
+// ?? May 2019 else
1269214984 // timer.setDelay((modifiers & 128) != 0?0:350);
1269314985 mouseDown = false;
1269414986 if (!control && !command) // june 2013
....@@ -12798,7 +15090,7 @@
1279815090 System.out.println("keyReleased: " + e);
1279915091 }
1280015092
12801
- void SetMouseMode(int modifiers)
15093
+ void SetMouseMode(int modifiers, int modifiersex)
1280215094 {
1280315095 //System.out.println("SetMouseMode = " + modifiers);
1280415096 //modifiers &= ~1024;
....@@ -12810,24 +15102,27 @@
1281015102 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1281115103 // return;
1281215104 //System.out.println("SetMode = " + modifiers);
12813
- if ((modifiers & WHEEL) == WHEEL)
15105
+ if ((modifiersex & WHEEL) == WHEEL)
1281415106 {
1281515107 mouseMode |= ZOOM;
1281615108 }
12817
- if ((modifiers & META) == META)
15109
+
15110
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15111
+ if (capsLocked) // || (modifiers & META) == META)
1281815112 {
1281915113 mouseMode |= VR; // BACKFORTH;
1282015114 }
12821
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12822
- {
12823
- mouseMode |= SELECT; // BACKFORTH;
12824
- }
12825
- if ((modifiers & COMMAND) == COMMAND)
15115
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1282615116 {
1282715117 mouseMode |= SELECT;
1282815118 }
12829
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15119
+ if ((modifiersex & COMMAND) == COMMAND)
1283015120 {
15121
+ mouseMode |= SELECT;
15122
+ }
15123
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15124
+ {
15125
+ mouseMode &= ~VR;
1283115126 mouseMode |= TRANSLATE;
1283215127 }
1283315128 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12854,10 +15149,10 @@
1285415149
1285515150 if (isRenderer) //
1285615151 {
12857
- SetMouseMode(modifiers);
15152
+ SetMouseMode(0, modifiers);
1285815153 }
1285915154
12860
- theRenderer.keyPressed(key);
15155
+ Globals.theRenderer.keyPressed(key);
1286115156 }
1286215157
1286315158 int kompactbit = 4; // power bit
....@@ -12869,7 +15164,7 @@
1286915164 float SATPOW = 1; // 2; // 0.5f;
1287015165 float BRIPOW = 1; // 0.5f; // 0.5f;
1287115166
12872
- void keyPressed(int key)
15167
+ public void keyPressed(int key)
1287315168 {
1287415169 if (key >= '0' && key <= '5')
1287515170 clampbit = (key-'0');
....@@ -12916,7 +15211,8 @@
1291615211 // break;
1291715212 case 'T':
1291815213 CACHETEXTURE ^= true;
12919
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1292015216 // repaint();
1292115217 break;
1292215218 case 'Y':
....@@ -12984,7 +15280,7 @@
1298415280 case 'B':
1298515281 BRISMOOTH ^= true;
1298615282 SHADOWCULLFACE ^= true;
12987
- lighttouched = true;
15283
+ Globals.lighttouched = true;
1298815284 repaint();
1298915285 break;
1299015286 case 'b':
....@@ -13001,7 +15297,9 @@
1300115297 case 'E' : COMPACT ^= true;
1300215298 repaint();
1300315299 break;
13004
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1300515303 repaint();
1300615304 break;
1300715305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13026,8 +15324,8 @@
1302615324 RevertCamera();
1302715325 repaint();
1302815326 break;
13029
- case 'L':
1303015327 case 'l':
15328
+ //case 'L':
1303115329 if (lightMode)
1303215330 {
1303315331 lightMode = false;
....@@ -13084,27 +15382,31 @@
1308415382 repaint();
1308515383 break;
1308615384 case 'O':
13087
- drawMode = OCCLUSION;
15385
+ Globals.drawMode = OCCLUSION; // WARNING
1308815386 repaint();
1308915387 break;
1309015388 case 'o':
1309115389 OCCLUSION_CULLING ^= true;
1309215390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1309315391 break;
13094
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1309515393 case '1':
1309615394 case '2':
1309715395 case '3':
1309815396 case '4':
1309915397 case '5':
13100
- newenvy = Character.getNumericValue(key);
13101
- repaint();
13102
- break;
1310315398 case '6':
1310415399 case '7':
1310515400 case '8':
1310615401 case '9':
13107
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1310815410 repaint();
1310915411 break;
1311015412 case '!':
....@@ -13170,12 +15472,12 @@
1317015472 case '_':
1317115473 kompactbit = 5;
1317215474 break;
13173
- case '+':
13174
- kompactbit = 6;
13175
- break;
15475
+// case '+':
15476
+// kompactbit = 6;
15477
+// break;
1317615478 case ' ':
1317715479 lightMode ^= true;
13178
- lighttouched = true;
15480
+ Globals.lighttouched = true;
1317915481 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1318015482 targetLookAt.set(manipCamera.lookAt);
1318115483 repaint();
....@@ -13184,14 +15486,15 @@
1318415486 case ESC:
1318515487 RENDERPROGRAM += 1;
1318615488 RENDERPROGRAM %= 3;
15489
+
1318715490 repaint();
1318815491 break;
1318915492 case 'Z':
13190
- RESIZETEXTURE ^= true;
13191
- break;
15493
+ //RESIZETEXTURE ^= true;
15494
+ //break;
1319215495 case 'z':
13193
- RENDERSHADOW ^= true;
13194
- lighttouched = true;
15496
+ Globals.RENDERSHADOW ^= true;
15497
+ Globals.lighttouched = true;
1319515498 repaint();
1319615499 break;
1319715500 //case UP:
....@@ -13217,13 +15520,15 @@
1321715520 FlipTransform();
1321815521 break;
1321915522 case ENTER:
13220
- object.editWindow.ScreenFit(); // Edit();
15523
+ // object.editWindow.ScreenFit(); // Edit();
15524
+ ToggleLive();
1322115525 break;
1322215526 case DELETE:
1322315527 ClearSelection();
1322415528 break;
13225
- /*
1322615529 case '+':
15530
+
15531
+ /*
1322715532 //fontsize += 1;
1322815533 bbzoom *= 2;
1322915534 repaint();
....@@ -13240,17 +15545,17 @@
1324015545 case '=':
1324115546 IncDepth();
1324215547 //fontsize += 1;
13243
- object.editWindow.refreshContents(true);
15548
+ object.GetWindow().refreshContents(true);
1324415549 maskbit = 6;
1324515550 break;
1324615551 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1324715552 DecDepth();
1324815553 maskbit = 5;
1324915554 //if(fontsize > 1) fontsize -= 1;
13250
- if (object.editWindow == null)
13251
- new Exception().printStackTrace();
13252
- else
13253
- object.editWindow.refreshContents(true);
15555
+// if (object.editWindow == null)
15556
+// new Exception().printStackTrace();
15557
+// else
15558
+ object.GetWindow().refreshContents(true);
1325415559 break;
1325515560 case '{':
1325615561 manipCamera.shaper_fovy /= 1.1;
....@@ -13305,6 +15610,7 @@
1330515610 }
1330615611 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1330715612 }
15613
+
1330815614 static double OCCLUSIONBOOST = 1; // 0.5;
1330915615
1331015616 void keyReleased(int key, int modifiers)
....@@ -13312,11 +15618,11 @@
1331215618 //mode = ROTATE;
1331315619 if ((MODIFIERS & COMMAND) == 0) // VR??
1331415620 {
13315
- SetMouseMode(modifiers);
15621
+ SetMouseMode(0, modifiers);
1331615622 }
1331715623 }
1331815624
13319
- protected void processKeyEvent(KeyEvent e)
15625
+ public void processKeyEvent(KeyEvent e)
1332015626 {
1332115627 switch (e.getID())
1332215628 {
....@@ -13446,8 +15752,9 @@
1344615752
1344715753 protected void processMouseMotionEvent(MouseEvent e)
1344815754 {
13449
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13450
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15755
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15756
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15757
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1345115758 {
1345215759 mouseMoved(e);
1345315760 } else
....@@ -13472,11 +15779,12 @@
1347215779 }
1347315780 */
1347415781
13475
- object.editWindow.EditSelection();
15782
+ object.GetWindow().EditSelection(false);
1347615783 }
1347715784
1347815785 void SelectParent()
1347915786 {
15787
+ new Exception().printStackTrace();
1348015788 System.exit(0);
1348115789 Composite group = (Composite) object;
1348215790 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13488,10 +15796,10 @@
1348815796 {
1348915797 //selectees.remove(i);
1349015798 System.out.println("select parent of " + elem);
13491
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1349215800 } else
1349315801 {
13494
- group.editWindow.Select(elem.GetTreePath(), first, true);
15802
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1349515803 }
1349615804
1349715805 first = false;
....@@ -13500,6 +15808,7 @@
1350015808
1350115809 void SelectChildren()
1350215810 {
15811
+ new Exception().printStackTrace();
1350315812 System.exit(0);
1350415813 /*
1350515814 Composite group = (Composite) object;
....@@ -13532,12 +15841,12 @@
1353215841 for (int j = 0; j < group.children.size(); j++)
1353315842 {
1353415843 elem = (Object3D) group.children.elementAt(j);
13535
- object.editWindow.Select(elem.GetTreePath(), first, true);
15844
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1353615845 first = false;
1353715846 }
1353815847 } else
1353915848 {
13540
- object.editWindow.Select(elem.GetTreePath(), first, true);
15849
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1354115850 }
1354215851
1354315852 first = false;
....@@ -13548,21 +15857,21 @@
1354815857 {
1354915858 //Composite group = (Composite) object;
1355015859 Object3D group = object;
13551
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15860
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1355215861 }
1355315862
1355415863 void ResetTransform(int mask)
1355515864 {
1355615865 //Composite group = (Composite) object;
1355715866 Object3D group = object;
13558
- group.editWindow.ResetTransform(mask);
15867
+ group.GetWindow().ResetTransform(mask);
1355915868 }
1356015869
1356115870 void FlipTransform()
1356215871 {
1356315872 //Composite group = (Composite) object;
1356415873 Object3D group = object;
13565
- group.editWindow.FlipTransform();
15874
+ group.GetWindow().FlipTransform();
1356615875 // group.editWindow.ReduceMesh(true);
1356715876 }
1356815877
....@@ -13570,7 +15879,7 @@
1357015879 {
1357115880 //Composite group = (Composite) object;
1357215881 Object3D group = object;
13573
- group.editWindow.PrintMemory();
15882
+ group.GetWindow().PrintMemory();
1357415883 // group.editWindow.ReduceMesh(true);
1357515884 }
1357615885
....@@ -13578,7 +15887,7 @@
1357815887 {
1357915888 //Composite group = (Composite) object;
1358015889 Object3D group = object;
13581
- group.editWindow.ResetCentroid();
15890
+ group.GetWindow().ResetCentroid();
1358215891 }
1358315892
1358415893 void IncDepth()
....@@ -13660,11 +15969,11 @@
1366015969
1366115970 int width = getBounds().width;
1366215971 int height = getBounds().height;
13663
- ClickInfo info = new ClickInfo();
13664
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1366515972 //Image img = CreateImage(width, height);
1366615973 //System.out.println("width = " + width + "; height = " + height + "\n");
15974
+
1366715975 Graphics gr = g; // img.getGraphics();
15976
+
1366815977 if (!hasMarquee)
1366915978 {
1367015979 if (Xmin < Xmax) // !locked)
....@@ -13736,40 +16045,88 @@
1373616045 }
1373716046 if (object != null && !hasMarquee)
1373816047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1373916054 if (isRenderer)
1374016055 {
13741
- info.flags++;
16056
+ object.clickInfo.flags++;
1374216057 double frameAspect = (double) width / (double) height;
1374316058 if (frameAspect > renderCamera.aspect)
1374416059 {
1374516060 int desired = (int) ((double) height * renderCamera.aspect);
13746
- info.bounds.width -= width - desired;
13747
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1374816063 } else
1374916064 {
1375016065 int desired = (int) ((double) width / renderCamera.aspect);
13751
- info.bounds.height -= height - desired;
13752
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1375316068 }
1375416069 }
13755
- info.g = gr;
13756
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1375716073 /*
1375816074 // Memory intensive (brep.verticescopy)
1375916075 if (!(object instanceof Composite))
1376016076 object.draw(info, 0, false); // SLOW :
1376116077 */
13762
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1376316079 {
13764
- object.drawEditHandles(info, 0);
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
16082
+ if (object.selection.Size() > 0)
16083
+ {
16084
+ int hitSomething = object.selection.get(0).hitSomething;
16085
+
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
16089
+ if (hitSomething == Object3D.hitCenter)
16090
+ {
16091
+ info.DX = X;
16092
+ if (X != 0)
16093
+ info.DX -= info.bounds.width/2;
16094
+
16095
+ info.DY = Y;
16096
+ if (Y != 0)
16097
+ info.DY -= info.bounds.height/2;
16098
+ }
16099
+
16100
+ object.drawEditHandles(//info,
16101
+ 0);
16102
+
16103
+ if (drag && (X != 0 || Y != 0))
16104
+ {
16105
+ switch (hitSomething)
16106
+ {
16107
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16114
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16115
+ break;
16116
+ }
16117
+
16118
+ }
16119
+ }
1376516120 }
1376616121 }
16122
+
1376716123 if (isRenderer)
1376816124 {
1376916125 //gr.setColor(Color.black);
1377016126 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1377116127 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1377216128 }
16129
+
1377316130 if (hasMarquee)
1377416131 {
1377516132 gr.setXORMode(Color.white);
....@@ -13792,6 +16149,7 @@
1379216149 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1379316150 }
1379416151
16152
+ // To avoid clear.
1379516153 public void update(Graphics g)
1379616154 {
1379716155 paint(g);
....@@ -13881,6 +16239,7 @@
1388116239 public boolean mouseDown(Event evt, int x, int y)
1388216240 {
1388316241 System.out.println("mouseDown: " + evt);
16242
+ System.exit(0);
1388416243 /*
1388516244 locked = true;
1388616245 drag = false;
....@@ -13924,7 +16283,7 @@
1392416283 {
1392516284 keyPressed(0, modifiers);
1392616285 }
13927
- clickStart(x, y, modifiers);
16286
+ // clickStart(x, y, modifiers);
1392816287 return true;
1392916288 }
1393016289
....@@ -14042,7 +16401,7 @@
1404216401 {
1404316402 keyReleased(0, 0);
1404416403 }
14045
- drag(x, y, modifiers);
16404
+ drag(x, y, 0, modifiers);
1404616405 return true;
1404716406 }
1404816407
....@@ -14174,7 +16533,7 @@
1417416533 Object3D object;
1417516534 static Object3D trackedobject;
1417616535 Camera renderCamera; // Light or Eye (or Occlusion)
14177
- /*static*/ Camera manipCamera; // Light or Eye
16536
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1417816537 /*static*/ Camera eyeCamera;
1417916538 /*static*/ Camera lightCamera;
1418016539 int cameracount;
....@@ -14238,6 +16597,8 @@
1423816597 private /*static*/ boolean firstime;
1423916598 private /*static*/ cVector newView = new cVector();
1424016599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1424116602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1424216603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1424316604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14250,29 +16611,67 @@
1425016611 {
1425116612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1425216613
16614
+ int usedsuf = 0;
16615
+
1425316616 for (int i = 0; i < suffixes.length; i++)
1425416617 {
14255
- String resourceName = basename + suffixes[i] + "." + suffix;
14256
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14257
- mipmapped,
14258
- FileUtil.getFileSuffix(resourceName));
14259
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1426016623 {
14261
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1426216628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1426316657 //System.out.println("Target = " + targets[i]);
1426416658 cubemap.updateImage(data, targets[i]);
1426516659 }
1426616660
1426716661 return cubemap;
1426816662 }
16663
+
1426916664 int bigsphere = -1;
1427016665
1427116666 float BGcolor = 0.5f;
1427216667
14273
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1427416671 {
14275
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1427616675 {
1427716676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1427816677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14287,7 +16686,17 @@
1428716686 // Compensates for ExaminerViewer's modification of modelview matrix
1428816687 gl.glMatrixMode(GL.GL_MODELVIEW);
1428916688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1429016690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1429116700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1429216701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1429316702
....@@ -14319,6 +16728,7 @@
1431916728 {
1432016729 gl.glScalef(1.0f, -1.0f, 1.0f);
1432116730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1432216732 gl.glMultMatrixd(viewrot_1, 0);
1432316733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1432416734 //viewer.updateInverseRotation(gl);
....@@ -14394,7 +16804,7 @@
1439416804 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1439516805 gl.glPushMatrix();
1439616806 gl.glLoadIdentity();
14397
- PushMatrix(checker.toParent);
16807
+ //PushMatrix(checker.toParent);
1439816808
1439916809 gl.glMatrixMode(GL.GL_TEXTURE);
1440016810 gl.glPushMatrix();
....@@ -14417,8 +16827,8 @@
1441716827
1441816828 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1441916829
14420
- float step = 0.1666f; //0.25f;
14421
- float stepv = step * 1652 / 998;
16830
+ float step = 2; // 0.1666f; //0.25f;
16831
+ float stepv = 2; // step * 1652 / 998;
1442216832
1442316833 int i0 = 0;
1442416834 /*
....@@ -14454,20 +16864,21 @@
1445416864 /**/
1445516865 //checker.GetMaterial().opacity = 1.1f;
1445616866 ////checker.GetMaterial().ambient = 0.99f;
14457
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14458
- Object3D.selectedstack[Object3D.materialdepth] = false;
14459
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16867
+ materialstack[materialdepth] = checker.material;
16868
+ selectedstack[materialdepth] = false;
16869
+ cStatic.objectstack[materialdepth++] = checker;
1446016870 //System.out.println("material " + material);
1446116871 //Applet3D.tracein(this, selected);
14462
- vector2buffer = checker.projectedVertices;
16872
+ //vector2buffer = checker.projectedVertices;
1446316873
14464
- checker.GetMaterial().Draw(this, false); // true);
16874
+ //checker.GetMaterial().Draw(this, false); // true);
16875
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1446516876
14466
- Object3D.materialdepth -= 1;
14467
- if (Object3D.materialdepth > 0)
16877
+ materialdepth -= 1;
16878
+ if (materialdepth > 0)
1446816879 {
14469
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14470
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16880
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16881
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1447116882 }
1447216883 //checker.GetMaterial().opacity = 1f;
1447316884 ////checker.GetMaterial().ambient = 1f;
....@@ -14488,15 +16899,27 @@
1448816899
1448916900 //float u = (i+1)/2;
1449016901 //float v = (j+1)/2;
14491
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16902
+ if (checker.flipV)
16903
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16904
+ else
16905
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1449216906 gl.glVertex3f(i, j, -0.5f);
1449316907
16908
+ if (checker.flipV)
16909
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16910
+ else
1449416911 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1449516912 gl.glVertex3f(i + step, j, -0.5f);
1449616913
16914
+ if (checker.flipV)
16915
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16916
+ else
1449716917 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1449816918 gl.glVertex3f(i + step, j + stepv, -0.5f);
1449916919
16920
+ if (checker.flipV)
16921
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16922
+ else
1450016923 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1450116924 gl.glVertex3f(i, j + stepv, -0.5f);
1450216925 }
....@@ -14508,7 +16931,7 @@
1450816931 gl.glMatrixMode(GL.GL_PROJECTION);
1450916932 gl.glPopMatrix();
1451016933 gl.glMatrixMode(GL.GL_MODELVIEW);
14511
- PopMatrix(null); // checker.toParent); // null);
16934
+ //PopMatrix(null); // checker.toParent); // null);
1451216935 gl.glPopMatrix();
1451316936 PopTextureMatrix(checker.toParent);
1451416937 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14541,6 +16964,14 @@
1454116964 }
1454216965 }
1454316966
16967
+ private Object3D GetFolder()
16968
+ {
16969
+ Object3D folder = object.GetWindow().copy;
16970
+ if (object.GetWindow().copy.selection.Size() > 0)
16971
+ folder = object.GetWindow().copy.selection.elementAt(0);
16972
+ return folder;
16973
+ }
16974
+
1454416975 class SelectBuffer implements GLEventListener
1454516976 {
1454616977
....@@ -14556,7 +16987,7 @@
1455616987 //new Exception().printStackTrace();
1455716988 System.out.println("select buffer init");
1455816989 // Use debug pipeline
14559
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1456016991
1456116992 GL gl = drawable.getGL();
1456216993
....@@ -14599,6 +17030,7 @@
1459917030 {
1460017031 if (!selection)
1460117032 {
17033
+ new Exception().printStackTrace();
1460217034 System.exit(0);
1460317035 return;
1460417036 }
....@@ -14619,17 +17051,39 @@
1461917051
1462017052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1462117053
17054
+ if (PAINTMODE)
17055
+ {
17056
+ if (object.GetWindow().copy.selection.Size() > 0)
17057
+ {
17058
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17059
+
17060
+ // Make what you paint not selectable.
17061
+ paintobj.ResetSelectable();
17062
+ }
17063
+ }
17064
+
1462217065 //int tmp = selection_view;
1462317066 //selection_view = -1;
14624
- int temp = drawMode;
14625
- drawMode = SELECTION;
17067
+ int temp = DrawMode();
17068
+ Globals.drawMode = SELECTION; // WARNING
1462617069 indexcount = 0;
1462717070 parent.display(drawable);
1462817071 //selection_view = tmp;
1462917072 //if (temp == SELECTION)
1463017073 // temp = DEFAULT; // patch for selection debug
14631
- drawMode = temp;
17074
+ Globals.drawMode = temp; // WARNING
1463217075
17076
+ if (PAINTMODE)
17077
+ {
17078
+ if (object.GetWindow().copy.selection.Size() > 0)
17079
+ {
17080
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17081
+
17082
+ // Revert.
17083
+ paintobj.RestoreSelectable();
17084
+ }
17085
+ }
17086
+
1463317087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1463417088
1463517089 // trying different ways of getting the depth info over
....@@ -14678,6 +17132,13 @@
1467817132 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1467917133 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1468017134
17135
+ CreateSelectedPoint();
17136
+
17137
+ // Will fit the mesh !!!
17138
+ selectedpoint.toParent[0][0] = 0.0001;
17139
+ selectedpoint.toParent[1][1] = 0.0001;
17140
+ selectedpoint.toParent[2][2] = 0.0001;
17141
+
1468117142 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1468217143
1468317144 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14721,34 +17182,36 @@
1472117182 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]));
1472217183 }
1472317184
14724
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17185
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1472517186 }
1472617187 }
1472717188
1472817189 if (!movingcamera && !PAINTMODE)
14729
- object.editWindow.ScreenFitPoint(); // fev 2014
17190
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1473017191
14731
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17192
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1473217193 {
14733
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17194
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1473417195
14735
- Object3D group = new Object3D("inst" + paintcount++);
17196
+ if (object.GetWindow().copy.selection.Size() > 0)
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1473617199
14737
- group.CreateMaterial(); // use a void leaf to select instances
14738
-
14739
- group.add(paintobj); // link
14740
-
14741
- object.editWindow.SnapObject(group);
14742
-
14743
- Object3D folder = object.editWindow.copy;
14744
-
14745
- if (object.editWindow.copy.selection.Size() > 0)
14746
- folder = object.editWindow.copy.selection.elementAt(0);
14747
-
14748
- folder.add(group);
14749
-
14750
- object.editWindow.ResetModel();
14751
- object.editWindow.refreshContents();
17200
+ Object3D inst = new Object3D("inst" + paintcount++);
17201
+
17202
+ inst.CreateMaterial(); // use a void leaf to select instances
17203
+
17204
+ inst.add(paintobj); // link
17205
+
17206
+ object.GetWindow().SnapObject(inst);
17207
+
17208
+ Object3D folder = paintFolder; // GetFolder();
17209
+
17210
+ folder.add(inst);
17211
+
17212
+ object.GetWindow().ResetModel();
17213
+ object.GetWindow().refreshContents();
17214
+ }
1475217215 }
1475317216 else
1475417217 paintcount = 0;
....@@ -14787,6 +17250,11 @@
1478717250 //System.out.println("objects[color] = " + objects[color]);
1478817251 //objects[color].Select();
1478917252 indexcount = 0;
17253
+ ObjEditor window = object.GetWindow();
17254
+ if (window != null && deselect)
17255
+ {
17256
+ window.Select(null, deselect, true);
17257
+ }
1479017258 object.Select(color, deselect);
1479117259 }
1479217260
....@@ -14886,7 +17354,7 @@
1488617354 gl.glDisable(gl.GL_CULL_FACE);
1488717355 }
1488817356
14889
- if (!RENDERSHADOW)
17357
+ if (!Globals.RENDERSHADOW)
1489017358 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1489117359
1489217360 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14896,14 +17364,14 @@
1489617364 //gl.glColorMask(false, false, false, false);
1489717365
1489817366 //render_scene_from_light_view(gl, drawable, 0, 0);
14899
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17367
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1490017368 {
1490117369 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1490217370
14903
- int temp = drawMode;
14904
- drawMode = SHADOW;
17371
+ int temp = DrawMode();
17372
+ Globals.drawMode = SHADOW; // WARNING
1490517373 parent.display(drawable);
14906
- drawMode = temp;
17374
+ Globals.drawMode = temp; // WARNING
1490717375 }
1490817376
1490917377 gl.glCullFace(gl.GL_BACK);
....@@ -14956,7 +17424,6 @@
1495617424
1495717425 class AntialiasBuffer implements GLEventListener
1495817426 {
14959
-
1496017427 CameraPane parent = null;
1496117428
1496217429 AntialiasBuffer(CameraPane p)
....@@ -15066,13 +17533,19 @@
1506617533 gl.glFlush();
1506717534
1506817535 /**/
15069
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17536
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
1507017537
15071
- int[] pixels = occlusionsizebuffer.array();
17538
+ float[] pixels = occlusionsizebuffer.array();
1507217539
1507317540 double r = 0, g = 0, b = 0;
1507417541
1507517542 double count = 0;
17543
+
17544
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17545
+
17546
+ float mindepth = 1;
17547
+
17548
+ double FACTOR = 1;
1507617549
1507717550 for (int i = 0; i < pixels.length; i++)
1507817551 {
....@@ -15157,7 +17630,7 @@
1515717630
1515817631 double scale = ray.z; // 1; // cos
1515917632
15160
- int p = pixels[newindex];
17633
+ float depth = pixels[newindex];
1516117634
1516217635 /*
1516317636 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15181,10 +17654,23 @@
1518117654 scale = (1 - modu) * modv;
1518217655 */
1518317656
15184
- r += ((p >> 16) & 0xFF) * scale / 255;
15185
- g += ((p >> 8) & 0xFF) * scale / 255;
15186
- b += (p & 0xFF) * scale / 255;
17657
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17658
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17659
+ //b += (p & 0xFF) * scale / 255;
17660
+
17661
+ if (mindepth > depth)
17662
+ {
17663
+ mindepth = depth;
17664
+ }
1518717665
17666
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17667
+
17668
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17669
+
17670
+ r += factor * scale;
17671
+ g += factor * scale;
17672
+ b += factor * scale;
17673
+
1518817674 count += scale;
1518917675 }
1519017676
....@@ -15282,12 +17768,6 @@
1528217768 GLUT glut = new GLUT();
1528317769
1528417770
15285
- static final public int DEFAULT = 0;
15286
- static final public int SELECTION = 1;
15287
- static final public int SHADOW = 2;
15288
- static final public int OCCLUSION = 3;
15289
- static
15290
- public int drawMode = DEFAULT;
1529117771 public boolean spherical = false;
1529217772 static boolean DEBUG_OCCLUSION = false;
1529317773 static boolean DEBUG_SELECTION = false;
....@@ -15300,23 +17780,15 @@
1530017780 int AAbuffersize = 0;
1530117781
1530217782 //double[] selectedpoint = new double[3];
15303
- static Sphere selectedpoint = new Sphere();
17783
+ static Superellipsoid selectedpoint;
1530417784 static Sphere previousselectedpoint = null;
15305
- static Sphere debugpoint = new Sphere();
15306
- static Sphere debugpoint2 = new Sphere();
15307
- static Sphere debugpoint3 = new Sphere();
15308
- static Sphere debugpoint4 = new Sphere();
17785
+ static Sphere debugpointG;
17786
+ static Sphere debugpointP;
17787
+ static Sphere debugpointC;
17788
+ static Sphere debugpointR;
1530917789
1531017790 static Sphere debugpoints[] = new Sphere[8];
1531117791
15312
- static
15313
- {
15314
- for (int i=0; i<8; i++)
15315
- {
15316
- debugpoints[i] = new Sphere();
15317
- }
15318
- }
15319
-
1532017792 static void InitPoints(float radius)
1532117793 {
1532217794 for (int i=0; i<8; i++)
....@@ -15336,7 +17808,7 @@
1533617808 }
1533717809 }
1533817810
15339
- static void DrawPoints(CameraPane cpane)
17811
+ static void DrawPoints(iCameraPane cpane)
1534017812 {
1534117813 for (int i=0; i<8; i++) // first and last are red
1534217814 {
....@@ -15358,7 +17830,8 @@
1535817830 static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1535917831 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1536017832 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15361
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17833
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17834
+ static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
1536217835 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1536317836 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1536417837 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15367,10 +17840,11 @@
1536717840 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1536817841 // Depth buffer format
1536917842 //private int depth_format;
15370
- static public void NextIndex(Object3D o, GL gl)
17843
+
17844
+ public void NextIndex()
1537117845 {
1537217846 indexcount+=16;
15373
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17847
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1537417848 //objects[indexcount] = o;
1537517849 //System.out.println("indexcount = " + indexcount);
1537617850 }