[Bf-extensions-cvs] [c3a6d91] master: Update sapling tree gen: T46559 major rewrite
meta-androcto
noreply at git.blender.org
Thu Apr 28 04:36:32 CEST 2016
Commit: c3a6d9132a44afd254fa120157c66e72b751e6f1
Author: meta-androcto
Date: Thu Apr 28 12:36:09 2016 +1000
Branches: master
https://developer.blender.org/rBAc3a6d9132a44afd254fa120157c66e72b751e6f1
Update sapling tree gen: T46559 major rewrite
===================================================================
M add_curve_sapling/__init__.py
A add_curve_sapling/presets/Callistemon.py
A add_curve_sapling/presets/Douglas Fir.py
A add_curve_sapling/presets/Japanese Maple.py
A add_curve_sapling/presets/Small Maple.py
A add_curve_sapling/presets/Small Pine.py
A add_curve_sapling/presets/Weeping Willow.py
A add_curve_sapling/presets/White Birch.py
D add_curve_sapling/presets/black_tupelo.py
D add_curve_sapling/presets/ca_black_oak.py
M add_curve_sapling/presets/quaking_aspen.py
M add_curve_sapling/utils.py
===================================================================
diff --git a/add_curve_sapling/__init__.py b/add_curve_sapling/__init__.py
index fa1b326..4360fd3 100644
--- a/add_curve_sapling/__init__.py
+++ b/add_curve_sapling/__init__.py
@@ -17,20 +17,15 @@
#======================= END GPL LICENSE BLOCK ========================
bl_info = {
- "name": "Sapling",
- "author": "Andrew Hale (TrumanBlending)",
- "version": (0, 2, 6),
- "blender": (2, 73, 0),
+ "name": "Sapling Tree Gen",
+ "author": "Andrew Hale (TrumanBlending), Aaron Buchler",
+ "version": (0, 3, 2),
+ "blender": (2, 77, 0),
"location": "View3D > Add > Curve",
"description": ("Adds a parametric tree. The method is presented by "
"Jason Weber & Joseph Penn in their paper 'Creation and Rendering of "
"Realistic Trees'."),
- "warning": "",
- "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
- "Scripts/Curve/Sapling_Tree",
- "category": "Add Curve",
-}
-
+ "category": "Add Curve"}
if "bpy" in locals():
import importlib
@@ -41,8 +36,10 @@ else:
import bpy
import time
import os
+import ast
+
+#import cProfile
-#from utils import *
from mathutils import *
from math import pi, sin, degrees, radians, atan2, copysign
from random import random, uniform, seed, choice, getstate, setstate
@@ -50,7 +47,6 @@ from bpy.props import *
from add_curve_sapling.utils import *
-#global splitError
useSet = False
shapeList = [('0', 'Conical (0)', 'Shape = 0'),
@@ -62,28 +58,74 @@ shapeList = [('0', 'Conical (0)', 'Shape = 0'),
('6', 'Inverse Conical (6)', 'Shape = 6'),
('7', 'Tend Flame (7)', 'Shape = 7')]
+shapeList3 = [('0', 'Conical', ''),
+ ('6', 'Inverse Conical', ''),
+ ('1', 'Spherical', ''),
+ ('2', 'Hemispherical', ''),
+ ('3', 'Cylindrical', ''),
+ ('4', 'Tapered Cylindrical', ''),
+ ('10', 'Inverse Tapered Cylindrical', ''),
+ ('5', 'Flame', ''),
+ ('7', 'Tend Flame', ''),
+ ('8', 'Custom Shape', '')]
+
+shapeList4 = [('0', 'Conical', ''),
+ ('6', 'Inverse Conical', ''),
+ ('1', 'Spherical', ''),
+ ('2', 'Hemispherical', ''),
+ ('3', 'Cylindrical', ''),
+ ('4', 'Tapered Cylindrical', ''),
+ ('10', 'Inverse Tapered Cylindrical', ''),
+ ('5', 'Flame', ''),
+ ('7', 'Tend Flame', '')]
+
handleList = [('0', 'Auto', 'Auto'),
('1', 'Vector', 'Vector')]
settings = [('0', 'Geometry', 'Geometry'),
- ('1', 'Branch Splitting', 'Branch Splitting'),
- ('2', 'Branch Growth', 'Branch Growth'),
- ('3', 'Pruning', 'Pruning'),
- ('4', 'Leaves', 'Leaves'),
- ('5', 'Armature', 'Armature')]
-
+ ('1', 'Branch Radius', 'Branch Radius'),
+ ('2', 'Branch Splitting', 'Branch Splitting'),
+ ('3', 'Branch Growth', 'Branch Growth'),
+ ('4', 'Pruning', 'Pruning'),
+ ('5', 'Leaves', 'Leaves'),
+ ('6', 'Armature', 'Armature'),
+ ('7', 'Animation', 'Animation')]
+
+branchmodes = [("original", "Original", "rotate around each branch"),
+ ("rotate", "Rotate", "evenly distribute branches to point outward from center of tree"),
+ ("random", "Random", "choose random point")]
def getPresetpath():
"""Support user defined scripts directory
Find the first ocurrence of add_curve_sapling/presets in possible script paths
and return it as preset path"""
- presetpath = ""
- for p in bpy.utils.script_paths():
- presetpath = os.path.join(p, 'addons', 'add_curve_sapling', 'presets')
- if os.path.exists(presetpath):
- break
- return presetpath
-
+ #presetpath = ""
+ #for p in bpy.utils.script_paths():
+ # presetpath = os.path.join(p, 'addons', 'add_curve_sapling_3', 'presets')
+ # if os.path.exists(presetpath):
+ # break
+ #return presetpath
+
+ # why not just do this
+ script_file = os.path.realpath(__file__)
+ directory = os.path.dirname(script_file)
+ directory = os.path.join(directory, "presets")
+ return directory
+
+def getPresetpaths():
+ """Return paths for both local and user preset folders"""
+ userDir = os.path.join(bpy.utils.script_path_user(), 'presets', 'operator', 'add_curve_sapling')
+
+ if os.path.isdir(userDir):
+ pass
+ else:
+ os.makedirs(userDir)
+
+ script_file = os.path.realpath(__file__)
+ directory = os.path.dirname(script_file)
+ localDir = os.path.join(directory, "presets")
+
+ return (localDir, userDir)
class ExportData(bpy.types.Operator):
"""This operator handles writing presets to file"""
@@ -94,24 +136,46 @@ class ExportData(bpy.types.Operator):
def execute(self, context):
# Unpack some data from the input
- data, filename = eval(self.data)
- try:
- # Check whether the file exists by trying to open it.
- f = open(os.path.join(getPresetpath(), filename + '.py'), 'r')
- f.close()
- # If it exists then report an error
- self.report({'ERROR_INVALID_INPUT'}, 'Preset Already Exists')
+ data, filename, overwrite = eval(self.data)
+
+# try:
+# # Check whether the file exists by trying to open it.
+# f = open(os.path.join(getPresetpaths()[1], filename + '.py'), 'r')
+# f.close()
+# # If it exists then report an error
+# self.report({'ERROR_INVALID_INPUT'}, 'Preset Already Exists')
+# return {'CANCELLED'}
+# except IOError:
+# if data:
+# # If it doesn't exist, create the file with the required data
+# f = open(os.path.join(getPresetpaths()[1], filename + '.py'), 'w')
+# f.write(data)
+# f.close()
+# return {'FINISHED'}
+# else:
+# return {'CANCELLED'}
+
+ fpath1 = os.path.join(getPresetpaths()[0], filename + '.py')
+ fpath2 = os.path.join(getPresetpaths()[1], filename + '.py')
+
+ if os.path.exists(fpath1):
+ # If it exists in built-in presets then report an error
+ self.report({'ERROR_INVALID_INPUT'}, 'Can\'t have same name as built-in preset')
return {'CANCELLED'}
- except IOError:
+ elif (not os.path.exists(fpath2)) or (os.path.exists(fpath2) and overwrite):
+ #if (it does not exist) or (exists and overwrite) then write file
if data:
# If it doesn't exist, create the file with the required data
- f = open(os.path.join(getPresetpath(), filename + '.py'), 'w')
+ f = open(os.path.join(getPresetpaths()[1], filename + '.py'), 'w')
f.write(data)
f.close()
return {'FINISHED'}
else:
return {'CANCELLED'}
-
+ else:
+ # If it exists then report an error
+ self.report({'ERROR_INVALID_INPUT'}, 'Preset Already Exists')
+ return {'CANCELLED'}
class ImportData(bpy.types.Operator):
"""This operator handles importing existing presets"""
@@ -124,40 +188,78 @@ class ImportData(bpy.types.Operator):
# Make sure the operator knows about the global variables
global settings, useSet
# Read the preset data into the global settings
- f = open(os.path.join(getPresetpath(), self.filename), 'r')
+ try:
+ f = open(os.path.join(getPresetpaths()[0], self.filename), 'r')
+ except (FileNotFoundError, IOError):
+ f = open(os.path.join(getPresetpaths()[1], self.filename), 'r')
settings = f.readline()
f.close()
#print(settings)
- settings = eval(settings)
+ settings = ast.literal_eval(settings)
+
+ #use old attractup
+ if type(settings['attractUp']) == float:
+ atr = settings['attractUp']
+ settings['attractUp'] = [0, 0, atr, atr]
+
+ #use old leaf rotations
+ if 'leafDownAngle' not in settings:
+ l = settings['levels']
+ settings['leafDownAngle'] = settings['downAngle'][min(l, 3)]
+ settings['leafDownAngleV'] = settings['downAngleV'][min(l, 3)]
+ settings['leafRotate'] = settings['rotate'][min(l, 3)]
+ settings['leafRotateV'] = settings['rotateV'][min(l, 3)]
+
+ #zero leaf bend
+ settings['bend'] = 0
+
# Set the flag to use the settings
useSet = True
return {'FINISHED'}
-
class PresetMenu(bpy.types.Menu):
- """Create the preset menu by finding all preset files """ \
- """in the preset directory"""
+ """Create the preset menu by finding all preset files
+ in the preset directory"""
bl_idname = "sapling.presetmenu"
bl_label = "Presets"
def draw(self, context):
# Get all the sapling presets
- presets = [a for a in os.listdir(getPresetpath()) if a[-3:] == '.py']
+ presets = [a for a in os.listdir(getPresetpaths()[0]) if a[-3:] == '.py']
+ presets.extend([a for a in os.listdir(getPresetpaths()[1]) if a[-3:] == '.py'])
layout = self.layout
# Append all to the menu
for p in presets:
layout.operator("sapling.importdata", text=p[:-3]).filename = p
-
class AddTree(bpy.types.Operator):
bl_idname = "curve.tree_add"
bl_label = "Sapling: Add Tree"
bl_options = {'REGISTER', 'UNDO'}
+ def objectList(self, context):
+ objects = []
+ bObjects = bpy.data.objects
+# try:
+# bObjects = bpy.data.objects
+# except AttributeError:
+# pass
+# else:
+ for obj in bObjects:
+ if (obj.type in ['MESH', 'CURVE', 'SURFACE']) and (obj.name not in ['tree', 'leaves']):
+ objects.append((obj.name, obj.name, ""))
+
+ return objects
def update_tree(self, context):
self.do_update = True
+ def update_leaves(self, context):
+ if self.showLeaves:
+ self.do_upda
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list