jPCT - a 3d engine for Java => Support => Topic started by: fireside on February 11, 2008, 07:10:38 am

Title: 2nd object
Post by: fireside on February 11, 2008, 07:10:38 am
I'm starting with the cartoon network code for a framework because it's small and a little easier to understand and I'm rusty with my Java.  Anyway, I have an object loaded from this code:

Code: [Select]
Object3D[] obj= Loader.load3DS("Shadow.3DS", 1);

      Object3D Toy=new Object3D(0);
        for (int i=0; i<obj.length; i++) {
           Object3D part=obj[i];

           part.setRotationMatrix(new Matrix());
          Toy=Object3D.mergeObjects(Toy, part);
  Toy.translate(0, 0, 0);

What I don't quite understand is it starts out with this Object3d array named obj, loads the model, and doesn't mention it again until it's rotating some parts.  What I'd like to know is how would I load the next object and would that rotation code that  sets it aright with the world work for the second object also, or is that just parts of one object and it has to be redone?

So, this code was made for some kind of cartoon effect, but I want to modify it so it just loads multiple objects and sets them right side up.
Title: Re: 2nd object
Post by: Jonas on February 11, 2008, 01:13:15 pm

Loading a 3ds model may result in more than one Object3D(e.g. in the cartoon example theres an object for the hand, one for the body and so on...).

So what that code does is to rotate all these parts of the loaded model. It is then merged into one bigger object3d representing the whole model.

If you want to load multiple models that way, just pack it into a method. Like

Code: [Select]
public Object3D loadModel(String filename, float scale)
Object3D[] model = Loader.load3DS(filename, scale);

Object3D o3d = new Object3D(0);
Object3D temp = null;
  for (int i=0; i<obj.length; i++)
  temp.setRotationMatrix(new Matrix());
  o3d=Object3D.mergeObjects(o3d, temp);
return o3d;           

and use this one in your code.
Title: Re: 2nd object
Post by: fireside on February 11, 2008, 02:40:18 pm
O.K.  Thanks.
I'm having a kind of rendering problem, now.  This is a mouse on a platform.  The platform is, you know, like any platform, but it seems like it doesn't look right.  It should be lighter on top.  The light is above and in front.  The mouse looks right, but the platform looks funny.

(http://aycu33.webshots.com/image/45392/2003826770881611142_th.jpg) (http://allyoucanupload.webshots.com/v/2003826770881611142)
Title: Re: 2nd object
Post by: EgonOlsen on February 11, 2008, 02:56:48 pm
That's caused by the low tesselation of the platform. Vertex lighting is calculated for vertices only and linear interpolated across the polygon. Therefore, no part of a polygon can be brighter than the brightest vertex. In your case, the vertices are quite far away from the light compared to the mouse which is why the whole platform appears quite dark. Use more polygons for the platform an see how it gets brighter...at least it should... ;)
Title: Re: 2nd object
Post by: fireside on February 11, 2008, 09:59:37 pm
The normals were turned around on the model, which didn't help either.  It looks pretty good when the normals are the right way.