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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Ariopolis · Jul 15, 2014 at 09:40 PM · c#mesh

Setting Mesh objects in C# only renders Triangles

I am trying to render mesh objects from a C# script. For some reason when I set mesh.verticies to have 4 or more verticies, and mesh.triangles to have a multiple of 3 indices I only get the result of a triangle.

Also, this is a project set up for 2D.

I have an object in my Unity hierarchy that has the following components: Mesh Renderer, Mesh Filter, Polygon Collider 2D.

Here is the code that I am using

 GameObject.Find("Building Object").GetComponent<MeshFilter>().mesh.vertices = new Vector3[] {new Vector3(26, -44, 0), new Vector3(34, -74, 0), new Vector3(54, -68, 0), new Vector3(45, -39, 0), new Vector3(26, -44, 0), new Vector3(26, 44, 0)};
 GameObject.Find("Building Object").GetComponent<MeshFilter>().mesh.triangles = new int[] {0, 1, 2, 3, 4, 5};

I have found that if I change mesh.triangles to be {0, 1, 2} I get a different triangle. I assume that this means that I am taking the first, second and third verticies from mesh.verticies.

Thank you in advance.

Comment
Add comment · Show 5
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 rutter · Jul 15, 2014 at 08:57 PM 0
Share

Not sure if I'm able to reproduce the problem.

This gives me two large triangles in an empty scene:

 [RequireComponent(typeof($$anonymous$$eshRenderer))]
 [RequireComponent(typeof($$anonymous$$eshFilter))]
 public class Dyn$$anonymous$$esh : $$anonymous$$onoBehaviour {
     void Start() {
         $$anonymous$$eshFilter meshFilter = GetComponent<$$anonymous$$eshFilter> ();
 
         $$anonymous$$esh mesh = new $$anonymous$$esh();
         mesh.vertices = new Vector3[] {new Vector3(26, -44, 0), new Vector3(34, -74, 0), new Vector3(54, -68, 0), new Vector3(45, -39, 0), new Vector3(26, -44, 0), new Vector3(26, 44, 0)};
         mesh.triangles = new int[] {0, 1, 2, 3, 4, 5};
 
         meshFilter.mesh = mesh;
     }
 }
avatar image Ariopolis · Jul 16, 2014 at 02:14 PM 0
Share

@rutter - I started a new 2D project to test the code that you posted and I only see one triangle. Take a look at my screenshot. one triangle

screen shot 2014-07-15 at 5.32.52 pm.png (20.1 kB)
avatar image Ariopolis · Jul 21, 2014 at 06:22 PM 0
Share

Is my problem a licensing issue? Currently I am using the free version of Unity and not Unity Pro.

avatar image $$anonymous$$ · Jul 21, 2014 at 08:40 PM 1
Share

Nope there's no problem with licensing.$$anonymous$$aybe your viewing angle is the wrong one.Try viewing it from a different side.

avatar image Ariopolis · Jul 22, 2014 at 09:53 PM 0
Share

If all the triangles are set in the x-y plane shouldn't they all be visible from the same perspective? And with the mesh.triangles that were set in rutter's example and $$anonymous$$e, there should not be any overlapping vertices or triangles

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by $$anonymous$$ · Jul 21, 2014 at 08:32 PM

Triangles is an int[].Every three values is a triangle.Each value is the index of a vertex on the vertices array. So in @rutters' example vertices with index 0,1,2 is one triangle and vertices with index 3,4,5 is the other.Unfortunately I don't know the mesh you are trying to render so I can't tell you which triangles to make.

Comment
Add comment · Show 1 · 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 Ariopolis · Jul 22, 2014 at 09:54 PM 0
Share

The problem that I am having is not so much the final shape of the mesh as it is that every mesh I manipulate in code is only a triangle.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Vertex coloring isn't working 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Distribute terrain in zones 3 Answers

Set UVs depending on input 1 Answer

Generate mesh from faces, invisible 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