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 Bartalo · Feb 24, 2014 at 04:53 PM · javascriptraycastvertexnormalface

How to get to know a mesh' faces normals?

Hello everyone, Can someone help me with a script i'm trying to make, i got an idea on how I could have shadowing without placing lights or learn complicated things about shaders, but i do not know where to start or even if it is possible.

I'm explaining what i'm thinking about: I'm going to attach a script to every mesh i want to have shaded, that detects every face' normal and check if it faces a specific direction (an interval of angles or something like that); then, i would send a raycast from the center of the face that's parallel to the face normal (or aiming a plane i would place in the scene) and see if it detects any collider. Then i would split the mesh in two subsmeshes: if no collider is detected, and if the face normal is in the specified boundaries, then the face is assigned to submesh1, otherwise it goes to submesh2. then to submesh1 it would be assigned the "lit" material, and to submesh2 the "shaded" one.

i suppose something like this would look very cartoonish and stylized and that's exactly what i want. i also know this would take away lot of performance, and work better as shader other than javascript but i would want to see how it works before worrying about performance or having to learn shaders (can shaders even do raycasting? i'm a real noob...)

I do not know how to use vertices and faces in javascript and found little help in Unity script reference... Sorry for bad english.

Comment
Add comment · Show 3
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 robertbu · Feb 24, 2014 at 05:05 PM 0
Share

You can get the normals from $$anonymous$$esh.normals:

 var normals = GetComponent($$anonymous$$eshFilter).mesh.normals;

avatar image whydoidoit · Feb 24, 2014 at 05:18 PM 0
Share

Wow that sounds about a hundred times more complicated than writing a shader! To get a face normal you need to average the normals of the vertices that make up the triangle. Your problem will be in working out how many triangles make up one of your "faces", I guess it might be something to do with a bunch of triangles that havea similar normal and share vertices.

Shaders can't ray cast but they can know the direction to the lights in the scene.

avatar image Bartalo · Feb 24, 2014 at 08:05 PM 0
Share

thanks, however i want proper shadows (if my computer doesn't explode trying to handle them), so i need physic raycasting to check for colliders... also i would prefear not to have lights at all in my project. For "face" i just meant a triangle. The question is how do i know that some three vertices make together a certain triangle, to be able to get the average of their normals...

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

20 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

Related Questions

Why does the raycast hit only objects/faces of a certain rotation? 1 Answer

Check texture of the face with raycast 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Raycasting2D please help 1 Answer

How to assign a Variable with a Raycast 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