" It only illuminates the one orb, not both, which is what I would want."
I want to illuminate both orbs.
I think I figured it out.
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Sphere;
import com.jme3.util.TangentBinormalGenerator;
import com.jme3.scene.Node;
import com.jme3.light.PointLight;
import com.jme3.scene.control.LightControl;
public class Main extends SimpleApplication {
Node ChildNodeA = new Node("ChildNodeA");
Node ChildNodeB = new Node("ChildNodeB");
Node LightNode = new Node("LightNode");
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
rootNode.attachChild(ChildNodeA);
rootNode.attachChild(ChildNodeB);
ChildNodeB.attachChild(LightNode); // <------------------------------- new code
/** A bumpy rock with a shiny light effect */
Sphere rock = new Sphere(32,32, 2f);
rock.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
TangentBinormalGenerator.generate(rock);
Material mat_lit = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat_lit.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
mat_lit.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
mat_lit.setBoolean("UseMaterialColors",true);
mat_lit.setColor("Specular",ColorRGBA.White);
mat_lit.setColor("Diffuse",ColorRGBA.White);
mat_lit.setFloat("Shininess", 5f); // [1,128]
Geometry shiny_rockA = new Geometry("Shiny rockA", rock);
shiny_rockA.setMaterial(mat_lit);
shiny_rockA.rotate(1.6f, 0, 0); // Rotate it a bit
ChildNodeA.attachChild(shiny_rockA);
Geometry shiny_rockB = new Geometry("Shiny rockB", rock);
shiny_rockB.setMaterial(mat_lit);
shiny_rockB.rotate(0, 1.6f, 0); // Rotate it a bit
ChildNodeB.attachChild(shiny_rockB);
/** Must add a light to make the lit object visible! */
PointLight lamp_light = new PointLight();
lamp_light.setColor(ColorRGBA.Red);
lamp_light.setRadius(50f);
rootNode.addLight(lamp_light);
LightControl lightControl = new LightControl(lamp_light);
LightNode.addControl(lightControl); // <------------------------------- new code
LightNode.setLocalTranslation(0, 0, 15);
ChildNodeA.setLocalTranslation(5, 0, 0);
ChildNodeB.setLocalTranslation(-5, 0, 0);
}
@Override
public void simpleUpdate(float tpf) {
ChildNodeA.rotate(0, 1f*tpf, 0);
ChildNodeB.rotate(1f*tpf, 0 , 0);
}
}
One new question that I have is that it seems that when I map a light to a control, the light must be located at the position of the Node that’s controlling it. When I tried to attach the light directly to Node ChildNodeB in the above example and then offset it a distance the light seemed to stay at the xyz coordinates of ChildNodeB. So if Node ChildNodeB is at xyz 3,0,0 and I set the lights location to be xyz 3,1,0, when I setup the light control the light seems to move to xyz 3,0,0 and even if I try to move it manually afterwords it always stays @ 3,0,0 , the location of the Node controlling it. To get around this I had to create a new Node “LightNode”, make it the child of ChildNodeB, made LightNode the controller for the point light (instead of ChildNodeB) and then move LightNode to the desired coordinates xyz 3,1,0.
Is this the correct way to do this? If I had for example a Car in a game and I wanted to add a headlight to it, am I correct that I wouldn’t set the light control to the Node of the car, but would instead need to create a child Node of the Car Node and position child node where I wanted the headlight to be, and then create a light control to the child Node?