diff options
Diffstat (limited to 'collada_funcs.py')
-rw-r--r-- | collada_funcs.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/collada_funcs.py b/collada_funcs.py new file mode 100644 index 0000000..ba96c0f --- /dev/null +++ b/collada_funcs.py @@ -0,0 +1,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 |