CloneObject and lighting

Started by acorn98, February 25, 2004, 05:03:16 AM

Previous topic - Next topic

acorn98

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..

EgonOlsen

Have you called build() on them, i.e.

enemyTemplate.build();

acorn98


EgonOlsen

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.