- improve atlas test, display quad with atlas texture
- clamp texture coordinates to 0-1 for atlas textures to better see actual texture mapping git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9035 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
fc5c7d06d2
commit
bb1ff2e9e5
@ -29,10 +29,8 @@
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package jme3test.tools;
|
||||
|
||||
import jme3test.model.shape.*;
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.asset.plugins.ZipLocator;
|
||||
import com.jme3.light.AmbientLight;
|
||||
@ -41,22 +39,24 @@ import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import jme3tools.optimize.GeometryBatchFactory;
|
||||
|
||||
public class TestTextureAtlas extends SimpleApplication {
|
||||
|
||||
public static void main(String[] args){
|
||||
public static void main(String[] args) {
|
||||
TestTextureAtlas app = new TestTextureAtlas();
|
||||
app.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void simpleInitApp() {
|
||||
assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName());
|
||||
flyCam.setMoveSpeed(50);
|
||||
assetManager.registerLocator("town.zip", ZipLocator.class.getName());
|
||||
Spatial scene = assetManager.loadModel("main.scene");
|
||||
|
||||
Geometry geom = GeometryBatchFactory.makeAtlasBatch(scene, assetManager, 4096);
|
||||
|
||||
|
||||
Geometry geom = GeometryBatchFactory.makeAtlasBatch(scene, assetManager, 2048);
|
||||
|
||||
AmbientLight al = new AmbientLight();
|
||||
rootNode.addLight(al);
|
||||
|
||||
@ -66,6 +66,11 @@ public class TestTextureAtlas extends SimpleApplication {
|
||||
rootNode.addLight(sun);
|
||||
|
||||
rootNode.attachChild(geom);
|
||||
}
|
||||
|
||||
//quad to display material
|
||||
Geometry box = new Geometry("displayquad", new Quad(4, 4));
|
||||
box.setMaterial(geom.getMaterial());
|
||||
box.setLocalTranslation(0, 1, 0);
|
||||
rootNode.attachChild(box);
|
||||
}
|
||||
}
|
||||
|
@ -352,9 +352,6 @@ public class GeometryBatchFactory {
|
||||
Geometry geom = new Geometry();
|
||||
Mesh mesh = new Mesh();
|
||||
mergeGeometries(geometries, mesh, atlas);
|
||||
TangentBinormalGenerator.generate(mesh);
|
||||
mesh.updateCounts();
|
||||
mesh.updateBound();
|
||||
geom.setMesh(mesh);
|
||||
|
||||
Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
|
||||
@ -365,6 +362,7 @@ public class GeometryBatchFactory {
|
||||
mat.setTexture("DiffuseMap", diffuseMap);
|
||||
}
|
||||
if (normalMap != null) {
|
||||
TangentBinormalGenerator.generate(mesh);
|
||||
mat.setTexture("NormalMap", normalMap);
|
||||
}
|
||||
if (specularMap != null) {
|
||||
|
@ -151,7 +151,6 @@ public class TextureAtlas {
|
||||
}
|
||||
|
||||
private void drawImage(Image source, int x, int y, String mapName) {
|
||||
//TODO: all buffers?
|
||||
if (images == null) {
|
||||
images = new HashMap<String, byte[]>();
|
||||
}
|
||||
@ -160,6 +159,7 @@ public class TextureAtlas {
|
||||
image = new byte[atlasWidth * atlasHeight * 4];
|
||||
images.put(mapName, image);
|
||||
}
|
||||
//TODO: all buffers?
|
||||
ByteBuffer sourceData = source.getData(0);
|
||||
int height = source.getHeight();
|
||||
int width = source.getWidth();
|
||||
@ -174,13 +174,13 @@ public class TextureAtlas {
|
||||
image[i + 3] = sourceData.get(j + 3); //r
|
||||
} else if (source.getFormat() == Format.BGR8) {
|
||||
int j = (xPos + yPos * width) * 3;
|
||||
image[i] = 0; //b
|
||||
image[i] = 0; //a
|
||||
image[i + 1] = sourceData.get(j); //b
|
||||
image[i + 2] = sourceData.get(j + 1); //g
|
||||
image[i + 3] = sourceData.get(j + 2); //r
|
||||
} else if (source.getFormat() == Format.RGB8) {
|
||||
int j = (xPos + yPos * width) * 3;
|
||||
image[i] = 0; //b
|
||||
image[i] = 0; //a
|
||||
image[i + 1] = sourceData.get(j + 2); //b
|
||||
image[i + 2] = sourceData.get(j + 1); //g
|
||||
image[i + 3] = sourceData.get(j); //r
|
||||
@ -322,8 +322,23 @@ public class TextureAtlas {
|
||||
float w = (float) getWidth() / (float) atlasWidth;
|
||||
float h = (float) getHeight() / (float) atlasHeight;
|
||||
Vector2f location = new Vector2f(x, y);
|
||||
Vector2f scale = new Vector2f(w, h);
|
||||
return location.addLocal(previousLocation.multLocal(scale));
|
||||
float prevX = previousLocation.x;
|
||||
float prevY = previousLocation.y;
|
||||
//TODO: remove workaround for texture wrap
|
||||
if (prevX > 1) {
|
||||
prevX = 1;
|
||||
}
|
||||
if (prevY > 1) {
|
||||
prevY = 1;
|
||||
}
|
||||
if (prevX < 0) {
|
||||
prevX = 0;
|
||||
}
|
||||
if (prevY < 0) {
|
||||
prevY = 0;
|
||||
}
|
||||
location.addLocal(prevX * w, prevY * h);
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,9 +357,10 @@ public class TextureAtlas {
|
||||
for (int i = 0; i < inBuf.capacity() / 2; i++) {
|
||||
tex.x = inBuf.get(i * 2 + 0);
|
||||
tex.y = inBuf.get(i * 2 + 1);
|
||||
Vector2f outLoc = getLocation(tex);
|
||||
outBuf.put(offset + i * 2 + 0, outLoc.x);
|
||||
outBuf.put(offset + i * 2 + 1, outLoc.y);
|
||||
Vector2f location = getLocation(tex);
|
||||
//TODO: replace with proper texture wrapping for atlases..
|
||||
outBuf.put(offset + i * 2 + 0, location.x);
|
||||
outBuf.put(offset + i * 2 + 1, location.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user