Cloning animated 3D objects (min3D framework for Android)

Posted by Dennis on May 26, 2010 in 3D, AndroidNo comments

These two examples show how you can clone animated objects with min3D. The first example makes a shallow copy of the object. All the vertices, normals and texture coordinates are shared between all the objects. Only the first object transforms all the data for each keyframe. The rest of the objects are updated automatically.

Another option is to clone an object and clone all its vertices, uv coordinates and normals. This way the animation can be controlled indepently for each object.

This example creates shallow copies:


package rozengain.min3doom;

import min3d.animation.AnimationObject3d;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Min3DoomActivity extends RendererActivity {
	private AnimationObject3d doomGuy;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
	}

	@Override
	public void initScene() {
		IParser parser = Parser.createParser(Parser.Type.MD2, getResources(),
				"rozengain.min3doom:raw/doomguy");
		parser.parse();
		doomGuy = parser.getParsedAnimationObject();
		doomGuy.scale().x = doomGuy.scale().y = doomGuy.scale().z = .01f;
		doomGuy.rotation().z = -90;
		doomGuy.rotation().x = -90;
		doomGuy.position().x = -.3f;
		doomGuy.position().z = -1f;
		scene.addChild(doomGuy);
		doomGuy.setFps(20);
		doomGuy.play();

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				// -- create a shallow copy
				AnimationObject3d doomGuyClone = (AnimationObject3d) doomGuy
						.clone(false);
				scene.addChild(doomGuyClone);
				doomGuyClone.position().x += .3 * i;
				doomGuyClone.position().z += 1.5 * j;
				if(i % 2 == 1) doomGuyClone.position().z += .5;
				// -- prevent this object from updating the vertices.
				doomGuyClone.setUpdateVertices(false);
			}
		}

		scene.camera().position.y = 1;
		scene.camera().position.z = 2;
	}

	@Override
	public void updateScene() {

	}
}

See the youtube video here:

Gay dancing Doom guys

This example copies the all the vertices, normals, texture coordinates, etc so that all the objects can be animated independently:


package rozengain.min3doom2;

import min3d.animation.AnimationObject3d;
import min3d.core.RendererActivity;
import min3d.parser.IParser;
import min3d.parser.Parser;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Min3Doom2Activity extends RendererActivity {
	private AnimationObject3d doomGuy;
	private AnimationObject3d doomGuyClone;
	private int frameCounter = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
	}

	@Override
	public void initScene() {
		IParser parser = Parser.createParser(Parser.Type.MD2, getResources(),
				"rozengain.min3doom2:raw/doomguy");
		parser.parse();
		doomGuy = parser.getParsedAnimationObject();
		doomGuy.scale().x = doomGuy.scale().y = doomGuy.scale().z = .01f;
		doomGuy.rotation().z = -90;
		doomGuy.rotation().x = -90;
		doomGuy.position().x = -.2f;
		doomGuy.position().z = -.5f;
		scene.addChild(doomGuy);
		doomGuy.setFps(20);
		doomGuy.play();

		// -- create a deep copy
		doomGuyClone = (AnimationObject3d) doomGuy.clone(true);
		doomGuyClone.position().x = .2f;
		scene.addChild(doomGuyClone);

		scene.camera().position.z = 1;
	}

	@Override
	public void updateScene() {
		// -- start playing a bit later
		if(frameCounter++ == 100)
			doomGuyClone.play();
	}
}

See the youtube video here:



Tags: , , , ,


Leave a comment