# Anim8or Community

• December 06, 2013, 06:28:07 am
• Welcome, Guest

### News:

Pages: 1 2 3 [4] 5

### AuthorTopic: Old Magnet Tool  (Read 19630 times)

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #45 on: November 09, 2008, 12:43:19 pm »

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).
« Last Edit: November 09, 2008, 12:46:58 pm by Francesco »
Logged

#### Kubajzz

• Flying Platypus
• Global Moderator
• Sr. Member
• Posts: 548
• Little doggie ate my avatar...
##### Re: Magnet Tool
« Reply #46 on: November 09, 2008, 12:57:01 pm »

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: [Select]
`\$transformMat = \$YourShape.GetGlobalTransform();\$p = \$transformMat.Project(\$p);`
Logged

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #47 on: November 09, 2008, 01:51:35 pm »

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.
Logged

#### Claude

• Full Member
• Posts: 150
##### Re: Magnet Tool
« Reply #48 on: November 09, 2008, 03:16:30 pm »

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
Logged

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #49 on: November 09, 2008, 04:49:35 pm »

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.
« Last Edit: November 09, 2008, 04:58:02 pm by Francesco »
Logged

#### Claude

• Full Member
• Posts: 150
##### Re: Magnet Tool
« Reply #50 on: November 09, 2008, 06:33:20 pm »

Have you consider the possibility of using the tridata structure
instead of the meshdata structure.If it's possible,you wouldn't
have to ask the user to triangulate himself.True?

Just a suggestion.
Logged

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #51 on: November 09, 2008, 06:47:34 pm »

Thank you for the suggestion, is a really good one. Using the tridata will simplify the script too - I wasn't aware of this structure, I must have slipped on it in the specs.

Another note for who's interested in testing the polimagnet script: I've discovered that the script chokes on small meshes.
Scale up the magnet and mesh01 to avoid all those points left behind.
Logged

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #52 on: November 11, 2008, 05:39:47 pm »

That script is full of crap. I hope that none of you has actually, carefully read the code, you would be laughing at me for ages... the good new is that I'm getting a deeper knowledge of ASL, and hopefully a serious version of all this stuff will be available soon.

(if you noticed the square root and the weird "is this the same point of that other?" section, don't stare at me so surprised. You couldn't be more surprised than me when I realised those absurdities... never speak about trying to break a for-loop)
Logged

#### neirao

• Sr. Member
• Posts: 363
• Neirao
##### Re: Magnet Tool
« Reply #53 on: November 12, 2008, 02:06:01 pm »

Hi Francesco, forgive me for the delay in answering

i make somes tests using the last "Polimagnet_2_script.a8s",
in your project work, but in others meshes no...
it better works in objects with "tips"..but not manys...

My tests:

but i dont know if i make something wrong in timer of runner script...

For future too..

However congratulations for scripts!

I wait that it is improved more still in the future
therefore will be of great utility for us Anim8or Users!

Thanks you Francesco!

Neirao-Brazil
« Last Edit: November 12, 2008, 02:08:34 pm by neirao »
Logged

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #54 on: November 12, 2008, 02:50:43 pm »

Thank you very much for your experiments and for posting them Neirao.

The script has a serious bug that you can walk around by rotating both the mesh and the magnet and applying the magnet again.

You can safely put apart that script though, I'm almost done with the new version, which will be really more easy to use and hopefully also faster.

Thanks again Neirao, I really appreciate your support.
Logged

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #55 on: November 13, 2008, 02:38:53 pm »

Hi to all the people that keep an eye to this topic.

Here I am with another release of the polimagnet. It is quite different from the previous versions so let's take it step by step.

