• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ina · Dec 20, 2010 at 12:46 AM · gameobjectmeshfilterglobalnormal

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..

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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]); 
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · Dec 20, 2010 at 01:04 AM 0
Share

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?

avatar image Jessy · Dec 20, 2010 at 03:12 AM 0
Share

(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.

avatar image ina · Dec 22, 2010 at 09:08 AM 0
Share

neat, so in other words, you don't have to declare the extra variable filter ? does this work for all $$anonymous$$esh* ?

avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Return All gameobjects in scene to an array 4 Answers

Mesh dissapearing from Resources 0 Answers

Referencing an instantiated object with a global variable 0 Answers

is it better to use MeshFilter[] or three separate MeshFilter var's 1 Answer

Assigning to global transforms of current gameobject 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges