¿Eres nuevo? ¡Lee el FAQ y ponte al día!
3k visitas

Papervision 3D: How to embed a 3D model (3DS, Collada, etc...)

In Flash, you can embed 3D objects using the Embed functionality. In this example a 3DS model is loaded, but you can use this technique to embed almost any 3D format. It looks like this:

ActionScript 3
  1. // Path is relative to the file you put the Embed into
  2. [Embed (source="path/to/model.3ds", mimeType="application/octet-stream")]
  3. private const Mesh:Class;
  4.  

­

This embeds the content of the 3ds file into a Class called Mesh. Then, you can use it this way:

ActionScript 3
  1. // Create a new instance of Mesh as an array of bytes
  2. var byteArray:ByteArray = new Mesh() as ByteArray;
  3. var object:Max3DS = new Max3DS();
  4. // The load method accepts the 3d object as a ByteArray and loads it successfully
  5. object.load(byteArray);
  6.  

­

You can also embed and load a texture:

ActionScript 3
  1. [Embed (source="path/to/texture.png")]
  2. private const Texture:Class;
  3.  

­

Flash "understands" the png format, so you don't need to set the mimeType. Then, you can load it and apply it to the 3d object this way:

ActionScript 3
  1. var materialList:MaterialsList = new MaterialsList();
  2. var bitmap:Bitmap = new Texture() as Bitmap;
  3. var bitmapMaterial:BitmapMaterial = new BitmapMaterial(bitmap.bitmapData, true);
  4. materialList.addMaterial(bitmapMaterial,"all");
  5.  
  6. var object:Max3DS = new Max3DS();
  7. var byteArray:ByteArray = new Mesh() as ByteArray;
  8. object.load(byteArray, materialList, ".");
  9.  

­

Etiquetas: ActionScript 3.0 flash papervision 3d embed

Insertar: