Normand Briere
2019-08-22 6a145f6c81dfcbe0653eda27d042efb48daa7512
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
....@@ -144,7 +168,7 @@
144168
145169
146170 // OPTIONS
147
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
148172 boolean cameraLight = false;
149173 boolean UVdebug = false;
150174 boolean Udebug = false;
....@@ -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,26 @@
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;
174212 }
175213
176214 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -185,7 +223,8 @@
185223
186224 SetCamera(cam);
187225
188
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
189228
190229 object = o;
191230
....@@ -206,12 +245,53 @@
206245 return CURRENTANTIALIAS > 0;
207246 }
208247
209
- 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()
210290 {
211291 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
212292 }
213293
214
- void DepthTest(boolean depthtest)
294
+ public void DepthTest(boolean depthtest)
215295 {
216296 if (depthtest)
217297 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -219,7 +299,7 @@
219299 GetGL().glDepthFunc(GL.GL_ALWAYS);
220300 }
221301
222
- void DepthWrite(boolean depthwrite)
302
+ public void DepthWrite(boolean depthwrite)
223303 {
224304 if (depthwrite)
225305 GetGL().glDepthMask(true);
....@@ -227,12 +307,1617 @@
227307 GetGL().glDepthMask(false);
228308 }
229309
230
- void BackFaceCull(boolean bfc)
310
+ public void BackFaceCull(boolean bfc)
231311 {
232312 if (bfc)
233313 GetGL().glEnable(GetGL().GL_CULL_FACE);
234314 else
235315 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
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
547
+ }
548
+
549
+ // P
550
+ float x = (float)pv.x;
551
+ float y = (float)pv.y;
552
+ float z = (float)pv.z;
553
+
554
+ if (hasnorm)
555
+ {
556
+// if (!pv.norm.normalized())
557
+// assert(pv.norm.normalized());
558
+
559
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
560
+ float nx = (float)pv.norm.x;
561
+ float ny = (float)pv.norm.y;
562
+ float nz = (float)pv.norm.z;
563
+
564
+ x += nx * obj.NORMALPUSH;
565
+ y += ny * obj.NORMALPUSH;
566
+ z += nz * obj.NORMALPUSH;
567
+
568
+ SetGLNormal(gl, nx, ny, nz);
569
+ }
570
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
571
+ SetColor(obj, pv);
572
+ //gl.glColor4f(r, g, b, 1);
573
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
574
+ if (obj.flipV)
575
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
576
+ else
577
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
578
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
579
+
580
+ gl.glVertex3f(x, y, z);
581
+
582
+ // Q
583
+ x = (float)qv.x;
584
+ y = (float)qv.y;
585
+ z = (float)qv.z;
586
+
587
+// Print(pv);
588
+ if (hasnorm)
589
+ {
590
+// assert(qv.norm.normalized());
591
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
592
+ float nx = (float)qv.norm.x;
593
+ float ny = (float)qv.norm.y;
594
+ float nz = (float)qv.norm.z;
595
+
596
+ x += nx * obj.NORMALPUSH;
597
+ y += ny * obj.NORMALPUSH;
598
+ z += nz * obj.NORMALPUSH;
599
+
600
+ SetGLNormal(gl, nx, ny, nz);
601
+ }
602
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
603
+ // boolean locked = false;
604
+ // float eps = 0.1f;
605
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
606
+
607
+ // int dot = 0; //*/ (int)f.dot;
608
+
609
+ // if ((dot&1) == 0)
610
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
611
+
612
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
613
+ if (obj.flipV)
614
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
615
+ else
616
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
617
+ // else
618
+ // {
619
+ // locked = true;
620
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
621
+ // }
622
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
623
+ SetColor(obj, qv);
624
+
625
+ gl.glVertex3f(x, y, z);
626
+ //gl.glColor4f(r, g, b, 1);
627
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
628
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
629
+// Print(qv);
630
+
631
+ // R
632
+ x = (float)rv.x;
633
+ y = (float)rv.y;
634
+ z = (float)rv.z;
635
+
636
+ if (hasnorm)
637
+ {
638
+// assert(rv.norm.normalized());
639
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
640
+ float nx = (float)rv.norm.x;
641
+ float ny = (float)rv.norm.y;
642
+ float nz = (float)rv.norm.z;
643
+
644
+ x += nx * obj.NORMALPUSH;
645
+ y += ny * obj.NORMALPUSH;
646
+ z += nz * obj.NORMALPUSH;
647
+
648
+ SetGLNormal(gl, nx, ny, nz);
649
+ }
650
+
651
+ // if ((dot&4) == 0)
652
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
653
+
654
+ // if (wrap || !locked && (dot&8) != 0)
655
+ if (obj.flipV)
656
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
657
+ else
658
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
659
+ // else
660
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
661
+
662
+ // f.dot = dot;
663
+
664
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
665
+ SetColor(obj, rv);
666
+ //gl.glColor4f(r, g, b, 1);
667
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
668
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
669
+ gl.glVertex3f(x, y, z);
670
+// Print(rv);
671
+ //gl.glEnd();
672
+ }
673
+ else
674
+ {
675
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
676
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
677
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
678
+
679
+ }
680
+
681
+ if (false) // (attributes & WIREFRAME) != 0)
682
+ {
683
+ gl.glDisable(gl.GL_LIGHTING);
684
+
685
+ gl.glBegin(gl.GL_LINE_LOOP);
686
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
687
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
688
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
689
+ gl.glEnd();
690
+
691
+ gl.glEnable(gl.GL_LIGHTING);
692
+ }
693
+ }
694
+
695
+ /**
696
+ * <code>draw</code> renders a <code>TriMesh</code> object including
697
+ * it's normals, colors, textures and vertices.
698
+ *
699
+ * @see Renderer#draw(TriMesh)
700
+ * @param tris
701
+ * the mesh to render.
702
+ */
703
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
704
+ {
705
+ CameraPane display = this;
706
+
707
+ float r = display.modelParams0[0];
708
+ float g = display.modelParams0[1];
709
+ float b = display.modelParams0[2];
710
+ float opacity = display.modelParams5[1];
711
+
712
+ //final GL gl = GLU.getCurrentGL();
713
+ GL gl = display.GetGL(); // getGL();
714
+
715
+ FloatBuffer vertBuf = geo.vertBuf;
716
+
717
+ int v = vertBuf.capacity();
718
+
719
+ int count = 0;
720
+
721
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
722
+ gl.glEnable(gl.GL_CULL_FACE);
723
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
724
+ for (int i=0; i<v/3; i++)
725
+ {
726
+ int index3 = i*3;
727
+
728
+ if (geo.sizeBuf.get(index3+1) == 0)
729
+ continue;
730
+
731
+ count++;
732
+
733
+ int index4 = i*4;
734
+
735
+ float tx = vertBuf.get(index3);
736
+ float ty = vertBuf.get(index3+1);
737
+ float tz = vertBuf.get(index3+2);
738
+
739
+ // if (tx == 0 && ty == 0 && tz == 0)
740
+ // continue;
741
+
742
+ gl.glMatrixMode(gl.GL_TEXTURE);
743
+ gl.glPushMatrix();
744
+
745
+ float[] texmat = geo.texmat;
746
+ texmat[12] = texmat[13] = texmat[14] = i;
747
+
748
+ gl.glMultMatrixf(texmat, 0);
749
+
750
+ gl.glMatrixMode(gl.GL_MODELVIEW);
751
+ gl.glPushMatrix();
752
+
753
+ gl.glTranslatef(tx,ty,tz);
754
+
755
+ if (rotate)
756
+ gl.glRotatef(i, 0, 1, 0);
757
+
758
+ float size = geo.sizeBuf.get(index3) / 100;
759
+ gl.glScalef(size,size,size);
760
+
761
+ float cr = geo.colorBuf.get(index4);
762
+ float cg = geo.colorBuf.get(index4+1);
763
+ float cb = geo.colorBuf.get(index4+2);
764
+ float ca = geo.colorBuf.get(index4+3);
765
+
766
+ display.modelParams0[0] = r * cr;
767
+ display.modelParams0[1] = g * cg;
768
+ display.modelParams0[2] = b * cb;
769
+
770
+ display.modelParams5[1] = opacity * ca;
771
+
772
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
773
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
774
+
775
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
776
+ RandomNode.globalseed2 = RandomNode.globalseed;
777
+
778
+// gl.glColor4f(cr,cg,cb,ca);
779
+ // gl.glScalef(1024/16,1024/16,1024/16);
780
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
781
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
782
+ //gl.glTranslatef(-tx,-ty,-tz);
783
+ gl.glPopMatrix();
784
+
785
+ gl.glMatrixMode(gl.GL_TEXTURE);
786
+ gl.glPopMatrix();
787
+ }
788
+ // gl.glScalef(1024,1024,1024);
789
+ if (!cf)
790
+ gl.glDisable(gl.GL_CULL_FACE);
791
+
792
+ display.modelParams0[0] = r;
793
+ display.modelParams0[1] = g;
794
+ display.modelParams0[2] = b;
795
+
796
+ display.modelParams5[1] = opacity;
797
+
798
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
799
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
800
+
801
+ gl.glMatrixMode(gl.GL_MODELVIEW);
802
+
803
+// System.err.println("total = " + v/3 + "; displayed = " + count);
804
+ if (true)
805
+ return;
806
+
807
+//// if (!tris.predraw(this))
808
+//// {
809
+//// return;
810
+//// }
811
+//// if (Debug.stats)
812
+//// {
813
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
814
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
815
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
816
+//// }
817
+////
818
+//// if (tris.getDisplayListID() != -1)
819
+//// {
820
+//// renderDisplayList(tris);
821
+//// return;
822
+//// }
823
+////
824
+//// if (!generatingDisplayList)
825
+//// {
826
+//// applyStates(tris.states, tris);
827
+//// }
828
+//// if (Debug.stats)
829
+//// {
830
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
831
+//// }
832
+//// boolean transformed = doTransforms(tris);
833
+//
834
+// int glMode = GL.GL_TRIANGLES;
835
+// switch (getMode())
836
+// {
837
+// case Triangles:
838
+// glMode = GL.GL_TRIANGLES;
839
+// break;
840
+// case Strip:
841
+// glMode = GL.GL_TRIANGLE_STRIP;
842
+// break;
843
+// case Fan:
844
+// glMode = GL.GL_TRIANGLE_FAN;
845
+// break;
846
+// }
847
+//
848
+// if (!predrawGeometry(gl))
849
+// {
850
+// // make sure only the necessary indices are sent through on old
851
+// // cards.
852
+// IntBuffer indices = this.getIndexBuffer();
853
+// if (indices == null)
854
+// {
855
+// logger.severe("missing indices on geometry object: " + this.toString());
856
+// } else
857
+// {
858
+// indices.rewind();
859
+// indices.limit(this.getMaxIndex());
860
+//
861
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
862
+//
863
+// indices.clear();
864
+// }
865
+// } else
866
+// {
867
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
868
+// GL.GL_UNSIGNED_INT, 0);
869
+// }
870
+//
871
+//// postdrawGeometry(tris);
872
+//// if (transformed)
873
+//// {
874
+//// undoTransforms(tris);
875
+//// }
876
+////
877
+//// if (Debug.stats)
878
+//// {
879
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
880
+//// }
881
+//// tris.postdraw(this);
882
+ }
883
+
884
+ static Camera localcamera = new Camera();
885
+ static cVector from = new cVector();
886
+ static cVector to = new cVector();
887
+
888
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
889
+ {
890
+ CameraPane cp = this;
891
+
892
+ Camera keep = cp.RenderCamera();
893
+ cp.renderCamera = localcamera;
894
+
895
+ if (br.trimmed)
896
+ {
897
+ float[] colors = new float[br.positions.length / 3];
898
+
899
+ int i3 = 0;
900
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
901
+ {
902
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
903
+ continue;
904
+
905
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
906
+ to.set(br.positions[i3] + br.normals[i3],
907
+ br.positions[i3 + 1] + br.normals[i3 + 1],
908
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
909
+ LA.xformPos(from, transform, from);
910
+ LA.xformPos(to, transform, to); // RIGID ONLY
911
+ localcamera.setAim(from, to);
912
+
913
+ CameraPane.occlusionbuffer.display();
914
+
915
+ if (CameraPane.DEBUG_OCCLUSION)
916
+ cp.display(); // debug
917
+
918
+ colors[i] = cp.vertexOcclusion.r;
919
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
920
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
921
+
922
+ if ((i % 100) == 0 && i != 0)
923
+ {
924
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
925
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
926
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
927
+ }
928
+ }
929
+
930
+ br.colors = colors;
931
+ }
932
+ else
933
+ {
934
+ for (int i = 0; i < br.VertexCount(); i++)
935
+ {
936
+ Vertex v = br.GetVertex(i);
937
+
938
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
939
+ continue;
940
+
941
+ from.set(v.x, v.y, v.z);
942
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
943
+ LA.xformPos(from, transform, from);
944
+ LA.xformPos(to, transform, to); // RIGID ONLY
945
+ localcamera.setAim(from, to);
946
+
947
+ CameraPane.occlusionbuffer.display();
948
+
949
+ if (CameraPane.DEBUG_OCCLUSION)
950
+ cp.display(); // debug
951
+
952
+ v.AO = cp.vertexOcclusion.r;
953
+
954
+ if ((i % 100) == 0 && i != 0)
955
+ {
956
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
957
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
958
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
959
+ }
960
+ }
961
+ }
962
+
963
+ //System.out.println("done.");
964
+
965
+ cp.renderCamera = keep;
966
+ }
967
+
968
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
969
+ {
970
+ CameraPane display = this;
971
+ pointFlow.CreateHT();
972
+
973
+ float r = display.modelParams0[0];
974
+ float g = display.modelParams0[1];
975
+ float b = display.modelParams0[2];
976
+ float opacity = display.modelParams5[1];
977
+
978
+ //final GL gl = GLU.getCurrentGL();
979
+ GL gl = display.GetGL(); // getGL();
980
+
981
+ int s = pointFlow.points.size();
982
+
983
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
984
+ gl.glEnable(gl.GL_CULL_FACE);
985
+
986
+ for (int i=s; --i>=0;)
987
+ //for (int i=0; i<s; i++)
988
+ {
989
+ cVector v = pointFlow.points.get(i);
990
+
991
+ double mindist = Double.MAX_VALUE;
992
+
993
+ double size = pointFlow.minimumSize;
994
+
995
+ double distancenext = 0;
996
+
997
+ if (i > 0)
998
+ {
999
+ cVector w = pointFlow.points.get(i-1);
1000
+
1001
+ double dist = w.distance(v);
1002
+
1003
+ distancenext = dist;
1004
+
1005
+ if (mindist > dist)
1006
+ {
1007
+ mindist = dist;
1008
+ size = mindist*pointFlow.resizefactor;
1009
+ }
1010
+ }
1011
+
1012
+ if (i < s-1)
1013
+ {
1014
+ cVector w = pointFlow.points.get(i+1);
1015
+
1016
+ double dist = w.distance(v);
1017
+
1018
+ if (mindist > dist)
1019
+ {
1020
+ mindist = dist;
1021
+ size = mindist*pointFlow.resizefactor;
1022
+ }
1023
+ }
1024
+
1025
+ if (size < pointFlow.minimumSize)
1026
+ size = pointFlow.minimumSize;
1027
+ if (size > pointFlow.maximumSize)
1028
+ size = pointFlow.maximumSize;
1029
+
1030
+ double tx = v.x;
1031
+ double ty = v.y;
1032
+ double tz = v.z;
1033
+
1034
+ // if (tx == 0 && ty == 0 && tz == 0)
1035
+ // continue;
1036
+
1037
+ gl.glMatrixMode(gl.GL_TEXTURE);
1038
+ gl.glPushMatrix();
1039
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1040
+
1041
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1042
+
1043
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1044
+ gl.glPushMatrix();
1045
+
1046
+ gl.glTranslated(tx,ty,tz);
1047
+
1048
+ gl.glScaled(size,size,size);
1049
+
1050
+// float cr = colorBuf.get(index4);
1051
+// float cg = colorBuf.get(index4+1);
1052
+// float cb = colorBuf.get(index4+2);
1053
+// float ca = colorBuf.get(index4+3);
1054
+//
1055
+// display.modelParams0[0] = r * cr;
1056
+// display.modelParams0[1] = g * cg;
1057
+// display.modelParams0[2] = b * cb;
1058
+//
1059
+// display.modelParams5[1] = opacity * ca;
1060
+//
1061
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1062
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1063
+//
1064
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1065
+// RandomNode.globalseed2 = RandomNode.globalseed;
1066
+//
1067
+//// gl.glColor4f(cr,cg,cb,ca);
1068
+// // gl.glScalef(1024/16,1024/16,1024/16);
1069
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1070
+
1071
+ gl.glPopMatrix();
1072
+
1073
+ double step = size/4; //
1074
+
1075
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1076
+ continue;
1077
+
1078
+ int nbsteps = (int)(distancenext/step);
1079
+
1080
+ step = distancenext/nbsteps;
1081
+
1082
+ cVector next = pointFlow.points.get(i-1);
1083
+
1084
+ tmp.set(next);
1085
+ tmp.sub(v);
1086
+ tmp.normalize();
1087
+ tmp.mul(step);
1088
+
1089
+ // calculate next size
1090
+ mindist = Double.MAX_VALUE;
1091
+
1092
+ double nextsize = pointFlow.minimumSize;
1093
+
1094
+ if (i > 1)
1095
+ {
1096
+ cVector w = pointFlow.points.get(i-2);
1097
+
1098
+ double dist = w.distance(next);
1099
+
1100
+ if (mindist > dist)
1101
+ {
1102
+ mindist = dist;
1103
+ nextsize = mindist*pointFlow.resizefactor;
1104
+ }
1105
+ }
1106
+
1107
+ double dist = v.distance(next);
1108
+
1109
+ if (mindist > dist)
1110
+ {
1111
+ mindist = dist;
1112
+ nextsize = mindist*pointFlow.resizefactor;
1113
+ }
1114
+
1115
+ if (nextsize < pointFlow.minimumSize)
1116
+ nextsize = pointFlow.minimumSize;
1117
+ if (nextsize > pointFlow.maximumSize)
1118
+ nextsize = pointFlow.maximumSize;
1119
+ //
1120
+
1121
+ double count = 0;
1122
+
1123
+ while (distancenext > 0.000000001) // step
1124
+ {
1125
+ gl.glPushMatrix();
1126
+
1127
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1128
+
1129
+ double K = count/nbsteps;
1130
+
1131
+ double intersize = K*nextsize + (1-K)*size;
1132
+
1133
+ gl.glScaled(intersize,intersize,intersize);
1134
+
1135
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1136
+
1137
+ count++;
1138
+
1139
+ distancenext -= step;
1140
+
1141
+ gl.glPopMatrix();
1142
+ }
1143
+
1144
+ if (count != nbsteps)
1145
+ assert(count == nbsteps);
1146
+
1147
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1148
+ //gl.glTranslatef(-tx,-ty,-tz);
1149
+
1150
+ gl.glMatrixMode(gl.GL_TEXTURE);
1151
+ gl.glPopMatrix();
1152
+ }
1153
+
1154
+ if (!cf)
1155
+ gl.glDisable(gl.GL_CULL_FACE);
1156
+
1157
+// display.modelParams0[0] = r;
1158
+// display.modelParams0[1] = g;
1159
+// display.modelParams0[2] = b;
1160
+//
1161
+// display.modelParams5[1] = opacity;
1162
+//
1163
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1164
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1165
+
1166
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1167
+ }
1168
+
1169
+ public void DrawBox(cVector min, cVector max)
1170
+ {
1171
+ javax.media.opengl.GL gl = GetGL();
1172
+ gl.glBegin(gl.GL_LINES);
1173
+
1174
+ gl.glVertex3d(min.x, min.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, max.z);
1176
+ gl.glVertex3d(min.x, min.y, min.z);
1177
+ gl.glVertex3d(min.x, max.y, min.z);
1178
+ gl.glVertex3d(min.x, min.y, min.z);
1179
+ gl.glVertex3d(max.x, min.y, min.z);
1180
+
1181
+ gl.glVertex3d(max.x, max.y, max.z);
1182
+ gl.glVertex3d(min.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, max.z);
1184
+ gl.glVertex3d(max.x, min.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, max.z);
1186
+ gl.glVertex3d(max.x, max.y, min.z);
1187
+
1188
+ gl.glEnd();
1189
+ }
1190
+
1191
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1192
+ {
1193
+ int[] strips = bRep.getRawIndices();
1194
+
1195
+ javax.media.opengl.GL gl = GetGL();
1196
+
1197
+ // TRIANGLE STRIP ARRAY
1198
+ if (bRep.trimmed)
1199
+ {
1200
+ float[] v = bRep.getRawVertices();
1201
+ float[] n = bRep.getRawNormals();
1202
+ float[] c = bRep.getRawColors();
1203
+ float[] uv = bRep.getRawUVMap();
1204
+
1205
+ int count2 = 0;
1206
+ int count3 = 0;
1207
+
1208
+ if (n.length > 0)
1209
+ {
1210
+ for (int i = 0; i < strips.length; i++)
1211
+ {
1212
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1213
+
1214
+ /*
1215
+ boolean locked = false;
1216
+ float eps = 0.1f;
1217
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1218
+
1219
+ int dot = 0;
1220
+
1221
+ if ((dot&1) == 0)
1222
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1223
+
1224
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1225
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1226
+ else
1227
+ {
1228
+ locked = true;
1229
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1230
+ }
1231
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1232
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1233
+ if (hasnorm)
1234
+ {
1235
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1236
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1237
+ }
1238
+
1239
+ if ((dot&4) == 0)
1240
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1241
+
1242
+ if (wrap || !locked && (dot&8) != 0)
1243
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1244
+ else
1245
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1246
+
1247
+ f.dot = dot;
1248
+ */
1249
+
1250
+ if (!selectmode)
1251
+ {
1252
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1253
+ {
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1255
+ } else
1256
+ {
1257
+ SetGLNormal(gl, 0, 0, 1);
1258
+ }
1259
+
1260
+ if (c != null)
1261
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1262
+ {
1263
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1264
+ }
1265
+ }
1266
+
1267
+ if (flipV)
1268
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1269
+ else
1270
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
1272
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1273
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1274
+
1275
+ count2 += 2;
1276
+ count3 += 3;
1277
+ if (!selectmode)
1278
+ {
1279
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1280
+ {
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1282
+ } else
1283
+ {
1284
+ SetGLNormal(gl, 0, 0, 1);
1285
+ }
1286
+ if (c != null)
1287
+ {
1288
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1289
+ }
1290
+ }
1291
+
1292
+ if (flipV)
1293
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1294
+ else
1295
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
1297
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1298
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1299
+
1300
+ count2 += 2;
1301
+ count3 += 3;
1302
+ for (int j = 0; j < strips[i] - 2; j++)
1303
+ {
1304
+ //gl.glTexCoord2d(...);
1305
+ if (!selectmode)
1306
+ {
1307
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1308
+ {
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1310
+ } else
1311
+ {
1312
+ SetGLNormal(gl, 0, 0, 1);
1313
+ }
1314
+ if (c != null)
1315
+ {
1316
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1317
+ }
1318
+ }
1319
+
1320
+ if (flipV)
1321
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1322
+ else
1323
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
1325
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1326
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
1328
+ count2 += 2;
1329
+ count3 += 3;
1330
+ }
1331
+
1332
+ gl.glEnd();
1333
+ }
1334
+ }
1335
+
1336
+ assert count3 == v.length;
1337
+ }
1338
+ else // !trimmed
1339
+ {
1340
+ int count = 0;
1341
+ for (int i = 0; i < strips.length; i++)
1342
+ {
1343
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1344
+
1345
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1346
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1347
+
1348
+ drawVertex(gl, p, flipV, selectmode);
1349
+ drawVertex(gl, q, flipV, selectmode);
1350
+
1351
+ for (int j = 0; j < strips[i] - 2; j++)
1352
+ {
1353
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1354
+
1355
+ // if (j%2 == 0)
1356
+ // drawFace(p, q, r, display, null);
1357
+ // else
1358
+ // drawFace(p, r, q, display, null);
1359
+
1360
+ // p = q;
1361
+ // q = r;
1362
+ drawVertex(gl, r, flipV, selectmode);
1363
+ }
1364
+
1365
+ gl.glEnd();
1366
+ }
1367
+ }
1368
+ }
1369
+
1370
+ static cSpring.Point3D temp = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1372
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1373
+
1374
+ public void DrawDynamicMesh(cMesh mesh)
1375
+ {
1376
+ GL gl = GetGL(); // getGL();
1377
+
1378
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1379
+
1380
+ gl.glDisable(gl.GL_LIGHTING);
1381
+
1382
+ gl.glLineWidth(1);
1383
+ gl.glColor3f(1,1,1);
1384
+ gl.glBegin(gl.GL_LINES);
1385
+ double scale = 0;
1386
+ int count = 0;
1387
+ for (int s=0; s<Phys.allSprings.size(); s++)
1388
+ {
1389
+ cSpring.Spring spring = Phys.allSprings.get(s);
1390
+ if(s == 0)
1391
+ {
1392
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1393
+ }
1394
+ if (mesh.showsprings)
1395
+ {
1396
+ temp.set(spring.a.position);
1397
+ temp.add(spring.b.position);
1398
+ temp.mul(0.5);
1399
+ temp2.set(spring.a.position);
1400
+ temp2.sub(spring.b.position);
1401
+ temp2.mul(spring.restLength/2);
1402
+ temp.sub(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ temp.add(temp2);
1405
+ temp.add(temp2);
1406
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1407
+ }
1408
+
1409
+ if (spring.isHandle)
1410
+ continue;
1411
+
1412
+ //if (scale < spring.restLength)
1413
+ scale += spring.restLength;
1414
+ count++;
1415
+ }
1416
+ gl.glEnd();
1417
+
1418
+ if (count == 0)
1419
+ scale = 0.01;
1420
+ else
1421
+ scale /= count * 3;
1422
+
1423
+ //scale = 0.25;
1424
+
1425
+ if (mesh.ShowInfo())
1426
+ {
1427
+ gl.glLineWidth(4);
1428
+ for (int s=0; s<Phys.allNodes.size(); s++)
1429
+ {
1430
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1431
+ if (node.mass == 0)
1432
+ continue;
1433
+
1434
+ int i = node.springs==null?-1:node.springs.size();
1435
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1436
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1437
+ //temp.normalize();
1438
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1439
+ gl.glBegin(gl.GL_LINES);
1440
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1441
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1442
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1443
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1444
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1445
+ gl.glEnd();
1446
+ }
1447
+
1448
+ gl.glLineWidth(8);
1449
+ for (int s=0; s<Phys.allNodes.size(); s++)
1450
+ {
1451
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1452
+
1453
+ if (node.springs != null)
1454
+ {
1455
+ for (int i=0; i<node.springs.size(); i+=1)
1456
+ {
1457
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1458
+
1459
+ int c = i+1;
1460
+ // c = node.springs.get(i).nbcopies;
1461
+
1462
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1463
+ gl.glBegin(gl.GL_LINES);
1464
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1465
+ 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);
1466
+ gl.glEnd();
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+ gl.glLineWidth(1);
1472
+ }
1473
+
1474
+ gl.glEnable(gl.GL_LIGHTING);
1475
+ }
1476
+
1477
+ /// INTERFACE
1478
+
1479
+ public void StartTriangles()
1480
+ {
1481
+ javax.media.opengl.GL gl = GetGL();
1482
+ gl.glBegin(gl.GL_TRIANGLES);
1483
+ }
1484
+
1485
+ public void EndTriangles()
1486
+ {
1487
+ GetGL().glEnd();
1488
+ }
1489
+
1490
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1491
+ {
1492
+ if (!selectmode)
1493
+ {
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1495
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1496
+
1497
+ if (flipV)
1498
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1499
+ else
1500
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1501
+ }
1502
+
1503
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1504
+ }
1505
+
1506
+ float[] colorV = new float[4];
1507
+
1508
+ void SetColor(Object3D obj, Vertex p0)
1509
+ {
1510
+ CameraPane display = this;
1511
+ BoundaryRep bRep = obj.bRep;
1512
+
1513
+ if (RENDERPROGRAM == 0)
1514
+ {
1515
+ float r = 0;
1516
+ if (bRep != null)
1517
+ {
1518
+ if (bRep.stripified)
1519
+ {
1520
+ r = 1;
1521
+ }
1522
+ }
1523
+ float g = 0;
1524
+ if (bRep != null)
1525
+ {
1526
+ if (bRep.trimmed)
1527
+ {
1528
+ g = 1;
1529
+ }
1530
+ }
1531
+ float b = 0;
1532
+ if (obj.support != null && obj.link2master)
1533
+ {
1534
+ b = 1;
1535
+ }
1536
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1537
+ return;
1538
+ }
1539
+
1540
+ if (display.DrawMode() != CameraPane.SHADOW)
1541
+ return;
1542
+
1543
+ javax.media.opengl.GL gl = display.GetGL();
1544
+// if (true) return;
1545
+// float ao = p.AO;
1546
+//
1547
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1548
+// // ao = 1;
1549
+//
1550
+// gl.glColor4f(ao, ao, ao, 1);
1551
+
1552
+// CameraPane.selectedpoint.
1553
+// getAverage(cStatic.point1, true);
1554
+ if (CameraPane.pointflow == null) // !random) // live)
1555
+ {
1556
+ return;
1557
+ }
1558
+
1559
+ cStatic.point1.set(0,0,0);
1560
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1561
+
1562
+ cStatic.point1.sub(p0);
1563
+
1564
+
1565
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1566
+// {
1567
+// return;
1568
+// }
1569
+
1570
+ //if (true)
1571
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1572
+ {
1573
+ return;
1574
+ }
1575
+
1576
+ if (false) // marked)
1577
+ {
1578
+ // debug rigging weights
1579
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1580
+ {
1581
+ float weight = p0.weights[object] / p0.totalweight;
1582
+
1583
+ // if (weight < 0.1)
1584
+ // {
1585
+ // assert(weight == 0);
1586
+ // continue;
1587
+ // }
1588
+
1589
+ if (p0.vertexlinks[object] == -1)
1590
+ continue;
1591
+
1592
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1593
+
1594
+ int color = //1 << object; //
1595
+ //p.vertexlinks.length;
1596
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1597
+ colorV[2] += (color & 1) * weight;
1598
+ colorV[1] += ((color & 2) >> 1) * weight;
1599
+ colorV[0] += ((color & 4) >> 2) * weight;
1600
+ }
1601
+ }
1602
+ else
1603
+ {
1604
+ if (obj.drawingstarted)
1605
+ {
1606
+ // find next point
1607
+ if (bRep.GetVertex(0).faceindices == null)
1608
+ {
1609
+ bRep.InitFaceIndices();
1610
+ }
1611
+
1612
+ double ymin = p0.y;
1613
+
1614
+ Vertex newp = p0;
1615
+
1616
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1617
+ {
1618
+ int fi = p0.faceindices[fii];
1619
+
1620
+ if (fi == -1)
1621
+ break;
1622
+
1623
+ Face f = bRep.GetFace(fi);
1624
+
1625
+ Vertex p = bRep.GetVertex(f.p);
1626
+ Vertex q = bRep.GetVertex(f.q);
1627
+ Vertex r = bRep.GetVertex(f.r);
1628
+
1629
+ int swap = (int)(Math.random()*3);
1630
+
1631
+// for (int s=swap; --s>=0;)
1632
+// {
1633
+// Vertex t = p;
1634
+// p = q;
1635
+// q = r;
1636
+// r = t;
1637
+// }
1638
+ if (ymin > p.y)
1639
+ {
1640
+ ymin = p.y;
1641
+ newp = p;
1642
+// break;
1643
+ }
1644
+ if (ymin > q.y)
1645
+ {
1646
+ ymin = q.y;
1647
+ newp = q;
1648
+// break;
1649
+ }
1650
+ if (ymin > r.y)
1651
+ {
1652
+ ymin = r.y;
1653
+ newp = r;
1654
+// break;
1655
+ }
1656
+ }
1657
+
1658
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1659
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1660
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1661
+
1662
+ obj.drawingstarted = false;
1663
+
1664
+ // return;
1665
+ }
1666
+
1667
+ if (false) // CameraPane.DRAW
1668
+ {
1669
+ p0.AO = colorV[0] = 2;
1670
+ colorV[1] = 2;
1671
+ colorV[2] = 2;
1672
+ }
1673
+
1674
+ CameraPane.pointflow.add(p0);
1675
+ CameraPane.pointflow.Touch();
1676
+ }
1677
+
1678
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1679
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1680
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1681
+ }
1682
+
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1684
+ {
1685
+ CameraPane display = this;
1686
+ //new Exception().printStackTrace();
1687
+
1688
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1689
+ {
1690
+ return;
1691
+ }
1692
+
1693
+ javax.media.opengl.GL gl = display.GetGL();
1694
+
1695
+ //Color col = Color.getHSBColor(color,modulation,1);
1696
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1697
+ if (!material.multiply)
1698
+ {
1699
+ display.color = material.color;
1700
+ display.saturation = material.modulation;
1701
+ }
1702
+ else
1703
+ {
1704
+ display.color *= material.color*2;
1705
+ display.saturation *= material.modulation*2;
1706
+ }
1707
+
1708
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1709
+
1710
+ float[] colorV = Grafreed.colorV;
1711
+
1712
+ /**/
1713
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1714
+ {
1715
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1716
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1717
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1718
+ colorV[3] = 1; // material.opacity;
1719
+
1720
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1721
+ //System.out.println("Opacity = " + opacity);
1722
+
1723
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1724
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1725
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1726
+
1727
+ float amb = material.ambient;
1728
+ if (amb < material.cameralight)
1729
+ {
1730
+ amb = material.cameralight;
1731
+ }
1732
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1733
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1734
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1735
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1736
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1737
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1738
+
1739
+ /**/
1740
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1741
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1742
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1743
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1744
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1745
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1746
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1747
+ //System.out.println("shininess = " + colorV[0]);
1748
+ if (colorV[0] > 128)
1749
+ {
1750
+ colorV[0] = 128;
1751
+ }
1752
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1753
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1754
+ /**/
1755
+ }
1756
+ /**/
1757
+
1758
+ //selected = false;
1759
+ selected = selected && display.flash;
1760
+
1761
+ //display.modelParams0[0] = 0; // pigment.r;
1762
+ //display.modelParams0[1] = 0; // pigment.g;
1763
+ //display.modelParams0[2] = 0; // pigment.b;
1764
+ if (!material.multiply)
1765
+ {
1766
+ display.modelParams0[3] = material.metalness;
1767
+ display.modelParams1[0] = material.diffuse;
1768
+ display.modelParams1[1] = material.specular;
1769
+ display.modelParams1[2] = 1 / material.shininess;
1770
+ display.modelParams1[3] = material.shift;
1771
+ display.modelParams2[0] = material.ambient;
1772
+ display.modelParams2[1] = material.lightarea;
1773
+ //System.out.println("light area = " + lightarea);
1774
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1775
+ display.modelParams2[3] = material.velvet;
1776
+ display.modelParams3[0] = material.sheen;
1777
+ display.modelParams3[1] = material.subsurface;
1778
+ display.modelParams3[2] = material.bump; // backlit
1779
+ display.modelParams3[3] = material.aniso;
1780
+ display.modelParams4[0] = material.anisoV;
1781
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1782
+ //System.out.println("selected = " + selected);
1783
+ display.modelParams4[2] = material.diffuseness;
1784
+ display.modelParams4[3] = material.shadow;
1785
+ display.modelParams5[0] = material.texture;
1786
+ display.modelParams5[1] = material.opacity;
1787
+ display.modelParams5[2] = material.fakedepth;
1788
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1789
+ }
1790
+ else
1791
+ {
1792
+ display.modelParams0[3] *= material.metalness*2;
1793
+ display.modelParams1[0] *= material.diffuse*2;
1794
+ display.modelParams1[1] *= material.specular*2;
1795
+ display.modelParams1[2] *= material.shininess*2;
1796
+ display.modelParams1[3] *= material.shift*2;
1797
+ display.modelParams2[0] *= material.ambient*2;
1798
+ display.modelParams2[1] *= material.lightarea*2;
1799
+ display.modelParams2[2] *= material.factor*2;
1800
+ display.modelParams2[3] *= material.velvet*2;
1801
+ display.modelParams3[0] *= material.sheen*2;
1802
+ display.modelParams3[1] *= material.subsurface*2;
1803
+ display.modelParams3[2] *= material.bump*2;
1804
+ display.modelParams3[3] *= material.aniso*2;
1805
+ display.modelParams4[0] *= material.anisoV*2;
1806
+ display.modelParams4[1] *= material.cameralight*2;
1807
+ //System.out.println("selected = " + selected);
1808
+ display.modelParams4[2] *= material.diffuseness*2;
1809
+ display.modelParams4[3] *= material.shadow*2;
1810
+ display.modelParams5[0] *= material.texture*2;
1811
+ display.modelParams5[1] *= material.opacity*2;
1812
+ display.modelParams5[2] *= material.fakedepth*2;
1813
+ display.modelParams5[3] *= material.shadowbias*2;
1814
+ }
1815
+
1816
+ display.modelParams6[0] = 0;
1817
+ display.modelParams6[1] = 0;
1818
+ display.modelParams6[2] = 0;
1819
+ display.modelParams6[3] = 0;
1820
+
1821
+ display.modelParams7[0] = 0;
1822
+ display.modelParams7[1] = 1000;
1823
+ display.modelParams7[2] = material.parallax;
1824
+ display.modelParams7[3] = 0;
1825
+
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
1827
+
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1829
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1830
+ {
1831
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1832
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1833
+ if (extparams.length > 1)
1834
+ {
1835
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1836
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1837
+ if (extparams.length > 2)
1838
+ {
1839
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1840
+ float x = extparams[2].y / 1000.0f;
1841
+ //if (x == 0)
1842
+ // x = 1f;
1843
+ 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
1844
+ if (extparams[2].y > 0)
1845
+ {
1846
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1847
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1848
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1849
+ }
1850
+ }
1851
+ }
1852
+ }
1853
+
1854
+ //if (display.modelParams6[2] != 0)
1855
+ /*
1856
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1857
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1858
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1859
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1860
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1861
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1862
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1863
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1864
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1865
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1866
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1867
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1868
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1869
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1870
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1871
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1872
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1873
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1874
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1875
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1876
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1877
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1878
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1879
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1880
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1881
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1882
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1883
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1884
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1885
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1886
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1887
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1888
+ /**/
1889
+ //assert (display.modelParams6[2] == 0);
1890
+
1891
+ //System.out.println("noise power = " + display.modelParams7[0]);
1892
+ //System.out.println("shadowbias = " + shadowbias);
1893
+
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1896
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1897
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1898
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1899
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1900
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1901
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1902
+
1903
+ int mode = display.FP_SHADER;
1904
+
1905
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1906
+ {
1907
+ mode |= display.FP_ANISO;
1908
+ }
1909
+
1910
+ display.EnableProgram(mode);
1911
+
1912
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1913
+
1914
+ if (!material.multiply)
1915
+ {
1916
+ if (Globals.drawMode == CameraPane.SHADOW)
1917
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1918
+ else
1919
+ gl.glDepthMask(material.opacity >= 0.99);
1920
+ }
2361921 }
2371922
2381923 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -253,7 +1938,7 @@
2531938 currentGL.glMultMatrixd(model, 0);
2541939 }
2551940
256
- void PushMatrix(double[][] matrix, int count)
1941
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2571942 {
2581943 matrixdepth++;
2591944 // GrafreeD.tracein(matrix);
....@@ -282,7 +1967,7 @@
2821967 void PushMatrix(double[][] matrix)
2831968 {
2841969 // GrafreeD.tracein(matrix);
285
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
2861971 }
2871972
2881973 void PushMatrix()
....@@ -298,7 +1983,7 @@
2981983
2991984 double[][] tmpmat = new double[4][4];
3001985
301
- void PopMatrix(double[][] inverse)
1986
+ public void PopMatrix(double[][] inverse) // INTERFACE
3021987 {
3031988 --matrixdepth;
3041989
....@@ -338,7 +2023,7 @@
3382023 PushTextureMatrix(matrix, 1);
3392024 }
3402025
341
- void PushTextureMatrix(double[][] matrix, int count)
2026
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3422027 {
3432028 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3442029
....@@ -352,7 +2037,7 @@
3522037 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3532038 }
3542039
355
- void PopTextureMatrix(double[][] inverse)
2040
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3562041 {
3572042 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3582043 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -368,9 +2053,9 @@
3682053 switch(viewcode)
3692054 {
3702055 case 0: return "main";
371
- case 1: return "one";
372
- case 2: return "two";
373
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
3742059 case 4: return "light";
3752060 }
3762061
....@@ -379,15 +2064,15 @@
3792064
3802065 static int camerachangeframe;
3812066
382
- boolean SetCamera(Camera cam)
2067
+ public boolean SetCamera(Camera cam)
3832068 {
3842069 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3852070 // return false;
3862071
387
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2072
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3882073 {
3892074 // check for last change
390
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2075
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3912076 {
3922077 // refuse the camera change
3932078 System.err.println("Camera " + cam + " REFUSED");
....@@ -395,7 +2080,7 @@
3952080 }
3962081 }
3972082
398
- camerachangeframe = framecount;
2083
+ camerachangeframe = Globals.framecount;
3992084
4002085 cam.hAspect = -1; // Read only
4012086
....@@ -426,7 +2111,7 @@
4262111 {
4272112 //System.err.println("Oeil on");
4282113 TRACK = true;
429
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2114
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4302115 // object.editWindow.ScreenFit(trackedobject);
4312116 //pingthread.StepToTarget(true);
4322117 }
....@@ -435,8 +2120,8 @@
4352120 {
4362121 //System.err.println("Oeil on");
4372122 OEIL = true;
438
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
439
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4402125 //pingthread.StepToTarget(true);
4412126 }
4422127
....@@ -499,39 +2184,12 @@
4992184 {
5002185 frozen ^= true;
5012186 // Weird...
502
- lighttouched = true;
2187
+ Globals.lighttouched = true;
5032188 }
5042189
5052190 void ToggleDL()
5062191 {
5072192 mainDL ^= true;
508
- }
509
-
510
- void ToggleTexture()
511
- {
512
- textureon ^= true;
513
- }
514
-
515
- void ToggleLive()
516
- {
517
- setLIVE(isLIVE() ^ true);
518
-
519
- System.err.println("LIVE = " + isLIVE());
520
-
521
- if (!isLIVE()) // save sound
522
- GrafreeD.savesound = true; // wav.save();
523
- // else
524
- repaint(); // start loop // may 2013
525
- }
526
-
527
- void ToggleSupport()
528
- {
529
- SUPPORT ^= true;
530
- }
531
-
532
- void ToggleAbort()
533
- {
534
- ABORTMODE ^= true;
5352193 }
5362194
5372195 void ToggleFullScreen()
....@@ -541,12 +2199,7 @@
5412199
5422200 void ToggleCrowd()
5432201 {
544
- CROWD ^= true;
545
- }
546
-
547
- void ToggleInertia()
548
- {
549
- INERTIA ^= true;
2202
+ Globals.CROWD ^= true;
5502203 }
5512204
5522205 void ToggleLocal()
....@@ -554,62 +2207,89 @@
5542207 LOCALTRANSFORM ^= true;
5552208 }
5562209
557
- void ToggleFast()
2210
+ public void ToggleTexture()
2211
+ {
2212
+ textureon ^= true;
2213
+ }
2214
+
2215
+ public void ToggleLive()
2216
+ {
2217
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2218
+
2219
+ System.err.println("LIVE = " + Globals.isLIVE());
2220
+
2221
+ if (!Globals.isLIVE()) // save sound
2222
+ Grafreed.savesound = true; // wav.save();
2223
+ // else
2224
+ repaint(); // start loop // may 2013
2225
+ }
2226
+
2227
+ public void ToggleSupport()
2228
+ {
2229
+ SUPPORT ^= true;
2230
+ }
2231
+
2232
+ public void ToggleAbort()
2233
+ {
2234
+ ABORTMODE ^= true;
2235
+ }
2236
+
2237
+ public void ToggleInertia()
2238
+ {
2239
+ INERTIA ^= true;
2240
+ }
2241
+
2242
+ public void ToggleFast()
5582243 {
5592244 FAST ^= true;
5602245 }
5612246
562
- void ToggleSlowPose()
2247
+ public void ToggleSlowPose()
5632248 {
5642249 SLOWPOSE ^= true;
5652250 }
5662251
567
- void ToggleFootContact()
568
- {
569
- FOOTCONTACT ^= true;
570
- }
571
-
572
- void ToggleBoxMode()
2252
+ public void ToggleBoxMode()
5732253 {
5742254 BOXMODE ^= true;
5752255 }
5762256
577
- void ToggleSmoothFocus()
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
2260
+ }
2261
+
2262
+ public void ToggleSmoothFocus()
5782263 {
5792264 SMOOTHFOCUS ^= true;
5802265 }
5812266
582
- void ToggleImageFlip()
2267
+ public void ToggleImageFlip()
5832268 {
5842269 IMAGEFLIP ^= true;
5852270 }
5862271
587
- void ToggleSpeakerMocap()
2272
+ public void ToggleSpeakerMocap()
5882273 {
5892274 SPEAKERMOCAP ^= true;
5902275 }
5912276
592
- void ToggleSpeakerCamera()
2277
+ public void ToggleSpeakerCamera()
5932278 {
5942279 SPEAKERCAMERA ^= true;
5952280 }
5962281
597
- void ToggleSpeakerFocus()
2282
+ public void ToggleSpeakerFocus()
5982283 {
5992284 SPEAKERFOCUS ^= true;
6002285 }
6012286
602
- void ToggleDebug()
603
- {
604
- DEBUG ^= true;
605
- }
606
-
607
- void ToggleFrustum()
2287
+ public void ToggleFrustum()
6082288 {
6092289 FRUSTUM ^= true;
6102290 }
6112291
612
- void ToggleTrack()
2292
+ public void ToggleTrack()
6132293 {
6142294 TRACK ^= true;
6152295 if (TRACK)
....@@ -628,25 +2308,35 @@
6282308 repaint();
6292309 }
6302310
631
- void ToggleTrackOnce()
2311
+ public void ToggleTrackOnce()
6322312 {
6332313 TRACKONCE ^= true;
6342314 }
6352315
636
- void ToggleShadowTrack()
2316
+ public void ToggleShadowTrack()
6372317 {
6382318 SHADOWTRACK ^= true;
6392319 repaint();
6402320 }
6412321
642
- void ToggleOeil()
2322
+ public void ToggleOeil()
6432323 {
6442324 OEIL ^= true;
6452325 }
6462326
647
- void ToggleOeilOnce()
2327
+ public void ToggleOeilOnce()
6482328 {
6492329 OEILONCE ^= true;
2330
+ }
2331
+
2332
+ void ToggleFootContact()
2333
+ {
2334
+ FOOTCONTACT ^= true;
2335
+ }
2336
+
2337
+ void ToggleDebug()
2338
+ {
2339
+ Globals.DEBUG ^= true;
6502340 }
6512341
6522342 void ToggleLookAt()
....@@ -654,9 +2344,9 @@
6542344 LOOKAT ^= true;
6552345 }
6562346
657
- void ToggleRandom()
2347
+ void ToggleSwitch()
6582348 {
659
- RANDOM ^= true;
2349
+ SWITCH ^= true;
6602350 }
6612351
6622352 void ToggleHandles()
....@@ -664,10 +2354,17 @@
6642354 HANDLES ^= true;
6652355 }
6662356
2357
+ Object3D paintFolder;
2358
+
6672359 void TogglePaint()
6682360 {
6692361 PAINTMODE ^= true;
6702362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
6712368 }
6722369
6732370 void SwapCamera(int a, int b)
....@@ -759,11 +2456,38 @@
7592456
7602457 GL currentGL;
7612458
762
- GL GetGL()
2459
+ public GL GetGL() // INTERFACE
7632460 {
7642461 return currentGL;
7652462 }
766
-
2463
+
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
7672491 /**/
7682492 class CacheTexture
7692493 {
....@@ -772,28 +2496,31 @@
7722496
7732497 int resolution;
7742498
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762500 {
777
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
7782503 resolution = res;
7792504 }
7802505 }
7812506 /**/
7822507
7832508 // 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>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
7872514 int pigmentdepth = 0;
7882515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892516 int bumpdepth = 0;
7902517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952522
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972524 {
7982525 TextureData texturedata = null;
7992526
....@@ -803,7 +2530,7 @@
8032530 com.sun.opengl.util.texture.TextureIO.newTextureData(
8042531 getClass().getClassLoader().getResourceAsStream(name),
8052532 true,
806
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
8072534 } catch (java.io.IOException e)
8082535 {
8092536 throw new javax.media.opengl.GLException(e);
....@@ -812,13 +2539,34 @@
8122539 if (bump)
8132540 texturedata = ConvertBump(texturedata, false);
8142541
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172544
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);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202547
821
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
8222570 }
8232571
8242572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3639,8 @@
18913639
18923640 System.out.println("LOADING TEXTURE : " + name);
18933641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
18943644 //
18953645 if (false) // compressbit > 0)
18963646 {
....@@ -2595,6 +4345,7 @@
25954345
25964346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25974347 {
4348
+ new Exception().printStackTrace();
25984349 System.exit(0);
25994350 com.sun.opengl.util.texture.Texture texture = null;
26004351
....@@ -6271,7 +8022,7 @@
62718022 return null;
62728023 }
62738024
6274
- void ReleaseTextures(cTexture tex)
8025
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62758026 {
62768027 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62778028 {
....@@ -6288,7 +8039,7 @@
62888039 String pigment = Object3D.GetPigment(tex);
62898040 String bump = Object3D.GetBump(tex);
62908041
6291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62928043 {
62938044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62948045 // System.out.println("; bump = " + bump);
....@@ -6303,13 +8054,71 @@
63038054 pigment = null;
63048055 }
63058056
6306
- ReleaseTexture(bump, true);
6307
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
63088059 }
63098060
6310
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63118062 {
6312
- if (// drawMode != 0 || /*tex == null ||*/
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
8120
+ {
8121
+ if (// DrawMode() != 0 || /*tex == null ||*/
63138122 ambientOcclusion ) // || !textureon)
63148123 {
63158124 return;
....@@ -6318,7 +8127,7 @@
63188127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63198128
63208129 if (tex != null)
6321
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63228131
63238132 // //assert( texture != null );
63248133 // if (texture == null)
....@@ -6410,9 +8219,57 @@
64108219 }
64118220 }
64128221
6413
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8222
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64148223 {
6415
- if (// drawMode != 0 || /*tex == null ||*/
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
8265
+
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
8268
+ }
8269
+
8270
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8271
+ {
8272
+ if (// DrawMode() != 0 || /*tex == null ||*/
64168273 ambientOcclusion ) // || !textureon)
64178274 {
64188275 return; // false;
....@@ -6421,17 +8278,47 @@
64218278 if (tex == null)
64228279 {
64238280 BindTexture(null,false,resolution);
6424
- BindTexture(null,true,resolution);
64258281 return;
64268282 }
64278283
64288284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
64298317 String bump = Object3D.GetBump(tex);
64308318
6431
- usedtextures.put(pigment, pigment);
6432
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
64338320
6434
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64358322 {
64368323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64378324 // System.out.println("; bump = " + bump);
....@@ -6441,43 +8328,94 @@
64418328 {
64428329 bump = null;
64438330 }
6444
- if (pigment.equals(""))
6445
- {
6446
- pigment = null;
6447
- }
64488331
6449
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
- BindTexture(pigment, false, resolution);
64518332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6452
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
64538334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6454
-
6455
- return; // true;
64568335 }
64578336
6458
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
64598340 {
6460
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
64618360
64628361 if (tex != null)
64638362 {
6464
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64658365
6466
- String[] split = tex.split("Textures");
6467
- if (split.length > 1)
6468
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6469
- else
6470
- if (!texname.startsWith("/"))
6471
- texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
8373
+// String[] split = tex.split("Textures");
8374
+// if (split.length > 1)
8375
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8376
+// else
8377
+// if (!texname.startsWith("/"))
8378
+// texname = "/Users/nbriere/Textures/" + texname;
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
8380
+ {
8381
+ texname = fallbackTextureName;
8382
+ }
64728383
64738384 if (CACHETEXTURE)
6474
- texture = textures.get(texname); // TEXTURE CACHE
6475
-
6476
- TextureData texturedata = null;
6477
-
6478
- if (texture == null || texture.resolution < resolution)
64798385 {
6480
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64818419 {
64828420 assert(!bump);
64838421 // if (bump)
....@@ -6488,19 +8426,23 @@
64888426 // }
64898427 // else
64908428 // {
6491
- texture = textures.get(tex);
6492
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
64938431 {
6494
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64958433 }
8434
+ else
8435
+ new Exception().printStackTrace();
64968436 // }
64978437 } else
6498
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64998439 {
65008440 assert(bump);
6501
- texture = textures.get(tex);
6502
- if (texture == null)
6503
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
65048446 } else
65058447 {
65068448 //if (tex.equals("IMMORTAL"))
....@@ -6508,11 +8450,22 @@
65088450 // texture = GetResourceTexture("default.png");
65098451 //} else
65108452 //{
6511
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
65128454 {
6513
- texture = textures.get(tex);
6514
- if (texture == null)
6515
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
65168469 } else
65178470 {
65188471 if (textureon)
....@@ -6537,7 +8490,7 @@
65378490 }
65388491
65398492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6540
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
65418494 cachename = texname;
65428495 else
65438496 processbump = false; // don't process bump map again
....@@ -6559,7 +8512,7 @@
65598512 }
65608513
65618514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6562
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
65638516 cachename = texname;
65648517 else
65658518 processbump = false; // don't process bump map again
....@@ -6568,20 +8521,23 @@
65688521 texturedata = GetFileTexture(cachename, processbump, resolution);
65698522
65708523
6571
- if (texturedata != null)
6572
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8524
+ if (texturedata == null)
8525
+ throw new Exception();
8526
+
8527
+ texturecache = new CacheTexture(texturedata,resolution);
65738528 //texture = GetTexture(tex, bump);
65748529 }
8530
+ }
65758531 }
65768532 //}
65778533 }
65788534
6579
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65808536 {
65818537 //return false;
65828538
65838539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6584
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65858541 {
65868542 // String ext = "_highres";
65878543 // if (REDUCETEXTURE)
....@@ -6598,52 +8554,17 @@
65988554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65998555 if (!cachefile.exists())
66008556 {
6601
- // cache to disk
6602
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6603
- //buffers[0].
6604
-
6605
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6606
- int[] pixels = new int[bytebuf.capacity()/3];
6607
-
6608
- // squared size heuristic...
6609
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
66108558 {
6611
- for (int i=pixels.length; --i>=0;)
6612
- {
6613
- int i3 = i*3;
6614
- pixels[i] = 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6617
- pixels[i] <<= 8;
6618
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6619
- pixels[i] <<= 8;
6620
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6621
- }
6622
-
6623
- /*
6624
- int r=0,g=0,b=0,a=0;
6625
- for (int i=0; i<width; i++)
6626
- for (int j=0; j<height; j++)
6627
- {
6628
- int index = j*width+i;
6629
- int p = pixels[index];
6630
- a = ((p>>24) & 0xFF);
6631
- r = ((p>>16) & 0xFF);
6632
- g = ((p>>8) & 0xFF);
6633
- b = (p & 0xFF);
6634
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6635
- }
6636
- /**/
6637
- int width = (int)Math.sqrt(pixels.length); // squared
6638
- int height = width;
6639
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6640
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
66418561 ImageWriter writer = null;
66428562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66438563 if (iter.hasNext()) {
66448564 writer = (ImageWriter)iter.next();
66458565 }
6646
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
66478568 try
66488569 {
66498570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6660,18 +8581,20 @@
66608581 }
66618582 }
66628583 }
6663
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
66648587 //System.out.println("Texture = " + tex);
6665
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
66668589 {
6667
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
66688591 thetex.texture.disable();
66698592 thetex.texture.dispose();
6670
- textures.remove(texname);
8593
+ textures.remove(tex);
66718594 }
66728595
6673
- texture.texturedata = texturedata;
6674
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
66758598
66768599 // newtex = true;
66778600 }
....@@ -6687,10 +8610,44 @@
66878610 }
66888611 }
66898612
6690
- return texture;
8613
+ return texturecache;
66918614 }
66928615
6693
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66948651 {
66958652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66968653
....@@ -6708,21 +8665,21 @@
67088665 return texture!=null?texture.texture:null;
67098666 }
67108667
6711
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67128669 {
67138670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67148671
67158672 return texture!=null?texture.texturedata:null;
67168673 }
67178674
6718
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67198676 {
67208677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67218678 {
67228679 return false;
67238680 }
67248681
6725
- boolean newtex = false;
8682
+ //boolean newtex = false;
67268683
67278684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67288685
....@@ -6754,9 +8711,75 @@
67548711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67558712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67568713
6757
- return newtex;
8714
+ return true; // Warning: not used.
67588715 }
67598716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
67608783 ShadowBuffer shadowPBuf;
67618784 AntialiasBuffer antialiasPBuf;
67628785 int MAXSTACK;
....@@ -6773,10 +8796,12 @@
67738796
67748797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67758798 MAXSTACK = temp[0];
6776
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67778801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67788802 MAXSTACK = temp[0];
6779
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67808805
67818806 // Use debug pipeline
67828807 //drawable.setGL(new DebugGL(gl)); //
....@@ -6784,7 +8809,8 @@
67848809 gl = drawable.getGL(); //
67858810
67868811 GL gl3 = getGL();
6787
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67888814
67898815
67908816 //float pos[] = { 100, 100, 100, 0 };
....@@ -6949,7 +8975,7 @@
69498975
69508976 if (cubemap == null)
69518977 {
6952
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
69538979 }
69548980
69558981 //cubemap.enable();
....@@ -7225,6 +9251,8 @@
72259251
72269252 void LoadEnvy(int which)
72279253 {
9254
+ assert(false);
9255
+
72289256 String name;
72299257 String ext;
72309258
....@@ -7236,37 +9264,58 @@
72369264 cubemap = null;
72379265 return;
72389266 case 1:
7239
- name = "cubemaps/box_";
7240
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
72419269 reverseUP = false;
72429270 break;
72439271 case 2:
7244
- name = "cubemaps/uffizi_";
7245
- ext = "png";
7246
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
72479276 case 3:
7248
- name = "cubemaps/CloudyHills_";
7249
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
72509279 reverseUP = false;
72519280 break;
72529281 case 4:
7253
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
72549283 ext = "png";
72559284 reverseUP = false;
72569285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
72579311 default:
7258
- name = "cubemaps/rgb_";
7259
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
72609315 break;
72619316 }
7262
-
7263
- try
7264
- {
7265
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7266
- } catch (IOException e)
7267
- {
7268
- throw new RuntimeException(e);
7269
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
72709319 }
72719320
72729321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7298,8 +9347,12 @@
72989347 static double[] model = new double[16];
72999348 double[] camera2light = new double[16];
73009349 double[] light2camera = new double[16];
7301
- int newenvy = -1;
7302
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
73039356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73049357 //float[] light0 = { 0,0,0 };
73059358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7312,9 +9365,9 @@
73129365 static boolean occlusionInitialized = false;
73139366 boolean selection = false;
73149367 boolean pointselection = false;
7315
- /*static*/ boolean lighttouched = true;
9368
+ ///*static*/ boolean lighttouched = true;
73169369 boolean deselect;
7317
- boolean ambientOcclusion = false;
9370
+ private boolean ambientOcclusion = false;
73189371 static boolean flash = false;
73199372 /*static*/ boolean wait = false;
73209373 boolean displaydone = false; // after repaint() calls
....@@ -7592,18 +9645,40 @@
75929645 jy8[3] = 0.5f;
75939646 }
75949647
7595
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75969649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
75979650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
75989651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75999652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
76009677 static int imagecount = 0; // movie generation
76019678
76029679 static int jitter = 0;
76039680
76049681 boolean restartframe = false;
7605
-
7606
- static int framecount = 0; // general-purpose global count
76079682
76089683 void displayAntiAliased(javax.media.opengl.GL gl)
76099684 {
....@@ -7635,7 +9710,7 @@
76359710 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76369711 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76379712 {
7638
- framecount++;
9713
+ Globals.framecount++;
76399714
76409715 if (CameraPane.tickcount > 0)
76419716 CameraPane.tickcount--;
....@@ -7673,7 +9748,7 @@
76739748
76749749 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76759750 */
7676
- lighttouched = true;
9751
+ Globals.lighttouched = true;
76779752 //System.err.println(" shadowbuffer: " + jitter);
76789753 shadowbuffer.display();
76799754
....@@ -7694,8 +9769,8 @@
76949769 assert (parentcam != renderCamera);
76959770
76969771 if (renderCamera != lightCamera)
7697
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7698
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76999774
77009775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
77019776
....@@ -7710,8 +9785,8 @@
77109785 LA.matCopy(renderCamera.fromScreen, matrix);
77119786
77129787 if (renderCamera != lightCamera)
7713
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7714
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77159790
77169791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77179792
....@@ -7757,10 +9832,12 @@
77579832 rati = 1 / rati;
77589833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77599834 }
7760
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
77619838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77629839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7763
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
77649841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77659842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77669843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7783,7 +9860,7 @@
77839860 //gl.glFlush();
77849861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77859862
7786
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
77879864 {
77889865 System.err.println(" ABORTED FRAME");
77899866 break;
....@@ -7813,7 +9890,7 @@
78139890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78149891
78159892 // save image
7816
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
78179894 {
78189895 VPwidth = viewport[2];
78199896 VPheight = viewport[3];
....@@ -7924,11 +10001,11 @@
792410001
792510002 // imagecount++;
792610003
7927
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
10004
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
792810005
792910006 if (!BOXMODE)
793010007 {
7931
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
10008
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
793210009 }
793310010
793410011 if (!BOXMODE)
....@@ -7966,7 +10043,7 @@
796610043 ABORTED = false;
796710044 }
796810045 else
7969
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
797010047
797110048 if (false)
797210049 {
....@@ -8620,32 +10697,34 @@
862010697 }
862110698 }
862210699
8623
- boolean IsFrozen()
8624
- {
8625
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8626
-
8627
- return !selectmode && cameracount == 0; // != 0;
8628
- }
8629
-
863010700 boolean niceon = false;
863110701 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
863210702 boolean currentlydrawing = false;
863310703 static boolean init = false;
863410704
863510705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
863610709
863710710 public void display(GLAutoDrawable drawable)
863810711 {
8639
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
864010713 {
8641
- GrafreeD.wav.save();
8642
- GrafreeD.savesound = false;
8643
- GrafreeD.hassound = false;
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
10718
+ if (Grafreed.savesound && Grafreed.hassound)
10719
+ {
10720
+ Grafreed.wav.save();
10721
+ Grafreed.savesound = false;
10722
+ Grafreed.hassound = false;
864410723 }
864510724 // if (DEBUG_SELECTION)
864610725 // {
8647
-// if (drawMode != SELECTION)
8648
-// drawMode = SELECTION;
10726
+// if (DrawMode() != SELECTION)
10727
+// DrawMode() = SELECTION;
864910728 // }
865010729
865110730 if (!isRenderer)
....@@ -8701,9 +10780,9 @@
870110780
870210781 //ANTIALIAS = 0;
870310782
8704
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10783
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870510784 {
8706
- if (niceon || isLIVE())
10785
+ if (niceon || Globals.isLIVE())
870710786 {
870810787 //if(active == 0)
870910788 // antialiaser = null;
....@@ -8716,6 +10795,7 @@
871610795 ANTIALIAS = 0;
871710796 //System.out.println("RESTART");
871810797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
871910799 }
872010800 }
872110801 }
....@@ -8728,7 +10808,7 @@
872810808 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872910809 */
873010810
8731
- if (drawMode == DEFAULT)
10811
+ if (DrawMode() == DEFAULT)
873210812 {
873310813 currentlydrawing = true;
873410814 }
....@@ -8759,18 +10839,18 @@
875910839
876010840 // if(Applet3D.clipboard != null)
876110841 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8762
-//drawMode = SELECTION;
10842
+//DrawMode() = SELECTION;
876310843 indexcount = 0;
876410844
8765
- if (drawMode == OCCLUSION)
10845
+ if (DrawMode() == OCCLUSION)
876610846 {
8767
- drawMode = DEFAULT;
10847
+ Globals.drawMode = DEFAULT; // WARNING
876810848 ambientOcclusion = true;
876910849 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
877010850 Object3D theobject = object;
877110851 Object3D theparent = object.parent;
877210852 object.parent = null;
8773
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
877410854 object.Stripify();
877510855 if (theobject.selection == null || theobject.selection.Size() == 0)
877610856 theobject.PreprocessOcclusion(this);
....@@ -8783,26 +10863,27 @@
878310863 ambientOcclusion = false;
878410864 }
878510865
8786
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878710868 {
878810869 //if (RENDERSHADOW) // ?
878910870 if (!IsFrozen())
879010871 {
879110872 // dec 2012
8792
- if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
879310874 {
8794
- framecount++;
10875
+ Globals.framecount++;
879510876 shadowbuffer.display();
879610877 }
879710878 }
8798
- lighttouched = false; // ??
10879
+ Globals.lighttouched = false; // ??
879910880 //drawing = true;
880010881 //lighttouched = true;
880110882 }
880210883
880310884 if (wait)
880410885 {
8805
- Sleep(500);
10886
+ Sleep(200); // blocks everything
880610887
880710888 wait = false;
880810889 }
....@@ -8816,9 +10897,9 @@
881610897 //eyeCamera.shaper_fovy = 1;
881710898 }
881810899
8819
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10900
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
882010901 {
8821
- //System.out.println("drawMode = " + drawMode);
10902
+ //System.out.println("DrawMode() = " + DrawMode());
882210903 vertexMode |= VP_PASS;
882310904 //vertexMode |= VP_PROJECTION;
882410905 if (!ambientOcclusion)
....@@ -8878,7 +10959,7 @@
887810959 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887910960 //Camera lightcam = new Camera(light0);
888010961
8881
- if (drawMode == SHADOW)
10962
+ if (DrawMode() == SHADOW)
888210963 {
888310964 /*
888410965 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8916,8 +10997,8 @@
891610997
891710998 // if (parentcam != renderCamera) // not a light
891810999 if (cam != lightCamera)
8919
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8920
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
892111002
892211003 for (int j = 0; j < 4; j++)
892311004 {
....@@ -8931,8 +11012,8 @@
893111012
893211013 // if (parentcam != renderCamera) // not a light
893311014 if (cam != lightCamera)
8934
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8935
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893611017
893711018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893811019
....@@ -8968,7 +11049,7 @@
896811049 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896911050 } else
897011051 {
8971
- if (drawMode != DEFAULT)
11052
+ if (DrawMode() != DEFAULT)
897211053 {
897311054 gl.glClearColor(1, 1, 1, 0);
897411055 } // 1);
....@@ -9018,13 +11099,43 @@
901811099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901911100 }
902011101
9021
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
902211110 {
9023
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
902411117 }
9025
-
9026
- newenvy = -1;
9027
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
902811139 ratio = ((double) getWidth()) / getHeight();
902911140 //System.out.println("ratio = " + ratio);
903011141
....@@ -9033,14 +11144,14 @@
903311144
903411145 fast &= !ambientOcclusion;
903511146
9036
- if (drawMode == DEFAULT)
11147
+ if (DrawMode() == DEFAULT)
903711148 {
903811149 //gl.glEnable(gl.GL_ALPHA_TEST);
903911150 //gl.glActiveTexture(GL.GL_TEXTURE0);
904011151
904111152 if (!IsFrozen() && !ambientOcclusion)
904211153 {
9043
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
904411155 }
904511156
904611157 //if (selection_view == -1)
....@@ -9191,7 +11302,16 @@
919111302 // Bump noise
919211303 gl.glActiveTexture(GL.GL_TEXTURE6);
919311304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9194
- BindTexture(NOISE_TEXTURE, false, 2);
11305
+
11306
+ try
11307
+ {
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
11309
+ }
11310
+ catch (Exception e)
11311
+ {
11312
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11313
+ }
11314
+
919511315
919611316 gl.glActiveTexture(GL.GL_TEXTURE0);
919711317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9214,9 +11334,9 @@
921411334
921511335 gl.glMatrixMode(GL.GL_MODELVIEW);
921611336
9217
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9218
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9219
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
922011340 } else
922111341 {
922211342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9227,11 +11347,11 @@
922711347 //System.out.println("BLENDING ON");
922811348 gl.glEnable(GL.GL_BLEND);
922911349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9230
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
923111351 gl.glMatrixMode(gl.GL_PROJECTION);
923211352 gl.glLoadIdentity();
923311353
9234
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11354
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
923511355 {
923611356 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923711357 double scale = lightCamera.SCALE / lightCamera.Distance();
....@@ -9289,7 +11409,7 @@
928911409 //gl.glPushMatrix();
929011410 gl.glLoadIdentity();
929111411
9292
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11412
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
929311413 {
929411414 //LA.xformPos(light0, lightCamera.fromScreen, light);
929511415 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9316,8 +11436,8 @@
931611436 System.err.println("parentcam != renderCamera");
931711437
931811438 // if (cam != lightCamera)
9319
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9320
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
932111441 }
932211442
932311443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9338,8 +11458,8 @@
933811458 if (true) // TODO
933911459 {
934011460 if (cam != lightCamera)
9341
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9342
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
934311463 }
934411464
934511465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9376,7 +11496,7 @@
937611496 }
937711497
937811498 /**/
9379
- if (true) // drawMode == SELECTION) // != DEFAULT)
11499
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
938011500 gl.glDisable(gl.GL_LIGHTING);
938111501 else
938211502 gl.glEnable(gl.GL_LIGHTING);
....@@ -9394,7 +11514,7 @@
939411514
939511515 lightslot = 64;
939611516
9397
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11517
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
939811518 {
939911519 DrawLights(object);
940011520 }
....@@ -9405,7 +11525,7 @@
940511525 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
940611526 //System.out.println("fragmentMode = " + fragmentMode);
940711527
9408
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11528
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
940911529 {
941011530 /*
941111531 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9438,7 +11558,7 @@
943811558 }
943911559 }
944011560
9441
- if (drawMode == DEFAULT)
11561
+ if (DrawMode() == DEFAULT)
944211562 {
944311563 if (WIREFRAME && !ambientOcclusion)
944411564 {
....@@ -9456,7 +11576,7 @@
945611576 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
945711577 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
945811578
9459
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11579
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
946011580 {
946111581 if (vertexMode != 0) // && !fast)
946211582 {
....@@ -9476,7 +11596,7 @@
947611596 }
947711597 }
947811598
9479
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
948011600 {
948111601 //gl.glDepthFunc(GL.GL_LEQUAL);
948211602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9484,27 +11604,24 @@
948411604
948511605 boolean texon = textureon;
948611606
9487
- if (RENDERPROGRAM > 0)
9488
- {
9489
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9490
- textureon = false;
9491
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
949211610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
949311611 //System.out.println("ALLO");
949411612 gl.glColorMask(false, false, false, false);
949511613 DrawObject(gl);
9496
- if (RENDERPROGRAM > 0)
9497
- {
9498
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9499
- textureon = texon;
9500
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
950111618 gl.glColorMask(true, true, true, true);
950211619
950311620 gl.glDepthFunc(GL.GL_EQUAL);
9504
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
950511622 }
950611623
9507
- if (false) // drawMode == SHADOW)
11624
+ if (false) // DrawMode() == SHADOW)
950811625 {
950911626 //SetColumnMajorData(cameraInverseTransform, view_1);
951011627 //System.out.println("light = " + cameraInverseTransform);
....@@ -9518,16 +11635,16 @@
951811635 //System.out.println("object = " + object);
951911636 if (!frozen && !imageLocked)
952011637 {
9521
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11638
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
952211639 {
952311640 displayAntiAliased(gl);
952411641 } else
952511642 {
952611643 programcount = 0;
9527
- int keepmode = drawMode;
11644
+ int keepmode = DrawMode();
952811645 // if (DEBUG_SELECTION)
952911646 // {
9530
-// drawMode = SELECTION;
11647
+// DrawMode() = SELECTION;
953111648 // }
953211649 // for point selection
953311650 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9537,10 +11654,10 @@
953711654 DrawObject(gl);
953811655
953911656 // jan 2013 System.err.println("RESET ABORT (display)");
9540
- // if (drawMode == DEFAULT)
11657
+ // if (DrawMode() == DEFAULT)
954111658 // ABORTED = false;
954211659 fullreset = false;
9543
- drawMode = keepmode;
11660
+ Globals.drawMode = keepmode; // WARNING
954411661 //System.out.println("PROGRAM SWITCH " + programcount);
954511662 }
954611663 }
....@@ -9548,11 +11665,11 @@
954811665 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
954911666 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
955011667
9551
- if (drawMode == DEFAULT)
11668
+ if (DrawMode() == DEFAULT)
955211669 {
955311670 ReleaseTexture(NOISE_TEXTURE, false);
955411671 }
9555
- //if (drawMode == DEFAULT)
11672
+ //if (DrawMode() == DEFAULT)
955611673 {
955711674
955811675 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9564,7 +11681,7 @@
956411681 //else
956511682 //gl.glDisable(gl.GL_TEXTURE_2D);
956611683 //gl.glPopMatrix();
9567
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11684
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
956811685 {
956911686 //new Exception().printStackTrace();
957011687 //System.out.println("Draw image " + width + ", " + height);
....@@ -9606,7 +11723,7 @@
960611723 //gl.glFlush();
960711724 }
960811725
9609
- if (flash && drawMode == DEFAULT)
11726
+ if (flash && DrawMode() == DEFAULT)
961011727 {
961111728 flash = false;
961211729 wait = true;
....@@ -9614,9 +11731,9 @@
961411731 }
961511732
961611733 //drawing = false;
9617
- //if(drawMode == DEFAULT)
11734
+ //if(DrawMode() == DEFAULT)
961811735 // niceon = false;
9619
- if (drawMode == DEFAULT)
11736
+ if (DrawMode() == DEFAULT)
962011737 {
962111738 currentlydrawing = false;
962211739 }
....@@ -9636,7 +11753,7 @@
963611753 repaint();
963711754 }
963811755
9639
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11756
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
964011757 repaint();
964111758
964211759 displaydone = true;
....@@ -9655,8 +11772,14 @@
965511772 {
965611773 renderpass++;
965711774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
965811776 if (FAST) // in case there is no script
9659
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
966011783
966111784 //object.FullInvariants();
966211785
....@@ -9670,23 +11793,44 @@
967011793 e.printStackTrace();
967111794 }
967211795
9673
- if (GrafreeD.RENDERME > 0)
9674
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
967511798
9676
- ONESTEP = false;
11799
+ Globals.ONESTEP = false;
967711800 }
967811801
967911802 static boolean zoomonce = false;
968011803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
968111822 void DrawObject(GL gl, boolean draw)
968211823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
968311827 //System.out.println("DRAW OBJECT " + mouseDown);
9684
-// drawMode = SELECTION;
11828
+// DrawMode() = SELECTION;
968511829 //GL gl = getGL();
968611830 if ((TRACK || SHADOWTRACK) || zoomonce)
968711831 {
9688
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9689
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11832
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
969011834 pingthread.StepToTarget(true); // true);
969111835 // zoomonce = false;
969211836 }
....@@ -9706,9 +11850,9 @@
970611850 callist = gl.glGenLists(1);
970711851 }
970811852
9709
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11853
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
971011854
9711
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11855
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
971211856
971311857 if (!mainDL || !active || touched)
971411858 {
....@@ -9735,13 +11879,20 @@
973511879 PushMatrix(ClickInfo.matbuffer);
973611880 }
973711881
9738
- if (drawMode == 0)
11882
+ if (DrawMode() == 0)
973911883 {
974011884 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
974111885
974211886 usedtextures.clear();
974311887
9744
- BindTextures(DEFAULT_TEXTURES, 2);
11888
+ try
11889
+ {
11890
+ BindTextures(DEFAULT_TEXTURES, 2);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11895
+ }
974511896 }
974611897 //System.out.println("--> " + stackdepth);
974711898 // GrafreeD.traceon();
....@@ -9749,10 +11900,11 @@
974911900 // DRAW
975011901 object.draw(this, /*(Composite)*/ object, false, false);
975111902
9752
- if (drawMode == DEFAULT)
11903
+ if (DrawMode() == DEFAULT)
975311904 {
9754
- if (DEBUG)
11905
+ if (Globals.DEBUG)
975511906 {
11907
+ CreateSelectedPoint();
975611908 float radius = 0.05f;
975711909 if (selectedpoint.radius != radius)
975811910 {
....@@ -9801,38 +11953,57 @@
980111953 }
980211954 // GrafreeD.traceoff();
980311955 //System.out.println(stackdepth);
9804
- if (drawMode == 0)
11956
+ if (DrawMode() == 0)
980511957 {
980611958 ReleaseTextures(DEFAULT_TEXTURES);
980711959
980811960 if (CLEANCACHE)
9809
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
981011962 {
9811
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
981211964
981311965 // System.out.println("Texture --------- " + tex);
981411966
9815
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
981611968 continue;
981711969
9818
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
981911971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
982011973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9821
- textures.get(tex).texture.dispose();
9822
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
982311987 }
982411988 }
982511989 }
982611990
982711991 checker = null;
982811992
9829
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11993
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
983011994 FindChecker(object);
983111995
9832
- if (checker != null && drawMode == DEFAULT)
11996
+ if (checker != null && DrawMode() == DEFAULT)
983311997 {
983411998 //BindTexture(IMMORTAL_TEXTURE);
9835
- BindTextures(checker.GetTextures(), checker.texres);
11999
+ try
12000
+ {
12001
+ BindTextures(checker.GetTextures(), checker.texres);
12002
+ }
12003
+ catch (Exception e)
12004
+ {
12005
+ System.err.println("FAILED: " + checker.GetTextures());
12006
+ }
983612007 // NEAREST
983712008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
983812009 DrawChecker(gl);
....@@ -9851,7 +12022,7 @@
985112022 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
985212023 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
985312024
9854
- if (DISPLAYTEXT && drawMode == DEFAULT)
12025
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
985512026 {
985612027 // Draw it once, then use the raster
985712028 Balloon(gl, balloon.createGraphics());
....@@ -9907,14 +12078,14 @@
990712078 int[] xs = new int[3];
990812079 int[] ys = new int[3];
990912080
9910
- void DrawString(Object3D obj) // String string)
12081
+ public void DrawString(Object3D obj) // String string) // INTERFACE
991112082 {
9912
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12083
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
991312084 {
991412085 return;
991512086 }
991612087
9917
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
991812089
991912090 GL gl = GetGL();
992012091
....@@ -10231,8 +12402,8 @@
1023112402 //obj.TransformToWorld(light, light);
1023212403 for (int i = tp.size(); --i >= 0;)
1023312404 {
10234
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10235
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1023612407 }
1023712408
1023812409
....@@ -10249,8 +12420,8 @@
1024912420 parentcam = cameras[0];
1025012421 }
1025112422
10252
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10253
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1025412425
1025512426 LA.xformPos(light, renderCamera.toScreen, light);
1025612427
....@@ -10340,8 +12511,76 @@
1034012511
1034112512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1034212513
10343
- String program =
12514
+ String programmin =
12515
+ // Min shader
1034412516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1034512584 //"OPTION ARB_fragment_program_shadow;" +
1034612585 "PARAM light2cam0 = program.env[10];" +
1034712586 "PARAM light2cam1 = program.env[11];" +
....@@ -10367,7 +12606,7 @@
1036712606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1036812607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1036912608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
10370
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1037112610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1037212611 "PARAM options1 = program.env[62];" + // fog rgb color
1037312612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -10456,8 +12695,7 @@
1045612695 "TEMP shininess;" +
1045712696 "\n" +
1045812697 "MOV texSamp, one;" +
10459
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10460
-
12698
+
1046112699 "MOV mapgrid.x, one2048th.x;" +
1046212700 "MOV temp, fragment.texcoord[1];" +
1046312701 /*
....@@ -10478,20 +12716,20 @@
1047812716 "MUL temp, floor, mapgrid.x;" +
1047912717 //"TEX depth0, temp, texture[1], 2D;" +
1048012718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10481
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1048212720 "") +
1048312721 "ADD temp.x, temp.x, mapgrid.x;" +
1048412722 //"TEX depth1, temp, texture[1], 2D;" +
1048512723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10486
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1048712725 "") +
1048812726 "ADD temp.y, temp.y, mapgrid.x;" +
1048912727 //"TEX depth2, temp, texture[1], 2D;" +
10490
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1049112729 "SUB temp.x, temp.x, mapgrid.x;" +
1049212730 //"TEX depth3, temp, texture[1], 2D;" +
1049312731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10494
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1049512733 "") +
1049612734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1049712735 //"MOV params, material;" +
....@@ -10613,7 +12851,7 @@
1061312851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1061412852 // mar 2013 ??? "KIL alpha.a;" +
1061512853 "MOV alpha, texSamp.aaaa;" + // y;" +
10616
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1061712855 /*
1061812856 "MUL temp.xy, temp, two;" +
1061912857 "TXB bump, temp, texture[0], 2D;" +
....@@ -10699,11 +12937,6 @@
1069912937 "SUB bump0, bump0, half;" +
1070012938 "ADD bump, bump, bump0;" +
1070112939
10702
- "MOV temp.x, texSamp.a;" +
10703
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
10704
- //"LRP texSamp0, params5.x, texSamp0, one;" +
10705
- "MOV texSamp.a, temp.x;" +
10706
-
1070712940 // double-sided
1070812941 /**/
1070912942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -10720,19 +12953,62 @@
1072012953 "MOV normald, normal;" +
1072112954 "MOV normals, normal;" +
1072212955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1072312958 // UV base
1072412959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1072512960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1072612961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
10727
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
10728
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
10729
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1073012967 "XPD V, normal, UP;" +
1073112968 Normalize("V") +
1073212969 "XPD U, V, normal;" +
1073312970 Normalize("U") +
1073412971
1073512972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1073613012
1073713013 //"MOV temp, fragment.texcoord[0];" +
1073813014 //
....@@ -10862,10 +13138,10 @@
1086213138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1086313139 "") +
1086413140
10865
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1086613142 "SUB temp.x, half.x, shadow.x;" +
10867
- "MOV temp.y, -params6.x;" +
10868
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1086913145 "SUB temp.y, one.x, temp.z;" +
1087013146 "MUL temp.x, temp.x, temp.y;" +
1087113147 "KIL temp.x;" +
....@@ -10994,8 +13270,10 @@
1099413270 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1099513271
1099613272 "SUB temp.x, one.x, ndotl.x;" +
10997
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
10998
- "ADD temp.y, one.y, options2.y;" + // sursurface
13273
+ // Tuning for default skin
13274
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13275
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13276
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1099913277 "MUL temp.x, temp.x, temp.y;" +
1100013278
1100113279 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11194,8 +13472,19 @@
1119413472 //once = true;
1119513473 }
1119613474
11197
- System.out.print("Program #" + mode + "; length = " + program.length());
11198
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1119913488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1120013489
1120113490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11242,7 +13531,8 @@
1124213531 "\n" +
1124313532 "END\n";
1124413533
11245
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1124613536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1124713537
1124813538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11287,25 +13577,26 @@
1128713577 return out;
1128813578 }
1128913579
11290
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1129113582 {
1129213583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1129313584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1129413585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1129513588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11296
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11297
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11298
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11299
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1130013591 //"SWZ buffer, temp, w,w,w,w;";
11301
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1130213593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1130313594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1130413595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11305
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130613597
11307
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11308
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130913600 }
1131013601
1131113602 String Shadow(String depth, String shadow)
....@@ -11327,12 +13618,16 @@
1132713618
1132813619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1132913620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1133013623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1133113624 "SGE temp.y, temp.x, zero.x;" +
11332
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1133313628 "SUB temp.x, one.x, temp.x;" +
1133413629 "MUL " + shadow + ".x, temp.x, temp.y;" +
11335
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1133613631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1133713632
1133813633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11346,6 +13641,10 @@
1134613641 // No shadow for backface
1134713642 "DP3 temp.x, normal, lightd;" +
1134813643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13644
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13645
+
13646
+ // No shadow when out of frustum
13647
+ "SGE temp.x, " + depth + ".z, one.z;" +
1134913648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1135013649 "";
1135113650 }
....@@ -11491,8 +13790,9 @@
1149113790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1149213791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1149313792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
11494
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11495
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1149613796
1149713797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1149813798 // OUT : diff, spec
....@@ -11508,9 +13808,10 @@
1150813808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1150913809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1151013810 //"MOV " + dest + ".w," + "normal.z;" +
11511
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11512
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11513
- //"MOV " + dest + ".z," + "params2.w;" +
13811
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13812
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13813
+
13814
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1151413815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1151513816 "RCP " + dest + ".w," + dest + ".w;" +
1151613817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11656,7 +13957,7 @@
1165613957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1165713958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1165813959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
11659
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1166013961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1166113962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1166213963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -11717,7 +14018,7 @@
1171714018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1171814019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1171914020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
11720
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1172114022 "MOV result.texcoord, temp;" +
1172214023 // border fade
1172314024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -11764,7 +14065,9 @@
1176414065
1176514066 //"ADD temp.z, temp.z, one;" +
1176614067
11767
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1176814071 : "MOV result.color, vertex.color;") +
1176914072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1177014073 : "") +
....@@ -11904,7 +14207,7 @@
1190414207 public void mousePressed(MouseEvent e)
1190514208 {
1190614209 //System.out.println("mousePressed: " + e);
11907
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1190814211 }
1190914212
1191014213 static long prevtime = 0;
....@@ -11931,14 +14234,16 @@
1193114234
1193214235 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1193314236
14237
+ if (BUTTONLESSWHEEL)
1193414238 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1193514239 {
1193614240 return;
1193714241 }
1193814242
14243
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1193914244
1194014245 // TIMER
11941
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14246
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1194214247 {
1194314248 keepboxmode = BOXMODE;
1194414249 keepsupport = SUPPORT;
....@@ -11978,8 +14283,8 @@
1197814283 // mode |= META;
1197914284 //}
1198014285
11981
- SetMouseMode(WHEEL | e.getModifiersEx());
11982
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1198314288 anchorX = ax;
1198414289 anchorY = ay;
1198514290 prevX = px;
....@@ -12013,6 +14318,7 @@
1201314318 else
1201414319 if (evt.getSource() == AAtimer)
1201514320 {
14321
+ Globals.TIMERRUNNING = false;
1201614322 if (mouseDown)
1201714323 {
1201814324 //new Exception().printStackTrace();
....@@ -12038,6 +14344,10 @@
1203814344 // LIVE = waslive;
1203914345 // wasliveok = true;
1204014346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1204114351
1204214352 // source == timer
1204314353 if (mouseDown)
....@@ -12067,8 +14377,8 @@
1206714377 // ObjEditor.tweenManager.update(1f / 60f);
1206814378
1206914379 // fev 2014???
12070
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12071
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14380
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1207214382 pingthread.StepToTarget(true); // true);
1207314383 }
1207414384 // if (!LIVE)
....@@ -12077,12 +14387,13 @@
1207714387
1207814388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1207914389
12080
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1208114391 {
1208214392 if (!wasliveok)
1208314393 return;
1208414394
1208514395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1208614397
1208714398 // waslive = LIVE;
1208814399 // LIVE = false;
....@@ -12094,7 +14405,7 @@
1209414405 // touched = true; // main DL
1209514406 if (isRenderer)
1209614407 {
12097
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1209814409 }
1209914410
1210014411 selectX = anchorX = x;
....@@ -12107,7 +14418,7 @@
1210714418 clicked = true;
1210814419 hold = false;
1210914420
12110
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1211114422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1211214423 {
1211314424 // System.out.println("RESTART II " + modifiers);
....@@ -12132,14 +14443,15 @@
1213214443 drag = false;
1213314444 //System.out.println("Mouse DOWN");
1213414445 editObj = false;
12135
- ClickInfo info = new ClickInfo();
12136
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12137
- info.pane = this;
12138
- info.camera = renderCamera;
12139
- info.x = x;
12140
- info.y = y;
12141
- info.modifiers = modifiers;
12142
- editObj = object.doEditClick(info, 0);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1214314455 if (!editObj)
1214414456 {
1214514457 hasMarquee = true;
....@@ -12155,11 +14467,14 @@
1215514467
1215614468 public void mouseDragged(MouseEvent e)
1215714469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
14472
+ //System.out.println("mouseDragged: " + e);
1215814473 if (isRenderer)
1215914474 movingcamera = true;
14475
+
1216014476 //if (drawing)
1216114477 //return;
12162
- //System.out.println("mouseDragged: " + e);
1216314478 if ((e.getModifiersEx() & CTRL) != 0
1216414479 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1216514480 {
....@@ -12167,7 +14482,7 @@
1216714482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1216814483 }
1216914484 else
12170
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1217114486
1217214487 //try { Thread.sleep(1); } catch (Exception ex) {}
1217314488 }
....@@ -12179,6 +14494,11 @@
1217914494 cVector tmp = new cVector();
1218014495 cVector tmp2 = new cVector();
1218114496 boolean isMoving;
14497
+
14498
+ public cVector TargetLookAt()
14499
+ {
14500
+ return targetLookAt;
14501
+ }
1218214502
1218314503 class PingThread extends Thread
1218414504 {
....@@ -12318,7 +14638,7 @@
1231814638 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1231914639 if (lightMode)
1232014640 {
12321
- lighttouched = true;
14641
+ Globals.lighttouched = true;
1232214642 }
1232314643
1232414644 if (OEILONCE && OEIL)
....@@ -12335,6 +14655,7 @@
1233514655
1233614656 public void run()
1233714657 {
14658
+ new Exception().printStackTrace();
1233814659 System.exit(0);
1233914660 for (;;)
1234014661 {
....@@ -12376,7 +14697,7 @@
1237614697 mouseDown = false;
1237714698 if (lightMode)
1237814699 {
12379
- lighttouched = true;
14700
+ Globals.lighttouched = true;
1238014701 }
1238114702 repaint();
1238214703 alreadypainted = true;
....@@ -12384,7 +14705,7 @@
1238414705 isMoving = false;
1238514706 } //??
1238614707
12387
- if (isLIVE() && !alreadypainted)
14708
+ if (Globals.isLIVE() && !alreadypainted)
1238814709 {
1238914710 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1239014711 repaint();
....@@ -12396,9 +14717,9 @@
1239614717 {
1239714718 if (lightMode)
1239814719 {
12399
- lighttouched = true;
14720
+ Globals.lighttouched = true;
1240014721 }
12401
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1240214723 }
1240314724 //else
1240414725 }
....@@ -12412,12 +14733,18 @@
1241214733 void GoDown(int mod)
1241314734 {
1241414735 MODIFIERS |= COMMAND;
12415
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1241614738 if((mod&SHIFT) == SHIFT)
12417
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1241814745 else
12419
- manipCamera.BackForth(0, -speed*delta, getWidth());
12420
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1242114748 if ((mod & SHIFT) == SHIFT)
1242214749 {
1242314750 mouseMode = mouseMode; // VR??
....@@ -12426,6 +14753,8 @@
1242614753 mouseMode |= BACKFORTH;
1242714754 }
1242814755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1242914758 //prevX = X = anchorX;
1243014759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1243114760 }
....@@ -12433,12 +14762,19 @@
1243314762 void GoUp(int mod)
1243414763 {
1243514764 MODIFIERS |= COMMAND;
12436
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1243714768 if((mod&SHIFT) == SHIFT)
12438
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1243914775 else
12440
- manipCamera.BackForth(0, speed*delta, getWidth());
12441
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1244214778 if ((mod & SHIFT) == SHIFT)
1244314779 {
1244414780 mouseMode = mouseMode;
....@@ -12447,6 +14783,8 @@
1244714783 mouseMode |= BACKFORTH;
1244814784 }
1244914785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1245014788 //prevX = X = anchorX;
1245114789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1245214790 }
....@@ -12454,12 +14792,17 @@
1245414792 void GoLeft(int mod)
1245514793 {
1245614794 MODIFIERS |= COMMAND;
12457
- /*
14795
+ /**/
1245814796 if((mod&SHIFT) == SHIFT)
12459
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1246014798 else
12461
- manipCamera.Translate(speed*delta, 0, getWidth());
12462
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1246314806 if ((mod & SHIFT) == SHIFT)
1246414807 {
1246514808 mouseMode = mouseMode;
....@@ -12468,6 +14811,8 @@
1246814811 mouseMode |= ROTATE;
1246914812 } // TRANSLATE;
1247014813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1247114816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1247214817 prevY = Y = anchorY;
1247314818 }
....@@ -12475,12 +14820,18 @@
1247514820 void GoRight(int mod)
1247614821 {
1247714822 MODIFIERS |= COMMAND;
12478
- /*
14823
+ /**/
1247914824 if((mod&SHIFT) == SHIFT)
12480
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1248114826 else
12482
- manipCamera.Translate(-speed*delta, 0, getWidth());
12483
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1248414835 if ((mod & SHIFT) == SHIFT)
1248514836 {
1248614837 mouseMode = mouseMode;
....@@ -12489,6 +14840,8 @@
1248914840 mouseMode |= ROTATE;
1249014841 } // TRANSLATE;
1249114842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1249214845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1249314846 prevY = Y = anchorY;
1249414847 }
....@@ -12498,7 +14851,7 @@
1249814851 int X, Y;
1249914852 boolean SX, SY;
1250014853
12501
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1250214855 {
1250314856 if (IsFrozen())
1250414857 {
....@@ -12507,17 +14860,17 @@
1250714860
1250814861 drag = true; // NEW
1250914862
12510
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1251114864
1251214865 X = x;
1251314866 Y = y;
1251414867 // floating state for animation
12515
- MODIFIERS = modifiers;
12516
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1251714870 if (false) // modifiers != 0)
1251814871 {
1251914872 //new Exception().printStackTrace();
12520
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1252114874 System.out.println("SHIFT = " + SHIFT);
1252214875 System.out.println("CONTROL = " + COMMAND);
1252314876 System.out.println("META = " + META);
....@@ -12530,14 +14883,16 @@
1253014883 if (editObj)
1253114884 {
1253214885 drag = true;
12533
- ClickInfo info = new ClickInfo();
12534
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1253514888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12536
- info.pane = this;
12537
- info.camera = renderCamera;
12538
- info.x = x;
12539
- info.y = y;
12540
- object.editWindow.copy.doEditDrag(info);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1254114896 } else
1254214897 {
1254314898 if (x < startX)
....@@ -12639,6 +14994,7 @@
1263914994 {
1264014995 manipCamera.Translate(dx, dy, getWidth());
1264114996 }
14997
+ else
1264214998 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1264314999 {
1264415000 manipCamera.RotateInterest(dx, dy);
....@@ -12649,7 +15005,7 @@
1264915005
1265015006 if (manipCamera == lightCamera)
1265115007 {
12652
- lighttouched = true;
15008
+ Globals.lighttouched = true;
1265315009 }
1265415010 /*
1265515011 switch (mode)
....@@ -12685,23 +15041,27 @@
1268515041 }
1268615042 }
1268715043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1268815046 public void mouseMoved(MouseEvent e)
1268915047 {
1269015048 //System.out.println("mouseMoved: " + e);
12691
-
1269215049 if (isRenderer)
1269315050 return;
1269415051
12695
- ClickInfo ci = new ClickInfo();
12696
- ci.x = e.getX();
12697
- ci.y = e.getY();
12698
- ci.modifiers = e.getModifiersEx();
12699
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12700
- ci.pane = this;
12701
- ci.camera = renderCamera;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1270215059 if (!isRenderer)
1270315060 {
12704
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1270515065 {
1270615066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1270715067 } else
....@@ -12713,7 +15073,11 @@
1271315073
1271415074 public void mouseReleased(MouseEvent e)
1271515075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1271615078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1271715081 //System.out.println("mouseReleased: " + e);
1271815082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1271915083 }
....@@ -12736,9 +15100,9 @@
1273615100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1273715101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1273815102
12739
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1274015104 timeout = true;
12741
- else
15105
+// ?? May 2019 else
1274215106 // timer.setDelay((modifiers & 128) != 0?0:350);
1274315107 mouseDown = false;
1274415108 if (!control && !command) // june 2013
....@@ -12848,7 +15212,7 @@
1284815212 System.out.println("keyReleased: " + e);
1284915213 }
1285015214
12851
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1285215216 {
1285315217 //System.out.println("SetMouseMode = " + modifiers);
1285415218 //modifiers &= ~1024;
....@@ -12860,25 +15224,25 @@
1286015224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1286115225 // return;
1286215226 //System.out.println("SetMode = " + modifiers);
12863
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1286415228 {
1286515229 mouseMode |= ZOOM;
1286615230 }
1286715231
1286815232 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
12869
- if (capsLocked || (modifiers & META) == META)
15233
+ if (capsLocked) // || (modifiers & META) == META)
1287015234 {
1287115235 mouseMode |= VR; // BACKFORTH;
1287215236 }
12873
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12874
- {
12875
- mouseMode |= SELECT; // BACKFORTH;
12876
- }
12877
- if ((modifiers & COMMAND) == COMMAND)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1287815238 {
1287915239 mouseMode |= SELECT;
1288015240 }
12881
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
15242
+ {
15243
+ mouseMode |= SELECT;
15244
+ }
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1288215246 {
1288315247 mouseMode &= ~VR;
1288415248 mouseMode |= TRANSLATE;
....@@ -12907,10 +15271,10 @@
1290715271
1290815272 if (isRenderer) //
1290915273 {
12910
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1291115275 }
1291215276
12913
- theRenderer.keyPressed(key);
15277
+ Globals.theRenderer.keyPressed(key);
1291415278 }
1291515279
1291615280 int kompactbit = 4; // power bit
....@@ -12922,7 +15286,7 @@
1292215286 float SATPOW = 1; // 2; // 0.5f;
1292315287 float BRIPOW = 1; // 0.5f; // 0.5f;
1292415288
12925
- void keyPressed(int key)
15289
+ public void keyPressed(int key)
1292615290 {
1292715291 if (key >= '0' && key <= '5')
1292815292 clampbit = (key-'0');
....@@ -12969,7 +15333,8 @@
1296915333 // break;
1297015334 case 'T':
1297115335 CACHETEXTURE ^= true;
12972
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1297315338 // repaint();
1297415339 break;
1297515340 case 'Y':
....@@ -12979,8 +15344,8 @@
1297915344 case 'K':
1298015345 KOMPACTTEXTURE ^= true;
1298115346 //textures.clear();
12982
- break;
12983
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1298415349 // SAVETEXTURE ^= true;
1298515350 macromode = true;
1298615351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -13037,7 +15402,7 @@
1303715402 case 'B':
1303815403 BRISMOOTH ^= true;
1303915404 SHADOWCULLFACE ^= true;
13040
- lighttouched = true;
15405
+ Globals.lighttouched = true;
1304115406 repaint();
1304215407 break;
1304315408 case 'b':
....@@ -13054,7 +15419,9 @@
1305415419 case 'E' : COMPACT ^= true;
1305515420 repaint();
1305615421 break;
13057
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1305815425 repaint();
1305915426 break;
1306015427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13079,8 +15446,8 @@
1307915446 RevertCamera();
1308015447 repaint();
1308115448 break;
13082
- case 'L':
1308315449 case 'l':
15450
+ //case 'L':
1308415451 if (lightMode)
1308515452 {
1308615453 lightMode = false;
....@@ -13099,7 +15466,7 @@
1309915466 targetLookAt.set(manipCamera.lookAt);
1310015467 repaint();
1310115468 break;
13102
- case 'p':
15469
+ case 'P': // p':
1310315470 // c'est quoi ca au juste? spherical ^= true;
1310415471 Skinshader ^= true; programInitialized = false;
1310515472 repaint();
....@@ -13137,27 +15504,31 @@
1313715504 repaint();
1313815505 break;
1313915506 case 'O':
13140
- drawMode = OCCLUSION;
15507
+ Globals.drawMode = OCCLUSION; // WARNING
1314115508 repaint();
1314215509 break;
1314315510 case 'o':
1314415511 OCCLUSION_CULLING ^= true;
1314515512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1314615513 break;
13147
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1314815515 case '1':
1314915516 case '2':
1315015517 case '3':
1315115518 case '4':
1315215519 case '5':
13153
- newenvy = Character.getNumericValue(key);
13154
- repaint();
13155
- break;
1315615520 case '6':
1315715521 case '7':
1315815522 case '8':
1315915523 case '9':
13160
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1316115532 repaint();
1316215533 break;
1316315534 case '!':
....@@ -13223,12 +15594,12 @@
1322315594 case '_':
1322415595 kompactbit = 5;
1322515596 break;
13226
- case '+':
13227
- kompactbit = 6;
13228
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1322915600 case ' ':
1323015601 lightMode ^= true;
13231
- lighttouched = true;
15602
+ Globals.lighttouched = true;
1323215603 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1323315604 targetLookAt.set(manipCamera.lookAt);
1323415605 repaint();
....@@ -13237,14 +15608,15 @@
1323715608 case ESC:
1323815609 RENDERPROGRAM += 1;
1323915610 RENDERPROGRAM %= 3;
15611
+
1324015612 repaint();
1324115613 break;
1324215614 case 'Z':
13243
- RESIZETEXTURE ^= true;
13244
- break;
15615
+ //RESIZETEXTURE ^= true;
15616
+ //break;
1324515617 case 'z':
13246
- RENDERSHADOW ^= true;
13247
- lighttouched = true;
15618
+ Globals.RENDERSHADOW ^= true;
15619
+ Globals.lighttouched = true;
1324815620 repaint();
1324915621 break;
1325015622 //case UP:
....@@ -13276,8 +15648,9 @@
1327615648 case DELETE:
1327715649 ClearSelection();
1327815650 break;
13279
- /*
1328015651 case '+':
15652
+
15653
+ /*
1328115654 //fontsize += 1;
1328215655 bbzoom *= 2;
1328315656 repaint();
....@@ -13294,17 +15667,17 @@
1329415667 case '=':
1329515668 IncDepth();
1329615669 //fontsize += 1;
13297
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1329815671 maskbit = 6;
1329915672 break;
1330015673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1330115674 DecDepth();
1330215675 maskbit = 5;
1330315676 //if(fontsize > 1) fontsize -= 1;
13304
- if (object.editWindow == null)
13305
- new Exception().printStackTrace();
13306
- else
13307
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1330815681 break;
1330915682 case '{':
1331015683 manipCamera.shaper_fovy /= 1.1;
....@@ -13359,6 +15732,7 @@
1335915732 }
1336015733 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1336115734 }
15735
+
1336215736 static double OCCLUSIONBOOST = 1; // 0.5;
1336315737
1336415738 void keyReleased(int key, int modifiers)
....@@ -13366,11 +15740,11 @@
1336615740 //mode = ROTATE;
1336715741 if ((MODIFIERS & COMMAND) == 0) // VR??
1336815742 {
13369
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1337015744 }
1337115745 }
1337215746
13373
- protected void processKeyEvent(KeyEvent e)
15747
+ public void processKeyEvent(KeyEvent e)
1337415748 {
1337515749 switch (e.getID())
1337615750 {
....@@ -13500,8 +15874,9 @@
1350015874
1350115875 protected void processMouseMotionEvent(MouseEvent e)
1350215876 {
13503
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13504
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15877
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15878
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1350515880 {
1350615881 mouseMoved(e);
1350715882 } else
....@@ -13526,11 +15901,12 @@
1352615901 }
1352715902 */
1352815903
13529
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1353015905 }
1353115906
1353215907 void SelectParent()
1353315908 {
15909
+ new Exception().printStackTrace();
1353415910 System.exit(0);
1353515911 Composite group = (Composite) object;
1353615912 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13542,10 +15918,10 @@
1354215918 {
1354315919 //selectees.remove(i);
1354415920 System.out.println("select parent of " + elem);
13545
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1354615922 } else
1354715923 {
13548
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1354915925 }
1355015926
1355115927 first = false;
....@@ -13554,6 +15930,7 @@
1355415930
1355515931 void SelectChildren()
1355615932 {
15933
+ new Exception().printStackTrace();
1355715934 System.exit(0);
1355815935 /*
1355915936 Composite group = (Composite) object;
....@@ -13586,12 +15963,12 @@
1358615963 for (int j = 0; j < group.children.size(); j++)
1358715964 {
1358815965 elem = (Object3D) group.children.elementAt(j);
13589
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1359015967 first = false;
1359115968 }
1359215969 } else
1359315970 {
13594
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1359515972 }
1359615973
1359715974 first = false;
....@@ -13602,21 +15979,21 @@
1360215979 {
1360315980 //Composite group = (Composite) object;
1360415981 Object3D group = object;
13605
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1360615983 }
1360715984
1360815985 void ResetTransform(int mask)
1360915986 {
1361015987 //Composite group = (Composite) object;
1361115988 Object3D group = object;
13612
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1361315990 }
1361415991
1361515992 void FlipTransform()
1361615993 {
1361715994 //Composite group = (Composite) object;
1361815995 Object3D group = object;
13619
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1362015997 // group.editWindow.ReduceMesh(true);
1362115998 }
1362215999
....@@ -13624,7 +16001,7 @@
1362416001 {
1362516002 //Composite group = (Composite) object;
1362616003 Object3D group = object;
13627
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1362816005 // group.editWindow.ReduceMesh(true);
1362916006 }
1363016007
....@@ -13632,7 +16009,7 @@
1363216009 {
1363316010 //Composite group = (Composite) object;
1363416011 Object3D group = object;
13635
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1363616013 }
1363716014
1363816015 void IncDepth()
....@@ -13714,11 +16091,11 @@
1371416091
1371516092 int width = getBounds().width;
1371616093 int height = getBounds().height;
13717
- ClickInfo info = new ClickInfo();
13718
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1371916094 //Image img = CreateImage(width, height);
1372016095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1372116097 Graphics gr = g; // img.getGraphics();
16098
+
1372216099 if (!hasMarquee)
1372316100 {
1372416101 if (Xmin < Xmax) // !locked)
....@@ -13790,44 +16167,92 @@
1379016167 }
1379116168 if (object != null && !hasMarquee)
1379216169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1379316176 if (isRenderer)
1379416177 {
13795
- info.flags++;
16178
+ object.clickInfo.flags++;
1379616179 double frameAspect = (double) width / (double) height;
1379716180 if (frameAspect > renderCamera.aspect)
1379816181 {
1379916182 int desired = (int) ((double) height * renderCamera.aspect);
13800
- info.bounds.width -= width - desired;
13801
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1380216185 } else
1380316186 {
1380416187 int desired = (int) ((double) width / renderCamera.aspect);
13805
- info.bounds.height -= height - desired;
13806
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1380716190 }
1380816191 }
13809
- info.g = gr;
13810
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1381116195 /*
1381216196 // Memory intensive (brep.verticescopy)
1381316197 if (!(object instanceof Composite))
1381416198 object.draw(info, 0, false); // SLOW :
1381516199 */
13816
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1381716201 {
13818
- object.drawEditHandles(info, 0);
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
16205
+ {
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
16212
+ {
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
16220
+ }
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
16241
+ }
1381916242 }
1382016243 }
16244
+
1382116245 if (isRenderer)
1382216246 {
1382316247 //gr.setColor(Color.black);
1382416248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1382516249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1382616250 }
16251
+
1382716252 if (hasMarquee)
1382816253 {
1382916254 gr.setXORMode(Color.white);
13830
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1383116256 if (!firstime)
1383216257 {
1383316258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -13846,6 +16271,7 @@
1384616271 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1384716272 }
1384816273
16274
+ // To avoid clear.
1384916275 public void update(Graphics g)
1385016276 {
1385116277 paint(g);
....@@ -13935,6 +16361,7 @@
1393516361 public boolean mouseDown(Event evt, int x, int y)
1393616362 {
1393716363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1393816365 /*
1393916366 locked = true;
1394016367 drag = false;
....@@ -13978,7 +16405,7 @@
1397816405 {
1397916406 keyPressed(0, modifiers);
1398016407 }
13981
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1398216409 return true;
1398316410 }
1398416411
....@@ -14096,7 +16523,7 @@
1409616523 {
1409716524 keyReleased(0, 0);
1409816525 }
14099
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1410016527 return true;
1410116528 }
1410216529
....@@ -14228,7 +16655,7 @@
1422816655 Object3D object;
1422916656 static Object3D trackedobject;
1423016657 Camera renderCamera; // Light or Eye (or Occlusion)
14231
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1423216659 /*static*/ Camera eyeCamera;
1423316660 /*static*/ Camera lightCamera;
1423416661 int cameracount;
....@@ -14292,6 +16719,8 @@
1429216719 private /*static*/ boolean firstime;
1429316720 private /*static*/ cVector newView = new cVector();
1429416721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1429516724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1429616725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1429716726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14304,29 +16733,67 @@
1430416733 {
1430516734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1430616735
16736
+ int usedsuf = 0;
16737
+
1430716738 for (int i = 0; i < suffixes.length; i++)
1430816739 {
14309
- String resourceName = basename + suffixes[i] + "." + suffix;
14310
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14311
- mipmapped,
14312
- FileUtil.getFileSuffix(resourceName));
14313
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1431416745 {
14315
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1431616750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1431716779 //System.out.println("Target = " + targets[i]);
1431816780 cubemap.updateImage(data, targets[i]);
1431916781 }
1432016782
1432116783 return cubemap;
1432216784 }
16785
+
1432316786 int bigsphere = -1;
1432416787
1432516788 float BGcolor = 0.5f;
1432616789
14327
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1432816793 {
14329
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1433016797 {
1433116798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1433216799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14341,7 +16808,17 @@
1434116808 // Compensates for ExaminerViewer's modification of modelview matrix
1434216809 gl.glMatrixMode(GL.GL_MODELVIEW);
1434316810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1434416812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1434516822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1434616823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1434716824
....@@ -14373,6 +16850,7 @@
1437316850 {
1437416851 gl.glScalef(1.0f, -1.0f, 1.0f);
1437516852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1437616854 gl.glMultMatrixd(viewrot_1, 0);
1437716855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1437816856 //viewer.updateInverseRotation(gl);
....@@ -14413,7 +16891,8 @@
1441316891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1441416892
1441516893 cubemap.disable();
14416
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1441716896 if (CULLFACE)
1441816897 {
1441916898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -14469,7 +16948,7 @@
1446916948 gl.glScalef(1.0f, -1.0f, 1.0f);
1447016949 }
1447116950
14472
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1447316952
1447416953 float step = 2; // 0.1666f; //0.25f;
1447516954 float stepv = 2; // step * 1652 / 998;
....@@ -14508,20 +16987,21 @@
1450816987 /**/
1450916988 //checker.GetMaterial().opacity = 1.1f;
1451016989 ////checker.GetMaterial().ambient = 0.99f;
14511
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14512
- Object3D.selectedstack[Object3D.materialdepth] = false;
14513
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16990
+ materialstack[materialdepth] = checker.material;
16991
+ selectedstack[materialdepth] = false;
16992
+ cStatic.objectstack[materialdepth++] = checker;
1451416993 //System.out.println("material " + material);
1451516994 //Applet3D.tracein(this, selected);
14516
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1451716996
14518
- checker.GetMaterial().Draw(this, false); // true);
16997
+ //checker.GetMaterial().Draw(this, false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1451916999
14520
- Object3D.materialdepth -= 1;
14521
- if (Object3D.materialdepth > 0)
17000
+ materialdepth -= 1;
17001
+ if (materialdepth > 0)
1452217002 {
14523
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14524
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
17003
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17004
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1452517005 }
1452617006 //checker.GetMaterial().opacity = 1f;
1452717007 ////checker.GetMaterial().ambient = 1f;
....@@ -14607,6 +17087,14 @@
1460717087 }
1460817088 }
1460917089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1461017098 class SelectBuffer implements GLEventListener
1461117099 {
1461217100
....@@ -14622,7 +17110,7 @@
1462217110 //new Exception().printStackTrace();
1462317111 System.out.println("select buffer init");
1462417112 // Use debug pipeline
14625
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1462617114
1462717115 GL gl = drawable.getGL();
1462817116
....@@ -14665,6 +17153,7 @@
1466517153 {
1466617154 if (!selection)
1466717155 {
17156
+ new Exception().printStackTrace();
1466817157 System.exit(0);
1466917158 return;
1467017159 }
....@@ -14685,17 +17174,39 @@
1468517174
1468617175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1468717176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1468817188 //int tmp = selection_view;
1468917189 //selection_view = -1;
14690
- int temp = drawMode;
14691
- drawMode = SELECTION;
17190
+ int temp = DrawMode();
17191
+ Globals.drawMode = SELECTION; // WARNING
1469217192 indexcount = 0;
1469317193 parent.display(drawable);
1469417194 //selection_view = tmp;
1469517195 //if (temp == SELECTION)
1469617196 // temp = DEFAULT; // patch for selection debug
14697
- drawMode = temp;
17197
+ Globals.drawMode = temp; // WARNING
1469817198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1469917210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1470017211
1470117212 // trying different ways of getting the depth info over
....@@ -14743,6 +17254,8 @@
1474317254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1474417255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1474517256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1474617259
1474717260 // Will fit the mesh !!!
1474817261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -14792,34 +17305,36 @@
1479217305 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]));
1479317306 }
1479417307
14795
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1479617309 }
1479717310 }
1479817311
1479917312 if (!movingcamera && !PAINTMODE)
14800
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1480117314
14802
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1480317316 {
14804
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1480517318
14806
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1480717322
14808
- group.CreateMaterial(); // use a void leaf to select instances
14809
-
14810
- group.add(paintobj); // link
14811
-
14812
- object.editWindow.SnapObject(group);
14813
-
14814
- Object3D folder = object.editWindow.copy;
14815
-
14816
- if (object.editWindow.copy.selection.Size() > 0)
14817
- folder = object.editWindow.copy.selection.elementAt(0);
14818
-
14819
- folder.add(group);
14820
-
14821
- object.editWindow.ResetModel();
14822
- object.editWindow.refreshContents();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1482317338 }
1482417339 else
1482517340 paintcount = 0;
....@@ -14858,6 +17373,11 @@
1485817373 //System.out.println("objects[color] = " + objects[color]);
1485917374 //objects[color].Select();
1486017375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1486117381 object.Select(color, deselect);
1486217382 }
1486317383
....@@ -14908,6 +17428,7 @@
1490817428
1490917429 public void init(GLAutoDrawable drawable)
1491017430 {
17431
+ if (Globals.DEBUG)
1491117432 System.out.println("shadow buffer init");
1491217433
1491317434 GL gl = drawable.getGL();
....@@ -14957,7 +17478,7 @@
1495717478 gl.glDisable(gl.GL_CULL_FACE);
1495817479 }
1495917480
14960
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1496117482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1496217483
1496317484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14967,14 +17488,14 @@
1496717488 //gl.glColorMask(false, false, false, false);
1496817489
1496917490 //render_scene_from_light_view(gl, drawable, 0, 0);
14970
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1497117492 {
1497217493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1497317494
14974
- int temp = drawMode;
14975
- drawMode = SHADOW;
17495
+ int temp = DrawMode();
17496
+ Globals.drawMode = SHADOW; // WARNING
1497617497 parent.display(drawable);
14977
- drawMode = temp;
17498
+ Globals.drawMode = temp; // WARNING
1497817499 }
1497917500
1498017501 gl.glCullFace(gl.GL_BACK);
....@@ -15027,7 +17548,6 @@
1502717548
1502817549 class AntialiasBuffer implements GLEventListener
1502917550 {
15030
-
1503117551 CameraPane parent = null;
1503217552
1503317553 AntialiasBuffer(CameraPane p)
....@@ -15137,10 +17657,14 @@
1513717657 gl.glFlush();
1513817658
1513917659 /**/
15140
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1514117661
15142
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1514317663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1514417668 double r = 0, g = 0, b = 0;
1514517669
1514617670 double count = 0;
....@@ -15151,7 +17675,7 @@
1515117675
1515217676 double FACTOR = 1;
1515317677
15154
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1515517679 {
1515617680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1515717681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15234,7 +17758,7 @@
1523417758
1523517759 double scale = ray.z; // 1; // cos
1523617760
15237
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1523817762
1523917763 /*
1524017764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15372,12 +17896,6 @@
1537217896 GLUT glut = new GLUT();
1537317897
1537417898
15375
- static final public int DEFAULT = 0;
15376
- static final public int SELECTION = 1;
15377
- static final public int SHADOW = 2;
15378
- static final public int OCCLUSION = 3;
15379
- static
15380
- public int drawMode = DEFAULT;
1538117899 public boolean spherical = false;
1538217900 static boolean DEBUG_OCCLUSION = false;
1538317901 static boolean DEBUG_SELECTION = false;
....@@ -15390,23 +17908,15 @@
1539017908 int AAbuffersize = 0;
1539117909
1539217910 //double[] selectedpoint = new double[3];
15393
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1539417912 static Sphere previousselectedpoint = null;
15395
- static Sphere debugpointG = new Sphere();
15396
- static Sphere debugpointP = new Sphere();
15397
- static Sphere debugpointC = new Sphere();
15398
- static Sphere debugpointR = new Sphere();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1539917917
1540017918 static Sphere debugpoints[] = new Sphere[8];
1540117919
15402
- static
15403
- {
15404
- for (int i=0; i<8; i++)
15405
- {
15406
- debugpoints[i] = new Sphere();
15407
- }
15408
- }
15409
-
1541017920 static void InitPoints(float radius)
1541117921 {
1541217922 for (int i=0; i<8; i++)
....@@ -15426,7 +17936,7 @@
1542617936 }
1542717937 }
1542817938
15429
- static void DrawPoints(CameraPane cpane)
17939
+ static void DrawPoints(iCameraPane cpane)
1543017940 {
1543117941 for (int i=0; i<8; i++) // first and last are red
1543217942 {
....@@ -15445,11 +17955,14 @@
1544517955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1544617956 static IntBuffer bigAAbuffer;
1544717957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15448
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1544917959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1545017960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1545117961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
15452
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1545317966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1545417967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1545517968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15458,10 +17971,11 @@
1545817971 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1545917972 // Depth buffer format
1546017973 //private int depth_format;
15461
- static public void NextIndex(Object3D o, GL gl)
17974
+
17975
+ public void NextIndex()
1546217976 {
1546317977 indexcount+=16;
15464
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17978
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1546517979 //objects[indexcount] = o;
1546617980 //System.out.println("indexcount = " + indexcount);
1546717981 }