-
Notifications
You must be signed in to change notification settings - Fork 5
/
import.py
61 lines (49 loc) · 1.65 KB
/
import.py
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
# Convenience functions
import struct
import mathutils
import bpy
# read unsigned byte from file
def read_byte(file_object, endian = '<'):
data = struct.unpack(endian+'B', file_object.read(1))[0]
return data
# read unsgned short from file
def read_short(file_object, endian = '<'):
data = struct.unpack(endian+'H', file_object.read(2))[0]
return data
# read unsigned integer from file
def read_uint(file_object, endian = '<'):
data = struct.unpack(endian+'I', file_object.read(4))[0]
return data
# read signed integer from file
def read_int(file_object, endian = '<'):
data = struct.unpack(endian+'i', file_object.read(4))[0]
return data
# read floating point number from file
def read_float(file_object, endian = '<'):
data = struct.unpack(endian+'f', file_object.read(4))[0]
return data
print('Importing bones...')
# Create Armature and Object
bpy.ops.object.add(type='ARMATURE', enter_editmode=True)
object = bpy.context.object
object.name = 'armature'
armature = object.data
armature.name = 'armature'
#Read our input file
file = open('filename.bones', 'rb') # 'rb' - open for reading in binary mode
boneCount = read_uint(file)
for b in range(0, boneCount):
matVals = []
for x in range(0, 4):
curMat = []
for y in range(0, 4):
val = read_float(file)
curMat.append(val)
matVals.append(curMat)
matrix = mathutils.Matrix(matVals).inverted()
bone = armature.edit_bones.new('bone' + str(b))
bone.tail = mathutils.Vector([1,0,0])
bone.transform(matrix)
# get out of edit mode when done
bpy.ops.object.mode_set(mode='OBJECT')
print('Done importing bones')