Normand Briere
2019-07-23 5140c320d8addf4bd8dcaa7f350b6accdc4ffbaf
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,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -93,7 +97,7 @@
9397 //boolean REDUCETEXTURE = true;
9498 boolean CACHETEXTURE = true;
9599 boolean CLEANCACHE = false; // true;
96
- boolean MIPMAP = true; // false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
97101 boolean COMPRESSTEXTURE = false;
98102 boolean KOMPACTTEXTURE = false; // true;
99103 boolean RESIZETEXTURE = false;
....@@ -8358,14 +8362,26 @@
83588362 {
83598363 TextureData texturedata = null;
83608364
8361
- if (texdata != null)
8365
+ if (texdata != null && textureon)
83628366 {
8363
- BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
83648368
8365
- CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
83668377
83678378 texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
83688379 bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
83698385 }
83708386 else
83718387 if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
....@@ -8560,29 +8576,32 @@
85608576 {
85618577 if (tex.pigmentdata == null)
85628578 {
8563
- String texname = Object3D.GetPigment(tex);
8579
+ //String texname = Object3D.GetPigment(tex);
85648580
85658581 CacheTexture texturecache = texturepigment.get(tex);
85668582
85678583 if (texturecache != null)
85688584 {
8569
- tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
85708585 tex.pw = texturecache.texturedata.getWidth();
85718586 tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
85728591 }
85738592 }
85748593
85758594 if (tex.bumpdata == null)
85768595 {
8577
- String texname = Object3D.GetBump(tex);
8596
+ //String texname = Object3D.GetBump(tex);
85788597
85798598 CacheTexture texturecache = texturebump.get(tex);
85808599
85818600 if (texturecache != null)
85828601 {
8583
- tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
85848602 tex.bw = texturecache.texturedata.getWidth();
85858603 tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
85868605 }
85878606 }
85888607 }
....@@ -8654,6 +8673,72 @@
86548673 return true; // Warning: not used.
86558674 }
86568675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
86578742 ShadowBuffer shadowPBuf;
86588743 AntialiasBuffer antialiasPBuf;
86598744 int MAXSTACK;
....@@ -11399,7 +11484,7 @@
1139911484 }
1140011485 }
1140111486
11402
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1140311488 {
1140411489 //gl.glDepthFunc(GL.GL_LEQUAL);
1140511490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11407,24 +11492,21 @@
1140711492
1140811493 boolean texon = textureon;
1140911494
11410
- if (RENDERPROGRAM > 0)
11411
- {
11412
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11413
- textureon = false;
11414
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1141511498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1141611499 //System.out.println("ALLO");
1141711500 gl.glColorMask(false, false, false, false);
1141811501 DrawObject(gl);
11419
- if (RENDERPROGRAM > 0)
11420
- {
11421
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11422
- textureon = texon;
11423
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1142411506 gl.glColorMask(true, true, true, true);
1142511507
1142611508 gl.glDepthFunc(GL.GL_EQUAL);
11427
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1142811510 }
1142911511
1143011512 if (false) // DrawMode() == SHADOW)
....@@ -12318,7 +12400,52 @@
1231812400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1231912401
1232012402 String program =
12403
+ // Min shader
1232112404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1232212449 //"OPTION ARB_fragment_program_shadow;" +
1232312450 "PARAM light2cam0 = program.env[10];" +
1232412451 "PARAM light2cam1 = program.env[11];" +
....@@ -12433,8 +12560,7 @@
1243312560 "TEMP shininess;" +
1243412561 "\n" +
1243512562 "MOV texSamp, one;" +
12436
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12437
-
12563
+
1243812564 "MOV mapgrid.x, one2048th.x;" +
1243912565 "MOV temp, fragment.texcoord[1];" +
1244012566 /*
....@@ -12839,7 +12965,7 @@
1283912965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284012966 "") +
1284112967
12842
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1284312969 "SUB temp.x, half.x, shadow.x;" +
1284412970 "MOV temp.y, -params5.z;" + // params6.x;" +
1284512971 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13271,20 +13397,20 @@
1327113397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327213398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327313399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327413402 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13275
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13276
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13277
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13278
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1327913405 //"SWZ buffer, temp, w,w,w,w;";
13280
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328113407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328213408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328313409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13284
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328513411
13286
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13287
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328813414 }
1328913415
1329013416 String Shadow(String depth, String shadow)
....@@ -13331,7 +13457,7 @@
1333113457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333213458 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333313459
13334
- // No shadow when out of frustrum
13460
+ // No shadow when out of frustum
1333513461 "SGE temp.x, " + depth + ".z, one.z;" +
1333613462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333713463 "";
....@@ -14129,14 +14255,15 @@
1412914255 drag = false;
1413014256 //System.out.println("Mouse DOWN");
1413114257 editObj = false;
14132
- ClickInfo info = new ClickInfo();
14133
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14134
- info.pane = this;
14135
- info.camera = renderCamera;
14136
- info.x = x;
14137
- info.y = y;
14138
- info.modifiers = modifiersex;
14139
- editObj = object.doEditClick(info, 0);
14258
+ //ClickInfo info = new ClickInfo();
14259
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
+ object.clickInfo.pane = this;
14261
+ object.clickInfo.camera = renderCamera;
14262
+ object.clickInfo.x = x;
14263
+ object.clickInfo.y = y;
14264
+ object.clickInfo.modifiers = modifiersex;
14265
+ editObj = object.doEditClick(//info,
14266
+ 0);
1414014267 if (!editObj)
1414114268 {
1414214269 hasMarquee = true;
....@@ -14536,15 +14663,16 @@
1453614663 if (editObj)
1453714664 {
1453814665 drag = true;
14539
- ClickInfo info = new ClickInfo();
14540
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1454114668 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14542
- info.pane = this;
14543
- info.camera = renderCamera;
14544
- info.x = x;
14545
- info.y = y;
14546
- object.GetWindow().copy
14547
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14669
+ object.clickInfo.pane = this;
14670
+ object.clickInfo.camera = renderCamera;
14671
+ object.clickInfo.x = x;
14672
+ object.clickInfo.y = y;
14673
+ object //.GetWindow().copy
14674
+ .doEditDrag(//info,
14675
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454814676 } else
1454914677 {
1455014678 if (x < startX)
....@@ -14693,24 +14821,27 @@
1469314821 }
1469414822 }
1469514823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1469614826 public void mouseMoved(MouseEvent e)
1469714827 {
1469814828 //System.out.println("mouseMoved: " + e);
1469914829 if (isRenderer)
1470014830 return;
1470114831
14702
- ClickInfo ci = new ClickInfo();
14703
- ci.x = e.getX();
14704
- ci.y = e.getY();
14705
- ci.modifiers = e.getModifiersEx();
14706
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14707
- ci.pane = this;
14708
- ci.camera = renderCamera;
14832
+ // Mouse cursor feedback
14833
+ object.clickInfo.x = e.getX();
14834
+ object.clickInfo.y = e.getY();
14835
+ object.clickInfo.modifiers = e.getModifiersEx();
14836
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14837
+ object.clickInfo.pane = this;
14838
+ object.clickInfo.camera = renderCamera;
1470914839 if (!isRenderer)
1471014840 {
1471114841 //ObjEditor editWindow = object.editWindow;
1471214842 //Object3D copy = editWindow.copy;
14713
- if (object.doEditClick(ci, 0))
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1471414845 {
1471514846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471614847 } else
....@@ -15736,8 +15867,6 @@
1573615867
1573715868 int width = getBounds().width;
1573815869 int height = getBounds().height;
15739
- ClickInfo info = new ClickInfo();
15740
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574115870 //Image img = CreateImage(width, height);
1574215871 //System.out.println("width = " + width + "; height = " + height + "\n");
1574315872
....@@ -15814,31 +15943,37 @@
1581415943 }
1581515944 if (object != null && !hasMarquee)
1581615945 {
15946
+ if (object.clickInfo == null)
15947
+ object.clickInfo = new ClickInfo();
15948
+ ClickInfo info = object.clickInfo;
15949
+ //ClickInfo info = new ClickInfo();
15950
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15951
+
1581715952 if (isRenderer)
1581815953 {
15819
- info.flags++;
15954
+ object.clickInfo.flags++;
1582015955 double frameAspect = (double) width / (double) height;
1582115956 if (frameAspect > renderCamera.aspect)
1582215957 {
1582315958 int desired = (int) ((double) height * renderCamera.aspect);
15824
- info.bounds.width -= width - desired;
15825
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1582615961 } else
1582715962 {
1582815963 int desired = (int) ((double) width / renderCamera.aspect);
15829
- info.bounds.height -= height - desired;
15830
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583115966 }
1583215967 }
1583315968
15834
- info.g = gr;
15835
- info.camera = renderCamera;
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1583615971 /*
1583715972 // Memory intensive (brep.verticescopy)
1583815973 if (!(object instanceof Composite))
1583915974 object.draw(info, 0, false); // SLOW :
1584015975 */
15841
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1584215977 {
1584315978 Grafreed.Assert(object != null);
1584415979 Grafreed.Assert(object.selection != null);
....@@ -15846,9 +15981,9 @@
1584615981 {
1584715982 int hitSomething = object.selection.get(0).hitSomething;
1584815983
15849
- info.DX = 0;
15850
- info.DY = 0;
15851
- info.W = 1;
15984
+ object.clickInfo.DX = 0;
15985
+ object.clickInfo.DY = 0;
15986
+ object.clickInfo.W = 1;
1585215987 if (hitSomething == Object3D.hitCenter)
1585315988 {
1585415989 info.DX = X;
....@@ -15860,7 +15995,8 @@
1586015995 info.DY -= info.bounds.height/2;
1586115996 }
1586215997
15863
- object.drawEditHandles(info, 0);
15998
+ object.drawEditHandles(//info,
15999
+ 0);
1586416000
1586516001 if (drag && (X != 0 || Y != 0))
1586616002 {
....@@ -15873,7 +16009,7 @@
1587316009 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1587416010 break;
1587516011 case Object3D.hitScale: gr.setColor(Color.cyan);
15876
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16012
+ gr.drawLine(X, Y, 0, 0);
1587716013 break;
1587816014 }
1587916015