[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1884] contrib/py/scripts/addons: First commit add_curve_sapling, added to contrib folder.

Andrew Hale TrumanBlending at gmail.com
Sun May 1 06:41:10 CEST 2011


Revision: 1884
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1884
Author:   trumanblending
Date:     2011-05-01 04:41:10 +0000 (Sun, 01 May 2011)
Log Message:
-----------
First commit add_curve_sapling, added to contrib folder.

Added Paths:
-----------
    contrib/py/scripts/addons/add_curve_sapling/
    contrib/py/scripts/addons/add_curve_sapling/__init__.py
    contrib/py/scripts/addons/add_curve_sapling/presets/
    contrib/py/scripts/addons/add_curve_sapling/presets/black_tupelo.py
    contrib/py/scripts/addons/add_curve_sapling/presets/quaking_aspen.py
    contrib/py/scripts/addons/add_curve_sapling/utils.py

Added: contrib/py/scripts/addons/add_curve_sapling/__init__.py
===================================================================
--- contrib/py/scripts/addons/add_curve_sapling/__init__.py	                        (rev 0)
+++ contrib/py/scripts/addons/add_curve_sapling/__init__.py	2011-05-01 04:41:10 UTC (rev 1884)
@@ -0,0 +1,552 @@
+#====================== BEGIN GPL LICENSE BLOCK ======================
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+#======================= END GPL LICENSE BLOCK ========================
+
+bl_info = {
+    "name": "Sapling",
+    "author": "Andrew Hale (TrumanBlending)",
+    "version": (0,2),
+    "blender": (2, 5, 7),
+    "api": 36147,
+    "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": "", # used for warning icon and text in addons panel
+    "wiki_url": "",
+    "tracker_url": "",
+    "category": "Add Curve"}
+
+if "bpy" in locals():
+    import imp
+    imp.reload(utils2)
+else:
+    from add_curve_sapling import utils
+
+import bpy
+import time
+import os
+
+#from utils import *
+from mathutils import *
+from math import pi,sin,degrees,radians,atan2,copysign
+from random import random,uniform,seed,choice,getstate,setstate
+from bpy.props import *
+
+from add_curve_sapling.utils import *
+
+#global splitError
+useSet = False
+
+shapeList = [('0','Conical','Shape = 0'),
+            ('1','Spherical','Shape = 1'),
+            ('2','Hemispherical','Shape = 2'),
+            ('3','Cylindrical','Shape = 3'),
+            ('4','Tapered Cylindrical','Shape = 4'),
+            ('5','Flame','Shape = 5'),
+            ('6','Inverse Conical','Shape = 6'),
+            ('7','Tend Flame','Shape = 7')]
+
+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')]
+
+# This operator handles writing presets to file
+class ExportData(bpy.types.Operator):
+    bl_idname = 'sapling.export'
+    bl_label = 'Export Preset'
+    
+    data = StringProperty()
+    
+    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('2.57//scripts//addons//add_curve_sapling//presets//'+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 and write the required data
+                f = open('2.57//scripts//addons//add_curve_sapling//presets//'+filename + '.py','w')
+                f.write(data)
+                f.close()
+                return {'FINISHED'}
+            else:
+                return {'CANCELLED'}
+
+# This operator handles importing existing presets
+class ImportData(bpy.types.Operator):
+    bl_idname = 'sapling.import'
+    bl_label = 'Import Preset'
+
+    filename = StringProperty()
+    
+    def execute(self,context):
+        # Make sure the operator knows about the global variables
+        global settings,useSet
+        # Read the preset data into the global settings
+        f = open('2.57//scripts//addons//add_curve_sapling//presets//'+self.filename,'r')
+        settings = f.readline()
+        f.close()
+        settings=eval(settings)
+        # Set the flag to use the settings
+        useSet = True
+        return {'FINISHED'}
+
+# Create the preset menu by finding all preset files in the preset directory
+class PresetMenu(bpy.types.Menu):
+    bl_idname = "sapling.presetmenu"
+    bl_label = "Presets"
+    
+    def draw(self, context):
+        # Get all the sapling presets
+        presets = [a for a in os.listdir('2.57//scripts//addons//add_curve_sapling//presets') if a[-3:] == '.py']
+        layout = self.layout
+        # Append all to the menu
+        for p in presets:
+            layout.operator("sapling.import",text=p[:-3]).filename=p
+
+class AddTree(bpy.types.Operator):
+    bl_idname = "curve.tree_add"
+    bl_label = "Sapling"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    chooseSet = EnumProperty(name='Settings',
+        description='Choose the settings to modify',
+        items=settings,
+        default='0')
+    bevel = BoolProperty(name='Bevel',
+        description='Whether the curve is bevelled',
+        default=False)
+    prune = BoolProperty(name='Prune',
+        description='Whether the tree is pruned',
+        default=False)
+    showLeaves = BoolProperty(name='Show Leaves',
+        description='Whether the leaves are shown',
+        default=False)
+    useArm = BoolProperty(name='Use Armature',
+        description='Whether the armature is generated',
+        default=False)
+    seed = IntProperty(name='Random Seed',
+        description='The seed of the random number generator',
+        default=0)
+    handleType = IntProperty(name='Handle Type',
+        description='The type of curve handles',
+        min=0,
+        max=1,
+        default=0)
+    levels = IntProperty(name='Levels',
+        description='Number of recursive branches (Levels)',
+        min=1,
+        max=6,
+        default=3)
+    length = FloatVectorProperty(name='Length',
+        description='The relative lengths of each branch level (nLength)',
+        min=0.0,
+        default=[1,0.3,0.6,0.45],
+        size=4)
+    lengthV = FloatVectorProperty(name='Length Variation',
+        description='The relative length variations of each branch level (nLengthV)',
+        min=0.0,
+        default=[0,0,0,0],
+        size=4)
+    branches = IntVectorProperty(name='Branches',
+        description='The number of branches sprouted at each level (nBranches)',
+        min=0,
+        default=[50,30,10,10],
+        size=4)
+    curveRes = IntVectorProperty(name='Curve Resolution',
+        description='The number of segments on each branch (nCurveRes)',
+        min=1,
+        default=[3,5,3,1],
+        size=4)
+    curve = FloatVectorProperty(name='Curvature',
+        description='The angle of the end of the branch (nCurve)',
+        default=[0,-40,-40,0],
+        size=4)
+    curveV = FloatVectorProperty(name='Curvature Variation',
+        description='Variation of the curvature (nCurveV)',
+        default=[20,50,75,0],
+        size=4)
+    curveBack = FloatVectorProperty(name='Back Curvature',
+        description='Curvature for the second half of a branch (nCurveBack)',
+        default=[0,0,0,0],
+        size=4)
+    baseSplits = IntProperty(name='Base Splits',
+        description='Number of trunk splits at its base (nBaseSplits)',
+        min=0,
+        default=0)
+    segSplits = FloatVectorProperty(name='Segment Splits',
+        description='Number of splits per segment (nSegSplits)',
+        min=0,
+        default=[0,0,0,0],
+        size=4)
+    splitAngle = FloatVectorProperty(name='Split Angle',
+        description='Angle of branch splitting (nSplitAngle)',
+        default=[0,0,0,0],
+        size=4)
+    splitAngleV = FloatVectorProperty(name='Split Angle Variation',
+        description='Variation in the split angle (nSplitAngleV)',
+        default=[0,0,0,0],
+        size=4)
+    scale = FloatProperty(name='Scale',
+        description='The tree scale (Scale)',
+        min=0.0,
+        default = 13.0)
+    scaleV = FloatProperty(name='Scale Variation',
+        description='The variation in the tree scale (ScaleV)',
+        default=3.0)
+    attractUp = FloatProperty(name='Vertical Attraction',
+        description='Branch upward attraction',
+        default=0.0)
+    shape = EnumProperty(name='Shape',
+        description='The overall shape of the tree (Shape)',
+        items=shapeList,
+        default='7')
+    baseSize = FloatProperty(name='Base Size',
+        description='Fraction of tree height with no branches (BaseSize)',
+        min=0.0,
+        max=1.0,
+        default=0.4)
+    ratio = FloatProperty(name='Ratio',
+        description='Base radius size (Ratio)',
+        min=0.0,
+        default=0.015)
+    taper = FloatVectorProperty(name='Taper',
+        description='The fraction of tapering on each branch (nTaper)',
+        min=0.0,
+        max=1.0,
+        default=[1,1,1,1],
+        size=4)
+    ratioPower = FloatProperty(name='Branch Radius Ratio',
+        description='Power which defines the radius of a branch compared to the radius of the branch it grew from (RatioPower)',
+        min=0.0,
+        default=1.2)
+    downAngle = FloatVectorProperty(name='Down Angle',
+        description='The angle between a new branch and the one it grew from (nDownAngle)',
+        default=[90,60,45,45],
+        size=4)
+    downAngleV = FloatVectorProperty(name='Down Angle Variation',
+        description='Variation in the down angle (nDownAngleV)',
+        default=[0,-50,10,10],
+        size=4)
+    rotate = FloatVectorProperty(name='Rotate Angle',
+        description='The angle of a new branch around the one it grew from (nRotate)',
+        default=[140,140,140,77],
+        size=4)
+    rotateV = FloatVectorProperty(name='Rotate Angle Variation',
+        description='Variation in the rotate angle (nRotateV)',
+        default=[0,0,0,0],
+        size=4)
+    scale0 = FloatProperty(name='Radius Scale',
+        description='The scale of the trunk radius (0Scale)',

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list