Fix for access of undefined ground object in UI code giving pointless
[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, 71, 0),
24     "location": "View3D > ToolShelf > Addons Tab",
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://developer.blender.org/T30238",
29     "category": "Object"}
30
31
32 import bpy
33 from bpy.props import *
34
35 # Returns the action we want to take
36 def getActionToDo(obj):
37     if not obj or obj.type != 'MESH':
38         return 'NOT_OBJ_DO_NOTHING'
39     elif obj.type == 'MESH':
40         return 'GENERATE'
41     else:
42         return "DO_NOTHING"
43
44 # TO DO
45 """
46 class saveSelectionPanel(bpy.types.Panel):
47     bl_space_type = 'VIEW_3D'
48     bl_region_type = 'TOOLS'
49
50     bl_label = "Selection Save"
51     bl_options = {'DEFAULT_CLOSED'}
52     bl_context = "particlemode"
53
54
55     def draw(self, context):
56         layout = self.layout
57         col = layout.column(align=True)
58
59         col.operator("save.selection", text="Save Selection 1")
60 """
61 ######GRASS########################
62 class grassLabPanel(bpy.types.Panel):
63     bl_space_type = 'VIEW_3D'
64     bl_region_type = 'TOOLS'
65     bl_label = "Grass Lab"
66     bl_context = "objectmode"
67     bl_options = {'DEFAULT_CLOSED'}
68     bl_category = "Addons"
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     bl_category = "Addons"
530
531     def draw(self, context):
532         active_obj = bpy.context.active_object
533         active_scn = bpy.context.scene.name
534         layout = self.layout
535         col = layout.column(align=True)
536
537         WhatToDo = getActionToDo(active_obj)
538
539
540         if WhatToDo == "GENERATE":
541             col.operator("hair.generate_hair", text="Create Hair")
542
543             col.prop(context.scene, "hair_type")
544         else:
545             col.label(text="Select mesh object")
546
547         if active_scn == "TestHairScene":
548             col.operator("hair.switch_back", text="Switch back to scene")
549         else:
550             col.operator("hair.test_scene", text="Create Test Scene")
551
552 # TO DO
553 """
554 class saveSelection(bpy.types.Operator):
555     bl_idname = "save.selection"
556     bl_label = "Save Selection"
557     bl_description = "Save selected particles"
558     bl_register = True
559     bl_undo = True
560
561     def execute(self, context):
562
563         return {'FINISHED'}
564 """
565 class testScene3(bpy.types.Operator):
566     bl_idname = "hair.switch_back"
567     bl_label = "Switch back to scene"
568     bl_description = "If you want keep this scene, switch scene in info window"
569     bl_register = True
570     bl_undo = True
571
572     def execute(self, context):
573         scene = bpy.context.scene
574         bpy.data.scenes.remove(scene)
575
576         return {'FINISHED'}
577
578
579 class testScene4(bpy.types.Operator):
580     bl_idname = "hair.test_scene"
581     bl_label = "Create test scene"
582     bl_description = "You can switch scene in info panel"
583     bl_register = True
584     bl_undo = True
585
586     def execute(self, context):
587 # add new scene
588         bpy.ops.scene.new(type="NEW")
589         scene = bpy.context.scene
590         scene.name = "TestHairScene"
591 # render settings
592         render = scene.render
593         render.resolution_x = 1920
594         render.resolution_y = 1080
595         render.resolution_percentage = 50
596 # add new world
597         world = bpy.data.worlds.new("HairWorld")
598         scene.world = world
599         world.use_sky_blend = True
600         world.use_sky_paper = True
601         world.horizon_color = (0.004393,0.02121,0.050)
602         world.zenith_color = (0.03335,0.227,0.359)
603
604 # add text
605         bpy.ops.object.text_add(location=(-0.292,0,-0.152), rotation =(1.571,0,0))
606         text = bpy.context.active_object
607         text.scale = (0.05,0.05,0.05)
608         text.data.body = "Hair Lab"
609
610 # add material to text
611         textMaterial = bpy.data.materials.new('textMaterial')
612         text.data.materials.append(textMaterial)
613         textMaterial.use_shadeless = True
614
615 # add camera
616         bpy.ops.object.camera_add(location = (0,-1,0),rotation = (1.571,0,0))
617         cam = bpy.context.active_object.data
618         cam.lens = 50
619         cam.draw_size = 0.1
620
621 # add spot lamp
622         bpy.ops.object.lamp_add(type="SPOT", location = (-0.7,-0.5,0.3), rotation =(1.223,0,-0.960))
623         lamp1 = bpy.context.active_object.data
624         lamp1.name = "Key Light"
625         lamp1.energy = 1.5
626         lamp1.distance = 1.5
627         lamp1.shadow_buffer_soft = 5
628         lamp1.shadow_buffer_size = 8192
629         lamp1.shadow_buffer_clip_end = 1.5
630         lamp1.spot_blend = 0.5
631
632 # add spot lamp2
633         bpy.ops.object.lamp_add(type="SPOT", location = (0.7,-0.6,0.1), rotation =(1.571,0,0.785))
634         lamp2 = bpy.context.active_object.data
635         lamp2.name = "Fill Light"
636         lamp2.color = (0.874,0.874,1)
637         lamp2.energy = 0.5
638         lamp2.distance = 1.5
639         lamp2.shadow_buffer_soft = 5
640         lamp2.shadow_buffer_size = 4096
641         lamp2.shadow_buffer_clip_end = 1.5
642         lamp2.spot_blend = 0.5
643
644 # light Rim
645         """
646         # add spot lamp3
647         bpy.ops.object.lamp_add(type="SPOT", location = (0.191,0.714,0.689), rotation =(0.891,0,2.884))
648         lamp3 = bpy.context.active_object.data
649         lamp3.name = "Rim Light"
650         lamp3.color = (0.194,0.477,1)
651         lamp3.energy = 3
652         lamp3.distance = 1.5
653         lamp3.shadow_buffer_soft = 5
654         lamp3.shadow_buffer_size = 4096
655         lamp3.shadow_buffer_clip_end = 1.5
656         lamp3.spot_blend = 0.5
657         """
658 # add sphere
659         bpy.ops.mesh.primitive_uv_sphere_add(size=0.1)
660         bpy.ops.object.shade_smooth()
661         return {'FINISHED'}
662
663
664 class GenerateHair(bpy.types.Operator):
665     bl_idname = "hair.generate_hair"
666     bl_label = "Generate Hair"
667     bl_description = "Create a Hair"
668     bl_register = True
669     bl_undo = True
670
671     def execute(self, context):
672 # Make variable that is the current .blend file main data blocks
673         blend_data = context.blend_data
674         ob = bpy.context.active_object
675         scene = context.scene
676
677 ######################################################################
678 ########################Long Red Straight Hair########################
679         if scene.hair_type == '0':
680
681 ###############Create New Material##################
682 # add new material
683             hairMaterial = bpy.data.materials.new('LongRedStraightHairMat')
684             ob.data.materials.append(hairMaterial)
685
686 #Material settings
687             hairMaterial.preview_render_type = "HAIR"
688             hairMaterial.diffuse_color = (0.287, 0.216, 0.04667)
689             hairMaterial.specular_color = (0.604, 0.465, 0.136)
690             hairMaterial.specular_intensity = 0.3
691             hairMaterial.ambient = 0
692             hairMaterial.use_cubic = True
693             hairMaterial.use_transparency = True
694             hairMaterial.alpha = 0
695             hairMaterial.use_transparent_shadows = True
696 #strand
697             hairMaterial.strand.use_blender_units = True
698             hairMaterial.strand.root_size = 0.00030
699             hairMaterial.strand.tip_size = 0.00010
700             hairMaterial.strand.size_min = 0.7
701             hairMaterial.strand.width_fade = 0.1
702             hairMaterial.strand.shape = 0.061
703             hairMaterial.strand.blend_distance = 0.001
704
705
706 # add texture
707             hairTex = bpy.data.textures.new("LongRedStraightHairTex", type='BLEND')
708             hairTex.use_preview_alpha = True
709             hairTex.use_color_ramp = True
710             ramp = hairTex.color_ramp
711             rampElements = ramp.elements
712             rampElements[0].position = 0
713             rampElements[0].color = [0.114,0.05613,0.004025,0.38]
714             rampElements[1].position = 1
715             rampElements[1].color = [0.267,0.155,0.02687,0]
716             rampElement1 = rampElements.new(0.111)
717             rampElement1.color = [0.281,0.168,0.03157,0.65]
718             rampElement2 = rampElements.new(0.366)
719             rampElement2.color = [0.288,0.135,0.006242,0.87]
720             rampElement3 = rampElements.new(0.608)
721             rampElement3.color = [0.247,0.113,0.006472,0.8]
722             rampElement4 = rampElements.new(0.828)
723             rampElement4.color = [0.253,0.09919,0.01242,0.64]
724
725 # add texture to material
726             MTex = hairMaterial.texture_slots.add()
727             MTex.texture = hairTex
728             MTex.texture_coords = "STRAND"
729             MTex.use_map_alpha = True
730
731
732
733 ###############Create Particles##################
734 # Add new particle system
735
736             NumberOfMaterials = 0
737             for i in ob.data.materials:
738                 NumberOfMaterials +=1
739
740
741             bpy.ops.object.particle_system_add()
742 #Particle settings setting it up!
743             hairParticles = bpy.context.object.particle_systems.active
744             hairParticles.name = "LongRedStraightHairPar"
745             hairParticles.settings.type = "HAIR"
746             hairParticles.settings.use_advanced_hair = True
747             hairParticles.settings.count = 500
748             hairParticles.settings.normal_factor = 0.05
749             hairParticles.settings.factor_random = 0.001
750             hairParticles.settings.use_dynamic_rotation = True
751
752             hairParticles.settings.material = NumberOfMaterials
753
754             hairParticles.settings.use_strand_primitive = True
755             hairParticles.settings.use_hair_bspline = True
756             hairParticles.settings.render_step = 5
757             hairParticles.settings.length_random = 0.5
758             hairParticles.settings.draw_step = 5
759 # children
760             hairParticles.settings.child_type = "INTERPOLATED"
761             hairParticles.settings.create_long_hair_children = True
762             hairParticles.settings.clump_factor = 0.55
763             hairParticles.settings.roughness_endpoint = 0.005
764             hairParticles.settings.roughness_end_shape = 5
765             hairParticles.settings.roughness_2 = 0.003
766             hairParticles.settings.roughness_2_size = 0.230
767
768
769 ######################################################################
770 ########################Long Brown Curl Hair##########################
771         if scene.hair_type == '1':
772 ###############Create New Material##################
773 # add new material
774             hairMaterial = bpy.data.materials.new('LongBrownCurlHairMat')
775             ob.data.materials.append(hairMaterial)
776
777 #Material settings
778             hairMaterial.preview_render_type = "HAIR"
779             hairMaterial.diffuse_color = (0.662, 0.518, 0.458)
780             hairMaterial.specular_color = (0.351, 0.249, 0.230)
781             hairMaterial.specular_intensity = 0.3
782             hairMaterial.specular_hardness = 100
783             hairMaterial.use_specular_ramp = True
784
785             ramp = hairMaterial.specular_ramp
786             rampElements = ramp.elements
787             rampElements[0].position = 0
788             rampElements[0].color = [0.0356,0.0152,0.009134,0]
789             rampElements[1].position = 1
790             rampElements[1].color = [0.352,0.250,0.231,1]
791             rampElement1 = rampElements.new(0.255)
792             rampElement1.color = [0.214,0.08244,0.0578,0.31]
793             rampElement2 = rampElements.new(0.594)
794             rampElement2.color = [0.296,0.143,0.0861,0.72]
795
796             hairMaterial.ambient = 0
797             hairMaterial.use_cubic = True
798             hairMaterial.use_transparency = True
799             hairMaterial.alpha = 0
800             hairMaterial.use_transparent_shadows = True
801 #strand
802             hairMaterial.strand.use_blender_units = True
803             hairMaterial.strand.root_size = 0.00030
804             hairMaterial.strand.tip_size = 0.00015
805             hairMaterial.strand.size_min = 0.450
806             hairMaterial.strand.width_fade = 0.1
807             hairMaterial.strand.shape = 0.02
808             hairMaterial.strand.blend_distance = 0.001
809
810
811 # add texture
812             hairTex = bpy.data.textures.new("HairTex", type='BLEND')
813             hairTex.name = "LongBrownCurlHairTex"
814             hairTex.use_preview_alpha = True
815             hairTex.use_color_ramp = True
816             ramp = hairTex.color_ramp
817             rampElements = ramp.elements
818             rampElements[0].position = 0
819             rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
820             rampElements[1].position = 1
821             rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
822             rampElement1 = rampElements.new(0.111)
823             rampElement1.color = [0.01467,0.005307,0.00316,0.65]
824             rampElement2 = rampElements.new(0.366)
825             rampElement2.color = [0.0272,0.01364,0.01013,0.87]
826             rampElement3 = rampElements.new(0.608)
827             rampElement3.color = [0.04445,0.02294,0.01729,0.8]
828             rampElement4 = rampElements.new(0.828)
829             rampElement4.color = [0.04092,0.0185,0.01161,0.64]
830
831 # add texture to material
832             MTex = hairMaterial.texture_slots.add()
833             MTex.texture = hairTex
834             MTex.texture_coords = "STRAND"
835             MTex.use_map_alpha = True
836
837
838 ###############Create Particles##################
839 # Add new particle system
840
841             NumberOfMaterials = 0
842             for i in ob.data.materials:
843                 NumberOfMaterials +=1
844
845
846             bpy.ops.object.particle_system_add()
847 #Particle settings setting it up!
848             hairParticles = bpy.context.object.particle_systems.active
849             hairParticles.name = "LongBrownCurlHairPar"
850             hairParticles.settings.type = "HAIR"
851             hairParticles.settings.use_advanced_hair = True
852             hairParticles.settings.count = 500
853             hairParticles.settings.normal_factor = 0.05
854             hairParticles.settings.factor_random = 0.001
855             hairParticles.settings.use_dynamic_rotation = True
856
857             hairParticles.settings.material = NumberOfMaterials
858
859             hairParticles.settings.use_strand_primitive = True
860             hairParticles.settings.use_hair_bspline = True
861             hairParticles.settings.render_step = 7
862             hairParticles.settings.length_random = 0.5
863             hairParticles.settings.draw_step = 5
864 # children
865             hairParticles.settings.child_type = "INTERPOLATED"
866             hairParticles.settings.create_long_hair_children = True
867             hairParticles.settings.clump_factor = 0.523
868             hairParticles.settings.clump_shape = 0.383
869             hairParticles.settings.roughness_endpoint = 0.002
870             hairParticles.settings.roughness_end_shape = 5
871             hairParticles.settings.roughness_2 = 0.003
872             hairParticles.settings.roughness_2_size = 2
873
874             hairParticles.settings.kink = "CURL"
875             hairParticles.settings.kink_amplitude = 0.007597
876             hairParticles.settings.kink_frequency = 6
877             hairParticles.settings.kink_shape = 0.4
878             hairParticles.settings.kink_flat = 0.8
879
880
881 ######################################################################
882 ########################Short Dark Hair##########################
883         elif scene.hair_type == '2':
884 ###############Create New Material##################
885 # add new material
886             hairMaterial = bpy.data.materials.new('ShortDarkHairMat')
887             ob.data.materials.append(hairMaterial)
888
889 #Material settings
890             hairMaterial.preview_render_type = "HAIR"
891             hairMaterial.diffuse_color = (0.560, 0.536, 0.506)
892             hairMaterial.specular_color = (0.196, 0.177, 0.162)
893             hairMaterial.specular_intensity = 0.5
894             hairMaterial.specular_hardness = 100
895             hairMaterial.ambient = 0
896             hairMaterial.use_cubic = True
897             hairMaterial.use_transparency = True
898             hairMaterial.alpha = 0
899             hairMaterial.use_transparent_shadows = True
900 #strand
901             hairMaterial.strand.use_blender_units = True
902             hairMaterial.strand.root_size = 0.0002
903             hairMaterial.strand.tip_size = 0.0001
904             hairMaterial.strand.size_min = 0.3
905             hairMaterial.strand.width_fade = 0.1
906             hairMaterial.strand.shape = 0
907             hairMaterial.strand.blend_distance = 0.001
908
909 # add texture
910             hairTex = bpy.data.textures.new("ShortDarkHair", type='BLEND')
911             hairTex.use_preview_alpha = True
912             hairTex.use_color_ramp = True
913             ramp = hairTex.color_ramp
914             rampElements = ramp.elements
915             rampElements[0].position = 0
916             rampElements[0].color = [0.004025,0.002732,0.002428,0.38]
917             rampElements[1].position = 1
918             rampElements[1].color = [0.141,0.122,0.107,0.2]
919             rampElement1 = rampElements.new(0.202)
920             rampElement1.color = [0.01885,0.0177,0.01827,0.65]
921             rampElement2 = rampElements.new(0.499)
922             rampElement2.color = [0.114,0.109,0.09822,0.87]
923             rampElement3 = rampElements.new(0.828)
924             rampElement3.color = [0.141,0.127,0.117,0.64]
925
926 # add texture to material
927             MTex = hairMaterial.texture_slots.add()
928             MTex.texture = hairTex
929             MTex.texture_coords = "STRAND"
930             MTex.use_map_alpha = True
931
932
933 ###############Create Particles##################
934 # Add new particle system
935
936             NumberOfMaterials = 0
937             for i in ob.data.materials:
938                 NumberOfMaterials +=1
939
940
941             bpy.ops.object.particle_system_add()
942 #Particle settings setting it up!
943             hairParticles = bpy.context.object.particle_systems.active
944             hairParticles.name = "ShortDarkHair"
945             hairParticles.settings.type = "HAIR"
946             hairParticles.settings.use_advanced_hair = True
947             hairParticles.settings.hair_step = 2
948             hairParticles.settings.count = 450
949             hairParticles.settings.normal_factor = 0.007
950             hairParticles.settings.factor_random = 0.001
951             hairParticles.settings.use_dynamic_rotation = True
952
953             hairParticles.settings.material = NumberOfMaterials
954
955             hairParticles.settings.use_strand_primitive = True
956             hairParticles.settings.use_hair_bspline = True
957             hairParticles.settings.render_step = 3
958             hairParticles.settings.length_random = 0.3
959             hairParticles.settings.draw_step = 3
960 # children
961             hairParticles.settings.child_type = "INTERPOLATED"
962             hairParticles.settings.rendered_child_count = 200
963             hairParticles.settings.virtual_parents = 1
964             hairParticles.settings.clump_factor = 0.425
965             hairParticles.settings.clump_shape = 0.1
966             hairParticles.settings.roughness_endpoint = 0.003
967             hairParticles.settings.roughness_end_shape = 5
968
969
970
971         return {'FINISHED'}
972 ####
973 ######## FUR LAB ########
974 ####
975
976 class FurLabPanel(bpy.types.Panel):
977     bl_space_type = 'VIEW_3D'
978     bl_region_type = 'TOOLS'
979     bl_label = "Fur Lab"
980     bl_context = "objectmode"
981     bl_options = {'DEFAULT_CLOSED'}
982     bl_category = "Addons"
983
984     def draw(self, context):
985         active_obj = bpy.context.active_object
986         active_scn = bpy.context.scene.name
987         layout = self.layout
988         col = layout.column(align=True)
989
990         WhatToDo = getActionToDo(active_obj)
991
992
993         if WhatToDo == "GENERATE":
994             col.operator("fur.generate_fur", text="Create Fur")
995
996             col.prop(context.scene, "fur_type")
997         else:
998             col.label(text="Select mesh object")
999
1000         if active_scn == "TestFurScene":
1001             col.operator("hair.switch_back", text="Switch back to scene")
1002         else:
1003             col.operator("fur.test_scene", text="Create Test Scene")
1004
1005 # TO DO
1006 """
1007 class saveSelection(bpy.types.Operator):
1008     bl_idname = "save.selection"
1009     bl_label = "Save Selection"
1010     bl_description = "Save selected particles"
1011     bl_register = True
1012     bl_undo = True
1013
1014     def execute(self, context):
1015
1016         return {'FINISHED'}
1017 """
1018 class testScene5(bpy.types.Operator):
1019     bl_idname = "fur.switch_back"
1020     bl_label = "Switch back to scene"
1021     bl_description = "If you want keep this scene, switch scene in info window"
1022     bl_register = True
1023     bl_undo = True
1024
1025     def execute(self, context):
1026         scene = bpy.context.scene
1027         bpy.data.scenes.remove(scene)
1028
1029         return {'FINISHED'}
1030
1031
1032 class testScene6(bpy.types.Operator):
1033     bl_idname = "fur.test_scene"
1034     bl_label = "Create test scene"
1035     bl_description = "You can switch scene in info panel"
1036     bl_register = True
1037     bl_undo = True
1038
1039     def execute(self, context):
1040 # add new scene
1041         bpy.ops.scene.new(type="NEW")
1042         scene = bpy.context.scene
1043         scene.name = "TestFurScene"
1044 # render settings
1045         render = scene.render
1046         render.resolution_x = 1920
1047         render.resolution_y = 1080
1048         render.resolution_percentage = 50
1049 # add new world
1050         world = bpy.data.worlds.new("FurWorld")
1051         scene.world = world
1052         world.use_sky_blend = True
1053         world.use_sky_paper = True
1054         world.horizon_color = (0.004393,0.02121,0.050)
1055         world.zenith_color = (0.03335,0.227,0.359)
1056
1057 # add text
1058         bpy.ops.object.text_add(location=(-0.292,0,-0.152), rotation =(1.571,0,0))
1059         text = bpy.context.active_object
1060         text.scale = (0.05,0.05,0.05)
1061         text.data.body = "Fur Lab"
1062
1063 # add material to text
1064         textMaterial = bpy.data.materials.new('textMaterial')
1065         text.data.materials.append(textMaterial)
1066         textMaterial.use_shadeless = True
1067
1068 # add camera
1069         bpy.ops.object.camera_add(location = (0,-1,0),rotation = (1.571,0,0))
1070         cam = bpy.context.active_object.data
1071         cam.lens = 50
1072         cam.draw_size = 0.1
1073
1074 # add spot lamp
1075         bpy.ops.object.lamp_add(type="SPOT", location = (-0.7,-0.5,0.3), rotation =(1.223,0,-0.960))
1076         lamp1 = bpy.context.active_object.data
1077         lamp1.name = "Key Light"
1078         lamp1.energy = 1.5
1079         lamp1.distance = 1.5
1080         lamp1.shadow_buffer_soft = 5
1081         lamp1.shadow_buffer_size = 8192
1082         lamp1.shadow_buffer_clip_end = 1.5
1083         lamp1.spot_blend = 0.5
1084
1085 # add spot lamp2
1086         bpy.ops.object.lamp_add(type="SPOT", location = (0.7,-0.6,0.1), rotation =(1.571,0,0.785))
1087         lamp2 = bpy.context.active_object.data
1088         lamp2.name = "Fill Light"
1089         lamp2.color = (0.874,0.874,1)
1090         lamp2.energy = 0.5
1091         lamp2.distance = 1.5
1092         lamp2.shadow_buffer_soft = 5
1093         lamp2.shadow_buffer_size = 4096
1094         lamp2.shadow_buffer_clip_end = 1.5
1095         lamp2.spot_blend = 0.5
1096
1097 # light Rim
1098         """
1099         # add spot lamp3
1100         bpy.ops.object.lamp_add(type="SPOT", location = (0.191,0.714,0.689), rotation =(0.891,0,2.884))
1101         lamp3 = bpy.context.active_object.data
1102         lamp3.name = "Rim Light"
1103         lamp3.color = (0.194,0.477,1)
1104         lamp3.energy = 3
1105         lamp3.distance = 1.5
1106         lamp3.shadow_buffer_soft = 5
1107         lamp3.shadow_buffer_size = 4096
1108         lamp3.shadow_buffer_clip_end = 1.5
1109         lamp3.spot_blend = 0.5
1110         """
1111 # add sphere
1112         bpy.ops.mesh.primitive_uv_sphere_add(size=0.1)
1113         bpy.ops.object.shade_smooth()
1114         return {'FINISHED'}
1115
1116
1117 class GenerateFur(bpy.types.Operator):
1118     bl_idname = "fur.generate_fur"
1119     bl_label = "Generate Fur"
1120     bl_description = "Create a Fur"
1121     bl_register = True
1122     bl_undo = True
1123
1124     def execute(self, context):
1125 # Make variable that is the current .blend file main data blocks
1126         blend_data = context.blend_data
1127         ob = bpy.context.active_object
1128         scene = context.scene
1129
1130 ######################################################################
1131 ########################Short Fur########################
1132         if scene.fur_type == '0':
1133
1134 ###############Create New Material##################
1135 # add new material
1136             furMaterial = bpy.data.materials.new('Fur 1')
1137             ob.data.materials.append(furMaterial)
1138
1139 #Material settings
1140             furMaterial.preview_render_type = "HAIR"
1141             furMaterial.diffuse_color = (0.287, 0.216, 0.04667)
1142             furMaterial.specular_color = (0.604, 0.465, 0.136)
1143             furMaterial.specular_intensity = 0.3
1144             furMaterial.ambient = 0
1145             furMaterial.use_cubic = True
1146             furMaterial.use_transparency = True
1147             furMaterial.alpha = 0
1148             furMaterial.use_transparent_shadows = True
1149 #strand
1150             furMaterial.strand.use_blender_units = True
1151             furMaterial.strand.root_size = 0.00030
1152             furMaterial.strand.tip_size = 0.00010
1153             furMaterial.strand.size_min = 0.7
1154             furMaterial.strand.width_fade = 0.1
1155             furMaterial.strand.shape = 0.061
1156             furMaterial.strand.blend_distance = 0.001
1157
1158
1159 # add texture
1160             furTex = bpy.data.textures.new("Fur1Tex", type='BLEND')
1161             furTex.use_preview_alpha = True
1162             furTex.use_color_ramp = True
1163             ramp = furTex.color_ramp
1164             rampElements = ramp.elements
1165             rampElements[0].position = 0
1166             rampElements[0].color = [0.114,0.05613,0.004025,0.38]
1167             rampElements[1].position = 1
1168             rampElements[1].color = [0.267,0.155,0.02687,0]
1169             rampElement1 = rampElements.new(0.111)
1170             rampElement1.color = [0.281,0.168,0.03157,0.65]
1171             rampElement2 = rampElements.new(0.366)
1172             rampElement2.color = [0.288,0.135,0.006242,0.87]
1173             rampElement3 = rampElements.new(0.608)
1174             rampElement3.color = [0.247,0.113,0.006472,0.8]
1175             rampElement4 = rampElements.new(0.828)
1176             rampElement4.color = [0.253,0.09919,0.01242,0.64]
1177
1178 # add texture to material
1179             MTex = furMaterial.texture_slots.add()
1180             MTex.texture = furTex
1181             MTex.texture_coords = "STRAND"
1182             MTex.use_map_alpha = True
1183
1184
1185 ###############Create Particles##################
1186 # Add new particle system
1187
1188             NumberOfMaterials = 0
1189             for i in ob.data.materials:
1190                 NumberOfMaterials +=1
1191
1192
1193             bpy.ops.object.particle_system_add()
1194 #Particle settings setting it up!
1195             furParticles = bpy.context.object.particle_systems.active
1196             furParticles.name = "Fur1Par"
1197             furParticles.settings.type = "HAIR"
1198             furParticles.settings.use_advanced_hair = True
1199             furParticles.settings.count = 500
1200             furParticles.settings.normal_factor = 0.05
1201             furParticles.settings.factor_random = 0.001
1202             furParticles.settings.use_dynamic_rotation = True
1203
1204             furParticles.settings.material = NumberOfMaterials
1205
1206             furParticles.settings.use_strand_primitive = True
1207             furParticles.settings.use_hair_bspline = True
1208             furParticles.settings.render_step = 5
1209             furParticles.settings.length_random = 0.5
1210             furParticles.settings.draw_step = 5
1211 # children
1212             furParticles.settings.child_type = "INTERPOLATED"
1213             furParticles.settings.child_length = 0.134
1214             furParticles.settings.create_long_hair_children = True
1215             furParticles.settings.clump_factor = 0.55
1216             furParticles.settings.roughness_endpoint = 0.005
1217             furParticles.settings.roughness_end_shape = 5
1218             furParticles.settings.roughness_2 = 0.003
1219             furParticles.settings.roughness_2_size = 0.230
1220
1221
1222 ######################################################################
1223 ########################Dalmation Fur##########################
1224         if scene.fur_type == '1':
1225 ###############Create New Material##################
1226 # add new material
1227             furMaterial = bpy.data.materials.new('Fur2Mat')
1228             ob.data.materials.append(furMaterial)
1229
1230 #Material settings
1231             furMaterial.preview_render_type = "HAIR"
1232             furMaterial.diffuse_color = (0.300, 0.280, 0.280)
1233             furMaterial.specular_color = (1.0, 1.0, 1.0)
1234             furMaterial.specular_intensity = 0.500
1235             furMaterial.specular_hardness = 50
1236
1237             furMaterial.ambient = 0
1238             furMaterial.use_cubic = True
1239             furMaterial.use_transparency = True
1240             furMaterial.alpha = 0
1241             furMaterial.use_transparent_shadows = True
1242 #strand
1243             furMaterial.strand.use_blender_units = True
1244             furMaterial.strand.root_size = 0.00030
1245             furMaterial.strand.tip_size = 0.00010
1246             furMaterial.strand.size_min = 0.7
1247             furMaterial.strand.width_fade = 0.1
1248             furMaterial.strand.shape = 0.061
1249             furMaterial.strand.blend_distance = 0.001
1250
1251
1252 # add texture
1253             furTex = bpy.data.textures.new("Fur2Tex", type='BLEND')
1254             furTex.name = "Fur2"
1255             furTex.use_preview_alpha = True
1256             furTex.use_color_ramp = True
1257             ramp = furTex.color_ramp
1258             rampElements = ramp.elements
1259             rampElements[0].position = 0
1260             rampElements[0].color = [1.0,1.0,1.0,1.0]
1261             rampElements[1].position = 1
1262             rampElements[1].color = [1.0,1.0,1.0,0.0]
1263             rampElement1 = rampElements.new(0.116)
1264             rampElement1.color = [1.0,1.0,1.0,1.0]
1265
1266
1267 # add texture to material
1268             MTex = furMaterial.texture_slots.add()
1269             MTex.texture = furTex
1270             MTex.texture_coords = "STRAND"
1271             MTex.use_map_alpha = True
1272
1273 # add texture 2
1274             furTex = bpy.data.textures.new("Fur2bTex", type='CLOUDS')
1275             furTex.name = "Fur2b"
1276             furTex.use_preview_alpha = False
1277             furTex.cloud_type = "COLOR"
1278             furTex.noise_type = "HARD_NOISE"
1279             furTex.noise_scale = 0.06410
1280             furTex.use_color_ramp = True
1281             ramp = furTex.color_ramp
1282             rampElements = ramp.elements
1283             rampElements[0].position = 0
1284             rampElements[0].color = [1.0,1.0,1.0, 1.0]
1285             rampElements[1].position = 1
1286             rampElements[1].color = [0.0,0.0,0.0,1.0]
1287             rampElement1 = rampElements.new(0.317)
1288             rampElement1.color = [1.0,1.0,1.0,1.0]
1289             rampElement2 = rampElements.new(0.347)
1290             rampElement2.color = [0.0,0.0,0.0,1.0]
1291
1292 # add texture 2 to material
1293             MTex = furMaterial.texture_slots.add()
1294             MTex.texture = furTex
1295             MTex.texture_coords = "GLOBAL"
1296             MTex.use_map_alpha = True
1297
1298 ###############Create Particles##################
1299 # Add new particle system
1300
1301             NumberOfMaterials = 0
1302             for i in ob.data.materials:
1303                 NumberOfMaterials +=1
1304
1305
1306             bpy.ops.object.particle_system_add()
1307 #Particle settings setting it up!
1308             furParticles = bpy.context.object.particle_systems.active
1309             furParticles.name = "Fur2Par"
1310             furParticles.settings.type = "HAIR"
1311             furParticles.settings.use_advanced_hair = True
1312             furParticles.settings.count = 500
1313             furParticles.settings.normal_factor = 0.05
1314             furParticles.settings.factor_random = 0.001
1315             furParticles.settings.use_dynamic_rotation = True
1316
1317             furParticles.settings.material = NumberOfMaterials
1318
1319             furParticles.settings.use_strand_primitive = True
1320             furParticles.settings.use_hair_bspline = True
1321             furParticles.settings.render_step = 5
1322             furParticles.settings.length_random = 0.5
1323             furParticles.settings.draw_step = 5
1324 # children
1325             furParticles.settings.child_type = "INTERPOLATED"
1326             furParticles.settings.child_length = 0.07227
1327             furParticles.settings.create_long_hair_children = True
1328             furParticles.settings.clump_factor = 0.55
1329             furParticles.settings.roughness_endpoint = 0.005
1330             furParticles.settings.roughness_end_shape = 5
1331             furParticles.settings.roughness_2 = 0.003
1332             furParticles.settings.roughness_2_size = 0.230
1333
1334 ######################################################################
1335 ########################Spotted_fur##########################
1336         elif scene.fur_type == '2':
1337
1338 ###############Create New Material##################
1339 # add new material
1340             furMaterial = bpy.data.materials.new('Fur3Mat')
1341             ob.data.materials.append(furMaterial)
1342
1343 #Material settings
1344             furMaterial.preview_render_type = "HAIR"
1345             furMaterial.diffuse_color = (0.300, 0.280, 0.280)
1346             furMaterial.specular_color = (1.0, 1.0, 1.0)
1347             furMaterial.specular_intensity = 0.500
1348             furMaterial.specular_hardness = 50
1349             furMaterial.use_specular_ramp = True
1350
1351             ramp = furMaterial.specular_ramp
1352             rampElements = ramp.elements
1353             rampElements[0].position = 0
1354             rampElements[0].color = [0.0356,0.0152,0.009134,0]
1355             rampElements[1].position = 1
1356             rampElements[1].color = [0.352,0.250,0.231,1]
1357             rampElement1 = rampElements.new(0.255)
1358             rampElement1.color = [0.214,0.08244,0.0578,0.31]
1359             rampElement2 = rampElements.new(0.594)
1360             rampElement2.color = [0.296,0.143,0.0861,0.72]
1361
1362             furMaterial.ambient = 0
1363             furMaterial.use_cubic = True
1364             furMaterial.use_transparency = True
1365             furMaterial.alpha = 0
1366             furMaterial.use_transparent_shadows = True
1367 #strand
1368             furMaterial.strand.use_blender_units = True
1369             furMaterial.strand.root_size = 0.00030
1370             furMaterial.strand.tip_size = 0.00015
1371             furMaterial.strand.size_min = 0.450
1372             furMaterial.strand.width_fade = 0.1
1373             furMaterial.strand.shape = 0.02
1374             furMaterial.strand.blend_distance = 0.001
1375
1376
1377 # add texture
1378             furTex = bpy.data.textures.new("Fur3Tex", type='BLEND')
1379             furTex.name = "Fur3"
1380             furTex.use_preview_alpha = True
1381             furTex.use_color_ramp = True
1382             ramp = furTex.color_ramp
1383             rampElements = ramp.elements
1384             rampElements[0].position = 0
1385             rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
1386             rampElements[1].position = 1
1387             rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
1388             rampElement1 = rampElements.new(0.111)
1389             rampElement1.color = [0.01467,0.005307,0.00316,0.65]
1390             rampElement2 = rampElements.new(0.366)
1391             rampElement2.color = [0.0272,0.01364,0.01013,0.87]
1392             rampElement3 = rampElements.new(0.608)
1393             rampElement3.color = [0.04445,0.02294,0.01729,0.8]
1394             rampElement4 = rampElements.new(0.828)
1395             rampElement4.color = [0.04092,0.0185,0.01161,0.64]
1396
1397 # add texture to material
1398             MTex = furMaterial.texture_slots.add()
1399             MTex.texture = furTex
1400             MTex.texture_coords = "STRAND"
1401             MTex.use_map_alpha = True
1402
1403 # add texture 2
1404             furTex = bpy.data.textures.new("Fur3bTex", type='CLOUDS')
1405             furTex.name = "Fur3b"
1406             furTex.use_preview_alpha = True
1407             furTex.cloud_type = "COLOR"
1408             furTex.use_color_ramp = True
1409             ramp = furTex.color_ramp
1410             rampElements = ramp.elements
1411             rampElements[0].position = 0
1412             rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
1413             rampElements[1].position = 1
1414             rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
1415             rampElement1 = rampElements.new(0.111)
1416             rampElement1.color = [0.01467,0.005307,0.00316,0.65]
1417             rampElement2 = rampElements.new(0.366)
1418             rampElement2.color = [0.0272,0.01364,0.01013,0.87]
1419             rampElement3 = rampElements.new(0.608)
1420             rampElement3.color = [0.04445,0.02294,0.01729,0.8]
1421             rampElement4 = rampElements.new(0.828)
1422             rampElement4.color = [0.04092,0.0185,0.01161,0.64]
1423
1424 # add texture 2 to material
1425             MTex = furMaterial.texture_slots.add()
1426             MTex.texture = furTex
1427             MTex.texture_coords = "GLOBAL"
1428             MTex.use_map_alpha = False
1429
1430 ###############Create Particles##################
1431 # Add new particle system
1432
1433             NumberOfMaterials = 0
1434             for i in ob.data.materials:
1435                 NumberOfMaterials +=1
1436
1437
1438             bpy.ops.object.particle_system_add()
1439 #Particle settings setting it up!
1440             furParticles = bpy.context.object.particle_systems.active
1441             furParticles.name = "Fur3Par"
1442             furParticles.settings.type = "HAIR"
1443             furParticles.settings.use_advanced_hair = True
1444             furParticles.settings.count = 500
1445             furParticles.settings.normal_factor = 0.05
1446             furParticles.settings.factor_random = 0.001
1447             furParticles.settings.use_dynamic_rotation = True
1448
1449             furParticles.settings.material = NumberOfMaterials
1450
1451             furParticles.settings.use_strand_primitive = True
1452             furParticles.settings.use_hair_bspline = True
1453             furParticles.settings.render_step = 5
1454             furParticles.settings.length_random = 0.5
1455             furParticles.settings.draw_step = 5
1456 # children
1457             furParticles.settings.child_type = "INTERPOLATED"
1458             furParticles.settings.child_length = 0.134
1459             furParticles.settings.create_long_hair_children = True
1460             furParticles.settings.clump_factor = 0.55
1461             furParticles.settings.roughness_endpoint = 0.005
1462             furParticles.settings.roughness_end_shape = 5
1463             furParticles.settings.roughness_2 = 0.003
1464             furParticles.settings.roughness_2_size = 0.230
1465
1466         return {'FINISHED'}
1467 def register():
1468     bpy.utils.register_module(__name__)
1469     bpy.types.Scene.grass_type = EnumProperty(
1470         name="Type",
1471         description="Select the type of grass",
1472         items=[("0","Green Grass","Generate particle grass"),
1473                ("1","Grassy Field","Generate particle grass"),
1474                ("2","Clumpy Grass","Generate particle grass"),
1475
1476               ],
1477         default='0')
1478     bpy.types.Scene.hair_type = EnumProperty(
1479         name="Type",
1480         description="Select the type of hair",
1481         items=[("0","Long Red Straight Hair","Generate particle Hair"),
1482                ("1","Long Brown Curl Hair","Generate particle Hair"),
1483                ("2","Short Dark Hair","Generate particle Hair"),
1484
1485               ],
1486         default='0')
1487     bpy.types.Scene.fur_type = EnumProperty(
1488         name="Type",
1489         description="Select the type of fur",
1490         items=[("0","Short Fur","Generate particle Fur"),
1491                ("1","Dalmation","Generate particle Fur"),
1492                ("2","Fur3","Generate particle Fur"),
1493
1494               ],
1495         default='0')
1496
1497 def unregister():
1498     bpy.utils.unregister_module(__name__)
1499     del bpy.types.Scene.hair_type
1500
1501 if __name__ == "__main__":
1502     register()
1503
1504
1505