-
Notifications
You must be signed in to change notification settings - Fork 7
/
README
118 lines (87 loc) · 2.72 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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 below
USAGE
=========================================
[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);
}
}
}