[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2996] contrib/py/scripts/addons/ particle_hair_lab.py: adding particle hair lab to contrib
Brendon Murphy
meta.androcto1 at gmail.com
Sat Feb 18 00:12:47 CET 2012
Revision: 2996
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2996
Author: meta-androcto
Date: 2012-02-17 23:12:41 +0000 (Fri, 17 Feb 2012)
Log Message:
-----------
adding particle hair lab to contrib
Added Paths:
-----------
contrib/py/scripts/addons/particle_hair_lab.py
Added: contrib/py/scripts/addons/particle_hair_lab.py
===================================================================
--- contrib/py/scripts/addons/particle_hair_lab.py (rev 0)
+++ contrib/py/scripts/addons/particle_hair_lab.py 2012-02-17 23:12:41 UTC (rev 2996)
@@ -0,0 +1,1506 @@
+# ##### 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": "Grass Lab",
+ "author": "Ondrej Raha(lokhorn), meta-androcto",
+ "version": (0,5),
+ "blender": (2, 6, 0),
+ "api": 42149,
+ "location": "View3D > Tool Shelf > Grass Preset Panel",
+ "description": "Creates particle grass with material",
+ "warning": "",
+ "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Object/grass_Lab",
+ "tracker_url": "",
+ "category": "Object"}
+
+
+import bpy
+from bpy.props import *
+
+# Returns the action we want to take
+def getActionToDo(obj):
+ if not obj or obj.type != 'MESH':
+ return 'NOT_OBJ_DO_NOTHING'
+ elif obj.type == 'MESH':
+ return 'GENERATE'
+ else:
+ return "DO_NOTHING"
+
+# TO DO
+"""
+class saveSelectionPanel(bpy.types.Panel):
+ bl_space_type = 'VIEW_3D'
+ bl_region_type = 'TOOLS'
+
+ bl_label = "Selection Save"
+ bl_options = {"DEFAULT_CLOSED"}
+ bl_context = "particlemode"
+
+
+ def draw(self, context):
+ layout = self.layout
+ col = layout.column(align=True)
+
+ col.operator("save.selection", text="Save Selection 1")
+"""
+######GRASS########################
+class grassLabPanel(bpy.types.Panel):
+ bl_space_type = 'VIEW_3D'
+ bl_region_type = 'TOOLS'
+
+ bl_label = "Grass Lab"
+ bl_context = "objectmode"
+
+
+ def draw(self, context):
+ active_obj = bpy.context.active_object
+ active_scn = bpy.context.scene.name
+ layout = self.layout
+ col = layout.column(align=True)
+
+ WhatToDo = getActionToDo(active_obj)
+
+
+ if WhatToDo == "GENERATE":
+ col.operator("grass.generate_grass", text="Create grass")
+
+ col.prop(context.scene, "grass_type")
+ else:
+ col.label(text="Select mesh object")
+
+ if active_scn == "TestgrassScene":
+ col.operator("grass.switch_back", text="Switch back to scene")
+ else:
+ col.operator("grass.test_scene", text="Create Test Scene")
+
+# TO DO
+"""
+class saveSelection(bpy.types.Operator):
+ bl_idname = "save.selection"
+ bl_label = "Save Selection"
+ bl_description = "Save selected particles"
+ bl_register = True
+ bl_undo = True
+
+ def execute(self, context):
+
+ return {"FINISHED"}
+"""
+class testScene1(bpy.types.Operator):
+ bl_idname = "grass.switch_back"
+ bl_label = "Switch back to scene"
+ bl_description = "If you want keep this scene, switch scene in info window"
+ bl_register = True
+ bl_undo = True
+
+ def execute(self, context):
+ scene = bpy.context.scene
+ bpy.data.scenes.remove(scene)
+
+ return {"FINISHED"}
+
+
+class testScene2(bpy.types.Operator):
+ bl_idname = "grass.test_scene"
+ bl_label = "Create test scene"
+ bl_description = "You can switch scene in info panel"
+ bl_register = True
+ bl_undo = True
+
+ def execute(self, context):
+# add new scene
+ bpy.ops.scene.new(type="NEW")
+ scene = bpy.context.scene
+ scene.name = "TestgrassScene"
+# render settings
+ render = scene.render
+ render.resolution_x = 1920
+ render.resolution_y = 1080
+ render.resolution_percentage = 50
+# add new world
+ world = bpy.data.worlds.new("grassWorld")
+ scene.world = world
+ world.use_sky_blend = True
+ world.use_sky_paper = True
+ world.horizon_color = (0.004393,0.02121,0.050)
+ world.zenith_color = (0.03335,0.227,0.359)
+
+# add text
+ bpy.ops.object.text_add(location=(-0.292,0,-0.152), rotation =(1.571,0,0))
+ text = bpy.context.active_object
+ text.scale = (0.05,0.05,0.05)
+ text.data.body = "Grass Lab"
+
+# add material to text
+ textMaterial = bpy.data.materials.new('textMaterial')
+ text.data.materials.append(textMaterial)
+ textMaterial.use_shadeless = True
+
+# add camera
+ bpy.ops.object.camera_add(location = (0,-1,0),rotation = (1.571,0,0))
+ cam = bpy.context.active_object.data
+ cam.lens = 50
+ cam.draw_size = 0.1
+
+# add spot lamp
+ bpy.ops.object.lamp_add(type="SPOT", location = (-0.7,-0.5,0.3), rotation =(1.223,0,-0.960))
+ lamp1 = bpy.context.active_object.data
+ lamp1.name = "Key Light"
+ lamp1.energy = 1.5
+ lamp1.distance = 1.5
+ lamp1.shadow_buffer_soft = 5
+ lamp1.shadow_buffer_size = 8192
+ lamp1.shadow_buffer_clip_end = 1.5
+ lamp1.spot_blend = 0.5
+
+# add spot lamp2
+ bpy.ops.object.lamp_add(type="SPOT", location = (0.7,-0.6,0.1), rotation =(1.571,0,0.785))
+ lamp2 = bpy.context.active_object.data
+ lamp2.name = "Fill Light"
+ lamp2.color = (0.874,0.874,1)
+ lamp2.energy = 0.5
+ lamp2.distance = 1.5
+ lamp2.shadow_buffer_soft = 5
+ lamp2.shadow_buffer_size = 4096
+ lamp2.shadow_buffer_clip_end = 1.5
+ lamp2.spot_blend = 0.5
+
+# light Rim
+ """
+ # add spot lamp3
+ bpy.ops.object.lamp_add(type="SPOT", location = (0.191,0.714,0.689), rotation =(0.891,0,2.884))
+ lamp3 = bpy.context.active_object.data
+ lamp3.name = "Rim Light"
+ lamp3.color = (0.194,0.477,1)
+ lamp3.energy = 3
+ lamp3.distance = 1.5
+ lamp3.shadow_buffer_soft = 5
+ lamp3.shadow_buffer_size = 4096
+ lamp3.shadow_buffer_clip_end = 1.5
+ lamp3.spot_blend = 0.5
+ """
+# add sphere
+# add sphere
+ bpy.ops.mesh.primitive_uv_sphere_add(size=0.1)
+ bpy.ops.object.shade_smooth()
+
+ return {"FINISHED"}
+
+
+class Generategrass(bpy.types.Operator):
+ bl_idname = "grass.generate_grass"
+ bl_label = "Generate grass"
+ bl_description = "Create a grass"
+ bl_register = True
+ bl_undo = True
+
+ def execute(self, context):
+# Make variable that is the current .blend file main data blocks
+ blend_data = context.blend_data
+ ob = bpy.context.active_object
+ scene = context.scene
+
+######################################################################
+########################Test screen grass########################
+ if scene.grass_type == '0':
+
+###############Create New Material##################
+# add new material
+ grassMaterial = bpy.data.materials.new('greengrassMat')
+ ob.data.materials.append(grassMaterial)
+
+#Material settings
+ grassMaterial.preview_render_type = "HAIR"
+ grassMaterial.diffuse_color = (0.09710, 0.288, 0.01687)
+ grassMaterial.specular_color = (0.604, 0.465, 0.136)
+ grassMaterial.specular_intensity = 0.3
+ grassMaterial.ambient = 0
+ grassMaterial.use_cubic = True
+ grassMaterial.use_transparency = True
+ grassMaterial.alpha = 0
+ grassMaterial.use_transparent_shadows = True
+ #strand
+ grassMaterial.strand.use_blender_units = True
+ grassMaterial.strand.root_size = 0.00030
+ grassMaterial.strand.tip_size = 0.00010
+ grassMaterial.strand.size_min = 0.7
+ grassMaterial.strand.width_fade = 0.1
+ grassMaterial.strand.shape = 0.061
+ grassMaterial.strand.blend_distance = 0.001
+
+
+# add texture
+ grassTex = bpy.data.textures.new("greengrassTex", type='BLEND')
+ grassTex.use_preview_alpha = True
+ grassTex.use_color_ramp = True
+ ramp = grassTex.color_ramp
+ rampElements = ramp.elements
+ rampElements[0].position = 0
+ rampElements[0].color = [0.114,0.375,0.004025,0.38]
+ rampElements[1].position = 1
+ rampElements[1].color = [0.267,0.155,0.02687,0]
+ rampElement1 = rampElements.new(0.111)
+ rampElement1.color = [0.281,0.598,0.03157,0.65]
+ rampElement2 = rampElements.new(0.366)
+ rampElement2.color = [0.119,0.528,0.136,0.87]
+ rampElement3 = rampElements.new(0.608)
+ rampElement3.color = [0.247,0.713,0.006472,0.8]
+ rampElement4 = rampElements.new(0.828)
+ rampElement4.color = [0.01943,0.163,0.01242,0.64]
+
+# add texture to material
+ MTex = grassMaterial.texture_slots.add()
+ MTex.texture = grassTex
+ MTex.texture_coords = "STRAND"
+ MTex.use_map_alpha = True
+
+
+
+############### Create Particles ##################
+# Add new particle system
+
+ NumberOfMaterials = 0
+ for i in ob.data.materials:
+ NumberOfMaterials +=1
+
+
+ bpy.ops.object.particle_system_add()
+#Particle settings setting it up!
+ grassParticles = bpy.context.object.particle_systems.active
+ grassParticles.name = "greengrassPar"
+ grassParticles.settings.type = "HAIR"
+ grassParticles.settings.use_advanced_hair = True
+ grassParticles.settings.count = 500
+ grassParticles.settings.normal_factor = 0.05
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list