version I: City generator. Displacement value added into Alpha

 

 

{
// create the file node and shader
//select -all;
//delete;

// __________ IMAGE MAPPING _________________________________
string $filenode = `createNode file`;
string $shader = `createNode lambert`;
string $path = "H:/vsfx705/texture/topo-house.TIF";
// connect the nodes
connectAttr ($filenode + ".outColor") ($shader + ".color");

// insert the image path in the file node
string $cropmap = $path;
setAttr -type "string" ($filenode + ".fileTextureName") $cropmap;

// assign the shader to an object
string $object[] = `nurbsPlane -ax 0 1 0 -w 2 -lr 1 -name "nurbsPlane1"`;
//string $object[] = `sphere -name "nurbsPlane1"`;
// __________________________________________________________
select -r $object[0];
hyperShade -assign $shader;

//DisplayShadedAndTextured;
int $u, $v,
$nu = 100, $nv = 100; // steps in u and v
float $minU = 0, $minV = 0, // u/v - start and ending
$maxU = 1, $maxV = 1; // the surface - slightly less than 0 to 1

// Grab all our texture map samples
float $rgb[] = `colorAtPoint -o RGBA -su $nu -sv $nv -mu $minU -mv $minV
-xu $maxU -xv $maxV $filenode`;

float $deltaU = ($maxU - $minU)/($nu - 1); // step size in u
float $deltaV = ($maxV - $minV)/($nv - 1); // step size in v
float $currU, $currV;
int $index = 0;

$currU = $minU;
//sphere -r 0.05 -n sph;
for($n = 0; $n < $nu; $n++)
{
$currU += $deltaU;
$currV = $minV;

for($i = 0; $i < $nv; $i++)
{
float $r = $rgb[$index];
float $g = $rgb[$index + 1];
float $b = $rgb[$index + 2];
float $a = $rgb[$index + 3];
print($r + " " + $g + " " + $b + " " + $a + "\n");
if( ($r + $g + $b) < 2)
{
float $p[] = `pointOnSurface
-u $currU
-v $currV
$object[0]`;

string $listB[]={"building01", "building02", "building03"};
string $listA[]={"building04", "building05", "building06"};
string $listC[]={"building01", "building02", "building03", "building04", "building05", "building06"};

//-----------R value. building A--commercial
if( $r > 0.8 )
{
int $number = rand(0,3);
string $building = $listA[$number];
select $building;
instance $building;
scale -r (rand(1, 2)) (rand(1, 2)) 1;
move $p[0] $p[1] $p[2];
move -r 0 (0.1*$a) 0;
int $rottime = rand(0,4);
rotate -r 0 (90*$rottime) 0;
}

//-----------B value. building B--residential
if($g > 0.8)
{
int $number = rand(0,3);
string $building = $listB[$number];
select $building;
instance $building;
scale -r (rand(1, 3)) (rand(1, 2)) (rand(1, 2));
move $p[0] $p[1] $p[2];
move -r 0 (0.1*$a) 0;
int $rottime = rand(0,4);
rotate -r 0 (90*$rottime) 0;
}

//-----------G value. building C--45 degree diagonal
if($b > 0.8)
{
int $number = rand(0,6);
string $building = $listC[$number];
select $building;
instance $building;
scale -r (rand(2, 3)) (rand(1, 2)) 1;
move $p[0] $p[1] $p[2];
move -r 0 (0.1*$a) 0;
int $rottime = rand(0,4);
rotate -r 0 (45+(90*$rottime)) 0;
//rotate -r 0 45 0;
}

}
$index += 4;
$currV += $deltaV;
}
}

}

This is the first test renderings, The TOPO was made by displacement map. It is not perfectlly matched with the buidling.

 

Fly throught animation. 4710 building generated.

Version II: City Generator: Displacment value moved into B channel, Rotate value added into Blue channel.

 

 

