]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/util.py
Redesign progress and error reporting in the Blender exporter
[libs/gl.git] / blender / io_mspgl / util.py
1 import os
2
3 def linear_to_srgb(l):
4         if l<0.0031308:
5                 return 12.92*l
6         else:
7                 return 1.055*(l**(1/2.4))-0.055
8
9 def get_colormap(srgb):
10         if srgb:
11                 return linear_to_srgb
12         else:
13                 return lambda x: x
14
15 def basename(path):
16         if path.startswith("//"):
17                 path = path[2:]
18         return os.path.basename(path)
19
20 def make_unique(values):
21         seen = set()
22         result = []
23         for i in values:
24                 if i not in seen:
25                         result.append(i)
26                         seen.add(i)
27         return result
28
29 def get_linked_node_and_socket(node_tree, socket):
30         for l in node_tree.links:
31                 if socket==l.to_socket:
32                         return (l.from_node, l.from_socket)
33                 elif socket==l.from_socket:
34                         return (l.to_node, l.to_socket)
35         return (None, None)
36
37 def compute_bounding_sphere(points):
38         p1 = max(((p, p.length) for p in points), key=lambda x:x[1])[0]
39         p2 = max(((p, (p-p1).length) for p in points), key=lambda x:x[1])[0]
40         center = (p1+p2)/2
41         radius = (p1-p2).length/2
42         for p in points:
43                 d = p-center
44                 if d.length>radius:
45                         center += d*(1-radius/d.length)/2
46                         radius = (radius+d.length)/2
47
48         return center, radius