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
0
Question by Dan 9 · Jan 27, 2011 at 07:34 PM · editornormalsquad

How can I reverse normals on a quad?

I'm using this script to create a 2D quad in Unity: Quad Script

My problem is I have to rotate my created object 180 degrees on the Y axis to see the texture on it.

I tried to reverse the normals in the script with:

Vector3[] normals = m.normals;
            for (int i = 0; i < normals.Length; i++)
                normals[i] = -normals[i];
            m.normals = normals;

No luck. Any idea?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jessy · Jan 27, 2011 at 07:52 PM

Normals are only for lighting calculations. As it is, your code just tells the faces to behave, when hit by lights, to act as if they were facing the other way.

You just need to wind the triangles in the opposite order. Unity will take care of the normals automatically for you, using that script, if you do that.

Comment
Add comment · Show 2 · 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 DaveA · Jan 27, 2011 at 10:18 PM 0
Share

Normals also used for raycasting, no? If he were to use this as a mesh collider?

avatar image Jessy · Jan 27, 2011 at 11:40 PM 0
Share

As far as I can tell, only winding order matters for mesh colliders, too.

avatar image
0

Answer by Dan 9 · Jan 28, 2011 at 01:52 PM

Thanks for the explanation; reversing the faces makes sense. I'm still having issues with reversing them.

Here is the original code that creates them (this is the code I will need to reverse).

    for (float y = 0.0f; y < vCount2; y++)
    {
        for (float x = 0.0f; x < hCount2; x++)
        {
            if (orientation == Orientation.Horizontal)
            {
                vertices[index] = new Vector3(x * scaleX, 0.0f, y * scaleY);
            }
            else
            {
                vertices[index] = new Vector3(x * scaleX, y * scaleY, 0.0f);
            }
            uvs[index++] = new Vector2(x * uvFactorX, y * uvFactorY);
        }
    }

I've tried to reverse them with no luck. I tried to reverse the index so it decrements which did not work. Then I tried reversing the for loops so they decrement. I'm not sure why it did not work. Here is the for loop reversal code I tried.

        for (float y = vCount2; y > 0.0f; y--)
        {
            for (float x = hCount2; x > 0.0f; x--)
            {
                if (orientation == Orientation.Horizontal)
                {
                    vertices[index] = new Vector3(x * scaleX, 0.0f, y * scaleY);
                }
                else
                {
                    vertices[index] = new Vector3(x * scaleX, y * scaleY, 0.0f);
                }
                uvs[index++] = new Vector2(x * uvFactorX, y * uvFactorY);
            }
        }

What am I missing?

Comment
Add comment · Show 1 · 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 Dan 9 · Jan 28, 2011 at 02:08 PM 0
Share

Did some debugging and found my for loops were wrong, but I still get the same results even though they are fixed. The new loops look like this: for (float y = vCount2 - 1; y >= 0.0f; y--) Same with the x. This gives me the correct coords now and they are reversed, but it is still culling the side facing me.

avatar image
0

Answer by Dan 9 · Jan 28, 2011 at 04:22 PM

Finally got it. I was reversing the vertices and not the triangle strip. Works now. Thanks for the help.

Comment
Add comment · Show 1 · 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 konsnos · Jul 30, 2014 at 10:39 AM 0
Share

Can you post your solution for anyone who's interested in it?

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

No one has followed this question yet.

Related Questions

Any script to 'fix' normals/winding order? 3 Answers

Is it possible to run a script in the editor so it doesnt have to run it again the runtime???? 2 Answers

Class Reference in Editor not working 1 Answer

Can't open scripts with monodevelop? 1 Answer

AssetPreview.GetMiniTypeThumbnail not working for custom scripts 0 Answers


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