Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
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;
....@@ -90,17 +110,17 @@
90110 //private Mat4f spotlightTransform = new Mat4f();
91111 //private Mat4f spotlightInverseTransform = new Mat4f();
92112 static GLContext glcontext = null;
93
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
94116 boolean reverseUP = false;
95117 static boolean frozen = false;
96118 boolean enablebackspace = false; // patch for back buffer refresh
97119
98120 static boolean textureon = true;
99121 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101122 static boolean FULLSCREEN = false;
102123 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104124 static boolean INERTIA = true;
105125 static boolean FAST = false;
106126 static boolean SLOWPOSE = false;
....@@ -108,6 +128,8 @@
108128
109129 static int tickcount = 0; // slow pose issue
110130
131
+static boolean BUTTONLESSWHEEL = false;
132
+static boolean ZOOMBOXMODE = false;
111133 static boolean BOXMODE = false;
112134 static boolean IMAGEFLIP = false;
113135 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +144,7 @@
122144 static boolean OEIL = true;
123145 static boolean OEILONCE = false; // do oeilon then oeiloff
124146 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
147
+static boolean SWITCH = true; // false;
126148 static boolean HANDLES = false; // selection doesn't work!!
127149 static boolean PAINTMODE = false;
128150
....@@ -153,7 +175,7 @@
153175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
154176 boolean anisotropy = true;
155177 boolean softshadow = true; // slower but better false;
156
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
157179
158180 boolean macromode = false;
159181
....@@ -165,12 +187,55 @@
165187 defaultcaps.setAccumBlueBits(16);
166188 defaultcaps.setAccumAlphaBits(16);
167189 }
168
- static CameraPane theRenderer;
190
+
191
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
169192
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
205
+
170206 void SetAsGLRenderer(boolean b)
171207 {
172208 isRenderer = b;
173
- theRenderer = this;
209
+ Globals.theRenderer = this;
210
+ }
211
+
212
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
213
+ {
214
+ super(defaultcaps, null, withcontext?glcontext:null, null);
215
+
216
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
217
+ glcontext = getContext();
218
+
219
+ cameras = new Camera[2];
220
+ targetLookAts = new cVector[2];
221
+
222
+ SetCamera(cam);
223
+
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
226
+
227
+ object = o;
228
+
229
+ setBackground(Color.white);
230
+
231
+ addKeyListener(this);
232
+ addMouseListener(this);
233
+ addMouseMotionListener(this);
234
+ addMouseWheelListener(this);
235
+ //System.out.println("addGLEventListener: " + this);
236
+ addGLEventListener(this);
237
+
238
+// pingthread.start(); // may 2013
174239 }
175240
176241 static boolean AntialiasingEnabled()
....@@ -178,12 +243,53 @@
178243 return CURRENTANTIALIAS > 0;
179244 }
180245
181
- void ClearDepth()
246
+ /// INTERFACE
247
+
248
+ public javax.media.opengl.GL GetGL0()
249
+ {
250
+ return null;
251
+ }
252
+
253
+ public int GenList()
254
+ {
255
+ javax.media.opengl.GL gl = GetGL();
256
+ return gl.glGenLists(1);
257
+ }
258
+
259
+ public void NewList(int id)
260
+ {
261
+ javax.media.opengl.GL gl = GetGL();
262
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
263
+ }
264
+
265
+ public void CallList(int id)
266
+ {
267
+ javax.media.opengl.GL gl = GetGL();
268
+ gl.glCallList(id);
269
+ }
270
+
271
+ public void EndList()
272
+ {
273
+ javax.media.opengl.GL gl = GetGL();
274
+ gl.glEndList();
275
+ }
276
+
277
+ public boolean IsBoxMode()
278
+ {
279
+ return BOXMODE;
280
+ }
281
+
282
+ public boolean IsZoomBoxMode()
283
+ {
284
+ return ZOOMBOXMODE;
285
+ }
286
+
287
+ public void ClearDepth()
182288 {
183289 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184290 }
185291
186
- void DepthTest(boolean depthtest)
292
+ public void DepthTest(boolean depthtest)
187293 {
188294 if (depthtest)
189295 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +297,7 @@
191297 GetGL().glDepthFunc(GL.GL_ALWAYS);
192298 }
193299
194
- void DepthWrite(boolean depthwrite)
300
+ public void DepthWrite(boolean depthwrite)
195301 {
196302 if (depthwrite)
197303 GetGL().glDepthMask(true);
....@@ -199,12 +305,1616 @@
199305 GetGL().glDepthMask(false);
200306 }
201307
202
- void BackFaceCull(boolean bfc)
308
+ public void BackFaceCull(boolean bfc)
203309 {
204310 if (bfc)
205311 GetGL().glEnable(GetGL().GL_CULL_FACE);
206312 else
207313 GetGL().glDisable(GetGL().GL_CULL_FACE);
314
+ }
315
+
316
+ public boolean BackFaceCullMode()
317
+ {
318
+ return this.CULLFACE;
319
+ }
320
+
321
+ public boolean IsAmbientOcclusionOn()
322
+ {
323
+ return this.ambientOcclusion;
324
+ }
325
+
326
+ public boolean IsDebugSelection()
327
+ {
328
+ return DEBUG_SELECTION;
329
+ }
330
+
331
+ public boolean IsFrozen()
332
+ {
333
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
334
+
335
+ return !selectmode && cameracount == 0; // != 0;
336
+ }
337
+
338
+ // Currently in Globals
339
+ public int DrawMode()
340
+ {
341
+ return Globals.DrawMode();
342
+ }
343
+
344
+ public Camera EyeCamera()
345
+ {
346
+ return eyeCamera;
347
+ }
348
+
349
+ public Camera LightCamera()
350
+ {
351
+ return lightCamera;
352
+ }
353
+
354
+ public Camera ManipCamera()
355
+ {
356
+ return manipCamera;
357
+ }
358
+
359
+ public Camera RenderCamera()
360
+ {
361
+ return renderCamera;
362
+ }
363
+
364
+ public Camera[] Cameras()
365
+ {
366
+ return cameras;
367
+ }
368
+
369
+ public void PushMaterial(Object3D obj, boolean selected)
370
+ {
371
+ CameraPane display = this;
372
+ javax.media.opengl.GL gl = display.GetGL();
373
+ cMaterial material = obj.material;
374
+
375
+ if (material != null)
376
+ {
377
+ materialstack[materialdepth] = material;
378
+ selectedstack[materialdepth] = selected;
379
+ cStatic.objectstack[materialdepth++] = obj;
380
+ //System.out.println("material " + material);
381
+ //Applet3D.tracein(this, selected);
382
+ //display.vector2buffer = obj.projectedVertices;
383
+ if (obj instanceof Camera)
384
+ {
385
+ display.options1[0] = material.shift;
386
+ //System.out.println("shift " + material.shift);
387
+ display.options1[1] = material.lightarea;
388
+ display.options1[2] = material.shadowbias;
389
+ display.options1[3] = material.aniso;
390
+ display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
396
+ display.options2[0] = material.opacity;
397
+ display.options2[1] = material.diffuse;
398
+ display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
402
+
403
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
407
+ display.options4[0] = material.cameralight/0.2f;
408
+ display.options4[1] = material.subsurface;
409
+ display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
413
+
414
+ // if (display.CURRENTANTIALIAS > 0)
415
+ // display.options3[3] /= 4;
416
+
417
+ /*
418
+ System.out.println("Focus = " + display.options1[0]);
419
+ System.out.println("Aperture = " + display.options1[1]);
420
+ System.out.println("ShadowBlur = " + display.options1[2]);
421
+ System.out.println("Antialiasing = " + display.options1[3]);
422
+ System.out.println("Fog = " + display.options2[0]);
423
+ System.out.println("Intensity = " + display.options2[1]);
424
+ System.out.println("Elevation = " + display.options2[2]);
425
+ /**/
426
+ } else
427
+ {
428
+ DrawMaterial(material, selected, obj.projectedVertices);
429
+ }
430
+ } else
431
+ {
432
+ if (selected && CameraPane.flash)
433
+ {
434
+ display.modelParams4[1] = 100;
435
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
436
+ }
437
+ }
438
+ }
439
+
440
+ public void PushMaterial2(Object3D obj, boolean selected)
441
+ {
442
+ CameraPane display = this;
443
+ cMaterial material = obj.material;
444
+
445
+ if (material != null)
446
+ {
447
+ materialstack[materialdepth] = material;
448
+ selectedstack[materialdepth] = selected;
449
+ cStatic.objectstack[materialdepth++] = obj;
450
+ //System.out.println("material " + material);
451
+ //Applet3D.tracein("selected ", selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
454
+ }
455
+ }
456
+
457
+ public void PopMaterial(Object3D obj, boolean selected)
458
+ {
459
+ CameraPane display = this;
460
+ javax.media.opengl.GL gl = display.GetGL();
461
+ cMaterial material = obj.material;
462
+
463
+ //if (parent != null && parent.GetMaterial() != null)
464
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
465
+ if (material != null)
466
+ {
467
+ materialdepth -= 1;
468
+ if (materialdepth > 0)
469
+ {
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
472
+ }
473
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
474
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
475
+ {
476
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
477
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
478
+ }
479
+ }
480
+
481
+ public void PopMaterial2(Object3D obj)
482
+ {
483
+ CameraPane display = this;
484
+ cMaterial material = obj.material;
485
+
486
+ if (material != null)
487
+ {
488
+ materialdepth -= 1;
489
+ if (materialdepth > 0)
490
+ {
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
493
+ }
494
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
495
+ //else
496
+ //material.Draw(display, false);
497
+ }
498
+ }
499
+
500
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
501
+ {
502
+ CameraPane display = this;
503
+
504
+ if (pv.y == -10000 ||
505
+ qv.y == -10000 ||
506
+ rv.y == -10000)
507
+ return;
508
+
509
+// float b = f.nbiterations & 1;
510
+// float g = (f.nbiterations>>1) & 1;
511
+// float r = (f.nbiterations>>2) & 1;
512
+//
513
+// //if (f.weight == 10000)
514
+// //{
515
+// // r = 1; g = b = 0;
516
+// //}
517
+// //else
518
+// //{
519
+// // assert(f.weight < 10000);
520
+// r = g = b = (float)bRep.FaceWeight(f)*100;
521
+// if (r<0)
522
+// assert(r>=0);
523
+// //}
524
+
525
+ javax.media.opengl.GL gl = display.GetGL();
526
+
527
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
528
+
529
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
530
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
531
+ {
532
+ //gl.glBegin(gl.GL_TRIANGLES);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
536
+ if (!hasnorm)
537
+ {
538
+ // System.out.println("Mesh normal");
539
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
540
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
541
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
542
+ LA.vecNormalize(obj.v2);
543
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
544
+ }
545
+
546
+ // P
547
+ float x = (float)pv.x;
548
+ float y = (float)pv.y;
549
+ float z = (float)pv.z;
550
+
551
+ if (hasnorm)
552
+ {
553
+// if (!pv.norm.normalized())
554
+// assert(pv.norm.normalized());
555
+
556
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
557
+ float nx = (float)pv.norm.x;
558
+ float ny = (float)pv.norm.y;
559
+ float nz = (float)pv.norm.z;
560
+
561
+ x += nx * obj.NORMALPUSH;
562
+ y += ny * obj.NORMALPUSH;
563
+ z += nz * obj.NORMALPUSH;
564
+
565
+ gl.glNormal3f(nx, ny, nz);
566
+ }
567
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
568
+ SetColor(obj, pv);
569
+ //gl.glColor4f(r, g, b, 1);
570
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
571
+ if (obj.flipV)
572
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
573
+ else
574
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
575
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
576
+
577
+ gl.glVertex3f(x, y, z);
578
+
579
+ // Q
580
+ x = (float)qv.x;
581
+ y = (float)qv.y;
582
+ z = (float)qv.z;
583
+
584
+// Print(pv);
585
+ if (hasnorm)
586
+ {
587
+// assert(qv.norm.normalized());
588
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
589
+ float nx = (float)qv.norm.x;
590
+ float ny = (float)qv.norm.y;
591
+ float nz = (float)qv.norm.z;
592
+
593
+ x += nx * obj.NORMALPUSH;
594
+ y += ny * obj.NORMALPUSH;
595
+ z += nz * obj.NORMALPUSH;
596
+
597
+ gl.glNormal3f(nx, ny, nz);
598
+ }
599
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
600
+ // boolean locked = false;
601
+ // float eps = 0.1f;
602
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
603
+
604
+ // int dot = 0; //*/ (int)f.dot;
605
+
606
+ // if ((dot&1) == 0)
607
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
608
+
609
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
610
+ if (obj.flipV)
611
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
612
+ else
613
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
614
+ // else
615
+ // {
616
+ // locked = true;
617
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
618
+ // }
619
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
620
+ SetColor(obj, qv);
621
+
622
+ gl.glVertex3f(x, y, z);
623
+ //gl.glColor4f(r, g, b, 1);
624
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
625
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
626
+// Print(qv);
627
+
628
+ // R
629
+ x = (float)rv.x;
630
+ y = (float)rv.y;
631
+ z = (float)rv.z;
632
+
633
+ if (hasnorm)
634
+ {
635
+// assert(rv.norm.normalized());
636
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
637
+ float nx = (float)rv.norm.x;
638
+ float ny = (float)rv.norm.y;
639
+ float nz = (float)rv.norm.z;
640
+
641
+ x += nx * obj.NORMALPUSH;
642
+ y += ny * obj.NORMALPUSH;
643
+ z += nz * obj.NORMALPUSH;
644
+
645
+ gl.glNormal3f(nx, ny, nz);
646
+ }
647
+
648
+ // if ((dot&4) == 0)
649
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
650
+
651
+ // if (wrap || !locked && (dot&8) != 0)
652
+ if (obj.flipV)
653
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
654
+ else
655
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
656
+ // else
657
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
658
+
659
+ // f.dot = dot;
660
+
661
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
662
+ SetColor(obj, rv);
663
+ //gl.glColor4f(r, g, b, 1);
664
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
665
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
666
+ gl.glVertex3f(x, y, z);
667
+// Print(rv);
668
+ //gl.glEnd();
669
+ }
670
+ else
671
+ {
672
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
673
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
674
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
675
+
676
+ }
677
+
678
+ if (false) // (attributes & WIREFRAME) != 0)
679
+ {
680
+ gl.glDisable(gl.GL_LIGHTING);
681
+
682
+ gl.glBegin(gl.GL_LINE_LOOP);
683
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
684
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
685
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
686
+ gl.glEnd();
687
+
688
+ gl.glEnable(gl.GL_LIGHTING);
689
+ }
690
+ }
691
+
692
+ /**
693
+ * <code>draw</code> renders a <code>TriMesh</code> object including
694
+ * it's normals, colors, textures and vertices.
695
+ *
696
+ * @see Renderer#draw(TriMesh)
697
+ * @param tris
698
+ * the mesh to render.
699
+ */
700
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
701
+ {
702
+ CameraPane display = this;
703
+
704
+ float r = display.modelParams0[0];
705
+ float g = display.modelParams0[1];
706
+ float b = display.modelParams0[2];
707
+ float opacity = display.modelParams5[1];
708
+
709
+ //final GL gl = GLU.getCurrentGL();
710
+ GL gl = display.GetGL(); // getGL();
711
+
712
+ FloatBuffer vertBuf = geo.vertBuf;
713
+
714
+ int v = vertBuf.capacity();
715
+
716
+ int count = 0;
717
+
718
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
719
+ gl.glEnable(gl.GL_CULL_FACE);
720
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
721
+ for (int i=0; i<v/3; i++)
722
+ {
723
+ int index3 = i*3;
724
+
725
+ if (geo.sizeBuf.get(index3+1) == 0)
726
+ continue;
727
+
728
+ count++;
729
+
730
+ int index4 = i*4;
731
+
732
+ float tx = vertBuf.get(index3);
733
+ float ty = vertBuf.get(index3+1);
734
+ float tz = vertBuf.get(index3+2);
735
+
736
+ // if (tx == 0 && ty == 0 && tz == 0)
737
+ // continue;
738
+
739
+ gl.glMatrixMode(gl.GL_TEXTURE);
740
+ gl.glPushMatrix();
741
+
742
+ float[] texmat = geo.texmat;
743
+ texmat[12] = texmat[13] = texmat[14] = i;
744
+
745
+ gl.glMultMatrixf(texmat, 0);
746
+
747
+ gl.glMatrixMode(gl.GL_MODELVIEW);
748
+ gl.glPushMatrix();
749
+
750
+ gl.glTranslatef(tx,ty,tz);
751
+
752
+ if (rotate)
753
+ gl.glRotatef(i, 0, 1, 0);
754
+
755
+ float size = geo.sizeBuf.get(index3) / 100;
756
+ gl.glScalef(size,size,size);
757
+
758
+ float cr = geo.colorBuf.get(index4);
759
+ float cg = geo.colorBuf.get(index4+1);
760
+ float cb = geo.colorBuf.get(index4+2);
761
+ float ca = geo.colorBuf.get(index4+3);
762
+
763
+ display.modelParams0[0] = r * cr;
764
+ display.modelParams0[1] = g * cg;
765
+ display.modelParams0[2] = b * cb;
766
+
767
+ display.modelParams5[1] = opacity * ca;
768
+
769
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
770
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
771
+
772
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
773
+ RandomNode.globalseed2 = RandomNode.globalseed;
774
+
775
+// gl.glColor4f(cr,cg,cb,ca);
776
+ // gl.glScalef(1024/16,1024/16,1024/16);
777
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
778
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
779
+ //gl.glTranslatef(-tx,-ty,-tz);
780
+ gl.glPopMatrix();
781
+
782
+ gl.glMatrixMode(gl.GL_TEXTURE);
783
+ gl.glPopMatrix();
784
+ }
785
+ // gl.glScalef(1024,1024,1024);
786
+ if (!cf)
787
+ gl.glDisable(gl.GL_CULL_FACE);
788
+
789
+ display.modelParams0[0] = r;
790
+ display.modelParams0[1] = g;
791
+ display.modelParams0[2] = b;
792
+
793
+ display.modelParams5[1] = opacity;
794
+
795
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
796
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
797
+
798
+ gl.glMatrixMode(gl.GL_MODELVIEW);
799
+
800
+// System.err.println("total = " + v/3 + "; displayed = " + count);
801
+ if (true)
802
+ return;
803
+
804
+//// if (!tris.predraw(this))
805
+//// {
806
+//// return;
807
+//// }
808
+//// if (Debug.stats)
809
+//// {
810
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
811
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
812
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
813
+//// }
814
+////
815
+//// if (tris.getDisplayListID() != -1)
816
+//// {
817
+//// renderDisplayList(tris);
818
+//// return;
819
+//// }
820
+////
821
+//// if (!generatingDisplayList)
822
+//// {
823
+//// applyStates(tris.states, tris);
824
+//// }
825
+//// if (Debug.stats)
826
+//// {
827
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
828
+//// }
829
+//// boolean transformed = doTransforms(tris);
830
+//
831
+// int glMode = GL.GL_TRIANGLES;
832
+// switch (getMode())
833
+// {
834
+// case Triangles:
835
+// glMode = GL.GL_TRIANGLES;
836
+// break;
837
+// case Strip:
838
+// glMode = GL.GL_TRIANGLE_STRIP;
839
+// break;
840
+// case Fan:
841
+// glMode = GL.GL_TRIANGLE_FAN;
842
+// break;
843
+// }
844
+//
845
+// if (!predrawGeometry(gl))
846
+// {
847
+// // make sure only the necessary indices are sent through on old
848
+// // cards.
849
+// IntBuffer indices = this.getIndexBuffer();
850
+// if (indices == null)
851
+// {
852
+// logger.severe("missing indices on geometry object: " + this.toString());
853
+// } else
854
+// {
855
+// indices.rewind();
856
+// indices.limit(this.getMaxIndex());
857
+//
858
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
859
+//
860
+// indices.clear();
861
+// }
862
+// } else
863
+// {
864
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
865
+// GL.GL_UNSIGNED_INT, 0);
866
+// }
867
+//
868
+//// postdrawGeometry(tris);
869
+//// if (transformed)
870
+//// {
871
+//// undoTransforms(tris);
872
+//// }
873
+////
874
+//// if (Debug.stats)
875
+//// {
876
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
877
+//// }
878
+//// tris.postdraw(this);
879
+ }
880
+
881
+ static Camera localcamera = new Camera();
882
+ static cVector from = new cVector();
883
+ static cVector to = new cVector();
884
+
885
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
886
+ {
887
+ CameraPane cp = this;
888
+
889
+ Camera keep = cp.RenderCamera();
890
+ cp.renderCamera = localcamera;
891
+
892
+ if (br.trimmed)
893
+ {
894
+ float[] colors = new float[br.positions.length / 3];
895
+
896
+ int i3 = 0;
897
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
898
+ {
899
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
900
+ continue;
901
+
902
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
903
+ to.set(br.positions[i3] + br.normals[i3],
904
+ br.positions[i3 + 1] + br.normals[i3 + 1],
905
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
906
+ LA.xformPos(from, transform, from);
907
+ LA.xformPos(to, transform, to); // RIGID ONLY
908
+ localcamera.setAim(from, to);
909
+
910
+ CameraPane.occlusionbuffer.display();
911
+
912
+ if (CameraPane.DEBUG_OCCLUSION)
913
+ cp.display(); // debug
914
+
915
+ colors[i] = cp.vertexOcclusion.r;
916
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
917
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
918
+
919
+ if ((i % 100) == 0 && i != 0)
920
+ {
921
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
922
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
923
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
924
+ }
925
+ }
926
+
927
+ br.colors = colors;
928
+ }
929
+ else
930
+ {
931
+ for (int i = 0; i < br.VertexCount(); i++)
932
+ {
933
+ Vertex v = br.GetVertex(i);
934
+
935
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
936
+ continue;
937
+
938
+ from.set(v.x, v.y, v.z);
939
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
940
+ LA.xformPos(from, transform, from);
941
+ LA.xformPos(to, transform, to); // RIGID ONLY
942
+ localcamera.setAim(from, to);
943
+
944
+ CameraPane.occlusionbuffer.display();
945
+
946
+ if (CameraPane.DEBUG_OCCLUSION)
947
+ cp.display(); // debug
948
+
949
+ v.AO = cp.vertexOcclusion.r;
950
+
951
+ if ((i % 100) == 0 && i != 0)
952
+ {
953
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
954
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
955
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
956
+ }
957
+ }
958
+ }
959
+
960
+ //System.out.println("done.");
961
+
962
+ cp.renderCamera = keep;
963
+ }
964
+
965
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
966
+ {
967
+ CameraPane display = this;
968
+ pointFlow.CreateHT();
969
+
970
+ float r = display.modelParams0[0];
971
+ float g = display.modelParams0[1];
972
+ float b = display.modelParams0[2];
973
+ float opacity = display.modelParams5[1];
974
+
975
+ //final GL gl = GLU.getCurrentGL();
976
+ GL gl = display.GetGL(); // getGL();
977
+
978
+ int s = pointFlow.points.size();
979
+
980
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
981
+ gl.glEnable(gl.GL_CULL_FACE);
982
+
983
+ for (int i=s; --i>=0;)
984
+ //for (int i=0; i<s; i++)
985
+ {
986
+ cVector v = pointFlow.points.get(i);
987
+
988
+ double mindist = Double.MAX_VALUE;
989
+
990
+ double size = pointFlow.minimumSize;
991
+
992
+ double distancenext = 0;
993
+
994
+ if (i > 0)
995
+ {
996
+ cVector w = pointFlow.points.get(i-1);
997
+
998
+ double dist = w.distance(v);
999
+
1000
+ distancenext = dist;
1001
+
1002
+ if (mindist > dist)
1003
+ {
1004
+ mindist = dist;
1005
+ size = mindist*pointFlow.resizefactor;
1006
+ }
1007
+ }
1008
+
1009
+ if (i < s-1)
1010
+ {
1011
+ cVector w = pointFlow.points.get(i+1);
1012
+
1013
+ double dist = w.distance(v);
1014
+
1015
+ if (mindist > dist)
1016
+ {
1017
+ mindist = dist;
1018
+ size = mindist*pointFlow.resizefactor;
1019
+ }
1020
+ }
1021
+
1022
+ if (size < pointFlow.minimumSize)
1023
+ size = pointFlow.minimumSize;
1024
+ if (size > pointFlow.maximumSize)
1025
+ size = pointFlow.maximumSize;
1026
+
1027
+ double tx = v.x;
1028
+ double ty = v.y;
1029
+ double tz = v.z;
1030
+
1031
+ // if (tx == 0 && ty == 0 && tz == 0)
1032
+ // continue;
1033
+
1034
+ gl.glMatrixMode(gl.GL_TEXTURE);
1035
+ gl.glPushMatrix();
1036
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1037
+
1038
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1039
+
1040
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1041
+ gl.glPushMatrix();
1042
+
1043
+ gl.glTranslated(tx,ty,tz);
1044
+
1045
+ gl.glScaled(size,size,size);
1046
+
1047
+// float cr = colorBuf.get(index4);
1048
+// float cg = colorBuf.get(index4+1);
1049
+// float cb = colorBuf.get(index4+2);
1050
+// float ca = colorBuf.get(index4+3);
1051
+//
1052
+// display.modelParams0[0] = r * cr;
1053
+// display.modelParams0[1] = g * cg;
1054
+// display.modelParams0[2] = b * cb;
1055
+//
1056
+// display.modelParams5[1] = opacity * ca;
1057
+//
1058
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1059
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1060
+//
1061
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1062
+// RandomNode.globalseed2 = RandomNode.globalseed;
1063
+//
1064
+//// gl.glColor4f(cr,cg,cb,ca);
1065
+// // gl.glScalef(1024/16,1024/16,1024/16);
1066
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1067
+
1068
+ gl.glPopMatrix();
1069
+
1070
+ double step = size/4; //
1071
+
1072
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1073
+ continue;
1074
+
1075
+ int nbsteps = (int)(distancenext/step);
1076
+
1077
+ step = distancenext/nbsteps;
1078
+
1079
+ cVector next = pointFlow.points.get(i-1);
1080
+
1081
+ tmp.set(next);
1082
+ tmp.sub(v);
1083
+ tmp.normalize();
1084
+ tmp.mul(step);
1085
+
1086
+ // calculate next size
1087
+ mindist = Double.MAX_VALUE;
1088
+
1089
+ double nextsize = pointFlow.minimumSize;
1090
+
1091
+ if (i > 1)
1092
+ {
1093
+ cVector w = pointFlow.points.get(i-2);
1094
+
1095
+ double dist = w.distance(next);
1096
+
1097
+ if (mindist > dist)
1098
+ {
1099
+ mindist = dist;
1100
+ nextsize = mindist*pointFlow.resizefactor;
1101
+ }
1102
+ }
1103
+
1104
+ double dist = v.distance(next);
1105
+
1106
+ if (mindist > dist)
1107
+ {
1108
+ mindist = dist;
1109
+ nextsize = mindist*pointFlow.resizefactor;
1110
+ }
1111
+
1112
+ if (nextsize < pointFlow.minimumSize)
1113
+ nextsize = pointFlow.minimumSize;
1114
+ if (nextsize > pointFlow.maximumSize)
1115
+ nextsize = pointFlow.maximumSize;
1116
+ //
1117
+
1118
+ double count = 0;
1119
+
1120
+ while (distancenext > 0.000000001) // step
1121
+ {
1122
+ gl.glPushMatrix();
1123
+
1124
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1125
+
1126
+ double K = count/nbsteps;
1127
+
1128
+ double intersize = K*nextsize + (1-K)*size;
1129
+
1130
+ gl.glScaled(intersize,intersize,intersize);
1131
+
1132
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1133
+
1134
+ count++;
1135
+
1136
+ distancenext -= step;
1137
+
1138
+ gl.glPopMatrix();
1139
+ }
1140
+
1141
+ if (count != nbsteps)
1142
+ assert(count == nbsteps);
1143
+
1144
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1145
+ //gl.glTranslatef(-tx,-ty,-tz);
1146
+
1147
+ gl.glMatrixMode(gl.GL_TEXTURE);
1148
+ gl.glPopMatrix();
1149
+ }
1150
+
1151
+ if (!cf)
1152
+ gl.glDisable(gl.GL_CULL_FACE);
1153
+
1154
+// display.modelParams0[0] = r;
1155
+// display.modelParams0[1] = g;
1156
+// display.modelParams0[2] = b;
1157
+//
1158
+// display.modelParams5[1] = opacity;
1159
+//
1160
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1161
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1162
+
1163
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1164
+ }
1165
+
1166
+ public void DrawBox(cVector min, cVector max)
1167
+ {
1168
+ javax.media.opengl.GL gl = GetGL();
1169
+ gl.glBegin(gl.GL_LINES);
1170
+
1171
+ gl.glVertex3d(min.x, min.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, max.z);
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, max.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(max.x, min.y, min.z);
1177
+
1178
+ gl.glVertex3d(max.x, max.y, max.z);
1179
+ gl.glVertex3d(min.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(max.x, min.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, min.z);
1184
+
1185
+ gl.glEnd();
1186
+ }
1187
+
1188
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1189
+ {
1190
+ int[] strips = bRep.getRawIndices();
1191
+
1192
+ javax.media.opengl.GL gl = GetGL();
1193
+
1194
+ // TRIANGLE STRIP ARRAY
1195
+ if (bRep.trimmed)
1196
+ {
1197
+ float[] v = bRep.getRawVertices();
1198
+ float[] n = bRep.getRawNormals();
1199
+ float[] c = bRep.getRawColors();
1200
+ float[] uv = bRep.getRawUVMap();
1201
+
1202
+ int count2 = 0;
1203
+ int count3 = 0;
1204
+
1205
+ if (n.length > 0)
1206
+ {
1207
+ for (int i = 0; i < strips.length; i++)
1208
+ {
1209
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1210
+
1211
+ /*
1212
+ boolean locked = false;
1213
+ float eps = 0.1f;
1214
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1215
+
1216
+ int dot = 0;
1217
+
1218
+ if ((dot&1) == 0)
1219
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1220
+
1221
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1222
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1223
+ else
1224
+ {
1225
+ locked = true;
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+ }
1228
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1229
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1230
+ if (hasnorm)
1231
+ {
1232
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1233
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1234
+ }
1235
+
1236
+ if ((dot&4) == 0)
1237
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1238
+
1239
+ if (wrap || !locked && (dot&8) != 0)
1240
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1241
+ else
1242
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1243
+
1244
+ f.dot = dot;
1245
+ */
1246
+
1247
+ if (!selectmode)
1248
+ {
1249
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1250
+ {
1251
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1252
+ } else
1253
+ {
1254
+ gl.glNormal3f(0, 0, 1);
1255
+ }
1256
+
1257
+ if (c != null)
1258
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1259
+ {
1260
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1261
+ }
1262
+ }
1263
+
1264
+ if (flipV)
1265
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1266
+ else
1267
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
1269
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1270
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1271
+
1272
+ count2 += 2;
1273
+ count3 += 3;
1274
+ if (!selectmode)
1275
+ {
1276
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1277
+ {
1278
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1279
+ } else
1280
+ {
1281
+ gl.glNormal3f(0, 0, 1);
1282
+ }
1283
+ if (c != null)
1284
+ {
1285
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1286
+ }
1287
+ }
1288
+
1289
+ if (flipV)
1290
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1291
+ else
1292
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
1294
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1295
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1296
+
1297
+ count2 += 2;
1298
+ count3 += 3;
1299
+ for (int j = 0; j < strips[i] - 2; j++)
1300
+ {
1301
+ //gl.glTexCoord2d(...);
1302
+ if (!selectmode)
1303
+ {
1304
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1305
+ {
1306
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1307
+ } else
1308
+ {
1309
+ gl.glNormal3f(0, 0, 1);
1310
+ }
1311
+ if (c != null)
1312
+ {
1313
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1314
+ }
1315
+ }
1316
+
1317
+ if (flipV)
1318
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1319
+ else
1320
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
1322
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1323
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
1325
+ count2 += 2;
1326
+ count3 += 3;
1327
+ }
1328
+
1329
+ gl.glEnd();
1330
+ }
1331
+ }
1332
+
1333
+ assert count3 == v.length;
1334
+ }
1335
+ else // !trimmed
1336
+ {
1337
+ int count = 0;
1338
+ for (int i = 0; i < strips.length; i++)
1339
+ {
1340
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1341
+
1342
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1343
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1344
+
1345
+ drawVertex(gl, p, flipV, selectmode);
1346
+ drawVertex(gl, q, flipV, selectmode);
1347
+
1348
+ for (int j = 0; j < strips[i] - 2; j++)
1349
+ {
1350
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1351
+
1352
+ // if (j%2 == 0)
1353
+ // drawFace(p, q, r, display, null);
1354
+ // else
1355
+ // drawFace(p, r, q, display, null);
1356
+
1357
+ // p = q;
1358
+ // q = r;
1359
+ drawVertex(gl, r, flipV, selectmode);
1360
+ }
1361
+
1362
+ gl.glEnd();
1363
+ }
1364
+ }
1365
+ }
1366
+
1367
+ static cSpring.Point3D temp = new cSpring.Point3D();
1368
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1369
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1370
+
1371
+ public void DrawDynamicMesh(cMesh mesh)
1372
+ {
1373
+ GL gl = GetGL(); // getGL();
1374
+
1375
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1376
+
1377
+ gl.glDisable(gl.GL_LIGHTING);
1378
+
1379
+ gl.glLineWidth(1);
1380
+ gl.glColor3f(1,1,1);
1381
+ gl.glBegin(gl.GL_LINES);
1382
+ double scale = 0;
1383
+ int count = 0;
1384
+ for (int s=0; s<Phys.allSprings.size(); s++)
1385
+ {
1386
+ cSpring.Spring spring = Phys.allSprings.get(s);
1387
+ if(s == 0)
1388
+ {
1389
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1390
+ }
1391
+ if (mesh.showsprings)
1392
+ {
1393
+ temp.set(spring.a.position);
1394
+ temp.add(spring.b.position);
1395
+ temp.mul(0.5);
1396
+ temp2.set(spring.a.position);
1397
+ temp2.sub(spring.b.position);
1398
+ temp2.mul(spring.restLength/2);
1399
+ temp.sub(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ temp.add(temp2);
1402
+ temp.add(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ }
1405
+
1406
+ if (spring.isHandle)
1407
+ continue;
1408
+
1409
+ //if (scale < spring.restLength)
1410
+ scale += spring.restLength;
1411
+ count++;
1412
+ }
1413
+ gl.glEnd();
1414
+
1415
+ if (count == 0)
1416
+ scale = 0.01;
1417
+ else
1418
+ scale /= count * 3;
1419
+
1420
+ //scale = 0.25;
1421
+
1422
+ if (mesh.ShowInfo())
1423
+ {
1424
+ gl.glLineWidth(4);
1425
+ for (int s=0; s<Phys.allNodes.size(); s++)
1426
+ {
1427
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1428
+ if (node.mass == 0)
1429
+ continue;
1430
+
1431
+ int i = node.springs==null?-1:node.springs.size();
1432
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1433
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1434
+ //temp.normalize();
1435
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1436
+ gl.glBegin(gl.GL_LINES);
1437
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1438
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1439
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1440
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1441
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1442
+ gl.glEnd();
1443
+ }
1444
+
1445
+ gl.glLineWidth(8);
1446
+ for (int s=0; s<Phys.allNodes.size(); s++)
1447
+ {
1448
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1449
+
1450
+ if (node.springs != null)
1451
+ {
1452
+ for (int i=0; i<node.springs.size(); i+=1)
1453
+ {
1454
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1455
+
1456
+ int c = i+1;
1457
+ // c = node.springs.get(i).nbcopies;
1458
+
1459
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1460
+ gl.glBegin(gl.GL_LINES);
1461
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1462
+ 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);
1463
+ gl.glEnd();
1464
+ }
1465
+ }
1466
+ }
1467
+
1468
+ gl.glLineWidth(1);
1469
+ }
1470
+
1471
+ gl.glEnable(gl.GL_LIGHTING);
1472
+ }
1473
+
1474
+ /// INTERFACE
1475
+
1476
+ public void StartTriangles()
1477
+ {
1478
+ javax.media.opengl.GL gl = GetGL();
1479
+ gl.glBegin(gl.GL_TRIANGLES);
1480
+ }
1481
+
1482
+ public void EndTriangles()
1483
+ {
1484
+ GetGL().glEnd();
1485
+ }
1486
+
1487
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1488
+ {
1489
+ if (!selectmode)
1490
+ {
1491
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1492
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1493
+
1494
+ if (flipV)
1495
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1496
+ else
1497
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1498
+ }
1499
+
1500
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1501
+ }
1502
+
1503
+ float[] colorV = new float[4];
1504
+
1505
+ void SetColor(Object3D obj, Vertex p0)
1506
+ {
1507
+ CameraPane display = this;
1508
+ BoundaryRep bRep = obj.bRep;
1509
+
1510
+ if (RENDERPROGRAM == 0)
1511
+ {
1512
+ float r = 0;
1513
+ if (bRep != null)
1514
+ {
1515
+ if (bRep.stripified)
1516
+ {
1517
+ r = 1;
1518
+ }
1519
+ }
1520
+ float g = 0;
1521
+ if (bRep != null)
1522
+ {
1523
+ if (bRep.trimmed)
1524
+ {
1525
+ g = 1;
1526
+ }
1527
+ }
1528
+ float b = 0;
1529
+ if (obj.support != null && obj.link2master)
1530
+ {
1531
+ b = 1;
1532
+ }
1533
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1534
+ return;
1535
+ }
1536
+
1537
+ if (display.DrawMode() != CameraPane.SHADOW)
1538
+ return;
1539
+
1540
+ javax.media.opengl.GL gl = display.GetGL();
1541
+// if (true) return;
1542
+// float ao = p.AO;
1543
+//
1544
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1545
+// // ao = 1;
1546
+//
1547
+// gl.glColor4f(ao, ao, ao, 1);
1548
+
1549
+// CameraPane.selectedpoint.
1550
+// getAverage(cStatic.point1, true);
1551
+ if (CameraPane.pointflow == null) // !random) // live)
1552
+ {
1553
+ return;
1554
+ }
1555
+
1556
+ cStatic.point1.set(0,0,0);
1557
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1558
+
1559
+ cStatic.point1.sub(p0);
1560
+
1561
+
1562
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1563
+// {
1564
+// return;
1565
+// }
1566
+
1567
+ //if (true)
1568
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1569
+ {
1570
+ return;
1571
+ }
1572
+
1573
+ if (false) // marked)
1574
+ {
1575
+ // debug rigging weights
1576
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1577
+ {
1578
+ float weight = p0.weights[object] / p0.totalweight;
1579
+
1580
+ // if (weight < 0.1)
1581
+ // {
1582
+ // assert(weight == 0);
1583
+ // continue;
1584
+ // }
1585
+
1586
+ if (p0.vertexlinks[object] == -1)
1587
+ continue;
1588
+
1589
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1590
+
1591
+ int color = //1 << object; //
1592
+ //p.vertexlinks.length;
1593
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1594
+ colorV[2] += (color & 1) * weight;
1595
+ colorV[1] += ((color & 2) >> 1) * weight;
1596
+ colorV[0] += ((color & 4) >> 2) * weight;
1597
+ }
1598
+ }
1599
+ else
1600
+ {
1601
+ if (obj.drawingstarted)
1602
+ {
1603
+ // find next point
1604
+ if (bRep.GetVertex(0).faceindices == null)
1605
+ {
1606
+ bRep.InitFaceIndices();
1607
+ }
1608
+
1609
+ double ymin = p0.y;
1610
+
1611
+ Vertex newp = p0;
1612
+
1613
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1614
+ {
1615
+ int fi = p0.faceindices[fii];
1616
+
1617
+ if (fi == -1)
1618
+ break;
1619
+
1620
+ Face f = bRep.GetFace(fi);
1621
+
1622
+ Vertex p = bRep.GetVertex(f.p);
1623
+ Vertex q = bRep.GetVertex(f.q);
1624
+ Vertex r = bRep.GetVertex(f.r);
1625
+
1626
+ int swap = (int)(Math.random()*3);
1627
+
1628
+// for (int s=swap; --s>=0;)
1629
+// {
1630
+// Vertex t = p;
1631
+// p = q;
1632
+// q = r;
1633
+// r = t;
1634
+// }
1635
+ if (ymin > p.y)
1636
+ {
1637
+ ymin = p.y;
1638
+ newp = p;
1639
+// break;
1640
+ }
1641
+ if (ymin > q.y)
1642
+ {
1643
+ ymin = q.y;
1644
+ newp = q;
1645
+// break;
1646
+ }
1647
+ if (ymin > r.y)
1648
+ {
1649
+ ymin = r.y;
1650
+ newp = r;
1651
+// break;
1652
+ }
1653
+ }
1654
+
1655
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1656
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1657
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1658
+
1659
+ obj.drawingstarted = false;
1660
+
1661
+ // return;
1662
+ }
1663
+
1664
+ if (false) // CameraPane.DRAW
1665
+ {
1666
+ p0.AO = colorV[0] = 2;
1667
+ colorV[1] = 2;
1668
+ colorV[2] = 2;
1669
+ }
1670
+
1671
+ CameraPane.pointflow.add(p0);
1672
+ CameraPane.pointflow.Touch();
1673
+ }
1674
+
1675
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1676
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1677
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1678
+ }
1679
+
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1681
+ {
1682
+ CameraPane display = this;
1683
+ //new Exception().printStackTrace();
1684
+
1685
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1686
+ {
1687
+ return;
1688
+ }
1689
+
1690
+ javax.media.opengl.GL gl = display.GetGL();
1691
+
1692
+ //Color col = Color.getHSBColor(color,modulation,1);
1693
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1694
+ if (!material.multiply)
1695
+ {
1696
+ display.color = material.color;
1697
+ display.saturation = material.modulation;
1698
+ }
1699
+ else
1700
+ {
1701
+ display.color *= material.color*2;
1702
+ display.saturation *= material.modulation*2;
1703
+ }
1704
+
1705
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1706
+
1707
+ float[] colorV = Grafreed.colorV;
1708
+
1709
+ /**/
1710
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1711
+ {
1712
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1713
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1714
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1715
+ colorV[3] = 1; // material.opacity;
1716
+
1717
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1718
+ //System.out.println("Opacity = " + opacity);
1719
+
1720
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1721
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1722
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1723
+
1724
+ float amb = material.ambient;
1725
+ if (amb < material.cameralight)
1726
+ {
1727
+ amb = material.cameralight;
1728
+ }
1729
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1730
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1731
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1732
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1733
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1734
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1735
+
1736
+ /**/
1737
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1738
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1739
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1740
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1741
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1742
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1743
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1744
+ //System.out.println("shininess = " + colorV[0]);
1745
+ if (colorV[0] > 128)
1746
+ {
1747
+ colorV[0] = 128;
1748
+ }
1749
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1750
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1751
+ /**/
1752
+ }
1753
+ /**/
1754
+
1755
+ //selected = false;
1756
+ selected = selected && display.flash;
1757
+
1758
+ //display.modelParams0[0] = 0; // pigment.r;
1759
+ //display.modelParams0[1] = 0; // pigment.g;
1760
+ //display.modelParams0[2] = 0; // pigment.b;
1761
+ if (!material.multiply)
1762
+ {
1763
+ display.modelParams0[3] = material.metalness;
1764
+ display.modelParams1[0] = material.diffuse;
1765
+ display.modelParams1[1] = material.specular;
1766
+ display.modelParams1[2] = 1 / material.shininess;
1767
+ display.modelParams1[3] = material.shift;
1768
+ display.modelParams2[0] = material.ambient;
1769
+ display.modelParams2[1] = material.lightarea;
1770
+ //System.out.println("light area = " + lightarea);
1771
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1772
+ display.modelParams2[3] = material.velvet;
1773
+ display.modelParams3[0] = material.sheen;
1774
+ display.modelParams3[1] = material.subsurface;
1775
+ display.modelParams3[2] = material.bump; // backlit
1776
+ display.modelParams3[3] = material.aniso;
1777
+ display.modelParams4[0] = material.anisoV;
1778
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1779
+ //System.out.println("selected = " + selected);
1780
+ display.modelParams4[2] = material.diffuseness;
1781
+ display.modelParams4[3] = material.shadow;
1782
+ display.modelParams5[0] = material.texture;
1783
+ display.modelParams5[1] = material.opacity;
1784
+ display.modelParams5[2] = material.fakedepth;
1785
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1786
+ }
1787
+ else
1788
+ {
1789
+ display.modelParams0[3] *= material.metalness*2;
1790
+ display.modelParams1[0] *= material.diffuse*2;
1791
+ display.modelParams1[1] *= material.specular*2;
1792
+ display.modelParams1[2] *= material.shininess*2;
1793
+ display.modelParams1[3] *= material.shift*2;
1794
+ display.modelParams2[0] *= material.ambient*2;
1795
+ display.modelParams2[1] *= material.lightarea*2;
1796
+ display.modelParams2[2] *= material.factor*2;
1797
+ display.modelParams2[3] *= material.velvet*2;
1798
+ display.modelParams3[0] *= material.sheen*2;
1799
+ display.modelParams3[1] *= material.subsurface*2;
1800
+ display.modelParams3[2] *= material.bump*2;
1801
+ display.modelParams3[3] *= material.aniso*2;
1802
+ display.modelParams4[0] *= material.anisoV*2;
1803
+ display.modelParams4[1] *= material.cameralight*2;
1804
+ //System.out.println("selected = " + selected);
1805
+ display.modelParams4[2] *= material.diffuseness*2;
1806
+ display.modelParams4[3] *= material.shadow*2;
1807
+ display.modelParams5[0] *= material.texture*2;
1808
+ display.modelParams5[1] *= material.opacity*2;
1809
+ display.modelParams5[2] *= material.fakedepth*2;
1810
+ display.modelParams5[3] *= material.shadowbias*2;
1811
+ }
1812
+
1813
+ display.modelParams6[0] = 0;
1814
+ display.modelParams6[1] = 0;
1815
+ display.modelParams6[2] = 0;
1816
+ display.modelParams6[3] = 0;
1817
+
1818
+ display.modelParams7[0] = 0;
1819
+ display.modelParams7[1] = 1000;
1820
+ display.modelParams7[2] = 0;
1821
+ display.modelParams7[3] = 0;
1822
+
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
1824
+
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1826
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1827
+ {
1828
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1829
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1830
+ if (extparams.length > 1)
1831
+ {
1832
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1833
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1834
+ if (extparams.length > 2)
1835
+ {
1836
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1837
+ float x = extparams[2].y / 1000.0f;
1838
+ //if (x == 0)
1839
+ // x = 1f;
1840
+ 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
1841
+ if (extparams[2].y > 0)
1842
+ {
1843
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1844
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1845
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1846
+ }
1847
+ }
1848
+ }
1849
+ }
1850
+
1851
+ //if (display.modelParams6[2] != 0)
1852
+ /*
1853
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1854
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1855
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1856
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1857
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1858
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1859
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1860
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1861
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1862
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1863
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1864
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1865
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1866
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1867
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1868
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1869
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1870
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1871
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1872
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1873
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1874
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1875
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1876
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1877
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1878
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1879
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1880
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1881
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1882
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1883
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1884
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1885
+ /**/
1886
+ //assert (display.modelParams6[2] == 0);
1887
+
1888
+ //System.out.println("noise power = " + display.modelParams7[0]);
1889
+ //System.out.println("shadowbias = " + shadowbias);
1890
+
1891
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1892
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1893
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1896
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1897
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1898
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1899
+
1900
+ int mode = display.FP_SHADER;
1901
+
1902
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1903
+ {
1904
+ mode |= display.FP_ANISO;
1905
+ }
1906
+
1907
+ display.EnableProgram(mode);
1908
+
1909
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1910
+
1911
+ if (!material.multiply)
1912
+ {
1913
+ if (Globals.drawMode == CameraPane.SHADOW)
1914
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1915
+ else
1916
+ gl.glDepthMask(material.opacity >= 0.99);
1917
+ }
2081918 }
2091919
2101920 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1935,7 @@
2251935 currentGL.glMultMatrixd(model, 0);
2261936 }
2271937
228
- void PushMatrix(double[][] matrix, int count)
1938
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291939 {
2301940 matrixdepth++;
2311941 // GrafreeD.tracein(matrix);
....@@ -254,7 +1964,7 @@
2541964 void PushMatrix(double[][] matrix)
2551965 {
2561966 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
2581968 }
2591969
2601970 void PushMatrix()
....@@ -270,7 +1980,7 @@
2701980
2711981 double[][] tmpmat = new double[4][4];
2721982
273
- void PopMatrix(double[][] inverse)
1983
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741984 {
2751985 --matrixdepth;
2761986
....@@ -310,7 +2020,7 @@
3102020 PushTextureMatrix(matrix, 1);
3112021 }
3122022
313
- void PushTextureMatrix(double[][] matrix, int count)
2023
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142024 {
3152025 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162026
....@@ -324,7 +2034,7 @@
3242034 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252035 }
3262036
327
- void PopTextureMatrix(double[][] inverse)
2037
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282038 {
3292039 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302040 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2061,15 @@
3512061
3522062 static int camerachangeframe;
3532063
354
- boolean SetCamera(Camera cam)
2064
+ public boolean SetCamera(Camera cam)
3552065 {
3562066 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572067 // return false;
3582068
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2069
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602070 {
3612071 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2072
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632073 {
3642074 // refuse the camera change
3652075 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2077,7 @@
3672077 }
3682078 }
3692079
370
- camerachangeframe = framecount;
2080
+ camerachangeframe = Globals.framecount;
3712081
3722082 cam.hAspect = -1; // Read only
3732083
....@@ -398,7 +2108,7 @@
3982108 {
3992109 //System.err.println("Oeil on");
4002110 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2111
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022112 // object.editWindow.ScreenFit(trackedobject);
4032113 //pingthread.StepToTarget(true);
4042114 }
....@@ -407,8 +2117,8 @@
4072117 {
4082118 //System.err.println("Oeil on");
4092119 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2120
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122122 //pingthread.StepToTarget(true);
4132123 }
4142124
....@@ -471,39 +2181,12 @@
4712181 {
4722182 frozen ^= true;
4732183 // Weird...
474
- lighttouched = true;
2184
+ Globals.lighttouched = true;
4752185 }
4762186
4772187 void ToggleDL()
4782188 {
4792189 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;
5072190 }
5082191
5092192 void ToggleFullScreen()
....@@ -513,12 +2196,7 @@
5132196
5142197 void ToggleCrowd()
5152198 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2199
+ Globals.CROWD ^= true;
5222200 }
5232201
5242202 void ToggleLocal()
....@@ -526,62 +2204,89 @@
5262204 LOCALTRANSFORM ^= true;
5272205 }
5282206
529
- void ToggleFast()
2207
+ public void ToggleTexture()
2208
+ {
2209
+ textureon ^= true;
2210
+ }
2211
+
2212
+ public void ToggleLive()
2213
+ {
2214
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2215
+
2216
+ System.err.println("LIVE = " + Globals.isLIVE());
2217
+
2218
+ if (!Globals.isLIVE()) // save sound
2219
+ Grafreed.savesound = true; // wav.save();
2220
+ // else
2221
+ repaint(); // start loop // may 2013
2222
+ }
2223
+
2224
+ public void ToggleSupport()
2225
+ {
2226
+ SUPPORT ^= true;
2227
+ }
2228
+
2229
+ public void ToggleAbort()
2230
+ {
2231
+ ABORTMODE ^= true;
2232
+ }
2233
+
2234
+ public void ToggleInertia()
2235
+ {
2236
+ INERTIA ^= true;
2237
+ }
2238
+
2239
+ public void ToggleFast()
5302240 {
5312241 FAST ^= true;
5322242 }
5332243
534
- void ToggleSlowPose()
2244
+ public void ToggleSlowPose()
5352245 {
5362246 SLOWPOSE ^= true;
5372247 }
5382248
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2249
+ public void ToggleBoxMode()
5452250 {
5462251 BOXMODE ^= true;
5472252 }
5482253
549
- void ToggleSmoothFocus()
2254
+ public void ToggleZoomBoxMode()
2255
+ {
2256
+ ZOOMBOXMODE ^= true;
2257
+ }
2258
+
2259
+ public void ToggleSmoothFocus()
5502260 {
5512261 SMOOTHFOCUS ^= true;
5522262 }
5532263
554
- void ToggleImageFlip()
2264
+ public void ToggleImageFlip()
5552265 {
5562266 IMAGEFLIP ^= true;
5572267 }
5582268
559
- void ToggleSpeakerMocap()
2269
+ public void ToggleSpeakerMocap()
5602270 {
5612271 SPEAKERMOCAP ^= true;
5622272 }
5632273
564
- void ToggleSpeakerCamera()
2274
+ public void ToggleSpeakerCamera()
5652275 {
5662276 SPEAKERCAMERA ^= true;
5672277 }
5682278
569
- void ToggleSpeakerFocus()
2279
+ public void ToggleSpeakerFocus()
5702280 {
5712281 SPEAKERFOCUS ^= true;
5722282 }
5732283
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2284
+ public void ToggleFrustum()
5802285 {
5812286 FRUSTUM ^= true;
5822287 }
5832288
584
- void ToggleTrack()
2289
+ public void ToggleTrack()
5852290 {
5862291 TRACK ^= true;
5872292 if (TRACK)
....@@ -600,25 +2305,35 @@
6002305 repaint();
6012306 }
6022307
603
- void ToggleTrackOnce()
2308
+ public void ToggleTrackOnce()
6042309 {
6052310 TRACKONCE ^= true;
6062311 }
6072312
608
- void ToggleShadowTrack()
2313
+ public void ToggleShadowTrack()
6092314 {
6102315 SHADOWTRACK ^= true;
6112316 repaint();
6122317 }
6132318
614
- void ToggleOeil()
2319
+ public void ToggleOeil()
6152320 {
6162321 OEIL ^= true;
6172322 }
6182323
619
- void ToggleOeilOnce()
2324
+ public void ToggleOeilOnce()
6202325 {
6212326 OEILONCE ^= true;
2327
+ }
2328
+
2329
+ void ToggleFootContact()
2330
+ {
2331
+ FOOTCONTACT ^= true;
2332
+ }
2333
+
2334
+ void ToggleDebug()
2335
+ {
2336
+ Globals.DEBUG ^= true;
6222337 }
6232338
6242339 void ToggleLookAt()
....@@ -626,9 +2341,9 @@
6262341 LOOKAT ^= true;
6272342 }
6282343
629
- void ToggleRandom()
2344
+ void ToggleSwitch()
6302345 {
631
- RANDOM ^= true;
2346
+ SWITCH ^= true;
6322347 }
6332348
6342349 void ToggleHandles()
....@@ -636,10 +2351,17 @@
6362351 HANDLES ^= true;
6372352 }
6382353
2354
+ Object3D paintFolder;
2355
+
6392356 void TogglePaint()
6402357 {
6412358 PAINTMODE ^= true;
6422359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
6432365 }
6442366
6452367 void SwapCamera(int a, int b)
....@@ -672,34 +2394,6 @@
6722394 //assert (cam.hAspect == 0);
6732395 cam.hAspect = 0;
6742396 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
7032397 }
7042398
7052399 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2453,26 @@
7592453
7602454 GL currentGL;
7612455
762
- GL GetGL()
2456
+ public GL GetGL() // INTERFACE
7632457 {
7642458 return currentGL;
7652459 }
766
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
7672476 /**/
7682477 class CacheTexture
7692478 {
....@@ -772,28 +2481,31 @@
7722481
7732482 int resolution;
7742483
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762485 {
777
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
7782488 resolution = res;
7792489 }
7802490 }
7812491 /**/
7822492
7832493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
7872499 int pigmentdepth = 0;
7882500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892501 int bumpdepth = 0;
7902502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952507
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972509 {
7982510 TextureData texturedata = null;
7992511
....@@ -812,13 +2524,34 @@
8122524 if (bump)
8132525 texturedata = ConvertBump(texturedata, false);
8142526
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202532
821
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
8222555 }
8232556
8242557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3624,8 @@
18913624
18923625 System.out.println("LOADING TEXTURE : " + name);
18933626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
18943629 //
18953630 if (false) // compressbit > 0)
18963631 {
....@@ -2000,10 +3735,12 @@
20003735 */
20013736 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20023737 {
3738
+ int pixelformat = texturedata.getPixelFormat();
3739
+
20033740 int stride = 1;
2004
- if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
3741
+ if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
20053742 stride = 3;
2006
- if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
3743
+ if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
20073744 stride = 4;
20083745
20093746 int width = texturedata.getWidth();
....@@ -2593,6 +4330,7 @@
25934330
25944331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25954332 {
4333
+ new Exception().printStackTrace();
25964334 System.exit(0);
25974335 com.sun.opengl.util.texture.Texture texture = null;
25984336
....@@ -6269,7 +8007,7 @@
62698007 return null;
62708008 }
62718009
6272
- void ReleaseTextures(cTexture tex)
8010
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62738011 {
62748012 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62758013 {
....@@ -6286,7 +8024,7 @@
62868024 String pigment = Object3D.GetPigment(tex);
62878025 String bump = Object3D.GetBump(tex);
62888026
6289
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62908028 {
62918029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62928030 // System.out.println("; bump = " + bump);
....@@ -6301,13 +8039,71 @@
63018039 pigment = null;
63028040 }
63038041
6304
- ReleaseTexture(bump, true);
6305
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
63068044 }
63078045
6308
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63098047 {
6310
- if (// drawMode != 0 || /*tex == null ||*/
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
8105
+ {
8106
+ if (// DrawMode() != 0 || /*tex == null ||*/
63118107 ambientOcclusion ) // || !textureon)
63128108 {
63138109 return;
....@@ -6316,7 +8112,7 @@
63168112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63178113
63188114 if (tex != null)
6319
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63208116
63218117 // //assert( texture != null );
63228118 // if (texture == null)
....@@ -6408,9 +8204,57 @@
64088204 }
64098205 }
64108206
6411
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64128208 {
6413
- if (// drawMode != 0 || /*tex == null ||*/
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8256
+ {
8257
+ if (// DrawMode() != 0 || /*tex == null ||*/
64148258 ambientOcclusion ) // || !textureon)
64158259 {
64168260 return; // false;
....@@ -6419,17 +8263,47 @@
64198263 if (tex == null)
64208264 {
64218265 BindTexture(null,false,resolution);
6422
- BindTexture(null,true,resolution);
64238266 return;
64248267 }
64258268
64268269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
64278302 String bump = Object3D.GetBump(tex);
64288303
6429
- usedtextures.put(pigment, pigment);
6430
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
64318305
6432
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64338307 {
64348308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64358309 // System.out.println("; bump = " + bump);
....@@ -6439,43 +8313,94 @@
64398313 {
64408314 bump = null;
64418315 }
6442
- if (pigment.equals(""))
6443
- {
6444
- pigment = null;
6445
- }
64468316
6447
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6448
- BindTexture(pigment, false, resolution);
64498317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6450
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
64518319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6452
-
6453
- return; // true;
64548320 }
64558321
6456
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
64578325 {
6458
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
64598345
64608346 if (tex != null)
64618347 {
6462
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64638350
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;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
64708368
64718369 if (CACHETEXTURE)
6472
- texture = textures.get(texname); // TEXTURE CACHE
6473
-
6474
- TextureData texturedata = null;
6475
-
6476
- if (texture == null || texture.resolution < resolution)
64778370 {
6478
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64798404 {
64808405 assert(!bump);
64818406 // if (bump)
....@@ -6486,19 +8411,23 @@
64868411 // }
64878412 // else
64888413 // {
6489
- texture = textures.get(tex);
6490
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
64918416 {
6492
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64938418 }
8419
+ else
8420
+ new Exception().printStackTrace();
64948421 // }
64958422 } else
6496
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64978424 {
64988425 assert(bump);
6499
- texture = textures.get(tex);
6500
- if (texture == null)
6501
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
65028431 } else
65038432 {
65048433 //if (tex.equals("IMMORTAL"))
....@@ -6506,11 +8435,22 @@
65068435 // texture = GetResourceTexture("default.png");
65078436 //} else
65088437 //{
6509
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
65108439 {
6511
- texture = textures.get(tex);
6512
- if (texture == null)
6513
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
65148454 } else
65158455 {
65168456 if (textureon)
....@@ -6535,7 +8475,7 @@
65358475 }
65368476
65378477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6538
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
65398479 cachename = texname;
65408480 else
65418481 processbump = false; // don't process bump map again
....@@ -6557,7 +8497,7 @@
65578497 }
65588498
65598499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6560
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
65618501 cachename = texname;
65628502 else
65638503 processbump = false; // don't process bump map again
....@@ -6566,20 +8506,23 @@
65668506 texturedata = GetFileTexture(cachename, processbump, resolution);
65678507
65688508
6569
- if (texturedata != null)
6570
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
65718513 //texture = GetTexture(tex, bump);
65728514 }
8515
+ }
65738516 }
65748517 //}
65758518 }
65768519
6577
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65788521 {
65798522 //return false;
65808523
65818524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6582
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65838526 {
65848527 // String ext = "_highres";
65858528 // if (REDUCETEXTURE)
....@@ -6596,52 +8539,17 @@
65968539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65978540 if (!cachefile.exists())
65988541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
66088543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
66398546 ImageWriter writer = null;
66408547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66418548 if (iter.hasNext()) {
66428549 writer = (ImageWriter)iter.next();
66438550 }
6644
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
66458553 try
66468554 {
66478555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6658,18 +8566,20 @@
66588566 }
66598567 }
66608568 }
6661
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
66628572 //System.out.println("Texture = " + tex);
6663
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
66648574 {
6665
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
66668576 thetex.texture.disable();
66678577 thetex.texture.dispose();
6668
- textures.remove(texname);
8578
+ textures.remove(tex);
66698579 }
66708580
6671
- texture.texturedata = texturedata;
6672
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
66738583
66748584 // newtex = true;
66758585 }
....@@ -6685,10 +8595,44 @@
66858595 }
66868596 }
66878597
6688
- return texture;
8598
+ return texturecache;
66898599 }
66908600
6691
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66928636 {
66938637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66948638
....@@ -6706,21 +8650,21 @@
67068650 return texture!=null?texture.texture:null;
67078651 }
67088652
6709
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67108654 {
67118655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67128656
67138657 return texture!=null?texture.texturedata:null;
67148658 }
67158659
6716
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67178661 {
67188662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67198663 {
67208664 return false;
67218665 }
67228666
6723
- boolean newtex = false;
8667
+ //boolean newtex = false;
67248668
67258669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67268670
....@@ -6752,9 +8696,75 @@
67528696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67538697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67548698
6755
- return newtex;
8699
+ return true; // Warning: not used.
67568700 }
67578701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
67588768 ShadowBuffer shadowPBuf;
67598769 AntialiasBuffer antialiasPBuf;
67608770 int MAXSTACK;
....@@ -6771,10 +8781,12 @@
67718781
67728782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67738783 MAXSTACK = temp[0];
6774
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67758786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67768787 MAXSTACK = temp[0];
6777
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67788790
67798791 // Use debug pipeline
67808792 //drawable.setGL(new DebugGL(gl)); //
....@@ -6782,7 +8794,8 @@
67828794 gl = drawable.getGL(); //
67838795
67848796 GL gl3 = getGL();
6785
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67868799
67878800
67888801 //float pos[] = { 100, 100, 100, 0 };
....@@ -6947,7 +8960,7 @@
69478960
69488961 if (cubemap == null)
69498962 {
6950
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
69518964 }
69528965
69538966 //cubemap.enable();
....@@ -7223,6 +9236,8 @@
72239236
72249237 void LoadEnvy(int which)
72259238 {
9239
+ assert(false);
9240
+
72269241 String name;
72279242 String ext;
72289243
....@@ -7234,37 +9249,58 @@
72349249 cubemap = null;
72359250 return;
72369251 case 1:
7237
- name = "cubemaps/box_";
7238
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
72399254 reverseUP = false;
72409255 break;
72419256 case 2:
7242
- name = "cubemaps/uffizi_";
7243
- ext = "png";
7244
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
72459261 case 3:
7246
- name = "cubemaps/CloudyHills_";
7247
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
72489264 reverseUP = false;
72499265 break;
72509266 case 4:
7251
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
72529268 ext = "png";
72539269 reverseUP = false;
72549270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
72559296 default:
7256
- name = "cubemaps/rgb_";
7257
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
72589300 break;
72599301 }
7260
-
7261
- try
7262
- {
7263
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7264
- } catch (IOException e)
7265
- {
7266
- throw new RuntimeException(e);
7267
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
72689304 }
72699305
72709306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7296,8 +9332,12 @@
72969332 static double[] model = new double[16];
72979333 double[] camera2light = new double[16];
72989334 double[] light2camera = new double[16];
7299
- int newenvy = -1;
7300
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
73019341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73029342 //float[] light0 = { 0,0,0 };
73039343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7310,9 +9350,9 @@
73109350 static boolean occlusionInitialized = false;
73119351 boolean selection = false;
73129352 boolean pointselection = false;
7313
- /*static*/ boolean lighttouched = true;
9353
+ ///*static*/ boolean lighttouched = true;
73149354 boolean deselect;
7315
- boolean ambientOcclusion = false;
9355
+ private boolean ambientOcclusion = false;
73169356 static boolean flash = false;
73179357 /*static*/ boolean wait = false;
73189358 boolean displaydone = false; // after repaint() calls
....@@ -7442,6 +9482,8 @@
74429482 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74439483 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74449484 double scale = lightCamera.SCALE / lightCamera.Distance();
9485
+// PATCH FILLE AUX JEANS
9486
+ //scale *= lightCamera.shaper_fovy / 25;
74459487 gl.glScaled(2 * scale, 2 * scale, -scale);
74469488 gl.glTranslated(0, 0, lightCamera.DECAL);
74479489
....@@ -7588,17 +9630,40 @@
75889630 jy8[3] = 0.5f;
75899631 }
75909632
7591
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75929634 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
9635
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9636
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75949637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
75959662 static int imagecount = 0; // movie generation
75969663
75979664 static int jitter = 0;
75989665
75999666 boolean restartframe = false;
7600
-
7601
- static int framecount = 0; // general-purpose global count
76029667
76039668 void displayAntiAliased(javax.media.opengl.GL gl)
76049669 {
....@@ -7630,7 +9695,7 @@
76309695 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76319696 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76329697 {
7633
- framecount++;
9698
+ Globals.framecount++;
76349699
76359700 if (CameraPane.tickcount > 0)
76369701 CameraPane.tickcount--;
....@@ -7668,7 +9733,7 @@
76689733
76699734 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76709735 */
7671
- lighttouched = true;
9736
+ Globals.lighttouched = true;
76729737 //System.err.println(" shadowbuffer: " + jitter);
76739738 shadowbuffer.display();
76749739
....@@ -7689,8 +9754,8 @@
76899754 assert (parentcam != renderCamera);
76909755
76919756 if (renderCamera != lightCamera)
7692
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7693
- LA.matConcat(parentcam.toParent, matrix, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76949759
76959760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76969761
....@@ -7705,8 +9770,8 @@
77059770 LA.matCopy(renderCamera.fromScreen, matrix);
77069771
77079772 if (renderCamera != lightCamera)
7708
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7709
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77109775
77119776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77129777
....@@ -7752,10 +9817,12 @@
77529817 rati = 1 / rati;
77539818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77549819 }
7755
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
77569823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77579824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7758
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
77599826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77609827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77619828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7778,7 +9845,7 @@
77789845 //gl.glFlush();
77799846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77809847
7781
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
77829849 {
77839850 System.err.println(" ABORTED FRAME");
77849851 break;
....@@ -7808,7 +9875,7 @@
78089875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78099876
78109877 // save image
7811
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
78129879 {
78139880 VPwidth = viewport[2];
78149881 VPheight = viewport[3];
....@@ -7919,11 +9986,11 @@
79199986
79209987 // imagecount++;
79219988
7922
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79239990
79249991 if (!BOXMODE)
79259992 {
7926
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79279994 }
79289995
79299996 if (!BOXMODE)
....@@ -7961,7 +10028,7 @@
796110028 ABORTED = false;
796210029 }
796310030 else
7964
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
796510032
796610033 if (false)
796710034 {
....@@ -8615,13 +10682,6 @@
861510682 }
861610683 }
861710684
8618
- boolean IsFrozen()
8619
- {
8620
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8621
-
8622
- return !selectmode && cameracount == 0; // != 0;
8623
- }
8624
-
862510685 boolean niceon = false;
862610686 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
862710687 boolean currentlydrawing = false;
....@@ -8631,16 +10691,16 @@
863110691
863210692 public void display(GLAutoDrawable drawable)
863310693 {
8634
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
863510695 {
8636
- GrafreeD.wav.save();
8637
- GrafreeD.savesound = false;
8638
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
863910699 }
864010700 // if (DEBUG_SELECTION)
864110701 // {
8642
-// if (drawMode != SELECTION)
8643
-// drawMode = SELECTION;
10702
+// if (DrawMode() != SELECTION)
10703
+// DrawMode() = SELECTION;
864410704 // }
864510705
864610706 if (!isRenderer)
....@@ -8696,9 +10756,9 @@
869610756
869710757 //ANTIALIAS = 0;
869810758
8699
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10759
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870010760 {
8701
- if (niceon || isLIVE())
10761
+ if (niceon || Globals.isLIVE())
870210762 {
870310763 //if(active == 0)
870410764 // antialiaser = null;
....@@ -8711,6 +10771,7 @@
871110771 ANTIALIAS = 0;
871210772 //System.out.println("RESTART");
871310773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
871410775 }
871510776 }
871610777 }
....@@ -8723,7 +10784,7 @@
872310784 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872410785 */
872510786
8726
- if (drawMode == DEFAULT)
10787
+ if (DrawMode() == DEFAULT)
872710788 {
872810789 currentlydrawing = true;
872910790 }
....@@ -8754,18 +10815,18 @@
875410815
875510816 // if(Applet3D.clipboard != null)
875610817 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8757
-//drawMode = SELECTION;
10818
+//DrawMode() = SELECTION;
875810819 indexcount = 0;
875910820
8760
- if (drawMode == OCCLUSION)
10821
+ if (DrawMode() == OCCLUSION)
876110822 {
8762
- drawMode = DEFAULT;
10823
+ Globals.drawMode = DEFAULT; // WARNING
876310824 ambientOcclusion = true;
876410825 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876510826 Object3D theobject = object;
876610827 Object3D theparent = object.parent;
876710828 object.parent = null;
8768
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
876910830 object.Stripify();
877010831 if (theobject.selection == null || theobject.selection.Size() == 0)
877110832 theobject.PreprocessOcclusion(this);
....@@ -8778,26 +10839,27 @@
877810839 ambientOcclusion = false;
877910840 }
878010841
8781
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878210844 {
878310845 //if (RENDERSHADOW) // ?
878410846 if (!IsFrozen())
878510847 {
878610848 // dec 2012
8787
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
878810850 {
8789
- framecount++;
10851
+ Globals.framecount++;
879010852 shadowbuffer.display();
879110853 }
879210854 }
8793
- lighttouched = false; // ??
10855
+ Globals.lighttouched = false; // ??
879410856 //drawing = true;
879510857 //lighttouched = true;
879610858 }
879710859
879810860 if (wait)
879910861 {
8800
- Sleep(500);
10862
+ Sleep(200); // blocks everything
880110863
880210864 wait = false;
880310865 }
....@@ -8811,9 +10873,9 @@
881110873 //eyeCamera.shaper_fovy = 1;
881210874 }
881310875
8814
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10876
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881510877 {
8816
- //System.out.println("drawMode = " + drawMode);
10878
+ //System.out.println("DrawMode() = " + DrawMode());
881710879 vertexMode |= VP_PASS;
881810880 //vertexMode |= VP_PROJECTION;
881910881 if (!ambientOcclusion)
....@@ -8873,7 +10935,7 @@
887310935 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887410936 //Camera lightcam = new Camera(light0);
887510937
8876
- if (drawMode == SHADOW)
10938
+ if (DrawMode() == SHADOW)
887710939 {
887810940 /*
887910941 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8911,8 +10973,8 @@
891110973
891210974 // if (parentcam != renderCamera) // not a light
891310975 if (cam != lightCamera)
8914
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8915
- LA.matConcat(parentcam.toParent, matrix, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891610978
891710979 for (int j = 0; j < 4; j++)
891810980 {
....@@ -8926,8 +10988,8 @@
892610988
892710989 // if (parentcam != renderCamera) // not a light
892810990 if (cam != lightCamera)
8929
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8930
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893110993
893210994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893310995
....@@ -8963,7 +11025,7 @@
896311025 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896411026 } else
896511027 {
8966
- if (drawMode != DEFAULT)
11028
+ if (DrawMode() != DEFAULT)
896711029 {
896811030 gl.glClearColor(1, 1, 1, 0);
896911031 } // 1);
....@@ -9013,13 +11075,41 @@
901311075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901411076 }
901511077
9016
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
901711086 {
9018
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
901911093 }
9020
-
9021
- newenvy = -1;
9022
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
902311113 ratio = ((double) getWidth()) / getHeight();
902411114 //System.out.println("ratio = " + ratio);
902511115
....@@ -9028,14 +11118,14 @@
902811118
902911119 fast &= !ambientOcclusion;
903011120
9031
- if (drawMode == DEFAULT)
11121
+ if (DrawMode() == DEFAULT)
903211122 {
903311123 //gl.glEnable(gl.GL_ALPHA_TEST);
903411124 //gl.glActiveTexture(GL.GL_TEXTURE0);
903511125
903611126 if (!IsFrozen() && !ambientOcclusion)
903711127 {
9038
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
903911129 }
904011130
904111131 //if (selection_view == -1)
....@@ -9089,6 +11179,8 @@
908911179 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909011180 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909111181 double scale = lightCamera.SCALE / lightCamera.Distance();
11182
+// PATCH FILLE AUX JEANS
11183
+ //scale *= lightCamera.shaper_fovy / 25;
909211184 gl.glScaled(2 * scale, 2 * scale, -scale);
909311185 gl.glTranslated(0, 0, lightCamera.DECAL);
909411186
....@@ -9184,7 +11276,16 @@
918411276 // Bump noise
918511277 gl.glActiveTexture(GL.GL_TEXTURE6);
918611278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9187
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
918811289
918911290 gl.glActiveTexture(GL.GL_TEXTURE0);
919011291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9207,9 +11308,9 @@
920711308
920811309 gl.glMatrixMode(GL.GL_MODELVIEW);
920911310
9210
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9211
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9212
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
921311314 } else
921411315 {
921511316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9220,14 +11321,16 @@
922011321 //System.out.println("BLENDING ON");
922111322 gl.glEnable(GL.GL_BLEND);
922211323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9223
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922411325 gl.glMatrixMode(gl.GL_PROJECTION);
922511326 gl.glLoadIdentity();
922611327
9227
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11328
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
922811329 {
922911330 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923011331 double scale = lightCamera.SCALE / lightCamera.Distance();
11332
+// PATCH FILLE AUX JEANS
11333
+ //scale *= lightCamera.shaper_fovy / 25;
923111334 gl.glScaled(2 * scale, 2 * scale, -scale);
923211335 gl.glTranslated(0, 0, lightCamera.DECAL);
923311336 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9280,7 +11383,7 @@
928011383 //gl.glPushMatrix();
928111384 gl.glLoadIdentity();
928211385
9283
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11386
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928411387 {
928511388 //LA.xformPos(light0, lightCamera.fromScreen, light);
928611389 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9307,8 +11410,8 @@
930711410 System.err.println("parentcam != renderCamera");
930811411
930911412 // if (cam != lightCamera)
9310
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9311
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
931211415 }
931311416
931411417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9329,8 +11432,8 @@
932911432 if (true) // TODO
933011433 {
933111434 if (cam != lightCamera)
9332
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9333
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933411437 }
933511438
933611439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9367,7 +11470,7 @@
936711470 }
936811471
936911472 /**/
9370
- if (true) // drawMode == SELECTION) // != DEFAULT)
11473
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937111474 gl.glDisable(gl.GL_LIGHTING);
937211475 else
937311476 gl.glEnable(gl.GL_LIGHTING);
....@@ -9379,12 +11482,13 @@
937911482
938011483 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
938111484 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11485
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
938211486
938311487 options2[0] *= renderCamera.Distance();
938411488
938511489 lightslot = 64;
938611490
9387
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11491
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
938811492 {
938911493 DrawLights(object);
939011494 }
....@@ -9395,7 +11499,7 @@
939511499 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
939611500 //System.out.println("fragmentMode = " + fragmentMode);
939711501
9398
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11502
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
939911503 {
940011504 /*
940111505 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9428,7 +11532,7 @@
942811532 }
942911533 }
943011534
9431
- if (drawMode == DEFAULT)
11535
+ if (DrawMode() == DEFAULT)
943211536 {
943311537 if (WIREFRAME && !ambientOcclusion)
943411538 {
....@@ -9446,7 +11550,7 @@
944611550 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
944711551 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
944811552
9449
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11553
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945011554 {
945111555 if (vertexMode != 0) // && !fast)
945211556 {
....@@ -9466,7 +11570,7 @@
946611570 }
946711571 }
946811572
9469
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947011574 {
947111575 //gl.glDepthFunc(GL.GL_LEQUAL);
947211576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9474,27 +11578,24 @@
947411578
947511579 boolean texon = textureon;
947611580
9477
- if (RENDERPROGRAM > 0)
9478
- {
9479
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9480
- textureon = false;
9481
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
948211584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948311585 //System.out.println("ALLO");
948411586 gl.glColorMask(false, false, false, false);
948511587 DrawObject(gl);
9486
- if (RENDERPROGRAM > 0)
9487
- {
9488
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9489
- textureon = texon;
9490
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
949111592 gl.glColorMask(true, true, true, true);
949211593
949311594 gl.glDepthFunc(GL.GL_EQUAL);
9494
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
949511596 }
949611597
9497
- if (false) // drawMode == SHADOW)
11598
+ if (false) // DrawMode() == SHADOW)
949811599 {
949911600 //SetColumnMajorData(cameraInverseTransform, view_1);
950011601 //System.out.println("light = " + cameraInverseTransform);
....@@ -9508,16 +11609,16 @@
950811609 //System.out.println("object = " + object);
950911610 if (!frozen && !imageLocked)
951011611 {
9511
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11612
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951211613 {
951311614 displayAntiAliased(gl);
951411615 } else
951511616 {
951611617 programcount = 0;
9517
- int keepmode = drawMode;
11618
+ int keepmode = DrawMode();
951811619 // if (DEBUG_SELECTION)
951911620 // {
9520
-// drawMode = SELECTION;
11621
+// DrawMode() = SELECTION;
952111622 // }
952211623 // for point selection
952311624 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9527,10 +11628,10 @@
952711628 DrawObject(gl);
952811629
952911630 // jan 2013 System.err.println("RESET ABORT (display)");
9530
- // if (drawMode == DEFAULT)
11631
+ // if (DrawMode() == DEFAULT)
953111632 // ABORTED = false;
953211633 fullreset = false;
9533
- drawMode = keepmode;
11634
+ Globals.drawMode = keepmode; // WARNING
953411635 //System.out.println("PROGRAM SWITCH " + programcount);
953511636 }
953611637 }
....@@ -9538,11 +11639,11 @@
953811639 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
953911640 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954011641
9541
- if (drawMode == DEFAULT)
11642
+ if (DrawMode() == DEFAULT)
954211643 {
954311644 ReleaseTexture(NOISE_TEXTURE, false);
954411645 }
9545
- //if (drawMode == DEFAULT)
11646
+ //if (DrawMode() == DEFAULT)
954611647 {
954711648
954811649 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9554,7 +11655,7 @@
955411655 //else
955511656 //gl.glDisable(gl.GL_TEXTURE_2D);
955611657 //gl.glPopMatrix();
9557
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11658
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
955811659 {
955911660 //new Exception().printStackTrace();
956011661 //System.out.println("Draw image " + width + ", " + height);
....@@ -9596,7 +11697,7 @@
959611697 //gl.glFlush();
959711698 }
959811699
9599
- if (flash && drawMode == DEFAULT)
11700
+ if (flash && DrawMode() == DEFAULT)
960011701 {
960111702 flash = false;
960211703 wait = true;
....@@ -9604,9 +11705,9 @@
960411705 }
960511706
960611707 //drawing = false;
9607
- //if(drawMode == DEFAULT)
11708
+ //if(DrawMode() == DEFAULT)
960811709 // niceon = false;
9609
- if (drawMode == DEFAULT)
11710
+ if (DrawMode() == DEFAULT)
961011711 {
961111712 currentlydrawing = false;
961211713 }
....@@ -9626,7 +11727,7 @@
962611727 repaint();
962711728 }
962811729
9629
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11730
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963011731 repaint();
963111732
963211733 displaydone = true;
....@@ -9645,8 +11746,14 @@
964511746 {
964611747 renderpass++;
964711748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
964811750 if (FAST) // in case there is no script
9649
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
965011757
965111758 //object.FullInvariants();
965211759
....@@ -9660,23 +11767,44 @@
966011767 e.printStackTrace();
966111768 }
966211769
9663
- if (GrafreeD.RENDERME > 0)
9664
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
966511772
9666
- ONESTEP = false;
11773
+ Globals.ONESTEP = false;
966711774 }
966811775
966911776 static boolean zoomonce = false;
967011777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
967111796 void DrawObject(GL gl, boolean draw)
967211797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
967311801 //System.out.println("DRAW OBJECT " + mouseDown);
9674
-// drawMode = SELECTION;
11802
+// DrawMode() = SELECTION;
967511803 //GL gl = getGL();
967611804 if ((TRACK || SHADOWTRACK) || zoomonce)
967711805 {
9678
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9679
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11806
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968011808 pingthread.StepToTarget(true); // true);
968111809 // zoomonce = false;
968211810 }
....@@ -9696,9 +11824,9 @@
969611824 callist = gl.glGenLists(1);
969711825 }
969811826
9699
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11827
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970011828
9701
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11829
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970211830
970311831 if (!mainDL || !active || touched)
970411832 {
....@@ -9725,13 +11853,20 @@
972511853 PushMatrix(ClickInfo.matbuffer);
972611854 }
972711855
9728
- if (drawMode == 0)
11856
+ if (DrawMode() == 0)
972911857 {
973011858 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973111859
973211860 usedtextures.clear();
973311861
9734
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
973511870 }
973611871 //System.out.println("--> " + stackdepth);
973711872 // GrafreeD.traceon();
....@@ -9739,10 +11874,11 @@
973911874 // DRAW
974011875 object.draw(this, /*(Composite)*/ object, false, false);
974111876
9742
- if (drawMode == DEFAULT)
11877
+ if (DrawMode() == DEFAULT)
974311878 {
9744
- if (DEBUG)
11879
+ if (Globals.DEBUG)
974511880 {
11881
+ CreateSelectedPoint();
974611882 float radius = 0.05f;
974711883 if (selectedpoint.radius != radius)
974811884 {
....@@ -9750,40 +11886,40 @@
975011886 selectedpoint.radius = radius;
975111887 selectedpoint.recalculate();
975211888 selectedpoint.material = new cMaterial();
9753
- selectedpoint.material.color = 0.25f;
11889
+ selectedpoint.material.color = 0.15f; // Yellow
975411890 selectedpoint.material.modulation = 0.75f;
975511891
9756
- debugpoint.radius = radius;
9757
- debugpoint.recalculate();
9758
- debugpoint.material = new cMaterial();
9759
- debugpoint.material.color = 0.25f;
9760
- debugpoint.material.modulation = 0.75f;
11892
+ debugpointG.radius = radius;
11893
+ debugpointG.recalculate();
11894
+ debugpointG.material = new cMaterial();
11895
+ debugpointG.material.color = 0.25f; // Green
11896
+ debugpointG.material.modulation = 0.75f;
976111897
9762
- debugpoint2.radius = radius;
9763
- debugpoint2.recalculate();
9764
- debugpoint2.material = new cMaterial();
9765
- debugpoint2.material.color = 0.75f;
9766
- debugpoint2.material.modulation = 0.75f;
11898
+ debugpointP.radius = radius;
11899
+ debugpointP.recalculate();
11900
+ debugpointP.material = new cMaterial();
11901
+ debugpointP.material.color = 0.75f; // Purple
11902
+ debugpointP.material.modulation = 0.75f;
976711903
9768
- debugpoint3.radius = radius;
9769
- debugpoint3.recalculate();
9770
- debugpoint3.material = new cMaterial();
9771
- debugpoint3.material.color = 0.5f;
9772
- debugpoint3.material.modulation = 0.75f;
11904
+ debugpointC.radius = radius;
11905
+ debugpointC.recalculate();
11906
+ debugpointC.material = new cMaterial();
11907
+ debugpointC.material.color = 0.5f; // Cyan
11908
+ debugpointC.material.modulation = 0.75f;
977311909
9774
- debugpoint4.radius = radius;
9775
- debugpoint4.recalculate();
9776
- debugpoint4.material = new cMaterial();
9777
- debugpoint4.material.color = 0f;
9778
- debugpoint4.material.modulation = 0.75f;
11910
+ debugpointR.radius = radius;
11911
+ debugpointR.recalculate();
11912
+ debugpointR.material = new cMaterial();
11913
+ debugpointR.material.color = 0f; // Red
11914
+ debugpointR.material.modulation = 0.75f;
977911915
978011916 InitPoints(radius);
978111917 }
978211918 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);
11919
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11920
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11921
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11922
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
978711923 // DrawPoints(this);
978811924 }
978911925
....@@ -9791,42 +11927,63 @@
979111927 }
979211928 // GrafreeD.traceoff();
979311929 //System.out.println(stackdepth);
9794
- if (drawMode == 0)
11930
+ if (DrawMode() == 0)
979511931 {
979611932 ReleaseTextures(DEFAULT_TEXTURES);
979711933
979811934 if (CLEANCACHE)
9799
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
980011936 {
9801
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
980211938
980311939 // System.out.println("Texture --------- " + tex);
980411940
9805
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
980611942 continue;
980711943
9808
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
980911945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
981011947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9811
- textures.get(tex).texture.dispose();
9812
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
981311961 }
981411962 }
981511963 }
981611964
981711965 checker = null;
981811966
9819
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11967
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
982011968 FindChecker(object);
982111969
9822
- if (checker != null && drawMode == DEFAULT)
11970
+ if (checker != null && DrawMode() == DEFAULT)
982311971 {
9824
- // BindTexture(IMMORTAL_TEXTURE);
11972
+ //BindTexture(IMMORTAL_TEXTURE);
11973
+ try
11974
+ {
11975
+ BindTextures(checker.GetTextures(), checker.texres);
11976
+ }
11977
+ catch (Exception e)
11978
+ {
11979
+ System.err.println("FAILED: " + checker.GetTextures());
11980
+ }
982511981 // NEAREST
982611982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
982711983 DrawChecker(gl);
982811984 //checker.Draw(this, null, false);
982911985 // ReleaseTexture(IMMORTAL_TEXTURE);
11986
+ ReleaseTextures(checker.GetTextures());
983011987 }
983111988
983211989 if (object.parent != null)
....@@ -9839,7 +11996,7 @@
983911996 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
984011997 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
984111998
9842
- if (DISPLAYTEXT && drawMode == DEFAULT)
11999
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
984312000 {
984412001 // Draw it once, then use the raster
984512002 Balloon(gl, balloon.createGraphics());
....@@ -9895,14 +12052,14 @@
989512052 int[] xs = new int[3];
989612053 int[] ys = new int[3];
989712054
9898
- void DrawString(Object3D obj) // String string)
12055
+ public void DrawString(Object3D obj) // String string) // INTERFACE
989912056 {
9900
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12057
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
990112058 {
990212059 return;
990312060 }
990412061
9905
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
990612063
990712064 GL gl = GetGL();
990812065
....@@ -10219,8 +12376,8 @@
1021912376 //obj.TransformToWorld(light, light);
1022012377 for (int i = tp.size(); --i >= 0;)
1022112378 {
10222
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10223
- LA.xformPos(light, tp.get(i).toParent, light);
12379
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1022412381 }
1022512382
1022612383
....@@ -10237,8 +12394,8 @@
1023712394 parentcam = cameras[0];
1023812395 }
1023912396
10240
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10241
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12397
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1024212399
1024312400 LA.xformPos(light, renderCamera.toScreen, light);
1024412401
....@@ -10328,8 +12485,76 @@
1032812485
1032912486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1033012487
10331
- String program =
12488
+ String programmin =
12489
+ // Min shader
1033212490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1033312558 //"OPTION ARB_fragment_program_shadow;" +
1033412559 "PARAM light2cam0 = program.env[10];" +
1033512560 "PARAM light2cam1 = program.env[11];" +
....@@ -10357,11 +12582,13 @@
1035712582 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1035812583 "PARAM params7 = program.env[7];" + // noise power, opacity power
1035912584 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10360
- "PARAM options1 = program.env[62];" + // fog rgb color, image intensity
12585
+ "PARAM options1 = program.env[62];" + // fog rgb color
12586
+ "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
1036112587 "PARAM pointlight = program.env[127];" + // ...
1036212588 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1036312589 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1036412590 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12591
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1036512592 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1036612593 "PARAM ten = { 10, 10, 10, 1.0 };" +
1036712594 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10382,6 +12609,7 @@
1038212609 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1038312610 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1038412611 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12612
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1038512613 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1038612614 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1038712615 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10422,6 +12650,10 @@
1042212650 "TEMP R1;" +
1042312651 "TEMP R2;" +
1042412652 "TEMP R3;" +
12653
+ "TEMP min;" +
12654
+ "TEMP max;" +
12655
+ "TEMP average;" +
12656
+ "TEMP saturation;" +
1042512657 "TEMP keep1;" +
1042612658 "TEMP keep2;" +
1042712659 "TEMP keep3;" +
....@@ -10437,8 +12669,7 @@
1043712669 "TEMP shininess;" +
1043812670 "\n" +
1043912671 "MOV texSamp, one;" +
10440
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10441
-
12672
+
1044212673 "MOV mapgrid.x, one2048th.x;" +
1044312674 "MOV temp, fragment.texcoord[1];" +
1044412675 /*
....@@ -10459,20 +12690,20 @@
1045912690 "MUL temp, floor, mapgrid.x;" +
1046012691 //"TEX depth0, temp, texture[1], 2D;" +
1046112692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10462
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1046312694 "") +
1046412695 "ADD temp.x, temp.x, mapgrid.x;" +
1046512696 //"TEX depth1, temp, texture[1], 2D;" +
1046612697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10467
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1046812699 "") +
1046912700 "ADD temp.y, temp.y, mapgrid.x;" +
1047012701 //"TEX depth2, temp, texture[1], 2D;" +
10471
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1047212703 "SUB temp.x, temp.x, mapgrid.x;" +
1047312704 //"TEX depth3, temp, texture[1], 2D;" +
1047412705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10475
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1047612707 "") +
1047712708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1047812709 //"MOV params, material;" +
....@@ -10843,10 +13074,10 @@
1084313074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1084413075 "") +
1084513076
10846
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1084713078 "SUB temp.x, half.x, shadow.x;" +
10848
- "MOV temp.y, -params6.x;" +
10849
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1085013081 "SUB temp.y, one.x, temp.z;" +
1085113082 "MUL temp.x, temp.x, temp.y;" +
1085213083 "KIL temp.x;" +
....@@ -10952,10 +13183,42 @@
1095213183
1095313184 // skin?
1095413185 // Saturation for skin
10955
- /**/ // c'est ici
10956
- (Skinshader? "DP3 temp.x, final,one;" +
13186
+ /**/
13187
+ (Skinshader?
13188
+ "DP3 average.x, final,one;" +
13189
+ "MUL average, one3rd.xxxx,average.xxxx;" +
13190
+
13191
+ "MIN min.x, final.x,final.y;" +
13192
+ "MIN min.x, min.x,final.z;" +
13193
+
13194
+ "MAX max.x, final.x,final.y;" +
13195
+ "MAX max.x, max.x,final.z;" +
13196
+ "MOV max, max.xxxx;" +
13197
+
13198
+ "SUB saturation, max, final;" +
13199
+
13200
+ "ADD temp.x, max.x, one10th.x;" +
13201
+ "RCP temp.x, temp.x;" +
13202
+ "MUL temp.x, temp.x, half.x;" +
13203
+ "MUL saturation, saturation, temp.xxxx;" +
13204
+
13205
+ "DP3 ndotl.x, normald, light;" +
13206
+ "MAX ndotl.x, ndotl.x, -ndotl.x;" +
13207
+
13208
+ "SUB temp.x, one.x, ndotl.x;" +
13209
+ // Tuning for default skin
13210
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13211
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13212
+ "ADD temp.y, one.y, options2.y;" + // subsurface
13213
+ "MUL temp.x, temp.x, temp.y;" +
13214
+
13215
+ "MUL saturation, saturation, temp.xxxx;" +
13216
+ "SUB_SAT temp, max, saturation;" +
13217
+/**
13218
+ "DP3 temp.x, final,one;" +
1095713219 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10958
- "SUB temp, final,R2;" +
13220
+ "SUB temp, final, R2;" +
13221
+
1095913222 // using light angle
1096013223 "DP3 ndotl.x, normald,light;" +
1096113224 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10968,7 +13231,6 @@
1096813231 // using light intensity
1096913232 "MOV ndotl.z, R2.x;" +
1097013233 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10971
-
1097213234 // june 2014
1097313235 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1097413236 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10980,6 +13242,7 @@
1098013242 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1098113243
1098213244 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13245
+/**/
1098313246
1098413247 // "ADD final, R2,temp;" +
1098513248 "MOV final, temp;"
....@@ -11069,7 +13332,7 @@
1106913332 /**/
1107013333 // HDR
1107113334 "MOV temp.z, final.a;" +
11072
- "MUL final, final,options1.w;" +
13335
+ "MUL final, final,options2.x;" +
1107313336 "MOV final.a, temp.z;" +
1107413337 /**/
1107513338
....@@ -11145,7 +13408,14 @@
1114513408 //once = true;
1114613409 }
1114713410
11148
- System.out.print("Program #" + mode + "; length = " + program.length());
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
13418
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1114913419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1115013420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1115113421
....@@ -11238,30 +13508,32 @@
1123813508 return out;
1123913509 }
1124013510
11241
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1124213513 {
1124313514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1124413515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1124513516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1124613519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1125113522 //"SWZ buffer, temp, w,w,w,w;";
11252
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1125313524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1125413525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1125513526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11256
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1125713528
11258
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11259
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1126013531 }
1126113532
1126213533 String Shadow(String depth, String shadow)
1126313534 {
1126413535 return "MAX temp.x, ndotl.x, one64th.x;" +
13536
+ "MIN temp.x, temp.x, ninetenth.x;" +
1126513537 /**/
1126613538 // Sine
1126713539 "MUL temp.y, temp.x, temp.x;" +
....@@ -11277,12 +13549,16 @@
1127713549
1127813550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1127913551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1128013554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1128113555 "SGE temp.y, temp.x, zero.x;" +
11282
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1128313559 "SUB temp.x, one.x, temp.x;" +
1128413560 "MUL " + shadow + ".x, temp.x, temp.y;" +
11285
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1128613562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1128713563
1128813564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11296,6 +13572,10 @@
1129613572 // No shadow for backface
1129713573 "DP3 temp.x, normal, lightd;" +
1129813574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13575
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13576
+
13577
+ // No shadow when out of frustum
13578
+ "SGE temp.x, " + depth + ".z, one.z;" +
1129913579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1130013580 "";
1130113581 }
....@@ -11442,7 +13722,8 @@
1144213722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1144313723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1144413724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11445
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1144613727
1144713728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1144813729 // OUT : diff, spec
....@@ -11458,9 +13739,10 @@
1145813739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1145913740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1146013741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1146413746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1146513747 "RCP " + dest + ".w," + dest + ".w;" +
1146613748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11854,7 +14136,7 @@
1185414136 public void mousePressed(MouseEvent e)
1185514137 {
1185614138 //System.out.println("mousePressed: " + e);
11857
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1185814140 }
1185914141
1186014142 static long prevtime = 0;
....@@ -11881,14 +14163,16 @@
1188114163
1188214164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1188314165
14166
+ if (BUTTONLESSWHEEL)
1188414167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1188514168 {
1188614169 return;
1188714170 }
1188814171
14172
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1188914173
1189014174 // TIMER
11891
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1189214176 {
1189314177 keepboxmode = BOXMODE;
1189414178 keepsupport = SUPPORT;
....@@ -11928,8 +14212,8 @@
1192814212 // mode |= META;
1192914213 //}
1193014214
11931
- SetMouseMode(WHEEL | e.getModifiersEx());
11932
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1193314217 anchorX = ax;
1193414218 anchorY = ay;
1193514219 prevX = px;
....@@ -11963,6 +14247,7 @@
1196314247 else
1196414248 if (evt.getSource() == AAtimer)
1196514249 {
14250
+ Globals.TIMERRUNNING = false;
1196614251 if (mouseDown)
1196714252 {
1196814253 //new Exception().printStackTrace();
....@@ -11988,6 +14273,10 @@
1198814273 // LIVE = waslive;
1198914274 // wasliveok = true;
1199014275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1199114280
1199214281 // source == timer
1199314282 if (mouseDown)
....@@ -12017,8 +14306,8 @@
1201714306 // ObjEditor.tweenManager.update(1f / 60f);
1201814307
1201914308 // fev 2014???
12020
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12021
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14309
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1202214311 pingthread.StepToTarget(true); // true);
1202314312 }
1202414313 // if (!LIVE)
....@@ -12027,12 +14316,13 @@
1202714316
1202814317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1202914318
12030
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1203114320 {
1203214321 if (!wasliveok)
1203314322 return;
1203414323
1203514324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1203614326
1203714327 // waslive = LIVE;
1203814328 // LIVE = false;
....@@ -12044,7 +14334,7 @@
1204414334 // touched = true; // main DL
1204514335 if (isRenderer)
1204614336 {
12047
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1204814338 }
1204914339
1205014340 selectX = anchorX = x;
....@@ -12057,7 +14347,7 @@
1205714347 clicked = true;
1205814348 hold = false;
1205914349
12060
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1206114351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1206214352 {
1206314353 // System.out.println("RESTART II " + modifiers);
....@@ -12082,14 +14372,15 @@
1208214372 drag = false;
1208314373 //System.out.println("Mouse DOWN");
1208414374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1209314384 if (!editObj)
1209414385 {
1209514386 hasMarquee = true;
....@@ -12105,11 +14396,14 @@
1210514396
1210614397 public void mouseDragged(MouseEvent e)
1210714398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1210814402 if (isRenderer)
1210914403 movingcamera = true;
14404
+
1211014405 //if (drawing)
1211114406 //return;
12112
- //System.out.println("mouseDragged: " + e);
1211314407 if ((e.getModifiersEx() & CTRL) != 0
1211414408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1211514409 {
....@@ -12117,7 +14411,7 @@
1211714411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1211814412 }
1211914413 else
12120
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1212114415
1212214416 //try { Thread.sleep(1); } catch (Exception ex) {}
1212314417 }
....@@ -12129,6 +14423,11 @@
1212914423 cVector tmp = new cVector();
1213014424 cVector tmp2 = new cVector();
1213114425 boolean isMoving;
14426
+
14427
+ public cVector TargetLookAt()
14428
+ {
14429
+ return targetLookAt;
14430
+ }
1213214431
1213314432 class PingThread extends Thread
1213414433 {
....@@ -12268,7 +14567,7 @@
1226814567 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1226914568 if (lightMode)
1227014569 {
12271
- lighttouched = true;
14570
+ Globals.lighttouched = true;
1227214571 }
1227314572
1227414573 if (OEILONCE && OEIL)
....@@ -12285,6 +14584,7 @@
1228514584
1228614585 public void run()
1228714586 {
14587
+ new Exception().printStackTrace();
1228814588 System.exit(0);
1228914589 for (;;)
1229014590 {
....@@ -12326,7 +14626,7 @@
1232614626 mouseDown = false;
1232714627 if (lightMode)
1232814628 {
12329
- lighttouched = true;
14629
+ Globals.lighttouched = true;
1233014630 }
1233114631 repaint();
1233214632 alreadypainted = true;
....@@ -12334,7 +14634,7 @@
1233414634 isMoving = false;
1233514635 } //??
1233614636
12337
- if (isLIVE() && !alreadypainted)
14637
+ if (Globals.isLIVE() && !alreadypainted)
1233814638 {
1233914639 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1234014640 repaint();
....@@ -12346,9 +14646,9 @@
1234614646 {
1234714647 if (lightMode)
1234814648 {
12349
- lighttouched = true;
14649
+ Globals.lighttouched = true;
1235014650 }
12351
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1235214652 }
1235314653 //else
1235414654 }
....@@ -12362,12 +14662,12 @@
1236214662 void GoDown(int mod)
1236314663 {
1236414664 MODIFIERS |= COMMAND;
12365
- /*
14665
+ /**/
1236614666 if((mod&SHIFT) == SHIFT)
12367
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1236814668 else
12369
- manipCamera.BackForth(0, -speed*delta, getWidth());
12370
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1237114671 if ((mod & SHIFT) == SHIFT)
1237214672 {
1237314673 mouseMode = mouseMode; // VR??
....@@ -12383,12 +14683,12 @@
1238314683 void GoUp(int mod)
1238414684 {
1238514685 MODIFIERS |= COMMAND;
12386
- /*
14686
+ /**/
1238714687 if((mod&SHIFT) == SHIFT)
12388
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1238914689 else
12390
- manipCamera.BackForth(0, speed*delta, getWidth());
12391
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1239214692 if ((mod & SHIFT) == SHIFT)
1239314693 {
1239414694 mouseMode = mouseMode;
....@@ -12404,12 +14704,12 @@
1240414704 void GoLeft(int mod)
1240514705 {
1240614706 MODIFIERS |= COMMAND;
12407
- /*
14707
+ /**/
1240814708 if((mod&SHIFT) == SHIFT)
12409
- manipCamera.RotatePosition(speed, 0);
12410
- else
1241114709 manipCamera.Translate(speed*delta, 0, getWidth());
12412
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1241314713 if ((mod & SHIFT) == SHIFT)
1241414714 {
1241514715 mouseMode = mouseMode;
....@@ -12425,12 +14725,12 @@
1242514725 void GoRight(int mod)
1242614726 {
1242714727 MODIFIERS |= COMMAND;
12428
- /*
14728
+ /**/
1242914729 if((mod&SHIFT) == SHIFT)
12430
- manipCamera.RotatePosition(-speed, 0);
12431
- else
1243214730 manipCamera.Translate(-speed*delta, 0, getWidth());
12433
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1243414734 if ((mod & SHIFT) == SHIFT)
1243514735 {
1243614736 mouseMode = mouseMode;
....@@ -12448,7 +14748,7 @@
1244814748 int X, Y;
1244914749 boolean SX, SY;
1245014750
12451
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1245214752 {
1245314753 if (IsFrozen())
1245414754 {
....@@ -12457,17 +14757,17 @@
1245714757
1245814758 drag = true; // NEW
1245914759
12460
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1246114761
1246214762 X = x;
1246314763 Y = y;
1246414764 // floating state for animation
12465
- MODIFIERS = modifiers;
12466
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1246714767 if (false) // modifiers != 0)
1246814768 {
1246914769 //new Exception().printStackTrace();
12470
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1247114771 System.out.println("SHIFT = " + SHIFT);
1247214772 System.out.println("CONTROL = " + COMMAND);
1247314773 System.out.println("META = " + META);
....@@ -12480,14 +14780,16 @@
1248014780 if (editObj)
1248114781 {
1248214782 drag = true;
12483
- ClickInfo info = new ClickInfo();
12484
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1248514785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1249114793 } else
1249214794 {
1249314795 if (x < startX)
....@@ -12589,6 +14891,7 @@
1258914891 {
1259014892 manipCamera.Translate(dx, dy, getWidth());
1259114893 }
14894
+ else
1259214895 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1259314896 {
1259414897 manipCamera.RotateInterest(dx, dy);
....@@ -12599,7 +14902,7 @@
1259914902
1260014903 if (manipCamera == lightCamera)
1260114904 {
12602
- lighttouched = true;
14905
+ Globals.lighttouched = true;
1260314906 }
1260414907 /*
1260514908 switch (mode)
....@@ -12635,23 +14938,27 @@
1263514938 }
1263614939 }
1263714940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1263814943 public void mouseMoved(MouseEvent e)
1263914944 {
1264014945 //System.out.println("mouseMoved: " + e);
12641
-
1264214946 if (isRenderer)
1264314947 return;
1264414948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1265214956 if (!isRenderer)
1265314957 {
12654
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1265514962 {
1265614963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1265714964 } else
....@@ -12663,7 +14970,11 @@
1266314970
1266414971 public void mouseReleased(MouseEvent e)
1266514972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1266614975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1266714978 //System.out.println("mouseReleased: " + e);
1266814979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1266914980 }
....@@ -12686,9 +14997,9 @@
1268614997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1268714998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1268814999
12689
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1269015001 timeout = true;
12691
- else
15002
+// ?? May 2019 else
1269215003 // timer.setDelay((modifiers & 128) != 0?0:350);
1269315004 mouseDown = false;
1269415005 if (!control && !command) // june 2013
....@@ -12798,7 +15109,7 @@
1279815109 System.out.println("keyReleased: " + e);
1279915110 }
1280015111
12801
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1280215113 {
1280315114 //System.out.println("SetMouseMode = " + modifiers);
1280415115 //modifiers &= ~1024;
....@@ -12810,24 +15121,27 @@
1281015121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1281115122 // return;
1281215123 //System.out.println("SetMode = " + modifiers);
12813
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1281415125 {
1281515126 mouseMode |= ZOOM;
1281615127 }
12817
- if ((modifiers & META) == META)
15128
+
15129
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15130
+ if (capsLocked) // || (modifiers & META) == META)
1281815131 {
1281915132 mouseMode |= VR; // BACKFORTH;
1282015133 }
12821
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12822
- {
12823
- mouseMode |= SELECT; // BACKFORTH;
12824
- }
12825
- if ((modifiers & COMMAND) == COMMAND)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1282615135 {
1282715136 mouseMode |= SELECT;
1282815137 }
12829
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1283015139 {
15140
+ mouseMode |= SELECT;
15141
+ }
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15143
+ {
15144
+ mouseMode &= ~VR;
1283115145 mouseMode |= TRANSLATE;
1283215146 }
1283315147 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12854,10 +15168,10 @@
1285415168
1285515169 if (isRenderer) //
1285615170 {
12857
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1285815172 }
1285915173
12860
- theRenderer.keyPressed(key);
15174
+ Globals.theRenderer.keyPressed(key);
1286115175 }
1286215176
1286315177 int kompactbit = 4; // power bit
....@@ -12869,7 +15183,7 @@
1286915183 float SATPOW = 1; // 2; // 0.5f;
1287015184 float BRIPOW = 1; // 0.5f; // 0.5f;
1287115185
12872
- void keyPressed(int key)
15186
+ public void keyPressed(int key)
1287315187 {
1287415188 if (key >= '0' && key <= '5')
1287515189 clampbit = (key-'0');
....@@ -12916,7 +15230,8 @@
1291615230 // break;
1291715231 case 'T':
1291815232 CACHETEXTURE ^= true;
12919
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1292015235 // repaint();
1292115236 break;
1292215237 case 'Y':
....@@ -12984,7 +15299,7 @@
1298415299 case 'B':
1298515300 BRISMOOTH ^= true;
1298615301 SHADOWCULLFACE ^= true;
12987
- lighttouched = true;
15302
+ Globals.lighttouched = true;
1298815303 repaint();
1298915304 break;
1299015305 case 'b':
....@@ -13001,7 +15316,9 @@
1300115316 case 'E' : COMPACT ^= true;
1300215317 repaint();
1300315318 break;
13004
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1300515322 repaint();
1300615323 break;
1300715324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13026,8 +15343,8 @@
1302615343 RevertCamera();
1302715344 repaint();
1302815345 break;
13029
- case 'L':
1303015346 case 'l':
15347
+ //case 'L':
1303115348 if (lightMode)
1303215349 {
1303315350 lightMode = false;
....@@ -13084,27 +15401,31 @@
1308415401 repaint();
1308515402 break;
1308615403 case 'O':
13087
- drawMode = OCCLUSION;
15404
+ Globals.drawMode = OCCLUSION; // WARNING
1308815405 repaint();
1308915406 break;
1309015407 case 'o':
1309115408 OCCLUSION_CULLING ^= true;
1309215409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1309315410 break;
13094
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1309515412 case '1':
1309615413 case '2':
1309715414 case '3':
1309815415 case '4':
1309915416 case '5':
13100
- newenvy = Character.getNumericValue(key);
13101
- repaint();
13102
- break;
1310315417 case '6':
1310415418 case '7':
1310515419 case '8':
1310615420 case '9':
13107
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1310815429 repaint();
1310915430 break;
1311015431 case '!':
....@@ -13170,12 +15491,12 @@
1317015491 case '_':
1317115492 kompactbit = 5;
1317215493 break;
13173
- case '+':
13174
- kompactbit = 6;
13175
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1317615497 case ' ':
1317715498 lightMode ^= true;
13178
- lighttouched = true;
15499
+ Globals.lighttouched = true;
1317915500 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1318015501 targetLookAt.set(manipCamera.lookAt);
1318115502 repaint();
....@@ -13184,14 +15505,15 @@
1318415505 case ESC:
1318515506 RENDERPROGRAM += 1;
1318615507 RENDERPROGRAM %= 3;
15508
+
1318715509 repaint();
1318815510 break;
1318915511 case 'Z':
13190
- RESIZETEXTURE ^= true;
13191
- break;
15512
+ //RESIZETEXTURE ^= true;
15513
+ //break;
1319215514 case 'z':
13193
- RENDERSHADOW ^= true;
13194
- lighttouched = true;
15515
+ Globals.RENDERSHADOW ^= true;
15516
+ Globals.lighttouched = true;
1319515517 repaint();
1319615518 break;
1319715519 //case UP:
....@@ -13217,13 +15539,15 @@
1321715539 FlipTransform();
1321815540 break;
1321915541 case ENTER:
13220
- object.editWindow.ScreenFit(); // Edit();
15542
+ // object.editWindow.ScreenFit(); // Edit();
15543
+ ToggleLive();
1322115544 break;
1322215545 case DELETE:
1322315546 ClearSelection();
1322415547 break;
13225
- /*
1322615548 case '+':
15549
+
15550
+ /*
1322715551 //fontsize += 1;
1322815552 bbzoom *= 2;
1322915553 repaint();
....@@ -13240,17 +15564,17 @@
1324015564 case '=':
1324115565 IncDepth();
1324215566 //fontsize += 1;
13243
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1324415568 maskbit = 6;
1324515569 break;
1324615570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1324715571 DecDepth();
1324815572 maskbit = 5;
1324915573 //if(fontsize > 1) fontsize -= 1;
13250
- if (object.editWindow == null)
13251
- new Exception().printStackTrace();
13252
- else
13253
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1325415578 break;
1325515579 case '{':
1325615580 manipCamera.shaper_fovy /= 1.1;
....@@ -13305,6 +15629,7 @@
1330515629 }
1330615630 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1330715631 }
15632
+
1330815633 static double OCCLUSIONBOOST = 1; // 0.5;
1330915634
1331015635 void keyReleased(int key, int modifiers)
....@@ -13312,11 +15637,11 @@
1331215637 //mode = ROTATE;
1331315638 if ((MODIFIERS & COMMAND) == 0) // VR??
1331415639 {
13315
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1331615641 }
1331715642 }
1331815643
13319
- protected void processKeyEvent(KeyEvent e)
15644
+ public void processKeyEvent(KeyEvent e)
1332015645 {
1332115646 switch (e.getID())
1332215647 {
....@@ -13446,8 +15771,9 @@
1344615771
1344715772 protected void processMouseMotionEvent(MouseEvent e)
1344815773 {
13449
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13450
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15774
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15775
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1345115777 {
1345215778 mouseMoved(e);
1345315779 } else
....@@ -13472,11 +15798,12 @@
1347215798 }
1347315799 */
1347415800
13475
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1347615802 }
1347715803
1347815804 void SelectParent()
1347915805 {
15806
+ new Exception().printStackTrace();
1348015807 System.exit(0);
1348115808 Composite group = (Composite) object;
1348215809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13488,10 +15815,10 @@
1348815815 {
1348915816 //selectees.remove(i);
1349015817 System.out.println("select parent of " + elem);
13491
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1349215819 } else
1349315820 {
13494
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1349515822 }
1349615823
1349715824 first = false;
....@@ -13500,6 +15827,7 @@
1350015827
1350115828 void SelectChildren()
1350215829 {
15830
+ new Exception().printStackTrace();
1350315831 System.exit(0);
1350415832 /*
1350515833 Composite group = (Composite) object;
....@@ -13532,12 +15860,12 @@
1353215860 for (int j = 0; j < group.children.size(); j++)
1353315861 {
1353415862 elem = (Object3D) group.children.elementAt(j);
13535
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1353615864 first = false;
1353715865 }
1353815866 } else
1353915867 {
13540
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1354115869 }
1354215870
1354315871 first = false;
....@@ -13548,21 +15876,21 @@
1354815876 {
1354915877 //Composite group = (Composite) object;
1355015878 Object3D group = object;
13551
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1355215880 }
1355315881
1355415882 void ResetTransform(int mask)
1355515883 {
1355615884 //Composite group = (Composite) object;
1355715885 Object3D group = object;
13558
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1355915887 }
1356015888
1356115889 void FlipTransform()
1356215890 {
1356315891 //Composite group = (Composite) object;
1356415892 Object3D group = object;
13565
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1356615894 // group.editWindow.ReduceMesh(true);
1356715895 }
1356815896
....@@ -13570,7 +15898,7 @@
1357015898 {
1357115899 //Composite group = (Composite) object;
1357215900 Object3D group = object;
13573
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1357415902 // group.editWindow.ReduceMesh(true);
1357515903 }
1357615904
....@@ -13578,7 +15906,7 @@
1357815906 {
1357915907 //Composite group = (Composite) object;
1358015908 Object3D group = object;
13581
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1358215910 }
1358315911
1358415912 void IncDepth()
....@@ -13660,11 +15988,11 @@
1366015988
1366115989 int width = getBounds().width;
1366215990 int height = getBounds().height;
13663
- ClickInfo info = new ClickInfo();
13664
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1366515991 //Image img = CreateImage(width, height);
1366615992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1366715994 Graphics gr = g; // img.getGraphics();
15995
+
1366815996 if (!hasMarquee)
1366915997 {
1367015998 if (Xmin < Xmax) // !locked)
....@@ -13736,40 +16064,88 @@
1373616064 }
1373716065 if (object != null && !hasMarquee)
1373816066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1373916073 if (isRenderer)
1374016074 {
13741
- info.flags++;
16075
+ object.clickInfo.flags++;
1374216076 double frameAspect = (double) width / (double) height;
1374316077 if (frameAspect > renderCamera.aspect)
1374416078 {
1374516079 int desired = (int) ((double) height * renderCamera.aspect);
13746
- info.bounds.width -= width - desired;
13747
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1374816082 } else
1374916083 {
1375016084 int desired = (int) ((double) width / renderCamera.aspect);
13751
- info.bounds.height -= height - desired;
13752
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1375316087 }
1375416088 }
13755
- info.g = gr;
13756
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1375716092 /*
1375816093 // Memory intensive (brep.verticescopy)
1375916094 if (!(object instanceof Composite))
1376016095 object.draw(info, 0, false); // SLOW :
1376116096 */
13762
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1376316098 {
13764
- object.drawEditHandles(info, 0);
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
16102
+ {
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
16109
+ {
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
16117
+ }
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
16138
+ }
1376516139 }
1376616140 }
16141
+
1376716142 if (isRenderer)
1376816143 {
1376916144 //gr.setColor(Color.black);
1377016145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1377116146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1377216147 }
16148
+
1377316149 if (hasMarquee)
1377416150 {
1377516151 gr.setXORMode(Color.white);
....@@ -13792,6 +16168,7 @@
1379216168 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1379316169 }
1379416170
16171
+ // To avoid clear.
1379516172 public void update(Graphics g)
1379616173 {
1379716174 paint(g);
....@@ -13881,6 +16258,7 @@
1388116258 public boolean mouseDown(Event evt, int x, int y)
1388216259 {
1388316260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1388416262 /*
1388516263 locked = true;
1388616264 drag = false;
....@@ -13924,7 +16302,7 @@
1392416302 {
1392516303 keyPressed(0, modifiers);
1392616304 }
13927
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1392816306 return true;
1392916307 }
1393016308
....@@ -14042,7 +16420,7 @@
1404216420 {
1404316421 keyReleased(0, 0);
1404416422 }
14045
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1404616424 return true;
1404716425 }
1404816426
....@@ -14174,7 +16552,7 @@
1417416552 Object3D object;
1417516553 static Object3D trackedobject;
1417616554 Camera renderCamera; // Light or Eye (or Occlusion)
14177
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1417816556 /*static*/ Camera eyeCamera;
1417916557 /*static*/ Camera lightCamera;
1418016558 int cameracount;
....@@ -14238,6 +16616,8 @@
1423816616 private /*static*/ boolean firstime;
1423916617 private /*static*/ cVector newView = new cVector();
1424016618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1424116621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1424216622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1424316623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14250,29 +16630,67 @@
1425016630 {
1425116631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1425216632
16633
+ int usedsuf = 0;
16634
+
1425316635 for (int i = 0; i < suffixes.length; i++)
1425416636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1426016642 {
14261
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1426216647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1426316676 //System.out.println("Target = " + targets[i]);
1426416677 cubemap.updateImage(data, targets[i]);
1426516678 }
1426616679
1426716680 return cubemap;
1426816681 }
16682
+
1426916683 int bigsphere = -1;
1427016684
1427116685 float BGcolor = 0.5f;
1427216686
14273
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1427416690 {
14275
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1427616694 {
1427716695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1427816696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14287,7 +16705,17 @@
1428716705 // Compensates for ExaminerViewer's modification of modelview matrix
1428816706 gl.glMatrixMode(GL.GL_MODELVIEW);
1428916707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1429016709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1429116719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1429216720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1429316721
....@@ -14319,6 +16747,7 @@
1431916747 {
1432016748 gl.glScalef(1.0f, -1.0f, 1.0f);
1432116749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1432216751 gl.glMultMatrixd(viewrot_1, 0);
1432316752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1432416753 //viewer.updateInverseRotation(gl);
....@@ -14394,7 +16823,7 @@
1439416823 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1439516824 gl.glPushMatrix();
1439616825 gl.glLoadIdentity();
14397
- PushMatrix(checker.toParent);
16826
+ //PushMatrix(checker.toParent);
1439816827
1439916828 gl.glMatrixMode(GL.GL_TEXTURE);
1440016829 gl.glPushMatrix();
....@@ -14417,8 +16846,8 @@
1441716846
1441816847 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1441916848
14420
- float step = 0.1666f; //0.25f;
14421
- float stepv = step * 1652 / 998;
16849
+ float step = 2; // 0.1666f; //0.25f;
16850
+ float stepv = 2; // step * 1652 / 998;
1442216851
1442316852 int i0 = 0;
1442416853 /*
....@@ -14454,20 +16883,21 @@
1445416883 /**/
1445516884 //checker.GetMaterial().opacity = 1.1f;
1445616885 ////checker.GetMaterial().ambient = 0.99f;
14457
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14458
- Object3D.selectedstack[Object3D.materialdepth] = false;
14459
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16886
+ materialstack[materialdepth] = checker.material;
16887
+ selectedstack[materialdepth] = false;
16888
+ cStatic.objectstack[materialdepth++] = checker;
1446016889 //System.out.println("material " + material);
1446116890 //Applet3D.tracein(this, selected);
14462
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1446316892
14464
- checker.GetMaterial().Draw(this, false); // true);
16893
+ //checker.GetMaterial().Draw(this, false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1446516895
14466
- Object3D.materialdepth -= 1;
14467
- if (Object3D.materialdepth > 0)
16896
+ materialdepth -= 1;
16897
+ if (materialdepth > 0)
1446816898 {
14469
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14470
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1447116901 }
1447216902 //checker.GetMaterial().opacity = 1f;
1447316903 ////checker.GetMaterial().ambient = 1f;
....@@ -14488,15 +16918,27 @@
1448816918
1448916919 //float u = (i+1)/2;
1449016920 //float v = (j+1)/2;
14491
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16921
+ if (checker.flipV)
16922
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16923
+ else
16924
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1449216925 gl.glVertex3f(i, j, -0.5f);
1449316926
16927
+ if (checker.flipV)
16928
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16929
+ else
1449416930 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1449516931 gl.glVertex3f(i + step, j, -0.5f);
1449616932
16933
+ if (checker.flipV)
16934
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16935
+ else
1449716936 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1449816937 gl.glVertex3f(i + step, j + stepv, -0.5f);
1449916938
16939
+ if (checker.flipV)
16940
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16941
+ else
1450016942 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1450116943 gl.glVertex3f(i, j + stepv, -0.5f);
1450216944 }
....@@ -14508,7 +16950,7 @@
1450816950 gl.glMatrixMode(GL.GL_PROJECTION);
1450916951 gl.glPopMatrix();
1451016952 gl.glMatrixMode(GL.GL_MODELVIEW);
14511
- PopMatrix(null); // checker.toParent); // null);
16953
+ //PopMatrix(null); // checker.toParent); // null);
1451216954 gl.glPopMatrix();
1451316955 PopTextureMatrix(checker.toParent);
1451416956 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14541,6 +16983,14 @@
1454116983 }
1454216984 }
1454316985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1454416994 class SelectBuffer implements GLEventListener
1454516995 {
1454616996
....@@ -14556,7 +17006,7 @@
1455617006 //new Exception().printStackTrace();
1455717007 System.out.println("select buffer init");
1455817008 // Use debug pipeline
14559
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1456017010
1456117011 GL gl = drawable.getGL();
1456217012
....@@ -14599,6 +17049,7 @@
1459917049 {
1460017050 if (!selection)
1460117051 {
17052
+ new Exception().printStackTrace();
1460217053 System.exit(0);
1460317054 return;
1460417055 }
....@@ -14619,17 +17070,39 @@
1461917070
1462017071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1462117072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1462217084 //int tmp = selection_view;
1462317085 //selection_view = -1;
14624
- int temp = drawMode;
14625
- drawMode = SELECTION;
17086
+ int temp = DrawMode();
17087
+ Globals.drawMode = SELECTION; // WARNING
1462617088 indexcount = 0;
1462717089 parent.display(drawable);
1462817090 //selection_view = tmp;
1462917091 //if (temp == SELECTION)
1463017092 // temp = DEFAULT; // patch for selection debug
14631
- drawMode = temp;
17093
+ Globals.drawMode = temp; // WARNING
1463217094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1463317106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1463417107
1463517108 // trying different ways of getting the depth info over
....@@ -14678,6 +17151,13 @@
1467817151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1467917152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1468017153
17154
+ CreateSelectedPoint();
17155
+
17156
+ // Will fit the mesh !!!
17157
+ selectedpoint.toParent[0][0] = 0.0001;
17158
+ selectedpoint.toParent[1][1] = 0.0001;
17159
+ selectedpoint.toParent[2][2] = 0.0001;
17160
+
1468117161 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1468217162
1468317163 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14721,34 +17201,36 @@
1472117201 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]));
1472217202 }
1472317203
14724
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1472517205 }
1472617206 }
1472717207
1472817208 if (!movingcamera && !PAINTMODE)
14729
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1473017210
14731
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1473217212 {
14733
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1473417214
14735
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1473617218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1475217234 }
1475317235 else
1475417236 paintcount = 0;
....@@ -14787,6 +17269,11 @@
1478717269 //System.out.println("objects[color] = " + objects[color]);
1478817270 //objects[color].Select();
1478917271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1479017277 object.Select(color, deselect);
1479117278 }
1479217279
....@@ -14886,7 +17373,7 @@
1488617373 gl.glDisable(gl.GL_CULL_FACE);
1488717374 }
1488817375
14889
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1489017377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1489117378
1489217379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14896,14 +17383,14 @@
1489617383 //gl.glColorMask(false, false, false, false);
1489717384
1489817385 //render_scene_from_light_view(gl, drawable, 0, 0);
14899
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1490017387 {
1490117388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1490217389
14903
- int temp = drawMode;
14904
- drawMode = SHADOW;
17390
+ int temp = DrawMode();
17391
+ Globals.drawMode = SHADOW; // WARNING
1490517392 parent.display(drawable);
14906
- drawMode = temp;
17393
+ Globals.drawMode = temp; // WARNING
1490717394 }
1490817395
1490917396 gl.glCullFace(gl.GL_BACK);
....@@ -14956,7 +17443,6 @@
1495617443
1495717444 class AntialiasBuffer implements GLEventListener
1495817445 {
14959
-
1496017446 CameraPane parent = null;
1496117447
1496217448 AntialiasBuffer(CameraPane p)
....@@ -15066,15 +17552,25 @@
1506617552 gl.glFlush();
1506717553
1506817554 /**/
15069
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1507017556
15071
- int[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1507217558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1507317563 double r = 0, g = 0, b = 0;
1507417564
1507517565 double count = 0;
17566
+
17567
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17568
+
17569
+ float mindepth = 1;
17570
+
17571
+ double FACTOR = 1;
1507617572
15077
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1507817574 {
1507917575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1508017576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15157,7 +17653,7 @@
1515717653
1515817654 double scale = ray.z; // 1; // cos
1515917655
15160
- int p = pixels[newindex];
17656
+ float depth = depths[newindex];
1516117657
1516217658 /*
1516317659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15181,10 +17677,23 @@
1518117677 scale = (1 - modu) * modv;
1518217678 */
1518317679
15184
- r += ((p >> 16) & 0xFF) * scale / 255;
15185
- g += ((p >> 8) & 0xFF) * scale / 255;
15186
- b += (p & 0xFF) * scale / 255;
17680
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17681
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17682
+ //b += (p & 0xFF) * scale / 255;
17683
+
17684
+ if (mindepth > depth)
17685
+ {
17686
+ mindepth = depth;
17687
+ }
1518717688
17689
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17690
+
17691
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17692
+
17693
+ r += factor * scale;
17694
+ g += factor * scale;
17695
+ b += factor * scale;
17696
+
1518817697 count += scale;
1518917698 }
1519017699
....@@ -15282,12 +17791,6 @@
1528217791 GLUT glut = new GLUT();
1528317792
1528417793
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;
1529117794 public boolean spherical = false;
1529217795 static boolean DEBUG_OCCLUSION = false;
1529317796 static boolean DEBUG_SELECTION = false;
....@@ -15300,23 +17803,15 @@
1530017803 int AAbuffersize = 0;
1530117804
1530217805 //double[] selectedpoint = new double[3];
15303
- static Sphere selectedpoint = new Sphere();
17806
+ static Superellipsoid selectedpoint;
1530417807 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();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1530917812
1531017813 static Sphere debugpoints[] = new Sphere[8];
1531117814
15312
- static
15313
- {
15314
- for (int i=0; i<8; i++)
15315
- {
15316
- debugpoints[i] = new Sphere();
15317
- }
15318
- }
15319
-
1532017815 static void InitPoints(float radius)
1532117816 {
1532217817 for (int i=0; i<8; i++)
....@@ -15336,7 +17831,7 @@
1533617831 }
1533717832 }
1533817833
15339
- static void DrawPoints(CameraPane cpane)
17834
+ static void DrawPoints(iCameraPane cpane)
1534017835 {
1534117836 for (int i=0; i<8; i++) // first and last are red
1534217837 {
....@@ -15355,10 +17850,14 @@
1535517850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1535617851 static IntBuffer bigAAbuffer;
1535717852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15358
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1535917854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1536017855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15361
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17856
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1536217861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1536317862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1536417863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15367,10 +17866,11 @@
1536717866 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1536817867 // Depth buffer format
1536917868 //private int depth_format;
15370
- static public void NextIndex(Object3D o, GL gl)
17869
+
17870
+ public void NextIndex()
1537117871 {
1537217872 indexcount+=16;
15373
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17873
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1537417874 //objects[indexcount] = o;
1537517875 //System.out.println("indexcount = " + indexcount);
1537617876 }