* HttpZipLocator UTF8 decoder replaced with proper code

* Removed some redundant javadoc from SceneProcessor
 * Fixed bug where GeometryBatchFactory.optimize() wouldn't reset the transform on the argument node as would be expected since optimize() applies the world transform of the geometries automatically
 * Terrain grid tests now stream terrain data from googlecode servers instead of having the data bundled in the nightly builds

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7619 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 14 years ago
parent 86eb9b5173
commit 37894d1698
  1. 9
      engine/src/core/com/jme3/post/SceneProcessor.java
  2. 117
      engine/src/desktop/com/jme3/asset/plugins/HttpZipLocator.java
  3. BIN
      engine/src/test-data/Textures/Terrain/grid/alphamap_0_0.png
  4. BIN
      engine/src/test-data/Textures/Terrain/grid/alphamap_0_512.png
  5. BIN
      engine/src/test-data/Textures/Terrain/grid/alphamap_512_0.png
  6. BIN
      engine/src/test-data/Textures/Terrain/grid/alphamap_512_512.png
  7. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_-1_-1.png
  8. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_-1_-2.png
  9. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_-1_0.png
  10. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_-1_1.png
  11. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_-1_2.png
  12. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_-1_3.png
  13. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_-1_4.png
  14. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_0_-1.png
  15. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_0_-2.png
  16. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_0_-3.png
  17. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_0_0.png
  18. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_0_1.png
  19. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_0_2.png
  20. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_0_3.png
  21. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_0_4.png
  22. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_1_-1.png
  23. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_1_-2.png
  24. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_1_-3.png
  25. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_1_0.png
  26. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_1_1.png
  27. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_1_2.png
  28. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_1_3.png
  29. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_1_4.png
  30. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_2_-1.png
  31. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_2_-2.png
  32. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_2_-3.png
  33. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_2_0.png
  34. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_2_1.png
  35. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_2_2.png
  36. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_2_3.png
  37. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_2_4.png
  38. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_3_-1.png
  39. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_3_-2.png
  40. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_3_-3.png
  41. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_3_0.png
  42. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_3_1.png
  43. BIN
      engine/src/test-data/Textures/Terrain/grid/terrain_3_2.png
  44. 19
      engine/src/test/jme3test/terrain/TerrainGridAlphaMapTest.java
  45. 4
      engine/src/test/jme3test/terrain/TerrainGridTest.java
  46. 4
      engine/src/tools/jme3tools/optimize/GeometryBatchFactory.java