{
// create the file node and shader
//select -all;
//delete;

// __________ IMAGE MAPPING _________________________________
string $filenode = `createNode file`;
string $shader = `createNode lambert`;
string $path = "F:/TM/vsfx705/texture/topo-house6.TIF";
// connect the nodes
connectAttr ($filenode + ".outColor") ($shader + ".color");

// insert the image path in the file node
string $cropmap = $path;
setAttr -type "string" ($filenode + ".fileTextureName") $cropmap;

// assign the shader to an object
string $object[] = `nurbsPlane -ax 0 1 0 -w 1 -lr 1 -name "nurbsPlane1"`;
//string $object[] = `sphere -name "nurbsPlane1"`;
// __________________________________________________________
select -r $object[0];
hyperShade -assign $shader;

//DisplayShadedAndTextured;
int $u, $v,
$nu = 50, $nv = 50; // steps in u and v
float $minU = 0, $minV = 0, // u/v - start and ending
$maxU = 1, $maxV = 1; // the surface - slightly less than 0 to 1

// Grab all our texture map samples
float $rgb[] = `colorAtPoint -o RGBA -su $nu -sv $nv -mu $minU -mv $minV
-xu $maxU -xv $maxV $filenode`;

float $deltaU = ($maxU - $minU)/($nu - 1); // step size in u
float $deltaV = ($maxV - $minV)/($nv - 1); // step size in v
float $currU, $currV;
int $index = 0;

$currU = $minU;
//sphere -r 0.05 -n sph;
for($n = 0; $n < $nu; $n++)
{
$currU += $deltaU;
$currV = $minV;

for($i = 0; $i < $nv; $i++)
{
float $r = $rgb[$index];
float $g = $rgb[$index + 1];
float $b = $rgb[$index + 2];
float $a = $rgb[$index + 3];
print($r + " " + $g + " " + $b + " " + $a + "\n");
if( ($r + $g + $b) < 2)
{
float $p[] = `pointOnSurface
-u $currU
-v $currV
$object[0]`;

string $listB[]={"building01", "building02", "building03"};
string $listA[]={"building04", "building05", "building06"};
string $listC[]={"building01", "building02", "building03", "building04", "building05", "building06"};

//-----------Red value. building A--commercial
if( $r > 0.8 )
{
int $number = rand(0,3);
string $building = $listA[$number];
select $building;
instance $building;
scale -r (rand(1, 2)) (rand(1, 2)) 1;
move $p[0] $p[1] $p[2];
move -r 0 (0.1*$b) 0;
rotate -r 0 ((-360)*$a) 0;

int $rottime = rand(0,4);
rotate -r 0 (90*$rottime) 0;
}

//-----------Green value. building B--residential
if($g > 0.8)
{
int $number = rand(0,3);
string $building = $listB[$number];
select $building;
instance $building;
scale -r (rand(1, 3)) (rand(1, 2)) (rand(1, 2));
move $p[0] $p[1] $p[2];
move -r 0 (0.1*$b) 0;
rotate -r 0 ((-360)*$a) 0;
int $rottime = rand(0,4);
rotate -r 0 (90*$rottime) 0;
}

//-----------Blue value. move building along Y axis
/*if($b > 0.1)
{
int $number = rand(0,6);
string $building = $listC[$number];
select $building;
instance $building;
scale -r (rand(2, 3)) (rand(1, 2)) 1;
move $p[0] $p[1] $p[2];
//move -r 0 (0.1*$a) 0;
int $rottime = rand(0,4);
rotate -r 0 (180*$a) 0;
//rotate -r 0 (45+(90*$rottime)) 0;
//rotate -r 0 45 0;
}
*/
}
$index += 4;
$currV += $deltaV;
}
}

}

 

 

 

 

This is a rendering using Blue channel to control the displacment value of terrain buildings' elevation

 

channels in Photoshop

 

 

 

 

Displacement in Terrain was added

 

 

Four channels in Phtoshop

 

rotatation is based on the alpha value multiply 180 degrees.

Alpha * multiply 360 degrees

 

Alpha * multiply 180 degrees

 

 

 

city growth

 

rotate 90 degree for each building

 

 

Version III: UI created

 

//this script create terrain based on displacement map
//ming tang. 2007

//------create terrain---------------------------------------
proc createterrain()
{
string $disfile = `textField -q -text disfile`;

//-----------create terrain command
//creat displacment shader node
shadingNode -asShader displacementShader -n dis;

//create shader group
sets -renderable true -noSurfaceShader true -empty -name disSG;

//connect displacement shader node to its shader group
connectAttr -f dis.displacement disSG.displacementShader;

//create filenode and link it to displacment shader
string $filenode2 = `createNode file`;
string $path2 = $disfile;
//string $path2 = "F:/TM/vsfx705/texture/displacment3.jpg";

//connect filenode to displacment shader node
connectAttr -f ($filenode2 + ".outColorB") dis.displacement;

//string $dismap = $path2;
setAttr -type "string" ($filenode2 + ".fileTextureName") $path2;

//create a lambert shader
string $shader = `createNode lambert -n dismap`;

//connect lambert shader node to the exsiting shader group
connectAttr -f dismap.outColor disSG.surfaceShader;

//connectAttr ($filenode2 + ".outColor") ($shader + ".color");

//update the graph network
select -r dismap ;
statusLineUpdateInputField;
autoUpdateAttrEd;
hyperShadePanelGraphCommand("hyperShadePanel1", "showUpAndDownstream");

// assign the shader to an object
string $TOPO[] = `nurbsPlane -ax 0 1 0 -w 1 -lr 1 -name "TOPO1"`;

select -r $TOPO[0];
hyperShade -assign dismap;
displacementToPoly;
delete TOPO1;
rename "TOPO1_displacement1" "terrain";
scale 1 0.1 1;

}

