Isotropix Forums

Load reference objects of specific layer

Clarisse Scripting related topics

Load reference objects of specific layer

Unread postby vishumish » Tue Feb 18, 2020 10:42 am

Hi, While rendering there were few instances where rendering completed upto a level e.g., 65% and then suddenly it restarted from 0 without any significant error/log. Till now we figured out that it might be happening because clarisse loads data (geo/cache/etc) in the memory as and when they needed to render but if we load (load means when it shows objects in resource viewer) everything before rendering (as a pre render script) then it won't fail.

So to make such script I want to know how to replicate that load behavior using script. Till now I have I did following :

python code

# get current context
import ix

print "*"*1000

# create an image object array
image_objects = ix.api.OfObjectArray()

# get all the image objects in the scene
ix.application.get_factory().get_all_objects("Image", image_objects)

active_passes = []
for index in xrange(image_objects.get_count()):
image_object = image_objects[index]
if not image_object.is_instance():
context = image_object.get_context()
if not context.is_disabled():
layers = image_object.get_module().get_layers()
for layer in layers:
layer_item = layer.get_object()
if layer_item.is_kindof("Layer3d"):
active_passes.append(layer_item)

for layer in active_passes:
# get reference object for geometries
object = layer.get_attribute("geometries").get_object()
# get group items
result_attr = object.get_attribute("references")
for index in xrange(result_attr.get_value_count()):
geo_object = result_attr.get_object(index)
geo_object_context = geo_object.get_context()
print geo_object
## >> here i want to load this object in the memory (so that it should show in the resource viewer) please suggest what to do << ##


Also if there is any suggestion to debug the root cause of rendering getting restart please let me know. Thanks!

Thanks in advance
-VM
vishumish
 
Posts: 6
Joined: Mon Jan 27, 2020 11:38 am

Re: Load reference objects of specific layer

Unread postby anemoff » Thu Feb 20, 2020 12:15 pm

Hi,

The behavior you are describing is a bug due to some geometries not being loaded up-front.

To work around this issue we suggest the following:
- create a Group that gathers all Geometries from the project
- then call the following to manually force loading all the gathered geometries

python code

group = ... # the group OfObject
group.get_module().get_gas()

By requestion the Geometry Acceleration Structure of the group, Clarisse will load all geometries in it.
Let us know if this helps.

Cheers,

Edit: fixed "get_module()" call
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 282
Joined: Wed Jan 13, 2016 10:10 am

Re: Load reference objects of specific layer

Unread postby vishumish » Thu Feb 20, 2020 2:14 pm

Hi Anthony,

Thanks for your response.
I tried calling get_gas using a group as you suggested but nothing happened. In other words I had cleared all the items in resource viewer before running the code and after that I am expecting resource viewer to show all the geos loaded but it still blank.

Here is the code that I am trying :

python code

group_object = ix.get_item("project://renderPasses/default_BEAUTY/default_BEAUTY_geometry") ## where "defautl_BEAUTY_geometry" is group object having all the geos added.
group_object.get_module.get_gas()


or

python code

group_object = ix.get_item("project://renderPasses/default_BEAUTY/default_BEAUTY_geometry") ## where "defautl_BEAUTY_geometry" is group object having all the geos added.
module = group_object.get_module()
module.get_gas()


Please let me know how can I check if the get_gas() method is working as expected.
vishumish
 
Posts: 6
Joined: Mon Jan 27, 2020 11:38 am

Re: Load reference objects of specific layer

Unread postby vishumish » Thu Feb 20, 2020 2:31 pm

Hi Again..

I tried calling the .get_gas() method on the geo object and it worked. Please see following :

python code

geo_object = ix.get_item("project://geometry/ZMDL_vehicle_cars_chevrolet_yukon_default_lod300/rearview_mirror_mount__plastic_geoShape")
module = geo_object.get_module()
module.get_gas()


But I think it will be expensive to load all the geometries this way. Please suggest. Thanks!
vishumish
 
Posts: 6
Joined: Mon Jan 27, 2020 11:38 am

Re: Load reference objects of specific layer

Unread postby anemoff » Thu Feb 20, 2020 5:05 pm

My bad, there was a typo in my code example but you found the solution.
"get_module" should have been "get_module()".

Yes, it can be expensive indeed. You can try to optimize the group by adding only geometries involved in 2nd rays (like for occlusion).

By the way, could you create a private bug report (link) with the assets or a simplified scene that reproduces it?
It will allow us to find a fix.

Thanks!
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 282
Joined: Wed Jan 13, 2016 10:10 am

Re: Load reference objects of specific layer

Unread postby vishumish » Fri Feb 21, 2020 6:31 am

Hi Anthony,

Did you check my other concern? Calling "get_gas()" on group is not working.
It is only working on geometry object directly. Please see following :

python code

######## NOT WORKING ON GROUP ######## 

group_object = ix.get_item("project://renderPasses/default_BEAUTY/default_BEAUTY_geometry") ## where "defautl_BEAUTY_geometry" is group object having all the geos added.
module = group_object.get_module()
module.get_gas()


python code

######## WORKING ON GEO ######## 

geo_object = ix.get_item("project://geometry/ZMDL_vehicle_cars_chevrolet_yukon_default_lod300/rearview_mirror_mount__plastic_geoShape")
module = geo_object.get_module()
module.get_gas()

Can you please me here. Looping through all the geometry will be an expensive task though I can do this on a group but unfortunately it is not working.

