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 giulio-pierucci · Feb 13, 2015 at 09:49 PM · meshproceduralvertextriangles

Procedural mesh creation issue

Hi all!

I'm trying to do a script that creates a mesh from scratch. I follow Unity Reference Example 1:

http://docs.unity3d.com/ScriptReference/Mesh.html

I try to do a quad: 4 Vertices, 4 Normals, 4 colors, 4 uv (primary), 4 uv (secondary), 6 triangles

All are drawn correctly. But if I want add tangents (4) i get this strange error: "Mesh.tangents is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array."

I checked with debug that vertices are 4 and tangent too.

What's wrong? Is a strange bug of mi Unity version?

Thanks in advance

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by giulio-pierucci · Feb 14, 2015 at 12:18 AM

I'm very sorry. It's my fault. For explain better, I write a stupid example to post, with my big surprise, works like a charm. I'm pretty sure that the problem is elsewhere.

then, by way for apologies, i post the stupid script:

 using UnityEngine;
 using System.Collections;
 using System.Linq;
 
 public class ProceduralQuad : MonoBehaviour {
 
     [SerializeField] Material material;
 
     Mesh mesh;
     Color32 c = Color.red;
     Vector4 t = new Vector4(1, 0, 0, -1);
 
     void Start () { mesh = new Mesh(); }
     
     void Update () {
 
         mesh.Clear();
         mesh.vertices = new Vector3[] 
         {
             transform.right * -.5f + transform.up * -.5f,
             transform.right * -.5f + transform.up * .5f,
             transform.right *  .5f + transform.up * .5f,
             transform.right *  .5f + transform.up * -.5f
         };
         mesh.uv = new Vector2[] 
         {
             new Vector2 (0,0),
             new Vector2 (0,1),
             new Vector2 (1,1),
             new Vector2 (1,0)
         };
         mesh.uv2 = mesh.uv1;
         mesh.colors32 = Enumerable.Repeat(c, mesh.vertexCount).ToArray();
         mesh.triangles = new int[] { 0, 1, 2, 2, 3, 0 } ;
         mesh.normals = Enumerable.Repeat(-Vector3.forward, mesh.vertexCount).ToArray();
         mesh.tangents = Enumerable.Repeat(t, mesh.vertexCount).ToArray();
         mesh.RecalculateBounds();
 
         Graphics.DrawMesh(mesh, transform.position, transform.rotation, material, gameObject.layer);
     
     }
 }
 

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

19 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

Related Questions

Optimized vertex manipulation 1 Answer

Colors do not work with a mesh created in script? 3 Answers

Trouble recalculating 3D mesh's triangles after deleting verts 2 Answers

Color triangle on mesh 3 Answers

Easy way to convert a bunch of vertices to triangles or uv's? 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