Isotropix Forums

Getting color data of scattered combined instances

Clarisse Scripting related topics

Getting color data of scattered combined instances

Unread postby jboissinot » Sat Jun 27, 2020 7:48 pm

Hi,

I'm looking for a way to get the color data of scattered combined instances and will use a simple example to describe what I'm actually trying to achieve.

Let's say, I have a combiner that contains a cube geometry, and I scatter this cube combiner with a scatterer A and a point array of 4 points, and also apply an instance color material connected to a black/white checkerboard texture map that drives the color of all instances so that I get 4 instances of that cube combiner, 2 with black color and 2 with white color.

Now, I connect the result of this scatterer A as a source geometry of another scatterer B that is also linked to another point array of 4 points. So, in the end, I get a total of 16 instances of the cube combiner that all either use the black or white color.

So here is my question here, because we're having basically 4 instances of the cube combiner per point of scatterer B, how can we get the color data of each instance with evaluate_texture_vertices() as we need to get the point that drives the instance position to evaluate the color of that point and therefore the instance?

With that in mind, the way I approached it was to create a point and set its position with the global matrix of the instance so that I could get the color data of that point. That would technically work, but I'm kinda blocked as I created a GeometryPointCloud object and not quite sure how I could get a ModuleGeometry or ModuleParticle object from it that I could then pass to the evaluate_texture_vertices() method. Maybe I would need to create a sort of dummy geometry with the scripting API - not in the scene - and then potentially connect that point cloud I created to the geometry object as its support.

Anyway, while I still need to investigate it a bit further, I was curious to get some thoughts on this and see if that would actually be possible.

The example I used is quite similar to what we can see in the first part of the following tutorial video if that can help to get a better idea:
https://www.youtube.com/watch?v=elyu_xttAVA

Thanks,
Jeremy
jboissinot
 
Posts: 79
Joined: Tue Jan 29, 2019 10:36 pm

Re: Getting color data of scattered combined instances

Unread postby nguiard » Mon Jun 29, 2020 3:32 pm

Hi Jeremy,

jboissinot wrote:With that in mind, the way I approached it was to create a point and set its position with the global matrix of the instance so that I could get the color data of that point. That would technically work, but I'm kinda blocked as I created a GeometryPointCloud object and not quite sure how I could get a ModuleGeometry or ModuleParticle object from it that I could then pass to the evaluate_texture_vertices() method. Maybe I would need to create a sort of dummy geometry with the scripting API - not in the scene - and then potentially connect that point cloud I created to the geometry object as its support.


You need to create an object of class GeometryParticleContainer and then use the following methods to setup it:
ix.api.IOHelpers.set_particles()
ix.api.IOHelpers.set_particles_properties()

You can have a look at the script we ship with Clarisse which bakes a scatterer (the last one of the scattering section in the shelf). You just have to drag & drop it in a Script Editor window to view it.

However, I fear that what you are trying to achieve is pretty complicated. Because this will work only if your texture uses world coordinates. I'm not sure it's possible to write a script that will work in all cases because it's hard to predict what textures are doing internally.

Hope it helps.

Cheers
Nicolas Guiard
Isotropix
Head of R&D
User avatar
nguiard
 
Posts: 399
Joined: Fri Jan 25, 2013 11:33 pm

Re: Getting color data of scattered combined instances

Unread postby jboissinot » Tue Jun 30, 2020 5:46 pm

Hi Nicolas,

I'm actually quite familiar with the Clarisse bake that helped to create some custom bake and point cloud rebuild tools for example, and I'm already using a particle container to bake the instances into points and their properties as well.

Because ModuleParticle and ModuleGeometry inherit from ModuleSceneObject class, I assume that we can't really access to such modules without creating a scene object, right? This actually refers to one of the questions I had as I was wondering if it's possible to create objects with the scripting API only, not in the scene, for doing this kind of things.

So, while exploring this further and by following what you suggested, I therefore created another particle container that I simply use to store one point that I set its position with the translate extracted from the instance global matrix. This is working as I have all the info I need to evaluate the texture on the vertex, even though I don't seem to get the proper color value for all instances from my testing. So, I may need to do more tests to investigate a bit more and get back to you on this.

Because this will work only if your texture uses world coordinates.

Do you mean that this won't likely work if the texture uses UV coordinates even though we connect a TextureSupportColor to the instance color node?

Thanks,
Jeremy
jboissinot
 
Posts: 79
Joined: Tue Jan 29, 2019 10:36 pm

Re: Getting color data of scattered combined instances

Unread postby nguiard » Wed Jul 01, 2020 8:31 am

Hi Jeremy,

jboissinot wrote:Do you mean that this won't likely work if the texture uses UV coordinates even though we connect a TextureSupportColor to the instance color node?


This will work if you evaluate the texture on the original point cloud that has been used as support of your scatterer.
But it won't work on a point cloud you have created on your side because it won't contain any information regarding a support surface on which it has been generated. The TextureSupportColor node is accessing data stored in the point cloud to know the ID of the primitive and the UV on this primitive which each point is attached to. It actually works only with our point cloud generator which takes a support as input.

Cheers
Nicolas Guiard
Isotropix
Head of R&D
User avatar
nguiard
 
Posts: 399
Joined: Fri Jan 25, 2013 11:33 pm

Re: Getting color data of scattered combined instances

Unread postby jboissinot » Wed Jul 22, 2020 10:04 pm

Hi Nicolas,

I finally had the chance to investigate this further and do more tests to eventually find out that something was actually wrong in the recursive process that was parsing objects to get the instance global matrix, which explains why I was not getting the correct color value.

So, I revised it and just wanted to let you know that this now works fine as I do get the proper color values of combined instances, with the dummy point creation approach that I described previously.

That's good, even though I may refine this later by getting it directly from the original point that drives the color of an instance as you suggested.

Thanks,
Jeremy
jboissinot
 
Posts: 79
Joined: Tue Jan 29, 2019 10:36 pm


Return to Scripting