protected void initScene() { DirectionalLight light = new DirectionalLight(0, 0, 1); getCurrentScene().addLight(light); getCurrentCamera().setPosition(0, 0, -16); mPlanes = new PlanesGalore(); mMaterial = mPlanes.getMaterial(); mMaterial.setColorInfluence(0); try { mMaterial.addTexture(new Texture("flickrPics", R.drawable.flickrpics)); } catch (TextureException e) { e.printStackTrace(); } mMaterialPlugin = mPlanes.getMaterialPlugin(); mPlanes.setDoubleSided(true); mPlanes.setZ(4); addChild(mPlanes); Object3D empty = new Object3D(); addChild(empty); CatmullRomCurve3D path = new CatmullRomCurve3D(); path.addPoint(new Vector3(-4, 0, -20)); path.addPoint(new Vector3(2, 1, -10)); path.addPoint(new Vector3(-2, 0, 10)); path.addPoint(new Vector3(0, -4, 20)); path.addPoint(new Vector3(5, 10, 30)); path.addPoint(new Vector3(-2, 5, 40)); path.addPoint(new Vector3(3, -1, 60)); path.addPoint(new Vector3(5, -1, 70)); mCamAnim = new TranslateAnimation3D(path); mCamAnim.setDuration(20000); mCamAnim.setRepeatMode(RepeatMode.REVERSE_INFINITE); mCamAnim.setTransformable3D(getCurrentCamera()); mCamAnim.setInterpolator(new AccelerateDecelerateInterpolator()); registerAnimation(mCamAnim); mCamAnim.play(); getCurrentCamera().setLookAt(new Vector3(0, 0, 30)); }
private Material getMaterialForMesh(Object3D o, String name) { Material mat = new Material(); FBXMaterial material = null; Stack<Connect> conns = mFbx.connections.connections; int num = conns.size(); String materialName = null; for (int i = 0; i < num; ++i) { if (conns.get(i).object2.equals(name)) { materialName = conns.get(i).object1; break; } } if (materialName != null) { Stack<FBXMaterial> materials = mFbx.objects.materials; num = materials.size(); for (int i = 0; i < num; ++i) { if (materials.get(i).name.equals(materialName)) { material = materials.get(i); break; } } } if (material != null) { mat.setDiffuseMethod(new DiffuseMethod.Lambert()); mat.enableLighting(true); Vector3 color = material.properties.diffuseColor; mat.setColor( Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f))); color = material.properties.ambientColor; mat.setAmbientColor( Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f))); float intensity = material.properties.ambientFactor.floatValue(); mat.setAmbientIntensity(intensity, intensity, intensity); if (material.shadingModel.equals("phong")) { SpecularMethod.Phong method = new SpecularMethod.Phong(); if (material.properties.specularColor != null) { color = material.properties.specularColor; method.setSpecularColor( Color.rgb((int) (color.x * 255.f), (int) (color.y * 255.f), (int) (color.z * 255.f))); } if (material.properties.shininess != null) method.setShininess(material.properties.shininess); } } return mat; }
public void onDrawFrame(GL10 glUnused) { super.onDrawFrame(glUnused); mMaterial.setTime((System.currentTimeMillis() - mStartTime) / 1000f); mMaterialPlugin.setCameraPosition(getCurrentCamera().getPosition()); }
protected void initScene() { PointLight light = new PointLight(); light.setZ(6); light.setPower(2); getCurrentScene().addLight(light); Texture jetTexture = new Texture("jetTexture", R.drawable.jettexture); SphereMapTexture sphereMapTexture = new SphereMapTexture("manilaSphereMapTex", R.drawable.manila_sphere_map); jetTexture.setInfluence(.8f); // -- important! sphereMapTexture.isEnvironmentTexture(true); sphereMapTexture.setInfluence(.2f); Object3D jet1 = null; // -- sphere map with texture try { Material material1 = new Material(); material1.enableLighting(true); material1.setDiffuseMethod(new DiffuseMethod.Lambert()); material1.addTexture(jetTexture); material1.addTexture(sphereMapTexture); ObjectInputStream ois; ois = new ObjectInputStream(mContext.getResources().openRawResource(R.raw.jet)); jet1 = new Object3D((SerializedObject3D) ois.readObject()); jet1.setMaterial(material1); jet1.setY(2.5f); addChild(jet1); } catch (Exception e) { e.printStackTrace(); } Vector3 axis = new Vector3(2, -4, 1); axis.normalize(); Animation3D anim1 = new RotateAnimation3D(axis, 360); anim1.setRepeatMode(RepeatMode.INFINITE); anim1.setDuration(12000); anim1.setTransformable3D(jet1); registerAnimation(anim1); anim1.play(); sphereMapTexture = new SphereMapTexture("manilaSphereMapTex2", R.drawable.manila_sphere_map); sphereMapTexture.isEnvironmentTexture(true); sphereMapTexture.setInfluence(.5f); Material material2 = new Material(); // -- important, indicate that we want to mix the sphere map with a color material2.enableLighting(true); material2.setDiffuseMethod(new DiffuseMethod.Lambert()); try { material2.addTexture(sphereMapTexture); } catch (TextureException e) { e.printStackTrace(); } material2.setColorInfluence(.5f); Object3D jet2 = jet1.clone(false); jet2.setMaterial(material2); // -- also specify a color jet2.setColor(0xff666666); jet2.setY(-2.5f); addChild(jet2); Animation3D anim2 = new RotateAnimation3D(axis, -360); anim2.setRepeatMode(RepeatMode.INFINITE); anim2.setDuration(12000); anim2.setTransformable3D(jet2); registerAnimation(anim2); anim2.play(); getCurrentCamera().setPosition(0, 0, 14); }
protected void initScene() { DirectionalLight light = new DirectionalLight(0, -.6f, .4f); light.setPower(1); getCurrentScene().addLight(light); // -- create sky sphere mSphere = new Sphere(400, 8, 8); Material sphereMaterial = new Material(); try { sphereMaterial.addTexture(new Texture("skySphere", R.drawable.skysphere)); } catch (TextureException e1) { e1.printStackTrace(); } mSphere.setMaterial(sphereMaterial); mSphere.setDoubleSided(true); addChild(mSphere); try { // -- load gzipped serialized object ObjectInputStream ois; GZIPInputStream zis = new GZIPInputStream(mContext.getResources().openRawResource(R.raw.raptor)); ois = new ObjectInputStream(zis); mRaptor = new Object3D((SerializedObject3D) ois.readObject()); Material raptorMaterial = new Material(); raptorMaterial.setDiffuseMethod(new DiffuseMethod.Lambert()); raptorMaterial.enableLighting(true); raptorMaterial.addTexture(new Texture("raptorTex", R.drawable.raptor_texture)); mRaptor.setMaterial(raptorMaterial); mRaptor.setScale(.5f); addChild(mRaptor); } catch (Exception e) { e.printStackTrace(); } // -- create a bunch of cubes that will serve as orientation helpers mCubes = new Object3D[30]; mRootCube = new Cube(1); Material rootCubeMaterial = new Material(); rootCubeMaterial.setDiffuseMethod(new DiffuseMethod.Lambert()); rootCubeMaterial.enableLighting(true); try { rootCubeMaterial.addTexture(new Texture("camouflage", R.drawable.camouflage)); } catch (TextureException e) { e.printStackTrace(); } mRootCube.setMaterial(rootCubeMaterial); mRootCube.setY(-1f); // -- similar objects with the same material, optimize mRootCube.setRenderChildrenAsBatch(true); addChild(mRootCube); mCubes[0] = mRootCube; for (int i = 1; i < mCubes.length; ++i) { Object3D cube = mRootCube.clone(true); cube.setY(-1f); cube.setZ(i * 30); mRootCube.addChild(cube); mCubes[i] = cube; } // -- create a chase camera // the first parameter is the camera offset // the second parameter is the interpolation factor ChaseCamera chaseCamera = new ChaseCamera(new Vector3(0, 3, 16), .1f); // -- tell the camera which object to chase chaseCamera.setObjectToChase(mRaptor); // -- set the far plane to 1000 so that we actually see the sky sphere chaseCamera.setFarPlane(1000); replaceAndSwitchCamera(chaseCamera, 0); }
/** * Copies this material's textures to another material. * * @param material * @throws TextureException */ public void copyTexturesTo(Material material) throws TextureException { int num = mTextureList.size(); for (int i = 0; i < num; ++i) material.addTexture(mTextureList.get(i)); }
public void initScene() { // // -- Pack all textures in the "assets/atlas" folder into an 1024x1024 atlas // -- this should be used to simplify implementation of multiple textures // -- and to reduce texture binding calls to the GPU for increased performance // mAtlas = new TexturePacker(mContext).packTexturesFromAssets(1024, 1024, 0, false, "atlas"); mAtlasMaterial = new Material(); mSphereMaterial = new Material(); mCubeMaterial = new Material(); mPlaneMaterial = new Material(); try { // // -- Add the entire atlas to a material so it can be shown in the example // -- this is not necessary in typical use cases // mAtlasMaterial.addTexture(new Texture("atlasTexture", mAtlas.getPages()[0])); mAtlasMaterial.setColorInfluence(0); // // -- Add each target texture to the material // -- they are pulled from the atlas by their original resource name // mSphereMaterial.addTexture(new Texture("earthtruecolor_nasa_big", mAtlas)); mSphereMaterial.setColorInfluence(0); mCubeMaterial.addTexture(new Texture("camden_town_alpha", mAtlas)); mCubeMaterial.setColorInfluence(0); mPlaneMaterial.addTexture(new Texture("rajawali", mAtlas)); mPlaneMaterial.setColorInfluence(0); } catch (TextureException e) { e.printStackTrace(); } // // -- Show the full atlas for demonstration purposes // mAtlasPlane = new Plane(Axis.Z); mAtlasPlane.setMaterial(mAtlasMaterial); mAtlasPlane.setY(1); addChild(mAtlasPlane); mTileSphere = new Sphere(.35f, 20, 20); mTileSphere.setMaterial(mAtlasMaterial); // // -- The method 'setAtlasTile' is used to scale the UVs of the target object // -- so that the appropriate image within the atlas is displayed // mTileSphere.setAtlasTile("earthtruecolor_nasa_big", mAtlas); mTileSphere.setPosition(0, -.1f, 0); addChild(mTileSphere); mTileCube = new Cube(.5f); mTileCube.setMaterial(mAtlasMaterial); mTileCube.setAtlasTile("camden_town_alpha", mAtlas); mTileCube.setPosition(-.5f, -1f, 0); mTileCube.setRotX(-1); addChild(mTileCube); mTilePlane = new Plane(.6f, .6f, 1, 1); mTilePlane.setMaterial(mAtlasMaterial); mTilePlane.setAtlasTile("rajawali", mAtlas); mTilePlane.setPosition(.5f, -1f, 0); addChild(mTilePlane); }