Starting with the serialization issue:
I was making a quick GUI serialization tool last night, and realised I did not fully understand the LoadOBJ parameters. I read the Wiki but do not quite understand the language used. My interpretation is that Textures are referenced inside the .Obj file, and that the material file is something different entirely? Currently what I'm doing is, getting InputStreams for both files, using LoadOBJ, using build() and strip(), and serialising, is that correct?
The lighting issue:
Does the default setup/shader only support one light? I thought I had read that it supported more, but I cant seem to get any more working.
Thanks in Advance ;)
EDIT: Just discovered the shader only supports one light, but could still do with some help understanding the serialiser.
The materials are referenced on the obj file, not the textures directly. And the materials are defined in that mtl file and so are the actual texture name that jPCT uses. To correctly load a model and its texture information, you need both files.
The process you apply seems fine to me. So where's the issue?
jPCT-AE in OpenGL ES 2.0 mode supports, just like the 1.1 variant, 8 lights by default. The default shaders that mimic the 1.1 pipeline also do this. Other shaders (like the parallax mapping example) or the spot light shader that can be found here somewhere might be limited to 1 or 2 or whatever. On a mobile device, it's best to support only as much as you have to if you don't want performance to suffer too much.
Thanks, understanding the format helped a lot! I seem to have got my serialization working; but I see a large increase in file size when merging the meshes (ie. around normal file size), is this normal?
Yes, it's normal...but that doesn't mean that it's perfect. It might be possible to reduce this somehow...i'll have a look...
Forgot about my own stuff...well...
Try to add a call to
obj.getMesh().compress();
right after doing the merge.
Brilliant! Just what I was after! Thanks a lot :)
So.. I'm trying to load my serialized data and I'm getting:
"No octree found in serialized data!
java.lang.ArrayIndexOutOfBoundsException: 49787
at com.threed.jpct.Object3D.recreateTextureCoords(Unknown Source)
at com.threed.jpct.Object3D.build(Unknown Source)
...."
EDIT: I'm also getting exception's while trying to display an Object3D returned by mergeAll(Object3D[]).
"Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...."
The "no octree" message is unrelated and normal. The rest isn't...are you trying to load the serialized object on Android or using the desktop version? If it's the latter, you can't deserialize objects that has been serialized for the Android version (that this boolean switch in serialize). Might that be the problem here?
Oh I was trying to load the serialized data on the desktop version. However the second error message is from trying a merge the meshes of a .OBJ file not a serialized file.
I fail to see any relation between merging objects and this exception
"Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...."
Maybe you can post the complete stack trace!?
My application is package com.codeturkey.modelrenderer. This only happens when I add the two lines to merge the meshes and to add the merged model to the world, those are the only two lines I add.
"Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NullPointerException
at com.codeturkey.modelrenderer.ModelRenderer.<init>(ModelRenderer.java:62)
at com.codeturkey.modelrenderer.ModelRenderer.main(ModelRenderer.java:26
)
... 5 more"
EDIT: I'm using Windows and rarely use CmdLine, I dont know how to access those "... 5 more" messages.
What exactly is in ModelRenderer.java:62? It might help if you post the code around that section.
Full code listing:
public class ModelRenderer {
private World world;
private FrameBuffer buffer;
private Object3D box;
private Object3D[] sonic;
private Object3D merged;
private JFrame frame;
public static void main(String[] args) throws Exception {
new ModelRenderer().loop();
}
public ModelRenderer() throws Exception {
frame = new JFrame("Model Renderer");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
world = new World();
world.setAmbientLight(0, 255, 0);
TextureManager.getInstance().addTexture("sonic", new Texture("Sonic.JPG"));
File snc = new File("Sonic.obj");
InputStream objIn = new FileInputStream(snc);
File sncMtl = new File("Sonic.mtl");
InputStream mtlIn = new FileInputStream(sncMtl);
sonic = Loader.loadOBJ(objIn, mtlIn, 1);
merged = Object3D.mergeAll(sonic);
world.addObject(merged);
world.getCamera().setPosition(0, 0, -100);
world.getCamera().lookAt(sonic[1].getTransformedCenter());
}
private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
while (frame.isShowing()) {
box.rotateY(0.01f);
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);
}
}
...but that class has no line 62!?
Sorry, removed the includes and stuff. Line 62 is the bottom of the constructor
world.getCamera().lookAt(sonic[1].getTransformedCenter());
I see. That's because the mergeAll()-method empties the array. Like the docs say:
Quote
The array will be empty afterwards.
This is done to save memory.
Aha! Thanks a lot! :)