Search code examples
android3dlive-wallpaper

Load 3d .obj file and add background image to live wallpaper in android?


i want to load a 3d .obj file in live wallpaper and animate it. i use RAJAWALI library to load it. the problem is that the the 3d obj file is load and animate successfully but Loading background image are not loaded in some android devices. code is follow:

protected void initScene() {


    DirectionalLight localDirectionalLight = new DirectionalLight(0.0F, 0.6F, 0.4F);
localDirectionalLight.setPower(3.0F);
PointLight mLight = new PointLight();
mLight.setPosition(0, 0, 0);
mLight.setPower(13);
Plane plane = new Plane(70, 70, 1, 1, 1);
plane.addLight(mLight);
plane.setMaterial(new SimpleMaterial());
plane.addTexture(mTextureManager.addTexture(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.pozadina)));  
addChild(plane);    
plane.setZ(10);

    try
    {
      ObjParser localObjParser = new ObjParser(this.mContext.getResources(), this.mTextureManager, R.raw.allah);
      localObjParser.parse();
      this.strela = localObjParser.getParsedObject();
      this.strela.addLight(localDirectionalLight);
      if (this.tekstura == null)
      {
        BitmapFactory.Options localOptions2 = new BitmapFactory.Options();
        localOptions2.inPurgeable = true;

        this.strela.setColor(Color.WHITE);
      }
      this.strela.setScale(2.0F);
      addChild(this.strela);
      this.mCamera.setPosition(0.0F, 0.0F, -50.0F);
      this.mCamera.setFarPlane(1000.0F);
      Number3D localNumber3D = new Number3D(0.0F, 1.0F, 0.0F);
      localNumber3D.normalize();
      this.mAnim = new RotateAnimation3D(localNumber3D, 360.0F);
      this.mAnim.setDuration(10000L);
      this.mAnim.setRepeatCount(-1);
      this.mAnim.setTransformable3D(this.strela);

      return; 
    }
    catch (Exception localException)
    {
      while (true)
        localException.printStackTrace();
    }


}

it give problem on SAMSUNG NEXUS android v4.1.

please help how can i do it?


Solution

  • This is tested and working on Galaxy S3. So it should work for you as well. I use it in my wallpapers. Try this:

        SimpleMaterial localSimpleMaterial = new SimpleMaterial();
        Bitmap localBitmap = BitmapFactory.decodeResource(this.mContext.getResources(), R.drawable.image);
        localSimpleMaterial.addTexture(this.mTextureManager.addTexture(localBitmap));
        Plane localPlane = new Plane(10.0F, 10.0F, 1, 1);
        localPlane.setRotZ(-90.0F);
        localPlane.setScale(3.7F);
        localPlane.setPosition(0.0F, 0.0F, 10.0F);
        localPlane.setMaterial(localSimpleMaterial);
        addChild(localPlane);
    

    Just make sure that your image is power of two, i.e., 256x256, 512x512, etc. Let me know how it works for you.

    Edit: Also make sure you import rajawali.primitives not rajawali.math