- 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
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package jme3test.tools;
|
package jme3test.tools;
|
||||||
|
|
||||||
import jme3test.model.shape.*;
|
|
||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.asset.plugins.ZipLocator;
|
import com.jme3.asset.plugins.ZipLocator;
|
||||||
import com.jme3.light.AmbientLight;
|
import com.jme3.light.AmbientLight;
|
||||||
@ -41,21 +39,23 @@ import com.jme3.math.ColorRGBA;
|
|||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
|
import com.jme3.scene.shape.Quad;
|
||||||
import jme3tools.optimize.GeometryBatchFactory;
|
import jme3tools.optimize.GeometryBatchFactory;
|
||||||
|
|
||||||
public class TestTextureAtlas extends SimpleApplication {
|
public class TestTextureAtlas extends SimpleApplication {
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args) {
|
||||||
TestTextureAtlas app = new TestTextureAtlas();
|
TestTextureAtlas app = new TestTextureAtlas();
|
||||||
app.start();
|
app.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
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");
|
Spatial scene = assetManager.loadModel("main.scene");
|
||||||
|
|
||||||
Geometry geom = GeometryBatchFactory.makeAtlasBatch(scene, assetManager, 4096);
|
Geometry geom = GeometryBatchFactory.makeAtlasBatch(scene, assetManager, 2048);
|
||||||
|
|
||||||
AmbientLight al = new AmbientLight();
|
AmbientLight al = new AmbientLight();
|
||||||
rootNode.addLight(al);
|
rootNode.addLight(al);
|
||||||
@ -66,6 +66,11 @@ public class TestTextureAtlas extends SimpleApplication {
|
|||||||
rootNode.addLight(sun);
|
rootNode.addLight(sun);
|
||||||
|
|
||||||
rootNode.attachChild(geom);
|
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();
|
Geometry geom = new Geometry();
|
||||||
Mesh mesh = new Mesh();
|
Mesh mesh = new Mesh();
|
||||||
mergeGeometries(geometries, mesh, atlas);
|
mergeGeometries(geometries, mesh, atlas);
|
||||||
TangentBinormalGenerator.generate(mesh);
|
|
||||||
mesh.updateCounts();
|
|
||||||
mesh.updateBound();
|
|
||||||
geom.setMesh(mesh);
|
geom.setMesh(mesh);
|
||||||
|
|
||||||
Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
|
Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
|
||||||
@ -365,6 +362,7 @@ public class GeometryBatchFactory {
|
|||||||
mat.setTexture("DiffuseMap", diffuseMap);
|
mat.setTexture("DiffuseMap", diffuseMap);
|
||||||
}
|
}
|
||||||
if (normalMap != null) {
|
if (normalMap != null) {
|
||||||
|
TangentBinormalGenerator.generate(mesh);
|
||||||
mat.setTexture("NormalMap", normalMap);
|
mat.setTexture("NormalMap", normalMap);
|
||||||
}
|
}
|
||||||
if (specularMap != null) {
|
if (specularMap != null) {
|
||||||
|
@ -151,7 +151,6 @@ public class TextureAtlas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void drawImage(Image source, int x, int y, String mapName) {
|
private void drawImage(Image source, int x, int y, String mapName) {
|
||||||
//TODO: all buffers?
|
|
||||||
if (images == null) {
|
if (images == null) {
|
||||||
images = new HashMap<String, byte[]>();
|
images = new HashMap<String, byte[]>();
|
||||||
}
|
}
|
||||||
@ -160,6 +159,7 @@ public class TextureAtlas {
|
|||||||
image = new byte[atlasWidth * atlasHeight * 4];
|
image = new byte[atlasWidth * atlasHeight * 4];
|
||||||
images.put(mapName, image);
|
images.put(mapName, image);
|
||||||
}
|
}
|
||||||
|
//TODO: all buffers?
|
||||||
ByteBuffer sourceData = source.getData(0);
|
ByteBuffer sourceData = source.getData(0);
|
||||||
int height = source.getHeight();
|
int height = source.getHeight();
|
||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
@ -174,13 +174,13 @@ public class TextureAtlas {
|
|||||||
image[i + 3] = sourceData.get(j + 3); //r
|
image[i + 3] = sourceData.get(j + 3); //r
|
||||||
} else if (source.getFormat() == Format.BGR8) {
|
} else if (source.getFormat() == Format.BGR8) {
|
||||||
int j = (xPos + yPos * width) * 3;
|
int j = (xPos + yPos * width) * 3;
|
||||||
image[i] = 0; //b
|
image[i] = 0; //a
|
||||||
image[i + 1] = sourceData.get(j); //b
|
image[i + 1] = sourceData.get(j); //b
|
||||||
image[i + 2] = sourceData.get(j + 1); //g
|
image[i + 2] = sourceData.get(j + 1); //g
|
||||||
image[i + 3] = sourceData.get(j + 2); //r
|
image[i + 3] = sourceData.get(j + 2); //r
|
||||||
} else if (source.getFormat() == Format.RGB8) {
|
} else if (source.getFormat() == Format.RGB8) {
|
||||||
int j = (xPos + yPos * width) * 3;
|
int j = (xPos + yPos * width) * 3;
|
||||||
image[i] = 0; //b
|
image[i] = 0; //a
|
||||||
image[i + 1] = sourceData.get(j + 2); //b
|
image[i + 1] = sourceData.get(j + 2); //b
|
||||||
image[i + 2] = sourceData.get(j + 1); //g
|
image[i + 2] = sourceData.get(j + 1); //g
|
||||||
image[i + 3] = sourceData.get(j); //r
|
image[i + 3] = sourceData.get(j); //r
|
||||||
@ -322,8 +322,23 @@ public class TextureAtlas {
|
|||||||
float w = (float) getWidth() / (float) atlasWidth;
|
float w = (float) getWidth() / (float) atlasWidth;
|
||||||
float h = (float) getHeight() / (float) atlasHeight;
|
float h = (float) getHeight() / (float) atlasHeight;
|
||||||
Vector2f location = new Vector2f(x, y);
|
Vector2f location = new Vector2f(x, y);
|
||||||
Vector2f scale = new Vector2f(w, h);
|
float prevX = previousLocation.x;
|
||||||
return location.addLocal(previousLocation.multLocal(scale));
|
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++) {
|
for (int i = 0; i < inBuf.capacity() / 2; i++) {
|
||||||
tex.x = inBuf.get(i * 2 + 0);
|
tex.x = inBuf.get(i * 2 + 0);
|
||||||
tex.y = inBuf.get(i * 2 + 1);
|
tex.y = inBuf.get(i * 2 + 1);
|
||||||
Vector2f outLoc = getLocation(tex);
|
Vector2f location = getLocation(tex);
|
||||||
outBuf.put(offset + i * 2 + 0, outLoc.x);
|
//TODO: replace with proper texture wrapping for atlases..
|
||||||
outBuf.put(offset + i * 2 + 1, outLoc.y);
|
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