| global proc spreadObjectsOnSurface(string $object, string $surface, int $duplicateNb) {
// 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")`;
for ($n = 0; $n < $duplicateNb; $n++) {
string $duplicatedObject[] = `duplicate $object`;
// Set random value and place the duplicated object
float $randomX = `floor(rand($surfaceMinX, $surfaceMaxX))`;
float $randomY = `floor(rand($surfaceMinY, $surfaceMaxY))`;
float $randomZ = `floor(rand($surfaceMinZ, $surfaceMaxZ))`;
move $randomX $randomY $randomZ $duplicatedObject;
// Could add random rotation and scale task here (apply it to $duplicatedObject)
// Aim the object to the surface
string $geometryConstraintNode[] = `geometryConstraint $surface $duplicatedObject`;
string $normalConstraintNode[] = `normalConstraint -aim 0 1 0 -wut "object" $surface $duplicatedObject`;
// Activate this line if you want to delete the constraints nodes keeping the object pose. So as too manipulate it easier after placing. Note normal constraint node prevent to rotate objects.
// delete $geometryConstraintNode $normalConstraintNode;
}
} |