Isotropix Forums

Auto TX scene conversion

Auto TX scene conversion

Unread postby purchasemediamonks » Wed Jun 20, 2018 3:42 pm

Hello,

In the latest Arnold renderer there is an option to auto make tx files from textures within your scene. Are you guys planning to work on something similar? It will save a lot of time both during production and rendering. Thank you for your reply.

Cheers,
Vincent
purchasemediamonks
 
Posts: 21
Joined: Wed Jan 25, 2017 10:03 am

Re: Auto TX scene conversion

Unread postby dboude » Wed Jun 20, 2018 4:46 pm

Hi,

It can be done with a python script.

python code

# Convert textures to .tx and set them to the MapFiles in the scene
import os, subprocess, platform

# Find the Clarisse folder to get the maketx of the current Clarisse
clarisse_dir = ix.application.get_factory().get_vars().get("CLARISSE_BIN_DIR").get_string()
extension = ""
if platform.system() == "Windows" :
extension = ".exe"
MakeTx = '"' + os.path.join(clarisse_dir, "maketx" + extension) + '"'

objects = ix.api.OfObjectVector() # will contain the items to work with
classnames = ["TextureMapFile", "TextureStreamedMapFile"] # The classnames that contain textures
filter_classes = ix.api.CoreStringArray(len(classnames))

# Convert the python list in CoreStringArray
for i in range(len(classnames)):
filter_classes[i] = classnames[i]

# Looking for all the items we will work with
ix.application.get_matching_objects(objects, "./*", ix.application.get_working_context(), filter_classes)


for i in range (objects.get_count()):
tex_path = objects[i].get_attribute("filename").get_string()
file = tex_path.split("/")[-1]
ext = tex_path.split(".")[-1]

if ext != "tx":
if "<UDIM>" in file:
name = file.split("<UDIM>")[0]
dir = os.path.dirname(tex_path)
list_dir = os.listdir(dir)
matching = [s for s in list_dir if name in s]
udim_files = matching
for j in range(len(udim_files)):
print udim_files[j]
cmd = MakeTx + " --oiio " + dir + os.sep + udim_files[j]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

else:
cmd = MakeTx + " --oiio \"" + tex_path + '"'
print cmd
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

# replace the extension
ix.cmds.SetValues([objects[i].get_full_name() + ".filename[0]"], [tex_path.replace(ext, "tx")])


This script will convert AND change the map file paths of all the map files that are in a context and sub-context. Make sure you select the context in the left column of the browser to set the working context the script needs. If you want to convert all the map files of the project, just select the root context. (project://). UDIM files will be converted as well ;)

Works only on windows but you can modify it for other platforms.

EDIT : The script was updated to work on all plateforms

Let me know if you encounter some weird things.

Cheers ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 883
Joined: Mon Jul 03, 2017 10:51 am

Re: Auto TX scene conversion

Unread postby purchasemediamonks » Wed Jun 27, 2018 10:53 am

Hi Démian,

Thank you very much for your response and your script is a huge help for every project. One thing that don't work is the conversion from TextureMapFile to StreamMapFile. I've tested this on a medium size project and with an empty scene with one sphere. The result in the empty scene was a little different when after the running the script I've got the standard checkerboard preview. When I replaced it by hand with a StreamMapFile it worked again. With the medium size project the textures still worked but the same thing with the empty scene project there are no StreamMapFiles types found. Can you look into it? Many thanks.

In the future maybe you can combine this node to one texture input node with a auto detection if it is a stream type of file or not.

Cheers,
Vincent
purchasemediamonks
 
Posts: 21
Joined: Wed Jan 25, 2017 10:03 am

Re: Auto TX scene conversion

Unread postby dboude » Wed Jun 27, 2018 4:43 pm

Hi,

The script was not designed to convert mapfile to streamed one. But I will have a look to add this possibility when I will have some time. If I remember well there is a script to turn map file into streamed one in the script part of the forum. Not 100% sure.

Thanks for your feedback.

Cheers ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 883
Joined: Mon Jul 03, 2017 10:51 am

Re: Auto TX scene conversion

Unread postby purchasemediamonks » Thu Jun 28, 2018 8:42 am

That would be amazing of you can find the time for it. I've searched through the forum with no luck finding the script. Are you guys planning to add more useful pipeline script to the shelf of new releases? Thank you in advance.

Cheers,
Vincent
purchasemediamonks
 
Posts: 21
Joined: Wed Jan 25, 2017 10:03 am


Return to Feature Requests Archives