Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

An update to Anim8or, v1.00b, is available with a few bug fixes. Get your copy HERE. See the "ReadMe" file for details.

Pages: [1] 2 3 ... 5

Author Topic: Old Magnet Tool  (Read 34051 times)

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Old Magnet Tool
« on: October 25, 2008, 05:47:27 pm »

I've rewritten all the scripts and I've released them in another topic:
Magnet Tools Package

Please refer to that topic for further discussion, thank you.

Consider this thread as locked.


[EDIT]
SCRIPT UPDATED: take a look to this post for the latest:
http://www.anim8or.com/smf/index.php?topic=1492.msg11109#msg11109
[/EDIT]


Hi all, that's my very first attempt at making a script. I've read somewhere that some 3D editors have a magnet tool. Honestly I never used one and I have no idea about the way it is intended to work, anyway, I tried to give a shot at it.

The idea by itself is simple, and the script I'm going to paste here below does compile without errors, but well, it simply doesn't work.

I took inspiration from the mirror script but I ended up with another way for exiting the script.

As with the mirror script, the CPU goes up 100% in my script, try it at your own risk.

I really don't know where I went wrong scripting, seems that moving the magnet shape around the screen doesn't make any difference, I think I'll have to debug it by outputting some values to a file.

As you will read in the code, only the first point of the "magnet" shape is used as reference. When this script gets fixed (if ever) it would be cool to use more than a point to model the "clay" shape, so that we could have some sort of "variable" magnet tool.


[EDIT]
I modified one line and actually now it works (well, no, it won't work as expected but it does work somehow).

Try this: add a large multifaceted sphere in an empty object, convert the sphere to a mesh and ensure it is named "mesh01", add another mesh and name it "magnet", then run the script. Moving around the magnet while the script is running will somehow modify the sphere.

The problem is that I am computing the distances checking each coordinate separately, which is too wrong... I'm trying to fix it.
[/EDIT]

[EDIT 2]
Cool! it works! and it's also quite easy to use... although it must be refined... try this, and notice that the script does not move the points as long as you keep the mouse button pressed to move the magnet. It does move the points only after that you release the mouse button. Enough for today, tomorrow I'll try to post a better version with some deeper instructions. Anyway, here below is the updated script, give it a try. The mesh "mesh01" must be centered at origin - for the moment...
[/EDIT 2]


/* magnet pseudo-tool
to stop the script change one of the shapes' names,
the while-loop goes on as long as both shapes are found */

#command("object");

shape $magnet;      /* shape named "magnet" */
shape $clay;        /* shape named "mesh01" */
point3 $clay_p;     /* clay point */
point3 $mag_p;      /* magnet location */
point3 $cur_p;      /* currently modified clay point */
float $distance;    /* actual distance between clay point and magnet location */
point3 $dist;       /* coord distances between clay point and magnet location */
float $min_dist;    /* min distance for modifying clay point */
float $max_dist;    /* max distance for modifying clay point */
float $step;        /* step of change */
int $continue;      /* flag for exiting the loop */
int $i;

$min_dist = 2;
$max_dist = 10;
$step = 1;
$continue = 1;

while ( $continue ) {
    $magnet = project.curObject.LookupShape("magnet");
    $clay = project.curObject.LookupShape("mesh01");
    if ( ($magnet != NULL) && ($clay != NULL) ) {
        $clay.Open();
        $mag_p = $magnet.loc;
        for $i = 0 to $clay.GetNumPoints()-1 do {
            $clay_p = $clay.GetPoint($i);
            $cur_p = $clay_p;       
            $dist.x = $mag_p.x - $clay_p.x;
            $dist.y = $mag_p.y - $clay_p.y;
            $dist.z = $mag_p.z - $clay_p.z;
            $distance = sqrt($dist.x * $dist.x + $dist.y * $dist.y + $dist.z * $dist.z);         
            if ( ($distance > $min_dist) && ($distance < $max_dist) ) {
                if ( $mag_p.x > $clay_p.x ) {
                    $cur_p.x = $cur_p.x + $step;
                } else {
                    $cur_p.x = $cur_p.x - $step;
                }
                if ( $mag_p.y > $clay_p.y ) {
                    $cur_p.y = $cur_p.y + $step;
                } else {
                    $cur_p.y = $cur_p.y - $step;
                }
                if ( $mag_p.z > $clay_p.z ) {
                    $cur_p.z = $cur_p.z + $step;
                } else {
                    $cur_p.z = $cur_p.z - $step;
                }
            }
            $clay.SetPoint($i, $cur_p);
        }
        $clay.Close();
        refresh();
    } else {
        $continue = 0; /* one or both shapes not found, exit loop */
    }
}


Use this script at your will of course, feel free to. By my side I think I'll have to get a firmer grasp on ASL before getting to work things correctly.
« Last Edit: November 20, 2008, 02:08:29 am by Francesco »
Logged

headwax

  • Sr. Member
  • ****
  • Posts: 600
    • View Profile
    • Headwax's Website
Re: Magnet Tool
« Reply #1 on: October 25, 2008, 10:20:44 pm »

It's seems like a great idea. But I think I need to be told how to use it :)
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: Magnet Tool
« Reply #2 on: October 26, 2008, 12:13:01 am »

Oh, yes... forgot to explain. I don't know exactly if it would be so easy to use.

The idea is like this: you add a simple mesh (a cube for example) to the object and you name it "magnet", then you run the script. The script checks if the points of your object (the mesh named "mesh01") are in the range of attraction of the magnet. The points that fall in this range are moved step by step toward the magnet.

In other words, moving the magnet shape close to the surface of your mesh (either in the inside or in the outside) you bump its points in and out - at least that's the idea.

Tomorrow I'll dig it further to see if I can make it work.

Thanks for your interest headwax.
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: Magnet Tool
« Reply #3 on: October 26, 2008, 12:19:20 am »

Oh well... (mumbling...)

I think that I've found where I mistaken my script. Moving the magnet shape around doesn't change the coords of its points, it changes the shape's displacement!

I'm on it, more to come.

[EDIT]
I've modified the script posted in the first message above but still it doesn't work as I expected, I'm on it again (eheheehh, I've managed to output some data to the console, debugging becomes simpler now ;) )
[/EDIT]
« Last Edit: October 26, 2008, 01:01:54 am by Francesco »
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: Magnet Tool
« Reply #4 on: October 26, 2008, 01:32:59 am »

