Isotropix Forums

Getting global matrix of scatterer instance

Clarisse Scripting related topics

Getting global matrix of scatterer instance

Unread postby jboissinot » Mon Sep 16, 2019 11:03 pm

Hi,

I was curious to know what would be the best way of getting the global matrix of a scatterer instance when its source combiner uses custom transform values for example.

Let say I got the matrix of the instance and the matrix of its source combiner, and I basically multiply both to get the global matrix of the instance:

Code: Select all
instanceMatrix = scatterer.get_module().get_instance_matrix(i)
combinerMatrix = combiner.get_module().get_global_matrix()

globalMatrix = ix.api.GMathMatrix4x4d()
globalMatrix.multiply(globalMatrix, instanceMatrix, combinerMatrix)


This works fine while the following syntax might be more accurate though:

Code: Select all
ix.api.GMathMatrix4x4d.multiply(globalMatrix, instanceMatrix, combinerMatrix)


Anyway, I was wondering if the order between both instance and combiner matrices could affect the result, and if this is a good way of doing it, or if there'd be a better way?

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

Re: Getting global matrix of scatterer instance

Unread postby KevinC » Thu Sep 19, 2019 10:17 am

Hello,

Sorry for the late reply.
When multiplying matrices the order always matter.
I did a script that compute the final matrix of the object that is in a combined scatterer and use this matrix to set the position of a custom object.
You can find the project in the attached file.

python code

#Get the combiner
combiner = ix.get_item("project://scene/combiner").get_module()

#Get the scatterer
scatterer = ix.get_item("project://scene/scatterer").get_module()

#Get the red box that will be placed to the instance we want
red_box = ix.get_item("project://scene/red_box").get_module()

#Get the combiner global matrix
combiner_matrix = combiner.get_global_matrix()

#Get the scatterer global matrix
scatterer_matrix = scatterer.get_global_matrix()

#Instance we want to extract the matrix from
#Here we could check if instance_id < instances count
#scatterer_instances = scatterer.get_instances()...
instance_id = 15;
instance_matrix = scatterer.get_instance_matrix(instance_id)

#Create global matrix of the instance in the scatterer
#RESULT = scatterer_matrix * instance_matrix (order matter)
scatterer_instance_matrix = ix.api.GMathMatrix4x4d()
scatterer_instance_matrix.multiply(scatterer_instance_matrix, scatterer_matrix, instance_matrix)
#you could also use this syntax
#ix.api.GMathMatrix4x4d.multiply(scatterer_instance_matrix, scatterer_matrix, instance_matrix)

#Create the CombinerInstance matrix
combiner_instance_matrix = ix.api.GMathMatrix4x4d()
combiner_instance_matrix.multiply(combiner_instance_matrix, combiner_matrix, scatterer_instance_matrix)

#Set matrix to the cube
red_box.set_matrix(combiner_instance_matrix, ix.api.ModuleSceneItem.SPACE_GLOBAL)


Hope it helps,

Kevin
Attachments
python_sactterer_combiner_matrix.project
(122.02 KiB) Downloaded 15 times
User avatar
KevinC
 
Posts: 30
Joined: Wed Jan 13, 2016 12:26 pm

Re: Getting global matrix of scatterer instance

Unread postby jboissinot » Mon Sep 23, 2019 2:32 pm

Hi Kevin,

My plan was actually to get the scatterer matrix as well in addition to the combiner matrix, so thank you for explaining the steps and matrix orders to get it properly.

That being said, I was just curious to know why the matrix order matters for a simple matrix multiplication though? Is it a general matrix rule or a Clarisse API design thing?

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

Re: Getting global matrix of scatterer instance

Unread postby KevinC » Mon Sep 23, 2019 2:38 pm

Hello,

Yes it is a general rule for the matrix.

You are welcome,

Kevin
User avatar
KevinC
 
Posts: 30
Joined: Wed Jan 13, 2016 12:26 pm

Re: Getting global matrix of scatterer instance

Unread postby jboissinot » Mon Sep 23, 2019 11:11 pm

Ok good to know, thanks again!!

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


Return to Scripting