Isotropix Forums

Export point cloud with name and matrix properties

Clarisse Scripting related topics

Export point cloud with name and matrix properties

Unread postby corentin » Wed Nov 07, 2018 10:03 pm

Hey Guys!

I'm quite new in scripting and in scripting in clarisse too.
I started to work on a tool and it will be great to have your help on it!

The idea is to bake a pointcloud (from multiple scatterer in a context) with custom properties (name and matrices store in the properties).
I manage (by checking at your scripts post in the forum) to create the point cloud, init the properties, get the name and the matrices of each points but I'm stuck when it come to set the property (name and matrices).

python code

#selection/list context
contScan = ix.selection[0]

context = ix.get_item(str(contScan)) # Get your contexdt item from the path
items = ix.api.OfObjectArray() # This object will contain the items in the context
context.get_objects(items) # Fill the items variable

#create PTC and Context with right name
nameSplit = str(contScan).split("/")
nameCont = nameSplit[-1]

ctx = ix.cmds.CreateContext(str(nameCont)+"_bake", "project:/")
ptc = ix.cmds.CreateObject(str(nameCont)+"_ptc", "GeometryParticleContainer", str(ctx))

#position INIT
pos = ix.api.GMathVec3f()
t = ix.api.GMathVec3d()
positions = ix.api.GMathVec3fVector()

#properties to inject in ptc
xform = ix.api.ResourceProperty("xform")
name = ix.api.ResourceProperty("assetName")

#count ptc
nbInstance = 0

for i in range(items.get_count()):

cc = items[i]

if cc.is_kindof('SceneObjectScatterer'): #check if scatterer

scat = cc.get_module()
instance_count = scat.get_instances().get_count()
nbInstance = nbInstance + instance_count


for i in range(instance_count):

nameAs = str(scat.get_base_objects()[scat.get_instances()[i]].get_object().get_full_name()).split("/")

assetName = nameAs[-1]

#name.set_string(i , assetName) PART WHERE I WANT TOO FEED THE NAME IN THE POINT CLOUD

mat = scat.get_instance_matrix(i)

#for j in range(16): PART WHERE I WANT TOO FEED THE MATRIX IN THE POINT CLOUD
#xform.set_float(i, mat[j], j)


#get position for each point
ix.api.GMathMatrix4x4d.extract_translation(mat, t)
for j in range(3):
pos[j] = t[j]

positions.add(pos)

# init the properties
xform.init(ix.api.ResourceProperty.TYPE_FLOAT_32, 16, nbInstance)
name.init(ix.api.ResourceProperty.TYPE_CHAR, 1, nbInstance)



ix.api.IOHelpers.set_particles(ptc, positions)
properties = ix.api.ResourcePropertyArray(2)
properties[0] = xform
properties[1] = name
ix.api.IOHelpers.set_particles_properties(ptc, properties)
corentin
 
Posts: 5
Joined: Wed Nov 07, 2018 9:52 pm

Re: Export point cloud with name and matrix properties

Unread postby bvaldes » Thu Nov 08, 2018 12:28 pm

Hello,

I wonder something: why do you set the path in a property? This will not be usable by an extract property. You should work with IDs like the script on the shelf called Bake Scatterer.

The main issue of your script is that you initialize the properties too late. You can't use set_string or set_float to a property that's not initialized. You have 2 options: use a loop to get the instance_count() of all your scatterer then use a second loop to fill the data OR store the data in python list instead of the properties and then once the property initialized copy the data form python list to the property.

To set the minimum changes to your script, I will show you the second method:

python code

#selection/list context
contScan = ix.selection[0]

context = ix.get_item(str(contScan)) # Get your contexdt item from the path
items = ix.api.OfObjectArray() # This object will contain the items in the context
context.get_objects(items) # Fill the items variable

#create PTC and Context with right name
nameSplit = str(contScan).split("/")
nameCont = nameSplit[-1]

ctx = ix.cmds.CreateContext(str(nameCont)+"_bake", "project:/")
ptc = ix.cmds.CreateObject(str(nameCont)+"_ptc", "GeometryParticleContainer", str(ctx))

#position INIT
pos = ix.api.GMathVec3f()
t = ix.api.GMathVec3d()
positions = ix.api.GMathVec3fVector()

#properties to inject in ptc
xform = ix.api.ResourceProperty("xform")
name = ix.api.ResourceProperty("assetName")

nameList = []
xformList = []

#count ptc
nbInstance = 0

for i in range(items.get_count()):

cc = items[i]

