Normand Briere
2019-08-16 64e20f390e4b8e58bd0006dde8fa10fba1dac1d5
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,19 @@
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;
116
+ boolean transformMode;
117
+
94118 boolean reverseUP = false;
95119 static boolean frozen = false;
96120 boolean enablebackspace = false; // patch for back buffer refresh
97121
98122 static boolean textureon = true;
99123 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101124 static boolean FULLSCREEN = false;
102125 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104126 static boolean INERTIA = true;
105127 static boolean FAST = false;
106128 static boolean SLOWPOSE = false;
....@@ -108,6 +130,8 @@
108130
109131 static int tickcount = 0; // slow pose issue
110132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
111135 static boolean BOXMODE = false;
112136 static boolean IMAGEFLIP = false;
113137 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +146,7 @@
122146 static boolean OEIL = true;
123147 static boolean OEILONCE = false; // do oeilon then oeiloff
124148 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
126150 static boolean HANDLES = false; // selection doesn't work!!
127151 static boolean PAINTMODE = false;
128152
....@@ -153,7 +177,7 @@
153177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
154178 boolean anisotropy = true;
155179 boolean softshadow = true; // slower but better false;
156
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
157181
158182 boolean macromode = false;
159183
....@@ -165,12 +189,55 @@
165189 defaultcaps.setAccumBlueBits(16);
166190 defaultcaps.setAccumAlphaBits(16);
167191 }
168
- static CameraPane theRenderer;
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
169194
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
207
+
170208 void SetAsGLRenderer(boolean b)
171209 {
172210 isRenderer = b;
173
- theRenderer = this;
211
+ Globals.theRenderer = this;
212
+ }
213
+
214
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
215
+ {
216
+ super(defaultcaps, null, withcontext?glcontext:null, null);
217
+
218
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
219
+ glcontext = getContext();
220
+
221
+ cameras = new Camera[2];
222
+ targetLookAts = new cVector[2];
223
+
224
+ SetCamera(cam);
225
+
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
228
+
229
+ object = o;
230
+
231
+ setBackground(Color.white);
232
+
233
+ addKeyListener(this);
234
+ addMouseListener(this);
235
+ addMouseMotionListener(this);
236
+ addMouseWheelListener(this);
237
+ //System.out.println("addGLEventListener: " + this);
238
+ addGLEventListener(this);
239
+
240
+// pingthread.start(); // may 2013
174241 }
175242
176243 static boolean AntialiasingEnabled()
....@@ -178,12 +245,53 @@
178245 return CURRENTANTIALIAS > 0;
179246 }
180247
181
- void ClearDepth()
248
+ /// INTERFACE
249
+
250
+ public javax.media.opengl.GL GetGL0()
251
+ {
252
+ return null;
253
+ }
254
+
255
+ public int GenList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ return gl.glGenLists(1);
259
+ }
260
+
261
+ public void NewList(int id)
262
+ {
263
+ javax.media.opengl.GL gl = GetGL();
264
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
265
+ }
266
+
267
+ public void CallList(int id)
268
+ {
269
+ javax.media.opengl.GL gl = GetGL();
270
+ gl.glCallList(id);
271
+ }
272
+
273
+ public void EndList()
274
+ {
275
+ javax.media.opengl.GL gl = GetGL();
276
+ gl.glEndList();
277
+ }
278
+
279
+ public boolean IsBoxMode()
280
+ {
281
+ return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
287
+ }
288
+
289
+ public void ClearDepth()
182290 {
183291 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184292 }
185293
186
- void DepthTest(boolean depthtest)
294
+ public void DepthTest(boolean depthtest)
187295 {
188296 if (depthtest)
189297 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +299,7 @@
191299 GetGL().glDepthFunc(GL.GL_ALWAYS);
192300 }
193301
194
- void DepthWrite(boolean depthwrite)
302
+ public void DepthWrite(boolean depthwrite)
195303 {
196304 if (depthwrite)
197305 GetGL().glDepthMask(true);
....@@ -199,12 +307,1616 @@
199307 GetGL().glDepthMask(false);
200308 }
201309
202
- void BackFaceCull(boolean bfc)
310
+ public void BackFaceCull(boolean bfc)
203311 {
204312 if (bfc)
205313 GetGL().glEnable(GetGL().GL_CULL_FACE);
206314 else
207315 GetGL().glDisable(GetGL().GL_CULL_FACE);
316
+ }
317
+
318
+ public boolean BackFaceCullMode()
319
+ {
320
+ return this.CULLFACE;
321
+ }
322
+
323
+ public boolean IsAmbientOcclusionOn()
324
+ {
325
+ return this.ambientOcclusion;
326
+ }
327
+
328
+ public boolean IsDebugSelection()
329
+ {
330
+ return DEBUG_SELECTION;
331
+ }
332
+
333
+ public boolean IsFrozen()
334
+ {
335
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
336
+
337
+ return !selectmode && cameracount == 0; // != 0;
338
+ }
339
+
340
+ // Currently in Globals
341
+ public int DrawMode()
342
+ {
343
+ return Globals.DrawMode();
344
+ }
345
+
346
+ public Camera EyeCamera()
347
+ {
348
+ return eyeCamera;
349
+ }
350
+
351
+ public Camera LightCamera()
352
+ {
353
+ return lightCamera;
354
+ }
355
+
356
+ public Camera ManipCamera()
357
+ {
358
+ return manipCamera;
359
+ }
360
+
361
+ public Camera RenderCamera()
362
+ {
363
+ return renderCamera;
364
+ }
365
+
366
+ public Camera[] Cameras()
367
+ {
368
+ return cameras;
369
+ }
370
+
371
+ public void PushMaterial(Object3D obj, boolean selected)
372
+ {
373
+ CameraPane display = this;
374
+ javax.media.opengl.GL gl = display.GetGL();
375
+ cMaterial material = obj.material;
376
+
377
+ if (material != null)
378
+ {
379
+ materialstack[materialdepth] = material;
380
+ selectedstack[materialdepth] = selected;
381
+ cStatic.objectstack[materialdepth++] = obj;
382
+ //System.out.println("material " + material);
383
+ //Applet3D.tracein(this, selected);
384
+ //display.vector2buffer = obj.projectedVertices;
385
+ if (obj instanceof Camera)
386
+ {
387
+ display.options1[0] = material.shift;
388
+ //System.out.println("shift " + material.shift);
389
+ display.options1[1] = material.lightarea;
390
+ display.options1[2] = material.shadowbias;
391
+ display.options1[3] = material.aniso;
392
+ display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
398
+ display.options2[0] = material.opacity;
399
+ display.options2[1] = material.diffuse;
400
+ display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
404
+
405
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
409
+ display.options4[0] = material.cameralight/0.2f;
410
+ display.options4[1] = material.subsurface;
411
+ display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
415
+
416
+ // if (display.CURRENTANTIALIAS > 0)
417
+ // display.options3[3] /= 4;
418
+
419
+ /*
420
+ System.out.println("Focus = " + display.options1[0]);
421
+ System.out.println("Aperture = " + display.options1[1]);
422
+ System.out.println("ShadowBlur = " + display.options1[2]);
423
+ System.out.println("Antialiasing = " + display.options1[3]);
424
+ System.out.println("Fog = " + display.options2[0]);
425
+ System.out.println("Intensity = " + display.options2[1]);
426
+ System.out.println("Elevation = " + display.options2[2]);
427
+ /**/
428
+ } else
429
+ {
430
+ DrawMaterial(material, selected, obj.projectedVertices);
431
+ }
432
+ } else
433
+ {
434
+ if (selected && CameraPane.flash)
435
+ {
436
+ display.modelParams4[1] = 100;
437
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
438
+ }
439
+ }
440
+ }
441
+
442
+ public void PushMaterial2(Object3D obj, boolean selected)
443
+ {
444
+ CameraPane display = this;
445
+ cMaterial material = obj.material;
446
+
447
+ if (material != null)
448
+ {
449
+ materialstack[materialdepth] = material;
450
+ selectedstack[materialdepth] = selected;
451
+ cStatic.objectstack[materialdepth++] = obj;
452
+ //System.out.println("material " + material);
453
+ //Applet3D.tracein("selected ", selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
456
+ }
457
+ }
458
+
459
+ public void PopMaterial(Object3D obj, boolean selected)
460
+ {
461
+ CameraPane display = this;
462
+ javax.media.opengl.GL gl = display.GetGL();
463
+ cMaterial material = obj.material;
464
+
465
+ //if (parent != null && parent.GetMaterial() != null)
466
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
467
+ if (material != null)
468
+ {
469
+ materialdepth -= 1;
470
+ if (materialdepth > 0)
471
+ {
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
474
+ }
475
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
476
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
477
+ {
478
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
479
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
480
+ }
481
+ }
482
+
483
+ public void PopMaterial2(Object3D obj)
484
+ {
485
+ CameraPane display = this;
486
+ cMaterial material = obj.material;
487
+
488
+ if (material != null)
489
+ {
490
+ materialdepth -= 1;
491
+ if (materialdepth > 0)
492
+ {
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
495
+ }
496
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
497
+ //else
498
+ //material.Draw(display, false);
499
+ }
500
+ }
501
+
502
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
503
+ {
504
+ CameraPane display = this;
505
+
506
+ if (pv.y == -10000 ||
507
+ qv.y == -10000 ||
508
+ rv.y == -10000)
509
+ return;
510
+
511
+// float b = f.nbiterations & 1;
512
+// float g = (f.nbiterations>>1) & 1;
513
+// float r = (f.nbiterations>>2) & 1;
514
+//
515
+// //if (f.weight == 10000)
516
+// //{
517
+// // r = 1; g = b = 0;
518
+// //}
519
+// //else
520
+// //{
521
+// // assert(f.weight < 10000);
522
+// r = g = b = (float)bRep.FaceWeight(f)*100;
523
+// if (r<0)
524
+// assert(r>=0);
525
+// //}
526
+
527
+ javax.media.opengl.GL gl = display.GetGL();
528
+
529
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
530
+
531
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
532
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
533
+ {
534
+ //gl.glBegin(gl.GL_TRIANGLES);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
538
+ if (!hasnorm)
539
+ {
540
+ // System.out.println("Mesh normal");
541
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
542
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
543
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
544
+ LA.vecNormalize(obj.v2);
545
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
546
+ }
547
+
548
+ // P
549
+ float x = (float)pv.x;
550
+ float y = (float)pv.y;
551
+ float z = (float)pv.z;
552
+
553
+ if (hasnorm)
554
+ {
555
+// if (!pv.norm.normalized())
556
+// assert(pv.norm.normalized());
557
+
558
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
559
+ float nx = (float)pv.norm.x;
560
+ float ny = (float)pv.norm.y;
561
+ float nz = (float)pv.norm.z;
562
+
563
+ x += nx * obj.NORMALPUSH;
564
+ y += ny * obj.NORMALPUSH;
565
+ z += nz * obj.NORMALPUSH;
566
+
567
+ gl.glNormal3f(nx, ny, nz);
568
+ }
569
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
570
+ SetColor(obj, pv);
571
+ //gl.glColor4f(r, g, b, 1);
572
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
573
+ if (obj.flipV)
574
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
575
+ else
576
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
577
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
578
+
579
+ gl.glVertex3f(x, y, z);
580
+
581
+ // Q
582
+ x = (float)qv.x;
583
+ y = (float)qv.y;
584
+ z = (float)qv.z;
585
+
586
+// Print(pv);
587
+ if (hasnorm)
588
+ {
589
+// assert(qv.norm.normalized());
590
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
591
+ float nx = (float)qv.norm.x;
592
+ float ny = (float)qv.norm.y;
593
+ float nz = (float)qv.norm.z;
594
+
595
+ x += nx * obj.NORMALPUSH;
596
+ y += ny * obj.NORMALPUSH;
597
+ z += nz * obj.NORMALPUSH;
598
+
599
+ gl.glNormal3f(nx, ny, nz);
600
+ }
601
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
602
+ // boolean locked = false;
603
+ // float eps = 0.1f;
604
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
605
+
606
+ // int dot = 0; //*/ (int)f.dot;
607
+
608
+ // if ((dot&1) == 0)
609
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
610
+
611
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
612
+ if (obj.flipV)
613
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
614
+ else
615
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
616
+ // else
617
+ // {
618
+ // locked = true;
619
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
620
+ // }
621
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
622
+ SetColor(obj, qv);
623
+
624
+ gl.glVertex3f(x, y, z);
625
+ //gl.glColor4f(r, g, b, 1);
626
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
627
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
628
+// Print(qv);
629
+
630
+ // R
631
+ x = (float)rv.x;
632
+ y = (float)rv.y;
633
+ z = (float)rv.z;
634
+
635
+ if (hasnorm)
636
+ {
637
+// assert(rv.norm.normalized());
638
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
639
+ float nx = (float)rv.norm.x;
640
+ float ny = (float)rv.norm.y;
641
+ float nz = (float)rv.norm.z;
642
+
643
+ x += nx * obj.NORMALPUSH;
644
+ y += ny * obj.NORMALPUSH;
645
+ z += nz * obj.NORMALPUSH;
646
+
647
+ gl.glNormal3f(nx, ny, nz);
648
+ }
649
+
650
+ // if ((dot&4) == 0)
651
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
652
+
653
+ // if (wrap || !locked && (dot&8) != 0)
654
+ if (obj.flipV)
655
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
656
+ else
657
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
658
+ // else
659
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
660
+
661
+ // f.dot = dot;
662
+
663
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
664
+ SetColor(obj, rv);
665
+ //gl.glColor4f(r, g, b, 1);
666
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
667
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
668
+ gl.glVertex3f(x, y, z);
669
+// Print(rv);
670
+ //gl.glEnd();
671
+ }
672
+ else
673
+ {
674
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
675
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
676
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
677
+
678
+ }
679
+
680
+ if (false) // (attributes & WIREFRAME) != 0)
681
+ {
682
+ gl.glDisable(gl.GL_LIGHTING);
683
+
684
+ gl.glBegin(gl.GL_LINE_LOOP);
685
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
686
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
687
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
688
+ gl.glEnd();
689
+
690
+ gl.glEnable(gl.GL_LIGHTING);
691
+ }
692
+ }
693
+
694
+ /**
695
+ * <code>draw</code> renders a <code>TriMesh</code> object including
696
+ * it's normals, colors, textures and vertices.
697
+ *
698
+ * @see Renderer#draw(TriMesh)
699
+ * @param tris
700
+ * the mesh to render.
701
+ */
702
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
703
+ {
704
+ CameraPane display = this;
705
+
706
+ float r = display.modelParams0[0];
707
+ float g = display.modelParams0[1];
708
+ float b = display.modelParams0[2];
709
+ float opacity = display.modelParams5[1];
710
+
711
+ //final GL gl = GLU.getCurrentGL();
712
+ GL gl = display.GetGL(); // getGL();
713
+
714
+ FloatBuffer vertBuf = geo.vertBuf;
715
+
716
+ int v = vertBuf.capacity();
717
+
718
+ int count = 0;
719
+
720
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
721
+ gl.glEnable(gl.GL_CULL_FACE);
722
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
723
+ for (int i=0; i<v/3; i++)
724
+ {
725
+ int index3 = i*3;
726
+
727
+ if (geo.sizeBuf.get(index3+1) == 0)
728
+ continue;
729
+
730
+ count++;
731
+
732
+ int index4 = i*4;
733
+
734
+ float tx = vertBuf.get(index3);
735
+ float ty = vertBuf.get(index3+1);
736
+ float tz = vertBuf.get(index3+2);
737
+
738
+ // if (tx == 0 && ty == 0 && tz == 0)
739
+ // continue;
740
+
741
+ gl.glMatrixMode(gl.GL_TEXTURE);
742
+ gl.glPushMatrix();
743
+
744
+ float[] texmat = geo.texmat;
745
+ texmat[12] = texmat[13] = texmat[14] = i;
746
+
747
+ gl.glMultMatrixf(texmat, 0);
748
+
749
+ gl.glMatrixMode(gl.GL_MODELVIEW);
750
+ gl.glPushMatrix();
751
+
752
+ gl.glTranslatef(tx,ty,tz);
753
+
754
+ if (rotate)
755
+ gl.glRotatef(i, 0, 1, 0);
756
+
757
+ float size = geo.sizeBuf.get(index3) / 100;
758
+ gl.glScalef(size,size,size);
759
+
760
+ float cr = geo.colorBuf.get(index4);
761
+ float cg = geo.colorBuf.get(index4+1);
762
+ float cb = geo.colorBuf.get(index4+2);
763
+ float ca = geo.colorBuf.get(index4+3);
764
+
765
+ display.modelParams0[0] = r * cr;
766
+ display.modelParams0[1] = g * cg;
767
+ display.modelParams0[2] = b * cb;
768
+
769
+ display.modelParams5[1] = opacity * ca;
770
+
771
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
772
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
773
+
774
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
775
+ RandomNode.globalseed2 = RandomNode.globalseed;
776
+
777
+// gl.glColor4f(cr,cg,cb,ca);
778
+ // gl.glScalef(1024/16,1024/16,1024/16);
779
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
780
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
781
+ //gl.glTranslatef(-tx,-ty,-tz);
782
+ gl.glPopMatrix();
783
+
784
+ gl.glMatrixMode(gl.GL_TEXTURE);
785
+ gl.glPopMatrix();
786
+ }
787
+ // gl.glScalef(1024,1024,1024);
788
+ if (!cf)
789
+ gl.glDisable(gl.GL_CULL_FACE);
790
+
791
+ display.modelParams0[0] = r;
792
+ display.modelParams0[1] = g;
793
+ display.modelParams0[2] = b;
794
+
795
+ display.modelParams5[1] = opacity;
796
+
797
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
798
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
799
+
800
+ gl.glMatrixMode(gl.GL_MODELVIEW);
801
+
802
+// System.err.println("total = " + v/3 + "; displayed = " + count);
803
+ if (true)
804
+ return;
805
+
806
+//// if (!tris.predraw(this))
807
+//// {
808
+//// return;
809
+//// }
810
+//// if (Debug.stats)
811
+//// {
812
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
813
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
814
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
815
+//// }
816
+////
817
+//// if (tris.getDisplayListID() != -1)
818
+//// {
819
+//// renderDisplayList(tris);
820
+//// return;
821
+//// }
822
+////
823
+//// if (!generatingDisplayList)
824
+//// {
825
+//// applyStates(tris.states, tris);
826
+//// }
827
+//// if (Debug.stats)
828
+//// {
829
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
830
+//// }
831
+//// boolean transformed = doTransforms(tris);
832
+//
833
+// int glMode = GL.GL_TRIANGLES;
834
+// switch (getMode())
835
+// {
836
+// case Triangles:
837
+// glMode = GL.GL_TRIANGLES;
838
+// break;
839
+// case Strip:
840
+// glMode = GL.GL_TRIANGLE_STRIP;
841
+// break;
842
+// case Fan:
843
+// glMode = GL.GL_TRIANGLE_FAN;
844
+// break;
845
+// }
846
+//
847
+// if (!predrawGeometry(gl))
848
+// {
849
+// // make sure only the necessary indices are sent through on old
850
+// // cards.
851
+// IntBuffer indices = this.getIndexBuffer();
852
+// if (indices == null)
853
+// {
854
+// logger.severe("missing indices on geometry object: " + this.toString());
855
+// } else
856
+// {
857
+// indices.rewind();
858
+// indices.limit(this.getMaxIndex());
859
+//
860
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
861
+//
862
+// indices.clear();
863
+// }
864
+// } else
865
+// {
866
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
867
+// GL.GL_UNSIGNED_INT, 0);
868
+// }
869
+//
870
+//// postdrawGeometry(tris);
871
+//// if (transformed)
872
+//// {
873
+//// undoTransforms(tris);
874
+//// }
875
+////
876
+//// if (Debug.stats)
877
+//// {
878
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
879
+//// }
880
+//// tris.postdraw(this);
881
+ }
882
+
883
+ static Camera localcamera = new Camera();
884
+ static cVector from = new cVector();
885
+ static cVector to = new cVector();
886
+
887
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
888
+ {
889
+ CameraPane cp = this;
890
+
891
+ Camera keep = cp.RenderCamera();
892
+ cp.renderCamera = localcamera;
893
+
894
+ if (br.trimmed)
895
+ {
896
+ float[] colors = new float[br.positions.length / 3];
897
+
898
+ int i3 = 0;
899
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
900
+ {
901
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
902
+ continue;
903
+
904
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
905
+ to.set(br.positions[i3] + br.normals[i3],
906
+ br.positions[i3 + 1] + br.normals[i3 + 1],
907
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
908
+ LA.xformPos(from, transform, from);
909
+ LA.xformPos(to, transform, to); // RIGID ONLY
910
+ localcamera.setAim(from, to);
911
+
912
+ CameraPane.occlusionbuffer.display();
913
+
914
+ if (CameraPane.DEBUG_OCCLUSION)
915
+ cp.display(); // debug
916
+
917
+ colors[i] = cp.vertexOcclusion.r;
918
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
919
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
920
+
921
+ if ((i % 100) == 0 && i != 0)
922
+ {
923
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
924
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
925
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
926
+ }
927
+ }
928
+
929
+ br.colors = colors;
930
+ }
931
+ else
932
+ {
933
+ for (int i = 0; i < br.VertexCount(); i++)
934
+ {
935
+ Vertex v = br.GetVertex(i);
936
+
937
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
938
+ continue;
939
+
940
+ from.set(v.x, v.y, v.z);
941
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
942
+ LA.xformPos(from, transform, from);
943
+ LA.xformPos(to, transform, to); // RIGID ONLY
944
+ localcamera.setAim(from, to);
945
+
946
+ CameraPane.occlusionbuffer.display();
947
+
948
+ if (CameraPane.DEBUG_OCCLUSION)
949
+ cp.display(); // debug
950
+
951
+ v.AO = cp.vertexOcclusion.r;
952
+
953
+ if ((i % 100) == 0 && i != 0)
954
+ {
955
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
956
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
957
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
958
+ }
959
+ }
960
+ }
961
+
962
+ //System.out.println("done.");
963
+
964
+ cp.renderCamera = keep;
965
+ }
966
+
967
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
968
+ {
969
+ CameraPane display = this;
970
+ pointFlow.CreateHT();
971
+
972
+ float r = display.modelParams0[0];
973
+ float g = display.modelParams0[1];
974
+ float b = display.modelParams0[2];
975
+ float opacity = display.modelParams5[1];
976
+
977
+ //final GL gl = GLU.getCurrentGL();
978
+ GL gl = display.GetGL(); // getGL();
979
+
980
+ int s = pointFlow.points.size();
981
+
982
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
983
+ gl.glEnable(gl.GL_CULL_FACE);
984
+
985
+ for (int i=s; --i>=0;)
986
+ //for (int i=0; i<s; i++)
987
+ {
988
+ cVector v = pointFlow.points.get(i);
989
+
990
+ double mindist = Double.MAX_VALUE;
991
+
992
+ double size = pointFlow.minimumSize;
993
+
994
+ double distancenext = 0;
995
+
996
+ if (i > 0)
997
+ {
998
+ cVector w = pointFlow.points.get(i-1);
999
+
1000
+ double dist = w.distance(v);
1001
+
1002
+ distancenext = dist;
1003
+
1004
+ if (mindist > dist)
1005
+ {
1006
+ mindist = dist;
1007
+ size = mindist*pointFlow.resizefactor;
1008
+ }
1009
+ }
1010
+
1011
+ if (i < s-1)
1012
+ {
1013
+ cVector w = pointFlow.points.get(i+1);
1014
+
1015
+ double dist = w.distance(v);
1016
+
1017
+ if (mindist > dist)
1018
+ {
1019
+ mindist = dist;
1020
+ size = mindist*pointFlow.resizefactor;
1021
+ }
1022
+ }
1023
+
1024
+ if (size < pointFlow.minimumSize)
1025
+ size = pointFlow.minimumSize;
1026
+ if (size > pointFlow.maximumSize)
1027
+ size = pointFlow.maximumSize;
1028
+
1029
+ double tx = v.x;
1030
+ double ty = v.y;
1031
+ double tz = v.z;
1032
+
1033
+ // if (tx == 0 && ty == 0 && tz == 0)
1034
+ // continue;
1035
+
1036
+ gl.glMatrixMode(gl.GL_TEXTURE);
1037
+ gl.glPushMatrix();
1038
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1039
+
1040
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1041
+
1042
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1043
+ gl.glPushMatrix();
1044
+
1045
+ gl.glTranslated(tx,ty,tz);
1046
+
1047
+ gl.glScaled(size,size,size);
1048
+
1049
+// float cr = colorBuf.get(index4);
1050
+// float cg = colorBuf.get(index4+1);
1051
+// float cb = colorBuf.get(index4+2);
1052
+// float ca = colorBuf.get(index4+3);
1053
+//
1054
+// display.modelParams0[0] = r * cr;
1055
+// display.modelParams0[1] = g * cg;
1056
+// display.modelParams0[2] = b * cb;
1057
+//
1058
+// display.modelParams5[1] = opacity * ca;
1059
+//
1060
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1061
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1062
+//
1063
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1064
+// RandomNode.globalseed2 = RandomNode.globalseed;
1065
+//
1066
+//// gl.glColor4f(cr,cg,cb,ca);
1067
+// // gl.glScalef(1024/16,1024/16,1024/16);
1068
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1069
+
1070
+ gl.glPopMatrix();
1071
+
1072
+ double step = size/4; //
1073
+
1074
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1075
+ continue;
1076
+
1077
+ int nbsteps = (int)(distancenext/step);
1078
+
1079
+ step = distancenext/nbsteps;
1080
+
1081
+ cVector next = pointFlow.points.get(i-1);
1082
+
1083
+ tmp.set(next);
1084
+ tmp.sub(v);
1085
+ tmp.normalize();
1086
+ tmp.mul(step);
1087
+
1088
+ // calculate next size
1089
+ mindist = Double.MAX_VALUE;
1090
+
1091
+ double nextsize = pointFlow.minimumSize;
1092
+
1093
+ if (i > 1)
1094
+ {
1095
+ cVector w = pointFlow.points.get(i-2);
1096
+
1097
+ double dist = w.distance(next);
1098
+
1099
+ if (mindist > dist)
1100
+ {
1101
+ mindist = dist;
1102
+ nextsize = mindist*pointFlow.resizefactor;
1103
+ }
1104
+ }
1105
+
1106
+ double dist = v.distance(next);
1107
+
1108
+ if (mindist > dist)
1109
+ {
1110
+ mindist = dist;
1111
+ nextsize = mindist*pointFlow.resizefactor;
1112
+ }
1113
+
1114
+ if (nextsize < pointFlow.minimumSize)
1115
+ nextsize = pointFlow.minimumSize;
1116
+ if (nextsize > pointFlow.maximumSize)
1117
+ nextsize = pointFlow.maximumSize;
1118
+ //
1119
+
1120
+ double count = 0;
1121
+
1122
+ while (distancenext > 0.000000001) // step
1123
+ {
1124
+ gl.glPushMatrix();
1125
+
1126
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1127
+
1128
+ double K = count/nbsteps;
1129
+
1130
+ double intersize = K*nextsize + (1-K)*size;
1131
+
1132
+ gl.glScaled(intersize,intersize,intersize);
1133
+
1134
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1135
+
1136
+ count++;
1137
+
1138
+ distancenext -= step;
1139
+
1140
+ gl.glPopMatrix();
1141
+ }
1142
+
1143
+ if (count != nbsteps)
1144
+ assert(count == nbsteps);
1145
+
1146
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1147
+ //gl.glTranslatef(-tx,-ty,-tz);
1148
+
1149
+ gl.glMatrixMode(gl.GL_TEXTURE);
1150
+ gl.glPopMatrix();
1151
+ }
1152
+
1153
+ if (!cf)
1154
+ gl.glDisable(gl.GL_CULL_FACE);
1155
+
1156
+// display.modelParams0[0] = r;
1157
+// display.modelParams0[1] = g;
1158
+// display.modelParams0[2] = b;
1159
+//
1160
+// display.modelParams5[1] = opacity;
1161
+//
1162
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1163
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1164
+
1165
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1166
+ }
1167
+
1168
+ public void DrawBox(cVector min, cVector max)
1169
+ {
1170
+ javax.media.opengl.GL gl = GetGL();
1171
+ gl.glBegin(gl.GL_LINES);
1172
+
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, min.y, max.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(min.x, max.y, min.z);
1177
+ gl.glVertex3d(min.x, min.y, min.z);
1178
+ gl.glVertex3d(max.x, min.y, min.z);
1179
+
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(min.x, max.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, min.y, max.z);
1184
+ gl.glVertex3d(max.x, max.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, min.z);
1186
+
1187
+ gl.glEnd();
1188
+ }
1189
+
1190
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1191
+ {
1192
+ int[] strips = bRep.getRawIndices();
1193
+
1194
+ javax.media.opengl.GL gl = GetGL();
1195
+
1196
+ // TRIANGLE STRIP ARRAY
1197
+ if (bRep.trimmed)
1198
+ {
1199
+ float[] v = bRep.getRawVertices();
1200
+ float[] n = bRep.getRawNormals();
1201
+ float[] c = bRep.getRawColors();
1202
+ float[] uv = bRep.getRawUVMap();
1203
+
1204
+ int count2 = 0;
1205
+ int count3 = 0;
1206
+
1207
+ if (n.length > 0)
1208
+ {
1209
+ for (int i = 0; i < strips.length; i++)
1210
+ {
1211
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1212
+
1213
+ /*
1214
+ boolean locked = false;
1215
+ float eps = 0.1f;
1216
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1217
+
1218
+ int dot = 0;
1219
+
1220
+ if ((dot&1) == 0)
1221
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1222
+
1223
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1224
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1225
+ else
1226
+ {
1227
+ locked = true;
1228
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1229
+ }
1230
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1231
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1232
+ if (hasnorm)
1233
+ {
1234
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1235
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1236
+ }
1237
+
1238
+ if ((dot&4) == 0)
1239
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1240
+
1241
+ if (wrap || !locked && (dot&8) != 0)
1242
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1243
+ else
1244
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1245
+
1246
+ f.dot = dot;
1247
+ */
1248
+
1249
+ if (!selectmode)
1250
+ {
1251
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1252
+ {
1253
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ } else
1255
+ {
1256
+ gl.glNormal3f(0, 0, 1);
1257
+ }
1258
+
1259
+ if (c != null)
1260
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1261
+ {
1262
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1263
+ }
1264
+ }
1265
+
1266
+ if (flipV)
1267
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1268
+ else
1269
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1270
+
1271
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1272
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1273
+
1274
+ count2 += 2;
1275
+ count3 += 3;
1276
+ if (!selectmode)
1277
+ {
1278
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1279
+ {
1280
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ } else
1282
+ {
1283
+ gl.glNormal3f(0, 0, 1);
1284
+ }
1285
+ if (c != null)
1286
+ {
1287
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1288
+ }
1289
+ }
1290
+
1291
+ if (flipV)
1292
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1293
+ else
1294
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1295
+
1296
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1297
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1298
+
1299
+ count2 += 2;
1300
+ count3 += 3;
1301
+ for (int j = 0; j < strips[i] - 2; j++)
1302
+ {
1303
+ //gl.glTexCoord2d(...);
1304
+ if (!selectmode)
1305
+ {
1306
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1307
+ {
1308
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ } else
1310
+ {
1311
+ gl.glNormal3f(0, 0, 1);
1312
+ }
1313
+ if (c != null)
1314
+ {
1315
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1316
+ }
1317
+ }
1318
+
1319
+ if (flipV)
1320
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1321
+ else
1322
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1323
+
1324
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1325
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1326
+
1327
+ count2 += 2;
1328
+ count3 += 3;
1329
+ }
1330
+
1331
+ gl.glEnd();
1332
+ }
1333
+ }
1334
+
1335
+ assert count3 == v.length;
1336
+ }
1337
+ else // !trimmed
1338
+ {
1339
+ int count = 0;
1340
+ for (int i = 0; i < strips.length; i++)
1341
+ {
1342
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1343
+
1344
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1345
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1346
+
1347
+ drawVertex(gl, p, flipV, selectmode);
1348
+ drawVertex(gl, q, flipV, selectmode);
1349
+
1350
+ for (int j = 0; j < strips[i] - 2; j++)
1351
+ {
1352
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1353
+
1354
+ // if (j%2 == 0)
1355
+ // drawFace(p, q, r, display, null);
1356
+ // else
1357
+ // drawFace(p, r, q, display, null);
1358
+
1359
+ // p = q;
1360
+ // q = r;
1361
+ drawVertex(gl, r, flipV, selectmode);
1362
+ }
1363
+
1364
+ gl.glEnd();
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ static cSpring.Point3D temp = new cSpring.Point3D();
1370
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1372
+
1373
+ public void DrawDynamicMesh(cMesh mesh)
1374
+ {
1375
+ GL gl = GetGL(); // getGL();
1376
+
1377
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1378
+
1379
+ gl.glDisable(gl.GL_LIGHTING);
1380
+
1381
+ gl.glLineWidth(1);
1382
+ gl.glColor3f(1,1,1);
1383
+ gl.glBegin(gl.GL_LINES);
1384
+ double scale = 0;
1385
+ int count = 0;
1386
+ for (int s=0; s<Phys.allSprings.size(); s++)
1387
+ {
1388
+ cSpring.Spring spring = Phys.allSprings.get(s);
1389
+ if(s == 0)
1390
+ {
1391
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1392
+ }
1393
+ if (mesh.showsprings)
1394
+ {
1395
+ temp.set(spring.a.position);
1396
+ temp.add(spring.b.position);
1397
+ temp.mul(0.5);
1398
+ temp2.set(spring.a.position);
1399
+ temp2.sub(spring.b.position);
1400
+ temp2.mul(spring.restLength/2);
1401
+ temp.sub(temp2);
1402
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1403
+ temp.add(temp2);
1404
+ temp.add(temp2);
1405
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1406
+ }
1407
+
1408
+ if (spring.isHandle)
1409
+ continue;
1410
+
1411
+ //if (scale < spring.restLength)
1412
+ scale += spring.restLength;
1413
+ count++;
1414
+ }
1415
+ gl.glEnd();
1416
+
1417
+ if (count == 0)
1418
+ scale = 0.01;
1419
+ else
1420
+ scale /= count * 3;
1421
+
1422
+ //scale = 0.25;
1423
+
1424
+ if (mesh.ShowInfo())
1425
+ {
1426
+ gl.glLineWidth(4);
1427
+ for (int s=0; s<Phys.allNodes.size(); s++)
1428
+ {
1429
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1430
+ if (node.mass == 0)
1431
+ continue;
1432
+
1433
+ int i = node.springs==null?-1:node.springs.size();
1434
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1435
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1436
+ //temp.normalize();
1437
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1438
+ gl.glBegin(gl.GL_LINES);
1439
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1440
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1441
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1442
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1443
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1444
+ gl.glEnd();
1445
+ }
1446
+
1447
+ gl.glLineWidth(8);
1448
+ for (int s=0; s<Phys.allNodes.size(); s++)
1449
+ {
1450
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1451
+
1452
+ if (node.springs != null)
1453
+ {
1454
+ for (int i=0; i<node.springs.size(); i+=1)
1455
+ {
1456
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1457
+
1458
+ int c = i+1;
1459
+ // c = node.springs.get(i).nbcopies;
1460
+
1461
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1462
+ gl.glBegin(gl.GL_LINES);
1463
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1464
+ 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);
1465
+ gl.glEnd();
1466
+ }
1467
+ }
1468
+ }
1469
+
1470
+ gl.glLineWidth(1);
1471
+ }
1472
+
1473
+ gl.glEnable(gl.GL_LIGHTING);
1474
+ }
1475
+
1476
+ /// INTERFACE
1477
+
1478
+ public void StartTriangles()
1479
+ {
1480
+ javax.media.opengl.GL gl = GetGL();
1481
+ gl.glBegin(gl.GL_TRIANGLES);
1482
+ }
1483
+
1484
+ public void EndTriangles()
1485
+ {
1486
+ GetGL().glEnd();
1487
+ }
1488
+
1489
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1490
+ {
1491
+ if (!selectmode)
1492
+ {
1493
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1495
+
1496
+ if (flipV)
1497
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1498
+ else
1499
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1500
+ }
1501
+
1502
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1503
+ }
1504
+
1505
+ float[] colorV = new float[4];
1506
+
1507
+ void SetColor(Object3D obj, Vertex p0)
1508
+ {
1509
+ CameraPane display = this;
1510
+ BoundaryRep bRep = obj.bRep;
1511
+
1512
+ if (RENDERPROGRAM == 0)
1513
+ {
1514
+ float r = 0;
1515
+ if (bRep != null)
1516
+ {
1517
+ if (bRep.stripified)
1518
+ {
1519
+ r = 1;
1520
+ }
1521
+ }
1522
+ float g = 0;
1523
+ if (bRep != null)
1524
+ {
1525
+ if (bRep.trimmed)
1526
+ {
1527
+ g = 1;
1528
+ }
1529
+ }
1530
+ float b = 0;
1531
+ if (obj.support != null && obj.link2master)
1532
+ {
1533
+ b = 1;
1534
+ }
1535
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1536
+ return;
1537
+ }
1538
+
1539
+ if (display.DrawMode() != CameraPane.SHADOW)
1540
+ return;
1541
+
1542
+ javax.media.opengl.GL gl = display.GetGL();
1543
+// if (true) return;
1544
+// float ao = p.AO;
1545
+//
1546
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1547
+// // ao = 1;
1548
+//
1549
+// gl.glColor4f(ao, ao, ao, 1);
1550
+
1551
+// CameraPane.selectedpoint.
1552
+// getAverage(cStatic.point1, true);
1553
+ if (CameraPane.pointflow == null) // !random) // live)
1554
+ {
1555
+ return;
1556
+ }
1557
+
1558
+ cStatic.point1.set(0,0,0);
1559
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1560
+
1561
+ cStatic.point1.sub(p0);
1562
+
1563
+
1564
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1565
+// {
1566
+// return;
1567
+// }
1568
+
1569
+ //if (true)
1570
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1571
+ {
1572
+ return;
1573
+ }
1574
+
1575
+ if (false) // marked)
1576
+ {
1577
+ // debug rigging weights
1578
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1579
+ {
1580
+ float weight = p0.weights[object] / p0.totalweight;
1581
+
1582
+ // if (weight < 0.1)
1583
+ // {
1584
+ // assert(weight == 0);
1585
+ // continue;
1586
+ // }
1587
+
1588
+ if (p0.vertexlinks[object] == -1)
1589
+ continue;
1590
+
1591
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1592
+
1593
+ int color = //1 << object; //
1594
+ //p.vertexlinks.length;
1595
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1596
+ colorV[2] += (color & 1) * weight;
1597
+ colorV[1] += ((color & 2) >> 1) * weight;
1598
+ colorV[0] += ((color & 4) >> 2) * weight;
1599
+ }
1600
+ }
1601
+ else
1602
+ {
1603
+ if (obj.drawingstarted)
1604
+ {
1605
+ // find next point
1606
+ if (bRep.GetVertex(0).faceindices == null)
1607
+ {
1608
+ bRep.InitFaceIndices();
1609
+ }
1610
+
1611
+ double ymin = p0.y;
1612
+
1613
+ Vertex newp = p0;
1614
+
1615
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1616
+ {
1617
+ int fi = p0.faceindices[fii];
1618
+
1619
+ if (fi == -1)
1620
+ break;
1621
+
1622
+ Face f = bRep.GetFace(fi);
1623
+
1624
+ Vertex p = bRep.GetVertex(f.p);
1625
+ Vertex q = bRep.GetVertex(f.q);
1626
+ Vertex r = bRep.GetVertex(f.r);
1627
+
1628
+ int swap = (int)(Math.random()*3);
1629
+
1630
+// for (int s=swap; --s>=0;)
1631
+// {
1632
+// Vertex t = p;
1633
+// p = q;
1634
+// q = r;
1635
+// r = t;
1636
+// }
1637
+ if (ymin > p.y)
1638
+ {
1639
+ ymin = p.y;
1640
+ newp = p;
1641
+// break;
1642
+ }
1643
+ if (ymin > q.y)
1644
+ {
1645
+ ymin = q.y;
1646
+ newp = q;
1647
+// break;
1648
+ }
1649
+ if (ymin > r.y)
1650
+ {
1651
+ ymin = r.y;
1652
+ newp = r;
1653
+// break;
1654
+ }
1655
+ }
1656
+
1657
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1658
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1659
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1660
+
1661
+ obj.drawingstarted = false;
1662
+
1663
+ // return;
1664
+ }
1665
+
1666
+ if (false) // CameraPane.DRAW
1667
+ {
1668
+ p0.AO = colorV[0] = 2;
1669
+ colorV[1] = 2;
1670
+ colorV[2] = 2;
1671
+ }
1672
+
1673
+ CameraPane.pointflow.add(p0);
1674
+ CameraPane.pointflow.Touch();
1675
+ }
1676
+
1677
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1678
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1679
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1680
+ }
1681
+
1682
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1683
+ {
1684
+ CameraPane display = this;
1685
+ //new Exception().printStackTrace();
1686
+
1687
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1688
+ {
1689
+ return;
1690
+ }
1691
+
1692
+ javax.media.opengl.GL gl = display.GetGL();
1693
+
1694
+ //Color col = Color.getHSBColor(color,modulation,1);
1695
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1696
+ if (!material.multiply)
1697
+ {
1698
+ display.color = material.color;
1699
+ display.saturation = material.modulation;
1700
+ }
1701
+ else
1702
+ {
1703
+ display.color *= material.color*2;
1704
+ display.saturation *= material.modulation*2;
1705
+ }
1706
+
1707
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1708
+
1709
+ float[] colorV = Grafreed.colorV;
1710
+
1711
+ /**/
1712
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1713
+ {
1714
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1715
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1716
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1717
+ colorV[3] = 1; // material.opacity;
1718
+
1719
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1720
+ //System.out.println("Opacity = " + opacity);
1721
+
1722
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1723
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1724
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1725
+
1726
+ float amb = material.ambient;
1727
+ if (amb < material.cameralight)
1728
+ {
1729
+ amb = material.cameralight;
1730
+ }
1731
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1732
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1733
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1734
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1735
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1736
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1737
+
1738
+ /**/
1739
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1740
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1741
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1742
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1743
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1744
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1745
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1746
+ //System.out.println("shininess = " + colorV[0]);
1747
+ if (colorV[0] > 128)
1748
+ {
1749
+ colorV[0] = 128;
1750
+ }
1751
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1752
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1753
+ /**/
1754
+ }
1755
+ /**/
1756
+
1757
+ //selected = false;
1758
+ selected = selected && display.flash;
1759
+
1760
+ //display.modelParams0[0] = 0; // pigment.r;
1761
+ //display.modelParams0[1] = 0; // pigment.g;
1762
+ //display.modelParams0[2] = 0; // pigment.b;
1763
+ if (!material.multiply)
1764
+ {
1765
+ display.modelParams0[3] = material.metalness;
1766
+ display.modelParams1[0] = material.diffuse;
1767
+ display.modelParams1[1] = material.specular;
1768
+ display.modelParams1[2] = 1 / material.shininess;
1769
+ display.modelParams1[3] = material.shift;
1770
+ display.modelParams2[0] = material.ambient;
1771
+ display.modelParams2[1] = material.lightarea;
1772
+ //System.out.println("light area = " + lightarea);
1773
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1774
+ display.modelParams2[3] = material.velvet;
1775
+ display.modelParams3[0] = material.sheen;
1776
+ display.modelParams3[1] = material.subsurface;
1777
+ display.modelParams3[2] = material.bump; // backlit
1778
+ display.modelParams3[3] = material.aniso;
1779
+ display.modelParams4[0] = material.anisoV;
1780
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1781
+ //System.out.println("selected = " + selected);
1782
+ display.modelParams4[2] = material.diffuseness;
1783
+ display.modelParams4[3] = material.shadow;
1784
+ display.modelParams5[0] = material.texture;
1785
+ display.modelParams5[1] = material.opacity;
1786
+ display.modelParams5[2] = material.fakedepth;
1787
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1788
+ }
1789
+ else
1790
+ {
1791
+ display.modelParams0[3] *= material.metalness*2;
1792
+ display.modelParams1[0] *= material.diffuse*2;
1793
+ display.modelParams1[1] *= material.specular*2;
1794
+ display.modelParams1[2] *= material.shininess*2;
1795
+ display.modelParams1[3] *= material.shift*2;
1796
+ display.modelParams2[0] *= material.ambient*2;
1797
+ display.modelParams2[1] *= material.lightarea*2;
1798
+ display.modelParams2[2] *= material.factor*2;
1799
+ display.modelParams2[3] *= material.velvet*2;
1800
+ display.modelParams3[0] *= material.sheen*2;
1801
+ display.modelParams3[1] *= material.subsurface*2;
1802
+ display.modelParams3[2] *= material.bump*2;
1803
+ display.modelParams3[3] *= material.aniso*2;
1804
+ display.modelParams4[0] *= material.anisoV*2;
1805
+ display.modelParams4[1] *= material.cameralight*2;
1806
+ //System.out.println("selected = " + selected);
1807
+ display.modelParams4[2] *= material.diffuseness*2;
1808
+ display.modelParams4[3] *= material.shadow*2;
1809
+ display.modelParams5[0] *= material.texture*2;
1810
+ display.modelParams5[1] *= material.opacity*2;
1811
+ display.modelParams5[2] *= material.fakedepth*2;
1812
+ display.modelParams5[3] *= material.shadowbias*2;
1813
+ }
1814
+
1815
+ display.modelParams6[0] = 0;
1816
+ display.modelParams6[1] = 0;
1817
+ display.modelParams6[2] = 0;
1818
+ display.modelParams6[3] = 0;
1819
+
1820
+ display.modelParams7[0] = 0;
1821
+ display.modelParams7[1] = 1000;
1822
+ display.modelParams7[2] = 0;
1823
+ display.modelParams7[3] = 0;
1824
+
1825
+ //display.modelParams6[0] = 100; // criss de bug de bump
1826
+
1827
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1828
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1829
+ {
1830
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1831
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1832
+ if (extparams.length > 1)
1833
+ {
1834
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1835
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1836
+ if (extparams.length > 2)
1837
+ {
1838
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1839
+ float x = extparams[2].y / 1000.0f;
1840
+ //if (x == 0)
1841
+ // x = 1f;
1842
+ 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
1843
+ if (extparams[2].y > 0)
1844
+ {
1845
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1846
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1847
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1848
+ }
1849
+ }
1850
+ }
1851
+ }
1852
+
1853
+ //if (display.modelParams6[2] != 0)
1854
+ /*
1855
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1856
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1857
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1858
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1859
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1860
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1861
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1862
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1863
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1864
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1865
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1866
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1867
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1868
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1869
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1870
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1871
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1872
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1873
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1874
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1875
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1876
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1877
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1878
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1879
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1880
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1881
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1882
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1883
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1884
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1885
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1886
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1887
+ /**/
1888
+ //assert (display.modelParams6[2] == 0);
1889
+
1890
+ //System.out.println("noise power = " + display.modelParams7[0]);
1891
+ //System.out.println("shadowbias = " + shadowbias);
1892
+
1893
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1896
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1897
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1898
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1899
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1900
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1901
+
1902
+ int mode = display.FP_SHADER;
1903
+
1904
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1905
+ {
1906
+ mode |= display.FP_ANISO;
1907
+ }
1908
+
1909
+ display.EnableProgram(mode);
1910
+
1911
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1912
+
1913
+ if (!material.multiply)
1914
+ {
1915
+ if (Globals.drawMode == CameraPane.SHADOW)
1916
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1917
+ else
1918
+ gl.glDepthMask(material.opacity >= 0.99);
1919
+ }
2081920 }
2091921
2101922 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1937,7 @@
2251937 currentGL.glMultMatrixd(model, 0);
2261938 }
2271939
228
- void PushMatrix(double[][] matrix, int count)
1940
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291941 {
2301942 matrixdepth++;
2311943 // GrafreeD.tracein(matrix);
....@@ -254,7 +1966,7 @@
2541966 void PushMatrix(double[][] matrix)
2551967 {
2561968 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1969
+ PushMatrix(matrix, 1);
2581970 }
2591971
2601972 void PushMatrix()
....@@ -270,7 +1982,7 @@
2701982
2711983 double[][] tmpmat = new double[4][4];
2721984
273
- void PopMatrix(double[][] inverse)
1985
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741986 {
2751987 --matrixdepth;
2761988
....@@ -310,7 +2022,7 @@
3102022 PushTextureMatrix(matrix, 1);
3112023 }
3122024
313
- void PushTextureMatrix(double[][] matrix, int count)
2025
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142026 {
3152027 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162028
....@@ -324,7 +2036,7 @@
3242036 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252037 }
3262038
327
- void PopTextureMatrix(double[][] inverse)
2039
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282040 {
3292041 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302042 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2063,15 @@
3512063
3522064 static int camerachangeframe;
3532065
354
- boolean SetCamera(Camera cam)
2066
+ public boolean SetCamera(Camera cam)
3552067 {
3562068 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572069 // return false;
3582070
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2071
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602072 {
3612073 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2074
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632075 {
3642076 // refuse the camera change
3652077 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2079,7 @@
3672079 }
3682080 }
3692081
370
- camerachangeframe = framecount;
2082
+ camerachangeframe = Globals.framecount;
3712083
3722084 cam.hAspect = -1; // Read only
3732085
....@@ -398,7 +2110,7 @@
3982110 {
3992111 //System.err.println("Oeil on");
4002112 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2113
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022114 // object.editWindow.ScreenFit(trackedobject);
4032115 //pingthread.StepToTarget(true);
4042116 }
....@@ -407,8 +2119,8 @@
4072119 {
4082120 //System.err.println("Oeil on");
4092121 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2122
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2123
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122124 //pingthread.StepToTarget(true);
4132125 }
4142126
....@@ -471,39 +2183,12 @@
4712183 {
4722184 frozen ^= true;
4732185 // Weird...
474
- lighttouched = true;
2186
+ Globals.lighttouched = true;
4752187 }
4762188
4772189 void ToggleDL()
4782190 {
4792191 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GrafreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072192 }
5082193
5092194 void ToggleFullScreen()
....@@ -513,12 +2198,7 @@
5132198
5142199 void ToggleCrowd()
5152200 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2201
+ Globals.CROWD ^= true;
5222202 }
5232203
5242204 void ToggleLocal()
....@@ -526,62 +2206,89 @@
5262206 LOCALTRANSFORM ^= true;
5272207 }
5282208
529
- void ToggleFast()
2209
+ public void ToggleTexture()
2210
+ {
2211
+ textureon ^= true;
2212
+ }
2213
+
2214
+ public void ToggleLive()
2215
+ {
2216
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2217
+
2218
+ System.err.println("LIVE = " + Globals.isLIVE());
2219
+
2220
+ if (!Globals.isLIVE()) // save sound
2221
+ Grafreed.savesound = true; // wav.save();
2222
+ // else
2223
+ repaint(); // start loop // may 2013
2224
+ }
2225
+
2226
+ public void ToggleSupport()
2227
+ {
2228
+ SUPPORT ^= true;
2229
+ }
2230
+
2231
+ public void ToggleAbort()
2232
+ {
2233
+ ABORTMODE ^= true;
2234
+ }
2235
+
2236
+ public void ToggleInertia()
2237
+ {
2238
+ INERTIA ^= true;
2239
+ }
2240
+
2241
+ public void ToggleFast()
5302242 {
5312243 FAST ^= true;
5322244 }
5332245
534
- void ToggleSlowPose()
2246
+ public void ToggleSlowPose()
5352247 {
5362248 SLOWPOSE ^= true;
5372249 }
5382250
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2251
+ public void ToggleBoxMode()
5452252 {
5462253 BOXMODE ^= true;
5472254 }
5482255
549
- void ToggleSmoothFocus()
2256
+ public void ToggleZoomBoxMode()
2257
+ {
2258
+ ZOOMBOXMODE ^= true;
2259
+ }
2260
+
2261
+ public void ToggleSmoothFocus()
5502262 {
5512263 SMOOTHFOCUS ^= true;
5522264 }
5532265
554
- void ToggleImageFlip()
2266
+ public void ToggleImageFlip()
5552267 {
5562268 IMAGEFLIP ^= true;
5572269 }
5582270
559
- void ToggleSpeakerMocap()
2271
+ public void ToggleSpeakerMocap()
5602272 {
5612273 SPEAKERMOCAP ^= true;
5622274 }
5632275
564
- void ToggleSpeakerCamera()
2276
+ public void ToggleSpeakerCamera()
5652277 {
5662278 SPEAKERCAMERA ^= true;
5672279 }
5682280
569
- void ToggleSpeakerFocus()
2281
+ public void ToggleSpeakerFocus()
5702282 {
5712283 SPEAKERFOCUS ^= true;
5722284 }
5732285
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2286
+ public void ToggleFrustum()
5802287 {
5812288 FRUSTUM ^= true;
5822289 }
5832290
584
- void ToggleTrack()
2291
+ public void ToggleTrack()
5852292 {
5862293 TRACK ^= true;
5872294 if (TRACK)
....@@ -600,25 +2307,35 @@
6002307 repaint();
6012308 }
6022309
603
- void ToggleTrackOnce()
2310
+ public void ToggleTrackOnce()
6042311 {
6052312 TRACKONCE ^= true;
6062313 }
6072314
608
- void ToggleShadowTrack()
2315
+ public void ToggleShadowTrack()
6092316 {
6102317 SHADOWTRACK ^= true;
6112318 repaint();
6122319 }
6132320
614
- void ToggleOeil()
2321
+ public void ToggleOeil()
6152322 {
6162323 OEIL ^= true;
6172324 }
6182325
619
- void ToggleOeilOnce()
2326
+ public void ToggleOeilOnce()
6202327 {
6212328 OEILONCE ^= true;
2329
+ }
2330
+
2331
+ void ToggleFootContact()
2332
+ {
2333
+ FOOTCONTACT ^= true;
2334
+ }
2335
+
2336
+ void ToggleDebug()
2337
+ {
2338
+ Globals.DEBUG ^= true;
6222339 }
6232340
6242341 void ToggleLookAt()
....@@ -626,9 +2343,9 @@
6262343 LOOKAT ^= true;
6272344 }
6282345
629
- void ToggleRandom()
2346
+ void ToggleSwitch()
6302347 {
631
- RANDOM ^= true;
2348
+ SWITCH ^= true;
6322349 }
6332350
6342351 void ToggleHandles()
....@@ -636,10 +2353,17 @@
6362353 HANDLES ^= true;
6372354 }
6382355
2356
+ Object3D paintFolder;
2357
+
6392358 void TogglePaint()
6402359 {
6412360 PAINTMODE ^= true;
6422361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
6432367 }
6442368
6452369 void SwapCamera(int a, int b)
....@@ -672,34 +2396,6 @@
6722396 //assert (cam.hAspect == 0);
6732397 cam.hAspect = 0;
6742398 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
7032399 }
7042400
7052401 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2455,26 @@
7592455
7602456 GL currentGL;
7612457
762
- GL GetGL()
2458
+ public GL GetGL() // INTERFACE
7632459 {
7642460 return currentGL;
7652461 }
766
-
2462
+
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
7672478 /**/
7682479 class CacheTexture
7692480 {
....@@ -772,28 +2483,31 @@
7722483
7732484 int resolution;
7742485
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762487 {
777
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
7782490 resolution = res;
7792491 }
7802492 }
7812493 /**/
7822494
7832495 // 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>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
7872501 int pigmentdepth = 0;
7882502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892503 int bumpdepth = 0;
7902504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952509
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972511 {
7982512 TextureData texturedata = null;
7992513
....@@ -803,7 +2517,7 @@
8032517 com.sun.opengl.util.texture.TextureIO.newTextureData(
8042518 getClass().getClassLoader().getResourceAsStream(name),
8052519 true,
806
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
8072521 } catch (java.io.IOException e)
8082522 {
8092523 throw new javax.media.opengl.GLException(e);
....@@ -812,13 +2526,34 @@
8122526 if (bump)
8132527 texturedata = ConvertBump(texturedata, false);
8142528
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172531
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);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202534
821
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
8222557 }
8232558
8242559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3626,8 @@
18913626
18923627 System.out.println("LOADING TEXTURE : " + name);
18933628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
18943631 //
18953632 if (false) // compressbit > 0)
18963633 {
....@@ -2000,10 +3737,12 @@
20003737 */
20013738 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20023739 {
3740
+ int pixelformat = texturedata.getPixelFormat();
3741
+
20033742 int stride = 1;
2004
- if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
3743
+ if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
20053744 stride = 3;
2006
- if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
3745
+ if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
20073746 stride = 4;
20083747
20093748 int width = texturedata.getWidth();
....@@ -2593,6 +4332,7 @@
25934332
25944333 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25954334 {
4335
+ new Exception().printStackTrace();
25964336 System.exit(0);
25974337 com.sun.opengl.util.texture.Texture texture = null;
25984338
....@@ -6269,7 +8009,7 @@
62698009 return null;
62708010 }
62718011
6272
- void ReleaseTextures(cTexture tex)
8012
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62738013 {
62748014 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62758015 {
....@@ -6286,7 +8026,7 @@
62868026 String pigment = Object3D.GetPigment(tex);
62878027 String bump = Object3D.GetBump(tex);
62888028
6289
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62908030 {
62918031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62928032 // System.out.println("; bump = " + bump);
....@@ -6301,13 +8041,71 @@
63018041 pigment = null;
63028042 }
63038043
6304
- ReleaseTexture(bump, true);
6305
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
63068046 }
63078047
6308
- void ReleaseTexture(String tex, boolean bump)
8048
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63098049 {
6310
- if (// drawMode != 0 || /*tex == null ||*/
8050
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8051
+ {
8052
+ return;
8053
+ }
8054
+
8055
+ if (tex == null)
8056
+ {
8057
+ ReleaseTexture(null, false);
8058
+ return;
8059
+ }
8060
+
8061
+ String pigment = Object3D.GetPigment(tex);
8062
+
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8064
+ {
8065
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8066
+ // System.out.println("; bump = " + bump);
8067
+ }
8068
+
8069
+ if (pigment.equals(""))
8070
+ {
8071
+ pigment = null;
8072
+ }
8073
+
8074
+ ReleaseTexture(tex, false);
8075
+ }
8076
+
8077
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8078
+ {
8079
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8080
+ {
8081
+ return;
8082
+ }
8083
+
8084
+ if (tex == null)
8085
+ {
8086
+ ReleaseTexture(null, true);
8087
+ return;
8088
+ }
8089
+
8090
+ String bump = Object3D.GetBump(tex);
8091
+
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8093
+ {
8094
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8095
+ // System.out.println("; bump = " + bump);
8096
+ }
8097
+
8098
+ if (bump.equals(""))
8099
+ {
8100
+ bump = null;
8101
+ }
8102
+
8103
+ ReleaseTexture(tex, true);
8104
+ }
8105
+
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
8107
+ {
8108
+ if (// DrawMode() != 0 || /*tex == null ||*/
63118109 ambientOcclusion ) // || !textureon)
63128110 {
63138111 return;
....@@ -6316,7 +8114,7 @@
63168114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63178115
63188116 if (tex != null)
6319
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63208118
63218119 // //assert( texture != null );
63228120 // if (texture == null)
....@@ -6408,9 +8206,57 @@
64088206 }
64098207 }
64108208
6411
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8209
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64128210 {
6413
- if (// drawMode != 0 || /*tex == null ||*/
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
8252
+
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
8255
+ }
8256
+
8257
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8258
+ {
8259
+ if (// DrawMode() != 0 || /*tex == null ||*/
64148260 ambientOcclusion ) // || !textureon)
64158261 {
64168262 return; // false;
....@@ -6419,17 +8265,47 @@
64198265 if (tex == null)
64208266 {
64218267 BindTexture(null,false,resolution);
6422
- BindTexture(null,true,resolution);
64238268 return;
64248269 }
64258270
64268271 String pigment = Object3D.GetPigment(tex);
8272
+
8273
+ usedtextures.add(tex);
8274
+
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8276
+ {
8277
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8278
+ // System.out.println("; bump = " + bump);
8279
+ }
8280
+
8281
+ if (pigment.equals(""))
8282
+ {
8283
+ pigment = null;
8284
+ }
8285
+
8286
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8287
+ BindTexture(tex, false, resolution);
8288
+ }
8289
+
8290
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8291
+ {
8292
+ if (// DrawMode() != 0 || /*tex == null ||*/
8293
+ ambientOcclusion ) // || !textureon)
8294
+ {
8295
+ return; // false;
8296
+ }
8297
+
8298
+ if (tex == null)
8299
+ {
8300
+ BindTexture(null,true,resolution);
8301
+ return;
8302
+ }
8303
+
64278304 String bump = Object3D.GetBump(tex);
64288305
6429
- usedtextures.put(pigment, pigment);
6430
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
64318307
6432
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64338309 {
64348310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64358311 // System.out.println("; bump = " + bump);
....@@ -6439,43 +8315,94 @@
64398315 {
64408316 bump = null;
64418317 }
6442
- if (pigment.equals(""))
6443
- {
6444
- pigment = null;
6445
- }
64468318
6447
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6448
- BindTexture(pigment, false, resolution);
64498319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6450
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
64518321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6452
-
6453
- return; // true;
64548322 }
64558323
6456
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8324
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8325
+
8326
+ private boolean FileExists(String tex)
64578327 {
6458
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ if (missingTextures.contains(tex))
8329
+ {
8330
+ return false;
8331
+ }
8332
+
8333
+ boolean fileExists = new File(tex).exists();
8334
+
8335
+ if (!fileExists)
8336
+ {
8337
+ // If file exists, the "new File()" is not executed sgain
8338
+ missingTextures.add(tex);
8339
+ }
8340
+
8341
+ return fileExists;
8342
+ }
8343
+
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8345
+ {
8346
+ CacheTexture texturecache = null;
64598347
64608348 if (tex != null)
64618349 {
6462
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64638352
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;
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
8357
+
8358
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8359
+
8360
+// String[] split = tex.split("Textures");
8361
+// if (split.length > 1)
8362
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8363
+// else
8364
+// if (!texname.startsWith("/"))
8365
+// texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
8367
+ {
8368
+ texname = fallbackTextureName;
8369
+ }
64708370
64718371 if (CACHETEXTURE)
6472
- texture = textures.get(texname); // TEXTURE CACHE
6473
-
6474
- TextureData texturedata = null;
6475
-
6476
- if (texture == null || texture.resolution < resolution)
64778372 {
6478
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64798406 {
64808407 assert(!bump);
64818408 // if (bump)
....@@ -6486,19 +8413,23 @@
64868413 // }
64878414 // else
64888415 // {
6489
- texture = textures.get(tex);
6490
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
64918418 {
6492
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64938420 }
8421
+ else
8422
+ new Exception().printStackTrace();
64948423 // }
64958424 } else
6496
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64978426 {
64988427 assert(bump);
6499
- texture = textures.get(tex);
6500
- if (texture == null)
6501
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
65028433 } else
65038434 {
65048435 //if (tex.equals("IMMORTAL"))
....@@ -6506,11 +8437,22 @@
65068437 // texture = GetResourceTexture("default.png");
65078438 //} else
65088439 //{
6509
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
65108441 {
6511
- texture = textures.get(tex);
6512
- if (texture == null)
6513
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
65148456 } else
65158457 {
65168458 if (textureon)
....@@ -6535,7 +8477,7 @@
65358477 }
65368478
65378479 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6538
- if (!new File(cachename).exists())
8480
+ if (!FileExists(cachename))
65398481 cachename = texname;
65408482 else
65418483 processbump = false; // don't process bump map again
....@@ -6557,7 +8499,7 @@
65578499 }
65588500
65598501 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6560
- if (!new File(cachename).exists())
8502
+ if (!FileExists(cachename))
65618503 cachename = texname;
65628504 else
65638505 processbump = false; // don't process bump map again
....@@ -6566,20 +8508,23 @@
65668508 texturedata = GetFileTexture(cachename, processbump, resolution);
65678509
65688510
6569
- if (texturedata != null)
6570
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8511
+ if (texturedata == null)
8512
+ throw new Exception();
8513
+
8514
+ texturecache = new CacheTexture(texturedata,resolution);
65718515 //texture = GetTexture(tex, bump);
65728516 }
8517
+ }
65738518 }
65748519 //}
65758520 }
65768521
6577
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65788523 {
65798524 //return false;
65808525
65818526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6582
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65838528 {
65848529 // String ext = "_highres";
65858530 // if (REDUCETEXTURE)
....@@ -6596,52 +8541,17 @@
65968541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65978542 if (!cachefile.exists())
65988543 {
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))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
66088545 {
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);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
66398548 ImageWriter writer = null;
66408549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66418550 if (iter.hasNext()) {
66428551 writer = (ImageWriter)iter.next();
66438552 }
6644
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
66458555 try
66468556 {
66478557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6658,18 +8568,20 @@
66588568 }
66598569 }
66608570 }
6661
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
66628574 //System.out.println("Texture = " + tex);
6663
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
66648576 {
6665
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
66668578 thetex.texture.disable();
66678579 thetex.texture.dispose();
6668
- textures.remove(texname);
8580
+ textures.remove(tex);
66698581 }
66708582
6671
- texture.texturedata = texturedata;
6672
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
66738585
66748586 // newtex = true;
66758587 }
....@@ -6685,10 +8597,44 @@
66858597 }
66868598 }
66878599
6688
- return texture;
8600
+ return texturecache;
66898601 }
66908602
6691
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66928638 {
66938639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66948640
....@@ -6706,21 +8652,21 @@
67068652 return texture!=null?texture.texture:null;
67078653 }
67088654
6709
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67108656 {
67118657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67128658
67138659 return texture!=null?texture.texturedata:null;
67148660 }
67158661
6716
- boolean BindTexture(String tex, boolean bump, int resolution)
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67178663 {
67188664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67198665 {
67208666 return false;
67218667 }
67228668
6723
- boolean newtex = false;
8669
+ //boolean newtex = false;
67248670
67258671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67268672
....@@ -6752,9 +8698,75 @@
67528698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67538699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67548700
6755
- return newtex;
8701
+ return true; // Warning: not used.
67568702 }
67578703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
67588770 ShadowBuffer shadowPBuf;
67598771 AntialiasBuffer antialiasPBuf;
67608772 int MAXSTACK;
....@@ -6771,10 +8783,12 @@
67718783
67728784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67738785 MAXSTACK = temp[0];
6774
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67758788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67768789 MAXSTACK = temp[0];
6777
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67788792
67798793 // Use debug pipeline
67808794 //drawable.setGL(new DebugGL(gl)); //
....@@ -6782,7 +8796,8 @@
67828796 gl = drawable.getGL(); //
67838797
67848798 GL gl3 = getGL();
6785
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67868801
67878802
67888803 //float pos[] = { 100, 100, 100, 0 };
....@@ -6947,7 +8962,7 @@
69478962
69488963 if (cubemap == null)
69498964 {
6950
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
69518966 }
69528967
69538968 //cubemap.enable();
....@@ -7223,6 +9238,8 @@
72239238
72249239 void LoadEnvy(int which)
72259240 {
9241
+ assert(false);
9242
+
72269243 String name;
72279244 String ext;
72289245
....@@ -7234,37 +9251,58 @@
72349251 cubemap = null;
72359252 return;
72369253 case 1:
7237
- name = "cubemaps/box_";
7238
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
72399256 reverseUP = false;
72409257 break;
72419258 case 2:
7242
- name = "cubemaps/uffizi_";
7243
- ext = "png";
7244
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
72459263 case 3:
7246
- name = "cubemaps/CloudyHills_";
7247
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
72489266 reverseUP = false;
72499267 break;
72509268 case 4:
7251
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
72529270 ext = "png";
72539271 reverseUP = false;
72549272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
72559298 default:
7256
- name = "cubemaps/rgb_";
7257
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
72589302 break;
72599303 }
7260
-
7261
- try
7262
- {
7263
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7264
- } catch (IOException e)
7265
- {
7266
- throw new RuntimeException(e);
7267
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
72689306 }
72699307
72709308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7296,8 +9334,12 @@
72969334 static double[] model = new double[16];
72979335 double[] camera2light = new double[16];
72989336 double[] light2camera = new double[16];
7299
- int newenvy = -1;
7300
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
73019343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73029344 //float[] light0 = { 0,0,0 };
73039345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7310,9 +9352,9 @@
73109352 static boolean occlusionInitialized = false;
73119353 boolean selection = false;
73129354 boolean pointselection = false;
7313
- /*static*/ boolean lighttouched = true;
9355
+ ///*static*/ boolean lighttouched = true;
73149356 boolean deselect;
7315
- boolean ambientOcclusion = false;
9357
+ private boolean ambientOcclusion = false;
73169358 static boolean flash = false;
73179359 /*static*/ boolean wait = false;
73189360 boolean displaydone = false; // after repaint() calls
....@@ -7442,6 +9484,8 @@
74429484 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74439485 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74449486 double scale = lightCamera.SCALE / lightCamera.Distance();
9487
+// PATCH FILLE AUX JEANS
9488
+ //scale *= lightCamera.shaper_fovy / 25;
74459489 gl.glScaled(2 * scale, 2 * scale, -scale);
74469490 gl.glTranslated(0, 0, lightCamera.DECAL);
74479491
....@@ -7588,17 +9632,40 @@
75889632 jy8[3] = 0.5f;
75899633 }
75909634
7591
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9635
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75929636 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
9637
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9638
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75949639
9640
+ void ResetOptions()
9641
+ {
9642
+ options1[0] = 100;
9643
+ options1[1] = 0.025f;
9644
+ options1[2] = 0.01f;
9645
+ options1[3] = 0;
9646
+ options1[4] = 0;
9647
+
9648
+ options2[0] = 0;
9649
+ options2[1] = 0.75f;
9650
+ options2[2] = 0;
9651
+ options2[3] = 0;
9652
+
9653
+ options3[0] = 1;
9654
+ options3[1] = 1;
9655
+ options3[2] = 1;
9656
+ options3[3] = 0;
9657
+
9658
+ options4[0] = 1;
9659
+ options4[1] = 0;
9660
+ options4[2] = 1;
9661
+ options4[3] = 0;
9662
+ }
9663
+
75959664 static int imagecount = 0; // movie generation
75969665
75979666 static int jitter = 0;
75989667
75999668 boolean restartframe = false;
7600
-
7601
- static int framecount = 0; // general-purpose global count
76029669
76039670 void displayAntiAliased(javax.media.opengl.GL gl)
76049671 {
....@@ -7630,7 +9697,7 @@
76309697 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76319698 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76329699 {
7633
- framecount++;
9700
+ Globals.framecount++;
76349701
76359702 if (CameraPane.tickcount > 0)
76369703 CameraPane.tickcount--;
....@@ -7668,7 +9735,7 @@
76689735
76699736 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76709737 */
7671
- lighttouched = true;
9738
+ Globals.lighttouched = true;
76729739 //System.err.println(" shadowbuffer: " + jitter);
76739740 shadowbuffer.display();
76749741
....@@ -7689,8 +9756,8 @@
76899756 assert (parentcam != renderCamera);
76909757
76919758 if (renderCamera != lightCamera)
7692
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7693
- LA.matConcat(parentcam.toParent, matrix, matrix);
9759
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76949761
76959762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76969763
....@@ -7705,8 +9772,8 @@
77059772 LA.matCopy(renderCamera.fromScreen, matrix);
77069773
77079774 if (renderCamera != lightCamera)
7708
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7709
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9775
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77109777
77119778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77129779
....@@ -7752,10 +9819,12 @@
77529819 rati = 1 / rati;
77539820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77549821 }
7755
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
77569825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77579826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7758
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
77599828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77609829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77619830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7778,7 +9847,7 @@
77789847 //gl.glFlush();
77799848 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77809849
7781
- if (ANIMATION && ABORTED)
9850
+ if (Globals.ANIMATION && ABORTED)
77829851 {
77839852 System.err.println(" ABORTED FRAME");
77849853 break;
....@@ -7808,7 +9877,7 @@
78089877 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78099878
78109879 // save image
7811
- if (ANIMATION && !ABORTED)
9880
+ if (Globals.ANIMATION && !ABORTED)
78129881 {
78139882 VPwidth = viewport[2];
78149883 VPheight = viewport[3];
....@@ -7919,11 +9988,11 @@
79199988
79209989 // imagecount++;
79219990
7922
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9991
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79239992
79249993 if (!BOXMODE)
79259994 {
7926
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9995
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79279996 }
79289997
79299998 if (!BOXMODE)
....@@ -7961,7 +10030,7 @@
796110030 ABORTED = false;
796210031 }
796310032 else
7964
- GrafreeD.wav.cursor += 735 * ACSIZE;
10033
+ Grafreed.wav.cursor += 735 * ACSIZE;
796510034
796610035 if (false)
796710036 {
....@@ -8615,13 +10684,6 @@
861510684 }
861610685 }
861710686
8618
- boolean IsFrozen()
8619
- {
8620
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8621
-
8622
- return !selectmode && cameracount == 0; // != 0;
8623
- }
8624
-
862510687 boolean niceon = false;
862610688 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
862710689 boolean currentlydrawing = false;
....@@ -8631,16 +10693,16 @@
863110693
863210694 public void display(GLAutoDrawable drawable)
863310695 {
8634
- if (GrafreeD.savesound && GrafreeD.hassound)
10696
+ if (Grafreed.savesound && Grafreed.hassound)
863510697 {
8636
- GrafreeD.wav.save();
8637
- GrafreeD.savesound = false;
8638
- GrafreeD.hassound = false;
10698
+ Grafreed.wav.save();
10699
+ Grafreed.savesound = false;
10700
+ Grafreed.hassound = false;
863910701 }
864010702 // if (DEBUG_SELECTION)
864110703 // {
8642
-// if (drawMode != SELECTION)
8643
-// drawMode = SELECTION;
10704
+// if (DrawMode() != SELECTION)
10705
+// DrawMode() = SELECTION;
864410706 // }
864510707
864610708 if (!isRenderer)
....@@ -8696,9 +10758,9 @@
869610758
869710759 //ANTIALIAS = 0;
869810760
8699
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10761
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870010762 {
8701
- if (niceon || isLIVE())
10763
+ if (niceon || Globals.isLIVE())
870210764 {
870310765 //if(active == 0)
870410766 // antialiaser = null;
....@@ -8711,6 +10773,7 @@
871110773 ANTIALIAS = 0;
871210774 //System.out.println("RESTART");
871310775 AAtimer.restart();
10776
+ Globals.TIMERRUNNING = true;
871410777 }
871510778 }
871610779 }
....@@ -8723,7 +10786,7 @@
872310786 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872410787 */
872510788
8726
- if (drawMode == DEFAULT)
10789
+ if (DrawMode() == DEFAULT)
872710790 {
872810791 currentlydrawing = true;
872910792 }
....@@ -8754,18 +10817,18 @@
875410817
875510818 // if(Applet3D.clipboard != null)
875610819 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8757
-//drawMode = SELECTION;
10820
+//DrawMode() = SELECTION;
875810821 indexcount = 0;
875910822
8760
- if (drawMode == OCCLUSION)
10823
+ if (DrawMode() == OCCLUSION)
876110824 {
8762
- drawMode = DEFAULT;
10825
+ Globals.drawMode = DEFAULT; // WARNING
876310826 ambientOcclusion = true;
876410827 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876510828 Object3D theobject = object;
876610829 Object3D theparent = object.parent;
876710830 object.parent = null;
8768
- object = (Object3D)GrafreeD.clone(object);
10831
+ object = (Object3D)Grafreed.clone(object);
876910832 object.Stripify();
877010833 if (theobject.selection == null || theobject.selection.Size() == 0)
877110834 theobject.PreprocessOcclusion(this);
....@@ -8778,26 +10841,27 @@
877810841 ambientOcclusion = false;
877910842 }
878010843
8781
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10844
+ if (//Globals.lighttouched &&
10845
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878210846 {
878310847 //if (RENDERSHADOW) // ?
878410848 if (!IsFrozen())
878510849 {
878610850 // dec 2012
8787
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10851
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
878810852 {
8789
- framecount++;
10853
+ Globals.framecount++;
879010854 shadowbuffer.display();
879110855 }
879210856 }
8793
- lighttouched = false; // ??
10857
+ Globals.lighttouched = false; // ??
879410858 //drawing = true;
879510859 //lighttouched = true;
879610860 }
879710861
879810862 if (wait)
879910863 {
8800
- Sleep(500);
10864
+ Sleep(200); // blocks everything
880110865
880210866 wait = false;
880310867 }
....@@ -8811,9 +10875,9 @@
881110875 //eyeCamera.shaper_fovy = 1;
881210876 }
881310877
8814
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10878
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881510879 {
8816
- //System.out.println("drawMode = " + drawMode);
10880
+ //System.out.println("DrawMode() = " + DrawMode());
881710881 vertexMode |= VP_PASS;
881810882 //vertexMode |= VP_PROJECTION;
881910883 if (!ambientOcclusion)
....@@ -8873,7 +10937,7 @@
887310937 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887410938 //Camera lightcam = new Camera(light0);
887510939
8876
- if (drawMode == SHADOW)
10940
+ if (DrawMode() == SHADOW)
887710941 {
887810942 /*
887910943 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8911,8 +10975,8 @@
891110975
891210976 // if (parentcam != renderCamera) // not a light
891310977 if (cam != lightCamera)
8914
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8915
- LA.matConcat(parentcam.toParent, matrix, matrix);
10978
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10979
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891610980
891710981 for (int j = 0; j < 4; j++)
891810982 {
....@@ -8926,8 +10990,8 @@
892610990
892710991 // if (parentcam != renderCamera) // not a light
892810992 if (cam != lightCamera)
8929
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8930
- LA.matConcat(matrix, parentcam.fromParent, matrix);
10993
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10994
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893110995
893210996 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893310997
....@@ -8963,7 +11027,7 @@
896311027 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896411028 } else
896511029 {
8966
- if (drawMode != DEFAULT)
11030
+ if (DrawMode() != DEFAULT)
896711031 {
896811032 gl.glClearColor(1, 1, 1, 0);
896911033 } // 1);
....@@ -9013,13 +11077,43 @@
901311077 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901411078 }
901511079
9016
- if (newenvy > -1)
11080
+// if (newenvy > -1)
11081
+// {
11082
+// LoadEnvy(newenvy);
11083
+// }
11084
+//
11085
+// newenvy = -1;
11086
+
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
901711088 {
9018
- LoadEnvy(newenvy);
11089
+ if (cubemaprgb == null)
11090
+ {
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11092
+ }
11093
+
11094
+ cubemap = cubemaprgb;
901911095 }
9020
-
9021
- newenvy = -1;
9022
-
11096
+ else
11097
+ {
11098
+ if (object.skyboxname != null)
11099
+ {
11100
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11101
+ {
11102
+ if (cubemap != null && cubemap != cubemaprgb)
11103
+ cubemap.dispose();
11104
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11105
+ loadedskyboxname = object.skyboxname;
11106
+ }
11107
+ }
11108
+ else
11109
+ {
11110
+ cubemapcustom = null;
11111
+ loadedskyboxname = null;
11112
+ }
11113
+
11114
+ cubemap = cubemapcustom;
11115
+ }
11116
+
902311117 ratio = ((double) getWidth()) / getHeight();
902411118 //System.out.println("ratio = " + ratio);
902511119
....@@ -9028,14 +11122,14 @@
902811122
902911123 fast &= !ambientOcclusion;
903011124
9031
- if (drawMode == DEFAULT)
11125
+ if (DrawMode() == DEFAULT)
903211126 {
903311127 //gl.glEnable(gl.GL_ALPHA_TEST);
903411128 //gl.glActiveTexture(GL.GL_TEXTURE0);
903511129
903611130 if (!IsFrozen() && !ambientOcclusion)
903711131 {
9038
- DrawSkyBox(gl);
11132
+ DrawSkyBox(gl, (float)ratio);
903911133 }
904011134
904111135 //if (selection_view == -1)
....@@ -9089,6 +11183,8 @@
908911183 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909011184 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909111185 double scale = lightCamera.SCALE / lightCamera.Distance();
11186
+// PATCH FILLE AUX JEANS
11187
+ //scale *= lightCamera.shaper_fovy / 25;
909211188 gl.glScaled(2 * scale, 2 * scale, -scale);
909311189 gl.glTranslated(0, 0, lightCamera.DECAL);
909411190
....@@ -9184,7 +11280,16 @@
918411280 // Bump noise
918511281 gl.glActiveTexture(GL.GL_TEXTURE6);
918611282 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9187
- BindTexture(NOISE_TEXTURE, false, 2);
11283
+
11284
+ try
11285
+ {
11286
+ BindTexture(NOISE_TEXTURE, false, 2);
11287
+ }
11288
+ catch (Exception e)
11289
+ {
11290
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11291
+ }
11292
+
918811293
918911294 gl.glActiveTexture(GL.GL_TEXTURE0);
919011295 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9207,9 +11312,9 @@
920711312
920811313 gl.glMatrixMode(GL.GL_MODELVIEW);
920911314
9210
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9211
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9212
-//gl.glEnable(gl.GL_MULTISAMPLE);
11315
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11316
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11317
+gl.glEnable(gl.GL_MULTISAMPLE);
921311318 } else
921411319 {
921511320 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9220,14 +11325,16 @@
922011325 //System.out.println("BLENDING ON");
922111326 gl.glEnable(GL.GL_BLEND);
922211327 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9223
-
11328
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922411329 gl.glMatrixMode(gl.GL_PROJECTION);
922511330 gl.glLoadIdentity();
922611331
9227
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11332
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
922811333 {
922911334 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923011335 double scale = lightCamera.SCALE / lightCamera.Distance();
11336
+// PATCH FILLE AUX JEANS
11337
+ //scale *= lightCamera.shaper_fovy / 25;
923111338 gl.glScaled(2 * scale, 2 * scale, -scale);
923211339 gl.glTranslated(0, 0, lightCamera.DECAL);
923311340 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9280,7 +11387,7 @@
928011387 //gl.glPushMatrix();
928111388 gl.glLoadIdentity();
928211389
9283
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11390
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928411391 {
928511392 //LA.xformPos(light0, lightCamera.fromScreen, light);
928611393 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9307,8 +11414,8 @@
930711414 System.err.println("parentcam != renderCamera");
930811415
930911416 // if (cam != lightCamera)
9310
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9311
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11417
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11418
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
931211419 }
931311420
931411421 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9329,8 +11436,8 @@
932911436 if (true) // TODO
933011437 {
933111438 if (cam != lightCamera)
9332
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9333
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933411441 }
933511442
933611443 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9367,7 +11474,7 @@
936711474 }
936811475
936911476 /**/
9370
- if (true) // drawMode == SELECTION) // != DEFAULT)
11477
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937111478 gl.glDisable(gl.GL_LIGHTING);
937211479 else
937311480 gl.glEnable(gl.GL_LIGHTING);
....@@ -9379,12 +11486,13 @@
937911486
938011487 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
938111488 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11489
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
938211490
938311491 options2[0] *= renderCamera.Distance();
938411492
938511493 lightslot = 64;
938611494
9387
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11495
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
938811496 {
938911497 DrawLights(object);
939011498 }
....@@ -9395,7 +11503,7 @@
939511503 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
939611504 //System.out.println("fragmentMode = " + fragmentMode);
939711505
9398
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11506
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
939911507 {
940011508 /*
940111509 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9428,7 +11536,7 @@
942811536 }
942911537 }
943011538
9431
- if (drawMode == DEFAULT)
11539
+ if (DrawMode() == DEFAULT)
943211540 {
943311541 if (WIREFRAME && !ambientOcclusion)
943411542 {
....@@ -9446,7 +11554,7 @@
944611554 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
944711555 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
944811556
9449
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11557
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945011558 {
945111559 if (vertexMode != 0) // && !fast)
945211560 {
....@@ -9466,7 +11574,7 @@
946611574 }
946711575 }
946811576
9469
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11577
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947011578 {
947111579 //gl.glDepthFunc(GL.GL_LEQUAL);
947211580 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9474,27 +11582,24 @@
947411582
947511583 boolean texon = textureon;
947611584
9477
- if (RENDERPROGRAM > 0)
9478
- {
9479
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9480
- textureon = false;
9481
- }
11585
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11586
+ textureon = false;
11587
+
948211588 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948311589 //System.out.println("ALLO");
948411590 gl.glColorMask(false, false, false, false);
948511591 DrawObject(gl);
9486
- if (RENDERPROGRAM > 0)
9487
- {
9488
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9489
- textureon = texon;
9490
- }
11592
+
11593
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11594
+ textureon = texon;
11595
+
949111596 gl.glColorMask(true, true, true, true);
949211597
949311598 gl.glDepthFunc(GL.GL_EQUAL);
9494
- //gl.glDepthMask(false);
11599
+ gl.glDepthMask(false);
949511600 }
949611601
9497
- if (false) // drawMode == SHADOW)
11602
+ if (false) // DrawMode() == SHADOW)
949811603 {
949911604 //SetColumnMajorData(cameraInverseTransform, view_1);
950011605 //System.out.println("light = " + cameraInverseTransform);
....@@ -9508,16 +11613,16 @@
950811613 //System.out.println("object = " + object);
950911614 if (!frozen && !imageLocked)
951011615 {
9511
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11616
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951211617 {
951311618 displayAntiAliased(gl);
951411619 } else
951511620 {
951611621 programcount = 0;
9517
- int keepmode = drawMode;
11622
+ int keepmode = DrawMode();
951811623 // if (DEBUG_SELECTION)
951911624 // {
9520
-// drawMode = SELECTION;
11625
+// DrawMode() = SELECTION;
952111626 // }
952211627 // for point selection
952311628 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9527,10 +11632,10 @@
952711632 DrawObject(gl);
952811633
952911634 // jan 2013 System.err.println("RESET ABORT (display)");
9530
- // if (drawMode == DEFAULT)
11635
+ // if (DrawMode() == DEFAULT)
953111636 // ABORTED = false;
953211637 fullreset = false;
9533
- drawMode = keepmode;
11638
+ Globals.drawMode = keepmode; // WARNING
953411639 //System.out.println("PROGRAM SWITCH " + programcount);
953511640 }
953611641 }
....@@ -9538,11 +11643,11 @@
953811643 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
953911644 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954011645
9541
- if (drawMode == DEFAULT)
11646
+ if (DrawMode() == DEFAULT)
954211647 {
954311648 ReleaseTexture(NOISE_TEXTURE, false);
954411649 }
9545
- //if (drawMode == DEFAULT)
11650
+ //if (DrawMode() == DEFAULT)
954611651 {
954711652
954811653 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9554,7 +11659,7 @@
955411659 //else
955511660 //gl.glDisable(gl.GL_TEXTURE_2D);
955611661 //gl.glPopMatrix();
9557
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11662
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
955811663 {
955911664 //new Exception().printStackTrace();
956011665 //System.out.println("Draw image " + width + ", " + height);
....@@ -9596,7 +11701,7 @@
959611701 //gl.glFlush();
959711702 }
959811703
9599
- if (flash && drawMode == DEFAULT)
11704
+ if (flash && DrawMode() == DEFAULT)
960011705 {
960111706 flash = false;
960211707 wait = true;
....@@ -9604,9 +11709,9 @@
960411709 }
960511710
960611711 //drawing = false;
9607
- //if(drawMode == DEFAULT)
11712
+ //if(DrawMode() == DEFAULT)
960811713 // niceon = false;
9609
- if (drawMode == DEFAULT)
11714
+ if (DrawMode() == DEFAULT)
961011715 {
961111716 currentlydrawing = false;
961211717 }
....@@ -9626,7 +11731,7 @@
962611731 repaint();
962711732 }
962811733
9629
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11734
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963011735 repaint();
963111736
963211737 displaydone = true;
....@@ -9645,8 +11750,14 @@
964511750 {
964611751 renderpass++;
964711752 // System.out.println("Draw object... ");
11753
+ STEP = 1;
964811754 if (FAST) // in case there is no script
9649
- STEP = 16;
11755
+ STEP = 8;
11756
+
11757
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11758
+ {
11759
+ STEP *= 4;
11760
+ }
965011761
965111762 //object.FullInvariants();
965211763
....@@ -9660,23 +11771,44 @@
966011771 e.printStackTrace();
966111772 }
966211773
9663
- if (GrafreeD.RENDERME > 0)
9664
- GrafreeD.RENDERME--; // mechante magouille
11774
+ if (Grafreed.RENDERME > 0)
11775
+ Grafreed.RENDERME--; // mechante magouille
966511776
9666
- ONESTEP = false;
11777
+ Globals.ONESTEP = false;
966711778 }
966811779
966911780 static boolean zoomonce = false;
967011781
11782
+ static void CreateSelectedPoint()
11783
+ {
11784
+ if (selectedpoint == null)
11785
+ {
11786
+ debugpointG = new Sphere();
11787
+ debugpointP = new Sphere();
11788
+ debugpointC = new Sphere();
11789
+ debugpointR = new Sphere();
11790
+
11791
+ selectedpoint = new Superellipsoid();
11792
+
11793
+ for (int i=0; i<8; i++)
11794
+ {
11795
+ debugpoints[i] = new Sphere();
11796
+ }
11797
+ }
11798
+ }
11799
+
967111800 void DrawObject(GL gl, boolean draw)
967211801 {
11802
+ // To clear camera values
11803
+ ResetOptions();
11804
+
967311805 //System.out.println("DRAW OBJECT " + mouseDown);
9674
-// drawMode = SELECTION;
11806
+// DrawMode() = SELECTION;
967511807 //GL gl = getGL();
967611808 if ((TRACK || SHADOWTRACK) || zoomonce)
967711809 {
9678
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9679
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11810
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11811
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968011812 pingthread.StepToTarget(true); // true);
968111813 // zoomonce = false;
968211814 }
....@@ -9696,9 +11828,9 @@
969611828 callist = gl.glGenLists(1);
969711829 }
969811830
9699
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11831
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970011832
9701
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11833
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970211834
970311835 if (!mainDL || !active || touched)
970411836 {
....@@ -9725,13 +11857,20 @@
972511857 PushMatrix(ClickInfo.matbuffer);
972611858 }
972711859
9728
- if (drawMode == 0)
11860
+ if (DrawMode() == 0)
972911861 {
973011862 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973111863
973211864 usedtextures.clear();
973311865
9734
- BindTextures(DEFAULT_TEXTURES, 2);
11866
+ try
11867
+ {
11868
+ BindTextures(DEFAULT_TEXTURES, 2);
11869
+ }
11870
+ catch (Exception e)
11871
+ {
11872
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11873
+ }
973511874 }
973611875 //System.out.println("--> " + stackdepth);
973711876 // GrafreeD.traceon();
....@@ -9739,10 +11878,11 @@
973911878 // DRAW
974011879 object.draw(this, /*(Composite)*/ object, false, false);
974111880
9742
- if (drawMode == DEFAULT)
11881
+ if (DrawMode() == DEFAULT)
974311882 {
9744
- if (DEBUG)
11883
+ if (Globals.DEBUG)
974511884 {
11885
+ CreateSelectedPoint();
974611886 float radius = 0.05f;
974711887 if (selectedpoint.radius != radius)
974811888 {
....@@ -9750,40 +11890,40 @@
975011890 selectedpoint.radius = radius;
975111891 selectedpoint.recalculate();
975211892 selectedpoint.material = new cMaterial();
9753
- selectedpoint.material.color = 0.25f;
11893
+ selectedpoint.material.color = 0.15f; // Yellow
975411894 selectedpoint.material.modulation = 0.75f;
975511895
9756
- debugpoint.radius = radius;
9757
- debugpoint.recalculate();
9758
- debugpoint.material = new cMaterial();
9759
- debugpoint.material.color = 0.25f;
9760
- debugpoint.material.modulation = 0.75f;
11896
+ debugpointG.radius = radius;
11897
+ debugpointG.recalculate();
11898
+ debugpointG.material = new cMaterial();
11899
+ debugpointG.material.color = 0.25f; // Green
11900
+ debugpointG.material.modulation = 0.75f;
976111901
9762
- debugpoint2.radius = radius;
9763
- debugpoint2.recalculate();
9764
- debugpoint2.material = new cMaterial();
9765
- debugpoint2.material.color = 0.75f;
9766
- debugpoint2.material.modulation = 0.75f;
11902
+ debugpointP.radius = radius;
11903
+ debugpointP.recalculate();
11904
+ debugpointP.material = new cMaterial();
11905
+ debugpointP.material.color = 0.75f; // Purple
11906
+ debugpointP.material.modulation = 0.75f;
976711907
9768
- debugpoint3.radius = radius;
9769
- debugpoint3.recalculate();
9770
- debugpoint3.material = new cMaterial();
9771
- debugpoint3.material.color = 0.5f;
9772
- debugpoint3.material.modulation = 0.75f;
11908
+ debugpointC.radius = radius;
11909
+ debugpointC.recalculate();
11910
+ debugpointC.material = new cMaterial();
11911
+ debugpointC.material.color = 0.5f; // Cyan
11912
+ debugpointC.material.modulation = 0.75f;
977311913
9774
- debugpoint4.radius = radius;
9775
- debugpoint4.recalculate();
9776
- debugpoint4.material = new cMaterial();
9777
- debugpoint4.material.color = 0f;
9778
- debugpoint4.material.modulation = 0.75f;
11914
+ debugpointR.radius = radius;
11915
+ debugpointR.recalculate();
11916
+ debugpointR.material = new cMaterial();
11917
+ debugpointR.material.color = 0f; // Red
11918
+ debugpointR.material.modulation = 0.75f;
977911919
978011920 InitPoints(radius);
978111921 }
978211922 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9783
- debugpoint.draw(this, /*(Composite)*/ null, false,false);
9784
- debugpoint2.draw(this, /*(Composite)*/ null, false,false);
9785
- debugpoint3.draw(this, /*(Composite)*/ null, false,false);
9786
- debugpoint4.draw(this, /*(Composite)*/ null, false,false);
11923
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11924
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11925
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11926
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
978711927 // DrawPoints(this);
978811928 }
978911929
....@@ -9791,42 +11931,63 @@
979111931 }
979211932 // GrafreeD.traceoff();
979311933 //System.out.println(stackdepth);
9794
- if (drawMode == 0)
11934
+ if (DrawMode() == 0)
979511935 {
979611936 ReleaseTextures(DEFAULT_TEXTURES);
979711937
979811938 if (CLEANCACHE)
9799
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11939
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
980011940 {
9801
- String tex = e.nextElement();
11941
+ cTexture tex = e.nextElement();
980211942
980311943 // System.out.println("Texture --------- " + tex);
980411944
9805
- if (tex.equals("WHITE_NOISE"))
11945
+ if (tex.equals("WHITE_NOISE:"))
980611946 continue;
980711947
9808
- if (!usedtextures.containsKey(tex))
11948
+ if (!usedtextures.contains(tex))
980911949 {
11950
+ CacheTexture gettex = texturepigment.get(tex);
981011951 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9811
- textures.get(tex).texture.dispose();
9812
- textures.remove(tex);
11952
+ if (gettex != null)
11953
+ {
11954
+ gettex.texture.dispose();
11955
+ texturepigment.remove(tex);
11956
+ }
11957
+
11958
+ gettex = texturebump.get(tex);
11959
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11960
+ if (gettex != null)
11961
+ {
11962
+ gettex.texture.dispose();
11963
+ texturebump.remove(tex);
11964
+ }
981311965 }
981411966 }
981511967 }
981611968
981711969 checker = null;
981811970
9819
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11971
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
982011972 FindChecker(object);
982111973
9822
- if (checker != null && drawMode == DEFAULT)
11974
+ if (checker != null && DrawMode() == DEFAULT)
982311975 {
9824
- // BindTexture(IMMORTAL_TEXTURE);
11976
+ //BindTexture(IMMORTAL_TEXTURE);
11977
+ try
11978
+ {
11979
+ BindTextures(checker.GetTextures(), checker.texres);
11980
+ }
11981
+ catch (Exception e)
11982
+ {
11983
+ System.err.println("FAILED: " + checker.GetTextures());
11984
+ }
982511985 // NEAREST
982611986 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
982711987 DrawChecker(gl);
982811988 //checker.Draw(this, null, false);
982911989 // ReleaseTexture(IMMORTAL_TEXTURE);
11990
+ ReleaseTextures(checker.GetTextures());
983011991 }
983111992
983211993 if (object.parent != null)
....@@ -9839,7 +12000,7 @@
983912000 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
984012001 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
984112002
9842
- if (DISPLAYTEXT && drawMode == DEFAULT)
12003
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
984312004 {
984412005 // Draw it once, then use the raster
984512006 Balloon(gl, balloon.createGraphics());
....@@ -9895,14 +12056,14 @@
989512056 int[] xs = new int[3];
989612057 int[] ys = new int[3];
989712058
9898
- void DrawString(Object3D obj) // String string)
12059
+ public void DrawString(Object3D obj) // String string) // INTERFACE
989912060 {
9900
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12061
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
990112062 {
990212063 return;
990312064 }
990412065
9905
- String string = obj.GetToolTip();
12066
+ String string = obj.toString(); //.GetToolTip();
990612067
990712068 GL gl = GetGL();
990812069
....@@ -10219,8 +12380,8 @@
1021912380 //obj.TransformToWorld(light, light);
1022012381 for (int i = tp.size(); --i >= 0;)
1022112382 {
10222
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10223
- LA.xformPos(light, tp.get(i).toParent, light);
12383
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12384
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1022412385 }
1022512386
1022612387
....@@ -10237,8 +12398,8 @@
1023712398 parentcam = cameras[0];
1023812399 }
1023912400
10240
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10241
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12401
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12402
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1024212403
1024312404 LA.xformPos(light, renderCamera.toScreen, light);
1024412405
....@@ -10328,8 +12489,76 @@
1032812489
1032912490 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1033012491
10331
- String program =
12492
+ String programmin =
12493
+ // Min shader
1033212494 "!!ARBfp1.0\n" +
12495
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12496
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12497
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12498
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12499
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12500
+ "PARAM light2cam0 = program.env[10];" +
12501
+ "PARAM light2cam1 = program.env[11];" +
12502
+ "PARAM light2cam2 = program.env[12];" +
12503
+ "TEMP temp;" +
12504
+ "TEMP light;" +
12505
+ "TEMP ndotl;" +
12506
+ "TEMP normal;" +
12507
+ "TEMP depth;" +
12508
+ "TEMP eye;" +
12509
+ "TEMP pos;" +
12510
+
12511
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12512
+ Normalize("normal") +
12513
+ "MOV light, state.light[0].position;" +
12514
+ "DP3 ndotl.x, light, normal;" +
12515
+
12516
+ // shadow
12517
+ "MOV pos, fragment.texcoord[1];" +
12518
+ "MOV temp, pos;" +
12519
+ ShadowTextureFetch("depth", "temp", "1") +
12520
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12521
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12522
+
12523
+ // No shadow when out of frustum
12524
+ //"SGE temp.y, depth.z, zero123.y;" +
12525
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12526
+
12527
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12528
+
12529
+ // Backlit
12530
+ "MOV pos.w, zero123.y;" +
12531
+ "DP4 eye.x, pos, light2cam0;" +
12532
+ "DP4 eye.y, pos, light2cam1;" +
12533
+ "DP4 eye.z, pos, light2cam2;" +
12534
+ Normalize("eye") +
12535
+
12536
+ "DP3 ndotl.y, -eye, normal;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12538
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12539
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12540
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12541
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12542
+
12543
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12544
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12545
+
12546
+ // Pigment
12547
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12548
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12549
+ "MUL temp, temp, ndotl.x;" +
12550
+
12551
+ "MUL temp, temp, zero123.z;" +
12552
+
12553
+ //"MUL temp, temp, ndotl.y;" +
12554
+
12555
+ "MOV temp.w, zero123.y;" + // reset alpha
12556
+ "MOV result.color, temp;" +
12557
+ "END";
12558
+
12559
+ String programmax =
12560
+ "!!ARBfp1.0\n" +
12561
+
1033312562 //"OPTION ARB_fragment_program_shadow;" +
1033412563 "PARAM light2cam0 = program.env[10];" +
1033512564 "PARAM light2cam1 = program.env[11];" +
....@@ -10357,11 +12586,13 @@
1035712586 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
1035812587 "PARAM params7 = program.env[7];" + // noise power, opacity power
1035912588 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10360
- "PARAM options1 = program.env[62];" + // fog rgb color, image intensity
12589
+ "PARAM options1 = program.env[62];" + // fog rgb color
12590
+ "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
1036112591 "PARAM pointlight = program.env[127];" + // ...
1036212592 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1036312593 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1036412594 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12595
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1036512596 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1036612597 "PARAM ten = { 10, 10, 10, 1.0 };" +
1036712598 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10382,6 +12613,7 @@
1038212613 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1038312614 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1038412615 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12616
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1038512617 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1038612618 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1038712619 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10422,6 +12654,10 @@
1042212654 "TEMP R1;" +
1042312655 "TEMP R2;" +
1042412656 "TEMP R3;" +
12657
+ "TEMP min;" +
12658
+ "TEMP max;" +
12659
+ "TEMP average;" +
12660
+ "TEMP saturation;" +
1042512661 "TEMP keep1;" +
1042612662 "TEMP keep2;" +
1042712663 "TEMP keep3;" +
....@@ -10437,8 +12673,7 @@
1043712673 "TEMP shininess;" +
1043812674 "\n" +
1043912675 "MOV texSamp, one;" +
10440
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10441
-
12676
+
1044212677 "MOV mapgrid.x, one2048th.x;" +
1044312678 "MOV temp, fragment.texcoord[1];" +
1044412679 /*
....@@ -10459,20 +12694,20 @@
1045912694 "MUL temp, floor, mapgrid.x;" +
1046012695 //"TEX depth0, temp, texture[1], 2D;" +
1046112696 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10462
- TextureFetch("depth0", "temp", "1") +
12697
+ ShadowTextureFetch("depth0", "temp", "1") +
1046312698 "") +
1046412699 "ADD temp.x, temp.x, mapgrid.x;" +
1046512700 //"TEX depth1, temp, texture[1], 2D;" +
1046612701 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10467
- TextureFetch("depth1", "temp", "1") +
12702
+ ShadowTextureFetch("depth1", "temp", "1") +
1046812703 "") +
1046912704 "ADD temp.y, temp.y, mapgrid.x;" +
1047012705 //"TEX depth2, temp, texture[1], 2D;" +
10471
- TextureFetch("depth2", "temp", "1") +
12706
+ ShadowTextureFetch("depth2", "temp", "1") +
1047212707 "SUB temp.x, temp.x, mapgrid.x;" +
1047312708 //"TEX depth3, temp, texture[1], 2D;" +
1047412709 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10475
- TextureFetch("depth3", "temp", "1") +
12710
+ ShadowTextureFetch("depth3", "temp", "1") +
1047612711 "") +
1047712712 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1047812713 //"MOV params, material;" +
....@@ -10843,10 +13078,10 @@
1084313078 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1084413079 "") +
1084513080
10846
- // display shadow only (bump == 0)
13081
+ // display shadow only (fakedepth == 0)
1084713082 "SUB temp.x, half.x, shadow.x;" +
10848
- "MOV temp.y, -params6.x;" +
10849
- "SLT temp.z, temp.y, zero.x;" +
13083
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13084
+ "SLT temp.z, temp.y, -c256i.x;" +
1085013085 "SUB temp.y, one.x, temp.z;" +
1085113086 "MUL temp.x, temp.x, temp.y;" +
1085213087 "KIL temp.x;" +
....@@ -10952,10 +13187,42 @@
1095213187
1095313188 // skin?
1095413189 // Saturation for skin
10955
- /**/ // c'est ici
10956
- (Skinshader? "DP3 temp.x, final,one;" +
13190
+ /**/
13191
+ (Skinshader?
13192
+ "DP3 average.x, final,one;" +
13193
+ "MUL average, one3rd.xxxx,average.xxxx;" +
13194
+
13195
+ "MIN min.x, final.x,final.y;" +
13196
+ "MIN min.x, min.x,final.z;" +
13197
+
13198
+ "MAX max.x, final.x,final.y;" +
13199
+ "MAX max.x, max.x,final.z;" +
13200
+ "MOV max, max.xxxx;" +
13201
+
13202
+ "SUB saturation, max, final;" +
13203
+
13204
+ "ADD temp.x, max.x, one10th.x;" +
13205
+ "RCP temp.x, temp.x;" +
13206
+ "MUL temp.x, temp.x, half.x;" +
13207
+ "MUL saturation, saturation, temp.xxxx;" +
13208
+
13209
+ "DP3 ndotl.x, normald, light;" +
13210
+ "MAX ndotl.x, ndotl.x, -ndotl.x;" +
13211
+
13212
+ "SUB temp.x, one.x, ndotl.x;" +
13213
+ // Tuning for default skin
13214
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13215
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13216
+ "ADD temp.y, one.y, options2.y;" + // subsurface
13217
+ "MUL temp.x, temp.x, temp.y;" +
13218
+
13219
+ "MUL saturation, saturation, temp.xxxx;" +
13220
+ "SUB_SAT temp, max, saturation;" +
13221
+/**
13222
+ "DP3 temp.x, final,one;" +
1095713223 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10958
- "SUB temp, final,R2;" +
13224
+ "SUB temp, final, R2;" +
13225
+
1095913226 // using light angle
1096013227 "DP3 ndotl.x, normald,light;" +
1096113228 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10968,7 +13235,6 @@
1096813235 // using light intensity
1096913236 "MOV ndotl.z, R2.x;" +
1097013237 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10971
-
1097213238 // june 2014
1097313239 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1097413240 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10980,6 +13246,7 @@
1098013246 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1098113247
1098213248 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13249
+/**/
1098313250
1098413251 // "ADD final, R2,temp;" +
1098513252 "MOV final, temp;"
....@@ -11069,7 +13336,7 @@
1106913336 /**/
1107013337 // HDR
1107113338 "MOV temp.z, final.a;" +
11072
- "MUL final, final,options1.w;" +
13339
+ "MUL final, final,options2.x;" +
1107313340 "MOV final.a, temp.z;" +
1107413341 /**/
1107513342
....@@ -11145,8 +13412,19 @@
1114513412 //once = true;
1114613413 }
1114713414
11148
- System.out.print("Program #" + mode + "; length = " + program.length());
11149
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13415
+ String program = programmax;
13416
+
13417
+ if (Globals.MINSHADER)
13418
+ {
13419
+ program = programmin;
13420
+ }
13421
+
13422
+ if (Globals.DEBUG)
13423
+ {
13424
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13425
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13426
+ }
13427
+
1115013428 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1115113429
1115213430 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11193,7 +13471,8 @@
1119313471 "\n" +
1119413472 "END\n";
1119513473
11196
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13474
+ if (Globals.DEBUG)
13475
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1119713476 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1119813477
1119913478 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11238,30 +13517,32 @@
1123813517 return out;
1123913518 }
1124013519
11241
- String TextureFetch(String dest, String src, String unit)
13520
+ // Also does frustum culling
13521
+ String ShadowTextureFetch(String dest, String src, String unit)
1124213522 {
1124313523 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1124413524 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1124513525 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13526
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13527
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1124613528 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11247
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11248
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11249
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11250
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13529
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13530
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1125113531 //"SWZ buffer, temp, w,w,w,w;";
11252
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13532
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1125313533 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1125413534 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1125513535 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11256
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13536
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1125713537
11258
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11259
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13538
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13539
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1126013540 }
1126113541
1126213542 String Shadow(String depth, String shadow)
1126313543 {
1126413544 return "MAX temp.x, ndotl.x, one64th.x;" +
13545
+ "MIN temp.x, temp.x, ninetenth.x;" +
1126513546 /**/
1126613547 // Sine
1126713548 "MUL temp.y, temp.x, temp.x;" +
....@@ -11277,12 +13558,16 @@
1127713558
1127813559 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1127913560 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13561
+
13562
+ // Compare fragment depth in light space with shadowmap.
1128013563 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1128113564 "SGE temp.y, temp.x, zero.x;" +
11282
- "SUB " + shadow + ".y, one.x, temp.y;" +
13565
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13566
+
13567
+ // Reverse comparison
1128313568 "SUB temp.x, one.x, temp.x;" +
1128413569 "MUL " + shadow + ".x, temp.x, temp.y;" +
11285
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13570
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1128613571 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1128713572
1128813573 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11296,6 +13581,10 @@
1129613581 // No shadow for backface
1129713582 "DP3 temp.x, normal, lightd;" +
1129813583 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13584
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13585
+
13586
+ // No shadow when out of frustum
13587
+ "SGE temp.x, " + depth + ".z, one.z;" +
1129913588 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1130013589 "";
1130113590 }
....@@ -11442,7 +13731,8 @@
1144213731 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1144313732 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1144413733 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11445
- Object3D.cVector2[] vector2buffer;
13734
+
13735
+ //Object3D.cVector2[] vector2buffer;
1144613736
1144713737 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1144813738 // OUT : diff, spec
....@@ -11458,9 +13748,10 @@
1145813748 "DP3 " + dest + ".z," + "normals," + "eye;" +
1145913749 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1146013750 //"MOV " + dest + ".w," + "normal.z;" +
11461
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11462
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11463
- //"MOV " + dest + ".z," + "params2.w;" +
13751
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13752
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13753
+
13754
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1146413755 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1146513756 "RCP " + dest + ".w," + dest + ".w;" +
1146613757 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11854,7 +14145,7 @@
1185414145 public void mousePressed(MouseEvent e)
1185514146 {
1185614147 //System.out.println("mousePressed: " + e);
11857
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14148
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1185814149 }
1185914150
1186014151 static long prevtime = 0;
....@@ -11881,14 +14172,16 @@
1188114172
1188214173 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1188314174
14175
+ if (BUTTONLESSWHEEL)
1188414176 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1188514177 {
1188614178 return;
1188714179 }
1188814180
14181
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1188914182
1189014183 // TIMER
11891
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14184
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1189214185 {
1189314186 keepboxmode = BOXMODE;
1189414187 keepsupport = SUPPORT;
....@@ -11928,8 +14221,8 @@
1192814221 // mode |= META;
1192914222 //}
1193014223
11931
- SetMouseMode(WHEEL | e.getModifiersEx());
11932
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14224
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14225
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1193314226 anchorX = ax;
1193414227 anchorY = ay;
1193514228 prevX = px;
....@@ -11963,6 +14256,7 @@
1196314256 else
1196414257 if (evt.getSource() == AAtimer)
1196514258 {
14259
+ Globals.TIMERRUNNING = false;
1196614260 if (mouseDown)
1196714261 {
1196814262 //new Exception().printStackTrace();
....@@ -11988,6 +14282,10 @@
1198814282 // LIVE = waslive;
1198914283 // wasliveok = true;
1199014284 // waslive = false;
14285
+
14286
+ // May 2019 Forget it:
14287
+ if (true)
14288
+ return;
1199114289
1199214290 // source == timer
1199314291 if (mouseDown)
....@@ -12017,8 +14315,8 @@
1201714315 // ObjEditor.tweenManager.update(1f / 60f);
1201814316
1201914317 // fev 2014???
12020
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12021
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14318
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14319
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1202214320 pingthread.StepToTarget(true); // true);
1202314321 }
1202414322 // if (!LIVE)
....@@ -12027,12 +14325,13 @@
1202714325
1202814326 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1202914327
12030
- void clickStart(int x, int y, int modifiers)
14328
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1203114329 {
1203214330 if (!wasliveok)
1203314331 return;
1203414332
1203514333 AAtimer.restart(); //
14334
+ Globals.TIMERRUNNING = true;
1203614335
1203714336 // waslive = LIVE;
1203814337 // LIVE = false;
....@@ -12044,7 +14343,7 @@
1204414343 // touched = true; // main DL
1204514344 if (isRenderer)
1204614345 {
12047
- SetMouseMode(modifiers);
14346
+ SetMouseMode(modifiers, modifiersex);
1204814347 }
1204914348
1205014349 selectX = anchorX = x;
....@@ -12057,7 +14356,7 @@
1205714356 clicked = true;
1205814357 hold = false;
1205914358
12060
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14359
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1206114360 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1206214361 {
1206314362 // System.out.println("RESTART II " + modifiers);
....@@ -12082,14 +14381,15 @@
1208214381 drag = false;
1208314382 //System.out.println("Mouse DOWN");
1208414383 editObj = false;
12085
- ClickInfo info = new ClickInfo();
12086
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12087
- info.pane = this;
12088
- info.camera = renderCamera;
12089
- info.x = x;
12090
- info.y = y;
12091
- info.modifiers = modifiers;
12092
- editObj = object.doEditClick(info, 0);
14384
+ //ClickInfo info = new ClickInfo();
14385
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14386
+ object.clickInfo.pane = this;
14387
+ object.clickInfo.camera = renderCamera;
14388
+ object.clickInfo.x = x;
14389
+ object.clickInfo.y = y;
14390
+ object.clickInfo.modifiers = modifiersex;
14391
+ editObj = object.doEditClick(//info,
14392
+ 0);
1209314393 if (!editObj)
1209414394 {
1209514395 hasMarquee = true;
....@@ -12105,11 +14405,14 @@
1210514405
1210614406 public void mouseDragged(MouseEvent e)
1210714407 {
14408
+ Globals.MOUSEDRAGGED = true;
14409
+
14410
+ //System.out.println("mouseDragged: " + e);
1210814411 if (isRenderer)
1210914412 movingcamera = true;
14413
+
1211014414 //if (drawing)
1211114415 //return;
12112
- //System.out.println("mouseDragged: " + e);
1211314416 if ((e.getModifiersEx() & CTRL) != 0
1211414417 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1211514418 {
....@@ -12117,7 +14420,7 @@
1211714420 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1211814421 }
1211914422 else
12120
- drag(e.getX(), e.getY(), e.getModifiersEx());
14423
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1212114424
1212214425 //try { Thread.sleep(1); } catch (Exception ex) {}
1212314426 }
....@@ -12129,6 +14432,11 @@
1212914432 cVector tmp = new cVector();
1213014433 cVector tmp2 = new cVector();
1213114434 boolean isMoving;
14435
+
14436
+ public cVector TargetLookAt()
14437
+ {
14438
+ return targetLookAt;
14439
+ }
1213214440
1213314441 class PingThread extends Thread
1213414442 {
....@@ -12268,7 +14576,7 @@
1226814576 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1226914577 if (lightMode)
1227014578 {
12271
- lighttouched = true;
14579
+ Globals.lighttouched = true;
1227214580 }
1227314581
1227414582 if (OEILONCE && OEIL)
....@@ -12285,6 +14593,7 @@
1228514593
1228614594 public void run()
1228714595 {
14596
+ new Exception().printStackTrace();
1228814597 System.exit(0);
1228914598 for (;;)
1229014599 {
....@@ -12326,7 +14635,7 @@
1232614635 mouseDown = false;
1232714636 if (lightMode)
1232814637 {
12329
- lighttouched = true;
14638
+ Globals.lighttouched = true;
1233014639 }
1233114640 repaint();
1233214641 alreadypainted = true;
....@@ -12334,7 +14643,7 @@
1233414643 isMoving = false;
1233514644 } //??
1233614645
12337
- if (isLIVE() && !alreadypainted)
14646
+ if (Globals.isLIVE() && !alreadypainted)
1233814647 {
1233914648 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1234014649 repaint();
....@@ -12346,9 +14655,9 @@
1234614655 {
1234714656 if (lightMode)
1234814657 {
12349
- lighttouched = true;
14658
+ Globals.lighttouched = true;
1235014659 }
12351
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14660
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1235214661 }
1235314662 //else
1235414663 }
....@@ -12362,12 +14671,18 @@
1236214671 void GoDown(int mod)
1236314672 {
1236414673 MODIFIERS |= COMMAND;
12365
- /*
14674
+ boolean isVR = (mouseMode&VR)!=0;
14675
+ /**/
1236614676 if((mod&SHIFT) == SHIFT)
12367
- manipCamera.RotatePosition(0, -speed);
14677
+ {
14678
+ if (isVR)
14679
+ manipCamera.RotateInterest(0, -speed);
14680
+ else
14681
+ manipCamera.RotatePosition(0, -speed);
14682
+ }
1236814683 else
12369
- manipCamera.BackForth(0, -speed*delta, getWidth());
12370
- */
14684
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14685
+ /**/
1237114686 if ((mod & SHIFT) == SHIFT)
1237214687 {
1237314688 mouseMode = mouseMode; // VR??
....@@ -12376,6 +14691,8 @@
1237614691 mouseMode |= BACKFORTH;
1237714692 }
1237814693
14694
+ targetLookAt.set(manipCamera.lookAt);
14695
+
1237914696 //prevX = X = anchorX;
1238014697 prevY = Y = anchorY - (int) (renderCamera.Distance());
1238114698 }
....@@ -12383,12 +14700,19 @@
1238314700 void GoUp(int mod)
1238414701 {
1238514702 MODIFIERS |= COMMAND;
12386
- /*
14703
+ /**/
14704
+ boolean isVR = (mouseMode&VR)!=0;
14705
+
1238714706 if((mod&SHIFT) == SHIFT)
12388
- manipCamera.RotatePosition(0, speed);
14707
+ {
14708
+ if (isVR)
14709
+ manipCamera.RotateInterest(0, speed);
14710
+ else
14711
+ manipCamera.RotatePosition(0, speed);
14712
+ }
1238914713 else
12390
- manipCamera.BackForth(0, speed*delta, getWidth());
12391
- */
14714
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14715
+ /**/
1239214716 if ((mod & SHIFT) == SHIFT)
1239314717 {
1239414718 mouseMode = mouseMode;
....@@ -12397,6 +14721,8 @@
1239714721 mouseMode |= BACKFORTH;
1239814722 }
1239914723
14724
+ targetLookAt.set(manipCamera.lookAt);
14725
+
1240014726 //prevX = X = anchorX;
1240114727 prevY = Y = anchorY + (int) (renderCamera.Distance());
1240214728 }
....@@ -12404,12 +14730,17 @@
1240414730 void GoLeft(int mod)
1240514731 {
1240614732 MODIFIERS |= COMMAND;
12407
- /*
14733
+ /**/
1240814734 if((mod&SHIFT) == SHIFT)
12409
- manipCamera.RotatePosition(speed, 0);
14735
+ manipCamera.Translate(speed*delta, 0, getWidth());
1241014736 else
12411
- manipCamera.Translate(speed*delta, 0, getWidth());
12412
- */
14737
+ {
14738
+ if ((mouseMode&VR)!=0)
14739
+ manipCamera.RotateInterest(-speed, 0);
14740
+ else
14741
+ manipCamera.RotatePosition(speed, 0);
14742
+ }
14743
+ /**/
1241314744 if ((mod & SHIFT) == SHIFT)
1241414745 {
1241514746 mouseMode = mouseMode;
....@@ -12418,6 +14749,8 @@
1241814749 mouseMode |= ROTATE;
1241914750 } // TRANSLATE;
1242014751
14752
+ targetLookAt.set(manipCamera.lookAt);
14753
+
1242114754 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1242214755 prevY = Y = anchorY;
1242314756 }
....@@ -12425,12 +14758,18 @@
1242514758 void GoRight(int mod)
1242614759 {
1242714760 MODIFIERS |= COMMAND;
12428
- /*
14761
+ /**/
1242914762 if((mod&SHIFT) == SHIFT)
12430
- manipCamera.RotatePosition(-speed, 0);
14763
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1243114764 else
12432
- manipCamera.Translate(-speed*delta, 0, getWidth());
12433
- */
14765
+ {
14766
+ if ((mouseMode&VR)!=0)
14767
+ manipCamera.RotateInterest(speed, 0);
14768
+ else
14769
+ manipCamera.RotatePosition(-speed, 0);
14770
+ }
14771
+
14772
+ /**/
1243414773 if ((mod & SHIFT) == SHIFT)
1243514774 {
1243614775 mouseMode = mouseMode;
....@@ -12439,6 +14778,8 @@
1243914778 mouseMode |= ROTATE;
1244014779 } // TRANSLATE;
1244114780
14781
+ targetLookAt.set(manipCamera.lookAt);
14782
+
1244214783 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1244314784 prevY = Y = anchorY;
1244414785 }
....@@ -12448,7 +14789,7 @@
1244814789 int X, Y;
1244914790 boolean SX, SY;
1245014791
12451
- void drag(int x, int y, int modifiers)
14792
+ void drag(int x, int y, int modifiers, int modifiersex)
1245214793 {
1245314794 if (IsFrozen())
1245414795 {
....@@ -12457,17 +14798,17 @@
1245714798
1245814799 drag = true; // NEW
1245914800
12460
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14801
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1246114802
1246214803 X = x;
1246314804 Y = y;
1246414805 // floating state for animation
12465
- MODIFIERS = modifiers;
12466
- modifiers &= ~1024;
14806
+ MODIFIERS = modifiersex;
14807
+ modifiersex &= ~1024;
1246714808 if (false) // modifiers != 0)
1246814809 {
1246914810 //new Exception().printStackTrace();
12470
- System.out.println("mouseDragged: " + modifiers);
14811
+ System.out.println("mouseDragged: " + modifiersex);
1247114812 System.out.println("SHIFT = " + SHIFT);
1247214813 System.out.println("CONTROL = " + COMMAND);
1247314814 System.out.println("META = " + META);
....@@ -12480,14 +14821,16 @@
1248014821 if (editObj)
1248114822 {
1248214823 drag = true;
12483
- ClickInfo info = new ClickInfo();
12484
- info.bounds.setBounds(0, 0,
14824
+ //ClickInfo info = new ClickInfo();
14825
+ object.clickInfo.bounds.setBounds(0, 0,
1248514826 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12486
- info.pane = this;
12487
- info.camera = renderCamera;
12488
- info.x = x;
12489
- info.y = y;
12490
- object.editWindow.copy.doEditDrag(info);
14827
+ object.clickInfo.pane = this;
14828
+ object.clickInfo.camera = renderCamera;
14829
+ object.clickInfo.x = x;
14830
+ object.clickInfo.y = y;
14831
+ object //.GetWindow().copy
14832
+ .doEditDrag(//info,
14833
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1249114834 } else
1249214835 {
1249314836 if (x < startX)
....@@ -12589,6 +14932,7 @@
1258914932 {
1259014933 manipCamera.Translate(dx, dy, getWidth());
1259114934 }
14935
+ else
1259214936 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1259314937 {
1259414938 manipCamera.RotateInterest(dx, dy);
....@@ -12599,7 +14943,7 @@
1259914943
1260014944 if (manipCamera == lightCamera)
1260114945 {
12602
- lighttouched = true;
14946
+ Globals.lighttouched = true;
1260314947 }
1260414948 /*
1260514949 switch (mode)
....@@ -12635,23 +14979,27 @@
1263514979 }
1263614980 }
1263714981
14982
+// ClickInfo clickInfo = new ClickInfo();
14983
+
1263814984 public void mouseMoved(MouseEvent e)
1263914985 {
1264014986 //System.out.println("mouseMoved: " + e);
12641
-
1264214987 if (isRenderer)
1264314988 return;
1264414989
12645
- ClickInfo ci = new ClickInfo();
12646
- ci.x = e.getX();
12647
- ci.y = e.getY();
12648
- ci.modifiers = e.getModifiersEx();
12649
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12650
- ci.pane = this;
12651
- ci.camera = renderCamera;
14990
+ // Mouse cursor feedback
14991
+ object.clickInfo.x = e.getX();
14992
+ object.clickInfo.y = e.getY();
14993
+ object.clickInfo.modifiers = e.getModifiersEx();
14994
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14995
+ object.clickInfo.pane = this;
14996
+ object.clickInfo.camera = renderCamera;
1265214997 if (!isRenderer)
1265314998 {
12654
- if (object.editWindow.copy.doEditClick(ci, 0))
14999
+ //ObjEditor editWindow = object.editWindow;
15000
+ //Object3D copy = editWindow.copy;
15001
+ if (object.doEditClick(//clickInfo,
15002
+ 0))
1265515003 {
1265615004 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1265715005 } else
....@@ -12663,7 +15011,11 @@
1266315011
1266415012 public void mouseReleased(MouseEvent e)
1266515013 {
15014
+ Globals.MOUSEDRAGGED = false;
15015
+
1266615016 movingcamera = false;
15017
+ X = 0; // getBounds().width/2;
15018
+ Y = 0; // getBounds().height/2;
1266715019 //System.out.println("mouseReleased: " + e);
1266815020 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1266915021 }
....@@ -12686,9 +15038,9 @@
1268615038 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1268715039 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1268815040
12689
- if (control || command || IsFrozen())
15041
+// No delay if (control || command || IsFrozen())
1269015042 timeout = true;
12691
- else
15043
+// ?? May 2019 else
1269215044 // timer.setDelay((modifiers & 128) != 0?0:350);
1269315045 mouseDown = false;
1269415046 if (!control && !command) // june 2013
....@@ -12798,7 +15150,7 @@
1279815150 System.out.println("keyReleased: " + e);
1279915151 }
1280015152
12801
- void SetMouseMode(int modifiers)
15153
+ void SetMouseMode(int modifiers, int modifiersex)
1280215154 {
1280315155 //System.out.println("SetMouseMode = " + modifiers);
1280415156 //modifiers &= ~1024;
....@@ -12810,24 +15162,27 @@
1281015162 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1281115163 // return;
1281215164 //System.out.println("SetMode = " + modifiers);
12813
- if ((modifiers & WHEEL) == WHEEL)
15165
+ if ((modifiersex & WHEEL) == WHEEL)
1281415166 {
1281515167 mouseMode |= ZOOM;
1281615168 }
12817
- if ((modifiers & META) == META)
15169
+
15170
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15171
+ if (capsLocked) // || (modifiers & META) == META)
1281815172 {
1281915173 mouseMode |= VR; // BACKFORTH;
1282015174 }
12821
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12822
- {
12823
- mouseMode |= SELECT; // BACKFORTH;
12824
- }
12825
- if ((modifiers & COMMAND) == COMMAND)
15175
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1282615176 {
1282715177 mouseMode |= SELECT;
1282815178 }
12829
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15179
+ if ((modifiersex & COMMAND) == COMMAND)
1283015180 {
15181
+ mouseMode |= SELECT;
15182
+ }
15183
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15184
+ {
15185
+ mouseMode &= ~VR;
1283115186 mouseMode |= TRANSLATE;
1283215187 }
1283315188 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12854,10 +15209,10 @@
1285415209
1285515210 if (isRenderer) //
1285615211 {
12857
- SetMouseMode(modifiers);
15212
+ SetMouseMode(0, modifiers);
1285815213 }
1285915214
12860
- theRenderer.keyPressed(key);
15215
+ Globals.theRenderer.keyPressed(key);
1286115216 }
1286215217
1286315218 int kompactbit = 4; // power bit
....@@ -12869,7 +15224,7 @@
1286915224 float SATPOW = 1; // 2; // 0.5f;
1287015225 float BRIPOW = 1; // 0.5f; // 0.5f;
1287115226
12872
- void keyPressed(int key)
15227
+ public void keyPressed(int key)
1287315228 {
1287415229 if (key >= '0' && key <= '5')
1287515230 clampbit = (key-'0');
....@@ -12916,7 +15271,8 @@
1291615271 // break;
1291715272 case 'T':
1291815273 CACHETEXTURE ^= true;
12919
- textures.clear();
15274
+ texturepigment.clear();
15275
+ texturebump.clear();
1292015276 // repaint();
1292115277 break;
1292215278 case 'Y':
....@@ -12984,7 +15340,7 @@
1298415340 case 'B':
1298515341 BRISMOOTH ^= true;
1298615342 SHADOWCULLFACE ^= true;
12987
- lighttouched = true;
15343
+ Globals.lighttouched = true;
1298815344 repaint();
1298915345 break;
1299015346 case 'b':
....@@ -13001,7 +15357,9 @@
1300115357 case 'E' : COMPACT ^= true;
1300215358 repaint();
1300315359 break;
13004
- case 'W' : DEBUGHSB ^= true;
15360
+ case 'W' : // Wide Window (fullscreen)
15361
+ //DEBUGHSB ^= true;
15362
+ ObjEditor.theFrame.ToggleFullScreen();
1300515363 repaint();
1300615364 break;
1300715365 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13026,8 +15384,8 @@
1302615384 RevertCamera();
1302715385 repaint();
1302815386 break;
13029
- case 'L':
1303015387 case 'l':
15388
+ //case 'L':
1303115389 if (lightMode)
1303215390 {
1303315391 lightMode = false;
....@@ -13084,27 +15442,31 @@
1308415442 repaint();
1308515443 break;
1308615444 case 'O':
13087
- drawMode = OCCLUSION;
15445
+ Globals.drawMode = OCCLUSION; // WARNING
1308815446 repaint();
1308915447 break;
1309015448 case 'o':
1309115449 OCCLUSION_CULLING ^= true;
1309215450 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1309315451 break;
13094
- case '0': envyoff ^= true; repaint(); break;
15452
+ //case '0': envyoff ^= true; repaint(); break;
1309515453 case '1':
1309615454 case '2':
1309715455 case '3':
1309815456 case '4':
1309915457 case '5':
13100
- newenvy = Character.getNumericValue(key);
13101
- repaint();
13102
- break;
1310315458 case '6':
1310415459 case '7':
1310515460 case '8':
1310615461 case '9':
13107
- BGcolor = (key - '6')/3.f;
15462
+ if (true) // envyoff)
15463
+ {
15464
+ BGcolor = (key - '1')/8.f;
15465
+ }
15466
+ else
15467
+ {
15468
+ //newenvy = Character.getNumericValue(key);
15469
+ }
1310815470 repaint();
1310915471 break;
1311015472 case '!':
....@@ -13170,12 +15532,12 @@
1317015532 case '_':
1317115533 kompactbit = 5;
1317215534 break;
13173
- case '+':
13174
- kompactbit = 6;
13175
- break;
15535
+// case '+':
15536
+// kompactbit = 6;
15537
+// break;
1317615538 case ' ':
1317715539 lightMode ^= true;
13178
- lighttouched = true;
15540
+ Globals.lighttouched = true;
1317915541 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1318015542 targetLookAt.set(manipCamera.lookAt);
1318115543 repaint();
....@@ -13184,14 +15546,15 @@
1318415546 case ESC:
1318515547 RENDERPROGRAM += 1;
1318615548 RENDERPROGRAM %= 3;
15549
+
1318715550 repaint();
1318815551 break;
1318915552 case 'Z':
13190
- RESIZETEXTURE ^= true;
13191
- break;
15553
+ //RESIZETEXTURE ^= true;
15554
+ //break;
1319215555 case 'z':
13193
- RENDERSHADOW ^= true;
13194
- lighttouched = true;
15556
+ Globals.RENDERSHADOW ^= true;
15557
+ Globals.lighttouched = true;
1319515558 repaint();
1319615559 break;
1319715560 //case UP:
....@@ -13217,13 +15580,15 @@
1321715580 FlipTransform();
1321815581 break;
1321915582 case ENTER:
13220
- object.editWindow.ScreenFit(); // Edit();
15583
+ // object.editWindow.ScreenFit(); // Edit();
15584
+ ToggleLive();
1322115585 break;
1322215586 case DELETE:
1322315587 ClearSelection();
1322415588 break;
13225
- /*
1322615589 case '+':
15590
+
15591
+ /*
1322715592 //fontsize += 1;
1322815593 bbzoom *= 2;
1322915594 repaint();
....@@ -13240,17 +15605,17 @@
1324015605 case '=':
1324115606 IncDepth();
1324215607 //fontsize += 1;
13243
- object.editWindow.refreshContents(true);
15608
+ object.GetWindow().refreshContents(true);
1324415609 maskbit = 6;
1324515610 break;
1324615611 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1324715612 DecDepth();
1324815613 maskbit = 5;
1324915614 //if(fontsize > 1) fontsize -= 1;
13250
- if (object.editWindow == null)
13251
- new Exception().printStackTrace();
13252
- else
13253
- object.editWindow.refreshContents(true);
15615
+// if (object.editWindow == null)
15616
+// new Exception().printStackTrace();
15617
+// else
15618
+ object.GetWindow().refreshContents(true);
1325415619 break;
1325515620 case '{':
1325615621 manipCamera.shaper_fovy /= 1.1;
....@@ -13305,6 +15670,7 @@
1330515670 }
1330615671 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1330715672 }
15673
+
1330815674 static double OCCLUSIONBOOST = 1; // 0.5;
1330915675
1331015676 void keyReleased(int key, int modifiers)
....@@ -13312,11 +15678,11 @@
1331215678 //mode = ROTATE;
1331315679 if ((MODIFIERS & COMMAND) == 0) // VR??
1331415680 {
13315
- SetMouseMode(modifiers);
15681
+ SetMouseMode(0, modifiers);
1331615682 }
1331715683 }
1331815684
13319
- protected void processKeyEvent(KeyEvent e)
15685
+ public void processKeyEvent(KeyEvent e)
1332015686 {
1332115687 switch (e.getID())
1332215688 {
....@@ -13446,8 +15812,9 @@
1344615812
1344715813 protected void processMouseMotionEvent(MouseEvent e)
1344815814 {
13449
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13450
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15815
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15816
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15817
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1345115818 {
1345215819 mouseMoved(e);
1345315820 } else
....@@ -13472,11 +15839,12 @@
1347215839 }
1347315840 */
1347415841
13475
- object.editWindow.EditSelection();
15842
+ object.GetWindow().EditSelection(false);
1347615843 }
1347715844
1347815845 void SelectParent()
1347915846 {
15847
+ new Exception().printStackTrace();
1348015848 System.exit(0);
1348115849 Composite group = (Composite) object;
1348215850 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13488,10 +15856,10 @@
1348815856 {
1348915857 //selectees.remove(i);
1349015858 System.out.println("select parent of " + elem);
13491
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15859
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1349215860 } else
1349315861 {
13494
- group.editWindow.Select(elem.GetTreePath(), first, true);
15862
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1349515863 }
1349615864
1349715865 first = false;
....@@ -13500,6 +15868,7 @@
1350015868
1350115869 void SelectChildren()
1350215870 {
15871
+ new Exception().printStackTrace();
1350315872 System.exit(0);
1350415873 /*
1350515874 Composite group = (Composite) object;
....@@ -13532,12 +15901,12 @@
1353215901 for (int j = 0; j < group.children.size(); j++)
1353315902 {
1353415903 elem = (Object3D) group.children.elementAt(j);
13535
- object.editWindow.Select(elem.GetTreePath(), first, true);
15904
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1353615905 first = false;
1353715906 }
1353815907 } else
1353915908 {
13540
- object.editWindow.Select(elem.GetTreePath(), first, true);
15909
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1354115910 }
1354215911
1354315912 first = false;
....@@ -13548,21 +15917,21 @@
1354815917 {
1354915918 //Composite group = (Composite) object;
1355015919 Object3D group = object;
13551
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15920
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1355215921 }
1355315922
1355415923 void ResetTransform(int mask)
1355515924 {
1355615925 //Composite group = (Composite) object;
1355715926 Object3D group = object;
13558
- group.editWindow.ResetTransform(mask);
15927
+ group.GetWindow().ResetTransform(mask);
1355915928 }
1356015929
1356115930 void FlipTransform()
1356215931 {
1356315932 //Composite group = (Composite) object;
1356415933 Object3D group = object;
13565
- group.editWindow.FlipTransform();
15934
+ group.GetWindow().FlipTransform();
1356615935 // group.editWindow.ReduceMesh(true);
1356715936 }
1356815937
....@@ -13570,7 +15939,7 @@
1357015939 {
1357115940 //Composite group = (Composite) object;
1357215941 Object3D group = object;
13573
- group.editWindow.PrintMemory();
15942
+ group.GetWindow().PrintMemory();
1357415943 // group.editWindow.ReduceMesh(true);
1357515944 }
1357615945
....@@ -13578,7 +15947,7 @@
1357815947 {
1357915948 //Composite group = (Composite) object;
1358015949 Object3D group = object;
13581
- group.editWindow.ResetCentroid();
15950
+ group.GetWindow().ResetCentroid();
1358215951 }
1358315952
1358415953 void IncDepth()
....@@ -13660,11 +16029,11 @@
1366016029
1366116030 int width = getBounds().width;
1366216031 int height = getBounds().height;
13663
- ClickInfo info = new ClickInfo();
13664
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1366516032 //Image img = CreateImage(width, height);
1366616033 //System.out.println("width = " + width + "; height = " + height + "\n");
16034
+
1366716035 Graphics gr = g; // img.getGraphics();
16036
+
1366816037 if (!hasMarquee)
1366916038 {
1367016039 if (Xmin < Xmax) // !locked)
....@@ -13736,44 +16105,92 @@
1373616105 }
1373716106 if (object != null && !hasMarquee)
1373816107 {
16108
+ if (object.clickInfo == null)
16109
+ object.clickInfo = new ClickInfo();
16110
+ ClickInfo info = object.clickInfo;
16111
+ //ClickInfo info = new ClickInfo();
16112
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16113
+
1373916114 if (isRenderer)
1374016115 {
13741
- info.flags++;
16116
+ object.clickInfo.flags++;
1374216117 double frameAspect = (double) width / (double) height;
1374316118 if (frameAspect > renderCamera.aspect)
1374416119 {
1374516120 int desired = (int) ((double) height * renderCamera.aspect);
13746
- info.bounds.width -= width - desired;
13747
- info.bounds.x += (width - desired) / 2;
16121
+ object.clickInfo.bounds.width -= width - desired;
16122
+ object.clickInfo.bounds.x += (width - desired) / 2;
1374816123 } else
1374916124 {
1375016125 int desired = (int) ((double) width / renderCamera.aspect);
13751
- info.bounds.height -= height - desired;
13752
- info.bounds.y += (height - desired) / 2;
16126
+ object.clickInfo.bounds.height -= height - desired;
16127
+ object.clickInfo.bounds.y += (height - desired) / 2;
1375316128 }
1375416129 }
13755
- info.g = gr;
13756
- info.camera = renderCamera;
16130
+
16131
+ object.clickInfo.g = gr;
16132
+ object.clickInfo.camera = renderCamera;
1375716133 /*
1375816134 // Memory intensive (brep.verticescopy)
1375916135 if (!(object instanceof Composite))
1376016136 object.draw(info, 0, false); // SLOW :
1376116137 */
13762
- if (!isRenderer)
16138
+ if (!isRenderer) // && drag)
1376316139 {
13764
- object.drawEditHandles(info, 0);
16140
+ Grafreed.Assert(object != null);
16141
+ Grafreed.Assert(object.selection != null);
16142
+ if (object.selection.Size() > 0)
16143
+ {
16144
+ int hitSomething = object.selection.get(0).hitSomething;
16145
+
16146
+ object.clickInfo.DX = 0;
16147
+ object.clickInfo.DY = 0;
16148
+ object.clickInfo.W = 1;
16149
+ if (hitSomething == Object3D.hitCenter)
16150
+ {
16151
+ info.DX = X;
16152
+ if (X != 0)
16153
+ info.DX -= info.bounds.width/2;
16154
+
16155
+ info.DY = Y;
16156
+ if (Y != 0)
16157
+ info.DY -= info.bounds.height/2;
16158
+ }
16159
+
16160
+ object.drawEditHandles(//info,
16161
+ 0);
16162
+
16163
+ if (drag && (X != 0 || Y != 0))
16164
+ {
16165
+ switch (hitSomething)
16166
+ {
16167
+ case Object3D.hitCenter: gr.setColor(Color.white);
16168
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16169
+ break;
16170
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16171
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16172
+ break;
16173
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16174
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16175
+ break;
16176
+ }
16177
+
16178
+ }
16179
+ }
1376516180 }
1376616181 }
16182
+
1376716183 if (isRenderer)
1376816184 {
1376916185 //gr.setColor(Color.black);
1377016186 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1377116187 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1377216188 }
16189
+
1377316190 if (hasMarquee)
1377416191 {
1377516192 gr.setXORMode(Color.white);
13776
- gr.setColor(Color.red);
16193
+ gr.setColor(Color.white);
1377716194 if (!firstime)
1377816195 {
1377916196 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -13792,6 +16209,7 @@
1379216209 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1379316210 }
1379416211
16212
+ // To avoid clear.
1379516213 public void update(Graphics g)
1379616214 {
1379716215 paint(g);
....@@ -13881,6 +16299,7 @@
1388116299 public boolean mouseDown(Event evt, int x, int y)
1388216300 {
1388316301 System.out.println("mouseDown: " + evt);
16302
+ System.exit(0);
1388416303 /*
1388516304 locked = true;
1388616305 drag = false;
....@@ -13924,7 +16343,7 @@
1392416343 {
1392516344 keyPressed(0, modifiers);
1392616345 }
13927
- clickStart(x, y, modifiers);
16346
+ // clickStart(x, y, modifiers);
1392816347 return true;
1392916348 }
1393016349
....@@ -14042,7 +16461,7 @@
1404216461 {
1404316462 keyReleased(0, 0);
1404416463 }
14045
- drag(x, y, modifiers);
16464
+ drag(x, y, 0, modifiers);
1404616465 return true;
1404716466 }
1404816467
....@@ -14174,7 +16593,7 @@
1417416593 Object3D object;
1417516594 static Object3D trackedobject;
1417616595 Camera renderCamera; // Light or Eye (or Occlusion)
14177
- /*static*/ Camera manipCamera; // Light or Eye
16596
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1417816597 /*static*/ Camera eyeCamera;
1417916598 /*static*/ Camera lightCamera;
1418016599 int cameracount;
....@@ -14238,6 +16657,8 @@
1423816657 private /*static*/ boolean firstime;
1423916658 private /*static*/ cVector newView = new cVector();
1424016659 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16660
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16661
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1424116662 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1424216663 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1424316664 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14250,29 +16671,67 @@
1425016671 {
1425116672 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1425216673
16674
+ int usedsuf = 0;
16675
+
1425316676 for (int i = 0; i < suffixes.length; i++)
1425416677 {
14255
- String resourceName = basename + suffixes[i] + "." + suffix;
14256
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14257
- mipmapped,
14258
- FileUtil.getFileSuffix(resourceName));
14259
- if (data == null)
16678
+ String[] suffixe = suffixes;
16679
+ String[] fallback = suffixes2;
16680
+ String[] fallfallback = suffixes3;
16681
+
16682
+ for (int c=usedsuf; --c>=0;)
1426016683 {
14261
- throw new IOException("Unable to load texture " + resourceName);
16684
+// String[] temp = suffixe;
16685
+// suffixe = fallback;
16686
+// fallback = fallfallback;
16687
+// fallfallback = temp;
1426216688 }
16689
+
16690
+ String resourceName = basename + suffixe[i] + "." + suffix;
16691
+ TextureData data;
16692
+
16693
+ try
16694
+ {
16695
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16696
+ mipmapped,
16697
+ FileUtil.getFileSuffix(resourceName));
16698
+ }
16699
+ catch (Exception e)
16700
+ {
16701
+ try
16702
+ {
16703
+ resourceName = basename + fallback[i] + "." + suffix;
16704
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16705
+ mipmapped,
16706
+ FileUtil.getFileSuffix(resourceName));
16707
+ }
16708
+ catch (Exception e2)
16709
+ {
16710
+ resourceName = basename + fallfallback[i] + "." + suffix;
16711
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16712
+ mipmapped,
16713
+ FileUtil.getFileSuffix(resourceName));
16714
+ }
16715
+ }
16716
+
1426316717 //System.out.println("Target = " + targets[i]);
1426416718 cubemap.updateImage(data, targets[i]);
1426516719 }
1426616720
1426716721 return cubemap;
1426816722 }
16723
+
1426916724 int bigsphere = -1;
1427016725
1427116726 float BGcolor = 0.5f;
1427216727
14273
- private void DrawSkyBox(GL gl)
16728
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16729
+
16730
+ private void DrawSkyBox(GL gl, float ratio)
1427416731 {
14275
- if (envyoff || cubemap == null)
16732
+ if (//envyoff ||
16733
+ WIREFRAME ||
16734
+ cubemap == null)
1427616735 {
1427716736 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1427816737 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14287,7 +16746,17 @@
1428716746 // Compensates for ExaminerViewer's modification of modelview matrix
1428816747 gl.glMatrixMode(GL.GL_MODELVIEW);
1428916748 gl.glLoadIdentity();
16749
+ gl.glScalef(1,ratio,1);
1429016750
16751
+// colorV[0] = 2;
16752
+// colorV[1] = 2;
16753
+// colorV[2] = 2;
16754
+// colorV[3] = 1;
16755
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16756
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16757
+//
16758
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16759
+
1429116760 //gl.glActiveTexture(GL.GL_TEXTURE1);
1429216761 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1429316762
....@@ -14319,6 +16788,7 @@
1431916788 {
1432016789 gl.glScalef(1.0f, -1.0f, 1.0f);
1432116790 }
16791
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1432216792 gl.glMultMatrixd(viewrot_1, 0);
1432316793 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1432416794 //viewer.updateInverseRotation(gl);
....@@ -14359,7 +16829,8 @@
1435916829 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1436016830
1436116831 cubemap.disable();
14362
- ////cubemap.unbind();
16832
+ //cubemap.dispose();
16833
+
1436316834 if (CULLFACE)
1436416835 {
1436516836 gl.glEnable(gl.GL_CULL_FACE);
....@@ -14394,7 +16865,7 @@
1439416865 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1439516866 gl.glPushMatrix();
1439616867 gl.glLoadIdentity();
14397
- PushMatrix(checker.toParent);
16868
+ //PushMatrix(checker.toParent);
1439816869
1439916870 gl.glMatrixMode(GL.GL_TEXTURE);
1440016871 gl.glPushMatrix();
....@@ -14417,8 +16888,8 @@
1441716888
1441816889 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1441916890
14420
- float step = 0.1666f; //0.25f;
14421
- float stepv = step * 1652 / 998;
16891
+ float step = 2; // 0.1666f; //0.25f;
16892
+ float stepv = 2; // step * 1652 / 998;
1442216893
1442316894 int i0 = 0;
1442416895 /*
....@@ -14454,20 +16925,21 @@
1445416925 /**/
1445516926 //checker.GetMaterial().opacity = 1.1f;
1445616927 ////checker.GetMaterial().ambient = 0.99f;
14457
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14458
- Object3D.selectedstack[Object3D.materialdepth] = false;
14459
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16928
+ materialstack[materialdepth] = checker.material;
16929
+ selectedstack[materialdepth] = false;
16930
+ cStatic.objectstack[materialdepth++] = checker;
1446016931 //System.out.println("material " + material);
1446116932 //Applet3D.tracein(this, selected);
14462
- vector2buffer = checker.projectedVertices;
16933
+ //vector2buffer = checker.projectedVertices;
1446316934
14464
- checker.GetMaterial().Draw(this, false); // true);
16935
+ //checker.GetMaterial().Draw(this, false); // true);
16936
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1446516937
14466
- Object3D.materialdepth -= 1;
14467
- if (Object3D.materialdepth > 0)
16938
+ materialdepth -= 1;
16939
+ if (materialdepth > 0)
1446816940 {
14469
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14470
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16941
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16942
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1447116943 }
1447216944 //checker.GetMaterial().opacity = 1f;
1447316945 ////checker.GetMaterial().ambient = 1f;
....@@ -14488,15 +16960,27 @@
1448816960
1448916961 //float u = (i+1)/2;
1449016962 //float v = (j+1)/2;
14491
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16963
+ if (checker.flipV)
16964
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16965
+ else
16966
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1449216967 gl.glVertex3f(i, j, -0.5f);
1449316968
16969
+ if (checker.flipV)
16970
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16971
+ else
1449416972 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1449516973 gl.glVertex3f(i + step, j, -0.5f);
1449616974
16975
+ if (checker.flipV)
16976
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16977
+ else
1449716978 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1449816979 gl.glVertex3f(i + step, j + stepv, -0.5f);
1449916980
16981
+ if (checker.flipV)
16982
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16983
+ else
1450016984 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1450116985 gl.glVertex3f(i, j + stepv, -0.5f);
1450216986 }
....@@ -14508,7 +16992,7 @@
1450816992 gl.glMatrixMode(GL.GL_PROJECTION);
1450916993 gl.glPopMatrix();
1451016994 gl.glMatrixMode(GL.GL_MODELVIEW);
14511
- PopMatrix(null); // checker.toParent); // null);
16995
+ //PopMatrix(null); // checker.toParent); // null);
1451216996 gl.glPopMatrix();
1451316997 PopTextureMatrix(checker.toParent);
1451416998 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14541,6 +17025,14 @@
1454117025 }
1454217026 }
1454317027
17028
+ private Object3D GetFolder()
17029
+ {
17030
+ Object3D folder = object.GetWindow().copy;
17031
+ if (object.GetWindow().copy.selection.Size() > 0)
17032
+ folder = object.GetWindow().copy.selection.elementAt(0);
17033
+ return folder;
17034
+ }
17035
+
1454417036 class SelectBuffer implements GLEventListener
1454517037 {
1454617038
....@@ -14556,7 +17048,7 @@
1455617048 //new Exception().printStackTrace();
1455717049 System.out.println("select buffer init");
1455817050 // Use debug pipeline
14559
- drawable.setGL(new DebugGL(drawable.getGL()));
17051
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1456017052
1456117053 GL gl = drawable.getGL();
1456217054
....@@ -14599,6 +17091,7 @@
1459917091 {
1460017092 if (!selection)
1460117093 {
17094
+ new Exception().printStackTrace();
1460217095 System.exit(0);
1460317096 return;
1460417097 }
....@@ -14619,17 +17112,39 @@
1461917112
1462017113 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1462117114
17115
+ if (PAINTMODE)
17116
+ {
17117
+ if (object.GetWindow().copy.selection.Size() > 0)
17118
+ {
17119
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17120
+
17121
+ // Make what you paint not selectable.
17122
+ paintobj.ResetSelectable();
17123
+ }
17124
+ }
17125
+
1462217126 //int tmp = selection_view;
1462317127 //selection_view = -1;
14624
- int temp = drawMode;
14625
- drawMode = SELECTION;
17128
+ int temp = DrawMode();
17129
+ Globals.drawMode = SELECTION; // WARNING
1462617130 indexcount = 0;
1462717131 parent.display(drawable);
1462817132 //selection_view = tmp;
1462917133 //if (temp == SELECTION)
1463017134 // temp = DEFAULT; // patch for selection debug
14631
- drawMode = temp;
17135
+ Globals.drawMode = temp; // WARNING
1463217136
17137
+ if (PAINTMODE)
17138
+ {
17139
+ if (object.GetWindow().copy.selection.Size() > 0)
17140
+ {
17141
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17142
+
17143
+ // Revert.
17144
+ paintobj.RestoreSelectable();
17145
+ }
17146
+ }
17147
+
1463317148 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1463417149
1463517150 // trying different ways of getting the depth info over
....@@ -14678,6 +17193,13 @@
1467817193 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1467917194 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1468017195
17196
+ CreateSelectedPoint();
17197
+
17198
+ // Will fit the mesh !!!
17199
+ selectedpoint.toParent[0][0] = 0.0001;
17200
+ selectedpoint.toParent[1][1] = 0.0001;
17201
+ selectedpoint.toParent[2][2] = 0.0001;
17202
+
1468117203 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1468217204
1468317205 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14721,34 +17243,36 @@
1472117243 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]));
1472217244 }
1472317245
14724
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17246
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1472517247 }
1472617248 }
1472717249
1472817250 if (!movingcamera && !PAINTMODE)
14729
- object.editWindow.ScreenFitPoint(); // fev 2014
17251
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1473017252
14731
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17253
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1473217254 {
14733
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17255
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1473417256
14735
- Object3D group = new Object3D("inst" + paintcount++);
17257
+ if (object.GetWindow().copy.selection.Size() > 0)
17258
+ {
17259
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1473617260
14737
- group.CreateMaterial(); // use a void leaf to select instances
14738
-
14739
- group.add(paintobj); // link
14740
-
14741
- object.editWindow.SnapObject(group);
14742
-
14743
- Object3D folder = object.editWindow.copy;
14744
-
14745
- if (object.editWindow.copy.selection.Size() > 0)
14746
- folder = object.editWindow.copy.selection.elementAt(0);
14747
-
14748
- folder.add(group);
14749
-
14750
- object.editWindow.ResetModel();
14751
- object.editWindow.refreshContents();
17261
+ Object3D inst = new Object3D("inst" + paintcount++);
17262
+
17263
+ inst.CreateMaterial(); // use a void leaf to select instances
17264
+
17265
+ inst.add(paintobj); // link
17266
+
17267
+ object.GetWindow().SnapObject(inst);
17268
+
17269
+ Object3D folder = paintFolder; // GetFolder();
17270
+
17271
+ folder.add(inst);
17272
+
17273
+ object.GetWindow().ResetModel();
17274
+ object.GetWindow().refreshContents();
17275
+ }
1475217276 }
1475317277 else
1475417278 paintcount = 0;
....@@ -14787,6 +17311,11 @@
1478717311 //System.out.println("objects[color] = " + objects[color]);
1478817312 //objects[color].Select();
1478917313 indexcount = 0;
17314
+ ObjEditor window = object.GetWindow();
17315
+ if (window != null && deselect)
17316
+ {
17317
+ window.Select(null, deselect, true);
17318
+ }
1479017319 object.Select(color, deselect);
1479117320 }
1479217321
....@@ -14837,6 +17366,7 @@
1483717366
1483817367 public void init(GLAutoDrawable drawable)
1483917368 {
17369
+ if (Globals.DEBUG)
1484017370 System.out.println("shadow buffer init");
1484117371
1484217372 GL gl = drawable.getGL();
....@@ -14886,7 +17416,7 @@
1488617416 gl.glDisable(gl.GL_CULL_FACE);
1488717417 }
1488817418
14889
- if (!RENDERSHADOW)
17419
+ if (!Globals.RENDERSHADOW)
1489017420 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1489117421
1489217422 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14896,14 +17426,14 @@
1489617426 //gl.glColorMask(false, false, false, false);
1489717427
1489817428 //render_scene_from_light_view(gl, drawable, 0, 0);
14899
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17429
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1490017430 {
1490117431 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1490217432
14903
- int temp = drawMode;
14904
- drawMode = SHADOW;
17433
+ int temp = DrawMode();
17434
+ Globals.drawMode = SHADOW; // WARNING
1490517435 parent.display(drawable);
14906
- drawMode = temp;
17436
+ Globals.drawMode = temp; // WARNING
1490717437 }
1490817438
1490917439 gl.glCullFace(gl.GL_BACK);
....@@ -14956,7 +17486,6 @@
1495617486
1495717487 class AntialiasBuffer implements GLEventListener
1495817488 {
14959
-
1496017489 CameraPane parent = null;
1496117490
1496217491 AntialiasBuffer(CameraPane p)
....@@ -15066,15 +17595,25 @@
1506617595 gl.glFlush();
1506717596
1506817597 /**/
15069
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17598
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1507017599
15071
- int[] pixels = occlusionsizebuffer.array();
17600
+ float[] depths = occlusiondepthbuffer.array();
1507217601
17602
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17603
+
17604
+ int[] pixels = selectsizebuffer.array();
17605
+
1507317606 double r = 0, g = 0, b = 0;
1507417607
1507517608 double count = 0;
17609
+
17610
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17611
+
17612
+ float mindepth = 1;
17613
+
17614
+ double FACTOR = 1;
1507617615
15077
- for (int i = 0; i < pixels.length; i++)
17616
+ for (int i = 0; i < depths.length; i++)
1507817617 {
1507917618 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1508017619 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15157,7 +17696,7 @@
1515717696
1515817697 double scale = ray.z; // 1; // cos
1515917698
15160
- int p = pixels[newindex];
17699
+ float depth = depths[newindex];
1516117700
1516217701 /*
1516317702 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15181,10 +17720,23 @@
1518117720 scale = (1 - modu) * modv;
1518217721 */
1518317722
15184
- r += ((p >> 16) & 0xFF) * scale / 255;
15185
- g += ((p >> 8) & 0xFF) * scale / 255;
15186
- b += (p & 0xFF) * scale / 255;
17723
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17724
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17725
+ //b += (p & 0xFF) * scale / 255;
17726
+
17727
+ if (mindepth > depth)
17728
+ {
17729
+ mindepth = depth;
17730
+ }
1518717731
17732
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17733
+
17734
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17735
+
17736
+ r += factor * scale;
17737
+ g += factor * scale;
17738
+ b += factor * scale;
17739
+
1518817740 count += scale;
1518917741 }
1519017742
....@@ -15282,12 +17834,6 @@
1528217834 GLUT glut = new GLUT();
1528317835
1528417836
15285
- static final public int DEFAULT = 0;
15286
- static final public int SELECTION = 1;
15287
- static final public int SHADOW = 2;
15288
- static final public int OCCLUSION = 3;
15289
- static
15290
- public int drawMode = DEFAULT;
1529117837 public boolean spherical = false;
1529217838 static boolean DEBUG_OCCLUSION = false;
1529317839 static boolean DEBUG_SELECTION = false;
....@@ -15300,23 +17846,15 @@
1530017846 int AAbuffersize = 0;
1530117847
1530217848 //double[] selectedpoint = new double[3];
15303
- static Sphere selectedpoint = new Sphere();
17849
+ static Superellipsoid selectedpoint;
1530417850 static Sphere previousselectedpoint = null;
15305
- static Sphere debugpoint = new Sphere();
15306
- static Sphere debugpoint2 = new Sphere();
15307
- static Sphere debugpoint3 = new Sphere();
15308
- static Sphere debugpoint4 = new Sphere();
17851
+ static Sphere debugpointG;
17852
+ static Sphere debugpointP;
17853
+ static Sphere debugpointC;
17854
+ static Sphere debugpointR;
1530917855
1531017856 static Sphere debugpoints[] = new Sphere[8];
1531117857
15312
- static
15313
- {
15314
- for (int i=0; i<8; i++)
15315
- {
15316
- debugpoints[i] = new Sphere();
15317
- }
15318
- }
15319
-
1532017858 static void InitPoints(float radius)
1532117859 {
1532217860 for (int i=0; i<8; i++)
....@@ -15336,7 +17874,7 @@
1533617874 }
1533717875 }
1533817876
15339
- static void DrawPoints(CameraPane cpane)
17877
+ static void DrawPoints(iCameraPane cpane)
1534017878 {
1534117879 for (int i=0; i<8; i++) // first and last are red
1534217880 {
....@@ -15355,10 +17893,14 @@
1535517893 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1535617894 static IntBuffer bigAAbuffer;
1535717895 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15358
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17896
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1535917897 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1536017898 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15361
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17899
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17900
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17901
+
17902
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17903
+
1536217904 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1536317905 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1536417906 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15367,10 +17909,11 @@
1536717909 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1536817910 // Depth buffer format
1536917911 //private int depth_format;
15370
- static public void NextIndex(Object3D o, GL gl)
17912
+
17913
+ public void NextIndex()
1537117914 {
1537217915 indexcount+=16;
15373
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17916
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1537417917 //objects[indexcount] = o;
1537517918 //System.out.println("indexcount = " + indexcount);
1537617919 }