.. | .. |
---|
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; |
---|
.. | .. |
---|
183 | 187 | } |
---|
184 | 188 | |
---|
185 | 189 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 190 | + |
---|
| 191 | + public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 192 | + { |
---|
| 193 | + try |
---|
| 194 | + { |
---|
| 195 | + cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 196 | + } catch (IOException e) |
---|
| 197 | + { |
---|
| 198 | + System.out.println("NAME = " + name); |
---|
| 199 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 200 | + } |
---|
| 201 | + } |
---|
186 | 202 | |
---|
187 | 203 | void SetAsGLRenderer(boolean b) |
---|
188 | 204 | { |
---|
.. | .. |
---|
202 | 218 | |
---|
203 | 219 | SetCamera(cam); |
---|
204 | 220 | |
---|
205 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 221 | + // Warning: not used. |
---|
| 222 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
206 | 223 | |
---|
207 | 224 | object = o; |
---|
208 | 225 | |
---|
.. | .. |
---|
1480 | 1497 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1481 | 1498 | } |
---|
1482 | 1499 | |
---|
| 1500 | + float[] colorV = new float[4]; |
---|
| 1501 | + |
---|
1483 | 1502 | void SetColor(Object3D obj, Vertex p0) |
---|
1484 | 1503 | { |
---|
1485 | 1504 | CameraPane display = this; |
---|
.. | .. |
---|
1547 | 1566 | { |
---|
1548 | 1567 | return; |
---|
1549 | 1568 | } |
---|
1550 | | - |
---|
1551 | | - float[] colorV = new float[3]; |
---|
1552 | 1569 | |
---|
1553 | 1570 | if (false) // marked) |
---|
1554 | 1571 | { |
---|
.. | .. |
---|
8358 | 8375 | { |
---|
8359 | 8376 | TextureData texturedata = null; |
---|
8360 | 8377 | |
---|
8361 | | - if (texdata != null) |
---|
| 8378 | + if (texdata != null && textureon) |
---|
8362 | 8379 | { |
---|
8363 | | - BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8380 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
8364 | 8381 | |
---|
8365 | | - CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8382 | + try |
---|
| 8383 | + { |
---|
| 8384 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8385 | + } |
---|
| 8386 | + catch (Exception e) |
---|
| 8387 | + { |
---|
| 8388 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8389 | + } |
---|
8366 | 8390 | |
---|
8367 | 8391 | texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
8368 | 8392 | bimtextures.put(texdata, texturecache); |
---|
| 8393 | + |
---|
| 8394 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8395 | + |
---|
| 8396 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8397 | + //bim2 = bim; |
---|
8369 | 8398 | } |
---|
8370 | 8399 | else |
---|
8371 | 8400 | if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
.. | .. |
---|
8560 | 8589 | { |
---|
8561 | 8590 | if (tex.pigmentdata == null) |
---|
8562 | 8591 | { |
---|
8563 | | - String texname = Object3D.GetPigment(tex); |
---|
| 8592 | + //String texname = Object3D.GetPigment(tex); |
---|
8564 | 8593 | |
---|
8565 | 8594 | CacheTexture texturecache = texturepigment.get(tex); |
---|
8566 | 8595 | |
---|
8567 | 8596 | if (texturecache != null) |
---|
8568 | 8597 | { |
---|
8569 | | - tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); |
---|
8570 | 8598 | tex.pw = texturecache.texturedata.getWidth(); |
---|
8571 | 8599 | tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8600 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8601 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8602 | + ; |
---|
| 8603 | + //, tex.pw, tex.ph), 0.5f); |
---|
8572 | 8604 | } |
---|
8573 | 8605 | } |
---|
8574 | 8606 | |
---|
8575 | 8607 | if (tex.bumpdata == null) |
---|
8576 | 8608 | { |
---|
8577 | | - String texname = Object3D.GetBump(tex); |
---|
| 8609 | + //String texname = Object3D.GetBump(tex); |
---|
8578 | 8610 | |
---|
8579 | 8611 | CacheTexture texturecache = texturebump.get(tex); |
---|
8580 | 8612 | |
---|
8581 | 8613 | if (texturecache != null) |
---|
8582 | 8614 | { |
---|
8583 | | - tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array(); |
---|
8584 | 8615 | tex.bw = texturecache.texturedata.getWidth(); |
---|
8585 | 8616 | tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8617 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
8586 | 8618 | } |
---|
8587 | 8619 | } |
---|
8588 | 8620 | } |
---|
.. | .. |
---|
8654 | 8686 | return true; // Warning: not used. |
---|
8655 | 8687 | } |
---|
8656 | 8688 | |
---|
| 8689 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8690 | + { |
---|
| 8691 | + try |
---|
| 8692 | + { |
---|
| 8693 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8694 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8695 | + ImageWriter writer = writers.next(); |
---|
| 8696 | + |
---|
| 8697 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8698 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8699 | + param.setCompressionQuality(quality); |
---|
| 8700 | + |
---|
| 8701 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8702 | + writer.setOutput(ios); |
---|
| 8703 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8704 | + |
---|
| 8705 | + byte[] data = baos.toByteArray(); |
---|
| 8706 | + writer.dispose(); |
---|
| 8707 | + return data; |
---|
| 8708 | + } |
---|
| 8709 | + catch (Exception e) |
---|
| 8710 | + { |
---|
| 8711 | + e.printStackTrace(); |
---|
| 8712 | + return null; |
---|
| 8713 | + } |
---|
| 8714 | + } |
---|
| 8715 | + |
---|
| 8716 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8717 | + { |
---|
| 8718 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8719 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8720 | + ImageReader reader = writers.next(); |
---|
| 8721 | + |
---|
| 8722 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8723 | + |
---|
| 8724 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8725 | + param.setDestination(bim); |
---|
| 8726 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8727 | + |
---|
| 8728 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8729 | + reader.setInput(ios); |
---|
| 8730 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8731 | + reader.dispose(); |
---|
| 8732 | + |
---|
| 8733 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8734 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8735 | +// byte[] bytes = data.getData(); |
---|
| 8736 | +// |
---|
| 8737 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8738 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8739 | +// { |
---|
| 8740 | +// int i3 = i*3; |
---|
| 8741 | +// pixels[i] = 0xFF; |
---|
| 8742 | +// pixels[i] <<= 8; |
---|
| 8743 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8744 | +// pixels[i] <<= 8; |
---|
| 8745 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8746 | +// pixels[i] <<= 8; |
---|
| 8747 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8748 | +// } |
---|
| 8749 | +// |
---|
| 8750 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8751 | + |
---|
| 8752 | + return bim; |
---|
| 8753 | + } |
---|
| 8754 | + |
---|
8657 | 8755 | ShadowBuffer shadowPBuf; |
---|
8658 | 8756 | AntialiasBuffer antialiasPBuf; |
---|
8659 | 8757 | int MAXSTACK; |
---|
.. | .. |
---|
8846 | 8944 | |
---|
8847 | 8945 | if (cubemap == null) |
---|
8848 | 8946 | { |
---|
8849 | | - LoadEnvy(5); |
---|
| 8947 | + //LoadEnvy(1); |
---|
8850 | 8948 | } |
---|
8851 | 8949 | |
---|
8852 | 8950 | //cubemap.enable(); |
---|
.. | .. |
---|
9133 | 9231 | cubemap = null; |
---|
9134 | 9232 | return; |
---|
9135 | 9233 | case 1: |
---|
9136 | | - name = "cubemaps/box_"; |
---|
9137 | | - ext = "png"; |
---|
| 9234 | + name = "cubemaps/rgb/"; |
---|
| 9235 | + ext = "jpg"; |
---|
9138 | 9236 | reverseUP = false; |
---|
9139 | 9237 | break; |
---|
9140 | 9238 | case 2: |
---|
9141 | | - name = "cubemaps/uffizi_"; |
---|
9142 | | - ext = "png"; |
---|
9143 | | - break; // reverseUP = true; break; |
---|
| 9239 | + name = "cubemaps/uffizi/"; |
---|
| 9240 | + ext = "jpg"; |
---|
| 9241 | + reverseUP = false; |
---|
| 9242 | + break; |
---|
9144 | 9243 | case 3: |
---|
9145 | | - name = "cubemaps/CloudyHills_"; |
---|
9146 | | - ext = "tga"; |
---|
| 9244 | + name = "cubemaps/CloudyHills/"; |
---|
| 9245 | + ext = "jpg"; |
---|
9147 | 9246 | reverseUP = false; |
---|
9148 | 9247 | break; |
---|
9149 | 9248 | case 4: |
---|
9150 | | - name = "cubemaps/cornell_"; |
---|
| 9249 | + name = "cubemaps/cornell/"; |
---|
9151 | 9250 | ext = "png"; |
---|
9152 | 9251 | reverseUP = false; |
---|
9153 | 9252 | break; |
---|
| 9253 | + case 5: |
---|
| 9254 | + name = "cubemaps/skycube/"; |
---|
| 9255 | + ext = "jpg"; |
---|
| 9256 | + reverseUP = false; |
---|
| 9257 | + break; |
---|
| 9258 | + case 6: |
---|
| 9259 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9260 | + ext = "jpg"; |
---|
| 9261 | + reverseUP = false; |
---|
| 9262 | + break; |
---|
| 9263 | + case 7: |
---|
| 9264 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9265 | + ext = "jpg"; |
---|
| 9266 | + reverseUP = false; |
---|
| 9267 | + break; |
---|
| 9268 | + case 8: |
---|
| 9269 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9270 | + ext = "jpg"; |
---|
| 9271 | + reverseUP = false; |
---|
| 9272 | + break; |
---|
| 9273 | + case 9: |
---|
| 9274 | + name = "cubemaps/UnionSquare/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
9154 | 9278 | default: |
---|
9155 | | - name = "cubemaps/rgb_"; |
---|
9156 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9279 | + name = "cubemaps/box/"; |
---|
| 9280 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9281 | + reverseUP = false; |
---|
9157 | 9282 | break; |
---|
9158 | 9283 | } |
---|
9159 | | - |
---|
9160 | | - try |
---|
9161 | | - { |
---|
9162 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9163 | | - } catch (IOException e) |
---|
9164 | | - { |
---|
9165 | | - throw new RuntimeException(e); |
---|
9166 | | - } |
---|
| 9284 | + |
---|
| 9285 | + LoadSkybox(name, ext, mipmap); |
---|
9167 | 9286 | } |
---|
9168 | 9287 | |
---|
9169 | 9288 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9195 | 9314 | static double[] model = new double[16]; |
---|
9196 | 9315 | double[] camera2light = new double[16]; |
---|
9197 | 9316 | double[] light2camera = new double[16]; |
---|
9198 | | - int newenvy = -1; |
---|
9199 | | - boolean envyoff = true; // false; |
---|
| 9317 | + |
---|
| 9318 | + //int newenvy = -1; |
---|
| 9319 | + //boolean envyoff = false; |
---|
| 9320 | + |
---|
| 9321 | + String loadedskyboxname; |
---|
| 9322 | + |
---|
9200 | 9323 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9201 | 9324 | //float[] light0 = { 0,0,0 }; |
---|
9202 | 9325 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9614 | 9737 | |
---|
9615 | 9738 | if (renderCamera != lightCamera) |
---|
9616 | 9739 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9617 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9740 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9618 | 9741 | |
---|
9619 | 9742 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9620 | 9743 | |
---|
.. | .. |
---|
9630 | 9753 | |
---|
9631 | 9754 | if (renderCamera != lightCamera) |
---|
9632 | 9755 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9633 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9756 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9634 | 9757 | |
---|
9635 | 9758 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9636 | 9759 | |
---|
.. | .. |
---|
9676 | 9799 | rati = 1 / rati; |
---|
9677 | 9800 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9678 | 9801 | } |
---|
9679 | | - assert (newenvy == -1); |
---|
| 9802 | + |
---|
| 9803 | + //assert (newenvy == -1); |
---|
| 9804 | + |
---|
9680 | 9805 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9681 | 9806 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9682 | | - DrawSkyBox(gl); |
---|
| 9807 | + DrawSkyBox(gl, (float)rati); |
---|
9683 | 9808 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9684 | 9809 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9685 | 9810 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10831 | 10956 | // if (parentcam != renderCamera) // not a light |
---|
10832 | 10957 | if (cam != lightCamera) |
---|
10833 | 10958 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10834 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10959 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10835 | 10960 | |
---|
10836 | 10961 | for (int j = 0; j < 4; j++) |
---|
10837 | 10962 | { |
---|
.. | .. |
---|
10846 | 10971 | // if (parentcam != renderCamera) // not a light |
---|
10847 | 10972 | if (cam != lightCamera) |
---|
10848 | 10973 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10849 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10974 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10850 | 10975 | |
---|
10851 | 10976 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10852 | 10977 | |
---|
.. | .. |
---|
10932 | 11057 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10933 | 11058 | } |
---|
10934 | 11059 | |
---|
10935 | | - if (newenvy > -1) |
---|
| 11060 | +// if (newenvy > -1) |
---|
| 11061 | +// { |
---|
| 11062 | +// LoadEnvy(newenvy); |
---|
| 11063 | +// } |
---|
| 11064 | +// |
---|
| 11065 | +// newenvy = -1; |
---|
| 11066 | + |
---|
| 11067 | + if (object.skyboxname != null) |
---|
10936 | 11068 | { |
---|
10937 | | - LoadEnvy(newenvy); |
---|
| 11069 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11070 | + { |
---|
| 11071 | + LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11072 | + loadedskyboxname = object.skyboxname; |
---|
| 11073 | + } |
---|
10938 | 11074 | } |
---|
10939 | | - |
---|
10940 | | - newenvy = -1; |
---|
10941 | | - |
---|
| 11075 | + else |
---|
| 11076 | + { |
---|
| 11077 | + cubemap = null; |
---|
| 11078 | + loadedskyboxname = null; |
---|
| 11079 | + } |
---|
| 11080 | + |
---|
10942 | 11081 | ratio = ((double) getWidth()) / getHeight(); |
---|
10943 | 11082 | //System.out.println("ratio = " + ratio); |
---|
10944 | 11083 | |
---|
.. | .. |
---|
10954 | 11093 | |
---|
10955 | 11094 | if (!IsFrozen() && !ambientOcclusion) |
---|
10956 | 11095 | { |
---|
10957 | | - DrawSkyBox(gl); |
---|
| 11096 | + DrawSkyBox(gl, (float)ratio); |
---|
10958 | 11097 | } |
---|
10959 | 11098 | |
---|
10960 | 11099 | //if (selection_view == -1) |
---|
.. | .. |
---|
11240 | 11379 | |
---|
11241 | 11380 | // if (cam != lightCamera) |
---|
11242 | 11381 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11243 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11382 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11244 | 11383 | } |
---|
11245 | 11384 | |
---|
11246 | 11385 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11399 | 11538 | } |
---|
11400 | 11539 | } |
---|
11401 | 11540 | |
---|
11402 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11541 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11403 | 11542 | { |
---|
11404 | 11543 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11405 | 11544 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11407 | 11546 | |
---|
11408 | 11547 | boolean texon = textureon; |
---|
11409 | 11548 | |
---|
11410 | | - if (RENDERPROGRAM > 0) |
---|
11411 | | - { |
---|
11412 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11413 | | - textureon = false; |
---|
11414 | | - } |
---|
| 11549 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11550 | + textureon = false; |
---|
| 11551 | + |
---|
11415 | 11552 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11416 | 11553 | //System.out.println("ALLO"); |
---|
11417 | 11554 | gl.glColorMask(false, false, false, false); |
---|
11418 | 11555 | DrawObject(gl); |
---|
11419 | | - if (RENDERPROGRAM > 0) |
---|
11420 | | - { |
---|
11421 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11422 | | - textureon = texon; |
---|
11423 | | - } |
---|
| 11556 | + |
---|
| 11557 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11558 | + textureon = texon; |
---|
| 11559 | + |
---|
11424 | 11560 | gl.glColorMask(true, true, true, true); |
---|
11425 | 11561 | |
---|
11426 | 11562 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11427 | | - //gl.glDepthMask(false); |
---|
| 11563 | + gl.glDepthMask(false); |
---|
11428 | 11564 | } |
---|
11429 | 11565 | |
---|
11430 | 11566 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
12317 | 12453 | |
---|
12318 | 12454 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12319 | 12455 | |
---|
12320 | | - String program = |
---|
| 12456 | + String programmin = |
---|
| 12457 | + // Min shader |
---|
12321 | 12458 | "!!ARBfp1.0\n" + |
---|
| 12459 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12460 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12461 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12462 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12463 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12464 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12465 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12466 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12467 | + "TEMP temp;" + |
---|
| 12468 | + "TEMP light;" + |
---|
| 12469 | + "TEMP ndotl;" + |
---|
| 12470 | + "TEMP normal;" + |
---|
| 12471 | + "TEMP depth;" + |
---|
| 12472 | + "TEMP eye;" + |
---|
| 12473 | + "TEMP pos;" + |
---|
| 12474 | + |
---|
| 12475 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12476 | + Normalize("normal") + |
---|
| 12477 | + "MOV light, state.light[0].position;" + |
---|
| 12478 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12479 | + |
---|
| 12480 | + // shadow |
---|
| 12481 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12482 | + "MOV temp, pos;" + |
---|
| 12483 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12484 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12485 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12486 | + |
---|
| 12487 | + // No shadow when out of frustum |
---|
| 12488 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12489 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12490 | + |
---|
| 12491 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12492 | + |
---|
| 12493 | + // Backlit |
---|
| 12494 | + "MOV pos.w, zero123.y;" + |
---|
| 12495 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12496 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12497 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12498 | + Normalize("eye") + |
---|
| 12499 | + |
---|
| 12500 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12501 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12502 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12503 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12504 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12505 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12506 | + |
---|
| 12507 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12508 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12509 | + |
---|
| 12510 | + // Pigment |
---|
| 12511 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12512 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12513 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12514 | + |
---|
| 12515 | + "MUL temp, temp, zero123.z;" + |
---|
| 12516 | + |
---|
| 12517 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12518 | + |
---|
| 12519 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12520 | + "MOV result.color, temp;" + |
---|
| 12521 | + "END"; |
---|
| 12522 | + |
---|
| 12523 | + String programmax = |
---|
| 12524 | + "!!ARBfp1.0\n" + |
---|
| 12525 | + |
---|
12322 | 12526 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12323 | 12527 | "PARAM light2cam0 = program.env[10];" + |
---|
12324 | 12528 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12433 | 12637 | "TEMP shininess;" + |
---|
12434 | 12638 | "\n" + |
---|
12435 | 12639 | "MOV texSamp, one;" + |
---|
12436 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12437 | | - |
---|
| 12640 | + |
---|
12438 | 12641 | "MOV mapgrid.x, one2048th.x;" + |
---|
12439 | 12642 | "MOV temp, fragment.texcoord[1];" + |
---|
12440 | 12643 | /* |
---|
.. | .. |
---|
12455 | 12658 | "MUL temp, floor, mapgrid.x;" + |
---|
12456 | 12659 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12457 | 12660 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12458 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12661 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12459 | 12662 | "") + |
---|
12460 | 12663 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12461 | 12664 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12462 | 12665 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12463 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12666 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12464 | 12667 | "") + |
---|
12465 | 12668 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12466 | 12669 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12467 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12670 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12468 | 12671 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12469 | 12672 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12470 | 12673 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12471 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12674 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12472 | 12675 | "") + |
---|
12473 | 12676 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12474 | 12677 | //"MOV params, material;" + |
---|
.. | .. |
---|
12839 | 13042 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12840 | 13043 | "") + |
---|
12841 | 13044 | |
---|
12842 | | - // display shadow only (bump == 0) |
---|
| 13045 | + // display shadow only (fakedepth == 0) |
---|
12843 | 13046 | "SUB temp.x, half.x, shadow.x;" + |
---|
12844 | 13047 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12845 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13048 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12846 | 13049 | "SUB temp.y, one.x, temp.z;" + |
---|
12847 | 13050 | "MUL temp.x, temp.x, temp.y;" + |
---|
12848 | 13051 | "KIL temp.x;" + |
---|
.. | .. |
---|
13173 | 13376 | //once = true; |
---|
13174 | 13377 | } |
---|
13175 | 13378 | |
---|
| 13379 | + String program = programmax; |
---|
| 13380 | + |
---|
| 13381 | + if (Globals.MINSHADER) |
---|
| 13382 | + { |
---|
| 13383 | + program = programmin; |
---|
| 13384 | + } |
---|
| 13385 | + |
---|
13176 | 13386 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13177 | 13387 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13178 | 13388 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13266 | 13476 | return out; |
---|
13267 | 13477 | } |
---|
13268 | 13478 | |
---|
13269 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13479 | + // Also does frustum culling |
---|
| 13480 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13270 | 13481 | { |
---|
13271 | 13482 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13272 | 13483 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13273 | 13484 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13485 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13486 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13274 | 13487 | "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;" + |
---|
| 13488 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13489 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13279 | 13490 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13280 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13491 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13281 | 13492 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13282 | 13493 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13283 | 13494 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13284 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13495 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13285 | 13496 | |
---|
13286 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13287 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13497 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13498 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13288 | 13499 | } |
---|
13289 | 13500 | |
---|
13290 | 13501 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13331 | 13542 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13332 | 13543 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13333 | 13544 | |
---|
13334 | | - // No shadow when out of frustrum |
---|
| 13545 | + // No shadow when out of frustum |
---|
13335 | 13546 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13336 | 13547 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13337 | 13548 | ""; |
---|
.. | .. |
---|
14129 | 14340 | drag = false; |
---|
14130 | 14341 | //System.out.println("Mouse DOWN"); |
---|
14131 | 14342 | 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); |
---|
| 14343 | + //ClickInfo info = new ClickInfo(); |
---|
| 14344 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14345 | + object.clickInfo.pane = this; |
---|
| 14346 | + object.clickInfo.camera = renderCamera; |
---|
| 14347 | + object.clickInfo.x = x; |
---|
| 14348 | + object.clickInfo.y = y; |
---|
| 14349 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14350 | + editObj = object.doEditClick(//info, |
---|
| 14351 | + 0); |
---|
14140 | 14352 | if (!editObj) |
---|
14141 | 14353 | { |
---|
14142 | 14354 | hasMarquee = true; |
---|
.. | .. |
---|
14420 | 14632 | MODIFIERS |= COMMAND; |
---|
14421 | 14633 | /**/ |
---|
14422 | 14634 | if((mod&SHIFT) == SHIFT) |
---|
14423 | | - manipCamera.RotatePosition(0, -speed); |
---|
14424 | | - else |
---|
14425 | 14635 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14636 | + else |
---|
| 14637 | + manipCamera.RotatePosition(0, -speed); |
---|
14426 | 14638 | /**/ |
---|
14427 | 14639 | if ((mod & SHIFT) == SHIFT) |
---|
14428 | 14640 | { |
---|
.. | .. |
---|
14441 | 14653 | MODIFIERS |= COMMAND; |
---|
14442 | 14654 | /**/ |
---|
14443 | 14655 | if((mod&SHIFT) == SHIFT) |
---|
14444 | | - manipCamera.RotatePosition(0, speed); |
---|
14445 | | - else |
---|
14446 | 14656 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14657 | + else |
---|
| 14658 | + manipCamera.RotatePosition(0, speed); |
---|
14447 | 14659 | /**/ |
---|
14448 | 14660 | if ((mod & SHIFT) == SHIFT) |
---|
14449 | 14661 | { |
---|
.. | .. |
---|
14536 | 14748 | if (editObj) |
---|
14537 | 14749 | { |
---|
14538 | 14750 | drag = true; |
---|
14539 | | - ClickInfo info = new ClickInfo(); |
---|
14540 | | - info.bounds.setBounds(0, 0, |
---|
| 14751 | + //ClickInfo info = new ClickInfo(); |
---|
| 14752 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14541 | 14753 | (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); |
---|
| 14754 | + object.clickInfo.pane = this; |
---|
| 14755 | + object.clickInfo.camera = renderCamera; |
---|
| 14756 | + object.clickInfo.x = x; |
---|
| 14757 | + object.clickInfo.y = y; |
---|
| 14758 | + object //.GetWindow().copy |
---|
| 14759 | + .doEditDrag(//info, |
---|
| 14760 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14548 | 14761 | } else |
---|
14549 | 14762 | { |
---|
14550 | 14763 | if (x < startX) |
---|
.. | .. |
---|
14693 | 14906 | } |
---|
14694 | 14907 | } |
---|
14695 | 14908 | |
---|
| 14909 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14910 | + |
---|
14696 | 14911 | public void mouseMoved(MouseEvent e) |
---|
14697 | 14912 | { |
---|
14698 | 14913 | //System.out.println("mouseMoved: " + e); |
---|
14699 | 14914 | if (isRenderer) |
---|
14700 | 14915 | return; |
---|
14701 | 14916 | |
---|
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; |
---|
| 14917 | + // Mouse cursor feedback |
---|
| 14918 | + object.clickInfo.x = e.getX(); |
---|
| 14919 | + object.clickInfo.y = e.getY(); |
---|
| 14920 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14921 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14922 | + object.clickInfo.pane = this; |
---|
| 14923 | + object.clickInfo.camera = renderCamera; |
---|
14709 | 14924 | if (!isRenderer) |
---|
14710 | 14925 | { |
---|
14711 | 14926 | //ObjEditor editWindow = object.editWindow; |
---|
14712 | 14927 | //Object3D copy = editWindow.copy; |
---|
14713 | | - if (object.doEditClick(ci, 0)) |
---|
| 14928 | + if (object.doEditClick(//clickInfo, |
---|
| 14929 | + 0)) |
---|
14714 | 14930 | { |
---|
14715 | 14931 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14716 | 14932 | } else |
---|
.. | .. |
---|
15160 | 15376 | OCCLUSION_CULLING ^= true; |
---|
15161 | 15377 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15162 | 15378 | break; |
---|
15163 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15379 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15164 | 15380 | case '1': |
---|
15165 | 15381 | case '2': |
---|
15166 | 15382 | case '3': |
---|
15167 | 15383 | case '4': |
---|
15168 | 15384 | case '5': |
---|
15169 | | - newenvy = Character.getNumericValue(key); |
---|
15170 | | - repaint(); |
---|
15171 | | - break; |
---|
15172 | 15385 | case '6': |
---|
15173 | 15386 | case '7': |
---|
15174 | 15387 | case '8': |
---|
15175 | 15388 | case '9': |
---|
15176 | | - BGcolor = (key - '6')/3.f; |
---|
| 15389 | + if (true) // envyoff) |
---|
| 15390 | + { |
---|
| 15391 | + BGcolor = (key - '1')/8.f; |
---|
| 15392 | + } |
---|
| 15393 | + else |
---|
| 15394 | + { |
---|
| 15395 | + //newenvy = Character.getNumericValue(key); |
---|
| 15396 | + } |
---|
15177 | 15397 | repaint(); |
---|
15178 | 15398 | break; |
---|
15179 | 15399 | case '!': |
---|
.. | .. |
---|
15736 | 15956 | |
---|
15737 | 15957 | int width = getBounds().width; |
---|
15738 | 15958 | int height = getBounds().height; |
---|
15739 | | - ClickInfo info = new ClickInfo(); |
---|
15740 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15741 | 15959 | //Image img = CreateImage(width, height); |
---|
15742 | 15960 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15743 | 15961 | |
---|
.. | .. |
---|
15814 | 16032 | } |
---|
15815 | 16033 | if (object != null && !hasMarquee) |
---|
15816 | 16034 | { |
---|
| 16035 | + if (object.clickInfo == null) |
---|
| 16036 | + object.clickInfo = new ClickInfo(); |
---|
| 16037 | + ClickInfo info = object.clickInfo; |
---|
| 16038 | + //ClickInfo info = new ClickInfo(); |
---|
| 16039 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16040 | + |
---|
15817 | 16041 | if (isRenderer) |
---|
15818 | 16042 | { |
---|
15819 | | - info.flags++; |
---|
| 16043 | + object.clickInfo.flags++; |
---|
15820 | 16044 | double frameAspect = (double) width / (double) height; |
---|
15821 | 16045 | if (frameAspect > renderCamera.aspect) |
---|
15822 | 16046 | { |
---|
15823 | 16047 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15824 | | - info.bounds.width -= width - desired; |
---|
15825 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16048 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16049 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15826 | 16050 | } else |
---|
15827 | 16051 | { |
---|
15828 | 16052 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15829 | | - info.bounds.height -= height - desired; |
---|
15830 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16053 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16054 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15831 | 16055 | } |
---|
15832 | 16056 | } |
---|
15833 | 16057 | |
---|
15834 | | - info.g = gr; |
---|
15835 | | - info.camera = renderCamera; |
---|
| 16058 | + object.clickInfo.g = gr; |
---|
| 16059 | + object.clickInfo.camera = renderCamera; |
---|
15836 | 16060 | /* |
---|
15837 | 16061 | // Memory intensive (brep.verticescopy) |
---|
15838 | 16062 | if (!(object instanceof Composite)) |
---|
15839 | 16063 | object.draw(info, 0, false); // SLOW : |
---|
15840 | 16064 | */ |
---|
15841 | | - if (!isRenderer) |
---|
| 16065 | + if (!isRenderer) // && drag) |
---|
15842 | 16066 | { |
---|
15843 | 16067 | Grafreed.Assert(object != null); |
---|
15844 | 16068 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15846 | 16070 | { |
---|
15847 | 16071 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15848 | 16072 | |
---|
15849 | | - info.DX = 0; |
---|
15850 | | - info.DY = 0; |
---|
15851 | | - info.W = 1; |
---|
| 16073 | + object.clickInfo.DX = 0; |
---|
| 16074 | + object.clickInfo.DY = 0; |
---|
| 16075 | + object.clickInfo.W = 1; |
---|
15852 | 16076 | if (hitSomething == Object3D.hitCenter) |
---|
15853 | 16077 | { |
---|
15854 | 16078 | info.DX = X; |
---|
.. | .. |
---|
15860 | 16084 | info.DY -= info.bounds.height/2; |
---|
15861 | 16085 | } |
---|
15862 | 16086 | |
---|
15863 | | - object.drawEditHandles(info, 0); |
---|
| 16087 | + object.drawEditHandles(//info, |
---|
| 16088 | + 0); |
---|
15864 | 16089 | |
---|
15865 | 16090 | if (drag && (X != 0 || Y != 0)) |
---|
15866 | 16091 | { |
---|
.. | .. |
---|
16359 | 16584 | private /*static*/ boolean firstime; |
---|
16360 | 16585 | private /*static*/ cVector newView = new cVector(); |
---|
16361 | 16586 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16587 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16588 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16362 | 16589 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16363 | 16590 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16364 | 16591 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16371 | 16598 | { |
---|
16372 | 16599 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16373 | 16600 | |
---|
| 16601 | + int usedsuf = 0; |
---|
| 16602 | + |
---|
16374 | 16603 | for (int i = 0; i < suffixes.length; i++) |
---|
16375 | 16604 | { |
---|
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) |
---|
| 16605 | + String[] suffixe = suffixes; |
---|
| 16606 | + String[] fallback = suffixes2; |
---|
| 16607 | + String[] fallfallback = suffixes3; |
---|
| 16608 | + |
---|
| 16609 | + for (int c=usedsuf; --c>=0;) |
---|
16381 | 16610 | { |
---|
16382 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16611 | +// String[] temp = suffixe; |
---|
| 16612 | +// suffixe = fallback; |
---|
| 16613 | +// fallback = fallfallback; |
---|
| 16614 | +// fallfallback = temp; |
---|
16383 | 16615 | } |
---|
| 16616 | + |
---|
| 16617 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16618 | + TextureData data; |
---|
| 16619 | + |
---|
| 16620 | + try |
---|
| 16621 | + { |
---|
| 16622 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16623 | + mipmapped, |
---|
| 16624 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16625 | + } |
---|
| 16626 | + catch (Exception e) |
---|
| 16627 | + { |
---|
| 16628 | + try |
---|
| 16629 | + { |
---|
| 16630 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16631 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16632 | + mipmapped, |
---|
| 16633 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16634 | + } |
---|
| 16635 | + catch (Exception e2) |
---|
| 16636 | + { |
---|
| 16637 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16638 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16639 | + mipmapped, |
---|
| 16640 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16641 | + } |
---|
| 16642 | + } |
---|
| 16643 | + |
---|
16384 | 16644 | //System.out.println("Target = " + targets[i]); |
---|
16385 | 16645 | cubemap.updateImage(data, targets[i]); |
---|
16386 | 16646 | } |
---|
16387 | 16647 | |
---|
16388 | 16648 | return cubemap; |
---|
16389 | 16649 | } |
---|
| 16650 | + |
---|
16390 | 16651 | int bigsphere = -1; |
---|
16391 | 16652 | |
---|
16392 | 16653 | float BGcolor = 0.5f; |
---|
16393 | 16654 | |
---|
16394 | | - private void DrawSkyBox(GL gl) |
---|
| 16655 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16656 | + |
---|
| 16657 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16395 | 16658 | { |
---|
16396 | | - if (envyoff || cubemap == null) |
---|
| 16659 | + if (//envyoff || |
---|
| 16660 | + cubemap == null) |
---|
16397 | 16661 | { |
---|
16398 | 16662 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16399 | 16663 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16408 | 16672 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16409 | 16673 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16410 | 16674 | gl.glLoadIdentity(); |
---|
| 16675 | + gl.glScalef(1,ratio,1); |
---|
16411 | 16676 | |
---|
| 16677 | +// colorV[0] = 2; |
---|
| 16678 | +// colorV[1] = 2; |
---|
| 16679 | +// colorV[2] = 2; |
---|
| 16680 | +// colorV[3] = 1; |
---|
| 16681 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16682 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16683 | +// |
---|
| 16684 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16685 | + |
---|
16412 | 16686 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16413 | 16687 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16414 | 16688 | |
---|
.. | .. |
---|
16440 | 16714 | { |
---|
16441 | 16715 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16442 | 16716 | } |
---|
| 16717 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16443 | 16718 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16444 | 16719 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16445 | 16720 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16698 | 16973 | //new Exception().printStackTrace(); |
---|
16699 | 16974 | System.out.println("select buffer init"); |
---|
16700 | 16975 | // Use debug pipeline |
---|
16701 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 16976 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16702 | 16977 | |
---|
16703 | 16978 | GL gl = drawable.getGL(); |
---|
16704 | 16979 | |
---|