@ -40,12 +40,12 @@ import com.jme3.texture.FrameBuffer;
/** /**
* Scene processors are used to compute/render things before and after the classic render of the scene. * Scene processors are used to compute/render things before and after the classic render of the scene.
* They have to be added to a viewport and are rendered in the order they've been added * They have to be added to a viewport and are rendered in the order they've been added
* @author Kirill Vainer aka Shadowislord aka Momoko_Fan *
* @author Kirill Vainer
*/ */
public interface SceneProcessor { public interface SceneProcessor {
/** /**
* For internal use only<br>
* Called in the render thread to initialize the scene processor. * Called in the render thread to initialize the scene processor.
* *
* @param rm The render manager to which the SP was added to * @param rm The render manager to which the SP was added to
@ -54,7 +54,6 @@ public interface SceneProcessor {
public void initialize(RenderManager rm, ViewPort vp); public void initialize(RenderManager rm, ViewPort vp);
/** /**
* For internal use only<br>
* Called when the resolution of the viewport has been changed. * Called when the resolution of the viewport has been changed.
* @param vp * @param vp
*/ */
@ -67,7 +66,6 @@ public interface SceneProcessor {
public boolean isInitialized(); public boolean isInitialized();
/** /**
* For internal use only<br>
* Called before a frame * Called before a frame
* *
* @param tpf Time per frame * @param tpf Time per frame
@ -75,7 +73,6 @@ public interface SceneProcessor {
public void preFrame(float tpf); public void preFrame(float tpf);
/** /**
* For internal use only<br>
* Called after the scene graph has been queued, but before it is flushed. * Called after the scene graph has been queued, but before it is flushed.
* *
* @param rq The render queue * @param rq The render queue
@ -83,7 +80,6 @@ public interface SceneProcessor {
public void postQueue(RenderQueue rq); public void postQueue(RenderQueue rq);
/** /**
* For internal use only<br>
* Called after a frame has been rendered and the queue flushed. * Called after a frame has been rendered and the queue flushed.
* *
* @param out The FB to which the scene was rendered. * @param out The FB to which the scene was rendered.
@ -91,7 +87,6 @@ public interface SceneProcessor {
public void postFrame(FrameBuffer out); public void postFrame(FrameBuffer out);
/** /**
* For internal use only<br>
* Called when the SP is removed from the RM. * Called when the SP is removed from the RM.
*/ */
public void cleanup(); public void cleanup();

@ -40,6 +40,12 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.util.HashMap; import java.util.HashMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -57,6 +63,15 @@ public class HttpZipLocator implements AssetLocator {
private int tableOffset; private int tableOffset;
private int tableLength; private int tableLength;
private HashMap<String, ZipEntry2> entries; private HashMap<String, ZipEntry2> entries;
private static final ByteBuffer byteBuf = ByteBuffer.allocate(250);
private static final CharBuffer charBuf = CharBuffer.allocate(250);
private static final CharsetDecoder utf8Decoder;
static {
Charset utf8 = Charset.forName("UTF-8");
utf8Decoder = utf8.newDecoder();
}
private static class ZipEntry2 { private static class ZipEntry2 {
String name; String name;
@ -94,66 +109,48 @@ public class HttpZipLocator implements AssetLocator {
(((long)(b[off]&0xff)) << 24); (((long)(b[off]&0xff)) << 24);
} }
private static String getUTF8String(byte[] b, int off, int len) { private static String getUTF8String(byte[] b, int off, int len) throws CharacterCodingException {
// First, count the number of characters in the sequence StringBuilder sb = new StringBuilder();
int count = 0;
int max = off + len; int read = 0;
int i = off; while (read < len){
while (i < max) { // Either read n remaining bytes in b or 250 if n is higher.
int c = b[i++] & 0xff; int toRead = Math.min(len - read, byteBuf.capacity());
switch (c >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: boolean endOfInput = toRead < byteBuf.capacity();
// 0xxxxxxx
count++; // read 'toRead' bytes into byteBuf
break; byteBuf.put(b, off + read, toRead);
case 12: case 13:
// 110xxxxx 10xxxxxx // set limit to position and set position to 0
if ((int)(b[i++] & 0xc0) != 0x80) { // so data can be decoded
throw new IllegalArgumentException(); byteBuf.flip();
}
count++; // decode data in byteBuf
break; CoderResult result = utf8Decoder.decode(byteBuf, charBuf, endOfInput);
case 14:
// 1110xxxx 10xxxxxx 10xxxxxx // if the result is not an underflow its an error
if (((int)(b[i++] & 0xc0) != 0x80) || // that cannot be handled.
((int)(b[i++] & 0xc0) != 0x80)) { // if the error is an underflow and its the end of input
throw new IllegalArgumentException(); // then the decoder expects more bytes but there are no more => error
} if (!result.isUnderflow() || !endOfInput){
count++; result.throwException();
break; }
default:
// 10xxxxxx, 1111xxxx // flip the char buf to get the string just decoded
throw new IllegalArgumentException(); charBuf.flip();
}
} // append the decoded data into the StringBuilder
if (i != max) { sb.append(charBuf.toString());
throw new IllegalArgumentException();
} // clear buffers for next use
// Now decode the characters... byteBuf.clear();
char[] cs = new char[count]; charBuf.clear();
i = 0;
while (off < max) { read += toRead;
int c = b[off++] & 0xff; }
switch (c >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: return sb.toString();
// 0xxxxxxx
cs[i++] = (char)c;
break;
case 12: case 13:
// 110xxxxx 10xxxxxx
cs[i++] = (char)(((c & 0x1f) << 6) | (b[off++] & 0x3f));
break;
case 14:
// 1110xxxx 10xxxxxx 10xxxxxx
int t = (b[off++] & 0x3f) << 6;
cs[i++] = (char)(((c & 0x0f) << 12) | t | (b[off++] & 0x3f));
break;
default:
// 10xxxxxx, 1111xxxx
throw new IllegalArgumentException();
}
}
return new String(cs, 0, count);
} }
private InputStream readData(int offset, int length) throws IOException{ private InputStream readData(int offset, int length) throws IOException{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 520 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 708 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 708 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 702 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 452 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 447 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 467 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 464 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 452 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 440 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 443 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 443 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 443 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 442 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 458 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 442 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 442 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 454 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 436 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 456 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 448 KiB

@ -5,6 +5,8 @@ import java.util.List;
import com.jme3.app.SimpleApplication; import com.jme3.app.SimpleApplication;
import com.jme3.app.state.ScreenshotAppState; import com.jme3.app.state.ScreenshotAppState;
import com.jme3.asset.plugins.HttpZipLocator;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.bullet.BulletAppState; import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape; import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape; import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape;
@ -20,12 +22,11 @@ import com.jme3.renderer.Camera;
import com.jme3.terrain.geomipmap.TerrainGrid; import com.jme3.terrain.geomipmap.TerrainGrid;
import com.jme3.terrain.geomipmap.TerrainGridListener; import com.jme3.terrain.geomipmap.TerrainGridListener;
import com.jme3.terrain.geomipmap.TerrainLodControl; import com.jme3.terrain.geomipmap.TerrainLodControl;
import com.jme3.terrain.geomipmap.TerrainQuad;
import com.jme3.terrain.heightmap.FractalHeightMapGrid;
import com.jme3.terrain.heightmap.ImageBasedHeightMapGrid; import com.jme3.terrain.heightmap.ImageBasedHeightMapGrid;
import com.jme3.terrain.heightmap.Namer; import com.jme3.terrain.heightmap.Namer;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode; import com.jme3.texture.Texture.WrapMode;
import java.io.File;
import org.novyon.noise.ShaderUtils; import org.novyon.noise.ShaderUtils;
import org.novyon.noise.basis.FilteredBasis; import org.novyon.noise.basis.FilteredBasis;
import org.novyon.noise.filter.IterativeFilter; import org.novyon.noise.filter.IterativeFilter;
@ -58,6 +59,13 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
@Override @Override
public void simpleInitApp() { public void simpleInitApp() {
File file = new File("mountains.zip");
if (!file.exists()) {
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/mountains.zip", HttpZipLocator.class);
}else{
assetManager.registerLocator("mountains.zip", ZipLocator.class);
}
this.flyCam.setMoveSpeed(100f); this.flyCam.setMoveSpeed(100f);
ScreenshotAppState state = new ScreenshotAppState(); ScreenshotAppState state = new ScreenshotAppState();
this.stateManager.attach(state); this.stateManager.attach(state);
@ -126,9 +134,8 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
ground.addPreFilter(this.iterate); ground.addPreFilter(this.iterate);
this.terrain = new TerrainGrid("terrain", 65, 1025, new ImageBasedHeightMapGrid(assetManager, new Namer() { this.terrain = new TerrainGrid("terrain", 65, 1025, new ImageBasedHeightMapGrid(assetManager, new Namer() {
public String getName(int x, int y) { public String getName(int x, int y) {
return "Textures/Terrain/grid/terrain_" + x + "_" + y + ".png"; return "Scenes/TerrainAlphaTest/terrain_" + x + "_" + y + ".png";
} }
})); }));
this.terrain.setMaterial(this.matRock); this.terrain.setMaterial(this.matRock);
@ -139,7 +146,9 @@ public class TerrainGridAlphaMapTest extends SimpleApplication {
} }
public Material tileLoaded(Material material, Vector3f cell) { public Material tileLoaded(Material material, Vector3f cell) {
material.setTexture("Alpha", assetManager.loadTexture("Textures/Terrain/grid/alphamap_" + (int)Math.abs(512 * (cell.x % 2)) + "_" + (int)Math.abs(512 * (cell.z % 2)) + ".png")); int x = (int)Math.abs(512 * (cell.x % 2));
int z = (int)Math.abs(512 * (cell.z % 2));
material.setTexture("Alpha", assetManager.loadTexture("Scenes/TerrainAlphaTest/alphamap_" + x + "_" + z + ".png"));
return material; return material;
} }
}); });

@ -61,9 +61,9 @@ public class TerrainGridTest extends SimpleApplication {
public void simpleInitApp() { public void simpleInitApp() {
File file = new File("mountains.zip"); File file = new File("mountains.zip");
if (!file.exists()) { if (!file.exists()) {
assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/mountains.zip", HttpZipLocator.class.getName()); assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/mountains.zip", HttpZipLocator.class);
}else{ }else{
assetManager.registerLocator("mountains.zip", ZipLocator.class.getName()); assetManager.registerLocator("mountains.zip", ZipLocator.class);
} }
this.flyCam.setMoveSpeed(100f); this.flyCam.setMoveSpeed(100f);

@ -2,6 +2,7 @@ package jme3tools.optimize;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.math.Transform;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh; import com.jme3.scene.Mesh;
@ -348,6 +349,9 @@ public class GeometryBatchFactory {
geometry.removeFromParent(); geometry.removeFromParent();
} }
// Since the scene is returned unaltered the transform must be reset
scene.setLocalTransform(Transform.IDENTITY);
return scene; return scene;
} }

Loading…
Cancel
Save