Isotropix Forums

Extracting negative scale values

Clarisse Scripting related topics

Extracting negative scale values

Unread postby jboissinot » Mon Jan 18, 2021 10:30 pm

Hi,

I'm having some issues with extracting the scale of a matrix when the object is set with some negative scale values.
In fact, for example, GMathMatrix4x4d.extract_scaling() returns (-1, -1, -1) instead of (-1, 1, 1) if the object scale values are set like: x=-1, y=1, z=1.

This applies when either of the three axes is set with a negative value and I'm getting the same wrong result with GMathMatrix4x4d.decompose().

Any idea why I'm not getting the proper scale values? From my findings, dealing with negative scale values seems to be a common known issue, so not sure if it's a bug, if I'm missing something, or if there is a way to get it properly?

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

Re: Extracting negative scale values

Unread postby anemoff » Wed Jan 20, 2021 4:58 pm

Hi Jeremy,

Extracting negative scales is indeed a known math problem, and GMathMatrix4x4d.extract_scaling is impacted by it.
Currently, the result is correct only if all scale values are positive or if they are all negative.

I'll see if there's a possible workaround or fix and come back to you.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 391
Joined: Wed Jan 13, 2016 10:10 am

Re: Extracting negative scale values

Unread postby anemoff » Thu Jan 21, 2021 2:56 pm

Actually, there's no magic solution. There's no unique answer to a given extracted scale vector. Multiple combinations of transforms can lead to the same final global matrix.

Here are some suggestions:
- If the extracted scale vector has 2 negative values, you can swap the sign of both negative values and compensate by adding a rotation of 180° on the axis that was already positive.
- If there are 3 negative values, you could swap 2 of them, but choosing which one remains negative is arbitrary.

It depends on what you need to do with the extracted scale vector, and which solution matches most of your use cases.
If you give us more details about what you are trying to achieve we might be able to suggest other solutions.

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

Re: Extracting negative scale values

Unread postby jboissinot » Fri Jan 22, 2021 12:48 am

Hi Anthony,

Thanks for looking into it and getting back on this.

To give you more details, we actually found out about this issue when rebuilding point clouds containing some instances that were using negative scales. Rebuilding a point cloud is done with a scatterer that uses extract properties for the rotation and scale whose values are extracted from the points matrix, while the position is driven by the points position of the particle container that is connected to the geometry support of the scatterer.
This is how we noticed that some of the instances were not matching basically.

If the extracted scale vector has 2 negative values, you can swap the sign of both negative values and compensate by adding a rotation of 180° on the axis that was already positive.

I did read about this and it seems to be automatically handled from my testing actually. In fact, if one or three axes use a negative scale, the matrix returns a negative scale vector (-1, -1, -1) and a negative determinant, while if two axes use a negative scale, the matrix returns a positive scale vector (1, 1, 1) and a positive determinant, and just compensate with a 180 degree rotation, and it does match, so no fix is needed in that case.

If there are 3 negative values, you could swap 2 of them, but choosing which one remains negative is arbitrary.

While investigating the issue and doing some tests, we actually realized that even though the instances of the baked scatterer were not matching with the original instances that were using negative scales, recreating them with a combiner by extracting the transform from the scatterer instance matrix did match after all.

With that in mind, and while exploring this a bit further, my plan would be to check if the determinant of an instance is negative when rebuilding the point cloud, and if so, extract the transform of the corresponding instance in the baked scatterer to eventually re-inject it in the rotation and scale extract properties that are connected to the scatterer to fix the instance transform, which may work and match with the original instance in the end.

This is something I'll continue to experiment but maybe you have other solutions to suggest as well.

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

Re: Extracting negative scale values

Unread postby jboissinot » Wed Jan 27, 2021 11:03 pm

Hi,

I just wanted to give you a heads up on this. Like I said in my previous post, recreating a combiner from an instance of the baked scatterer was matching with the original instance that has been baked into the point cloud.

Because the instance of the baked scatterer is generated with the translate, rotate, and scale vectors that are extracted from the point matrix and linked to the scatterer, my original plan was to therefore recreate such matrix from these vectors.

To do so, I tried to do it by using GMathMatrix4x4d.compose() but was basically getting back the exact same matrix of the point I extracted the transform vectors from, also tried to create the matrix by combining the set_translation(), set_rotation(), and set_scaling() methods, or even make_translation(), make_rotation(), and make_scaling(), but could not find a way to get the same matrix I was getting from the scatterrer instance somehow.

After testing this for a while and with no success, I finally got into exploring another solution and finally ended up using a dummy locator to get the right matrix. In fact, I set the transform vectors to a locator, get the matrix of the locator, extract the transform vectors of the locator's matrix and link them to the scatterer, which did work fine in the end.

While this is a working workaround, I would be curious to know if you think it'd be possible to achieve this without using a locator, like if there would be a way to recreate the scatterer instance from the transform vectors just by math?

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


Return to Scripting