General Category > ASL Scripts
Old Magnet Tool
Francesco:
Thank you Neirao, I'm looking forward to see your renders, I believe you tested my script properly ;-)
People, I'm lost. The math behind bringing a point to one coord system to another is easy to me:
mesh1_pt_in_mesh2_coords = mesh1_pt - mesh1_location + mesh2_location
and back:
mesh1_pt = mesh1_pt_in_mesh2_coords + mesh1_location - mesh2_location
But this way all gets messed up as I rotate something.
Now, from NickE's script I learnt that with this code...
$sourcerotmat = toFloat4x4($source.orientation);
$p = $sourcerotmat.Project($p) + $source.loc;
...I am bringing the point to world's coordinates taking care of the rotation. Fine. But the reverse? How can I bring it back to original source's coordinates?
Help me. I feel like I'm lost in a glass of water (a large one for me, currently).
Kubajzz:
I'm afraid it's not possible to convert point location from the world coordinates into the local mesh coordinates...
You can get the "mesh --> global" transformation matrix using the "GetGlobalTransform()" or "toFloat4x4" functions, but there's no way to get the reversed matrices.
btw. the "GetGlobalTransform()" function is easier to use than "toFloat4x4", because it converts both orientation and position:
--- Code: ---$transformMat = $YourShape.GetGlobalTransform();
$p = $transformMat.Project($p);
--- End code ---
Francesco:
Good idea using global transformation, but sounds strange to me that I cannot do the inverse process.
I'm on it, I think I found the solution.
Claude:
It's possible.You have to trick ASL into giving you the 16 elements of the matrix.Then,you calculate the inverse matrix
and apply it to the point coordinates.
Here's an example:
http://www.anim8or.com/smf/index.php?action=dlattach;topic=1309.0;attach=1725
Francesco:
Thank you for the hint Claude, I've come to the same solution in another flavour:
quaternion $mag_q, $clay_q;
$mag_q = $magnet.orientation;
$clay_q = $clay.orientation;
float4x4 $mag_rotmat, $clay_rotmat;
$mag_rotmat = toFloat4x4($mag_q);
$clay_rotmat = toFloat4x4($clay_q);
/* invert orientation quaternion for building inverse transformation */
$mag_q = ( -$mag_q.x, -$mag_q.y, -$mag_q.z, $mag_q.w);
$clay_q = ( -$clay_q.x, -$clay_q.y, -$clay_q.z, $clay_q.w);
float4x4 $mag_inv_rotmat, $clay_inv_rotmat;
$mag_inv_rotmat = toFloat4x4($mag_q);
$clay_inv_rotmat = toFloat4x4($clay_q);
...then...
/* translate clay point to magnet's coordinates */
$clay_p = $clay_rotmat.Project($clay_p) + $clay_l - $mag_l;
$clay_p = $mag_inv_rotmat.Project($clay_p);
...and back:
/* translate back clay point to clay's coordinates */
$clay_p = $mag_rotmat.Project($clay_p) - $clay_l + $mag_l;
$clay_p = $clay_inv_rotmat.Project($clay_p);
I attach the updated script here.
Now you can freely rotate the magnet or mesh01 while the script is running.
The single axis modes are (currently) tied to mesh01 axes, if somebody cares to know. I think I'll add an option for choosing the system onto which move the coordinates (clay's, magnet's or world's axes).
Thank you all for your attention and for your support, I really hope that you find this script useful, now that it's getting refined.
Reminder: the script still needs a well formed, all-triangle mesh as magnet.
If a magnet's face has more than three sides, only the triangle built on the first three edges is used; if a face is missing, points falling behind that face will not be pushed (nothing changes here respect to the first version of the polimagnet script, I've only added the ability to rotate the meshes).
The triangulate mesh script and the simplify mesh script are a must for using the polimagnet, thank you guys for sharing.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version