Create lightweight 3D models with Away3D

This is taking less than 2MB!

 

Alot of the flash 3D project on the internet are massive. They first have to download 40mb before they start. There are 2 ways to reduce this.

  1. Use PreFab 2.0 export (not yet released) to export every model to awd files.
  2. Make simple models with Actionscript

I made a example project to show how to make your own milk pack

 

Away3D contains different classes to help you create your own models with actionscript. Witch one to use depends on what you want to draw. For now I made an example using SkinExtrude. With SkinExtrude you draw every geometry on Vertex (points in 3D) level.

Step 1. Create the square shape

 

var mesh:Mesh = new Mesh(); //every little part will be merged to this
var merge:Merge = new Merge(true, true); // merge every part == performance boost
var packProfile1:Vector. = new Vector.(); // bottom box profile
var packProfile2:Vector. = new Vector.(); // top box profile
var packSkinExtrudeProfile:Vector.> = new Vector.>() // every profile for the SkinExtrude is added to this

//Create the bottom box profile
//_width = 210
packProfile1.push(new Vector3D(-_width, 0, -_width));
packProfile1.push(new Vector3D(_width,0,-_width));
packProfile1.push(new Vector3D(_width,0,_width));
packProfile1.push(new Vector3D(-_width,0,_width));
packProfile1.push(new Vector3D(-_width, 0, -_width));

//create box top profile
//_width = 210; _height = 1100;
packProfile2.push(new Vector3D(-_width, _height * .8, -_width));
packProfile2.push(new Vector3D(_width,_height * .8,-_width));
packProfile2.push(new Vector3D(_width,_height * .8,_width));
packProfile2.push(new Vector3D(-_width,_height * .8,_width));
packProfile2.push(new Vector3D(-_width, _height * .8, -_width));

packSkinExtrudeProfile.push(packProfile1);
packSkinExtrudeProfile.push(packProfile2);

//Execute SkinExtrude
//_textureMaterial = texturematerial
//_textureMaterial can replaced by new ColorMaterial(0xff0000, 1) to get a red milk pack
var packSkinExtrude:SkinExtrude = new SkinExtrude(_textureMaterial, packSkinExtrudeProfile, 1, false, true, true, true);
//merge to mesh
merge.apply(mesh, packSkinExtrude);
The result

 

This is the result of the code if you add Mesh to the view.

Step 2. Close bottom

You see there is no bottom this is no problem if you have to milk pack standing on a table or so but now it looks weird. Lets add the bottom.

var packProfile:Vector. = new Vector.();
packProfile.push(new Vector3D(_width, 0, 0));
packProfile.push(new Vector3D(_width,0,0));
packProfile.push(new Vector3D(_width,0,0));
packProfile.push(new Vector3D(_width,0,0));
packProfile.push(new Vector3D(_width, 0, 0));

packSkinExtrudeProfile = new Vector.>()
packSkinExtrudeProfile.push(packProfile);
//packProfile1 is already set so we push/use it again
packSkinExtrudeProfile.push(packProfile1);

packSkinExtrude= new SkinExtrude(new ColorMaterial(0xEFEFEF), packSkinExtrudeProfile, 1, false, true, true, true);
merge.apply(mesh, packSkinExtrude);

 

Second code result

 

Now you have the bottom part of the milk pack.

Step 3. Create the top of the milk pack

Now we have to create the triangle shape top of the pack

 

// create the top point profile
// _width = 210; _height = 1100;
var packCloseProfile:Vector. = new Vector.();
packCloseProfile.push(new Vector3D(0, _height, -_width));
packCloseProfile.push(new Vector3D(0,_height,-_width));
packCloseProfile.push(new Vector3D(0,_height,_width));
packCloseProfile.push(new Vector3D(0,_height,_width));
packCloseProfile.push(new Vector3D(0, _height, -_width));

//Create a new topSkinExtrudeProfile you could also use the packSkinExtrudeProfile again
var topSkinExtrudeProfile:Vector.> = new Vector.>()
topSkinExtrudeProfile.push(packProfile2);
topSkinExtrudeProfile.push(packCloseProfile);
//New SkinExtrude. Here you can also use packSkinExtrude again.
var topSkinExtrude:SkinExtrude = new SkinExtrude(new ColorMaterial(0x023AC5), topSkinExtrudeProfile, 1, false, false, false, true);
//and merge to mesh again
merge.apply(mesh, topSkinExtrude);

 

Now the only thing we need is the top of the pack

var flapTopSkinExtrudeProfile:Vector.> = new Vector.>()
flapTopSkinExtrudeProfile.push(packCloseProfile);

//_width= 210; _height=1100;
var flapCloseProfile:Vector. = new Vector.();
flapCloseProfile.push(new Vector3D(0, _height + 70, -_width));
flapCloseProfile.push(new Vector3D(0,_height + 70,-_width));
flapCloseProfile.push(new Vector3D(0,_height + 70,_width));
flapCloseProfile.push(new Vector3D(0,_height + 70,_width));
flapCloseProfile.push(new Vector3D(0, _height + 70, -_width));
flapTopSkinExtrudeProfile.push(flapCloseProfile);
var flatTopSkinExtrude:SkinExtrude = new SkinExtrude(new ColorMaterial(0xffffff), flapTopSkinExtrudeProfile, 1, false, false, false, true);
merge.apply(mesh, flatTopSkinExtrude);

_view.scene.addChild(mesh);

Now you have a full milk pack

Result

 


Posted

in

, , , ,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *