Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,10 +33,14 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
34
-class CameraPane extends GLCanvas implements Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
38
+class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
36
- static boolean DEBUG = false;
40
+ static cMaterial[] materialstack = new cMaterial[65536];
41
+ static boolean[] selectedstack = new boolean[65536];
42
+ static int materialdepth = 0;
43
+
3744 static boolean FRUSTUM = false; // still bogus true; // frustum culling
3845
3946 // camera change fix
....@@ -42,25 +49,40 @@
4249
4350 static int STEP = 1;
4451
45
- static boolean ONESTEP = false; // do LIVE once
46
-
47
- /**
48
- * @return the LIVE
49
- */
50
- public static boolean isLIVE()
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
5153 {
52
- return LIVE || ONESTEP;
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
5383 }
5484
55
- /**
56
- * @param aLIVE the LIVE to set
57
- */
58
- public static void setLIVE(boolean aLIVE)
59
- {
60
- LIVE = aLIVE;
61
- }
62
-
63
- /*static*/ boolean CULLFACE = false; // true;
85
+ /*static*/ private boolean CULLFACE = false; // true;
6486 /*static*/ boolean NEAREST = false; // true;
6587 /*static*/ boolean WIREFRAME = false; // true;
6688
....@@ -70,14 +92,12 @@
7092 static int CURRENTANTIALIAS = 0; // 1;
7193 /*static*/ boolean RENDERSHADOW = true;
7294 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
73
- static boolean ANIMATION = false;
74
- static String filename;
7595
7696 boolean DISPLAYTEXT = false;
7797 //boolean REDUCETEXTURE = true;
7898 boolean CACHETEXTURE = true;
7999 boolean CLEANCACHE = false; // true;
80
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
81101 boolean COMPRESSTEXTURE = false;
82102 boolean KOMPACTTEXTURE = false; // true;
83103 boolean RESIZETEXTURE = false;
....@@ -90,17 +110,17 @@
90110 //private Mat4f spotlightTransform = new Mat4f();
91111 //private Mat4f spotlightInverseTransform = new Mat4f();
92112 static GLContext glcontext = null;
93
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
94116 boolean reverseUP = false;
95117 static boolean frozen = false;
96118 boolean enablebackspace = false; // patch for back buffer refresh
97119
98120 static boolean textureon = true;
99121 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101122 static boolean FULLSCREEN = false;
102123 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104124 static boolean INERTIA = true;
105125 static boolean FAST = false;
106126 static boolean SLOWPOSE = false;
....@@ -108,6 +128,8 @@
108128
109129 static int tickcount = 0; // slow pose issue
110130
131
+static boolean BUTTONLESSWHEEL = false;
132
+static boolean ZOOMBOXMODE = false;
111133 static boolean BOXMODE = false;
112134 static boolean IMAGEFLIP = false;
113135 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +144,7 @@
122144 static boolean OEIL = true;
123145 static boolean OEILONCE = false; // do oeilon then oeiloff
124146 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
147
+static boolean SWITCH = true; // false;
126148 static boolean HANDLES = false; // selection doesn't work!!
127149 static boolean PAINTMODE = false;
128150
....@@ -153,7 +175,7 @@
153175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
154176 boolean anisotropy = true;
155177 boolean softshadow = true; // slower but better false;
156
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
157179
158180 boolean macromode = false;
159181
....@@ -165,12 +187,55 @@
165187 defaultcaps.setAccumBlueBits(16);
166188 defaultcaps.setAccumAlphaBits(16);
167189 }
168
- static CameraPane theRenderer;
190
+
191
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
169192
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
205
+
170206 void SetAsGLRenderer(boolean b)
171207 {
172208 isRenderer = b;
173
- theRenderer = this;
209
+ Globals.theRenderer = this;
210
+ }
211
+
212
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
213
+ {
214
+ super(defaultcaps, null, withcontext?glcontext:null, null);
215
+
216
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
217
+ glcontext = getContext();
218
+
219
+ cameras = new Camera[2];
220
+ targetLookAts = new cVector[2];
221
+
222
+ SetCamera(cam);
223
+
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
226
+
227
+ object = o;
228
+
229
+ setBackground(Color.white);
230
+
231
+ addKeyListener(this);
232
+ addMouseListener(this);
233
+ addMouseMotionListener(this);
234
+ addMouseWheelListener(this);
235
+ //System.out.println("addGLEventListener: " + this);
236
+ addGLEventListener(this);
237
+
238
+// pingthread.start(); // may 2013
174239 }
175240
176241 static boolean AntialiasingEnabled()
....@@ -178,12 +243,53 @@
178243 return CURRENTANTIALIAS > 0;
179244 }
180245
181
- void ClearDepth()
246
+ /// INTERFACE
247
+
248
+ public javax.media.opengl.GL GetGL0()
249
+ {
250
+ return null;
251
+ }
252
+
253
+ public int GenList()
254
+ {
255
+ javax.media.opengl.GL gl = GetGL();
256
+ return gl.glGenLists(1);
257
+ }
258
+
259
+ public void NewList(int id)
260
+ {
261
+ javax.media.opengl.GL gl = GetGL();
262
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
263
+ }
264
+
265
+ public void CallList(int id)
266
+ {
267
+ javax.media.opengl.GL gl = GetGL();
268
+ gl.glCallList(id);
269
+ }
270
+
271
+ public void EndList()
272
+ {
273
+ javax.media.opengl.GL gl = GetGL();
274
+ gl.glEndList();
275
+ }
276
+
277
+ public boolean IsBoxMode()
278
+ {
279
+ return BOXMODE;
280
+ }
281
+
282
+ public boolean IsZoomBoxMode()
283
+ {
284
+ return ZOOMBOXMODE;
285
+ }
286
+
287
+ public void ClearDepth()
182288 {
183289 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184290 }
185291
186
- void DepthTest(boolean depthtest)
292
+ public void DepthTest(boolean depthtest)
187293 {
188294 if (depthtest)
189295 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +297,7 @@
191297 GetGL().glDepthFunc(GL.GL_ALWAYS);
192298 }
193299
194
- void DepthWrite(boolean depthwrite)
300
+ public void DepthWrite(boolean depthwrite)
195301 {
196302 if (depthwrite)
197303 GetGL().glDepthMask(true);
....@@ -199,12 +305,1616 @@
199305 GetGL().glDepthMask(false);
200306 }
201307
202
- void BackFaceCull(boolean bfc)
308
+ public void BackFaceCull(boolean bfc)
203309 {
204310 if (bfc)
205311 GetGL().glEnable(GetGL().GL_CULL_FACE);
206312 else
207313 GetGL().glDisable(GetGL().GL_CULL_FACE);
314
+ }
315
+
316
+ public boolean BackFaceCullMode()
317
+ {
318
+ return this.CULLFACE;
319
+ }
320
+
321
+ public boolean IsAmbientOcclusionOn()
322
+ {
323
+ return this.ambientOcclusion;
324
+ }
325
+
326
+ public boolean IsDebugSelection()
327
+ {
328
+ return DEBUG_SELECTION;
329
+ }
330
+
331
+ public boolean IsFrozen()
332
+ {
333
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
334
+
335
+ return !selectmode && cameracount == 0; // != 0;
336
+ }
337
+
338
+ // Currently in Globals
339
+ public int DrawMode()
340
+ {
341
+ return Globals.DrawMode();
342
+ }
343
+
344
+ public Camera EyeCamera()
345
+ {
346
+ return eyeCamera;
347
+ }
348
+
349
+ public Camera LightCamera()
350
+ {
351
+ return lightCamera;
352
+ }
353
+
354
+ public Camera ManipCamera()
355
+ {
356
+ return manipCamera;
357
+ }
358
+
359
+ public Camera RenderCamera()
360
+ {
361
+ return renderCamera;
362
+ }
363
+
364
+ public Camera[] Cameras()
365
+ {
366
+ return cameras;
367
+ }
368
+
369
+ public void PushMaterial(Object3D obj, boolean selected)
370
+ {
371
+ CameraPane display = this;
372
+ javax.media.opengl.GL gl = display.GetGL();
373
+ cMaterial material = obj.material;
374
+
375
+ if (material != null)
376
+ {
377
+ materialstack[materialdepth] = material;
378
+ selectedstack[materialdepth] = selected;
379
+ cStatic.objectstack[materialdepth++] = obj;
380
+ //System.out.println("material " + material);
381
+ //Applet3D.tracein(this, selected);
382
+ //display.vector2buffer = obj.projectedVertices;
383
+ if (obj instanceof Camera)
384
+ {
385
+ display.options1[0] = material.shift;
386
+ //System.out.println("shift " + material.shift);
387
+ display.options1[1] = material.lightarea;
388
+ display.options1[2] = material.shadowbias;
389
+ display.options1[3] = material.aniso;
390
+ display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
396
+ display.options2[0] = material.opacity;
397
+ display.options2[1] = material.diffuse;
398
+ display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
402
+
403
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
407
+ display.options4[0] = material.cameralight/0.2f;
408
+ display.options4[1] = material.subsurface;
409
+ display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
413
+
414
+ // if (display.CURRENTANTIALIAS > 0)
415
+ // display.options3[3] /= 4;
416
+
417
+ /*
418
+ System.out.println("Focus = " + display.options1[0]);
419
+ System.out.println("Aperture = " + display.options1[1]);
420
+ System.out.println("ShadowBlur = " + display.options1[2]);
421
+ System.out.println("Antialiasing = " + display.options1[3]);
422
+ System.out.println("Fog = " + display.options2[0]);
423
+ System.out.println("Intensity = " + display.options2[1]);
424
+ System.out.println("Elevation = " + display.options2[2]);
425
+ /**/
426
+ } else
427
+ {
428
+ DrawMaterial(material, selected, obj.projectedVertices);
429
+ }
430
+ } else
431
+ {
432
+ if (selected && CameraPane.flash)
433
+ {
434
+ display.modelParams4[1] = 100;
435
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
436
+ }
437
+ }
438
+ }
439
+
440
+ public void PushMaterial2(Object3D obj, boolean selected)
441
+ {
442
+ CameraPane display = this;
443
+ cMaterial material = obj.material;
444
+
445
+ if (material != null)
446
+ {
447
+ materialstack[materialdepth] = material;
448
+ selectedstack[materialdepth] = selected;
449
+ cStatic.objectstack[materialdepth++] = obj;
450
+ //System.out.println("material " + material);
451
+ //Applet3D.tracein("selected ", selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
454
+ }
455
+ }
456
+
457
+ public void PopMaterial(Object3D obj, boolean selected)
458
+ {
459
+ CameraPane display = this;
460
+ javax.media.opengl.GL gl = display.GetGL();
461
+ cMaterial material = obj.material;
462
+
463
+ //if (parent != null && parent.GetMaterial() != null)
464
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
465
+ if (material != null)
466
+ {
467
+ materialdepth -= 1;
468
+ if (materialdepth > 0)
469
+ {
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
472
+ }
473
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
474
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
475
+ {
476
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
477
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
478
+ }
479
+ }
480
+
481
+ public void PopMaterial2(Object3D obj)
482
+ {
483
+ CameraPane display = this;
484
+ cMaterial material = obj.material;
485
+
486
+ if (material != null)
487
+ {
488
+ materialdepth -= 1;
489
+ if (materialdepth > 0)
490
+ {
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
493
+ }
494
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
495
+ //else
496
+ //material.Draw(display, false);
497
+ }
498
+ }
499
+
500
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
501
+ {
502
+ CameraPane display = this;
503
+
504
+ if (pv.y == -10000 ||
505
+ qv.y == -10000 ||
506
+ rv.y == -10000)
507
+ return;
508
+
509
+// float b = f.nbiterations & 1;
510
+// float g = (f.nbiterations>>1) & 1;
511
+// float r = (f.nbiterations>>2) & 1;
512
+//
513
+// //if (f.weight == 10000)
514
+// //{
515
+// // r = 1; g = b = 0;
516
+// //}
517
+// //else
518
+// //{
519
+// // assert(f.weight < 10000);
520
+// r = g = b = (float)bRep.FaceWeight(f)*100;
521
+// if (r<0)
522
+// assert(r>=0);
523
+// //}
524
+
525
+ javax.media.opengl.GL gl = display.GetGL();
526
+
527
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
528
+
529
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
530
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
531
+ {
532
+ //gl.glBegin(gl.GL_TRIANGLES);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
536
+ if (!hasnorm)
537
+ {
538
+ // System.out.println("Mesh normal");
539
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
540
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
541
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
542
+ LA.vecNormalize(obj.v2);
543
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
544
+ }
545
+
546
+ // P
547
+ float x = (float)pv.x;
548
+ float y = (float)pv.y;
549
+ float z = (float)pv.z;
550
+
551
+ if (hasnorm)
552
+ {
553
+// if (!pv.norm.normalized())
554
+// assert(pv.norm.normalized());
555
+
556
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
557
+ float nx = (float)pv.norm.x;
558
+ float ny = (float)pv.norm.y;
559
+ float nz = (float)pv.norm.z;
560
+
561
+ x += nx * obj.NORMALPUSH;
562
+ y += ny * obj.NORMALPUSH;
563
+ z += nz * obj.NORMALPUSH;
564
+
565
+ gl.glNormal3f(nx, ny, nz);
566
+ }
567
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
568
+ SetColor(obj, pv);
569
+ //gl.glColor4f(r, g, b, 1);
570
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
571
+ if (obj.flipV)
572
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
573
+ else
574
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
575
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
576
+
577
+ gl.glVertex3f(x, y, z);
578
+
579
+ // Q
580
+ x = (float)qv.x;
581
+ y = (float)qv.y;
582
+ z = (float)qv.z;
583
+
584
+// Print(pv);
585
+ if (hasnorm)
586
+ {
587
+// assert(qv.norm.normalized());
588
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
589
+ float nx = (float)qv.norm.x;
590
+ float ny = (float)qv.norm.y;
591
+ float nz = (float)qv.norm.z;
592
+
593
+ x += nx * obj.NORMALPUSH;
594
+ y += ny * obj.NORMALPUSH;
595
+ z += nz * obj.NORMALPUSH;
596
+
597
+ gl.glNormal3f(nx, ny, nz);
598
+ }
599
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
600
+ // boolean locked = false;
601
+ // float eps = 0.1f;
602
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
603
+
604
+ // int dot = 0; //*/ (int)f.dot;
605
+
606
+ // if ((dot&1) == 0)
607
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
608
+
609
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
610
+ if (obj.flipV)
611
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
612
+ else
613
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
614
+ // else
615
+ // {
616
+ // locked = true;
617
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
618
+ // }
619
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
620
+ SetColor(obj, qv);
621
+
622
+ gl.glVertex3f(x, y, z);
623
+ //gl.glColor4f(r, g, b, 1);
624
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
625
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
626
+// Print(qv);
627
+
628
+ // R
629
+ x = (float)rv.x;
630
+ y = (float)rv.y;
631
+ z = (float)rv.z;
632
+
633
+ if (hasnorm)
634
+ {
635
+// assert(rv.norm.normalized());
636
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
637
+ float nx = (float)rv.norm.x;
638
+ float ny = (float)rv.norm.y;
639
+ float nz = (float)rv.norm.z;
640
+
641
+ x += nx * obj.NORMALPUSH;
642
+ y += ny * obj.NORMALPUSH;
643
+ z += nz * obj.NORMALPUSH;
644
+
645
+ gl.glNormal3f(nx, ny, nz);
646
+ }
647
+
648
+ // if ((dot&4) == 0)
649
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
650
+
651
+ // if (wrap || !locked && (dot&8) != 0)
652
+ if (obj.flipV)
653
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
654
+ else
655
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
656
+ // else
657
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
658
+
659
+ // f.dot = dot;
660
+
661
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
662
+ SetColor(obj, rv);
663
+ //gl.glColor4f(r, g, b, 1);
664
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
665
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
666
+ gl.glVertex3f(x, y, z);
667
+// Print(rv);
668
+ //gl.glEnd();
669
+ }
670
+ else
671
+ {
672
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
673
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
674
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
675
+
676
+ }
677
+
678
+ if (false) // (attributes & WIREFRAME) != 0)
679
+ {
680
+ gl.glDisable(gl.GL_LIGHTING);
681
+
682
+ gl.glBegin(gl.GL_LINE_LOOP);
683
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
684
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
685
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
686
+ gl.glEnd();
687
+
688
+ gl.glEnable(gl.GL_LIGHTING);
689
+ }
690
+ }
691
+
692
+ /**
693
+ * <code>draw</code> renders a <code>TriMesh</code> object including
694
+ * it's normals, colors, textures and vertices.
695
+ *
696
+ * @see Renderer#draw(TriMesh)
697
+ * @param tris
698
+ * the mesh to render.
699
+ */
700
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
701
+ {
702
+ CameraPane display = this;
703
+
704
+ float r = display.modelParams0[0];
705
+ float g = display.modelParams0[1];
706
+ float b = display.modelParams0[2];
707
+ float opacity = display.modelParams5[1];
708
+
709
+ //final GL gl = GLU.getCurrentGL();
710
+ GL gl = display.GetGL(); // getGL();
711
+
712
+ FloatBuffer vertBuf = geo.vertBuf;
713
+
714
+ int v = vertBuf.capacity();
715
+
716
+ int count = 0;
717
+
718
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
719
+ gl.glEnable(gl.GL_CULL_FACE);
720
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
721
+ for (int i=0; i<v/3; i++)
722
+ {
723
+ int index3 = i*3;
724
+
725
+ if (geo.sizeBuf.get(index3+1) == 0)
726
+ continue;
727
+
728
+ count++;
729
+
730
+ int index4 = i*4;
731
+
732
+ float tx = vertBuf.get(index3);
733
+ float ty = vertBuf.get(index3+1);
734
+ float tz = vertBuf.get(index3+2);
735
+
736
+ // if (tx == 0 && ty == 0 && tz == 0)
737
+ // continue;
738
+
739
+ gl.glMatrixMode(gl.GL_TEXTURE);
740
+ gl.glPushMatrix();
741
+
742
+ float[] texmat = geo.texmat;
743
+ texmat[12] = texmat[13] = texmat[14] = i;
744
+
745
+ gl.glMultMatrixf(texmat, 0);
746
+
747
+ gl.glMatrixMode(gl.GL_MODELVIEW);
748
+ gl.glPushMatrix();
749
+
750
+ gl.glTranslatef(tx,ty,tz);
751
+
752
+ if (rotate)
753
+ gl.glRotatef(i, 0, 1, 0);
754
+
755
+ float size = geo.sizeBuf.get(index3) / 100;
756
+ gl.glScalef(size,size,size);
757
+
758
+ float cr = geo.colorBuf.get(index4);
759
+ float cg = geo.colorBuf.get(index4+1);
760
+ float cb = geo.colorBuf.get(index4+2);
761
+ float ca = geo.colorBuf.get(index4+3);
762
+
763
+ display.modelParams0[0] = r * cr;
764
+ display.modelParams0[1] = g * cg;
765
+ display.modelParams0[2] = b * cb;
766
+
767
+ display.modelParams5[1] = opacity * ca;
768
+
769
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
770
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
771
+
772
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
773
+ RandomNode.globalseed2 = RandomNode.globalseed;
774
+
775
+// gl.glColor4f(cr,cg,cb,ca);
776
+ // gl.glScalef(1024/16,1024/16,1024/16);
777
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
778
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
779
+ //gl.glTranslatef(-tx,-ty,-tz);
780
+ gl.glPopMatrix();
781
+
782
+ gl.glMatrixMode(gl.GL_TEXTURE);
783
+ gl.glPopMatrix();
784
+ }
785
+ // gl.glScalef(1024,1024,1024);
786
+ if (!cf)
787
+ gl.glDisable(gl.GL_CULL_FACE);
788
+
789
+ display.modelParams0[0] = r;
790
+ display.modelParams0[1] = g;
791
+ display.modelParams0[2] = b;
792
+
793
+ display.modelParams5[1] = opacity;
794
+
795
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
796
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
797
+
798
+ gl.glMatrixMode(gl.GL_MODELVIEW);
799
+
800
+// System.err.println("total = " + v/3 + "; displayed = " + count);
801
+ if (true)
802
+ return;
803
+
804
+//// if (!tris.predraw(this))
805
+//// {
806
+//// return;
807
+//// }
808
+//// if (Debug.stats)
809
+//// {
810
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
811
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
812
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
813
+//// }
814
+////
815
+//// if (tris.getDisplayListID() != -1)
816
+//// {
817
+//// renderDisplayList(tris);
818
+//// return;
819
+//// }
820
+////
821
+//// if (!generatingDisplayList)
822
+//// {
823
+//// applyStates(tris.states, tris);
824
+//// }
825
+//// if (Debug.stats)
826
+//// {
827
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
828
+//// }
829
+//// boolean transformed = doTransforms(tris);
830
+//
831
+// int glMode = GL.GL_TRIANGLES;
832
+// switch (getMode())
833
+// {
834
+// case Triangles:
835
+// glMode = GL.GL_TRIANGLES;
836
+// break;
837
+// case Strip:
838
+// glMode = GL.GL_TRIANGLE_STRIP;
839
+// break;
840
+// case Fan:
841
+// glMode = GL.GL_TRIANGLE_FAN;
842
+// break;
843
+// }
844
+//
845
+// if (!predrawGeometry(gl))
846
+// {
847
+// // make sure only the necessary indices are sent through on old
848
+// // cards.
849
+// IntBuffer indices = this.getIndexBuffer();
850
+// if (indices == null)
851
+// {
852
+// logger.severe("missing indices on geometry object: " + this.toString());
853
+// } else
854
+// {
855
+// indices.rewind();
856
+// indices.limit(this.getMaxIndex());
857
+//
858
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
859
+//
860
+// indices.clear();
861
+// }
862
+// } else
863
+// {
864
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
865
+// GL.GL_UNSIGNED_INT, 0);
866
+// }
867
+//
868
+//// postdrawGeometry(tris);
869
+//// if (transformed)
870
+//// {
871
+//// undoTransforms(tris);
872
+//// }
873
+////
874
+//// if (Debug.stats)
875
+//// {
876
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
877
+//// }
878
+//// tris.postdraw(this);
879
+ }
880
+
881
+ static Camera localcamera = new Camera();
882
+ static cVector from = new cVector();
883
+ static cVector to = new cVector();
884
+
885
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
886
+ {
887
+ CameraPane cp = this;
888
+
889
+ Camera keep = cp.RenderCamera();
890
+ cp.renderCamera = localcamera;
891
+
892
+ if (br.trimmed)
893
+ {
894
+ float[] colors = new float[br.positions.length / 3];
895
+
896
+ int i3 = 0;
897
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
898
+ {
899
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
900
+ continue;
901
+
902
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
903
+ to.set(br.positions[i3] + br.normals[i3],
904
+ br.positions[i3 + 1] + br.normals[i3 + 1],
905
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
906
+ LA.xformPos(from, transform, from);
907
+ LA.xformPos(to, transform, to); // RIGID ONLY
908
+ localcamera.setAim(from, to);
909
+
910
+ CameraPane.occlusionbuffer.display();
911
+
912
+ if (CameraPane.DEBUG_OCCLUSION)
913
+ cp.display(); // debug
914
+
915
+ colors[i] = cp.vertexOcclusion.r;
916
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
917
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
918
+
919
+ if ((i % 100) == 0 && i != 0)
920
+ {
921
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
922
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
923
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
924
+ }
925
+ }
926
+
927
+ br.colors = colors;
928
+ }
929
+ else
930
+ {
931
+ for (int i = 0; i < br.VertexCount(); i++)
932
+ {
933
+ Vertex v = br.GetVertex(i);
934
+
935
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
936
+ continue;
937
+
938
+ from.set(v.x, v.y, v.z);
939
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
940
+ LA.xformPos(from, transform, from);
941
+ LA.xformPos(to, transform, to); // RIGID ONLY
942
+ localcamera.setAim(from, to);
943
+
944
+ CameraPane.occlusionbuffer.display();
945
+
946
+ if (CameraPane.DEBUG_OCCLUSION)
947
+ cp.display(); // debug
948
+
949
+ v.AO = cp.vertexOcclusion.r;
950
+
951
+ if ((i % 100) == 0 && i != 0)
952
+ {
953
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
954
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
955
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
956
+ }
957
+ }
958
+ }
959
+
960
+ //System.out.println("done.");
961
+
962
+ cp.renderCamera = keep;
963
+ }
964
+
965
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
966
+ {
967
+ CameraPane display = this;
968
+ pointFlow.CreateHT();
969
+
970
+ float r = display.modelParams0[0];
971
+ float g = display.modelParams0[1];
972
+ float b = display.modelParams0[2];
973
+ float opacity = display.modelParams5[1];
974
+
975
+ //final GL gl = GLU.getCurrentGL();
976
+ GL gl = display.GetGL(); // getGL();
977
+
978
+ int s = pointFlow.points.size();
979
+
980
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
981
+ gl.glEnable(gl.GL_CULL_FACE);
982
+
983
+ for (int i=s; --i>=0;)
984
+ //for (int i=0; i<s; i++)
985
+ {
986
+ cVector v = pointFlow.points.get(i);
987
+
988
+ double mindist = Double.MAX_VALUE;
989
+
990
+ double size = pointFlow.minimumSize;
991
+
992
+ double distancenext = 0;
993
+
994
+ if (i > 0)
995
+ {
996
+ cVector w = pointFlow.points.get(i-1);
997
+
998
+ double dist = w.distance(v);
999
+
1000
+ distancenext = dist;
1001
+
1002
+ if (mindist > dist)
1003
+ {
1004
+ mindist = dist;
1005
+ size = mindist*pointFlow.resizefactor;
1006
+ }
1007
+ }
1008
+
1009
+ if (i < s-1)
1010
+ {
1011
+ cVector w = pointFlow.points.get(i+1);
1012
+
1013
+ double dist = w.distance(v);
1014
+
1015
+ if (mindist > dist)
1016
+ {
1017
+ mindist = dist;
1018
+ size = mindist*pointFlow.resizefactor;
1019
+ }
1020
+ }
1021
+
1022
+ if (size < pointFlow.minimumSize)
1023
+ size = pointFlow.minimumSize;
1024
+ if (size > pointFlow.maximumSize)
1025
+ size = pointFlow.maximumSize;
1026
+
1027
+ double tx = v.x;
1028
+ double ty = v.y;
1029
+ double tz = v.z;
1030
+
1031
+ // if (tx == 0 && ty == 0 && tz == 0)
1032
+ // continue;
1033
+
1034
+ gl.glMatrixMode(gl.GL_TEXTURE);
1035
+ gl.glPushMatrix();
1036
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1037
+
1038
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1039
+
1040
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1041
+ gl.glPushMatrix();
1042
+
1043
+ gl.glTranslated(tx,ty,tz);
1044
+
1045
+ gl.glScaled(size,size,size);
1046
+
1047
+// float cr = colorBuf.get(index4);
1048
+// float cg = colorBuf.get(index4+1);
1049
+// float cb = colorBuf.get(index4+2);
1050
+// float ca = colorBuf.get(index4+3);
1051
+//
1052
+// display.modelParams0[0] = r * cr;
1053
+// display.modelParams0[1] = g * cg;
1054
+// display.modelParams0[2] = b * cb;
1055
+//
1056
+// display.modelParams5[1] = opacity * ca;
1057
+//
1058
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1059
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1060
+//
1061
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1062
+// RandomNode.globalseed2 = RandomNode.globalseed;
1063
+//
1064
+//// gl.glColor4f(cr,cg,cb,ca);
1065
+// // gl.glScalef(1024/16,1024/16,1024/16);
1066
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1067
+
1068
+ gl.glPopMatrix();
1069
+
1070
+ double step = size/4; //
1071
+
1072
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1073
+ continue;
1074
+
1075
+ int nbsteps = (int)(distancenext/step);
1076
+
1077
+ step = distancenext/nbsteps;
1078
+
1079
+ cVector next = pointFlow.points.get(i-1);
1080
+
1081
+ tmp.set(next);
1082
+ tmp.sub(v);
1083
+ tmp.normalize();
1084
+ tmp.mul(step);
1085
+
1086
+ // calculate next size
1087
+ mindist = Double.MAX_VALUE;
1088
+
1089
+ double nextsize = pointFlow.minimumSize;
1090
+
1091
+ if (i > 1)
1092
+ {
1093
+ cVector w = pointFlow.points.get(i-2);
1094
+
1095
+ double dist = w.distance(next);
1096
+
1097
+ if (mindist > dist)
1098
+ {
1099
+ mindist = dist;
1100
+ nextsize = mindist*pointFlow.resizefactor;
1101
+ }
1102
+ }
1103
+
1104
+ double dist = v.distance(next);
1105
+
1106
+ if (mindist > dist)
1107
+ {
1108
+ mindist = dist;
1109
+ nextsize = mindist*pointFlow.resizefactor;
1110
+ }
1111
+
1112
+ if (nextsize < pointFlow.minimumSize)
1113
+ nextsize = pointFlow.minimumSize;
1114
+ if (nextsize > pointFlow.maximumSize)
1115
+ nextsize = pointFlow.maximumSize;
1116
+ //
1117
+
1118
+ double count = 0;
1119
+
1120
+ while (distancenext > 0.000000001) // step
1121
+ {
1122
+ gl.glPushMatrix();
1123
+
1124
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1125
+
1126
+ double K = count/nbsteps;
1127
+
1128
+ double intersize = K*nextsize + (1-K)*size;
1129
+
1130
+ gl.glScaled(intersize,intersize,intersize);
1131
+
1132
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1133
+
1134
+ count++;
1135
+
1136
+ distancenext -= step;
1137
+
1138
+ gl.glPopMatrix();
1139
+ }
1140
+
1141
+ if (count != nbsteps)
1142
+ assert(count == nbsteps);
1143
+
1144
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1145
+ //gl.glTranslatef(-tx,-ty,-tz);
1146
+
1147
+ gl.glMatrixMode(gl.GL_TEXTURE);
1148
+ gl.glPopMatrix();
1149
+ }
1150
+
1151
+ if (!cf)
1152
+ gl.glDisable(gl.GL_CULL_FACE);
1153
+
1154
+// display.modelParams0[0] = r;
1155
+// display.modelParams0[1] = g;
1156
+// display.modelParams0[2] = b;
1157
+//
1158
+// display.modelParams5[1] = opacity;
1159
+//
1160
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1161
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1162
+
1163
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1164
+ }
1165
+
1166
+ public void DrawBox(cVector min, cVector max)
1167
+ {
1168
+ javax.media.opengl.GL gl = GetGL();
1169
+ gl.glBegin(gl.GL_LINES);
1170
+
1171
+ gl.glVertex3d(min.x, min.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, max.z);
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, max.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(max.x, min.y, min.z);
1177
+
1178
+ gl.glVertex3d(max.x, max.y, max.z);
1179
+ gl.glVertex3d(min.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(max.x, min.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, min.z);
1184
+
1185
+ gl.glEnd();
1186
+ }
1187
+
1188
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1189
+ {
1190
+ int[] strips = bRep.getRawIndices();
1191
+
1192
+ javax.media.opengl.GL gl = GetGL();
1193
+
1194
+ // TRIANGLE STRIP ARRAY
1195
+ if (bRep.trimmed)
1196
+ {
1197
+ float[] v = bRep.getRawVertices();
1198
+ float[] n = bRep.getRawNormals();
1199
+ float[] c = bRep.getRawColors();
1200
+ float[] uv = bRep.getRawUVMap();
1201
+
1202
+ int count2 = 0;
1203
+ int count3 = 0;
1204
+
1205
+ if (n.length > 0)
1206
+ {
1207
+ for (int i = 0; i < strips.length; i++)
1208
+ {
1209
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1210
+
1211
+ /*
1212
+ boolean locked = false;
1213
+ float eps = 0.1f;
1214
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1215
+
1216
+ int dot = 0;
1217
+
1218
+ if ((dot&1) == 0)
1219
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1220
+
1221
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1222
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1223
+ else
1224
+ {
1225
+ locked = true;
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+ }
1228
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1229
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1230
+ if (hasnorm)
1231
+ {
1232
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1233
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1234
+ }
1235
+
1236
+ if ((dot&4) == 0)
1237
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1238
+
1239
+ if (wrap || !locked && (dot&8) != 0)
1240
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1241
+ else
1242
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1243
+
1244
+ f.dot = dot;
1245
+ */
1246
+
1247
+ if (!selectmode)
1248
+ {
1249
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1250
+ {
1251
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1252
+ } else
1253
+ {
1254
+ gl.glNormal3f(0, 0, 1);
1255
+ }
1256
+
1257
+ if (c != null)
1258
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1259
+ {
1260
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1261
+ }
1262
+ }
1263
+
1264
+ if (flipV)
1265
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1266
+ else
1267
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
1269
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1270
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1271
+
1272
+ count2 += 2;
1273
+ count3 += 3;
1274
+ if (!selectmode)
1275
+ {
1276
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1277
+ {
1278
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1279
+ } else
1280
+ {
1281
+ gl.glNormal3f(0, 0, 1);
1282
+ }
1283
+ if (c != null)
1284
+ {
1285
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1286
+ }
1287
+ }
1288
+
1289
+ if (flipV)
1290
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1291
+ else
1292
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
1294
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1295
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1296
+
1297
+ count2 += 2;
1298
+ count3 += 3;
1299
+ for (int j = 0; j < strips[i] - 2; j++)
1300
+ {
1301
+ //gl.glTexCoord2d(...);
1302
+ if (!selectmode)
1303
+ {
1304
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1305
+ {
1306
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1307
+ } else
1308
+ {
1309
+ gl.glNormal3f(0, 0, 1);
1310
+ }
1311
+ if (c != null)
1312
+ {
1313
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1314
+ }
1315
+ }
1316
+
1317
+ if (flipV)
1318
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1319
+ else
1320
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
1322
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1323
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
1325
+ count2 += 2;
1326
+ count3 += 3;
1327
+ }
1328
+
1329
+ gl.glEnd();
1330
+ }
1331
+ }
1332
+
1333
+ assert count3 == v.length;
1334
+ }
1335
+ else // !trimmed
1336
+ {
1337
+ int count = 0;
1338
+ for (int i = 0; i < strips.length; i++)
1339
+ {
1340
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1341
+
1342
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1343
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1344
+
1345
+ drawVertex(gl, p, flipV, selectmode);
1346
+ drawVertex(gl, q, flipV, selectmode);
1347
+
1348
+ for (int j = 0; j < strips[i] - 2; j++)
1349
+ {
1350
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1351
+
1352
+ // if (j%2 == 0)
1353
+ // drawFace(p, q, r, display, null);
1354
+ // else
1355
+ // drawFace(p, r, q, display, null);
1356
+
1357
+ // p = q;
1358
+ // q = r;
1359
+ drawVertex(gl, r, flipV, selectmode);
1360
+ }
1361
+
1362
+ gl.glEnd();
1363
+ }
1364
+ }
1365
+ }
1366
+
1367
+ static cSpring.Point3D temp = new cSpring.Point3D();
1368
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1369
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1370
+
1371
+ public void DrawDynamicMesh(cMesh mesh)
1372
+ {
1373
+ GL gl = GetGL(); // getGL();
1374
+
1375
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1376
+
1377
+ gl.glDisable(gl.GL_LIGHTING);
1378
+
1379
+ gl.glLineWidth(1);
1380
+ gl.glColor3f(1,1,1);
1381
+ gl.glBegin(gl.GL_LINES);
1382
+ double scale = 0;
1383
+ int count = 0;
1384
+ for (int s=0; s<Phys.allSprings.size(); s++)
1385
+ {
1386
+ cSpring.Spring spring = Phys.allSprings.get(s);
1387
+ if(s == 0)
1388
+ {
1389
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1390
+ }
1391
+ if (mesh.showsprings)
1392
+ {
1393
+ temp.set(spring.a.position);
1394
+ temp.add(spring.b.position);
1395
+ temp.mul(0.5);
1396
+ temp2.set(spring.a.position);
1397
+ temp2.sub(spring.b.position);
1398
+ temp2.mul(spring.restLength/2);
1399
+ temp.sub(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ temp.add(temp2);
1402
+ temp.add(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ }
1405
+
1406
+ if (spring.isHandle)
1407
+ continue;
1408
+
1409
+ //if (scale < spring.restLength)
1410
+ scale += spring.restLength;
1411
+ count++;
1412
+ }
1413
+ gl.glEnd();
1414
+
1415
+ if (count == 0)
1416
+ scale = 0.01;
1417
+ else
1418
+ scale /= count * 3;
1419
+
1420
+ //scale = 0.25;
1421
+
1422
+ if (mesh.ShowInfo())
1423
+ {
1424
+ gl.glLineWidth(4);
1425
+ for (int s=0; s<Phys.allNodes.size(); s++)
1426
+ {
1427
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1428
+ if (node.mass == 0)
1429
+ continue;
1430
+
1431
+ int i = node.springs==null?-1:node.springs.size();
1432
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1433
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1434
+ //temp.normalize();
1435
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1436
+ gl.glBegin(gl.GL_LINES);
1437
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1438
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1439
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1440
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1441
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1442
+ gl.glEnd();
1443
+ }
1444
+
1445
+ gl.glLineWidth(8);
1446
+ for (int s=0; s<Phys.allNodes.size(); s++)
1447
+ {
1448
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1449
+
1450
+ if (node.springs != null)
1451
+ {
1452
+ for (int i=0; i<node.springs.size(); i+=1)
1453
+ {
1454
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1455
+
1456
+ int c = i+1;
1457
+ // c = node.springs.get(i).nbcopies;
1458
+
1459
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1460
+ gl.glBegin(gl.GL_LINES);
1461
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1462
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1463
+ gl.glEnd();
1464
+ }
1465
+ }
1466
+ }
1467
+
1468
+ gl.glLineWidth(1);
1469
+ }
1470
+
1471
+ gl.glEnable(gl.GL_LIGHTING);
1472
+ }
1473
+
1474
+ /// INTERFACE
1475
+
1476
+ public void StartTriangles()
1477
+ {
1478
+ javax.media.opengl.GL gl = GetGL();
1479
+ gl.glBegin(gl.GL_TRIANGLES);
1480
+ }
1481
+
1482
+ public void EndTriangles()
1483
+ {
1484
+ GetGL().glEnd();
1485
+ }
1486
+
1487
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1488
+ {
1489
+ if (!selectmode)
1490
+ {
1491
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1492
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1493
+
1494
+ if (flipV)
1495
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1496
+ else
1497
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1498
+ }
1499
+
1500
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1501
+ }
1502
+
1503
+ float[] colorV = new float[4];
1504
+
1505
+ void SetColor(Object3D obj, Vertex p0)
1506
+ {
1507
+ CameraPane display = this;
1508
+ BoundaryRep bRep = obj.bRep;
1509
+
1510
+ if (RENDERPROGRAM == 0)
1511
+ {
1512
+ float r = 0;
1513
+ if (bRep != null)
1514
+ {
1515
+ if (bRep.stripified)
1516
+ {
1517
+ r = 1;
1518
+ }
1519
+ }
1520
+ float g = 0;
1521
+ if (bRep != null)
1522
+ {
1523
+ if (bRep.trimmed)
1524
+ {
1525
+ g = 1;
1526
+ }
1527
+ }
1528
+ float b = 0;
1529
+ if (obj.support != null && obj.link2master)
1530
+ {
1531
+ b = 1;
1532
+ }
1533
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1534
+ return;
1535
+ }
1536
+
1537
+ if (display.DrawMode() != CameraPane.SHADOW)
1538
+ return;
1539
+
1540
+ javax.media.opengl.GL gl = display.GetGL();
1541
+// if (true) return;
1542
+// float ao = p.AO;
1543
+//
1544
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1545
+// // ao = 1;
1546
+//
1547
+// gl.glColor4f(ao, ao, ao, 1);
1548
+
1549
+// CameraPane.selectedpoint.
1550
+// getAverage(cStatic.point1, true);
1551
+ if (CameraPane.pointflow == null) // !random) // live)
1552
+ {
1553
+ return;
1554
+ }
1555
+
1556
+ cStatic.point1.set(0,0,0);
1557
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1558
+
1559
+ cStatic.point1.sub(p0);
1560
+
1561
+
1562
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1563
+// {
1564
+// return;
1565
+// }
1566
+
1567
+ //if (true)
1568
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1569
+ {
1570
+ return;
1571
+ }
1572
+
1573
+ if (false) // marked)
1574
+ {
1575
+ // debug rigging weights
1576
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1577
+ {
1578
+ float weight = p0.weights[object] / p0.totalweight;
1579
+
1580
+ // if (weight < 0.1)
1581
+ // {
1582
+ // assert(weight == 0);
1583
+ // continue;
1584
+ // }
1585
+
1586
+ if (p0.vertexlinks[object] == -1)
1587
+ continue;
1588
+
1589
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1590
+
1591
+ int color = //1 << object; //
1592
+ //p.vertexlinks.length;
1593
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1594
+ colorV[2] += (color & 1) * weight;
1595
+ colorV[1] += ((color & 2) >> 1) * weight;
1596
+ colorV[0] += ((color & 4) >> 2) * weight;
1597
+ }
1598
+ }
1599
+ else
1600
+ {
1601
+ if (obj.drawingstarted)
1602
+ {
1603
+ // find next point
1604
+ if (bRep.GetVertex(0).faceindices == null)
1605
+ {
1606
+ bRep.InitFaceIndices();
1607
+ }
1608
+
1609
+ double ymin = p0.y;
1610
+
1611
+ Vertex newp = p0;
1612
+
1613
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1614
+ {
1615
+ int fi = p0.faceindices[fii];
1616
+
1617
+ if (fi == -1)
1618
+ break;
1619
+
1620
+ Face f = bRep.GetFace(fi);
1621
+
1622
+ Vertex p = bRep.GetVertex(f.p);
1623
+ Vertex q = bRep.GetVertex(f.q);
1624
+ Vertex r = bRep.GetVertex(f.r);
1625
+
1626
+ int swap = (int)(Math.random()*3);
1627
+
1628
+// for (int s=swap; --s>=0;)
1629
+// {
1630
+// Vertex t = p;
1631
+// p = q;
1632
+// q = r;
1633
+// r = t;
1634
+// }
1635
+ if (ymin > p.y)
1636
+ {
1637
+ ymin = p.y;
1638
+ newp = p;
1639
+// break;
1640
+ }
1641
+ if (ymin > q.y)
1642
+ {
1643
+ ymin = q.y;
1644
+ newp = q;
1645
+// break;
1646
+ }
1647
+ if (ymin > r.y)
1648
+ {
1649
+ ymin = r.y;
1650
+ newp = r;
1651
+// break;
1652
+ }
1653
+ }
1654
+
1655
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1656
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1657
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1658
+
1659
+ obj.drawingstarted = false;
1660
+
1661
+ // return;
1662
+ }
1663
+
1664
+ if (false) // CameraPane.DRAW
1665
+ {
1666
+ p0.AO = colorV[0] = 2;
1667
+ colorV[1] = 2;
1668
+ colorV[2] = 2;
1669
+ }
1670
+
1671
+ CameraPane.pointflow.add(p0);
1672
+ CameraPane.pointflow.Touch();
1673
+ }
1674
+
1675
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1676
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1677
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1678
+ }
1679
+
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1681
+ {
1682
+ CameraPane display = this;
1683
+ //new Exception().printStackTrace();
1684
+
1685
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1686
+ {
1687
+ return;
1688
+ }
1689
+
1690
+ javax.media.opengl.GL gl = display.GetGL();
1691
+
1692
+ //Color col = Color.getHSBColor(color,modulation,1);
1693
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1694
+ if (!material.multiply)
1695
+ {
1696
+ display.color = material.color;
1697
+ display.saturation = material.modulation;
1698
+ }
1699
+ else
1700
+ {
1701
+ display.color *= material.color*2;
1702
+ display.saturation *= material.modulation*2;
1703
+ }
1704
+
1705
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1706
+
1707
+ float[] colorV = Grafreed.colorV;
1708
+
1709
+ /**/
1710
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1711
+ {
1712
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1713
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1714
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1715
+ colorV[3] = 1; // material.opacity;
1716
+
1717
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1718
+ //System.out.println("Opacity = " + opacity);
1719
+
1720
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1721
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1722
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1723
+
1724
+ float amb = material.ambient;
1725
+ if (amb < material.cameralight)
1726
+ {
1727
+ amb = material.cameralight;
1728
+ }
1729
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1730
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1731
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1732
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1733
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1734
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1735
+
1736
+ /**/
1737
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1738
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1739
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1740
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1741
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1742
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1743
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1744
+ //System.out.println("shininess = " + colorV[0]);
1745
+ if (colorV[0] > 128)
1746
+ {
1747
+ colorV[0] = 128;
1748
+ }
1749
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1750
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1751
+ /**/
1752
+ }
1753
+ /**/
1754
+
1755
+ //selected = false;
1756
+ selected = selected && display.flash;
1757
+
1758
+ //display.modelParams0[0] = 0; // pigment.r;
1759
+ //display.modelParams0[1] = 0; // pigment.g;
1760
+ //display.modelParams0[2] = 0; // pigment.b;
1761
+ if (!material.multiply)
1762
+ {
1763
+ display.modelParams0[3] = material.metalness;
1764
+ display.modelParams1[0] = material.diffuse;
1765
+ display.modelParams1[1] = material.specular;
1766
+ display.modelParams1[2] = 1 / material.shininess;
1767
+ display.modelParams1[3] = material.shift;
1768
+ display.modelParams2[0] = material.ambient;
1769
+ display.modelParams2[1] = material.lightarea;
1770
+ //System.out.println("light area = " + lightarea);
1771
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1772
+ display.modelParams2[3] = material.velvet;
1773
+ display.modelParams3[0] = material.sheen;
1774
+ display.modelParams3[1] = material.subsurface;
1775
+ display.modelParams3[2] = material.bump; // backlit
1776
+ display.modelParams3[3] = material.aniso;
1777
+ display.modelParams4[0] = material.anisoV;
1778
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1779
+ //System.out.println("selected = " + selected);
1780
+ display.modelParams4[2] = material.diffuseness;
1781
+ display.modelParams4[3] = material.shadow;
1782
+ display.modelParams5[0] = material.texture;
1783
+ display.modelParams5[1] = material.opacity;
1784
+ display.modelParams5[2] = material.fakedepth;
1785
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1786
+ }
1787
+ else
1788
+ {
1789
+ display.modelParams0[3] *= material.metalness*2;
1790
+ display.modelParams1[0] *= material.diffuse*2;
1791
+ display.modelParams1[1] *= material.specular*2;
1792
+ display.modelParams1[2] *= material.shininess*2;
1793
+ display.modelParams1[3] *= material.shift*2;
1794
+ display.modelParams2[0] *= material.ambient*2;
1795
+ display.modelParams2[1] *= material.lightarea*2;
1796
+ display.modelParams2[2] *= material.factor*2;
1797
+ display.modelParams2[3] *= material.velvet*2;
1798
+ display.modelParams3[0] *= material.sheen*2;
1799
+ display.modelParams3[1] *= material.subsurface*2;
1800
+ display.modelParams3[2] *= material.bump*2;
1801
+ display.modelParams3[3] *= material.aniso*2;
1802
+ display.modelParams4[0] *= material.anisoV*2;
1803
+ display.modelParams4[1] *= material.cameralight*2;
1804
+ //System.out.println("selected = " + selected);
1805
+ display.modelParams4[2] *= material.diffuseness*2;
1806
+ display.modelParams4[3] *= material.shadow*2;
1807
+ display.modelParams5[0] *= material.texture*2;
1808
+ display.modelParams5[1] *= material.opacity*2;
1809
+ display.modelParams5[2] *= material.fakedepth*2;
1810
+ display.modelParams5[3] *= material.shadowbias*2;
1811
+ }
1812
+
1813
+ display.modelParams6[0] = 0;
1814
+ display.modelParams6[1] = 0;
1815
+ display.modelParams6[2] = 0;
1816
+ display.modelParams6[3] = 0;
1817
+
1818
+ display.modelParams7[0] = 0;
1819
+ display.modelParams7[1] = 1000;
1820
+ display.modelParams7[2] = 0;
1821
+ display.modelParams7[3] = 0;
1822
+
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
1824
+
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1826
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1827
+ {
1828
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1829
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1830
+ if (extparams.length > 1)
1831
+ {
1832
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1833
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1834
+ if (extparams.length > 2)
1835
+ {
1836
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1837
+ float x = extparams[2].y / 1000.0f;
1838
+ //if (x == 0)
1839
+ // x = 1f;
1840
+ display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power
1841
+ if (extparams[2].y > 0)
1842
+ {
1843
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1844
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1845
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1846
+ }
1847
+ }
1848
+ }
1849
+ }
1850
+
1851
+ //if (display.modelParams6[2] != 0)
1852
+ /*
1853
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1854
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1855
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1856
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1857
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1858
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1859
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1860
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1861
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1862
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1863
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1864
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1865
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1866
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1867
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1868
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1869
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1870
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1871
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1872
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1873
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1874
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1875
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1876
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1877
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1878
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1879
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1880
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1881
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1882
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1883
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1884
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1885
+ /**/
1886
+ //assert (display.modelParams6[2] == 0);
1887
+
1888
+ //System.out.println("noise power = " + display.modelParams7[0]);
1889
+ //System.out.println("shadowbias = " + shadowbias);
1890
+
1891
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1892
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1893
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1896
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1897
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1898
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1899
+
1900
+ int mode = display.FP_SHADER;
1901
+
1902
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1903
+ {
1904
+ mode |= display.FP_ANISO;
1905
+ }
1906
+
1907
+ display.EnableProgram(mode);
1908
+
1909
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1910
+
1911
+ if (!material.multiply)
1912
+ {
1913
+ if (Globals.drawMode == CameraPane.SHADOW)
1914
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1915
+ else
1916
+ gl.glDepthMask(material.opacity >= 0.99);
1917
+ }
2081918 }
2091919
2101920 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1935,7 @@
2251935 currentGL.glMultMatrixd(model, 0);
2261936 }
2271937
228
- void PushMatrix(double[][] matrix, int count)
1938
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291939 {
2301940 matrixdepth++;
2311941 // GrafreeD.tracein(matrix);
....@@ -254,7 +1964,7 @@
2541964 void PushMatrix(double[][] matrix)
2551965 {
2561966 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
2581968 }
2591969
2601970 void PushMatrix()
....@@ -270,7 +1980,7 @@
2701980
2711981 double[][] tmpmat = new double[4][4];
2721982
273
- void PopMatrix(double[][] inverse)
1983
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741984 {
2751985 --matrixdepth;
2761986
....@@ -310,7 +2020,7 @@
3102020 PushTextureMatrix(matrix, 1);
3112021 }
3122022
313
- void PushTextureMatrix(double[][] matrix, int count)
2023
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142024 {
3152025 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162026
....@@ -324,7 +2034,7 @@
3242034 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252035 }
3262036
327
- void PopTextureMatrix(double[][] inverse)
2037
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282038 {
3292039 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302040 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -351,15 +2061,15 @@
3512061
3522062 static int camerachangeframe;
3532063
354
- boolean SetCamera(Camera cam)
2064
+ public boolean SetCamera(Camera cam)
3552065 {
3562066 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572067 // return false;
3582068
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2069
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602070 {
3612071 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2072
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632073 {
3642074 // refuse the camera change
3652075 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2077,7 @@
3672077 }
3682078 }
3692079
370
- camerachangeframe = framecount;
2080
+ camerachangeframe = Globals.framecount;
3712081
3722082 cam.hAspect = -1; // Read only
3732083
....@@ -398,7 +2108,7 @@
3982108 {
3992109 //System.err.println("Oeil on");
4002110 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2111
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022112 // object.editWindow.ScreenFit(trackedobject);
4032113 //pingthread.StepToTarget(true);
4042114 }
....@@ -407,8 +2117,8 @@
4072117 {
4082118 //System.err.println("Oeil on");
4092119 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2120
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122122 //pingthread.StepToTarget(true);
4132123 }
4142124
....@@ -471,39 +2181,12 @@
4712181 {
4722182 frozen ^= true;
4732183 // Weird...
474
- lighttouched = true;
2184
+ Globals.lighttouched = true;
4752185 }
4762186
4772187 void ToggleDL()
4782188 {
4792189 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GrafreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072190 }
5082191
5092192 void ToggleFullScreen()
....@@ -513,12 +2196,7 @@
5132196
5142197 void ToggleCrowd()
5152198 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2199
+ Globals.CROWD ^= true;
5222200 }
5232201
5242202 void ToggleLocal()
....@@ -526,62 +2204,89 @@
5262204 LOCALTRANSFORM ^= true;
5272205 }
5282206
529
- void ToggleFast()
2207
+ public void ToggleTexture()
2208
+ {
2209
+ textureon ^= true;
2210
+ }
2211
+
2212
+ public void ToggleLive()
2213
+ {
2214
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2215
+
2216
+ System.err.println("LIVE = " + Globals.isLIVE());
2217
+
2218
+ if (!Globals.isLIVE()) // save sound
2219
+ Grafreed.savesound = true; // wav.save();
2220
+ // else
2221
+ repaint(); // start loop // may 2013
2222
+ }
2223
+
2224
+ public void ToggleSupport()
2225
+ {
2226
+ SUPPORT ^= true;
2227
+ }
2228
+
2229
+ public void ToggleAbort()
2230
+ {
2231
+ ABORTMODE ^= true;
2232
+ }
2233
+
2234
+ public void ToggleInertia()
2235
+ {
2236
+ INERTIA ^= true;
2237
+ }
2238
+
2239
+ public void ToggleFast()
5302240 {
5312241 FAST ^= true;
5322242 }
5332243
534
- void ToggleSlowPose()
2244
+ public void ToggleSlowPose()
5352245 {
5362246 SLOWPOSE ^= true;
5372247 }
5382248
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2249
+ public void ToggleBoxMode()
5452250 {
5462251 BOXMODE ^= true;
5472252 }
5482253
549
- void ToggleSmoothFocus()
2254
+ public void ToggleZoomBoxMode()
2255
+ {
2256
+ ZOOMBOXMODE ^= true;
2257
+ }
2258
+
2259
+ public void ToggleSmoothFocus()
5502260 {
5512261 SMOOTHFOCUS ^= true;
5522262 }
5532263
554
- void ToggleImageFlip()
2264
+ public void ToggleImageFlip()
5552265 {
5562266 IMAGEFLIP ^= true;
5572267 }
5582268
559
- void ToggleSpeakerMocap()
2269
+ public void ToggleSpeakerMocap()
5602270 {
5612271 SPEAKERMOCAP ^= true;
5622272 }
5632273
564
- void ToggleSpeakerCamera()
2274
+ public void ToggleSpeakerCamera()
5652275 {
5662276 SPEAKERCAMERA ^= true;
5672277 }
5682278
569
- void ToggleSpeakerFocus()
2279
+ public void ToggleSpeakerFocus()
5702280 {
5712281 SPEAKERFOCUS ^= true;
5722282 }
5732283
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2284
+ public void ToggleFrustum()
5802285 {
5812286 FRUSTUM ^= true;
5822287 }
5832288
584
- void ToggleTrack()
2289
+ public void ToggleTrack()
5852290 {
5862291 TRACK ^= true;
5872292 if (TRACK)
....@@ -600,25 +2305,35 @@
6002305 repaint();
6012306 }
6022307
603
- void ToggleTrackOnce()
2308
+ public void ToggleTrackOnce()
6042309 {
6052310 TRACKONCE ^= true;
6062311 }
6072312
608
- void ToggleShadowTrack()
2313
+ public void ToggleShadowTrack()
6092314 {
6102315 SHADOWTRACK ^= true;
6112316 repaint();
6122317 }
6132318
614
- void ToggleOeil()
2319
+ public void ToggleOeil()
6152320 {
6162321 OEIL ^= true;
6172322 }
6182323
619
- void ToggleOeilOnce()
2324
+ public void ToggleOeilOnce()
6202325 {
6212326 OEILONCE ^= true;
2327
+ }
2328
+
2329
+ void ToggleFootContact()
2330
+ {
2331
+ FOOTCONTACT ^= true;
2332
+ }
2333
+
2334
+ void ToggleDebug()
2335
+ {
2336
+ Globals.DEBUG ^= true;
6222337 }
6232338
6242339 void ToggleLookAt()
....@@ -626,9 +2341,9 @@
6262341 LOOKAT ^= true;
6272342 }
6282343
629
- void ToggleRandom()
2344
+ void ToggleSwitch()
6302345 {
631
- RANDOM ^= true;
2346
+ SWITCH ^= true;
6322347 }
6332348
6342349 void ToggleHandles()
....@@ -636,10 +2351,17 @@
6362351 HANDLES ^= true;
6372352 }
6382353
2354
+ Object3D paintFolder;
2355
+
6392356 void TogglePaint()
6402357 {
6412358 PAINTMODE ^= true;
6422359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
6432365 }
6442366
6452367 void SwapCamera(int a, int b)
....@@ -672,34 +2394,6 @@
6722394 //assert (cam.hAspect == 0);
6732395 cam.hAspect = 0;
6742396 lightCamera = cam;
675
- }
676
-
677
- CameraPane(Object3D o, Camera cam, boolean withcontext)
678
- {
679
- super(defaultcaps, null, withcontext?glcontext:null, null);
680
-
681
- //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
682
- glcontext = getContext();
683
-
684
- cameras = new Camera[2];
685
- targetLookAts = new cVector[2];
686
-
687
- SetCamera(cam);
688
-
689
- SetLight(new Camera(new cVector(10, 10, -20)));
690
-
691
- object = o;
692
-
693
- setBackground(Color.white);
694
-
695
- addKeyListener(this);
696
- addMouseListener(this);
697
- addMouseMotionListener(this);
698
- addMouseWheelListener(this);
699
- //System.out.println("addGLEventListener: " + this);
700
- addGLEventListener(this);
701
-
702
-// pingthread.start(); // may 2013
7032397 }
7042398
7052399 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2453,26 @@
7592453
7602454 GL currentGL;
7612455
762
- GL GetGL()
2456
+ public GL GetGL() // INTERFACE
7632457 {
7642458 return currentGL;
7652459 }
766
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
7672476 /**/
7682477 class CacheTexture
7692478 {
....@@ -772,28 +2481,31 @@
7722481
7732482 int resolution;
7742483
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762485 {
777
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
7782488 resolution = res;
7792489 }
7802490 }
7812491 /**/
7822492
7832493 // TEXTURE static Texture texture;
784
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
785
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
786
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
7872499 int pigmentdepth = 0;
7882500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892501 int bumpdepth = 0;
7902502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952507
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972509 {
7982510 TextureData texturedata = null;
7992511
....@@ -812,13 +2524,34 @@
8122524 if (bump)
8132525 texturedata = ConvertBump(texturedata, false);
8142526
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172529
818
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
819
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202532
821
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
8222555 }
8232556
8242557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3624,8 @@
18913624
18923625 System.out.println("LOADING TEXTURE : " + name);
18933626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
18943629 //
18953630 if (false) // compressbit > 0)
18963631 {
....@@ -2595,6 +4330,7 @@
25954330
25964331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25974332 {
4333
+ new Exception().printStackTrace();
25984334 System.exit(0);
25994335 com.sun.opengl.util.texture.Texture texture = null;
26004336
....@@ -6271,7 +8007,7 @@
62718007 return null;
62728008 }
62738009
6274
- void ReleaseTextures(cTexture tex)
8010
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62758011 {
62768012 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62778013 {
....@@ -6288,7 +8024,7 @@
62888024 String pigment = Object3D.GetPigment(tex);
62898025 String bump = Object3D.GetBump(tex);
62908026
6291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62928028 {
62938029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62948030 // System.out.println("; bump = " + bump);
....@@ -6303,13 +8039,71 @@
63038039 pigment = null;
63048040 }
63058041
6306
- ReleaseTexture(bump, true);
6307
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
63088044 }
63098045
6310
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63118047 {
6312
- if (// drawMode != 0 || /*tex == null ||*/
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
8105
+ {
8106
+ if (// DrawMode() != 0 || /*tex == null ||*/
63138107 ambientOcclusion ) // || !textureon)
63148108 {
63158109 return;
....@@ -6318,7 +8112,7 @@
63188112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63198113
63208114 if (tex != null)
6321
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63228116
63238117 // //assert( texture != null );
63248118 // if (texture == null)
....@@ -6410,9 +8204,57 @@
64108204 }
64118205 }
64128206
6413
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64148208 {
6415
- if (// drawMode != 0 || /*tex == null ||*/
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8256
+ {
8257
+ if (// DrawMode() != 0 || /*tex == null ||*/
64168258 ambientOcclusion ) // || !textureon)
64178259 {
64188260 return; // false;
....@@ -6421,17 +8263,47 @@
64218263 if (tex == null)
64228264 {
64238265 BindTexture(null,false,resolution);
6424
- BindTexture(null,true,resolution);
64258266 return;
64268267 }
64278268
64288269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
64298302 String bump = Object3D.GetBump(tex);
64308303
6431
- usedtextures.put(pigment, pigment);
6432
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
64338305
6434
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64358307 {
64368308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64378309 // System.out.println("; bump = " + bump);
....@@ -6441,43 +8313,94 @@
64418313 {
64428314 bump = null;
64438315 }
6444
- if (pigment.equals(""))
6445
- {
6446
- pigment = null;
6447
- }
64488316
6449
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
- BindTexture(pigment, false, resolution);
64518317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6452
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
64538319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6454
-
6455
- return; // true;
64568320 }
64578321
6458
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
64598325 {
6460
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
64618345
64628346 if (tex != null)
64638347 {
6464
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64658350
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;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
64728368
64738369 if (CACHETEXTURE)
6474
- texture = textures.get(texname); // TEXTURE CACHE
6475
-
6476
- TextureData texturedata = null;
6477
-
6478
- if (texture == null || texture.resolution < resolution)
64798370 {
6480
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64818404 {
64828405 assert(!bump);
64838406 // if (bump)
....@@ -6488,19 +8411,23 @@
64888411 // }
64898412 // else
64908413 // {
6491
- texture = textures.get(tex);
6492
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
64938416 {
6494
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64958418 }
8419
+ else
8420
+ new Exception().printStackTrace();
64968421 // }
64978422 } else
6498
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64998424 {
65008425 assert(bump);
6501
- texture = textures.get(tex);
6502
- if (texture == null)
6503
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
65048431 } else
65058432 {
65068433 //if (tex.equals("IMMORTAL"))
....@@ -6508,11 +8435,22 @@
65088435 // texture = GetResourceTexture("default.png");
65098436 //} else
65108437 //{
6511
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
65128439 {
6513
- texture = textures.get(tex);
6514
- if (texture == null)
6515
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
65168454 } else
65178455 {
65188456 if (textureon)
....@@ -6537,7 +8475,7 @@
65378475 }
65388476
65398477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6540
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
65418479 cachename = texname;
65428480 else
65438481 processbump = false; // don't process bump map again
....@@ -6559,7 +8497,7 @@
65598497 }
65608498
65618499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6562
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
65638501 cachename = texname;
65648502 else
65658503 processbump = false; // don't process bump map again
....@@ -6568,20 +8506,23 @@
65688506 texturedata = GetFileTexture(cachename, processbump, resolution);
65698507
65708508
6571
- if (texturedata != null)
6572
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
65738513 //texture = GetTexture(tex, bump);
65748514 }
8515
+ }
65758516 }
65768517 //}
65778518 }
65788519
6579
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65808521 {
65818522 //return false;
65828523
65838524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6584
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65858526 {
65868527 // String ext = "_highres";
65878528 // if (REDUCETEXTURE)
....@@ -6598,52 +8539,17 @@
65988539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65998540 if (!cachefile.exists())
66008541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
66108543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
66418546 ImageWriter writer = null;
66428547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66438548 if (iter.hasNext()) {
66448549 writer = (ImageWriter)iter.next();
66458550 }
6646
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
66478553 try
66488554 {
66498555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6660,18 +8566,20 @@
66608566 }
66618567 }
66628568 }
6663
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
66648572 //System.out.println("Texture = " + tex);
6665
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
66668574 {
6667
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
66688576 thetex.texture.disable();
66698577 thetex.texture.dispose();
6670
- textures.remove(texname);
8578
+ textures.remove(tex);
66718579 }
66728580
6673
- texture.texturedata = texturedata;
6674
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
66758583
66768584 // newtex = true;
66778585 }
....@@ -6687,10 +8595,44 @@
66878595 }
66888596 }
66898597
6690
- return texture;
8598
+ return texturecache;
66918599 }
66928600
6693
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66948636 {
66958637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66968638
....@@ -6708,21 +8650,21 @@
67088650 return texture!=null?texture.texture:null;
67098651 }
67108652
6711
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67128654 {
67138655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67148656
67158657 return texture!=null?texture.texturedata:null;
67168658 }
67178659
6718
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67198661 {
67208662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67218663 {
67228664 return false;
67238665 }
67248666
6725
- boolean newtex = false;
8667
+ //boolean newtex = false;
67268668
67278669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67288670
....@@ -6754,9 +8696,75 @@
67548696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67558697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67568698
6757
- return newtex;
8699
+ return true; // Warning: not used.
67588700 }
67598701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
67608768 ShadowBuffer shadowPBuf;
67618769 AntialiasBuffer antialiasPBuf;
67628770 int MAXSTACK;
....@@ -6773,10 +8781,12 @@
67738781
67748782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67758783 MAXSTACK = temp[0];
6776
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67778786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67788787 MAXSTACK = temp[0];
6779
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67808790
67818791 // Use debug pipeline
67828792 //drawable.setGL(new DebugGL(gl)); //
....@@ -6784,7 +8794,8 @@
67848794 gl = drawable.getGL(); //
67858795
67868796 GL gl3 = getGL();
6787
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67888799
67898800
67908801 //float pos[] = { 100, 100, 100, 0 };
....@@ -6949,7 +8960,7 @@
69498960
69508961 if (cubemap == null)
69518962 {
6952
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
69538964 }
69548965
69558966 //cubemap.enable();
....@@ -7225,6 +9236,8 @@
72259236
72269237 void LoadEnvy(int which)
72279238 {
9239
+ assert(false);
9240
+
72289241 String name;
72299242 String ext;
72309243
....@@ -7236,37 +9249,58 @@
72369249 cubemap = null;
72379250 return;
72389251 case 1:
7239
- name = "cubemaps/box_";
7240
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
72419254 reverseUP = false;
72429255 break;
72439256 case 2:
7244
- name = "cubemaps/uffizi_";
7245
- ext = "png";
7246
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
72479261 case 3:
7248
- name = "cubemaps/CloudyHills_";
7249
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
72509264 reverseUP = false;
72519265 break;
72529266 case 4:
7253
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
72549268 ext = "png";
72559269 reverseUP = false;
72569270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
72579296 default:
7258
- name = "cubemaps/rgb_";
7259
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
72609300 break;
72619301 }
7262
-
7263
- try
7264
- {
7265
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7266
- } catch (IOException e)
7267
- {
7268
- throw new RuntimeException(e);
7269
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
72709304 }
72719305
72729306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7298,8 +9332,12 @@
72989332 static double[] model = new double[16];
72999333 double[] camera2light = new double[16];
73009334 double[] light2camera = new double[16];
7301
- int newenvy = -1;
7302
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
73039341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73049342 //float[] light0 = { 0,0,0 };
73059343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7312,9 +9350,9 @@
73129350 static boolean occlusionInitialized = false;
73139351 boolean selection = false;
73149352 boolean pointselection = false;
7315
- /*static*/ boolean lighttouched = true;
9353
+ ///*static*/ boolean lighttouched = true;
73169354 boolean deselect;
7317
- boolean ambientOcclusion = false;
9355
+ private boolean ambientOcclusion = false;
73189356 static boolean flash = false;
73199357 /*static*/ boolean wait = false;
73209358 boolean displaydone = false; // after repaint() calls
....@@ -7592,18 +9630,40 @@
75929630 jy8[3] = 0.5f;
75939631 }
75949632
7595
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75969634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
75979635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
75989636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75999637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
76009662 static int imagecount = 0; // movie generation
76019663
76029664 static int jitter = 0;
76039665
76049666 boolean restartframe = false;
7605
-
7606
- static int framecount = 0; // general-purpose global count
76079667
76089668 void displayAntiAliased(javax.media.opengl.GL gl)
76099669 {
....@@ -7635,7 +9695,7 @@
76359695 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76369696 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76379697 {
7638
- framecount++;
9698
+ Globals.framecount++;
76399699
76409700 if (CameraPane.tickcount > 0)
76419701 CameraPane.tickcount--;
....@@ -7673,7 +9733,7 @@
76739733
76749734 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76759735 */
7676
- lighttouched = true;
9736
+ Globals.lighttouched = true;
76779737 //System.err.println(" shadowbuffer: " + jitter);
76789738 shadowbuffer.display();
76799739
....@@ -7694,8 +9754,8 @@
76949754 assert (parentcam != renderCamera);
76959755
76969756 if (renderCamera != lightCamera)
7697
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7698
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76999759
77009760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
77019761
....@@ -7710,8 +9770,8 @@
77109770 LA.matCopy(renderCamera.fromScreen, matrix);
77119771
77129772 if (renderCamera != lightCamera)
7713
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7714
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77159775
77169776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77179777
....@@ -7757,10 +9817,12 @@
77579817 rati = 1 / rati;
77589818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77599819 }
7760
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
77619823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77629824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7763
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
77649826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77659827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77669828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7783,7 +9845,7 @@
77839845 //gl.glFlush();
77849846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77859847
7786
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
77879849 {
77889850 System.err.println(" ABORTED FRAME");
77899851 break;
....@@ -7813,7 +9875,7 @@
78139875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78149876
78159877 // save image
7816
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
78179879 {
78189880 VPwidth = viewport[2];
78199881 VPheight = viewport[3];
....@@ -7924,11 +9986,11 @@
79249986
79259987 // imagecount++;
79269988
7927
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79289990
79299991 if (!BOXMODE)
79309992 {
7931
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79329994 }
79339995
79349996 if (!BOXMODE)
....@@ -7966,7 +10028,7 @@
796610028 ABORTED = false;
796710029 }
796810030 else
7969
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
797010032
797110033 if (false)
797210034 {
....@@ -8620,13 +10682,6 @@
862010682 }
862110683 }
862210684
8623
- boolean IsFrozen()
8624
- {
8625
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8626
-
8627
- return !selectmode && cameracount == 0; // != 0;
8628
- }
8629
-
863010685 boolean niceon = false;
863110686 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
863210687 boolean currentlydrawing = false;
....@@ -8636,16 +10691,16 @@
863610691
863710692 public void display(GLAutoDrawable drawable)
863810693 {
8639
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
864010695 {
8641
- GrafreeD.wav.save();
8642
- GrafreeD.savesound = false;
8643
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
864410699 }
864510700 // if (DEBUG_SELECTION)
864610701 // {
8647
-// if (drawMode != SELECTION)
8648
-// drawMode = SELECTION;
10702
+// if (DrawMode() != SELECTION)
10703
+// DrawMode() = SELECTION;
864910704 // }
865010705
865110706 if (!isRenderer)
....@@ -8701,9 +10756,9 @@
870110756
870210757 //ANTIALIAS = 0;
870310758
8704
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10759
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870510760 {
8706
- if (niceon || isLIVE())
10761
+ if (niceon || Globals.isLIVE())
870710762 {
870810763 //if(active == 0)
870910764 // antialiaser = null;
....@@ -8716,6 +10771,7 @@
871610771 ANTIALIAS = 0;
871710772 //System.out.println("RESTART");
871810773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
871910775 }
872010776 }
872110777 }
....@@ -8728,7 +10784,7 @@
872810784 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872910785 */
873010786
8731
- if (drawMode == DEFAULT)
10787
+ if (DrawMode() == DEFAULT)
873210788 {
873310789 currentlydrawing = true;
873410790 }
....@@ -8759,18 +10815,18 @@
875910815
876010816 // if(Applet3D.clipboard != null)
876110817 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8762
-//drawMode = SELECTION;
10818
+//DrawMode() = SELECTION;
876310819 indexcount = 0;
876410820
8765
- if (drawMode == OCCLUSION)
10821
+ if (DrawMode() == OCCLUSION)
876610822 {
8767
- drawMode = DEFAULT;
10823
+ Globals.drawMode = DEFAULT; // WARNING
876810824 ambientOcclusion = true;
876910825 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
877010826 Object3D theobject = object;
877110827 Object3D theparent = object.parent;
877210828 object.parent = null;
8773
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
877410830 object.Stripify();
877510831 if (theobject.selection == null || theobject.selection.Size() == 0)
877610832 theobject.PreprocessOcclusion(this);
....@@ -8783,26 +10839,27 @@
878310839 ambientOcclusion = false;
878410840 }
878510841
8786
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878710844 {
878810845 //if (RENDERSHADOW) // ?
878910846 if (!IsFrozen())
879010847 {
879110848 // dec 2012
8792
- if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
879310850 {
8794
- framecount++;
10851
+ Globals.framecount++;
879510852 shadowbuffer.display();
879610853 }
879710854 }
8798
- lighttouched = false; // ??
10855
+ Globals.lighttouched = false; // ??
879910856 //drawing = true;
880010857 //lighttouched = true;
880110858 }
880210859
880310860 if (wait)
880410861 {
8805
- Sleep(500);
10862
+ Sleep(200); // blocks everything
880610863
880710864 wait = false;
880810865 }
....@@ -8816,9 +10873,9 @@
881610873 //eyeCamera.shaper_fovy = 1;
881710874 }
881810875
8819
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10876
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
882010877 {
8821
- //System.out.println("drawMode = " + drawMode);
10878
+ //System.out.println("DrawMode() = " + DrawMode());
882210879 vertexMode |= VP_PASS;
882310880 //vertexMode |= VP_PROJECTION;
882410881 if (!ambientOcclusion)
....@@ -8878,7 +10935,7 @@
887810935 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887910936 //Camera lightcam = new Camera(light0);
888010937
8881
- if (drawMode == SHADOW)
10938
+ if (DrawMode() == SHADOW)
888210939 {
888310940 /*
888410941 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8916,8 +10973,8 @@
891610973
891710974 // if (parentcam != renderCamera) // not a light
891810975 if (cam != lightCamera)
8919
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8920
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
892110978
892210979 for (int j = 0; j < 4; j++)
892310980 {
....@@ -8931,8 +10988,8 @@
893110988
893210989 // if (parentcam != renderCamera) // not a light
893310990 if (cam != lightCamera)
8934
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8935
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893610993
893710994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893810995
....@@ -8968,7 +11025,7 @@
896811025 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896911026 } else
897011027 {
8971
- if (drawMode != DEFAULT)
11028
+ if (DrawMode() != DEFAULT)
897211029 {
897311030 gl.glClearColor(1, 1, 1, 0);
897411031 } // 1);
....@@ -9018,13 +11075,41 @@
901811075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901911076 }
902011077
9021
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
902211086 {
9023
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
902411093 }
9025
-
9026
- newenvy = -1;
9027
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
902811113 ratio = ((double) getWidth()) / getHeight();
902911114 //System.out.println("ratio = " + ratio);
903011115
....@@ -9033,14 +11118,14 @@
903311118
903411119 fast &= !ambientOcclusion;
903511120
9036
- if (drawMode == DEFAULT)
11121
+ if (DrawMode() == DEFAULT)
903711122 {
903811123 //gl.glEnable(gl.GL_ALPHA_TEST);
903911124 //gl.glActiveTexture(GL.GL_TEXTURE0);
904011125
904111126 if (!IsFrozen() && !ambientOcclusion)
904211127 {
9043
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
904411129 }
904511130
904611131 //if (selection_view == -1)
....@@ -9191,7 +11276,16 @@
919111276 // Bump noise
919211277 gl.glActiveTexture(GL.GL_TEXTURE6);
919311278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9194
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
919511289
919611290 gl.glActiveTexture(GL.GL_TEXTURE0);
919711291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9214,9 +11308,9 @@
921411308
921511309 gl.glMatrixMode(GL.GL_MODELVIEW);
921611310
9217
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9218
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9219
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
922011314 } else
922111315 {
922211316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9227,11 +11321,11 @@
922711321 //System.out.println("BLENDING ON");
922811322 gl.glEnable(GL.GL_BLEND);
922911323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9230
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
923111325 gl.glMatrixMode(gl.GL_PROJECTION);
923211326 gl.glLoadIdentity();
923311327
9234
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11328
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
923511329 {
923611330 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923711331 double scale = lightCamera.SCALE / lightCamera.Distance();
....@@ -9289,7 +11383,7 @@
928911383 //gl.glPushMatrix();
929011384 gl.glLoadIdentity();
929111385
9292
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11386
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
929311387 {
929411388 //LA.xformPos(light0, lightCamera.fromScreen, light);
929511389 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9316,8 +11410,8 @@
931611410 System.err.println("parentcam != renderCamera");
931711411
931811412 // if (cam != lightCamera)
9319
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9320
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
932111415 }
932211416
932311417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9338,8 +11432,8 @@
933811432 if (true) // TODO
933911433 {
934011434 if (cam != lightCamera)
9341
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9342
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
934311437 }
934411438
934511439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9376,7 +11470,7 @@
937611470 }
937711471
937811472 /**/
9379
- if (true) // drawMode == SELECTION) // != DEFAULT)
11473
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
938011474 gl.glDisable(gl.GL_LIGHTING);
938111475 else
938211476 gl.glEnable(gl.GL_LIGHTING);
....@@ -9394,7 +11488,7 @@
939411488
939511489 lightslot = 64;
939611490
9397
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11491
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
939811492 {
939911493 DrawLights(object);
940011494 }
....@@ -9405,7 +11499,7 @@
940511499 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
940611500 //System.out.println("fragmentMode = " + fragmentMode);
940711501
9408
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11502
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
940911503 {
941011504 /*
941111505 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9438,7 +11532,7 @@
943811532 }
943911533 }
944011534
9441
- if (drawMode == DEFAULT)
11535
+ if (DrawMode() == DEFAULT)
944211536 {
944311537 if (WIREFRAME && !ambientOcclusion)
944411538 {
....@@ -9456,7 +11550,7 @@
945611550 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
945711551 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
945811552
9459
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11553
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
946011554 {
946111555 if (vertexMode != 0) // && !fast)
946211556 {
....@@ -9476,7 +11570,7 @@
947611570 }
947711571 }
947811572
9479
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
948011574 {
948111575 //gl.glDepthFunc(GL.GL_LEQUAL);
948211576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9484,27 +11578,24 @@
948411578
948511579 boolean texon = textureon;
948611580
9487
- if (RENDERPROGRAM > 0)
9488
- {
9489
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9490
- textureon = false;
9491
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
949211584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
949311585 //System.out.println("ALLO");
949411586 gl.glColorMask(false, false, false, false);
949511587 DrawObject(gl);
9496
- if (RENDERPROGRAM > 0)
9497
- {
9498
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9499
- textureon = texon;
9500
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
950111592 gl.glColorMask(true, true, true, true);
950211593
950311594 gl.glDepthFunc(GL.GL_EQUAL);
9504
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
950511596 }
950611597
9507
- if (false) // drawMode == SHADOW)
11598
+ if (false) // DrawMode() == SHADOW)
950811599 {
950911600 //SetColumnMajorData(cameraInverseTransform, view_1);
951011601 //System.out.println("light = " + cameraInverseTransform);
....@@ -9518,16 +11609,16 @@
951811609 //System.out.println("object = " + object);
951911610 if (!frozen && !imageLocked)
952011611 {
9521
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11612
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
952211613 {
952311614 displayAntiAliased(gl);
952411615 } else
952511616 {
952611617 programcount = 0;
9527
- int keepmode = drawMode;
11618
+ int keepmode = DrawMode();
952811619 // if (DEBUG_SELECTION)
952911620 // {
9530
-// drawMode = SELECTION;
11621
+// DrawMode() = SELECTION;
953111622 // }
953211623 // for point selection
953311624 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9537,10 +11628,10 @@
953711628 DrawObject(gl);
953811629
953911630 // jan 2013 System.err.println("RESET ABORT (display)");
9540
- // if (drawMode == DEFAULT)
11631
+ // if (DrawMode() == DEFAULT)
954111632 // ABORTED = false;
954211633 fullreset = false;
9543
- drawMode = keepmode;
11634
+ Globals.drawMode = keepmode; // WARNING
954411635 //System.out.println("PROGRAM SWITCH " + programcount);
954511636 }
954611637 }
....@@ -9548,11 +11639,11 @@
954811639 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
954911640 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
955011641
9551
- if (drawMode == DEFAULT)
11642
+ if (DrawMode() == DEFAULT)
955211643 {
955311644 ReleaseTexture(NOISE_TEXTURE, false);
955411645 }
9555
- //if (drawMode == DEFAULT)
11646
+ //if (DrawMode() == DEFAULT)
955611647 {
955711648
955811649 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9564,7 +11655,7 @@
956411655 //else
956511656 //gl.glDisable(gl.GL_TEXTURE_2D);
956611657 //gl.glPopMatrix();
9567
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11658
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
956811659 {
956911660 //new Exception().printStackTrace();
957011661 //System.out.println("Draw image " + width + ", " + height);
....@@ -9606,7 +11697,7 @@
960611697 //gl.glFlush();
960711698 }
960811699
9609
- if (flash && drawMode == DEFAULT)
11700
+ if (flash && DrawMode() == DEFAULT)
961011701 {
961111702 flash = false;
961211703 wait = true;
....@@ -9614,9 +11705,9 @@
961411705 }
961511706
961611707 //drawing = false;
9617
- //if(drawMode == DEFAULT)
11708
+ //if(DrawMode() == DEFAULT)
961811709 // niceon = false;
9619
- if (drawMode == DEFAULT)
11710
+ if (DrawMode() == DEFAULT)
962011711 {
962111712 currentlydrawing = false;
962211713 }
....@@ -9636,7 +11727,7 @@
963611727 repaint();
963711728 }
963811729
9639
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11730
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
964011731 repaint();
964111732
964211733 displaydone = true;
....@@ -9655,8 +11746,14 @@
965511746 {
965611747 renderpass++;
965711748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
965811750 if (FAST) // in case there is no script
9659
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
966011757
966111758 //object.FullInvariants();
966211759
....@@ -9670,23 +11767,44 @@
967011767 e.printStackTrace();
967111768 }
967211769
9673
- if (GrafreeD.RENDERME > 0)
9674
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
967511772
9676
- ONESTEP = false;
11773
+ Globals.ONESTEP = false;
967711774 }
967811775
967911776 static boolean zoomonce = false;
968011777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
968111796 void DrawObject(GL gl, boolean draw)
968211797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
968311801 //System.out.println("DRAW OBJECT " + mouseDown);
9684
-// drawMode = SELECTION;
11802
+// DrawMode() = SELECTION;
968511803 //GL gl = getGL();
968611804 if ((TRACK || SHADOWTRACK) || zoomonce)
968711805 {
9688
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9689
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11806
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
969011808 pingthread.StepToTarget(true); // true);
969111809 // zoomonce = false;
969211810 }
....@@ -9706,9 +11824,9 @@
970611824 callist = gl.glGenLists(1);
970711825 }
970811826
9709
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11827
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
971011828
9711
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11829
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
971211830
971311831 if (!mainDL || !active || touched)
971411832 {
....@@ -9735,13 +11853,20 @@
973511853 PushMatrix(ClickInfo.matbuffer);
973611854 }
973711855
9738
- if (drawMode == 0)
11856
+ if (DrawMode() == 0)
973911857 {
974011858 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
974111859
974211860 usedtextures.clear();
974311861
9744
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
974511870 }
974611871 //System.out.println("--> " + stackdepth);
974711872 // GrafreeD.traceon();
....@@ -9749,10 +11874,11 @@
974911874 // DRAW
975011875 object.draw(this, /*(Composite)*/ object, false, false);
975111876
9752
- if (drawMode == DEFAULT)
11877
+ if (DrawMode() == DEFAULT)
975311878 {
9754
- if (DEBUG)
11879
+ if (Globals.DEBUG)
975511880 {
11881
+ CreateSelectedPoint();
975611882 float radius = 0.05f;
975711883 if (selectedpoint.radius != radius)
975811884 {
....@@ -9801,38 +11927,57 @@
980111927 }
980211928 // GrafreeD.traceoff();
980311929 //System.out.println(stackdepth);
9804
- if (drawMode == 0)
11930
+ if (DrawMode() == 0)
980511931 {
980611932 ReleaseTextures(DEFAULT_TEXTURES);
980711933
980811934 if (CLEANCACHE)
9809
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
981011936 {
9811
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
981211938
981311939 // System.out.println("Texture --------- " + tex);
981411940
9815
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
981611942 continue;
981711943
9818
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
981911945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
982011947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9821
- textures.get(tex).texture.dispose();
9822
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
982311961 }
982411962 }
982511963 }
982611964
982711965 checker = null;
982811966
9829
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11967
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
983011968 FindChecker(object);
983111969
9832
- if (checker != null && drawMode == DEFAULT)
11970
+ if (checker != null && DrawMode() == DEFAULT)
983311971 {
983411972 //BindTexture(IMMORTAL_TEXTURE);
9835
- BindTextures(checker.GetTextures(), checker.texres);
11973
+ try
11974
+ {
11975
+ BindTextures(checker.GetTextures(), checker.texres);
11976
+ }
11977
+ catch (Exception e)
11978
+ {
11979
+ System.err.println("FAILED: " + checker.GetTextures());
11980
+ }
983611981 // NEAREST
983711982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
983811983 DrawChecker(gl);
....@@ -9851,7 +11996,7 @@
985111996 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
985211997 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
985311998
9854
- if (DISPLAYTEXT && drawMode == DEFAULT)
11999
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
985512000 {
985612001 // Draw it once, then use the raster
985712002 Balloon(gl, balloon.createGraphics());
....@@ -9907,14 +12052,14 @@
990712052 int[] xs = new int[3];
990812053 int[] ys = new int[3];
990912054
9910
- void DrawString(Object3D obj) // String string)
12055
+ public void DrawString(Object3D obj) // String string) // INTERFACE
991112056 {
9912
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12057
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
991312058 {
991412059 return;
991512060 }
991612061
9917
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
991812063
991912064 GL gl = GetGL();
992012065
....@@ -10231,8 +12376,8 @@
1023112376 //obj.TransformToWorld(light, light);
1023212377 for (int i = tp.size(); --i >= 0;)
1023312378 {
10234
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10235
- LA.xformPos(light, tp.get(i).toParent, light);
12379
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1023612381 }
1023712382
1023812383
....@@ -10249,8 +12394,8 @@
1024912394 parentcam = cameras[0];
1025012395 }
1025112396
10252
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10253
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12397
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1025412399
1025512400 LA.xformPos(light, renderCamera.toScreen, light);
1025612401
....@@ -10340,8 +12485,76 @@
1034012485
1034112486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1034212487
10343
- String program =
12488
+ String programmin =
12489
+ // Min shader
1034412490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1034512558 //"OPTION ARB_fragment_program_shadow;" +
1034612559 "PARAM light2cam0 = program.env[10];" +
1034712560 "PARAM light2cam1 = program.env[11];" +
....@@ -10456,8 +12669,7 @@
1045612669 "TEMP shininess;" +
1045712670 "\n" +
1045812671 "MOV texSamp, one;" +
10459
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10460
-
12672
+
1046112673 "MOV mapgrid.x, one2048th.x;" +
1046212674 "MOV temp, fragment.texcoord[1];" +
1046312675 /*
....@@ -10478,20 +12690,20 @@
1047812690 "MUL temp, floor, mapgrid.x;" +
1047912691 //"TEX depth0, temp, texture[1], 2D;" +
1048012692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10481
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1048212694 "") +
1048312695 "ADD temp.x, temp.x, mapgrid.x;" +
1048412696 //"TEX depth1, temp, texture[1], 2D;" +
1048512697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10486
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1048712699 "") +
1048812700 "ADD temp.y, temp.y, mapgrid.x;" +
1048912701 //"TEX depth2, temp, texture[1], 2D;" +
10490
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1049112703 "SUB temp.x, temp.x, mapgrid.x;" +
1049212704 //"TEX depth3, temp, texture[1], 2D;" +
1049312705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10494
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1049512707 "") +
1049612708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1049712709 //"MOV params, material;" +
....@@ -10862,10 +13074,10 @@
1086213074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1086313075 "") +
1086413076
10865
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1086613078 "SUB temp.x, half.x, shadow.x;" +
10867
- "MOV temp.y, -params6.x;" +
10868
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1086913081 "SUB temp.y, one.x, temp.z;" +
1087013082 "MUL temp.x, temp.x, temp.y;" +
1087113083 "KIL temp.x;" +
....@@ -10994,8 +13206,10 @@
1099413206 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1099513207
1099613208 "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
13209
+ // Tuning for default skin
13210
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13211
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13212
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1099913213 "MUL temp.x, temp.x, temp.y;" +
1100013214
1100113215 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11194,7 +13408,14 @@
1119413408 //once = true;
1119513409 }
1119613410
11197
- System.out.print("Program #" + mode + "; length = " + program.length());
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
13418
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1119813419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1119913420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1120013421
....@@ -11287,25 +13508,26 @@
1128713508 return out;
1128813509 }
1128913510
11290
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1129113513 {
1129213514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1129313515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1129413516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1129513519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1130013522 //"SWZ buffer, temp, w,w,w,w;";
11301
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1130213524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1130313525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1130413526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11305
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130613528
11307
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11308
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130913531 }
1131013532
1131113533 String Shadow(String depth, String shadow)
....@@ -11327,12 +13549,16 @@
1132713549
1132813550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1132913551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1133013554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1133113555 "SGE temp.y, temp.x, zero.x;" +
11332
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1133313559 "SUB temp.x, one.x, temp.x;" +
1133413560 "MUL " + shadow + ".x, temp.x, temp.y;" +
11335
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1133613562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1133713563
1133813564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11346,6 +13572,10 @@
1134613572 // No shadow for backface
1134713573 "DP3 temp.x, normal, lightd;" +
1134813574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13575
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13576
+
13577
+ // No shadow when out of frustum
13578
+ "SGE temp.x, " + depth + ".z, one.z;" +
1134913579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1135013580 "";
1135113581 }
....@@ -11492,7 +13722,8 @@
1149213722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1149313723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1149413724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11495
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1149613727
1149713728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1149813729 // OUT : diff, spec
....@@ -11508,9 +13739,10 @@
1150813739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1150913740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1151013741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1151413746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1151513747 "RCP " + dest + ".w," + dest + ".w;" +
1151613748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11904,7 +14136,7 @@
1190414136 public void mousePressed(MouseEvent e)
1190514137 {
1190614138 //System.out.println("mousePressed: " + e);
11907
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1190814140 }
1190914141
1191014142 static long prevtime = 0;
....@@ -11931,14 +14163,16 @@
1193114163
1193214164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1193314165
14166
+ if (BUTTONLESSWHEEL)
1193414167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1193514168 {
1193614169 return;
1193714170 }
1193814171
14172
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1193914173
1194014174 // TIMER
11941
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1194214176 {
1194314177 keepboxmode = BOXMODE;
1194414178 keepsupport = SUPPORT;
....@@ -11978,8 +14212,8 @@
1197814212 // mode |= META;
1197914213 //}
1198014214
11981
- SetMouseMode(WHEEL | e.getModifiersEx());
11982
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1198314217 anchorX = ax;
1198414218 anchorY = ay;
1198514219 prevX = px;
....@@ -12013,6 +14247,7 @@
1201314247 else
1201414248 if (evt.getSource() == AAtimer)
1201514249 {
14250
+ Globals.TIMERRUNNING = false;
1201614251 if (mouseDown)
1201714252 {
1201814253 //new Exception().printStackTrace();
....@@ -12038,6 +14273,10 @@
1203814273 // LIVE = waslive;
1203914274 // wasliveok = true;
1204014275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1204114280
1204214281 // source == timer
1204314282 if (mouseDown)
....@@ -12067,8 +14306,8 @@
1206714306 // ObjEditor.tweenManager.update(1f / 60f);
1206814307
1206914308 // fev 2014???
12070
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12071
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14309
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1207214311 pingthread.StepToTarget(true); // true);
1207314312 }
1207414313 // if (!LIVE)
....@@ -12077,12 +14316,13 @@
1207714316
1207814317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1207914318
12080
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1208114320 {
1208214321 if (!wasliveok)
1208314322 return;
1208414323
1208514324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1208614326
1208714327 // waslive = LIVE;
1208814328 // LIVE = false;
....@@ -12094,7 +14334,7 @@
1209414334 // touched = true; // main DL
1209514335 if (isRenderer)
1209614336 {
12097
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1209814338 }
1209914339
1210014340 selectX = anchorX = x;
....@@ -12107,7 +14347,7 @@
1210714347 clicked = true;
1210814348 hold = false;
1210914349
12110
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1211114351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1211214352 {
1211314353 // System.out.println("RESTART II " + modifiers);
....@@ -12132,14 +14372,15 @@
1213214372 drag = false;
1213314373 //System.out.println("Mouse DOWN");
1213414374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1214314384 if (!editObj)
1214414385 {
1214514386 hasMarquee = true;
....@@ -12155,11 +14396,14 @@
1215514396
1215614397 public void mouseDragged(MouseEvent e)
1215714398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1215814402 if (isRenderer)
1215914403 movingcamera = true;
14404
+
1216014405 //if (drawing)
1216114406 //return;
12162
- //System.out.println("mouseDragged: " + e);
1216314407 if ((e.getModifiersEx() & CTRL) != 0
1216414408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1216514409 {
....@@ -12167,7 +14411,7 @@
1216714411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1216814412 }
1216914413 else
12170
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1217114415
1217214416 //try { Thread.sleep(1); } catch (Exception ex) {}
1217314417 }
....@@ -12179,6 +14423,11 @@
1217914423 cVector tmp = new cVector();
1218014424 cVector tmp2 = new cVector();
1218114425 boolean isMoving;
14426
+
14427
+ public cVector TargetLookAt()
14428
+ {
14429
+ return targetLookAt;
14430
+ }
1218214431
1218314432 class PingThread extends Thread
1218414433 {
....@@ -12318,7 +14567,7 @@
1231814567 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1231914568 if (lightMode)
1232014569 {
12321
- lighttouched = true;
14570
+ Globals.lighttouched = true;
1232214571 }
1232314572
1232414573 if (OEILONCE && OEIL)
....@@ -12335,6 +14584,7 @@
1233514584
1233614585 public void run()
1233714586 {
14587
+ new Exception().printStackTrace();
1233814588 System.exit(0);
1233914589 for (;;)
1234014590 {
....@@ -12376,7 +14626,7 @@
1237614626 mouseDown = false;
1237714627 if (lightMode)
1237814628 {
12379
- lighttouched = true;
14629
+ Globals.lighttouched = true;
1238014630 }
1238114631 repaint();
1238214632 alreadypainted = true;
....@@ -12384,7 +14634,7 @@
1238414634 isMoving = false;
1238514635 } //??
1238614636
12387
- if (isLIVE() && !alreadypainted)
14637
+ if (Globals.isLIVE() && !alreadypainted)
1238814638 {
1238914639 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1239014640 repaint();
....@@ -12396,9 +14646,9 @@
1239614646 {
1239714647 if (lightMode)
1239814648 {
12399
- lighttouched = true;
14649
+ Globals.lighttouched = true;
1240014650 }
12401
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1240214652 }
1240314653 //else
1240414654 }
....@@ -12412,12 +14662,12 @@
1241214662 void GoDown(int mod)
1241314663 {
1241414664 MODIFIERS |= COMMAND;
12415
- /*
14665
+ /**/
1241614666 if((mod&SHIFT) == SHIFT)
12417
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1241814668 else
12419
- manipCamera.BackForth(0, -speed*delta, getWidth());
12420
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1242114671 if ((mod & SHIFT) == SHIFT)
1242214672 {
1242314673 mouseMode = mouseMode; // VR??
....@@ -12433,12 +14683,12 @@
1243314683 void GoUp(int mod)
1243414684 {
1243514685 MODIFIERS |= COMMAND;
12436
- /*
14686
+ /**/
1243714687 if((mod&SHIFT) == SHIFT)
12438
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1243914689 else
12440
- manipCamera.BackForth(0, speed*delta, getWidth());
12441
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1244214692 if ((mod & SHIFT) == SHIFT)
1244314693 {
1244414694 mouseMode = mouseMode;
....@@ -12454,12 +14704,12 @@
1245414704 void GoLeft(int mod)
1245514705 {
1245614706 MODIFIERS |= COMMAND;
12457
- /*
14707
+ /**/
1245814708 if((mod&SHIFT) == SHIFT)
12459
- manipCamera.RotatePosition(speed, 0);
12460
- else
1246114709 manipCamera.Translate(speed*delta, 0, getWidth());
12462
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1246314713 if ((mod & SHIFT) == SHIFT)
1246414714 {
1246514715 mouseMode = mouseMode;
....@@ -12475,12 +14725,12 @@
1247514725 void GoRight(int mod)
1247614726 {
1247714727 MODIFIERS |= COMMAND;
12478
- /*
14728
+ /**/
1247914729 if((mod&SHIFT) == SHIFT)
12480
- manipCamera.RotatePosition(-speed, 0);
12481
- else
1248214730 manipCamera.Translate(-speed*delta, 0, getWidth());
12483
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1248414734 if ((mod & SHIFT) == SHIFT)
1248514735 {
1248614736 mouseMode = mouseMode;
....@@ -12498,7 +14748,7 @@
1249814748 int X, Y;
1249914749 boolean SX, SY;
1250014750
12501
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1250214752 {
1250314753 if (IsFrozen())
1250414754 {
....@@ -12507,17 +14757,17 @@
1250714757
1250814758 drag = true; // NEW
1250914759
12510
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1251114761
1251214762 X = x;
1251314763 Y = y;
1251414764 // floating state for animation
12515
- MODIFIERS = modifiers;
12516
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1251714767 if (false) // modifiers != 0)
1251814768 {
1251914769 //new Exception().printStackTrace();
12520
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1252114771 System.out.println("SHIFT = " + SHIFT);
1252214772 System.out.println("CONTROL = " + COMMAND);
1252314773 System.out.println("META = " + META);
....@@ -12530,14 +14780,16 @@
1253014780 if (editObj)
1253114781 {
1253214782 drag = true;
12533
- ClickInfo info = new ClickInfo();
12534
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1253514785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1254114793 } else
1254214794 {
1254314795 if (x < startX)
....@@ -12639,6 +14891,7 @@
1263914891 {
1264014892 manipCamera.Translate(dx, dy, getWidth());
1264114893 }
14894
+ else
1264214895 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1264314896 {
1264414897 manipCamera.RotateInterest(dx, dy);
....@@ -12649,7 +14902,7 @@
1264914902
1265014903 if (manipCamera == lightCamera)
1265114904 {
12652
- lighttouched = true;
14905
+ Globals.lighttouched = true;
1265314906 }
1265414907 /*
1265514908 switch (mode)
....@@ -12685,23 +14938,27 @@
1268514938 }
1268614939 }
1268714940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1268814943 public void mouseMoved(MouseEvent e)
1268914944 {
1269014945 //System.out.println("mouseMoved: " + e);
12691
-
1269214946 if (isRenderer)
1269314947 return;
1269414948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1270214956 if (!isRenderer)
1270314957 {
12704
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1270514962 {
1270614963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1270714964 } else
....@@ -12713,7 +14970,11 @@
1271314970
1271414971 public void mouseReleased(MouseEvent e)
1271514972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1271614975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1271714978 //System.out.println("mouseReleased: " + e);
1271814979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1271914980 }
....@@ -12736,9 +14997,9 @@
1273614997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1273714998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1273814999
12739
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1274015001 timeout = true;
12741
- else
15002
+// ?? May 2019 else
1274215003 // timer.setDelay((modifiers & 128) != 0?0:350);
1274315004 mouseDown = false;
1274415005 if (!control && !command) // june 2013
....@@ -12848,7 +15109,7 @@
1284815109 System.out.println("keyReleased: " + e);
1284915110 }
1285015111
12851
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1285215113 {
1285315114 //System.out.println("SetMouseMode = " + modifiers);
1285415115 //modifiers &= ~1024;
....@@ -12860,25 +15121,25 @@
1286015121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1286115122 // return;
1286215123 //System.out.println("SetMode = " + modifiers);
12863
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1286415125 {
1286515126 mouseMode |= ZOOM;
1286615127 }
1286715128
1286815129 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
12869
- if (capsLocked || (modifiers & META) == META)
15130
+ if (capsLocked) // || (modifiers & META) == META)
1287015131 {
1287115132 mouseMode |= VR; // BACKFORTH;
1287215133 }
12873
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12874
- {
12875
- mouseMode |= SELECT; // BACKFORTH;
12876
- }
12877
- if ((modifiers & COMMAND) == COMMAND)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1287815135 {
1287915136 mouseMode |= SELECT;
1288015137 }
12881
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
15139
+ {
15140
+ mouseMode |= SELECT;
15141
+ }
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1288215143 {
1288315144 mouseMode &= ~VR;
1288415145 mouseMode |= TRANSLATE;
....@@ -12907,10 +15168,10 @@
1290715168
1290815169 if (isRenderer) //
1290915170 {
12910
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1291115172 }
1291215173
12913
- theRenderer.keyPressed(key);
15174
+ Globals.theRenderer.keyPressed(key);
1291415175 }
1291515176
1291615177 int kompactbit = 4; // power bit
....@@ -12922,7 +15183,7 @@
1292215183 float SATPOW = 1; // 2; // 0.5f;
1292315184 float BRIPOW = 1; // 0.5f; // 0.5f;
1292415185
12925
- void keyPressed(int key)
15186
+ public void keyPressed(int key)
1292615187 {
1292715188 if (key >= '0' && key <= '5')
1292815189 clampbit = (key-'0');
....@@ -12969,7 +15230,8 @@
1296915230 // break;
1297015231 case 'T':
1297115232 CACHETEXTURE ^= true;
12972
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1297315235 // repaint();
1297415236 break;
1297515237 case 'Y':
....@@ -13037,7 +15299,7 @@
1303715299 case 'B':
1303815300 BRISMOOTH ^= true;
1303915301 SHADOWCULLFACE ^= true;
13040
- lighttouched = true;
15302
+ Globals.lighttouched = true;
1304115303 repaint();
1304215304 break;
1304315305 case 'b':
....@@ -13054,7 +15316,9 @@
1305415316 case 'E' : COMPACT ^= true;
1305515317 repaint();
1305615318 break;
13057
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1305815322 repaint();
1305915323 break;
1306015324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13079,8 +15343,8 @@
1307915343 RevertCamera();
1308015344 repaint();
1308115345 break;
13082
- case 'L':
1308315346 case 'l':
15347
+ //case 'L':
1308415348 if (lightMode)
1308515349 {
1308615350 lightMode = false;
....@@ -13137,27 +15401,31 @@
1313715401 repaint();
1313815402 break;
1313915403 case 'O':
13140
- drawMode = OCCLUSION;
15404
+ Globals.drawMode = OCCLUSION; // WARNING
1314115405 repaint();
1314215406 break;
1314315407 case 'o':
1314415408 OCCLUSION_CULLING ^= true;
1314515409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1314615410 break;
13147
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1314815412 case '1':
1314915413 case '2':
1315015414 case '3':
1315115415 case '4':
1315215416 case '5':
13153
- newenvy = Character.getNumericValue(key);
13154
- repaint();
13155
- break;
1315615417 case '6':
1315715418 case '7':
1315815419 case '8':
1315915420 case '9':
13160
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1316115429 repaint();
1316215430 break;
1316315431 case '!':
....@@ -13223,12 +15491,12 @@
1322315491 case '_':
1322415492 kompactbit = 5;
1322515493 break;
13226
- case '+':
13227
- kompactbit = 6;
13228
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1322915497 case ' ':
1323015498 lightMode ^= true;
13231
- lighttouched = true;
15499
+ Globals.lighttouched = true;
1323215500 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1323315501 targetLookAt.set(manipCamera.lookAt);
1323415502 repaint();
....@@ -13237,14 +15505,15 @@
1323715505 case ESC:
1323815506 RENDERPROGRAM += 1;
1323915507 RENDERPROGRAM %= 3;
15508
+
1324015509 repaint();
1324115510 break;
1324215511 case 'Z':
13243
- RESIZETEXTURE ^= true;
13244
- break;
15512
+ //RESIZETEXTURE ^= true;
15513
+ //break;
1324515514 case 'z':
13246
- RENDERSHADOW ^= true;
13247
- lighttouched = true;
15515
+ Globals.RENDERSHADOW ^= true;
15516
+ Globals.lighttouched = true;
1324815517 repaint();
1324915518 break;
1325015519 //case UP:
....@@ -13276,8 +15545,9 @@
1327615545 case DELETE:
1327715546 ClearSelection();
1327815547 break;
13279
- /*
1328015548 case '+':
15549
+
15550
+ /*
1328115551 //fontsize += 1;
1328215552 bbzoom *= 2;
1328315553 repaint();
....@@ -13294,17 +15564,17 @@
1329415564 case '=':
1329515565 IncDepth();
1329615566 //fontsize += 1;
13297
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1329815568 maskbit = 6;
1329915569 break;
1330015570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1330115571 DecDepth();
1330215572 maskbit = 5;
1330315573 //if(fontsize > 1) fontsize -= 1;
13304
- if (object.editWindow == null)
13305
- new Exception().printStackTrace();
13306
- else
13307
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1330815578 break;
1330915579 case '{':
1331015580 manipCamera.shaper_fovy /= 1.1;
....@@ -13359,6 +15629,7 @@
1335915629 }
1336015630 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1336115631 }
15632
+
1336215633 static double OCCLUSIONBOOST = 1; // 0.5;
1336315634
1336415635 void keyReleased(int key, int modifiers)
....@@ -13366,11 +15637,11 @@
1336615637 //mode = ROTATE;
1336715638 if ((MODIFIERS & COMMAND) == 0) // VR??
1336815639 {
13369
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1337015641 }
1337115642 }
1337215643
13373
- protected void processKeyEvent(KeyEvent e)
15644
+ public void processKeyEvent(KeyEvent e)
1337415645 {
1337515646 switch (e.getID())
1337615647 {
....@@ -13500,8 +15771,9 @@
1350015771
1350115772 protected void processMouseMotionEvent(MouseEvent e)
1350215773 {
13503
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13504
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15774
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15775
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1350515777 {
1350615778 mouseMoved(e);
1350715779 } else
....@@ -13526,11 +15798,12 @@
1352615798 }
1352715799 */
1352815800
13529
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1353015802 }
1353115803
1353215804 void SelectParent()
1353315805 {
15806
+ new Exception().printStackTrace();
1353415807 System.exit(0);
1353515808 Composite group = (Composite) object;
1353615809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13542,10 +15815,10 @@
1354215815 {
1354315816 //selectees.remove(i);
1354415817 System.out.println("select parent of " + elem);
13545
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1354615819 } else
1354715820 {
13548
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1354915822 }
1355015823
1355115824 first = false;
....@@ -13554,6 +15827,7 @@
1355415827
1355515828 void SelectChildren()
1355615829 {
15830
+ new Exception().printStackTrace();
1355715831 System.exit(0);
1355815832 /*
1355915833 Composite group = (Composite) object;
....@@ -13586,12 +15860,12 @@
1358615860 for (int j = 0; j < group.children.size(); j++)
1358715861 {
1358815862 elem = (Object3D) group.children.elementAt(j);
13589
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1359015864 first = false;
1359115865 }
1359215866 } else
1359315867 {
13594
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1359515869 }
1359615870
1359715871 first = false;
....@@ -13602,21 +15876,21 @@
1360215876 {
1360315877 //Composite group = (Composite) object;
1360415878 Object3D group = object;
13605
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1360615880 }
1360715881
1360815882 void ResetTransform(int mask)
1360915883 {
1361015884 //Composite group = (Composite) object;
1361115885 Object3D group = object;
13612
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1361315887 }
1361415888
1361515889 void FlipTransform()
1361615890 {
1361715891 //Composite group = (Composite) object;
1361815892 Object3D group = object;
13619
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1362015894 // group.editWindow.ReduceMesh(true);
1362115895 }
1362215896
....@@ -13624,7 +15898,7 @@
1362415898 {
1362515899 //Composite group = (Composite) object;
1362615900 Object3D group = object;
13627
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1362815902 // group.editWindow.ReduceMesh(true);
1362915903 }
1363015904
....@@ -13632,7 +15906,7 @@
1363215906 {
1363315907 //Composite group = (Composite) object;
1363415908 Object3D group = object;
13635
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1363615910 }
1363715911
1363815912 void IncDepth()
....@@ -13714,11 +15988,11 @@
1371415988
1371515989 int width = getBounds().width;
1371615990 int height = getBounds().height;
13717
- ClickInfo info = new ClickInfo();
13718
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1371915991 //Image img = CreateImage(width, height);
1372015992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1372115994 Graphics gr = g; // img.getGraphics();
15995
+
1372215996 if (!hasMarquee)
1372315997 {
1372415998 if (Xmin < Xmax) // !locked)
....@@ -13790,40 +16064,88 @@
1379016064 }
1379116065 if (object != null && !hasMarquee)
1379216066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1379316073 if (isRenderer)
1379416074 {
13795
- info.flags++;
16075
+ object.clickInfo.flags++;
1379616076 double frameAspect = (double) width / (double) height;
1379716077 if (frameAspect > renderCamera.aspect)
1379816078 {
1379916079 int desired = (int) ((double) height * renderCamera.aspect);
13800
- info.bounds.width -= width - desired;
13801
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1380216082 } else
1380316083 {
1380416084 int desired = (int) ((double) width / renderCamera.aspect);
13805
- info.bounds.height -= height - desired;
13806
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1380716087 }
1380816088 }
13809
- info.g = gr;
13810
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1381116092 /*
1381216093 // Memory intensive (brep.verticescopy)
1381316094 if (!(object instanceof Composite))
1381416095 object.draw(info, 0, false); // SLOW :
1381516096 */
13816
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1381716098 {
13818
- object.drawEditHandles(info, 0);
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
16102
+ {
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
16109
+ {
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
16117
+ }
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
16138
+ }
1381916139 }
1382016140 }
16141
+
1382116142 if (isRenderer)
1382216143 {
1382316144 //gr.setColor(Color.black);
1382416145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1382516146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1382616147 }
16148
+
1382716149 if (hasMarquee)
1382816150 {
1382916151 gr.setXORMode(Color.white);
....@@ -13846,6 +16168,7 @@
1384616168 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1384716169 }
1384816170
16171
+ // To avoid clear.
1384916172 public void update(Graphics g)
1385016173 {
1385116174 paint(g);
....@@ -13935,6 +16258,7 @@
1393516258 public boolean mouseDown(Event evt, int x, int y)
1393616259 {
1393716260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1393816262 /*
1393916263 locked = true;
1394016264 drag = false;
....@@ -13978,7 +16302,7 @@
1397816302 {
1397916303 keyPressed(0, modifiers);
1398016304 }
13981
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1398216306 return true;
1398316307 }
1398416308
....@@ -14096,7 +16420,7 @@
1409616420 {
1409716421 keyReleased(0, 0);
1409816422 }
14099
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1410016424 return true;
1410116425 }
1410216426
....@@ -14228,7 +16552,7 @@
1422816552 Object3D object;
1422916553 static Object3D trackedobject;
1423016554 Camera renderCamera; // Light or Eye (or Occlusion)
14231
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1423216556 /*static*/ Camera eyeCamera;
1423316557 /*static*/ Camera lightCamera;
1423416558 int cameracount;
....@@ -14292,6 +16616,8 @@
1429216616 private /*static*/ boolean firstime;
1429316617 private /*static*/ cVector newView = new cVector();
1429416618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1429516621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1429616622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1429716623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14304,29 +16630,67 @@
1430416630 {
1430516631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1430616632
16633
+ int usedsuf = 0;
16634
+
1430716635 for (int i = 0; i < suffixes.length; i++)
1430816636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1431416642 {
14315
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1431616647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1431716676 //System.out.println("Target = " + targets[i]);
1431816677 cubemap.updateImage(data, targets[i]);
1431916678 }
1432016679
1432116680 return cubemap;
1432216681 }
16682
+
1432316683 int bigsphere = -1;
1432416684
1432516685 float BGcolor = 0.5f;
1432616686
14327
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1432816690 {
14329
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1433016694 {
1433116695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1433216696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14341,7 +16705,17 @@
1434116705 // Compensates for ExaminerViewer's modification of modelview matrix
1434216706 gl.glMatrixMode(GL.GL_MODELVIEW);
1434316707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1434416709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1434516719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1434616720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1434716721
....@@ -14373,6 +16747,7 @@
1437316747 {
1437416748 gl.glScalef(1.0f, -1.0f, 1.0f);
1437516749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1437616751 gl.glMultMatrixd(viewrot_1, 0);
1437716752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1437816753 //viewer.updateInverseRotation(gl);
....@@ -14508,20 +16883,21 @@
1450816883 /**/
1450916884 //checker.GetMaterial().opacity = 1.1f;
1451016885 ////checker.GetMaterial().ambient = 0.99f;
14511
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14512
- Object3D.selectedstack[Object3D.materialdepth] = false;
14513
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16886
+ materialstack[materialdepth] = checker.material;
16887
+ selectedstack[materialdepth] = false;
16888
+ cStatic.objectstack[materialdepth++] = checker;
1451416889 //System.out.println("material " + material);
1451516890 //Applet3D.tracein(this, selected);
14516
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1451716892
14518
- checker.GetMaterial().Draw(this, false); // true);
16893
+ //checker.GetMaterial().Draw(this, false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1451916895
14520
- Object3D.materialdepth -= 1;
14521
- if (Object3D.materialdepth > 0)
16896
+ materialdepth -= 1;
16897
+ if (materialdepth > 0)
1452216898 {
14523
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14524
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1452516901 }
1452616902 //checker.GetMaterial().opacity = 1f;
1452716903 ////checker.GetMaterial().ambient = 1f;
....@@ -14607,6 +16983,14 @@
1460716983 }
1460816984 }
1460916985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1461016994 class SelectBuffer implements GLEventListener
1461116995 {
1461216996
....@@ -14622,7 +17006,7 @@
1462217006 //new Exception().printStackTrace();
1462317007 System.out.println("select buffer init");
1462417008 // Use debug pipeline
14625
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1462617010
1462717011 GL gl = drawable.getGL();
1462817012
....@@ -14665,6 +17049,7 @@
1466517049 {
1466617050 if (!selection)
1466717051 {
17052
+ new Exception().printStackTrace();
1466817053 System.exit(0);
1466917054 return;
1467017055 }
....@@ -14685,17 +17070,39 @@
1468517070
1468617071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1468717072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1468817084 //int tmp = selection_view;
1468917085 //selection_view = -1;
14690
- int temp = drawMode;
14691
- drawMode = SELECTION;
17086
+ int temp = DrawMode();
17087
+ Globals.drawMode = SELECTION; // WARNING
1469217088 indexcount = 0;
1469317089 parent.display(drawable);
1469417090 //selection_view = tmp;
1469517091 //if (temp == SELECTION)
1469617092 // temp = DEFAULT; // patch for selection debug
14697
- drawMode = temp;
17093
+ Globals.drawMode = temp; // WARNING
1469817094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1469917106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1470017107
1470117108 // trying different ways of getting the depth info over
....@@ -14743,6 +17150,8 @@
1474317150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1474417151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1474517152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1474617155
1474717156 // Will fit the mesh !!!
1474817157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -14792,34 +17201,36 @@
1479217201 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]));
1479317202 }
1479417203
14795
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1479617205 }
1479717206 }
1479817207
1479917208 if (!movingcamera && !PAINTMODE)
14800
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1480117210
14802
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1480317212 {
14804
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1480517214
14806
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1480717218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1482317234 }
1482417235 else
1482517236 paintcount = 0;
....@@ -14858,6 +17269,11 @@
1485817269 //System.out.println("objects[color] = " + objects[color]);
1485917270 //objects[color].Select();
1486017271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1486117277 object.Select(color, deselect);
1486217278 }
1486317279
....@@ -14957,7 +17373,7 @@
1495717373 gl.glDisable(gl.GL_CULL_FACE);
1495817374 }
1495917375
14960
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1496117377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1496217378
1496317379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14967,14 +17383,14 @@
1496717383 //gl.glColorMask(false, false, false, false);
1496817384
1496917385 //render_scene_from_light_view(gl, drawable, 0, 0);
14970
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1497117387 {
1497217388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1497317389
14974
- int temp = drawMode;
14975
- drawMode = SHADOW;
17390
+ int temp = DrawMode();
17391
+ Globals.drawMode = SHADOW; // WARNING
1497617392 parent.display(drawable);
14977
- drawMode = temp;
17393
+ Globals.drawMode = temp; // WARNING
1497817394 }
1497917395
1498017396 gl.glCullFace(gl.GL_BACK);
....@@ -15027,7 +17443,6 @@
1502717443
1502817444 class AntialiasBuffer implements GLEventListener
1502917445 {
15030
-
1503117446 CameraPane parent = null;
1503217447
1503317448 AntialiasBuffer(CameraPane p)
....@@ -15137,10 +17552,14 @@
1513717552 gl.glFlush();
1513817553
1513917554 /**/
15140
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1514117556
15142
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1514317558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1514417563 double r = 0, g = 0, b = 0;
1514517564
1514617565 double count = 0;
....@@ -15151,7 +17570,7 @@
1515117570
1515217571 double FACTOR = 1;
1515317572
15154
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1515517574 {
1515617575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1515717576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15234,7 +17653,7 @@
1523417653
1523517654 double scale = ray.z; // 1; // cos
1523617655
15237
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1523817657
1523917658 /*
1524017659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15372,12 +17791,6 @@
1537217791 GLUT glut = new GLUT();
1537317792
1537417793
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;
1538117794 public boolean spherical = false;
1538217795 static boolean DEBUG_OCCLUSION = false;
1538317796 static boolean DEBUG_SELECTION = false;
....@@ -15390,23 +17803,15 @@
1539017803 int AAbuffersize = 0;
1539117804
1539217805 //double[] selectedpoint = new double[3];
15393
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1539417807 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();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1539917812
1540017813 static Sphere debugpoints[] = new Sphere[8];
1540117814
15402
- static
15403
- {
15404
- for (int i=0; i<8; i++)
15405
- {
15406
- debugpoints[i] = new Sphere();
15407
- }
15408
- }
15409
-
1541017815 static void InitPoints(float radius)
1541117816 {
1541217817 for (int i=0; i<8; i++)
....@@ -15426,7 +17831,7 @@
1542617831 }
1542717832 }
1542817833
15429
- static void DrawPoints(CameraPane cpane)
17834
+ static void DrawPoints(iCameraPane cpane)
1543017835 {
1543117836 for (int i=0; i<8; i++) // first and last are red
1543217837 {
....@@ -15445,11 +17850,14 @@
1544517850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1544617851 static IntBuffer bigAAbuffer;
1544717852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15448
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1544917854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1545017855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1545117856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
15452
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1545317861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1545417862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1545517863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15458,10 +17866,11 @@
1545817866 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1545917867 // Depth buffer format
1546017868 //private int depth_format;
15461
- static public void NextIndex(Object3D o, GL gl)
17869
+
17870
+ public void NextIndex()
1546217871 {
1546317872 indexcount+=16;
15464
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17873
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1546517874 //objects[indexcount] = o;
1546617875 //System.out.println("indexcount = " + indexcount);
1546717876 }