Hello, I am new to jPCT. I have some experience with LWJGL and JOGL though.
I am trying to load a house with an animated door, created with Blender into a world.
Rendered with Blender:
When imported by the object-loader:
I think something goes wrong with the back-face culling and the coordinates of the textures, and I'm not sure what to do with
setEnvmapped() and
setEnvmapMode(). Furthermore, when I try to enable blending (
thing.setBlending(true);), I get an ArrayIndexOutOfBoundsException at the
world.draw(buffer); line.
import com.threed.jpct.*;
import javax.swing.*;
public class HouseTest {
private String[] textures = {"door", "wall", "roof", "tile2"};
private String thingName = "hous1";
private int thingScale = 1;
private World world;
private FrameBuffer buffer;
private Object3D thing;
private JFrame frame;
private int an = 2;//do a walk animation
private float ind = 0;
public int height = 600;
public int width = 800;
public static void main(String[] args) throws Exception {
new HouseTest().loop();
}
public HouseTest() throws Exception {
frame = new JFrame("Blender Model Loading");
frame.setSize(width, height);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
world = new World();
world.setAmbientLight(150, 150, 150);
for (int i = 0; i < textures.length; ++i) {
TextureManager.getInstance().addTexture(textures[i] + ".jpg", new Texture("res/" + textures[i] + ".jpg"));
}
thing = loadModel("res/" + thingName + ".3ds", thingScale);
Animation anim = new Animation(4);
anim.createSubSequence("idle");
anim.addKeyFrame(thing.getMesh());
anim.createSubSequence("house");
anim.addKeyFrame(loadModel("res/" + "hous1.3ds", 1).getMesh());
anim.addKeyFrame(loadModel("res/" + "hous2.3ds", 1).getMesh());
anim.addKeyFrame(loadModel("res/" + "hous3.3ds", 1).getMesh());
thing.setAnimationSequence(anim);
world.addObject(thing);
world.getCamera().setPosition(0, 0, -20);
world.getCamera().lookAt(thing.getTransformedCenter());
thing.setEnvmapped(true);
thing.setEnvmapMode(false);
}
private void loop() throws Exception {
buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
while (frame.isShowing()) {
doAnim();
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.display(frame.getGraphics());
Thread.sleep(10);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
frame.dispose();
System.exit(0);
}
private Object3D loadModel(String filename, float scale) {
Loader.setVertexOptimization(false);
Object3D[] model = Loader.load3DS(filename, scale);
Object3D o3d = new Object3D(0);
Object3D temp = null;
for (int i = 0; i < model.length; i++) {
temp = model[i];
temp.setCenter(SimpleVector.ORIGIN);
temp.rotateX((float)( -.5*Math.PI));
temp.rotateMesh();
temp.setRotationMatrix(new Matrix());
o3d = Object3D.mergeObjects(o3d, temp);
o3d.build();
}
return o3d;
}
public void doAnim() {
{
ind += 0.018f;
if (ind > 1f) {
ind -= 1f;
}
}
thing.animate(ind, an);
}
}
EDIT: Don't mind the door. I forgot the texture.