johnjoe
12-11-2008, 06: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;
}
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;
}
