Hi
I have the following lines from @pspeed’s sim-eth-es modified example:
AssetManager assetManager = getApplication().getAssetManager();
Spatial ship = assetManager.loadModel("Models/fighter.j3o");
ship.scale(0.5f);
ship.rotateUpTo(Vector3f.UNIT_Y); //Make sure that ship is rotate so that Y-axis upwards
ship.center(); //Center in the origin of the world bound
Texture texture = assetManager.loadTexture("Textures/ship1.png");
Material mat = GuiGlobals.getInstance().createMaterial(texture, false).getMaterial();
ship.setMaterial(mat);
Node result = new Node("ship:" + entity.getId());
//This is shown:
result.attachChild(ship);
result.setUserData("entityId", entity.getId().getId());
Texture ships = assetManager.loadTexture("Textures/Subspace/ships.gif");
Texture bullets = assetManager.loadTexture("Textures/Subspace/bullets.gif");
Quad quad = new Quad(10, 10);
quad.setBuffer(VertexBuffer.Type.TexCoord, 2, spriteCoords(0, 3, 36f / 360f, 36f / 1152f));
float halfSize = 0.5f * 0.5f;
quad.setBuffer(VertexBuffer.Type.Position, 3, new float[]{-halfSize, -halfSize, 0,
halfSize, -halfSize, 0,
halfSize, halfSize, 0,
-halfSize, halfSize, 0
});
quad.updateBound();
Geometry geom = new Geometry("SHIP", quad);
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat2.setTexture("ColorMap", ships);
//mat2.setColor("Color", color);
mat2.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
geom.setMaterial(mat2);
//This is not shown:
result.attachChild(geom);
And I cannot figure out why the first child is shown (the model as it is from sim-eth-es), but not the one I am trying to load. If I create a test-case, it works:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
* @author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
private Texture ships;
private Texture bullets;
@Override
public void simpleInitApp() {
ships = assetManager.loadTexture("Textures/Subspace/ships.gif");
bullets = assetManager.loadTexture("Textures/Subspace/bullets.gif");
Quad quad = new Quad(10, 10);
quad.setBuffer(VertexBuffer.Type.TexCoord, 2, spriteCoords(0, 3, 36f / 360f, 36f / 1152f));
float halfSize = 0.5f * 0.5f;
quad.setBuffer(VertexBuffer.Type.Position, 3, new float[]{-halfSize, -halfSize, 0,
halfSize, -halfSize, 0,
halfSize, halfSize, 0,
-halfSize, halfSize, 0
});
quad.updateBound();
Geometry geom = new Geometry("SHIP", quad);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", ships);
//mat.setColor("Color", color);
mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
geom.setMaterial(mat);
//geom.setQueueBucket(RenderQueue.Bucket.Translucent); //Make the alpha channel translucent
rootNode.attachChild(geom);
}
private float[] spriteCoords(int x, int y, float cellsize_x, float cellsize_y) {
float s = x * cellsize_x;
float t = y * cellsize_y;
return new float[]{s, t,
s + cellsize_x, t,
s + cellsize_x, t + cellsize_y,
s, t + cellsize_y};
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
What am I doing wrong…?!