Normand Briere
2019-08-18 66aca73cce89e4b4d7521862760edf4b0888bc38
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,1616 @@
199307 GetGL().glDepthMask(false);
200308 }
201309
202
- void BackFaceCull(boolean bfc)
310
+ public void BackFaceCull(boolean bfc)
203311 {
204312 if (bfc)
205313 GetGL().glEnable(GetGL().GL_CULL_FACE);
206314 else
207315 GetGL().glDisable(GetGL().GL_CULL_FACE);
316
+ }
317
+
318
+ public boolean BackFaceCullMode()
319
+ {
320
+ return this.CULLFACE;
321
+ }
322
+
323
+ public boolean IsAmbientOcclusionOn()
324
+ {
325
+ return this.ambientOcclusion;
326
+ }
327
+
328
+ public boolean IsDebugSelection()
329
+ {
330
+ return DEBUG_SELECTION;
331
+ }
332
+
333
+ public boolean IsFrozen()
334
+ {
335
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
336
+
337
+ return !selectmode && cameracount == 0; // != 0;
338
+ }
339
+
340
+ // Currently in Globals
341
+ public int DrawMode()
342
+ {
343
+ return Globals.DrawMode();
344
+ }
345
+
346
+ public Camera EyeCamera()
347
+ {
348
+ return eyeCamera;
349
+ }
350
+
351
+ public Camera LightCamera()
352
+ {
353
+ return lightCamera;
354
+ }
355
+
356
+ public Camera ManipCamera()
357
+ {
358
+ return manipCamera;
359
+ }
360
+
361
+ public Camera RenderCamera()
362
+ {
363
+ return renderCamera;
364
+ }
365
+
366
+ public Camera[] Cameras()
367
+ {
368
+ return cameras;
369
+ }
370
+
371
+ public void PushMaterial(Object3D obj, boolean selected)
372
+ {
373
+ CameraPane display = this;
374
+ javax.media.opengl.GL gl = display.GetGL();
375
+ cMaterial material = obj.material;
376
+
377
+ if (material != null)
378
+ {
379
+ materialstack[materialdepth] = material;
380
+ selectedstack[materialdepth] = selected;
381
+ cStatic.objectstack[materialdepth++] = obj;
382
+ //System.out.println("material " + material);
383
+ //Applet3D.tracein(this, selected);
384
+ //display.vector2buffer = obj.projectedVertices;
385
+ if (obj instanceof Camera)
386
+ {
387
+ display.options1[0] = material.shift;
388
+ //System.out.println("shift " + material.shift);
389
+ display.options1[1] = material.lightarea;
390
+ display.options1[2] = material.shadowbias;
391
+ display.options1[3] = material.aniso;
392
+ display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
398
+ display.options2[0] = material.opacity;
399
+ display.options2[1] = material.diffuse;
400
+ display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
404
+
405
+ cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
409
+ display.options4[0] = material.cameralight/0.2f;
410
+ display.options4[1] = material.subsurface;
411
+ display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
415
+
416
+ // if (display.CURRENTANTIALIAS > 0)
417
+ // display.options3[3] /= 4;
418
+
419
+ /*
420
+ System.out.println("Focus = " + display.options1[0]);
421
+ System.out.println("Aperture = " + display.options1[1]);
422
+ System.out.println("ShadowBlur = " + display.options1[2]);
423
+ System.out.println("Antialiasing = " + display.options1[3]);
424
+ System.out.println("Fog = " + display.options2[0]);
425
+ System.out.println("Intensity = " + display.options2[1]);
426
+ System.out.println("Elevation = " + display.options2[2]);
427
+ /**/
428
+ } else
429
+ {
430
+ DrawMaterial(material, selected, obj.projectedVertices);
431
+ }
432
+ } else
433
+ {
434
+ if (selected && CameraPane.flash)
435
+ {
436
+ display.modelParams4[1] = 100;
437
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
438
+ }
439
+ }
440
+ }
441
+
442
+ public void PushMaterial2(Object3D obj, boolean selected)
443
+ {
444
+ CameraPane display = this;
445
+ cMaterial material = obj.material;
446
+
447
+ if (material != null)
448
+ {
449
+ materialstack[materialdepth] = material;
450
+ selectedstack[materialdepth] = selected;
451
+ cStatic.objectstack[materialdepth++] = obj;
452
+ //System.out.println("material " + material);
453
+ //Applet3D.tracein("selected ", selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
456
+ }
457
+ }
458
+
459
+ public void PopMaterial(Object3D obj, boolean selected)
460
+ {
461
+ CameraPane display = this;
462
+ javax.media.opengl.GL gl = display.GetGL();
463
+ cMaterial material = obj.material;
464
+
465
+ //if (parent != null && parent.GetMaterial() != null)
466
+ // parent.GetMaterial().Draw(display, parent.IsSelected(this));
467
+ if (material != null)
468
+ {
469
+ materialdepth -= 1;
470
+ if (materialdepth > 0)
471
+ {
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
474
+ }
475
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
476
+ } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
477
+ {
478
+ display.modelParams4[1] = obj.GetMaterial().cameralight;
479
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
480
+ }
481
+ }
482
+
483
+ public void PopMaterial2(Object3D obj)
484
+ {
485
+ CameraPane display = this;
486
+ cMaterial material = obj.material;
487
+
488
+ if (material != null)
489
+ {
490
+ materialdepth -= 1;
491
+ if (materialdepth > 0)
492
+ {
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
495
+ }
496
+ //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
497
+ //else
498
+ //material.Draw(display, false);
499
+ }
500
+ }
501
+
502
+ public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
503
+ {
504
+ CameraPane display = this;
505
+
506
+ if (pv.y == -10000 ||
507
+ qv.y == -10000 ||
508
+ rv.y == -10000)
509
+ return;
510
+
511
+// float b = f.nbiterations & 1;
512
+// float g = (f.nbiterations>>1) & 1;
513
+// float r = (f.nbiterations>>2) & 1;
514
+//
515
+// //if (f.weight == 10000)
516
+// //{
517
+// // r = 1; g = b = 0;
518
+// //}
519
+// //else
520
+// //{
521
+// // assert(f.weight < 10000);
522
+// r = g = b = (float)bRep.FaceWeight(f)*100;
523
+// if (r<0)
524
+// assert(r>=0);
525
+// //}
526
+
527
+ javax.media.opengl.GL gl = display.GetGL();
528
+
529
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
530
+
531
+ //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
532
+ if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
533
+ {
534
+ //gl.glBegin(gl.GL_TRIANGLES);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
538
+ if (!hasnorm)
539
+ {
540
+ // System.out.println("Mesh normal");
541
+ LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
542
+ LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
543
+ LA.vecCross(obj.v0, obj.v1, obj.v2);
544
+ LA.vecNormalize(obj.v2);
545
+ gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
546
+ }
547
+
548
+ // P
549
+ float x = (float)pv.x;
550
+ float y = (float)pv.y;
551
+ float z = (float)pv.z;
552
+
553
+ if (hasnorm)
554
+ {
555
+// if (!pv.norm.normalized())
556
+// assert(pv.norm.normalized());
557
+
558
+ //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
559
+ float nx = (float)pv.norm.x;
560
+ float ny = (float)pv.norm.y;
561
+ float nz = (float)pv.norm.z;
562
+
563
+ x += nx * obj.NORMALPUSH;
564
+ y += ny * obj.NORMALPUSH;
565
+ z += nz * obj.NORMALPUSH;
566
+
567
+ gl.glNormal3f(nx, ny, nz);
568
+ }
569
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
570
+ SetColor(obj, pv);
571
+ //gl.glColor4f(r, g, b, 1);
572
+ //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
573
+ if (obj.flipV)
574
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
575
+ else
576
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
577
+ //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
578
+
579
+ gl.glVertex3f(x, y, z);
580
+
581
+ // Q
582
+ x = (float)qv.x;
583
+ y = (float)qv.y;
584
+ z = (float)qv.z;
585
+
586
+// Print(pv);
587
+ if (hasnorm)
588
+ {
589
+// assert(qv.norm.normalized());
590
+ //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
591
+ float nx = (float)qv.norm.x;
592
+ float ny = (float)qv.norm.y;
593
+ float nz = (float)qv.norm.z;
594
+
595
+ x += nx * obj.NORMALPUSH;
596
+ y += ny * obj.NORMALPUSH;
597
+ z += nz * obj.NORMALPUSH;
598
+
599
+ gl.glNormal3f(nx, ny, nz);
600
+ }
601
+ //System.out.println("vertexq = " + qv.s + ", " + qv.t);
602
+ // boolean locked = false;
603
+ // float eps = 0.1f;
604
+ // boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
605
+
606
+ // int dot = 0; //*/ (int)f.dot;
607
+
608
+ // if ((dot&1) == 0)
609
+ // dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
610
+
611
+ // if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
612
+ if (obj.flipV)
613
+ gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
614
+ else
615
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
616
+ // else
617
+ // {
618
+ // locked = true;
619
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
620
+ // }
621
+ gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
622
+ SetColor(obj, qv);
623
+
624
+ gl.glVertex3f(x, y, z);
625
+ //gl.glColor4f(r, g, b, 1);
626
+ //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
627
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
628
+// Print(qv);
629
+
630
+ // R
631
+ x = (float)rv.x;
632
+ y = (float)rv.y;
633
+ z = (float)rv.z;
634
+
635
+ if (hasnorm)
636
+ {
637
+// assert(rv.norm.normalized());
638
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
639
+ float nx = (float)rv.norm.x;
640
+ float ny = (float)rv.norm.y;
641
+ float nz = (float)rv.norm.z;
642
+
643
+ x += nx * obj.NORMALPUSH;
644
+ y += ny * obj.NORMALPUSH;
645
+ z += nz * obj.NORMALPUSH;
646
+
647
+ gl.glNormal3f(nx, ny, nz);
648
+ }
649
+
650
+ // if ((dot&4) == 0)
651
+ // dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
652
+
653
+ // if (wrap || !locked && (dot&8) != 0)
654
+ if (obj.flipV)
655
+ gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
656
+ else
657
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
658
+ // else
659
+ // gl.glTexCoord2f((float) pv.s, (float) pv.t);
660
+
661
+ // f.dot = dot;
662
+
663
+ gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
664
+ SetColor(obj, rv);
665
+ //gl.glColor4f(r, g, b, 1);
666
+ //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
667
+ //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
668
+ gl.glVertex3f(x, y, z);
669
+// Print(rv);
670
+ //gl.glEnd();
671
+ }
672
+ else
673
+ {
674
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
675
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
676
+ gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
677
+
678
+ }
679
+
680
+ if (false) // (attributes & WIREFRAME) != 0)
681
+ {
682
+ gl.glDisable(gl.GL_LIGHTING);
683
+
684
+ gl.glBegin(gl.GL_LINE_LOOP);
685
+ gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
686
+ gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
687
+ gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
688
+ gl.glEnd();
689
+
690
+ gl.glEnable(gl.GL_LIGHTING);
691
+ }
692
+ }
693
+
694
+ /**
695
+ * <code>draw</code> renders a <code>TriMesh</code> object including
696
+ * it's normals, colors, textures and vertices.
697
+ *
698
+ * @see Renderer#draw(TriMesh)
699
+ * @param tris
700
+ * the mesh to render.
701
+ */
702
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
703
+ {
704
+ CameraPane display = this;
705
+
706
+ float r = display.modelParams0[0];
707
+ float g = display.modelParams0[1];
708
+ float b = display.modelParams0[2];
709
+ float opacity = display.modelParams5[1];
710
+
711
+ //final GL gl = GLU.getCurrentGL();
712
+ GL gl = display.GetGL(); // getGL();
713
+
714
+ FloatBuffer vertBuf = geo.vertBuf;
715
+
716
+ int v = vertBuf.capacity();
717
+
718
+ int count = 0;
719
+
720
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
721
+ gl.glEnable(gl.GL_CULL_FACE);
722
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
723
+ for (int i=0; i<v/3; i++)
724
+ {
725
+ int index3 = i*3;
726
+
727
+ if (geo.sizeBuf.get(index3+1) == 0)
728
+ continue;
729
+
730
+ count++;
731
+
732
+ int index4 = i*4;
733
+
734
+ float tx = vertBuf.get(index3);
735
+ float ty = vertBuf.get(index3+1);
736
+ float tz = vertBuf.get(index3+2);
737
+
738
+ // if (tx == 0 && ty == 0 && tz == 0)
739
+ // continue;
740
+
741
+ gl.glMatrixMode(gl.GL_TEXTURE);
742
+ gl.glPushMatrix();
743
+
744
+ float[] texmat = geo.texmat;
745
+ texmat[12] = texmat[13] = texmat[14] = i;
746
+
747
+ gl.glMultMatrixf(texmat, 0);
748
+
749
+ gl.glMatrixMode(gl.GL_MODELVIEW);
750
+ gl.glPushMatrix();
751
+
752
+ gl.glTranslatef(tx,ty,tz);
753
+
754
+ if (rotate)
755
+ gl.glRotatef(i, 0, 1, 0);
756
+
757
+ float size = geo.sizeBuf.get(index3) / 100;
758
+ gl.glScalef(size,size,size);
759
+
760
+ float cr = geo.colorBuf.get(index4);
761
+ float cg = geo.colorBuf.get(index4+1);
762
+ float cb = geo.colorBuf.get(index4+2);
763
+ float ca = geo.colorBuf.get(index4+3);
764
+
765
+ display.modelParams0[0] = r * cr;
766
+ display.modelParams0[1] = g * cg;
767
+ display.modelParams0[2] = b * cb;
768
+
769
+ display.modelParams5[1] = opacity * ca;
770
+
771
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
772
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
773
+
774
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
775
+ RandomNode.globalseed2 = RandomNode.globalseed;
776
+
777
+// gl.glColor4f(cr,cg,cb,ca);
778
+ // gl.glScalef(1024/16,1024/16,1024/16);
779
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
780
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
781
+ //gl.glTranslatef(-tx,-ty,-tz);
782
+ gl.glPopMatrix();
783
+
784
+ gl.glMatrixMode(gl.GL_TEXTURE);
785
+ gl.glPopMatrix();
786
+ }
787
+ // gl.glScalef(1024,1024,1024);
788
+ if (!cf)
789
+ gl.glDisable(gl.GL_CULL_FACE);
790
+
791
+ display.modelParams0[0] = r;
792
+ display.modelParams0[1] = g;
793
+ display.modelParams0[2] = b;
794
+
795
+ display.modelParams5[1] = opacity;
796
+
797
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
798
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
799
+
800
+ gl.glMatrixMode(gl.GL_MODELVIEW);
801
+
802
+// System.err.println("total = " + v/3 + "; displayed = " + count);
803
+ if (true)
804
+ return;
805
+
806
+//// if (!tris.predraw(this))
807
+//// {
808
+//// return;
809
+//// }
810
+//// if (Debug.stats)
811
+//// {
812
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
813
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
814
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
815
+//// }
816
+////
817
+//// if (tris.getDisplayListID() != -1)
818
+//// {
819
+//// renderDisplayList(tris);
820
+//// return;
821
+//// }
822
+////
823
+//// if (!generatingDisplayList)
824
+//// {
825
+//// applyStates(tris.states, tris);
826
+//// }
827
+//// if (Debug.stats)
828
+//// {
829
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
830
+//// }
831
+//// boolean transformed = doTransforms(tris);
832
+//
833
+// int glMode = GL.GL_TRIANGLES;
834
+// switch (getMode())
835
+// {
836
+// case Triangles:
837
+// glMode = GL.GL_TRIANGLES;
838
+// break;
839
+// case Strip:
840
+// glMode = GL.GL_TRIANGLE_STRIP;
841
+// break;
842
+// case Fan:
843
+// glMode = GL.GL_TRIANGLE_FAN;
844
+// break;
845
+// }
846
+//
847
+// if (!predrawGeometry(gl))
848
+// {
849
+// // make sure only the necessary indices are sent through on old
850
+// // cards.
851
+// IntBuffer indices = this.getIndexBuffer();
852
+// if (indices == null)
853
+// {
854
+// logger.severe("missing indices on geometry object: " + this.toString());
855
+// } else
856
+// {
857
+// indices.rewind();
858
+// indices.limit(this.getMaxIndex());
859
+//
860
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
861
+//
862
+// indices.clear();
863
+// }
864
+// } else
865
+// {
866
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
867
+// GL.GL_UNSIGNED_INT, 0);
868
+// }
869
+//
870
+//// postdrawGeometry(tris);
871
+//// if (transformed)
872
+//// {
873
+//// undoTransforms(tris);
874
+//// }
875
+////
876
+//// if (Debug.stats)
877
+//// {
878
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
879
+//// }
880
+//// tris.postdraw(this);
881
+ }
882
+
883
+ static Camera localcamera = new Camera();
884
+ static cVector from = new cVector();
885
+ static cVector to = new cVector();
886
+
887
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
888
+ {
889
+ CameraPane cp = this;
890
+
891
+ Camera keep = cp.RenderCamera();
892
+ cp.renderCamera = localcamera;
893
+
894
+ if (br.trimmed)
895
+ {
896
+ float[] colors = new float[br.positions.length / 3];
897
+
898
+ int i3 = 0;
899
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
900
+ {
901
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
902
+ continue;
903
+
904
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
905
+ to.set(br.positions[i3] + br.normals[i3],
906
+ br.positions[i3 + 1] + br.normals[i3 + 1],
907
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
908
+ LA.xformPos(from, transform, from);
909
+ LA.xformPos(to, transform, to); // RIGID ONLY
910
+ localcamera.setAim(from, to);
911
+
912
+ CameraPane.occlusionbuffer.display();
913
+
914
+ if (CameraPane.DEBUG_OCCLUSION)
915
+ cp.display(); // debug
916
+
917
+ colors[i] = cp.vertexOcclusion.r;
918
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
919
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
920
+
921
+ if ((i % 100) == 0 && i != 0)
922
+ {
923
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
924
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
925
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
926
+ }
927
+ }
928
+
929
+ br.colors = colors;
930
+ }
931
+ else
932
+ {
933
+ for (int i = 0; i < br.VertexCount(); i++)
934
+ {
935
+ Vertex v = br.GetVertex(i);
936
+
937
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
938
+ continue;
939
+
940
+ from.set(v.x, v.y, v.z);
941
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
942
+ LA.xformPos(from, transform, from);
943
+ LA.xformPos(to, transform, to); // RIGID ONLY
944
+ localcamera.setAim(from, to);
945
+
946
+ CameraPane.occlusionbuffer.display();
947
+
948
+ if (CameraPane.DEBUG_OCCLUSION)
949
+ cp.display(); // debug
950
+
951
+ v.AO = cp.vertexOcclusion.r;
952
+
953
+ if ((i % 100) == 0 && i != 0)
954
+ {
955
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
956
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
957
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
958
+ }
959
+ }
960
+ }
961
+
962
+ //System.out.println("done.");
963
+
964
+ cp.renderCamera = keep;
965
+ }
966
+
967
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
968
+ {
969
+ CameraPane display = this;
970
+ pointFlow.CreateHT();
971
+
972
+ float r = display.modelParams0[0];
973
+ float g = display.modelParams0[1];
974
+ float b = display.modelParams0[2];
975
+ float opacity = display.modelParams5[1];
976
+
977
+ //final GL gl = GLU.getCurrentGL();
978
+ GL gl = display.GetGL(); // getGL();
979
+
980
+ int s = pointFlow.points.size();
981
+
982
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
983
+ gl.glEnable(gl.GL_CULL_FACE);
984
+
985
+ for (int i=s; --i>=0;)
986
+ //for (int i=0; i<s; i++)
987
+ {
988
+ cVector v = pointFlow.points.get(i);
989
+
990
+ double mindist = Double.MAX_VALUE;
991
+
992
+ double size = pointFlow.minimumSize;
993
+
994
+ double distancenext = 0;
995
+
996
+ if (i > 0)
997
+ {
998
+ cVector w = pointFlow.points.get(i-1);
999
+
1000
+ double dist = w.distance(v);
1001
+
1002
+ distancenext = dist;
1003
+
1004
+ if (mindist > dist)
1005
+ {
1006
+ mindist = dist;
1007
+ size = mindist*pointFlow.resizefactor;
1008
+ }
1009
+ }
1010
+
1011
+ if (i < s-1)
1012
+ {
1013
+ cVector w = pointFlow.points.get(i+1);
1014
+
1015
+ double dist = w.distance(v);
1016
+
1017
+ if (mindist > dist)
1018
+ {
1019
+ mindist = dist;
1020
+ size = mindist*pointFlow.resizefactor;
1021
+ }
1022
+ }
1023
+
1024
+ if (size < pointFlow.minimumSize)
1025
+ size = pointFlow.minimumSize;
1026
+ if (size > pointFlow.maximumSize)
1027
+ size = pointFlow.maximumSize;
1028
+
1029
+ double tx = v.x;
1030
+ double ty = v.y;
1031
+ double tz = v.z;
1032
+
1033
+ // if (tx == 0 && ty == 0 && tz == 0)
1034
+ // continue;
1035
+
1036
+ gl.glMatrixMode(gl.GL_TEXTURE);
1037
+ gl.glPushMatrix();
1038
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1039
+
1040
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1041
+
1042
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1043
+ gl.glPushMatrix();
1044
+
1045
+ gl.glTranslated(tx,ty,tz);
1046
+
1047
+ gl.glScaled(size,size,size);
1048
+
1049
+// float cr = colorBuf.get(index4);
1050
+// float cg = colorBuf.get(index4+1);
1051
+// float cb = colorBuf.get(index4+2);
1052
+// float ca = colorBuf.get(index4+3);
1053
+//
1054
+// display.modelParams0[0] = r * cr;
1055
+// display.modelParams0[1] = g * cg;
1056
+// display.modelParams0[2] = b * cb;
1057
+//
1058
+// display.modelParams5[1] = opacity * ca;
1059
+//
1060
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1061
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1062
+//
1063
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1064
+// RandomNode.globalseed2 = RandomNode.globalseed;
1065
+//
1066
+//// gl.glColor4f(cr,cg,cb,ca);
1067
+// // gl.glScalef(1024/16,1024/16,1024/16);
1068
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1069
+
1070
+ gl.glPopMatrix();
1071
+
1072
+ double step = size/4; //
1073
+
1074
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1075
+ continue;
1076
+
1077
+ int nbsteps = (int)(distancenext/step);
1078
+
1079
+ step = distancenext/nbsteps;
1080
+
1081
+ cVector next = pointFlow.points.get(i-1);
1082
+
1083
+ tmp.set(next);
1084
+ tmp.sub(v);
1085
+ tmp.normalize();
1086
+ tmp.mul(step);
1087
+
1088
+ // calculate next size
1089
+ mindist = Double.MAX_VALUE;
1090
+
1091
+ double nextsize = pointFlow.minimumSize;
1092
+
1093
+ if (i > 1)
1094
+ {
1095
+ cVector w = pointFlow.points.get(i-2);
1096
+
1097
+ double dist = w.distance(next);
1098
+
1099
+ if (mindist > dist)
1100
+ {
1101
+ mindist = dist;
1102
+ nextsize = mindist*pointFlow.resizefactor;
1103
+ }
1104
+ }
1105
+
1106
+ double dist = v.distance(next);
1107
+
1108
+ if (mindist > dist)
1109
+ {
1110
+ mindist = dist;
1111
+ nextsize = mindist*pointFlow.resizefactor;
1112
+ }
1113
+
1114
+ if (nextsize < pointFlow.minimumSize)
1115
+ nextsize = pointFlow.minimumSize;
1116
+ if (nextsize > pointFlow.maximumSize)
1117
+ nextsize = pointFlow.maximumSize;
1118
+ //
1119
+
1120
+ double count = 0;
1121
+
1122
+ while (distancenext > 0.000000001) // step
1123
+ {
1124
+ gl.glPushMatrix();
1125
+
1126
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1127
+
1128
+ double K = count/nbsteps;
1129
+
1130
+ double intersize = K*nextsize + (1-K)*size;
1131
+
1132
+ gl.glScaled(intersize,intersize,intersize);
1133
+
1134
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1135
+
1136
+ count++;
1137
+
1138
+ distancenext -= step;
1139
+
1140
+ gl.glPopMatrix();
1141
+ }
1142
+
1143
+ if (count != nbsteps)
1144
+ assert(count == nbsteps);
1145
+
1146
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1147
+ //gl.glTranslatef(-tx,-ty,-tz);
1148
+
1149
+ gl.glMatrixMode(gl.GL_TEXTURE);
1150
+ gl.glPopMatrix();
1151
+ }
1152
+
1153
+ if (!cf)
1154
+ gl.glDisable(gl.GL_CULL_FACE);
1155
+
1156
+// display.modelParams0[0] = r;
1157
+// display.modelParams0[1] = g;
1158
+// display.modelParams0[2] = b;
1159
+//
1160
+// display.modelParams5[1] = opacity;
1161
+//
1162
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1163
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1164
+
1165
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1166
+ }
1167
+
1168
+ public void DrawBox(cVector min, cVector max)
1169
+ {
1170
+ javax.media.opengl.GL gl = GetGL();
1171
+ gl.glBegin(gl.GL_LINES);
1172
+
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, min.y, max.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(min.x, max.y, min.z);
1177
+ gl.glVertex3d(min.x, min.y, min.z);
1178
+ gl.glVertex3d(max.x, min.y, min.z);
1179
+
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(min.x, max.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, min.y, max.z);
1184
+ gl.glVertex3d(max.x, max.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, min.z);
1186
+
1187
+ gl.glEnd();
1188
+ }
1189
+
1190
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1191
+ {
1192
+ int[] strips = bRep.getRawIndices();
1193
+
1194
+ javax.media.opengl.GL gl = GetGL();
1195
+
1196
+ // TRIANGLE STRIP ARRAY
1197
+ if (bRep.trimmed)
1198
+ {
1199
+ float[] v = bRep.getRawVertices();
1200
+ float[] n = bRep.getRawNormals();
1201
+ float[] c = bRep.getRawColors();
1202
+ float[] uv = bRep.getRawUVMap();
1203
+
1204
+ int count2 = 0;
1205
+ int count3 = 0;
1206
+
1207
+ if (n.length > 0)
1208
+ {
1209
+ for (int i = 0; i < strips.length; i++)
1210
+ {
1211
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1212
+
1213
+ /*
1214
+ boolean locked = false;
1215
+ float eps = 0.1f;
1216
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1217
+
1218
+ int dot = 0;
1219
+
1220
+ if ((dot&1) == 0)
1221
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1222
+
1223
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1224
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1225
+ else
1226
+ {
1227
+ locked = true;
1228
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1229
+ }
1230
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1231
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1232
+ if (hasnorm)
1233
+ {
1234
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1235
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1236
+ }
1237
+
1238
+ if ((dot&4) == 0)
1239
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1240
+
1241
+ if (wrap || !locked && (dot&8) != 0)
1242
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1243
+ else
1244
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1245
+
1246
+ f.dot = dot;
1247
+ */
1248
+
1249
+ if (!selectmode)
1250
+ {
1251
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1252
+ {
1253
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ } else
1255
+ {
1256
+ gl.glNormal3f(0, 0, 1);
1257
+ }
1258
+
1259
+ if (c != null)
1260
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1261
+ {
1262
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1263
+ }
1264
+ }
1265
+
1266
+ if (flipV)
1267
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1268
+ else
1269
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1270
+
1271
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1272
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1273
+
1274
+ count2 += 2;
1275
+ count3 += 3;
1276
+ if (!selectmode)
1277
+ {
1278
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1279
+ {
1280
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ } else
1282
+ {
1283
+ gl.glNormal3f(0, 0, 1);
1284
+ }
1285
+ if (c != null)
1286
+ {
1287
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1288
+ }
1289
+ }
1290
+
1291
+ if (flipV)
1292
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1293
+ else
1294
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1295
+
1296
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1297
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1298
+
1299
+ count2 += 2;
1300
+ count3 += 3;
1301
+ for (int j = 0; j < strips[i] - 2; j++)
1302
+ {
1303
+ //gl.glTexCoord2d(...);
1304
+ if (!selectmode)
1305
+ {
1306
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1307
+ {
1308
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ } else
1310
+ {
1311
+ gl.glNormal3f(0, 0, 1);
1312
+ }
1313
+ if (c != null)
1314
+ {
1315
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1316
+ }
1317
+ }
1318
+
1319
+ if (flipV)
1320
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1321
+ else
1322
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1323
+
1324
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1325
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1326
+
1327
+ count2 += 2;
1328
+ count3 += 3;
1329
+ }
1330
+
1331
+ gl.glEnd();
1332
+ }
1333
+ }
1334
+
1335
+ assert count3 == v.length;
1336
+ }
1337
+ else // !trimmed
1338
+ {
1339
+ int count = 0;
1340
+ for (int i = 0; i < strips.length; i++)
1341
+ {
1342
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1343
+
1344
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1345
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1346
+
1347
+ drawVertex(gl, p, flipV, selectmode);
1348
+ drawVertex(gl, q, flipV, selectmode);
1349
+
1350
+ for (int j = 0; j < strips[i] - 2; j++)
1351
+ {
1352
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1353
+
1354
+ // if (j%2 == 0)
1355
+ // drawFace(p, q, r, display, null);
1356
+ // else
1357
+ // drawFace(p, r, q, display, null);
1358
+
1359
+ // p = q;
1360
+ // q = r;
1361
+ drawVertex(gl, r, flipV, selectmode);
1362
+ }
1363
+
1364
+ gl.glEnd();
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ static cSpring.Point3D temp = new cSpring.Point3D();
1370
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1372
+
1373
+ public void DrawDynamicMesh(cMesh mesh)
1374
+ {
1375
+ GL gl = GetGL(); // getGL();
1376
+
1377
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1378
+
1379
+ gl.glDisable(gl.GL_LIGHTING);
1380
+
1381
+ gl.glLineWidth(1);
1382
+ gl.glColor3f(1,1,1);
1383
+ gl.glBegin(gl.GL_LINES);
1384
+ double scale = 0;
1385
+ int count = 0;
1386
+ for (int s=0; s<Phys.allSprings.size(); s++)
1387
+ {
1388
+ cSpring.Spring spring = Phys.allSprings.get(s);
1389
+ if(s == 0)
1390
+ {
1391
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1392
+ }
1393
+ if (mesh.showsprings)
1394
+ {
1395
+ temp.set(spring.a.position);
1396
+ temp.add(spring.b.position);
1397
+ temp.mul(0.5);
1398
+ temp2.set(spring.a.position);
1399
+ temp2.sub(spring.b.position);
1400
+ temp2.mul(spring.restLength/2);
1401
+ temp.sub(temp2);
1402
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1403
+ temp.add(temp2);
1404
+ temp.add(temp2);
1405
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1406
+ }
1407
+
1408
+ if (spring.isHandle)
1409
+ continue;
1410
+
1411
+ //if (scale < spring.restLength)
1412
+ scale += spring.restLength;
1413
+ count++;
1414
+ }
1415
+ gl.glEnd();
1416
+
1417
+ if (count == 0)
1418
+ scale = 0.01;
1419
+ else
1420
+ scale /= count * 3;
1421
+
1422
+ //scale = 0.25;
1423
+
1424
+ if (mesh.ShowInfo())
1425
+ {
1426
+ gl.glLineWidth(4);
1427
+ for (int s=0; s<Phys.allNodes.size(); s++)
1428
+ {
1429
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1430
+ if (node.mass == 0)
1431
+ continue;
1432
+
1433
+ int i = node.springs==null?-1:node.springs.size();
1434
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1435
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1436
+ //temp.normalize();
1437
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1438
+ gl.glBegin(gl.GL_LINES);
1439
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1440
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1441
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1442
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1443
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1444
+ gl.glEnd();
1445
+ }
1446
+
1447
+ gl.glLineWidth(8);
1448
+ for (int s=0; s<Phys.allNodes.size(); s++)
1449
+ {
1450
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1451
+
1452
+ if (node.springs != null)
1453
+ {
1454
+ for (int i=0; i<node.springs.size(); i+=1)
1455
+ {
1456
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1457
+
1458
+ int c = i+1;
1459
+ // c = node.springs.get(i).nbcopies;
1460
+
1461
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1462
+ gl.glBegin(gl.GL_LINES);
1463
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1464
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1465
+ gl.glEnd();
1466
+ }
1467
+ }
1468
+ }
1469
+
1470
+ gl.glLineWidth(1);
1471
+ }
1472
+
1473
+ gl.glEnable(gl.GL_LIGHTING);
1474
+ }
1475
+
1476
+ /// INTERFACE
1477
+
1478
+ public void StartTriangles()
1479
+ {
1480
+ javax.media.opengl.GL gl = GetGL();
1481
+ gl.glBegin(gl.GL_TRIANGLES);
1482
+ }
1483
+
1484
+ public void EndTriangles()
1485
+ {
1486
+ GetGL().glEnd();
1487
+ }
1488
+
1489
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1490
+ {
1491
+ if (!selectmode)
1492
+ {
1493
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1495
+
1496
+ if (flipV)
1497
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1498
+ else
1499
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1500
+ }
1501
+
1502
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1503
+ }
1504
+
1505
+ float[] colorV = new float[4];
1506
+
1507
+ void SetColor(Object3D obj, Vertex p0)
1508
+ {
1509
+ CameraPane display = this;
1510
+ BoundaryRep bRep = obj.bRep;
1511
+
1512
+ if (RENDERPROGRAM == 0)
1513
+ {
1514
+ float r = 0;
1515
+ if (bRep != null)
1516
+ {
1517
+ if (bRep.stripified)
1518
+ {
1519
+ r = 1;
1520
+ }
1521
+ }
1522
+ float g = 0;
1523
+ if (bRep != null)
1524
+ {
1525
+ if (bRep.trimmed)
1526
+ {
1527
+ g = 1;
1528
+ }
1529
+ }
1530
+ float b = 0;
1531
+ if (obj.support != null && obj.link2master)
1532
+ {
1533
+ b = 1;
1534
+ }
1535
+ display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
1536
+ return;
1537
+ }
1538
+
1539
+ if (display.DrawMode() != CameraPane.SHADOW)
1540
+ return;
1541
+
1542
+ javax.media.opengl.GL gl = display.GetGL();
1543
+// if (true) return;
1544
+// float ao = p.AO;
1545
+//
1546
+// // if (ao == 0 && !bRep.AOdone) // transient problem!
1547
+// // ao = 1;
1548
+//
1549
+// gl.glColor4f(ao, ao, ao, 1);
1550
+
1551
+// CameraPane.selectedpoint.
1552
+// getAverage(cStatic.point1, true);
1553
+ if (CameraPane.pointflow == null) // !random) // live)
1554
+ {
1555
+ return;
1556
+ }
1557
+
1558
+ cStatic.point1.set(0,0,0);
1559
+ LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
1560
+
1561
+ cStatic.point1.sub(p0);
1562
+
1563
+
1564
+// if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
1565
+// {
1566
+// return;
1567
+// }
1568
+
1569
+ //if (true)
1570
+ if (cStatic.point1.dot(cStatic.point1) > 0.000001)
1571
+ {
1572
+ return;
1573
+ }
1574
+
1575
+ if (false) // marked)
1576
+ {
1577
+ // debug rigging weights
1578
+ for (int object = 0; object < p0.vertexlinks.length; object++)
1579
+ {
1580
+ float weight = p0.weights[object] / p0.totalweight;
1581
+
1582
+ // if (weight < 0.1)
1583
+ // {
1584
+ // assert(weight == 0);
1585
+ // continue;
1586
+ // }
1587
+
1588
+ if (p0.vertexlinks[object] == -1)
1589
+ continue;
1590
+
1591
+ Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
1592
+
1593
+ int color = //1 << object; //
1594
+ //p.vertexlinks.length;
1595
+ obj.support.bRep.supports[p0.closestsupport].links[object];
1596
+ colorV[2] += (color & 1) * weight;
1597
+ colorV[1] += ((color & 2) >> 1) * weight;
1598
+ colorV[0] += ((color & 4) >> 2) * weight;
1599
+ }
1600
+ }
1601
+ else
1602
+ {
1603
+ if (obj.drawingstarted)
1604
+ {
1605
+ // find next point
1606
+ if (bRep.GetVertex(0).faceindices == null)
1607
+ {
1608
+ bRep.InitFaceIndices();
1609
+ }
1610
+
1611
+ double ymin = p0.y;
1612
+
1613
+ Vertex newp = p0;
1614
+
1615
+ for (int fii = 0; fii < p0.faceindices.length; fii++)
1616
+ {
1617
+ int fi = p0.faceindices[fii];
1618
+
1619
+ if (fi == -1)
1620
+ break;
1621
+
1622
+ Face f = bRep.GetFace(fi);
1623
+
1624
+ Vertex p = bRep.GetVertex(f.p);
1625
+ Vertex q = bRep.GetVertex(f.q);
1626
+ Vertex r = bRep.GetVertex(f.r);
1627
+
1628
+ int swap = (int)(Math.random()*3);
1629
+
1630
+// for (int s=swap; --s>=0;)
1631
+// {
1632
+// Vertex t = p;
1633
+// p = q;
1634
+// q = r;
1635
+// r = t;
1636
+// }
1637
+ if (ymin > p.y)
1638
+ {
1639
+ ymin = p.y;
1640
+ newp = p;
1641
+// break;
1642
+ }
1643
+ if (ymin > q.y)
1644
+ {
1645
+ ymin = q.y;
1646
+ newp = q;
1647
+// break;
1648
+ }
1649
+ if (ymin > r.y)
1650
+ {
1651
+ ymin = r.y;
1652
+ newp = r;
1653
+// break;
1654
+ }
1655
+ }
1656
+
1657
+ CameraPane.selectedpoint.toParent[3][0] = newp.x;
1658
+ CameraPane.selectedpoint.toParent[3][1] = newp.y;
1659
+ CameraPane.selectedpoint.toParent[3][2] = newp.z;
1660
+
1661
+ obj.drawingstarted = false;
1662
+
1663
+ // return;
1664
+ }
1665
+
1666
+ if (false) // CameraPane.DRAW
1667
+ {
1668
+ p0.AO = colorV[0] = 2;
1669
+ colorV[1] = 2;
1670
+ colorV[2] = 2;
1671
+ }
1672
+
1673
+ CameraPane.pointflow.add(p0);
1674
+ CameraPane.pointflow.Touch();
1675
+ }
1676
+
1677
+// gl.glColor3f(colorV[0], colorV[1], colorV[2]);
1678
+// gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1679
+// gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1680
+ }
1681
+
1682
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
1683
+ {
1684
+ CameraPane display = this;
1685
+ //new Exception().printStackTrace();
1686
+
1687
+ if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
1688
+ {
1689
+ return;
1690
+ }
1691
+
1692
+ javax.media.opengl.GL gl = display.GetGL();
1693
+
1694
+ //Color col = Color.getHSBColor(color,modulation,1);
1695
+ //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
1696
+ if (!material.multiply)
1697
+ {
1698
+ display.color = material.color;
1699
+ display.saturation = material.modulation;
1700
+ }
1701
+ else
1702
+ {
1703
+ display.color *= material.color*2;
1704
+ display.saturation *= material.modulation*2;
1705
+ }
1706
+
1707
+ cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
1708
+
1709
+ float[] colorV = Grafreed.colorV;
1710
+
1711
+ /**/
1712
+ if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
1713
+ {
1714
+ colorV[0] = display.modelParams0[0] * material.diffuse;
1715
+ colorV[1] = display.modelParams0[1] * material.diffuse;
1716
+ colorV[2] = display.modelParams0[2] * material.diffuse;
1717
+ colorV[3] = 1; // material.opacity;
1718
+
1719
+ gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
1720
+ //System.out.println("Opacity = " + opacity);
1721
+
1722
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
1723
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1724
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
1725
+
1726
+ float amb = material.ambient;
1727
+ if (amb < material.cameralight)
1728
+ {
1729
+ amb = material.cameralight;
1730
+ }
1731
+ colorV[0] = display.modelParams0[0] * material.diffuse * amb;
1732
+ colorV[1] = display.modelParams0[1] * material.diffuse * amb;
1733
+ colorV[2] = display.modelParams0[2] * material.diffuse * amb;
1734
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
1735
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1736
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
1737
+
1738
+ /**/
1739
+ colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
1740
+ colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
1741
+ colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
1742
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
1743
+ //color[0] /= 2; color[1] /= 2; color[2] /= 2;
1744
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
1745
+ colorV[0] = 10 / material.shininess; // 1/0.005f;
1746
+ //System.out.println("shininess = " + colorV[0]);
1747
+ if (colorV[0] > 128)
1748
+ {
1749
+ colorV[0] = 128;
1750
+ }
1751
+ gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
1752
+ gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
1753
+ /**/
1754
+ }
1755
+ /**/
1756
+
1757
+ //selected = false;
1758
+ selected = selected && display.flash;
1759
+
1760
+ //display.modelParams0[0] = 0; // pigment.r;
1761
+ //display.modelParams0[1] = 0; // pigment.g;
1762
+ //display.modelParams0[2] = 0; // pigment.b;
1763
+ if (!material.multiply)
1764
+ {
1765
+ display.modelParams0[3] = material.metalness;
1766
+ display.modelParams1[0] = material.diffuse;
1767
+ display.modelParams1[1] = material.specular;
1768
+ display.modelParams1[2] = 1 / material.shininess;
1769
+ display.modelParams1[3] = material.shift;
1770
+ display.modelParams2[0] = material.ambient;
1771
+ display.modelParams2[1] = material.lightarea;
1772
+ //System.out.println("light area = " + lightarea);
1773
+ display.modelParams2[2] = 1 / material.factor; // diffuseness
1774
+ display.modelParams2[3] = material.velvet;
1775
+ display.modelParams3[0] = material.sheen;
1776
+ display.modelParams3[1] = material.subsurface;
1777
+ display.modelParams3[2] = material.bump; // backlit
1778
+ display.modelParams3[3] = material.aniso;
1779
+ display.modelParams4[0] = material.anisoV;
1780
+ display.modelParams4[1] = selected ? 100 : material.cameralight;
1781
+ //System.out.println("selected = " + selected);
1782
+ display.modelParams4[2] = material.diffuseness;
1783
+ display.modelParams4[3] = material.shadow;
1784
+ display.modelParams5[0] = material.texture;
1785
+ display.modelParams5[1] = material.opacity;
1786
+ display.modelParams5[2] = material.fakedepth;
1787
+ display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
1788
+ }
1789
+ else
1790
+ {
1791
+ display.modelParams0[3] *= material.metalness*2;
1792
+ display.modelParams1[0] *= material.diffuse*2;
1793
+ display.modelParams1[1] *= material.specular*2;
1794
+ display.modelParams1[2] *= material.shininess*2;
1795
+ display.modelParams1[3] *= material.shift*2;
1796
+ display.modelParams2[0] *= material.ambient*2;
1797
+ display.modelParams2[1] *= material.lightarea*2;
1798
+ display.modelParams2[2] *= material.factor*2;
1799
+ display.modelParams2[3] *= material.velvet*2;
1800
+ display.modelParams3[0] *= material.sheen*2;
1801
+ display.modelParams3[1] *= material.subsurface*2;
1802
+ display.modelParams3[2] *= material.bump*2;
1803
+ display.modelParams3[3] *= material.aniso*2;
1804
+ display.modelParams4[0] *= material.anisoV*2;
1805
+ display.modelParams4[1] *= material.cameralight*2;
1806
+ //System.out.println("selected = " + selected);
1807
+ display.modelParams4[2] *= material.diffuseness*2;
1808
+ display.modelParams4[3] *= material.shadow*2;
1809
+ display.modelParams5[0] *= material.texture*2;
1810
+ display.modelParams5[1] *= material.opacity*2;
1811
+ display.modelParams5[2] *= material.fakedepth*2;
1812
+ display.modelParams5[3] *= material.shadowbias*2;
1813
+ }
1814
+
1815
+ display.modelParams6[0] = 0;
1816
+ display.modelParams6[1] = 0;
1817
+ display.modelParams6[2] = 0;
1818
+ display.modelParams6[3] = 0;
1819
+
1820
+ display.modelParams7[0] = 0;
1821
+ display.modelParams7[1] = 1000;
1822
+ display.modelParams7[2] = 0;
1823
+ display.modelParams7[3] = 0;
1824
+
1825
+ //display.modelParams6[0] = 100; // criss de bug de bump
1826
+
1827
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
1828
+ if (extparams != null && extparams.length > 0 && extparams[0] != null)
1829
+ {
1830
+ display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
1831
+ display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
1832
+ if (extparams.length > 1)
1833
+ {
1834
+ display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
1835
+ display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
1836
+ if (extparams.length > 2)
1837
+ {
1838
+ display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
1839
+ float x = extparams[2].y / 1000.0f;
1840
+ //if (x == 0)
1841
+ // x = 1f;
1842
+ display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power
1843
+ if (extparams[2].y > 0)
1844
+ {
1845
+ //System.out.println("extparams[1].y = " + extparams[1].y);
1846
+ //System.out.println("extparams[2].y = " + extparams[2].y);
1847
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1848
+ }
1849
+ }
1850
+ }
1851
+ }
1852
+
1853
+ //if (display.modelParams6[2] != 0)
1854
+ /*
1855
+ System.out.println("modelParams0[0] = " + display.modelParams0[0]);
1856
+ System.out.println("modelParams0[1] = " + display.modelParams0[1]);
1857
+ System.out.println("modelParams0[2] = " + display.modelParams0[2]);
1858
+ System.out.println("modelParams0[3] = " + display.modelParams0[3]);
1859
+ System.out.println("modelParams1[0] = " + display.modelParams1[0]);
1860
+ System.out.println("modelParams1[1] = " + display.modelParams1[1]);
1861
+ System.out.println("modelParams1[2] = " + display.modelParams1[2]);
1862
+ System.out.println("modelParams1[3] = " + display.modelParams1[3]);
1863
+ System.out.println("modelParams2[0] = " + display.modelParams2[0]);
1864
+ System.out.println("modelParams2[1] = " + display.modelParams2[1]);
1865
+ System.out.println("modelParams2[2] = " + display.modelParams2[2]);
1866
+ System.out.println("modelParams2[3] = " + display.modelParams2[3]);
1867
+ System.out.println("modelParams3[0] = " + display.modelParams3[0]);
1868
+ System.out.println("modelParams3[1] = " + display.modelParams3[1]);
1869
+ System.out.println("modelParams3[2] = " + display.modelParams3[2]);
1870
+ System.out.println("modelParams3[3] = " + display.modelParams3[3]);
1871
+ System.out.println("modelParams4[0] = " + display.modelParams4[0]);
1872
+ System.out.println("modelParams4[1] = " + display.modelParams4[1]);
1873
+ System.out.println("modelParams4[2] = " + display.modelParams4[2]);
1874
+ System.out.println("modelParams4[3] = " + display.modelParams4[3]);
1875
+ System.out.println("modelParams5[0] = " + display.modelParams5[0]);
1876
+ System.out.println("modelParams5[1] = " + display.modelParams5[1]);
1877
+ System.out.println("modelParams5[2] = " + display.modelParams5[2]);
1878
+ System.out.println("modelParams5[3] = " + display.modelParams5[3]);
1879
+ System.out.println("modelParams6[0] = " + display.modelParams6[0]);
1880
+ System.out.println("modelParams6[1] = " + display.modelParams6[1]);
1881
+ System.out.println("modelParams6[2] = " + display.modelParams6[2]);
1882
+ System.out.println("modelParams6[3] = " + display.modelParams6[3]);
1883
+ System.out.println("modelParams7[0] = " + display.modelParams7[0]);
1884
+ System.out.println("modelParams7[1] = " + display.modelParams7[1]);
1885
+ System.out.println("modelParams7[2] = " + display.modelParams7[2]);
1886
+ System.out.println("modelParams7[3] = " + display.modelParams7[3]);
1887
+ /**/
1888
+ //assert (display.modelParams6[2] == 0);
1889
+
1890
+ //System.out.println("noise power = " + display.modelParams7[0]);
1891
+ //System.out.println("shadowbias = " + shadowbias);
1892
+
1893
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1894
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
1895
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
1896
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
1897
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
1898
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1899
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
1900
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
1901
+
1902
+ int mode = display.FP_SHADER;
1903
+
1904
+ if (material.aniso != material.anisoV || material.aniso > 0.002)
1905
+ {
1906
+ mode |= display.FP_ANISO;
1907
+ }
1908
+
1909
+ display.EnableProgram(mode);
1910
+
1911
+ //System.out.println("opacity power = " + display.modelParams7[1]);
1912
+
1913
+ if (!material.multiply)
1914
+ {
1915
+ if (Globals.drawMode == CameraPane.SHADOW)
1916
+ gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
1917
+ else
1918
+ gl.glDepthMask(material.opacity >= 0.99);
1919
+ }
2081920 }
2091921
2101922 int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!! 0;
....@@ -225,7 +1937,7 @@
2251937 currentGL.glMultMatrixd(model, 0);
2261938 }
2271939
228
- void PushMatrix(double[][] matrix, int count)
1940
+ public void PushMatrix(double[][] matrix, int count) // INTERFACE
2291941 {
2301942 matrixdepth++;
2311943 // GrafreeD.tracein(matrix);
....@@ -254,7 +1966,7 @@
2541966 void PushMatrix(double[][] matrix)
2551967 {
2561968 // GrafreeD.tracein(matrix);
257
- PushMatrix(matrix,1);
1969
+ PushMatrix(matrix, 1);
2581970 }
2591971
2601972 void PushMatrix()
....@@ -270,7 +1982,7 @@
2701982
2711983 double[][] tmpmat = new double[4][4];
2721984
273
- void PopMatrix(double[][] inverse)
1985
+ public void PopMatrix(double[][] inverse) // INTERFACE
2741986 {
2751987 --matrixdepth;
2761988
....@@ -310,7 +2022,7 @@
3102022 PushTextureMatrix(matrix, 1);
3112023 }
3122024
313
- void PushTextureMatrix(double[][] matrix, int count)
2025
+ public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
3142026 {
3152027 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3162028
....@@ -324,7 +2036,7 @@
3242036 currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
3252037 }
3262038
327
- void PopTextureMatrix(double[][] inverse)
2039
+ public void PopTextureMatrix(double[][] inverse) // INTERFACE
3282040 {
3292041 currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
3302042 currentGL.glMatrixMode(GetGL().GL_TEXTURE);
....@@ -340,9 +2052,9 @@
3402052 switch(viewcode)
3412053 {
3422054 case 0: return "main";
343
- case 1: return "one";
344
- case 2: return "two";
345
- case 3: return "three";
2055
+ case 1: return "Red";
2056
+ case 2: return "Green";
2057
+ case 3: return "Blue";
3462058 case 4: return "light";
3472059 }
3482060
....@@ -351,15 +2063,15 @@
3512063
3522064 static int camerachangeframe;
3532065
354
- boolean SetCamera(Camera cam)
2066
+ public boolean SetCamera(Camera cam)
3552067 {
3562068 // may 2014 if (cam == cameras[0] || cam == cameras[1])
3572069 // return false;
3582070
359
- if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
2071
+ if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
3602072 {
3612073 // check for last change
362
- if (framecount < camerachangeframe + 400) // 120 == 1 second
2074
+ if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
3632075 {
3642076 // refuse the camera change
3652077 System.err.println("Camera " + cam + " REFUSED");
....@@ -367,7 +2079,7 @@
3672079 }
3682080 }
3692081
370
- camerachangeframe = framecount;
2082
+ camerachangeframe = Globals.framecount;
3712083
3722084 cam.hAspect = -1; // Read only
3732085
....@@ -398,7 +2110,7 @@
3982110 {
3992111 //System.err.println("Oeil on");
4002112 TRACK = true;
401
-// JUNE 2014 if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
2113
+// JUNE 2014 if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
4022114 // object.editWindow.ScreenFit(trackedobject);
4032115 //pingthread.StepToTarget(true);
4042116 }
....@@ -407,8 +2119,8 @@
4072119 {
4082120 //System.err.println("Oeil on");
4092121 OEIL = true;
410
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
411
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2122
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
2123
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
4122124 //pingthread.StepToTarget(true);
4132125 }
4142126
....@@ -471,39 +2183,12 @@
4712183 {
4722184 frozen ^= true;
4732185 // Weird...
474
- lighttouched = true;
2186
+ Globals.lighttouched = true;
4752187 }
4762188
4772189 void ToggleDL()
4782190 {
4792191 mainDL ^= true;
480
- }
481
-
482
- void ToggleTexture()
483
- {
484
- textureon ^= true;
485
- }
486
-
487
- void ToggleLive()
488
- {
489
- setLIVE(isLIVE() ^ true);
490
-
491
- System.err.println("LIVE = " + isLIVE());
492
-
493
- if (!isLIVE()) // save sound
494
- GrafreeD.savesound = true; // wav.save();
495
- // else
496
- repaint(); // start loop // may 2013
497
- }
498
-
499
- void ToggleSupport()
500
- {
501
- SUPPORT ^= true;
502
- }
503
-
504
- void ToggleAbort()
505
- {
506
- ABORTMODE ^= true;
5072192 }
5082193
5092194 void ToggleFullScreen()
....@@ -513,12 +2198,7 @@
5132198
5142199 void ToggleCrowd()
5152200 {
516
- CROWD ^= true;
517
- }
518
-
519
- void ToggleInertia()
520
- {
521
- INERTIA ^= true;
2201
+ Globals.CROWD ^= true;
5222202 }
5232203
5242204 void ToggleLocal()
....@@ -526,62 +2206,89 @@
5262206 LOCALTRANSFORM ^= true;
5272207 }
5282208
529
- void ToggleFast()
2209
+ public void ToggleTexture()
2210
+ {
2211
+ textureon ^= true;
2212
+ }
2213
+
2214
+ public void ToggleLive()
2215
+ {
2216
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2217
+
2218
+ System.err.println("LIVE = " + Globals.isLIVE());
2219
+
2220
+ if (!Globals.isLIVE()) // save sound
2221
+ Grafreed.savesound = true; // wav.save();
2222
+ // else
2223
+ repaint(); // start loop // may 2013
2224
+ }
2225
+
2226
+ public void ToggleSupport()
2227
+ {
2228
+ SUPPORT ^= true;
2229
+ }
2230
+
2231
+ public void ToggleAbort()
2232
+ {
2233
+ ABORTMODE ^= true;
2234
+ }
2235
+
2236
+ public void ToggleInertia()
2237
+ {
2238
+ INERTIA ^= true;
2239
+ }
2240
+
2241
+ public void ToggleFast()
5302242 {
5312243 FAST ^= true;
5322244 }
5332245
534
- void ToggleSlowPose()
2246
+ public void ToggleSlowPose()
5352247 {
5362248 SLOWPOSE ^= true;
5372249 }
5382250
539
- void ToggleFootContact()
540
- {
541
- FOOTCONTACT ^= true;
542
- }
543
-
544
- void ToggleBoxMode()
2251
+ public void ToggleBoxMode()
5452252 {
5462253 BOXMODE ^= true;
5472254 }
5482255
549
- void ToggleSmoothFocus()
2256
+ public void ToggleZoomBoxMode()
2257
+ {
2258
+ ZOOMBOXMODE ^= true;
2259
+ }
2260
+
2261
+ public void ToggleSmoothFocus()
5502262 {
5512263 SMOOTHFOCUS ^= true;
5522264 }
5532265
554
- void ToggleImageFlip()
2266
+ public void ToggleImageFlip()
5552267 {
5562268 IMAGEFLIP ^= true;
5572269 }
5582270
559
- void ToggleSpeakerMocap()
2271
+ public void ToggleSpeakerMocap()
5602272 {
5612273 SPEAKERMOCAP ^= true;
5622274 }
5632275
564
- void ToggleSpeakerCamera()
2276
+ public void ToggleSpeakerCamera()
5652277 {
5662278 SPEAKERCAMERA ^= true;
5672279 }
5682280
569
- void ToggleSpeakerFocus()
2281
+ public void ToggleSpeakerFocus()
5702282 {
5712283 SPEAKERFOCUS ^= true;
5722284 }
5732285
574
- void ToggleDebug()
575
- {
576
- DEBUG ^= true;
577
- }
578
-
579
- void ToggleFrustum()
2286
+ public void ToggleFrustum()
5802287 {
5812288 FRUSTUM ^= true;
5822289 }
5832290
584
- void ToggleTrack()
2291
+ public void ToggleTrack()
5852292 {
5862293 TRACK ^= true;
5872294 if (TRACK)
....@@ -600,25 +2307,35 @@
6002307 repaint();
6012308 }
6022309
603
- void ToggleTrackOnce()
2310
+ public void ToggleTrackOnce()
6042311 {
6052312 TRACKONCE ^= true;
6062313 }
6072314
608
- void ToggleShadowTrack()
2315
+ public void ToggleShadowTrack()
6092316 {
6102317 SHADOWTRACK ^= true;
6112318 repaint();
6122319 }
6132320
614
- void ToggleOeil()
2321
+ public void ToggleOeil()
6152322 {
6162323 OEIL ^= true;
6172324 }
6182325
619
- void ToggleOeilOnce()
2326
+ public void ToggleOeilOnce()
6202327 {
6212328 OEILONCE ^= true;
2329
+ }
2330
+
2331
+ void ToggleFootContact()
2332
+ {
2333
+ FOOTCONTACT ^= true;
2334
+ }
2335
+
2336
+ void ToggleDebug()
2337
+ {
2338
+ Globals.DEBUG ^= true;
6222339 }
6232340
6242341 void ToggleLookAt()
....@@ -626,9 +2343,9 @@
6262343 LOOKAT ^= true;
6272344 }
6282345
629
- void ToggleRandom()
2346
+ void ToggleSwitch()
6302347 {
631
- RANDOM ^= true;
2348
+ SWITCH ^= true;
6322349 }
6332350
6342351 void ToggleHandles()
....@@ -636,10 +2353,17 @@
6362353 HANDLES ^= true;
6372354 }
6382355
2356
+ Object3D paintFolder;
2357
+
6392358 void TogglePaint()
6402359 {
6412360 PAINTMODE ^= true;
6422361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
6432367 }
6442368
6452369 void SwapCamera(int a, int b)
....@@ -672,34 +2396,6 @@
6722396 //assert (cam.hAspect == 0);
6732397 cam.hAspect = 0;
6742398 lightCamera = cam;
675
- }
676
-
677
- CameraPane(Object3D o, Camera cam, boolean withcontext)
678
- {
679
- super(defaultcaps, null, withcontext?glcontext:null, null);
680
-
681
- //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395 + 2736391 + 1943018 + 1289475 + 1141569 + 1069350 + 911559 + 721229 + 395886 + 377972 + 246700 + 211156 + 173985 + 141133 + 118279 + 112079 + 108523));
682
- glcontext = getContext();
683
-
684
- cameras = new Camera[2];
685
- targetLookAts = new cVector[2];
686
-
687
- SetCamera(cam);
688
-
689
- SetLight(new Camera(new cVector(10, 10, -20)));
690
-
691
- object = o;
692
-
693
- setBackground(Color.white);
694
-
695
- addKeyListener(this);
696
- addMouseListener(this);
697
- addMouseMotionListener(this);
698
- addMouseWheelListener(this);
699
- //System.out.println("addGLEventListener: " + this);
700
- addGLEventListener(this);
701
-
702
-// pingthread.start(); // may 2013
7032399 }
7042400
7052401 private static void ApplyTransform(GL gl, Mat4f xform)
....@@ -759,11 +2455,26 @@
7592455
7602456 GL currentGL;
7612457
762
- GL GetGL()
2458
+ public GL GetGL() // INTERFACE
7632459 {
7642460 return currentGL;
7652461 }
766
-
2462
+
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
7672478 /**/
7682479 class CacheTexture
7692480 {
....@@ -772,28 +2483,31 @@
7722483
7732484 int resolution;
7742485
775
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
7762487 {
777
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
7782490 resolution = res;
7792491 }
7802492 }
7812493 /**/
7822494
7832495 // TEXTURE static Texture texture;
784
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
785
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
786
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
7872501 int pigmentdepth = 0;
7882502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
7892503 int bumpdepth = 0;
7902504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
7912505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
7922506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
793
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
7942508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
7952509
796
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
7972511 {
7982512 TextureData texturedata = null;
7992513
....@@ -803,7 +2517,7 @@
8032517 com.sun.opengl.util.texture.TextureIO.newTextureData(
8042518 getClass().getClassLoader().getResourceAsStream(name),
8052519 true,
806
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
8072521 } catch (java.io.IOException e)
8082522 {
8092523 throw new javax.media.opengl.GLException(e);
....@@ -812,13 +2526,34 @@
8122526 if (bump)
8132527 texturedata = ConvertBump(texturedata, false);
8142528
815
- com.sun.opengl.util.texture.Texture texture =
816
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
8172531
818
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
819
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
8202534
821
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
8222557 }
8232558
8242559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -1891,6 +3626,8 @@
18913626
18923627 System.out.println("LOADING TEXTURE : " + name);
18933628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
18943631 //
18953632 if (false) // compressbit > 0)
18963633 {
....@@ -2595,6 +4332,7 @@
25954332
25964333 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
25974334 {
4335
+ new Exception().printStackTrace();
25984336 System.exit(0);
25994337 com.sun.opengl.util.texture.Texture texture = null;
26004338
....@@ -6271,7 +8009,7 @@
62718009 return null;
62728010 }
62738011
6274
- void ReleaseTextures(cTexture tex)
8012
+ public void ReleaseTextures(cTexture tex) // INTERFACE
62758013 {
62768014 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
62778015 {
....@@ -6288,7 +8026,7 @@
62888026 String pigment = Object3D.GetPigment(tex);
62898027 String bump = Object3D.GetBump(tex);
62908028
6291
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
62928030 {
62938031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
62948032 // System.out.println("; bump = " + bump);
....@@ -6303,13 +8041,71 @@
63038041 pigment = null;
63048042 }
63058043
6306
- ReleaseTexture(bump, true);
6307
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
63088046 }
63098047
6310
- void ReleaseTexture(String tex, boolean bump)
8048
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
63118049 {
6312
- if (// drawMode != 0 || /*tex == null ||*/
8050
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8051
+ {
8052
+ return;
8053
+ }
8054
+
8055
+ if (tex == null)
8056
+ {
8057
+ ReleaseTexture(null, false);
8058
+ return;
8059
+ }
8060
+
8061
+ String pigment = Object3D.GetPigment(tex);
8062
+
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8064
+ {
8065
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8066
+ // System.out.println("; bump = " + bump);
8067
+ }
8068
+
8069
+ if (pigment.equals(""))
8070
+ {
8071
+ pigment = null;
8072
+ }
8073
+
8074
+ ReleaseTexture(tex, false);
8075
+ }
8076
+
8077
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8078
+ {
8079
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8080
+ {
8081
+ return;
8082
+ }
8083
+
8084
+ if (tex == null)
8085
+ {
8086
+ ReleaseTexture(null, true);
8087
+ return;
8088
+ }
8089
+
8090
+ String bump = Object3D.GetBump(tex);
8091
+
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8093
+ {
8094
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8095
+ // System.out.println("; bump = " + bump);
8096
+ }
8097
+
8098
+ if (bump.equals(""))
8099
+ {
8100
+ bump = null;
8101
+ }
8102
+
8103
+ ReleaseTexture(tex, true);
8104
+ }
8105
+
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
8107
+ {
8108
+ if (// DrawMode() != 0 || /*tex == null ||*/
63138109 ambientOcclusion ) // || !textureon)
63148110 {
63158111 return;
....@@ -6318,7 +8114,7 @@
63188114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
63198115
63208116 if (tex != null)
6321
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
63228118
63238119 // //assert( texture != null );
63248120 // if (texture == null)
....@@ -6410,9 +8206,57 @@
64108206 }
64118207 }
64128208
6413
- /*boolean*/ void BindTextures(cTexture tex, int resolution)
8209
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
64148210 {
6415
- if (// drawMode != 0 || /*tex == null ||*/
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
8252
+
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
8255
+ }
8256
+
8257
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8258
+ {
8259
+ if (// DrawMode() != 0 || /*tex == null ||*/
64168260 ambientOcclusion ) // || !textureon)
64178261 {
64188262 return; // false;
....@@ -6421,17 +8265,47 @@
64218265 if (tex == null)
64228266 {
64238267 BindTexture(null,false,resolution);
6424
- BindTexture(null,true,resolution);
64258268 return;
64268269 }
64278270
64288271 String pigment = Object3D.GetPigment(tex);
8272
+
8273
+ usedtextures.add(tex);
8274
+
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8276
+ {
8277
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8278
+ // System.out.println("; bump = " + bump);
8279
+ }
8280
+
8281
+ if (pigment.equals(""))
8282
+ {
8283
+ pigment = null;
8284
+ }
8285
+
8286
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8287
+ BindTexture(tex, false, resolution);
8288
+ }
8289
+
8290
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8291
+ {
8292
+ if (// DrawMode() != 0 || /*tex == null ||*/
8293
+ ambientOcclusion ) // || !textureon)
8294
+ {
8295
+ return; // false;
8296
+ }
8297
+
8298
+ if (tex == null)
8299
+ {
8300
+ BindTexture(null,true,resolution);
8301
+ return;
8302
+ }
8303
+
64298304 String bump = Object3D.GetBump(tex);
64308305
6431
- usedtextures.put(pigment, pigment);
6432
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
64338307
6434
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
64358309 {
64368310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
64378311 // System.out.println("; bump = " + bump);
....@@ -6441,43 +8315,94 @@
64418315 {
64428316 bump = null;
64438317 }
6444
- if (pigment.equals(""))
6445
- {
6446
- pigment = null;
6447
- }
64488318
6449
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6450
- BindTexture(pigment, false, resolution);
64518319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
6452
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
64538321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
6454
-
6455
- return; // true;
64568322 }
64578323
6458
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8324
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8325
+
8326
+ private boolean FileExists(String tex)
64598327 {
6460
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ if (missingTextures.contains(tex))
8329
+ {
8330
+ return false;
8331
+ }
8332
+
8333
+ boolean fileExists = new File(tex).exists();
8334
+
8335
+ if (!fileExists)
8336
+ {
8337
+ // If file exists, the "new File()" is not executed sgain
8338
+ missingTextures.add(tex);
8339
+ }
8340
+
8341
+ return fileExists;
8342
+ }
8343
+
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8345
+ {
8346
+ CacheTexture texturecache = null;
64618347
64628348 if (tex != null)
64638349 {
6464
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
64658352
6466
- String[] split = tex.split("Textures");
6467
- if (split.length > 1)
6468
- texname = "/Users/nbriere/Textures" + split[split.length-1];
6469
- else
6470
- if (!texname.startsWith("/"))
6471
- texname = "/Users/nbriere/Textures/" + texname;
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
8357
+
8358
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8359
+
8360
+// String[] split = tex.split("Textures");
8361
+// if (split.length > 1)
8362
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8363
+// else
8364
+// if (!texname.startsWith("/"))
8365
+// texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
8367
+ {
8368
+ texname = fallbackTextureName;
8369
+ }
64728370
64738371 if (CACHETEXTURE)
6474
- texture = textures.get(texname); // TEXTURE CACHE
6475
-
6476
- TextureData texturedata = null;
6477
-
6478
- if (texture == null || texture.resolution < resolution)
64798372 {
6480
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
64818406 {
64828407 assert(!bump);
64838408 // if (bump)
....@@ -6488,19 +8413,23 @@
64888413 // }
64898414 // else
64908415 // {
6491
- texture = textures.get(tex);
6492
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
64938418 {
6494
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
64958420 }
8421
+ else
8422
+ new Exception().printStackTrace();
64968423 // }
64978424 } else
6498
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
64998426 {
65008427 assert(bump);
6501
- texture = textures.get(tex);
6502
- if (texture == null)
6503
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
65048433 } else
65058434 {
65068435 //if (tex.equals("IMMORTAL"))
....@@ -6508,11 +8437,22 @@
65088437 // texture = GetResourceTexture("default.png");
65098438 //} else
65108439 //{
6511
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
65128441 {
6513
- texture = textures.get(tex);
6514
- if (texture == null)
6515
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
65168456 } else
65178457 {
65188458 if (textureon)
....@@ -6537,7 +8477,7 @@
65378477 }
65388478
65398479 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
6540
- if (!new File(cachename).exists())
8480
+ if (!FileExists(cachename))
65418481 cachename = texname;
65428482 else
65438483 processbump = false; // don't process bump map again
....@@ -6559,7 +8499,7 @@
65598499 }
65608500
65618501 cachename = texname.substring(0, texname.length()-4)+ext+".png";
6562
- if (!new File(cachename).exists())
8502
+ if (!FileExists(cachename))
65638503 cachename = texname;
65648504 else
65658505 processbump = false; // don't process bump map again
....@@ -6568,20 +8508,23 @@
65688508 texturedata = GetFileTexture(cachename, processbump, resolution);
65698509
65708510
6571
- if (texturedata != null)
6572
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8511
+ if (texturedata == null)
8512
+ throw new Exception();
8513
+
8514
+ texturecache = new CacheTexture(texturedata,resolution);
65738515 //texture = GetTexture(tex, bump);
65748516 }
8517
+ }
65758518 }
65768519 //}
65778520 }
65788521
6579
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
65808523 {
65818524 //return false;
65828525
65838526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
6584
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
65858528 {
65868529 // String ext = "_highres";
65878530 // if (REDUCETEXTURE)
....@@ -6598,52 +8541,17 @@
65988541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
65998542 if (!cachefile.exists())
66008543 {
6601
- // cache to disk
6602
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
6603
- //buffers[0].
6604
-
6605
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
6606
- int[] pixels = new int[bytebuf.capacity()/3];
6607
-
6608
- // squared size heuristic...
6609
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
66108545 {
6611
- for (int i=pixels.length; --i>=0;)
6612
- {
6613
- int i3 = i*3;
6614
- pixels[i] = 0xFF;
6615
- pixels[i] <<= 8;
6616
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
6617
- pixels[i] <<= 8;
6618
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
6619
- pixels[i] <<= 8;
6620
- pixels[i] |= bytebuf.get(i3) & 0xFF;
6621
- }
6622
-
6623
- /*
6624
- int r=0,g=0,b=0,a=0;
6625
- for (int i=0; i<width; i++)
6626
- for (int j=0; j<height; j++)
6627
- {
6628
- int index = j*width+i;
6629
- int p = pixels[index];
6630
- a = ((p>>24) & 0xFF);
6631
- r = ((p>>16) & 0xFF);
6632
- g = ((p>>8) & 0xFF);
6633
- b = (p & 0xFF);
6634
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
6635
- }
6636
- /**/
6637
- int width = (int)Math.sqrt(pixels.length); // squared
6638
- int height = width;
6639
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
6640
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
66418548 ImageWriter writer = null;
66428549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
66438550 if (iter.hasNext()) {
66448551 writer = (ImageWriter)iter.next();
66458552 }
6646
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
66478555 try
66488556 {
66498557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -6660,18 +8568,20 @@
66608568 }
66618569 }
66628570 }
6663
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
66648574 //System.out.println("Texture = " + tex);
6665
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
66668576 {
6667
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
66688578 thetex.texture.disable();
66698579 thetex.texture.dispose();
6670
- textures.remove(texname);
8580
+ textures.remove(tex);
66718581 }
66728582
6673
- texture.texturedata = texturedata;
6674
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
66758585
66768586 // newtex = true;
66778587 }
....@@ -6687,10 +8597,44 @@
66878597 }
66888598 }
66898599
6690
- return texture;
8600
+ return texturecache;
66918601 }
66928602
6693
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
66948638 {
66958639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
66968640
....@@ -6708,21 +8652,21 @@
67088652 return texture!=null?texture.texture:null;
67098653 }
67108654
6711
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
67128656 {
67138657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
67148658
67158659 return texture!=null?texture.texturedata:null;
67168660 }
67178661
6718
- boolean BindTexture(String tex, boolean bump, int resolution)
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
67198663 {
67208664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
67218665 {
67228666 return false;
67238667 }
67248668
6725
- boolean newtex = false;
8669
+ //boolean newtex = false;
67268670
67278671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
67288672
....@@ -6754,9 +8698,75 @@
67548698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
67558699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
67568700
6757
- return newtex;
8701
+ return true; // Warning: not used.
67588702 }
67598703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
67608770 ShadowBuffer shadowPBuf;
67618771 AntialiasBuffer antialiasPBuf;
67628772 int MAXSTACK;
....@@ -6773,10 +8783,12 @@
67738783
67748784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
67758785 MAXSTACK = temp[0];
6776
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
67778788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
67788789 MAXSTACK = temp[0];
6779
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
67808792
67818793 // Use debug pipeline
67828794 //drawable.setGL(new DebugGL(gl)); //
....@@ -6784,7 +8796,8 @@
67848796 gl = drawable.getGL(); //
67858797
67868798 GL gl3 = getGL();
6787
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
67888801
67898802
67908803 //float pos[] = { 100, 100, 100, 0 };
....@@ -6949,7 +8962,7 @@
69498962
69508963 if (cubemap == null)
69518964 {
6952
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
69538966 }
69548967
69558968 //cubemap.enable();
....@@ -7225,6 +9238,8 @@
72259238
72269239 void LoadEnvy(int which)
72279240 {
9241
+ assert(false);
9242
+
72289243 String name;
72299244 String ext;
72309245
....@@ -7236,37 +9251,58 @@
72369251 cubemap = null;
72379252 return;
72389253 case 1:
7239
- name = "cubemaps/box_";
7240
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
72419256 reverseUP = false;
72429257 break;
72439258 case 2:
7244
- name = "cubemaps/uffizi_";
7245
- ext = "png";
7246
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
72479263 case 3:
7248
- name = "cubemaps/CloudyHills_";
7249
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
72509266 reverseUP = false;
72519267 break;
72529268 case 4:
7253
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
72549270 ext = "png";
72559271 reverseUP = false;
72569272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
72579298 default:
7258
- name = "cubemaps/rgb_";
7259
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
72609302 break;
72619303 }
7262
-
7263
- try
7264
- {
7265
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
7266
- } catch (IOException e)
7267
- {
7268
- throw new RuntimeException(e);
7269
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
72709306 }
72719307
72729308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -7298,8 +9334,12 @@
72989334 static double[] model = new double[16];
72999335 double[] camera2light = new double[16];
73009336 double[] light2camera = new double[16];
7301
- int newenvy = -1;
7302
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
73039343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
73049344 //float[] light0 = { 0,0,0 };
73059345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -7312,9 +9352,9 @@
73129352 static boolean occlusionInitialized = false;
73139353 boolean selection = false;
73149354 boolean pointselection = false;
7315
- /*static*/ boolean lighttouched = true;
9355
+ ///*static*/ boolean lighttouched = true;
73169356 boolean deselect;
7317
- boolean ambientOcclusion = false;
9357
+ private boolean ambientOcclusion = false;
73189358 static boolean flash = false;
73199359 /*static*/ boolean wait = false;
73209360 boolean displaydone = false; // after repaint() calls
....@@ -7444,6 +9484,8 @@
74449484 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
74459485 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
74469486 double scale = lightCamera.SCALE / lightCamera.Distance();
9487
+// PATCH FILLE AUX JEANS
9488
+ //scale *= lightCamera.shaper_fovy / 25;
74479489 gl.glScaled(2 * scale, 2 * scale, -scale);
74489490 gl.glTranslated(0, 0, lightCamera.DECAL);
74499491
....@@ -7590,18 +9632,40 @@
75909632 jy8[3] = 0.5f;
75919633 }
75929634
7593
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9635
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
75949636 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
75959637 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
75969638 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
75979639
9640
+ void ResetOptions()
9641
+ {
9642
+ options1[0] = 100;
9643
+ options1[1] = 0.025f;
9644
+ options1[2] = 0.01f;
9645
+ options1[3] = 0;
9646
+ options1[4] = 0;
9647
+
9648
+ options2[0] = 0;
9649
+ options2[1] = 0.75f;
9650
+ options2[2] = 0;
9651
+ options2[3] = 0;
9652
+
9653
+ options3[0] = 1;
9654
+ options3[1] = 1;
9655
+ options3[2] = 1;
9656
+ options3[3] = 0;
9657
+
9658
+ options4[0] = 1;
9659
+ options4[1] = 0;
9660
+ options4[2] = 1;
9661
+ options4[3] = 0;
9662
+ }
9663
+
75989664 static int imagecount = 0; // movie generation
75999665
76009666 static int jitter = 0;
76019667
76029668 boolean restartframe = false;
7603
-
7604
- static int framecount = 0; // general-purpose global count
76059669
76069670 void displayAntiAliased(javax.media.opengl.GL gl)
76079671 {
....@@ -7633,7 +9697,7 @@
76339697 gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
76349698 for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
76359699 {
7636
- framecount++;
9700
+ Globals.framecount++;
76379701
76389702 if (CameraPane.tickcount > 0)
76399703 CameraPane.tickcount--;
....@@ -7671,7 +9735,7 @@
76719735
76729736 gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
76739737 */
7674
- lighttouched = true;
9738
+ Globals.lighttouched = true;
76759739 //System.err.println(" shadowbuffer: " + jitter);
76769740 shadowbuffer.display();
76779741
....@@ -7692,8 +9756,8 @@
76929756 assert (parentcam != renderCamera);
76939757
76949758 if (renderCamera != lightCamera)
7695
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7696
- LA.matConcat(parentcam.toParent, matrix, matrix);
9759
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
76979761
76989762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
76999763
....@@ -7708,8 +9772,8 @@
77089772 LA.matCopy(renderCamera.fromScreen, matrix);
77099773
77109774 if (renderCamera != lightCamera)
7711
- for (int count = parentcam.GetTransformCount(); --count>=0;)
7712
- LA.matConcat(matrix, parentcam.fromParent, matrix);
9775
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
77139777
77149778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
77159779
....@@ -7755,10 +9819,12 @@
77559819 rati = 1 / rati;
77569820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
77579821 }
7758
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
77599825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
77609826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
7761
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
77629828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
77639829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
77649830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -7781,7 +9847,7 @@
77819847 //gl.glFlush();
77829848 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
77839849
7784
- if (ANIMATION && ABORTED)
9850
+ if (Globals.ANIMATION && ABORTED)
77859851 {
77869852 System.err.println(" ABORTED FRAME");
77879853 break;
....@@ -7811,7 +9877,7 @@
78119877 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
78129878
78139879 // save image
7814
- if (ANIMATION && !ABORTED)
9880
+ if (Globals.ANIMATION && !ABORTED)
78159881 {
78169882 VPwidth = viewport[2];
78179883 VPheight = viewport[3];
....@@ -7922,11 +9988,11 @@
79229988
79239989 // imagecount++;
79249990
7925
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9991
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
79269992
79279993 if (!BOXMODE)
79289994 {
7929
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9995
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
79309996 }
79319997
79329998 if (!BOXMODE)
....@@ -7964,7 +10030,7 @@
796410030 ABORTED = false;
796510031 }
796610032 else
7967
- GrafreeD.wav.cursor += 735 * ACSIZE;
10033
+ Grafreed.wav.cursor += 735 * ACSIZE;
796810034
796910035 if (false)
797010036 {
....@@ -8618,32 +10684,34 @@
861810684 }
861910685 }
862010686
8621
- boolean IsFrozen()
8622
- {
8623
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
8624
-
8625
- return !selectmode && cameracount == 0; // != 0;
8626
- }
8627
-
862810687 boolean niceon = false;
862910688 javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
863010689 boolean currentlydrawing = false;
863110690 static boolean init = false;
863210691
863310692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
863410696
863510697 public void display(GLAutoDrawable drawable)
863610698 {
8637
- if (GrafreeD.savesound && GrafreeD.hassound)
10699
+ if (patchMaterial.patchMaterial)
863810700 {
8639
- GrafreeD.wav.save();
8640
- GrafreeD.savesound = false;
8641
- GrafreeD.hassound = false;
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(0);
10703
+ }
10704
+
10705
+ if (Grafreed.savesound && Grafreed.hassound)
10706
+ {
10707
+ Grafreed.wav.save();
10708
+ Grafreed.savesound = false;
10709
+ Grafreed.hassound = false;
864210710 }
864310711 // if (DEBUG_SELECTION)
864410712 // {
8645
-// if (drawMode != SELECTION)
8646
-// drawMode = SELECTION;
10713
+// if (DrawMode() != SELECTION)
10714
+// DrawMode() = SELECTION;
864710715 // }
864810716
864910717 if (!isRenderer)
....@@ -8699,9 +10767,9 @@
869910767
870010768 //ANTIALIAS = 0;
870110769
8702
- if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
10770
+ if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
870310771 {
8704
- if (niceon || isLIVE())
10772
+ if (niceon || Globals.isLIVE())
870510773 {
870610774 //if(active == 0)
870710775 // antialiaser = null;
....@@ -8714,6 +10782,7 @@
871410782 ANTIALIAS = 0;
871510783 //System.out.println("RESTART");
871610784 AAtimer.restart();
10785
+ Globals.TIMERRUNNING = true;
871710786 }
871810787 }
871910788 }
....@@ -8726,7 +10795,7 @@
872610795 assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
872710796 */
872810797
8729
- if (drawMode == DEFAULT)
10798
+ if (DrawMode() == DEFAULT)
873010799 {
873110800 currentlydrawing = true;
873210801 }
....@@ -8757,18 +10826,18 @@
875710826
875810827 // if(Applet3D.clipboard != null)
875910828 // System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
8760
-//drawMode = SELECTION;
10829
+//DrawMode() = SELECTION;
876110830 indexcount = 0;
876210831
8763
- if (drawMode == OCCLUSION)
10832
+ if (DrawMode() == OCCLUSION)
876410833 {
8765
- drawMode = DEFAULT;
10834
+ Globals.drawMode = DEFAULT; // WARNING
876610835 ambientOcclusion = true;
876710836 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
876810837 Object3D theobject = object;
876910838 Object3D theparent = object.parent;
877010839 object.parent = null;
8771
- object = (Object3D)GrafreeD.clone(object);
10840
+ object = (Object3D)Grafreed.clone(object);
877210841 object.Stripify();
877310842 if (theobject.selection == null || theobject.selection.Size() == 0)
877410843 theobject.PreprocessOcclusion(this);
....@@ -8781,26 +10850,27 @@
878110850 ambientOcclusion = false;
878210851 }
878310852
8784
- if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
10853
+ if (//Globals.lighttouched &&
10854
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
878510855 {
878610856 //if (RENDERSHADOW) // ?
878710857 if (!IsFrozen())
878810858 {
878910859 // dec 2012
8790
- if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
10860
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
879110861 {
8792
- framecount++;
10862
+ Globals.framecount++;
879310863 shadowbuffer.display();
879410864 }
879510865 }
8796
- lighttouched = false; // ??
10866
+ Globals.lighttouched = false; // ??
879710867 //drawing = true;
879810868 //lighttouched = true;
879910869 }
880010870
880110871 if (wait)
880210872 {
8803
- Sleep(500);
10873
+ Sleep(200); // blocks everything
880410874
880510875 wait = false;
880610876 }
....@@ -8814,9 +10884,9 @@
881410884 //eyeCamera.shaper_fovy = 1;
881510885 }
881610886
8817
- if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
10887
+ if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
881810888 {
8819
- //System.out.println("drawMode = " + drawMode);
10889
+ //System.out.println("DrawMode() = " + DrawMode());
882010890 vertexMode |= VP_PASS;
882110891 //vertexMode |= VP_PROJECTION;
882210892 if (!ambientOcclusion)
....@@ -8876,7 +10946,7 @@
887610946 Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
887710947 //Camera lightcam = new Camera(light0);
887810948
8879
- if (drawMode == SHADOW)
10949
+ if (DrawMode() == SHADOW)
888010950 {
888110951 /*
888210952 gl.glMatrixMode(GL.GL_MODELVIEW);
....@@ -8914,8 +10984,8 @@
891410984
891510985 // if (parentcam != renderCamera) // not a light
891610986 if (cam != lightCamera)
8917
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8918
- LA.matConcat(parentcam.toParent, matrix, matrix);
10987
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10988
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
891910989
892010990 for (int j = 0; j < 4; j++)
892110991 {
....@@ -8929,8 +10999,8 @@
892910999
893011000 // if (parentcam != renderCamera) // not a light
893111001 if (cam != lightCamera)
8932
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8933
- LA.matConcat(matrix, parentcam.fromParent, matrix);
11002
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11003
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
893411004
893511005 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
893611006
....@@ -8966,7 +11036,7 @@
896611036 gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
896711037 } else
896811038 {
8969
- if (drawMode != DEFAULT)
11039
+ if (DrawMode() != DEFAULT)
897011040 {
897111041 gl.glClearColor(1, 1, 1, 0);
897211042 } // 1);
....@@ -9016,13 +11086,43 @@
901611086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
901711087 }
901811088
9019
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
902011097 {
9021
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
902211104 }
9023
-
9024
- newenvy = -1;
9025
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
902611126 ratio = ((double) getWidth()) / getHeight();
902711127 //System.out.println("ratio = " + ratio);
902811128
....@@ -9031,14 +11131,14 @@
903111131
903211132 fast &= !ambientOcclusion;
903311133
9034
- if (drawMode == DEFAULT)
11134
+ if (DrawMode() == DEFAULT)
903511135 {
903611136 //gl.glEnable(gl.GL_ALPHA_TEST);
903711137 //gl.glActiveTexture(GL.GL_TEXTURE0);
903811138
903911139 if (!IsFrozen() && !ambientOcclusion)
904011140 {
9041
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
904211142 }
904311143
904411144 //if (selection_view == -1)
....@@ -9092,6 +11192,8 @@
909211192 //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
909311193 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
909411194 double scale = lightCamera.SCALE / lightCamera.Distance();
11195
+// PATCH FILLE AUX JEANS
11196
+ //scale *= lightCamera.shaper_fovy / 25;
909511197 gl.glScaled(2 * scale, 2 * scale, -scale);
909611198 gl.glTranslated(0, 0, lightCamera.DECAL);
909711199
....@@ -9187,7 +11289,16 @@
918711289 // Bump noise
918811290 gl.glActiveTexture(GL.GL_TEXTURE6);
918911291 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9190
- BindTexture(NOISE_TEXTURE, false, 2);
11292
+
11293
+ try
11294
+ {
11295
+ BindTexture(NOISE_TEXTURE, false, 2);
11296
+ }
11297
+ catch (Exception e)
11298
+ {
11299
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11300
+ }
11301
+
919111302
919211303 gl.glActiveTexture(GL.GL_TEXTURE0);
919311304 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9210,9 +11321,9 @@
921011321
921111322 gl.glMatrixMode(GL.GL_MODELVIEW);
921211323
9213
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9214
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9215
-//gl.glEnable(gl.GL_MULTISAMPLE);
11324
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11325
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11326
+gl.glEnable(gl.GL_MULTISAMPLE);
921611327 } else
921711328 {
921811329 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9223,14 +11334,16 @@
922311334 //System.out.println("BLENDING ON");
922411335 gl.glEnable(GL.GL_BLEND);
922511336 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9226
-
11337
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
922711338 gl.glMatrixMode(gl.GL_PROJECTION);
922811339 gl.glLoadIdentity();
922911340
9230
- if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
11341
+ if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
923111342 {
923211343 //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
923311344 double scale = lightCamera.SCALE / lightCamera.Distance();
11345
+// PATCH FILLE AUX JEANS
11346
+ //scale *= lightCamera.shaper_fovy / 25;
923411347 gl.glScaled(2 * scale, 2 * scale, -scale);
923511348 gl.glTranslated(0, 0, lightCamera.DECAL);
923611349 //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
....@@ -9283,7 +11396,7 @@
928311396 //gl.glPushMatrix();
928411397 gl.glLoadIdentity();
928511398
9286
- if (!ambientOcclusion) // drawMode != OCCLUSION)
11399
+ if (!ambientOcclusion) // DrawMode() != OCCLUSION)
928711400 {
928811401 //LA.xformPos(light0, lightCamera.fromScreen, light);
928911402 LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
....@@ -9310,8 +11423,8 @@
931011423 System.err.println("parentcam != renderCamera");
931111424
931211425 // if (cam != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11426
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
931511428 }
931611429
931711430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -9332,8 +11445,8 @@
933211445 if (true) // TODO
933311446 {
933411447 if (cam != lightCamera)
9335
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9336
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11448
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11449
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
933711450 }
933811451
933911452 LA.xformPos(light0, cam.toScreen, light0);
....@@ -9370,7 +11483,7 @@
937011483 }
937111484
937211485 /**/
9373
- if (true) // drawMode == SELECTION) // != DEFAULT)
11486
+ if (true) // DrawMode() == SELECTION) // != DEFAULT)
937411487 gl.glDisable(gl.GL_LIGHTING);
937511488 else
937611489 gl.glEnable(gl.GL_LIGHTING);
....@@ -9388,7 +11501,7 @@
938811501
938911502 lightslot = 64;
939011503
9391
- if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
11504
+ if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
939211505 {
939311506 DrawLights(object);
939411507 }
....@@ -9399,7 +11512,7 @@
939911512 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
940011513 //System.out.println("fragmentMode = " + fragmentMode);
940111514
9402
- if (drawMode == DEFAULT || drawMode == SELECTION || DEBUG_SELECTION)
11515
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
940311516 {
940411517 /*
940511518 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -9432,7 +11545,7 @@
943211545 }
943311546 }
943411547
9435
- if (drawMode == DEFAULT)
11548
+ if (DrawMode() == DEFAULT)
943611549 {
943711550 if (WIREFRAME && !ambientOcclusion)
943811551 {
....@@ -9450,7 +11563,7 @@
945011563 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
945111564 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
945211565
9453
- if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
11566
+ if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
945411567 {
945511568 if (vertexMode != 0) // && !fast)
945611569 {
....@@ -9470,7 +11583,7 @@
947011583 }
947111584 }
947211585
9473
- if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
11586
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
947411587 {
947511588 //gl.glDepthFunc(GL.GL_LEQUAL);
947611589 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -9478,27 +11591,24 @@
947811591
947911592 boolean texon = textureon;
948011593
9481
- if (RENDERPROGRAM > 0)
9482
- {
9483
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
9484
- textureon = false;
9485
- }
11594
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11595
+ textureon = false;
11596
+
948611597 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
948711598 //System.out.println("ALLO");
948811599 gl.glColorMask(false, false, false, false);
948911600 DrawObject(gl);
9490
- if (RENDERPROGRAM > 0)
9491
- {
9492
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
9493
- textureon = texon;
9494
- }
11601
+
11602
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11603
+ textureon = texon;
11604
+
949511605 gl.glColorMask(true, true, true, true);
949611606
949711607 gl.glDepthFunc(GL.GL_EQUAL);
9498
- //gl.glDepthMask(false);
11608
+ gl.glDepthMask(false);
949911609 }
950011610
9501
- if (false) // drawMode == SHADOW)
11611
+ if (false) // DrawMode() == SHADOW)
950211612 {
950311613 //SetColumnMajorData(cameraInverseTransform, view_1);
950411614 //System.out.println("light = " + cameraInverseTransform);
....@@ -9512,16 +11622,16 @@
951211622 //System.out.println("object = " + object);
951311623 if (!frozen && !imageLocked)
951411624 {
9515
- if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
11625
+ if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
951611626 {
951711627 displayAntiAliased(gl);
951811628 } else
951911629 {
952011630 programcount = 0;
9521
- int keepmode = drawMode;
11631
+ int keepmode = DrawMode();
952211632 // if (DEBUG_SELECTION)
952311633 // {
9524
-// drawMode = SELECTION;
11634
+// DrawMode() = SELECTION;
952511635 // }
952611636 // for point selection
952711637 // gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
....@@ -9531,10 +11641,10 @@
953111641 DrawObject(gl);
953211642
953311643 // jan 2013 System.err.println("RESET ABORT (display)");
9534
- // if (drawMode == DEFAULT)
11644
+ // if (DrawMode() == DEFAULT)
953511645 // ABORTED = false;
953611646 fullreset = false;
9537
- drawMode = keepmode;
11647
+ Globals.drawMode = keepmode; // WARNING
953811648 //System.out.println("PROGRAM SWITCH " + programcount);
953911649 }
954011650 }
....@@ -9542,11 +11652,11 @@
954211652 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
954311653 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
954411654
9545
- if (drawMode == DEFAULT)
11655
+ if (DrawMode() == DEFAULT)
954611656 {
954711657 ReleaseTexture(NOISE_TEXTURE, false);
954811658 }
9549
- //if (drawMode == DEFAULT)
11659
+ //if (DrawMode() == DEFAULT)
955011660 {
955111661
955211662 gl.glActiveTexture(GL.GL_TEXTURE1);
....@@ -9558,7 +11668,7 @@
955811668 //else
955911669 //gl.glDisable(gl.GL_TEXTURE_2D);
956011670 //gl.glPopMatrix();
9561
- if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
11671
+ if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
956211672 {
956311673 //new Exception().printStackTrace();
956411674 //System.out.println("Draw image " + width + ", " + height);
....@@ -9600,7 +11710,7 @@
960011710 //gl.glFlush();
960111711 }
960211712
9603
- if (flash && drawMode == DEFAULT)
11713
+ if (flash && DrawMode() == DEFAULT)
960411714 {
960511715 flash = false;
960611716 wait = true;
....@@ -9608,9 +11718,9 @@
960811718 }
960911719
961011720 //drawing = false;
9611
- //if(drawMode == DEFAULT)
11721
+ //if(DrawMode() == DEFAULT)
961211722 // niceon = false;
9613
- if (drawMode == DEFAULT)
11723
+ if (DrawMode() == DEFAULT)
961411724 {
961511725 currentlydrawing = false;
961611726 }
....@@ -9630,7 +11740,7 @@
963011740 repaint();
963111741 }
963211742
9633
- if (isLIVE() && drawMode == DEFAULT) // may 2013
11743
+ if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
963411744 repaint();
963511745
963611746 displaydone = true;
....@@ -9649,8 +11759,14 @@
964911759 {
965011760 renderpass++;
965111761 // System.out.println("Draw object... ");
11762
+ STEP = 1;
965211763 if (FAST) // in case there is no script
9653
- STEP = 16;
11764
+ STEP = 8;
11765
+
11766
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11767
+ {
11768
+ STEP *= 4;
11769
+ }
965411770
965511771 //object.FullInvariants();
965611772
....@@ -9664,23 +11780,44 @@
966411780 e.printStackTrace();
966511781 }
966611782
9667
- if (GrafreeD.RENDERME > 0)
9668
- GrafreeD.RENDERME--; // mechante magouille
11783
+ if (Grafreed.RENDERME > 0)
11784
+ Grafreed.RENDERME--; // mechante magouille
966911785
9670
- ONESTEP = false;
11786
+ Globals.ONESTEP = false;
967111787 }
967211788
967311789 static boolean zoomonce = false;
967411790
11791
+ static void CreateSelectedPoint()
11792
+ {
11793
+ if (selectedpoint == null)
11794
+ {
11795
+ debugpointG = new Sphere();
11796
+ debugpointP = new Sphere();
11797
+ debugpointC = new Sphere();
11798
+ debugpointR = new Sphere();
11799
+
11800
+ selectedpoint = new Superellipsoid();
11801
+
11802
+ for (int i=0; i<8; i++)
11803
+ {
11804
+ debugpoints[i] = new Sphere();
11805
+ }
11806
+ }
11807
+ }
11808
+
967511809 void DrawObject(GL gl, boolean draw)
967611810 {
11811
+ // To clear camera values
11812
+ ResetOptions();
11813
+
967711814 //System.out.println("DRAW OBJECT " + mouseDown);
9678
-// drawMode = SELECTION;
11815
+// DrawMode() = SELECTION;
967911816 //GL gl = getGL();
968011817 if ((TRACK || SHADOWTRACK) || zoomonce)
968111818 {
9682
- if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
9683
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11819
+ if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
11820
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
968411821 pingthread.StepToTarget(true); // true);
968511822 // zoomonce = false;
968611823 }
....@@ -9700,9 +11837,9 @@
970011837 callist = gl.glGenLists(1);
970111838 }
970211839
9703
- boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
11840
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
970411841
9705
- boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
11842
+ boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
970611843
970711844 if (!mainDL || !active || touched)
970811845 {
....@@ -9729,13 +11866,20 @@
972911866 PushMatrix(ClickInfo.matbuffer);
973011867 }
973111868
9732
- if (drawMode == 0)
11869
+ if (DrawMode() == 0)
973311870 {
973411871 // System.out.println("CLEAR +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
973511872
973611873 usedtextures.clear();
973711874
9738
- BindTextures(DEFAULT_TEXTURES, 2);
11875
+ try
11876
+ {
11877
+ BindTextures(DEFAULT_TEXTURES, 2);
11878
+ }
11879
+ catch (Exception e)
11880
+ {
11881
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11882
+ }
973911883 }
974011884 //System.out.println("--> " + stackdepth);
974111885 // GrafreeD.traceon();
....@@ -9743,10 +11887,11 @@
974311887 // DRAW
974411888 object.draw(this, /*(Composite)*/ object, false, false);
974511889
9746
- if (drawMode == DEFAULT)
11890
+ if (DrawMode() == DEFAULT)
974711891 {
9748
- if (DEBUG)
11892
+ if (Globals.DEBUG)
974911893 {
11894
+ CreateSelectedPoint();
975011895 float radius = 0.05f;
975111896 if (selectedpoint.radius != radius)
975211897 {
....@@ -9754,40 +11899,40 @@
975411899 selectedpoint.radius = radius;
975511900 selectedpoint.recalculate();
975611901 selectedpoint.material = new cMaterial();
9757
- selectedpoint.material.color = 0.25f;
11902
+ selectedpoint.material.color = 0.15f; // Yellow
975811903 selectedpoint.material.modulation = 0.75f;
975911904
9760
- debugpoint.radius = radius;
9761
- debugpoint.recalculate();
9762
- debugpoint.material = new cMaterial();
9763
- debugpoint.material.color = 0.25f;
9764
- debugpoint.material.modulation = 0.75f;
11905
+ debugpointG.radius = radius;
11906
+ debugpointG.recalculate();
11907
+ debugpointG.material = new cMaterial();
11908
+ debugpointG.material.color = 0.25f; // Green
11909
+ debugpointG.material.modulation = 0.75f;
976511910
9766
- debugpoint2.radius = radius;
9767
- debugpoint2.recalculate();
9768
- debugpoint2.material = new cMaterial();
9769
- debugpoint2.material.color = 0.75f;
9770
- debugpoint2.material.modulation = 0.75f;
11911
+ debugpointP.radius = radius;
11912
+ debugpointP.recalculate();
11913
+ debugpointP.material = new cMaterial();
11914
+ debugpointP.material.color = 0.75f; // Purple
11915
+ debugpointP.material.modulation = 0.75f;
977111916
9772
- debugpoint3.radius = radius;
9773
- debugpoint3.recalculate();
9774
- debugpoint3.material = new cMaterial();
9775
- debugpoint3.material.color = 0.5f;
9776
- debugpoint3.material.modulation = 0.75f;
11917
+ debugpointC.radius = radius;
11918
+ debugpointC.recalculate();
11919
+ debugpointC.material = new cMaterial();
11920
+ debugpointC.material.color = 0.5f; // Cyan
11921
+ debugpointC.material.modulation = 0.75f;
977711922
9778
- debugpoint4.radius = radius;
9779
- debugpoint4.recalculate();
9780
- debugpoint4.material = new cMaterial();
9781
- debugpoint4.material.color = 0f;
9782
- debugpoint4.material.modulation = 0.75f;
11923
+ debugpointR.radius = radius;
11924
+ debugpointR.recalculate();
11925
+ debugpointR.material = new cMaterial();
11926
+ debugpointR.material.color = 0f; // Red
11927
+ debugpointR.material.modulation = 0.75f;
978311928
978411929 InitPoints(radius);
978511930 }
978611931 selectedpoint.draw(this, /*(Composite)*/ null, false, false);
9787
- debugpoint.draw(this, /*(Composite)*/ null, false,false);
9788
- debugpoint2.draw(this, /*(Composite)*/ null, false,false);
9789
- debugpoint3.draw(this, /*(Composite)*/ null, false,false);
9790
- debugpoint4.draw(this, /*(Composite)*/ null, false,false);
11932
+ debugpointG.draw(this, /*(Composite)*/ null, false,false);
11933
+ debugpointP.draw(this, /*(Composite)*/ null, false,false);
11934
+ debugpointC.draw(this, /*(Composite)*/ null, false,false);
11935
+ debugpointR.draw(this, /*(Composite)*/ null, false,false);
979111936 // DrawPoints(this);
979211937 }
979311938
....@@ -9795,42 +11940,63 @@
979511940 }
979611941 // GrafreeD.traceoff();
979711942 //System.out.println(stackdepth);
9798
- if (drawMode == 0)
11943
+ if (DrawMode() == 0)
979911944 {
980011945 ReleaseTextures(DEFAULT_TEXTURES);
980111946
980211947 if (CLEANCACHE)
9803
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11948
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
980411949 {
9805
- String tex = e.nextElement();
11950
+ cTexture tex = e.nextElement();
980611951
980711952 // System.out.println("Texture --------- " + tex);
980811953
9809
- if (tex.equals("WHITE_NOISE"))
11954
+ if (tex.equals("WHITE_NOISE:"))
981011955 continue;
981111956
9812
- if (!usedtextures.containsKey(tex))
11957
+ if (!usedtextures.contains(tex))
981311958 {
11959
+ CacheTexture gettex = texturepigment.get(tex);
981411960 // System.out.println("DISPOSE +++++++++++++++ " + tex);
9815
- textures.get(tex).texture.dispose();
9816
- textures.remove(tex);
11961
+ if (gettex != null)
11962
+ {
11963
+ gettex.texture.dispose();
11964
+ texturepigment.remove(tex);
11965
+ }
11966
+
11967
+ gettex = texturebump.get(tex);
11968
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11969
+ if (gettex != null)
11970
+ {
11971
+ gettex.texture.dispose();
11972
+ texturebump.remove(tex);
11973
+ }
981711974 }
981811975 }
981911976 }
982011977
982111978 checker = null;
982211979
9823
- if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
11980
+ if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
982411981 FindChecker(object);
982511982
9826
- if (checker != null && drawMode == DEFAULT)
11983
+ if (checker != null && DrawMode() == DEFAULT)
982711984 {
9828
- // BindTexture(IMMORTAL_TEXTURE);
11985
+ //BindTexture(IMMORTAL_TEXTURE);
11986
+ try
11987
+ {
11988
+ BindTextures(checker.GetTextures(), checker.texres);
11989
+ }
11990
+ catch (Exception e)
11991
+ {
11992
+ System.err.println("FAILED: " + checker.GetTextures());
11993
+ }
982911994 // NEAREST
983011995 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
983111996 DrawChecker(gl);
983211997 //checker.Draw(this, null, false);
983311998 // ReleaseTexture(IMMORTAL_TEXTURE);
11999
+ ReleaseTextures(checker.GetTextures());
983412000 }
983512001
983612002 if (object.parent != null)
....@@ -9843,7 +12009,7 @@
984312009 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
984412010 //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
984512011
9846
- if (DISPLAYTEXT && drawMode == DEFAULT)
12012
+ if (DISPLAYTEXT && DrawMode() == DEFAULT)
984712013 {
984812014 // Draw it once, then use the raster
984912015 Balloon(gl, balloon.createGraphics());
....@@ -9899,14 +12065,14 @@
989912065 int[] xs = new int[3];
990012066 int[] ys = new int[3];
990112067
9902
- void DrawString(Object3D obj) // String string)
12068
+ public void DrawString(Object3D obj) // String string) // INTERFACE
990312069 {
9904
- if (!DISPLAYTEXT || drawMode != DEFAULT)
12070
+ if (!DISPLAYTEXT || DrawMode() != DEFAULT)
990512071 {
990612072 return;
990712073 }
990812074
9909
- String string = obj.GetToolTip();
12075
+ String string = obj.toString(); //.GetToolTip();
991012076
991112077 GL gl = GetGL();
991212078
....@@ -10223,8 +12389,8 @@
1022312389 //obj.TransformToWorld(light, light);
1022412390 for (int i = tp.size(); --i >= 0;)
1022512391 {
10226
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10227
- LA.xformPos(light, tp.get(i).toParent, light);
12392
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12393
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1022812394 }
1022912395
1023012396
....@@ -10241,8 +12407,8 @@
1024112407 parentcam = cameras[0];
1024212408 }
1024312409
10244
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10245
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12410
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12411
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1024612412
1024712413 LA.xformPos(light, renderCamera.toScreen, light);
1024812414
....@@ -10332,8 +12498,76 @@
1033212498
1033312499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1033412500
10335
- String program =
12501
+ String programmin =
12502
+ // Min shader
1033612503 "!!ARBfp1.0\n" +
12504
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12505
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12506
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12507
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12508
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12509
+ "PARAM light2cam0 = program.env[10];" +
12510
+ "PARAM light2cam1 = program.env[11];" +
12511
+ "PARAM light2cam2 = program.env[12];" +
12512
+ "TEMP temp;" +
12513
+ "TEMP light;" +
12514
+ "TEMP ndotl;" +
12515
+ "TEMP normal;" +
12516
+ "TEMP depth;" +
12517
+ "TEMP eye;" +
12518
+ "TEMP pos;" +
12519
+
12520
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12521
+ Normalize("normal") +
12522
+ "MOV light, state.light[0].position;" +
12523
+ "DP3 ndotl.x, light, normal;" +
12524
+
12525
+ // shadow
12526
+ "MOV pos, fragment.texcoord[1];" +
12527
+ "MOV temp, pos;" +
12528
+ ShadowTextureFetch("depth", "temp", "1") +
12529
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12530
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12531
+
12532
+ // No shadow when out of frustum
12533
+ //"SGE temp.y, depth.z, zero123.y;" +
12534
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12535
+
12536
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12537
+
12538
+ // Backlit
12539
+ "MOV pos.w, zero123.y;" +
12540
+ "DP4 eye.x, pos, light2cam0;" +
12541
+ "DP4 eye.y, pos, light2cam1;" +
12542
+ "DP4 eye.z, pos, light2cam2;" +
12543
+ Normalize("eye") +
12544
+
12545
+ "DP3 ndotl.y, -eye, normal;" +
12546
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12547
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12548
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12549
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12550
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12551
+
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12554
+
12555
+ // Pigment
12556
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12557
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12558
+ "MUL temp, temp, ndotl.x;" +
12559
+
12560
+ "MUL temp, temp, zero123.z;" +
12561
+
12562
+ //"MUL temp, temp, ndotl.y;" +
12563
+
12564
+ "MOV temp.w, zero123.y;" + // reset alpha
12565
+ "MOV result.color, temp;" +
12566
+ "END";
12567
+
12568
+ String programmax =
12569
+ "!!ARBfp1.0\n" +
12570
+
1033712571 //"OPTION ARB_fragment_program_shadow;" +
1033812572 "PARAM light2cam0 = program.env[10];" +
1033912573 "PARAM light2cam1 = program.env[11];" +
....@@ -10388,6 +12622,7 @@
1038812622 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
1038912623 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
1039012624 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
12625
+ "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
1039112626 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
1039212627 "PARAM c256 = { 256, 256, 256, 1.0 };" +
1039312628 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
....@@ -10447,8 +12682,7 @@
1044712682 "TEMP shininess;" +
1044812683 "\n" +
1044912684 "MOV texSamp, one;" +
10450
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
10451
-
12685
+
1045212686 "MOV mapgrid.x, one2048th.x;" +
1045312687 "MOV temp, fragment.texcoord[1];" +
1045412688 /*
....@@ -10469,20 +12703,20 @@
1046912703 "MUL temp, floor, mapgrid.x;" +
1047012704 //"TEX depth0, temp, texture[1], 2D;" +
1047112705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10472
- TextureFetch("depth0", "temp", "1") +
12706
+ ShadowTextureFetch("depth0", "temp", "1") +
1047312707 "") +
1047412708 "ADD temp.x, temp.x, mapgrid.x;" +
1047512709 //"TEX depth1, temp, texture[1], 2D;" +
1047612710 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10477
- TextureFetch("depth1", "temp", "1") +
12711
+ ShadowTextureFetch("depth1", "temp", "1") +
1047812712 "") +
1047912713 "ADD temp.y, temp.y, mapgrid.x;" +
1048012714 //"TEX depth2, temp, texture[1], 2D;" +
10481
- TextureFetch("depth2", "temp", "1") +
12715
+ ShadowTextureFetch("depth2", "temp", "1") +
1048212716 "SUB temp.x, temp.x, mapgrid.x;" +
1048312717 //"TEX depth3, temp, texture[1], 2D;" +
1048412718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
10485
- TextureFetch("depth3", "temp", "1") +
12719
+ ShadowTextureFetch("depth3", "temp", "1") +
1048612720 "") +
1048712721 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1048812722 //"MOV params, material;" +
....@@ -10853,10 +13087,10 @@
1085313087 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1085413088 "") +
1085513089
10856
- // display shadow only (bump == 0)
13090
+ // display shadow only (fakedepth == 0)
1085713091 "SUB temp.x, half.x, shadow.x;" +
10858
- "MOV temp.y, -params6.x;" +
10859
- "SLT temp.z, temp.y, zero.x;" +
13092
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13093
+ "SLT temp.z, temp.y, -c256i.x;" +
1086013094 "SUB temp.y, one.x, temp.z;" +
1086113095 "MUL temp.x, temp.x, temp.y;" +
1086213096 "KIL temp.x;" +
....@@ -10985,8 +13219,10 @@
1098513219 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1098613220
1098713221 "SUB temp.x, one.x, ndotl.x;" +
10988
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
10989
- "ADD temp.y, one.y, options2.y;" + // sursurface
13222
+ // Tuning for default skin
13223
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13224
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13225
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1099013226 "MUL temp.x, temp.x, temp.y;" +
1099113227
1099213228 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11185,8 +13421,19 @@
1118513421 //once = true;
1118613422 }
1118713423
11188
- System.out.print("Program #" + mode + "; length = " + program.length());
11189
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13424
+ String program = programmax;
13425
+
13426
+ if (Globals.MINSHADER)
13427
+ {
13428
+ program = programmin;
13429
+ }
13430
+
13431
+ if (Globals.DEBUG)
13432
+ {
13433
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13434
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13435
+ }
13436
+
1119013437 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1119113438
1119213439 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11233,7 +13480,8 @@
1123313480 "\n" +
1123413481 "END\n";
1123513482
11236
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13483
+ if (Globals.DEBUG)
13484
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1123713485 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1123813486
1123913487 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11278,30 +13526,32 @@
1127813526 return out;
1127913527 }
1128013528
11281
- String TextureFetch(String dest, String src, String unit)
13529
+ // Also does frustum culling
13530
+ String ShadowTextureFetch(String dest, String src, String unit)
1128213531 {
1128313532 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1128413533 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1128513534 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13535
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13536
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1128613537 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11287
- "SLT " + src + ".z, " + src + ".x, one.x;" +
11288
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
11289
- "SLT " + src + ".z, " + src + ".y, one.x;" +
11290
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13538
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13539
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1129113540 //"SWZ buffer, temp, w,w,w,w;";
11292
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13541
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1129313542 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1129413543 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1129513544 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
11296
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13545
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1129713546
11298
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
11299
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13547
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13548
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1130013549 }
1130113550
1130213551 String Shadow(String depth, String shadow)
1130313552 {
1130413553 return "MAX temp.x, ndotl.x, one64th.x;" +
13554
+ "MIN temp.x, temp.x, ninetenth.x;" +
1130513555 /**/
1130613556 // Sine
1130713557 "MUL temp.y, temp.x, temp.x;" +
....@@ -11317,12 +13567,16 @@
1131713567
1131813568 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1131913569 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13570
+
13571
+ // Compare fragment depth in light space with shadowmap.
1132013572 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1132113573 "SGE temp.y, temp.x, zero.x;" +
11322
- "SUB " + shadow + ".y, one.x, temp.y;" +
13574
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13575
+
13576
+ // Reverse comparison
1132313577 "SUB temp.x, one.x, temp.x;" +
1132413578 "MUL " + shadow + ".x, temp.x, temp.y;" +
11325
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13579
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1132613580 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1132713581
1132813582 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -11336,6 +13590,10 @@
1133613590 // No shadow for backface
1133713591 "DP3 temp.x, normal, lightd;" +
1133813592 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13593
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13594
+
13595
+ // No shadow when out of frustum
13596
+ "SGE temp.x, " + depth + ".z, one.z;" +
1133913597 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1134013598 "";
1134113599 }
....@@ -11482,7 +13740,8 @@
1148213740 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1148313741 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1148413742 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
11485
- Object3D.cVector2[] vector2buffer;
13743
+
13744
+ //Object3D.cVector2[] vector2buffer;
1148613745
1148713746 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1148813747 // OUT : diff, spec
....@@ -11498,9 +13757,10 @@
1149813757 "DP3 " + dest + ".z," + "normals," + "eye;" +
1149913758 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1150013759 //"MOV " + dest + ".w," + "normal.z;" +
11501
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
11502
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
11503
- //"MOV " + dest + ".z," + "params2.w;" +
13760
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13761
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13762
+
13763
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1150413764 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1150513765 "RCP " + dest + ".w," + dest + ".w;" +
1150613766 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -11894,7 +14154,7 @@
1189414154 public void mousePressed(MouseEvent e)
1189514155 {
1189614156 //System.out.println("mousePressed: " + e);
11897
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14157
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1189814158 }
1189914159
1190014160 static long prevtime = 0;
....@@ -11921,14 +14181,16 @@
1192114181
1192214182 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1192314183
14184
+ if (BUTTONLESSWHEEL)
1192414185 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1192514186 {
1192614187 return;
1192714188 }
1192814189
14190
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1192914191
1193014192 // TIMER
11931
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
14193
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1193214194 {
1193314195 keepboxmode = BOXMODE;
1193414196 keepsupport = SUPPORT;
....@@ -11968,8 +14230,8 @@
1196814230 // mode |= META;
1196914231 //}
1197014232
11971
- SetMouseMode(WHEEL | e.getModifiersEx());
11972
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14233
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14234
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1197314235 anchorX = ax;
1197414236 anchorY = ay;
1197514237 prevX = px;
....@@ -12003,6 +14265,7 @@
1200314265 else
1200414266 if (evt.getSource() == AAtimer)
1200514267 {
14268
+ Globals.TIMERRUNNING = false;
1200614269 if (mouseDown)
1200714270 {
1200814271 //new Exception().printStackTrace();
....@@ -12028,6 +14291,10 @@
1202814291 // LIVE = waslive;
1202914292 // wasliveok = true;
1203014293 // waslive = false;
14294
+
14295
+ // May 2019 Forget it:
14296
+ if (true)
14297
+ return;
1203114298
1203214299 // source == timer
1203314300 if (mouseDown)
....@@ -12057,8 +14324,8 @@
1205714324 // ObjEditor.tweenManager.update(1f / 60f);
1205814325
1205914326 // fev 2014???
12060
- if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
12061
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14327
+ if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
14328
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1206214329 pingthread.StepToTarget(true); // true);
1206314330 }
1206414331 // if (!LIVE)
....@@ -12067,12 +14334,13 @@
1206714334
1206814335 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1206914336
12070
- void clickStart(int x, int y, int modifiers)
14337
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1207114338 {
1207214339 if (!wasliveok)
1207314340 return;
1207414341
1207514342 AAtimer.restart(); //
14343
+ Globals.TIMERRUNNING = true;
1207614344
1207714345 // waslive = LIVE;
1207814346 // LIVE = false;
....@@ -12084,7 +14352,7 @@
1208414352 // touched = true; // main DL
1208514353 if (isRenderer)
1208614354 {
12087
- SetMouseMode(modifiers);
14355
+ SetMouseMode(modifiers, modifiersex);
1208814356 }
1208914357
1209014358 selectX = anchorX = x;
....@@ -12097,7 +14365,7 @@
1209714365 clicked = true;
1209814366 hold = false;
1209914367
12100
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14368
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1210114369 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1210214370 {
1210314371 // System.out.println("RESTART II " + modifiers);
....@@ -12122,14 +14390,15 @@
1212214390 drag = false;
1212314391 //System.out.println("Mouse DOWN");
1212414392 editObj = false;
12125
- ClickInfo info = new ClickInfo();
12126
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12127
- info.pane = this;
12128
- info.camera = renderCamera;
12129
- info.x = x;
12130
- info.y = y;
12131
- info.modifiers = modifiers;
12132
- editObj = object.doEditClick(info, 0);
14393
+ //ClickInfo info = new ClickInfo();
14394
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14395
+ object.clickInfo.pane = this;
14396
+ object.clickInfo.camera = renderCamera;
14397
+ object.clickInfo.x = x;
14398
+ object.clickInfo.y = y;
14399
+ object.clickInfo.modifiers = modifiersex;
14400
+ editObj = object.doEditClick(//info,
14401
+ 0);
1213314402 if (!editObj)
1213414403 {
1213514404 hasMarquee = true;
....@@ -12145,11 +14414,14 @@
1214514414
1214614415 public void mouseDragged(MouseEvent e)
1214714416 {
14417
+ Globals.MOUSEDRAGGED = true;
14418
+
14419
+ //System.out.println("mouseDragged: " + e);
1214814420 if (isRenderer)
1214914421 movingcamera = true;
14422
+
1215014423 //if (drawing)
1215114424 //return;
12152
- //System.out.println("mouseDragged: " + e);
1215314425 if ((e.getModifiersEx() & CTRL) != 0
1215414426 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1215514427 {
....@@ -12157,7 +14429,7 @@
1215714429 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1215814430 }
1215914431 else
12160
- drag(e.getX(), e.getY(), e.getModifiersEx());
14432
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1216114433
1216214434 //try { Thread.sleep(1); } catch (Exception ex) {}
1216314435 }
....@@ -12169,6 +14441,11 @@
1216914441 cVector tmp = new cVector();
1217014442 cVector tmp2 = new cVector();
1217114443 boolean isMoving;
14444
+
14445
+ public cVector TargetLookAt()
14446
+ {
14447
+ return targetLookAt;
14448
+ }
1217214449
1217314450 class PingThread extends Thread
1217414451 {
....@@ -12308,7 +14585,7 @@
1230814585 //System.out.println("---------------- ---------- Paint " + tmp.length2());
1230914586 if (lightMode)
1231014587 {
12311
- lighttouched = true;
14588
+ Globals.lighttouched = true;
1231214589 }
1231314590
1231414591 if (OEILONCE && OEIL)
....@@ -12325,6 +14602,7 @@
1232514602
1232614603 public void run()
1232714604 {
14605
+ new Exception().printStackTrace();
1232814606 System.exit(0);
1232914607 for (;;)
1233014608 {
....@@ -12366,7 +14644,7 @@
1236614644 mouseDown = false;
1236714645 if (lightMode)
1236814646 {
12369
- lighttouched = true;
14647
+ Globals.lighttouched = true;
1237014648 }
1237114649 repaint();
1237214650 alreadypainted = true;
....@@ -12374,7 +14652,7 @@
1237414652 isMoving = false;
1237514653 } //??
1237614654
12377
- if (isLIVE() && !alreadypainted)
14655
+ if (Globals.isLIVE() && !alreadypainted)
1237814656 {
1237914657 // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
1238014658 repaint();
....@@ -12386,9 +14664,9 @@
1238614664 {
1238714665 if (lightMode)
1238814666 {
12389
- lighttouched = true;
14667
+ Globals.lighttouched = true;
1239014668 }
12391
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14669
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1239214670 }
1239314671 //else
1239414672 }
....@@ -12402,12 +14680,18 @@
1240214680 void GoDown(int mod)
1240314681 {
1240414682 MODIFIERS |= COMMAND;
12405
- /*
14683
+ boolean isVR = (mouseMode&VR)!=0;
14684
+ /**/
1240614685 if((mod&SHIFT) == SHIFT)
12407
- manipCamera.RotatePosition(0, -speed);
14686
+ {
14687
+ if (isVR)
14688
+ manipCamera.RotateInterest(0, -speed);
14689
+ else
14690
+ manipCamera.RotatePosition(0, -speed);
14691
+ }
1240814692 else
12409
- manipCamera.BackForth(0, -speed*delta, getWidth());
12410
- */
14693
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14694
+ /**/
1241114695 if ((mod & SHIFT) == SHIFT)
1241214696 {
1241314697 mouseMode = mouseMode; // VR??
....@@ -12416,6 +14700,8 @@
1241614700 mouseMode |= BACKFORTH;
1241714701 }
1241814702
14703
+ targetLookAt.set(manipCamera.lookAt);
14704
+
1241914705 //prevX = X = anchorX;
1242014706 prevY = Y = anchorY - (int) (renderCamera.Distance());
1242114707 }
....@@ -12423,12 +14709,19 @@
1242314709 void GoUp(int mod)
1242414710 {
1242514711 MODIFIERS |= COMMAND;
12426
- /*
14712
+ /**/
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+
1242714715 if((mod&SHIFT) == SHIFT)
12428
- manipCamera.RotatePosition(0, speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, speed);
14721
+ }
1242914722 else
12430
- manipCamera.BackForth(0, speed*delta, getWidth());
12431
- */
14723
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14724
+ /**/
1243214725 if ((mod & SHIFT) == SHIFT)
1243314726 {
1243414727 mouseMode = mouseMode;
....@@ -12437,6 +14730,8 @@
1243714730 mouseMode |= BACKFORTH;
1243814731 }
1243914732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1244014735 //prevX = X = anchorX;
1244114736 prevY = Y = anchorY + (int) (renderCamera.Distance());
1244214737 }
....@@ -12444,12 +14739,17 @@
1244414739 void GoLeft(int mod)
1244514740 {
1244614741 MODIFIERS |= COMMAND;
12447
- /*
14742
+ /**/
1244814743 if((mod&SHIFT) == SHIFT)
12449
- manipCamera.RotatePosition(speed, 0);
14744
+ manipCamera.Translate(speed*delta, 0, getWidth());
1245014745 else
12451
- manipCamera.Translate(speed*delta, 0, getWidth());
12452
- */
14746
+ {
14747
+ if ((mouseMode&VR)!=0)
14748
+ manipCamera.RotateInterest(-speed, 0);
14749
+ else
14750
+ manipCamera.RotatePosition(speed, 0);
14751
+ }
14752
+ /**/
1245314753 if ((mod & SHIFT) == SHIFT)
1245414754 {
1245514755 mouseMode = mouseMode;
....@@ -12458,6 +14758,8 @@
1245814758 mouseMode |= ROTATE;
1245914759 } // TRANSLATE;
1246014760
14761
+ targetLookAt.set(manipCamera.lookAt);
14762
+
1246114763 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1246214764 prevY = Y = anchorY;
1246314765 }
....@@ -12465,12 +14767,18 @@
1246514767 void GoRight(int mod)
1246614768 {
1246714769 MODIFIERS |= COMMAND;
12468
- /*
14770
+ /**/
1246914771 if((mod&SHIFT) == SHIFT)
12470
- manipCamera.RotatePosition(-speed, 0);
14772
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1247114773 else
12472
- manipCamera.Translate(-speed*delta, 0, getWidth());
12473
- */
14774
+ {
14775
+ if ((mouseMode&VR)!=0)
14776
+ manipCamera.RotateInterest(speed, 0);
14777
+ else
14778
+ manipCamera.RotatePosition(-speed, 0);
14779
+ }
14780
+
14781
+ /**/
1247414782 if ((mod & SHIFT) == SHIFT)
1247514783 {
1247614784 mouseMode = mouseMode;
....@@ -12479,6 +14787,8 @@
1247914787 mouseMode |= ROTATE;
1248014788 } // TRANSLATE;
1248114789
14790
+ targetLookAt.set(manipCamera.lookAt);
14791
+
1248214792 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1248314793 prevY = Y = anchorY;
1248414794 }
....@@ -12488,7 +14798,7 @@
1248814798 int X, Y;
1248914799 boolean SX, SY;
1249014800
12491
- void drag(int x, int y, int modifiers)
14801
+ void drag(int x, int y, int modifiers, int modifiersex)
1249214802 {
1249314803 if (IsFrozen())
1249414804 {
....@@ -12497,17 +14807,17 @@
1249714807
1249814808 drag = true; // NEW
1249914809
12500
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14810
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1250114811
1250214812 X = x;
1250314813 Y = y;
1250414814 // floating state for animation
12505
- MODIFIERS = modifiers;
12506
- modifiers &= ~1024;
14815
+ MODIFIERS = modifiersex;
14816
+ modifiersex &= ~1024;
1250714817 if (false) // modifiers != 0)
1250814818 {
1250914819 //new Exception().printStackTrace();
12510
- System.out.println("mouseDragged: " + modifiers);
14820
+ System.out.println("mouseDragged: " + modifiersex);
1251114821 System.out.println("SHIFT = " + SHIFT);
1251214822 System.out.println("CONTROL = " + COMMAND);
1251314823 System.out.println("META = " + META);
....@@ -12520,14 +14830,16 @@
1252014830 if (editObj)
1252114831 {
1252214832 drag = true;
12523
- ClickInfo info = new ClickInfo();
12524
- info.bounds.setBounds(0, 0,
14833
+ //ClickInfo info = new ClickInfo();
14834
+ object.clickInfo.bounds.setBounds(0, 0,
1252514835 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12526
- info.pane = this;
12527
- info.camera = renderCamera;
12528
- info.x = x;
12529
- info.y = y;
12530
- object.editWindow.copy.doEditDrag(info);
14836
+ object.clickInfo.pane = this;
14837
+ object.clickInfo.camera = renderCamera;
14838
+ object.clickInfo.x = x;
14839
+ object.clickInfo.y = y;
14840
+ object //.GetWindow().copy
14841
+ .doEditDrag(//info,
14842
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1253114843 } else
1253214844 {
1253314845 if (x < startX)
....@@ -12629,6 +14941,7 @@
1262914941 {
1263014942 manipCamera.Translate(dx, dy, getWidth());
1263114943 }
14944
+ else
1263214945 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
1263314946 {
1263414947 manipCamera.RotateInterest(dx, dy);
....@@ -12639,7 +14952,7 @@
1263914952
1264014953 if (manipCamera == lightCamera)
1264114954 {
12642
- lighttouched = true;
14955
+ Globals.lighttouched = true;
1264314956 }
1264414957 /*
1264514958 switch (mode)
....@@ -12675,23 +14988,27 @@
1267514988 }
1267614989 }
1267714990
14991
+// ClickInfo clickInfo = new ClickInfo();
14992
+
1267814993 public void mouseMoved(MouseEvent e)
1267914994 {
1268014995 //System.out.println("mouseMoved: " + e);
12681
-
1268214996 if (isRenderer)
1268314997 return;
1268414998
12685
- ClickInfo ci = new ClickInfo();
12686
- ci.x = e.getX();
12687
- ci.y = e.getY();
12688
- ci.modifiers = e.getModifiersEx();
12689
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12690
- ci.pane = this;
12691
- ci.camera = renderCamera;
14999
+ // Mouse cursor feedback
15000
+ object.clickInfo.x = e.getX();
15001
+ object.clickInfo.y = e.getY();
15002
+ object.clickInfo.modifiers = e.getModifiersEx();
15003
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15004
+ object.clickInfo.pane = this;
15005
+ object.clickInfo.camera = renderCamera;
1269215006 if (!isRenderer)
1269315007 {
12694
- if (object.editWindow.copy.doEditClick(ci, 0))
15008
+ //ObjEditor editWindow = object.editWindow;
15009
+ //Object3D copy = editWindow.copy;
15010
+ if (object.doEditClick(//clickInfo,
15011
+ 0))
1269515012 {
1269615013 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1269715014 } else
....@@ -12703,7 +15020,11 @@
1270315020
1270415021 public void mouseReleased(MouseEvent e)
1270515022 {
15023
+ Globals.MOUSEDRAGGED = false;
15024
+
1270615025 movingcamera = false;
15026
+ X = 0; // getBounds().width/2;
15027
+ Y = 0; // getBounds().height/2;
1270715028 //System.out.println("mouseReleased: " + e);
1270815029 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1270915030 }
....@@ -12726,9 +15047,9 @@
1272615047 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1272715048 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1272815049
12729
- if (control || command || IsFrozen())
15050
+// No delay if (control || command || IsFrozen())
1273015051 timeout = true;
12731
- else
15052
+// ?? May 2019 else
1273215053 // timer.setDelay((modifiers & 128) != 0?0:350);
1273315054 mouseDown = false;
1273415055 if (!control && !command) // june 2013
....@@ -12838,7 +15159,7 @@
1283815159 System.out.println("keyReleased: " + e);
1283915160 }
1284015161
12841
- void SetMouseMode(int modifiers)
15162
+ void SetMouseMode(int modifiers, int modifiersex)
1284215163 {
1284315164 //System.out.println("SetMouseMode = " + modifiers);
1284415165 //modifiers &= ~1024;
....@@ -12850,24 +15171,27 @@
1285015171 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1285115172 // return;
1285215173 //System.out.println("SetMode = " + modifiers);
12853
- if ((modifiers & WHEEL) == WHEEL)
15174
+ if ((modifiersex & WHEEL) == WHEEL)
1285415175 {
1285515176 mouseMode |= ZOOM;
1285615177 }
12857
- if ((modifiers & META) == META)
15178
+
15179
+ boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
15180
+ if (capsLocked) // || (modifiers & META) == META)
1285815181 {
1285915182 mouseMode |= VR; // BACKFORTH;
1286015183 }
12861
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
12862
- {
12863
- mouseMode |= SELECT; // BACKFORTH;
12864
- }
12865
- if ((modifiers & COMMAND) == COMMAND)
15184
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1286615185 {
1286715186 mouseMode |= SELECT;
1286815187 }
12869
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15188
+ if ((modifiersex & COMMAND) == COMMAND)
1287015189 {
15190
+ mouseMode |= SELECT;
15191
+ }
15192
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
15193
+ {
15194
+ mouseMode &= ~VR;
1287115195 mouseMode |= TRANSLATE;
1287215196 }
1287315197 // if ((modifiers & SHIFT_META) == SHIFT_META)
....@@ -12894,10 +15218,10 @@
1289415218
1289515219 if (isRenderer) //
1289615220 {
12897
- SetMouseMode(modifiers);
15221
+ SetMouseMode(0, modifiers);
1289815222 }
1289915223
12900
- theRenderer.keyPressed(key);
15224
+ Globals.theRenderer.keyPressed(key);
1290115225 }
1290215226
1290315227 int kompactbit = 4; // power bit
....@@ -12909,7 +15233,7 @@
1290915233 float SATPOW = 1; // 2; // 0.5f;
1291015234 float BRIPOW = 1; // 0.5f; // 0.5f;
1291115235
12912
- void keyPressed(int key)
15236
+ public void keyPressed(int key)
1291315237 {
1291415238 if (key >= '0' && key <= '5')
1291515239 clampbit = (key-'0');
....@@ -12956,7 +15280,8 @@
1295615280 // break;
1295715281 case 'T':
1295815282 CACHETEXTURE ^= true;
12959
- textures.clear();
15283
+ texturepigment.clear();
15284
+ texturebump.clear();
1296015285 // repaint();
1296115286 break;
1296215287 case 'Y':
....@@ -12966,8 +15291,8 @@
1296615291 case 'K':
1296715292 KOMPACTTEXTURE ^= true;
1296815293 //textures.clear();
12969
- break;
12970
- case 'P': // Texture Projection macros
15294
+ // break;
15295
+ //case 'P': // Texture Projection macros
1297115296 // SAVETEXTURE ^= true;
1297215297 macromode = true;
1297315298 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -13024,7 +15349,7 @@
1302415349 case 'B':
1302515350 BRISMOOTH ^= true;
1302615351 SHADOWCULLFACE ^= true;
13027
- lighttouched = true;
15352
+ Globals.lighttouched = true;
1302815353 repaint();
1302915354 break;
1303015355 case 'b':
....@@ -13041,7 +15366,9 @@
1304115366 case 'E' : COMPACT ^= true;
1304215367 repaint();
1304315368 break;
13044
- case 'W' : DEBUGHSB ^= true;
15369
+ case 'W' : // Wide Window (fullscreen)
15370
+ //DEBUGHSB ^= true;
15371
+ ObjEditor.theFrame.ToggleFullScreen();
1304515372 repaint();
1304615373 break;
1304715374 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13066,8 +15393,8 @@
1306615393 RevertCamera();
1306715394 repaint();
1306815395 break;
13069
- case 'L':
1307015396 case 'l':
15397
+ //case 'L':
1307115398 if (lightMode)
1307215399 {
1307315400 lightMode = false;
....@@ -13086,7 +15413,7 @@
1308615413 targetLookAt.set(manipCamera.lookAt);
1308715414 repaint();
1308815415 break;
13089
- case 'p':
15416
+ case 'P': // p':
1309015417 // c'est quoi ca au juste? spherical ^= true;
1309115418 Skinshader ^= true; programInitialized = false;
1309215419 repaint();
....@@ -13124,27 +15451,31 @@
1312415451 repaint();
1312515452 break;
1312615453 case 'O':
13127
- drawMode = OCCLUSION;
15454
+ Globals.drawMode = OCCLUSION; // WARNING
1312815455 repaint();
1312915456 break;
1313015457 case 'o':
1313115458 OCCLUSION_CULLING ^= true;
1313215459 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1313315460 break;
13134
- case '0': envyoff ^= true; repaint(); break;
15461
+ //case '0': envyoff ^= true; repaint(); break;
1313515462 case '1':
1313615463 case '2':
1313715464 case '3':
1313815465 case '4':
1313915466 case '5':
13140
- newenvy = Character.getNumericValue(key);
13141
- repaint();
13142
- break;
1314315467 case '6':
1314415468 case '7':
1314515469 case '8':
1314615470 case '9':
13147
- BGcolor = (key - '6')/3.f;
15471
+ if (true) // envyoff)
15472
+ {
15473
+ BGcolor = (key - '1')/8.f;
15474
+ }
15475
+ else
15476
+ {
15477
+ //newenvy = Character.getNumericValue(key);
15478
+ }
1314815479 repaint();
1314915480 break;
1315015481 case '!':
....@@ -13210,12 +15541,12 @@
1321015541 case '_':
1321115542 kompactbit = 5;
1321215543 break;
13213
- case '+':
13214
- kompactbit = 6;
13215
- break;
15544
+// case '+':
15545
+// kompactbit = 6;
15546
+// break;
1321615547 case ' ':
1321715548 lightMode ^= true;
13218
- lighttouched = true;
15549
+ Globals.lighttouched = true;
1321915550 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
1322015551 targetLookAt.set(manipCamera.lookAt);
1322115552 repaint();
....@@ -13224,14 +15555,15 @@
1322415555 case ESC:
1322515556 RENDERPROGRAM += 1;
1322615557 RENDERPROGRAM %= 3;
15558
+
1322715559 repaint();
1322815560 break;
1322915561 case 'Z':
13230
- RESIZETEXTURE ^= true;
13231
- break;
15562
+ //RESIZETEXTURE ^= true;
15563
+ //break;
1323215564 case 'z':
13233
- RENDERSHADOW ^= true;
13234
- lighttouched = true;
15565
+ Globals.RENDERSHADOW ^= true;
15566
+ Globals.lighttouched = true;
1323515567 repaint();
1323615568 break;
1323715569 //case UP:
....@@ -13257,13 +15589,15 @@
1325715589 FlipTransform();
1325815590 break;
1325915591 case ENTER:
13260
- object.editWindow.ScreenFit(); // Edit();
15592
+ // object.editWindow.ScreenFit(); // Edit();
15593
+ ToggleLive();
1326115594 break;
1326215595 case DELETE:
1326315596 ClearSelection();
1326415597 break;
13265
- /*
1326615598 case '+':
15599
+
15600
+ /*
1326715601 //fontsize += 1;
1326815602 bbzoom *= 2;
1326915603 repaint();
....@@ -13280,17 +15614,17 @@
1328015614 case '=':
1328115615 IncDepth();
1328215616 //fontsize += 1;
13283
- object.editWindow.refreshContents(true);
15617
+ object.GetWindow().refreshContents(true);
1328415618 maskbit = 6;
1328515619 break;
1328615620 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1328715621 DecDepth();
1328815622 maskbit = 5;
1328915623 //if(fontsize > 1) fontsize -= 1;
13290
- if (object.editWindow == null)
13291
- new Exception().printStackTrace();
13292
- else
13293
- object.editWindow.refreshContents(true);
15624
+// if (object.editWindow == null)
15625
+// new Exception().printStackTrace();
15626
+// else
15627
+ object.GetWindow().refreshContents(true);
1329415628 break;
1329515629 case '{':
1329615630 manipCamera.shaper_fovy /= 1.1;
....@@ -13345,6 +15679,7 @@
1334515679 }
1334615680 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1334715681 }
15682
+
1334815683 static double OCCLUSIONBOOST = 1; // 0.5;
1334915684
1335015685 void keyReleased(int key, int modifiers)
....@@ -13352,11 +15687,11 @@
1335215687 //mode = ROTATE;
1335315688 if ((MODIFIERS & COMMAND) == 0) // VR??
1335415689 {
13355
- SetMouseMode(modifiers);
15690
+ SetMouseMode(0, modifiers);
1335615691 }
1335715692 }
1335815693
13359
- protected void processKeyEvent(KeyEvent e)
15694
+ public void processKeyEvent(KeyEvent e)
1336015695 {
1336115696 switch (e.getID())
1336215697 {
....@@ -13486,8 +15821,9 @@
1348615821
1348715822 protected void processMouseMotionEvent(MouseEvent e)
1348815823 {
13489
- //System.out.println("processMouseMotionEvent: " + mouseMode);
13490
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15824
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15825
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15826
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1349115827 {
1349215828 mouseMoved(e);
1349315829 } else
....@@ -13512,11 +15848,12 @@
1351215848 }
1351315849 */
1351415850
13515
- object.editWindow.EditSelection();
15851
+ object.GetWindow().EditSelection(false);
1351615852 }
1351715853
1351815854 void SelectParent()
1351915855 {
15856
+ new Exception().printStackTrace();
1352015857 System.exit(0);
1352115858 Composite group = (Composite) object;
1352215859 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -13528,10 +15865,10 @@
1352815865 {
1352915866 //selectees.remove(i);
1353015867 System.out.println("select parent of " + elem);
13531
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15868
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1353215869 } else
1353315870 {
13534
- group.editWindow.Select(elem.GetTreePath(), first, true);
15871
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1353515872 }
1353615873
1353715874 first = false;
....@@ -13540,6 +15877,7 @@
1354015877
1354115878 void SelectChildren()
1354215879 {
15880
+ new Exception().printStackTrace();
1354315881 System.exit(0);
1354415882 /*
1354515883 Composite group = (Composite) object;
....@@ -13572,12 +15910,12 @@
1357215910 for (int j = 0; j < group.children.size(); j++)
1357315911 {
1357415912 elem = (Object3D) group.children.elementAt(j);
13575
- object.editWindow.Select(elem.GetTreePath(), first, true);
15913
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1357615914 first = false;
1357715915 }
1357815916 } else
1357915917 {
13580
- object.editWindow.Select(elem.GetTreePath(), first, true);
15918
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1358115919 }
1358215920
1358315921 first = false;
....@@ -13588,21 +15926,21 @@
1358815926 {
1358915927 //Composite group = (Composite) object;
1359015928 Object3D group = object;
13591
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15929
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1359215930 }
1359315931
1359415932 void ResetTransform(int mask)
1359515933 {
1359615934 //Composite group = (Composite) object;
1359715935 Object3D group = object;
13598
- group.editWindow.ResetTransform(mask);
15936
+ group.GetWindow().ResetTransform(mask);
1359915937 }
1360015938
1360115939 void FlipTransform()
1360215940 {
1360315941 //Composite group = (Composite) object;
1360415942 Object3D group = object;
13605
- group.editWindow.FlipTransform();
15943
+ group.GetWindow().FlipTransform();
1360615944 // group.editWindow.ReduceMesh(true);
1360715945 }
1360815946
....@@ -13610,7 +15948,7 @@
1361015948 {
1361115949 //Composite group = (Composite) object;
1361215950 Object3D group = object;
13613
- group.editWindow.PrintMemory();
15951
+ group.GetWindow().PrintMemory();
1361415952 // group.editWindow.ReduceMesh(true);
1361515953 }
1361615954
....@@ -13618,7 +15956,7 @@
1361815956 {
1361915957 //Composite group = (Composite) object;
1362015958 Object3D group = object;
13621
- group.editWindow.ResetCentroid();
15959
+ group.GetWindow().ResetCentroid();
1362215960 }
1362315961
1362415962 void IncDepth()
....@@ -13700,11 +16038,11 @@
1370016038
1370116039 int width = getBounds().width;
1370216040 int height = getBounds().height;
13703
- ClickInfo info = new ClickInfo();
13704
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1370516041 //Image img = CreateImage(width, height);
1370616042 //System.out.println("width = " + width + "; height = " + height + "\n");
16043
+
1370716044 Graphics gr = g; // img.getGraphics();
16045
+
1370816046 if (!hasMarquee)
1370916047 {
1371016048 if (Xmin < Xmax) // !locked)
....@@ -13776,44 +16114,92 @@
1377616114 }
1377716115 if (object != null && !hasMarquee)
1377816116 {
16117
+ if (object.clickInfo == null)
16118
+ object.clickInfo = new ClickInfo();
16119
+ ClickInfo info = object.clickInfo;
16120
+ //ClickInfo info = new ClickInfo();
16121
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16122
+
1377916123 if (isRenderer)
1378016124 {
13781
- info.flags++;
16125
+ object.clickInfo.flags++;
1378216126 double frameAspect = (double) width / (double) height;
1378316127 if (frameAspect > renderCamera.aspect)
1378416128 {
1378516129 int desired = (int) ((double) height * renderCamera.aspect);
13786
- info.bounds.width -= width - desired;
13787
- info.bounds.x += (width - desired) / 2;
16130
+ object.clickInfo.bounds.width -= width - desired;
16131
+ object.clickInfo.bounds.x += (width - desired) / 2;
1378816132 } else
1378916133 {
1379016134 int desired = (int) ((double) width / renderCamera.aspect);
13791
- info.bounds.height -= height - desired;
13792
- info.bounds.y += (height - desired) / 2;
16135
+ object.clickInfo.bounds.height -= height - desired;
16136
+ object.clickInfo.bounds.y += (height - desired) / 2;
1379316137 }
1379416138 }
13795
- info.g = gr;
13796
- info.camera = renderCamera;
16139
+
16140
+ object.clickInfo.g = gr;
16141
+ object.clickInfo.camera = renderCamera;
1379716142 /*
1379816143 // Memory intensive (brep.verticescopy)
1379916144 if (!(object instanceof Composite))
1380016145 object.draw(info, 0, false); // SLOW :
1380116146 */
13802
- if (!isRenderer)
16147
+ if (!isRenderer) // && drag)
1380316148 {
13804
- object.drawEditHandles(info, 0);
16149
+ Grafreed.Assert(object != null);
16150
+ Grafreed.Assert(object.selection != null);
16151
+ if (object.selection.Size() > 0)
16152
+ {
16153
+ int hitSomething = object.selection.get(0).hitSomething;
16154
+
16155
+ object.clickInfo.DX = 0;
16156
+ object.clickInfo.DY = 0;
16157
+ object.clickInfo.W = 1;
16158
+ if (hitSomething == Object3D.hitCenter)
16159
+ {
16160
+ info.DX = X;
16161
+ if (X != 0)
16162
+ info.DX -= info.bounds.width/2;
16163
+
16164
+ info.DY = Y;
16165
+ if (Y != 0)
16166
+ info.DY -= info.bounds.height/2;
16167
+ }
16168
+
16169
+ object.drawEditHandles(//info,
16170
+ 0);
16171
+
16172
+ if (drag && (X != 0 || Y != 0))
16173
+ {
16174
+ switch (hitSomething)
16175
+ {
16176
+ case Object3D.hitCenter: gr.setColor(Color.white);
16177
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16178
+ break;
16179
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16180
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16181
+ break;
16182
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16183
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16184
+ break;
16185
+ }
16186
+
16187
+ }
16188
+ }
1380516189 }
1380616190 }
16191
+
1380716192 if (isRenderer)
1380816193 {
1380916194 //gr.setColor(Color.black);
1381016195 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1381116196 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1381216197 }
16198
+
1381316199 if (hasMarquee)
1381416200 {
1381516201 gr.setXORMode(Color.white);
13816
- gr.setColor(Color.red);
16202
+ gr.setColor(Color.white);
1381716203 if (!firstime)
1381816204 {
1381916205 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -13832,6 +16218,7 @@
1383216218 //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
1383316219 }
1383416220
16221
+ // To avoid clear.
1383516222 public void update(Graphics g)
1383616223 {
1383716224 paint(g);
....@@ -13921,6 +16308,7 @@
1392116308 public boolean mouseDown(Event evt, int x, int y)
1392216309 {
1392316310 System.out.println("mouseDown: " + evt);
16311
+ System.exit(0);
1392416312 /*
1392516313 locked = true;
1392616314 drag = false;
....@@ -13964,7 +16352,7 @@
1396416352 {
1396516353 keyPressed(0, modifiers);
1396616354 }
13967
- clickStart(x, y, modifiers);
16355
+ // clickStart(x, y, modifiers);
1396816356 return true;
1396916357 }
1397016358
....@@ -14082,7 +16470,7 @@
1408216470 {
1408316471 keyReleased(0, 0);
1408416472 }
14085
- drag(x, y, modifiers);
16473
+ drag(x, y, 0, modifiers);
1408616474 return true;
1408716475 }
1408816476
....@@ -14214,7 +16602,7 @@
1421416602 Object3D object;
1421516603 static Object3D trackedobject;
1421616604 Camera renderCamera; // Light or Eye (or Occlusion)
14217
- /*static*/ Camera manipCamera; // Light or Eye
16605
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1421816606 /*static*/ Camera eyeCamera;
1421916607 /*static*/ Camera lightCamera;
1422016608 int cameracount;
....@@ -14278,6 +16666,8 @@
1427816666 private /*static*/ boolean firstime;
1427916667 private /*static*/ cVector newView = new cVector();
1428016668 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16669
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16670
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1428116671 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1428216672 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1428316673 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -14290,29 +16680,67 @@
1429016680 {
1429116681 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1429216682
16683
+ int usedsuf = 0;
16684
+
1429316685 for (int i = 0; i < suffixes.length; i++)
1429416686 {
14295
- String resourceName = basename + suffixes[i] + "." + suffix;
14296
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
14297
- mipmapped,
14298
- FileUtil.getFileSuffix(resourceName));
14299
- if (data == null)
16687
+ String[] suffixe = suffixes;
16688
+ String[] fallback = suffixes2;
16689
+ String[] fallfallback = suffixes3;
16690
+
16691
+ for (int c=usedsuf; --c>=0;)
1430016692 {
14301
- throw new IOException("Unable to load texture " + resourceName);
16693
+// String[] temp = suffixe;
16694
+// suffixe = fallback;
16695
+// fallback = fallfallback;
16696
+// fallfallback = temp;
1430216697 }
16698
+
16699
+ String resourceName = basename + suffixe[i] + "." + suffix;
16700
+ TextureData data;
16701
+
16702
+ try
16703
+ {
16704
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16705
+ mipmapped,
16706
+ FileUtil.getFileSuffix(resourceName));
16707
+ }
16708
+ catch (Exception e)
16709
+ {
16710
+ try
16711
+ {
16712
+ resourceName = basename + fallback[i] + "." + suffix;
16713
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16714
+ mipmapped,
16715
+ FileUtil.getFileSuffix(resourceName));
16716
+ }
16717
+ catch (Exception e2)
16718
+ {
16719
+ resourceName = basename + fallfallback[i] + "." + suffix;
16720
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16721
+ mipmapped,
16722
+ FileUtil.getFileSuffix(resourceName));
16723
+ }
16724
+ }
16725
+
1430316726 //System.out.println("Target = " + targets[i]);
1430416727 cubemap.updateImage(data, targets[i]);
1430516728 }
1430616729
1430716730 return cubemap;
1430816731 }
16732
+
1430916733 int bigsphere = -1;
1431016734
1431116735 float BGcolor = 0.5f;
1431216736
14313
- private void DrawSkyBox(GL gl)
16737
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16738
+
16739
+ private void DrawSkyBox(GL gl, float ratio)
1431416740 {
14315
- if (envyoff || cubemap == null)
16741
+ if (//envyoff ||
16742
+ WIREFRAME ||
16743
+ cubemap == null)
1431616744 {
1431716745 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1431816746 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -14327,7 +16755,17 @@
1432716755 // Compensates for ExaminerViewer's modification of modelview matrix
1432816756 gl.glMatrixMode(GL.GL_MODELVIEW);
1432916757 gl.glLoadIdentity();
16758
+ gl.glScalef(1,ratio,1);
1433016759
16760
+// colorV[0] = 2;
16761
+// colorV[1] = 2;
16762
+// colorV[2] = 2;
16763
+// colorV[3] = 1;
16764
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16765
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16766
+//
16767
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16768
+
1433116769 //gl.glActiveTexture(GL.GL_TEXTURE1);
1433216770 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1433316771
....@@ -14359,6 +16797,7 @@
1435916797 {
1436016798 gl.glScalef(1.0f, -1.0f, 1.0f);
1436116799 }
16800
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1436216801 gl.glMultMatrixd(viewrot_1, 0);
1436316802 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1436416803 //viewer.updateInverseRotation(gl);
....@@ -14399,7 +16838,8 @@
1439916838 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1440016839
1440116840 cubemap.disable();
14402
- ////cubemap.unbind();
16841
+ //cubemap.dispose();
16842
+
1440316843 if (CULLFACE)
1440416844 {
1440516845 gl.glEnable(gl.GL_CULL_FACE);
....@@ -14434,7 +16874,7 @@
1443416874 gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
1443516875 gl.glPushMatrix();
1443616876 gl.glLoadIdentity();
14437
- PushMatrix(checker.toParent);
16877
+ //PushMatrix(checker.toParent);
1443816878
1443916879 gl.glMatrixMode(GL.GL_TEXTURE);
1444016880 gl.glPushMatrix();
....@@ -14457,8 +16897,8 @@
1445716897
1445816898 gl.glNormal3f(0.0f, 0.0f, 1.0f);
1445916899
14460
- float step = 0.1666f; //0.25f;
14461
- float stepv = step * 1652 / 998;
16900
+ float step = 2; // 0.1666f; //0.25f;
16901
+ float stepv = 2; // step * 1652 / 998;
1446216902
1446316903 int i0 = 0;
1446416904 /*
....@@ -14494,20 +16934,21 @@
1449416934 /**/
1449516935 //checker.GetMaterial().opacity = 1.1f;
1449616936 ////checker.GetMaterial().ambient = 0.99f;
14497
- Object3D.materialstack[Object3D.materialdepth] = checker.material;
14498
- Object3D.selectedstack[Object3D.materialdepth] = false;
14499
- cStatic.objectstack[Object3D.materialdepth++] = checker;
16937
+ materialstack[materialdepth] = checker.material;
16938
+ selectedstack[materialdepth] = false;
16939
+ cStatic.objectstack[materialdepth++] = checker;
1450016940 //System.out.println("material " + material);
1450116941 //Applet3D.tracein(this, selected);
14502
- vector2buffer = checker.projectedVertices;
16942
+ //vector2buffer = checker.projectedVertices;
1450316943
14504
- checker.GetMaterial().Draw(this, false); // true);
16944
+ //checker.GetMaterial().Draw(this, false); // true);
16945
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1450516946
14506
- Object3D.materialdepth -= 1;
14507
- if (Object3D.materialdepth > 0)
16947
+ materialdepth -= 1;
16948
+ if (materialdepth > 0)
1450816949 {
14509
- vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
14510
- Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
16950
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16951
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1451116952 }
1451216953 //checker.GetMaterial().opacity = 1f;
1451316954 ////checker.GetMaterial().ambient = 1f;
....@@ -14528,15 +16969,27 @@
1452816969
1452916970 //float u = (i+1)/2;
1453016971 //float v = (j+1)/2;
14531
- gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
16972
+ if (checker.flipV)
16973
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
16974
+ else
16975
+ gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
1453216976 gl.glVertex3f(i, j, -0.5f);
1453316977
16978
+ if (checker.flipV)
16979
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
16980
+ else
1453416981 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
1453516982 gl.glVertex3f(i + step, j, -0.5f);
1453616983
16984
+ if (checker.flipV)
16985
+ gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
16986
+ else
1453716987 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
1453816988 gl.glVertex3f(i + step, j + stepv, -0.5f);
1453916989
16990
+ if (checker.flipV)
16991
+ gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
16992
+ else
1454016993 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
1454116994 gl.glVertex3f(i, j + stepv, -0.5f);
1454216995 }
....@@ -14548,7 +17001,7 @@
1454817001 gl.glMatrixMode(GL.GL_PROJECTION);
1454917002 gl.glPopMatrix();
1455017003 gl.glMatrixMode(GL.GL_MODELVIEW);
14551
- PopMatrix(null); // checker.toParent); // null);
17004
+ //PopMatrix(null); // checker.toParent); // null);
1455217005 gl.glPopMatrix();
1455317006 PopTextureMatrix(checker.toParent);
1455417007 gl.glMatrixMode(GL.GL_TEXTURE);
....@@ -14581,6 +17034,14 @@
1458117034 }
1458217035 }
1458317036
17037
+ private Object3D GetFolder()
17038
+ {
17039
+ Object3D folder = object.GetWindow().copy;
17040
+ if (object.GetWindow().copy.selection.Size() > 0)
17041
+ folder = object.GetWindow().copy.selection.elementAt(0);
17042
+ return folder;
17043
+ }
17044
+
1458417045 class SelectBuffer implements GLEventListener
1458517046 {
1458617047
....@@ -14596,7 +17057,7 @@
1459617057 //new Exception().printStackTrace();
1459717058 System.out.println("select buffer init");
1459817059 // Use debug pipeline
14599
- drawable.setGL(new DebugGL(drawable.getGL()));
17060
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1460017061
1460117062 GL gl = drawable.getGL();
1460217063
....@@ -14639,6 +17100,7 @@
1463917100 {
1464017101 if (!selection)
1464117102 {
17103
+ new Exception().printStackTrace();
1464217104 System.exit(0);
1464317105 return;
1464417106 }
....@@ -14659,17 +17121,39 @@
1465917121
1466017122 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1466117123
17124
+ if (PAINTMODE)
17125
+ {
17126
+ if (object.GetWindow().copy.selection.Size() > 0)
17127
+ {
17128
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17129
+
17130
+ // Make what you paint not selectable.
17131
+ paintobj.ResetSelectable();
17132
+ }
17133
+ }
17134
+
1466217135 //int tmp = selection_view;
1466317136 //selection_view = -1;
14664
- int temp = drawMode;
14665
- drawMode = SELECTION;
17137
+ int temp = DrawMode();
17138
+ Globals.drawMode = SELECTION; // WARNING
1466617139 indexcount = 0;
1466717140 parent.display(drawable);
1466817141 //selection_view = tmp;
1466917142 //if (temp == SELECTION)
1467017143 // temp = DEFAULT; // patch for selection debug
14671
- drawMode = temp;
17144
+ Globals.drawMode = temp; // WARNING
1467217145
17146
+ if (PAINTMODE)
17147
+ {
17148
+ if (object.GetWindow().copy.selection.Size() > 0)
17149
+ {
17150
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17151
+
17152
+ // Revert.
17153
+ paintobj.RestoreSelectable();
17154
+ }
17155
+ }
17156
+
1467317157 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1467417158
1467517159 // trying different ways of getting the depth info over
....@@ -14718,6 +17202,13 @@
1471817202 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1471917203 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
1472017204
17205
+ CreateSelectedPoint();
17206
+
17207
+ // Will fit the mesh !!!
17208
+ selectedpoint.toParent[0][0] = 0.0001;
17209
+ selectedpoint.toParent[1][1] = 0.0001;
17210
+ selectedpoint.toParent[2][2] = 0.0001;
17211
+
1472117212 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
1472217213
1472317214 // if (object.selection != null && object.selection.Size() > 0)
....@@ -14761,34 +17252,36 @@
1476117252 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]));
1476217253 }
1476317254
14764
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17255
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1476517256 }
1476617257 }
1476717258
1476817259 if (!movingcamera && !PAINTMODE)
14769
- object.editWindow.ScreenFitPoint(); // fev 2014
17260
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1477017261
14771
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17262
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1477217263 {
14773
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17264
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1477417265
14775
- Object3D group = new Object3D("inst" + paintcount++);
17266
+ if (object.GetWindow().copy.selection.Size() > 0)
17267
+ {
17268
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1477617269
14777
- group.CreateMaterial(); // use a void leaf to select instances
14778
-
14779
- group.add(paintobj); // link
14780
-
14781
- object.editWindow.SnapObject(group);
14782
-
14783
- Object3D folder = object.editWindow.copy;
14784
-
14785
- if (object.editWindow.copy.selection.Size() > 0)
14786
- folder = object.editWindow.copy.selection.elementAt(0);
14787
-
14788
- folder.add(group);
14789
-
14790
- object.editWindow.ResetModel();
14791
- object.editWindow.refreshContents();
17270
+ Object3D inst = new Object3D("inst" + paintcount++);
17271
+
17272
+ inst.CreateMaterial(); // use a void leaf to select instances
17273
+
17274
+ inst.add(paintobj); // link
17275
+
17276
+ object.GetWindow().SnapObject(inst);
17277
+
17278
+ Object3D folder = paintFolder; // GetFolder();
17279
+
17280
+ folder.add(inst);
17281
+
17282
+ object.GetWindow().ResetModel();
17283
+ object.GetWindow().refreshContents();
17284
+ }
1479217285 }
1479317286 else
1479417287 paintcount = 0;
....@@ -14827,6 +17320,11 @@
1482717320 //System.out.println("objects[color] = " + objects[color]);
1482817321 //objects[color].Select();
1482917322 indexcount = 0;
17323
+ ObjEditor window = object.GetWindow();
17324
+ if (window != null && deselect)
17325
+ {
17326
+ window.Select(null, deselect, true);
17327
+ }
1483017328 object.Select(color, deselect);
1483117329 }
1483217330
....@@ -14877,6 +17375,7 @@
1487717375
1487817376 public void init(GLAutoDrawable drawable)
1487917377 {
17378
+ if (Globals.DEBUG)
1488017379 System.out.println("shadow buffer init");
1488117380
1488217381 GL gl = drawable.getGL();
....@@ -14926,7 +17425,7 @@
1492617425 gl.glDisable(gl.GL_CULL_FACE);
1492717426 }
1492817427
14929
- if (!RENDERSHADOW)
17428
+ if (!Globals.RENDERSHADOW)
1493017429 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1493117430
1493217431 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -14936,14 +17435,14 @@
1493617435 //gl.glColorMask(false, false, false, false);
1493717436
1493817437 //render_scene_from_light_view(gl, drawable, 0, 0);
14939
- if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
17438
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1494017439 {
1494117440 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1494217441
14943
- int temp = drawMode;
14944
- drawMode = SHADOW;
17442
+ int temp = DrawMode();
17443
+ Globals.drawMode = SHADOW; // WARNING
1494517444 parent.display(drawable);
14946
- drawMode = temp;
17445
+ Globals.drawMode = temp; // WARNING
1494717446 }
1494817447
1494917448 gl.glCullFace(gl.GL_BACK);
....@@ -14996,7 +17495,6 @@
1499617495
1499717496 class AntialiasBuffer implements GLEventListener
1499817497 {
14999
-
1500017498 CameraPane parent = null;
1500117499
1500217500 AntialiasBuffer(CameraPane p)
....@@ -15106,15 +17604,25 @@
1510617604 gl.glFlush();
1510717605
1510817606 /**/
15109
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
17607
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1511017608
15111
- int[] pixels = occlusionsizebuffer.array();
17609
+ float[] depths = occlusiondepthbuffer.array();
1511217610
17611
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17612
+
17613
+ int[] pixels = selectsizebuffer.array();
17614
+
1511317615 double r = 0, g = 0, b = 0;
1511417616
1511517617 double count = 0;
17618
+
17619
+ gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
17620
+
17621
+ float mindepth = 1;
17622
+
17623
+ double FACTOR = 1;
1511617624
15117
- for (int i = 0; i < pixels.length; i++)
17625
+ for (int i = 0; i < depths.length; i++)
1511817626 {
1511917627 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1512017628 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15197,7 +17705,7 @@
1519717705
1519817706 double scale = ray.z; // 1; // cos
1519917707
15200
- int p = pixels[newindex];
17708
+ float depth = depths[newindex];
1520117709
1520217710 /*
1520317711 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -15221,10 +17729,23 @@
1522117729 scale = (1 - modu) * modv;
1522217730 */
1522317731
15224
- r += ((p >> 16) & 0xFF) * scale / 255;
15225
- g += ((p >> 8) & 0xFF) * scale / 255;
15226
- b += (p & 0xFF) * scale / 255;
17732
+ //r += ((p >> 16) & 0xFF) * scale / 255;
17733
+ //g += ((p >> 8) & 0xFF) * scale / 255;
17734
+ //b += (p & 0xFF) * scale / 255;
17735
+
17736
+ if (mindepth > depth)
17737
+ {
17738
+ mindepth = depth;
17739
+ }
1522717740
17741
+ double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
17742
+
17743
+ double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
17744
+
17745
+ r += factor * scale;
17746
+ g += factor * scale;
17747
+ b += factor * scale;
17748
+
1522817749 count += scale;
1522917750 }
1523017751
....@@ -15322,12 +17843,6 @@
1532217843 GLUT glut = new GLUT();
1532317844
1532417845
15325
- static final public int DEFAULT = 0;
15326
- static final public int SELECTION = 1;
15327
- static final public int SHADOW = 2;
15328
- static final public int OCCLUSION = 3;
15329
- static
15330
- public int drawMode = DEFAULT;
1533117846 public boolean spherical = false;
1533217847 static boolean DEBUG_OCCLUSION = false;
1533317848 static boolean DEBUG_SELECTION = false;
....@@ -15340,23 +17855,15 @@
1534017855 int AAbuffersize = 0;
1534117856
1534217857 //double[] selectedpoint = new double[3];
15343
- static Sphere selectedpoint = new Sphere();
17858
+ static Superellipsoid selectedpoint;
1534417859 static Sphere previousselectedpoint = null;
15345
- static Sphere debugpoint = new Sphere();
15346
- static Sphere debugpoint2 = new Sphere();
15347
- static Sphere debugpoint3 = new Sphere();
15348
- static Sphere debugpoint4 = new Sphere();
17860
+ static Sphere debugpointG;
17861
+ static Sphere debugpointP;
17862
+ static Sphere debugpointC;
17863
+ static Sphere debugpointR;
1534917864
1535017865 static Sphere debugpoints[] = new Sphere[8];
1535117866
15352
- static
15353
- {
15354
- for (int i=0; i<8; i++)
15355
- {
15356
- debugpoints[i] = new Sphere();
15357
- }
15358
- }
15359
-
1536017867 static void InitPoints(float radius)
1536117868 {
1536217869 for (int i=0; i<8; i++)
....@@ -15376,7 +17883,7 @@
1537617883 }
1537717884 }
1537817885
15379
- static void DrawPoints(CameraPane cpane)
17886
+ static void DrawPoints(iCameraPane cpane)
1538017887 {
1538117888 for (int i=0; i<8; i++) // first and last are red
1538217889 {
....@@ -15395,10 +17902,14 @@
1539517902 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1539617903 static IntBuffer bigAAbuffer;
1539717904 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
15398
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17905
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1539917906 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1540017907 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
15401
- static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17908
+ //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17909
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17910
+
17911
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17912
+
1540217913 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1540317914 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1540417915 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -15407,10 +17918,11 @@
1540717918 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1540817919 // Depth buffer format
1540917920 //private int depth_format;
15410
- static public void NextIndex(Object3D o, GL gl)
17921
+
17922
+ public void NextIndex()
1541117923 {
1541217924 indexcount+=16;
15413
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17925
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1541417926 //objects[indexcount] = o;
1541517927 //System.out.println("indexcount = " + indexcount);
1541617928 }