Author Topic: vertex sharing and vertex indices  (Read 6824 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
vertex sharing and vertex indices
« on: December 28, 2009, 07:13:16 pm »
hi,

indeed i would keep this as a surprise ::) what i'm after is to make a skeletal animation implementation based on Ardor3d's Collada loader. i'm aiming it will be very lightweight and the runtime will not require Ardor3d.

i've constructed the mesh out of Ardor3d's mesh, assigned texture and coordinates but stuck at vertex indices. Ardor3d stores weights and joint indices in buffers where data is ordered according to mesh vertices. i need a way to match ardor3d vertices and jPCT vertices but there seems no way. futhermore Ardor3d also makes its own vertex sharing among polygons (not sure if engine optimizes it or Collada file is already optimized but that doesnt matter). so Object3D.disableVertexSharing doesnt help either.

only solution i can think of is, use same exact vertices and vertex sharing in jPCT to create an Object3D.

so is it possible to add a method or constructor to Object3D which takes vertice and texture coordinates as float arrays and an int array as index buffer ?

thanks,
r a f t


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: vertex sharing and vertex indices
« Reply #1 on: December 28, 2009, 11:36:00 pm »
It's no surprise. It was the only reasonable thing to assume by looking at your other posts... ;)

I'll look at it. I think i already have something similar that is package public only for loading indexed 3ds files. Either i may make that public (if it fits) or add something new.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: vertex sharing and vertex indices
« Reply #2 on: December 29, 2009, 09:21:48 pm »
Ok, here you go: http://www.jpct.net/download/beta/jpct.jar

I haven't tested it very well. Here's a simple test case that works fine:

Code: [Select]
import com.threed.jpct.*;

class BulkTest {

public static void main(String args[]) throws Exception {
float[] coords=new float[]{0,0,0,0,50,0,50,0,0,50,50,0};
float[] uvs=new float[]{0,0,0,1,1,0,1,1};
int[] indices=new int[]{0,1,2,2,1,3};

TextureManager texMan=TextureManager.getInstance();
texMan.addTexture("test", new Texture("test.jpg"));

Object3D ob=new Object3D(coords, uvs, indices, texMan.getTextureID("test"));

System.out.println("Triangles: "+ob.getMesh().getTriangleCount());
System.out.println("Vertices: "+ob.getMesh().getVertexCount());
System.out.println("Unique vertices: "+ob.getMesh().getUniqueVertexCount());

World world = new World();
world.setAmbientLight(200, 200, 200);

world.addObject(ob);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 200);

FrameBuffer fb = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);
fb.enableRenderer(IRenderer.RENDERER_OPENGL);

ob.compile();
world.buildAllObjects();

while (!org.lwjgl.opengl.Display.isCloseRequested()) {
fb.clear();
world.renderScene(fb);
world.draw(fb);

fb.update();
fb.displayGLOnly();
Thread.sleep(10);
}
fb.disableRenderer(IRenderer.RENDERER_OPENGL);
fb.dispose();
System.exit(0);
}
}

If it doesn't work on your data, please provide the data you are using.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: vertex sharing and vertex indices
« Reply #3 on: December 30, 2009, 07:02:38 am »
great :) i will test it tonight or tomorrow

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: vertex sharing and vertex indices
« Reply #4 on: December 30, 2009, 10:11:35 am »
i couldnt wait and tried it here. it loads ok :) seems as i dont need to call recreateTextureCoords in this case

can i suggest, if indices is null, loading vertices sequentially. it may be the case and as you kmow, invoking super class's constructor conditionally is not possible in java

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: vertex sharing and vertex indices
« Reply #5 on: December 30, 2009, 05:45:02 pm »
Ok, i'll add that simply be creating my own, linear indices-array if none is present. That should do the trick in that case.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: vertex sharing and vertex indices
« Reply #6 on: January 20, 2010, 10:40:44 pm »
Is that Collada loader capable of loading multi textured objects and would it be possible to get those different uv-arrays somehow? If so, it might be worth it to add a constructor that takes multiple uv-arrays, because OBJ and 3DS both don't support this.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: vertex sharing and vertex indices
« Reply #7 on: January 20, 2010, 11:40:25 pm »
i'm not sure if collada supports it but it's in the api. there are multiple texture bufferes.
the thing is i'm not using texture information at the moment, only the coordinates. so the user need to call Object3D.setTexture(..) which overrides all texture info of polygons, right ?

even if i use it, how will it be saved and reloaded again ? texture id's are created by TextureManager and will be meaningless in a new jvm session..

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: vertex sharing and vertex indices
« Reply #8 on: January 21, 2010, 12:04:36 am »
The textures don't matter, just the uv-coordinates. The textures will be applied in the same way on multiple layers as they are applied on one. What i have in mind is something like this:

Code: [Select]
new Object3D(coords, uvs, indices, textureIds);
Where uvs is a float[<layerCount>][<vertexCount>]-array and textureIds is a simple int[<layerCount>]-array. Collada supports multiple layers. I think i have an example file lying around somewhere. I'll look for it tomorrow.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: vertex sharing and vertex indices
« Reply #9 on: January 21, 2010, 12:10:36 am »
single texture and multiple layers  ??? what's the purpose ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: vertex sharing and vertex indices
« Reply #10 on: January 21, 2010, 07:01:00 am »
Multiple layers AND multiple textures. That's why textureIds is an array...one for each layer.
« Last Edit: January 21, 2010, 07:44:33 am by EgonOlsen »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: vertex sharing and vertex indices
« Reply #11 on: January 21, 2010, 12:54:00 pm »
ok but who and how will set the multiple textures ? Object3D.setTexture(..) does not help in this case

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: vertex sharing and vertex indices
« Reply #12 on: January 21, 2010, 03:25:05 pm »
The constructor will do...and setTexture(...) will work fine too. You are not mixing the textures between the layers. You have layer0 with texture0 assigned, layer1 with texture1 assigned...like a Quake3 level where one layer is the texture- and the other layer is the lightmap. Currently, i have to load the level two times with different uv-mappings and merge the result into one. While this is doable for me, it isn't for the artist who has to create the content.
« Last Edit: January 21, 2010, 05:03:32 pm by EgonOlsen »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: vertex sharing and vertex indices
« Reply #13 on: January 21, 2010, 04:27:47 pm »
ah, you mean Object3D.setTexture(TextureInfo), it supports multiple layers..

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: vertex sharing and vertex indices
« Reply #14 on: January 21, 2010, 05:03:53 pm »
Exactly... ;D