- You can use any kind of mesh as magnet (that is, you don't need to triangulate it).
- I merged the sphere-magnet script with the polimagnet script.
- I added a control panel that gets created by the script itself, and also the needed materials get created by the script (that is, you can use this script on a plain new project).

So, right after you run the script on an empty project you get the following objects...

Image 1:
A - Panel frame
B - Mono/Poli toggle
C - All-directions switch
D, E, F - single axis switches
G - Push/pull ratio slider (the triangle thingie)
H - One of the following: Range tool (in Polimagnet mode) Spherical Magnet (in MonoMagnet mode).

As it is, you get all the panel in "inactive state" (everything is gray), and actually the script is stopped.

Image 2:
K - a mesh named "MAGNET"
L - a mesh named "mesh01"

I, J - the gray sphere get changed into two spheres, one inside the other. The green sphere pushes, the red one pulls. The ratio between the two is set by the triangle-slider mentioned above.

OK, let's see how does it work.

While the script is running (remember that you need both "MAGNET" and "mesh01" to let the script run continuously) you can:
- move and rotate the panel frame (all the attached objects will be rearranged at the next refresh)
- switch all the toggles (just grab them and move them up or down, they will be aligned correctly at the next refresh)
- change the ratio between the push/pull spheres (again, grab the triangle thingie and move it left-right)

Notice how the Mono/Poli toggle and the All-directions switch are at the bottom of the panel. Now the script is in monomagnet mode and in all-directions mode.

When you grab and move around the red sphere, the green one will be moved accordingly. For your ease, you can select them both and move or scale them together (but don't group them, it wouldn't work).

The result of applying the red/green monomagnet to a sheet of triangles can be seen in images 5~8.

Now take a look at image 3. The script is in Polimode, and the blue sphere marked with M is the range of action of the polimagnet.

Before describing how the polimagnet & bluerange work (images 9~12), notice the difference in the panel from image 3 and image 4: although the XYZ switches are down and should be in green in image 3, they are superseded by the all-directions switch and thus they are in gray. In image 4 they are active (green) because the all-dirs switch is off.

(and remember that the all-directions mode is really different from the XYZ modes used together)

Now, maybe you recall that I complained about not being able to access the pivot's location, because I needed it to become the centre of projection for the polimagnet.

Now the center of projection is the center of the blue sphere. Also, only the points (of "mesh01") and the faces (of "MAGNET") that fall inside of this blue sphere will be considered while the script is running.

In other words, you can use complex meshes and apply the magnet only in selected areas, while most of the points and faces (those that fall outside of the blue range) will be quickly skipped.

The result of applying the magnet and the range at the sheet of triangles can be seen in images 9~12. Although that was a quick test with a simple magnet, the script should work fine on more complex meshes.

In the diagram you can see the idea implemented by the script. The points marked in green project on a magnet's face and lie between the face and the center of the range, then those points will be pushed till the magnet's face.
The points marked in red will not be touched (one of them doesn't project on a face, the other one does not fall between the center and the face).

Is this stuff too complicated?

Final note: don't tell me that the script code is messy. That's a 1K lines function, if you know what I mean, it has to be messy
Logged

#### neirao

• Sr. Member
• Posts: 363
• Neirao
##### Re: Magnet Tool
« Reply #56 on: November 13, 2008, 03:19:56 pm »

hi Francesco congratulations for new script

i try but no obtained make work..i think then i´m making something wrong...

is possible post the " FULL project.an8", in time for tests?

thanks

neirao
Logged

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #57 on: November 13, 2008, 03:49:16 pm »

The project wouldn't be of much use, all you need is in the script. Notice that the panel is put at coords (0 500 0), so you might have to hit F on the keyboard to adapt the view. I'm posting from my mobile phone right now, I'll add more hints later when I get back to my PC.
Logged

#### neirao

• Sr. Member
• Posts: 363
• Neirao
##### Re: Magnet Tool
« Reply #58 on: November 13, 2008, 05:42:24 pm »

I know the script make all the itens...i saw..

but after i maker the "MAGNET" and "mesh01" i run script again i dont obtained make the displace work of right way..(like your imagens samples).

i think then im is maker something wrong..

sorry my english..

« Last Edit: November 13, 2008, 05:46:29 pm by neirao »
Logged

#### Francesco

• Full Member
• Posts: 182
##### Re: Magnet Tool
« Reply #59 on: November 13, 2008, 06:46:15 pm »

I don't really know what's going wrong Neirao, did you put the blue sphere around the magnet and mesh01? As I described in the diagram, only the points and the faces that fall inside of the blue sphere are considered by the script. I admit that this is absolutely not an userfriendly tool - I'm not really making honour to the Anim8or philosophy.

I'm a bit stuck. I've made several trials but the only good thing I've been able to do is to use the red pulling sphere to move out the inner mouth from an highly detailed woman's head, after having cut half part away (see picture).

I'm working on another experiment, if I get it right I'll post it here.

[Edit: reading your post again I think I misunderstood it before. The script is running and is changing the points, but you don't get the result you expect. Well I think that for getting the result you expect you have to play with it a bit. If you don't mind, attach a project with the mesh that is giving you problems and I'll have a look, and thanks again for your attention and your interest Neirao. ]
« Last Edit: November 13, 2008, 06:56:20 pm by Francesco »
Logged
Pages: 1 2 3 [4] 5