C4D Python script for creating RS Mat UDIMS support

  Рет қаралды 72

Nikolay Kirkov

Nikolay Kirkov

Ай бұрын

I've developed a useful Python script with chatGPT for handling various scenarios, including UDIM textures support, specifically designed for Cinema 4D. When the script runs, a window pops up to select a texture, but instead of loading that texture directly, it selects the folder containing it. From there, it creates a material with textures such as Albedo, Roughness, Metalness, Displacement, Normal, Opacity, Translucency, etc. from the same folder where selected file is.
The script can be found in the RS forum:
Post name - C4D script for creating RS Mat works also with UDIMS
in Scripts, Tools, Tips & Tricks.
Sorry I can't post a link, but youtube haven't given me that option yet.

Пікірлер: 2
@nikolaykirkov
@nikolaykirkov Ай бұрын
Forum link to the script - redshift.maxon.net/topic/51041/c4d-script-for-creating-rs-mat-works-also-with-udims?_=1719370222062
@nikolaykirkov
@nikolaykirkov Ай бұрын
import c4d import os from c4d import storage, gui def create_redshift_base_node(node_master, nodetype, name, posX, posY): rs_node = node_master.CreateNode(node_master.GetRoot(), 1036227, None, posX, posY) rs_node[c4d.GV_REDSHIFT_SHADER_META_CLASSNAME] = nodetype rs_node[c4d.ID_BASELIST_NAME] = name print(f"Created node: {name} at position ({posX}, {posY})") return rs_node def create_rs_tex_node(node_master, texPath, name, link, rs_material, posX, posY, colorspace): # Replace 1001 with if 1001 is found in the texture path if "1001" in texPath: texPath = texPath.replace("1001", "") rs_tex_node = create_redshift_base_node(node_master, "TextureSampler", name, posX, posY) rs_tex_node[c4d.REDSHIFT_SHADER_TEXTURESAMPLER_TEX0, c4d.REDSHIFT_FILE_PATH] = texPath rs_tex_node[c4d.REDSHIFT_SHADER_TEXTURESAMPLER_TEX0, c4d.REDSHIFT_FILE_COLORSPACE] = colorspace rs_tex_node.GetOutPort(0).Connect(rs_material.GetInPort(link)) print(f"Created texture node: {name} with texture path: {texPath}") return rs_tex_node def setup_redshift_material(texture_folder): try: import redshift # Try to import the Redshift API. textures = os.listdir(texture_folder) texture_paths = {} albedo_name = None texture_types = { "albedo": ["albedo", "diffuse", "base color", "base_color", "basecolor","diff"], "roughness": ["roughness", "gloss", "glossiness","rough"], "normal": ["normal","norm"], "displacement": ["displacement", "height", "depth"], "metalness": ["metalness", "metallic","metal"], "opacity": ["opacity"], "translucency": ["translucency"], "transmission": ["transmission"] } for key, aliases in texture_types.items(): for alias in aliases: for file in textures: if alias in file.lower(): if "1001" in file: texture_paths[key] = os.path.join(texture_folder, file.replace("1001", "")) else: texture_paths[key] = os.path.join(texture_folder, file) print(f"Found texture: {key}, path: {texture_paths[key]}") if key == "albedo": albedo_name = file.split('_')[0] break if albedo_name is None: print("No albedo texture found.") return None doc = c4d.documents.GetActiveDocument() c4d.CallCommand(1036759, 1000) # Create a new Redshift material mat = doc.GetFirstMaterial() mat.SetName(albedo_name) # Set material name based on albedo texture node_master = redshift.GetRSMaterialNodeMaster(mat) output = node_master.GetRoot().GetDown() rs_material = output.GetNext() rs_material[c4d.REDSHIFT_SHADER_MATERIAL_REFL_BRDF] = 1 # Set Fresnel Mode based on the existence of any metalness texture if any(key in texture_paths for key in ["metalness", "metallic", "metal"]): rs_material[c4d.REDSHIFT_SHADER_MATERIAL_REFL_FRESNEL_MODE] = 2 # Set to Metalness else: rs_material[c4d.REDSHIFT_SHADER_MATERIAL_REFL_FRESNEL_MODE] = 3 # Set to IOR rs_material.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.REDSHIFT_SHADER_MATERIAL_DIFFUSE_COLOR)), message=True) rs_material.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.REDSHIFT_SHADER_MATERIAL_REFL_ROUGHNESS)), message=True) # Define index for the normal map input normal_index = 2 # Add metalness port if metalness texture is found if any(key in texture_paths for key in ["metalness", "metallic", "metal"]): rs_material.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.REDSHIFT_SHADER_MATERIAL_REFL_METALNESS)), message=True) normal_index = 3 # Adjust normal map index if metalness is present # Create and connect texture nodes if "albedo" in texture_paths: albedo_node = create_rs_tex_node(node_master, texture_paths["albedo"], "Albedo", 0, rs_material, -100, 200, "RS_INPUT_COLORSPACE_SRGB") albedo_node.GetOutPort(0).Connect(rs_material.GetInPort(0)) if "roughness" in texture_paths: if any(alias in texture_paths["roughness"].lower() for alias in ["gloss", "glossiness"]): rs_material[c4d.REDSHIFT_SHADER_MATERIAL_REFL_ISGLOSSINESS] = True create_rs_tex_node(node_master, texture_paths["roughness"], "Roughness", 1, rs_material, -100, 250, "RS_INPUT_COLORSPACE_RAW") if "metalness" in texture_paths: create_rs_tex_node(node_master, texture_paths["metalness"], "Metalness", 2, rs_material, -100, 300, "RS_INPUT_COLORSPACE_RAW") elif "metallic" in texture_paths: create_rs_tex_node(node_master, texture_paths["metallic"], "Metalness", 2, rs_material, -100, 300, "RS_INPUT_COLORSPACE_RAW") elif "metal" in texture_paths: create_rs_tex_node(node_master, texture_paths["metal"], "Metalness", 2, rs_material, -100, 300, "RS_INPUT_COLORSPACE_RAW") if "normal" in texture_paths: rs_bump_node = create_redshift_base_node(node_master, "BumpMap", "BumpMap", -100, 350) rs_bump_node.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(10000)), message=True) rs_bump_node[c4d.REDSHIFT_SHADER_BUMPMAP_INPUTTYPE] = 1 create_rs_tex_node(node_master, texture_paths["normal"], "Normal", 0, rs_bump_node, -250, 350, "RS_INPUT_COLORSPACE_RAW") print("Bump node and normal map created successfully") # Check and add Overall Bump Map port overall_bump_port = rs_material.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(10062)), message=True) if overall_bump_port: rs_bump_node.GetOutPort(0).Connect(overall_bump_port) print("Connected Bump Map to Overall Bump Map port on the RS Material") else: print("Failed to create Overall Bump Map port on the RS Material") return None # Displacement Map Setup if "displacement" in texture_paths: output.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(10001)), message=True) rs_disp_node = create_redshift_base_node(node_master, "Displacement", "RS Displacement", 100, 500) rs_disp_node.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(10000)), message=True) rs_disp_node[c4d.REDSHIFT_SHADER_DISPLACEMENT_SPACE_TYPE] = 2 rs_disp_node[c4d.REDSHIFT_SHADER_DISPLACEMENT_NEWRANGE_MIN] = -0.5 rs_disp_node[c4d.REDSHIFT_SHADER_DISPLACEMENT_NEWRANGE_MAX] = 0.5 disp_tex_node = create_rs_tex_node(node_master, texture_paths["displacement"], "Displacement", 0, rs_disp_node, -100, 550, "RS_INPUT_COLORSPACE_RAW") rs_disp_node.GetOutPort(0).Connect(output.GetInPort(1)) print("Displacement node and texture created successfully") # Opacity Map Setup if "opacity" in texture_paths: rs_sprite_material = create_redshift_base_node(node_master, "Sprite", "Opacity", 200, 200) rs_sprite_material.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(10000)), message=True) rs_sprite_material[c4d.REDSHIFT_SHADER_SPRITE_TEX0, c4d.REDSHIFT_FILE_COLORSPACE] = "RS_INPUT_COLORSPACE_SRGB" rs_sprite_material[c4d.REDSHIFT_SHADER_SPRITE_TEX0, c4d.REDSHIFT_FILE_PATH] = texture_paths["opacity"] rs_material.GetOutPort(0).Connect(rs_sprite_material.GetInPort(0)) rs_sprite_material.GetOutPort(0).Connect(output.GetInPort(0)) print("Opacity node and texture created successfully") # Translucency and Transmission Map Setup translucency_index = normal_index + 1 transmission_index = normal_index + 1 if "translucency" in texture_paths: rs_material.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.REDSHIFT_SHADER_MATERIAL_TRANSL_COLOR)), message=True) create_rs_tex_node(node_master, texture_paths["translucency"], "Translucency", translucency_index, rs_material, -100, 450, "RS_INPUT_COLORSPACE_SRGB") print("Translucency node and texture created successfully") if "transmission" in texture_paths: rs_material.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.REDSHIFT_SHADER_MATERIAL_TRANSL_WEIGHT)), message=True) create_rs_tex_node(node_master, texture_paths["transmission"], "Transmission", transmission_index, rs_material, -100, 500, "RS_INPUT_COLORSPACE_SRGB") print("Transmission node and texture created successfully") mat.Update(True, True) print("Redshift material setup successfully") return mat except Exception as e: gui.MessageDialog(f"Failed to create Redshift material. Error: {e}") return None def main(): file_path = storage.LoadDialog(title="Select any file in the folder with Textures", flags=c4d.FILESELECT_LOAD) if not file_path: return folder_path = os.path.dirname(file_path) setup_redshift_material(folder_path) if __name__ == '__main__': main()
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 790 М.
Java Is Better Than Rust
42:14
ThePrimeTime
Рет қаралды 160 М.
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 31 МЛН
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 78 МЛН
ВОДА В СОЛО
00:20
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 29 МЛН
Cool Items! New Gadgets, Smart Appliances 🌟 By 123 GO! House
00:18
123 GO! HOUSE
Рет қаралды 17 МЛН
AMD Almost Went Bankrupt…but were saved by Sony and Microsoft?
5:35
3 Hours vs. 3 Years of Blender
17:44
Isto Inc.
Рет қаралды 4,3 МЛН
Procedural Shader Graph Unity Glowing Stone Ring
17:27
Tech Hamlin
Рет қаралды 75
I tried to recreate Death by Glamour from memory
8:44
Shady Cicada
Рет қаралды 19 М.
Calibrate your Resin 3D Prints with a Sword!
12:59
Uncle Jessy
Рет қаралды 7 М.
Build Anything With ChatGPT, Here’s How
1:24:05
David Ondrej
Рет қаралды 1 МЛН
Chat GPT with Cinema 4d AI write python scripts for Cinema 4d
23:10
How To Access Any Forked GitHub Repositories Data
9:31
Mental Outlaw
Рет қаралды 47 М.
Deep Drowsiness Detection using YOLO, Pytorch and Python
1:18:35
Nicholas Renotte
Рет қаралды 246 М.
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 31 МЛН