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...
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.
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?
Well, I'm here to hear your advice to improve and simplify it. And to answer your questions, if you have any.
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