I have one more query :
I have group which includes geometries, combiners, groups in it. How can I extract all the referenced elements. Is there a better way then querying items from each group/combiner recursively.

Also I will create a ticket as you suggested in some time.

Thanks,
-VIshal
vishumish
 
Posts: 6
Joined: Mon Jan 27, 2020 11:38 am

Re: Load reference objects of specific layer

Unread postby anemoff » Fri Feb 21, 2020 11:59 am

Hi Vishal,

Can you remind us what Clarisse version you are using?

The method get_gas() should load the geometries. Can you confirm that the Group contains all the geometries?
Be sure to set the Inclusion Rule to "*".
You can also replace "Geometry" with "SceneObject" in the Group's Filter, so that it includes Bundles and Trees (combiners + scatterers) too.
You can see the list of gathered items in the Group attribute "References", in the category "Result" at the very bottom of the Group's attributes.

To check if an item is from a reference, you can use "item.is_remote()".
The group already gathers items recursively so you don't need to do that yourself. However, there's no API to filter gathered objects based on their remote status.

Here is an idea:

python code

# First group that gaters all SceneObjects
# Filter = "SceneObject", Inclusion Rule = "*"
group_all = ix.get_item("project://group")
group_all_mod = group_all.get_module()

all_scene_objects = ix.api.OfObjectArray()
group_all_mod.get_objects(all_scene_objects)
print("all: {}".format(all_scene_objects.get_count()))

# Get only the remote scene objects
remote_scene_objects = ix.api.OfObjectVector()
for i in xrange(all_scene_objects.get_count()):
obj = all_scene_objects[i]
if obj.is_remote():
remote_scene_objects.add(obj)

print("remote: {}".format(remote_scene_objects.get_count()))

# Populate 2nd group with the remote objects from the 1st group
# Filter = "SceneObject", Inclusion Rule = ""
group_remotes = ix.get_item("project://group_remotes")
group_remotes_mod = group_remotes.get_module()
group_remotes_mod.add_inclusion_objects(remote_scene_objects)

# Check for events to allow the group to update, otherwise get_gas might not work on the first call
ix.application.check_for_events()

# Force load remote geometries from 2nd group
group_remotes_mod.get_gas()


PS: when using the "code2" block tag, be sure to specify the language after the "=", for example "python" or "cpp" to enable syntax highlighting.

Edit: added call to ix.application.check_for_events()
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 282
Joined: Wed Jan 13, 2016 10:10 am

Re: Load reference objects of specific layer

Unread postby vishumish » Mon Feb 24, 2020 1:16 pm

Hi Anthony,

# We are using Clarisse 3.6 IFX SP10c x64 (Build showing 16th September 2019).
# Yes, as you suggested I have created two groups.
First with filter = "SceneObject", Inclusion Rule = "*"
Second with filter = "SceneObject", Inclusion Rule = ""

But the code you have sent didn't work. Following line is not adding geo in "group_remotes". I am not sure if there is a typo in add_inclusion_objects ("s" in objects) method. I tried removing that "s" though but it still not working.
Code: Select all
group_remotes_mod.add_inclusion_objects(remote_scene_objects)


I tried other ways of adding geo in "group_remotes" but nothing is happening when I called "get_gas()".

Your code is working pretty fine in clarisse 4. But we can't use it for now so please let me know if there is some working solution for clarisse 3.6.

Many Thanks!


P.s. : Also I think there is a typo in "add_inclusion_objects" method in version 3.6.
vishumish
 
Posts: 6
Joined: Mon Jan 27, 2020 11:38 am

Re: Load reference objects of specific layer

Unread postby anemoff » Mon Feb 24, 2020 3:48 pm

Hi,

add_inclusion_objects doesn't exist in 3.6. It was added in 4.0. Sorry about that.

However, you can use set_inclusion_objects(const CoreBasicArray<ModuleObject *>& included) instead. See doc link here.
But you'll have to provide a ModuleObjectVector instead of a OfObjectVector. See in the example below

You can also try adding a call to force_update_references() on both groups to force them to gather the objects.
1. on the 1st group: before iterating on current objects to filter remote ones
2. on the 2nd group: before calling get_gas()

Code: Select all
...
group_all_mod.force_update_references()

remote_scene_objects = ix.api.ModuleObjectVector() # using ModuleObject vector
for i in xrange(all_scene_objects.get_count()):
    obj = all_scene_objects[i]
    if obj.is_remote():
        remote_scene_objects.add(obj.get_module()) # get object module

group_remotes_mod.set_inclusion_objects(remote_scene_objects)
group_remotes_mod.force_update_references()
group_remotes_mod.get_gas()


I've tested on 3.6 SP10, in a simple project though, and get_gas() works and loads the geometries.
When are you calling your script?
Has the project finished loading?

It would be really helpful if you can send us a project that reproduces the issue so that we can investigate the real issue and provide a fix.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 282
Joined: Wed Jan 13, 2016 10:10 am

Re: Load reference objects of specific layer

Unread postby vishumish » Fri Feb 28, 2020 10:21 am

Hi Anthony,

Thanks for the suggestions. The fix is working in 3.6 now though the time it is taking to iterate through all the Geos in the scene is quite huge and we might not be able to use this.

For the bug report, there is a higher level discussion going on to find out what assets we can send without having any security compliance issue. Soon you will get to here something on this front.

Regards,
VM
vishumish
 
Posts: 6
Joined: Mon Jan 27, 2020 11:38 am

Next

Return to Scripting