Author Topic: Two questions.. Serialization/Lights  (Read 5709 times)

Offline McJug

  • byte
  • *
  • Posts: 9
    • View Profile
Two questions.. Serialization/Lights
« on: June 25, 2012, 03:50:58 pm »
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.
« Last Edit: June 25, 2012, 04:26:13 pm by McJug »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two questions.. Serialization/Lights
« Reply #1 on: June 25, 2012, 08:13:49 pm »
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.

Offline McJug

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Two questions.. Serialization/Lights
« Reply #2 on: June 25, 2012, 08:52:46 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two questions.. Serialization/Lights
« Reply #3 on: June 25, 2012, 09:24:47 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two questions.. Serialization/Lights
« Reply #4 on: June 25, 2012, 09:30:07 pm »
Forgot about my own stuff...well...

Try to add a call to

Code: [Select]
obj.getMesh().compress();

right after doing the merge.

Offline McJug

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Two questions.. Serialization/Lights
« Reply #5 on: June 25, 2012, 10:06:28 pm »
Brilliant! Just what I was after! Thanks a lot :)

Offline McJug

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Two questions.. Serialization/Lights
« Reply #6 on: June 27, 2012, 12:27:37 am »
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)
    ...."
« Last Edit: June 27, 2012, 12:59:08 am by McJug »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two questions.. Serialization/Lights
« Reply #7 on: June 27, 2012, 07:10:40 am »
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?

Offline McJug

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Two questions.. Serialization/Lights
« Reply #8 on: June 27, 2012, 02:12:25 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two questions.. Serialization/Lights
« Reply #9 on: June 27, 2012, 02:41:09 pm »
I fail to see any relation between merging objects and this exception

Code: [Select]
"Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ...."

Maybe you can post the complete stack trace!?

Offline McJug

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Two questions.. Serialization/Lights
« Reply #10 on: June 27, 2012, 03:18:53 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two questions.. Serialization/Lights
« Reply #11 on: June 28, 2012, 09:33:46 am »
What exactly is in ModelRenderer.java:62? It might help if you post the code around that section.

Offline McJug

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Two questions.. Serialization/Lights
« Reply #12 on: July 02, 2012, 08:06:09 pm »
Full code listing:

Code: [Select]
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);
}
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Two questions.. Serialization/Lights
« Reply #13 on: July 02, 2012, 08:23:41 pm »
...but that class has no line 62!?

Offline McJug

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Two questions.. Serialization/Lights
« Reply #14 on: July 02, 2012, 08:33:22 pm »
Sorry, removed the includes and stuff. Line 62 is the bottom of the constructor

Code: [Select]
world.getCamera().lookAt(sonic[1].getTransformedCenter());
« Last Edit: July 02, 2012, 08:36:23 pm by McJug »