[SOLVED] Bitmap to ImageTexture conversion through python?

Forums: [SOLVED] Bitmap to ImageTexture conversion through python?
Maxon Cinema 4D (Export script developed by abstrax, Integrated Plugin developed by aoktar)

Moderator: aoktar

[SOLVED] Bitmap to ImageTexture conversion through python?

Postby Hurricane046 » Thu Jun 01, 2023 12:12 pm

Hurricane046 Thu Jun 01, 2023 12:12 pm
Hello fellow Octane users!

What is a c4d python octane command to convert c4d native Bitmap into Octane ImageTexture? Or what way we can do instead creating Bitmap shader containing texture and injecting it into material, create ImageTexture node if material is OctaneMaterial and connect it into correct link inside Octane Node Editor?

C4D default python example that creates Bitmap link:
Code: Select all
# Create a new bitmap shader and set its filename to the texture path
                            shader = c4d.BaseList2D(c4d.Xbitmap)
                            shader[c4d.BITMAPSHADER_FILENAME] = texture_path
                           
                            # Insert the shader into the document
                            doc.InsertShader(shader)
                           
                            # Set the shader as the link for c4d.OCT_MATERIAL_DIFFUSE_LINK
                            mat[c4d.OCT_MATERIAL_DIFFUSE_LINK] = shader
                           
                            # Print the name of the selected texture
                            print(f"Selected diffuse texture: {file_name}")
Last edited by Hurricane046 on Fri Jun 02, 2023 9:08 am, edited 1 time in total.
2x RTX 2080 Ti | 2x RTX 2070 | 2x GTX 1080 Ti | 1x GTX 1080 | 1x GTX980 Ti
User avatar
Hurricane046
Licensed Customer
Licensed Customer
 
Posts: 78
Joined: Wed Jul 25, 2018 6:57 am

Re: Bitmap to ImageTexture conversion through python?

Postby aoktar » Thu Jun 01, 2023 5:26 pm

aoktar Thu Jun 01, 2023 5:26 pm
There are not a simple command to convert one node to another one. Nodes are complicated with their data structures and has own parameters types. You can do it a python script by creating new node and transfer/convert the parameters and links. See example scripts under C4D section.
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
aoktar
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 15937
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye

Re: Bitmap to ImageTexture conversion through python?

Postby Hurricane046 » Fri Jun 02, 2023 9:08 am

Hurricane046 Fri Jun 02, 2023 9:08 am
Thanks for quick response. It worked! We skip the bitmap node and go straight for the imagetexture one!
Code: Select all
 for file_name in os.listdir(folder_path):
                    for texture_type in texture_types:
                        if texture_type in file_name.lower():
                            texture_path = os.path.join(folder_path, file_name)
                            print(f"Found {texture_types[texture_type][1]} texture: {texture_path}")

                            # Create a new Octane Image Texture and set its filename to the texture path
                            shader = c4d.BaseShader(ID_OCTANE_IMAGE_TEXTURE)
                            shader[c4d.IMAGETEXTURE_FILE] = texture_path

                            # Insert the shader into the document
                            doc.InsertShader(shader)

                            # Set the shader as the link for c4d.OCT_MATERIAL_DIFFUSE_LINK
                            mat[texture_types[texture_type][0]] = shader

                            # Print the name of the selected texture
                            print(f"Selected {texture_types[texture_type][1]} texture: {file_name}")

                            break
2x RTX 2080 Ti | 2x RTX 2070 | 2x GTX 1080 Ti | 1x GTX 1080 | 1x GTX980 Ti
User avatar
Hurricane046
Licensed Customer
Licensed Customer
 
Posts: 78
Joined: Wed Jul 25, 2018 6:57 am

Re: [SOLVED] Bitmap to ImageTexture conversion through python?

Postby aoktar » Fri Jun 02, 2023 11:27 am

aoktar Fri Jun 02, 2023 11:27 am
You'll need to insert the created ImageTextures to materials. They have to be owned by the material
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
aoktar
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 15937
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye

Return to Maxon Cinema 4D


Who is online

Users browsing this forum: Bing [Bot] and 13 guests

Thu Mar 28, 2024 10:34 am [ UTC ]