//---------------delete terrain-------------------------------
proc deleteterrain()
{
delete terrain;

select -r dis ;
delete;
select -r dismap ;
delete;

}

//-------------create city-------------
proc citygenerator()
{
string $disfile = `textField -q -text disfile`;
// create the file node and shader
//select -all;
//delete;

// __________ IMAGE MAPPING _________________________________
string $filenode = `createNode file`;
string $shader = `createNode lambert`;
string $path = $disfile;
// connect the nodes
connectAttr ($filenode + ".outColor") ($shader + ".color");

// insert the image path in the file node
string $cropmap = $path;
setAttr -type "string" ($filenode + ".fileTextureName") $cropmap;

// assign the shader to an object
string $object[] = `nurbsPlane -ax 0 1 0 -w 1 -lr 1 -name "nurbsPlane1"`;
//string $object[] = `sphere -name "nurbsPlane1"`;
// __________________________________________________________
select -r $object[0];
hyperShade -assign $shader;

//DisplayShadedAndTextured;
int $u, $v,
$nu = 50, $nv = 50; // steps in u and v
float $minU = 0, $minV = 0, // u/v - start and ending
$maxU = 1, $maxV = 1; // the surface - slightly less than 0 to 1

// Grab all our texture map samples
float $rgb[] = `colorAtPoint -o RGBA -su $nu -sv $nv -mu $minU -mv $minV
-xu $maxU -xv $maxV $filenode`;

float $deltaU = ($maxU - $minU)/($nu - 1); // step size in u
float $deltaV = ($maxV - $minV)/($nv - 1); // step size in v
float $currU, $currV;
int $index = 0;

$currU = $minU;
//sphere -r 0.05 -n sph;
for($n = 0; $n < $nu; $n++)
{
$currU += $deltaU;
$currV = $minV;

for($i = 0; $i < $nv; $i++)
{
float $r = $rgb[$index];
float $g = $rgb[$index + 1];
float $b = $rgb[$index + 2];
float $a = $rgb[$index + 3];
print($r + " " + $g + " " + $b + " " + $a + "\n");
if( ($r + $g + $b) < 2)
{
float $p[] = `pointOnSurface
-u $currU
-v $currV
$object[0]`;

string $listB[]={"building01", "building02", "building03"};
string $listA[]={"building04", "building05", "building06"};
string $listC[]={"building01", "building02", "building03", "building04", "building05", "building06"};

//-----------Red value. building A--commercial
if( $r > 0.8 )
{
int $number = rand(0,3);
string $building = $listA[$number];
select $building;
instance $building;
scale -r (rand(1, 2)) (rand(1, 2)) 1;
move $p[0] $p[1] $p[2];
move -r 0 (0.1*$b) 0;
rotate -r 0 ((-360)*$a) 0;

int $rottime = rand(0,4);
rotate -r 0 (90*$rottime) 0;
//group -parent $item city;

}

//-----------Green value. building B--residential
if($g > 0.8)
{
int $number = rand(0,3);
string $building = $listB[$number];
select $building;
instance $building;
scale -r (rand(1, 3)) (rand(1, 2)) (rand(1, 2));
move $p[0] $p[1] $p[2];
move -r 0 (0.1*$b) 0;
rotate -r 0 ((-360)*$a) 0;
int $rottime = rand(0,4);
rotate -r 0 (90*$rottime) 0;
//group -parent $item city;
}

//-----------Blue value. move building along Y axis
/*
if($b > 0.1)
{
int $number = rand(0,6);
string $building = $listC[$number];
select $building;
instance $building;
scale -r (rand(2, 3)) (rand(1, 2)) 1;
move $p[0] $p[1] $p[2];
//move -r 0 (0.1*$a) 0;
int $rottime = rand(0,4);
rotate -r 0 (180*$a) 0;
//rotate -r 0 (45+(90*$rottime)) 0;
//rotate -r 0 45 0;
}
*/
}
$index += 4;
$currV += $deltaV;
}
}
delete nurbsPlane1;

}
//------------create UI window-------------------------------

global proc terraingenerator ()
{
if (`window -exists terraingenerator`) { deleteUI terraingenerator; }
window
-widthHeight 300 300
-title "City Generator"
-sizeable true
terraingenerator;

//add three values

columnLayout;
rowColumnLayout -nc 1
-columnWidth 1 500
-columnSpacing 1 20;

text "input image file";
textField -tx "F:/TM/vsfx705/texture/topo-house6.tif" disfile;
setParent ..;

 

//----break
text -l "";
separator -w 800;

//three buttons
rowColumnLayout -numberOfColumns 2
-columnWidth 1 200
-columnSpacing 1 20
-columnWidth 2 200
-columnSpacing 2 20;

text -l &qu