Forests in maya mental ray.


#201

InfernalDarkness, keytay is talking about to move the uvs to get a 3x3 array of leafs for the texture, and for that you need to use and script, or at least you need to divide the geo into 9 diferent geos. to try to move the uvs manually is a hard task

Currently I have the same problem as keytay :frowning:

Using trees from Onyx, or PFX, or…? I think in Onyx you can output (export) different leaf-sets from one tree. For example it would split the leaves into different groups. I could be confusing BroadLeaf with Flower, though. If it were that easy, you guys would have already nailed it way ahead of me. I have a tendency to stumble through complexity in a trial-and-error fashion, which you’ve likely noticed!


#202

:smiley:
In Onyxtree its easy (as you mentioned, with the groups). But animating those Onyxtrees in Maya is a pain. Yes, I talk about Paint Effects. :slight_smile:

I tried two scripts which should randomly assign different shaders to a defined amount of faces. But unfortunately both scripts did not work properly.


#203

InfernalDarkness here is my screenie.
My apologies all, I should have explained myself better in the first place. My texture is 2x2 leaf which I’ve applied to my leaf geo which are simple quads. The tree is PaintFX btw. I randomly select a quarter of the faces and save a selection set and then try to move the UV’s to house one of the leaves on my texture. This is when maya freaks out and freezes or thinks about the move for an unacceptable amount of time (I have to restart maya pretty much everytime). I guess a way around it is to have 4 separate leaf textures so I don’t have to enter the uv editor at all and divide the geo into 4 pieces. Which is ok but it’s a work around and sometimes peeps have a texture budget and would have to do it with one texture. :hmm:


#204

How are you creating your random leaf selection? MEL script?


#205

there are a couple random selection scripts on creativecrash if you need them, keytay. Also, if you have a lot of leaves selected, w/smooth shading enabled for your display and you try to move UVs, your system will be in pain. If you’re not already trying that in wireframe mode, do that instead. You can also try copying UVs over to selected meshes as another option.


#206

here you have a mel script that change the uvs into a 2x2 or 3x3 matrix, to work properly, you must to select the polymesh in object mode.
After to execute the script you must to reassing the original shader.

it only works with square leafs.

sorry if there are any error, it works for me.

int $sys = 4;

if (`window -exists Div_Mesh`) 
  deleteUI Div_Mesh;


window -w 280 -h 600 -title "Dividir mesh" Div_Mesh; 
	columnLayout Ejes;

//Definir los ejes y la tolerancia

	frameLayout -w 285 -bs "etchedIn" -borderVisible true -labelVisible true -labelAlign "center" -marginWidth 5 -marginHeight 5 -label "Define arrangement" -cll true HPlace; 

	columnLayout;
	rowLayout -numberOfColumns 3 -columnWidth 1 100 -columnWidth 2 80 -columnWidth 3 80;
			
				text -l "Matrix:";
				radioCollection; 
				$Matr2 = `radioButton -sl -label "2x2"`; 
				$Matr3 = `radioButton -label "3x3"`;
				
	setParent -u;
//intSliderGrp -label "N. porciones" -field true -maxValue 10 -value 1 -cw 1 60 -cal 1 left -cw 2 50 Perc;

text -l "";

radioButton -edit -onCommand "$sys = 4" $Matr2; 
radioButton -edit -onCommand "$sys = 9" $Matr3;

string $botonaccion = `button -w 270 -h 20 -label "Process" proces`;



showWindow Div_Mesh;


button -edit -command "Seleccionar ($sys)" $botonaccion; 


