/* A demo of using the pointOnSurface command on a nurbs sphere. A number of random uv's are used to get the corresponding xyz locations on a sphere along with their normalized normals. The normals are handy is you wish to make items such as curves, cylinders etc. appear to "stick out" of the sphere. M.Kesson Feb 9 2005 */ select -all; delete; defaultDirectionalLight(1, 1,1,1, "0", 0,0,0); string $sph[] = `sphere -sections 8 -spans 4`; float $pnt[], $norm[]; float $u, $v; // Get a "master" small sphere that can be instanced string $master[] = `sphere -r 0.09`; // Choose a number of random locations for($n = 0; $n < 50; $n++) { $u = rand(0,1) * 4; // notice this matches the -spans $v = rand(0,1) * 8; // ditto the -sections $pnt = `pointOnSurface -u $u -v $v $sph[0]`; $norm = `pointOnSurface -u $u -v $v -nn $sph[0]`; // Distribute small spheres over the surface instance; xform -t ($pnt[0]) ($pnt[1]) ($pnt[2]); // or, use these two lines of code //cylinder -axis ($norm[0]) ($norm[1]) ($norm[2]) -p ($pnt[0]) ($pnt[1]) ($pnt[2]) -r 0.001 -hr 1000; //move ($pnt[0]/2) ($pnt[1]/2) ($pnt[2]/2); } //select -all; select $master; delete; setAttr cylinder /* select -all; delete; defaultDirectionalLight(1, 1,1,1, "0", 0,0,0); string $sph[] = `sphere -sections 8 -spans 4`; float $pnt[], $norm[]; float $u, $v; // Get "master" objects that can be instanced string $masterSph[] = `sphere -r 0.09`; string $masterCyl[] = `cylinder -r 0.001 -hr 1000`; // Choose a number of random locations for($n = 0; $n < 5; $n++) { $u = rand(0,1) * 4; // notice this matches the -spans $v = rand(0,1) * 8; // ditto the -sections $pnt = `pointOnSurface -u $u -v $v $sph[0]`; $norm = `pointOnSurface -u $u -v $v -nn $sph[0]`; // Distribute small objects over the surface switch(1) { case 0: string $ins1[] = `instance $masterSph`; xform -t ($pnt[0]) ($pnt[1]) ($pnt[2]) $ins1; break; case 1: string $ins2[] = `instance $masterCyl`; float $xrot = acos($norm[0]) * 57; print($xrot + "\n\n"); float $yrot = acos($norm[1]) * 57; float $zrot = acos($norm[2]) * 57; string $attr = $masterCyl[1] + ".axisY"; //$attr = ($norm[0]);//, ($norm[1]), ($norm[2])>>; //setAttr -axisX $ins2[1];//($norm[0]) ($norm[1]) ($norm[2]) $ins2[1]; //setAttr sphere.translateX 5; //setAttr $attr 90; xform -ro $yrot $xrot $zrot -t ($pnt[0]) ($pnt[1]) ($pnt[2]) $ins2; break; } // or, use these two lines of code //cylinder -axis ($norm[0]) ($norm[1]) ($norm[2]) -p ($pnt[0]) ($pnt[1]) ($pnt[2]) -r 0.001 -hr 1000; //move ($pnt[0]/2) ($pnt[1]/2) ($pnt[2]/2); } //select -all; //select $masterSph; //delete; */