I had a 3D model loaded with JMEDesktop swing components.
But the 3D model's texture is rendered with JMEDesktop instead of the .jpg image file.
3D model looked 1st
http://www.oniva.com/upload/1356/tex.jpg
then the 3D model's texture is using the JMEDesktop screen ( but not .jpg image file )
http://www.oniva.com/upload/1356/tex2.jpg
http://www.oniva.com/upload/1356/BackgroundGameState.java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.controls.GameControlManager;
import com.jme.light.PointLight;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.game.state.BasicGameState;
import com.jmex.model.converters.Md3ToJme;
import jmetest.monkeymahjongg.Main;
import jmetest.renderer.loader.TestMd3JmeWrite;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.scene.Spatial;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.Md3ToJme;
/**
*
* @author DGronau
*/
public class BackgroundGameState extends BasicGameState {
private static final Logger logger = Logger.getLogger(BackgroundGameState.class
.getName());
private GameControlManager gameControlManager;
//private Box box;
private Vector3f cameraLocation;
private Vector3f cameraDirection;
public BackgroundGameState(String texture) {
super("background");
init(texture);
}
private void init(String texture) {
PointLight light = new PointLight();
light.setDiffuse(new ColorRGBA(0.75f, 0.75f, 0.75f, 0.75f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setLocation(new Vector3f(100, 100, 100));
light.setEnabled(true);
LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
lightState.setEnabled(true);
lightState.attach(light);
getRootNode().setRenderState(lightState);
getRootNode().updateRenderState();
try {
Md3ToJme converter=new Md3ToJme();
URL model=null;
model=BackgroundGameState.class.getClassLoader().getResource("jmetest/data/model/nordhorse.md3");
URL tex=BackgroundGameState.class.getClassLoader().getResource("jmetest/data/model/nordhorse_color.jpg");
ByteArrayOutputStream BO=new ByteArrayOutputStream();
converter.convert(model.openStream(),BO);
logger.info("Done converting, now watch how fast it loads!");
long time=System.currentTimeMillis();
Spatial r=(Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
r.setModelBound(new BoundingBox());
r.updateModelBound();
logger.info("Finished loading time is "+(System.currentTimeMillis()-time));
TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
ts.setTexture(TextureManager.loadTexture(tex,Texture.MM_LINEAR,Texture.FM_LINEAR));
ts.setEnabled(true);
r.setRenderState(ts);
r.setLocalScale(1.0f);
getRootNode().attachChild(r);
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to load Md3 file", e);
}
cameraLocation = DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation();
cameraDirection = DisplaySystem.getDisplaySystem().getRenderer().getCamera().getDirection();
}
@Override
public void setActive(boolean active) {
super.setActive(active);
if (active) {
DisplaySystem.getDisplaySystem().getRenderer().getCamera().setLocation(cameraLocation);
DisplaySystem.getDisplaySystem().getRenderer().getCamera().setDirection(cameraDirection);
}
}
}
Any one knows why the texture image is not applied to the Horse, but instead the JMEDesktop screen is applied as texture??