global proc Seleccionar (int $typo) {

print $typo;
float $scaleuv, $moveuv;


	
string $Locator_nodes[] = `ls -sl`;
int $totalf[] = `polyEvaluate -f`;
string $object;


ConvertSelectionToUVs;

if ($typo == 4){
	
	$scaleuv = 0.49;
	$moveuv = 0.25;
	
	}
	
if ($typo == 9){
	
	$scaleuv = 0.32;
	$moveuv = 0.3333333;
	
}

polyEditUV -pu 0.5 -pv 0.5 -su $scaleuv -sv $scaleuv ;	

for ($Sn= 0; $Sn <$typo; $Sn++){
	
	crearLambert ("lambert_" + $Sn);
	
	}



int $f = 0;

selectMode -component;

selectType -pf true;


//	int $time = $totalf[0];

//	currentTime $time;

while ($f != $totalf[0])
{ 
	
	int $factor = (`rand 0 ($typo)`);
//    select -r ($Locator_nodes[0] + ".f[" + $f +"]");
	

		sets -e -forceElement ("lambert_" + $factor + "SG") ($Locator_nodes[0] + ".f[" + $f +"]");
	


		$f++;
		
//			$time--; 
//    currentTime $time;

	}
	
	for ($Sn= 0; $Sn <$typo; $Sn++){
		
		switch ($Sn){
			case 0:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
				
				if ($typo == 4){

					polyEditUV -u -0.25 -v -0.25 ;
					
				} else {
					
					polyEditUV -u -0.33333 -v -0.33333 ;
				}

			break;
			
			
			case 1:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
				
				if ($typo == 4){

					polyEditUV -u 0.25 -v -0.25 ;
					
				} else {
					
					polyEditUV -u 0 -v -0.33333 ;
				}

			break;
			
			case 2:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
				
				if ($typo == 4){

					polyEditUV -u 0.25 -v 0.25 ;
					
				} else {
					
					polyEditUV -u 0.33333 -v -0.33333 ;
				}

			break;
			
			case 3:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
				
				if ($typo == 4){

					polyEditUV -u -0.25 -v 0.25 ;
					
				} else {
					
					polyEditUV -u -0.33333 -v 0 ;
				}

			break;
			
			case 4:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u 0 -v 0 ;


			break;
			
			case 5:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u 0.33333 -v 0 ;


			break;
			
			case 6:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u -0.33333 -v 0.33333 ;


			break;
			
			case 7:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u 0 -v 0.33333 ;


			break;
			
			case 8:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u 0.33333 -v 0.33333 ;


			break;
		
		
		
		}
		
		
	
	
	
	}
	
	
	

}

	

proc crearLambert (string $shaderName) 

{


	if (`objExists ($shaderName + "SG")` == 0){
	
		sets -renderable true -noSurfaceShader true -empty -name ($shaderName + "SG");


		shadingNode -asShader lambert - n $shaderName;
	

		connectAttr ($shaderName + ".outColor") ($shaderName + "SG.surfaceShader");
	
	}



}

#207

tostao_wayne: That script is absolutely brilliant! Thank you so much! You have saved me so much time and it keeps me far far away from the uv editor! I think I’ve got an actual tear in my eye. :bowdown:

pix3lm0nk: Thanks for the info, unfortunately even in wireframe the uv editor behaves the same chug’a’lug way.

TheNeverman: Before tostao_wayne’s script here I was using ‘select using constraints’ with the random option on .25. But it was still super slow and the uv editor would still freeze when it came to moving the uv’s.

Thanks again guys! That’s one huge road block out of the way. Now I can add way more geo without fear of breaking the uv editor and see if I can’t make this thing look like an actual tree. :wip:


#208

thankx Keytay, the solution is to assign the faces to a shaderset without selecting them, and this only can be done scripting. after that, manage a set is more quick than manage a group of faces.


#209

Thank you tostao_wayne, your script works good!


#210

thakx Skoczylas, if someone need it, i can modify it to work with leafs that have more than only a polygon, but all the leaves must to have the same number of polys.


#211

That would be fantastic! When I use paint effects trees the leaves need to have more than one polygon so they can bent to the sky (duncans trick).


#212

the problem is that i need the polys of one leaf to be consecutives, and in paint effects they aren’t consecutives.
One solution can be separate first the leaves and combine again.

now i’m in a deathline, tomorrow i will post the script here.


#213

finally i have got 10 minutes to do the script.

to work properly, you must to select one complete leaf (and only one) in face selection mode
by this way, the script can know how many polys has each leaf

after that execute the script

it also works if each leaf has only one poly.

int $sys = 4;

if (`window -exists Div_Mesh`) 
  deleteUI Div_Mesh;


window -w 280 -h 600 -title "Dividir mesh" Div_Mesh; 
	columnLayout Ejes;

//Definir los ejes y la tolerancia

	frameLayout -w 285 -bs "etchedIn" -borderVisible true -labelVisible true -labelAlign "center" -marginWidth 5 -marginHeight 5 -label "Define arrangement" -cll true HPlace; 

	columnLayout;
	rowLayout -numberOfColumns 3 -columnWidth 1 100 -columnWidth 2 80 -columnWidth 3 80;
			
				text -l "Matrix:";
				radioCollection; 
				$Matr2 = `radioButton -sl -label "2x2"`; 
				$Matr3 = `radioButton -label "3x3"`;
				
	setParent -u;
//intSliderGrp -label "N. porciones" -field true -maxValue 10 -value 1 -cw 1 60 -cal 1 left -cw 2 50 Perc;

text -l "";

radioButton -edit -onCommand "$sys = 4" $Matr2; 
radioButton -edit -onCommand "$sys = 9" $Matr3;

string $botonaccion = `button -w 270 -h 20 -label "Process" proces`;



showWindow Div_Mesh;


button -edit -command "Seleccionar ($sys)" $botonaccion; 


