minor code cleanup
[blender-addons-contrib.git] / particle_hair_lab.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 bl_info = {
20     "name": "Grass Lab",
21     "author": "Ondrej Raha(lokhorn), meta-androcto",
22     "version": (0,5),
23     "blender": (2, 6, 0),
24     "location": "View3D > Tool Shelf > Grass Preset Panel",
25     "description": "Creates particle grass with material",
26     "warning": "",
27     "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Object/Hair_Lab",
28     "tracker_url": "https://projects.blender.org/tracker/index.php?"\
29         "func=detail&aid=30238",
30     "category": "Object"}
31
32
33 import bpy
34 from bpy.props import *
35
36 # Returns the action we want to take
37 def getActionToDo(obj):
38     if not obj or obj.type != 'MESH':
39         return 'NOT_OBJ_DO_NOTHING'
40     elif obj.type == 'MESH':
41         return 'GENERATE'
42     else:
43         return "DO_NOTHING"
44
45 # TO DO
46 """
47 class saveSelectionPanel(bpy.types.Panel):
48     bl_space_type = 'VIEW_3D'
49     bl_region_type = 'TOOLS'
50
51     bl_label = "Selection Save"
52     bl_options = {'DEFAULT_CLOSED'}
53     bl_context = "particlemode"
54     
55
56     def draw(self, context):
57         layout = self.layout
58         col = layout.column(align=True)
59         
60         col.operator("save.selection", text="Save Selection 1")
61 """
62 ######GRASS########################
63 class grassLabPanel(bpy.types.Panel):
64     bl_space_type = 'VIEW_3D'
65     bl_region_type = 'TOOLS'
66
67     bl_label = "Grass Lab"
68     bl_context = "objectmode"
69     
70
71     def draw(self, context):
72         active_obj = bpy.context.active_object
73         active_scn = bpy.context.scene.name
74         layout = self.layout
75         col = layout.column(align=True)
76         
77         WhatToDo = getActionToDo(active_obj)
78       
79         
80         if WhatToDo == "GENERATE":
81             col.operator("grass.generate_grass", text="Create grass")
82
83             col.prop(context.scene, "grass_type")
84         else:
85             col.label(text="Select mesh object")
86         
87         if active_scn == "TestgrassScene":
88             col.operator("grass.switch_back", text="Switch back to scene")
89         else:
90             col.operator("grass.test_scene", text="Create Test Scene")
91
92 # TO DO
93 """
94 class saveSelection(bpy.types.Operator):
95     bl_idname = "save.selection"
96     bl_label = "Save Selection"
97     bl_description = "Save selected particles"
98     bl_register = True
99     bl_undo = True
100     
101     def execute(self, context):
102         
103         return {'FINISHED'}
104 """
105 class testScene1(bpy.types.Operator):
106     bl_idname = "grass.switch_back"
107     bl_label = "Switch back to scene"
108     bl_description = "If you want keep this scene, switch scene in info window"
109     bl_register = True
110     bl_undo = True
111     
112     def execute(self, context):
113         scene = bpy.context.scene
114         bpy.data.scenes.remove(scene)
115         
116         return {'FINISHED'}
117         
118         
119 class testScene2(bpy.types.Operator):
120     bl_idname = "grass.test_scene"
121     bl_label = "Create test scene"
122     bl_description = "You can switch scene in info panel"
123     bl_register = True
124     bl_undo = True
125     
126     def execute(self, context):
127 # add new scene
128         bpy.ops.scene.new(type="NEW")
129         scene = bpy.context.scene
130         scene.name = "TestgrassScene"
131 # render settings
132         render = scene.render
133         render.resolution_x = 1920
134         render.resolution_y = 1080
135         render.resolution_percentage = 50
136 # add new world
137         world = bpy.data.worlds.new("grassWorld")
138         scene.world = world
139         world.use_sky_blend = True
140         world.use_sky_paper = True
141         world.horizon_color = (0.004393,0.02121,0.050)
142         world.zenith_color = (0.03335,0.227,0.359)
143        
144 # add text
145         bpy.ops.object.text_add(location=(-0.292,0,-0.152), rotation =(1.571,0,0))
146         text = bpy.context.active_object
147         text.scale = (0.05,0.05,0.05)
148         text.data.body = "Grass Lab"
149         
150 # add material to text
151         textMaterial = bpy.data.materials.new('textMaterial')
152         text.data.materials.append(textMaterial)
153         textMaterial.use_shadeless = True
154         
155 # add camera
156         bpy.ops.object.camera_add(location = (0,-1,0),rotation = (1.571,0,0))
157         cam = bpy.context.active_object.data
158         cam.lens = 50
159         cam.draw_size = 0.1
160         
161 # add spot lamp
162         bpy.ops.object.lamp_add(type="SPOT", location = (-0.7,-0.5,0.3), rotation =(1.223,0,-0.960))
163         lamp1 = bpy.context.active_object.data
164         lamp1.name = "Key Light"
165         lamp1.energy = 1.5
166         lamp1.distance = 1.5
167         lamp1.shadow_buffer_soft = 5
168         lamp1.shadow_buffer_size = 8192
169         lamp1.shadow_buffer_clip_end = 1.5
170         lamp1.spot_blend = 0.5
171         
172 # add spot lamp2
173         bpy.ops.object.lamp_add(type="SPOT", location = (0.7,-0.6,0.1), rotation =(1.571,0,0.785))
174         lamp2 = bpy.context.active_object.data
175         lamp2.name = "Fill Light"
176         lamp2.color = (0.874,0.874,1)
177         lamp2.energy = 0.5
178         lamp2.distance = 1.5
179         lamp2.shadow_buffer_soft = 5
180         lamp2.shadow_buffer_size = 4096
181         lamp2.shadow_buffer_clip_end = 1.5
182         lamp2.spot_blend = 0.5
183         
184 # light Rim
185         """
186         # add spot lamp3
187         bpy.ops.object.lamp_add(type="SPOT", location = (0.191,0.714,0.689), rotation =(0.891,0,2.884))
188         lamp3 = bpy.context.active_object.data
189         lamp3.name = "Rim Light"
190         lamp3.color = (0.194,0.477,1)
191         lamp3.energy = 3
192         lamp3.distance = 1.5
193         lamp3.shadow_buffer_soft = 5
194         lamp3.shadow_buffer_size = 4096
195         lamp3.shadow_buffer_clip_end = 1.5
196         lamp3.spot_blend = 0.5
197         """
198 # add sphere
199 # add sphere
200         bpy.ops.mesh.primitive_uv_sphere_add(size=0.1)
201         bpy.ops.object.shade_smooth()
202                 
203         return {'FINISHED'}
204
205
206 class Generategrass(bpy.types.Operator):
207     bl_idname = "grass.generate_grass"
208     bl_label = "Generate grass"
209     bl_description = "Create a grass"
210     bl_register = True
211     bl_undo = True
212     
213     def execute(self, context):
214 # Make variable that is the current .blend file main data blocks
215         blend_data = context.blend_data
216         ob = bpy.context.active_object
217         scene = context.scene
218
219 ######################################################################
220 ########################Test screen grass########################
221         if scene.grass_type == '0':              
222             
223 ###############Create New Material##################
224 # add new material
225             grassMaterial = bpy.data.materials.new('greengrassMat')
226             ob.data.materials.append(grassMaterial)
227             
228 #Material settings
229             grassMaterial.preview_render_type = "HAIR"
230             grassMaterial.diffuse_color = (0.09710, 0.288, 0.01687)
231             grassMaterial.specular_color = (0.604, 0.465, 0.136)
232             grassMaterial.specular_intensity = 0.3
233             grassMaterial.ambient = 0
234             grassMaterial.use_cubic = True
235             grassMaterial.use_transparency = True
236             grassMaterial.alpha = 0
237             grassMaterial.use_transparent_shadows = True
238             #strand
239             grassMaterial.strand.use_blender_units = True
240             grassMaterial.strand.root_size = 0.00030
241             grassMaterial.strand.tip_size = 0.00010
242             grassMaterial.strand.size_min = 0.7
243             grassMaterial.strand.width_fade = 0.1
244             grassMaterial.strand.shape = 0.061
245             grassMaterial.strand.blend_distance = 0.001
246             
247             
248 # add texture
249             grassTex = bpy.data.textures.new("greengrassTex", type='BLEND')
250             grassTex.use_preview_alpha = True
251             grassTex.use_color_ramp = True
252             ramp = grassTex.color_ramp
253             rampElements = ramp.elements
254             rampElements[0].position = 0
255             rampElements[0].color = [0.114,0.375,0.004025,0.38]
256             rampElements[1].position = 1
257             rampElements[1].color = [0.267,0.155,0.02687,0]
258             rampElement1 = rampElements.new(0.111)
259             rampElement1.color = [0.281,0.598,0.03157,0.65]
260             rampElement2 = rampElements.new(0.366)
261             rampElement2.color = [0.119,0.528,0.136,0.87]
262             rampElement3 = rampElements.new(0.608)
263             rampElement3.color = [0.247,0.713,0.006472,0.8]
264             rampElement4 = rampElements.new(0.828)
265             rampElement4.color = [0.01943,0.163,0.01242,0.64]
266     
267 # add texture to material
268             MTex = grassMaterial.texture_slots.add()
269             MTex.texture = grassTex
270             MTex.texture_coords = "STRAND"
271             MTex.use_map_alpha = True
272             
273             
274             
275 ###############  Create Particles  ##################
276 # Add new particle system
277             
278             NumberOfMaterials = 0
279             for i in ob.data.materials:
280                 NumberOfMaterials +=1
281             
282             
283             bpy.ops.object.particle_system_add()
284 #Particle settings setting it up!
285             grassParticles = bpy.context.object.particle_systems.active
286             grassParticles.name = "greengrassPar"
287             grassParticles.settings.type = "HAIR"
288             grassParticles.settings.use_advanced_hair = True
289             grassParticles.settings.count = 500
290             grassParticles.settings.normal_factor = 0.05
291             grassParticles.settings.factor_random = 0.001
292             grassParticles.settings.use_dynamic_rotation = True
293             
294             grassParticles.settings.material = NumberOfMaterials
295             
296             grassParticles.settings.use_strand_primitive = True
297             grassParticles.settings.use_hair_bspline = True
298             grassParticles.settings.render_step = 5
299             grassParticles.settings.length_random = 0.5
300             grassParticles.settings.draw_step = 5
301 # children
302             grassParticles.settings.rendered_child_count = 50
303             grassParticles.settings.child_type = "INTERPOLATED"
304             grassParticles.settings.child_length = 0.250
305             grassParticles.settings.create_long_hair_children = True
306             grassParticles.settings.clump_shape = 0.074
307             grassParticles.settings.clump_factor = 0.55
308             grassParticles.settings.roughness_endpoint = 0.080
309             grassParticles.settings.roughness_end_shape = 0.80
310             grassParticles.settings.roughness_2 = 0.043
311             grassParticles.settings.roughness_2_size = 0.230
312         
313         
314 ######################################################################
315 ######################  Field Grass  ########################
316         if scene.grass_type == '1':
317 ###############Create New Material##################
318 # add new material
319             grassMaterial = bpy.data.materials.new('fieldgrassMat')
320             ob.data.materials.append(grassMaterial)
321             
322 #Material settings
323             grassMaterial.preview_render_type = "HAIR"
324             grassMaterial.diffuse_color = (0.229, 0.800, 0.010)
325             grassMaterial.specular_color = (0.010, 0.06072, 0.000825)
326             grassMaterial.specular_intensity = 0.3
327             grassMaterial.specular_hardness = 100
328             grassMaterial.use_specular_ramp = True
329             
330             ramp = grassMaterial.specular_ramp
331             rampElements = ramp.elements
332             rampElements[0].position = 0
333             rampElements[0].color = [0.0356,0.0652,0.009134,0]
334             rampElements[1].position = 1
335             rampElements[1].color = [0.352,0.750,0.231,1]
336             rampElement1 = rampElements.new(0.255)
337             rampElement1.color = [0.214,0.342,0.0578,0.31]
338             rampElement2 = rampElements.new(0.594)
339             rampElement2.color = [0.096,0.643,0.0861,0.72]
340             
341             grassMaterial.ambient = 0
342             grassMaterial.use_cubic = True
343             grassMaterial.use_transparency = True
344             grassMaterial.alpha = 0
345             grassMaterial.use_transparent_shadows = True
346             #strand
347             grassMaterial.strand.use_blender_units = True
348             grassMaterial.strand.root_size = 0.00030
349             grassMaterial.strand.tip_size = 0.00015
350             grassMaterial.strand.size_min = 0.450
351             grassMaterial.strand.width_fade = 0.1
352             grassMaterial.strand.shape = 0.02
353             grassMaterial.strand.blend_distance = 0.001
354             
355             
356 # add texture
357             grassTex = bpy.data.textures.new("feildgrassTex", type='BLEND')
358             grassTex.name = "feildgrassTex"
359             grassTex.use_preview_alpha = True
360             grassTex.use_color_ramp = True
361             ramp = grassTex.color_ramp
362             rampElements = ramp.elements
363             rampElements[0].position = 0
364             rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
365             rampElements[1].position = 1
366             rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
367             rampElement1 = rampElements.new(0.111)
368             rampElement1.color = [0.01467,0.005307,0.00316,0.65]
369             rampElement2 = rampElements.new(0.366)
370             rampElement2.color = [0.0272,0.01364,0.01013,0.87]
371             rampElement3 = rampElements.new(0.608)
372             rampElement3.color = [0.04445,0.02294,0.01729,0.8]
373             rampElement4 = rampElements.new(0.828)
374             rampElement4.color = [0.04092,0.0185,0.01161,0.64]
375             
376 # add texture to material
377             MTex = grassMaterial.texture_slots.add()
378             MTex.texture = grassTex
379             MTex.texture_coords = "STRAND"
380             MTex.use_map_alpha = True
381             
382             
383 ###############Create Particles##################
384 # Add new particle system
385             
386             NumberOfMaterials = 0
387             for i in ob.data.materials:
388                 NumberOfMaterials +=1
389             
390             
391             bpy.ops.object.particle_system_add()
392 #Particle settings setting it up!
393             grassParticles = bpy.context.object.particle_systems.active
394             grassParticles.name = "fieldgrassPar"
395             grassParticles.settings.type = "HAIR"
396             grassParticles.settings.use_emit_random = True
397             grassParticles.settings.use_even_distribution = True
398             grassParticles.settings.use_advanced_hair = True
399             grassParticles.settings.count = 2000
400 #Particle settings Velocity
401             grassParticles.settings.normal_factor = 0.060
402             grassParticles.settings.factor_random = 0.045
403             grassParticles.settings.use_dynamic_rotation = False
404             grassParticles.settings.brownian_factor = 0.070
405             grassParticles.settings.damping = 0.160
406             grassParticles.settings.material = NumberOfMaterials
407  # strands           
408             grassParticles.settings.use_strand_primitive = True
409             grassParticles.settings.use_hair_bspline = True
410             grassParticles.settings.render_step = 7
411             grassParticles.settings.length_random = 1.0
412             grassParticles.settings.draw_step = 2
413 # children
414             grassParticles.settings.child_type = "INTERPOLATED"
415             grassParticles.settings.child_length = 0.160
416             grassParticles.settings.create_long_hair_children = False
417             grassParticles.settings.clump_factor = 0.000
418             grassParticles.settings.clump_shape = 0.000
419             grassParticles.settings.roughness_endpoint = 0.000
420             grassParticles.settings.roughness_end_shape = 1
421             grassParticles.settings.roughness_2 = 0.200
422             grassParticles.settings.roughness_2_size = 0.230
423         
424         
425 ######################################################################
426 ########################Short Clumpped grass##########################
427         elif scene.grass_type == '2':
428 ###############Create New Material##################
429 # add new material
430             grassMaterial = bpy.data.materials.new('clumpygrassMat')
431             ob.data.materials.append(grassMaterial)
432             
433 #Material settings
434             grassMaterial.preview_render_type = "HAIR"
435             grassMaterial.diffuse_color = (0.01504, 0.05222, 0.007724)
436             grassMaterial.specular_color = (0.02610, 0.196, 0.04444)
437             grassMaterial.specular_intensity = 0.5
438             grassMaterial.specular_hardness = 100
439             grassMaterial.ambient = 0
440             grassMaterial.use_cubic = True
441             grassMaterial.use_transparency = True
442             grassMaterial.alpha = 0
443             grassMaterial.use_transparent_shadows = True
444 #strand
445             grassMaterial.strand.use_blender_units = True
446             grassMaterial.strand.root_size = 0.000315
447             grassMaterial.strand.tip_size = 0.00020
448             grassMaterial.strand.size_min = 0.2
449             grassMaterial.strand.width_fade = 0.1
450             grassMaterial.strand.shape = -0.900
451             grassMaterial.strand.blend_distance = 0.001
452             
453 # add texture
454             grassTex = bpy.data.textures.new("clumpygrasstex", type='BLEND')
455             grassTex.use_preview_alpha = True
456             grassTex.use_color_ramp = True
457             ramp = grassTex.color_ramp
458             rampElements = ramp.elements
459             rampElements[0].position = 0
460             rampElements[0].color = [0.004025,0.002732,0.002428,0.38]
461             rampElements[1].position = 1
462             rampElements[1].color = [0.141,0.622,0.107,0.2]
463             rampElement1 = rampElements.new(0.202)
464             rampElement1.color = [0.01885,0.2177,0.01827,0.65]
465             rampElement2 = rampElements.new(0.499)
466             rampElement2.color = [0.114,0.309,0.09822,0.87]
467             rampElement3 = rampElements.new(0.828)
468             rampElement3.color = [0.141,0.427,0.117,0.64]
469             
470 # add texture to material
471             MTex = grassMaterial.texture_slots.add()
472             MTex.texture = grassTex
473             MTex.texture_coords = "STRAND"
474             MTex.use_map_alpha = True
475             
476             
477 ###############Create Particles##################
478 # Add new particle system
479             
480             NumberOfMaterials = 0
481             for i in ob.data.materials:
482                 NumberOfMaterials +=1
483             
484             
485             bpy.ops.object.particle_system_add()
486 #Particle settings setting it up!
487             grassParticles = bpy.context.object.particle_systems.active
488             grassParticles.name = "clumpygrass"
489             grassParticles.settings.type = "HAIR"
490             grassParticles.settings.use_advanced_hair = True
491             grassParticles.settings.hair_step = 2
492             grassParticles.settings.count = 250
493             grassParticles.settings.normal_factor = 0.0082
494             grassParticles.settings.tangent_factor = 0.001
495             grassParticles.settings.tangent_phase = 0.250
496             grassParticles.settings.factor_random = 0.001
497             grassParticles.settings.use_dynamic_rotation = True
498             
499             grassParticles.settings.material = NumberOfMaterials
500             
501             grassParticles.settings.use_strand_primitive = True
502             grassParticles.settings.use_hair_bspline = True
503             grassParticles.settings.render_step = 3
504             grassParticles.settings.length_random = 0.3
505             grassParticles.settings.draw_step = 3
506 # children
507             grassParticles.settings.child_type = "INTERPOLATED"
508             grassParticles.settings.child_length = 0.667
509             grassParticles.settings.child_length_threshold = 0.111
510             grassParticles.settings.rendered_child_count = 200
511             grassParticles.settings.virtual_parents = 1
512             grassParticles.settings.clump_factor = 0.425
513             grassParticles.settings.clump_shape = -0.999
514             grassParticles.settings.roughness_endpoint = 0.003
515             grassParticles.settings.roughness_end_shape = 5
516             
517             
518         
519         return {'FINISHED'}
520                 
521 ####
522 ######### HAIR LAB ##########
523 ####
524 class HairLabPanel(bpy.types.Panel):
525     bl_space_type = 'VIEW_3D'
526     bl_region_type = 'TOOLS'
527
528     bl_label = "Hair Lab"
529     bl_context = "objectmode"
530     
531
532     def draw(self, context):
533         active_obj = bpy.context.active_object
534         active_scn = bpy.context.scene.name
535         layout = self.layout
536         col = layout.column(align=True)
537         
538         WhatToDo = getActionToDo(active_obj)
539       
540         
541         if WhatToDo == "GENERATE":
542             col.operator("hair.generate_hair", text="Create Hair")
543
544             col.prop(context.scene, "hair_type")
545         else:
546             col.label(text="Select mesh object")
547         
548         if active_scn == "TestHairScene":
549             col.operator("hair.switch_back", text="Switch back to scene")
550         else:
551             col.operator("hair.test_scene", text="Create Test Scene")
552
553 # TO DO
554 """
555 class saveSelection(bpy.types.Operator):
556     bl_idname = "save.selection"
557     bl_label = "Save Selection"
558     bl_description = "Save selected particles"
559     bl_register = True
560     bl_undo = True
561     
562     def execute(self, context):
563         
564         return {'FINISHED'}
565 """
566 class testScene3(bpy.types.Operator):
567     bl_idname = "hair.switch_back"
568     bl_label = "Switch back to scene"
569     bl_description = "If you want keep this scene, switch scene in info window"
570     bl_register = True
571     bl_undo = True
572     
573     def execute(self, context):
574         scene = bpy.context.scene
575         bpy.data.scenes.remove(scene)
576         
577         return {'FINISHED'}
578         
579         
580 class testScene4(bpy.types.Operator):
581     bl_idname = "hair.test_scene"
582     bl_label = "Create test scene"
583     bl_description = "You can switch scene in info panel"
584     bl_register = True
585     bl_undo = True
586     
587     def execute(self, context):
588 # add new scene
589         bpy.ops.scene.new(type="NEW")
590         scene = bpy.context.scene
591         scene.name = "TestHairScene"
592 # render settings
593         render = scene.render
594         render.resolution_x = 1920
595         render.resolution_y = 1080
596         render.resolution_percentage = 50
597 # add new world
598         world = bpy.data.worlds.new("HairWorld")
599         scene.world = world
600         world.use_sky_blend = True
601         world.use_sky_paper = True
602         world.horizon_color = (0.004393,0.02121,0.050)
603         world.zenith_color = (0.03335,0.227,0.359)
604         
605 # add text
606         bpy.ops.object.text_add(location=(-0.292,0,-0.152), rotation =(1.571,0,0))
607         text = bpy.context.active_object
608         text.scale = (0.05,0.05,0.05)
609         text.data.body = "Hair Lab"
610         
611 # add material to text
612         textMaterial = bpy.data.materials.new('textMaterial')
613         text.data.materials.append(textMaterial)
614         textMaterial.use_shadeless = True
615         
616 # add camera
617         bpy.ops.object.camera_add(location = (0,-1,0),rotation = (1.571,0,0))
618         cam = bpy.context.active_object.data
619         cam.lens = 50
620         cam.draw_size = 0.1
621         
622 # add spot lamp
623         bpy.ops.object.lamp_add(type="SPOT", location = (-0.7,-0.5,0.3), rotation =(1.223,0,-0.960))
624         lamp1 = bpy.context.active_object.data
625         lamp1.name = "Key Light"
626         lamp1.energy = 1.5
627         lamp1.distance = 1.5
628         lamp1.shadow_buffer_soft = 5
629         lamp1.shadow_buffer_size = 8192
630         lamp1.shadow_buffer_clip_end = 1.5
631         lamp1.spot_blend = 0.5
632         
633 # add spot lamp2
634         bpy.ops.object.lamp_add(type="SPOT", location = (0.7,-0.6,0.1), rotation =(1.571,0,0.785))
635         lamp2 = bpy.context.active_object.data
636         lamp2.name = "Fill Light"
637         lamp2.color = (0.874,0.874,1)
638         lamp2.energy = 0.5
639         lamp2.distance = 1.5
640         lamp2.shadow_buffer_soft = 5
641         lamp2.shadow_buffer_size = 4096
642         lamp2.shadow_buffer_clip_end = 1.5
643         lamp2.spot_blend = 0.5
644         
645 # light Rim
646         """
647         # add spot lamp3
648         bpy.ops.object.lamp_add(type="SPOT", location = (0.191,0.714,0.689), rotation =(0.891,0,2.884))
649         lamp3 = bpy.context.active_object.data
650         lamp3.name = "Rim Light"
651         lamp3.color = (0.194,0.477,1)
652         lamp3.energy = 3
653         lamp3.distance = 1.5
654         lamp3.shadow_buffer_soft = 5
655         lamp3.shadow_buffer_size = 4096
656         lamp3.shadow_buffer_clip_end = 1.5
657         lamp3.spot_blend = 0.5
658         """
659 # add sphere
660         bpy.ops.mesh.primitive_uv_sphere_add(size=0.1)
661         bpy.ops.object.shade_smooth()       
662         return {'FINISHED'}
663
664
665 class GenerateHair(bpy.types.Operator):
666     bl_idname = "hair.generate_hair"
667     bl_label = "Generate Hair"
668     bl_description = "Create a Hair"
669     bl_register = True
670     bl_undo = True
671     
672     def execute(self, context):
673 # Make variable that is the current .blend file main data blocks
674         blend_data = context.blend_data
675         ob = bpy.context.active_object
676         scene = context.scene
677
678 ######################################################################
679 ########################Long Red Straight Hair########################
680         if scene.hair_type == '0':              
681             
682 ###############Create New Material##################
683 # add new material
684             hairMaterial = bpy.data.materials.new('LongRedStraightHairMat')
685             ob.data.materials.append(hairMaterial)
686             
687 #Material settings
688             hairMaterial.preview_render_type = "HAIR"
689             hairMaterial.diffuse_color = (0.287, 0.216, 0.04667)
690             hairMaterial.specular_color = (0.604, 0.465, 0.136)
691             hairMaterial.specular_intensity = 0.3
692             hairMaterial.ambient = 0
693             hairMaterial.use_cubic = True
694             hairMaterial.use_transparency = True
695             hairMaterial.alpha = 0
696             hairMaterial.use_transparent_shadows = True
697 #strand
698             hairMaterial.strand.use_blender_units = True
699             hairMaterial.strand.root_size = 0.00030
700             hairMaterial.strand.tip_size = 0.00010
701             hairMaterial.strand.size_min = 0.7
702             hairMaterial.strand.width_fade = 0.1
703             hairMaterial.strand.shape = 0.061
704             hairMaterial.strand.blend_distance = 0.001
705             
706             
707 # add texture
708             hairTex = bpy.data.textures.new("LongRedStraightHairTex", type='BLEND')
709             hairTex.use_preview_alpha = True
710             hairTex.use_color_ramp = True
711             ramp = hairTex.color_ramp
712             rampElements = ramp.elements
713             rampElements[0].position = 0
714             rampElements[0].color = [0.114,0.05613,0.004025,0.38]
715             rampElements[1].position = 1
716             rampElements[1].color = [0.267,0.155,0.02687,0]
717             rampElement1 = rampElements.new(0.111)
718             rampElement1.color = [0.281,0.168,0.03157,0.65]
719             rampElement2 = rampElements.new(0.366)
720             rampElement2.color = [0.288,0.135,0.006242,0.87]
721             rampElement3 = rampElements.new(0.608)
722             rampElement3.color = [0.247,0.113,0.006472,0.8]
723             rampElement4 = rampElements.new(0.828)
724             rampElement4.color = [0.253,0.09919,0.01242,0.64]
725     
726 # add texture to material
727             MTex = hairMaterial.texture_slots.add()
728             MTex.texture = hairTex
729             MTex.texture_coords = "STRAND"
730             MTex.use_map_alpha = True
731             
732             
733             
734 ###############Create Particles##################
735 # Add new particle system
736             
737             NumberOfMaterials = 0
738             for i in ob.data.materials:
739                 NumberOfMaterials +=1
740             
741             
742             bpy.ops.object.particle_system_add()
743 #Particle settings setting it up!
744             hairParticles = bpy.context.object.particle_systems.active
745             hairParticles.name = "LongRedStraightHairPar"
746             hairParticles.settings.type = "HAIR"
747             hairParticles.settings.use_advanced_hair = True
748             hairParticles.settings.count = 500
749             hairParticles.settings.normal_factor = 0.05
750             hairParticles.settings.factor_random = 0.001
751             hairParticles.settings.use_dynamic_rotation = True
752             
753             hairParticles.settings.material = NumberOfMaterials
754             
755             hairParticles.settings.use_strand_primitive = True
756             hairParticles.settings.use_hair_bspline = True
757             hairParticles.settings.render_step = 5
758             hairParticles.settings.length_random = 0.5
759             hairParticles.settings.draw_step = 5
760 # children
761             hairParticles.settings.child_type = "INTERPOLATED"
762             hairParticles.settings.create_long_hair_children = True
763             hairParticles.settings.clump_factor = 0.55
764             hairParticles.settings.roughness_endpoint = 0.005
765             hairParticles.settings.roughness_end_shape = 5
766             hairParticles.settings.roughness_2 = 0.003
767             hairParticles.settings.roughness_2_size = 0.230
768         
769         
770 ######################################################################
771 ########################Long Brown Curl Hair##########################
772         if scene.hair_type == '1':
773 ###############Create New Material##################
774 # add new material
775             hairMaterial = bpy.data.materials.new('LongBrownCurlHairMat')
776             ob.data.materials.append(hairMaterial)
777             
778 #Material settings
779             hairMaterial.preview_render_type = "HAIR"
780             hairMaterial.diffuse_color = (0.662, 0.518, 0.458)
781             hairMaterial.specular_color = (0.351, 0.249, 0.230)
782             hairMaterial.specular_intensity = 0.3
783             hairMaterial.specular_hardness = 100
784             hairMaterial.use_specular_ramp = True
785             
786             ramp = hairMaterial.specular_ramp
787             rampElements = ramp.elements
788             rampElements[0].position = 0
789             rampElements[0].color = [0.0356,0.0152,0.009134,0]
790             rampElements[1].position = 1
791             rampElements[1].color = [0.352,0.250,0.231,1]
792             rampElement1 = rampElements.new(0.255)
793             rampElement1.color = [0.214,0.08244,0.0578,0.31]
794             rampElement2 = rampElements.new(0.594)
795             rampElement2.color = [0.296,0.143,0.0861,0.72]
796             
797             hairMaterial.ambient = 0
798             hairMaterial.use_cubic = True
799             hairMaterial.use_transparency = True
800             hairMaterial.alpha = 0
801             hairMaterial.use_transparent_shadows = True
802 #strand
803             hairMaterial.strand.use_blender_units = True
804             hairMaterial.strand.root_size = 0.00030
805             hairMaterial.strand.tip_size = 0.00015
806             hairMaterial.strand.size_min = 0.450
807             hairMaterial.strand.width_fade = 0.1
808             hairMaterial.strand.shape = 0.02
809             hairMaterial.strand.blend_distance = 0.001
810             
811             
812 # add texture
813             hairTex = bpy.data.textures.new("HairTex", type='BLEND')
814             hairTex.name = "LongBrownCurlHairTex"
815             hairTex.use_preview_alpha = True
816             hairTex.use_color_ramp = True
817             ramp = hairTex.color_ramp
818             rampElements = ramp.elements
819             rampElements[0].position = 0
820             rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
821             rampElements[1].position = 1
822             rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
823             rampElement1 = rampElements.new(0.111)
824             rampElement1.color = [0.01467,0.005307,0.00316,0.65]
825             rampElement2 = rampElements.new(0.366)
826             rampElement2.color = [0.0272,0.01364,0.01013,0.87]
827             rampElement3 = rampElements.new(0.608)
828             rampElement3.color = [0.04445,0.02294,0.01729,0.8]
829             rampElement4 = rampElements.new(0.828)
830             rampElement4.color = [0.04092,0.0185,0.01161,0.64]
831             
832 # add texture to material
833             MTex = hairMaterial.texture_slots.add()
834             MTex.texture = hairTex
835             MTex.texture_coords = "STRAND"
836             MTex.use_map_alpha = True
837             
838             
839 ###############Create Particles##################
840 # Add new particle system
841             
842             NumberOfMaterials = 0
843             for i in ob.data.materials:
844                 NumberOfMaterials +=1
845             
846             
847             bpy.ops.object.particle_system_add()
848 #Particle settings setting it up!
849             hairParticles = bpy.context.object.particle_systems.active
850             hairParticles.name = "LongBrownCurlHairPar"
851             hairParticles.settings.type = "HAIR"
852             hairParticles.settings.use_advanced_hair = True
853             hairParticles.settings.count = 500
854             hairParticles.settings.normal_factor = 0.05
855             hairParticles.settings.factor_random = 0.001
856             hairParticles.settings.use_dynamic_rotation = True
857             
858             hairParticles.settings.material = NumberOfMaterials
859             
860             hairParticles.settings.use_strand_primitive = True
861             hairParticles.settings.use_hair_bspline = True
862             hairParticles.settings.render_step = 7
863             hairParticles.settings.length_random = 0.5
864             hairParticles.settings.draw_step = 5
865 # children
866             hairParticles.settings.child_type = "INTERPOLATED"
867             hairParticles.settings.create_long_hair_children = True
868             hairParticles.settings.clump_factor = 0.523
869             hairParticles.settings.clump_shape = 0.383
870             hairParticles.settings.roughness_endpoint = 0.002
871             hairParticles.settings.roughness_end_shape = 5
872             hairParticles.settings.roughness_2 = 0.003
873             hairParticles.settings.roughness_2_size = 2
874             
875             hairParticles.settings.kink = "CURL"
876             hairParticles.settings.kink_amplitude = 0.007597
877             hairParticles.settings.kink_frequency = 6
878             hairParticles.settings.kink_shape = 0.4
879             hairParticles.settings.kink_flat = 0.8
880         
881         
882 ######################################################################
883 ########################Short Dark Hair##########################
884         elif scene.hair_type == '2':
885 ###############Create New Material##################
886 # add new material
887             hairMaterial = bpy.data.materials.new('ShortDarkHairMat')
888             ob.data.materials.append(hairMaterial)
889             
890 #Material settings
891             hairMaterial.preview_render_type = "HAIR"
892             hairMaterial.diffuse_color = (0.560, 0.536, 0.506)
893             hairMaterial.specular_color = (0.196, 0.177, 0.162)
894             hairMaterial.specular_intensity = 0.5
895             hairMaterial.specular_hardness = 100
896             hairMaterial.ambient = 0
897             hairMaterial.use_cubic = True
898             hairMaterial.use_transparency = True
899             hairMaterial.alpha = 0
900             hairMaterial.use_transparent_shadows = True
901 #strand
902             hairMaterial.strand.use_blender_units = True
903             hairMaterial.strand.root_size = 0.0002
904             hairMaterial.strand.tip_size = 0.0001
905             hairMaterial.strand.size_min = 0.3
906             hairMaterial.strand.width_fade = 0.1
907             hairMaterial.strand.shape = 0
908             hairMaterial.strand.blend_distance = 0.001
909             
910 # add texture
911             hairTex = bpy.data.textures.new("ShortDarkHair", type='BLEND')
912             hairTex.use_preview_alpha = True
913             hairTex.use_color_ramp = True
914             ramp = hairTex.color_ramp
915             rampElements = ramp.elements
916             rampElements[0].position = 0
917             rampElements[0].color = [0.004025,0.002732,0.002428,0.38]
918             rampElements[1].position = 1
919             rampElements[1].color = [0.141,0.122,0.107,0.2]
920             rampElement1 = rampElements.new(0.202)
921             rampElement1.color = [0.01885,0.0177,0.01827,0.65]
922             rampElement2 = rampElements.new(0.499)
923             rampElement2.color = [0.114,0.109,0.09822,0.87]
924             rampElement3 = rampElements.new(0.828)
925             rampElement3.color = [0.141,0.127,0.117,0.64]
926             
927 # add texture to material
928             MTex = hairMaterial.texture_slots.add()
929             MTex.texture = hairTex
930             MTex.texture_coords = "STRAND"
931             MTex.use_map_alpha = True
932             
933             
934 ###############Create Particles##################
935 # Add new particle system
936             
937             NumberOfMaterials = 0
938             for i in ob.data.materials:
939                 NumberOfMaterials +=1
940             
941             
942             bpy.ops.object.particle_system_add()
943 #Particle settings setting it up!
944             hairParticles = bpy.context.object.particle_systems.active
945             hairParticles.name = "ShortDarkHair"
946             hairParticles.settings.type = "HAIR"
947             hairParticles.settings.use_advanced_hair = True
948             hairParticles.settings.hair_step = 2
949             hairParticles.settings.count = 450
950             hairParticles.settings.normal_factor = 0.007
951             hairParticles.settings.factor_random = 0.001
952             hairParticles.settings.use_dynamic_rotation = True
953             
954             hairParticles.settings.material = NumberOfMaterials
955             
956             hairParticles.settings.use_strand_primitive = True
957             hairParticles.settings.use_hair_bspline = True
958             hairParticles.settings.render_step = 3
959             hairParticles.settings.length_random = 0.3
960             hairParticles.settings.draw_step = 3
961 # children
962             hairParticles.settings.child_type = "INTERPOLATED"
963             hairParticles.settings.rendered_child_count = 200
964             hairParticles.settings.virtual_parents = 1
965             hairParticles.settings.clump_factor = 0.425
966             hairParticles.settings.clump_shape = 0.1
967             hairParticles.settings.roughness_endpoint = 0.003
968             hairParticles.settings.roughness_end_shape = 5
969             
970             
971         
972         return {'FINISHED'}
973 ####
974 ######## FUR LAB ########
975 ####
976
977 class FurLabPanel(bpy.types.Panel):
978     bl_space_type = 'VIEW_3D'
979     bl_region_type = 'TOOLS'
980
981     bl_label = "Fur Lab"
982     bl_context = "objectmode"
983     
984
985     def draw(self, context):
986         active_obj = bpy.context.active_object
987         active_scn = bpy.context.scene.name
988         layout = self.layout
989         col = layout.column(align=True)
990         
991         WhatToDo = getActionToDo(active_obj)
992       
993         
994         if WhatToDo == "GENERATE":
995             col.operator("fur.generate_fur", text="Create Fur")
996
997             col.prop(context.scene, "fur_type")
998         else:
999             col.label(text="Select mesh object")
1000         
1001         if active_scn == "TestFurScene":
1002             col.operator("hair.switch_back", text="Switch back to scene")
1003         else:
1004             col.operator("fur.test_scene", text="Create Test Scene")
1005
1006 # TO DO
1007 """
1008 class saveSelection(bpy.types.Operator):
1009     bl_idname = "save.selection"
1010     bl_label = "Save Selection"
1011     bl_description = "Save selected particles"
1012     bl_register = True
1013     bl_undo = True
1014     
1015     def execute(self, context):
1016         
1017         return {'FINISHED'}
1018 """
1019 class testScene5(bpy.types.Operator):
1020     bl_idname = "fur.switch_back"
1021     bl_label = "Switch back to scene"
1022     bl_description = "If you want keep this scene, switch scene in info window"
1023     bl_register = True
1024     bl_undo = True
1025     
1026     def execute(self, context):
1027         scene = bpy.context.scene
1028         bpy.data.scenes.remove(scene)
1029         
1030         return {'FINISHED'}
1031         
1032         
1033 class testScene6(bpy.types.Operator):
1034     bl_idname = "fur.test_scene"
1035     bl_label = "Create test scene"
1036     bl_description = "You can switch scene in info panel"
1037     bl_register = True
1038     bl_undo = True
1039     
1040     def execute(self, context):
1041 # add new scene
1042         bpy.ops.scene.new(type="NEW")
1043         scene = bpy.context.scene
1044         scene.name = "TestFurScene"
1045 # render settings
1046         render = scene.render
1047         render.resolution_x = 1920
1048         render.resolution_y = 1080
1049         render.resolution_percentage = 50
1050 # add new world
1051         world = bpy.data.worlds.new("FurWorld")
1052         scene.world = world
1053         world.use_sky_blend = True
1054         world.use_sky_paper = True
1055         world.horizon_color = (0.004393,0.02121,0.050)
1056         world.zenith_color = (0.03335,0.227,0.359)
1057         
1058 # add text
1059         bpy.ops.object.text_add(location=(-0.292,0,-0.152), rotation =(1.571,0,0))
1060         text = bpy.context.active_object
1061         text.scale = (0.05,0.05,0.05)
1062         text.data.body = "Fur Lab"
1063         
1064 # add material to text
1065         textMaterial = bpy.data.materials.new('textMaterial')
1066         text.data.materials.append(textMaterial)
1067         textMaterial.use_shadeless = True
1068         
1069 # add camera
1070         bpy.ops.object.camera_add(location = (0,-1,0),rotation = (1.571,0,0))
1071         cam = bpy.context.active_object.data
1072         cam.lens = 50
1073         cam.draw_size = 0.1
1074         
1075 # add spot lamp
1076         bpy.ops.object.lamp_add(type="SPOT", location = (-0.7,-0.5,0.3), rotation =(1.223,0,-0.960))
1077         lamp1 = bpy.context.active_object.data
1078         lamp1.name = "Key Light"
1079         lamp1.energy = 1.5
1080         lamp1.distance = 1.5
1081         lamp1.shadow_buffer_soft = 5
1082         lamp1.shadow_buffer_size = 8192
1083         lamp1.shadow_buffer_clip_end = 1.5
1084         lamp1.spot_blend = 0.5
1085         
1086 # add spot lamp2
1087         bpy.ops.object.lamp_add(type="SPOT", location = (0.7,-0.6,0.1), rotation =(1.571,0,0.785))
1088         lamp2 = bpy.context.active_object.data
1089         lamp2.name = "Fill Light"
1090         lamp2.color = (0.874,0.874,1)
1091         lamp2.energy = 0.5
1092         lamp2.distance = 1.5
1093         lamp2.shadow_buffer_soft = 5
1094         lamp2.shadow_buffer_size = 4096
1095         lamp2.shadow_buffer_clip_end = 1.5
1096         lamp2.spot_blend = 0.5
1097         
1098 # light Rim
1099         """
1100         # add spot lamp3
1101         bpy.ops.object.lamp_add(type="SPOT", location = (0.191,0.714,0.689), rotation =(0.891,0,2.884))
1102         lamp3 = bpy.context.active_object.data
1103         lamp3.name = "Rim Light"
1104         lamp3.color = (0.194,0.477,1)
1105         lamp3.energy = 3
1106         lamp3.distance = 1.5
1107         lamp3.shadow_buffer_soft = 5
1108         lamp3.shadow_buffer_size = 4096
1109         lamp3.shadow_buffer_clip_end = 1.5
1110         lamp3.spot_blend = 0.5
1111         """
1112 # add sphere
1113         bpy.ops.mesh.primitive_uv_sphere_add(size=0.1)
1114         bpy.ops.object.shade_smooth()       
1115         return {'FINISHED'}
1116
1117
1118 class GenerateFur(bpy.types.Operator):
1119     bl_idname = "fur.generate_fur"
1120     bl_label = "Generate Fur"
1121     bl_description = "Create a Fur"
1122     bl_register = True
1123     bl_undo = True
1124     
1125     def execute(self, context):
1126 # Make variable that is the current .blend file main data blocks
1127         blend_data = context.blend_data
1128         ob = bpy.context.active_object
1129         scene = context.scene
1130
1131 ######################################################################
1132 ########################Short Fur########################
1133         if scene.fur_type == '0':              
1134             
1135 ###############Create New Material##################
1136 # add new material
1137             furMaterial = bpy.data.materials.new('Fur 1')
1138             ob.data.materials.append(furMaterial)
1139             
1140 #Material settings
1141             furMaterial.preview_render_type = "HAIR"
1142             furMaterial.diffuse_color = (0.287, 0.216, 0.04667)
1143             furMaterial.specular_color = (0.604, 0.465, 0.136)
1144             furMaterial.specular_intensity = 0.3
1145             furMaterial.ambient = 0
1146             furMaterial.use_cubic = True
1147             furMaterial.use_transparency = True
1148             furMaterial.alpha = 0
1149             furMaterial.use_transparent_shadows = True
1150 #strand
1151             furMaterial.strand.use_blender_units = True
1152             furMaterial.strand.root_size = 0.00030
1153             furMaterial.strand.tip_size = 0.00010
1154             furMaterial.strand.size_min = 0.7
1155             furMaterial.strand.width_fade = 0.1
1156             furMaterial.strand.shape = 0.061
1157             furMaterial.strand.blend_distance = 0.001
1158             
1159             
1160 # add texture
1161             furTex = bpy.data.textures.new("Fur1Tex", type='BLEND')
1162             furTex.use_preview_alpha = True
1163             furTex.use_color_ramp = True
1164             ramp = furTex.color_ramp
1165             rampElements = ramp.elements
1166             rampElements[0].position = 0
1167             rampElements[0].color = [0.114,0.05613,0.004025,0.38]
1168             rampElements[1].position = 1
1169             rampElements[1].color = [0.267,0.155,0.02687,0]
1170             rampElement1 = rampElements.new(0.111)
1171             rampElement1.color = [0.281,0.168,0.03157,0.65]
1172             rampElement2 = rampElements.new(0.366)
1173             rampElement2.color = [0.288,0.135,0.006242,0.87]
1174             rampElement3 = rampElements.new(0.608)
1175             rampElement3.color = [0.247,0.113,0.006472,0.8]
1176             rampElement4 = rampElements.new(0.828)
1177             rampElement4.color = [0.253,0.09919,0.01242,0.64]
1178     
1179 # add texture to material
1180             MTex = furMaterial.texture_slots.add()
1181             MTex.texture = furTex
1182             MTex.texture_coords = "STRAND"
1183             MTex.use_map_alpha = True  
1184             
1185             
1186 ###############Create Particles##################
1187 # Add new particle system
1188             
1189             NumberOfMaterials = 0
1190             for i in ob.data.materials:
1191                 NumberOfMaterials +=1
1192             
1193             
1194             bpy.ops.object.particle_system_add()
1195 #Particle settings setting it up!
1196             furParticles = bpy.context.object.particle_systems.active
1197             furParticles.name = "Fur1Par"
1198             furParticles.settings.type = "HAIR"
1199             furParticles.settings.use_advanced_hair = True
1200             furParticles.settings.count = 500
1201             furParticles.settings.normal_factor = 0.05
1202             furParticles.settings.factor_random = 0.001
1203             furParticles.settings.use_dynamic_rotation = True
1204             
1205             furParticles.settings.material = NumberOfMaterials
1206             
1207             furParticles.settings.use_strand_primitive = True
1208             furParticles.settings.use_hair_bspline = True
1209             furParticles.settings.render_step = 5
1210             furParticles.settings.length_random = 0.5
1211             furParticles.settings.draw_step = 5
1212 # children
1213             furParticles.settings.child_type = "INTERPOLATED"
1214             furParticles.settings.child_length = 0.134
1215             furParticles.settings.create_long_hair_children = True
1216             furParticles.settings.clump_factor = 0.55
1217             furParticles.settings.roughness_endpoint = 0.005
1218             furParticles.settings.roughness_end_shape = 5
1219             furParticles.settings.roughness_2 = 0.003
1220             furParticles.settings.roughness_2_size = 0.230
1221         
1222         
1223 ######################################################################
1224 ########################Dalmation Fur##########################
1225         if scene.fur_type == '1':
1226 ###############Create New Material##################
1227 # add new material
1228             furMaterial = bpy.data.materials.new('Fur2Mat')
1229             ob.data.materials.append(furMaterial)
1230             
1231 #Material settings
1232             furMaterial.preview_render_type = "HAIR"
1233             furMaterial.diffuse_color = (0.300, 0.280, 0.280)
1234             furMaterial.specular_color = (1.0, 1.0, 1.0)
1235             furMaterial.specular_intensity = 0.500
1236             furMaterial.specular_hardness = 50
1237             
1238             furMaterial.ambient = 0
1239             furMaterial.use_cubic = True
1240             furMaterial.use_transparency = True
1241             furMaterial.alpha = 0
1242             furMaterial.use_transparent_shadows = True
1243 #strand
1244             furMaterial.strand.use_blender_units = True
1245             furMaterial.strand.root_size = 0.00030
1246             furMaterial.strand.tip_size = 0.00010
1247             furMaterial.strand.size_min = 0.7
1248             furMaterial.strand.width_fade = 0.1
1249             furMaterial.strand.shape = 0.061
1250             furMaterial.strand.blend_distance = 0.001
1251             
1252             
1253 # add texture
1254             furTex = bpy.data.textures.new("Fur2Tex", type='BLEND')
1255             furTex.name = "Fur2"
1256             furTex.use_preview_alpha = True
1257             furTex.use_color_ramp = True
1258             ramp = furTex.color_ramp
1259             rampElements = ramp.elements
1260             rampElements[0].position = 0
1261             rampElements[0].color = [1.0,1.0,1.0,1.0]
1262             rampElements[1].position = 1
1263             rampElements[1].color = [1.0,1.0,1.0,0.0]
1264             rampElement1 = rampElements.new(0.116)
1265             rampElement1.color = [1.0,1.0,1.0,1.0]
1266        
1267             
1268 # add texture to material
1269             MTex = furMaterial.texture_slots.add()
1270             MTex.texture = furTex
1271             MTex.texture_coords = "STRAND"
1272             MTex.use_map_alpha = True
1273                         
1274 # add texture 2
1275             furTex = bpy.data.textures.new("Fur2bTex", type='CLOUDS')
1276             furTex.name = "Fur2b"
1277             furTex.use_preview_alpha = False
1278             furTex.cloud_type = "COLOR"
1279             furTex.noise_type = "HARD_NOISE"
1280             furTex.noise_scale = 0.06410
1281             furTex.use_color_ramp = True
1282             ramp = furTex.color_ramp
1283             rampElements = ramp.elements
1284             rampElements[0].position = 0
1285             rampElements[0].color = [1.0,1.0,1.0, 1.0]
1286             rampElements[1].position = 1
1287             rampElements[1].color = [0.0,0.0,0.0,1.0]
1288             rampElement1 = rampElements.new(0.317)
1289             rampElement1.color = [1.0,1.0,1.0,1.0]
1290             rampElement2 = rampElements.new(0.347)
1291             rampElement2.color = [0.0,0.0,0.0,1.0]
1292             
1293 # add texture 2 to material
1294             MTex = furMaterial.texture_slots.add()
1295             MTex.texture = furTex
1296             MTex.texture_coords = "GLOBAL"
1297             MTex.use_map_alpha = True      
1298             
1299 ###############Create Particles##################
1300 # Add new particle system
1301             
1302             NumberOfMaterials = 0
1303             for i in ob.data.materials:
1304                 NumberOfMaterials +=1
1305             
1306             
1307             bpy.ops.object.particle_system_add()
1308 #Particle settings setting it up!
1309             furParticles = bpy.context.object.particle_systems.active
1310             furParticles.name = "Fur2Par"
1311             furParticles.settings.type = "HAIR"
1312             furParticles.settings.use_advanced_hair = True
1313             furParticles.settings.count = 500
1314             furParticles.settings.normal_factor = 0.05
1315             furParticles.settings.factor_random = 0.001
1316             furParticles.settings.use_dynamic_rotation = True
1317             
1318             furParticles.settings.material = NumberOfMaterials
1319             
1320             furParticles.settings.use_strand_primitive = True
1321             furParticles.settings.use_hair_bspline = True
1322             furParticles.settings.render_step = 5
1323             furParticles.settings.length_random = 0.5
1324             furParticles.settings.draw_step = 5
1325 # children
1326             furParticles.settings.child_type = "INTERPOLATED"
1327             furParticles.settings.child_length = 0.07227
1328             furParticles.settings.create_long_hair_children = True
1329             furParticles.settings.clump_factor = 0.55
1330             furParticles.settings.roughness_endpoint = 0.005
1331             furParticles.settings.roughness_end_shape = 5
1332             furParticles.settings.roughness_2 = 0.003
1333             furParticles.settings.roughness_2_size = 0.230
1334         
1335 ######################################################################
1336 ########################Spotted_fur##########################
1337         elif scene.fur_type == '2':
1338
1339 ###############Create New Material##################
1340 # add new material
1341             furMaterial = bpy.data.materials.new('Fur3Mat')
1342             ob.data.materials.append(furMaterial)
1343             
1344 #Material settings
1345             furMaterial.preview_render_type = "HAIR"
1346             furMaterial.diffuse_color = (0.300, 0.280, 0.280)
1347             furMaterial.specular_color = (1.0, 1.0, 1.0)
1348             furMaterial.specular_intensity = 0.500
1349             furMaterial.specular_hardness = 50
1350             furMaterial.use_specular_ramp = True
1351             
1352             ramp = furMaterial.specular_ramp
1353             rampElements = ramp.elements
1354             rampElements[0].position = 0
1355             rampElements[0].color = [0.0356,0.0152,0.009134,0]
1356             rampElements[1].position = 1
1357             rampElements[1].color = [0.352,0.250,0.231,1]
1358             rampElement1 = rampElements.new(0.255)
1359             rampElement1.color = [0.214,0.08244,0.0578,0.31]
1360             rampElement2 = rampElements.new(0.594)
1361             rampElement2.color = [0.296,0.143,0.0861,0.72]
1362             
1363             furMaterial.ambient = 0
1364             furMaterial.use_cubic = True
1365             furMaterial.use_transparency = True
1366             furMaterial.alpha = 0
1367             furMaterial.use_transparent_shadows = True
1368 #strand
1369             furMaterial.strand.use_blender_units = True
1370             furMaterial.strand.root_size = 0.00030
1371             furMaterial.strand.tip_size = 0.00015
1372             furMaterial.strand.size_min = 0.450
1373             furMaterial.strand.width_fade = 0.1
1374             furMaterial.strand.shape = 0.02
1375             furMaterial.strand.blend_distance = 0.001
1376             
1377             
1378 # add texture
1379             furTex = bpy.data.textures.new("Fur3Tex", type='BLEND')
1380             furTex.name = "Fur3"
1381             furTex.use_preview_alpha = True
1382             furTex.use_color_ramp = True
1383             ramp = furTex.color_ramp
1384             rampElements = ramp.elements
1385             rampElements[0].position = 0
1386             rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
1387             rampElements[1].position = 1
1388             rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
1389             rampElement1 = rampElements.new(0.111)
1390             rampElement1.color = [0.01467,0.005307,0.00316,0.65]
1391             rampElement2 = rampElements.new(0.366)
1392             rampElement2.color = [0.0272,0.01364,0.01013,0.87]
1393             rampElement3 = rampElements.new(0.608)
1394             rampElement3.color = [0.04445,0.02294,0.01729,0.8]
1395             rampElement4 = rampElements.new(0.828)
1396             rampElement4.color = [0.04092,0.0185,0.01161,0.64]
1397             
1398 # add texture to material
1399             MTex = furMaterial.texture_slots.add()
1400             MTex.texture = furTex
1401             MTex.texture_coords = "STRAND"
1402             MTex.use_map_alpha = True
1403                         
1404 # add texture 2
1405             furTex = bpy.data.textures.new("Fur3bTex", type='CLOUDS')
1406             furTex.name = "Fur3b"
1407             furTex.use_preview_alpha = True
1408             furTex.cloud_type = "COLOR"
1409             furTex.use_color_ramp = True
1410             ramp = furTex.color_ramp
1411             rampElements = ramp.elements
1412             rampElements[0].position = 0
1413             rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
1414             rampElements[1].position = 1
1415             rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
1416             rampElement1 = rampElements.new(0.111)
1417             rampElement1.color = [0.01467,0.005307,0.00316,0.65]
1418             rampElement2 = rampElements.new(0.366)
1419             rampElement2.color = [0.0272,0.01364,0.01013,0.87]
1420             rampElement3 = rampElements.new(0.608)
1421             rampElement3.color = [0.04445,0.02294,0.01729,0.8]
1422             rampElement4 = rampElements.new(0.828)
1423             rampElement4.color = [0.04092,0.0185,0.01161,0.64]
1424             
1425 # add texture 2 to material
1426             MTex = furMaterial.texture_slots.add()
1427             MTex.texture = furTex
1428             MTex.texture_coords = "GLOBAL"
1429             MTex.use_map_alpha = False      
1430             
1431 ###############Create Particles##################
1432 # Add new particle system
1433             
1434             NumberOfMaterials = 0
1435             for i in ob.data.materials:
1436                 NumberOfMaterials +=1
1437             
1438             
1439             bpy.ops.object.particle_system_add()
1440 #Particle settings setting it up!
1441             furParticles = bpy.context.object.particle_systems.active
1442             furParticles.name = "Fur3Par"
1443             furParticles.settings.type = "HAIR"
1444             furParticles.settings.use_advanced_hair = True
1445             furParticles.settings.count = 500
1446             furParticles.settings.normal_factor = 0.05
1447             furParticles.settings.factor_random = 0.001
1448             furParticles.settings.use_dynamic_rotation = True
1449             
1450             furParticles.settings.material = NumberOfMaterials
1451             
1452             furParticles.settings.use_strand_primitive = True
1453             furParticles.settings.use_hair_bspline = True
1454             furParticles.settings.render_step = 5
1455             furParticles.settings.length_random = 0.5
1456             furParticles.settings.draw_step = 5
1457 # children
1458             furParticles.settings.child_type = "INTERPOLATED"
1459             furParticles.settings.child_length = 0.134
1460             furParticles.settings.create_long_hair_children = True
1461             furParticles.settings.clump_factor = 0.55
1462             furParticles.settings.roughness_endpoint = 0.005
1463             furParticles.settings.roughness_end_shape = 5
1464             furParticles.settings.roughness_2 = 0.003
1465             furParticles.settings.roughness_2_size = 0.230
1466         
1467         return {'FINISHED'}
1468 def register():
1469     bpy.utils.register_module(__name__)
1470     bpy.types.Scene.grass_type = EnumProperty(
1471         name="Type",
1472         description="Select the type of grass",
1473         items=[("0","Green Grass","Generate particle grass"),
1474                ("1","Grassy Field","Generate particle grass"),
1475                ("2","Clumpy Grass","Generate particle grass"),
1476         
1477               ],
1478         default='0')
1479     bpy.types.Scene.hair_type = EnumProperty(
1480         name="Type",
1481         description="Select the type of hair",
1482         items=[("0","Long Red Straight Hair","Generate particle Hair"),
1483                ("1","Long Brown Curl Hair","Generate particle Hair"),
1484                ("2","Short Dark Hair","Generate particle Hair"),
1485         
1486               ],
1487         default='0')
1488     bpy.types.Scene.fur_type = EnumProperty(
1489         name="Type",
1490         description="Select the type of fur",
1491         items=[("0","Short Fur","Generate particle Fur"),
1492                ("1","Dalmation","Generate particle Fur"),
1493                ("2","Fur3","Generate particle Fur"),
1494         
1495               ],
1496         default='0')
1497         
1498 def unregister():
1499     bpy.utils.unregister_module(__name__)
1500     del bpy.types.Scene.hair_type
1501     
1502 if __name__ == "__main__":
1503     register()
1504     
1505     
1506