Anim8or Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Ian Ross has just released a book on Anim8or. It's perect for a beginner and a good reference for experienced users. It contains detailed chapters on every aspect, with many examples. Get your own copy here: "Anim8or Tutorial Book"

Pages: [1] 2

Author Topic: Script: Copy "Source" mesh to "Target" mesh  (Read 27870 times)

NickE

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Script: Copy "Source" mesh to "Target" mesh
« on: June 25, 2008, 01:35:42 pm »

Attached below are parametric and non-parametric versions of a script that maps copies a "source" mesh to a "target" mesh's points.  It is similar in capability to the Mongoose's awesome GrassGen application.

The parametric and command versions of the script are different in the following ways:
1)  The command version creates a separate mesh for each copy, while the parametric version is all one shape.
2)  The command version has one more parameter because parametric scripts are apparently limited to 10 parameters.

To use, you must have an object that contains a mesh named "source" and another mesh named "target".  If you are using the command (non-parametric) version, you must edit the script to adjust the parameters, then Scripts->Run Script File.  If you are using the parametric version, just click on the "Mesh Source to Target" icon, then click (or click-drag).

The parameters that can be changed are:

1) The fraction of target mesh points to use: 0 to 1
   Anything less than 1 uses a random distribution of points
2) Min and Max Copies per mesh point: 0 to 100
   In the parametric version, there is only the max parameter.  If max is greater than 1, it will produce a random number from 1 to max for each target mesh point.  In the command version, you can set the minimum.
3) Min and Max Scale: 0 to 100.
   If the min and max are not equal, it will produce a random distribution of scales between min and max.
4) Fixed rotation x,y,z:
   Rotates the copies a fixed amount
5) Variable rotation x,y,z
   This will produce a random rotation plus or minus half the amount entered added to the fixed rotation amount in (4).

The lowest y-point on the copy of "source" will correspond to the "target" mesh point.

Open up the scripts in a text editor to see further documentation.

If you are creating many copies, it may appear to be locked up.  The Debug Output console shows some stats during execution as well as dots showing progress.  You can look here to see if it is locked up or just bogged down with zillions of points and faces.

*** Remember to convert the parametric shape to a mesh before using it in any other objects, in figures, or scenes.  It is totally dependent on the original "source" and "target" objects while it remains a parametric shape.  As Steve stated: parametric scripts were never intended to work this way. ***

Attached are examples of the script in use.

Please let me know your feedback.
Logged

hihosilver

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1294
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #1 on: June 25, 2008, 01:52:54 pm »

This is awesome NickE!
I simply love all the scripts you've produced.  They will prove very useful.  Now I have a very useful way to create things such as grass randomly and nicely.

