.. | .. |
---|
18 | 18 | import javax.imageio.ImageIO; |
---|
19 | 19 | import javax.imageio.ImageWriteParam; |
---|
20 | 20 | import javax.imageio.ImageWriter; |
---|
| 21 | +import javax.imageio.ImageReadParam; |
---|
| 22 | +import javax.imageio.ImageReader; |
---|
21 | 23 | import javax.imageio.plugins.jpeg.JPEGImageWriteParam; |
---|
| 24 | +import javax.imageio.stream.ImageInputStream; |
---|
22 | 25 | import javax.imageio.stream.ImageOutputStream; |
---|
23 | 26 | import javax.imageio.ImageWriteParam; |
---|
24 | 27 | |
---|
.. | .. |
---|
30 | 33 | import java.nio.*; |
---|
31 | 34 | |
---|
32 | 35 | import gleem.linalg.Mat4f; |
---|
| 36 | +import javax.imageio.ImageTypeSpecifier; |
---|
33 | 37 | |
---|
34 | 38 | class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener |
---|
35 | 39 | { |
---|
.. | .. |
---|
93 | 97 | //boolean REDUCETEXTURE = true; |
---|
94 | 98 | boolean CACHETEXTURE = true; |
---|
95 | 99 | boolean CLEANCACHE = false; // true; |
---|
96 | | - boolean MIPMAP = true; // false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
97 | 101 | boolean COMPRESSTEXTURE = false; |
---|
98 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
99 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
106 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
107 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
108 | 112 | static GLContext glcontext = null; |
---|
109 | | - /*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; |
---|
110 | 116 | boolean reverseUP = false; |
---|
111 | 117 | static boolean frozen = false; |
---|
112 | 118 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
169 | 175 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
170 | 176 | boolean anisotropy = true; |
---|
171 | 177 | boolean softshadow = true; // slower but better false; |
---|
172 | | - boolean opacityhalo = false; |
---|
| 178 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
173 | 179 | |
---|
174 | 180 | boolean macromode = false; |
---|
175 | 181 | |
---|
.. | .. |
---|
183 | 189 | } |
---|
184 | 190 | |
---|
185 | 191 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 192 | + |
---|
| 193 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 194 | + { |
---|
| 195 | + try |
---|
| 196 | + { |
---|
| 197 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 198 | + } catch (IOException e) |
---|
| 199 | + { |
---|
| 200 | + System.out.println("NAME = " + name); |
---|
| 201 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 202 | + return null; |
---|
| 203 | + } |
---|
| 204 | + } |
---|
186 | 205 | |
---|
187 | 206 | void SetAsGLRenderer(boolean b) |
---|
188 | 207 | { |
---|
.. | .. |
---|
202 | 221 | |
---|
203 | 222 | SetCamera(cam); |
---|
204 | 223 | |
---|
205 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 224 | + // Warning: not used. |
---|
| 225 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
206 | 226 | |
---|
207 | 227 | object = o; |
---|
208 | 228 | |
---|
.. | .. |
---|
1480 | 1500 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1481 | 1501 | } |
---|
1482 | 1502 | |
---|
| 1503 | + float[] colorV = new float[4]; |
---|
| 1504 | + |
---|
1483 | 1505 | void SetColor(Object3D obj, Vertex p0) |
---|
1484 | 1506 | { |
---|
1485 | 1507 | CameraPane display = this; |
---|
.. | .. |
---|
1547 | 1569 | { |
---|
1548 | 1570 | return; |
---|
1549 | 1571 | } |
---|
1550 | | - |
---|
1551 | | - float[] colorV = new float[3]; |
---|
1552 | 1572 | |
---|
1553 | 1573 | if (false) // marked) |
---|
1554 | 1574 | { |
---|
.. | .. |
---|
8341 | 8361 | // else |
---|
8342 | 8362 | // if (!texname.startsWith("/")) |
---|
8343 | 8363 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8344 | | - if (!FileExists(texname)) |
---|
| 8364 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8345 | 8365 | { |
---|
8346 | 8366 | texname = fallbackTextureName; |
---|
8347 | 8367 | } |
---|
.. | .. |
---|
8358 | 8378 | { |
---|
8359 | 8379 | TextureData texturedata = null; |
---|
8360 | 8380 | |
---|
8361 | | - if (texdata != null) |
---|
| 8381 | + if (texdata != null && textureon) |
---|
8362 | 8382 | { |
---|
8363 | | - BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8383 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
8364 | 8384 | |
---|
8365 | | - CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8385 | + try |
---|
| 8386 | + { |
---|
| 8387 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8388 | + } |
---|
| 8389 | + catch (Exception e) |
---|
| 8390 | + { |
---|
| 8391 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8392 | + } |
---|
8366 | 8393 | |
---|
8367 | 8394 | texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
8368 | 8395 | bimtextures.put(texdata, texturecache); |
---|
| 8396 | + |
---|
| 8397 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8398 | + |
---|
| 8399 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8400 | + //bim2 = bim; |
---|
8369 | 8401 | } |
---|
8370 | 8402 | else |
---|
8371 | 8403 | if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
.. | .. |
---|
8408 | 8440 | // texturecache = textures.get(texname); // suspicious |
---|
8409 | 8441 | if (texturecache == null) |
---|
8410 | 8442 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8443 | + else |
---|
| 8444 | + new Exception().printStackTrace(); |
---|
| 8445 | + } else |
---|
| 8446 | + { |
---|
| 8447 | + if (texname.startsWith("@")) |
---|
| 8448 | + { |
---|
| 8449 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8450 | + if (texturecache == null) |
---|
| 8451 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
8411 | 8452 | else |
---|
8412 | 8453 | new Exception().printStackTrace(); |
---|
8413 | 8454 | } else |
---|
.. | .. |
---|
8471 | 8512 | texturecache = new CacheTexture(texturedata,resolution); |
---|
8472 | 8513 | //texture = GetTexture(tex, bump); |
---|
8473 | 8514 | } |
---|
| 8515 | + } |
---|
8474 | 8516 | } |
---|
8475 | 8517 | //} |
---|
8476 | 8518 | } |
---|
.. | .. |
---|
8560 | 8602 | { |
---|
8561 | 8603 | if (tex.pigmentdata == null) |
---|
8562 | 8604 | { |
---|
8563 | | - String texname = Object3D.GetPigment(tex); |
---|
| 8605 | + //String texname = Object3D.GetPigment(tex); |
---|
8564 | 8606 | |
---|
8565 | 8607 | CacheTexture texturecache = texturepigment.get(tex); |
---|
8566 | 8608 | |
---|
8567 | 8609 | if (texturecache != null) |
---|
8568 | 8610 | { |
---|
8569 | | - tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); |
---|
8570 | 8611 | tex.pw = texturecache.texturedata.getWidth(); |
---|
8571 | 8612 | tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8613 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8614 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8615 | + ; |
---|
| 8616 | + //, tex.pw, tex.ph), 0.5f); |
---|
8572 | 8617 | } |
---|
8573 | 8618 | } |
---|
8574 | 8619 | |
---|
8575 | 8620 | if (tex.bumpdata == null) |
---|
8576 | 8621 | { |
---|
8577 | | - String texname = Object3D.GetBump(tex); |
---|
| 8622 | + //String texname = Object3D.GetBump(tex); |
---|
8578 | 8623 | |
---|
8579 | 8624 | CacheTexture texturecache = texturebump.get(tex); |
---|
8580 | 8625 | |
---|
8581 | 8626 | if (texturecache != null) |
---|
8582 | 8627 | { |
---|
8583 | | - tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); |
---|
8584 | 8628 | tex.bw = texturecache.texturedata.getWidth(); |
---|
8585 | 8629 | tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8630 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
8586 | 8631 | } |
---|
8587 | 8632 | } |
---|
8588 | 8633 | } |
---|
.. | .. |
---|
8654 | 8699 | return true; // Warning: not used. |
---|
8655 | 8700 | } |
---|
8656 | 8701 | |
---|
| 8702 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8703 | + { |
---|
| 8704 | + try |
---|
| 8705 | + { |
---|
| 8706 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8707 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8708 | + ImageWriter writer = writers.next(); |
---|
| 8709 | + |
---|
| 8710 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8711 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8712 | + param.setCompressionQuality(quality); |
---|
| 8713 | + |
---|
| 8714 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8715 | + writer.setOutput(ios); |
---|
| 8716 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8717 | + |
---|
| 8718 | + byte[] data = baos.toByteArray(); |
---|
| 8719 | + writer.dispose(); |
---|
| 8720 | + return data; |
---|
| 8721 | + } |
---|
| 8722 | + catch (Exception e) |
---|
| 8723 | + { |
---|
| 8724 | + e.printStackTrace(); |
---|
| 8725 | + return null; |
---|
| 8726 | + } |
---|
| 8727 | + } |
---|
| 8728 | + |
---|
| 8729 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8730 | + { |
---|
| 8731 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8732 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8733 | + ImageReader reader = writers.next(); |
---|
| 8734 | + |
---|
| 8735 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8736 | + |
---|
| 8737 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8738 | + param.setDestination(bim); |
---|
| 8739 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8740 | + |
---|
| 8741 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8742 | + reader.setInput(ios); |
---|
| 8743 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8744 | + reader.dispose(); |
---|
| 8745 | + |
---|
| 8746 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8747 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8748 | +// byte[] bytes = data.getData(); |
---|
| 8749 | +// |
---|
| 8750 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8751 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8752 | +// { |
---|
| 8753 | +// int i3 = i*3; |
---|
| 8754 | +// pixels[i] = 0xFF; |
---|
| 8755 | +// pixels[i] <<= 8; |
---|
| 8756 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8757 | +// pixels[i] <<= 8; |
---|
| 8758 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8759 | +// pixels[i] <<= 8; |
---|
| 8760 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8761 | +// } |
---|
| 8762 | +// |
---|
| 8763 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8764 | + |
---|
| 8765 | + return bim; |
---|
| 8766 | + } |
---|
| 8767 | + |
---|
8657 | 8768 | ShadowBuffer shadowPBuf; |
---|
8658 | 8769 | AntialiasBuffer antialiasPBuf; |
---|
8659 | 8770 | int MAXSTACK; |
---|
.. | .. |
---|
8670 | 8781 | |
---|
8671 | 8782 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8672 | 8783 | MAXSTACK = temp[0]; |
---|
8673 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8784 | + if (Globals.DEBUG) |
---|
| 8785 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8674 | 8786 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8675 | 8787 | MAXSTACK = temp[0]; |
---|
8676 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8788 | + if (Globals.DEBUG) |
---|
| 8789 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8677 | 8790 | |
---|
8678 | 8791 | // Use debug pipeline |
---|
8679 | 8792 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8681 | 8794 | gl = drawable.getGL(); // |
---|
8682 | 8795 | |
---|
8683 | 8796 | GL gl3 = getGL(); |
---|
8684 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8797 | + if (Globals.DEBUG) |
---|
| 8798 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8685 | 8799 | |
---|
8686 | 8800 | |
---|
8687 | 8801 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8846 | 8960 | |
---|
8847 | 8961 | if (cubemap == null) |
---|
8848 | 8962 | { |
---|
8849 | | - LoadEnvy(5); |
---|
| 8963 | + //LoadEnvy(1); |
---|
8850 | 8964 | } |
---|
8851 | 8965 | |
---|
8852 | 8966 | //cubemap.enable(); |
---|
.. | .. |
---|
9122 | 9236 | |
---|
9123 | 9237 | void LoadEnvy(int which) |
---|
9124 | 9238 | { |
---|
| 9239 | + assert(false); |
---|
| 9240 | + |
---|
9125 | 9241 | String name; |
---|
9126 | 9242 | String ext; |
---|
9127 | 9243 | |
---|
.. | .. |
---|
9133 | 9249 | cubemap = null; |
---|
9134 | 9250 | return; |
---|
9135 | 9251 | case 1: |
---|
9136 | | - name = "cubemaps/box_"; |
---|
9137 | | - ext = "png"; |
---|
| 9252 | + name = "cubemaps/rgb/"; |
---|
| 9253 | + ext = "jpg"; |
---|
9138 | 9254 | reverseUP = false; |
---|
9139 | 9255 | break; |
---|
9140 | 9256 | case 2: |
---|
9141 | | - name = "cubemaps/uffizi_"; |
---|
9142 | | - ext = "png"; |
---|
9143 | | - break; // reverseUP = true; break; |
---|
| 9257 | + name = "cubemaps/uffizi/"; |
---|
| 9258 | + ext = "jpg"; |
---|
| 9259 | + reverseUP = false; |
---|
| 9260 | + break; |
---|
9144 | 9261 | case 3: |
---|
9145 | | - name = "cubemaps/CloudyHills_"; |
---|
9146 | | - ext = "tga"; |
---|
| 9262 | + name = "cubemaps/CloudyHills/"; |
---|
| 9263 | + ext = "jpg"; |
---|
9147 | 9264 | reverseUP = false; |
---|
9148 | 9265 | break; |
---|
9149 | 9266 | case 4: |
---|
9150 | | - name = "cubemaps/cornell_"; |
---|
| 9267 | + name = "cubemaps/cornell/"; |
---|
9151 | 9268 | ext = "png"; |
---|
9152 | 9269 | reverseUP = false; |
---|
9153 | 9270 | break; |
---|
| 9271 | + case 5: |
---|
| 9272 | + name = "cubemaps/skycube/"; |
---|
| 9273 | + ext = "jpg"; |
---|
| 9274 | + reverseUP = false; |
---|
| 9275 | + break; |
---|
| 9276 | + case 6: |
---|
| 9277 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9278 | + ext = "jpg"; |
---|
| 9279 | + reverseUP = false; |
---|
| 9280 | + break; |
---|
| 9281 | + case 7: |
---|
| 9282 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9283 | + ext = "jpg"; |
---|
| 9284 | + reverseUP = false; |
---|
| 9285 | + break; |
---|
| 9286 | + case 8: |
---|
| 9287 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9288 | + ext = "jpg"; |
---|
| 9289 | + reverseUP = false; |
---|
| 9290 | + break; |
---|
| 9291 | + case 9: |
---|
| 9292 | + name = "cubemaps/UnionSquare/"; |
---|
| 9293 | + ext = "jpg"; |
---|
| 9294 | + reverseUP = false; |
---|
| 9295 | + break; |
---|
9154 | 9296 | default: |
---|
9155 | | - name = "cubemaps/rgb_"; |
---|
9156 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9297 | + name = "cubemaps/box/"; |
---|
| 9298 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9299 | + reverseUP = false; |
---|
9157 | 9300 | break; |
---|
9158 | 9301 | } |
---|
9159 | | - |
---|
9160 | | - try |
---|
9161 | | - { |
---|
9162 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9163 | | - } catch (IOException e) |
---|
9164 | | - { |
---|
9165 | | - throw new RuntimeException(e); |
---|
9166 | | - } |
---|
| 9302 | + |
---|
| 9303 | + LoadSkybox(name, ext, mipmap); |
---|
9167 | 9304 | } |
---|
9168 | 9305 | |
---|
9169 | 9306 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9195 | 9332 | static double[] model = new double[16]; |
---|
9196 | 9333 | double[] camera2light = new double[16]; |
---|
9197 | 9334 | double[] light2camera = new double[16]; |
---|
9198 | | - int newenvy = -1; |
---|
9199 | | - boolean envyoff = true; // false; |
---|
| 9335 | + |
---|
| 9336 | + //int newenvy = -1; |
---|
| 9337 | + //boolean envyoff = false; |
---|
| 9338 | + |
---|
| 9339 | + String loadedskyboxname; |
---|
| 9340 | + |
---|
9200 | 9341 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9201 | 9342 | //float[] light0 = { 0,0,0 }; |
---|
9202 | 9343 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9614 | 9755 | |
---|
9615 | 9756 | if (renderCamera != lightCamera) |
---|
9616 | 9757 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9617 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9758 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9618 | 9759 | |
---|
9619 | 9760 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9620 | 9761 | |
---|
.. | .. |
---|
9630 | 9771 | |
---|
9631 | 9772 | if (renderCamera != lightCamera) |
---|
9632 | 9773 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9633 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9774 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9634 | 9775 | |
---|
9635 | 9776 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9636 | 9777 | |
---|
.. | .. |
---|
9676 | 9817 | rati = 1 / rati; |
---|
9677 | 9818 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9678 | 9819 | } |
---|
9679 | | - assert (newenvy == -1); |
---|
| 9820 | + |
---|
| 9821 | + //assert (newenvy == -1); |
---|
| 9822 | + |
---|
9680 | 9823 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9681 | 9824 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9682 | | - DrawSkyBox(gl); |
---|
| 9825 | + DrawSkyBox(gl, (float)rati); |
---|
9683 | 9826 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9684 | 9827 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9685 | 9828 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10716 | 10859 | |
---|
10717 | 10860 | if (wait) |
---|
10718 | 10861 | { |
---|
10719 | | - Sleep(500); |
---|
| 10862 | + Sleep(200); // blocks everything |
---|
10720 | 10863 | |
---|
10721 | 10864 | wait = false; |
---|
10722 | 10865 | } |
---|
.. | .. |
---|
10831 | 10974 | // if (parentcam != renderCamera) // not a light |
---|
10832 | 10975 | if (cam != lightCamera) |
---|
10833 | 10976 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10834 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10977 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10835 | 10978 | |
---|
10836 | 10979 | for (int j = 0; j < 4; j++) |
---|
10837 | 10980 | { |
---|
.. | .. |
---|
10846 | 10989 | // if (parentcam != renderCamera) // not a light |
---|
10847 | 10990 | if (cam != lightCamera) |
---|
10848 | 10991 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10849 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10992 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10850 | 10993 | |
---|
10851 | 10994 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10852 | 10995 | |
---|
.. | .. |
---|
10932 | 11075 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10933 | 11076 | } |
---|
10934 | 11077 | |
---|
10935 | | - if (newenvy > -1) |
---|
| 11078 | +// if (newenvy > -1) |
---|
| 11079 | +// { |
---|
| 11080 | +// LoadEnvy(newenvy); |
---|
| 11081 | +// } |
---|
| 11082 | +// |
---|
| 11083 | +// newenvy = -1; |
---|
| 11084 | + |
---|
| 11085 | + if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10936 | 11086 | { |
---|
10937 | | - LoadEnvy(newenvy); |
---|
| 11087 | + if (cubemaprgb == null) |
---|
| 11088 | + { |
---|
| 11089 | + cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11090 | + } |
---|
| 11091 | + |
---|
| 11092 | + cubemap = cubemaprgb; |
---|
10938 | 11093 | } |
---|
10939 | | - |
---|
10940 | | - newenvy = -1; |
---|
10941 | | - |
---|
| 11094 | + else |
---|
| 11095 | + { |
---|
| 11096 | + if (object.skyboxname != null) |
---|
| 11097 | + { |
---|
| 11098 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11099 | + { |
---|
| 11100 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11101 | + loadedskyboxname = object.skyboxname; |
---|
| 11102 | + } |
---|
| 11103 | + } |
---|
| 11104 | + else |
---|
| 11105 | + { |
---|
| 11106 | + cubemapcustom = null; |
---|
| 11107 | + loadedskyboxname = null; |
---|
| 11108 | + } |
---|
| 11109 | + |
---|
| 11110 | + cubemap = cubemapcustom; |
---|
| 11111 | + } |
---|
| 11112 | + |
---|
10942 | 11113 | ratio = ((double) getWidth()) / getHeight(); |
---|
10943 | 11114 | //System.out.println("ratio = " + ratio); |
---|
10944 | 11115 | |
---|
.. | .. |
---|
10954 | 11125 | |
---|
10955 | 11126 | if (!IsFrozen() && !ambientOcclusion) |
---|
10956 | 11127 | { |
---|
10957 | | - DrawSkyBox(gl); |
---|
| 11128 | + DrawSkyBox(gl, (float)ratio); |
---|
10958 | 11129 | } |
---|
10959 | 11130 | |
---|
10960 | 11131 | //if (selection_view == -1) |
---|
.. | .. |
---|
11240 | 11411 | |
---|
11241 | 11412 | // if (cam != lightCamera) |
---|
11242 | 11413 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11243 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11414 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11244 | 11415 | } |
---|
11245 | 11416 | |
---|
11246 | 11417 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11399 | 11570 | } |
---|
11400 | 11571 | } |
---|
11401 | 11572 | |
---|
11402 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11573 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11403 | 11574 | { |
---|
11404 | 11575 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11405 | 11576 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11407 | 11578 | |
---|
11408 | 11579 | boolean texon = textureon; |
---|
11409 | 11580 | |
---|
11410 | | - if (RENDERPROGRAM > 0) |
---|
11411 | | - { |
---|
11412 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11413 | | - textureon = false; |
---|
11414 | | - } |
---|
| 11581 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11582 | + textureon = false; |
---|
| 11583 | + |
---|
11415 | 11584 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11416 | 11585 | //System.out.println("ALLO"); |
---|
11417 | 11586 | gl.glColorMask(false, false, false, false); |
---|
11418 | 11587 | DrawObject(gl); |
---|
11419 | | - if (RENDERPROGRAM > 0) |
---|
11420 | | - { |
---|
11421 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11422 | | - textureon = texon; |
---|
11423 | | - } |
---|
| 11588 | + |
---|
| 11589 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11590 | + textureon = texon; |
---|
| 11591 | + |
---|
11424 | 11592 | gl.glColorMask(true, true, true, true); |
---|
11425 | 11593 | |
---|
11426 | 11594 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11427 | | - //gl.glDepthMask(false); |
---|
| 11595 | + gl.glDepthMask(false); |
---|
11428 | 11596 | } |
---|
11429 | 11597 | |
---|
11430 | 11598 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
12317 | 12485 | |
---|
12318 | 12486 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12319 | 12487 | |
---|
12320 | | - String program = |
---|
| 12488 | + String programmin = |
---|
| 12489 | + // Min shader |
---|
12321 | 12490 | "!!ARBfp1.0\n" + |
---|
| 12491 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12492 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12493 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12494 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12495 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12496 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12497 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12498 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12499 | + "TEMP temp;" + |
---|
| 12500 | + "TEMP light;" + |
---|
| 12501 | + "TEMP ndotl;" + |
---|
| 12502 | + "TEMP normal;" + |
---|
| 12503 | + "TEMP depth;" + |
---|
| 12504 | + "TEMP eye;" + |
---|
| 12505 | + "TEMP pos;" + |
---|
| 12506 | + |
---|
| 12507 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12508 | + Normalize("normal") + |
---|
| 12509 | + "MOV light, state.light[0].position;" + |
---|
| 12510 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12511 | + |
---|
| 12512 | + // shadow |
---|
| 12513 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12514 | + "MOV temp, pos;" + |
---|
| 12515 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12516 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12517 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12518 | + |
---|
| 12519 | + // No shadow when out of frustum |
---|
| 12520 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12521 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12522 | + |
---|
| 12523 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12524 | + |
---|
| 12525 | + // Backlit |
---|
| 12526 | + "MOV pos.w, zero123.y;" + |
---|
| 12527 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12528 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12529 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12530 | + Normalize("eye") + |
---|
| 12531 | + |
---|
| 12532 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12533 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12534 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12535 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12536 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12537 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12538 | + |
---|
| 12539 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12540 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12541 | + |
---|
| 12542 | + // Pigment |
---|
| 12543 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12544 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12545 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12546 | + |
---|
| 12547 | + "MUL temp, temp, zero123.z;" + |
---|
| 12548 | + |
---|
| 12549 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12550 | + |
---|
| 12551 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12552 | + "MOV result.color, temp;" + |
---|
| 12553 | + "END"; |
---|
| 12554 | + |
---|
| 12555 | + String programmax = |
---|
| 12556 | + "!!ARBfp1.0\n" + |
---|
| 12557 | + |
---|
12322 | 12558 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12323 | 12559 | "PARAM light2cam0 = program.env[10];" + |
---|
12324 | 12560 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12433 | 12669 | "TEMP shininess;" + |
---|
12434 | 12670 | "\n" + |
---|
12435 | 12671 | "MOV texSamp, one;" + |
---|
12436 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12437 | | - |
---|
| 12672 | + |
---|
12438 | 12673 | "MOV mapgrid.x, one2048th.x;" + |
---|
12439 | 12674 | "MOV temp, fragment.texcoord[1];" + |
---|
12440 | 12675 | /* |
---|
.. | .. |
---|
12455 | 12690 | "MUL temp, floor, mapgrid.x;" + |
---|
12456 | 12691 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12457 | 12692 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12458 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12693 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12459 | 12694 | "") + |
---|
12460 | 12695 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12461 | 12696 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12462 | 12697 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12463 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12698 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12464 | 12699 | "") + |
---|
12465 | 12700 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12466 | 12701 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12467 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12702 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12468 | 12703 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12469 | 12704 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12470 | 12705 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12471 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12706 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12472 | 12707 | "") + |
---|
12473 | 12708 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12474 | 12709 | //"MOV params, material;" + |
---|
.. | .. |
---|
12839 | 13074 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12840 | 13075 | "") + |
---|
12841 | 13076 | |
---|
12842 | | - // display shadow only (bump == 0) |
---|
| 13077 | + // display shadow only (fakedepth == 0) |
---|
12843 | 13078 | "SUB temp.x, half.x, shadow.x;" + |
---|
12844 | 13079 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12845 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13080 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12846 | 13081 | "SUB temp.y, one.x, temp.z;" + |
---|
12847 | 13082 | "MUL temp.x, temp.x, temp.y;" + |
---|
12848 | 13083 | "KIL temp.x;" + |
---|
.. | .. |
---|
13173 | 13408 | //once = true; |
---|
13174 | 13409 | } |
---|
13175 | 13410 | |
---|
| 13411 | + String program = programmax; |
---|
| 13412 | + |
---|
| 13413 | + if (Globals.MINSHADER) |
---|
| 13414 | + { |
---|
| 13415 | + program = programmin; |
---|
| 13416 | + } |
---|
| 13417 | + |
---|
13176 | 13418 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13177 | 13419 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13178 | 13420 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13266 | 13508 | return out; |
---|
13267 | 13509 | } |
---|
13268 | 13510 | |
---|
13269 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13511 | + // Also does frustum culling |
---|
| 13512 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13270 | 13513 | { |
---|
13271 | 13514 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13272 | 13515 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13273 | 13516 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13517 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13518 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13274 | 13519 | "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;" + |
---|
| 13520 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13521 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13279 | 13522 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13280 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13523 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13281 | 13524 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13282 | 13525 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13283 | 13526 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13284 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13527 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13285 | 13528 | |
---|
13286 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13287 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13529 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13530 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13288 | 13531 | } |
---|
13289 | 13532 | |
---|
13290 | 13533 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13331 | 13574 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13332 | 13575 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13333 | 13576 | |
---|
13334 | | - // No shadow when out of frustrum |
---|
| 13577 | + // No shadow when out of frustum |
---|
13335 | 13578 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13336 | 13579 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13337 | 13580 | ""; |
---|
.. | .. |
---|
14129 | 14372 | drag = false; |
---|
14130 | 14373 | //System.out.println("Mouse DOWN"); |
---|
14131 | 14374 | 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); |
---|
| 14375 | + //ClickInfo info = new ClickInfo(); |
---|
| 14376 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14377 | + object.clickInfo.pane = this; |
---|
| 14378 | + object.clickInfo.camera = renderCamera; |
---|
| 14379 | + object.clickInfo.x = x; |
---|
| 14380 | + object.clickInfo.y = y; |
---|
| 14381 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14382 | + editObj = object.doEditClick(//info, |
---|
| 14383 | + 0); |
---|
14140 | 14384 | if (!editObj) |
---|
14141 | 14385 | { |
---|
14142 | 14386 | hasMarquee = true; |
---|
.. | .. |
---|
14420 | 14664 | MODIFIERS |= COMMAND; |
---|
14421 | 14665 | /**/ |
---|
14422 | 14666 | if((mod&SHIFT) == SHIFT) |
---|
14423 | | - manipCamera.RotatePosition(0, -speed); |
---|
14424 | | - else |
---|
14425 | 14667 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14668 | + else |
---|
| 14669 | + manipCamera.RotatePosition(0, -speed); |
---|
14426 | 14670 | /**/ |
---|
14427 | 14671 | if ((mod & SHIFT) == SHIFT) |
---|
14428 | 14672 | { |
---|
.. | .. |
---|
14441 | 14685 | MODIFIERS |= COMMAND; |
---|
14442 | 14686 | /**/ |
---|
14443 | 14687 | if((mod&SHIFT) == SHIFT) |
---|
14444 | | - manipCamera.RotatePosition(0, speed); |
---|
14445 | | - else |
---|
14446 | 14688 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14689 | + else |
---|
| 14690 | + manipCamera.RotatePosition(0, speed); |
---|
14447 | 14691 | /**/ |
---|
14448 | 14692 | if ((mod & SHIFT) == SHIFT) |
---|
14449 | 14693 | { |
---|
.. | .. |
---|
14536 | 14780 | if (editObj) |
---|
14537 | 14781 | { |
---|
14538 | 14782 | drag = true; |
---|
14539 | | - ClickInfo info = new ClickInfo(); |
---|
14540 | | - info.bounds.setBounds(0, 0, |
---|
| 14783 | + //ClickInfo info = new ClickInfo(); |
---|
| 14784 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14541 | 14785 | (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); |
---|
| 14786 | + object.clickInfo.pane = this; |
---|
| 14787 | + object.clickInfo.camera = renderCamera; |
---|
| 14788 | + object.clickInfo.x = x; |
---|
| 14789 | + object.clickInfo.y = y; |
---|
| 14790 | + object //.GetWindow().copy |
---|
| 14791 | + .doEditDrag(//info, |
---|
| 14792 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14548 | 14793 | } else |
---|
14549 | 14794 | { |
---|
14550 | 14795 | if (x < startX) |
---|
.. | .. |
---|
14693 | 14938 | } |
---|
14694 | 14939 | } |
---|
14695 | 14940 | |
---|
| 14941 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14942 | + |
---|
14696 | 14943 | public void mouseMoved(MouseEvent e) |
---|
14697 | 14944 | { |
---|
14698 | 14945 | //System.out.println("mouseMoved: " + e); |
---|
14699 | 14946 | if (isRenderer) |
---|
14700 | 14947 | return; |
---|
14701 | 14948 | |
---|
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; |
---|
| 14949 | + // Mouse cursor feedback |
---|
| 14950 | + object.clickInfo.x = e.getX(); |
---|
| 14951 | + object.clickInfo.y = e.getY(); |
---|
| 14952 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14953 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14954 | + object.clickInfo.pane = this; |
---|
| 14955 | + object.clickInfo.camera = renderCamera; |
---|
14709 | 14956 | if (!isRenderer) |
---|
14710 | 14957 | { |
---|
14711 | 14958 | //ObjEditor editWindow = object.editWindow; |
---|
14712 | 14959 | //Object3D copy = editWindow.copy; |
---|
14713 | | - if (object.doEditClick(ci, 0)) |
---|
| 14960 | + if (object.doEditClick(//clickInfo, |
---|
| 14961 | + 0)) |
---|
14714 | 14962 | { |
---|
14715 | 14963 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14716 | 14964 | } else |
---|
.. | .. |
---|
15160 | 15408 | OCCLUSION_CULLING ^= true; |
---|
15161 | 15409 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15162 | 15410 | break; |
---|
15163 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15411 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15164 | 15412 | case '1': |
---|
15165 | 15413 | case '2': |
---|
15166 | 15414 | case '3': |
---|
15167 | 15415 | case '4': |
---|
15168 | 15416 | case '5': |
---|
15169 | | - newenvy = Character.getNumericValue(key); |
---|
15170 | | - repaint(); |
---|
15171 | | - break; |
---|
15172 | 15417 | case '6': |
---|
15173 | 15418 | case '7': |
---|
15174 | 15419 | case '8': |
---|
15175 | 15420 | case '9': |
---|
15176 | | - BGcolor = (key - '6')/3.f; |
---|
| 15421 | + if (true) // envyoff) |
---|
| 15422 | + { |
---|
| 15423 | + BGcolor = (key - '1')/8.f; |
---|
| 15424 | + } |
---|
| 15425 | + else |
---|
| 15426 | + { |
---|
| 15427 | + //newenvy = Character.getNumericValue(key); |
---|
| 15428 | + } |
---|
15177 | 15429 | repaint(); |
---|
15178 | 15430 | break; |
---|
15179 | 15431 | case '!': |
---|
.. | .. |
---|
15736 | 15988 | |
---|
15737 | 15989 | int width = getBounds().width; |
---|
15738 | 15990 | int height = getBounds().height; |
---|
15739 | | - ClickInfo info = new ClickInfo(); |
---|
15740 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15741 | 15991 | //Image img = CreateImage(width, height); |
---|
15742 | 15992 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15743 | 15993 | |
---|
.. | .. |
---|
15814 | 16064 | } |
---|
15815 | 16065 | if (object != null && !hasMarquee) |
---|
15816 | 16066 | { |
---|
| 16067 | + if (object.clickInfo == null) |
---|
| 16068 | + object.clickInfo = new ClickInfo(); |
---|
| 16069 | + ClickInfo info = object.clickInfo; |
---|
| 16070 | + //ClickInfo info = new ClickInfo(); |
---|
| 16071 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16072 | + |
---|
15817 | 16073 | if (isRenderer) |
---|
15818 | 16074 | { |
---|
15819 | | - info.flags++; |
---|
| 16075 | + object.clickInfo.flags++; |
---|
15820 | 16076 | double frameAspect = (double) width / (double) height; |
---|
15821 | 16077 | if (frameAspect > renderCamera.aspect) |
---|
15822 | 16078 | { |
---|
15823 | 16079 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15824 | | - info.bounds.width -= width - desired; |
---|
15825 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16080 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16081 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15826 | 16082 | } else |
---|
15827 | 16083 | { |
---|
15828 | 16084 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15829 | | - info.bounds.height -= height - desired; |
---|
15830 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16085 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16086 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15831 | 16087 | } |
---|
15832 | 16088 | } |
---|
15833 | 16089 | |
---|
15834 | | - info.g = gr; |
---|
15835 | | - info.camera = renderCamera; |
---|
| 16090 | + object.clickInfo.g = gr; |
---|
| 16091 | + object.clickInfo.camera = renderCamera; |
---|
15836 | 16092 | /* |
---|
15837 | 16093 | // Memory intensive (brep.verticescopy) |
---|
15838 | 16094 | if (!(object instanceof Composite)) |
---|
15839 | 16095 | object.draw(info, 0, false); // SLOW : |
---|
15840 | 16096 | */ |
---|
15841 | | - if (!isRenderer) |
---|
| 16097 | + if (!isRenderer) // && drag) |
---|
15842 | 16098 | { |
---|
15843 | 16099 | Grafreed.Assert(object != null); |
---|
15844 | 16100 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15846 | 16102 | { |
---|
15847 | 16103 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15848 | 16104 | |
---|
15849 | | - info.DX = 0; |
---|
15850 | | - info.DY = 0; |
---|
15851 | | - info.W = 1; |
---|
| 16105 | + object.clickInfo.DX = 0; |
---|
| 16106 | + object.clickInfo.DY = 0; |
---|
| 16107 | + object.clickInfo.W = 1; |
---|
15852 | 16108 | if (hitSomething == Object3D.hitCenter) |
---|
15853 | 16109 | { |
---|
15854 | 16110 | info.DX = X; |
---|
.. | .. |
---|
15860 | 16116 | info.DY -= info.bounds.height/2; |
---|
15861 | 16117 | } |
---|
15862 | 16118 | |
---|
15863 | | - object.drawEditHandles(info, 0); |
---|
| 16119 | + object.drawEditHandles(//info, |
---|
| 16120 | + 0); |
---|
15864 | 16121 | |
---|
15865 | 16122 | if (drag && (X != 0 || Y != 0)) |
---|
15866 | 16123 | { |
---|
.. | .. |
---|
16359 | 16616 | private /*static*/ boolean firstime; |
---|
16360 | 16617 | private /*static*/ cVector newView = new cVector(); |
---|
16361 | 16618 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16619 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16620 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16362 | 16621 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16363 | 16622 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16364 | 16623 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16371 | 16630 | { |
---|
16372 | 16631 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16373 | 16632 | |
---|
| 16633 | + int usedsuf = 0; |
---|
| 16634 | + |
---|
16374 | 16635 | for (int i = 0; i < suffixes.length; i++) |
---|
16375 | 16636 | { |
---|
16376 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16377 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16378 | | - mipmapped, |
---|
16379 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16380 | | - if (data == null) |
---|
| 16637 | + String[] suffixe = suffixes; |
---|
| 16638 | + String[] fallback = suffixes2; |
---|
| 16639 | + String[] fallfallback = suffixes3; |
---|
| 16640 | + |
---|
| 16641 | + for (int c=usedsuf; --c>=0;) |
---|
16381 | 16642 | { |
---|
16382 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16643 | +// String[] temp = suffixe; |
---|
| 16644 | +// suffixe = fallback; |
---|
| 16645 | +// fallback = fallfallback; |
---|
| 16646 | +// fallfallback = temp; |
---|
16383 | 16647 | } |
---|
| 16648 | + |
---|
| 16649 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16650 | + TextureData data; |
---|
| 16651 | + |
---|
| 16652 | + try |
---|
| 16653 | + { |
---|
| 16654 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16655 | + mipmapped, |
---|
| 16656 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16657 | + } |
---|
| 16658 | + catch (Exception e) |
---|
| 16659 | + { |
---|
| 16660 | + try |
---|
| 16661 | + { |
---|
| 16662 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16663 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16664 | + mipmapped, |
---|
| 16665 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16666 | + } |
---|
| 16667 | + catch (Exception e2) |
---|
| 16668 | + { |
---|
| 16669 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16670 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16671 | + mipmapped, |
---|
| 16672 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16673 | + } |
---|
| 16674 | + } |
---|
| 16675 | + |
---|
16384 | 16676 | //System.out.println("Target = " + targets[i]); |
---|
16385 | 16677 | cubemap.updateImage(data, targets[i]); |
---|
16386 | 16678 | } |
---|
16387 | 16679 | |
---|
16388 | 16680 | return cubemap; |
---|
16389 | 16681 | } |
---|
| 16682 | + |
---|
16390 | 16683 | int bigsphere = -1; |
---|
16391 | 16684 | |
---|
16392 | 16685 | float BGcolor = 0.5f; |
---|
16393 | 16686 | |
---|
16394 | | - private void DrawSkyBox(GL gl) |
---|
| 16687 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16688 | + |
---|
| 16689 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16395 | 16690 | { |
---|
16396 | | - if (envyoff || cubemap == null) |
---|
| 16691 | + if (//envyoff || |
---|
| 16692 | + WIREFRAME || |
---|
| 16693 | + cubemap == null) |
---|
16397 | 16694 | { |
---|
16398 | 16695 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16399 | 16696 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16408 | 16705 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16409 | 16706 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16410 | 16707 | gl.glLoadIdentity(); |
---|
| 16708 | + gl.glScalef(1,ratio,1); |
---|
16411 | 16709 | |
---|
| 16710 | +// colorV[0] = 2; |
---|
| 16711 | +// colorV[1] = 2; |
---|
| 16712 | +// colorV[2] = 2; |
---|
| 16713 | +// colorV[3] = 1; |
---|
| 16714 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16715 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16716 | +// |
---|
| 16717 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16718 | + |
---|
16412 | 16719 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16413 | 16720 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16414 | 16721 | |
---|
.. | .. |
---|
16440 | 16747 | { |
---|
16441 | 16748 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16442 | 16749 | } |
---|
| 16750 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16443 | 16751 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16444 | 16752 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16445 | 16753 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16698 | 17006 | //new Exception().printStackTrace(); |
---|
16699 | 17007 | System.out.println("select buffer init"); |
---|
16700 | 17008 | // Use debug pipeline |
---|
16701 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17009 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16702 | 17010 | |
---|
16703 | 17011 | GL gl = drawable.getGL(); |
---|
16704 | 17012 | |
---|
.. | .. |
---|
17244 | 17552 | gl.glFlush(); |
---|
17245 | 17553 | |
---|
17246 | 17554 | /**/ |
---|
17247 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17555 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17248 | 17556 | |
---|
17249 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17557 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17250 | 17558 | |
---|
| 17559 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17560 | + |
---|
| 17561 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17562 | + |
---|
17251 | 17563 | double r = 0, g = 0, b = 0; |
---|
17252 | 17564 | |
---|
17253 | 17565 | double count = 0; |
---|
.. | .. |
---|
17258 | 17570 | |
---|
17259 | 17571 | double FACTOR = 1; |
---|
17260 | 17572 | |
---|
17261 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17573 | + for (int i = 0; i < depths.length; i++) |
---|
17262 | 17574 | { |
---|
17263 | 17575 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17264 | 17576 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17341 | 17653 | |
---|
17342 | 17654 | double scale = ray.z; // 1; // cos |
---|
17343 | 17655 | |
---|
17344 | | - float depth = pixels[newindex]; |
---|
| 17656 | + float depth = depths[newindex]; |
---|
17345 | 17657 | |
---|
17346 | 17658 | /* |
---|
17347 | 17659 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17538 | 17850 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17539 | 17851 | static IntBuffer bigAAbuffer; |
---|
17540 | 17852 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17541 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17853 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17542 | 17854 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17543 | 17855 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17544 | 17856 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17545 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17857 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17858 | + |
---|
| 17859 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17860 | + |
---|
17546 | 17861 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17547 | 17862 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17548 | 17863 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|