[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25128] trunk/blender/release/scripts: String fix and a bunch of PEP8 issues I had collected in the meanwhile.
gsr b3d
gsr.b3d at infernal-iceberg.com
Fri Dec 4 18:54:49 CET 2009
Revision: 25128
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25128
Author: gsrb3d
Date: 2009-12-04 18:54:48 +0100 (Fri, 04 Dec 2009)
Log Message:
-----------
String fix and a bunch of PEP8 issues I had collected in the meanwhile.
Modified Paths:
--------------
trunk/blender/release/scripts/modules/retopo.py
trunk/blender/release/scripts/modules/rna_prop_ui.py
trunk/blender/release/scripts/op/console_python.py
trunk/blender/release/scripts/op/console_shell.py
trunk/blender/release/scripts/ui/properties_physics_cloth.py
trunk/blender/release/scripts/ui/space_console.py
trunk/blender/release/scripts/ui/space_image.py
trunk/blender/release/scripts/ui/space_info.py
trunk/blender/release/scripts/ui/space_node.py
trunk/blender/release/scripts/ui/space_outliner.py
trunk/blender/release/scripts/ui/space_sequencer.py
trunk/blender/release/scripts/ui/space_text.py
trunk/blender/release/scripts/ui/space_userpref.py
trunk/blender/release/scripts/ui/space_view3d.py
Modified: trunk/blender/release/scripts/modules/retopo.py
===================================================================
--- trunk/blender/release/scripts/modules/retopo.py 2009-12-04 16:35:31 UTC (rev 25127)
+++ trunk/blender/release/scripts/modules/retopo.py 2009-12-04 17:54:48 UTC (rev 25128)
@@ -22,19 +22,20 @@
EPS_SPLINE_DIV = 15.0 # remove doubles is ~15th the length of the spline
+
def get_hub(co, _hubs, EPS_SPLINE):
-
+
if 1:
for hub in _hubs.values():
if (hub.co - co).length < EPS_SPLINE:
return hub
-
+
key = co.toTuple(3)
hub = _hubs[key] = Hub(co, key, len(_hubs))
return hub
else:
pass
-
+
'''
key = co.toTuple(3)
try:
@@ -43,10 +44,11 @@
hub = _hubs[key] = Hub(co, key, len(_hubs))
return hub
'''
-
+
class Hub(object):
__slots__ = "co", "key", "index", "links"
+
def __init__(self, co, key, index):
self.co = co.copy()
self.key = key
@@ -55,10 +57,10 @@
def get_weight(self):
f = 0.0
-
+
for hub_other in self.links:
f += (self.co - hub_other.co).length
-
+
def replace(self, other):
for hub in self.links:
try:
@@ -67,8 +69,7 @@
pass
if other not in hub.links:
hub.links.append(other)
-
-
+
def dist(self, other):
return (self.co - other.co).length
@@ -80,9 +81,8 @@
if l_b is not self and l_b in self.links:
# will give duplicates
faces.append((self.index, l_a.index, l_b.index))
-
- # now quads, check which links share 2 different verts
- # directly
+
+ # now quads, check which links share 2 different verts directly
def validate_quad(face):
if len(set(face)) != len(face):
return False
@@ -90,41 +90,41 @@
return False
if hub_ls[face[2]] in hub_ls[face[0]].links:
return False
-
+
if hub_ls[face[1]] in hub_ls[face[3]].links:
return False
if hub_ls[face[3]] in hub_ls[face[1]].links:
return False
-
+
return True
for i, l_a in enumerate(self.links):
links_a = set([l.index for l in l_a.links])
for j in range(i):
l_b = self.links[j]
-
+
links_b = set([l.index for l in l_b.links])
-
+
isect = links_a.intersection(links_b)
if len(isect) == 2:
isect = list(isect)
-
+
# check there are no diagonal lines
face = (isect[0], l_a.index, isect[1], l_b.index)
if validate_quad(face):
-
+
faces.append(face)
-
+
return faces
-
class Spline:
__slots__ = "points", "hubs", "length"
+
def __init__(self, points):
self.points = points
self.hubs = []
-
+
# calc length
f = 0.0
co_prev = self.points[0]
@@ -136,46 +136,49 @@
def link(self):
if len(self.hubs) < 2:
return
-
+
edges = list(set([i for i, hub in self.hubs]))
edges.sort()
edges_order = {}
for i in edges:
edges_order[i] = []
-
-
+
+
# self.hubs.sort()
for i, hub in self.hubs:
edges_order[i].append(hub)
-
+
hubs_order = []
for i in edges:
ls = edges_order[i]
edge_start = self.points[i]
ls.sort(key=lambda hub: (hub.co - edge_start).length)
hubs_order.extend(ls)
-
+
# Now we have the order, connect the hubs
hub_prev = hubs_order[0]
-
+
for hub in hubs_order[1:]:
hub.links.append(hub_prev)
hub_prev.links.append(hub)
hub_prev = hub
+
def get_points(stroke):
return [point.co.copy() for point in stroke.points]
+
def get_splines(gp):
for l in gp.layers:
if l.active: # XXX - should be layers.active
break
-
+
frame = l.active_frame
-
+
return [Spline(get_points(stroke)) for stroke in frame.strokes]
+
def xsect_spline(sp_a, sp_b, _hubs):
from Mathutils import LineIntersect
from Mathutils import MidpointVecs
@@ -191,7 +194,7 @@
# print(pt_a, pt_a_prev, pt_b, pt_b_prev)
xsect = LineIntersect(pt_a, pt_a_prev, pt_b, pt_b_prev)
if xsect is not None:
- if (xsect[0]-xsect[1]).length <= EPS_SPLINE:
+ if (xsect[0] - xsect[1]).length <= EPS_SPLINE:
f = ClosestPointOnLine(xsect[1], pt_a, pt_a_prev)[1]
# if f >= 0.0-EPS_SPLINE and f <= 1.0+EPS_SPLINE: # for some reason doesnt work so well, same below
if f >= 0.0 and f <= 1.0:
@@ -206,90 +209,90 @@
sp_b.hubs.append((b, hub))
pt_b_prev = pt_b
-
+
pt_a_prev = pt_a
def calculate(gp):
splines = get_splines(gp)
_hubs = {}
-
+
for i, sp in enumerate(splines):
for j, sp_other in enumerate(splines):
- if j<=i:
+ if j <= i:
continue
xsect_spline(sp, sp_other, _hubs)
-
+
for sp in splines:
sp.link()
-
+
# remove these
hubs_ls = [hub for hub in _hubs.values() if hub.index != -1]
-
+
_hubs.clear()
_hubs = None
-
+
for i, hub in enumerate(hubs_ls):
hub.index = i
-
+
# Now we have connected hubs, write all edges!
def order(i1, i2):
if i1 > i2:
return i2, i1
return i1, i2
-
+
edges = {}
-
+
for hub in hubs_ls:
i1 = hub.index
- for hub_other in hub.links:
+ for hub_other in hub.links:
i2 = hub_other.index
edges[order(i1, i2)] = None
-
+
verts = []
edges = edges.keys()
faces = []
-
+
for hub in hubs_ls:
verts.append(hub.co)
faces.extend(hub.calc_faces(hubs_ls))
-
+
# remove double faces
faces = dict([(tuple(sorted(f)), f) for f in faces]).values()
-
+
mesh = bpy.data.add_mesh("Retopo")
mesh.from_pydata(verts, [], faces)
-
+
scene = bpy.context.scene
mesh.update()
obj_new = bpy.data.add_object('MESH', "Torus")
obj_new.data = mesh
scene.objects.link(obj_new)
-
+
return obj_new
-
-
+
+
def main():
scene = bpy.context.scene
obj = bpy.context.object
-
+
gp = None
-
+
if obj:
gp = obj.grease_pencil
-
+
if not gp:
gp = scene.grease_pencil
if not gp:
raise Exception("no active grease pencil")
-
+
obj_new = calculate(gp)
-
+
scene.objects.active = obj_new
obj_new.selected = True
-
+
# nasty, recalc normals
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
bpy.ops.mesh.normals_make_consistent(inside=False)
Modified: trunk/blender/release/scripts/modules/rna_prop_ui.py
===================================================================
--- trunk/blender/release/scripts/modules/rna_prop_ui.py 2009-12-04 16:35:31 UTC (rev 25127)
+++ trunk/blender/release/scripts/modules/rna_prop_ui.py 2009-12-04 17:54:48 UTC (rev 25128)
@@ -20,6 +20,7 @@
import bpy
+
def rna_idprop_ui_get(item, create=True):
try:
return item['_RNA_UI']
@@ -57,7 +58,7 @@
pass
-def draw(layout, context, context_member, use_edit = True):
+def draw(layout, context, context_member, use_edit=True):
def assign_props(prop, val, key):
prop.path = context_member
@@ -69,7 +70,7 @@
pass
rna_item = eval("context." + context_member)
-
+
# poll should really get this...
if not rna_item:
return
@@ -138,6 +139,7 @@
rna_min = FloatProperty(name="Min", default=0.0, precision=3)
rna_max = FloatProperty(name="Max", default=1.0, precision=3)
+
class WM_OT_properties_edit(bpy.types.Operator):
'''Internal use (edit a property path)'''
bl_idname = "wm.properties_edit"
@@ -206,15 +208,15 @@
prop_ui = rna_idprop_ui_prop_get(item, self.properties.property, False) # dont create
if prop_ui:
self.properties.min = prop_ui.get("min", -1000000000)
- self.properties.max = prop_ui.get("max", 1000000000)
- self.properties.description = prop_ui.get("description", "")
+ self.properties.max = prop_ui.get("max", 1000000000)
+ self.properties.description = prop_ui.get("description", "")
if 0:
- _message= "PyConsole, press Ctrl+D to unlock the BGE"
+ _message = "PyConsole, press Ctrl+D to unlock the BGE"
import sys
# evaluate commands in current namespace
- frame= sys._getframe()
+ frame = sys._getframe()
namespace = frame.f_globals.copy()
namespace.update(frame.f_locals)
@@ -252,7 +254,7 @@
i = 1
while prop_new in names:
prop_new = prop + str(i)
- i+=1
+ i += 1
return prop_new
@@ -261,6 +263,7 @@
item[property] = 1.0
return ('FINISHED',)
+
class WM_OT_properties_remove(bpy.types.Operator):
'''Internal use (edit a property path)'''
bl_idname = "wm.properties_remove"
@@ -273,4 +276,3 @@
item = eval("context.%s" % self.properties.path)
del item[self.properties.property]
return ('FINISHED',)
-
Modified: trunk/blender/release/scripts/op/console_python.py
===================================================================
--- trunk/blender/release/scripts/op/console_python.py 2009-12-04 16:35:31 UTC (rev 25127)
+++ trunk/blender/release/scripts/op/console_python.py 2009-12-04 17:54:48 UTC (rev 25128)
@@ -22,11 +22,13 @@
language_id = 'python'
+
def add_scrollback(text, text_type):
for l in text.split('\n'):
bpy.ops.console.scrollback_append(text=l.replace('\t', ' '),
type=text_type)
+
def get_console(console_id):
'''
helper function for console operators
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list