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
|
from lxml import etree
from mathutils import Matrix
# function to check if a collada file is valid
# for now if it wil well formatted
# it will also remove namespaces
def check_collada(xml_path):
# check for errors
try:
xml = etree.parse(xml_path)
except:
return None
# function to remove namespaces
def strip_namespace(element):
if element.tag.startswith("{"):
element.tag = element.tag.split("}")[1]
for child in element:
strip_namespace(child)
return element
# return the clean xml element
strip_namespace(xml.getroot())
return xml
# function to return the matrix contained in a matrix element
def get_text_mat4x4(text, offset):
# remove the starting whitespace characters
while (text[0] in " \n\t\r"):
text = text[1:]
text = text.split()
a = []
for num in text:
a.append(float(num))
for i in range(0, offset):
a.pop(0)
mat = Matrix(([a[0], a[1], a[2], a[3]],
[a[4], a[5], a[6], a[7]],
[a[8], a[9], a[10], a[11]],
[a[12], a[13], a[14], a[15]]))
return mat
|