From 17fd2304270b2ef619cceb980b9f49cb656a6d13 Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 14 Aug 2024 22:48:16 -0400 Subject: updated Collada importer/exporter for SuperBMD --- collada_funcs.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 collada_funcs.py (limited to 'collada_funcs.py') 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 -- cgit v1.2.3-70-g09d2