- Home /
Getting the (instantaneous) normal of a meshfilter object
This snippet below seems to return the normal, but when I rotate the object during runtime, the normal does not change. As I understand, TransformDirection
should convert that local normal vector from a local to a global, so it should be changing? If not, how do you get the global normal of an object?
function Update(){ var filter:MeshFilter=(GetComponent(MeshFilter) as MeshFilter); var normal = filter.transform.TransformDirection(filter.mesh.normals[0]); Debug.Log(normal); }
Actually - mea culpa... I was using the ImageTargets plane from the Qualcomm AR Unity SDK. It has a meshcollider in it, but I didn't realize it also had a script that disabled meshfilter. Got rid of that disabling script, but still no go. The downside is that ImageTargets tracks a planar object in the real world, but can't seem to return meshfilter data as you move the object - the plane normal does not change no matter which direction i move the printed card. :-(
--
Update, it seems the oddness was due to competitive noise from both the device camera (noise motion, while held in hands) and the target object. Some nontrivial bit of noise elimination would be needed to get this to work..
Answer by Jessy · Dec 20, 2010 at 12:56 AM
Your code works fine in isolation. Something else must be screwing it up.
Do know that you can use the generic form of GetComponent, in Unity 3's JavaScript, and that you don't need to do filter.transform.
var normal = transform.TransformDirection(GetComponent.<MeshFilter>().mesh.normals[0]);
I just have a plane and a sphere (rigid body). The snippet above is in the plane... I'm manually rotating the plane in scene view during runtime. The debug log shows 0,0,1 - and it doesn't change no matter which way i move the plane... How do you get it to change?
(0,0,1) means the plane is pointing along the Z axis. Like Eric said, you would need to rotate it around the X or Y axis.
neat, so in other words, you don't have to declare the extra variable filter
? does this work for all $$anonymous$$esh* ?
Answer by Eric5h5 · Dec 20, 2010 at 01:03 AM
That code works; you need to rotate on an axis that will actually cause the normal to change. For example, if you have a plane lying flat with the normals all facing straight up, rotating around the y axis won't change the value at all.
Your answer
![](https://koobas.hobune.stream/wayback/20220613091720im_/https://answers.unity.com/themes/thub/images/avi.jpg)