www.jpct.net

jPCT - a 3d engine for Java => Bugs => Topic started by: acorn98 on February 25, 2004, 05:03:16 am

Title: CloneObject and lighting
Post by: acorn98 on February 25, 2004, 05:03:16 am
Not sure if this is a bug, but I have a template object3D that I use to spawn new 'enemies', like this:

              enemy = enemyTemplate.cloneObject();
             
              enemy.translate(0, 0, 0);
              enemy.setTranslationMatrix(new Matrix());
              enemy.setLighting(Object3D.LIGHTING_ALL_ENABLED);
                           
              theWorld.addObject(enemy);

The problem is, my enemies don't seem to react to light sources at all.

The enemy model was created in MAX and uses default diffuse colours (I don't manually texture them after importing with the load3ds method). Have I missed something obvious?

Thanks..
Title: CloneObject and lighting
Post by: EgonOlsen on February 25, 2004, 07:57:16 am
Have you called build() on them, i.e.

Code: [Select]
enemyTemplate.build();
Title: CloneObject and lighting
Post by: acorn98 on February 25, 2004, 03:03:12 pm
That's fixed it. Thanks.
Title: CloneObject and lighting
Post by: EgonOlsen on February 25, 2004, 11:22:57 pm
Calling build() on anything that isn't a dummy object is required in almost every case (or call World.buildAllObjects()...but that can only build the objects that have already been attached to the world). I thought about handling this internally, but there are too many places in the code, where a correctly "builded" object is required, so this would result in a gazillion of "if (!hasBeenBuild) {this.build();} in the code and that's quite ugly.
Another problem is, that the engine can't decide if it's a good time to build an object or not.
That's why it's up to the user to call build(). However, calling build on the template is sufficient. There's no need to call it on cloned objects because they inherit the mesh data from the source.