use of org.rajawali3d.lights.DirectionalLight in project Rajawali by Rajawali.
the class RajawaliVRExampleRenderer method initScene.
@Override
public void initScene() {
DirectionalLight light = new DirectionalLight(0.2f, -1f, 0f);
light.setPower(.7f);
getCurrentScene().addLight(light);
light = new DirectionalLight(0.2f, 1f, 0f);
light.setPower(1f);
getCurrentScene().addLight(light);
getCurrentCamera().setFarPlane(1000);
getCurrentScene().setBackgroundColor(0xdddddd);
createTerrain();
try {
getCurrentScene().setSkybox(R.drawable.posx, R.drawable.negx, R.drawable.posy, R.drawable.negy, R.drawable.posz, R.drawable.negz);
LoaderAWD loader = new LoaderAWD(getContext().getResources(), getTextureManager(), R.raw.space_cruiser);
loader.parse();
Material cruiserMaterial = new Material();
cruiserMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
cruiserMaterial.setColorInfluence(0);
cruiserMaterial.enableLighting(true);
cruiserMaterial.addTexture(new Texture("spaceCruiserTex", R.drawable.space_cruiser_4_color_1));
Object3D spaceCruiser = loader.getParsedObject();
spaceCruiser.setMaterial(cruiserMaterial);
spaceCruiser.setZ(-6);
spaceCruiser.setY(1);
getCurrentScene().addChild(spaceCruiser);
spaceCruiser = spaceCruiser.clone(true);
spaceCruiser.setZ(-12);
spaceCruiser.setY(-3);
spaceCruiser.setRotY(180);
getCurrentScene().addChild(spaceCruiser);
loader = new LoaderAWD(getContext().getResources(), getTextureManager(), R.raw.dark_fighter);
loader.parse();
Material darkFighterMaterial = new Material();
darkFighterMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
darkFighterMaterial.setColorInfluence(0);
darkFighterMaterial.enableLighting(true);
darkFighterMaterial.addTexture(new Texture("darkFighterTex", R.drawable.dark_fighter_6_color));
Object3D darkFighter = loader.getParsedObject();
darkFighter.setMaterial(darkFighterMaterial);
darkFighter.setZ(-6);
getCurrentScene().addChild(darkFighter);
CatmullRomCurve3D path = new CatmullRomCurve3D();
path.addPoint(new Vector3(0, -5, -10));
path.addPoint(new Vector3(10, -5, 0));
path.addPoint(new Vector3(0, -4, 8));
path.addPoint(new Vector3(-16, -6, 0));
path.isClosedCurve(true);
SplineTranslateAnimation3D anim = new SplineTranslateAnimation3D(path);
anim.setDurationMilliseconds(44000);
anim.setRepeatMode(RepeatMode.INFINITE);
// -- orient to path
anim.setOrientToPath(true);
anim.setTransformable3D(darkFighter);
getCurrentScene().registerAnimation(anim);
anim.play();
loader = new LoaderAWD(getContext().getResources(), getTextureManager(), R.raw.capital);
loader.parse();
Material capitalMaterial = new Material();
capitalMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
capitalMaterial.setColorInfluence(0);
capitalMaterial.enableLighting(true);
capitalMaterial.addTexture(new Texture("capitalTex", R.drawable.hullw));
capitalMaterial.addTexture(new NormalMapTexture("capitalNormTex", R.drawable.hulln));
capital = loader.getParsedObject();
capital.setMaterial(capitalMaterial);
capital.setScale(18);
getCurrentScene().addChild(capital);
path = new CatmullRomCurve3D();
path.addPoint(new Vector3(0, 13, 34));
path.addPoint(new Vector3(34, 13, 0));
path.addPoint(new Vector3(0, 13, -34));
path.addPoint(new Vector3(-34, 13, 0));
path.isClosedCurve(true);
anim = new SplineTranslateAnimation3D(path);
anim.setDurationMilliseconds(60000);
anim.setRepeatMode(RepeatMode.INFINITE);
anim.setOrientToPath(true);
anim.setTransformable3D(capital);
getCurrentScene().registerAnimation(anim);
anim.play();
} catch (Exception e) {
e.printStackTrace();
}
lookatSphere = new Sphere(1, 12, 12);
Material sphereMaterial = new Material();
sphereMaterial.setDiffuseMethod(new DiffuseMethod.Lambert());
sphereMaterial.enableLighting(true);
lookatSphere.setMaterial(sphereMaterial);
lookatSphere.setColor(Color.YELLOW);
lookatSphere.setPosition(0, 0, -6);
getCurrentScene().addChild(lookatSphere);
initAudio();
}
use of org.rajawali3d.lights.DirectionalLight in project Rajawali by Rajawali.
the class WallpaperRenderer method initScene.
@Override
protected void initScene() {
ALight light = new DirectionalLight(-1, 0, -1);
light.setPower(2);
getCurrentScene().addLight(light);
getCurrentCamera().setPosition(0, 0, 7);
getCurrentCamera().setLookAt(0, 0, 0);
try {
Cube cube = new Cube(1);
Material material = new Material();
material.enableLighting(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());
material.addTexture(new Texture("rajawaliTex", R.drawable.rajawali_tex));
material.setColorInfluence(0);
cube.setMaterial(material);
getCurrentScene().addChild(cube);
Vector3 axis = new Vector3(3, 1, 6);
axis.normalize();
Animation3D anim = new RotateOnAxisAnimation(axis, 0, 360);
anim.setDurationMilliseconds(8000);
anim.setRepeatMode(Animation.RepeatMode.INFINITE);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.setTransformable3D(cube);
getCurrentScene().registerAnimation(anim);
anim.play();
} catch (ATexture.TextureException e) {
e.printStackTrace();
}
}
use of org.rajawali3d.lights.DirectionalLight in project Rajawali by Rajawali.
the class LoaderFBX method parse.
@Override
public LoaderFBX parse() throws ParsingException {
super.parse();
BufferedReader buffer = null;
if (mFile == null) {
InputStream fileIn = mResources.openRawResource(mResourceId);
buffer = new BufferedReader(new InputStreamReader(fileIn));
} else {
try {
buffer = new BufferedReader(new FileReader(mFile));
} catch (FileNotFoundException e) {
RajLog.e("[" + getClass().getCanonicalName() + "] Could not find file.");
throw new ParsingException(e);
}
}
String line;
try {
while ((line = buffer.readLine()) != null) {
String repl = line.replaceAll(REGEX_CLEAN, REPLACE_EMPTY);
if (repl.length() == 0 || repl.charAt(0) == COMMENT)
continue;
readLine(buffer, line);
}
buffer.close();
} catch (Exception e) {
throw new ParsingException(e);
}
// -- get lights
Stack<Model> lights = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_LIGHT);
int numLights = lights.size();
Renderer.setMaxLights(numLights == 0 ? 1 : numLights);
Stack<ALight> sceneLights = new Stack<ALight>();
for (int i = 0; i < numLights; ++i) {
Model l = lights.get(i);
// -- really need to add more light types
sceneLights.add(buildLight(l));
}
if (numLights == 0) {
ALight light = new DirectionalLight();
light.setPosition(2, 0, -5);
light.setPower(1);
sceneLights.add(light);
}
// -- check fog
//TODO: add fog support
/*if(mFbx.version5.fogOptions.fogEnable != null && mFbx.version5.fogOptions.fogEnable == 1) {
FogOptions fogOptions = mFbx.version5.fogOptions;
mRenderer.setFogEnabled(true);
Camera cam = mRenderer.getCamera();
cam.setFogEnabled(true);
cam.setFogNear(fogOptions.fogStart);
cam.setFogColor(fogOptions.fogColor.color);
mRenderer.setBackgroundColor(fogOptions.fogColor.color);
}*/
// -- get meshes
Stack<Model> models = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_MESH);
try {
for (int i = 0; i < models.size(); ++i) {
buildMesh(models.get(i), sceneLights);
}
} catch (TextureException tme) {
throw new ParsingException(tme);
}
// -- get cameras
Stack<Model> cameras = mFbx.objects.getModelsByType(FBXValues.MODELTYPE_CAMERA);
Model camera = null;
for (int i = 0; i < cameras.size(); ++i) {
if (cameras.get(i).hidden == null || !cameras.get(i).hidden.equals("True")) {
camera = cameras.get(i);
break;
}
}
if (camera != null) {
//TODO: FIX
Camera cam = mRenderer.getCurrentCamera();
cam.setPosition(camera.position);
cam.setX(mRenderer.getCurrentCamera().getX() * -1);
cam.setRotation(camera.properties.lclRotation);
Vector3 lookAt = camera.lookAt;
// lookAt.x = -lookAt.x;
cam.setLookAt(lookAt);
cam.setNearPlane(camera.properties.nearPlane);
cam.setFarPlane(camera.properties.farPlane);
cam.setFieldOfView(camera.properties.fieldOfView);
}
return this;
}
use of org.rajawali3d.lights.DirectionalLight in project Rajawali by Rajawali.
the class LoaderFBX method buildLight.
private ALight buildLight(Model l) {
int m = l.properties.lightType != null ? l.properties.lightType : ALight.POINT_LIGHT;
switch(m) {
case //Point
ALight.POINT_LIGHT:
PointLight light = new PointLight();
light.setPosition(l.properties.lclTranslation);
light.setX(light.getX() * -1f);
light.setRotation(l.properties.lclRotation);
light.setPower(l.properties.intensity / 100f);
light.setColor(l.properties.color);
//mRootObject.addLight(light);
return light;
case //Area
ALight.DIRECTIONAL_LIGHT:
//TODO calculate direction based on position and rotation
DirectionalLight lD = new DirectionalLight();
lD.setPosition(l.properties.lclTranslation);
lD.setX(lD.getX() * -1f);
lD.setRotation(l.properties.lclRotation);
lD.setPower(l.properties.intensity / 100f);
lD.setColor(l.properties.color);
//mRootObject.addLight(lD);
return lD;
default:
case //Spot
ALight.SPOT_LIGHT:
//TODO calculate direction based on position and rotation
SpotLight lS = new SpotLight();
lS.setPosition(l.properties.lclTranslation);
lS.setX(lS.getX() * -1f);
lS.setRotation(l.properties.lclRotation);
lS.setPower(l.properties.intensity / 100f);
lS.setCutoffAngle(l.properties.coneangle);
lS.setColor(l.properties.color);
lS.setLookAt(0, 0, 0);
//mRootObject.addLight(lS);
return lS;
}
}
use of org.rajawali3d.lights.DirectionalLight in project Rajawali by Rajawali.
the class LightsVertexShaderFragment method applyParams.
@Override
public void applyParams() {
super.applyParams();
int lightCount = mLights.size();
int dirCount = 0, spotCount = 0, attCount = 0;
for (int i = 0; i < lightCount; i++) {
ALight light = mLights.get(i);
int t = light.getLightType();
GLES20.glUniform3fv(muLightColorHandles[i], 1, light.getColor(), 0);
GLES20.glUniform1f(muLightPowerHandles[i], light.getPower());
GLES20.glUniform3fv(muLightPositionHandles[i], 1, ArrayUtils.convertDoublesToFloats(light.getPositionArray(), mTemp3Floats), 0);
if (t == ALight.SPOT_LIGHT) {
SpotLight l = (SpotLight) light;
GLES20.glUniform3fv(muLightDirectionHandles[spotCount], 1, ArrayUtils.convertDoublesToFloats(l.getDirection(), mTemp3Floats), 0);
GLES20.glUniform4fv(muLightAttenuationHandles[attCount], 1, l.getAttenuation(), 0);
//GLES20.glUniform1f(muSpotExponentHandles[spotCount], l.get)
GLES20.glUniform1f(muSpotCutoffAngleHandles[spotCount], l.getCutoffAngle());
GLES20.glUniform1f(muSpotFalloffHandles[spotCount], l.getFalloff());
spotCount++;
dirCount++;
attCount++;
} else if (t == ALight.POINT_LIGHT) {
PointLight l = (PointLight) light;
GLES20.glUniform4fv(muLightAttenuationHandles[attCount], 1, l.getAttenuation(), 0);
attCount++;
} else if (t == ALight.DIRECTIONAL_LIGHT) {
DirectionalLight l = (DirectionalLight) light;
GLES20.glUniform3fv(muLightDirectionHandles[dirCount], 1, ArrayUtils.convertDoublesToFloats(l.getDirection(), mTemp3Floats), 0);
dirCount++;
}
}
GLES20.glUniform3fv(muAmbientColorHandle, 1, mAmbientColor, 0);
GLES20.glUniform3fv(muAmbientIntensityHandle, 1, mAmbientIntensity, 0);
}
Aggregations