Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by Vicas · Jun 18, 2014 at 05:50 PM · meshrenderersurfacealgebra

Detect a flat surface on a complex mesh?

I am trying to write a script that can detect, wether or not a given object has a flat surface somewhere on it's mesh or not.

For instance, a sphere would be a negative, where as a cube would be a positive, as this has at least one flat surface. Furthermore, a capsule would be a negative, where as a cylinder would be a positive, as the two sides of this are flat.

How do I go about doing this?

Thanks in advance.

Comment
Add comment · Show 1
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 Navy_Seals · Oct 14, 2021 at 10:07 AM 0
Share

@Vicas I am trying to find the flat surface of a mesh within a given square or rectangle area inside the mesh. Any suggestions?

1 Reply

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

Answer by Bunny83 · Jun 18, 2014 at 06:03 PM

Actually all surfaces are technically flat as all geometry is made up with triangles. However if you mean at least 1 flat-shaded surface, then you just have to compare the 3 vertex normals of each triangle. If they are equal, it's flatshaded. Something like this:

 // C#
 bool HasFlatshadedSurface(Mesh m)
 {
     Vector3[] normals = m.normals;
     int[] indices = m.triangles;
     int triangleCount = indices.Count / 3;
     for(int i = 0; i < triangleCount; i++)
     {
         Vector3 n1 = normals[indices[i*3    ]];
         Vector3 n2 = normals[indices[i*3 + 1]];
         Vector3 n3 = normals[indices[i*3 + 2]];
         if (n1 == n2 and n1 == n3)
             return true;
     }
     return false;
 }

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 Vicas · Jun 19, 2014 at 06:08 AM 0
Share

That makes sense. I should probably have said that the surface also had to be horizontal, but from your code I can take it from there, the normals just have to be the same direction as some Vector.up I figure.

avatar image Navy_Seals · Oct 14, 2021 at 10:08 AM 0
Share

@Bunny83 Suppose if I want to know whether the area of the mesh is flat or not at which point I am raycasting with a square or rectangle boundary on it. How do I achieve this? Any suggestions?

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

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Conforming a mesh path to arbitrary surface - runtime 1 Answer

Mesh renderer properties 1 Answer

Are Mesh Filters Really Necessary? 1 Answer

No renderer at top level 1 Answer

3d mesh glitch in particle system (mesh reduction when sizing down to 0) 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