Tutorial: Skin A PV3D Cube Using MovieAssetMaterial

Skin A PV3D Cube Using MovieAssetMaterial Screenshot

Objective
  • Learn about the properties that can be used in the generic object that you pass in to the MaterialsList constructor.
  • Learn how to use a movieclip as a material through its linkage id using MovieAssetMaterial.
Prerequisite
Files Required
Let’s Get Started!

This is a pretty simple tutorial, which basically elaborates more on the MaterialsList class, and in combination with the MovieAssetMaterial, creates a custom skinned cube.

private function init3D ():void
{
	// VIEWPORT
	viewport = new Viewport3D( 0, 0, true, false );
	addChild( viewport );
	//
	// RENDERER
	renderer = new BasicRenderEngine();
	//
	// SCENE
	scene = new Scene3D();
	//
	// CAMERA
	camera = new Camera3D();
	camera.zoom = 11;
	camera.focus = 100;
}

This function is generally similar with what we had in the previous tutorial, except for lines 15-16. What they do makes the cube in the scene look the same size as the movieclips that we have in the library. πŸ˜‰

private function createCube():void
{
	var materials:MaterialsList = new MaterialsList(
	{
		front: new MovieAssetMaterial( "front" ),
		back: new MovieAssetMaterial( "back" ),
		right: new MovieAssetMaterial( "right" ),
		left: new MovieAssetMaterial( "left" ),
		top: new MovieAssetMaterial( "top" ),
		bottom: new MovieAssetMaterial( "bottom" )
	} );
	//
	cube = new Cube( materials, 100, 100, 100, 10, 10, 10 );
	//
	scene.addChild( cube );
}

The first thing that you might notice that’s different will be the other properties of the generic object that we are passing into the MaterialsList constructor. Instead of the all property, we now describe each side of the cube using front, back, right, left, top and bottom properties.

With the ability to describe each side of the cube, we can now assign different materials to them, which is exactly what we have done. Each side is now an instance of the MovieAssetMaterial class, and pulls the movieclip that is residing in our library via their linkage id.

In line 13 where we create the cube, we are also inputting several additional parameters than before. We pass in "100" for the three subsequent parameters after "materials" to describe the width, depth and height of the cube respectively. Just in case you haven’t notice, the reason why we pass in "100", and not some other number, is because the movieclips that we are going to use as materials are 100×100. :)

To increase the rendering quality of our cube, we pass in "10" for the next three subsequent parameters, rather than taking the default value of "1".

Final Note

If you want your materials to be animated, simply change this:

new MovieAssetMaterial( "bottom" )

to this:

new MovieAssetMaterial( "bottom", false, true )

The third parameter allows animated movieclips to play. You can check out this example that I whipped up. :)

About Flashmech

I have too many things in plans for my own good. But well, that's me. :) I love God, praise Him, and trust that He has the best plans in life for me.
This entry was posted in ActionScript, Flash Platform, PaperVision3D, Tutorials. Bookmark the permalink.

4 Responses to Tutorial: Skin A PV3D Cube Using MovieAssetMaterial

  1. Pingback: Tutorial | Skin A PV3D Cube Using MovieAssetMaterial « Flash Enabled Blog

  2. Adrian says:

    Thanks for the clear tutorial. However I’m having a problem with the MovieAssetMaterial datatype. If i use a movie asset material for a plane, plane1= new MovieAssetMaterial( “mc” ) Is there anyway I can create the “mc” linkage dynamically from actionscript alone? eg without exporting a movie linkage from the library.

    I’ve attached my code for clarity:

    loader.load(new URLRequest(“http://www.deadinsect.co.uk/images/blackspot.gif”));
    mc.addChild(loader);
    mc.name = “firstpic”;
    movAss= new movieAssetMaterial(“firstpic”);
    plane1= new plane(movAss, 200,200,0,0,0);

  3. flashmech says:

    Hi Adrian, as the docs mentioned:

    “The MovieAssetMaterial class creates a texture from a MovieClip library symbol.”

    So basically what you should be using is using the BitmapFileMaterial class. I’ll write up a tutorial on this soon. πŸ˜‰

    Updated: Here is the tutorial on BitmapFileMaterial. :)

  4. Random T. says:

    If you want to hear a reader’s feedback :) , I rate this article for 4/5. Detailed info, but I just have to go to that damn yahoo to find the missed parts. Thanks, anyway!