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,11 +2453,26 @@
7592453
7602454 GL currentGL;
7612455
762
- GL GetGL()
2456
+ public GL GetGL() // INTERFACE
7632457 {
7642458 return currentGL;
7652459 }
766
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
7672476 /**/
7682477 class CacheTexture
7692478 {
....@@ -772,28 +2481,31 @@
7722481
7732482 int resolution;
7742483
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762485 {
777
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
7782488 resolution = res;
7792489 }
7802490 }
7812491 /**/
7822492
7832493 // TEXTURE static Texture texture;
784
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
785
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
786
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
7872499 int pigmentdepth = 0;
7882500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892501 int bumpdepth = 0;
7902502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952507
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972509 {
7982510 TextureData texturedata = null;
7992511
....@@ -812,13 +2524,34 @@
8122524 if (bump)
8132525 texturedata = ConvertBump(texturedata, false);
8142526
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172529
818
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
819
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202532
821
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
8222555 }
8232556
8242557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3624,8 @@
18913624
18923625 System.out.println("LOADING TEXTURE : " + name);
18933626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
18943629 //
18953630 if (false) // compressbit > 0)
18963631 {
....@@ -2000,10 +3735,12 @@
20003735 */
20013736 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20023737 {
3738
+ int pixelformat = texturedata.getPixelFormat();
3739
+
20033740 int stride = 1;
2004
- if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
3741
+ if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
20053742 stride = 3;
2006
- if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
3743
+ if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
20073744 stride = 4;
20083745
20093746 int width = texturedata.getWidth();
....@@ -2593,6 +4330,7 @@
25934330
25944331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25954332 {
4333
+ new Exception().printStackTrace();
25964334 System.exit(0);
25974335 com.sun.opengl.util.texture.Texture texture = null;
25984336
....@@ -6269,7 +8007,7 @@
62698007 return null;
62708008 }
62718009
6272
- void ReleaseTextures(cTexture tex)
8010
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62738011 {
62748012 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62758013 {
....@@ -6286,7 +8024,7 @@
62868024 String pigment = Object3D.GetPigment(tex);
62878025 String bump = Object3D.GetBump(tex);
62888026
6289
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62908028 {
62918029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62928030 // System.out.println("; bump = " + bump);
....@@ -6301,13 +8039,71 @@
63018039 pigment = null;
63028040 }
63038041
6304
- ReleaseTexture(bump, true);
6305
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
63068044 }
63078045
6308
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63098047 {
6310
- if (// drawMode != 0 || /*tex == null ||*/
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
8105
+ {
8106
+ if (// DrawMode() != 0 || /*tex == null ||*/
63118107 ambientOcclusion ) // || !textureon)
63128108 {
63138109 return;
....@@ -6316,7 +8112,7 @@
63168112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63178113
63188114 if (tex != null)
6319
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63208116
63218117 // //assert( texture != null );
63228118 // if (texture == null)
....@@ -6333,7 +8129,7 @@
63338129 {
63348130 bumpdepth--;
63358131
6336
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8132
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63378133 if (bumpstack[bumpdepth] != (texture!=null?texture.texture:null))
63388134 {
63398135 // assert (bumpstack[bumpdepth] == texture);
....@@ -6363,7 +8159,7 @@
63638159 {
63648160 pigmentdepth--;
63658161
6366
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8162
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63678163 if (pigmentstack[pigmentdepth] != (texture!=null?texture.texture:null))
63688164 {
63698165 // assert (pigmentstack[pigmentdepth] == texture);
....@@ -6408,9 +8204,57 @@
64088204 }
64098205 }
64108206
6411
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64128208 {
6413
- if (// drawMode != 0 || /*tex == null ||*/
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8256
+ {
8257
+ if (// DrawMode() != 0 || /*tex == null ||*/
64148258 ambientOcclusion ) // || !textureon)
64158259 {
64168260 return; // false;
....@@ -6419,17 +8263,47 @@
64198263 if (tex == null)
64208264 {
64218265 BindTexture(null,false,resolution);
6422
- BindTexture(null,true,resolution);
64238266 return;
64248267 }
64258268
64268269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
64278302 String bump = Object3D.GetBump(tex);
64288303
6429
- usedtextures.put(pigment, pigment);
6430
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
64318305
6432
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64338307 {
64348308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64358309 // System.out.println("; bump = " + bump);
....@@ -6439,43 +8313,94 @@
64398313 {
64408314 bump = null;
64418315 }
6442
- if (pigment.equals(""))
6443
- {
6444
- pigment = null;
6445
- }
64468316
6447
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6448
- BindTexture(pigment, false, resolution);
64498317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6450
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
64518319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6452
-
6453
- return; // true;
64548320 }
64558321
6456
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
64578325 {
6458
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
64598345
64608346 if (tex != null)
64618347 {
6462
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64638350
6464
- String[] split = tex.split("Textures");
6465
- if (split.length > 1)
6466
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6467
- else
6468
- if (!texname.startsWith("/"))
6469
- texname = "/Users/nbriere/Textures/" + texname;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
64708368
64718369 if (CACHETEXTURE)
6472
- texture = textures.get(texname); // TEXTURE CACHE
6473
-
6474
- TextureData texturedata = null;
6475
-
6476
- if (texture == null || texture.resolution < resolution)
64778370 {
6478
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64798404 {
64808405 assert(!bump);
64818406 // if (bump)
....@@ -6486,19 +8411,23 @@
64868411 // }
64878412 // else
64888413 // {
6489
- texture = textures.get(tex);
6490
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
64918416 {
6492
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64938418 }
8419
+ else
8420
+ new Exception().printStackTrace();
64948421 // }
64958422 } else
6496
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64978424 {
64988425 assert(bump);
6499
- texture = textures.get(tex);
6500
- if (texture == null)
6501
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
65028431 } else
65038432 {
65048433 //if (tex.equals("IMMORTAL"))
....@@ -6506,11 +8435,22 @@
65068435 // texture = GetResourceTexture("default.png");
65078436 //} else
65088437 //{
6509
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
65108439 {
6511
- texture = textures.get(tex);
6512
- if (texture == null)
6513
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
65148454 } else
65158455 {
65168456 if (textureon)
....@@ -6535,7 +8475,7 @@
65358475 }
65368476
65378477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6538
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
65398479 cachename = texname;
65408480 else
65418481 processbump = false; // don't process bump map again
....@@ -6557,7 +8497,7 @@
65578497 }
65588498
65598499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6560
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
65618501 cachename = texname;
65628502 else
65638503 processbump = false; // don't process bump map again
....@@ -6566,20 +8506,23 @@
65668506 texturedata = GetFileTexture(cachename, processbump, resolution);
65678507
65688508
6569
- if (texturedata != null)
6570
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
65718513 //texture = GetTexture(tex, bump);
65728514 }
8515
+ }
65738516 }
65748517 //}
65758518 }
65768519
6577
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65788521 {
65798522 //return false;
65808523
65818524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6582
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65838526 {
65848527 // String ext = "_highres";
65858528 // if (REDUCETEXTURE)
....@@ -6596,52 +8539,17 @@
65968539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65978540 if (!cachefile.exists())
65988541 {
6599
- // cache to disk
6600
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6601
- //buffers[0].
6602
-
6603
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6604
- int[] pixels = new int[bytebuf.capacity()/3];
6605
-
6606
- // squared size heuristic...
6607
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
66088543 {
6609
- for (int i=pixels.length; --i>=0;)
6610
- {
6611
- int i3 = i*3;
6612
- pixels[i] = 0xFF;
6613
- pixels[i] <<= 8;
6614
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6617
- pixels[i] <<= 8;
6618
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6619
- }
6620
-
6621
- /*
6622
- int r=0,g=0,b=0,a=0;
6623
- for (int i=0; i<width; i++)
6624
- for (int j=0; j<height; j++)
6625
- {
6626
- int index = j*width+i;
6627
- int p = pixels[index];
6628
- a = ((p>>24) & 0xFF);
6629
- r = ((p>>16) & 0xFF);
6630
- g = ((p>>8) & 0xFF);
6631
- b = (p & 0xFF);
6632
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6633
- }
6634
- /**/
6635
- int width = (int)Math.sqrt(pixels.length); // squared
6636
- int height = width;
6637
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6638
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
66398546 ImageWriter writer = null;
66408547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66418548 if (iter.hasNext()) {
66428549 writer = (ImageWriter)iter.next();
66438550 }
6644
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
66458553 try
66468554 {
66478555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6658,18 +8566,20 @@
66588566 }
66598567 }
66608568 }
6661
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
66628572 //System.out.println("Texture = " + tex);
6663
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
66648574 {
6665
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
66668576 thetex.texture.disable();
66678577 thetex.texture.dispose();
6668
- textures.remove(texname);
8578
+ textures.remove(tex);
66698579 }
66708580
6671
- texture.texturedata = texturedata;
6672
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
66738583
66748584 // newtex = true;
66758585 }
....@@ -6685,42 +8595,76 @@
66858595 }
66868596 }
66878597
6688
- return texture;
8598
+ return texturecache;
66898599 }
66908600
6691
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66928636 {
66938637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66948638
66958639 if (bump)
66968640 {
6697
- // GraphreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
8641
+ // GrafreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
66988642 bumpstack[bumpdepth++] = texture!=null?texture.texture:null;
66998643 }
67008644 else
67018645 {
6702
- // GraphreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
8646
+ // GrafreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
67038647 pigmentstack[pigmentdepth++] = texture!=null?texture.texture:null;
67048648 }
67058649
67068650 return texture!=null?texture.texture:null;
67078651 }
67088652
6709
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67108654 {
67118655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67128656
67138657 return texture!=null?texture.texturedata:null;
67148658 }
67158659
6716
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67178661 {
67188662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67198663 {
67208664 return false;
67218665 }
67228666
6723
- boolean newtex = false;
8667
+ //boolean newtex = false;
67248668
67258669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67268670
....@@ -6752,9 +8696,75 @@
67528696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67538697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67548698
6755
- return newtex;
8699
+ return true; // Warning: not used.
67568700 }
67578701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
67588768 ShadowBuffer shadowPBuf;
67598769 AntialiasBuffer antialiasPBuf;
67608770 int MAXSTACK;
....@@ -6771,10 +8781,12 @@
67718781
67728782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67738783 MAXSTACK = temp[0];
6774
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67758786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67768787 MAXSTACK = temp[0];
6777
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67788790
67798791 // Use debug pipeline
67808792 //drawable.setGL(new DebugGL(gl)); //
....@@ -6782,7 +8794,8 @@
67828794 gl = drawable.getGL(); //
67838795
67848796 GL gl3 = getGL();
6785
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67868799
67878800
67888801 //float pos[] = { 100, 100, 100, 0 };
....@@ -6947,7 +8960,7 @@
69478960
69488961 if (cubemap == null)
69498962 {
6950
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
69518964 }
69528965
69538966 //cubemap.enable();
....@@ -7223,6 +9236,8 @@
72239236
72249237 void LoadEnvy(int which)
72259238 {
9239
+ assert(false);
9240
+
72269241 String name;
72279242 String ext;
72289243
....@@ -7234,37 +9249,58 @@
72349249 cubemap = null;
72359250 return;
72369251 case 1:
7237
- name = "cubemaps/box_";
7238
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
72399254 reverseUP = false;
72409255 break;
72419256 case 2:
7242
- name = "cubemaps/uffizi_";
7243
- ext = "png";
7244
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
72459261 case 3:
7246
- name = "cubemaps/CloudyHills_";
7247
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
72489264 reverseUP = false;
72499265 break;
72509266 case 4:
7251
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
72529268 ext = "png";
72539269 reverseUP = false;
72549270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
72559296 default:
7256
- name = "cubemaps/rgb_";
7257
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
72589300 break;
72599301 }
7260
-
7261
- try
7262
- {
7263
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7264
- } catch (IOException e)
7265
- {
7266
- throw new RuntimeException(e);
7267
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
72689304 }
72699305
72709306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7296,8 +9332,12 @@
72969332 static double[] model = new double[16];
72979333 double[] camera2light = new double[16];
72989334 double[] light2camera = new double[16];
7299
- int newenvy = -1;
7300
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
73019341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73029342 //float[] light0 = { 0,0,0 };
73039343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7310,9 +9350,9 @@
73109350 static boolean occlusionInitialized = false;
73119351 boolean selection = false;
73129352 boolean pointselection = false;
7313
- /*static*/ boolean lighttouched = true;
9353
+ ///*static*/ boolean lighttouched = true;
73149354 boolean deselect;
7315
- boolean ambientOcclusion = false;
9355
+ private boolean ambientOcclusion = false;
73169356 static boolean flash = false;
73179357 /*static*/ boolean wait = false;
73189358 boolean displaydone = false; // after repaint() calls
....@@ -7442,6 +9482,8 @@
74429482 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74439483 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74449484 double scale = lightCamera.SCALE / lightCamera.Distance();
9485
+// PATCH FILLE AUX JEANS
9486
+ //scale *= lightCamera.shaper_fovy / 25;
74459487 gl.glScaled(2 * scale, 2 * scale, -scale);
74469488 gl.glTranslated(0, 0, lightCamera.DECAL);
74479489
....@@ -7588,17 +9630,40 @@
75889630 jy8[3] = 0.5f;
75899631 }
75909632
7591
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75929634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
7593
- float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
9635
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9636
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75949637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
75959662 static int imagecount = 0; // movie generation
75969663
75979664 static int jitter = 0;
75989665
75999666 boolean restartframe = false;
7600
-
7601
- static int framecount = 0; // general-purpose global count
76029667
76039668 void displayAntiAliased(javax.media.opengl.GL gl)
76049669 {
....@@ -7628,14 +9693,14 @@
76289693
76299694 //System.out.println("start frame");
76309695 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
7631
- 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)
76329697 {
7633
- framecount++;
9698
+ Globals.framecount++;
76349699
76359700 if (CameraPane.tickcount > 0)
76369701 CameraPane.tickcount--;
76379702
7638
-// 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)
76399704 // restartframe = true;
76409705 if (options1[2] > 100 && (jitter%2==0))
76419706 {
....@@ -7668,7 +9733,7 @@
76689733
76699734 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76709735 */
7671
- lighttouched = true;
9736
+ Globals.lighttouched = true;
76729737 //System.err.println(" shadowbuffer: " + jitter);
76739738 shadowbuffer.display();
76749739
....@@ -7689,8 +9754,8 @@
76899754 assert (parentcam != renderCamera);
76909755
76919756 if (renderCamera != lightCamera)
7692
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7693
- LA.matConcat(parentcam.toParent, matrix, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76949759
76959760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76969761
....@@ -7705,8 +9770,8 @@
77059770 LA.matCopy(renderCamera.fromScreen, matrix);
77069771
77079772 if (renderCamera != lightCamera)
7708
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7709
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77109775
77119776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77129777
....@@ -7752,10 +9817,12 @@
77529817 rati = 1 / rati;
77539818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77549819 }
7755
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
77569823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77579824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7758
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
77599826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77609827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77619828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7778,7 +9845,7 @@
77789845 //gl.glFlush();
77799846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77809847
7781
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
77829849 {
77839850 System.err.println(" ABORTED FRAME");
77849851 break;
....@@ -7808,7 +9875,7 @@
78089875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78099876
78109877 // save image
7811
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
78129879 {
78139880 VPwidth = viewport[2];
78149881 VPheight = viewport[3];
....@@ -7919,11 +9986,11 @@
79199986
79209987 // imagecount++;
79219988
7922
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79239990
79249991 if (!BOXMODE)
79259992 {
7926
- System.out.println("image: " + fullname + " (" + (GraphreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79279994 }
79289995
79299996 if (!BOXMODE)
....@@ -7951,7 +10018,7 @@
795110018 {
795210019 if (ACSIZE > 1)
795310020 {
7954
- // System.err.println("image #" + (GraphreeD.wav.cursor / 735 / 4));
10021
+ // System.err.println("image #" + (GrafreeD.wav.cursor / 735 / 4));
795510022 }
795610023 }
795710024
....@@ -7961,7 +10028,7 @@
796110028 ABORTED = false;
796210029 }
796310030 else
7964
- GraphreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
796510032
796610033 if (false)
796710034 {
....@@ -8615,13 +10682,6 @@
861510682 }
861610683 }
861710684
8618
- boolean IsFrozen()
8619
- {
8620
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8621
-
8622
- return !selectmode && cameracount == 0; // != 0;
8623
- }
8624
-
862510685 boolean niceon = false;
862610686 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
862710687 boolean currentlydrawing = false;
....@@ -8631,16 +10691,16 @@
863110691
863210692 public void display(GLAutoDrawable drawable)
863310693 {
8634
- if (GraphreeD.savesound && GraphreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
863510695 {
8636
- GraphreeD.wav.save();
8637
- GraphreeD.savesound = false;
8638
- GraphreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
863910699 }
864010700 // if (DEBUG_SELECTION)
864110701 // {
8642
-// if (drawMode != SELECTION)
8643
-// drawMode = SELECTION;
10702
+// if (DrawMode() != SELECTION)
10703
+// DrawMode() = SELECTION;
864410704 // }
864510705
864610706 if (!isRenderer)
....@@ -8696,9 +10756,9 @@
869610756
869710757 //ANTIALIAS = 0;
869810758
8699
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10759
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870010760 {
8701
- if (niceon || isLIVE())
10761
+ if (niceon || Globals.isLIVE())
870210762 {
870310763 //if(active == 0)
870410764 // antialiaser = null;
....@@ -8711,6 +10771,7 @@
871110771 ANTIALIAS = 0;
871210772 //System.out.println("RESTART");
871310773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
871410775 }
871510776 }
871610777 }
....@@ -8723,7 +10784,7 @@
872310784 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872410785 */
872510786
8726
- if (drawMode == DEFAULT)
10787
+ if (DrawMode() == DEFAULT)
872710788 {
872810789 currentlydrawing = true;
872910790 }
....@@ -8754,18 +10815,18 @@
875410815
875510816 // if(Applet3D.clipboard != null)
875610817 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8757
-//drawMode = SELECTION;
10818
+//DrawMode() = SELECTION;
875810819 indexcount = 0;
875910820
8760
- if (drawMode == OCCLUSION)
10821
+ if (DrawMode() == OCCLUSION)
876110822 {
8762
- drawMode = DEFAULT;
10823
+ Globals.drawMode = DEFAULT; // WARNING
876310824 ambientOcclusion = true;
876410825 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876510826 Object3D theobject = object;
876610827 Object3D theparent = object.parent;
876710828 object.parent = null;
8768
- object = (Object3D)GraphreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
876910830 object.Stripify();
877010831 if (theobject.selection == null || theobject.selection.Size() == 0)
877110832 theobject.PreprocessOcclusion(this);
....@@ -8778,26 +10839,27 @@
877810839 ambientOcclusion = false;
877910840 }
878010841
8781
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878210844 {
878310845 //if (RENDERSHADOW) // ?
878410846 if (!IsFrozen())
878510847 {
878610848 // dec 2012
8787
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
878810850 {
8789
- framecount++;
10851
+ Globals.framecount++;
879010852 shadowbuffer.display();
879110853 }
879210854 }
8793
- lighttouched = false; // ??
10855
+ Globals.lighttouched = false; // ??
879410856 //drawing = true;
879510857 //lighttouched = true;
879610858 }
879710859
879810860 if (wait)
879910861 {
8800
- Sleep(500);
10862
+ Sleep(200); // blocks everything
880110863
880210864 wait = false;
880310865 }
....@@ -8811,9 +10873,9 @@
881110873 //eyeCamera.shaper_fovy = 1;
881210874 }
881310875
8814
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10876
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881510877 {
8816
- //System.out.println("drawMode = " + drawMode);
10878
+ //System.out.println("DrawMode() = " + DrawMode());
881710879 vertexMode |= VP_PASS;
881810880 //vertexMode |= VP_PROJECTION;
881910881 if (!ambientOcclusion)
....@@ -8873,7 +10935,7 @@
887310935 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887410936 //Camera lightcam = new Camera(light0);
887510937
8876
- if (drawMode == SHADOW)
10938
+ if (DrawMode() == SHADOW)
887710939 {
887810940 /*
887910941 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8911,8 +10973,8 @@
891110973
891210974 // if (parentcam != renderCamera) // not a light
891310975 if (cam != lightCamera)
8914
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8915
- LA.matConcat(parentcam.toParent, matrix, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891610978
891710979 for (int j = 0; j < 4; j++)
891810980 {
....@@ -8926,8 +10988,8 @@
892610988
892710989 // if (parentcam != renderCamera) // not a light
892810990 if (cam != lightCamera)
8929
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8930
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893110993
893210994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893310995
....@@ -8963,7 +11025,7 @@
896311025 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896411026 } else
896511027 {
8966
- if (drawMode != DEFAULT)
11028
+ if (DrawMode() != DEFAULT)
896711029 {
896811030 gl.glClearColor(1, 1, 1, 0);
896911031 } // 1);
....@@ -9013,13 +11075,41 @@
901311075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901411076 }
901511077
9016
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
901711086 {
9018
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
901911093 }
9020
-
9021
- newenvy = -1;
9022
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
902311113 ratio = ((double) getWidth()) / getHeight();
902411114 //System.out.println("ratio = " + ratio);
902511115
....@@ -9028,14 +11118,14 @@
902811118
902911119 fast &= !ambientOcclusion;
903011120
9031
- if (drawMode == DEFAULT)
11121
+ if (DrawMode() == DEFAULT)
903211122 {
903311123 //gl.glEnable(gl.GL_ALPHA_TEST);
903411124 //gl.glActiveTexture(GL.GL_TEXTURE0);
903511125
903611126 if (!IsFrozen() && !ambientOcclusion)
903711127 {
9038
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
903911129 }
904011130
904111131 //if (selection_view == -1)
....@@ -9089,6 +11179,8 @@
908911179 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909011180 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909111181 double scale = lightCamera.SCALE / lightCamera.Distance();
11182
+// PATCH FILLE AUX JEANS
11183
+ //scale *= lightCamera.shaper_fovy / 25;
909211184 gl.glScaled(2 * scale, 2 * scale, -scale);
909311185 gl.glTranslated(0, 0, lightCamera.DECAL);
909411186
....@@ -9184,7 +11276,16 @@
918411276 // Bump noise
918511277 gl.glActiveTexture(GL.GL_TEXTURE6);
918611278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9187
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
918811289
918911290 gl.glActiveTexture(GL.GL_TEXTURE0);
919011291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9207,9 +11308,9 @@
920711308
920811309 gl.glMatrixMode(GL.GL_MODELVIEW);
920911310
9210
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9211
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9212
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
921311314 } else
921411315 {
921511316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9220,14 +11321,16 @@
922011321 //System.out.println("BLENDING ON");
922111322 gl.glEnable(GL.GL_BLEND);
922211323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9223
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922411325 gl.glMatrixMode(gl.GL_PROJECTION);
922511326 gl.glLoadIdentity();
922611327
9227
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11328
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
922811329 {
922911330 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923011331 double scale = lightCamera.SCALE / lightCamera.Distance();
11332
+// PATCH FILLE AUX JEANS
11333
+ //scale *= lightCamera.shaper_fovy / 25;
923111334 gl.glScaled(2 * scale, 2 * scale, -scale);
923211335 gl.glTranslated(0, 0, lightCamera.DECAL);
923311336 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9280,7 +11383,7 @@
928011383 //gl.glPushMatrix();
928111384 gl.glLoadIdentity();
928211385
9283
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11386
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928411387 {
928511388 //LA.xformPos(light0, lightCamera.fromScreen, light);
928611389 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9307,8 +11410,8 @@
930711410 System.err.println("parentcam != renderCamera");
930811411
930911412 // if (cam != lightCamera)
9310
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9311
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
931211415 }
931311416
931411417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9329,8 +11432,8 @@
932911432 if (true) // TODO
933011433 {
933111434 if (cam != lightCamera)
9332
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9333
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933411437 }
933511438
933611439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9367,7 +11470,7 @@
936711470 }
936811471
936911472 /**/
9370
- if (true) // drawMode == SELECTION) // != DEFAULT)
11473
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937111474 gl.glDisable(gl.GL_LIGHTING);
937211475 else
937311476 gl.glEnable(gl.GL_LIGHTING);
....@@ -9379,12 +11482,13 @@
937911482
938011483 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
938111484 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11485
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
938211486
938311487 options2[0] *= renderCamera.Distance();
938411488
938511489 lightslot = 64;
938611490
9387
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11491
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
938811492 {
938911493 DrawLights(object);
939011494 }
....@@ -9395,7 +11499,7 @@
939511499 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
939611500 //System.out.println("fragmentMode = " + fragmentMode);
939711501
9398
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11502
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
939911503 {
940011504 /*
940111505 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9428,7 +11532,7 @@
942811532 }
942911533 }
943011534
9431
- if (drawMode == DEFAULT)
11535
+ if (DrawMode() == DEFAULT)
943211536 {
943311537 if (WIREFRAME && !ambientOcclusion)
943411538 {
....@@ -9446,7 +11550,7 @@
944611550 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
944711551 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
944811552
9449
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11553
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945011554 {
945111555 if (vertexMode != 0) // && !fast)
945211556 {
....@@ -9466,7 +11570,7 @@
946611570 }
946711571 }
946811572
9469
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947011574 {
947111575 //gl.glDepthFunc(GL.GL_LEQUAL);
947211576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9474,27 +11578,24 @@
947411578
947511579 boolean texon = textureon;
947611580
9477
- if (RENDERPROGRAM > 0)
9478
- {
9479
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9480
- textureon = false;
9481
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
948211584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948311585 //System.out.println("ALLO");
948411586 gl.glColorMask(false, false, false, false);
948511587 DrawObject(gl);
9486
- if (RENDERPROGRAM > 0)
9487
- {
9488
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9489
- textureon = texon;
9490
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
949111592 gl.glColorMask(true, true, true, true);
949211593
949311594 gl.glDepthFunc(GL.GL_EQUAL);
9494
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
949511596 }
949611597
9497
- if (false) // drawMode == SHADOW)
11598
+ if (false) // DrawMode() == SHADOW)
949811599 {
949911600 //SetColumnMajorData(cameraInverseTransform, view_1);
950011601 //System.out.println("light = " + cameraInverseTransform);
....@@ -9508,16 +11609,16 @@
950811609 //System.out.println("object = " + object);
950911610 if (!frozen && !imageLocked)
951011611 {
9511
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11612
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951211613 {
951311614 displayAntiAliased(gl);
951411615 } else
951511616 {
951611617 programcount = 0;
9517
- int keepmode = drawMode;
11618
+ int keepmode = DrawMode();
951811619 // if (DEBUG_SELECTION)
951911620 // {
9520
-// drawMode = SELECTION;
11621
+// DrawMode() = SELECTION;
952111622 // }
952211623 // for point selection
952311624 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9527,10 +11628,10 @@
952711628 DrawObject(gl);
952811629
952911630 // jan 2013 System.err.println("RESET ABORT (display)");
9530
- // if (drawMode == DEFAULT)
11631
+ // if (DrawMode() == DEFAULT)
953111632 // ABORTED = false;
953211633 fullreset = false;
9533
- drawMode = keepmode;
11634
+ Globals.drawMode = keepmode; // WARNING
953411635 //System.out.println("PROGRAM SWITCH " + programcount);
953511636 }
953611637 }
....@@ -9538,11 +11639,11 @@
953811639 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
953911640 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954011641
9541
- if (drawMode == DEFAULT)
11642
+ if (DrawMode() == DEFAULT)
954211643 {
954311644 ReleaseTexture(NOISE_TEXTURE, false);
954411645 }
9545
- //if (drawMode == DEFAULT)
11646
+ //if (DrawMode() == DEFAULT)
954611647 {
954711648
954811649 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9554,7 +11655,7 @@
955411655 //else
955511656 //gl.glDisable(gl.GL_TEXTURE_2D);
955611657 //gl.glPopMatrix();
9557
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11658
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
955811659 {
955911660 //new Exception().printStackTrace();
956011661 //System.out.println("Draw image " + width + ", " + height);
....@@ -9596,7 +11697,7 @@
959611697 //gl.glFlush();
959711698 }
959811699
9599
- if (flash && drawMode == DEFAULT)
11700
+ if (flash && DrawMode() == DEFAULT)
960011701 {
960111702 flash = false;
960211703 wait = true;
....@@ -9604,9 +11705,9 @@
960411705 }
960511706
960611707 //drawing = false;
9607
- //if(drawMode == DEFAULT)
11708
+ //if(DrawMode() == DEFAULT)
960811709 // niceon = false;
9609
- if (drawMode == DEFAULT)
11710
+ if (DrawMode() == DEFAULT)
961011711 {
961111712 currentlydrawing = false;
961211713 }
....@@ -9626,7 +11727,7 @@
962611727 repaint();
962711728 }
962811729
9629
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11730
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963011731 repaint();
963111732
963211733 displaydone = true;
....@@ -9645,8 +11746,14 @@
964511746 {
964611747 renderpass++;
964711748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
964811750 if (FAST) // in case there is no script
9649
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
965011757
965111758 //object.FullInvariants();
965211759
....@@ -9660,23 +11767,44 @@
966011767 e.printStackTrace();
966111768 }
966211769
9663
- if (GraphreeD.RENDERME > 0)
9664
- GraphreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
966511772
9666
- ONESTEP = false;
11773
+ Globals.ONESTEP = false;
966711774 }
966811775
966911776 static boolean zoomonce = false;
967011777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
967111796 void DrawObject(GL gl, boolean draw)
967211797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
967311801 //System.out.println("DRAW OBJECT " + mouseDown);
9674
-// drawMode = SELECTION;
11802
+// DrawMode() = SELECTION;
967511803 //GL gl = getGL();
967611804 if ((TRACK || SHADOWTRACK) || zoomonce)
967711805 {
9678
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9679
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11806
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968011808 pingthread.StepToTarget(true); // true);
968111809 // zoomonce = false;
968211810 }
....@@ -9696,9 +11824,9 @@
969611824 callist = gl.glGenLists(1);
969711825 }
969811826
9699
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11827
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970011828
9701
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11829
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970211830
970311831 if (!mainDL || !active || touched)
970411832 {
....@@ -9725,24 +11853,32 @@
972511853 PushMatrix(ClickInfo.matbuffer);
972611854 }
972711855
9728
- if (drawMode == 0)
11856
+ if (DrawMode() == 0)
972911857 {
973011858 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973111859
973211860 usedtextures.clear();
973311861
9734
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
973511870 }
973611871 //System.out.println("--> " + stackdepth);
9737
-// GraphreeD.traceon();
11872
+// GrafreeD.traceon();
973811873
973911874 // DRAW
974011875 object.draw(this, /*(Composite)*/ object, false, false);
974111876
9742
- if (drawMode == DEFAULT)
11877
+ if (DrawMode() == DEFAULT)
974311878 {
9744
- if (DEBUG)
11879
+ if (Globals.DEBUG)
974511880 {
11881
+ CreateSelectedPoint();
974611882 float radius = 0.05f;
974711883 if (selectedpoint.radius != radius)
974811884 {
....@@ -9750,69 +11886,104 @@
975011886 selectedpoint.radius = radius;
975111887 selectedpoint.recalculate();
975211888 selectedpoint.material = new cMaterial();
9753
- selectedpoint.material.color = 0.25f;
11889
+ selectedpoint.material.color = 0.15f; // Yellow
975411890 selectedpoint.material.modulation = 0.75f;
975511891
9756
- debugpoint.radius = radius;
9757
- debugpoint.recalculate();
9758
- debugpoint.material = new cMaterial();
9759
- debugpoint.material.color = 0.25f;
9760
- debugpoint.material.modulation = 0.75f;
11892
+ debugpointG.radius = radius;
11893
+ debugpointG.recalculate();
11894
+ debugpointG.material = new cMaterial();
11895
+ debugpointG.material.color = 0.25f; // Green
11896
+ debugpointG.material.modulation = 0.75f;
976111897
9762
- debugpoint2.radius = radius;
9763
- debugpoint2.recalculate();
9764
- debugpoint2.material = new cMaterial();
9765
- debugpoint2.material.color = 0.75f;
9766
- debugpoint2.material.modulation = 0.75f;
11898
+ debugpointP.radius = radius;
11899
+ debugpointP.recalculate();
11900
+ debugpointP.material = new cMaterial();
11901
+ debugpointP.material.color = 0.75f; // Purple
11902
+ debugpointP.material.modulation = 0.75f;
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;
976711915
976811916 InitPoints(radius);
976911917 }
977011918 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9771
- //debugpoint.draw(this, /*(Composite)*/ null, false);
9772
- //debugpoint2.draw(this, /*(Composite)*/ null, false);
9773
- 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);
977411924 }
977511925
977611926 // debugstuff.draw(this, /*(Composite)*/ null, false);
977711927 }
9778
-// GraphreeD.traceoff();
11928
+// GrafreeD.traceoff();
977911929 //System.out.println(stackdepth);
9780
- if (drawMode == 0)
11930
+ if (DrawMode() == 0)
978111931 {
978211932 ReleaseTextures(DEFAULT_TEXTURES);
978311933
978411934 if (CLEANCACHE)
9785
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
978611936 {
9787
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
978811938
978911939 // System.out.println("Texture --------- " + tex);
979011940
9791
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
979211942 continue;
979311943
9794
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
979511945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
979611947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9797
- textures.get(tex).texture.dispose();
9798
- 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
+ }
979911961 }
980011962 }
980111963 }
980211964
980311965 checker = null;
980411966
9805
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11967
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
980611968 FindChecker(object);
980711969
9808
- if (checker != null && drawMode == DEFAULT)
11970
+ if (checker != null && DrawMode() == DEFAULT)
980911971 {
9810
- // 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
+ }
981111981 // NEAREST
981211982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
981311983 DrawChecker(gl);
981411984 //checker.Draw(this, null, false);
981511985 // ReleaseTexture(IMMORTAL_TEXTURE);
11986
+ ReleaseTextures(checker.GetTextures());
981611987 }
981711988
981811989 if (object.parent != null)
....@@ -9825,7 +11996,7 @@
982511996 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
982611997 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
982711998
9828
- if (DISPLAYTEXT && drawMode == DEFAULT)
11999
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
982912000 {
983012001 // Draw it once, then use the raster
983112002 Balloon(gl, balloon.createGraphics());
....@@ -9881,14 +12052,14 @@
988112052 int[] xs = new int[3];
988212053 int[] ys = new int[3];
988312054
9884
- void DrawString(Object3D obj) // String string)
12055
+ public void DrawString(Object3D obj) // String string) // INTERFACE
988512056 {
9886
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12057
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
988712058 {
988812059 return;
988912060 }
989012061
9891
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
989212063
989312064 GL gl = GetGL();
989412065
....@@ -10205,8 +12376,8 @@
1020512376 //obj.TransformToWorld(light, light);
1020612377 for (int i = tp.size(); --i >= 0;)
1020712378 {
10208
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10209
- 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);
1021012381 }
1021112382
1021212383
....@@ -10223,8 +12394,8 @@
1022312394 parentcam = cameras[0];
1022412395 }
1022512396
10226
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10227
- 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
1022812399
1022912400 LA.xformPos(light, renderCamera.toScreen, light);
1023012401
....@@ -10314,8 +12485,76 @@
1031412485
1031512486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1031612487
10317
- String program =
12488
+ String programmin =
12489
+ // Min shader
1031812490 "!!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
+
1031912558 //"OPTION ARB_fragment_program_shadow;" +
1032012559 "PARAM light2cam0 = program.env[10];" +
1032112560 "PARAM light2cam1 = program.env[11];" +
....@@ -10343,11 +12582,13 @@
1034312582 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1034412583 "PARAM params7 = program.env[7];" + // noise power, opacity power
1034512584 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10346
- "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
1034712587 "PARAM pointlight = program.env[127];" + // ...
1034812588 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1034912589 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1035012590 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12591
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1035112592 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1035212593 "PARAM ten = { 10, 10, 10, 1.0 };" +
1035312594 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10368,6 +12609,7 @@
1036812609 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1036912610 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1037012611 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12612
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1037112613 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1037212614 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1037312615 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10408,6 +12650,10 @@
1040812650 "TEMP R1;" +
1040912651 "TEMP R2;" +
1041012652 "TEMP R3;" +
12653
+ "TEMP min;" +
12654
+ "TEMP max;" +
12655
+ "TEMP average;" +
12656
+ "TEMP saturation;" +
1041112657 "TEMP keep1;" +
1041212658 "TEMP keep2;" +
1041312659 "TEMP keep3;" +
....@@ -10423,8 +12669,7 @@
1042312669 "TEMP shininess;" +
1042412670 "\n" +
1042512671 "MOV texSamp, one;" +
10426
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10427
-
12672
+
1042812673 "MOV mapgrid.x, one2048th.x;" +
1042912674 "MOV temp, fragment.texcoord[1];" +
1043012675 /*
....@@ -10445,20 +12690,20 @@
1044512690 "MUL temp, floor, mapgrid.x;" +
1044612691 //"TEX depth0, temp, texture[1], 2D;" +
1044712692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10448
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1044912694 "") +
1045012695 "ADD temp.x, temp.x, mapgrid.x;" +
1045112696 //"TEX depth1, temp, texture[1], 2D;" +
1045212697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10453
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1045412699 "") +
1045512700 "ADD temp.y, temp.y, mapgrid.x;" +
1045612701 //"TEX depth2, temp, texture[1], 2D;" +
10457
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1045812703 "SUB temp.x, temp.x, mapgrid.x;" +
1045912704 //"TEX depth3, temp, texture[1], 2D;" +
1046012705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10461
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1046212707 "") +
1046312708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1046412709 //"MOV params, material;" +
....@@ -10829,10 +13074,10 @@
1082913074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1083013075 "") +
1083113076
10832
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1083313078 "SUB temp.x, half.x, shadow.x;" +
10834
- "MOV temp.y, -params6.x;" +
10835
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1083613081 "SUB temp.y, one.x, temp.z;" +
1083713082 "MUL temp.x, temp.x, temp.y;" +
1083813083 "KIL temp.x;" +
....@@ -10938,10 +13183,42 @@
1093813183
1093913184 // skin?
1094013185 // Saturation for skin
10941
- /**/ // c'est ici
10942
- (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;" +
1094313219 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10944
- "SUB temp, final,R2;" +
13220
+ "SUB temp, final, R2;" +
13221
+
1094513222 // using light angle
1094613223 "DP3 ndotl.x, normald,light;" +
1094713224 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10954,7 +13231,6 @@
1095413231 // using light intensity
1095513232 "MOV ndotl.z, R2.x;" +
1095613233 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10957
-
1095813234 // june 2014
1095913235 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1096013236 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10966,6 +13242,7 @@
1096613242 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1096713243
1096813244 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13245
+/**/
1096913246
1097013247 // "ADD final, R2,temp;" +
1097113248 "MOV final, temp;"
....@@ -11055,7 +13332,7 @@
1105513332 /**/
1105613333 // HDR
1105713334 "MOV temp.z, final.a;" +
11058
- "MUL final, final,options1.w;" +
13335
+ "MUL final, final,options2.x;" +
1105913336 "MOV final.a, temp.z;" +
1106013337 /**/
1106113338
....@@ -11092,10 +13369,17 @@
1109213369 "MOV final.z, zero.x;" +
1109313370 "MOV final.a, one.w;":""
1109413371 ) +
13372
+ /*
1109513373 (NORMALdebug?"MOV final.x, normal.x;" +
1109613374 "MOV final.y, normal.y;" +
1109713375 "MOV final.z, normal.z;" +
1109813376 "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;":""
1109913383 ) +
1110013384 // "MOV final, bumpmap;" +
1110113385 "MOV result.color, final;" +
....@@ -11124,7 +13408,14 @@
1112413408 //once = true;
1112513409 }
1112613410
11127
- 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());
1112813419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1112913420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1113013421
....@@ -11217,30 +13508,32 @@
1121713508 return out;
1121813509 }
1121913510
11220
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1122113513 {
1122213514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1122313515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1122413516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1122513519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11226
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11227
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11228
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11229
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1123013522 //"SWZ buffer, temp, w,w,w,w;";
11231
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1123213524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1123313525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1123413526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11235
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1123613528
11237
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11238
- //"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;";
1123913531 }
1124013532
1124113533 String Shadow(String depth, String shadow)
1124213534 {
1124313535 return "MAX temp.x, ndotl.x, one64th.x;" +
13536
+ "MIN temp.x, temp.x, ninetenth.x;" +
1124413537 /**/
1124513538 // Sine
1124613539 "MUL temp.y, temp.x, temp.x;" +
....@@ -11256,12 +13549,16 @@
1125613549
1125713550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1125813551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1125913554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1126013555 "SGE temp.y, temp.x, zero.x;" +
11261
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1126213559 "SUB temp.x, one.x, temp.x;" +
1126313560 "MUL " + shadow + ".x, temp.x, temp.y;" +
11264
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1126513562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1126613563
1126713564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11275,6 +13572,10 @@
1127513572 // No shadow for backface
1127613573 "DP3 temp.x, normal, lightd;" +
1127713574 "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;" +
1127813579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1127913580 "";
1128013581 }
....@@ -11421,7 +13722,8 @@
1142113722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1142213723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1142313724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11424
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1142513727
1142613728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1142713729 // OUT : diff, spec
....@@ -11437,9 +13739,10 @@
1143713739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1143813740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1143913741 //"MOV " + dest + ".w," + "normal.z;" +
11440
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11441
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11442
- //"MOV " + dest + ".z," + "params2.w;" +
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
1144313746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1144413747 "RCP " + dest + ".w," + dest + ".w;" +
1144513748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11833,7 +14136,7 @@
1183314136 public void mousePressed(MouseEvent e)
1183414137 {
1183514138 //System.out.println("mousePressed: " + e);
11836
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1183714140 }
1183814141
1183914142 static long prevtime = 0;
....@@ -11860,14 +14163,16 @@
1186014163
1186114164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1186214165
14166
+ if (BUTTONLESSWHEEL)
1186314167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1186414168 {
1186514169 return;
1186614170 }
1186714171
14172
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1186814173
1186914174 // TIMER
11870
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1187114176 {
1187214177 keepboxmode = BOXMODE;
1187314178 keepsupport = SUPPORT;
....@@ -11907,8 +14212,8 @@
1190714212 // mode |= META;
1190814213 //}
1190914214
11910
- SetMouseMode(WHEEL | e.getModifiersEx());
11911
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1191214217 anchorX = ax;
1191314218 anchorY = ay;
1191414219 prevX = px;
....@@ -11942,6 +14247,7 @@
1194214247 else
1194314248 if (evt.getSource() == AAtimer)
1194414249 {
14250
+ Globals.TIMERRUNNING = false;
1194514251 if (mouseDown)
1194614252 {
1194714253 //new Exception().printStackTrace();
....@@ -11967,6 +14273,10 @@
1196714273 // LIVE = waslive;
1196814274 // wasliveok = true;
1196914275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1197014280
1197114281 // source == timer
1197214282 if (mouseDown)
....@@ -11996,8 +14306,8 @@
1199614306 // ObjEditor.tweenManager.update(1f / 60f);
1199714307
1199814308 // fev 2014???
11999
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12000
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14309
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1200114311 pingthread.StepToTarget(true); // true);
1200214312 }
1200314313 // if (!LIVE)
....@@ -12006,12 +14316,13 @@
1200614316
1200714317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1200814318
12009
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1201014320 {
1201114321 if (!wasliveok)
1201214322 return;
1201314323
1201414324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1201514326
1201614327 // waslive = LIVE;
1201714328 // LIVE = false;
....@@ -12023,7 +14334,7 @@
1202314334 // touched = true; // main DL
1202414335 if (isRenderer)
1202514336 {
12026
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1202714338 }
1202814339
1202914340 selectX = anchorX = x;
....@@ -12036,7 +14347,7 @@
1203614347 clicked = true;
1203714348 hold = false;
1203814349
12039
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1204014351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1204114352 {
1204214353 // System.out.println("RESTART II " + modifiers);
....@@ -12061,14 +14372,15 @@
1206114372 drag = false;
1206214373 //System.out.println("Mouse DOWN");
1206314374 editObj = false;
12064
- ClickInfo info = new ClickInfo();
12065
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12066
- info.pane = this;
12067
- info.camera = renderCamera;
12068
- info.x = x;
12069
- info.y = y;
12070
- info.modifiers = modifiers;
12071
- editObj = object.doEditClick(info, 0);
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);
1207214384 if (!editObj)
1207314385 {
1207414386 hasMarquee = true;
....@@ -12084,11 +14396,14 @@
1208414396
1208514397 public void mouseDragged(MouseEvent e)
1208614398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1208714402 if (isRenderer)
1208814403 movingcamera = true;
14404
+
1208914405 //if (drawing)
1209014406 //return;
12091
- //System.out.println("mouseDragged: " + e);
1209214407 if ((e.getModifiersEx() & CTRL) != 0
1209314408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1209414409 {
....@@ -12096,7 +14411,7 @@
1209614411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1209714412 }
1209814413 else
12099
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1210014415
1210114416 //try { Thread.sleep(1); } catch (Exception ex) {}
1210214417 }
....@@ -12108,6 +14423,11 @@
1210814423 cVector tmp = new cVector();
1210914424 cVector tmp2 = new cVector();
1211014425 boolean isMoving;
14426
+
14427
+ public cVector TargetLookAt()
14428
+ {
14429
+ return targetLookAt;
14430
+ }
1211114431
1211214432 class PingThread extends Thread
1211314433 {
....@@ -12247,7 +14567,7 @@
1224714567 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1224814568 if (lightMode)
1224914569 {
12250
- lighttouched = true;
14570
+ Globals.lighttouched = true;
1225114571 }
1225214572
1225314573 if (OEILONCE && OEIL)
....@@ -12264,6 +14584,7 @@
1226414584
1226514585 public void run()
1226614586 {
14587
+ new Exception().printStackTrace();
1226714588 System.exit(0);
1226814589 for (;;)
1226914590 {
....@@ -12305,7 +14626,7 @@
1230514626 mouseDown = false;
1230614627 if (lightMode)
1230714628 {
12308
- lighttouched = true;
14629
+ Globals.lighttouched = true;
1230914630 }
1231014631 repaint();
1231114632 alreadypainted = true;
....@@ -12313,7 +14634,7 @@
1231314634 isMoving = false;
1231414635 } //??
1231514636
12316
- if (isLIVE() && !alreadypainted)
14637
+ if (Globals.isLIVE() && !alreadypainted)
1231714638 {
1231814639 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1231914640 repaint();
....@@ -12325,9 +14646,9 @@
1232514646 {
1232614647 if (lightMode)
1232714648 {
12328
- lighttouched = true;
14649
+ Globals.lighttouched = true;
1232914650 }
12330
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1233114652 }
1233214653 //else
1233314654 }
....@@ -12341,12 +14662,12 @@
1234114662 void GoDown(int mod)
1234214663 {
1234314664 MODIFIERS |= COMMAND;
12344
- /*
14665
+ /**/
1234514666 if((mod&SHIFT) == SHIFT)
12346
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1234714668 else
12348
- manipCamera.BackForth(0, -speed*delta, getWidth());
12349
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1235014671 if ((mod & SHIFT) == SHIFT)
1235114672 {
1235214673 mouseMode = mouseMode; // VR??
....@@ -12362,12 +14683,12 @@
1236214683 void GoUp(int mod)
1236314684 {
1236414685 MODIFIERS |= COMMAND;
12365
- /*
14686
+ /**/
1236614687 if((mod&SHIFT) == SHIFT)
12367
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1236814689 else
12369
- manipCamera.BackForth(0, speed*delta, getWidth());
12370
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1237114692 if ((mod & SHIFT) == SHIFT)
1237214693 {
1237314694 mouseMode = mouseMode;
....@@ -12383,12 +14704,12 @@
1238314704 void GoLeft(int mod)
1238414705 {
1238514706 MODIFIERS |= COMMAND;
12386
- /*
14707
+ /**/
1238714708 if((mod&SHIFT) == SHIFT)
12388
- manipCamera.RotatePosition(speed, 0);
12389
- else
1239014709 manipCamera.Translate(speed*delta, 0, getWidth());
12391
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1239214713 if ((mod & SHIFT) == SHIFT)
1239314714 {
1239414715 mouseMode = mouseMode;
....@@ -12404,12 +14725,12 @@
1240414725 void GoRight(int mod)
1240514726 {
1240614727 MODIFIERS |= COMMAND;
12407
- /*
14728
+ /**/
1240814729 if((mod&SHIFT) == SHIFT)
12409
- manipCamera.RotatePosition(-speed, 0);
12410
- else
1241114730 manipCamera.Translate(-speed*delta, 0, getWidth());
12412
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1241314734 if ((mod & SHIFT) == SHIFT)
1241414735 {
1241514736 mouseMode = mouseMode;
....@@ -12427,7 +14748,7 @@
1242714748 int X, Y;
1242814749 boolean SX, SY;
1242914750
12430
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1243114752 {
1243214753 if (IsFrozen())
1243314754 {
....@@ -12436,17 +14757,17 @@
1243614757
1243714758 drag = true; // NEW
1243814759
12439
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1244014761
1244114762 X = x;
1244214763 Y = y;
1244314764 // floating state for animation
12444
- MODIFIERS = modifiers;
12445
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1244614767 if (false) // modifiers != 0)
1244714768 {
1244814769 //new Exception().printStackTrace();
12449
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1245014771 System.out.println("SHIFT = " + SHIFT);
1245114772 System.out.println("CONTROL = " + COMMAND);
1245214773 System.out.println("META = " + META);
....@@ -12459,14 +14780,16 @@
1245914780 if (editObj)
1246014781 {
1246114782 drag = true;
12462
- ClickInfo info = new ClickInfo();
12463
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1246414785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12465
- info.pane = this;
12466
- info.camera = renderCamera;
12467
- info.x = x;
12468
- info.y = y;
12469
- object.editWindow.copy.doEditDrag(info);
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);
1247014793 } else
1247114794 {
1247214795 if (x < startX)
....@@ -12568,6 +14891,7 @@
1256814891 {
1256914892 manipCamera.Translate(dx, dy, getWidth());
1257014893 }
14894
+ else
1257114895 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1257214896 {
1257314897 manipCamera.RotateInterest(dx, dy);
....@@ -12578,7 +14902,7 @@
1257814902
1257914903 if (manipCamera == lightCamera)
1258014904 {
12581
- lighttouched = true;
14905
+ Globals.lighttouched = true;
1258214906 }
1258314907 /*
1258414908 switch (mode)
....@@ -12614,23 +14938,27 @@
1261414938 }
1261514939 }
1261614940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1261714943 public void mouseMoved(MouseEvent e)
1261814944 {
1261914945 //System.out.println("mouseMoved: " + e);
12620
-
1262114946 if (isRenderer)
1262214947 return;
1262314948
12624
- ClickInfo ci = new ClickInfo();
12625
- ci.x = e.getX();
12626
- ci.y = e.getY();
12627
- ci.modifiers = e.getModifiersEx();
12628
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12629
- ci.pane = this;
12630
- ci.camera = renderCamera;
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;
1263114956 if (!isRenderer)
1263214957 {
12633
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1263414962 {
1263514963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1263614964 } else
....@@ -12642,7 +14970,11 @@
1264214970
1264314971 public void mouseReleased(MouseEvent e)
1264414972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1264514975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1264614978 //System.out.println("mouseReleased: " + e);
1264714979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1264814980 }
....@@ -12665,9 +14997,9 @@
1266514997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1266614998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1266714999
12668
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1266915001 timeout = true;
12670
- else
15002
+// ?? May 2019 else
1267115003 // timer.setDelay((modifiers & 128) != 0?0:350);
1267215004 mouseDown = false;
1267315005 if (!control && !command) // june 2013
....@@ -12777,7 +15109,7 @@
1277715109 System.out.println("keyReleased: " + e);
1277815110 }
1277915111
12780
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1278115113 {
1278215114 //System.out.println("SetMouseMode = " + modifiers);
1278315115 //modifiers &= ~1024;
....@@ -12789,24 +15121,27 @@
1278915121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1279015122 // return;
1279115123 //System.out.println("SetMode = " + modifiers);
12792
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1279315125 {
1279415126 mouseMode |= ZOOM;
1279515127 }
12796
- if ((modifiers & META) == META)
15128
+
15129
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15130
+ if (capsLocked) // || (modifiers & META) == META)
1279715131 {
1279815132 mouseMode |= VR; // BACKFORTH;
1279915133 }
12800
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12801
- {
12802
- mouseMode |= SELECT; // BACKFORTH;
12803
- }
12804
- if ((modifiers & COMMAND) == COMMAND)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1280515135 {
1280615136 mouseMode |= SELECT;
1280715137 }
12808
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1280915139 {
15140
+ mouseMode |= SELECT;
15141
+ }
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15143
+ {
15144
+ mouseMode &= ~VR;
1281015145 mouseMode |= TRANSLATE;
1281115146 }
1281215147 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12833,10 +15168,10 @@
1283315168
1283415169 if (isRenderer) //
1283515170 {
12836
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1283715172 }
1283815173
12839
- theRenderer.keyPressed(key);
15174
+ Globals.theRenderer.keyPressed(key);
1284015175 }
1284115176
1284215177 int kompactbit = 4; // power bit
....@@ -12848,7 +15183,7 @@
1284815183 float SATPOW = 1; // 2; // 0.5f;
1284915184 float BRIPOW = 1; // 0.5f; // 0.5f;
1285015185
12851
- void keyPressed(int key)
15186
+ public void keyPressed(int key)
1285215187 {
1285315188 if (key >= '0' && key <= '5')
1285415189 clampbit = (key-'0');
....@@ -12895,7 +15230,8 @@
1289515230 // break;
1289615231 case 'T':
1289715232 CACHETEXTURE ^= true;
12898
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1289915235 // repaint();
1290015236 break;
1290115237 case 'Y':
....@@ -12963,7 +15299,7 @@
1296315299 case 'B':
1296415300 BRISMOOTH ^= true;
1296515301 SHADOWCULLFACE ^= true;
12966
- lighttouched = true;
15302
+ Globals.lighttouched = true;
1296715303 repaint();
1296815304 break;
1296915305 case 'b':
....@@ -12980,7 +15316,9 @@
1298015316 case 'E' : COMPACT ^= true;
1298115317 repaint();
1298215318 break;
12983
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1298415322 repaint();
1298515323 break;
1298615324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13005,8 +15343,8 @@
1300515343 RevertCamera();
1300615344 repaint();
1300715345 break;
13008
- case 'L':
1300915346 case 'l':
15347
+ //case 'L':
1301015348 if (lightMode)
1301115349 {
1301215350 lightMode = false;
....@@ -13063,27 +15401,31 @@
1306315401 repaint();
1306415402 break;
1306515403 case 'O':
13066
- drawMode = OCCLUSION;
15404
+ Globals.drawMode = OCCLUSION; // WARNING
1306715405 repaint();
1306815406 break;
1306915407 case 'o':
1307015408 OCCLUSION_CULLING ^= true;
1307115409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1307215410 break;
13073
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1307415412 case '1':
1307515413 case '2':
1307615414 case '3':
1307715415 case '4':
1307815416 case '5':
13079
- newenvy = Character.getNumericValue(key);
13080
- repaint();
13081
- break;
1308215417 case '6':
1308315418 case '7':
1308415419 case '8':
1308515420 case '9':
13086
- 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
+ }
1308715429 repaint();
1308815430 break;
1308915431 case '!':
....@@ -13149,12 +15491,12 @@
1314915491 case '_':
1315015492 kompactbit = 5;
1315115493 break;
13152
- case '+':
13153
- kompactbit = 6;
13154
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1315515497 case ' ':
1315615498 lightMode ^= true;
13157
- lighttouched = true;
15499
+ Globals.lighttouched = true;
1315815500 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1315915501 targetLookAt.set(manipCamera.lookAt);
1316015502 repaint();
....@@ -13163,14 +15505,15 @@
1316315505 case ESC:
1316415506 RENDERPROGRAM += 1;
1316515507 RENDERPROGRAM %= 3;
15508
+
1316615509 repaint();
1316715510 break;
1316815511 case 'Z':
13169
- RESIZETEXTURE ^= true;
13170
- break;
15512
+ //RESIZETEXTURE ^= true;
15513
+ //break;
1317115514 case 'z':
13172
- RENDERSHADOW ^= true;
13173
- lighttouched = true;
15515
+ Globals.RENDERSHADOW ^= true;
15516
+ Globals.lighttouched = true;
1317415517 repaint();
1317515518 break;
1317615519 //case UP:
....@@ -13196,13 +15539,15 @@
1319615539 FlipTransform();
1319715540 break;
1319815541 case ENTER:
13199
- object.editWindow.ScreenFit(); // Edit();
15542
+ // object.editWindow.ScreenFit(); // Edit();
15543
+ ToggleLive();
1320015544 break;
1320115545 case DELETE:
1320215546 ClearSelection();
1320315547 break;
13204
- /*
1320515548 case '+':
15549
+
15550
+ /*
1320615551 //fontsize += 1;
1320715552 bbzoom *= 2;
1320815553 repaint();
....@@ -13219,17 +15564,17 @@
1321915564 case '=':
1322015565 IncDepth();
1322115566 //fontsize += 1;
13222
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1322315568 maskbit = 6;
1322415569 break;
1322515570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1322615571 DecDepth();
1322715572 maskbit = 5;
1322815573 //if(fontsize > 1) fontsize -= 1;
13229
- if (object.editWindow == null)
13230
- new Exception().printStackTrace();
13231
- else
13232
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1323315578 break;
1323415579 case '{':
1323515580 manipCamera.shaper_fovy /= 1.1;
....@@ -13284,6 +15629,7 @@
1328415629 }
1328515630 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1328615631 }
15632
+
1328715633 static double OCCLUSIONBOOST = 1; // 0.5;
1328815634
1328915635 void keyReleased(int key, int modifiers)
....@@ -13291,11 +15637,11 @@
1329115637 //mode = ROTATE;
1329215638 if ((MODIFIERS & COMMAND) == 0) // VR??
1329315639 {
13294
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1329515641 }
1329615642 }
1329715643
13298
- protected void processKeyEvent(KeyEvent e)
15644
+ public void processKeyEvent(KeyEvent e)
1329915645 {
1330015646 switch (e.getID())
1330115647 {
....@@ -13425,8 +15771,9 @@
1342515771
1342615772 protected void processMouseMotionEvent(MouseEvent e)
1342715773 {
13428
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13429
- 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)
1343015777 {
1343115778 mouseMoved(e);
1343215779 } else
....@@ -13451,11 +15798,12 @@
1345115798 }
1345215799 */
1345315800
13454
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1345515802 }
1345615803
1345715804 void SelectParent()
1345815805 {
15806
+ new Exception().printStackTrace();
1345915807 System.exit(0);
1346015808 Composite group = (Composite) object;
1346115809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13467,10 +15815,10 @@
1346715815 {
1346815816 //selectees.remove(i);
1346915817 System.out.println("select parent of " + elem);
13470
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1347115819 } else
1347215820 {
13473
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1347415822 }
1347515823
1347615824 first = false;
....@@ -13479,6 +15827,7 @@
1347915827
1348015828 void SelectChildren()
1348115829 {
15830
+ new Exception().printStackTrace();
1348215831 System.exit(0);
1348315832 /*
1348415833 Composite group = (Composite) object;
....@@ -13511,12 +15860,12 @@
1351115860 for (int j = 0; j < group.children.size(); j++)
1351215861 {
1351315862 elem = (Object3D) group.children.elementAt(j);
13514
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1351515864 first = false;
1351615865 }
1351715866 } else
1351815867 {
13519
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1352015869 }
1352115870
1352215871 first = false;
....@@ -13527,21 +15876,21 @@
1352715876 {
1352815877 //Composite group = (Composite) object;
1352915878 Object3D group = object;
13530
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1353115880 }
1353215881
1353315882 void ResetTransform(int mask)
1353415883 {
1353515884 //Composite group = (Composite) object;
1353615885 Object3D group = object;
13537
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1353815887 }
1353915888
1354015889 void FlipTransform()
1354115890 {
1354215891 //Composite group = (Composite) object;
1354315892 Object3D group = object;
13544
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1354515894 // group.editWindow.ReduceMesh(true);
1354615895 }
1354715896
....@@ -13549,7 +15898,7 @@
1354915898 {
1355015899 //Composite group = (Composite) object;
1355115900 Object3D group = object;
13552
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1355315902 // group.editWindow.ReduceMesh(true);
1355415903 }
1355515904
....@@ -13557,7 +15906,7 @@
1355715906 {
1355815907 //Composite group = (Composite) object;
1355915908 Object3D group = object;
13560
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1356115910 }
1356215911
1356315912 void IncDepth()
....@@ -13639,11 +15988,11 @@
1363915988
1364015989 int width = getBounds().width;
1364115990 int height = getBounds().height;
13642
- ClickInfo info = new ClickInfo();
13643
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1364415991 //Image img = CreateImage(width, height);
1364515992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1364615994 Graphics gr = g; // img.getGraphics();
15995
+
1364715996 if (!hasMarquee)
1364815997 {
1364915998 if (Xmin < Xmax) // !locked)
....@@ -13715,40 +16064,88 @@
1371516064 }
1371616065 if (object != null && !hasMarquee)
1371716066 {
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
+
1371816073 if (isRenderer)
1371916074 {
13720
- info.flags++;
16075
+ object.clickInfo.flags++;
1372116076 double frameAspect = (double) width / (double) height;
1372216077 if (frameAspect > renderCamera.aspect)
1372316078 {
1372416079 int desired = (int) ((double) height * renderCamera.aspect);
13725
- info.bounds.width -= width - desired;
13726
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1372716082 } else
1372816083 {
1372916084 int desired = (int) ((double) width / renderCamera.aspect);
13730
- info.bounds.height -= height - desired;
13731
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1373216087 }
1373316088 }
13734
- info.g = gr;
13735
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1373616092 /*
1373716093 // Memory intensive (brep.verticescopy)
1373816094 if (!(object instanceof Composite))
1373916095 object.draw(info, 0, false); // SLOW :
1374016096 */
13741
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1374216098 {
13743
- 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
+ }
1374416139 }
1374516140 }
16141
+
1374616142 if (isRenderer)
1374716143 {
1374816144 //gr.setColor(Color.black);
1374916145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1375016146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1375116147 }
16148
+
1375216149 if (hasMarquee)
1375316150 {
1375416151 gr.setXORMode(Color.white);
....@@ -13771,6 +16168,7 @@
1377116168 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1377216169 }
1377316170
16171
+ // To avoid clear.
1377416172 public void update(Graphics g)
1377516173 {
1377616174 paint(g);
....@@ -13860,6 +16258,7 @@
1386016258 public boolean mouseDown(Event evt, int x, int y)
1386116259 {
1386216260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1386316262 /*
1386416263 locked = true;
1386516264 drag = false;
....@@ -13903,7 +16302,7 @@
1390316302 {
1390416303 keyPressed(0, modifiers);
1390516304 }
13906
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1390716306 return true;
1390816307 }
1390916308
....@@ -14021,7 +16420,7 @@
1402116420 {
1402216421 keyReleased(0, 0);
1402316422 }
14024
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1402516424 return true;
1402616425 }
1402716426
....@@ -14153,7 +16552,7 @@
1415316552 Object3D object;
1415416553 static Object3D trackedobject;
1415516554 Camera renderCamera; // Light or Eye (or Occlusion)
14156
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1415716556 /*static*/ Camera eyeCamera;
1415816557 /*static*/ Camera lightCamera;
1415916558 int cameracount;
....@@ -14217,6 +16616,8 @@
1421716616 private /*static*/ boolean firstime;
1421816617 private /*static*/ cVector newView = new cVector();
1421916618 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"};
1422016621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1422116622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1422216623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14229,29 +16630,67 @@
1422916630 {
1423016631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1423116632
16633
+ int usedsuf = 0;
16634
+
1423216635 for (int i = 0; i < suffixes.length; i++)
1423316636 {
14234
- String resourceName = basename + suffixes[i] + "." + suffix;
14235
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14236
- mipmapped,
14237
- FileUtil.getFileSuffix(resourceName));
14238
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1423916642 {
14240
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1424116647 }
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
+
1424216676 //System.out.println("Target = " + targets[i]);
1424316677 cubemap.updateImage(data, targets[i]);
1424416678 }
1424516679
1424616680 return cubemap;
1424716681 }
16682
+
1424816683 int bigsphere = -1;
1424916684
1425016685 float BGcolor = 0.5f;
1425116686
14252
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1425316690 {
14254
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1425516694 {
1425616695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1425716696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14266,7 +16705,17 @@
1426616705 // Compensates for ExaminerViewer's modification of modelview matrix
1426716706 gl.glMatrixMode(GL.GL_MODELVIEW);
1426816707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1426916709
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
+
1427016719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1427116720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1427216721
....@@ -14298,6 +16747,7 @@
1429816747 {
1429916748 gl.glScalef(1.0f, -1.0f, 1.0f);
1430016749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1430116751 gl.glMultMatrixd(viewrot_1, 0);
1430216752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1430316753 //viewer.updateInverseRotation(gl);
....@@ -14373,7 +16823,7 @@
1437316823 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1437416824 gl.glPushMatrix();
1437516825 gl.glLoadIdentity();
14376
- PushMatrix(checker.toParent);
16826
+ //PushMatrix(checker.toParent);
1437716827
1437816828 gl.glMatrixMode(GL.GL_TEXTURE);
1437916829 gl.glPushMatrix();
....@@ -14396,8 +16846,8 @@
1439616846
1439716847 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1439816848
14399
- float step = 0.1666f; //0.25f;
14400
- float stepv = step * 1652 / 998;
16849
+ float step = 2; // 0.1666f; //0.25f;
16850
+ float stepv = 2; // step * 1652 / 998;
1440116851
1440216852 int i0 = 0;
1440316853 /*
....@@ -14433,20 +16883,21 @@
1443316883 /**/
1443416884 //checker.GetMaterial().opacity = 1.1f;
1443516885 ////checker.GetMaterial().ambient = 0.99f;
14436
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14437
- Object3D.selectedstack[Object3D.materialdepth] = false;
14438
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16886
+ materialstack[materialdepth] = checker.material;
16887
+ selectedstack[materialdepth] = false;
16888
+ cStatic.objectstack[materialdepth++] = checker;
1443916889 //System.out.println("material " + material);
1444016890 //Applet3D.tracein(this, selected);
14441
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1444216892
14443
- checker.GetMaterial().Draw(this, false); // true);
16893
+ //checker.GetMaterial().Draw(this, false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1444416895
14445
- Object3D.materialdepth -= 1;
14446
- if (Object3D.materialdepth > 0)
16896
+ materialdepth -= 1;
16897
+ if (materialdepth > 0)
1444716898 {
14448
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14449
- 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);
1445016901 }
1445116902 //checker.GetMaterial().opacity = 1f;
1445216903 ////checker.GetMaterial().ambient = 1f;
....@@ -14467,15 +16918,27 @@
1446716918
1446816919 //float u = (i+1)/2;
1446916920 //float v = (j+1)/2;
14470
- 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);
1447116925 gl.glVertex3f(i, j, -0.5f);
1447216926
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
1447316930 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1447416931 gl.glVertex3f(i + step, j, -0.5f);
1447516932
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
1447616936 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1447716937 gl.glVertex3f(i + step, j + stepv, -0.5f);
1447816938
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
1447916942 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1448016943 gl.glVertex3f(i, j + stepv, -0.5f);
1448116944 }
....@@ -14487,7 +16950,7 @@
1448716950 gl.glMatrixMode(GL.GL_PROJECTION);
1448816951 gl.glPopMatrix();
1448916952 gl.glMatrixMode(GL.GL_MODELVIEW);
14490
- PopMatrix(null); // checker.toParent); // null);
16953
+ //PopMatrix(null); // checker.toParent); // null);
1449116954 gl.glPopMatrix();
1449216955 PopTextureMatrix(checker.toParent);
1449316956 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14520,6 +16983,14 @@
1452016983 }
1452116984 }
1452216985
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
+
1452316994 class SelectBuffer implements GLEventListener
1452416995 {
1452516996
....@@ -14535,7 +17006,7 @@
1453517006 //new Exception().printStackTrace();
1453617007 System.out.println("select buffer init");
1453717008 // Use debug pipeline
14538
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1453917010
1454017011 GL gl = drawable.getGL();
1454117012
....@@ -14578,6 +17049,7 @@
1457817049 {
1457917050 if (!selection)
1458017051 {
17052
+ new Exception().printStackTrace();
1458117053 System.exit(0);
1458217054 return;
1458317055 }
....@@ -14598,17 +17070,39 @@
1459817070
1459917071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1460017072
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
+
1460117084 //int tmp = selection_view;
1460217085 //selection_view = -1;
14603
- int temp = drawMode;
14604
- drawMode = SELECTION;
17086
+ int temp = DrawMode();
17087
+ Globals.drawMode = SELECTION; // WARNING
1460517088 indexcount = 0;
1460617089 parent.display(drawable);
1460717090 //selection_view = tmp;
1460817091 //if (temp == SELECTION)
1460917092 // temp = DEFAULT; // patch for selection debug
14610
- drawMode = temp;
17093
+ Globals.drawMode = temp; // WARNING
1461117094
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
+
1461217106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1461317107
1461417108 // trying different ways of getting the depth info over
....@@ -14657,6 +17151,13 @@
1465717151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1465817152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1465917153
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
+
1466017161 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1466117162
1466217163 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14700,34 +17201,36 @@
1470017201 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]));
1470117202 }
1470217203
14703
- previousselectedpoint = (Sphere) GraphreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1470417205 }
1470517206 }
1470617207
1470717208 if (!movingcamera && !PAINTMODE)
14708
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1470917210
14710
- 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)
1471117212 {
14712
- 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);
1471317214
14714
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1471517218
14716
- group.CreateMaterial(); // use a void leaf to select instances
14717
-
14718
- group.add(paintobj); // link
14719
-
14720
- object.editWindow.SnapObject(group);
14721
-
14722
- Object3D folder = object.editWindow.copy;
14723
-
14724
- if (object.editWindow.copy.selection.Size() > 0)
14725
- folder = object.editWindow.copy.selection.elementAt(0);
14726
-
14727
- folder.add(group);
14728
-
14729
- object.editWindow.ResetModel();
14730
- object.editWindow.refreshContents();
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
+ }
1473117234 }
1473217235 else
1473317236 paintcount = 0;
....@@ -14766,6 +17269,11 @@
1476617269 //System.out.println("objects[color] = " + objects[color]);
1476717270 //objects[color].Select();
1476817271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1476917277 object.Select(color, deselect);
1477017278 }
1477117279
....@@ -14865,7 +17373,7 @@
1486517373 gl.glDisable(gl.GL_CULL_FACE);
1486617374 }
1486717375
14868
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1486917377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1487017378
1487117379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14875,14 +17383,14 @@
1487517383 //gl.glColorMask(false, false, false, false);
1487617384
1487717385 //render_scene_from_light_view(gl, drawable, 0, 0);
14878
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1487917387 {
1488017388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1488117389
14882
- int temp = drawMode;
14883
- drawMode = SHADOW;
17390
+ int temp = DrawMode();
17391
+ Globals.drawMode = SHADOW; // WARNING
1488417392 parent.display(drawable);
14885
- drawMode = temp;
17393
+ Globals.drawMode = temp; // WARNING
1488617394 }
1488717395
1488817396 gl.glCullFace(gl.GL_BACK);
....@@ -14935,7 +17443,6 @@
1493517443
1493617444 class AntialiasBuffer implements GLEventListener
1493717445 {
14938
-
1493917446 CameraPane parent = null;
1494017447
1494117448 AntialiasBuffer(CameraPane p)
....@@ -15045,15 +17552,25 @@
1504517552 gl.glFlush();
1504617553
1504717554 /**/
15048
- 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);
1504917556
15050
- int[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1505117558
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
+
1505217563 double r = 0, g = 0, b = 0;
1505317564
1505417565 double count = 0;
17566
+
17567
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17568
+
17569
+ float mindepth = 1;
17570
+
17571
+ double FACTOR = 1;
1505517572
15056
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1505717574 {
1505817575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1505917576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15136,7 +17653,7 @@
1513617653
1513717654 double scale = ray.z; // 1; // cos
1513817655
15139
- int p = pixels[newindex];
17656
+ float depth = depths[newindex];
1514017657
1514117658 /*
1514217659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15160,10 +17677,23 @@
1516017677 scale = (1 - modu) * modv;
1516117678 */
1516217679
15163
- r += ((p >> 16) & 0xFF) * scale / 255;
15164
- g += ((p >> 8) & 0xFF) * scale / 255;
15165
- 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
+ }
1516617688
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
+
1516717697 count += scale;
1516817698 }
1516917699
....@@ -15261,12 +17791,6 @@
1526117791 GLUT glut = new GLUT();
1526217792
1526317793
15264
- static final public int DEFAULT = 0;
15265
- static final public int SELECTION = 1;
15266
- static final public int SHADOW = 2;
15267
- static final public int OCCLUSION = 3;
15268
- static
15269
- public int drawMode = DEFAULT;
1527017794 public boolean spherical = false;
1527117795 static boolean DEBUG_OCCLUSION = false;
1527217796 static boolean DEBUG_SELECTION = false;
....@@ -15279,21 +17803,15 @@
1527917803 int AAbuffersize = 0;
1528017804
1528117805 //double[] selectedpoint = new double[3];
15282
- static Sphere selectedpoint = new Sphere();
17806
+ static Superellipsoid selectedpoint;
1528317807 static Sphere previousselectedpoint = null;
15284
- static Sphere debugpoint = new Sphere();
15285
- static Sphere debugpoint2 = new Sphere();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1528617812
1528717813 static Sphere debugpoints[] = new Sphere[8];
1528817814
15289
- static
15290
- {
15291
- for (int i=0; i<8; i++)
15292
- {
15293
- debugpoints[i] = new Sphere();
15294
- }
15295
- }
15296
-
1529717815 static void InitPoints(float radius)
1529817816 {
1529917817 for (int i=0; i<8; i++)
....@@ -15313,7 +17831,7 @@
1531317831 }
1531417832 }
1531517833
15316
- static void DrawPoints(CameraPane cpane)
17834
+ static void DrawPoints(iCameraPane cpane)
1531717835 {
1531817836 for (int i=0; i<8; i++) // first and last are red
1531917837 {
....@@ -15332,10 +17850,14 @@
1533217850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1533317851 static IntBuffer bigAAbuffer;
1533417852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15335
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1533617854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1533717855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15338
- 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
+
1533917861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1534017862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1534117863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15344,10 +17866,11 @@
1534417866 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1534517867 // Depth buffer format
1534617868 //private int depth_format;
15347
- static public void NextIndex(Object3D o, GL gl)
17869
+
17870
+ public void NextIndex()
1534817871 {
1534917872 indexcount+=16;
15350
- 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);
1535117874 //objects[indexcount] = o;
1535217875 //System.out.println("indexcount = " + indexcount);
1535317876 }