]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/util.py
Refactor some parts of the Blender exporter to improve reusability
[libs/gl.git] / blender / io_mspgl / util.py
index ca13875befe31aeae05433d84ebc04ae073b5342..4141e9f77600891eb7ef405ecf2cc6bb3d642944 100644 (file)
@@ -68,3 +68,33 @@ def basename(path):
        if path.startswith("//"):
                path = path[2:]
        return os.path.basename(path)
+
+def make_unique(values):
+       seen = set()
+       result = []
+       for i in values:
+               if i not in seen:
+                       result.append(i)
+                       seen.add(i)
+       return result
+
+def get_linked_node_and_socket(node_tree, socket):
+       for l in node_tree.links:
+               if socket==l.to_socket:
+                       return (l.from_node, l.from_socket)
+               elif socket==l.from_socket:
+                       return (l.to_node, l.to_socket)
+       return (None, None)
+
+def compute_bounding_sphere(points):
+       p1 = max(((p, p.length) for p in points), key=lambda x:x[1])[0]
+       p2 = max(((p, (p-p1).length) for p in points), key=lambda x:x[1])[0]
+       center = (p1+p2)/2
+       radius = (p1-p2).length/2
+       for p in points:
+               d = p-center
+               if d.length>radius:
+                       center += d*(1-radius/d.length)/2
+                       radius = (radius+d.length)/2
+
+       return center, radius