Author Topic: CloneObject and lighting  (Read 6885 times)

Offline acorn98

  • byte
  • *
  • Posts: 46
    • View Profile
CloneObject and lighting
« 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..

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
CloneObject and lighting
« Reply #1 on: February 25, 2004, 07:57:16 am »
Have you called build() on them, i.e.

Code: [Select]
enemyTemplate.build();

Offline acorn98

  • byte
  • *
  • Posts: 46
    • View Profile
CloneObject and lighting
« Reply #2 on: February 25, 2004, 03:03:12 pm »
That's fixed it. Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
CloneObject and lighting
« Reply #3 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.