Created
September 8, 2023 07:15
-
-
Save CGArtPython/0f74f1c71051150514df309052a3a190 to your computer and use it in GitHub Desktop.
Use a custom displacement image texture in a displacement modifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# downlaod and extract example image from there https://polyhaven.com/a/mud_cracked_dry_03 | |
import bpy | |
# set path to the folder where the texture is | |
image_folder_path = r'c:\path\to\your\textures' | |
# set the name of the displacement texture image | |
image_name = 'name_of_your_texture.png' | |
# load the image | |
bpy.ops.image.open(directory=image_folder_path, files=[{"name": image_name}]) | |
# get a reference to the image | |
image_obj = bpy.data.images[image_name] | |
# create a new texture object and get a reference to it | |
texture_obj = bpy.data.textures.new(name=image_name, type='IMAGE') | |
# assign the image object to the image property of the texture object | |
texture_obj.image = image_obj | |
# get a reference to the active object | |
obj = bpy.context.active_object | |
# apply a subsurf modifier | |
bpy.ops.object.modifier_add(type='SUBSURF') | |
subdiv_modifier = obj.modifiers["Subdivision"] | |
# set the Subdivision levels | |
subdiv_modifier.levels = 4 | |
subdiv_modifier.render_levels = 4 | |
# apply a displacement modifier | |
bpy.ops.object.modifier_add(type="DISPLACE") | |
displace_modifier = obj.modifiers["Displace"] | |
# assign the texture object we created to the texture prop of the modifier | |
displace_modifier.texture = texture_obj | |
displace_modifier.name = f"displace.{image_name}" | |
displace_modifier.texture_coords = "OBJECT" | |
displace_modifier.strength = 0.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment