Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by OswaldP · Feb 01, 2016 at 04:42 PM · meshlightingprocedural meshfaces

Procedurally generated mesh having some faces that don't receive light

Hi,

I'm having some troubles using lights on a procedurally generated mesh. It seems that depending on the point light position, some faces will not receive light, even if they are fully exposed.

This is how I generate the mesh :

 using UnityEngine;
 using System.Collections;
 
 public class MeshGen : MonoBehaviour {
 
     public GameObject obj;
 
     void Start () {
         generate();
     }
 
     void generate(){
         Vector3 pt0 = new Vector3(0,0,0);
         Vector3 pt1 = new Vector3(0,1,0);
         Vector3 pt2 = new Vector3(1,1,0);
         Vector3 cross = GetNormal (pt0, pt1, pt2);
         Vector3 pt3 = pt0+cross;
         Vector3 pt4 = pt1+cross;
         Vector3 pt5 = pt2+cross;
         Vector3[] newVertices = {pt2, pt1, pt0, 
             pt3, pt4, pt5, 
             pt0, pt1, pt3, 
             pt1, pt4, pt3, 
             pt0, pt3, pt2, 
             pt2, pt3, pt5,
             pt1, pt2, pt4, 
             pt2, pt5, pt4};
         int[] newTriangles = {0,1,2,
             3,4,5,
             6,7,8,
             9,10,11,
             12,13,14,
             15,16,17,
             18,19,20,
             21,22,23
         };
         GameObject myFace = (GameObject) Instantiate(obj, new Vector3(0,0,0), Quaternion.identity);
         Mesh mesh = new Mesh();
         myFace.GetComponent<MeshFilter>().mesh = mesh;
         mesh.vertices = newVertices;
             Vector3[] vertices = mesh.vertices;
         Vector2[] uvs = new Vector2[vertices.Length];
         for (int i=0; i < uvs.Length; i++) {
             uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
         }
         mesh.uv = uvs;
         mesh.triangles = newTriangles;
     }
 
     public static Vector3 GetNormal(Vector3 a, Vector3 b, Vector3 c) {
         Vector3 side1 = b - a;
         Vector3 side2 = c - a;
         return Vector3.Cross(side1, side2).normalized;
     }
 }


And this is the result (the generated mesh is on the left) :

Illustration

Could someone tell me what I'm doing wrong please ?

Thanks a lot.

lightmesh.jpg (141.7 kB)
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 hexagonius · Feb 01, 2016 at 09:36 PM 0
Share

I think you're forgetting the call to RecalculateNormals at the end.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by OswaldP · Feb 01, 2016 at 09:36 PM

I found the solution to my problem, I only needed to recalculate the normals of the mesh at the end of the mesh generation script using :

 mesh.RecalculateNormals();

Hope it will help someone else !

Comment
Add comment · 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

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

45 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 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

How is a Mesh Built? 1 Answer

Can't get submesh to work 1 Answer

Issue with Modifying Vertices of multiple Game objects 0 Answers

Procedural Mesh Problems 0 Answers

Find the volume of an object that is underneath a mesh 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