Page 1 of 1

Resource Reloading

Unread postPosted: Wed Sep 16, 2020 10:38 am
by wilso_will

I'm putting together some tools to allow artists to easily reload resources when they change on disk. Primarily I'm concerned with USD and texture maps, but I've also been testing with Alembics and references to other Clarisse files. I'm getting some pretty varied results as to whether Clarisse will pick up the updates or not.

I'll touch on both the UI reload methods and the code ones. The UI methods I'm testing are the "Reload Resources" option in the File menu. The "Reload" button in the Attribute Editor on the reference node itself, and the "Reload" and "Reload all" buttons in the Resource View. I will say, up front, that the buttons in the Resource View have not worked to reload any form of resource for me, which makes me wonder if I'm misunderstanding their purpose.

None of the UI methods work to reload a USD. The only piece of code I can produce that will reload a USD is the following:
Code: Select all
for item in ix.selection:
    if item.is_context():
        engine = item.get_engine()

Furthermore, if there are two references to the same USD in the scene, even the above code won't work. You need to first unload all references to the USD and then load them again.

Texture Maps
The File menu "Reload Resources" button will reload texture maps. I can't find any way to reload an individual map (I may be missing something), as I said the Resource View "Reload" button doesn't do anything here. If I "Clear" the texture map in the Resource View and then tumble the viewport Clarisse will pull the texture back in and it will be the updated texture.

In the same vein, this code will reload a selected texture map:
Code: Select all
textures = ix.api.OfObjectVector()
texture_items = ix.api.OfItemVector()
for item in textures:
    if item.is_kindof("Texture"):

As with pressing "Clear" in the Resource View you will need to do something to prompt Clarisse to pull the texture back in. Tumbling the viewport does the trick.

Alembic/Clarisse Files
These seem far more predictable. All the different UI buttons work (except the Resource View) and the following code does the job:
Code: Select all
for item in ix.selection:
    if item.is_context():
        engine = item.get_engine()

So, given all this, I was wondering if this is the expected behaviour? Should USDs be reloadable? Am I doing something wrong? Is there better code to reload a single texture map? If there isn't, is there something I can do through code to prompt Clarisse to reprocess the scene so that users don't have to tumble the viewport in order for the updates to appear? Should the "Reload" buttons in the Resource View reload the resource files, or are they for something else?

Re: Resource Reloading

Unread postPosted: Wed Sep 16, 2020 11:47 am
by wilso_will
I meant to say, I'm using Windows 10, Clarisse 4.0 SP10.

We have since found this post, which seems relevant with regard to the Resource View, but also dates back to 2017 and the bug mentioned is no longer in the bug tracker.

Re: Resource Reloading

Unread postPosted: Wed Sep 16, 2020 1:35 pm
by dcourtois

USD: there's indeed a bug in how we manage it. Contrary to Alembic, opening a stage can be quite costly, and takes up significant memory. To avoid this, stages are deduplicated and kept in memory (for playback without paying the cost of reopening the stage) This is why when you have the same stage referenced twice it won't update when you reload only one.
I'll have a look and make it at least behave like Alembic references (which should have been the case, but we missed this)

Resource View / Texture Maps: I'm not really familiar with this part, so I'll have to read the other post you mentioned and do some digging around before reporting back, but it seems there are some bugs (I don't see why `Reload all` would work and not `Reload`...)

Edit: the bug report ID is an internal ID, that's why you won't find it in the bug tracker. Still digging :)

Re: Resource Reloading

Unread postPosted: Thu Sep 17, 2020 9:41 am
by will_wilson
Thanks. Apologies, I was actually logged in to the wrong account when I made this thread. This is the account I'll use from now on.

I mostly content with the solution I've found for USD. I can hunt out the other references to the same file and do a mass unload/reload. Once you bring USD more in line with Alembic I can change the system.

What I've got for the textures feels like a hack, and like I'm missing a better option somewhere. If you find anything in your digging, let me know. Failing that, what I'm doing at present is working. I'm sure there must be some way to force Clarisse to do whatever internal evaluation causes it to pull the textures back in. If you find anything on that, please let me know.

On the Resource View, neither "Reload all" nor "Reload" is working for me.

Re: Resource Reloading

Unread postPosted: Fri Sep 18, 2020 4:34 pm
by anemoff
For textures, that is the way to go for now. There's no dedicated API on Texture items.


Re: Resource Reloading

Unread postPosted: Mon Sep 21, 2020 10:51 am
by will_wilson
Thanks. I'll move ahead with what I've got then. Any suggestions as to how to get the update to appear in the viewport without manually having to tumble the camera or similar? I'm not even certain whether it's just a simple redraw I need, or whether Clarisse needs to do some deeper re-evaluation. I think it's the latter as the resources in question don't pop back in to the Resource View until after tumbling the viewport.

Re: Resource Reloading

Unread postPosted: Tue Sep 29, 2020 4:56 pm
by anemoff
Sorry for the late reply.
There's no scriptable workaround for that, or none that I can think of, for now.

Re: Resource Reloading

Unread postPosted: Thu May 26, 2022 2:34 am
by devinj898
Is there any update on how to easily reload selected textures, or is it still best to just use the script posted above?

EDIT: That script above doesn't seem to work in 5.0 SP8, so any chance someone has a good method to reload selected textures? ctrl + shift + r isn't doing anything like that for me.

Re: Resource Reloading

Unread postPosted: Mon May 30, 2022 2:31 pm
by anemoff
Here is a possible workaround. It's overkill and naive but it should do the work in the meantime.
The idea is to invalidate all the filenames of the selected texture maps, clear resources, and revert the filenames to their original values.

Hopefully, we will release a real fix soon enough.

python code

selected_items = ix.api.OfObjectVector()
tex_maps = ix.api.OfItemVector()
for item in selected_items:
if item.is_kindof("TextureMapFile") or item.is_kindof("TextureStreamedMapFile"):

if tex_maps.get_count() == 0:
ix.log_warning('No texture maps selected.')
ix.begin_command_batch('Updating texture map(s)...')
ix.log_info('Updating {} texture map(s)...'.format(tex_maps.get_count()))

# Invalidate current ressources

# Do a first loop to invalidate all map filenames
for tex in tex_maps:
filename_attr = tex.get_attribute('filename')
filename = filename_attr.get_raw_string() # Use raw string to preserve expressions
filename += 'X'
ix.cmds.SetValue(filename_attr.get_full_name(), [filename])

# Check for events to make sure the invalid filenames are applied

# Clear OIIO stream texture cache (a bit overkill but needed to released previous file handles)

# Revert map files names to their original value
for tex in tex_maps:
filename_attr = tex.get_attribute('filename')
filename = str(filename_attr.get_raw_string())
assert len(filename) > 0 and filename[-1] == 'X'
filename = filename[:-1]
ix.cmds.SetValue(filename_attr.get_full_name(), [filename])