Light

I need to know how to create a light bulb. This would be for blinking lights on a helicopter. Right now I am using a PointLight which is how I created it in JME 1 but now the light only illuminates when the scene light is pointing on it. If its not pointing on it its gray or black. I need it to be lit even in a dark scene. Also I used a controller before to turn the light on and off by setting the enabled to false then back to true in a timed interval. Setting the light enabled to false doesn’t do anything. I am using JME3 r6518.



Here is a code sample.



pre type="java"
ColorRGBA lightColor = (vertex.validColor()) ? vertex.getPackedColor() : new ColorRGBA(1,1,1,1);


        ColorRGBA frontIntensityColor = lightColor.multLocal(intensityFront);


        Point point = new Point(vertex.getCoord(), vertex.getNormal());





PointLight light = new PointLight();


         light.setColor(frontIntensityColor);


         light.setPosition(new Vector3f(vertex.getNormal()));


         light.setRadius(actualPixelSize  180f);


         light.setEnabled(true);


         point.setPointSize(actualPixelSize 
 20f);


        lightGeom = new FlightGeom(id + “_omnilight”,point);


        lightGeom.addLight(light);





Material material = new Material(doc.assetManager,“Common/MatDefs/Light/Lighting.j3md”);


        material.setFloat(“Shininess”, Float.MAX_VALUE);


        material.setBoolean(“UseMaterialColors”, true);


        material.setColor(“Ambient”,  frontIntensityColor);


        material.setColor(“Diffuse”,  frontIntensityColor);


        material.setColor(“Specular”, ColorRGBA.White);


        material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);


        lightGeom.setMaterial(material);


        lightGeom.setModelBound(new BoundingSphere());


        lightGeom.updateModelBound();


        ((Node)node).attachChild(lightGeom);


       





        // if the flashing or rotating bit is set in the flags, add a blink sequence


        if (((flags & FLASHING) != 0) || ((flags & ROTATING) != 0)){


         LightAnimationController nac;


nac = new LightAnimationController(node,id,animationPeriodEnable,animationPeriod,-1,1.0f,(animationPeriod - animationPeriodEnable), doc);


node.addControl(nac);


        }
/pre

Instead creating a point light and attach it to the lightGeom you could use glow map.

edit : or glow color.

For the light, you can use the unshaded material so it is not effected by lighting

@Momoko_Fan: The only way to “cast light” to a geom with an unshaded material is using light map, right?

What is the point in even having the light then. I can comment the addLight code out when using the unshaded and its no different than having the light. Also why does the setEnabled not work. If I set the light to enabled false. The material overrides it if it does work. It still lights up.

Yes

andy_g said:
...but now the light only illuminates when the scene light is pointing on it. If its not pointing on it its gray or black...


Thus I think you will never see the lightGeom outside lights up, independently of the face cull mode. Did you try the unshaded material with glow map or glow color?

Is there any way to create a light and be able to turn it on and off? I am having to switch the material from the desired color to black to give the illusion the light is blinking.

andy_g said:
Is there any way to create a light and be able to turn it on and off?


By adding and removing it from its parent.

I have tried it with unshaded and glow color. The geometry is all white. I do not have a texture so there is no need for glowmap.

andy_g said:
I have tried it with unshaded and glow color. The geometry is all white. I do not have a texture so there is no need for glowmap.

And what color did you want :??
Control the glow effect with a bloom filter : https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:bloom_and_glow

I got the glow color working and like the way the bloom works but I have a problem the bloom glows through other models, terrain and buildings if the model is located behind one of these. Not good.

Is there a setting that keep it from having this behavior?

I don’t know, but looking at your code you shouldn’t add the point light to the lightGeom, you should add it to the rootNode and keep them in the same location instead.

[java]

public void simpleInitApp() {



rootNode.add(lightGeom);

Vector3f loc = lightGeom.getLocalTranslation();

PointLight light = new PointLight();

light.setLocation(loc);

rootNode.addLight(light);



}



public void simpleUpdate() {

//do something here to keep them in the same location

}

[/java]