Ok, seems I got a deeper grip, I managed to make it work, see the updated script in the first post. Sorry for this mess of messages. Tomorrow I'll post a refined version of this script.
Logged

kreator

  • Hero Member
  • *****
  • Posts: 1114
  • Anim8or, Blender, & Carrara. A Great Combination!
    • View Profile
    • Anim8orWorld
Re: Magnet Tool
« Reply #5 on: October 26, 2008, 09:53:45 am »

Nice little script there Francesco, It works now,  might need another routine within the body to "repel" as its a bit hit and miss.


Logged
O

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: Magnet Tool
« Reply #6 on: October 26, 2008, 11:08:15 am »

Thank you kreator, you gave me a good idea to further refine it, I'm on it and I'll post the result in a short while.
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: Magnet Tool
« Reply #7 on: October 26, 2008, 05:44:10 pm »

Here I am.

It came out quite a nice tool, please forgive me the autocelebration ;)

EDIT: I fixed the "all coords" part of the script and I have updated the zip file attached here. Details on the fix in this post.

WARNING: this script is experimental stuff and will make your cpu usage go up 100%, use this script at your own risk.

So then, here is the tutorial (well, sort of...):
http://francesco1978.altervista.org/magnet_tutorial.avi

and attached to this post there is a zip file containing the script, a project and four bitmaps.

I used the material of the magnet shape to switch between attraction and repulsion, and also to limit the coordinates influenced by the magnet. The bitmaps are used to clearly show the script mode used at each time.

The project contains all the materials used by the script and a flat face mesh to make some experiments if you like.

Sorry if it seems all a bit messy, in particular the video tutorial, but it was the first time I used wink to make one.

So then, take a look to the archive attached here below, opening the project file should automatically load the bitmaps too - assuming that you open the project file from its folder containing the bitmaps.

Some details in the scripts comments.