global proc Seleccionar (int $typo) {

print $typo;
float $scaleuv, $moveuv;


	
string $Locator_nodes[] = `ls -sl -fl`;

int $leafF = size ($Locator_nodes);
print ("Numero de poligonos por hoja: " + $leafF + "
");

string $tokens[];
int $numTokens = `tokenize $Locator_nodes[0] "." $tokens`;

select -r $tokens[0];


int $totalf[] = `polyEvaluate -f`;

string $object;


ConvertSelectionToUVs;

if ($typo == 4){
	
	$scaleuv = 0.49;
	$moveuv = 0.25;
	
	}
	
if ($typo == 9){
	
	$scaleuv = 0.32;
	$moveuv = 0.3333333;
	
}

polyEditUV -pu 0.5 -pv 0.5 -su $scaleuv -sv $scaleuv ;	

for ($Sn= 0; $Sn <$typo; $Sn++){
	
	crearLambert ("lambert_" + $Sn);
	
	}



int $f = 0;

selectMode -component;

selectType -pf true;


//	int $time = $totalf[0];

//	currentTime $time;

int $totalF = $totalf[0]/$leafF;

for ($f=0; $f< $totalF; $f++)
{ 
	
	int $factor = (`rand 0 ($typo)`);
//    select -r ($Locator_nodes[0] + ".f[" + $f +"]");

		for ($fg=0; $fg < $leafF; $fg++){
	

		sets -e -forceElement ("lambert_" + $factor + "SG") ($tokens[0] + ".f[" + (($f * $leafF) + $fg) +"]");
	
		}


		
//			$time--; 
//    currentTime $time;

}
	
	for ($Sn= 0; $Sn <$typo; $Sn++){
		
		switch ($Sn){
			case 0:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
				
				if ($typo == 4){

					polyEditUV -u -0.25 -v -0.25 ;
					
				} else {
					
					polyEditUV -u -0.33333 -v -0.33333 ;
				}

			break;
			
			
			case 1:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
				
				if ($typo == 4){

					polyEditUV -u 0.25 -v -0.25 ;
					
				} else {
					
					polyEditUV -u 0 -v -0.33333 ;
				}

			break;
			
			case 2:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
				
				if ($typo == 4){

					polyEditUV -u 0.25 -v 0.25 ;
					
				} else {
					
					polyEditUV -u 0.33333 -v -0.33333 ;
				}

			break;
			
			case 3:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
				
				if ($typo == 4){

					polyEditUV -u -0.25 -v 0.25 ;
					
				} else {
					
					polyEditUV -u -0.33333 -v 0 ;
				}

			break;
			
			case 4:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u 0 -v 0 ;


			break;
			
			case 5:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u 0.33333 -v 0 ;


			break;
			
			case 6:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u -0.33333 -v 0.33333 ;


			break;
			
			case 7:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u 0 -v 0.33333 ;


			break;
			
			case 8:
				select -r ("lambert_" + $Sn + "SG");
				ConvertSelectionToUVs;
							
				polyEditUV -u 0.33333 -v 0.33333 ;


			break;
		
		
		
		}
		
		
	
	
	
	}
	
	
	

}

	

proc crearLambert (string $shaderName) 

{


	if (`objExists ($shaderName + "SG")` == 0){
	
		sets -renderable true -noSurfaceShader true -empty -name ($shaderName + "SG");


		shadingNode -asShader lambert - n $shaderName;
	

		connectAttr ($shaderName + ".outColor") ($shaderName + "SG.surfaceShader");
	
	}



}

#214

Here is my result so far:

I have used mia_material with translucency. The whole trees and the grass is rendered by using the mip_binary_proxy.

There is still a lot to do. Especially the branch geometry and the bark texturing.


#215

Thank you so much tostao_wayne! I guess it works - I cant say anymore because it runs for more than 2 hours on my 120.000 poly tree.

JayHoo: Great result! What about those trees in the background? Is this an image or are those polys too? What did you use for the grass?
Those trees are paint effects, right? Than tostao_wayne’s script is useful for you too, to assign different leaves textures to get more variation.


#216

Hi Sven. The trees are onxy trees. I can simply add another shader to the leaf objects. The grass is paintfx converted to polygons. I created a grass patch and applied it via the mip_binary_proxy over the scene. The paint geometry tool is quite useful for that.


#217

Is it still possible to have the grass animated?
How long did this rendering took?


#218

The rendertimes are crazy. Maybe 20h. :argh: The rendertimes are high because everything is geometry. And the grass has translucency too.

Animation is a bit difficult. Maybe through a deformer.


#219

wow, 20hours is much more as I expected.
I ask for animation since you said its paint effects grass. And therefore its easy to animate through its turbulence parameter. Or is the animation then getting lost because of the mib_proxy?


#220

My computer crashed for the second time while using it. Your first script needed around 2-3 hours, then it was done successfully :thumbsup: This modified one freeze my computer after 2-3 hours. Did somebody else try that script?