if cc.is_kindof('SceneObjectScatterer'): #check if scatterer

scat = cc.get_module()
instance_count = scat.get_instances().get_count()
nbInstance = nbInstance + instance_count


for i in range(instance_count):

nameAs = str(scat.get_base_objects()[scat.get_instances()[i]].get_object().get_full_name()).split("/")

assetName = nameAs[-1]

# Store the name to the nameList
nameList.append(assetName)

mat = scat.get_instance_matrix(i)

# Store the matrix to the xformList
xformList.append(mat)

#get position for each point
ix.api.GMathMatrix4x4d.extract_translation(mat, t)
for j in range(3):
pos[j] = t[j]

positions.add(pos)

# init the properties
xform.init(ix.api.ResourceProperty.TYPE_FLOAT_32, 16, nbInstance)
name.init(ix.api.ResourceProperty.TYPE_CHAR, 1, nbInstance)

# Now that the properties are initialized, fill them with the data
for i in range(len(nameList)):
name.set_string(i, nameList[i])

# We have to the the matrix one by one so we have to split it.
# Because it's an array[4][4] we need 2 coords
# The count variable is to know the positin the the array[16]
count = 0
for x in range(4):
for y in range(4):
xform.set_float(i, xformList[i].get_item(x, y), count)
count += 1

ix.api.IOHelpers.set_particles(ptc, positions)
properties = ix.api.ResourcePropertyArray(2)
properties[0] = xform
properties[1] = name
ix.api.IOHelpers.set_particles_properties(ptc, properties)


You still have the issue about the path instead of the ID but maybe you have a reason to do it like this.
Best regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Export point cloud with name and matrix properties

Unread postby corentin » Thu Nov 08, 2018 3:34 pm

Great!
Yes I had to get the name of the asset and xform in the property to be able to rebuild the setdress in differents software.

Thks a lot for your help and quick response.
corentin
 
Posts: 5
Joined: Wed Nov 07, 2018 9:52 pm

Re: Export point cloud with name and matrix properties

Unread postby corentin » Thu Nov 08, 2018 3:52 pm

I have another related question:)
Can you export a abc file with the point cloud and properties on it??
corentin
 
Posts: 5
Joined: Wed Nov 07, 2018 9:52 pm

Re: Export point cloud with name and matrix properties

Unread postby stheroux » Thu Nov 08, 2018 4:11 pm

Hi Corentin,

I asked the same thing a few months ago
viewtopic.php?f=5&t=4982

Answer was no then. I don't think it changed since. We wrote our data out to a json file instead.

Sylvain
stheroux
 
Posts: 84
Joined: Thu Jan 15, 2015 9:23 pm

Re: Export point cloud with name and matrix properties

Unread postby corentin » Thu Nov 08, 2018 4:20 pm

Yep!
I just saw your post, that's quite problematic on our side...
I hope there will be an update.

Thks

Corentin
corentin
 
Posts: 5
Joined: Wed Nov 07, 2018 9:52 pm

Re: Export point cloud with name and matrix properties

Unread postby sam » Thu Nov 08, 2018 4:22 pm

Hi guys,

It's supposed to work but it doesn't. It's something that is currently being working on. It should be available in the next SP.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1419
Joined: Fri Jan 25, 2013 11:33 pm

Re: Export point cloud with name and matrix properties

Unread postby stheroux » Thu Nov 08, 2018 5:12 pm

Good news,
Thanks Sam.
stheroux
 
Posts: 84
Joined: Thu Jan 15, 2015 9:23 pm

Re: Export point cloud with name and matrix properties

Unread postby sam » Thu Nov 08, 2018 6:19 pm

While this is not directly related to the point cloud ABC export (which can be very useful to externalize particle containers for example), I'm not convinced that using an Alembic point cloud is the best approach to export Clarisse scatterers to rebuild the scene.

I think your custom JSON description is way more suited because you can describe hierarchy of scatterers and more.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1419
Joined: Fri Jan 25, 2013 11:33 pm

Re: Export point cloud with name and matrix properties

Unread postby corentin » Fri Nov 09, 2018 11:33 pm

Yes I know and with a JSON file we could decide how to rebuild our assembly (point cloud, asset layout, bounding box...) in any software. But right now we have to match how the export are currently done by the other departements. If you have an ETA for the next SP (I know that the last one was the 5th nov) dont hesitate to share it with us:D
corentin
 
Posts: 5
Joined: Wed Nov 07, 2018 9:52 pm

Next

Return to Scripting