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