PDA

View Full Version : How to Snap to a "Make Alive" polygon object just along Y axes


smoluck
12-12-2005, 12:28 PM
I like the Make live function.. that's pretty cool, but I want to use it by translate along Y a bunch of object and snap there on a displaced polyplane.

How I can force move just along Y axes ?

Emil3d
12-12-2005, 01:00 PM
Very easy.

Select all objects.
In the channel box Ctrl click on the names of the TranslateX and TranslateZ attribute.
From the Channels's menu choose Lock Selected.

smoluck
12-12-2005, 02:09 PM
No !!! I think you missunderstood my problem.

And I've already tried to use that tweaks to just move on live object by locking Tx and Tz value.

Imagine that you've sclupt a Polyplane with 20 by 20 for the subdivision. So now you'll get a landscape. Now You want to snap some trees shape on it. But you've already placed all you trees by using a Spread map (by usin an alpha map to spread trees in white area using a mel).

All trees get Ty = 0 and many different value on Tz Tx.
Now You want to Snap every tree along Y on the landscape shape, and preserve the Tx and Tz value after the Snap.

Emil3d
12-12-2005, 03:01 PM
Sorry, but now I’m more confused. May be posting a screen shot can help

cpan
12-12-2005, 03:12 PM
you don't need make live to do that :p
select the object you need to snap and then the surface and in the animation menu set choose Constrain>Geometry. Now the objects snaps to the surface and no mather what you do to it, it will stay on the surface. Move it on y to do what you want :)

smoluck
12-12-2005, 03:50 PM
ok I'll post a screenshot !

Here you can see my landscape in green, a Black and White plane who represent my spread map for the multiple instanced trees billboard. and Blue are all resulted Billborad who represent Trees.

Notice that my mel ( take on the web ) works in 2D not 3 d so I need to Snap Along Y all my trees on the landscape, so that's why i've think about make live tool.

http://skeeter.mot.free.fr/cgtalkupload/FTCPlacement/screen.jpg


