[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3822] contrib/py/scripts/addons/ mesh_fiber.py: port of ripsting's fiber addon to 2.64

Brendon Murphy meta.androcto1 at gmail.com
Sun Oct 7 02:32:10 CEST 2012


Revision: 3822
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3822
Author:   meta-androcto
Date:     2012-10-07 00:32:09 +0000 (Sun, 07 Oct 2012)
Log Message:
-----------
port of ripsting's fiber addon to 2.64

Added Paths:
-----------
    contrib/py/scripts/addons/mesh_fiber.py

Added: contrib/py/scripts/addons/mesh_fiber.py
===================================================================
--- contrib/py/scripts/addons/mesh_fiber.py	                        (rev 0)
+++ contrib/py/scripts/addons/mesh_fiber.py	2012-10-07 00:32:09 UTC (rev 3822)
@@ -0,0 +1,1340 @@
+
+#Fiber Generator V3 - June 5th, 2012
+#Created by Alan Dennis (RipSting)
+#dennisa at onid.orst.edu
+#Updated for 2.6 by Gert De Roost (paleajed)
+#_________________________________________________
+#Special thanks to Alfredo de Greef (Eeshlo) for
+#providing the DyNoise module and the multmat
+#and renormal subroutines!!!
+#Thanks goes out to Peter De Bock for
+#fixing the vertex color problems!!!
+#_________________________________________________
+
+
+
+#--------------I N F O R M A T I O N--------------
+#
+#Go to user preferences->addons and navigate to Mesh category
+#Enable Fiber addon.  Subpanel will appear in Tools panel.
+#
+#You must have at least one mesh object selected.
+#You may select multiple mesh objects for the script
+#to run on.
+
+bl_info = {
+	"name": "Fiber",
+	"author": "Alan Dennis - Gert De Roost",
+	"version": (3, 1, 0),
+	"blender": (2, 6, 3),
+	"location": "View3D > Mesh Tools",
+	"description": "Generates grass",
+	"warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/"\
+        "Extensions:2.6/Py/Scripts",
+    "tracker_url": "http://projects.blender.org/tracker/"\
+        "?func=detail&aid=32802"
+	"category": "Mesh"}
+
+
+
+if "bpy" in locals():
+	import imp
+
+import bpy
+import bmesh
+import os
+
+from math import pow
+import string
+from mathutils import *
+from mathutils.noise import random, hetero_terrain as HTerrain, seed_set as InitNoise
+
+
+
+seed = 1
+CurVersion = "3"
+txtFollowtext = "Follow Normals / Z-Axis"
+
+
+#Get the current .fib filename
+bpy.context.user_preferences.filepaths.use_relative_paths = 0
+a = bpy.data.filepath
+b = os.path.dirname(a)
+a = a.split(os.sep)[len(a.split(os.sep)) -1]
+fname = b + os.sep + str(a.split(".")[0]) + ".fib"
+fname = fname.replace("//", "")
+
+
+
+bpy.types.Scene.txtFile = bpy.props.StringProperty(
+		name="Set file",
+#		attr="custompath",# this a variable that will set or get from the scene
+		description="",
+		maxlen= 1024,
+		subtype='FILE_PATH',
+		default= fname)
+	
+bpy.types.Scene.txtFaces = bpy.props.StringProperty(
+		name="",
+		description="",
+		maxlen= 1024,
+		default= "")
+
+
+bpy.types.Scene.chkPointed = bpy.props.BoolProperty(
+		name = "Pointed", 
+		description = "Pointed?",
+		default = False)
+	
+bpy.types.Scene.chkVCol = bpy.props.BoolProperty(
+		name = "Use VCol", 
+		description = "Use VCol?",
+		default = False)
+	
+bpy.types.Scene.chkWind = bpy.props.BoolProperty(
+		name = "Use Wind", 
+		description = "Use Wind?",
+		default = False)
+	
+bpy.types.Scene.chkGuides = bpy.props.BoolProperty(
+		name = "Use Guides", 
+		description = "Use Guides?",
+		default = False)
+
+
+
+bpy.types.Scene.sldDensity = bpy.props.FloatProperty(
+		name = "Density", 
+		description = "Enter density",
+		default = 5,
+		min = 0,
+		max = 50)
+
+bpy.types.Scene.sldSegments = bpy.props.IntProperty(
+		name = "Segments", 
+		description = "Enter segments",
+		default = 3,
+		min = 1,
+		max = 20)
+
+bpy.types.Scene.sldLength = bpy.props.FloatProperty(
+		name = "Length of Segment", 
+		description = "Enter segment length",
+		default = 5,
+		min = 0,
+		max = 50)
+
+bpy.types.Scene.sldSegRand = bpy.props.FloatProperty(
+		name = "Randomize Length %", 
+		description = "Enter Randomize Length %",
+		default = 0,
+		min = 0,
+		max = 1.0)
+
+bpy.types.Scene.sldWidth = bpy.props.FloatProperty(
+		name = "Width", 
+		description = "Enter Width",
+		default = 3,
+		min = 0,
+		max = 20)
+
+bpy.types.Scene.sldGravity = bpy.props.FloatProperty(
+		name = "Gravity", 
+		description = "Enter Gravity",
+		default = 2,
+		min = 0,
+		max = 20)
+
+bpy.types.Scene.sldInit = bpy.props.FloatProperty(
+		name = "Initial Gravity", 
+		description = "Enter Initial Gravity",
+		default = 0,
+		min = 0,
+		max = 50)
+
+bpy.types.Scene.sldRand = bpy.props.FloatProperty(
+		name = "Randomize Direction", 
+		description = "Enter Randomize Direction",
+		default = 5,
+		min = 0,
+		max = 50)
+
+bpy.types.Scene.sldRloc = bpy.props.FloatProperty(
+		name = "Frizziness", 
+		description = "Enter Frizziness",
+		default = 0,
+		min = 0,
+		max = 50)
+
+bpy.types.Scene.sldFollow = bpy.props.FloatProperty(
+		name = "Normals / Clumpiness", 
+		description = "Enter Normals / Clumpiness",
+		default = 1,
+		min = 0,
+		max = 1)
+
+bpy.types.Scene.sldFalloff = bpy.props.FloatProperty(
+		name = "Clumpiness Falloff", 
+		description = "Enter Clumpiness Falloff",
+		default = 2,
+		min = 0,
+		max = 10)
+
+bpy.types.Scene.sldControl = bpy.props.IntProperty(
+		name = "Fiber Guides", 
+		description = "Enter Fiber Guides",
+		default = 10,
+		min = 3,
+		max = 100)
+
+bpy.types.Scene.sldCtrlSeg = bpy.props.IntProperty(
+		name = "Fiber Guide Segments", 
+		description = "Enter Fiber Guide Segments",
+		default = 4,
+		min = 3,
+		max = 4)
+
+
+class FiberPanel(bpy.types.Panel):
+	bl_label = "Fiber"
+	bl_space_type = "VIEW_3D"
+	bl_region_type = "TOOLS"
+	
+	def draw(self, context):
+
+		scn = bpy.context.scene
+		layout = self.layout
+		
+		layout.label("Fiber Generator-	Version " + str(CurVersion))
+	
+		row = layout.row()
+		row.operator("fiber.savepreset", text="Save Preset")
+		row.operator("fiber.loadpreset", text="Load Preset")
+#		row.operator("fiber.exit", text="Exit")
+		layout.prop(scn, "txtFile")
+		
+		layout.prop(scn, "sldDensity")
+		layout.prop(scn, "sldSegments")
+		layout.prop(scn, "sldLength")
+		layout.prop(scn, "sldSegRand")
+		layout.prop(scn, "sldWidth")
+		layout.prop(scn, "sldGravity")
+		layout.prop(scn, "sldInit")
+		layout.prop(scn, "sldRand")
+		layout.prop(scn, "sldRloc")
+		layout.prop(scn, "sldFollow")
+		layout.prop(scn, "sldFalloff")
+		layout.prop(scn, "sldControl")
+	
+		row = layout.split(0.8)
+		row.prop(scn, "sldCtrlSeg")
+		row.operator("fiber.make", text="Make")
+		
+		row = layout.row()
+		row.prop(scn, "chkPointed")
+		row.prop(scn, "chkVCol")
+		row.prop(scn, "chkWind")
+		row.prop(scn, "chkGuides")
+	
+		row = layout.row()
+		row.operator("fiber.estimate", text="Estimate Faces")
+		row.prop(scn, "txtFaces")
+		row.operator("fiber.create", text="Create")
+
+		updatepars()
+
+
+
+class SavePreset(bpy.types.Operator):
+	bl_idname = "fiber.savepreset"
+	bl_label = ""
+	bl_description = "Saves .fib preset"
+
+	def invoke(self, context, event):
+		
+		scn = bpy.context.scene
+		SavePreset(scn.txtFile)
+
+		return {'FINISHED'}
+
+class LoadPreset(bpy.types.Operator):
+	bl_idname = "fiber.loadpreset"
+	bl_label = ""
+	bl_description = "Loads .fib preset"
+
+	def invoke(self, context, event):
+		
+		scn = bpy.context.scene
+		LoadPreset(scn.txtFile)
+
+		return {'FINISHED'}
+
+class Exit(bpy.types.Operator):
+	bl_idname = "fiber.exit"
+	bl_label = ""
+	bl_description = "Exits Fiber"
+
+	def invoke(self, context, event):
+		
+		pass
+
+		return {'FINISHED'}
+
+class Make(bpy.types.Operator):
+	bl_idname = "fiber.make"
+	bl_label = ""
+	bl_description = "Make fiber guide segments"
+
+	def invoke(self, context, event):
+		
+		scn = bpy.context.scene
+		ControlPoints(scn.sldControl, scn.sldCtrlSeg)
+
+		return {'FINISHED'}
+
+class EstimateFaces(bpy.types.Operator):
+	bl_idname = "fiber.estimate"
+	bl_label = ""
+	bl_description = "Estimate # faces"
+
+	def invoke(self, context, event):
+		
+		global tempbm, firstrun
+		
+		scn = bpy.context.scene
+		faces = 0
+		objects = bpy.context.selected_objects
+		mat = adapt(objects[0])
+		tempbm = bmesh.new()
+		for num in range(len(objects)):
+			original = objects[num].data
+			bm = bmesh.new()
+			bm.from_mesh(original)
+			newbm = bmesh.new()
+			for fa in bm.faces:
+				faces += (int(fncArea(fa,mat) * scn.sldDensity))
+		scn.txtFaces = str(faces *2)
+		print (str(faces *2) + " faces predicted")
+
+		return {'FINISHED'}
+
+class Create(bpy.types.Operator):
+	bl_idname = "fiber.create"
+	bl_label = ""
+	bl_description = "Create faces"
+
+	def invoke(self, context, event):
+		
+		RunFiber()
+
+		return {'FINISHED'}
+
+
+
+def register():
+	bpy.utils.register_module(__name__)
+
+
+def unregister():
+	bpy.utils.unregister_module(__name__)
+
+
+if __name__ == "__main__":
+	register()
+
+
+
+
+
+#	elif evt == 72: #Use Wind
+#		if chkWind.val == 1:
+#			try:
+#				Wind = Object.Get("Wind")
+#				test = Wind.LocY
+#			except:
+#				Wind = Object.New(Object.Types.EMPTY)
+#				Wind.name = "Wind"
+#
+#				Wind.LocX = 0.0
+#				Wind.LocY = 0.0
+#				Wind.LocZ = 0.0
+#				Wind.RotX = 0.0
+#				Wind.RotY = 0.0
+#				Wind.RotZ = 0.0
+
+
+def SavePreset(FName):
+
+	FName = FName.replace("//", "")
+	try:
+		f = open(FName,'w')
+	except:
+		message = "unable to save file."
+		return
+	
+	writeln(f,CurVersion)
+	
+	scn = bpy.context.scene
+	writeln(f, scn.sldDensity)
+	writeln(f, scn.sldGravity)
+	writeln(f, scn.sldSegments)
+	writeln(f, scn.sldLength)
+	writeln(f, scn.sldWidth)
+	writeln(f, scn.sldInit)
+	writeln(f, scn.sldRand)
+	writeln(f, scn.sldRloc)
+	writeln(f, scn.sldFollow)
+	writeln(f, scn.sldControl)
+	writeln(f, scn.sldCtrlSeg)
+	writeln(f, scn.sldSegRand)
+	writeln(f, scn.sldFalloff)
+		
+	if scn.chkPointed:
+		writeln(f, "1")
+	else:
+		writeln(f, "0")
+	if scn.chkVCol:
+		writeln(f, "1")
+	else:
+		writeln(f, "0")
+	if scn.chkWind:
+		writeln(f, "1")
+	else:
+		writeln(f, "0")
+	if scn.chkGuides:
+		writeln(f, "1")
+	else:
+		writeln(f, "0")
+	writeln(f,int(random()*1000))
+	writeln(f,1) #First Run
+	objects = bpy.context.selected_objects
+	for z in range(len(objects)):
+		writeln(f,objects[z].name)
+	f.close()
+
+def LoadPreset(FName):
+
+	global FVersion, seed, firstrun, objects
+
+	FName = FName.replace("//", "")
+	try:
+		f = open(FName,'r')
+	except:
+		message = "unable to open preset."
+		return
+	
+	FVersion = readfloat(f)
+	
+	scn = bpy.context.scene
+	scn.sldDensity	= readfloat(f)	
+	scn.sldGravity	= readfloat(f)
+	scn.sldSegments = readint(f)
+	scn.sldLength	= readfloat(f)
+	scn.sldWidth	= readfloat(f)
+	scn.sldInit		= readfloat(f)
+	scn.sldRand		= readfloat(f)
+	scn.sldRloc		= readfloat(f)
+	scn.sldFollow	= readfloat(f)
+	scn.sldControl	= readfloat(f)
+	scn.sldCtrlSeg	= readfloat(f)
+	scn.sldSegRand	= readfloat(f)
+	scn.sldFalloff	= readfloat(f)
+		
+	scn.chkPointed	= readint(f)
+	scn.chkVCol		= readint(f)
+	scn.chkWind		= readint(f)
+	scn.chkGuides	= readint(f)
+	seed		= readint(f)
+	firstrun	= readint(f)
+	
+	objects = []
+	#Load object list
+	while 0==0:
+		item = readstr(f)
+		if len(item) > 0:
+			objects.append(bpy.data.objects.get(item))
+		else:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list