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