Happy anim8ing, feel free to ask if something isn't clear enough.

EDIT: Here are the instructions reported by the readme.txt file as well as by the script's comments:

Magnet Pseudo-Tool by Francesco

Requisites:
- work in object mode;
- there must be a mesh named "MAGNET";
- there must be a mesh named "mesh01";
- there must be one or more of the following materials:
    M_PULL, M_PULL_X, M_PULL_Y, M_PULL_Z
    M_PUSH, M_PUSH_X, M_PUSH_Y, M_PUSH_Z

Usage:
- apply one of these materials to the magnet (depending if you want it
    to attract or to repel the points of "mesh01", and depending on
    which coordinates you want to modify);
- start the script;
- move the magnet around your mesh to modify it;
- resize the magnet to change its range of action;
- change the material of the magnet (one of the above mentioned)
    to switch between attractive and repulsive magnet and to change
    the affected coordinates;

To stop the script (pick your choice, all of them work):
- change the magnet's material to a unused one (I use "M_NONE" for my ease);
- change one of the meshes' names;
- delete one of the meshes;

Hints:
- make your magnet a spherical one (a dodecahedron will be fine);
- make the M_ materials halfway transparent;
- work in flat shaded view;

IMPORTANT: DO NOT ROTATE THE MESH NAMED "mesh01", BECAUSE IT WILL
            MESS UP ALL THE SCRIPT'S EFFECT. You can translate it though,
            and you can freely rotate the magnet.

« Last Edit: November 02, 2008, 01:26:51 pm by Francesco »
Logged

Kubajzz

  • Flying Platypus
  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 548
  • Little doggie ate my avatar...
    • View Profile
Re: Magnet Tool
« Reply #8 on: October 26, 2008, 06:38:18 pm »

Great work Francesco!
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: Magnet Tool
« Reply #9 on: October 26, 2008, 07:11:08 pm »

Thanks Kubajzz, I wish I were good at using it too... maybe some modeller here can show its opportunities, although I admit it could be improved a lot...
« Last Edit: October 27, 2008, 12:05:45 am by Francesco »
Logged

neirao

  • Sr. Member
  • ****
  • Posts: 570
  • Neirao
    • View Profile
Re: Magnet Tool
« Reply #10 on: October 26, 2008, 10:34:32 pm »

Francesco VERY COOL SCRIP!!! CONGRATULATIONS!! ;)

I have two sugestions for Future using your script OK... ::)



and i think then is possible too... ::)




sorry my english ok?

Thank you for this script very cool!!
Logged

Francesco

  • Full Member
  • ***
  • Posts: 182
    • View Profile
Re: Magnet Tool
« Reply #11 on: October 26, 2008, 11:58:57 pm »

Hi Neirao, I'm very glad you liked it.

Although I didn't post in your topics I like very much your works, also the way you illustrate your ideas.

Also in this case your ideas are very nice, and actually they work sort of like the magnet script (just a bigger amount of computations, also because I fear that collision detection would be surface over surface and not point over point).

Maybe I'll take inspiration from them to improve the magnet script, but meanwhile I'd like to know the way you made all those examples... did you build them manually before rendering or did you use some other program's tools?

Just out of curiosity.

Thanks again, also to all the people that downloaded my work.

Logged

wedgehead

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Magnet Tool
« Reply #12 on: October 27, 2008, 01:59:07 am »

I'm a complete newb; I've got try it.
Logged

emuman4evr

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Magnet Tool
« Reply #13 on: October 27, 2008, 02:12:44 am »

Well I'm going to use this right away... tomorrow. I'm still anticipating the rise of an anim8or that can match blender. I'm using anim8or for animating and blender for modeling because anim8or is so easy and simple and blender has a lot more useful tools.
Logged

captaindrewi

  • Sr. Member
  • ****
  • Posts: 450
  • errm...errr?
    • View Profile
Re: Magnet Tool
« Reply #14 on: October 27, 2008, 02:36:10 am »

i'm having trouble finding the script and video
the link at the top takes me to the avi link and that link takes me to an italian site
with no obvious page to go to.
Logged
!
Pages: [1] 2 3 ... 5