Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 03-04-2006, 08:35 PM   #1
vladimirjp
Subscriber
 
vladimirjp's Avatar
 
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871
Thanks: 0
Thanked 4 Times in 3 Posts
Default normals [state]

is there a way to catch the state of normals? to know what direction they are facing?
if they are facing away from camera or not.

im tring to writte a script that finds all objects who's normals are inverted. and make them point in the right direction.
__________________
Image dump
vladimirjp is offline   Reply With Quote
Old 03-04-2006, 10:08 PM   #2
MattTheMan
Registered User
 
MattTheMan's Avatar
 
Join Date: Apr 2005
Location: Fairfield, CT
Posts: 2,436
Thanks: 0
Thanked 18 Times in 18 Posts
Default

well, you could scan all normals and then take the dot product between the normal and the camera (which the normal of the camera would be a vector from the actual camera and the point it is rotating around, and then normalize that

then if the dot product was negative, then its facing outward, but if the dot product was positive then its facing inward

then you flip the normals that the dot product was negative

this might work, but I'm not sure
__________________
Live the life you love, love the life you live

Last edited by MattTheMan : 05-04-2006 at 02:03 AM.
MattTheMan is offline   Reply With Quote
Old 05-04-2006, 05:13 PM   #3
vladimirjp
Subscriber
 
vladimirjp's Avatar
 
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871
Thanks: 0
Thanked 4 Times in 3 Posts
Default

you lost me at "dot"

what is that? is that a mel function?

can u write a pseudo code on how youd hadle this.

this sound like a logical approach.

if i could get the state or the "dot" positive/negative of normals facing camera, i could easily write a mel that reverse them.
__________________
Image dump
vladimirjp is offline   Reply With Quote
Old 05-04-2006, 05:46 PM   #4
Velusion
Registered User
 
Velusion's Avatar
 
Join Date: May 2004
Location: Utah, USA
Posts: 368
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm pretty sure there is an option, under normals, that will flip whichever normals are not pointing in the same direction as the majority of them.
__________________
James Rogers
www.morphicmotion.com
Velusion is offline   Reply With Quote
Old 05-04-2006, 06:09 PM   #5
vladimirjp
Subscriber
 
vladimirjp's Avatar
 
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871
Thanks: 0
Thanked 4 Times in 3 Posts
Default

i wish thre were,
but the option under normals>conform
as i thought it was, really does nothing,

so any mel savvy members can look into this, i have a model and a huge scene with many many parts im trying to set all their normals to face the camera.
__________________
Image dump
vladimirjp is offline   Reply With Quote
Old 06-04-2006, 12:24 AM   #6
MattTheMan
Registered User
 
MattTheMan's Avatar
 
Join Date: Apr 2005
Location: Fairfield, CT
Posts: 2,436
Thanks: 0
Thanked 18 Times in 18 Posts
Default

dot product, or scalar product, is a mathmatical operation done like this:

vectors c and n, c being camera, n being normal

dot product = n.x*c.x + n.y*c.y + n.z*c.z
__________________
Live the life you love, love the life you live
MattTheMan is offline   Reply With Quote
Old 06-04-2006, 01:06 AM   #7
vladimirjp
Subscriber
 
vladimirjp's Avatar
 
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871
Thanks: 0
Thanked 4 Times in 3 Posts
Default

i think youre way off matt
__________________
Image dump
vladimirjp is offline   Reply With Quote
Old 06-04-2006, 01:18 AM   #8
MattTheMan
Registered User
 
MattTheMan's Avatar
 
Join Date: Apr 2005
Location: Fairfield, CT
Posts: 2,436
Thanks: 0
Thanked 18 Times in 18 Posts
Default

me too but I was just trying to help.
__________________
Live the life you love, love the life you live
MattTheMan is offline   Reply With Quote
Old 06-04-2006, 11:18 AM   #9
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Originally posted by vladimirjp
i wish thre were,
Well, there is but depending on the situation it takes some trial and error to get the normals sorted out. Usually some mode of the Conform function followed by Set To Face does the trick. Sometimes you have to do it in reverse order. I don't really know what's going on with these normal operations but they do work eventually.
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
kbrown is offline   Reply With Quote
Old 06-04-2006, 11:31 AM   #10
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Here's a copy-paste of my getFaceNormals procedure, which I wrote for my auto map script. It takes in a string variable containing the name of the polygon object and returns a vector array containing face normals.

Code:
// getFaceNormals by kbrown
//
proc vector[] getFaceNormals(string $sPolyObject)
{
	vector $vNormals[];
	int $i;

	// get all face normals in to a string array
	string $sFaceNormals[] = `polyInfo -fn $sPolyObject`;
	
	// parse the string array and create a vector array holding the normal info
	for($i = 0; $i < size($sFaceNormals); $i++)
	{
		string $sBuffer[];
		tokenize($sFaceNormals[$i], $sBuffer);
		float $fX = $sBuffer[2];
		float $fY = $sBuffer[3];
		float $fZ = $sBuffer[4];
		$vNormals[$i] = <<$fX, $fY, $fZ>>;
	}
	
	// free some memory
	clear($sFaceNormals);
	
	// return the vector array
	return $vNormals;
}
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
kbrown is offline   Reply With Quote
Old 06-04-2006, 11:34 AM   #11
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Thanks: 0
Thanked 8 Times in 8 Posts
Default Re: normals [state]

Originally posted by vladimirjp
is there a way to catch the state of normals? to know what direction they are facing?
if they are facing away from camera or not.

im tring to writte a script that finds all objects who's normals are inverted. and make them point in the right direction.
I think there is a problem with this concept. Normals can face away from camera and still be just fine. I'm talking about the faces on the back side of the object (which the camera cannot see). Might be safer if you just investigate the normals of the selected faces only...
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
kbrown is offline   Reply With Quote
Old 06-04-2006, 01:53 PM   #12
vladimirjp
Subscriber
 
vladimirjp's Avatar
 
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871
Thanks: 0
Thanked 4 Times in 3 Posts
Default

yea, the state [or directions] of my normals matter a lot.

im doing a lot of dynamics which requires normals to be pointed out to calculate.

also some rendering issues i have with inverted normals.

i did a lot of negative duplicates, so the normals get inverted [sometimes arbitrarily ]
ill experiment with your code with some of the codes i already have for this.


thankx. ill keep testing.

this is harder than it seems. i dont know why alias hasnt made a tool for this yet.
__________________
Image dump

Last edited by vladimirjp : 06-04-2006 at 02:34 PM.
vladimirjp is offline   Reply With Quote
Old 07-04-2006, 02:50 PM   #13
vladimirjp
Subscriber
 
vladimirjp's Avatar
 
Join Date: Jun 2003
Location: stuck in the 90's boston, USA
Posts: 1,871
Thanks: 0
Thanked 4 Times in 3 Posts
Default

close enough:
"normalChecker; "
of course since its from alias it only does half the job.

Code:
 // Copyright (C) 1997-2004 Alias Systems Corp.
// 
// The information in this file is provided for the exclusive use of the
// licensees of Alias.  Such users have the right to use, modify,
// and incorporate this code into other products for purposes authorized
// by the Alias license agreement, without fee.
// 
// ALIAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
// EVENT SHALL ALIAS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
//
// authors: afuchs and rreyer
//
// Version 23.12.04 - 13:55
//
//
//

proc copyTRS( string $source, string $dest)
{
	float $v[] = `getAttr ($source + ".translate")`;
	setAttr -type double3 ($dest + ".translate") ($v[0]) ($v[1]) ($v[2]);
	float $v[] = `getAttr ($source + ".rotate")`;
	setAttr -type double3 ($dest + ".rotate") ($v[0]) ($v[1]) ($v[2]);
	float $v[] = `getAttr ($source + ".scale")`;
	setAttr -type double3 ($dest + ".scale") ($v[0]) ($v[1]) ($v[2]);
}

global proc normalChecker( )
{
	
		string $selection[] = `ls-sl`;

		string $shapes[];
		string $inverse[];
	
		$shapes = `ls -v -ni -ut -sl -dag -type nurbsSurface -type mesh`;
		
	if (size($shapes)) {			// create red inverse surfaces
	
		string $inverseShadingGroup;
		if (!`objExists "normalCheckRedShader"`) {
			$inverseShader = `shadingNode -name "normalCheckRedShader" -asShader lambert`;
			setAttr ($inverseShader +".color") -type double3 1 0 0 ;
			$inverseShadingGroup =`sets -renderable true -noSurfaceShader true -empty -name ($inverseShader +"SG")`;
			connectAttr -f ($inverseShader + ".outColor") ($inverseShadingGroup + ".surfaceShader");
		} else $inverseShadingGroup = "normalCheckRedShaderSG";
	
		if (!`objExists "normalCheckLayer"`) {
			createDisplayLayer -name "normalCheckLayer" -number 1 -empty;
			setAttr normalCheckLayer.displayType 2;
		}
	
	
	
		for ( $obj in $shapes ) 
		{
			// check, if this shape is connected to the inverseLayer (that means, it is an inverse)
			if (!`isConnected normalCheckLayer.drawInfo ($obj + ".drawOverride")`) {
				string $tmp[] = `listRelatives -p $obj`;
				string $parent = $tmp[0];

				string $inverse;
				if ( `objectType $obj` == "nurbsSurface" ) 
				{
					// first check, if an inverse already exists
					if (!`objExists ($obj + "_inverse")` || !`isConnected ($obj + ".worldSpace[0]") ($obj + "_inverse.create")`) {

						$inverse =`createNode -n ($obj + "_inverse") nurbsSurface`;
//						$inverse =`createNode -p $parent -n ($obj + "_inverse") nurbsSurface`;
						connectAttr -f ($obj+ ".worldSpace[0]") ($inverse +".create");
					}
				} else {
					// first check, if an inverse already exists
					if (!`objExists ($obj + "_inverse")` || !`isConnected ($obj + ".outMesh") ($obj + "_inverse.inMesh")`) {

						$inverse =`createNode -n ($obj + "_inverse") mesh`;
//						$inverse =`createNode -p $parent -n ($obj + "_inverse") mesh`;
						connectAttr -f ($obj + ".outMesh") ($inverse + ".inMesh");
					}
				}

				// do we have a new inverse?
				if (size($inverse)) {

					string $tmp[] = `listRelatives -p $inverse`;
					string $inverseParent = $tmp[0];
					copyTRS( $parent, $inverseParent);

					select $inverseParent;
					layerEditorAddObjects normalCheckLayer;

					// now set the new shape to be reverse (from whatever the orig ist)
					setAttr ($obj + ".doubleSided") 0;
					setAttr ($inverse + ".doubleSided") 0;

					// set the opposite flag for the single side option
					setAttr ($inverse + ".opposite") (!`getAttr ($obj + ".opposite")`);

					// connecting it to the red shader
					select -r $inverse;
					sets -e -forceElement $inverseShadingGroup;
				}
			}
		}

	} else {			// delete red inverse surfaces, the layer and the red shader
		if (`objExists "normalCheckLayer"`) {
			layerEditorSelectObjects normalCheckLayer;

			// set the original shapes back to "doublesided"
			string $shapes[] = `ls -v -ni -ut -sl -dag -type nurbsSurface -type mesh`;
			for ( $s in $shapes ) {
				string $tmp[];
				if ( `objectType $s` == "nurbsSurface" ) $tmp = `listConnections -s 1 -p 0 -sh 1 ($s + ".create")`;
				else $tmp = `listConnections -s 1 -p 0 -sh 1 ($s + ".inMesh")`;
				setAttr ($tmp[0] + ".doubleSided") 1;
			}

			if (size(`ls -sl`)) delete;
			evalDeferred ("layerEditorDeleteLayer normalCheckLayer");
		}

		if (`objExists "normalCheckRedShader"`) {
			string $tmp[] = `listConnections -d 1 "normalCheckRedShader.outColor"`;
			$tmp = `ls -type shadingEngine $tmp`;
			if (size($tmp)) delete $tmp;
			delete normalCheckRedShader;
		}
	}

	select -r $selection;

}
__________________
Image dump

Last edited by vladimirjp : 07-04-2006 at 02:54 PM.
vladimirjp is offline   Reply With Quote
Old 24-04-2006, 09:21 PM   #14
Velusion
Registered User
 
Velusion's Avatar
 
Join Date: May 2004
Location: Utah, USA
Posts: 368
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm going to look into this tonight. I know that one of my books explains how Maya can find and flip normals that aren't pointing in the same direction as the majority.

Question: If some of the normals are flipped, can't you just tell Maya to make your texture double sided?
__________________
James Rogers
www.morphicmotion.com
Velusion is offline   Reply With Quote
Old 27-04-2006, 02:47 AM   #15
Velusion
Registered User
 
Velusion's Avatar
 
Join Date: May 2004
Location: Utah, USA
Posts: 368
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I struck out. I can't find a way to flip the "odd" normals but one thing I don't understand is how you guys are running into situations where some of your normals are getting reversed. I've never had that happen,,, yet.

One thing I discovered is that if YOU reverse some or all of your normals using the reverse function, a node is created and you really can't unreverse those normals by hitting the reverse normals button again. You have to delete the node. I reversed some normals on purpose then went into the outliner and turned off DAG OBJECTS ONLY then went down to the node that was created; POLYNORMAL, and deleted it. By doing this, the normals that I reversed turned back around the way they originally were.

I've yet to come across a situation that has made me want to reverse normals except sometimes when I import a model from Zbrush. Sometimes when I import the model, the normals are reversed. When that happens, it's the whole model and not just a few normals.

I'm going to post this question in the Polygon modeling forum..
__________________
James Rogers
www.morphicmotion.com

Last edited by Velusion : 27-04-2006 at 02:57 AM.
Velusion is offline   Reply With Quote
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Normals Funkyness 3dStudent Modeling 5 04-12-2010 03:10 PM

Thread Tools





A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.