Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by kaihsyn · Oct 07, 2012 at 08:56 PM · meshproceduralnormal

Do we need to call RecalculateNormals() if normal vectors are assigned?

Hi, I'm learning how to modify mesh in Unity3D. Following code is from the Unity website - Procedural example. I'm not really sure about it assigning normal vectors in the for-loop and then called RecalculateNormals() afterwards. I thought if it is calling RecalculateNormals() then it doesn't need to assign normal vectors in the for-loop. Am I wrong? Thanks!

 // This script is placed in public domain....
 
 // example code REDACTED to avoid propagation
 // because it had incredible number of severe errors
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

1 Reply

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

Answer by Fattie · Oct 08, 2012 at 09:11 AM

no, you don't !

Unity's RecalculateNormals is just ONE WAY to decide on your normals.

It is one algorithm, offered for "free" by unity, for your convenience.

For example, I literally have two projects in front of me .. for one, it was adequate to just use Unity's RecalculateNormals. In the other, the engineers created the normals themselves - so unity's "recalculate normals" was irrelevant, and not used.

Re the code fragment above ... yes, you can comment away the line RecalculateNormals. It is a fact that whoever wrote that original code example, simply made a mistake.

(Just to be clear - there is another , unrelated, straightforward typo in that example code! See my long comment below on that.)

Also note Eric's critical comment below and bear that in mind!

Comment
Add comment · Show 5 · 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 Eric5h5 · Oct 08, 2012 at 03:53 PM 4
Share

dont forget the normals "have to be there", there has to be "something there" before you can use recalculatenormals.

Nope, RecalculateNormals() could in fact be called CreateNormals(). It will make normals out of thin air if necessary. All you need are vertices and triangles.

avatar image Fattie · Oct 08, 2012 at 04:00 PM 0
Share

ah! I thought it needed the array! good one.

avatar image kaihsyn · Oct 08, 2012 at 06:16 PM 0
Share

Thank you!

avatar image Fattie · Oct 08, 2012 at 06:28 PM 1
Share

That example code has many, many problems! Notice the 4th and 3rd final lines of the Update(0 routine:

They build their own normals array named normals. But they accidentally set the .normals property to their variable named vertices!!

So, they are setting .normals totally wrong:

BUT everything still barely works, because, they (unnecessarily) run RecalculateNormals() !!!!!

(You could say, that example code is "both pointless, and wrong" :) )

This is an example in program$$anonymous$$g of where "one bad mistake masks another bad mistake."

SUGGESTION: we should always use clear variable names. Do not use variable names that look similar to other important words in Unity3D. Your own normals array should be called (for example) OurSpecialNormals, SimplestPossibleNormals, NormalsForDiscoLook, NormalsFor$$anonymous$$edeivalLook, or whatever is descriptive in your project.

avatar image kaihsyn · Oct 08, 2012 at 06:41 PM 0
Share

I didn't noticed that typo! Thanks for the suggestion. :D

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.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flat shading procedural generated mesh? 1 Answer

Triangles overlapping in mesh 0 Answers

Detail mesh normals sometimes flipped inside. 0 Answers

Preserving Mesh Normals and Smoothing 2 Answers

Mesh triagnles/surface with normals 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