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,10 +1935,10 @@
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++;
231
- // GraphreeD.tracein(matrix);
1941
+ // GrafreeD.tracein(matrix);
2321942 if (matrix == null)
2331943 return; // Identity
2341944
....@@ -253,13 +1963,13 @@
2531963
2541964 void PushMatrix(double[][] matrix)
2551965 {
256
- // GraphreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1966
+ // GrafreeD.tracein(matrix);
1967
+ PushMatrix(matrix, 1);
2581968 }
2591969
2601970 void PushMatrix()
2611971 {
262
- // GraphreeD.tracein(null);
1972
+ // GrafreeD.tracein(null);
2631973 if (matrixdepth++ < MAXSTACK - 1)
2641974 {
2651975 currentGL.glPushMatrix();
....@@ -270,11 +1980,11 @@
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
277
- // GraphreeD.traceout(inverse);
1987
+ // GrafreeD.traceout(inverse);
2781988 if (inverse == null)
2791989 return; // Identity
2801990
....@@ -292,7 +2002,7 @@
2922002
2932003 void PopMatrix()
2942004 {
295
- // GraphreeD.traceout(null);
2005
+ // GrafreeD.traceout(null);
2962006 // inverse == null??
2972007 if (--matrixdepth < MAXSTACK - 1)
2982008 {
....@@ -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
- GraphreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
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,39 +2453,59 @@
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 {
7702479 com.sun.opengl.util.texture.Texture texture;
2480
+ com.sun.opengl.util.texture.TextureData texturedata;
2481
+
7712482 int resolution;
7722483
773
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7742485 {
775
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
7762488 resolution = res;
7772489 }
7782490 }
7792491 /**/
7802492
7812493 // TEXTURE static Texture texture;
782
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
783
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
784
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
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
+
7852499 int pigmentdepth = 0;
7862500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7872501 int bumpdepth = 0;
7882502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7892503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7902504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
791
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7922506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7932507
794
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7952509 {
7962510 TextureData texturedata = null;
7972511
....@@ -810,13 +2524,34 @@
8102524 if (bump)
8112525 texturedata = ConvertBump(texturedata, false);
8122526
813
- com.sun.opengl.util.texture.Texture texture =
814
- 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);
8152529
816
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
817
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
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);
8182532
819
- 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;
8202555 }
8212556
8222557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1889,6 +3624,8 @@
18893624
18903625 System.out.println("LOADING TEXTURE : " + name);
18913626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
18923629 //
18933630 if (false) // compressbit > 0)
18943631 {
....@@ -1998,10 +3735,12 @@
19983735 */
19993736 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20003737 {
3738
+ int pixelformat = texturedata.getPixelFormat();
3739
+
20013740 int stride = 1;
2002
- 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)
20033742 stride = 3;
2004
- 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)
20053744 stride = 4;
20063745
20073746 int width = texturedata.getWidth();
....@@ -2591,6 +4330,7 @@
25914330
25924331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25934332 {
4333
+ new Exception().printStackTrace();
25944334 System.exit(0);
25954335 com.sun.opengl.util.texture.Texture texture = null;
25964336
....@@ -6267,7 +8007,7 @@
62678007 return null;
62688008 }
62698009
6270
- void ReleaseTextures(cTexture tex)
8010
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62718011 {
62728012 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62738013 {
....@@ -6284,7 +8024,7 @@
62848024 String pigment = Object3D.GetPigment(tex);
62858025 String bump = Object3D.GetBump(tex);
62868026
6287
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62888028 {
62898029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62908030 // System.out.println("; bump = " + bump);
....@@ -6299,13 +8039,71 @@
62998039 pigment = null;
63008040 }
63018041
6302
- ReleaseTexture(bump, true);
6303
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
63048044 }
63058045
6306
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63078047 {
6308
- 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 ||*/
63098107 ambientOcclusion ) // || !textureon)
63108108 {
63118109 return;
....@@ -6314,7 +8112,7 @@
63148112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63158113
63168114 if (tex != null)
6317
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63188116
63198117 // //assert( texture != null );
63208118 // if (texture == null)
....@@ -6331,7 +8129,7 @@
63318129 {
63328130 bumpdepth--;
63338131
6334
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8132
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63358133 if (bumpstack[bumpdepth] != (texture!=null?texture.texture:null))
63368134 {
63378135 // assert (bumpstack[bumpdepth] == texture);
....@@ -6361,7 +8159,7 @@
63618159 {
63628160 pigmentdepth--;
63638161
6364
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8162
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63658163 if (pigmentstack[pigmentdepth] != (texture!=null?texture.texture:null))
63668164 {
63678165 // assert (pigmentstack[pigmentdepth] == texture);
....@@ -6406,9 +8204,57 @@
64068204 }
64078205 }
64088206
6409
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64108208 {
6411
- 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 ||*/
64128258 ambientOcclusion ) // || !textureon)
64138259 {
64148260 return; // false;
....@@ -6417,17 +8263,47 @@
64178263 if (tex == null)
64188264 {
64198265 BindTexture(null,false,resolution);
6420
- BindTexture(null,true,resolution);
64218266 return;
64228267 }
64238268
64248269 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
+
64258302 String bump = Object3D.GetBump(tex);
64268303
6427
- usedtextures.put(pigment, pigment);
6428
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
64298305
6430
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64318307 {
64328308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64338309 // System.out.println("; bump = " + bump);
....@@ -6437,43 +8313,94 @@
64378313 {
64388314 bump = null;
64398315 }
6440
- if (pigment.equals(""))
6441
- {
6442
- pigment = null;
6443
- }
64448316
6445
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6446
- BindTexture(pigment, false, resolution);
64478317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6448
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
64498319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
-
6451
- return; // true;
64528320 }
64538321
6454
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
64558325 {
6456
- 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;
64578345
64588346 if (tex != null)
64598347 {
6460
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64618350
6462
- String[] split = tex.split("Textures");
6463
- if (split.length > 1)
6464
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6465
- else
6466
- if (!texname.startsWith("/"))
6467
- texname = "/Users/nbriere/Textures/" + texname;
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
+ }
64688368
64698369 if (CACHETEXTURE)
6470
- texture = textures.get(texname); // TEXTURE CACHE
6471
-
6472
- TextureData texturedata = null;
6473
-
6474
- if (texture == null || texture.resolution < resolution)
64758370 {
6476
- 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(""))
64778404 {
64788405 assert(!bump);
64798406 // if (bump)
....@@ -6484,19 +8411,23 @@
64848411 // }
64858412 // else
64868413 // {
6487
- texture = textures.get(tex);
6488
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
64898416 {
6490
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64918418 }
8419
+ else
8420
+ new Exception().printStackTrace();
64928421 // }
64938422 } else
6494
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64958424 {
64968425 assert(bump);
6497
- texture = textures.get(tex);
6498
- if (texture == null)
6499
- 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();
65008431 } else
65018432 {
65028433 //if (tex.equals("IMMORTAL"))
....@@ -6504,11 +8435,22 @@
65048435 // texture = GetResourceTexture("default.png");
65058436 //} else
65068437 //{
6507
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
65088439 {
6509
- texture = textures.get(tex);
6510
- if (texture == null)
6511
- 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();
65128454 } else
65138455 {
65148456 if (textureon)
....@@ -6533,7 +8475,7 @@
65338475 }
65348476
65358477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6536
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
65378479 cachename = texname;
65388480 else
65398481 processbump = false; // don't process bump map again
....@@ -6555,7 +8497,7 @@
65558497 }
65568498
65578499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6558
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
65598501 cachename = texname;
65608502 else
65618503 processbump = false; // don't process bump map again
....@@ -6564,20 +8506,23 @@
65648506 texturedata = GetFileTexture(cachename, processbump, resolution);
65658507
65668508
6567
- if (texturedata != null)
6568
- 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);
65698513 //texture = GetTexture(tex, bump);
65708514 }
8515
+ }
65718516 }
65728517 //}
65738518 }
65748519
6575
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65768521 {
65778522 //return false;
65788523
65798524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6580
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65818526 {
65828527 // String ext = "_highres";
65838528 // if (REDUCETEXTURE)
....@@ -6594,52 +8539,17 @@
65948539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65958540 if (!cachefile.exists())
65968541 {
6597
- // cache to disk
6598
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6599
- //buffers[0].
6600
-
6601
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6602
- int[] pixels = new int[bytebuf.capacity()/3];
6603
-
6604
- // squared size heuristic...
6605
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
66068543 {
6607
- for (int i=pixels.length; --i>=0;)
6608
- {
6609
- int i3 = i*3;
6610
- pixels[i] = 0xFF;
6611
- pixels[i] <<= 8;
6612
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6613
- pixels[i] <<= 8;
6614
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6617
- }
6618
-
6619
- /*
6620
- int r=0,g=0,b=0,a=0;
6621
- for (int i=0; i<width; i++)
6622
- for (int j=0; j<height; j++)
6623
- {
6624
- int index = j*width+i;
6625
- int p = pixels[index];
6626
- a = ((p>>24) & 0xFF);
6627
- r = ((p>>16) & 0xFF);
6628
- g = ((p>>8) & 0xFF);
6629
- b = (p & 0xFF);
6630
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6631
- }
6632
- /**/
6633
- int width = (int)Math.sqrt(pixels.length); // squared
6634
- int height = width;
6635
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6636
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
66378546 ImageWriter writer = null;
66388547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66398548 if (iter.hasNext()) {
66408549 writer = (ImageWriter)iter.next();
66418550 }
6642
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
66438553 try
66448554 {
66458555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6656,16 +8566,20 @@
66568566 }
66578567 }
66588568 }
6659
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
66608572 //System.out.println("Texture = " + tex);
6661
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
66628574 {
6663
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
66648576 thetex.texture.disable();
66658577 thetex.texture.dispose();
6666
- textures.remove(texname);
8578
+ textures.remove(tex);
66678579 }
6668
- textures.put(texname, texture);
8580
+
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
66698583
66708584 // newtex = true;
66718585 }
....@@ -6681,28 +8595,76 @@
66818595 }
66828596 }
66838597
8598
+ return texturecache;
8599
+ }
8600
+
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
8636
+ {
8637
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8638
+
66848639 if (bump)
66858640 {
6686
- // GraphreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
8641
+ // GrafreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
66878642 bumpstack[bumpdepth++] = texture!=null?texture.texture:null;
66888643 }
66898644 else
66908645 {
6691
- // GraphreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
8646
+ // GrafreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
66928647 pigmentstack[pigmentdepth++] = texture!=null?texture.texture:null;
66938648 }
66948649
66958650 return texture!=null?texture.texture:null;
66968651 }
66978652
6698
- boolean BindTexture(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
8654
+ {
8655
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8656
+
8657
+ return texture!=null?texture.texturedata:null;
8658
+ }
8659
+
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
66998661 {
67008662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67018663 {
67028664 return false;
67038665 }
67048666
6705
- boolean newtex = false;
8667
+ //boolean newtex = false;
67068668
67078669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67088670
....@@ -6734,9 +8696,75 @@
67348696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67358697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67368698
6737
- return newtex;
8699
+ return true; // Warning: not used.
67388700 }
67398701
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
+
67408768 ShadowBuffer shadowPBuf;
67418769 AntialiasBuffer antialiasPBuf;
67428770 int MAXSTACK;
....@@ -6753,10 +8781,12 @@
67538781
67548782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67558783 MAXSTACK = temp[0];
6756
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67578786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67588787 MAXSTACK = temp[0];
6759
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67608790
67618791 // Use debug pipeline
67628792 //drawable.setGL(new DebugGL(gl)); //
....@@ -6764,7 +8794,8 @@
67648794 gl = drawable.getGL(); //
67658795
67668796 GL gl3 = getGL();
6767
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67688799
67698800
67708801 //float pos[] = { 100, 100, 100, 0 };
....@@ -6929,7 +8960,7 @@
69298960
69308961 if (cubemap == null)
69318962 {
6932
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
69338964 }
69348965
69358966 //cubemap.enable();
....@@ -7205,6 +9236,8 @@
72059236
72069237 void LoadEnvy(int which)
72079238 {
9239
+ assert(false);
9240
+
72089241 String name;
72099242 String ext;
72109243
....@@ -7216,37 +9249,58 @@
72169249 cubemap = null;
72179250 return;
72189251 case 1:
7219
- name = "cubemaps/box_";
7220
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
72219254 reverseUP = false;
72229255 break;
72239256 case 2:
7224
- name = "cubemaps/uffizi_";
7225
- ext = "png";
7226
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
72279261 case 3:
7228
- name = "cubemaps/CloudyHills_";
7229
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
72309264 reverseUP = false;
72319265 break;
72329266 case 4:
7233
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
72349268 ext = "png";
72359269 reverseUP = false;
72369270 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;
72379296 default:
7238
- name = "cubemaps/rgb_";
7239
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
72409300 break;
72419301 }
7242
-
7243
- try
7244
- {
7245
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7246
- } catch (IOException e)
7247
- {
7248
- throw new RuntimeException(e);
7249
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
72509304 }
72519305
72529306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7278,8 +9332,12 @@
72789332 static double[] model = new double[16];
72799333 double[] camera2light = new double[16];
72809334 double[] light2camera = new double[16];
7281
- int newenvy = -1;
7282
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
72839341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
72849342 //float[] light0 = { 0,0,0 };
72859343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7292,9 +9350,9 @@
72929350 static boolean occlusionInitialized = false;
72939351 boolean selection = false;
72949352 boolean pointselection = false;
7295
- /*static*/ boolean lighttouched = true;
9353
+ ///*static*/ boolean lighttouched = true;
72969354 boolean deselect;
7297
- boolean ambientOcclusion = false;
9355
+ private boolean ambientOcclusion = false;
72989356 static boolean flash = false;
72999357 /*static*/ boolean wait = false;
73009358 boolean displaydone = false; // after repaint() calls
....@@ -7424,6 +9482,8 @@
74249482 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74259483 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74269484 double scale = lightCamera.SCALE / lightCamera.Distance();
9485
+// PATCH FILLE AUX JEANS
9486
+ //scale *= lightCamera.shaper_fovy / 25;
74279487 gl.glScaled(2 * scale, 2 * scale, -scale);
74289488 gl.glTranslated(0, 0, lightCamera.DECAL);
74299489
....@@ -7570,17 +9630,40 @@
75709630 jy8[3] = 0.5f;
75719631 }
75729632
7573
- 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
75749634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
7575
- float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
9635
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9636
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75769637
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
+
75779662 static int imagecount = 0; // movie generation
75789663
75799664 static int jitter = 0;
75809665
75819666 boolean restartframe = false;
7582
-
7583
- static int framecount = 0; // general-purpose global count
75849667
75859668 void displayAntiAliased(javax.media.opengl.GL gl)
75869669 {
....@@ -7610,14 +9693,14 @@
76109693
76119694 //System.out.println("start frame");
76129695 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
7613
- for (jitter = 0; jitter < ACSIZE; jitter++) //, GraphreeD.wav.cursor += LIVE ? 735 : 0)
9696
+ for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76149697 {
7615
- framecount++;
9698
+ Globals.framecount++;
76169699
76179700 if (CameraPane.tickcount > 0)
76189701 CameraPane.tickcount--;
76199702
7620
-// GraphreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
9703
+// GrafreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
76219704 // restartframe = true;
76229705 if (options1[2] > 100 && (jitter%2==0))
76239706 {
....@@ -7650,7 +9733,7 @@
76509733
76519734 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76529735 */
7653
- lighttouched = true;
9736
+ Globals.lighttouched = true;
76549737 //System.err.println(" shadowbuffer: " + jitter);
76559738 shadowbuffer.display();
76569739
....@@ -7671,8 +9754,8 @@
76719754 assert (parentcam != renderCamera);
76729755
76739756 if (renderCamera != lightCamera)
7674
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7675
- LA.matConcat(parentcam.toParent, matrix, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76769759
76779760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76789761
....@@ -7687,8 +9770,8 @@
76879770 LA.matCopy(renderCamera.fromScreen, matrix);
76889771
76899772 if (renderCamera != lightCamera)
7690
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7691
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
76929775
76939776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
76949777
....@@ -7734,10 +9817,12 @@
77349817 rati = 1 / rati;
77359818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77369819 }
7737
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
77389823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77399824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7740
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
77419826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77429827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77439828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7760,7 +9845,7 @@
77609845 //gl.glFlush();
77619846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77629847
7763
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
77649849 {
77659850 System.err.println(" ABORTED FRAME");
77669851 break;
....@@ -7790,7 +9875,7 @@
77909875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
77919876
77929877 // save image
7793
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
77949879 {
77959880 VPwidth = viewport[2];
77969881 VPheight = viewport[3];
....@@ -7901,11 +9986,11 @@
79019986
79029987 // imagecount++;
79039988
7904
- 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;
79059990
79069991 if (!BOXMODE)
79079992 {
7908
- System.out.println("image: " + fullname + " (" + (GraphreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79099994 }
79109995
79119996 if (!BOXMODE)
....@@ -7933,7 +10018,7 @@
793310018 {
793410019 if (ACSIZE > 1)
793510020 {
7936
- // System.err.println("image #" + (GraphreeD.wav.cursor / 735 / 4));
10021
+ // System.err.println("image #" + (GrafreeD.wav.cursor / 735 / 4));
793710022 }
793810023 }
793910024
....@@ -7943,7 +10028,7 @@
794310028 ABORTED = false;
794410029 }
794510030 else
7946
- GraphreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
794710032
794810033 if (false)
794910034 {
....@@ -8597,13 +10682,6 @@
859710682 }
859810683 }
859910684
8600
- boolean IsFrozen()
8601
- {
8602
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8603
-
8604
- return !selectmode && cameracount == 0; // != 0;
8605
- }
8606
-
860710685 boolean niceon = false;
860810686 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
860910687 boolean currentlydrawing = false;
....@@ -8613,16 +10691,16 @@
861310691
861410692 public void display(GLAutoDrawable drawable)
861510693 {
8616
- if (GraphreeD.savesound && GraphreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
861710695 {
8618
- GraphreeD.wav.save();
8619
- GraphreeD.savesound = false;
8620
- GraphreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
862110699 }
862210700 // if (DEBUG_SELECTION)
862310701 // {
8624
-// if (drawMode != SELECTION)
8625
-// drawMode = SELECTION;
10702
+// if (DrawMode() != SELECTION)
10703
+// DrawMode() = SELECTION;
862610704 // }
862710705
862810706 if (!isRenderer)
....@@ -8678,9 +10756,9 @@
867810756
867910757 //ANTIALIAS = 0;
868010758
8681
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10759
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
868210760 {
8683
- if (niceon || isLIVE())
10761
+ if (niceon || Globals.isLIVE())
868410762 {
868510763 //if(active == 0)
868610764 // antialiaser = null;
....@@ -8693,6 +10771,7 @@
869310771 ANTIALIAS = 0;
869410772 //System.out.println("RESTART");
869510773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
869610775 }
869710776 }
869810777 }
....@@ -8705,7 +10784,7 @@
870510784 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
870610785 */
870710786
8708
- if (drawMode == DEFAULT)
10787
+ if (DrawMode() == DEFAULT)
870910788 {
871010789 currentlydrawing = true;
871110790 }
....@@ -8736,18 +10815,18 @@
873610815
873710816 // if(Applet3D.clipboard != null)
873810817 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8739
-//drawMode = SELECTION;
10818
+//DrawMode() = SELECTION;
874010819 indexcount = 0;
874110820
8742
- if (drawMode == OCCLUSION)
10821
+ if (DrawMode() == OCCLUSION)
874310822 {
8744
- drawMode = DEFAULT;
10823
+ Globals.drawMode = DEFAULT; // WARNING
874510824 ambientOcclusion = true;
874610825 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
874710826 Object3D theobject = object;
874810827 Object3D theparent = object.parent;
874910828 object.parent = null;
8750
- object = (Object3D)GraphreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
875110830 object.Stripify();
875210831 if (theobject.selection == null || theobject.selection.Size() == 0)
875310832 theobject.PreprocessOcclusion(this);
....@@ -8760,26 +10839,27 @@
876010839 ambientOcclusion = false;
876110840 }
876210841
8763
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
876410844 {
876510845 //if (RENDERSHADOW) // ?
876610846 if (!IsFrozen())
876710847 {
876810848 // dec 2012
8769
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
877010850 {
8771
- framecount++;
10851
+ Globals.framecount++;
877210852 shadowbuffer.display();
877310853 }
877410854 }
8775
- lighttouched = false; // ??
10855
+ Globals.lighttouched = false; // ??
877610856 //drawing = true;
877710857 //lighttouched = true;
877810858 }
877910859
878010860 if (wait)
878110861 {
8782
- Sleep(500);
10862
+ Sleep(200); // blocks everything
878310863
878410864 wait = false;
878510865 }
....@@ -8793,9 +10873,9 @@
879310873 //eyeCamera.shaper_fovy = 1;
879410874 }
879510875
8796
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10876
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
879710877 {
8798
- //System.out.println("drawMode = " + drawMode);
10878
+ //System.out.println("DrawMode() = " + DrawMode());
879910879 vertexMode |= VP_PASS;
880010880 //vertexMode |= VP_PROJECTION;
880110881 if (!ambientOcclusion)
....@@ -8855,7 +10935,7 @@
885510935 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
885610936 //Camera lightcam = new Camera(light0);
885710937
8858
- if (drawMode == SHADOW)
10938
+ if (DrawMode() == SHADOW)
885910939 {
886010940 /*
886110941 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8893,8 +10973,8 @@
889310973
889410974 // if (parentcam != renderCamera) // not a light
889510975 if (cam != lightCamera)
8896
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8897
- LA.matConcat(parentcam.toParent, matrix, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
889810978
889910979 for (int j = 0; j < 4; j++)
890010980 {
....@@ -8908,8 +10988,8 @@
890810988
890910989 // if (parentcam != renderCamera) // not a light
891010990 if (cam != lightCamera)
8911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8912
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
891310993
891410994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
891510995
....@@ -8945,7 +11025,7 @@
894511025 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
894611026 } else
894711027 {
8948
- if (drawMode != DEFAULT)
11028
+ if (DrawMode() != DEFAULT)
894911029 {
895011030 gl.glClearColor(1, 1, 1, 0);
895111031 } // 1);
....@@ -8995,13 +11075,41 @@
899511075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
899611076 }
899711077
8998
- 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"))
899911086 {
9000
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
900111093 }
9002
-
9003
- newenvy = -1;
9004
-
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
+
900511113 ratio = ((double) getWidth()) / getHeight();
900611114 //System.out.println("ratio = " + ratio);
900711115
....@@ -9010,14 +11118,14 @@
901011118
901111119 fast &= !ambientOcclusion;
901211120
9013
- if (drawMode == DEFAULT)
11121
+ if (DrawMode() == DEFAULT)
901411122 {
901511123 //gl.glEnable(gl.GL_ALPHA_TEST);
901611124 //gl.glActiveTexture(GL.GL_TEXTURE0);
901711125
901811126 if (!IsFrozen() && !ambientOcclusion)
901911127 {
9020
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
902111129 }
902211130
902311131 //if (selection_view == -1)
....@@ -9071,6 +11179,8 @@
907111179 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
907211180 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
907311181 double scale = lightCamera.SCALE / lightCamera.Distance();
11182
+// PATCH FILLE AUX JEANS
11183
+ //scale *= lightCamera.shaper_fovy / 25;
907411184 gl.glScaled(2 * scale, 2 * scale, -scale);
907511185 gl.glTranslated(0, 0, lightCamera.DECAL);
907611186
....@@ -9166,7 +11276,16 @@
916611276 // Bump noise
916711277 gl.glActiveTexture(GL.GL_TEXTURE6);
916811278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9169
- 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
+
917011289
917111290 gl.glActiveTexture(GL.GL_TEXTURE0);
917211291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9189,9 +11308,9 @@
918911308
919011309 gl.glMatrixMode(GL.GL_MODELVIEW);
919111310
9192
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9193
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9194
-//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);
919511314 } else
919611315 {
919711316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9202,14 +11321,16 @@
920211321 //System.out.println("BLENDING ON");
920311322 gl.glEnable(GL.GL_BLEND);
920411323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9205
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
920611325 gl.glMatrixMode(gl.GL_PROJECTION);
920711326 gl.glLoadIdentity();
920811327
9209
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11328
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
921011329 {
921111330 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
921211331 double scale = lightCamera.SCALE / lightCamera.Distance();
11332
+// PATCH FILLE AUX JEANS
11333
+ //scale *= lightCamera.shaper_fovy / 25;
921311334 gl.glScaled(2 * scale, 2 * scale, -scale);
921411335 gl.glTranslated(0, 0, lightCamera.DECAL);
921511336 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9262,7 +11383,7 @@
926211383 //gl.glPushMatrix();
926311384 gl.glLoadIdentity();
926411385
9265
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11386
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
926611387 {
926711388 //LA.xformPos(light0, lightCamera.fromScreen, light);
926811389 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9289,8 +11410,8 @@
928911410 System.err.println("parentcam != renderCamera");
929011411
929111412 // if (cam != lightCamera)
9292
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9293
- 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
929411415 }
929511416
929611417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9311,8 +11432,8 @@
931111432 if (true) // TODO
931211433 {
931311434 if (cam != lightCamera)
9314
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9315
- 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
931611437 }
931711438
931811439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9349,7 +11470,7 @@
934911470 }
935011471
935111472 /**/
9352
- if (true) // drawMode == SELECTION) // != DEFAULT)
11473
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
935311474 gl.glDisable(gl.GL_LIGHTING);
935411475 else
935511476 gl.glEnable(gl.GL_LIGHTING);
....@@ -9361,12 +11482,13 @@
936111482
936211483 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
936311484 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11485
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
936411486
936511487 options2[0] *= renderCamera.Distance();
936611488
936711489 lightslot = 64;
936811490
9369
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11491
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
937011492 {
937111493 DrawLights(object);
937211494 }
....@@ -9377,7 +11499,7 @@
937711499 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
937811500 //System.out.println("fragmentMode = " + fragmentMode);
937911501
9380
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11502
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
938111503 {
938211504 /*
938311505 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9410,7 +11532,7 @@
941011532 }
941111533 }
941211534
9413
- if (drawMode == DEFAULT)
11535
+ if (DrawMode() == DEFAULT)
941411536 {
941511537 if (WIREFRAME && !ambientOcclusion)
941611538 {
....@@ -9428,7 +11550,7 @@
942811550 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
942911551 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
943011552
9431
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11553
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
943211554 {
943311555 if (vertexMode != 0) // && !fast)
943411556 {
....@@ -9448,7 +11570,7 @@
944811570 }
944911571 }
945011572
9451
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
945211574 {
945311575 //gl.glDepthFunc(GL.GL_LEQUAL);
945411576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9456,27 +11578,24 @@
945611578
945711579 boolean texon = textureon;
945811580
9459
- if (RENDERPROGRAM > 0)
9460
- {
9461
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9462
- textureon = false;
9463
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
946411584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
946511585 //System.out.println("ALLO");
946611586 gl.glColorMask(false, false, false, false);
946711587 DrawObject(gl);
9468
- if (RENDERPROGRAM > 0)
9469
- {
9470
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9471
- textureon = texon;
9472
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
947311592 gl.glColorMask(true, true, true, true);
947411593
947511594 gl.glDepthFunc(GL.GL_EQUAL);
9476
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
947711596 }
947811597
9479
- if (false) // drawMode == SHADOW)
11598
+ if (false) // DrawMode() == SHADOW)
948011599 {
948111600 //SetColumnMajorData(cameraInverseTransform, view_1);
948211601 //System.out.println("light = " + cameraInverseTransform);
....@@ -9490,16 +11609,16 @@
949011609 //System.out.println("object = " + object);
949111610 if (!frozen && !imageLocked)
949211611 {
9493
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11612
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
949411613 {
949511614 displayAntiAliased(gl);
949611615 } else
949711616 {
949811617 programcount = 0;
9499
- int keepmode = drawMode;
11618
+ int keepmode = DrawMode();
950011619 // if (DEBUG_SELECTION)
950111620 // {
9502
-// drawMode = SELECTION;
11621
+// DrawMode() = SELECTION;
950311622 // }
950411623 // for point selection
950511624 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9509,10 +11628,10 @@
950911628 DrawObject(gl);
951011629
951111630 // jan 2013 System.err.println("RESET ABORT (display)");
9512
- // if (drawMode == DEFAULT)
11631
+ // if (DrawMode() == DEFAULT)
951311632 // ABORTED = false;
951411633 fullreset = false;
9515
- drawMode = keepmode;
11634
+ Globals.drawMode = keepmode; // WARNING
951611635 //System.out.println("PROGRAM SWITCH " + programcount);
951711636 }
951811637 }
....@@ -9520,11 +11639,11 @@
952011639 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
952111640 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
952211641
9523
- if (drawMode == DEFAULT)
11642
+ if (DrawMode() == DEFAULT)
952411643 {
952511644 ReleaseTexture(NOISE_TEXTURE, false);
952611645 }
9527
- //if (drawMode == DEFAULT)
11646
+ //if (DrawMode() == DEFAULT)
952811647 {
952911648
953011649 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9536,7 +11655,7 @@
953611655 //else
953711656 //gl.glDisable(gl.GL_TEXTURE_2D);
953811657 //gl.glPopMatrix();
9539
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11658
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
954011659 {
954111660 //new Exception().printStackTrace();
954211661 //System.out.println("Draw image " + width + ", " + height);
....@@ -9578,7 +11697,7 @@
957811697 //gl.glFlush();
957911698 }
958011699
9581
- if (flash && drawMode == DEFAULT)
11700
+ if (flash && DrawMode() == DEFAULT)
958211701 {
958311702 flash = false;
958411703 wait = true;
....@@ -9586,9 +11705,9 @@
958611705 }
958711706
958811707 //drawing = false;
9589
- //if(drawMode == DEFAULT)
11708
+ //if(DrawMode() == DEFAULT)
959011709 // niceon = false;
9591
- if (drawMode == DEFAULT)
11710
+ if (DrawMode() == DEFAULT)
959211711 {
959311712 currentlydrawing = false;
959411713 }
....@@ -9608,7 +11727,7 @@
960811727 repaint();
960911728 }
961011729
9611
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11730
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
961211731 repaint();
961311732
961411733 displaydone = true;
....@@ -9627,8 +11746,14 @@
962711746 {
962811747 renderpass++;
962911748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
963011750 if (FAST) // in case there is no script
9631
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
963211757
963311758 //object.FullInvariants();
963411759
....@@ -9642,23 +11767,44 @@
964211767 e.printStackTrace();
964311768 }
964411769
9645
- if (GraphreeD.RENDERME > 0)
9646
- GraphreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
964711772
9648
- ONESTEP = false;
11773
+ Globals.ONESTEP = false;
964911774 }
965011775
965111776 static boolean zoomonce = false;
965211777
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
+
965311796 void DrawObject(GL gl, boolean draw)
965411797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
965511801 //System.out.println("DRAW OBJECT " + mouseDown);
9656
-// drawMode = SELECTION;
11802
+// DrawMode() = SELECTION;
965711803 //GL gl = getGL();
965811804 if ((TRACK || SHADOWTRACK) || zoomonce)
965911805 {
9660
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9661
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11806
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
966211808 pingthread.StepToTarget(true); // true);
966311809 // zoomonce = false;
966411810 }
....@@ -9678,9 +11824,9 @@
967811824 callist = gl.glGenLists(1);
967911825 }
968011826
9681
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11827
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
968211828
9683
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11829
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
968411830
968511831 if (!mainDL || !active || touched)
968611832 {
....@@ -9707,24 +11853,32 @@
970711853 PushMatrix(ClickInfo.matbuffer);
970811854 }
970911855
9710
- if (drawMode == 0)
11856
+ if (DrawMode() == 0)
971111857 {
971211858 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
971311859
971411860 usedtextures.clear();
971511861
9716
- 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
+ }
971711870 }
971811871 //System.out.println("--> " + stackdepth);
9719
-// GraphreeD.traceon();
11872
+// GrafreeD.traceon();
972011873
972111874 // DRAW
972211875 object.draw(this, /*(Composite)*/ object, false, false);
972311876
9724
- if (drawMode == DEFAULT)
11877
+ if (DrawMode() == DEFAULT)
972511878 {
9726
- if (DEBUG)
11879
+ if (Globals.DEBUG)
972711880 {
11881
+ CreateSelectedPoint();
972811882 float radius = 0.05f;
972911883 if (selectedpoint.radius != radius)
973011884 {
....@@ -9732,69 +11886,104 @@
973211886 selectedpoint.radius = radius;
973311887 selectedpoint.recalculate();
973411888 selectedpoint.material = new cMaterial();
9735
- selectedpoint.material.color = 0.25f;
11889
+ selectedpoint.material.color = 0.15f; // Yellow
973611890 selectedpoint.material.modulation = 0.75f;
973711891
9738
- debugpoint.radius = radius;
9739
- debugpoint.recalculate();
9740
- debugpoint.material = new cMaterial();
9741
- debugpoint.material.color = 0.25f;
9742
- 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;
974311897
9744
- debugpoint2.radius = radius;
9745
- debugpoint2.recalculate();
9746
- debugpoint2.material = new cMaterial();
9747
- debugpoint2.material.color = 0.75f;
9748
- 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;
11903
+
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;
11909
+
11910
+ debugpointR.radius = radius;
11911
+ debugpointR.recalculate();
11912
+ debugpointR.material = new cMaterial();
11913
+ debugpointR.material.color = 0f; // Red
11914
+ debugpointR.material.modulation = 0.75f;
974911915
975011916 InitPoints(radius);
975111917 }
975211918 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9753
- //debugpoint.draw(this, /*(Composite)*/ null, false);
9754
- //debugpoint2.draw(this, /*(Composite)*/ null, false);
9755
- DrawPoints(this);
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);
11923
+ // DrawPoints(this);
975611924 }
975711925
975811926 // debugstuff.draw(this, /*(Composite)*/ null, false);
975911927 }
9760
-// GraphreeD.traceoff();
11928
+// GrafreeD.traceoff();
976111929 //System.out.println(stackdepth);
9762
- if (drawMode == 0)
11930
+ if (DrawMode() == 0)
976311931 {
976411932 ReleaseTextures(DEFAULT_TEXTURES);
976511933
976611934 if (CLEANCACHE)
9767
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
976811936 {
9769
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
977011938
977111939 // System.out.println("Texture --------- " + tex);
977211940
9773
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
977411942 continue;
977511943
9776
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
977711945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
977811947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9779
- textures.get(tex).texture.dispose();
9780
- 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
+ }
978111961 }
978211962 }
978311963 }
978411964
978511965 checker = null;
978611966
9787
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11967
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
978811968 FindChecker(object);
978911969
9790
- if (checker != null && drawMode == DEFAULT)
11970
+ if (checker != null && DrawMode() == DEFAULT)
979111971 {
9792
- // 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
+ }
979311981 // NEAREST
979411982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
979511983 DrawChecker(gl);
979611984 //checker.Draw(this, null, false);
979711985 // ReleaseTexture(IMMORTAL_TEXTURE);
11986
+ ReleaseTextures(checker.GetTextures());
979811987 }
979911988
980011989 if (object.parent != null)
....@@ -9807,7 +11996,7 @@
980711996 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
980811997 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
980911998
9810
- if (DISPLAYTEXT && drawMode == DEFAULT)
11999
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
981112000 {
981212001 // Draw it once, then use the raster
981312002 Balloon(gl, balloon.createGraphics());
....@@ -9863,14 +12052,14 @@
986312052 int[] xs = new int[3];
986412053 int[] ys = new int[3];
986512054
9866
- void DrawString(Object3D obj) // String string)
12055
+ public void DrawString(Object3D obj) // String string) // INTERFACE
986712056 {
9868
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12057
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
986912058 {
987012059 return;
987112060 }
987212061
9873
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
987412063
987512064 GL gl = GetGL();
987612065
....@@ -10187,8 +12376,8 @@
1018712376 //obj.TransformToWorld(light, light);
1018812377 for (int i = tp.size(); --i >= 0;)
1018912378 {
10190
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10191
- 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);
1019212381 }
1019312382
1019412383
....@@ -10205,8 +12394,8 @@
1020512394 parentcam = cameras[0];
1020612395 }
1020712396
10208
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10209
- 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
1021012399
1021112400 LA.xformPos(light, renderCamera.toScreen, light);
1021212401
....@@ -10253,7 +12442,7 @@
1025312442 return;
1025412443 }
1025512444
10256
- if (obj instanceof CheckerIG)
12445
+ if (obj instanceof Checker)
1025712446 {
1025812447 checker = obj;
1025912448
....@@ -10296,8 +12485,76 @@
1029612485
1029712486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1029812487
10299
- String program =
12488
+ String programmin =
12489
+ // Min shader
1030012490 "!!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
+
1030112558 //"OPTION ARB_fragment_program_shadow;" +
1030212559 "PARAM light2cam0 = program.env[10];" +
1030312560 "PARAM light2cam1 = program.env[11];" +
....@@ -10325,11 +12582,13 @@
1032512582 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1032612583 "PARAM params7 = program.env[7];" + // noise power, opacity power
1032712584 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10328
- "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
1032912587 "PARAM pointlight = program.env[127];" + // ...
1033012588 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1033112589 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1033212590 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12591
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1033312592 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1033412593 "PARAM ten = { 10, 10, 10, 1.0 };" +
1033512594 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10350,6 +12609,7 @@
1035012609 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1035112610 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1035212611 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12612
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1035312613 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1035412614 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1035512615 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10390,6 +12650,10 @@
1039012650 "TEMP R1;" +
1039112651 "TEMP R2;" +
1039212652 "TEMP R3;" +
12653
+ "TEMP min;" +
12654
+ "TEMP max;" +
12655
+ "TEMP average;" +
12656
+ "TEMP saturation;" +
1039312657 "TEMP keep1;" +
1039412658 "TEMP keep2;" +
1039512659 "TEMP keep3;" +
....@@ -10405,8 +12669,7 @@
1040512669 "TEMP shininess;" +
1040612670 "\n" +
1040712671 "MOV texSamp, one;" +
10408
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10409
-
12672
+
1041012673 "MOV mapgrid.x, one2048th.x;" +
1041112674 "MOV temp, fragment.texcoord[1];" +
1041212675 /*
....@@ -10427,20 +12690,20 @@
1042712690 "MUL temp, floor, mapgrid.x;" +
1042812691 //"TEX depth0, temp, texture[1], 2D;" +
1042912692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10430
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1043112694 "") +
1043212695 "ADD temp.x, temp.x, mapgrid.x;" +
1043312696 //"TEX depth1, temp, texture[1], 2D;" +
1043412697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10435
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1043612699 "") +
1043712700 "ADD temp.y, temp.y, mapgrid.x;" +
1043812701 //"TEX depth2, temp, texture[1], 2D;" +
10439
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1044012703 "SUB temp.x, temp.x, mapgrid.x;" +
1044112704 //"TEX depth3, temp, texture[1], 2D;" +
1044212705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10443
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1044412707 "") +
1044512708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1044612709 //"MOV params, material;" +
....@@ -10811,10 +13074,10 @@
1081113074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1081213075 "") +
1081313076
10814
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1081513078 "SUB temp.x, half.x, shadow.x;" +
10816
- "MOV temp.y, -params6.x;" +
10817
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1081813081 "SUB temp.y, one.x, temp.z;" +
1081913082 "MUL temp.x, temp.x, temp.y;" +
1082013083 "KIL temp.x;" +
....@@ -10920,10 +13183,42 @@
1092013183
1092113184 // skin?
1092213185 // Saturation for skin
10923
- /**/ // c'est ici
10924
- (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;" +
1092513219 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10926
- "SUB temp, final,R2;" +
13220
+ "SUB temp, final, R2;" +
13221
+
1092713222 // using light angle
1092813223 "DP3 ndotl.x, normald,light;" +
1092913224 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10936,7 +13231,6 @@
1093613231 // using light intensity
1093713232 "MOV ndotl.z, R2.x;" +
1093813233 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10939
-
1094013234 // june 2014
1094113235 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1094213236 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10948,6 +13242,7 @@
1094813242 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1094913243
1095013244 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13245
+/**/
1095113246
1095213247 // "ADD final, R2,temp;" +
1095313248 "MOV final, temp;"
....@@ -11037,7 +13332,7 @@
1103713332 /**/
1103813333 // HDR
1103913334 "MOV temp.z, final.a;" +
11040
- "MUL final, final,options1.w;" +
13335
+ "MUL final, final,options2.x;" +
1104113336 "MOV final.a, temp.z;" +
1104213337 /**/
1104313338
....@@ -11074,10 +13369,17 @@
1107413369 "MOV final.z, zero.x;" +
1107513370 "MOV final.a, one.w;":""
1107613371 ) +
13372
+ /*
1107713373 (NORMALdebug?"MOV final.x, normal.x;" +
1107813374 "MOV final.y, normal.y;" +
1107913375 "MOV final.z, normal.z;" +
1108013376 "MOV final.a, one.w;":""
13377
+ ) +
13378
+ */
13379
+ (NORMALdebug?"SUB final.x, one.x, final.x;" +
13380
+ "SUB final.y, one.x, final.y;" +
13381
+ "SUB final.z, one.x, final.z;" +
13382
+ "MOV final.a, final.a;":""
1108113383 ) +
1108213384 // "MOV final, bumpmap;" +
1108313385 "MOV result.color, final;" +
....@@ -11106,7 +13408,14 @@
1110613408 //once = true;
1110713409 }
1110813410
11109
- 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());
1111013419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1111113420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1111213421
....@@ -11199,30 +13508,32 @@
1119913508 return out;
1120013509 }
1120113510
11202
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1120313513 {
1120413514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1120513515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1120613516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1120713519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11208
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11209
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11210
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11211
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1121213522 //"SWZ buffer, temp, w,w,w,w;";
11213
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1121413524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1121513525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1121613526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11217
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1121813528
11219
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11220
- //"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;";
1122113531 }
1122213532
1122313533 String Shadow(String depth, String shadow)
1122413534 {
1122513535 return "MAX temp.x, ndotl.x, one64th.x;" +
13536
+ "MIN temp.x, temp.x, ninetenth.x;" +
1122613537 /**/
1122713538 // Sine
1122813539 "MUL temp.y, temp.x, temp.x;" +
....@@ -11238,12 +13549,16 @@
1123813549
1123913550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1124013551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1124113554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1124213555 "SGE temp.y, temp.x, zero.x;" +
11243
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1124413559 "SUB temp.x, one.x, temp.x;" +
1124513560 "MUL " + shadow + ".x, temp.x, temp.y;" +
11246
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1124713562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1124813563
1124913564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11257,6 +13572,10 @@
1125713572 // No shadow for backface
1125813573 "DP3 temp.x, normal, lightd;" +
1125913574 "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;" +
1126013579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1126113580 "";
1126213581 }
....@@ -11403,7 +13722,8 @@
1140313722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1140413723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1140513724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11406
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1140713727
1140813728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1140913729 // OUT : diff, spec
....@@ -11419,9 +13739,10 @@
1141913739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1142013740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1142113741 //"MOV " + dest + ".w," + "normal.z;" +
11422
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11423
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11424
- //"MOV " + dest + ".z," + "params2.w;" +
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
1142513746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1142613747 "RCP " + dest + ".w," + dest + ".w;" +
1142713748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11815,7 +14136,7 @@
1181514136 public void mousePressed(MouseEvent e)
1181614137 {
1181714138 //System.out.println("mousePressed: " + e);
11818
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1181914140 }
1182014141
1182114142 static long prevtime = 0;
....@@ -11842,14 +14163,16 @@
1184214163
1184314164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1184414165
14166
+ if (BUTTONLESSWHEEL)
1184514167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1184614168 {
1184714169 return;
1184814170 }
1184914171
14172
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1185014173
1185114174 // TIMER
11852
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1185314176 {
1185414177 keepboxmode = BOXMODE;
1185514178 keepsupport = SUPPORT;
....@@ -11889,8 +14212,8 @@
1188914212 // mode |= META;
1189014213 //}
1189114214
11892
- SetMouseMode(WHEEL | e.getModifiersEx());
11893
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1189414217 anchorX = ax;
1189514218 anchorY = ay;
1189614219 prevX = px;
....@@ -11924,6 +14247,7 @@
1192414247 else
1192514248 if (evt.getSource() == AAtimer)
1192614249 {
14250
+ Globals.TIMERRUNNING = false;
1192714251 if (mouseDown)
1192814252 {
1192914253 //new Exception().printStackTrace();
....@@ -11949,6 +14273,10 @@
1194914273 // LIVE = waslive;
1195014274 // wasliveok = true;
1195114275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1195214280
1195314281 // source == timer
1195414282 if (mouseDown)
....@@ -11978,8 +14306,8 @@
1197814306 // ObjEditor.tweenManager.update(1f / 60f);
1197914307
1198014308 // fev 2014???
11981
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
11982
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14309
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1198314311 pingthread.StepToTarget(true); // true);
1198414312 }
1198514313 // if (!LIVE)
....@@ -11988,12 +14316,13 @@
1198814316
1198914317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1199014318
11991
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1199214320 {
1199314321 if (!wasliveok)
1199414322 return;
1199514323
1199614324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1199714326
1199814327 // waslive = LIVE;
1199914328 // LIVE = false;
....@@ -12005,7 +14334,7 @@
1200514334 // touched = true; // main DL
1200614335 if (isRenderer)
1200714336 {
12008
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1200914338 }
1201014339
1201114340 selectX = anchorX = x;
....@@ -12018,7 +14347,7 @@
1201814347 clicked = true;
1201914348 hold = false;
1202014349
12021
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1202214351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1202314352 {
1202414353 // System.out.println("RESTART II " + modifiers);
....@@ -12043,14 +14372,15 @@
1204314372 drag = false;
1204414373 //System.out.println("Mouse DOWN");
1204514374 editObj = false;
12046
- ClickInfo info = new ClickInfo();
12047
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12048
- info.pane = this;
12049
- info.camera = renderCamera;
12050
- info.x = x;
12051
- info.y = y;
12052
- info.modifiers = modifiers;
12053
- editObj = object.doEditClick(info, 0);
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);
1205414384 if (!editObj)
1205514385 {
1205614386 hasMarquee = true;
....@@ -12066,11 +14396,14 @@
1206614396
1206714397 public void mouseDragged(MouseEvent e)
1206814398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1206914402 if (isRenderer)
1207014403 movingcamera = true;
14404
+
1207114405 //if (drawing)
1207214406 //return;
12073
- //System.out.println("mouseDragged: " + e);
1207414407 if ((e.getModifiersEx() & CTRL) != 0
1207514408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1207614409 {
....@@ -12078,7 +14411,7 @@
1207814411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1207914412 }
1208014413 else
12081
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1208214415
1208314416 //try { Thread.sleep(1); } catch (Exception ex) {}
1208414417 }
....@@ -12090,6 +14423,11 @@
1209014423 cVector tmp = new cVector();
1209114424 cVector tmp2 = new cVector();
1209214425 boolean isMoving;
14426
+
14427
+ public cVector TargetLookAt()
14428
+ {
14429
+ return targetLookAt;
14430
+ }
1209314431
1209414432 class PingThread extends Thread
1209514433 {
....@@ -12229,7 +14567,7 @@
1222914567 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1223014568 if (lightMode)
1223114569 {
12232
- lighttouched = true;
14570
+ Globals.lighttouched = true;
1223314571 }
1223414572
1223514573 if (OEILONCE && OEIL)
....@@ -12246,6 +14584,7 @@
1224614584
1224714585 public void run()
1224814586 {
14587
+ new Exception().printStackTrace();
1224914588 System.exit(0);
1225014589 for (;;)
1225114590 {
....@@ -12287,7 +14626,7 @@
1228714626 mouseDown = false;
1228814627 if (lightMode)
1228914628 {
12290
- lighttouched = true;
14629
+ Globals.lighttouched = true;
1229114630 }
1229214631 repaint();
1229314632 alreadypainted = true;
....@@ -12295,7 +14634,7 @@
1229514634 isMoving = false;
1229614635 } //??
1229714636
12298
- if (isLIVE() && !alreadypainted)
14637
+ if (Globals.isLIVE() && !alreadypainted)
1229914638 {
1230014639 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1230114640 repaint();
....@@ -12307,9 +14646,9 @@
1230714646 {
1230814647 if (lightMode)
1230914648 {
12310
- lighttouched = true;
14649
+ Globals.lighttouched = true;
1231114650 }
12312
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1231314652 }
1231414653 //else
1231514654 }
....@@ -12323,12 +14662,12 @@
1232314662 void GoDown(int mod)
1232414663 {
1232514664 MODIFIERS |= COMMAND;
12326
- /*
14665
+ /**/
1232714666 if((mod&SHIFT) == SHIFT)
12328
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1232914668 else
12330
- manipCamera.BackForth(0, -speed*delta, getWidth());
12331
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1233214671 if ((mod & SHIFT) == SHIFT)
1233314672 {
1233414673 mouseMode = mouseMode; // VR??
....@@ -12344,12 +14683,12 @@
1234414683 void GoUp(int mod)
1234514684 {
1234614685 MODIFIERS |= COMMAND;
12347
- /*
14686
+ /**/
1234814687 if((mod&SHIFT) == SHIFT)
12349
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1235014689 else
12351
- manipCamera.BackForth(0, speed*delta, getWidth());
12352
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1235314692 if ((mod & SHIFT) == SHIFT)
1235414693 {
1235514694 mouseMode = mouseMode;
....@@ -12365,12 +14704,12 @@
1236514704 void GoLeft(int mod)
1236614705 {
1236714706 MODIFIERS |= COMMAND;
12368
- /*
14707
+ /**/
1236914708 if((mod&SHIFT) == SHIFT)
12370
- manipCamera.RotatePosition(speed, 0);
12371
- else
1237214709 manipCamera.Translate(speed*delta, 0, getWidth());
12373
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1237414713 if ((mod & SHIFT) == SHIFT)
1237514714 {
1237614715 mouseMode = mouseMode;
....@@ -12386,12 +14725,12 @@
1238614725 void GoRight(int mod)
1238714726 {
1238814727 MODIFIERS |= COMMAND;
12389
- /*
14728
+ /**/
1239014729 if((mod&SHIFT) == SHIFT)
12391
- manipCamera.RotatePosition(-speed, 0);
12392
- else
1239314730 manipCamera.Translate(-speed*delta, 0, getWidth());
12394
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1239514734 if ((mod & SHIFT) == SHIFT)
1239614735 {
1239714736 mouseMode = mouseMode;
....@@ -12409,7 +14748,7 @@
1240914748 int X, Y;
1241014749 boolean SX, SY;
1241114750
12412
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1241314752 {
1241414753 if (IsFrozen())
1241514754 {
....@@ -12418,17 +14757,17 @@
1241814757
1241914758 drag = true; // NEW
1242014759
12421
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1242214761
1242314762 X = x;
1242414763 Y = y;
1242514764 // floating state for animation
12426
- MODIFIERS = modifiers;
12427
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1242814767 if (false) // modifiers != 0)
1242914768 {
1243014769 //new Exception().printStackTrace();
12431
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1243214771 System.out.println("SHIFT = " + SHIFT);
1243314772 System.out.println("CONTROL = " + COMMAND);
1243414773 System.out.println("META = " + META);
....@@ -12441,14 +14780,16 @@
1244114780 if (editObj)
1244214781 {
1244314782 drag = true;
12444
- ClickInfo info = new ClickInfo();
12445
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1244614785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12447
- info.pane = this;
12448
- info.camera = renderCamera;
12449
- info.x = x;
12450
- info.y = y;
12451
- object.editWindow.copy.doEditDrag(info);
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);
1245214793 } else
1245314794 {
1245414795 if (x < startX)
....@@ -12550,6 +14891,7 @@
1255014891 {
1255114892 manipCamera.Translate(dx, dy, getWidth());
1255214893 }
14894
+ else
1255314895 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1255414896 {
1255514897 manipCamera.RotateInterest(dx, dy);
....@@ -12560,7 +14902,7 @@
1256014902
1256114903 if (manipCamera == lightCamera)
1256214904 {
12563
- lighttouched = true;
14905
+ Globals.lighttouched = true;
1256414906 }
1256514907 /*
1256614908 switch (mode)
....@@ -12596,23 +14938,27 @@
1259614938 }
1259714939 }
1259814940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1259914943 public void mouseMoved(MouseEvent e)
1260014944 {
1260114945 //System.out.println("mouseMoved: " + e);
12602
-
1260314946 if (isRenderer)
1260414947 return;
1260514948
12606
- ClickInfo ci = new ClickInfo();
12607
- ci.x = e.getX();
12608
- ci.y = e.getY();
12609
- ci.modifiers = e.getModifiersEx();
12610
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12611
- ci.pane = this;
12612
- ci.camera = renderCamera;
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;
1261314956 if (!isRenderer)
1261414957 {
12615
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1261614962 {
1261714963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1261814964 } else
....@@ -12624,7 +14970,11 @@
1262414970
1262514971 public void mouseReleased(MouseEvent e)
1262614972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1262714975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1262814978 //System.out.println("mouseReleased: " + e);
1262914979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1263014980 }
....@@ -12647,9 +14997,9 @@
1264714997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1264814998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1264914999
12650
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1265115001 timeout = true;
12652
- else
15002
+// ?? May 2019 else
1265315003 // timer.setDelay((modifiers & 128) != 0?0:350);
1265415004 mouseDown = false;
1265515005 if (!control && !command) // june 2013
....@@ -12759,7 +15109,7 @@
1275915109 System.out.println("keyReleased: " + e);
1276015110 }
1276115111
12762
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1276315113 {
1276415114 //System.out.println("SetMouseMode = " + modifiers);
1276515115 //modifiers &= ~1024;
....@@ -12771,24 +15121,27 @@
1277115121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1277215122 // return;
1277315123 //System.out.println("SetMode = " + modifiers);
12774
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1277515125 {
1277615126 mouseMode |= ZOOM;
1277715127 }
12778
- if ((modifiers & META) == META)
15128
+
15129
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15130
+ if (capsLocked) // || (modifiers & META) == META)
1277915131 {
1278015132 mouseMode |= VR; // BACKFORTH;
1278115133 }
12782
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12783
- {
12784
- mouseMode |= SELECT; // BACKFORTH;
12785
- }
12786
- if ((modifiers & COMMAND) == COMMAND)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1278715135 {
1278815136 mouseMode |= SELECT;
1278915137 }
12790
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1279115139 {
15140
+ mouseMode |= SELECT;
15141
+ }
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15143
+ {
15144
+ mouseMode &= ~VR;
1279215145 mouseMode |= TRANSLATE;
1279315146 }
1279415147 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12815,10 +15168,10 @@
1281515168
1281615169 if (isRenderer) //
1281715170 {
12818
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1281915172 }
1282015173
12821
- theRenderer.keyPressed(key);
15174
+ Globals.theRenderer.keyPressed(key);
1282215175 }
1282315176
1282415177 int kompactbit = 4; // power bit
....@@ -12830,7 +15183,7 @@
1283015183 float SATPOW = 1; // 2; // 0.5f;
1283115184 float BRIPOW = 1; // 0.5f; // 0.5f;
1283215185
12833
- void keyPressed(int key)
15186
+ public void keyPressed(int key)
1283415187 {
1283515188 if (key >= '0' && key <= '5')
1283615189 clampbit = (key-'0');
....@@ -12877,7 +15230,8 @@
1287715230 // break;
1287815231 case 'T':
1287915232 CACHETEXTURE ^= true;
12880
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1288115235 // repaint();
1288215236 break;
1288315237 case 'Y':
....@@ -12945,7 +15299,7 @@
1294515299 case 'B':
1294615300 BRISMOOTH ^= true;
1294715301 SHADOWCULLFACE ^= true;
12948
- lighttouched = true;
15302
+ Globals.lighttouched = true;
1294915303 repaint();
1295015304 break;
1295115305 case 'b':
....@@ -12962,7 +15316,9 @@
1296215316 case 'E' : COMPACT ^= true;
1296315317 repaint();
1296415318 break;
12965
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1296615322 repaint();
1296715323 break;
1296815324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -12987,8 +15343,8 @@
1298715343 RevertCamera();
1298815344 repaint();
1298915345 break;
12990
- case 'L':
1299115346 case 'l':
15347
+ //case 'L':
1299215348 if (lightMode)
1299315349 {
1299415350 lightMode = false;
....@@ -13045,27 +15401,31 @@
1304515401 repaint();
1304615402 break;
1304715403 case 'O':
13048
- drawMode = OCCLUSION;
15404
+ Globals.drawMode = OCCLUSION; // WARNING
1304915405 repaint();
1305015406 break;
1305115407 case 'o':
1305215408 OCCLUSION_CULLING ^= true;
1305315409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1305415410 break;
13055
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1305615412 case '1':
1305715413 case '2':
1305815414 case '3':
1305915415 case '4':
1306015416 case '5':
13061
- newenvy = Character.getNumericValue(key);
13062
- repaint();
13063
- break;
1306415417 case '6':
1306515418 case '7':
1306615419 case '8':
1306715420 case '9':
13068
- 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
+ }
1306915429 repaint();
1307015430 break;
1307115431 case '!':
....@@ -13131,12 +15491,12 @@
1313115491 case '_':
1313215492 kompactbit = 5;
1313315493 break;
13134
- case '+':
13135
- kompactbit = 6;
13136
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1313715497 case ' ':
1313815498 lightMode ^= true;
13139
- lighttouched = true;
15499
+ Globals.lighttouched = true;
1314015500 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1314115501 targetLookAt.set(manipCamera.lookAt);
1314215502 repaint();
....@@ -13145,14 +15505,15 @@
1314515505 case ESC:
1314615506 RENDERPROGRAM += 1;
1314715507 RENDERPROGRAM %= 3;
15508
+
1314815509 repaint();
1314915510 break;
1315015511 case 'Z':
13151
- RESIZETEXTURE ^= true;
13152
- break;
15512
+ //RESIZETEXTURE ^= true;
15513
+ //break;
1315315514 case 'z':
13154
- RENDERSHADOW ^= true;
13155
- lighttouched = true;
15515
+ Globals.RENDERSHADOW ^= true;
15516
+ Globals.lighttouched = true;
1315615517 repaint();
1315715518 break;
1315815519 //case UP:
....@@ -13178,13 +15539,15 @@
1317815539 FlipTransform();
1317915540 break;
1318015541 case ENTER:
13181
- object.editWindow.ScreenFit(); // Edit();
15542
+ // object.editWindow.ScreenFit(); // Edit();
15543
+ ToggleLive();
1318215544 break;
1318315545 case DELETE:
1318415546 ClearSelection();
1318515547 break;
13186
- /*
1318715548 case '+':
15549
+
15550
+ /*
1318815551 //fontsize += 1;
1318915552 bbzoom *= 2;
1319015553 repaint();
....@@ -13201,17 +15564,17 @@
1320115564 case '=':
1320215565 IncDepth();
1320315566 //fontsize += 1;
13204
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1320515568 maskbit = 6;
1320615569 break;
1320715570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1320815571 DecDepth();
1320915572 maskbit = 5;
1321015573 //if(fontsize > 1) fontsize -= 1;
13211
- if (object.editWindow == null)
13212
- new Exception().printStackTrace();
13213
- else
13214
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1321515578 break;
1321615579 case '{':
1321715580 manipCamera.shaper_fovy /= 1.1;
....@@ -13266,6 +15629,7 @@
1326615629 }
1326715630 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1326815631 }
15632
+
1326915633 static double OCCLUSIONBOOST = 1; // 0.5;
1327015634
1327115635 void keyReleased(int key, int modifiers)
....@@ -13273,11 +15637,11 @@
1327315637 //mode = ROTATE;
1327415638 if ((MODIFIERS & COMMAND) == 0) // VR??
1327515639 {
13276
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1327715641 }
1327815642 }
1327915643
13280
- protected void processKeyEvent(KeyEvent e)
15644
+ public void processKeyEvent(KeyEvent e)
1328115645 {
1328215646 switch (e.getID())
1328315647 {
....@@ -13407,8 +15771,9 @@
1340715771
1340815772 protected void processMouseMotionEvent(MouseEvent e)
1340915773 {
13410
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13411
- 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)
1341215777 {
1341315778 mouseMoved(e);
1341415779 } else
....@@ -13433,11 +15798,12 @@
1343315798 }
1343415799 */
1343515800
13436
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1343715802 }
1343815803
1343915804 void SelectParent()
1344015805 {
15806
+ new Exception().printStackTrace();
1344115807 System.exit(0);
1344215808 Composite group = (Composite) object;
1344315809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13449,10 +15815,10 @@
1344915815 {
1345015816 //selectees.remove(i);
1345115817 System.out.println("select parent of " + elem);
13452
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1345315819 } else
1345415820 {
13455
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1345615822 }
1345715823
1345815824 first = false;
....@@ -13461,6 +15827,7 @@
1346115827
1346215828 void SelectChildren()
1346315829 {
15830
+ new Exception().printStackTrace();
1346415831 System.exit(0);
1346515832 /*
1346615833 Composite group = (Composite) object;
....@@ -13493,12 +15860,12 @@
1349315860 for (int j = 0; j < group.children.size(); j++)
1349415861 {
1349515862 elem = (Object3D) group.children.elementAt(j);
13496
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1349715864 first = false;
1349815865 }
1349915866 } else
1350015867 {
13501
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1350215869 }
1350315870
1350415871 first = false;
....@@ -13509,21 +15876,21 @@
1350915876 {
1351015877 //Composite group = (Composite) object;
1351115878 Object3D group = object;
13512
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1351315880 }
1351415881
1351515882 void ResetTransform(int mask)
1351615883 {
1351715884 //Composite group = (Composite) object;
1351815885 Object3D group = object;
13519
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1352015887 }
1352115888
1352215889 void FlipTransform()
1352315890 {
1352415891 //Composite group = (Composite) object;
1352515892 Object3D group = object;
13526
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1352715894 // group.editWindow.ReduceMesh(true);
1352815895 }
1352915896
....@@ -13531,7 +15898,7 @@
1353115898 {
1353215899 //Composite group = (Composite) object;
1353315900 Object3D group = object;
13534
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1353515902 // group.editWindow.ReduceMesh(true);
1353615903 }
1353715904
....@@ -13539,7 +15906,7 @@
1353915906 {
1354015907 //Composite group = (Composite) object;
1354115908 Object3D group = object;
13542
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1354315910 }
1354415911
1354515912 void IncDepth()
....@@ -13621,11 +15988,11 @@
1362115988
1362215989 int width = getBounds().width;
1362315990 int height = getBounds().height;
13624
- ClickInfo info = new ClickInfo();
13625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1362615991 //Image img = CreateImage(width, height);
1362715992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1362815994 Graphics gr = g; // img.getGraphics();
15995
+
1362915996 if (!hasMarquee)
1363015997 {
1363115998 if (Xmin < Xmax) // !locked)
....@@ -13697,40 +16064,88 @@
1369716064 }
1369816065 if (object != null && !hasMarquee)
1369916066 {
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
+
1370016073 if (isRenderer)
1370116074 {
13702
- info.flags++;
16075
+ object.clickInfo.flags++;
1370316076 double frameAspect = (double) width / (double) height;
1370416077 if (frameAspect > renderCamera.aspect)
1370516078 {
1370616079 int desired = (int) ((double) height * renderCamera.aspect);
13707
- info.bounds.width -= width - desired;
13708
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1370916082 } else
1371016083 {
1371116084 int desired = (int) ((double) width / renderCamera.aspect);
13712
- info.bounds.height -= height - desired;
13713
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1371416087 }
1371516088 }
13716
- info.g = gr;
13717
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1371816092 /*
1371916093 // Memory intensive (brep.verticescopy)
1372016094 if (!(object instanceof Composite))
1372116095 object.draw(info, 0, false); // SLOW :
1372216096 */
13723
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1372416098 {
13725
- 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
+ }
1372616139 }
1372716140 }
16141
+
1372816142 if (isRenderer)
1372916143 {
1373016144 //gr.setColor(Color.black);
1373116145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1373216146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1373316147 }
16148
+
1373416149 if (hasMarquee)
1373516150 {
1373616151 gr.setXORMode(Color.white);
....@@ -13753,6 +16168,7 @@
1375316168 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1375416169 }
1375516170
16171
+ // To avoid clear.
1375616172 public void update(Graphics g)
1375716173 {
1375816174 paint(g);
....@@ -13842,6 +16258,7 @@
1384216258 public boolean mouseDown(Event evt, int x, int y)
1384316259 {
1384416260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1384516262 /*
1384616263 locked = true;
1384716264 drag = false;
....@@ -13885,7 +16302,7 @@
1388516302 {
1388616303 keyPressed(0, modifiers);
1388716304 }
13888
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1388916306 return true;
1389016307 }
1389116308
....@@ -14003,7 +16420,7 @@
1400316420 {
1400416421 keyReleased(0, 0);
1400516422 }
14006
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1400716424 return true;
1400816425 }
1400916426
....@@ -14135,7 +16552,7 @@
1413516552 Object3D object;
1413616553 static Object3D trackedobject;
1413716554 Camera renderCamera; // Light or Eye (or Occlusion)
14138
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1413916556 /*static*/ Camera eyeCamera;
1414016557 /*static*/ Camera lightCamera;
1414116558 int cameracount;
....@@ -14199,6 +16616,8 @@
1419916616 private /*static*/ boolean firstime;
1420016617 private /*static*/ cVector newView = new cVector();
1420116618 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"};
1420216621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1420316622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1420416623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14211,29 +16630,67 @@
1421116630 {
1421216631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1421316632
16633
+ int usedsuf = 0;
16634
+
1421416635 for (int i = 0; i < suffixes.length; i++)
1421516636 {
14216
- String resourceName = basename + suffixes[i] + "." + suffix;
14217
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14218
- mipmapped,
14219
- FileUtil.getFileSuffix(resourceName));
14220
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1422116642 {
14222
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1422316647 }
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
+
1422416676 //System.out.println("Target = " + targets[i]);
1422516677 cubemap.updateImage(data, targets[i]);
1422616678 }
1422716679
1422816680 return cubemap;
1422916681 }
16682
+
1423016683 int bigsphere = -1;
1423116684
1423216685 float BGcolor = 0.5f;
1423316686
14234
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1423516690 {
14236
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1423716694 {
1423816695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1423916696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14248,7 +16705,17 @@
1424816705 // Compensates for ExaminerViewer's modification of modelview matrix
1424916706 gl.glMatrixMode(GL.GL_MODELVIEW);
1425016707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1425116709
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
+
1425216719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1425316720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1425416721
....@@ -14280,6 +16747,7 @@
1428016747 {
1428116748 gl.glScalef(1.0f, -1.0f, 1.0f);
1428216749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1428316751 gl.glMultMatrixd(viewrot_1, 0);
1428416752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1428516753 //viewer.updateInverseRotation(gl);
....@@ -14355,7 +16823,7 @@
1435516823 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1435616824 gl.glPushMatrix();
1435716825 gl.glLoadIdentity();
14358
- PushMatrix(checker.toParent);
16826
+ //PushMatrix(checker.toParent);
1435916827
1436016828 gl.glMatrixMode(GL.GL_TEXTURE);
1436116829 gl.glPushMatrix();
....@@ -14378,8 +16846,8 @@
1437816846
1437916847 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1438016848
14381
- float step = 0.1666f; //0.25f;
14382
- float stepv = step * 1652 / 998;
16849
+ float step = 2; // 0.1666f; //0.25f;
16850
+ float stepv = 2; // step * 1652 / 998;
1438316851
1438416852 int i0 = 0;
1438516853 /*
....@@ -14415,20 +16883,21 @@
1441516883 /**/
1441616884 //checker.GetMaterial().opacity = 1.1f;
1441716885 ////checker.GetMaterial().ambient = 0.99f;
14418
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14419
- Object3D.selectedstack[Object3D.materialdepth] = false;
14420
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16886
+ materialstack[materialdepth] = checker.material;
16887
+ selectedstack[materialdepth] = false;
16888
+ cStatic.objectstack[materialdepth++] = checker;
1442116889 //System.out.println("material " + material);
1442216890 //Applet3D.tracein(this, selected);
14423
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1442416892
14425
- checker.GetMaterial().Draw(this, false); // true);
16893
+ //checker.GetMaterial().Draw(this, false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1442616895
14427
- Object3D.materialdepth -= 1;
14428
- if (Object3D.materialdepth > 0)
16896
+ materialdepth -= 1;
16897
+ if (materialdepth > 0)
1442916898 {
14430
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14431
- 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);
1443216901 }
1443316902 //checker.GetMaterial().opacity = 1f;
1443416903 ////checker.GetMaterial().ambient = 1f;
....@@ -14449,15 +16918,27 @@
1444916918
1445016919 //float u = (i+1)/2;
1445116920 //float v = (j+1)/2;
14452
- 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);
1445316925 gl.glVertex3f(i, j, -0.5f);
1445416926
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
1445516930 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1445616931 gl.glVertex3f(i + step, j, -0.5f);
1445716932
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
1445816936 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1445916937 gl.glVertex3f(i + step, j + stepv, -0.5f);
1446016938
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
1446116942 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1446216943 gl.glVertex3f(i, j + stepv, -0.5f);
1446316944 }
....@@ -14469,7 +16950,7 @@
1446916950 gl.glMatrixMode(GL.GL_PROJECTION);
1447016951 gl.glPopMatrix();
1447116952 gl.glMatrixMode(GL.GL_MODELVIEW);
14472
- PopMatrix(null); // checker.toParent); // null);
16953
+ //PopMatrix(null); // checker.toParent); // null);
1447316954 gl.glPopMatrix();
1447416955 PopTextureMatrix(checker.toParent);
1447516956 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14502,6 +16983,14 @@
1450216983 }
1450316984 }
1450416985
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
+
1450516994 class SelectBuffer implements GLEventListener
1450616995 {
1450716996
....@@ -14517,7 +17006,7 @@
1451717006 //new Exception().printStackTrace();
1451817007 System.out.println("select buffer init");
1451917008 // Use debug pipeline
14520
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1452117010
1452217011 GL gl = drawable.getGL();
1452317012
....@@ -14560,6 +17049,7 @@
1456017049 {
1456117050 if (!selection)
1456217051 {
17052
+ new Exception().printStackTrace();
1456317053 System.exit(0);
1456417054 return;
1456517055 }
....@@ -14580,17 +17070,39 @@
1458017070
1458117071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1458217072
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
+
1458317084 //int tmp = selection_view;
1458417085 //selection_view = -1;
14585
- int temp = drawMode;
14586
- drawMode = SELECTION;
17086
+ int temp = DrawMode();
17087
+ Globals.drawMode = SELECTION; // WARNING
1458717088 indexcount = 0;
1458817089 parent.display(drawable);
1458917090 //selection_view = tmp;
1459017091 //if (temp == SELECTION)
1459117092 // temp = DEFAULT; // patch for selection debug
14592
- drawMode = temp;
17093
+ Globals.drawMode = temp; // WARNING
1459317094
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
+
1459417106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1459517107
1459617108 // trying different ways of getting the depth info over
....@@ -14639,6 +17151,13 @@
1463917151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1464017152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1464117153
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
+
1464217161 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1464317162
1464417163 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14682,34 +17201,36 @@
1468217201 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]));
1468317202 }
1468417203
14685
- previousselectedpoint = (Sphere) GraphreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1468617205 }
1468717206 }
1468817207
1468917208 if (!movingcamera && !PAINTMODE)
14690
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1469117210
14692
- if (PAINTMODE && GraphreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1469317212 {
14694
- Object3D paintobj = GraphreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1469517214
14696
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1469717218
14698
- group.CreateMaterial(); // use a void leaf to select instances
14699
-
14700
- group.add(paintobj); // link
14701
-
14702
- object.editWindow.SnapObject(group);
14703
-
14704
- Object3D folder = object.editWindow.copy;
14705
-
14706
- if (object.editWindow.copy.selection.Size() > 0)
14707
- folder = object.editWindow.copy.selection.elementAt(0);
14708
-
14709
- folder.add(group);
14710
-
14711
- object.editWindow.ResetModel();
14712
- object.editWindow.refreshContents();
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
+ }
1471317234 }
1471417235 else
1471517236 paintcount = 0;
....@@ -14748,6 +17269,11 @@
1474817269 //System.out.println("objects[color] = " + objects[color]);
1474917270 //objects[color].Select();
1475017271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1475117277 object.Select(color, deselect);
1475217278 }
1475317279
....@@ -14847,7 +17373,7 @@
1484717373 gl.glDisable(gl.GL_CULL_FACE);
1484817374 }
1484917375
14850
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1485117377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1485217378
1485317379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14857,14 +17383,14 @@
1485717383 //gl.glColorMask(false, false, false, false);
1485817384
1485917385 //render_scene_from_light_view(gl, drawable, 0, 0);
14860
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1486117387 {
1486217388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1486317389
14864
- int temp = drawMode;
14865
- drawMode = SHADOW;
17390
+ int temp = DrawMode();
17391
+ Globals.drawMode = SHADOW; // WARNING
1486617392 parent.display(drawable);
14867
- drawMode = temp;
17393
+ Globals.drawMode = temp; // WARNING
1486817394 }
1486917395
1487017396 gl.glCullFace(gl.GL_BACK);
....@@ -14917,7 +17443,6 @@
1491717443
1491817444 class AntialiasBuffer implements GLEventListener
1491917445 {
14920
-
1492117446 CameraPane parent = null;
1492217447
1492317448 AntialiasBuffer(CameraPane p)
....@@ -15027,15 +17552,25 @@
1502717552 gl.glFlush();
1502817553
1502917554 /**/
15030
- 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);
1503117556
15032
- int[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1503317558
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
+
1503417563 double r = 0, g = 0, b = 0;
1503517564
1503617565 double count = 0;
17566
+
17567
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17568
+
17569
+ float mindepth = 1;
17570
+
17571
+ double FACTOR = 1;
1503717572
15038
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1503917574 {
1504017575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1504117576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15118,7 +17653,7 @@
1511817653
1511917654 double scale = ray.z; // 1; // cos
1512017655
15121
- int p = pixels[newindex];
17656
+ float depth = depths[newindex];
1512217657
1512317658 /*
1512417659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15142,10 +17677,23 @@
1514217677 scale = (1 - modu) * modv;
1514317678 */
1514417679
15145
- r += ((p >> 16) & 0xFF) * scale / 255;
15146
- g += ((p >> 8) & 0xFF) * scale / 255;
15147
- 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
+ }
1514817688
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
+
1514917697 count += scale;
1515017698 }
1515117699
....@@ -15243,12 +17791,6 @@
1524317791 GLUT glut = new GLUT();
1524417792
1524517793
15246
- static final public int DEFAULT = 0;
15247
- static final public int SELECTION = 1;
15248
- static final public int SHADOW = 2;
15249
- static final public int OCCLUSION = 3;
15250
- static
15251
- public int drawMode = DEFAULT;
1525217794 public boolean spherical = false;
1525317795 static boolean DEBUG_OCCLUSION = false;
1525417796 static boolean DEBUG_SELECTION = false;
....@@ -15261,21 +17803,15 @@
1526117803 int AAbuffersize = 0;
1526217804
1526317805 //double[] selectedpoint = new double[3];
15264
- static Sphere selectedpoint = new Sphere();
17806
+ static Superellipsoid selectedpoint;
1526517807 static Sphere previousselectedpoint = null;
15266
- static Sphere debugpoint = new Sphere();
15267
- static Sphere debugpoint2 = new Sphere();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1526817812
1526917813 static Sphere debugpoints[] = new Sphere[8];
1527017814
15271
- static
15272
- {
15273
- for (int i=0; i<8; i++)
15274
- {
15275
- debugpoints[i] = new Sphere();
15276
- }
15277
- }
15278
-
1527917815 static void InitPoints(float radius)
1528017816 {
1528117817 for (int i=0; i<8; i++)
....@@ -15295,7 +17831,7 @@
1529517831 }
1529617832 }
1529717833
15298
- static void DrawPoints(CameraPane cpane)
17834
+ static void DrawPoints(iCameraPane cpane)
1529917835 {
1530017836 for (int i=0; i<8; i++) // first and last are red
1530117837 {
....@@ -15314,10 +17850,14 @@
1531417850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1531517851 static IntBuffer bigAAbuffer;
1531617852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15317
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1531817854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1531917855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15320
- 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
+
1532117861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1532217862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1532317863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15326,10 +17866,11 @@
1532617866 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1532717867 // Depth buffer format
1532817868 //private int depth_format;
15329
- static public void NextIndex(Object3D o, GL gl)
17869
+
17870
+ public void NextIndex()
1533017871 {
1533117872 indexcount+=16;
15332
- 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);
1533317874 //objects[indexcount] = o;
1533417875 //System.out.println("indexcount = " + indexcount);
1533517876 }