Normand Briere
2019-08-22 6a145f6c81dfcbe0653eda27d042efb48daa7512
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,10 +33,14 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
34
-class CameraPane extends GLCanvas implements Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
38
+class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
36
- static boolean DEBUG = false;
40
+ static cMaterial[] materialstack = new cMaterial[65536];
41
+ static boolean[] selectedstack = new boolean[65536];
42
+ static int materialdepth = 0;
43
+
3744 static boolean FRUSTUM = false; // still bogus true; // frustum culling
3845
3946 // camera change fix
....@@ -42,25 +49,40 @@
4249
4350 static int STEP = 1;
4451
45
- static boolean ONESTEP = false; // do LIVE once
46
-
47
- /**
48
- * @return the LIVE
49
- */
50
- public static boolean isLIVE()
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
5153 {
52
- return LIVE || ONESTEP;
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
5383 }
5484
55
- /**
56
- * @param aLIVE the LIVE to set
57
- */
58
- public static void setLIVE(boolean aLIVE)
59
- {
60
- LIVE = aLIVE;
61
- }
62
-
63
- /*static*/ boolean CULLFACE = false; // true;
85
+ /*static*/ private boolean CULLFACE = false; // true;
6486 /*static*/ boolean NEAREST = false; // true;
6587 /*static*/ boolean WIREFRAME = false; // true;
6688
....@@ -70,14 +92,12 @@
7092 static int CURRENTANTIALIAS = 0; // 1;
7193 /*static*/ boolean RENDERSHADOW = true;
7294 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
73
- static boolean ANIMATION = false;
74
- static String filename;
7595
7696 boolean DISPLAYTEXT = false;
7797 //boolean REDUCETEXTURE = true;
7898 boolean CACHETEXTURE = true;
7999 boolean CLEANCACHE = false; // true;
80
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
81101 boolean COMPRESSTEXTURE = false;
82102 boolean KOMPACTTEXTURE = false; // true;
83103 boolean RESIZETEXTURE = false;
....@@ -90,17 +110,19 @@
90110 //private Mat4f spotlightTransform = new Mat4f();
91111 //private Mat4f spotlightInverseTransform = new Mat4f();
92112 static GLContext glcontext = null;
93
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
94118 boolean reverseUP = false;
95119 static boolean frozen = false;
96120 boolean enablebackspace = false; // patch for back buffer refresh
97121
98122 static boolean textureon = true;
99123 static boolean LOCALTRANSFORM = false;
100
-private static boolean LIVE = false;
101124 static boolean FULLSCREEN = false;
102125 static boolean SUPPORT = true;
103
-static boolean CROWD = false;
104126 static boolean INERTIA = true;
105127 static boolean FAST = false;
106128 static boolean SLOWPOSE = false;
....@@ -108,6 +130,8 @@
108130
109131 static int tickcount = 0; // slow pose issue
110132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
111135 static boolean BOXMODE = false;
112136 static boolean IMAGEFLIP = false;
113137 static boolean SMOOTHFOCUS = false;
....@@ -122,7 +146,7 @@
122146 static boolean OEIL = true;
123147 static boolean OEILONCE = false; // do oeilon then oeiloff
124148 static boolean LOOKAT = true;
125
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
126150 static boolean HANDLES = false; // selection doesn't work!!
127151 static boolean PAINTMODE = false;
128152
....@@ -144,7 +168,7 @@
144168
145169
146170 // OPTIONS
147
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
148172 boolean cameraLight = false;
149173 boolean UVdebug = false;
150174 boolean Udebug = false;
....@@ -153,7 +177,7 @@
153177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
154178 boolean anisotropy = true;
155179 boolean softshadow = true; // slower but better false;
156
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
157181
158182 boolean macromode = false;
159183
....@@ -165,12 +189,55 @@
165189 defaultcaps.setAccumBlueBits(16);
166190 defaultcaps.setAccumAlphaBits(16);
167191 }
168
- static CameraPane theRenderer;
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
169194
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
207
+
170208 void SetAsGLRenderer(boolean b)
171209 {
172210 isRenderer = b;
173
- theRenderer = this;
211
+ Globals.theRenderer = this;
212
+ }
213
+
214
+ CameraPane(Object3D o, Camera cam, boolean withcontext)
215
+ {
216
+ super(defaultcaps, null, withcontext?glcontext:null, null);
217
+
218
+ //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
219
+ glcontext = getContext();
220
+
221
+ cameras = new Camera[2];
222
+ targetLookAts = new cVector[2];
223
+
224
+ SetCamera(cam);
225
+
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
228
+
229
+ object = o;
230
+
231
+ setBackground(Color.white);
232
+
233
+ addKeyListener(this);
234
+ addMouseListener(this);
235
+ addMouseMotionListener(this);
236
+ addMouseWheelListener(this);
237
+ //System.out.println("addGLEventListener: " + this);
238
+ addGLEventListener(this);
239
+
240
+// pingthread.start(); // may 2013
174241 }
175242
176243 static boolean AntialiasingEnabled()
....@@ -178,12 +245,53 @@
178245 return CURRENTANTIALIAS > 0;
179246 }
180247
181
- void ClearDepth()
248
+ /// INTERFACE
249
+
250
+ public javax.media.opengl.GL GetGL0()
251
+ {
252
+ return null;
253
+ }
254
+
255
+ public int GenList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ return gl.glGenLists(1);
259
+ }
260
+
261
+ public void NewList(int id)
262
+ {
263
+ javax.media.opengl.GL gl = GetGL();
264
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
265
+ }
266
+
267
+ public void CallList(int id)
268
+ {
269
+ javax.media.opengl.GL gl = GetGL();
270
+ gl.glCallList(id);
271
+ }
272
+
273
+ public void EndList()
274
+ {
275
+ javax.media.opengl.GL gl = GetGL();
276
+ gl.glEndList();
277
+ }
278
+
279
+ public boolean IsBoxMode()
280
+ {
281
+ return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
287
+ }
288
+
289
+ public void ClearDepth()
182290 {
183291 GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
184292 }
185293
186
- void DepthTest(boolean depthtest)
294
+ public void DepthTest(boolean depthtest)
187295 {
188296 if (depthtest)
189297 GetGL().glDepthFunc(GL.GL_LEQUAL);
....@@ -191,7 +299,7 @@
191299 GetGL().glDepthFunc(GL.GL_ALWAYS);
192300 }
193301
194
- void DepthWrite(boolean depthwrite)
302
+ public void DepthWrite(boolean depthwrite)
195303 {
196304 if (depthwrite)
197305 GetGL().glDepthMask(true);
....@@ -199,12 +307,1617 @@
199307 GetGL().glDepthMask(false);
200308 }
201309
202
- void BackFaceCull(boolean bfc)
310
+ public void BackFaceCull(boolean bfc)
203311 {
204312 if (bfc)
205313 GetGL().glEnable(GetGL().GL_CULL_FACE);
206314 else
207315 GetGL().glDisable(GetGL().GL_CULL_FACE);
316
+ }
317
+
318
+ public boolean BackFaceCullMode()
319
+ {
320
+ return this.CULLFACE;
321
+ }
322
+
323
+ public boolean IsAmbientOcclusionOn()
324
+ {
325
+ return this.ambientOcclusion;
326
+ }
327
+
328
+ public boolean IsDebugSelection()
329
+ {
330
+ return DEBUG_SELECTION;
331
+ }
332
+
333
+ public boolean IsFrozen()
334
+ {
335
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
336
+
337
+ return !selectmode && cameracount == 0; // != 0;
338
+ }
339
+
340
+ // Currently in Globals
341
+ public int DrawMode()
342
+ {
343
+ return Globals.DrawMode();
344
+ }
345
+
346
+ public Camera EyeCamera()
347
+ {
348
+ return eyeCamera;
349
+ }
350
+
351
+ public Camera LightCamera()
352
+ {
353
+ return lightCamera;
354
+ }
355
+
356
+ public Camera ManipCamera()
357
+ {
358
+ return manipCamera;
359
+ }
360
+
361
+ public Camera RenderCamera()
362
+ {
363
+ return renderCamera;
364
+ }
365
+
366
+ public Camera[] Cameras()
367
+ {
368
+ return cameras;
369
+ }
370
+
371
+ public void PushMaterial(Object3D obj, boolean selected)
372
+ {
373
+ CameraPane display = this;
374
+ javax.media.opengl.GL gl = display.GetGL();
375
+ cMaterial material = obj.material;
376
+
377
+ if (material != null)
378
+ {
379
+ materialstack[materialdepth] = material;
380
+ selectedstack[materialdepth] = selected;
381
+ cStatic.objectstack[materialdepth++] = obj;
382
+ //System.out.println("material " + material);
383
+ //Applet3D.tracein(this, selected);
384
+ //display.vector2buffer = obj.projectedVertices;
385
+ if (obj instanceof Camera)
386
+ {
387
+ display.options1[0] = material.shift;
388
+ //System.out.println("shift " + material.shift);
389
+ display.options1[1] = material.lightarea;
390
+ display.options1[2] = material.shadowbias;
391
+ display.options1[3] = material.aniso;
392
+ display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
398
+ display.options2[0] = material.opacity;
399
+ display.options2[1] = material.diffuse;
400
+ display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
404
+
405
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
409
+ display.options4[0] = material.cameralight/0.2f;
410
+ display.options4[1] = material.subsurface;
411
+ display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
415
+
416
+ // if (display.CURRENTANTIALIAS > 0)
417
+ // display.options3[3] /= 4;
418
+
419
+ /*
420
+ System.out.println("Focus = " + display.options1[0]);
421
+ System.out.println("Aperture = " + display.options1[1]);
422
+ System.out.println("ShadowBlur = " + display.options1[2]);
423
+ System.out.println("Antialiasing = " + display.options1[3]);
424
+ System.out.println("Fog = " + display.options2[0]);
425
+ System.out.println("Intensity = " + display.options2[1]);
426
+ System.out.println("Elevation = " + display.options2[2]);
427
+ /**/
428
+ } else
429
+ {
430
+ DrawMaterial(material, selected, obj.projectedVertices);
431
+ }
432
+ } else
433
+ {
434
+ if (selected && CameraPane.flash)
435
+ {
436
+ display.modelParams4[1] = 100;
437
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
438
+ }
439
+ }
440
+ }
441
+
442
+ public void PushMaterial2(Object3D obj, boolean selected)
443
+ {
444
+ CameraPane display = this;
445
+ cMaterial material = obj.material;
446
+
447
+ if (material != null)
448
+ {
449
+ materialstack[materialdepth] = material;
450
+ selectedstack[materialdepth] = selected;
451
+ cStatic.objectstack[materialdepth++] = obj;
452
+ //System.out.println("material " + material);
453
+ //Applet3D.tracein("selected ", selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
456
+ }
457
+ }
458
+
459
+ public void PopMaterial(Object3D obj, boolean selected)
460
+ {
461
+ CameraPane display = this;
462
+ javax.media.opengl.GL gl = display.GetGL();
463
+ cMaterial material = obj.material;
464
+
465
+ //if (parent != null && parent.GetMaterial() != null)
466
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
467
+ if (material != null)
468
+ {
469
+ materialdepth -= 1;
470
+ if (materialdepth > 0)
471
+ {
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
474
+ }
475
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
476
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
477
+ {
478
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
479
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
480
+ }
481
+ }
482
+
483
+ public void PopMaterial2(Object3D obj)
484
+ {
485
+ CameraPane display = this;
486
+ cMaterial material = obj.material;
487
+
488
+ if (material != null)
489
+ {
490
+ materialdepth -= 1;
491
+ if (materialdepth > 0)
492
+ {
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
495
+ }
496
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
497
+ //else
498
+ //material.Draw(display, false);
499
+ }
500
+ }
501
+
502
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
503
+ {
504
+ CameraPane display = this;
505
+
506
+ if (pv.y == -10000 ||
507
+ qv.y == -10000 ||
508
+ rv.y == -10000)
509
+ return;
510
+
511
+// float b = f.nbiterations & 1;
512
+// float g = (f.nbiterations>>1) & 1;
513
+// float r = (f.nbiterations>>2) & 1;
514
+//
515
+// //if (f.weight == 10000)
516
+// //{
517
+// // r = 1; g = b = 0;
518
+// //}
519
+// //else
520
+// //{
521
+// // assert(f.weight < 10000);
522
+// r = g = b = (float)bRep.FaceWeight(f)*100;
523
+// if (r<0)
524
+// assert(r>=0);
525
+// //}
526
+
527
+ javax.media.opengl.GL gl = display.GetGL();
528
+
529
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
530
+
531
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
532
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
533
+ {
534
+ //gl.glBegin(gl.GL_TRIANGLES);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
538
+ if (!hasnorm)
539
+ {
540
+ // System.out.println("Mesh normal");
541
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
542
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
543
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
544
+ LA.vecNormalize(obj.v2);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
547
+ }
548
+
549
+ // P
550
+ float x = (float)pv.x;
551
+ float y = (float)pv.y;
552
+ float z = (float)pv.z;
553
+
554
+ if (hasnorm)
555
+ {
556
+// if (!pv.norm.normalized())
557
+// assert(pv.norm.normalized());
558
+
559
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
560
+ float nx = (float)pv.norm.x;
561
+ float ny = (float)pv.norm.y;
562
+ float nz = (float)pv.norm.z;
563
+
564
+ x += nx * obj.NORMALPUSH;
565
+ y += ny * obj.NORMALPUSH;
566
+ z += nz * obj.NORMALPUSH;
567
+
568
+ SetGLNormal(gl, nx, ny, nz);
569
+ }
570
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
571
+ SetColor(obj, pv);
572
+ //gl.glColor4f(r, g, b, 1);
573
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
574
+ if (obj.flipV)
575
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
576
+ else
577
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
578
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
579
+
580
+ gl.glVertex3f(x, y, z);
581
+
582
+ // Q
583
+ x = (float)qv.x;
584
+ y = (float)qv.y;
585
+ z = (float)qv.z;
586
+
587
+// Print(pv);
588
+ if (hasnorm)
589
+ {
590
+// assert(qv.norm.normalized());
591
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
592
+ float nx = (float)qv.norm.x;
593
+ float ny = (float)qv.norm.y;
594
+ float nz = (float)qv.norm.z;
595
+
596
+ x += nx * obj.NORMALPUSH;
597
+ y += ny * obj.NORMALPUSH;
598
+ z += nz * obj.NORMALPUSH;
599
+
600
+ SetGLNormal(gl, nx, ny, nz);
601
+ }
602
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
603
+ // boolean locked = false;
604
+ // float eps = 0.1f;
605
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
606
+
607
+ // int dot = 0; //*/ (int)f.dot;
608
+
609
+ // if ((dot&1) == 0)
610
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
611
+
612
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
613
+ if (obj.flipV)
614
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
615
+ else
616
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
617
+ // else
618
+ // {
619
+ // locked = true;
620
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
621
+ // }
622
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
623
+ SetColor(obj, qv);
624
+
625
+ gl.glVertex3f(x, y, z);
626
+ //gl.glColor4f(r, g, b, 1);
627
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
628
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
629
+// Print(qv);
630
+
631
+ // R
632
+ x = (float)rv.x;
633
+ y = (float)rv.y;
634
+ z = (float)rv.z;
635
+
636
+ if (hasnorm)
637
+ {
638
+// assert(rv.norm.normalized());
639
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
640
+ float nx = (float)rv.norm.x;
641
+ float ny = (float)rv.norm.y;
642
+ float nz = (float)rv.norm.z;
643
+
644
+ x += nx * obj.NORMALPUSH;
645
+ y += ny * obj.NORMALPUSH;
646
+ z += nz * obj.NORMALPUSH;
647
+
648
+ SetGLNormal(gl, nx, ny, nz);
649
+ }
650
+
651
+ // if ((dot&4) == 0)
652
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
653
+
654
+ // if (wrap || !locked && (dot&8) != 0)
655
+ if (obj.flipV)
656
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
657
+ else
658
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
659
+ // else
660
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
661
+
662
+ // f.dot = dot;
663
+
664
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
665
+ SetColor(obj, rv);
666
+ //gl.glColor4f(r, g, b, 1);
667
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
668
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
669
+ gl.glVertex3f(x, y, z);
670
+// Print(rv);
671
+ //gl.glEnd();
672
+ }
673
+ else
674
+ {
675
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
676
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
677
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
678
+
679
+ }
680
+
681
+ if (false) // (attributes & WIREFRAME) != 0)
682
+ {
683
+ gl.glDisable(gl.GL_LIGHTING);
684
+
685
+ gl.glBegin(gl.GL_LINE_LOOP);
686
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
687
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
688
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
689
+ gl.glEnd();
690
+
691
+ gl.glEnable(gl.GL_LIGHTING);
692
+ }
693
+ }
694
+
695
+ /**
696
+ * <code>draw</code> renders a <code>TriMesh</code> object including
697
+ * it's normals, colors, textures and vertices.
698
+ *
699
+ * @see Renderer#draw(TriMesh)
700
+ * @param tris
701
+ * the mesh to render.
702
+ */
703
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
704
+ {
705
+ CameraPane display = this;
706
+
707
+ float r = display.modelParams0[0];
708
+ float g = display.modelParams0[1];
709
+ float b = display.modelParams0[2];
710
+ float opacity = display.modelParams5[1];
711
+
712
+ //final GL gl = GLU.getCurrentGL();
713
+ GL gl = display.GetGL(); // getGL();
714
+
715
+ FloatBuffer vertBuf = geo.vertBuf;
716
+
717
+ int v = vertBuf.capacity();
718
+
719
+ int count = 0;
720
+
721
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
722
+ gl.glEnable(gl.GL_CULL_FACE);
723
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
724
+ for (int i=0; i<v/3; i++)
725
+ {
726
+ int index3 = i*3;
727
+
728
+ if (geo.sizeBuf.get(index3+1) == 0)
729
+ continue;
730
+
731
+ count++;
732
+
733
+ int index4 = i*4;
734
+
735
+ float tx = vertBuf.get(index3);
736
+ float ty = vertBuf.get(index3+1);
737
+ float tz = vertBuf.get(index3+2);
738
+
739
+ // if (tx == 0 && ty == 0 && tz == 0)
740
+ // continue;
741
+
742
+ gl.glMatrixMode(gl.GL_TEXTURE);
743
+ gl.glPushMatrix();
744
+
745
+ float[] texmat = geo.texmat;
746
+ texmat[12] = texmat[13] = texmat[14] = i;
747
+
748
+ gl.glMultMatrixf(texmat, 0);
749
+
750
+ gl.glMatrixMode(gl.GL_MODELVIEW);
751
+ gl.glPushMatrix();
752
+
753
+ gl.glTranslatef(tx,ty,tz);
754
+
755
+ if (rotate)
756
+ gl.glRotatef(i, 0, 1, 0);
757
+
758
+ float size = geo.sizeBuf.get(index3) / 100;
759
+ gl.glScalef(size,size,size);
760
+
761
+ float cr = geo.colorBuf.get(index4);
762
+ float cg = geo.colorBuf.get(index4+1);
763
+ float cb = geo.colorBuf.get(index4+2);
764
+ float ca = geo.colorBuf.get(index4+3);
765
+
766
+ display.modelParams0[0] = r * cr;
767
+ display.modelParams0[1] = g * cg;
768
+ display.modelParams0[2] = b * cb;
769
+
770
+ display.modelParams5[1] = opacity * ca;
771
+
772
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
773
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
774
+
775
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
776
+ RandomNode.globalseed2 = RandomNode.globalseed;
777
+
778
+// gl.glColor4f(cr,cg,cb,ca);
779
+ // gl.glScalef(1024/16,1024/16,1024/16);
780
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
781
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
782
+ //gl.glTranslatef(-tx,-ty,-tz);
783
+ gl.glPopMatrix();
784
+
785
+ gl.glMatrixMode(gl.GL_TEXTURE);
786
+ gl.glPopMatrix();
787
+ }
788
+ // gl.glScalef(1024,1024,1024);
789
+ if (!cf)
790
+ gl.glDisable(gl.GL_CULL_FACE);
791
+
792
+ display.modelParams0[0] = r;
793
+ display.modelParams0[1] = g;
794
+ display.modelParams0[2] = b;
795
+
796
+ display.modelParams5[1] = opacity;
797
+
798
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
799
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
800
+
801
+ gl.glMatrixMode(gl.GL_MODELVIEW);
802
+
803
+// System.err.println("total = " + v/3 + "; displayed = " + count);
804
+ if (true)
805
+ return;
806
+
807
+//// if (!tris.predraw(this))
808
+//// {
809
+//// return;
810
+//// }
811
+//// if (Debug.stats)
812
+//// {
813
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
814
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
815
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
816
+//// }
817
+////
818
+//// if (tris.getDisplayListID() != -1)
819
+//// {
820
+//// renderDisplayList(tris);
821
+//// return;
822
+//// }
823
+////
824
+//// if (!generatingDisplayList)
825
+//// {
826
+//// applyStates(tris.states, tris);
827
+//// }
828
+//// if (Debug.stats)
829
+//// {
830
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
831
+//// }
832
+//// boolean transformed = doTransforms(tris);
833
+//
834
+// int glMode = GL.GL_TRIANGLES;
835
+// switch (getMode())
836
+// {
837
+// case Triangles:
838
+// glMode = GL.GL_TRIANGLES;
839
+// break;
840
+// case Strip:
841
+// glMode = GL.GL_TRIANGLE_STRIP;
842
+// break;
843
+// case Fan:
844
+// glMode = GL.GL_TRIANGLE_FAN;
845
+// break;
846
+// }
847
+//
848
+// if (!predrawGeometry(gl))
849
+// {
850
+// // make sure only the necessary indices are sent through on old
851
+// // cards.
852
+// IntBuffer indices = this.getIndexBuffer();
853
+// if (indices == null)
854
+// {
855
+// logger.severe("missing indices on geometry object: " + this.toString());
856
+// } else
857
+// {
858
+// indices.rewind();
859
+// indices.limit(this.getMaxIndex());
860
+//
861
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
862
+//
863
+// indices.clear();
864
+// }
865
+// } else
866
+// {
867
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
868
+// GL.GL_UNSIGNED_INT, 0);
869
+// }
870
+//
871
+//// postdrawGeometry(tris);
872
+//// if (transformed)
873
+//// {
874
+//// undoTransforms(tris);
875
+//// }
876
+////
877
+//// if (Debug.stats)
878
+//// {
879
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
880
+//// }
881
+//// tris.postdraw(this);
882
+ }
883
+
884
+ static Camera localcamera = new Camera();
885
+ static cVector from = new cVector();
886
+ static cVector to = new cVector();
887
+
888
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
889
+ {
890
+ CameraPane cp = this;
891
+
892
+ Camera keep = cp.RenderCamera();
893
+ cp.renderCamera = localcamera;
894
+
895
+ if (br.trimmed)
896
+ {
897
+ float[] colors = new float[br.positions.length / 3];
898
+
899
+ int i3 = 0;
900
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
901
+ {
902
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
903
+ continue;
904
+
905
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
906
+ to.set(br.positions[i3] + br.normals[i3],
907
+ br.positions[i3 + 1] + br.normals[i3 + 1],
908
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
909
+ LA.xformPos(from, transform, from);
910
+ LA.xformPos(to, transform, to); // RIGID ONLY
911
+ localcamera.setAim(from, to);
912
+
913
+ CameraPane.occlusionbuffer.display();
914
+
915
+ if (CameraPane.DEBUG_OCCLUSION)
916
+ cp.display(); // debug
917
+
918
+ colors[i] = cp.vertexOcclusion.r;
919
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
920
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
921
+
922
+ if ((i % 100) == 0 && i != 0)
923
+ {
924
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
925
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
926
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
927
+ }
928
+ }
929
+
930
+ br.colors = colors;
931
+ }
932
+ else
933
+ {
934
+ for (int i = 0; i < br.VertexCount(); i++)
935
+ {
936
+ Vertex v = br.GetVertex(i);
937
+
938
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
939
+ continue;
940
+
941
+ from.set(v.x, v.y, v.z);
942
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
943
+ LA.xformPos(from, transform, from);
944
+ LA.xformPos(to, transform, to); // RIGID ONLY
945
+ localcamera.setAim(from, to);
946
+
947
+ CameraPane.occlusionbuffer.display();
948
+
949
+ if (CameraPane.DEBUG_OCCLUSION)
950
+ cp.display(); // debug
951
+
952
+ v.AO = cp.vertexOcclusion.r;
953
+
954
+ if ((i % 100) == 0 && i != 0)
955
+ {
956
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
957
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
958
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
959
+ }
960
+ }
961
+ }
962
+
963
+ //System.out.println("done.");
964
+
965
+ cp.renderCamera = keep;
966
+ }
967
+
968
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
969
+ {
970
+ CameraPane display = this;
971
+ pointFlow.CreateHT();
972
+
973
+ float r = display.modelParams0[0];
974
+ float g = display.modelParams0[1];
975
+ float b = display.modelParams0[2];
976
+ float opacity = display.modelParams5[1];
977
+
978
+ //final GL gl = GLU.getCurrentGL();
979
+ GL gl = display.GetGL(); // getGL();
980
+
981
+ int s = pointFlow.points.size();
982
+
983
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
984
+ gl.glEnable(gl.GL_CULL_FACE);
985
+
986
+ for (int i=s; --i>=0;)
987
+ //for (int i=0; i<s; i++)
988
+ {
989
+ cVector v = pointFlow.points.get(i);
990
+
991
+ double mindist = Double.MAX_VALUE;
992
+
993
+ double size = pointFlow.minimumSize;
994
+
995
+ double distancenext = 0;
996
+
997
+ if (i > 0)
998
+ {
999
+ cVector w = pointFlow.points.get(i-1);
1000
+
1001
+ double dist = w.distance(v);
1002
+
1003
+ distancenext = dist;
1004
+
1005
+ if (mindist > dist)
1006
+ {
1007
+ mindist = dist;
1008
+ size = mindist*pointFlow.resizefactor;
1009
+ }
1010
+ }
1011
+
1012
+ if (i < s-1)
1013
+ {
1014
+ cVector w = pointFlow.points.get(i+1);
1015
+
1016
+ double dist = w.distance(v);
1017
+
1018
+ if (mindist > dist)
1019
+ {
1020
+ mindist = dist;
1021
+ size = mindist*pointFlow.resizefactor;
1022
+ }
1023
+ }
1024
+
1025
+ if (size < pointFlow.minimumSize)
1026
+ size = pointFlow.minimumSize;
1027
+ if (size > pointFlow.maximumSize)
1028
+ size = pointFlow.maximumSize;
1029
+
1030
+ double tx = v.x;
1031
+ double ty = v.y;
1032
+ double tz = v.z;
1033
+
1034
+ // if (tx == 0 && ty == 0 && tz == 0)
1035
+ // continue;
1036
+
1037
+ gl.glMatrixMode(gl.GL_TEXTURE);
1038
+ gl.glPushMatrix();
1039
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1040
+
1041
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1042
+
1043
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1044
+ gl.glPushMatrix();
1045
+
1046
+ gl.glTranslated(tx,ty,tz);
1047
+
1048
+ gl.glScaled(size,size,size);
1049
+
1050
+// float cr = colorBuf.get(index4);
1051
+// float cg = colorBuf.get(index4+1);
1052
+// float cb = colorBuf.get(index4+2);
1053
+// float ca = colorBuf.get(index4+3);
1054
+//
1055
+// display.modelParams0[0] = r * cr;
1056
+// display.modelParams0[1] = g * cg;
1057
+// display.modelParams0[2] = b * cb;
1058
+//
1059
+// display.modelParams5[1] = opacity * ca;
1060
+//
1061
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1062
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1063
+//
1064
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1065
+// RandomNode.globalseed2 = RandomNode.globalseed;
1066
+//
1067
+//// gl.glColor4f(cr,cg,cb,ca);
1068
+// // gl.glScalef(1024/16,1024/16,1024/16);
1069
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1070
+
1071
+ gl.glPopMatrix();
1072
+
1073
+ double step = size/4; //
1074
+
1075
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1076
+ continue;
1077
+
1078
+ int nbsteps = (int)(distancenext/step);
1079
+
1080
+ step = distancenext/nbsteps;
1081
+
1082
+ cVector next = pointFlow.points.get(i-1);
1083
+
1084
+ tmp.set(next);
1085
+ tmp.sub(v);
1086
+ tmp.normalize();
1087
+ tmp.mul(step);
1088
+
1089
+ // calculate next size
1090
+ mindist = Double.MAX_VALUE;
1091
+
1092
+ double nextsize = pointFlow.minimumSize;
1093
+
1094
+ if (i > 1)
1095
+ {
1096
+ cVector w = pointFlow.points.get(i-2);
1097
+
1098
+ double dist = w.distance(next);
1099
+
1100
+ if (mindist > dist)
1101
+ {
1102
+ mindist = dist;
1103
+ nextsize = mindist*pointFlow.resizefactor;
1104
+ }
1105
+ }
1106
+
1107
+ double dist = v.distance(next);
1108
+
1109
+ if (mindist > dist)
1110
+ {
1111
+ mindist = dist;
1112
+ nextsize = mindist*pointFlow.resizefactor;
1113
+ }
1114
+
1115
+ if (nextsize < pointFlow.minimumSize)
1116
+ nextsize = pointFlow.minimumSize;
1117
+ if (nextsize > pointFlow.maximumSize)
1118
+ nextsize = pointFlow.maximumSize;
1119
+ //
1120
+
1121
+ double count = 0;
1122
+
1123
+ while (distancenext > 0.000000001) // step
1124
+ {
1125
+ gl.glPushMatrix();
1126
+
1127
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1128
+
1129
+ double K = count/nbsteps;
1130
+
1131
+ double intersize = K*nextsize + (1-K)*size;
1132
+
1133
+ gl.glScaled(intersize,intersize,intersize);
1134
+
1135
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1136
+
1137
+ count++;
1138
+
1139
+ distancenext -= step;
1140
+
1141
+ gl.glPopMatrix();
1142
+ }
1143
+
1144
+ if (count != nbsteps)
1145
+ assert(count == nbsteps);
1146
+
1147
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1148
+ //gl.glTranslatef(-tx,-ty,-tz);
1149
+
1150
+ gl.glMatrixMode(gl.GL_TEXTURE);
1151
+ gl.glPopMatrix();
1152
+ }
1153
+
1154
+ if (!cf)
1155
+ gl.glDisable(gl.GL_CULL_FACE);
1156
+
1157
+// display.modelParams0[0] = r;
1158
+// display.modelParams0[1] = g;
1159
+// display.modelParams0[2] = b;
1160
+//
1161
+// display.modelParams5[1] = opacity;
1162
+//
1163
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1164
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1165
+
1166
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1167
+ }
1168
+
1169
+ public void DrawBox(cVector min, cVector max)
1170
+ {
1171
+ javax.media.opengl.GL gl = GetGL();
1172
+ gl.glBegin(gl.GL_LINES);
1173
+
1174
+ gl.glVertex3d(min.x, min.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, max.z);
1176
+ gl.glVertex3d(min.x, min.y, min.z);
1177
+ gl.glVertex3d(min.x, max.y, min.z);
1178
+ gl.glVertex3d(min.x, min.y, min.z);
1179
+ gl.glVertex3d(max.x, min.y, min.z);
1180
+
1181
+ gl.glVertex3d(max.x, max.y, max.z);
1182
+ gl.glVertex3d(min.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, max.z);
1184
+ gl.glVertex3d(max.x, min.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, max.z);
1186
+ gl.glVertex3d(max.x, max.y, min.z);
1187
+
1188
+ gl.glEnd();
1189
+ }
1190
+
1191
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1192
+ {
1193
+ int[] strips = bRep.getRawIndices();
1194
+
1195
+ javax.media.opengl.GL gl = GetGL();
1196
+
1197
+ // TRIANGLE STRIP ARRAY
1198
+ if (bRep.trimmed)
1199
+ {
1200
+ float[] v = bRep.getRawVertices();
1201
+ float[] n = bRep.getRawNormals();
1202
+ float[] c = bRep.getRawColors();
1203
+ float[] uv = bRep.getRawUVMap();
1204
+
1205
+ int count2 = 0;
1206
+ int count3 = 0;
1207
+
1208
+ if (n.length > 0)
1209
+ {
1210
+ for (int i = 0; i < strips.length; i++)
1211
+ {
1212
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1213
+
1214
+ /*
1215
+ boolean locked = false;
1216
+ float eps = 0.1f;
1217
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1218
+
1219
+ int dot = 0;
1220
+
1221
+ if ((dot&1) == 0)
1222
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1223
+
1224
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1225
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1226
+ else
1227
+ {
1228
+ locked = true;
1229
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1230
+ }
1231
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1232
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1233
+ if (hasnorm)
1234
+ {
1235
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1236
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1237
+ }
1238
+
1239
+ if ((dot&4) == 0)
1240
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1241
+
1242
+ if (wrap || !locked && (dot&8) != 0)
1243
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1244
+ else
1245
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1246
+
1247
+ f.dot = dot;
1248
+ */
1249
+
1250
+ if (!selectmode)
1251
+ {
1252
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1253
+ {
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1255
+ } else
1256
+ {
1257
+ SetGLNormal(gl, 0, 0, 1);
1258
+ }
1259
+
1260
+ if (c != null)
1261
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1262
+ {
1263
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1264
+ }
1265
+ }
1266
+
1267
+ if (flipV)
1268
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1269
+ else
1270
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
1272
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1273
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1274
+
1275
+ count2 += 2;
1276
+ count3 += 3;
1277
+ if (!selectmode)
1278
+ {
1279
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1280
+ {
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1282
+ } else
1283
+ {
1284
+ SetGLNormal(gl, 0, 0, 1);
1285
+ }
1286
+ if (c != null)
1287
+ {
1288
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1289
+ }
1290
+ }
1291
+
1292
+ if (flipV)
1293
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1294
+ else
1295
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
1297
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1298
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1299
+
1300
+ count2 += 2;
1301
+ count3 += 3;
1302
+ for (int j = 0; j < strips[i] - 2; j++)
1303
+ {
1304
+ //gl.glTexCoord2d(...);
1305
+ if (!selectmode)
1306
+ {
1307
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1308
+ {
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1310
+ } else
1311
+ {
1312
+ SetGLNormal(gl, 0, 0, 1);
1313
+ }
1314
+ if (c != null)
1315
+ {
1316
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1317
+ }
1318
+ }
1319
+
1320
+ if (flipV)
1321
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1322
+ else
1323
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
1325
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1326
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
1328
+ count2 += 2;
1329
+ count3 += 3;
1330
+ }
1331
+
1332
+ gl.glEnd();
1333
+ }
1334
+ }
1335
+
1336
+ assert count3 == v.length;
1337
+ }
1338
+ else // !trimmed
1339
+ {
1340
+ int count = 0;
1341
+ for (int i = 0; i < strips.length; i++)
1342
+ {
1343
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1344
+
1345
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1346
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1347
+
1348
+ drawVertex(gl, p, flipV, selectmode);
1349
+ drawVertex(gl, q, flipV, selectmode);
1350
+
1351
+ for (int j = 0; j < strips[i] - 2; j++)
1352
+ {
1353
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1354
+
1355
+ // if (j%2 == 0)
1356
+ // drawFace(p, q, r, display, null);
1357
+ // else
1358
+ // drawFace(p, r, q, display, null);
1359
+
1360
+ // p = q;
1361
+ // q = r;
1362
+ drawVertex(gl, r, flipV, selectmode);
1363
+ }
1364
+
1365
+ gl.glEnd();
1366
+ }
1367
+ }
1368
+ }
1369
+
1370
+ static cSpring.Point3D temp = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1372
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1373
+
1374
+ public void DrawDynamicMesh(cMesh mesh)
1375
+ {
1376
+ GL gl = GetGL(); // getGL();
1377
+
1378
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1379
+
1380
+ gl.glDisable(gl.GL_LIGHTING);
1381
+
1382
+ gl.glLineWidth(1);
1383
+ gl.glColor3f(1,1,1);
1384
+ gl.glBegin(gl.GL_LINES);
1385
+ double scale = 0;
1386
+ int count = 0;
1387
+ for (int s=0; s<Phys.allSprings.size(); s++)
1388
+ {
1389
+ cSpring.Spring spring = Phys.allSprings.get(s);
1390
+ if(s == 0)
1391
+ {
1392
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1393
+ }
1394
+ if (mesh.showsprings)
1395
+ {
1396
+ temp.set(spring.a.position);
1397
+ temp.add(spring.b.position);
1398
+ temp.mul(0.5);
1399
+ temp2.set(spring.a.position);
1400
+ temp2.sub(spring.b.position);
1401
+ temp2.mul(spring.restLength/2);
1402
+ temp.sub(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ temp.add(temp2);
1405
+ temp.add(temp2);
1406
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1407
+ }
1408
+
1409
+ if (spring.isHandle)
1410
+ continue;
1411
+
1412
+ //if (scale < spring.restLength)
1413
+ scale += spring.restLength;
1414
+ count++;
1415
+ }
1416
+ gl.glEnd();
1417
+
1418
+ if (count == 0)
1419
+ scale = 0.01;
1420
+ else
1421
+ scale /= count * 3;
1422
+
1423
+ //scale = 0.25;
1424
+
1425
+ if (mesh.ShowInfo())
1426
+ {
1427
+ gl.glLineWidth(4);
1428
+ for (int s=0; s<Phys.allNodes.size(); s++)
1429
+ {
1430
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1431
+ if (node.mass == 0)
1432
+ continue;
1433
+
1434
+ int i = node.springs==null?-1:node.springs.size();
1435
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1436
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1437
+ //temp.normalize();
1438
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1439
+ gl.glBegin(gl.GL_LINES);
1440
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1441
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1442
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1443
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1444
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1445
+ gl.glEnd();
1446
+ }
1447
+
1448
+ gl.glLineWidth(8);
1449
+ for (int s=0; s<Phys.allNodes.size(); s++)
1450
+ {
1451
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1452
+
1453
+ if (node.springs != null)
1454
+ {
1455
+ for (int i=0; i<node.springs.size(); i+=1)
1456
+ {
1457
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1458
+
1459
+ int c = i+1;
1460
+ // c = node.springs.get(i).nbcopies;
1461
+
1462
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1463
+ gl.glBegin(gl.GL_LINES);
1464
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1465
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1466
+ gl.glEnd();
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+ gl.glLineWidth(1);
1472
+ }
1473
+
1474
+ gl.glEnable(gl.GL_LIGHTING);
1475
+ }
1476
+
1477
+ /// INTERFACE
1478
+
1479
+ public void StartTriangles()
1480
+ {
1481
+ javax.media.opengl.GL gl = GetGL();
1482
+ gl.glBegin(gl.GL_TRIANGLES);
1483
+ }
1484
+
1485
+ public void EndTriangles()
1486
+ {
1487
+ GetGL().glEnd();
1488
+ }
1489
+
1490
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1491
+ {
1492
+ if (!selectmode)
1493
+ {
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1495
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1496
+
1497
+ if (flipV)
1498
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1499
+ else
1500
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1501
+ }
1502
+
1503
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1504
+ }
1505
+
1506
+ float[] colorV = new float[4];
1507
+
1508
+ void SetColor(Object3D obj, Vertex p0)
1509
+ {
1510
+ CameraPane display = this;
1511
+ BoundaryRep bRep = obj.bRep;
1512
+
1513
+ if (RENDERPROGRAM == 0)
1514
+ {
1515
+ float r = 0;
1516
+ if (bRep != null)
1517
+ {
1518
+ if (bRep.stripified)
1519
+ {
1520
+ r = 1;
1521
+ }
1522
+ }
1523
+ float g = 0;
1524
+ if (bRep != null)
1525
+ {
1526
+ if (bRep.trimmed)
1527
+ {
1528
+ g = 1;
1529
+ }
1530
+ }
1531
+ float b = 0;
1532
+ if (obj.support != null && obj.link2master)
1533
+ {
1534
+ b = 1;
1535
+ }
1536
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1537
+ return;
1538
+ }
1539
+
1540
+ if (display.DrawMode() != CameraPane.SHADOW)
1541
+ return;
1542
+
1543
+ javax.media.opengl.GL gl = display.GetGL();
1544
+// if (true) return;
1545
+// float ao = p.AO;
1546
+//
1547
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1548
+// // ao = 1;
1549
+//
1550
+// gl.glColor4f(ao, ao, ao, 1);
1551
+
1552
+// CameraPane.selectedpoint.
1553
+// getAverage(cStatic.point1, true);
1554
+ if (CameraPane.pointflow == null) // !random) // live)
1555
+ {
1556
+ return;
1557
+ }
1558
+
1559
+ cStatic.point1.set(0,0,0);
1560
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1561
+
1562
+ cStatic.point1.sub(p0);
1563
+
1564
+
1565
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1566
+// {
1567
+// return;
1568
+// }
1569
+
1570
+ //if (true)
1571
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1572
+ {
1573
+ return;
1574
+ }
1575
+
1576
+ if (false) // marked)
1577
+ {
1578
+ // debug rigging weights
1579
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1580
+ {
1581
+ float weight = p0.weights[object] / p0.totalweight;
1582
+
1583
+ // if (weight < 0.1)
1584
+ // {
1585
+ // assert(weight == 0);
1586
+ // continue;
1587
+ // }
1588
+
1589
+ if (p0.vertexlinks[object] == -1)
1590
+ continue;
1591
+
1592
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1593
+
1594
+ int color = //1 << object; //
1595
+ //p.vertexlinks.length;
1596
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1597
+ colorV[2] += (color & 1) * weight;
1598
+ colorV[1] += ((color & 2) >> 1) * weight;
1599
+ colorV[0] += ((color & 4) >> 2) * weight;
1600
+ }
1601
+ }
1602
+ else
1603
+ {
1604
+ if (obj.drawingstarted)
1605
+ {
1606
+ // find next point
1607
+ if (bRep.GetVertex(0).faceindices == null)
1608
+ {
1609
+ bRep.InitFaceIndices();
1610
+ }
1611
+
1612
+ double ymin = p0.y;
1613
+
1614
+ Vertex newp = p0;
1615
+
1616
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1617
+ {
1618
+ int fi = p0.faceindices[fii];
1619
+
1620
+ if (fi == -1)
1621
+ break;
1622
+
1623
+ Face f = bRep.GetFace(fi);
1624
+
1625
+ Vertex p = bRep.GetVertex(f.p);
1626
+ Vertex q = bRep.GetVertex(f.q);
1627
+ Vertex r = bRep.GetVertex(f.r);
1628
+
1629
+ int swap = (int)(Math.random()*3);
1630
+
1631
+// for (int s=swap; --s>=0;)
1632
+// {
1633
+// Vertex t = p;
1634
+// p = q;
1635
+// q = r;
1636
+// r = t;
1637
+// }
1638
+ if (ymin > p.y)
1639
+ {
1640
+ ymin = p.y;
1641
+ newp = p;
1642
+// break;
1643
+ }
1644
+ if (ymin > q.y)
1645
+ {
1646
+ ymin = q.y;
1647
+ newp = q;
1648
+// break;
1649
+ }
1650
+ if (ymin > r.y)
1651
+ {
1652
+ ymin = r.y;
1653
+ newp = r;
1654
+// break;
1655
+ }
1656
+ }
1657
+
1658
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1659
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1660
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1661
+
1662
+ obj.drawingstarted = false;
1663
+
1664
+ // return;
1665
+ }
1666
+
1667
+ if (false) // CameraPane.DRAW
1668
+ {
1669
+ p0.AO = colorV[0] = 2;
1670
+ colorV[1] = 2;
1671
+ colorV[2] = 2;
1672
+ }
1673
+
1674
+ CameraPane.pointflow.add(p0);
1675
+ CameraPane.pointflow.Touch();
1676
+ }
1677
+
1678
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1679
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1680
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1681
+ }
1682
+
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1684
+ {
1685
+ CameraPane display = this;
1686
+ //new Exception().printStackTrace();
1687
+
1688
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1689
+ {
1690
+ return;
1691
+ }
1692
+
1693
+ javax.media.opengl.GL gl = display.GetGL();
1694
+
1695
+ //Color col = Color.getHSBColor(color,modulation,1);
1696
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1697
+ if (!material.multiply)
1698
+ {
1699
+ display.color = material.color;
1700
+ display.saturation = material.modulation;
1701
+ }
1702
+ else
1703
+ {
1704
+ display.color *= material.color*2;
1705
+ display.saturation *= material.modulation*2;
1706
+ }
1707
+
1708
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1709
+
1710
+ float[] colorV = Grafreed.colorV;
1711
+
1712
+ /**/
1713
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1714
+ {
1715
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1716
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1717
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1718
+ colorV[3] = 1; // material.opacity;
1719
+
1720
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1721
+ //System.out.println("Opacity = " + opacity);
1722
+
1723
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1724
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1725
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1726
+
1727
+ float amb = material.ambient;
1728
+ if (amb < material.cameralight)
1729
+ {
1730
+ amb = material.cameralight;
1731
+ }
1732
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1733
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1734
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1735
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1736
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1737
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1738
+
1739
+ /**/
1740
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1741
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1742
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1743
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1744
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1745
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1746
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1747
+ //System.out.println("shininess = " + colorV[0]);
1748
+ if (colorV[0] > 128)
1749
+ {
1750
+ colorV[0] = 128;
1751
+ }
1752
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1753
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1754
+ /**/
1755
+ }
1756
+ /**/
1757
+
1758
+ //selected = false;
1759
+ selected = selected && display.flash;
1760
+
1761
+ //display.modelParams0[0] = 0; // pigment.r;
1762
+ //display.modelParams0[1] = 0; // pigment.g;
1763
+ //display.modelParams0[2] = 0; // pigment.b;
1764
+ if (!material.multiply)
1765
+ {
1766
+ display.modelParams0[3] = material.metalness;
1767
+ display.modelParams1[0] = material.diffuse;
1768
+ display.modelParams1[1] = material.specular;
1769
+ display.modelParams1[2] = 1 / material.shininess;
1770
+ display.modelParams1[3] = material.shift;
1771
+ display.modelParams2[0] = material.ambient;
1772
+ display.modelParams2[1] = material.lightarea;
1773
+ //System.out.println("light area = " + lightarea);
1774
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1775
+ display.modelParams2[3] = material.velvet;
1776
+ display.modelParams3[0] = material.sheen;
1777
+ display.modelParams3[1] = material.subsurface;
1778
+ display.modelParams3[2] = material.bump; // backlit
1779
+ display.modelParams3[3] = material.aniso;
1780
+ display.modelParams4[0] = material.anisoV;
1781
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1782
+ //System.out.println("selected = " + selected);
1783
+ display.modelParams4[2] = material.diffuseness;
1784
+ display.modelParams4[3] = material.shadow;
1785
+ display.modelParams5[0] = material.texture;
1786
+ display.modelParams5[1] = material.opacity;
1787
+ display.modelParams5[2] = material.fakedepth;
1788
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1789
+ }
1790
+ else
1791
+ {
1792
+ display.modelParams0[3] *= material.metalness*2;
1793
+ display.modelParams1[0] *= material.diffuse*2;
1794
+ display.modelParams1[1] *= material.specular*2;
1795
+ display.modelParams1[2] *= material.shininess*2;
1796
+ display.modelParams1[3] *= material.shift*2;
1797
+ display.modelParams2[0] *= material.ambient*2;
1798
+ display.modelParams2[1] *= material.lightarea*2;
1799
+ display.modelParams2[2] *= material.factor*2;
1800
+ display.modelParams2[3] *= material.velvet*2;
1801
+ display.modelParams3[0] *= material.sheen*2;
1802
+ display.modelParams3[1] *= material.subsurface*2;
1803
+ display.modelParams3[2] *= material.bump*2;
1804
+ display.modelParams3[3] *= material.aniso*2;
1805
+ display.modelParams4[0] *= material.anisoV*2;
1806
+ display.modelParams4[1] *= material.cameralight*2;
1807
+ //System.out.println("selected = " + selected);
1808
+ display.modelParams4[2] *= material.diffuseness*2;
1809
+ display.modelParams4[3] *= material.shadow*2;
1810
+ display.modelParams5[0] *= material.texture*2;
1811
+ display.modelParams5[1] *= material.opacity*2;
1812
+ display.modelParams5[2] *= material.fakedepth*2;
1813
+ display.modelParams5[3] *= material.shadowbias*2;
1814
+ }
1815
+
1816
+ display.modelParams6[0] = 0;
1817
+ display.modelParams6[1] = 0;
1818
+ display.modelParams6[2] = 0;
1819
+ display.modelParams6[3] = 0;
1820
+
1821
+ display.modelParams7[0] = 0;
1822
+ display.modelParams7[1] = 1000;
1823
+ display.modelParams7[2] = material.parallax;
1824
+ display.modelParams7[3] = 0;
1825
+
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
1827
+
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1829
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1830
+ {
1831
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1832
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1833
+ if (extparams.length > 1)
1834
+ {
1835
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1836
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1837
+ if (extparams.length > 2)
1838
+ {
1839
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1840
+ float x = extparams[2].y / 1000.0f;
1841
+ //if (x == 0)
1842
+ // x = 1f;
1843
+ display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power
1844
+ if (extparams[2].y > 0)
1845
+ {
1846
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1847
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1848
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1849
+ }
1850
+ }
1851
+ }
1852
+ }
1853
+
1854
+ //if (display.modelParams6[2] != 0)
1855
+ /*
1856
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1857
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1858
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1859
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1860
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1861
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1862
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1863
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1864
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1865
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1866
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1867
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1868
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1869
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1870
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1871
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1872
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1873
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1874
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1875
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1876
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1877
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1878
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1879
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1880
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1881
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1882
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1883
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1884
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1885
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1886
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1887
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1888
+ /**/
1889
+ //assert (display.modelParams6[2] == 0);
1890
+
1891
+ //System.out.println("noise power = " + display.modelParams7[0]);
1892
+ //System.out.println("shadowbias = " + shadowbias);
1893
+
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1896
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1897
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1898
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1899
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1900
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1901
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1902
+
1903
+ int mode = display.FP_SHADER;
1904
+
1905
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1906
+ {
1907
+ mode |= display.FP_ANISO;
1908
+ }
1909
+
1910
+ display.EnableProgram(mode);
1911
+
1912
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1913
+
1914
+ if (!material.multiply)
1915
+ {
1916
+ if (Globals.drawMode == CameraPane.SHADOW)
1917
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1918
+ else
1919
+ gl.glDepthMask(material.opacity >= 0.99);
1920
+ }
2081921 }
2091922
2101923 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,10 +1938,10 @@
2251938 currentGL.glMultMatrixd(model, 0);
2261939 }
2271940
228
- void PushMatrix(double[][] matrix, int count)
1941
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291942 {
2301943 matrixdepth++;
231
- // GraphreeD.tracein(matrix);
1944
+ // GrafreeD.tracein(matrix);
2321945 if (matrix == null)
2331946 return; // Identity
2341947
....@@ -253,13 +1966,13 @@
2531966
2541967 void PushMatrix(double[][] matrix)
2551968 {
256
- // GraphreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1969
+ // GrafreeD.tracein(matrix);
1970
+ PushMatrix(matrix, 1);
2581971 }
2591972
2601973 void PushMatrix()
2611974 {
262
- // GraphreeD.tracein(null);
1975
+ // GrafreeD.tracein(null);
2631976 if (matrixdepth++ < MAXSTACK - 1)
2641977 {
2651978 currentGL.glPushMatrix();
....@@ -270,11 +1983,11 @@
2701983
2711984 double[][] tmpmat = new double[4][4];
2721985
273
- void PopMatrix(double[][] inverse)
1986
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741987 {
2751988 --matrixdepth;
2761989
277
- // GraphreeD.traceout(inverse);
1990
+ // GrafreeD.traceout(inverse);
2781991 if (inverse == null)
2791992 return; // Identity
2801993
....@@ -292,7 +2005,7 @@
2922005
2932006 void PopMatrix()
2942007 {
295
- // GraphreeD.traceout(null);
2008
+ // GrafreeD.traceout(null);
2962009 // inverse == null??
2972010 if (--matrixdepth < MAXSTACK - 1)
2982011 {
....@@ -310,7 +2023,7 @@
3102023 PushTextureMatrix(matrix, 1);
3112024 }
3122025
313
- void PushTextureMatrix(double[][] matrix, int count)
2026
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142027 {
3152028 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162029
....@@ -324,7 +2037,7 @@
3242037 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252038 }
3262039
327
- void PopTextureMatrix(double[][] inverse)
2040
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282041 {
3292042 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302043 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -340,9 +2053,9 @@
3402053 switch(viewcode)
3412054 {
3422055 case 0: return "main";
343
- case 1: return "one";
344
- case 2: return "two";
345
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
3462059 case 4: return "light";
3472060 }
3482061
....@@ -351,15 +2064,15 @@
3512064
3522065 static int camerachangeframe;
3532066
354
- boolean SetCamera(Camera cam)
2067
+ public boolean SetCamera(Camera cam)
3552068 {
3562069 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572070 // return false;
3582071
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2072
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602073 {
3612074 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2075
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632076 {
3642077 // refuse the camera change
3652078 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2080,7 @@
3672080 }
3682081 }
3692082
370
- camerachangeframe = framecount;
2083
+ camerachangeframe = Globals.framecount;
3712084
3722085 cam.hAspect = -1; // Read only
3732086
....@@ -398,7 +2111,7 @@
3982111 {
3992112 //System.err.println("Oeil on");
4002113 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2114
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022115 // object.editWindow.ScreenFit(trackedobject);
4032116 //pingthread.StepToTarget(true);
4042117 }
....@@ -407,8 +2120,8 @@
4072120 {
4082121 //System.err.println("Oeil on");
4092122 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122125 //pingthread.StepToTarget(true);
4132126 }
4142127
....@@ -471,39 +2184,12 @@
4712184 {
4722185 frozen ^= true;
4732186 // Weird...
474
- lighttouched = true;
2187
+ Globals.lighttouched = true;
4752188 }
4762189
4772190 void ToggleDL()
4782191 {
4792192 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GraphreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072193 }
5082194
5092195 void ToggleFullScreen()
....@@ -513,12 +2199,7 @@
5132199
5142200 void ToggleCrowd()
5152201 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2202
+ Globals.CROWD ^= true;
5222203 }
5232204
5242205 void ToggleLocal()
....@@ -526,62 +2207,89 @@
5262207 LOCALTRANSFORM ^= true;
5272208 }
5282209
529
- void ToggleFast()
2210
+ public void ToggleTexture()
2211
+ {
2212
+ textureon ^= true;
2213
+ }
2214
+
2215
+ public void ToggleLive()
2216
+ {
2217
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2218
+
2219
+ System.err.println("LIVE = " + Globals.isLIVE());
2220
+
2221
+ if (!Globals.isLIVE()) // save sound
2222
+ Grafreed.savesound = true; // wav.save();
2223
+ // else
2224
+ repaint(); // start loop // may 2013
2225
+ }
2226
+
2227
+ public void ToggleSupport()
2228
+ {
2229
+ SUPPORT ^= true;
2230
+ }
2231
+
2232
+ public void ToggleAbort()
2233
+ {
2234
+ ABORTMODE ^= true;
2235
+ }
2236
+
2237
+ public void ToggleInertia()
2238
+ {
2239
+ INERTIA ^= true;
2240
+ }
2241
+
2242
+ public void ToggleFast()
5302243 {
5312244 FAST ^= true;
5322245 }
5332246
534
- void ToggleSlowPose()
2247
+ public void ToggleSlowPose()
5352248 {
5362249 SLOWPOSE ^= true;
5372250 }
5382251
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2252
+ public void ToggleBoxMode()
5452253 {
5462254 BOXMODE ^= true;
5472255 }
5482256
549
- void ToggleSmoothFocus()
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
2260
+ }
2261
+
2262
+ public void ToggleSmoothFocus()
5502263 {
5512264 SMOOTHFOCUS ^= true;
5522265 }
5532266
554
- void ToggleImageFlip()
2267
+ public void ToggleImageFlip()
5552268 {
5562269 IMAGEFLIP ^= true;
5572270 }
5582271
559
- void ToggleSpeakerMocap()
2272
+ public void ToggleSpeakerMocap()
5602273 {
5612274 SPEAKERMOCAP ^= true;
5622275 }
5632276
564
- void ToggleSpeakerCamera()
2277
+ public void ToggleSpeakerCamera()
5652278 {
5662279 SPEAKERCAMERA ^= true;
5672280 }
5682281
569
- void ToggleSpeakerFocus()
2282
+ public void ToggleSpeakerFocus()
5702283 {
5712284 SPEAKERFOCUS ^= true;
5722285 }
5732286
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2287
+ public void ToggleFrustum()
5802288 {
5812289 FRUSTUM ^= true;
5822290 }
5832291
584
- void ToggleTrack()
2292
+ public void ToggleTrack()
5852293 {
5862294 TRACK ^= true;
5872295 if (TRACK)
....@@ -600,25 +2308,35 @@
6002308 repaint();
6012309 }
6022310
603
- void ToggleTrackOnce()
2311
+ public void ToggleTrackOnce()
6042312 {
6052313 TRACKONCE ^= true;
6062314 }
6072315
608
- void ToggleShadowTrack()
2316
+ public void ToggleShadowTrack()
6092317 {
6102318 SHADOWTRACK ^= true;
6112319 repaint();
6122320 }
6132321
614
- void ToggleOeil()
2322
+ public void ToggleOeil()
6152323 {
6162324 OEIL ^= true;
6172325 }
6182326
619
- void ToggleOeilOnce()
2327
+ public void ToggleOeilOnce()
6202328 {
6212329 OEILONCE ^= true;
2330
+ }
2331
+
2332
+ void ToggleFootContact()
2333
+ {
2334
+ FOOTCONTACT ^= true;
2335
+ }
2336
+
2337
+ void ToggleDebug()
2338
+ {
2339
+ Globals.DEBUG ^= true;
6222340 }
6232341
6242342 void ToggleLookAt()
....@@ -626,9 +2344,9 @@
6262344 LOOKAT ^= true;
6272345 }
6282346
629
- void ToggleRandom()
2347
+ void ToggleSwitch()
6302348 {
631
- RANDOM ^= true;
2349
+ SWITCH ^= true;
6322350 }
6332351
6342352 void ToggleHandles()
....@@ -636,10 +2354,17 @@
6362354 HANDLES ^= true;
6372355 }
6382356
2357
+ Object3D paintFolder;
2358
+
6392359 void TogglePaint()
6402360 {
6412361 PAINTMODE ^= true;
6422362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
6432368 }
6442369
6452370 void SwapCamera(int a, int b)
....@@ -672,34 +2397,6 @@
6722397 //assert (cam.hAspect == 0);
6732398 cam.hAspect = 0;
6742399 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
7032400 }
7042401
7052402 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,39 +2456,71 @@
7592456
7602457 GL currentGL;
7612458
762
- GL GetGL()
2459
+ public GL GetGL() // INTERFACE
7632460 {
7642461 return currentGL;
7652462 }
766
-
2463
+
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
7672491 /**/
7682492 class CacheTexture
7692493 {
7702494 com.sun.opengl.util.texture.Texture texture;
2495
+ com.sun.opengl.util.texture.TextureData texturedata;
2496
+
7712497 int resolution;
7722498
773
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7742500 {
775
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
7762503 resolution = res;
7772504 }
7782505 }
7792506 /**/
7802507
7812508 // TEXTURE static Texture texture;
782
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
783
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
784
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
7852514 int pigmentdepth = 0;
7862515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7872516 int bumpdepth = 0;
7882517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7892518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7902519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
791
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7922521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7932522
794
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7952524 {
7962525 TextureData texturedata = null;
7972526
....@@ -801,7 +2530,7 @@
8012530 com.sun.opengl.util.texture.TextureIO.newTextureData(
8022531 getClass().getClassLoader().getResourceAsStream(name),
8032532 true,
804
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
8052534 } catch (java.io.IOException e)
8062535 {
8072536 throw new javax.media.opengl.GLException(e);
....@@ -810,13 +2539,34 @@
8102539 if (bump)
8112540 texturedata = ConvertBump(texturedata, false);
8122541
813
- com.sun.opengl.util.texture.Texture texture =
814
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8152544
816
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
817
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8182547
819
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
8202570 }
8212571
8222572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1889,6 +3639,8 @@
18893639
18903640 System.out.println("LOADING TEXTURE : " + name);
18913641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
18923644 //
18933645 if (false) // compressbit > 0)
18943646 {
....@@ -1998,10 +3750,12 @@
19983750 */
19993751 TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
20003752 {
3753
+ int pixelformat = texturedata.getPixelFormat();
3754
+
20013755 int stride = 1;
2002
- if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
3756
+ if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
20033757 stride = 3;
2004
- if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
3758
+ if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
20053759 stride = 4;
20063760
20073761 int width = texturedata.getWidth();
....@@ -2591,6 +4345,7 @@
25914345
25924346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25934347 {
4348
+ new Exception().printStackTrace();
25944349 System.exit(0);
25954350 com.sun.opengl.util.texture.Texture texture = null;
25964351
....@@ -6267,7 +8022,7 @@
62678022 return null;
62688023 }
62698024
6270
- void ReleaseTextures(cTexture tex)
8025
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62718026 {
62728027 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62738028 {
....@@ -6284,7 +8039,7 @@
62848039 String pigment = Object3D.GetPigment(tex);
62858040 String bump = Object3D.GetBump(tex);
62868041
6287
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62888043 {
62898044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62908045 // System.out.println("; bump = " + bump);
....@@ -6299,13 +8054,71 @@
62998054 pigment = null;
63008055 }
63018056
6302
- ReleaseTexture(bump, true);
6303
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
63048059 }
63058060
6306
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63078062 {
6308
- if (// drawMode != 0 || /*tex == null ||*/
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
8120
+ {
8121
+ if (// DrawMode() != 0 || /*tex == null ||*/
63098122 ambientOcclusion ) // || !textureon)
63108123 {
63118124 return;
....@@ -6314,7 +8127,7 @@
63148127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63158128
63168129 if (tex != null)
6317
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63188131
63198132 // //assert( texture != null );
63208133 // if (texture == null)
....@@ -6331,7 +8144,7 @@
63318144 {
63328145 bumpdepth--;
63338146
6334
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8147
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63358148 if (bumpstack[bumpdepth] != (texture!=null?texture.texture:null))
63368149 {
63378150 // assert (bumpstack[bumpdepth] == texture);
....@@ -6361,7 +8174,7 @@
63618174 {
63628175 pigmentdepth--;
63638176
6364
- // GraphreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
8177
+ // GrafreeD.trace("POP " + tex + "(" + pigmentdepth + ")" + " : " + pigmentstack[pigmentdepth] + " vs " + texture);
63658178 if (pigmentstack[pigmentdepth] != (texture!=null?texture.texture:null))
63668179 {
63678180 // assert (pigmentstack[pigmentdepth] == texture);
....@@ -6406,9 +8219,57 @@
64068219 }
64078220 }
64088221
6409
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8222
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64108223 {
6411
- if (// drawMode != 0 || /*tex == null ||*/
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
8265
+
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
8268
+ }
8269
+
8270
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8271
+ {
8272
+ if (// DrawMode() != 0 || /*tex == null ||*/
64128273 ambientOcclusion ) // || !textureon)
64138274 {
64148275 return; // false;
....@@ -6417,17 +8278,47 @@
64178278 if (tex == null)
64188279 {
64198280 BindTexture(null,false,resolution);
6420
- BindTexture(null,true,resolution);
64218281 return;
64228282 }
64238283
64248284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
64258317 String bump = Object3D.GetBump(tex);
64268318
6427
- usedtextures.put(pigment, pigment);
6428
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
64298320
6430
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64318322 {
64328323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64338324 // System.out.println("; bump = " + bump);
....@@ -6437,43 +8328,94 @@
64378328 {
64388329 bump = null;
64398330 }
6440
- if (pigment.equals(""))
6441
- {
6442
- pigment = null;
6443
- }
64448331
6445
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6446
- BindTexture(pigment, false, resolution);
64478332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6448
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
64498334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
-
6451
- return; // true;
64528335 }
64538336
6454
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
64558340 {
6456
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
64578360
64588361 if (tex != null)
64598362 {
6460
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64618365
6462
- String[] split = tex.split("Textures");
6463
- if (split.length > 1)
6464
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6465
- else
6466
- if (!texname.startsWith("/"))
6467
- texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
8373
+// String[] split = tex.split("Textures");
8374
+// if (split.length > 1)
8375
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8376
+// else
8377
+// if (!texname.startsWith("/"))
8378
+// texname = "/Users/nbriere/Textures/" + texname;
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
8380
+ {
8381
+ texname = fallbackTextureName;
8382
+ }
64688383
64698384 if (CACHETEXTURE)
6470
- texture = textures.get(texname); // TEXTURE CACHE
6471
-
6472
- TextureData texturedata = null;
6473
-
6474
- if (texture == null || texture.resolution < resolution)
64758385 {
6476
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64778419 {
64788420 assert(!bump);
64798421 // if (bump)
....@@ -6484,19 +8426,23 @@
64848426 // }
64858427 // else
64868428 // {
6487
- texture = textures.get(tex);
6488
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
64898431 {
6490
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64918433 }
8434
+ else
8435
+ new Exception().printStackTrace();
64928436 // }
64938437 } else
6494
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64958439 {
64968440 assert(bump);
6497
- texture = textures.get(tex);
6498
- if (texture == null)
6499
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
65008446 } else
65018447 {
65028448 //if (tex.equals("IMMORTAL"))
....@@ -6504,11 +8450,22 @@
65048450 // texture = GetResourceTexture("default.png");
65058451 //} else
65068452 //{
6507
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
65088454 {
6509
- texture = textures.get(tex);
6510
- if (texture == null)
6511
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
65128469 } else
65138470 {
65148471 if (textureon)
....@@ -6533,7 +8490,7 @@
65338490 }
65348491
65358492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6536
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
65378494 cachename = texname;
65388495 else
65398496 processbump = false; // don't process bump map again
....@@ -6555,7 +8512,7 @@
65558512 }
65568513
65578514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6558
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
65598516 cachename = texname;
65608517 else
65618518 processbump = false; // don't process bump map again
....@@ -6564,20 +8521,23 @@
65648521 texturedata = GetFileTexture(cachename, processbump, resolution);
65658522
65668523
6567
- if (texturedata != null)
6568
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8524
+ if (texturedata == null)
8525
+ throw new Exception();
8526
+
8527
+ texturecache = new CacheTexture(texturedata,resolution);
65698528 //texture = GetTexture(tex, bump);
65708529 }
8530
+ }
65718531 }
65728532 //}
65738533 }
65748534
6575
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65768536 {
65778537 //return false;
65788538
65798539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6580
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65818541 {
65828542 // String ext = "_highres";
65838543 // if (REDUCETEXTURE)
....@@ -6594,52 +8554,17 @@
65948554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65958555 if (!cachefile.exists())
65968556 {
6597
- // cache to disk
6598
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6599
- //buffers[0].
6600
-
6601
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6602
- int[] pixels = new int[bytebuf.capacity()/3];
6603
-
6604
- // squared size heuristic...
6605
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
66068558 {
6607
- for (int i=pixels.length; --i>=0;)
6608
- {
6609
- int i3 = i*3;
6610
- pixels[i] = 0xFF;
6611
- pixels[i] <<= 8;
6612
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6613
- pixels[i] <<= 8;
6614
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6617
- }
6618
-
6619
- /*
6620
- int r=0,g=0,b=0,a=0;
6621
- for (int i=0; i<width; i++)
6622
- for (int j=0; j<height; j++)
6623
- {
6624
- int index = j*width+i;
6625
- int p = pixels[index];
6626
- a = ((p>>24) & 0xFF);
6627
- r = ((p>>16) & 0xFF);
6628
- g = ((p>>8) & 0xFF);
6629
- b = (p & 0xFF);
6630
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6631
- }
6632
- /**/
6633
- int width = (int)Math.sqrt(pixels.length); // squared
6634
- int height = width;
6635
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6636
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
66378561 ImageWriter writer = null;
66388562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66398563 if (iter.hasNext()) {
66408564 writer = (ImageWriter)iter.next();
66418565 }
6642
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
66438568 try
66448569 {
66458570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6656,16 +8581,20 @@
66568581 }
66578582 }
66588583 }
6659
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
66608587 //System.out.println("Texture = " + tex);
6661
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
66628589 {
6663
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
66648591 thetex.texture.disable();
66658592 thetex.texture.dispose();
6666
- textures.remove(texname);
8593
+ textures.remove(tex);
66678594 }
6668
- textures.put(texname, texture);
8595
+
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
66698598
66708599 // newtex = true;
66718600 }
....@@ -6681,28 +8610,76 @@
66818610 }
66828611 }
66838612
8613
+ return texturecache;
8614
+ }
8615
+
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
8651
+ {
8652
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8653
+
66848654 if (bump)
66858655 {
6686
- // GraphreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
8656
+ // GrafreeD.trace("PUSH BUMP " + tex + "(" + bumpdepth + ")" + " : " + texture);
66878657 bumpstack[bumpdepth++] = texture!=null?texture.texture:null;
66888658 }
66898659 else
66908660 {
6691
- // GraphreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
8661
+ // GrafreeD.trace("PUSH PIGMENT " + tex + "(" + pigmentdepth + ")" + " : " + texture);
66928662 pigmentstack[pigmentdepth++] = texture!=null?texture.texture:null;
66938663 }
66948664
66958665 return texture!=null?texture.texture:null;
66968666 }
66978667
6698
- boolean BindTexture(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
8669
+ {
8670
+ CacheTexture texture = GetCacheTexture(tex, bump, resolution);
8671
+
8672
+ return texture!=null?texture.texturedata:null;
8673
+ }
8674
+
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
66998676 {
67008677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67018678 {
67028679 return false;
67038680 }
67048681
6705
- boolean newtex = false;
8682
+ //boolean newtex = false;
67068683
67078684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67088685
....@@ -6734,9 +8711,75 @@
67348711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67358712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67368713
6737
- return newtex;
8714
+ return true; // Warning: not used.
67388715 }
67398716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
67408783 ShadowBuffer shadowPBuf;
67418784 AntialiasBuffer antialiasPBuf;
67428785 int MAXSTACK;
....@@ -6753,10 +8796,12 @@
67538796
67548797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67558798 MAXSTACK = temp[0];
6756
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67578801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67588802 MAXSTACK = temp[0];
6759
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67608805
67618806 // Use debug pipeline
67628807 //drawable.setGL(new DebugGL(gl)); //
....@@ -6764,7 +8809,8 @@
67648809 gl = drawable.getGL(); //
67658810
67668811 GL gl3 = getGL();
6767
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67688814
67698815
67708816 //float pos[] = { 100, 100, 100, 0 };
....@@ -6929,7 +8975,7 @@
69298975
69308976 if (cubemap == null)
69318977 {
6932
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
69338979 }
69348980
69358981 //cubemap.enable();
....@@ -7205,6 +9251,8 @@
72059251
72069252 void LoadEnvy(int which)
72079253 {
9254
+ assert(false);
9255
+
72089256 String name;
72099257 String ext;
72109258
....@@ -7216,37 +9264,58 @@
72169264 cubemap = null;
72179265 return;
72189266 case 1:
7219
- name = "cubemaps/box_";
7220
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
72219269 reverseUP = false;
72229270 break;
72239271 case 2:
7224
- name = "cubemaps/uffizi_";
7225
- ext = "png";
7226
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
72279276 case 3:
7228
- name = "cubemaps/CloudyHills_";
7229
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
72309279 reverseUP = false;
72319280 break;
72329281 case 4:
7233
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
72349283 ext = "png";
72359284 reverseUP = false;
72369285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
72379311 default:
7238
- name = "cubemaps/rgb_";
7239
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
72409315 break;
72419316 }
7242
-
7243
- try
7244
- {
7245
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7246
- } catch (IOException e)
7247
- {
7248
- throw new RuntimeException(e);
7249
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
72509319 }
72519320
72529321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7278,8 +9347,12 @@
72789347 static double[] model = new double[16];
72799348 double[] camera2light = new double[16];
72809349 double[] light2camera = new double[16];
7281
- int newenvy = -1;
7282
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
72839356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
72849357 //float[] light0 = { 0,0,0 };
72859358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7292,9 +9365,9 @@
72929365 static boolean occlusionInitialized = false;
72939366 boolean selection = false;
72949367 boolean pointselection = false;
7295
- /*static*/ boolean lighttouched = true;
9368
+ ///*static*/ boolean lighttouched = true;
72969369 boolean deselect;
7297
- boolean ambientOcclusion = false;
9370
+ private boolean ambientOcclusion = false;
72989371 static boolean flash = false;
72999372 /*static*/ boolean wait = false;
73009373 boolean displaydone = false; // after repaint() calls
....@@ -7424,6 +9497,8 @@
74249497 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74259498 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74269499 double scale = lightCamera.SCALE / lightCamera.Distance();
9500
+// PATCH FILLE AUX JEANS
9501
+ //scale *= lightCamera.shaper_fovy / 25;
74279502 gl.glScaled(2 * scale, 2 * scale, -scale);
74289503 gl.glTranslated(0, 0, lightCamera.DECAL);
74299504
....@@ -7570,17 +9645,40 @@
75709645 jy8[3] = 0.5f;
75719646 }
75729647
7573
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75749649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
7575
- float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
9650
+ float[] options3 = new float[]{1, 1, 1, 0}; // fog color
9651
+ float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75769652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
75779677 static int imagecount = 0; // movie generation
75789678
75799679 static int jitter = 0;
75809680
75819681 boolean restartframe = false;
7582
-
7583
- static int framecount = 0; // general-purpose global count
75849682
75859683 void displayAntiAliased(javax.media.opengl.GL gl)
75869684 {
....@@ -7610,14 +9708,14 @@
76109708
76119709 //System.out.println("start frame");
76129710 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
7613
- for (jitter = 0; jitter < ACSIZE; jitter++) //, GraphreeD.wav.cursor += LIVE ? 735 : 0)
9711
+ for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76149712 {
7615
- framecount++;
9713
+ Globals.framecount++;
76169714
76179715 if (CameraPane.tickcount > 0)
76189716 CameraPane.tickcount--;
76199717
7620
-// GraphreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
9718
+// GrafreeD.wav.cursor += 735; // 44100 Hz / 120 Hz * 2 (for 16 bits)
76219719 // restartframe = true;
76229720 if (options1[2] > 100 && (jitter%2==0))
76239721 {
....@@ -7650,7 +9748,7 @@
76509748
76519749 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76529750 */
7653
- lighttouched = true;
9751
+ Globals.lighttouched = true;
76549752 //System.err.println(" shadowbuffer: " + jitter);
76559753 shadowbuffer.display();
76569754
....@@ -7671,8 +9769,8 @@
76719769 assert (parentcam != renderCamera);
76729770
76739771 if (renderCamera != lightCamera)
7674
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7675
- LA.matConcat(parentcam.toParent, matrix, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76769774
76779775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76789776
....@@ -7687,8 +9785,8 @@
76879785 LA.matCopy(renderCamera.fromScreen, matrix);
76889786
76899787 if (renderCamera != lightCamera)
7690
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7691
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
76929790
76939791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
76949792
....@@ -7734,10 +9832,12 @@
77349832 rati = 1 / rati;
77359833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77369834 }
7737
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
77389838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77399839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7740
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
77419841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77429842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77439843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7760,7 +9860,7 @@
77609860 //gl.glFlush();
77619861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77629862
7763
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
77649864 {
77659865 System.err.println(" ABORTED FRAME");
77669866 break;
....@@ -7790,7 +9890,7 @@
77909890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
77919891
77929892 // save image
7793
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
77949894 {
77959895 VPwidth = viewport[2];
77969896 VPheight = viewport[3];
....@@ -7901,11 +10001,11 @@
790110001
790210002 // imagecount++;
790310003
7904
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
10004
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
790510005
790610006 if (!BOXMODE)
790710007 {
7908
- System.out.println("image: " + fullname + " (" + (GraphreeD.wav.cursor / 735 / 4) + ")");
10008
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
790910009 }
791010010
791110011 if (!BOXMODE)
....@@ -7933,7 +10033,7 @@
793310033 {
793410034 if (ACSIZE > 1)
793510035 {
7936
- // System.err.println("image #" + (GraphreeD.wav.cursor / 735 / 4));
10036
+ // System.err.println("image #" + (GrafreeD.wav.cursor / 735 / 4));
793710037 }
793810038 }
793910039
....@@ -7943,7 +10043,7 @@
794310043 ABORTED = false;
794410044 }
794510045 else
7946
- GraphreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
794710047
794810048 if (false)
794910049 {
....@@ -8597,32 +10697,34 @@
859710697 }
859810698 }
859910699
8600
- boolean IsFrozen()
8601
- {
8602
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8603
-
8604
- return !selectmode && cameracount == 0; // != 0;
8605
- }
8606
-
860710700 boolean niceon = false;
860810701 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
860910702 boolean currentlydrawing = false;
861010703 static boolean init = false;
861110704
861210705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
861310709
861410710 public void display(GLAutoDrawable drawable)
861510711 {
8616
- if (GraphreeD.savesound && GraphreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
861710713 {
8618
- GraphreeD.wav.save();
8619
- GraphreeD.savesound = false;
8620
- GraphreeD.hassound = false;
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
10718
+ if (Grafreed.savesound && Grafreed.hassound)
10719
+ {
10720
+ Grafreed.wav.save();
10721
+ Grafreed.savesound = false;
10722
+ Grafreed.hassound = false;
862110723 }
862210724 // if (DEBUG_SELECTION)
862310725 // {
8624
-// if (drawMode != SELECTION)
8625
-// drawMode = SELECTION;
10726
+// if (DrawMode() != SELECTION)
10727
+// DrawMode() = SELECTION;
862610728 // }
862710729
862810730 if (!isRenderer)
....@@ -8678,9 +10780,9 @@
867810780
867910781 //ANTIALIAS = 0;
868010782
8681
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10783
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
868210784 {
8683
- if (niceon || isLIVE())
10785
+ if (niceon || Globals.isLIVE())
868410786 {
868510787 //if(active == 0)
868610788 // antialiaser = null;
....@@ -8693,6 +10795,7 @@
869310795 ANTIALIAS = 0;
869410796 //System.out.println("RESTART");
869510797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
869610799 }
869710800 }
869810801 }
....@@ -8705,7 +10808,7 @@
870510808 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
870610809 */
870710810
8708
- if (drawMode == DEFAULT)
10811
+ if (DrawMode() == DEFAULT)
870910812 {
871010813 currentlydrawing = true;
871110814 }
....@@ -8736,18 +10839,18 @@
873610839
873710840 // if(Applet3D.clipboard != null)
873810841 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8739
-//drawMode = SELECTION;
10842
+//DrawMode() = SELECTION;
874010843 indexcount = 0;
874110844
8742
- if (drawMode == OCCLUSION)
10845
+ if (DrawMode() == OCCLUSION)
874310846 {
8744
- drawMode = DEFAULT;
10847
+ Globals.drawMode = DEFAULT; // WARNING
874510848 ambientOcclusion = true;
874610849 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
874710850 Object3D theobject = object;
874810851 Object3D theparent = object.parent;
874910852 object.parent = null;
8750
- object = (Object3D)GraphreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
875110854 object.Stripify();
875210855 if (theobject.selection == null || theobject.selection.Size() == 0)
875310856 theobject.PreprocessOcclusion(this);
....@@ -8760,26 +10863,27 @@
876010863 ambientOcclusion = false;
876110864 }
876210865
8763
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
876410868 {
876510869 //if (RENDERSHADOW) // ?
876610870 if (!IsFrozen())
876710871 {
876810872 // dec 2012
8769
- if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
877010874 {
8771
- framecount++;
10875
+ Globals.framecount++;
877210876 shadowbuffer.display();
877310877 }
877410878 }
8775
- lighttouched = false; // ??
10879
+ Globals.lighttouched = false; // ??
877610880 //drawing = true;
877710881 //lighttouched = true;
877810882 }
877910883
878010884 if (wait)
878110885 {
8782
- Sleep(500);
10886
+ Sleep(200); // blocks everything
878310887
878410888 wait = false;
878510889 }
....@@ -8793,9 +10897,9 @@
879310897 //eyeCamera.shaper_fovy = 1;
879410898 }
879510899
8796
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10900
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
879710901 {
8798
- //System.out.println("drawMode = " + drawMode);
10902
+ //System.out.println("DrawMode() = " + DrawMode());
879910903 vertexMode |= VP_PASS;
880010904 //vertexMode |= VP_PROJECTION;
880110905 if (!ambientOcclusion)
....@@ -8855,7 +10959,7 @@
885510959 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
885610960 //Camera lightcam = new Camera(light0);
885710961
8858
- if (drawMode == SHADOW)
10962
+ if (DrawMode() == SHADOW)
885910963 {
886010964 /*
886110965 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8893,8 +10997,8 @@
889310997
889410998 // if (parentcam != renderCamera) // not a light
889510999 if (cam != lightCamera)
8896
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8897
- LA.matConcat(parentcam.toParent, matrix, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
889811002
889911003 for (int j = 0; j < 4; j++)
890011004 {
....@@ -8908,8 +11012,8 @@
890811012
890911013 // if (parentcam != renderCamera) // not a light
891011014 if (cam != lightCamera)
8911
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8912
- LA.matConcat(matrix, parentcam.fromParent, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
891311017
891411018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
891511019
....@@ -8945,7 +11049,7 @@
894511049 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
894611050 } else
894711051 {
8948
- if (drawMode != DEFAULT)
11052
+ if (DrawMode() != DEFAULT)
894911053 {
895011054 gl.glClearColor(1, 1, 1, 0);
895111055 } // 1);
....@@ -8995,13 +11099,43 @@
899511099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
899611100 }
899711101
8998
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
899911110 {
9000
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
900111117 }
9002
-
9003
- newenvy = -1;
9004
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
900511139 ratio = ((double) getWidth()) / getHeight();
900611140 //System.out.println("ratio = " + ratio);
900711141
....@@ -9010,14 +11144,14 @@
901011144
901111145 fast &= !ambientOcclusion;
901211146
9013
- if (drawMode == DEFAULT)
11147
+ if (DrawMode() == DEFAULT)
901411148 {
901511149 //gl.glEnable(gl.GL_ALPHA_TEST);
901611150 //gl.glActiveTexture(GL.GL_TEXTURE0);
901711151
901811152 if (!IsFrozen() && !ambientOcclusion)
901911153 {
9020
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
902111155 }
902211156
902311157 //if (selection_view == -1)
....@@ -9071,6 +11205,8 @@
907111205 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
907211206 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
907311207 double scale = lightCamera.SCALE / lightCamera.Distance();
11208
+// PATCH FILLE AUX JEANS
11209
+ //scale *= lightCamera.shaper_fovy / 25;
907411210 gl.glScaled(2 * scale, 2 * scale, -scale);
907511211 gl.glTranslated(0, 0, lightCamera.DECAL);
907611212
....@@ -9166,7 +11302,16 @@
916611302 // Bump noise
916711303 gl.glActiveTexture(GL.GL_TEXTURE6);
916811304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9169
- BindTexture(NOISE_TEXTURE, false, 2);
11305
+
11306
+ try
11307
+ {
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
11309
+ }
11310
+ catch (Exception e)
11311
+ {
11312
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11313
+ }
11314
+
917011315
917111316 gl.glActiveTexture(GL.GL_TEXTURE0);
917211317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9189,9 +11334,9 @@
918911334
919011335 gl.glMatrixMode(GL.GL_MODELVIEW);
919111336
9192
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9193
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9194
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
919511340 } else
919611341 {
919711342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9202,14 +11347,16 @@
920211347 //System.out.println("BLENDING ON");
920311348 gl.glEnable(GL.GL_BLEND);
920411349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9205
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
920611351 gl.glMatrixMode(gl.GL_PROJECTION);
920711352 gl.glLoadIdentity();
920811353
9209
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11354
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
921011355 {
921111356 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
921211357 double scale = lightCamera.SCALE / lightCamera.Distance();
11358
+// PATCH FILLE AUX JEANS
11359
+ //scale *= lightCamera.shaper_fovy / 25;
921311360 gl.glScaled(2 * scale, 2 * scale, -scale);
921411361 gl.glTranslated(0, 0, lightCamera.DECAL);
921511362 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9262,7 +11409,7 @@
926211409 //gl.glPushMatrix();
926311410 gl.glLoadIdentity();
926411411
9265
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11412
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
926611413 {
926711414 //LA.xformPos(light0, lightCamera.fromScreen, light);
926811415 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9289,8 +11436,8 @@
928911436 System.err.println("parentcam != renderCamera");
929011437
929111438 // if (cam != lightCamera)
9292
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9293
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
929411441 }
929511442
929611443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9311,8 +11458,8 @@
931111458 if (true) // TODO
931211459 {
931311460 if (cam != lightCamera)
9314
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9315
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
931611463 }
931711464
931811465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9349,7 +11496,7 @@
934911496 }
935011497
935111498 /**/
9352
- if (true) // drawMode == SELECTION) // != DEFAULT)
11499
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
935311500 gl.glDisable(gl.GL_LIGHTING);
935411501 else
935511502 gl.glEnable(gl.GL_LIGHTING);
....@@ -9361,12 +11508,13 @@
936111508
936211509 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
936311510 gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
11511
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
936411512
936511513 options2[0] *= renderCamera.Distance();
936611514
936711515 lightslot = 64;
936811516
9369
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11517
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
937011518 {
937111519 DrawLights(object);
937211520 }
....@@ -9377,7 +11525,7 @@
937711525 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
937811526 //System.out.println("fragmentMode = " + fragmentMode);
937911527
9380
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11528
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
938111529 {
938211530 /*
938311531 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9410,7 +11558,7 @@
941011558 }
941111559 }
941211560
9413
- if (drawMode == DEFAULT)
11561
+ if (DrawMode() == DEFAULT)
941411562 {
941511563 if (WIREFRAME && !ambientOcclusion)
941611564 {
....@@ -9428,7 +11576,7 @@
942811576 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
942911577 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
943011578
9431
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11579
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
943211580 {
943311581 if (vertexMode != 0) // && !fast)
943411582 {
....@@ -9448,7 +11596,7 @@
944811596 }
944911597 }
945011598
9451
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
945211600 {
945311601 //gl.glDepthFunc(GL.GL_LEQUAL);
945411602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9456,27 +11604,24 @@
945611604
945711605 boolean texon = textureon;
945811606
9459
- if (RENDERPROGRAM > 0)
9460
- {
9461
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9462
- textureon = false;
9463
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
946411610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
946511611 //System.out.println("ALLO");
946611612 gl.glColorMask(false, false, false, false);
946711613 DrawObject(gl);
9468
- if (RENDERPROGRAM > 0)
9469
- {
9470
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9471
- textureon = texon;
9472
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
947311618 gl.glColorMask(true, true, true, true);
947411619
947511620 gl.glDepthFunc(GL.GL_EQUAL);
9476
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
947711622 }
947811623
9479
- if (false) // drawMode == SHADOW)
11624
+ if (false) // DrawMode() == SHADOW)
948011625 {
948111626 //SetColumnMajorData(cameraInverseTransform, view_1);
948211627 //System.out.println("light = " + cameraInverseTransform);
....@@ -9490,16 +11635,16 @@
949011635 //System.out.println("object = " + object);
949111636 if (!frozen && !imageLocked)
949211637 {
9493
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11638
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
949411639 {
949511640 displayAntiAliased(gl);
949611641 } else
949711642 {
949811643 programcount = 0;
9499
- int keepmode = drawMode;
11644
+ int keepmode = DrawMode();
950011645 // if (DEBUG_SELECTION)
950111646 // {
9502
-// drawMode = SELECTION;
11647
+// DrawMode() = SELECTION;
950311648 // }
950411649 // for point selection
950511650 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9509,10 +11654,10 @@
950911654 DrawObject(gl);
951011655
951111656 // jan 2013 System.err.println("RESET ABORT (display)");
9512
- // if (drawMode == DEFAULT)
11657
+ // if (DrawMode() == DEFAULT)
951311658 // ABORTED = false;
951411659 fullreset = false;
9515
- drawMode = keepmode;
11660
+ Globals.drawMode = keepmode; // WARNING
951611661 //System.out.println("PROGRAM SWITCH " + programcount);
951711662 }
951811663 }
....@@ -9520,11 +11665,11 @@
952011665 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
952111666 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
952211667
9523
- if (drawMode == DEFAULT)
11668
+ if (DrawMode() == DEFAULT)
952411669 {
952511670 ReleaseTexture(NOISE_TEXTURE, false);
952611671 }
9527
- //if (drawMode == DEFAULT)
11672
+ //if (DrawMode() == DEFAULT)
952811673 {
952911674
953011675 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9536,7 +11681,7 @@
953611681 //else
953711682 //gl.glDisable(gl.GL_TEXTURE_2D);
953811683 //gl.glPopMatrix();
9539
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11684
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
954011685 {
954111686 //new Exception().printStackTrace();
954211687 //System.out.println("Draw image " + width + ", " + height);
....@@ -9578,7 +11723,7 @@
957811723 //gl.glFlush();
957911724 }
958011725
9581
- if (flash && drawMode == DEFAULT)
11726
+ if (flash && DrawMode() == DEFAULT)
958211727 {
958311728 flash = false;
958411729 wait = true;
....@@ -9586,9 +11731,9 @@
958611731 }
958711732
958811733 //drawing = false;
9589
- //if(drawMode == DEFAULT)
11734
+ //if(DrawMode() == DEFAULT)
959011735 // niceon = false;
9591
- if (drawMode == DEFAULT)
11736
+ if (DrawMode() == DEFAULT)
959211737 {
959311738 currentlydrawing = false;
959411739 }
....@@ -9608,7 +11753,7 @@
960811753 repaint();
960911754 }
961011755
9611
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11756
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
961211757 repaint();
961311758
961411759 displaydone = true;
....@@ -9627,8 +11772,14 @@
962711772 {
962811773 renderpass++;
962911774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
963011776 if (FAST) // in case there is no script
9631
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
963211783
963311784 //object.FullInvariants();
963411785
....@@ -9642,23 +11793,44 @@
964211793 e.printStackTrace();
964311794 }
964411795
9645
- if (GraphreeD.RENDERME > 0)
9646
- GraphreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
964711798
9648
- ONESTEP = false;
11799
+ Globals.ONESTEP = false;
964911800 }
965011801
965111802 static boolean zoomonce = false;
965211803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
965311822 void DrawObject(GL gl, boolean draw)
965411823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
965511827 //System.out.println("DRAW OBJECT " + mouseDown);
9656
-// drawMode = SELECTION;
11828
+// DrawMode() = SELECTION;
965711829 //GL gl = getGL();
965811830 if ((TRACK || SHADOWTRACK) || zoomonce)
965911831 {
9660
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9661
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11832
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
966211834 pingthread.StepToTarget(true); // true);
966311835 // zoomonce = false;
966411836 }
....@@ -9678,9 +11850,9 @@
967811850 callist = gl.glGenLists(1);
967911851 }
968011852
9681
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11853
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
968211854
9683
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11855
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
968411856
968511857 if (!mainDL || !active || touched)
968611858 {
....@@ -9707,24 +11879,32 @@
970711879 PushMatrix(ClickInfo.matbuffer);
970811880 }
970911881
9710
- if (drawMode == 0)
11882
+ if (DrawMode() == 0)
971111883 {
971211884 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
971311885
971411886 usedtextures.clear();
971511887
9716
- BindTextures(DEFAULT_TEXTURES, 2);
11888
+ try
11889
+ {
11890
+ BindTextures(DEFAULT_TEXTURES, 2);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11895
+ }
971711896 }
971811897 //System.out.println("--> " + stackdepth);
9719
-// GraphreeD.traceon();
11898
+// GrafreeD.traceon();
972011899
972111900 // DRAW
972211901 object.draw(this, /*(Composite)*/ object, false, false);
972311902
9724
- if (drawMode == DEFAULT)
11903
+ if (DrawMode() == DEFAULT)
972511904 {
9726
- if (DEBUG)
11905
+ if (Globals.DEBUG)
972711906 {
11907
+ CreateSelectedPoint();
972811908 float radius = 0.05f;
972911909 if (selectedpoint.radius != radius)
973011910 {
....@@ -9732,69 +11912,104 @@
973211912 selectedpoint.radius = radius;
973311913 selectedpoint.recalculate();
973411914 selectedpoint.material = new cMaterial();
9735
- selectedpoint.material.color = 0.25f;
11915
+ selectedpoint.material.color = 0.15f; // Yellow
973611916 selectedpoint.material.modulation = 0.75f;
973711917
9738
- debugpoint.radius = radius;
9739
- debugpoint.recalculate();
9740
- debugpoint.material = new cMaterial();
9741
- debugpoint.material.color = 0.25f;
9742
- debugpoint.material.modulation = 0.75f;
11918
+ debugpointG.radius = radius;
11919
+ debugpointG.recalculate();
11920
+ debugpointG.material = new cMaterial();
11921
+ debugpointG.material.color = 0.25f; // Green
11922
+ debugpointG.material.modulation = 0.75f;
974311923
9744
- debugpoint2.radius = radius;
9745
- debugpoint2.recalculate();
9746
- debugpoint2.material = new cMaterial();
9747
- debugpoint2.material.color = 0.75f;
9748
- debugpoint2.material.modulation = 0.75f;
11924
+ debugpointP.radius = radius;
11925
+ debugpointP.recalculate();
11926
+ debugpointP.material = new cMaterial();
11927
+ debugpointP.material.color = 0.75f; // Purple
11928
+ debugpointP.material.modulation = 0.75f;
11929
+
11930
+ debugpointC.radius = radius;
11931
+ debugpointC.recalculate();
11932
+ debugpointC.material = new cMaterial();
11933
+ debugpointC.material.color = 0.5f; // Cyan
11934
+ debugpointC.material.modulation = 0.75f;
11935
+
11936
+ debugpointR.radius = radius;
11937
+ debugpointR.recalculate();
11938
+ debugpointR.material = new cMaterial();
11939
+ debugpointR.material.color = 0f; // Red
11940
+ debugpointR.material.modulation = 0.75f;
974911941
975011942 InitPoints(radius);
975111943 }
975211944 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9753
- //debugpoint.draw(this, /*(Composite)*/ null, false);
9754
- //debugpoint2.draw(this, /*(Composite)*/ null, false);
9755
- DrawPoints(this);
11945
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11946
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11947
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11948
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
11949
+ // DrawPoints(this);
975611950 }
975711951
975811952 // debugstuff.draw(this, /*(Composite)*/ null, false);
975911953 }
9760
-// GraphreeD.traceoff();
11954
+// GrafreeD.traceoff();
976111955 //System.out.println(stackdepth);
9762
- if (drawMode == 0)
11956
+ if (DrawMode() == 0)
976311957 {
976411958 ReleaseTextures(DEFAULT_TEXTURES);
976511959
976611960 if (CLEANCACHE)
9767
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
976811962 {
9769
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
977011964
977111965 // System.out.println("Texture --------- " + tex);
977211966
9773
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
977411968 continue;
977511969
9776
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
977711971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
977811973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9779
- textures.get(tex).texture.dispose();
9780
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
978111987 }
978211988 }
978311989 }
978411990
978511991 checker = null;
978611992
9787
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11993
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
978811994 FindChecker(object);
978911995
9790
- if (checker != null && drawMode == DEFAULT)
11996
+ if (checker != null && DrawMode() == DEFAULT)
979111997 {
9792
- // BindTexture(IMMORTAL_TEXTURE);
11998
+ //BindTexture(IMMORTAL_TEXTURE);
11999
+ try
12000
+ {
12001
+ BindTextures(checker.GetTextures(), checker.texres);
12002
+ }
12003
+ catch (Exception e)
12004
+ {
12005
+ System.err.println("FAILED: " + checker.GetTextures());
12006
+ }
979312007 // NEAREST
979412008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
979512009 DrawChecker(gl);
979612010 //checker.Draw(this, null, false);
979712011 // ReleaseTexture(IMMORTAL_TEXTURE);
12012
+ ReleaseTextures(checker.GetTextures());
979812013 }
979912014
980012015 if (object.parent != null)
....@@ -9807,7 +12022,7 @@
980712022 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
980812023 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
980912024
9810
- if (DISPLAYTEXT && drawMode == DEFAULT)
12025
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
981112026 {
981212027 // Draw it once, then use the raster
981312028 Balloon(gl, balloon.createGraphics());
....@@ -9863,14 +12078,14 @@
986312078 int[] xs = new int[3];
986412079 int[] ys = new int[3];
986512080
9866
- void DrawString(Object3D obj) // String string)
12081
+ public void DrawString(Object3D obj) // String string) // INTERFACE
986712082 {
9868
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12083
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
986912084 {
987012085 return;
987112086 }
987212087
9873
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
987412089
987512090 GL gl = GetGL();
987612091
....@@ -10187,8 +12402,8 @@
1018712402 //obj.TransformToWorld(light, light);
1018812403 for (int i = tp.size(); --i >= 0;)
1018912404 {
10190
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10191
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1019212407 }
1019312408
1019412409
....@@ -10205,8 +12420,8 @@
1020512420 parentcam = cameras[0];
1020612421 }
1020712422
10208
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10209
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1021012425
1021112426 LA.xformPos(light, renderCamera.toScreen, light);
1021212427
....@@ -10253,7 +12468,7 @@
1025312468 return;
1025412469 }
1025512470
10256
- if (obj instanceof CheckerIG)
12471
+ if (obj instanceof Checker)
1025712472 {
1025812473 checker = obj;
1025912474
....@@ -10296,8 +12511,76 @@
1029612511
1029712512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1029812513
10299
- String program =
12514
+ String programmin =
12515
+ // Min shader
1030012516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1030112584 //"OPTION ARB_fragment_program_shadow;" +
1030212585 "PARAM light2cam0 = program.env[10];" +
1030312586 "PARAM light2cam1 = program.env[11];" +
....@@ -10323,13 +12606,15 @@
1032312606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1032412607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1032512608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
10326
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1032712610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
10328
- "PARAM options1 = program.env[62];" + // fog rgb color, image intensity
12611
+ "PARAM options1 = program.env[62];" + // fog rgb color
12612
+ "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
1032912613 "PARAM pointlight = program.env[127];" + // ...
1033012614 "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" +
1033112615 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
1033212616 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12617
+ "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
1033312618 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1033412619 "PARAM ten = { 10, 10, 10, 1.0 };" +
1033512620 "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
....@@ -10350,6 +12635,7 @@
1035012635 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1035112636 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1035212637 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12638
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1035312639 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1035412640 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1035512641 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10390,6 +12676,10 @@
1039012676 "TEMP R1;" +
1039112677 "TEMP R2;" +
1039212678 "TEMP R3;" +
12679
+ "TEMP min;" +
12680
+ "TEMP max;" +
12681
+ "TEMP average;" +
12682
+ "TEMP saturation;" +
1039312683 "TEMP keep1;" +
1039412684 "TEMP keep2;" +
1039512685 "TEMP keep3;" +
....@@ -10405,8 +12695,7 @@
1040512695 "TEMP shininess;" +
1040612696 "\n" +
1040712697 "MOV texSamp, one;" +
10408
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10409
-
12698
+
1041012699 "MOV mapgrid.x, one2048th.x;" +
1041112700 "MOV temp, fragment.texcoord[1];" +
1041212701 /*
....@@ -10427,20 +12716,20 @@
1042712716 "MUL temp, floor, mapgrid.x;" +
1042812717 //"TEX depth0, temp, texture[1], 2D;" +
1042912718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10430
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1043112720 "") +
1043212721 "ADD temp.x, temp.x, mapgrid.x;" +
1043312722 //"TEX depth1, temp, texture[1], 2D;" +
1043412723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10435
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1043612725 "") +
1043712726 "ADD temp.y, temp.y, mapgrid.x;" +
1043812727 //"TEX depth2, temp, texture[1], 2D;" +
10439
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1044012729 "SUB temp.x, temp.x, mapgrid.x;" +
1044112730 //"TEX depth3, temp, texture[1], 2D;" +
1044212731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10443
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1044412733 "") +
1044512734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1044612735 //"MOV params, material;" +
....@@ -10562,7 +12851,7 @@
1056212851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1056312852 // mar 2013 ??? "KIL alpha.a;" +
1056412853 "MOV alpha, texSamp.aaaa;" + // y;" +
10565
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1056612855 /*
1056712856 "MUL temp.xy, temp, two;" +
1056812857 "TXB bump, temp, texture[0], 2D;" +
....@@ -10648,11 +12937,6 @@
1064812937 "SUB bump0, bump0, half;" +
1064912938 "ADD bump, bump, bump0;" +
1065012939
10651
- "MOV temp.x, texSamp.a;" +
10652
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
10653
- //"LRP texSamp0, params5.x, texSamp0, one;" +
10654
- "MOV texSamp.a, temp.x;" +
10655
-
1065612940 // double-sided
1065712941 /**/
1065812942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -10669,19 +12953,62 @@
1066912953 "MOV normald, normal;" +
1067012954 "MOV normals, normal;" +
1067112955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1067212958 // UV base
1067312959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1067412960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1067512961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
10676
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
10677
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
10678
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1067912967 "XPD V, normal, UP;" +
1068012968 Normalize("V") +
1068112969 "XPD U, V, normal;" +
1068212970 Normalize("U") +
1068312971
1068412972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1068513012
1068613013 //"MOV temp, fragment.texcoord[0];" +
1068713014 //
....@@ -10811,10 +13138,10 @@
1081113138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1081213139 "") +
1081313140
10814
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1081513142 "SUB temp.x, half.x, shadow.x;" +
10816
- "MOV temp.y, -params6.x;" +
10817
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1081813145 "SUB temp.y, one.x, temp.z;" +
1081913146 "MUL temp.x, temp.x, temp.y;" +
1082013147 "KIL temp.x;" +
....@@ -10920,10 +13247,42 @@
1092013247
1092113248 // skin?
1092213249 // Saturation for skin
10923
- /**/ // c'est ici
10924
- (Skinshader? "DP3 temp.x, final,one;" +
13250
+ /**/
13251
+ (Skinshader?
13252
+ "DP3 average.x, final,one;" +
13253
+ "MUL average, one3rd.xxxx,average.xxxx;" +
13254
+
13255
+ "MIN min.x, final.x,final.y;" +
13256
+ "MIN min.x, min.x,final.z;" +
13257
+
13258
+ "MAX max.x, final.x,final.y;" +
13259
+ "MAX max.x, max.x,final.z;" +
13260
+ "MOV max, max.xxxx;" +
13261
+
13262
+ "SUB saturation, max, final;" +
13263
+
13264
+ "ADD temp.x, max.x, one10th.x;" +
13265
+ "RCP temp.x, temp.x;" +
13266
+ "MUL temp.x, temp.x, half.x;" +
13267
+ "MUL saturation, saturation, temp.xxxx;" +
13268
+
13269
+ "DP3 ndotl.x, normald, light;" +
13270
+ "MAX ndotl.x, ndotl.x, -ndotl.x;" +
13271
+
13272
+ "SUB temp.x, one.x, ndotl.x;" +
13273
+ // Tuning for default skin
13274
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13275
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13276
+ "ADD temp.y, one.y, options2.y;" + // subsurface
13277
+ "MUL temp.x, temp.x, temp.y;" +
13278
+
13279
+ "MUL saturation, saturation, temp.xxxx;" +
13280
+ "SUB_SAT temp, max, saturation;" +
13281
+/**
13282
+ "DP3 temp.x, final,one;" +
1092513283 "MUL R2, one3rd.xxxx,temp.xxxx;" +
10926
- "SUB temp, final,R2;" +
13284
+ "SUB temp, final, R2;" +
13285
+
1092713286 // using light angle
1092813287 "DP3 ndotl.x, normald,light;" +
1092913288 //"SLT ndotl.y, ndotl.x, zero.x;" +
....@@ -10936,7 +13295,6 @@
1093613295 // using light intensity
1093713296 "MOV ndotl.z, R2.x;" +
1093813297 "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
10939
-
1094013298 // june 2014
1094113299 "MAD R1.x, ndotl.z,slope.y,one.x;" +
1094213300 // "SUB ndotl.x, one.x, ndotl.x;" +
....@@ -10948,6 +13306,7 @@
1094813306 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
1094913307
1095013308 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
13309
+/**/
1095113310
1095213311 // "ADD final, R2,temp;" +
1095313312 "MOV final, temp;"
....@@ -11037,7 +13396,7 @@
1103713396 /**/
1103813397 // HDR
1103913398 "MOV temp.z, final.a;" +
11040
- "MUL final, final,options1.w;" +
13399
+ "MUL final, final,options2.x;" +
1104113400 "MOV final.a, temp.z;" +
1104213401 /**/
1104313402
....@@ -11074,10 +13433,17 @@
1107413433 "MOV final.z, zero.x;" +
1107513434 "MOV final.a, one.w;":""
1107613435 ) +
13436
+ /*
1107713437 (NORMALdebug?"MOV final.x, normal.x;" +
1107813438 "MOV final.y, normal.y;" +
1107913439 "MOV final.z, normal.z;" +
1108013440 "MOV final.a, one.w;":""
13441
+ ) +
13442
+ */
13443
+ (NORMALdebug?"SUB final.x, one.x, final.x;" +
13444
+ "SUB final.y, one.x, final.y;" +
13445
+ "SUB final.z, one.x, final.z;" +
13446
+ "MOV final.a, final.a;":""
1108113447 ) +
1108213448 // "MOV final, bumpmap;" +
1108313449 "MOV result.color, final;" +
....@@ -11106,8 +13472,19 @@
1110613472 //once = true;
1110713473 }
1110813474
11109
- System.out.print("Program #" + mode + "; length = " + program.length());
11110
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1111113488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1111213489
1111313490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11154,7 +13531,8 @@
1115413531 "\n" +
1115513532 "END\n";
1115613533
11157
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1115813536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1115913537
1116013538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11199,30 +13577,32 @@
1119913577 return out;
1120013578 }
1120113579
11202
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1120313582 {
1120413583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1120513584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1120613585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1120713588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11208
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11209
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11210
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11211
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1121213591 //"SWZ buffer, temp, w,w,w,w;";
11213
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1121413593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1121513594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1121613595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11217
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1121813597
11219
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11220
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1122113600 }
1122213601
1122313602 String Shadow(String depth, String shadow)
1122413603 {
1122513604 return "MAX temp.x, ndotl.x, one64th.x;" +
13605
+ "MIN temp.x, temp.x, ninetenth.x;" +
1122613606 /**/
1122713607 // Sine
1122813608 "MUL temp.y, temp.x, temp.x;" +
....@@ -11238,12 +13618,16 @@
1123813618
1123913619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1124013620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1124113623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1124213624 "SGE temp.y, temp.x, zero.x;" +
11243
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1124413628 "SUB temp.x, one.x, temp.x;" +
1124513629 "MUL " + shadow + ".x, temp.x, temp.y;" +
11246
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1124713631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1124813632
1124913633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11257,6 +13641,10 @@
1125713641 // No shadow for backface
1125813642 "DP3 temp.x, normal, lightd;" +
1125913643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13644
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13645
+
13646
+ // No shadow when out of frustum
13647
+ "SGE temp.x, " + depth + ".z, one.z;" +
1126013648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1126113649 "";
1126213650 }
....@@ -11402,8 +13790,9 @@
1140213790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1140313791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1140413792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
11405
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11406
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1140713796
1140813797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1140913798 // OUT : diff, spec
....@@ -11419,9 +13808,10 @@
1141913808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1142013809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1142113810 //"MOV " + dest + ".w," + "normal.z;" +
11422
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11423
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11424
- //"MOV " + dest + ".z," + "params2.w;" +
13811
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13812
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13813
+
13814
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1142513815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1142613816 "RCP " + dest + ".w," + dest + ".w;" +
1142713817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11567,7 +13957,7 @@
1156713957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1156813958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1156913959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
11570
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1157113961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1157213962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1157313963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -11628,7 +14018,7 @@
1162814018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1162914019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1163014020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
11631
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1163214022 "MOV result.texcoord, temp;" +
1163314023 // border fade
1163414024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -11675,7 +14065,9 @@
1167514065
1167614066 //"ADD temp.z, temp.z, one;" +
1167714067
11678
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1167914071 : "MOV result.color, vertex.color;") +
1168014072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1168114073 : "") +
....@@ -11815,7 +14207,7 @@
1181514207 public void mousePressed(MouseEvent e)
1181614208 {
1181714209 //System.out.println("mousePressed: " + e);
11818
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1181914211 }
1182014212
1182114213 static long prevtime = 0;
....@@ -11842,14 +14234,16 @@
1184214234
1184314235 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1184414236
14237
+ if (BUTTONLESSWHEEL)
1184514238 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1184614239 {
1184714240 return;
1184814241 }
1184914242
14243
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1185014244
1185114245 // TIMER
11852
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14246
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1185314247 {
1185414248 keepboxmode = BOXMODE;
1185514249 keepsupport = SUPPORT;
....@@ -11889,8 +14283,8 @@
1188914283 // mode |= META;
1189014284 //}
1189114285
11892
- SetMouseMode(WHEEL | e.getModifiersEx());
11893
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1189414288 anchorX = ax;
1189514289 anchorY = ay;
1189614290 prevX = px;
....@@ -11924,6 +14318,7 @@
1192414318 else
1192514319 if (evt.getSource() == AAtimer)
1192614320 {
14321
+ Globals.TIMERRUNNING = false;
1192714322 if (mouseDown)
1192814323 {
1192914324 //new Exception().printStackTrace();
....@@ -11949,6 +14344,10 @@
1194914344 // LIVE = waslive;
1195014345 // wasliveok = true;
1195114346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1195214351
1195314352 // source == timer
1195414353 if (mouseDown)
....@@ -11978,8 +14377,8 @@
1197814377 // ObjEditor.tweenManager.update(1f / 60f);
1197914378
1198014379 // fev 2014???
11981
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
11982
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14380
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1198314382 pingthread.StepToTarget(true); // true);
1198414383 }
1198514384 // if (!LIVE)
....@@ -11988,12 +14387,13 @@
1198814387
1198914388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1199014389
11991
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1199214391 {
1199314392 if (!wasliveok)
1199414393 return;
1199514394
1199614395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1199714397
1199814398 // waslive = LIVE;
1199914399 // LIVE = false;
....@@ -12005,7 +14405,7 @@
1200514405 // touched = true; // main DL
1200614406 if (isRenderer)
1200714407 {
12008
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1200914409 }
1201014410
1201114411 selectX = anchorX = x;
....@@ -12018,7 +14418,7 @@
1201814418 clicked = true;
1201914419 hold = false;
1202014420
12021
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1202214422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1202314423 {
1202414424 // System.out.println("RESTART II " + modifiers);
....@@ -12043,14 +14443,15 @@
1204314443 drag = false;
1204414444 //System.out.println("Mouse DOWN");
1204514445 editObj = false;
12046
- ClickInfo info = new ClickInfo();
12047
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12048
- info.pane = this;
12049
- info.camera = renderCamera;
12050
- info.x = x;
12051
- info.y = y;
12052
- info.modifiers = modifiers;
12053
- editObj = object.doEditClick(info, 0);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1205414455 if (!editObj)
1205514456 {
1205614457 hasMarquee = true;
....@@ -12066,11 +14467,14 @@
1206614467
1206714468 public void mouseDragged(MouseEvent e)
1206814469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
14472
+ //System.out.println("mouseDragged: " + e);
1206914473 if (isRenderer)
1207014474 movingcamera = true;
14475
+
1207114476 //if (drawing)
1207214477 //return;
12073
- //System.out.println("mouseDragged: " + e);
1207414478 if ((e.getModifiersEx() & CTRL) != 0
1207514479 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1207614480 {
....@@ -12078,7 +14482,7 @@
1207814482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1207914483 }
1208014484 else
12081
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1208214486
1208314487 //try { Thread.sleep(1); } catch (Exception ex) {}
1208414488 }
....@@ -12090,6 +14494,11 @@
1209014494 cVector tmp = new cVector();
1209114495 cVector tmp2 = new cVector();
1209214496 boolean isMoving;
14497
+
14498
+ public cVector TargetLookAt()
14499
+ {
14500
+ return targetLookAt;
14501
+ }
1209314502
1209414503 class PingThread extends Thread
1209514504 {
....@@ -12229,7 +14638,7 @@
1222914638 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1223014639 if (lightMode)
1223114640 {
12232
- lighttouched = true;
14641
+ Globals.lighttouched = true;
1223314642 }
1223414643
1223514644 if (OEILONCE && OEIL)
....@@ -12246,6 +14655,7 @@
1224614655
1224714656 public void run()
1224814657 {
14658
+ new Exception().printStackTrace();
1224914659 System.exit(0);
1225014660 for (;;)
1225114661 {
....@@ -12287,7 +14697,7 @@
1228714697 mouseDown = false;
1228814698 if (lightMode)
1228914699 {
12290
- lighttouched = true;
14700
+ Globals.lighttouched = true;
1229114701 }
1229214702 repaint();
1229314703 alreadypainted = true;
....@@ -12295,7 +14705,7 @@
1229514705 isMoving = false;
1229614706 } //??
1229714707
12298
- if (isLIVE() && !alreadypainted)
14708
+ if (Globals.isLIVE() && !alreadypainted)
1229914709 {
1230014710 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1230114711 repaint();
....@@ -12307,9 +14717,9 @@
1230714717 {
1230814718 if (lightMode)
1230914719 {
12310
- lighttouched = true;
14720
+ Globals.lighttouched = true;
1231114721 }
12312
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1231314723 }
1231414724 //else
1231514725 }
....@@ -12323,12 +14733,18 @@
1232314733 void GoDown(int mod)
1232414734 {
1232514735 MODIFIERS |= COMMAND;
12326
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1232714738 if((mod&SHIFT) == SHIFT)
12328
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1232914745 else
12330
- manipCamera.BackForth(0, -speed*delta, getWidth());
12331
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1233214748 if ((mod & SHIFT) == SHIFT)
1233314749 {
1233414750 mouseMode = mouseMode; // VR??
....@@ -12337,6 +14753,8 @@
1233714753 mouseMode |= BACKFORTH;
1233814754 }
1233914755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1234014758 //prevX = X = anchorX;
1234114759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1234214760 }
....@@ -12344,12 +14762,19 @@
1234414762 void GoUp(int mod)
1234514763 {
1234614764 MODIFIERS |= COMMAND;
12347
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1234814768 if((mod&SHIFT) == SHIFT)
12349
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1235014775 else
12351
- manipCamera.BackForth(0, speed*delta, getWidth());
12352
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1235314778 if ((mod & SHIFT) == SHIFT)
1235414779 {
1235514780 mouseMode = mouseMode;
....@@ -12358,6 +14783,8 @@
1235814783 mouseMode |= BACKFORTH;
1235914784 }
1236014785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1236114788 //prevX = X = anchorX;
1236214789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1236314790 }
....@@ -12365,12 +14792,17 @@
1236514792 void GoLeft(int mod)
1236614793 {
1236714794 MODIFIERS |= COMMAND;
12368
- /*
14795
+ /**/
1236914796 if((mod&SHIFT) == SHIFT)
12370
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1237114798 else
12372
- manipCamera.Translate(speed*delta, 0, getWidth());
12373
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1237414806 if ((mod & SHIFT) == SHIFT)
1237514807 {
1237614808 mouseMode = mouseMode;
....@@ -12379,6 +14811,8 @@
1237914811 mouseMode |= ROTATE;
1238014812 } // TRANSLATE;
1238114813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1238214816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1238314817 prevY = Y = anchorY;
1238414818 }
....@@ -12386,12 +14820,18 @@
1238614820 void GoRight(int mod)
1238714821 {
1238814822 MODIFIERS |= COMMAND;
12389
- /*
14823
+ /**/
1239014824 if((mod&SHIFT) == SHIFT)
12391
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1239214826 else
12393
- manipCamera.Translate(-speed*delta, 0, getWidth());
12394
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1239514835 if ((mod & SHIFT) == SHIFT)
1239614836 {
1239714837 mouseMode = mouseMode;
....@@ -12400,6 +14840,8 @@
1240014840 mouseMode |= ROTATE;
1240114841 } // TRANSLATE;
1240214842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1240314845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1240414846 prevY = Y = anchorY;
1240514847 }
....@@ -12409,7 +14851,7 @@
1240914851 int X, Y;
1241014852 boolean SX, SY;
1241114853
12412
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1241314855 {
1241414856 if (IsFrozen())
1241514857 {
....@@ -12418,17 +14860,17 @@
1241814860
1241914861 drag = true; // NEW
1242014862
12421
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1242214864
1242314865 X = x;
1242414866 Y = y;
1242514867 // floating state for animation
12426
- MODIFIERS = modifiers;
12427
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1242814870 if (false) // modifiers != 0)
1242914871 {
1243014872 //new Exception().printStackTrace();
12431
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1243214874 System.out.println("SHIFT = " + SHIFT);
1243314875 System.out.println("CONTROL = " + COMMAND);
1243414876 System.out.println("META = " + META);
....@@ -12441,14 +14883,16 @@
1244114883 if (editObj)
1244214884 {
1244314885 drag = true;
12444
- ClickInfo info = new ClickInfo();
12445
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1244614888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12447
- info.pane = this;
12448
- info.camera = renderCamera;
12449
- info.x = x;
12450
- info.y = y;
12451
- object.editWindow.copy.doEditDrag(info);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1245214896 } else
1245314897 {
1245414898 if (x < startX)
....@@ -12550,6 +14994,7 @@
1255014994 {
1255114995 manipCamera.Translate(dx, dy, getWidth());
1255214996 }
14997
+ else
1255314998 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1255414999 {
1255515000 manipCamera.RotateInterest(dx, dy);
....@@ -12560,7 +15005,7 @@
1256015005
1256115006 if (manipCamera == lightCamera)
1256215007 {
12563
- lighttouched = true;
15008
+ Globals.lighttouched = true;
1256415009 }
1256515010 /*
1256615011 switch (mode)
....@@ -12596,23 +15041,27 @@
1259615041 }
1259715042 }
1259815043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1259915046 public void mouseMoved(MouseEvent e)
1260015047 {
1260115048 //System.out.println("mouseMoved: " + e);
12602
-
1260315049 if (isRenderer)
1260415050 return;
1260515051
12606
- ClickInfo ci = new ClickInfo();
12607
- ci.x = e.getX();
12608
- ci.y = e.getY();
12609
- ci.modifiers = e.getModifiersEx();
12610
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12611
- ci.pane = this;
12612
- ci.camera = renderCamera;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1261315059 if (!isRenderer)
1261415060 {
12615
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1261615065 {
1261715066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1261815067 } else
....@@ -12624,7 +15073,11 @@
1262415073
1262515074 public void mouseReleased(MouseEvent e)
1262615075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1262715078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1262815081 //System.out.println("mouseReleased: " + e);
1262915082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1263015083 }
....@@ -12647,9 +15100,9 @@
1264715100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1264815101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1264915102
12650
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1265115104 timeout = true;
12652
- else
15105
+// ?? May 2019 else
1265315106 // timer.setDelay((modifiers & 128) != 0?0:350);
1265415107 mouseDown = false;
1265515108 if (!control && !command) // june 2013
....@@ -12759,7 +15212,7 @@
1275915212 System.out.println("keyReleased: " + e);
1276015213 }
1276115214
12762
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1276315216 {
1276415217 //System.out.println("SetMouseMode = " + modifiers);
1276515218 //modifiers &= ~1024;
....@@ -12771,24 +15224,27 @@
1277115224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1277215225 // return;
1277315226 //System.out.println("SetMode = " + modifiers);
12774
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1277515228 {
1277615229 mouseMode |= ZOOM;
1277715230 }
12778
- if ((modifiers & META) == META)
15231
+
15232
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15233
+ if (capsLocked) // || (modifiers & META) == META)
1277915234 {
1278015235 mouseMode |= VR; // BACKFORTH;
1278115236 }
12782
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12783
- {
12784
- mouseMode |= SELECT; // BACKFORTH;
12785
- }
12786
- if ((modifiers & COMMAND) == COMMAND)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1278715238 {
1278815239 mouseMode |= SELECT;
1278915240 }
12790
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
1279115242 {
15243
+ mouseMode |= SELECT;
15244
+ }
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15246
+ {
15247
+ mouseMode &= ~VR;
1279215248 mouseMode |= TRANSLATE;
1279315249 }
1279415250 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12815,10 +15271,10 @@
1281515271
1281615272 if (isRenderer) //
1281715273 {
12818
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1281915275 }
1282015276
12821
- theRenderer.keyPressed(key);
15277
+ Globals.theRenderer.keyPressed(key);
1282215278 }
1282315279
1282415280 int kompactbit = 4; // power bit
....@@ -12830,7 +15286,7 @@
1283015286 float SATPOW = 1; // 2; // 0.5f;
1283115287 float BRIPOW = 1; // 0.5f; // 0.5f;
1283215288
12833
- void keyPressed(int key)
15289
+ public void keyPressed(int key)
1283415290 {
1283515291 if (key >= '0' && key <= '5')
1283615292 clampbit = (key-'0');
....@@ -12877,7 +15333,8 @@
1287715333 // break;
1287815334 case 'T':
1287915335 CACHETEXTURE ^= true;
12880
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1288115338 // repaint();
1288215339 break;
1288315340 case 'Y':
....@@ -12887,8 +15344,8 @@
1288715344 case 'K':
1288815345 KOMPACTTEXTURE ^= true;
1288915346 //textures.clear();
12890
- break;
12891
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1289215349 // SAVETEXTURE ^= true;
1289315350 macromode = true;
1289415351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -12945,7 +15402,7 @@
1294515402 case 'B':
1294615403 BRISMOOTH ^= true;
1294715404 SHADOWCULLFACE ^= true;
12948
- lighttouched = true;
15405
+ Globals.lighttouched = true;
1294915406 repaint();
1295015407 break;
1295115408 case 'b':
....@@ -12962,7 +15419,9 @@
1296215419 case 'E' : COMPACT ^= true;
1296315420 repaint();
1296415421 break;
12965
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1296615425 repaint();
1296715426 break;
1296815427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -12987,8 +15446,8 @@
1298715446 RevertCamera();
1298815447 repaint();
1298915448 break;
12990
- case 'L':
1299115449 case 'l':
15450
+ //case 'L':
1299215451 if (lightMode)
1299315452 {
1299415453 lightMode = false;
....@@ -13007,7 +15466,7 @@
1300715466 targetLookAt.set(manipCamera.lookAt);
1300815467 repaint();
1300915468 break;
13010
- case 'p':
15469
+ case 'P': // p':
1301115470 // c'est quoi ca au juste? spherical ^= true;
1301215471 Skinshader ^= true; programInitialized = false;
1301315472 repaint();
....@@ -13045,27 +15504,31 @@
1304515504 repaint();
1304615505 break;
1304715506 case 'O':
13048
- drawMode = OCCLUSION;
15507
+ Globals.drawMode = OCCLUSION; // WARNING
1304915508 repaint();
1305015509 break;
1305115510 case 'o':
1305215511 OCCLUSION_CULLING ^= true;
1305315512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1305415513 break;
13055
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1305615515 case '1':
1305715516 case '2':
1305815517 case '3':
1305915518 case '4':
1306015519 case '5':
13061
- newenvy = Character.getNumericValue(key);
13062
- repaint();
13063
- break;
1306415520 case '6':
1306515521 case '7':
1306615522 case '8':
1306715523 case '9':
13068
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1306915532 repaint();
1307015533 break;
1307115534 case '!':
....@@ -13131,12 +15594,12 @@
1313115594 case '_':
1313215595 kompactbit = 5;
1313315596 break;
13134
- case '+':
13135
- kompactbit = 6;
13136
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1313715600 case ' ':
1313815601 lightMode ^= true;
13139
- lighttouched = true;
15602
+ Globals.lighttouched = true;
1314015603 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1314115604 targetLookAt.set(manipCamera.lookAt);
1314215605 repaint();
....@@ -13145,14 +15608,15 @@
1314515608 case ESC:
1314615609 RENDERPROGRAM += 1;
1314715610 RENDERPROGRAM %= 3;
15611
+
1314815612 repaint();
1314915613 break;
1315015614 case 'Z':
13151
- RESIZETEXTURE ^= true;
13152
- break;
15615
+ //RESIZETEXTURE ^= true;
15616
+ //break;
1315315617 case 'z':
13154
- RENDERSHADOW ^= true;
13155
- lighttouched = true;
15618
+ Globals.RENDERSHADOW ^= true;
15619
+ Globals.lighttouched = true;
1315615620 repaint();
1315715621 break;
1315815622 //case UP:
....@@ -13178,13 +15642,15 @@
1317815642 FlipTransform();
1317915643 break;
1318015644 case ENTER:
13181
- object.editWindow.ScreenFit(); // Edit();
15645
+ // object.editWindow.ScreenFit(); // Edit();
15646
+ ToggleLive();
1318215647 break;
1318315648 case DELETE:
1318415649 ClearSelection();
1318515650 break;
13186
- /*
1318715651 case '+':
15652
+
15653
+ /*
1318815654 //fontsize += 1;
1318915655 bbzoom *= 2;
1319015656 repaint();
....@@ -13201,17 +15667,17 @@
1320115667 case '=':
1320215668 IncDepth();
1320315669 //fontsize += 1;
13204
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1320515671 maskbit = 6;
1320615672 break;
1320715673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1320815674 DecDepth();
1320915675 maskbit = 5;
1321015676 //if(fontsize > 1) fontsize -= 1;
13211
- if (object.editWindow == null)
13212
- new Exception().printStackTrace();
13213
- else
13214
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1321515681 break;
1321615682 case '{':
1321715683 manipCamera.shaper_fovy /= 1.1;
....@@ -13266,6 +15732,7 @@
1326615732 }
1326715733 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1326815734 }
15735
+
1326915736 static double OCCLUSIONBOOST = 1; // 0.5;
1327015737
1327115738 void keyReleased(int key, int modifiers)
....@@ -13273,11 +15740,11 @@
1327315740 //mode = ROTATE;
1327415741 if ((MODIFIERS & COMMAND) == 0) // VR??
1327515742 {
13276
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1327715744 }
1327815745 }
1327915746
13280
- protected void processKeyEvent(KeyEvent e)
15747
+ public void processKeyEvent(KeyEvent e)
1328115748 {
1328215749 switch (e.getID())
1328315750 {
....@@ -13407,8 +15874,9 @@
1340715874
1340815875 protected void processMouseMotionEvent(MouseEvent e)
1340915876 {
13410
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13411
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15877
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15878
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1341215880 {
1341315881 mouseMoved(e);
1341415882 } else
....@@ -13433,11 +15901,12 @@
1343315901 }
1343415902 */
1343515903
13436
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1343715905 }
1343815906
1343915907 void SelectParent()
1344015908 {
15909
+ new Exception().printStackTrace();
1344115910 System.exit(0);
1344215911 Composite group = (Composite) object;
1344315912 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13449,10 +15918,10 @@
1344915918 {
1345015919 //selectees.remove(i);
1345115920 System.out.println("select parent of " + elem);
13452
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1345315922 } else
1345415923 {
13455
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1345615925 }
1345715926
1345815927 first = false;
....@@ -13461,6 +15930,7 @@
1346115930
1346215931 void SelectChildren()
1346315932 {
15933
+ new Exception().printStackTrace();
1346415934 System.exit(0);
1346515935 /*
1346615936 Composite group = (Composite) object;
....@@ -13493,12 +15963,12 @@
1349315963 for (int j = 0; j < group.children.size(); j++)
1349415964 {
1349515965 elem = (Object3D) group.children.elementAt(j);
13496
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1349715967 first = false;
1349815968 }
1349915969 } else
1350015970 {
13501
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1350215972 }
1350315973
1350415974 first = false;
....@@ -13509,21 +15979,21 @@
1350915979 {
1351015980 //Composite group = (Composite) object;
1351115981 Object3D group = object;
13512
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1351315983 }
1351415984
1351515985 void ResetTransform(int mask)
1351615986 {
1351715987 //Composite group = (Composite) object;
1351815988 Object3D group = object;
13519
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1352015990 }
1352115991
1352215992 void FlipTransform()
1352315993 {
1352415994 //Composite group = (Composite) object;
1352515995 Object3D group = object;
13526
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1352715997 // group.editWindow.ReduceMesh(true);
1352815998 }
1352915999
....@@ -13531,7 +16001,7 @@
1353116001 {
1353216002 //Composite group = (Composite) object;
1353316003 Object3D group = object;
13534
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1353516005 // group.editWindow.ReduceMesh(true);
1353616006 }
1353716007
....@@ -13539,7 +16009,7 @@
1353916009 {
1354016010 //Composite group = (Composite) object;
1354116011 Object3D group = object;
13542
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1354316013 }
1354416014
1354516015 void IncDepth()
....@@ -13621,11 +16091,11 @@
1362116091
1362216092 int width = getBounds().width;
1362316093 int height = getBounds().height;
13624
- ClickInfo info = new ClickInfo();
13625
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1362616094 //Image img = CreateImage(width, height);
1362716095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1362816097 Graphics gr = g; // img.getGraphics();
16098
+
1362916099 if (!hasMarquee)
1363016100 {
1363116101 if (Xmin < Xmax) // !locked)
....@@ -13697,44 +16167,92 @@
1369716167 }
1369816168 if (object != null && !hasMarquee)
1369916169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1370016176 if (isRenderer)
1370116177 {
13702
- info.flags++;
16178
+ object.clickInfo.flags++;
1370316179 double frameAspect = (double) width / (double) height;
1370416180 if (frameAspect > renderCamera.aspect)
1370516181 {
1370616182 int desired = (int) ((double) height * renderCamera.aspect);
13707
- info.bounds.width -= width - desired;
13708
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1370916185 } else
1371016186 {
1371116187 int desired = (int) ((double) width / renderCamera.aspect);
13712
- info.bounds.height -= height - desired;
13713
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1371416190 }
1371516191 }
13716
- info.g = gr;
13717
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1371816195 /*
1371916196 // Memory intensive (brep.verticescopy)
1372016197 if (!(object instanceof Composite))
1372116198 object.draw(info, 0, false); // SLOW :
1372216199 */
13723
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1372416201 {
13725
- object.drawEditHandles(info, 0);
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
16205
+ {
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
16212
+ {
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
16220
+ }
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
16241
+ }
1372616242 }
1372716243 }
16244
+
1372816245 if (isRenderer)
1372916246 {
1373016247 //gr.setColor(Color.black);
1373116248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1373216249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1373316250 }
16251
+
1373416252 if (hasMarquee)
1373516253 {
1373616254 gr.setXORMode(Color.white);
13737
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1373816256 if (!firstime)
1373916257 {
1374016258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -13753,6 +16271,7 @@
1375316271 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1375416272 }
1375516273
16274
+ // To avoid clear.
1375616275 public void update(Graphics g)
1375716276 {
1375816277 paint(g);
....@@ -13842,6 +16361,7 @@
1384216361 public boolean mouseDown(Event evt, int x, int y)
1384316362 {
1384416363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1384516365 /*
1384616366 locked = true;
1384716367 drag = false;
....@@ -13885,7 +16405,7 @@
1388516405 {
1388616406 keyPressed(0, modifiers);
1388716407 }
13888
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1388916409 return true;
1389016410 }
1389116411
....@@ -14003,7 +16523,7 @@
1400316523 {
1400416524 keyReleased(0, 0);
1400516525 }
14006
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1400716527 return true;
1400816528 }
1400916529
....@@ -14135,7 +16655,7 @@
1413516655 Object3D object;
1413616656 static Object3D trackedobject;
1413716657 Camera renderCamera; // Light or Eye (or Occlusion)
14138
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1413916659 /*static*/ Camera eyeCamera;
1414016660 /*static*/ Camera lightCamera;
1414116661 int cameracount;
....@@ -14199,6 +16719,8 @@
1419916719 private /*static*/ boolean firstime;
1420016720 private /*static*/ cVector newView = new cVector();
1420116721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1420216724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1420316725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1420416726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14211,29 +16733,67 @@
1421116733 {
1421216734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1421316735
16736
+ int usedsuf = 0;
16737
+
1421416738 for (int i = 0; i < suffixes.length; i++)
1421516739 {
14216
- String resourceName = basename + suffixes[i] + "." + suffix;
14217
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14218
- mipmapped,
14219
- FileUtil.getFileSuffix(resourceName));
14220
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1422116745 {
14222
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1422316750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1422416779 //System.out.println("Target = " + targets[i]);
1422516780 cubemap.updateImage(data, targets[i]);
1422616781 }
1422716782
1422816783 return cubemap;
1422916784 }
16785
+
1423016786 int bigsphere = -1;
1423116787
1423216788 float BGcolor = 0.5f;
1423316789
14234
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1423516793 {
14236
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1423716797 {
1423816798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1423916799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14248,7 +16808,17 @@
1424816808 // Compensates for ExaminerViewer's modification of modelview matrix
1424916809 gl.glMatrixMode(GL.GL_MODELVIEW);
1425016810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1425116812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1425216822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1425316823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1425416824
....@@ -14280,6 +16850,7 @@
1428016850 {
1428116851 gl.glScalef(1.0f, -1.0f, 1.0f);
1428216852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1428316854 gl.glMultMatrixd(viewrot_1, 0);
1428416855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1428516856 //viewer.updateInverseRotation(gl);
....@@ -14320,7 +16891,8 @@
1432016891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1432116892
1432216893 cubemap.disable();
14323
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1432416896 if (CULLFACE)
1432516897 {
1432616898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -14355,7 +16927,7 @@
1435516927 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1435616928 gl.glPushMatrix();
1435716929 gl.glLoadIdentity();
14358
- PushMatrix(checker.toParent);
16930
+ //PushMatrix(checker.toParent);
1435916931
1436016932 gl.glMatrixMode(GL.GL_TEXTURE);
1436116933 gl.glPushMatrix();
....@@ -14376,10 +16948,10 @@
1437616948 gl.glScalef(1.0f, -1.0f, 1.0f);
1437716949 }
1437816950
14379
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1438016952
14381
- float step = 0.1666f; //0.25f;
14382
- float stepv = step * 1652 / 998;
16953
+ float step = 2; // 0.1666f; //0.25f;
16954
+ float stepv = 2; // step * 1652 / 998;
1438316955
1438416956 int i0 = 0;
1438516957 /*
....@@ -14415,20 +16987,21 @@
1441516987 /**/
1441616988 //checker.GetMaterial().opacity = 1.1f;
1441716989 ////checker.GetMaterial().ambient = 0.99f;
14418
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14419
- Object3D.selectedstack[Object3D.materialdepth] = false;
14420
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16990
+ materialstack[materialdepth] = checker.material;
16991
+ selectedstack[materialdepth] = false;
16992
+ cStatic.objectstack[materialdepth++] = checker;
1442116993 //System.out.println("material " + material);
1442216994 //Applet3D.tracein(this, selected);
14423
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1442416996
14425
- checker.GetMaterial().Draw(this, false); // true);
16997
+ //checker.GetMaterial().Draw(this, false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1442616999
14427
- Object3D.materialdepth -= 1;
14428
- if (Object3D.materialdepth > 0)
17000
+ materialdepth -= 1;
17001
+ if (materialdepth > 0)
1442917002 {
14430
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14431
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
17003
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17004
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1443217005 }
1443317006 //checker.GetMaterial().opacity = 1f;
1443417007 ////checker.GetMaterial().ambient = 1f;
....@@ -14449,15 +17022,27 @@
1444917022
1445017023 //float u = (i+1)/2;
1445117024 //float v = (j+1)/2;
14452
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
17025
+ if (checker.flipV)
17026
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
17027
+ else
17028
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1445317029 gl.glVertex3f(i, j, -0.5f);
1445417030
17031
+ if (checker.flipV)
17032
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
17033
+ else
1445517034 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1445617035 gl.glVertex3f(i + step, j, -0.5f);
1445717036
17037
+ if (checker.flipV)
17038
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
17039
+ else
1445817040 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1445917041 gl.glVertex3f(i + step, j + stepv, -0.5f);
1446017042
17043
+ if (checker.flipV)
17044
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
17045
+ else
1446117046 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1446217047 gl.glVertex3f(i, j + stepv, -0.5f);
1446317048 }
....@@ -14469,7 +17054,7 @@
1446917054 gl.glMatrixMode(GL.GL_PROJECTION);
1447017055 gl.glPopMatrix();
1447117056 gl.glMatrixMode(GL.GL_MODELVIEW);
14472
- PopMatrix(null); // checker.toParent); // null);
17057
+ //PopMatrix(null); // checker.toParent); // null);
1447317058 gl.glPopMatrix();
1447417059 PopTextureMatrix(checker.toParent);
1447517060 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14502,6 +17087,14 @@
1450217087 }
1450317088 }
1450417089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1450517098 class SelectBuffer implements GLEventListener
1450617099 {
1450717100
....@@ -14517,7 +17110,7 @@
1451717110 //new Exception().printStackTrace();
1451817111 System.out.println("select buffer init");
1451917112 // Use debug pipeline
14520
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1452117114
1452217115 GL gl = drawable.getGL();
1452317116
....@@ -14560,6 +17153,7 @@
1456017153 {
1456117154 if (!selection)
1456217155 {
17156
+ new Exception().printStackTrace();
1456317157 System.exit(0);
1456417158 return;
1456517159 }
....@@ -14580,17 +17174,39 @@
1458017174
1458117175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1458217176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1458317188 //int tmp = selection_view;
1458417189 //selection_view = -1;
14585
- int temp = drawMode;
14586
- drawMode = SELECTION;
17190
+ int temp = DrawMode();
17191
+ Globals.drawMode = SELECTION; // WARNING
1458717192 indexcount = 0;
1458817193 parent.display(drawable);
1458917194 //selection_view = tmp;
1459017195 //if (temp == SELECTION)
1459117196 // temp = DEFAULT; // patch for selection debug
14592
- drawMode = temp;
17197
+ Globals.drawMode = temp; // WARNING
1459317198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1459417210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1459517211
1459617212 // trying different ways of getting the depth info over
....@@ -14639,6 +17255,13 @@
1463917255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1464017256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1464117257
17258
+ CreateSelectedPoint();
17259
+
17260
+ // Will fit the mesh !!!
17261
+ selectedpoint.toParent[0][0] = 0.0001;
17262
+ selectedpoint.toParent[1][1] = 0.0001;
17263
+ selectedpoint.toParent[2][2] = 0.0001;
17264
+
1464217265 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1464317266
1464417267 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14682,34 +17305,36 @@
1468217305 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]));
1468317306 }
1468417307
14685
- previousselectedpoint = (Sphere) GraphreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1468617309 }
1468717310 }
1468817311
1468917312 if (!movingcamera && !PAINTMODE)
14690
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1469117314
14692
- if (PAINTMODE && GraphreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1469317316 {
14694
- Object3D paintobj = GraphreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1469517318
14696
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1469717322
14698
- group.CreateMaterial(); // use a void leaf to select instances
14699
-
14700
- group.add(paintobj); // link
14701
-
14702
- object.editWindow.SnapObject(group);
14703
-
14704
- Object3D folder = object.editWindow.copy;
14705
-
14706
- if (object.editWindow.copy.selection.Size() > 0)
14707
- folder = object.editWindow.copy.selection.elementAt(0);
14708
-
14709
- folder.add(group);
14710
-
14711
- object.editWindow.ResetModel();
14712
- object.editWindow.refreshContents();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1471317338 }
1471417339 else
1471517340 paintcount = 0;
....@@ -14748,6 +17373,11 @@
1474817373 //System.out.println("objects[color] = " + objects[color]);
1474917374 //objects[color].Select();
1475017375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1475117381 object.Select(color, deselect);
1475217382 }
1475317383
....@@ -14798,6 +17428,7 @@
1479817428
1479917429 public void init(GLAutoDrawable drawable)
1480017430 {
17431
+ if (Globals.DEBUG)
1480117432 System.out.println("shadow buffer init");
1480217433
1480317434 GL gl = drawable.getGL();
....@@ -14847,7 +17478,7 @@
1484717478 gl.glDisable(gl.GL_CULL_FACE);
1484817479 }
1484917480
14850
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1485117482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1485217483
1485317484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14857,14 +17488,14 @@
1485717488 //gl.glColorMask(false, false, false, false);
1485817489
1485917490 //render_scene_from_light_view(gl, drawable, 0, 0);
14860
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1486117492 {
1486217493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1486317494
14864
- int temp = drawMode;
14865
- drawMode = SHADOW;
17495
+ int temp = DrawMode();
17496
+ Globals.drawMode = SHADOW; // WARNING
1486617497 parent.display(drawable);
14867
- drawMode = temp;
17498
+ Globals.drawMode = temp; // WARNING
1486817499 }
1486917500
1487017501 gl.glCullFace(gl.GL_BACK);
....@@ -14917,7 +17548,6 @@
1491717548
1491817549 class AntialiasBuffer implements GLEventListener
1491917550 {
14920
-
1492117551 CameraPane parent = null;
1492217552
1492317553 AntialiasBuffer(CameraPane p)
....@@ -15027,15 +17657,25 @@
1502717657 gl.glFlush();
1502817658
1502917659 /**/
15030
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1503117661
15032
- int[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1503317663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1503417668 double r = 0, g = 0, b = 0;
1503517669
1503617670 double count = 0;
17671
+
17672
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17673
+
17674
+ float mindepth = 1;
17675
+
17676
+ double FACTOR = 1;
1503717677
15038
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1503917679 {
1504017680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1504117681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15118,7 +17758,7 @@
1511817758
1511917759 double scale = ray.z; // 1; // cos
1512017760
15121
- int p = pixels[newindex];
17761
+ float depth = depths[newindex];
1512217762
1512317763 /*
1512417764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15142,10 +17782,23 @@
1514217782 scale = (1 - modu) * modv;
1514317783 */
1514417784
15145
- r += ((p >> 16) & 0xFF) * scale / 255;
15146
- g += ((p >> 8) & 0xFF) * scale / 255;
15147
- b += (p & 0xFF) * scale / 255;
17785
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17786
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17787
+ //b += (p & 0xFF) * scale / 255;
17788
+
17789
+ if (mindepth > depth)
17790
+ {
17791
+ mindepth = depth;
17792
+ }
1514817793
17794
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17795
+
17796
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17797
+
17798
+ r += factor * scale;
17799
+ g += factor * scale;
17800
+ b += factor * scale;
17801
+
1514917802 count += scale;
1515017803 }
1515117804
....@@ -15243,12 +17896,6 @@
1524317896 GLUT glut = new GLUT();
1524417897
1524517898
15246
- static final public int DEFAULT = 0;
15247
- static final public int SELECTION = 1;
15248
- static final public int SHADOW = 2;
15249
- static final public int OCCLUSION = 3;
15250
- static
15251
- public int drawMode = DEFAULT;
1525217899 public boolean spherical = false;
1525317900 static boolean DEBUG_OCCLUSION = false;
1525417901 static boolean DEBUG_SELECTION = false;
....@@ -15261,21 +17908,15 @@
1526117908 int AAbuffersize = 0;
1526217909
1526317910 //double[] selectedpoint = new double[3];
15264
- static Sphere selectedpoint = new Sphere();
17911
+ static Superellipsoid selectedpoint;
1526517912 static Sphere previousselectedpoint = null;
15266
- static Sphere debugpoint = new Sphere();
15267
- static Sphere debugpoint2 = new Sphere();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1526817917
1526917918 static Sphere debugpoints[] = new Sphere[8];
1527017919
15271
- static
15272
- {
15273
- for (int i=0; i<8; i++)
15274
- {
15275
- debugpoints[i] = new Sphere();
15276
- }
15277
- }
15278
-
1527917920 static void InitPoints(float radius)
1528017921 {
1528117922 for (int i=0; i<8; i++)
....@@ -15295,7 +17936,7 @@
1529517936 }
1529617937 }
1529717938
15298
- static void DrawPoints(CameraPane cpane)
17939
+ static void DrawPoints(iCameraPane cpane)
1529917940 {
1530017941 for (int i=0; i<8; i++) // first and last are red
1530117942 {
....@@ -15314,10 +17955,14 @@
1531417955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1531517956 static IntBuffer bigAAbuffer;
1531617957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15317
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1531817959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1531917960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15320
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17961
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1532117966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1532217967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1532317968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15326,10 +17971,11 @@
1532617971 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1532717972 // Depth buffer format
1532817973 //private int depth_format;
15329
- static public void NextIndex(Object3D o, GL gl)
17974
+
17975
+ public void NextIndex()
1533017976 {
1533117977 indexcount+=16;
15332
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17978
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1533317979 //objects[indexcount] = o;
1533417980 //System.out.println("indexcount = " + indexcount);
1533517981 }