Thanks to Nicool who help me with is own spread tutorial (http://ndhaussy.free.fr/maya_object_spreading).

To understand more my problem take a look at this past thread (http://forums.cgsociety.org/showthread.php?t=186817).

Emil3d
12-12-2005, 09:55 PM
Oh, now I see what you mean, and that’s a really a tough one, because I guess you want to avoid planting each tree billboard plane individually.

Aside from a mel solution that I’m not that good at to offer you, I think you may try dynamics with proper settings to drop all billboards over the plane or put a lattice around each forest and drop the lattice as a soft body on the plane. However no matter what you will use - dynamics, snapping or constrains, you will have one major problem with these billboards – their vertical orientation. Since you have a picture of a tree on each rectangular plane, you will want the plane to be slightly inserted vertically in the ground so that the stem of the tree starts from the ground, which will become a big problem on a hilly terrain.

If I were you, I will look for a mel solution help, and if not available I would simply put a lattice around each forest and manually model the lattice, either directly or with additional deformers to conform each forest to the terrain. This of course will introduce some vertical skewing, but I don’t think it will matter in your case.

smoluck
12-13-2005, 07:30 AM
to Yashu:

I've tried to use a geometry constraint but the problem that I assign multiple Target when I select First the landscape and after all the billboards. And the other problem was that Tx and Tz change slightly.

So I can't choose the constraint solution.

And dynamics will be too slow workflow to achieve.

I think there is a way to use a mel script to doo that , but I've not enouth skills to do that !

Please I need help. Mel scripting will be a solution. Should we can use the 16bits Tiff file to translate all my billboards in Ty ?

smoluck
12-13-2005, 10:05 AM
Ok, by popular request, Damien Courtois (my Lead Programming enginner) modified the Nicool MapSpread melscript.

He add the third dimension for that scatter script. Now you can use a 16 bit Tiff file in order to snap all object on a displaced landscape geometry. So now the script works fully in 3D, and helps you create a wonderfull landscape with trees spread on valley, hills and mountain. I suggest you to use Terragen or Maya to create distribution map by define Min/max Altitude, Min/Max Slope.

here the new Code; and for those who wants to download it here (http://skeeter.mot.free.fr/cgtalkupload/FTCPlacement/mapSpread_heightMap.mel):


/*
.oO mapSpread by Nicolas d'Haussy Oo.
This melScript spread randomly objects in 2D function to a texture map (has a photo taken from a plane).
Design the texture the way you want to spread your object. For instance : a forest crossed by a river.
.oO mapSpread parameters Oo.
objectToBeDuplicated : name of the object you want to spread (by giving the quotes "myTree").
objectsNb : number of object you want to spread.
map : texture map name (by giving the quotes "myTexture").
threshold : a value between 0 and 0.99 (Determines the contrast).
scale : just so as to scale placement (let tweak).
.oO Notes Oo.
Example of use : type it in the command line "mapSpread("pSphere1", 250, "file1", 0.9, 30)" (after having sourcing this script).
("pSphere1" is the name of the TRANSFORM of the object, not the shape)
Does not support layered texture directly. Convert it to file texture.
For Maya 4.5 and higher (reason : colorAtPoint function required).
USE OR MODIFY THIS SCRIPT AT YOUR OWN RISK - FOR NON-COMMERCIAL USE ONLY.
*/
/*
Modifications added by Damien Courtois (programming) by request from Franck Elisabeth (CG artist):

-- PARAMETERS --
- $instanced: If this parameter is set to 1, then the command `instance` is used. If 0, then `duplicate` is used
- $heightMap: Like $distributionMap is a map of distribution, $heightMap is a height map ^^ Instead of spreading
at y = 0, it speads depending on the heightmap
- $minHeight: It's the min height of the heightmap. A black pixel will be at this height
- $maxHeight: It's the max height of the heightmap. A white pixel will be at this height

-- NOTES --
Now, the distribution map is centered on the origin. It means that if the distribution map is full white, and has a
scale of 512, then the selected object will be duplicated in ranges from -256.0 to +256.0, instead of 0.0 to 512.0
as it initially was.
To reverse at it was, simply set $centerX and $centerY to 0.
ex: mapSpread ("name of object(transform)", number of copies (Density), Simple copies (0) or Instanced copies (1), "name of the texture file node for the DistributionMap", search threshold, scale of the surface landscape (need to be a square), "name of the texture file node for the HeightMap, Min altitude, Max altitude)
ex: mapSpread ("ArbresAtlas_04_FTC_1", 500, 1, "fileDistribution", 0.9, 5120, "FileHeightmap", -20, 185)
*/
global proc mapSpread (
string $objectToBeDuplicated,
int $objectsNb,
int $instanced,
string $distributionMap,
float $threshold,
float $scale,
string $heightMap,
float $minHeight,
float $maxHeight
)
{
// Start message
if (`exists colorAtPoint` != 1)
error "Cannot process because \"colorAtPoint\" MEL function does not exist.\n";
// check $threshold validity
if ($threshold > 0.99)
{
$threshold = 0.99;
print("Threshold corrected to 0.99 (To prevent error).\n");
}
// info message
print("\n\nProcessing started from the " + nodeType($distributionMap) + " texture called : \"" + $distributionMap + "\".\n");
waitCursor -state on;
// to center on the origin. Set to 0 distribute from 0 -> $scale.
int $centerX = $scale / 2.0;
int $centerY = $scale / 2.0;
int $objectsCount = 0;
while($objectsCount < $objectsNb)
{
// Get random values for placement
float $randomU = `rand 0 1`;
float $randomV = `rand 0 1`;
// Analyse the map color at this point
float $alphaLevelAtPoint[] = `colorAtPoint -o A -u $randomU -v $randomV $distributionMap`;
// Check if the object can exist
if($alphaLevelAtPoint[0] >= $threshold)
{
// An object can be created here. So place it.
float $x = $centerX - $randomU * $scale;
float $z = $randomV * $scale - $centerY;
// copy or instance the object
string $duplicatedObject[];
if ($instanced == 1) $duplicatedObject = `instance $objectToBeDuplicated`;
else $duplicatedObject = `duplicate $objectToBeDuplicated`;
// get the height from the heightmap
float $height[] = `colorAtPoint -o RGB -u $randomU -v $randomV $heightMap`;
float $y = $minHeight + $height[0] * ($maxHeight - $minHeight);
// place the newly duplicated object
move -rpr $x $y $z $duplicatedObject;
// Count one more object
$objectsCount++;
}
}
// End message
waitCursor -state off;
print("Process successful : " + $objectsCount + " objects placed.\n\n");
}


After 3min:40 for 3000 trees you will be satisfied I think ! :thumbsup:

Some screenshots of the scene will come wen my FTP will be up.

GennadiyKorol
12-13-2005, 11:04 AM
Hi :) Well, there could be some other possible solutions aside mel. For one I'd try using particles with instancer, emmiting the "trees" from a textured nurbs plane with "emit texture" on. Then I'd collide them with a landscape with a high friction, so that they will not slide. You can add per particle attributes and supply different models of the trees to different particles, scale them randomly rotate, etc etc.

The other solution could be is: Copy your landscape, flatten out the copy, ie scale 0 in y axis. Now position your trees over the flattened version of the landscape. Now attach the trees to a flat landscape with a wrap deformer. Now the most interesting - add a blend shape to the flat landscape, as a target take your "volumed" landscape, and set the weight of the target to 1. The trees should rise together with your geometry. You should play with some settings for the wrap, to make the best deformations. Another variation of this would be to create a lattice aroud each group of the trees, and attach the lattices with a wrap to the landscape. Or even something different, following this idea you can scatter anything you want actually :) Anyways I'd first try the particles solution, it would allow some easy randomizing, model substitution i.e better modularity.

Anyways hope this gives you some ideas if it's not late:)

Cheers:)

Emil3d
12-13-2005, 12:56 PM
Franck, thanks for sharing the script.

Brilliant suggestions Henry, especially the blend shapes of the wrap deformer. It is as simple as making a blend shape between a copy of the terrain extruded up to the height of the trees and a flattened copy of it used is a wrap deformer of the trees.

About directly using on a rough terrain the particles solution, dynamics, and for that matter may be the script, I think, as I mention in my previous message, that there will be a problem with the fact, that each billboard plane, depending on the terrain has to be inserted, to some degree in the ground. Of course this can be compensated by images of trees with very long stems and just moving all the trees down and it will work OK for a terrain that is not very rough, but for a very rough terrain with a lot of steep hills and vegetation with short or no stems like bushes this will become a problem if a lot of individual adjustment is required.

So I think for cases like that the best would be to apply your first suggestion with the particles on a flat terrain and then raising the trees by the use of a blend shaped wrap deformer.

smoluck
12-13-2005, 03:28 PM
yes Mr Hawk! Blend Shape wrap suggestion would be fine.

Personnaly I prefer my melscript because it's easy to duplicate and place at one time all my trees succesively. The random Scale was already done by an old melscript, who define min and Max value. So the random rotate isn't needed because all the billboard where in Face To Camera.

PS: Elisabeth was my surname... so call-me Franck :D

Emil3d
12-13-2005, 04:20 PM
... so call-me Franck :D
Fixed. Sorry, I should have read more carefuly

CGTalk Moderation
12-13-2005, 04:20 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.