Skip to content
Snippets Groups Projects
object_particle_hair_lab.py 55.8 KiB
Newer Older
  • Learn to ignore specific revisions
  •             col.operator("hair.switch_back", text="Switch back to scene")
            else:
                col.operator("fur.test_scene", text="Create Test Scene")
    
    # TO DO
    """
    class saveSelection(bpy.types.Operator):
        bl_idname = "save.selection"
        bl_label = "Save Selection"
        bl_description = "Save selected particles"
        bl_register = True
        bl_undo = True
    
        def execute(self, context):
    
    """
    class testScene5(bpy.types.Operator):
        bl_idname = "fur.switch_back"
        bl_label = "Switch back to scene"
        bl_description = "If you want keep this scene, switch scene in info window"
        bl_register = True
        bl_undo = True
    
        def execute(self, context):
            scene = bpy.context.scene
            bpy.data.scenes.remove(scene)
    
    class testScene6(bpy.types.Operator):
        bl_idname = "fur.test_scene"
        bl_label = "Create test scene"
        bl_description = "You can switch scene in info panel"
        bl_register = True
        bl_undo = True
    
        def execute(self, context):
    # add new scene
            bpy.ops.scene.new(type="NEW")
            scene = bpy.context.scene
            scene.name = "TestFurScene"
    # render settings
            render = scene.render
            render.resolution_x = 1920
            render.resolution_y = 1080
            render.resolution_percentage = 50
    # add new world
            world = bpy.data.worlds.new("FurWorld")
            scene.world = world
            world.use_sky_blend = True
            world.use_sky_paper = True
            world.horizon_color = (0.004393,0.02121,0.050)
            world.zenith_color = (0.03335,0.227,0.359)
    
    # add text
            bpy.ops.object.text_add(location=(-0.292,0,-0.152), rotation =(1.571,0,0))
            text = bpy.context.active_object
            text.scale = (0.05,0.05,0.05)
            text.data.body = "Fur Lab"
    
    # add material to text
            textMaterial = bpy.data.materials.new('textMaterial')
            text.data.materials.append(textMaterial)
            textMaterial.use_shadeless = True
    
    # add camera
            bpy.ops.object.camera_add(location = (0,-1,0),rotation = (1.571,0,0))
            cam = bpy.context.active_object.data
            cam.lens = 50
    
    # add spot lamp
            bpy.ops.object.lamp_add(type="SPOT", location = (-0.7,-0.5,0.3), rotation =(1.223,0,-0.960))
            lamp1 = bpy.context.active_object.data
            lamp1.name = "Key Light"
            lamp1.energy = 1.5
            lamp1.distance = 1.5
            lamp1.shadow_buffer_soft = 5
            lamp1.shadow_buffer_size = 8192
            lamp1.shadow_buffer_clip_end = 1.5
            lamp1.spot_blend = 0.5
    
    # add spot lamp2
            bpy.ops.object.lamp_add(type="SPOT", location = (0.7,-0.6,0.1), rotation =(1.571,0,0.785))
            lamp2 = bpy.context.active_object.data
            lamp2.name = "Fill Light"
            lamp2.color = (0.874,0.874,1)
            lamp2.energy = 0.5
            lamp2.distance = 1.5
            lamp2.shadow_buffer_soft = 5
            lamp2.shadow_buffer_size = 4096
            lamp2.shadow_buffer_clip_end = 1.5
            lamp2.spot_blend = 0.5
    
    # light Rim
            """
            # add spot lamp3
            bpy.ops.object.lamp_add(type="SPOT", location = (0.191,0.714,0.689), rotation =(0.891,0,2.884))
            lamp3 = bpy.context.active_object.data
            lamp3.name = "Rim Light"
            lamp3.color = (0.194,0.477,1)
            lamp3.energy = 3
            lamp3.distance = 1.5
            lamp3.shadow_buffer_soft = 5
            lamp3.shadow_buffer_size = 4096
            lamp3.shadow_buffer_clip_end = 1.5
            lamp3.spot_blend = 0.5
            """
    # add sphere
            bpy.ops.mesh.primitive_uv_sphere_add(size=0.1)
    
    
    
    class GenerateFur(bpy.types.Operator):
        bl_idname = "fur.generate_fur"
        bl_label = "Generate Fur"
        bl_description = "Create a Fur"
        bl_register = True
        bl_undo = True
    
        def execute(self, context):
    # Make variable that is the current .blend file main data blocks
            blend_data = context.blend_data
            ob = bpy.context.active_object
            scene = context.scene
    
    ######################################################################
    ########################Short Fur########################
    
    ###############Create New Material##################
    # add new material
                furMaterial = bpy.data.materials.new('Fur 1')
                ob.data.materials.append(furMaterial)
    
    #Material settings
                furMaterial.preview_render_type = "HAIR"
                furMaterial.diffuse_color = (0.287, 0.216, 0.04667)
                furMaterial.specular_color = (0.604, 0.465, 0.136)
                furMaterial.specular_intensity = 0.3
                furMaterial.ambient = 0
                furMaterial.use_cubic = True
                furMaterial.use_transparency = True
                furMaterial.alpha = 0
                furMaterial.use_transparent_shadows = True
    #strand
                furMaterial.strand.use_blender_units = True
                furMaterial.strand.root_size = 0.00030
                furMaterial.strand.tip_size = 0.00010
                furMaterial.strand.size_min = 0.7
                furMaterial.strand.width_fade = 0.1
                furMaterial.strand.shape = 0.061
                furMaterial.strand.blend_distance = 0.001
    
    # add texture
                furTex = bpy.data.textures.new("Fur1Tex", type='BLEND')
                furTex.use_preview_alpha = True
                furTex.use_color_ramp = True
                ramp = furTex.color_ramp
                rampElements = ramp.elements
                rampElements[0].position = 0
                rampElements[0].color = [0.114,0.05613,0.004025,0.38]
                rampElements[1].position = 1
                rampElements[1].color = [0.267,0.155,0.02687,0]
                rampElement1 = rampElements.new(0.111)
                rampElement1.color = [0.281,0.168,0.03157,0.65]
                rampElement2 = rampElements.new(0.366)
                rampElement2.color = [0.288,0.135,0.006242,0.87]
                rampElement3 = rampElements.new(0.608)
                rampElement3.color = [0.247,0.113,0.006472,0.8]
                rampElement4 = rampElements.new(0.828)
                rampElement4.color = [0.253,0.09919,0.01242,0.64]
    
    # add texture to material
                MTex = furMaterial.texture_slots.add()
                MTex.texture = furTex
                MTex.texture_coords = "STRAND"
    
    ###############Create Particles##################
    # Add new particle system
    
                NumberOfMaterials = 0
                for i in ob.data.materials:
                    NumberOfMaterials +=1
    
                bpy.ops.object.particle_system_add()
    #Particle settings setting it up!
                furParticles = bpy.context.object.particle_systems.active
                furParticles.name = "Fur1Par"
                furParticles.settings.type = "HAIR"
                furParticles.settings.use_advanced_hair = True
                furParticles.settings.count = 500
                furParticles.settings.normal_factor = 0.05
                furParticles.settings.factor_random = 0.001
                furParticles.settings.use_dynamic_rotation = True
    
                furParticles.settings.material = NumberOfMaterials
    
                furParticles.settings.use_strand_primitive = True
                furParticles.settings.use_hair_bspline = True
                furParticles.settings.render_step = 5
                furParticles.settings.length_random = 0.5
    
                furParticles.settings.display_step = 5
    
    # children
                furParticles.settings.child_type = "INTERPOLATED"
                furParticles.settings.child_length = 0.134
                furParticles.settings.create_long_hair_children = True
                furParticles.settings.clump_factor = 0.55
                furParticles.settings.roughness_endpoint = 0.005
                furParticles.settings.roughness_end_shape = 5
                furParticles.settings.roughness_2 = 0.003
                furParticles.settings.roughness_2_size = 0.230
    
    ######################################################################
    ########################Dalmation Fur##########################
            if scene.fur_type == '1':
    ###############Create New Material##################
    # add new material
                furMaterial = bpy.data.materials.new('Fur2Mat')
                ob.data.materials.append(furMaterial)
    
    #Material settings
                furMaterial.preview_render_type = "HAIR"
                furMaterial.diffuse_color = (0.300, 0.280, 0.280)
                furMaterial.specular_color = (1.0, 1.0, 1.0)
                furMaterial.specular_intensity = 0.500
                furMaterial.specular_hardness = 50
    
                furMaterial.ambient = 0
                furMaterial.use_cubic = True
                furMaterial.use_transparency = True
                furMaterial.alpha = 0
                furMaterial.use_transparent_shadows = True
    #strand
                furMaterial.strand.use_blender_units = True
                furMaterial.strand.root_size = 0.00030
                furMaterial.strand.tip_size = 0.00010
                furMaterial.strand.size_min = 0.7
                furMaterial.strand.width_fade = 0.1
                furMaterial.strand.shape = 0.061
                furMaterial.strand.blend_distance = 0.001
    
    # add texture
                furTex = bpy.data.textures.new("Fur2Tex", type='BLEND')
                furTex.name = "Fur2"
                furTex.use_preview_alpha = True
                furTex.use_color_ramp = True
                ramp = furTex.color_ramp
                rampElements = ramp.elements
                rampElements[0].position = 0
                rampElements[0].color = [1.0,1.0,1.0,1.0]
                rampElements[1].position = 1
                rampElements[1].color = [1.0,1.0,1.0,0.0]
                rampElement1 = rampElements.new(0.116)
                rampElement1.color = [1.0,1.0,1.0,1.0]
    
    # add texture to material
                MTex = furMaterial.texture_slots.add()
                MTex.texture = furTex
                MTex.texture_coords = "STRAND"
                MTex.use_map_alpha = True
    
    # add texture 2
                furTex = bpy.data.textures.new("Fur2bTex", type='CLOUDS')
                furTex.name = "Fur2b"
                furTex.use_preview_alpha = False
                furTex.cloud_type = "COLOR"
                furTex.noise_type = "HARD_NOISE"
                furTex.noise_scale = 0.06410
                furTex.use_color_ramp = True
                ramp = furTex.color_ramp
                rampElements = ramp.elements
                rampElements[0].position = 0
                rampElements[0].color = [1.0,1.0,1.0, 1.0]
                rampElements[1].position = 1
                rampElements[1].color = [0.0,0.0,0.0,1.0]
                rampElement1 = rampElements.new(0.317)
                rampElement1.color = [1.0,1.0,1.0,1.0]
                rampElement2 = rampElements.new(0.347)
                rampElement2.color = [0.0,0.0,0.0,1.0]
    
    # add texture 2 to material
                MTex = furMaterial.texture_slots.add()
                MTex.texture = furTex
                MTex.texture_coords = "GLOBAL"
    
    ###############Create Particles##################
    # Add new particle system
    
                NumberOfMaterials = 0
                for i in ob.data.materials:
                    NumberOfMaterials +=1
    
                bpy.ops.object.particle_system_add()
    #Particle settings setting it up!
                furParticles = bpy.context.object.particle_systems.active
                furParticles.name = "Fur2Par"
                furParticles.settings.type = "HAIR"
                furParticles.settings.use_advanced_hair = True
                furParticles.settings.count = 500
                furParticles.settings.normal_factor = 0.05
                furParticles.settings.factor_random = 0.001
                furParticles.settings.use_dynamic_rotation = True
    
                furParticles.settings.material = NumberOfMaterials
    
                furParticles.settings.use_strand_primitive = True
                furParticles.settings.use_hair_bspline = True
                furParticles.settings.render_step = 5
                furParticles.settings.length_random = 0.5
    
                furParticles.settings.display_step = 5
    
    # children
                furParticles.settings.child_type = "INTERPOLATED"
                furParticles.settings.child_length = 0.07227
                furParticles.settings.create_long_hair_children = True
                furParticles.settings.clump_factor = 0.55
                furParticles.settings.roughness_endpoint = 0.005
                furParticles.settings.roughness_end_shape = 5
                furParticles.settings.roughness_2 = 0.003
                furParticles.settings.roughness_2_size = 0.230
    
    ######################################################################
    ########################Spotted_fur##########################
            elif scene.fur_type == '2':
    
    ###############Create New Material##################
    # add new material
                furMaterial = bpy.data.materials.new('Fur3Mat')
                ob.data.materials.append(furMaterial)
    
    #Material settings
                furMaterial.preview_render_type = "HAIR"
                furMaterial.diffuse_color = (0.300, 0.280, 0.280)
                furMaterial.specular_color = (1.0, 1.0, 1.0)
                furMaterial.specular_intensity = 0.500
                furMaterial.specular_hardness = 50
                furMaterial.use_specular_ramp = True
    
                ramp = furMaterial.specular_ramp
                rampElements = ramp.elements
                rampElements[0].position = 0
                rampElements[0].color = [0.0356,0.0152,0.009134,0]
                rampElements[1].position = 1
                rampElements[1].color = [0.352,0.250,0.231,1]
                rampElement1 = rampElements.new(0.255)
                rampElement1.color = [0.214,0.08244,0.0578,0.31]
                rampElement2 = rampElements.new(0.594)
                rampElement2.color = [0.296,0.143,0.0861,0.72]
    
                furMaterial.ambient = 0
                furMaterial.use_cubic = True
                furMaterial.use_transparency = True
                furMaterial.alpha = 0
                furMaterial.use_transparent_shadows = True
    #strand
                furMaterial.strand.use_blender_units = True
                furMaterial.strand.root_size = 0.00030
                furMaterial.strand.tip_size = 0.00015
                furMaterial.strand.size_min = 0.450
                furMaterial.strand.width_fade = 0.1
                furMaterial.strand.shape = 0.02
                furMaterial.strand.blend_distance = 0.001
    
    # add texture
                furTex = bpy.data.textures.new("Fur3Tex", type='BLEND')
                furTex.name = "Fur3"
                furTex.use_preview_alpha = True
                furTex.use_color_ramp = True
                ramp = furTex.color_ramp
                rampElements = ramp.elements
                rampElements[0].position = 0
                rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
                rampElements[1].position = 1
                rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
                rampElement1 = rampElements.new(0.111)
                rampElement1.color = [0.01467,0.005307,0.00316,0.65]
                rampElement2 = rampElements.new(0.366)
                rampElement2.color = [0.0272,0.01364,0.01013,0.87]
                rampElement3 = rampElements.new(0.608)
                rampElement3.color = [0.04445,0.02294,0.01729,0.8]
                rampElement4 = rampElements.new(0.828)
                rampElement4.color = [0.04092,0.0185,0.01161,0.64]
    
    # add texture to material
                MTex = furMaterial.texture_slots.add()
                MTex.texture = furTex
                MTex.texture_coords = "STRAND"
                MTex.use_map_alpha = True
    
    # add texture 2
                furTex = bpy.data.textures.new("Fur3bTex", type='CLOUDS')
                furTex.name = "Fur3b"
                furTex.use_preview_alpha = True
                furTex.cloud_type = "COLOR"
                furTex.use_color_ramp = True
                ramp = furTex.color_ramp
                rampElements = ramp.elements
                rampElements[0].position = 0
                rampElements[0].color = [0.009721,0.006049,0.003677,0.38]
                rampElements[1].position = 1
                rampElements[1].color = [0.04231,0.02029,0.01444,0.16]
                rampElement1 = rampElements.new(0.111)
                rampElement1.color = [0.01467,0.005307,0.00316,0.65]
                rampElement2 = rampElements.new(0.366)
                rampElement2.color = [0.0272,0.01364,0.01013,0.87]
                rampElement3 = rampElements.new(0.608)
                rampElement3.color = [0.04445,0.02294,0.01729,0.8]
                rampElement4 = rampElements.new(0.828)
                rampElement4.color = [0.04092,0.0185,0.01161,0.64]
    
    # add texture 2 to material
                MTex = furMaterial.texture_slots.add()
                MTex.texture = furTex
                MTex.texture_coords = "GLOBAL"
    
    ###############Create Particles##################
    # Add new particle system
    
                NumberOfMaterials = 0
                for i in ob.data.materials:
                    NumberOfMaterials +=1
    
                bpy.ops.object.particle_system_add()
    #Particle settings setting it up!
                furParticles = bpy.context.object.particle_systems.active
                furParticles.name = "Fur3Par"
                furParticles.settings.type = "HAIR"
                furParticles.settings.use_advanced_hair = True
                furParticles.settings.count = 500
                furParticles.settings.normal_factor = 0.05
                furParticles.settings.factor_random = 0.001
                furParticles.settings.use_dynamic_rotation = True
    
                furParticles.settings.material = NumberOfMaterials
    
                furParticles.settings.use_strand_primitive = True
                furParticles.settings.use_hair_bspline = True
                furParticles.settings.render_step = 5
                furParticles.settings.length_random = 0.5
    
                furParticles.settings.display_step = 5
    
    # children
                furParticles.settings.child_type = "INTERPOLATED"
                furParticles.settings.child_length = 0.134
                furParticles.settings.create_long_hair_children = True
                furParticles.settings.clump_factor = 0.55
                furParticles.settings.roughness_endpoint = 0.005
                furParticles.settings.roughness_end_shape = 5
                furParticles.settings.roughness_2 = 0.003
                furParticles.settings.roughness_2_size = 0.230
    
            return {'FINISHED'}
    def register():
        bpy.utils.register_module(__name__)
        bpy.types.Scene.grass_type = EnumProperty(
            name="Type",
            description="Select the type of grass",
            items=[("0","Green Grass","Generate particle grass"),
                   ("1","Grassy Field","Generate particle grass"),
                   ("2","Clumpy Grass","Generate particle grass"),
    
                  ],
            default='0')
        bpy.types.Scene.hair_type = EnumProperty(
            name="Type",
            description="Select the type of hair",
            items=[("0","Long Red Straight Hair","Generate particle Hair"),
                   ("1","Long Brown Curl Hair","Generate particle Hair"),
                   ("2","Short Dark Hair","Generate particle Hair"),
    
                  ],
            default='0')
        bpy.types.Scene.fur_type = EnumProperty(
            name="Type",
            description="Select the type of fur",
            items=[("0","Short Fur","Generate particle Fur"),
                   ("1","Dalmation","Generate particle Fur"),
                   ("2","Fur3","Generate particle Fur"),
    
    def unregister():
        bpy.utils.unregister_module(__name__)
        del bpy.types.Scene.hair_type
    
    if __name__ == "__main__":
        register()