[Bf-extensions-cvs] [34a27a42] master: Fix T54414: Address changes to object.ray_cast, cleanup
lijenstina
noreply at git.blender.org
Tue Apr 3 18:39:01 CEST 2018
Commit: 34a27a42d781d80f9f1833bad8cc5b2abcac2933
Author: lijenstina
Date: Tue Apr 3 18:37:42 2018 +0200
Branches: master
https://developer.blender.org/rBAC34a27a42d781d80f9f1833bad8cc5b2abcac2933
Fix T54414: Address changes to object.ray_cast, cleanup
Bump version to 0.1.3
Pep8 cleanup
Some style tweaks
Consistent property definitions
Remove unused varibles
Change the object.ray_cast call to the one introduced in 2.77
Bump requirements to 2.77 minimum
===================================================================
M add_mesh_space_tree/__init__.py
M add_mesh_space_tree/kdtree.py
M add_mesh_space_tree/sca.py
M add_mesh_space_tree/simplefork.py
===================================================================
diff --git a/add_mesh_space_tree/__init__.py b/add_mesh_space_tree/__init__.py
index 53ac55ac..5b4d3ee2 100644
--- a/add_mesh_space_tree/__init__.py
+++ b/add_mesh_space_tree/__init__.py
@@ -1,6 +1,6 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
-# SCA Tree Generator, a Blender addon
+# SCA Tree Generator, a Blender add-on
# (c) 2013 Michel J. Anders (varkenvarken)
#
# This program is free software; you can redistribute it and/or
@@ -24,26 +24,45 @@
bl_info = {
"name": "SCA Tree Generator",
"author": "michel anders (varkenvarken)",
- "version": (0, 1, 2),
- "blender": (2, 66, 0),
+ "version": (0, 1, 3),
+ "blender": (2, 77, 0),
"location": "View3D > Add > Mesh",
- "description": "Adds a tree created with the space colonization algorithm starting at the 3D cursor",
+ "description": "Create a tree using the space colonization algorithm starting at the 3D cursor",
"warning": "",
- "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Add_Mesh/Add_Space_Tree",
+ "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
+ "Scripts/Add_Mesh/Add_Space_Tree",
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
- "category": "Add Mesh"}
-
-from time import time
-from random import random, gauss
-from functools import partial
-from math import sin, cos
+ "category": "Add Mesh"
+}
import bpy
-from bpy.props import FloatProperty, IntProperty, BoolProperty, EnumProperty
-from mathutils import Vector, Euler, Matrix, Quaternion
-
-from .simplefork import simplefork, simplefork2, quadfork, bridgequads # simple skinning algorithm building blocks
-from .sca import SCA, Branchpoint # the core class that implements the space colonization algorithm and the definition of a segment
+from random import (
+ gauss, random,
+)
+from functools import partial
+from math import (
+ cos, sin,
+)
+from bpy.props import (
+ BoolProperty,
+ EnumProperty,
+ FloatProperty,
+ IntProperty,
+)
+from mathutils import (
+ Euler,
+ Vector,
+ Quaternion,
+)
+# simple skinning algorithm building blocks
+from .simplefork import (
+ quadfork, bridgequads,
+)
+# the core class that implements the space colonization
+# algorithm and the definition of a segment
+from .sca import (
+ SCA, Branchpoint,
+)
from .timer import Timer
@@ -76,13 +95,15 @@ def ellipsoid(r=5, rz=5, p=Vector((0, 0, 8)), taper=0):
def pointInsideMesh(pointrelativetocursor, ob):
- # adapted from http://blenderartists.org/forum/showthread.php?195605-Detecting-if-a-point-is-inside-a-mesh-2-5-API&p=1691633&viewfull=1#post1691633
+ # adapted from http://blenderartists.org/forum/showthread.php?"
+ # "195605-Detecting-if-a-point-is-inside-a-mesh-2-5-API&p=1691633&viewfull=1#post1691633
mat = ob.matrix_world.inverted()
orig = mat * (pointrelativetocursor + bpy.context.scene.cursor_location)
count = 0
axis = Vector((0, 0, 1))
while True:
- location, normal, index = ob.ray_cast(orig, orig + axis * 10000.0)
+ # Note: address changes introduced to object.ray_cast return (see T54414)
+ result, location, normal, index = ob.ray_cast(orig, orig + axis * 10000.0)
if index == -1:
break
count += 1
@@ -102,7 +123,7 @@ def ellipsoid2(rxy=5, rz=5, p=Vector((0, 0, 8)), surfacebias=1, topbias=1):
st = sin(theta)
st = (((st + 1) / 2) ** topbias) * 2 - 1
z = r * rz * st
- #print(">>>%.2f %.2f %.2f "%(x,y,z))
+ # print(">>>%.2f %.2f %.2f "%(x,y,z))
m = p + Vector((x, y, z))
reject = False
for ob in bpy.context.selected_objects:
@@ -144,7 +165,8 @@ def insidegroup(pointrelativetocursor, group):
return False
-def groupdistribution(crowngroup, shadowgroup=None, seed=0, size=Vector((1, 1, 1)), pointrelativetocursor=Vector((0, 0, 0))):
+def groupdistribution(crowngroup, shadowgroup=None, seed=0, size=Vector((1, 1, 1)),
+ pointrelativetocursor=Vector((0, 0, 0))):
if crowngroup == shadowgroup:
shadowgroup = None # safeguard otherwise every marker would be rejected
nocrowngroup = bpy.data.groups.find(crowngroup) < 0
@@ -190,14 +212,15 @@ def groupExtends(group):
return mx - mn, mn
-def createLeaves(tree, probability=0.5, size=0.5, randomsize=0.1, randomrot=0.1, maxconnections=2, bunchiness=1.0, connectoffset=-0.1):
+def createLeaves(tree, probability=0.5, size=0.5, randomsize=0.1,
+ randomrot=0.1, maxconnections=2, bunchiness=1.0, connectoffset=-0.1):
p = bpy.context.scene.cursor_location
verts = []
faces = []
c1 = Vector((connectoffset, -size / 2, 0))
- c2 = Vector((size+connectoffset, -size / 2, 0))
- c3 = Vector((size+connectoffset, size / 2, 0))
+ c2 = Vector((size + connectoffset, -size / 2, 0))
+ c3 = Vector((size + connectoffset, size / 2, 0))
c4 = Vector((connectoffset, size / 2, 0))
t = gauss(1.0 / probability, 0.1)
bpswithleaves = 0
@@ -229,7 +252,9 @@ def createLeaves(tree, probability=0.5, size=0.5, randomsize=0.1, randomrot=0.1,
verts.append(v * scale + bp.v + dvp)
n = len(verts)
faces.append((n - 1, n - 4, n - 3, n - 2))
- t += gauss(1.0 / probability, 0.1) # this is not the best choice of distribution because we might get negative values especially if sigma is large
+ # this is not the best choice of distribution because we might
+ # get negative values especially if sigma is large
+ t += gauss(1.0 / probability, 0.1)
dvp = nleavesonbp * (dv / (probability ** bunchiness)) # TODO add some randomness to the offset
mesh = bpy.data.meshes.new('Leaves')
@@ -240,8 +265,8 @@ def createLeaves(tree, probability=0.5, size=0.5, randomsize=0.1, randomrot=0.1,
def createMarkers(tree, scale=0.05):
- #not used as markers are parented to tree object that is created at the cursor position
- #p=bpy.context.scene.cursor_location
+ # not used as markers are parented to tree object that is created at the cursor position
+ # p=bpy.context.scene.cursor_location
verts = []
faces = []
@@ -261,7 +286,8 @@ def createMarkers(tree, scale=0.05):
return mesh
-def createObjects(tree, parent=None, objectname=None, probability=0.5, size=0.5, randomsize=0.1, randomrot=0.1, maxconnections=2, bunchiness=1.0):
+def createObjects(tree, parent=None, objectname=None, probability=0.5, size=0.5,
+ randomsize=0.1, randomrot=0.1, maxconnections=2, bunchiness=1.0):
if (parent is None) or (objectname is None) or (objectname == 'None'):
return
@@ -295,8 +321,9 @@ def createObjects(tree, parent=None, objectname=None, probability=0.5, size=0.5,
obj.scale = [scale, scale, scale]
obj.parent = parent
bpy.context.scene.objects.link(obj)
-
- t += gauss(1.0 / probability, 0.1) # this is not the best choice of distribution because we might get negative values especially if sigma is large
+ # this is not the best choice of distribution because we might
+ # get negative values especially if sigma is large
+ t += gauss(1.0 / probability, 0.1)
dvp = nleavesonbp * (dv / (probability ** bunchiness)) # TODO add some randomness to the offset
@@ -308,20 +335,20 @@ def vertextend(v, dv):
def vertcopy(loopa, v, p):
dv = [v[i] + p for i in loopa]
- #print(loopa,p,dv)
+ # print(loopa, p, dv)
return vertextend(v, dv)
def bend(p0, p1, p2, loopa, loopb, verts):
# will extend this with a tri centered at p0
- #print('bend')
+ # print('bend')
return bridgequads(loopa, loopb, verts)
def extend(p0, p1, p2, loopa, verts):
# will extend this with a tri centered at p0
- #print('extend')
- #print(p0,p1,p2,[verts[i] for i in loopa])
+ # print('extend')
+ # print(p0,p1,p2,[verts[i] for i in loopa])
# both difference point upward, we extend to the second
d1 = p1 - p0
@@ -329,22 +356,23 @@ def extend(p0, p1, p2, loopa, verts):
p = (verts[loopa[0]] + verts[loopa[1]] + verts[loopa[2]] + verts[loopa[3]]) / 4
a = d1.angle(d2, 0)
if abs(a) < 0.05:
- #print('small angle')
+ # print('small angle')
loopb = vertcopy(loopa, verts, p0 - d2 / 2 - p)
# all verts in loopb are displaced the same amount so no need to find the minimum distance
n = 4
- return ([(loopa[(i) % n], loopa[(i + 1) % n], loopb[(i + 1) % n], loopb[(i) % n]) for i in range(n)], loopa, loopb)
+ return ([(loopa[(i) % n], loopa[(i + 1) % n],
+ loopb[(i + 1) % n], loopb[(i) % n]) for i in range(n)], loopa, loopb)
r = d2.cross(d1)
q = Quaternion(r, -a)
dverts = [verts[i] - p for i in loopa]
- #print('large angle',dverts,'axis',r)
+ # print('large angle',dverts,'axis',r)
for dv in dverts:
dv.rotate(q)
- #print('rotated',dverts)
+ # print('rotated',dverts)
for dv in dverts:
dv += (p0 - d2 / 2)
- #print('moved',dverts)
+ # print('moved',dverts)
loopb = vertextend(verts, dverts)
# none of the verts in loopb are rotated so no need to find the minimum distance
n = 4
@@ -352,22 +380,22 @@ def extend(p0, p1, p2, loopa, verts):
def nonfork(bp, parent, apex, verts, p, branchpoints):
- #print('nonfork bp ',bp.index,bp.v,bp.loop if hasattr(bp,'loop') else None)
- #print('nonfork parent',parent.index,parent.v,parent.loop if hasattr(parent,'loop') else None)
- #print('nonfork apex ',apex.index,apex.v,apex.loop if hasattr(apex,'loop') else None)
+ # print('nonfork bp ',bp.index,bp.v,bp.loop if hasattr(bp,'loop') else None)
+ # print('nonfork parent',parent.index,parent.v,parent.loop if hasattr(parent,'loop') else None)
+ # print('nonfork apex ',apex.index,apex.v,apex.loop if hasattr(apex,'loop') else None)
if hasattr(bp, 'loop'):
if hasattr(apex, 'loop'):
- #print('nonfork bend
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list