]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/util.py
Use bpy.path.basename instead of a custom function
[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 make_unique(values):
16         seen = set()
17         result = []
18         for i in values:
19                 if i not in seen:
20                         result.append(i)
21                         seen.add(i)
22         return result
23
24 def get_linked_node_and_socket(node_tree, socket):
25         for l in node_tree.links:
26                 if socket==l.to_socket:
27                         return (l.from_node, l.from_socket)
28                 elif socket==l.from_socket:
29                         return (l.to_node, l.to_socket)
30         return (None, None)
31
32 def compute_bounding_sphere(points):
33         p1 = max(((p, p.length) for p in points), key=lambda x:x[1])[0]
34         p2 = max(((p, (p-p1).length) for p in points), key=lambda x:x[1])[0]
35         center = (p1+p2)/2
36         radius = (p1-p2).length/2
37         for p in points:
38                 d = p-center
39                 if d.length>radius:
40                         center += d*(1-radius/d.length)/2
41                         radius = (radius+d.length)/2
42
43         return center, radius