Author Topic: steps to take after Object3D.setMesh(mesh)  (Read 2797 times)

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
steps to take after Object3D.setMesh(mesh)
« on: January 06, 2010, 08:35:30 pm »
hi,

i created an Object3D with zero triangles and set a mesh to it. after this either calling build() or recreateTextureCoords() throws a null pointer exception at recreateTextureCoords().

what other steps should i take to prepare the object ?
« Last Edit: January 06, 2010, 08:48:14 pm by raft »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: steps to take after Object3D.setMesh(mesh)
« Reply #1 on: January 06, 2010, 08:59:27 pm »
The Mesh just contains the geometry information. For example, it doesn't contain any texturing information. Those are part of the object itself (or at least bound to it in 1-to-1-relationship contained in a package private object). So by creating an Object3D with 0 polygons, no space is reserved for texturing information at all...hence the null pointer exception. You either have to create the initial object with the correct triangle size or...i'm not sure what else...what's the purpose of this? Why not create the object directly?

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: steps to take after Object3D.setMesh(mesh)
« Reply #2 on: January 06, 2010, 09:13:43 pm »
ok, i can live with it. let me try..
the purpose is, to save a skinned object group and related information (skeleton, pose, joints, weights etc) to a stream and reload it.
i dont want to save Object3D itself as it gets too big and unnecessary. so i save the mesh only and restore object with that mesh

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: steps to take after Object3D.setMesh(mesh)
« Reply #3 on: January 06, 2010, 09:35:25 pm »
ok, i got rid of exception but i cant get a correct render. i set the texture, call build() and recreateTextureCoords(). what else ?


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: steps to take after Object3D.setMesh(mesh)
« Reply #4 on: January 06, 2010, 09:51:05 pm »
What are you doing exactly now? Serializing the Object3D or just the Mesh and inject it into a newly created Object3D with the proper triangle count?

BTW: build() includes recreateTextureCoords(). There's no need to call it if you are already calling build() anyway.
« Last Edit: January 06, 2010, 09:53:35 pm by EgonOlsen »

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: steps to take after Object3D.setMesh(mesh)
« Reply #5 on: January 06, 2010, 09:56:28 pm »
i serialize only the mesh and some skin data, not the Object3D. while reloading, create a Object3D with the triangle count of mesh, set the mesh, set texture and finally call build

a cycle very similar to Object3D(other object, true)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: steps to take after Object3D.setMesh(mesh)
« Reply #6 on: January 06, 2010, 10:01:17 pm »
Well, as said: The Object3D contains the texturing information. And that means the u/v coordinates, not just the texture id. Can't you simply serialize what you drop in her anyway:

public Object3D(float[] coordinates, float[] uvs, int[] indices, int textureId)


? That's as short as it gets and not bound to any implementation. It could be reloaded at any time even if the Mesh's UID changes or something.

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: steps to take after Object3D.setMesh(mesh)
« Reply #7 on: January 06, 2010, 10:10:01 pm »
ok. i can do that

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: steps to take after Object3D.setMesh(mesh)
« Reply #8 on: January 06, 2010, 10:13:55 pm »
Another option would be to extract texturing information from the Object3D by using the PolygonManager (possible unless you are using multi texturing, which the manager's getTextureUV()-method doesn't support) and recreate it at load time again by using the PM. Or i could write some getDump()/setDump()-methods for Object3D, but i really think that using the plain float[]-arrays is the better solution, isn't it?

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: steps to take after Object3D.setMesh(mesh)
« Reply #9 on: January 06, 2010, 10:17:57 pm »
this is good enough. the only detail i dont like with this is, i should keep a copy of that coordinates in my object and user should manually discard it if not used. but no big deal

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: steps to take after Object3D.setMesh(mesh)
« Reply #10 on: January 06, 2010, 10:50:16 pm »
Ok, great. I've tried to reduce the space usage of a serialized Object3D anyway, but all i could squeeze out of it was approx. 1.1 KB/Object3D. Nothing to get crazy about... ;)

Offline raft

  • quad
  • ******
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: steps to take after Object3D.setMesh(mesh)
« Reply #11 on: January 09, 2010, 03:49:02 am »
Well, as said: The Object3D contains the texturing information. And that means the u/v coordinates, not just the texture id.
just for curiosity, why is it that way btw ? isnt mesh a more natural location to put texture coordinates ? current scheme allows using same mesh with different coordinates but i guess there are very few cases requiring that and can be handled differently.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: steps to take after Object3D.setMesh(mesh)
« Reply #12 on: January 09, 2010, 01:18:58 pm »
That's mostly an artefact of the software renderer. The software renderer uses different u/v-coordinates for rendering than the normalized ones that you load from a file. They depend on the texture(s), so two objects with the same u/v-mapping but different textures may use different rendering u/vs. So for the sw renderer, you obviously can't store these coordinates in a shared mesh. You could actually store the normalized ones there as you said, but i didn't want to separate the two. Basically, jPCT stores everything indexed in  Mesh and everything not indexed in Vectors (not public). Texture coords are not indexed in jPCT (unlike OpenGL), because i wanted to keep the geometry count as low as possible (i.e. index rate as high as possible).
« Last Edit: January 09, 2010, 02:23:36 pm by EgonOlsen »