PDA

View Full Version : Spread objects over another by using an image map


johnjoe
12-11-2008, 07:43 PM
I've got a script that does a fairly good job at duplicating a individual object and spreading it over another but I'd like to take this further if it's possible??

What I'd like to do is only populate a selected area by using an image to dictate/mask the chosen area. I have had a go at using the colorAtPoint command but it doesn't quite work. Do I need to use something like closestPointonSurface?

If anyone has any ideas I'd be really grateful :bowdown:

Here's the duplicate and spread script:

TIA

global proc spreadObj(string $object, string $surface, int $dupNum)
{
// Get surface size
float $surfaceMinX = getAttr ($surface+".boundingBoxMinX");
float $surfaceMaxX = getAttr ($surface+".boundingBoxMaxX");
float $surfaceMinY = getAttr ($surface+".boundingBoxMinY");
float $surfaceMaxY = getAttr ($surface+".boundingBoxMaxY");
float $surfaceMinZ = getAttr ($surface+".boundingBoxMinZ");
float $surfaceMaxZ = getAttr ($surface+".boundingBoxMaxZ");

string $saNewObjects[], $combinedChunks[];

for ($n = 0; $n < $dupNum; $n++)
{
// Duplicate object
string $duplicatedObject[] = `duplicate $object`;
//Store the name of the new object, to polyUnite it later.
$saNewObjects = stringArrayCatenate($saNewObjects,{$duplicatedObject[0]});

// Set random value and place the duplicated object
float $randomX = `rand $surfaceMinX $surfaceMaxX`;
float $randomY = `rand $surfaceMinY $surfaceMaxY`;
float $randomZ = `rand $surfaceMinZ $surfaceMaxZ`;

move $randomX $randomY $randomZ $duplicatedObject;

// Aim the object with the surface normal and delete constraints used
delete `geometryConstraint $surface $duplicatedObject`;
delete `normalConstraint -aim 0 1 0 -wut "object" $surface $duplicatedObject`;

//rotate object randomly
float $anyNum = `rand 0 360`;
rotate -r -os 0 $anyNum 0 $duplicatedObject;

//scale object randomly
float $anyNumScl = `rand 0.2 1`;
scale -r $anyNumScl $anyNumScl $anyNumScl $duplicatedObject;

if(size($saNewObjects) > 1000)
{
//Unite all the new objects
$combinedChunks = stringArrayCatenate($combinedChunks, `polyUnite -ch 0 $saNewObjects`);
//clear the array, so you don't try to unite things already done.
clear $saNewObjects;
}
}

//Final combine the chunks and the last ones in $saNewObjects
polyUnite -ch 0 $combinedChunks $saNewObjects;

flushUndo;
}

Mgns
12-11-2008, 09:39 PM
hi,

we developed a similar tool when dealing with the task to create about one million objects at a surface..we used particles which we spawned using a mask image, and then we duplicated objects and aligned with each particle...

/mgns

johnjoe
12-11-2008, 09:51 PM
I originally started doing this with particles but just couldn't figure out how to rotate the instances so that they would stand down the direction of the surface normal.

there is a script here: http://www.lo-motion.de/scripts.html that uses fur but didn't seem stable with numbers over 1000. If you have any knowledge you can share I would love to learn more. :wavey:

Big thanks :)

Mgns
12-11-2008, 10:14 PM
I originally started doing this with particles but just couldn't figure out how to rotate the instances so that they would stand down the direction of the surface normal.
we did'nt have to deal with that issue, as the objects we duplicated were trees which should be pointing along the y-axis... and at this point I don't have any good ideas about how to help you with that...sorry :/

/mgns

johnjoe
12-11-2008, 10:23 PM
No worries Magnus, Thanks for taking a look at this anyway. :wavey:

Aikiman
12-12-2008, 03:10 AM
yes you can use the closestPointOnSurface node to achieve that for nurbs. Just extract the normal info from the cPOS node and use that as the aim direction. USe setAttr to connect the inPosition to particles position. im not sure how it performs with larger numbers of instances.

To populate your scene you can use surface emission based on B/W texture (found in the emitter options) white emits, black doesnt.

CGTalk Moderation
12-12-2008, 03:10 AM
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.