JME 3 Alpha4 : Lighting problems (Solved)

Hi,



This post follows this one : ( The solution found in the previous post doesn’t seem to work with alpha 4 )

http://hub.jmonkeyengine.org/groups/general-2/forum/topic/adding-child-to-an-existing-element-to-inherits-its-lights/



I’m importing a 3D object via OgreXML.

This object contains the battleground and some lightings.



When I’m importing the object, I gave to scale it to the correct size and translate it so that it fill the area :

(0,0) ____________ (W, 0)

| _________________ |

| _________________ |

| _________________ |

(0,D) ____________ (W, D)



For that I use this code :

[java]

BoundingBox box = ((BoundingBox)battlegroundModel.getWorldBound());



float currentWidth = box.getXExtent();

float currentHeight = box.getYExtent();

float currentDepth = box.getZExtent();



//Scale

float scaleX = width / ( currentWidth * 2 );

float scaleZ = depth / ( currentDepth * 2 );

float scaleY = ( scaleX + scaleZ ) / 2 ;

battlegroundModel.scale( scaleX, scaleY, scaleZ );



battlegroundModel.setLocalTranslation( currentWidth * scaleX, currentHeight * scaleY, currentDepth * scaleZ );

[/java]



My first problem is as follow :

When I’m translation the battlegroundModel the lights are not following and my scene who was first like this :



became like this :







I think I will have another problem with the behavior of the method breadthFirstTraversal.

But I must first fix this translate problem :slight_smile:



Thanks in advance !

Lights are always in world space and are not affected by the transform of the node they are attached to.

Aarg, Is there a way to move them manually ?

I didn’t see any method like setLocalTranslation() the Light object



What I intend to do anyway, is to remove the from the object is loaded and add the to the root node ( So that other object can be affected by it )

So is there a way to change the method you gave me so that it will take a translation into account ? :slight_smile:



[java]

final Vector3f lightTranslation = …

final Node rootNode = …



scene.breadthFirstTraversal(new SceneGraphVisitor(){

public void visit(Spatial spatial){

for (Light l : spatial.getLocalLightList())

{

//l.move( lightTranslation ); Something like that ?

rootNode.addLight(l);

}

spatial.getLocalLightList().clear();

}

});[/java]

l.setPosition?

Ergg… I should have check the API before asking questions…



Light does not have a setPosition() but PointLight has it… I just have use l.getType() to see if I need to move it.



I will try that ! Thanks!



Edit :

Excellent, it works!



Just one last think :

LightType.Directional–> DirectionalLight

LightType.Point → PointLight

LightType.Ambient–> AmbientLight

LightType.Spot → ?? DirectionalLight ?

Spot does not exist (yet)

Ok, that settle it!



Thanks !