Now, I have one request.  Would it be possible to have an option where the object goes outward in the direction of the vertices normal? (If anim8or can't get vertice normals, you can average the connected face's normals.)  Or, perhaps have a script where it scatters the objects over the face instead of the vertice? (This one isn't as needed but could be useful so that I don't have to create a high poly mesh when I want to create a lot of grass or fur or something.
As I said before though, this is an amazingly awesome script.  Keep up the good work!
Logged

NickE

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #2 on: June 25, 2008, 02:04:51 pm »

I have already started trying to figure out how to orient the copies along the normals of the mesh point.  Hopefully, I will have that figured out soon.  It should be fairly straightforward to scatter objects across the faces.  I'll look into it.
Logged

kreator

  • Hero Member
  • *****
  • Posts: 1146
  • Anim8or, Blender, & Carrara. A Great Combination!
    • View Profile
    • Anim8orWorld
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #3 on: June 25, 2008, 02:13:57 pm »

Hats off to you NickE ... another wicked script!.....
Logged
O

Steve

  • Administrator
  • Hero Member
  • *****
  • Posts: 2124
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #4 on: June 26, 2008, 01:59:10 am »

Guys, please!  These scripts may stop working in the near future.  I ask you to not reference outside meshes in parameteric scripts.  That is not a valid operation!

Parameteric scripts are designed to depend only on their parameters, no outside values of any kind.  Anim8or is simply not designed to make that work consistently.
Logged

kreator

  • Hero Member
  • *****
  • Posts: 1146
  • Anim8or, Blender, & Carrara. A Great Combination!
    • View Profile
    • Anim8orWorld
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #5 on: June 26, 2008, 03:07:07 am »

oh dear all that work NickE and they might not work in the future... I think I`ll hold onto 0.97B ... so that it continues to give me the tools that I need...... ;D

any progress with attached objects in scene mode ..... assume that would need to be done with controller script
« Last Edit: June 26, 2008, 03:09:15 am by kreator »
Logged
O

hihosilver

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1294
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #6 on: June 26, 2008, 05:01:22 am »

Luckily he provides a non-parametric script as well.  Sorry if it's stepping over the bounds here!  I hope you can provide a way to access outside meshes.
Logged

NickE

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #7 on: June 26, 2008, 09:13:35 am »

Steve and everyone,
I will always write a command version and a parametric version, knowing that the parametric version will probably stop working at some point. With only ten parameters to work with, and larding all the points into a single shape, you are limited in what you can do in a parametric script.
Logged

NickE

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #8 on: June 26, 2008, 10:03:41 pm »

Attached is an updated and expanded version of the script.  Following Steve's wishes, there is only a command version of the script.  To use the script, you must edit it with a text editor to change the parameters.  First, create a mesh named "target" to be the template where the "source" will be copied.  Create a mesh called "source" to be copied onto the "target" mesh.  The script is very highly documented, so you can always look at it in a text editor to see how it is constructed as well as the parameter explanations below.

Parameters:
1) Fixed rotations of the copies around the x, y, and z axes [xabsrot,yabsrot,zabsrot]
2) Variable rotations of the copies around the x, y, and z axes.  The variable rotations are random up to half the amount entered plus or minus the Fixed rotations in (1) above.[xrot,yrot,zrot]
3) Fraction of available copy positions to be used.  If you enter 1.0, all available copy positions are populated.  If you enter less than 1.0, that fraction of the points will be randomly distributed. [meshptfraction]
4) Number of copies per available copy position.  This can be a random number between a minimum and the maximum per copy position or it can always be the maximum number. [minusemesh,maxusemesh,usemeshrand]
5) Scale of each copy.  This can be fixed at some value or random between a minimum and maximum.[minscale,maxscale,scalerand]
6) An offset to allow you to "sink" the copy into the surface of the target.  It is entered as a fraction of the total y-axis length of the "source".[yoffsetfraction]
7) Set the original orientation of the copies to be either straight up and down along the y-axis or normal to the surface of the mesh at the copy position.[usenormals]
8) Set whether to use the unrotate "source" y minimum point as the attachment point to the "target" mesh or to use the new calculated y minimum point after all the rotations.[useorigmin]
9) Set the copy positions to be the vertices (mesh points) of the "target" mesh.[useverts]
10) Set the copy positions to be on the faces of the "target" mesh.  If this is set, there will the number of sides of the face of the "target" mesh plus one: one in the center, and one each between the center and the vertices of the face.[usefaces]
11) A random seed to alter the random elements above.  If you leave this the same, each time you run script you will get the same distribution of random numbers.[the integer in parenthesis of randseed]

To achieve the highest density for fur, hair, or grass, set the variable rotation, a relatively high number for maxusemesh, use the vertices and the faces.  If you have a curved surface for the "target", use normals to have the copies point directly away from the faces and vertices instead of straight "up".

Enjoy!

I'd love to hear your feedback and suggestions.




« Last Edit: June 26, 2008, 10:56:10 pm by NickE »
Logged

hihosilver

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1294
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #9 on: July 12, 2008, 01:02:16 pm »

As before, this is an awesome script, and I have a request for it.

I'm wondering if there would be a way to have the script assign materials to a mesh, as in, an option to have the material already assigned to the mesh, or have the material of the face the mesh is assigned to (this may not work with having them come out of the vertices... perhaps an average and figure out which material or something.)  I think it could be great though, especially with creating fur or something.  Just an idea, not sure if it's possible.
Logged

NickE

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #10 on: July 12, 2008, 11:35:28 pm »

I don't understand your request.  The script currently assigns the materials and UV coordinates of the source to all the copies.  Are you talking about assigning materials of the source to the target mesh?  Or are you talking about the materials of the target mesh being assigned to the copies of the source?  Either of these can be done.

If you could explain further, I will see what I can figure out.
Logged

hihosilver

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1294
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #11 on: July 14, 2008, 03:45:02 am »

I'm talking about using the target's material and applying it to the copies of the source.  So, for example, one face on the target mesh has a green material, so all instances of the source on that face would have the green material.  Then whatever was on the red face would have the red material.  That's the idea.  So I could do things like create great fur for the tennisball I created simply and not have to worry about it all becoming green, or splitting objects, running the script, applying materials, then running again, etc.
Would this be possible?
Logged

NickE

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #12 on: July 14, 2008, 10:35:50 am »

The transferring of the target's material at the point of the copy to the copy of the mesh is possible and I will work at putting out an updated script for that.  Keep in mind, though, that textures and UV coordinates will likely not transfer to the mesh copies predictably.
Logged

NickE

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #13 on: July 14, 2008, 03:17:20 pm »

It turns out that adding hihosilver's request to the script was more straightforward that I originally thought.  Attached below is an updated version of the script.  For comprehensive instructions on how to use the script see post above:

http://www.anim8or.com/smf/index.php?topic=906.msg6668#msg6668

plus:

12) Set the copies to use the original source mesh's materials and UV coordinates, or set the copies to use the target's materials.  If you choose to use the target's materials then the copy will take on the color of the target at the attachment point.  This is also true if the target's material at the attachment point is a texture.  It calculates the UV coordinate at the attachment point and assignes that UV coordinate to the whole copy.[usesourcemat].

Below are some examples of this new feature in action.  The first picture is simply a plane mesh with a cheetah skin texture on it.  The second picture shows the cylinder copied onto the cheetah textured plane.  It picks us the color from the texture and copies it to each individual copy of the source.  The third picture show how it will pick up simple color material and copy it to the individual copies of the source.

As always, your feedback is welcomed!
« Last Edit: July 14, 2008, 07:45:18 pm by NickE »
Logged

headwax

  • Sr. Member
  • ****
  • Posts: 600
    • View Profile
    • Headwax's Website
Re: Script: Copy "Source" mesh to "Target" mesh
« Reply #14 on: July 14, 2008, 11:54:25 pm »

Hya Nick

I had a play with your script yesterday (not the new version) and it is fantastic!

The possibilities are endless. (Well almost endless)

Thanks again

headwax
Logged
Pages: [1] 2