use of org.rajawali3d.materials.textures.Texture 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.materials.textures.Texture in project Rajawali by Rajawali.
the class RajawaliVRExampleRenderer method createTerrain.
public void createTerrain() {
//
// -- Load a bitmap that represents the terrain. Its color values will
// be used to generate heights.
//
Bitmap bmp = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.terrain);
try {
SquareTerrain.Parameters terrainParams = SquareTerrain.createParameters(bmp);
// -- set terrain scale
terrainParams.setScale(4f, 54f, 4f);
// -- the number of plane subdivisions
terrainParams.setDivisions(128);
// -- the number of times the textures should be repeated
terrainParams.setTextureMult(4);
//
// -- Terrain colors can be set by manually specifying base, middle and
// top colors.
//
// -- terrainParams.setBasecolor(Color.argb(255, 0, 0, 0));
// terrainParams.setMiddleColor(Color.argb(255, 200, 200, 200));
// terrainParams.setUpColor(Color.argb(255, 0, 30, 0));
//
// -- However, for this example we'll use a bitmap
//
terrainParams.setColorMapBitmap(bmp);
//
// -- create the terrain
//
terrain = TerrainGenerator.createSquareTerrainFromBitmap(terrainParams, true);
} catch (Exception e) {
e.printStackTrace();
}
//
// -- The bitmap won't be used anymore, so get rid of it.
//
bmp.recycle();
//
// -- A normal map material will give the terrain a bit more detail.
//
Material material = new Material();
material.enableLighting(true);
material.useVertexColors(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());
try {
Texture groundTexture = new Texture("ground", R.drawable.ground);
groundTexture.setInfluence(.5f);
material.addTexture(groundTexture);
material.addTexture(new NormalMapTexture("groundNormalMap", R.drawable.groundnor));
material.setColorInfluence(0);
} catch (TextureException e) {
e.printStackTrace();
}
//
// -- Blend the texture with the vertex colors
//
material.setColorInfluence(.5f);
terrain.setY(-100);
terrain.setMaterial(material);
getCurrentScene().addChild(terrain);
}
use of org.rajawali3d.materials.textures.Texture in project Rajawali by Rajawali.
the class LoaderFBX method setMeshTextures.
private void setMeshTextures(Object3D o, String name) throws TextureException, ParsingException {
Stack<FBXValues.Objects.Texture> textures = mFbx.objects.textures;
Stack<Connect> connections = mFbx.connections.connections;
int numTex = textures.size();
int numCon = connections.size();
for (int i = 0; i < numTex; ++i) {
FBXValues.Objects.Texture tex = textures.get(i);
for (int j = 0; j < numCon; ++j) {
Connect conn = connections.get(j);
if (conn.object2.equals(name) && conn.object1.equals(tex.textureName)) {
// -- one texture for now
String textureName = tex.fileName;
Bitmap bitmap = null;
if (mFile == null) {
int identifier = mResources.getIdentifier(getFileNameWithoutExtension(textureName).toLowerCase(Locale.US), "drawable", mResources.getResourcePackageName(mResourceId));
bitmap = BitmapFactory.decodeResource(mResources, identifier);
} else {
try {
String filePath = mFile.getParent() + File.separatorChar + getOnlyFileName(textureName);
bitmap = BitmapFactory.decodeFile(filePath);
} catch (Exception e) {
throw new ParsingException("[" + getClass().getCanonicalName() + "] Could not find file " + getOnlyFileName(textureName));
}
}
o.getMaterial().setColorInfluence(0);
o.getMaterial().addTexture(new Texture(textureName.replaceAll("[\\W]|_", ""), bitmap));
return;
}
}
}
}
use of org.rajawali3d.materials.textures.Texture in project Rajawali by Rajawali.
the class LoaderMD2 method parse.
public LoaderMD2 parse() throws ParsingException {
super.parse();
BufferedInputStream stream = null;
if (mFile == null) {
InputStream fileIn = mResources.openRawResource(mResourceId);
stream = new BufferedInputStream(fileIn);
} else {
try {
stream = new BufferedInputStream(new FileInputStream(mFile));
} catch (FileNotFoundException e) {
RajLog.e("[" + getClass().getCanonicalName() + "] Could not find file.");
throw new ParsingException(e);
}
}
mObject = new VertexAnimationObject3D();
mObject.setFps(10);
mHeader = new MD2Header();
try {
mHeader.parse(stream);
mFrames = new Stack<IAnimationFrame>();
for (int i = 0; i < mHeader.numFrames; ++i) mFrames.add(new VertexAnimationFrame());
byte[] bytes = new byte[mHeader.offsetEnd - 68];
stream.read(bytes);
getMaterials(stream, bytes);
float[] texCoords = getTexCoords(stream, bytes);
getFrames(stream, bytes);
getTriangles(stream, bytes, texCoords);
mObject.setFrames(mFrames);
IAnimationFrame firstFrame = mFrames.get(0);
Material material = new Material();
material.enableLighting(true);
material.setDiffuseMethod(new DiffuseMethod.Lambert());
material.addPlugin(new VertexAnimationMaterialPlugin());
mObject.getGeometry().copyFromGeometry3D(firstFrame.getGeometry());
mObject.setData(firstFrame.getGeometry().getVertexBufferInfo(), firstFrame.getGeometry().getNormalBufferInfo(), mTextureCoords, null, mIndices, false);
mObject.setMaterial(material);
mObject.setColor(0xffffffff);
if (mTexture != null) {
material.addTexture(new Texture(mCurrentTextureName, mTexture));
material.setColorInfluence(0);
}
stream.close();
} catch (Exception e) {
throw new ParsingException(e);
}
mObject.isContainer(false);
mRootObject = mObject;
return this;
}
use of org.rajawali3d.materials.textures.Texture 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();
}
}
Aggregations