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 athert · Aug 09, 2014 at 06:14 PM · normalizedhalf

normalized Z axis is always positive

Hi all. I have a question about normalize coordinates that you get from the mesh. I'm trying to do a simple Sphere, but for some reason I create only one half and the other not. I have observed that this is due to the fact that the coordinates "vertices[i].z" is always positive and never negative. I would like to ask if you do not know what is wrong. Thank you :)

     Mesh mesh = GetComponent<MeshFilter>().mesh;
     Vector3[] vertices = mesh.vertices;
     Vector3[] verticesN = vertices;
     
     int k = 0;
     for (var i = 0; i < vertices.Length; i++)
     {
         verticesN[i] = vertices[i].normalized * 50;
         if (k >= 100)
         {
             Instantiate(sp_debug, verticesN[i], Quaternion.identity);
             k = 0;
         }
         k++;
     }
     
     mesh.vertices = verticesN;
     mesh.RecalculateNormals();


(Red sphere on picture are only for my debug. You can see there are only half sphere) alt text

sphere.png (90.4 kB)
Comment
Add comment · Show 6
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 Scribe · Aug 09, 2014 at 07:04 PM 0
Share

what is the actual half sphere about? If that is the mesh you are using then of course you will only get half a sphere

avatar image athert · Aug 09, 2014 at 07:35 PM 0
Share

No,no i use Box (64x64) mesh as root.

avatar image tanoshimi · Aug 09, 2014 at 07:58 PM 2
Share

""vertices[i].z" is always positive and never negative" - that rather depends on the model, doesn't it?

avatar image Scribe · Aug 09, 2014 at 10:12 PM 1
Share

normalizing certainly should not change the sign of anything though you could try doing the normalizing manually by changing line 8 to:

 verticesN[i] = vertices[i] * 50/vertices[i].magnitude;

I'd be very surprised if you see any difference!

alternatively you could add a few lines:

 if(verticesN[i].z*vertices[i].z < 0){
     Debug.Log("normalized vertice has a different sign to normal: " + verticesN[i].z + ", " + vertices[i].z);
 }

And see if that prints anything, I would agree with tanoshimi that is is unlikely that the code is wrong and more likely that the mesh is not 'centred' i.e. one side of you cube has 0 z values (the pivot point for rotation of the mesh is not in the centre of the cube but at a side)

avatar image Bunny83 · Aug 10, 2014 at 12:12 AM 1
Share

I wouldn't involve the normal in that debug log. If your z axis is never negative it might not be negative. You can do those tests:

 // use the unaltered vertices for this:
 if(vertices[i].z < -0.001f){
     Debug.Log("z has a negative value: " + vertices[i].z);
 }

You could also accumulate all vertex positions to get the geometric center. If your vertices are actually around 0,0,0 the result should be 0,0,0 or quite close to. If the vector is quite huge, the mesh probably isn't centered on 0,0,0

edit

ps: This line Vector3[] verticesN = vertices; is pretty pointless. It will make your "verticesN" variable to reference the same array as your vertices variable. So you only have one array and effectively doing:

 vertices[i] = vertices[i].normalized * 50;

btw: For debugging it might be a problem to only show every 100. vertex as depending on your mesh topology you might produce a strange pattern which actually doesn't exist.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Editor Viewport not working since I tried splitting the Scene and Game tabs 1 Answer

Debugging locals, vector3 normalized repeating 1 Answer

C# Dividing Gameobject List by Half 1 Answer

Angle gun 2D 0 Answers

help with making enemy projectile fly at player at one speed 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