global proc buildVolcano(){ int $i, //number of subdivisions in width and height $subDivW = 25, $subDivH = 25, //scale of the mountain $scaleW = 25, $scaleH = 25; float $height, $peak = 25.0, $dist, $max_dist, $position[3], $jitterX, $jitterZ, $roughness = 2.0, $overhang = 1.0, $crater_radius = 5.0, $crater_depth = 15.0, $crater_roughness = 1.0; //maxDist = the farthest possible point on the plane from the center //this is the same as 1/2 the diagonal of the plane. $max_dist=sqrt( $scaleW * $scaleW + $scaleH * $scaleH ) / 2; //create a plane with given size and subdivision. we will pull vertices to make the mtn. polyPlane -name volcano -w $scaleW -h $scaleH -sx $subDivW -sy $subDivH -ch 0; //for each vertex for($i=0; $i < ($subDivH +1) * ($subDivW + 1); $i++){ //get the position in world space of the current vertex $position = `xform -worldSpace -query -translation volcano.vtx[$i]`; //mag gives the length of the vector, if we give world coords of the //vertex, we get the distance from the origin $dist = `mag(<<$position[0], $position[1], $position[2]>>)`; //calculate the new height of the vertex based on distance from //peak (origin), the height of the peak, and the roughness. if($dist > $crater_radius) $height = $peak * (1 - ($dist / $max_dist) ) + rand(-1 * $roughness, $roughness); else $height = $peak - ($crater_depth + rand(-1 * $crater_roughness, $crater_roughness)); //jitter the point a bit in x and y $jitterX = rand(0, ($scaleW / (float)$subDivW) * $overhang); $jitterZ = rand(0, ($scaleH / (float)$subDivH) * $overhang); select -r volcano.vtx[$i] ; move -r $jitterX $height $jitterZ; } select -r volcano; }