Mel: Infectious animation

Heres an animation I did yesterday.

Basicly the mel loop checks which objects still have to be transformed/rotated/scaled whatever, and if they are next to ones that are already visible, if they are, they are animated towards the original mesh.

int $x;

//init
if (frame == 1) {
	int $z;
	for ($z = 159; $z <=338; $z++) {
		if ($z != 159) {
			float $rand = rand(1) * 360 ;
			setAttr ("polySurface" + $z + ".rotateX") $rand;
			setAttr ("polySurface" + $z + ".rotateY") $rand;
			setAttr ("polySurface" + $z + ".rotateZ") $rand;
			setAttr ("polySurface" + $z + ".scaleX") 0;
			setAttr ("polySurface" + $z + ".scaleY") 0;
			setAttr ("polySurface" + $z + ".scaleZ") 0;
		}
	}
}

if (frame > 2) {
for ($x = 159; $x <= 338; $x++)
{
	float $attrx = getAttr ("polySurface" + $x + ".scaleX");
	float $attry = getAttr ("polySurface" + $x + ".scaleY");
	float $attrz = getAttr ("polySurface" + $x + ".scaleZ");

	float $attrrx = getAttr ("polySurface" + $x + ".rotateX");
	float $attrry = getAttr ("polySurface" + $x + ".rotateY");
	float $attrrz = getAttr ("polySurface" + $x + ".rotateZ");

	float $attr[3] = `xform -ws -q -piv ("polySurface" + $x)`;

	if (($attrx > 1) || ($attry != 1) || ($attrz != 1) || ($attrrx !=0) || ($attrry !=0) || ($attrrz !=0))
	{
		// now go through all other objects and check
		// if nearest objects are visible
		int $y;
		for ($y = 159; $y <=338; $y++) {
			if ($y != $x) {
					float $attr2x = getAttr ("polySurface" + $y + ".rotateX");
					float $attr2sz = getAttr ("polySurface" + $y + ".scaleZ");
					if ($attr2sz > 0.5) {

						float $attr2[3] = `xform -ws -q -piv ("polySurface" + $y)`;
						float $distancex = $attr[0] - $attr2[0];
						float $distancey = $attr[1] - $attr2[1];
						float $distancez = $attr[2] - $attr2[2];
						float $dist = sqrt ($distancex*$distancex + $distancey*$distancey + $distancez*$distancez);
						if ($dist <= 0.3) {
								float $attribtemp = getAttr ("polySurface" + $x + ".scaleX");
								if ($attribtemp < 1) $attribtemp = $attribtemp + (rand(1) / 10);
								if ($attribtemp > 1) $attribtemp = 1;
								setAttr ("polySurface" + $x + ".scaleX") $attribtemp;

								$attribtemp = getAttr ("polySurface" + $x + ".scaleY");
								if ($attribtemp < 1) $attribtemp = $attribtemp + (rand(1) / 10);
								if ($attribtemp > 1) $attribtemp = 1;
								setAttr ("polySurface" + $x + ".scaleY") $attribtemp;

								$attribtemp = getAttr ("polySurface" + $x + ".scaleZ");
								if ($attribtemp < 1) $attribtemp = $attribtemp + (rand(1) / 10);
								if ($attribtemp > 1) $attribtemp = 1;
								setAttr ("polySurface" + $x + ".scaleZ") $attribtemp;

								$attribtemp = getAttr ("polySurface" + $x + ".rotateX");
								if ($attribtemp != 0) {
									if (($attribtemp <= 5) && ( $attribtemp >= -5 )) $attribtemp = 0;
									}
									if ($attribtemp > 0) $attribtemp = $attribtemp - 5;
									if ($attribtemp < 0) $attribtemp = $attribtemp + 5;
								setAttr ("polySurface" + $x + ".rotateX") $attribtemp;

								$attribtemp = getAttr ("polySurface" + $x + ".rotateY");
								if ($attribtemp != 0) {
									$attribtemp = $attribtemp * 0.75;
									if (($attribtemp <= 5) && ( $attribtemp >= -5 )) $attribtemp = 0;
									}
									if ($attribtemp > 0) $attribtemp = $attribtemp - 5;
									if ($attribtemp < 0) $attribtemp = $attribtemp + 5;
								setAttr ("polySurface" + $x + ".rotateY") $attribtemp;

								$attribtemp = getAttr ("polySurface" + $x + ".rotateZ");
								if ($attribtemp != 0) {
									$attribtemp = $attribtemp * 0.75;
									if (($attribtemp <= 5) && ( $attribtemp >= -5 )) $attribtemp = 0;
									}
									if ($attribtemp > 0) $attribtemp = $attribtemp - 5;
									if ($attribtemp < 0) $attribtemp = $attribtemp + 5;
								setAttr ("polySurface" + $x + ".rotateZ") $attribtemp;

						}
					}
			}
		}
	}
}
}

3 Comments so far

  1. Fabianv on April 18th, 2008

    Looks awesome :) Thanks for sharing

  2. Rouan van der Ende on April 18th, 2008

    Hey Fabian! I got some requests for more information on this through email. So as soon as I have some time Im going to do a tutorial describing the whole process.

    Cheers

  3. [...] is basicly the same code I used for the old video I posted. Since then I’ve received a couple of requests on how to get that code to work. So I’ve [...]

Leave a Reply