Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timknip/asblender
Actionscript 3 library for reading Blender .blend files
https://github.com/timknip/asblender
Last synced: 22 days ago
JSON representation
Actionscript 3 library for reading Blender .blend files
- Host: GitHub
- URL: https://github.com/timknip/asblender
- Owner: timknip
- Created: 2010-01-22T16:58:43.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2010-01-25T00:05:40.000Z (almost 15 years ago)
- Last Synced: 2024-08-03T05:02:50.289Z (3 months ago)
- Language: ActionScript
- Homepage: http://wiki.github.com/timknip/asblender/
- Size: 2.28 MB
- Stars: 38
- Watchers: 4
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
- awesome-actionscript-sorted - asblender - AS3 library for reading Blender .BLEND files (File Formats / 3D Formats)
README
ASBLENDER
=========================================ASBlender is an Actionscript 3 library to read Blender .blend files.
See http://www.blender.org/development/architecture/blender-file-format/ for an explanation of the .blend format.
The complete .blend is read into simple AS3 Object's which map to the structures defined in the so-called DNA.
Disadvantage of this approach is that you have to "know" how the structures look like.
=> check "printDNA" in USAGE belowUSAGE
=========================================[Embed (source="/assets/crystal_cube.blend", mimeType="application/octet-stream")]
public var BlenderData:Class;var blend:BlendFile = new BlendFile();
blend.read(new BlenderData());
if (blend.scenes.length) {
// Blender can have multiple scenes, don't know yet how to grab the "active" scene.
buildScene(blend.scenes[0]);
}/**
* Prints out the DNA as contained in the .blend
*/
private function printDNA(blend:BlendFile):void {
var struct:DNAStruct;
var field:DNAField;
for each (struct in blend.dna.structs) {
var type:String = blend.dna.types[ struct.type ];
trace(type);
for each (field in struct.fields) {
trace(field.type + " " + field.name);
}
}
}private function buildScene(scene:Object):void {
var obj:Object = scene.base.first;
while (obj) {
// grab the Blender Object.
// The Blender Object defines rotation, scale, translation etc.
var object:Object = obj.object;
trace("Object name: " + object.id.name + " type: " + object.type + " matrix: " + object.obmat);
//for (var key:String in object) {
// trace(key);
//}
if (object.data) {
switch (object.type) {
case 1: // Mesh
trace (" -> Mesh: " + object.data.id.name);
buildMesh(object.data);
break;
case 10: // Lamp
trace (" -> Lamp: " + object.data.id.name);
break;
case 11: // Camera
trace (" -> Camera: " + object.data.id.name);
break;
default:
break;
}
}
obj = obj.next;
}
}private function buildMesh(mesh:Object):void {
var numVertices:int = mesh.totvert;
var numFaces:int = mesh.totface;
var i:int;
trace(" -> #verts : " + numVertices);for (i = 0; i < numVertices; i++) {
var v:Object = mesh.mvert[i];
var x:Number = v.co[0];
var y:Number = v.co[1];
var z:Number = v.co[2];
trace(" -> -> vertex: " + x + " " + y + " " + z);
}
trace(" -> #faces : " + numFaces);
for (i = 0; i < numFaces; i++) {
var f:Object = mesh.mface[i];
var v1:int = f.v1;
var v2:int = f.v2;
var v3:int = f.v3;
var v4:int = f.v4;
trace(" -> -> indices: " + v1 + " " + v2 + " " + v3 + " " + v4);
if (mesh.mtface) {
// UV coords are defined
var tf:Object = mesh.mtface[i];
trace(" -> -> -> uv: " + tf.uv);
}
}
}