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 kerbo · Nov 07, 2012 at 08:06 PM · c#meshproceduralmeshfilter

Procedural array of meshes problem / solved

Hi guys! Here is my attempt to generate and render an array(list) of simple rectangle meshes. List contains 100 items but Unity renders the only one (i suppose that the problem is because of incorrect using of MeshFilter but im not sure). Also i tried to make simple color changing with OnMouseOver() and here is also fail. Any suggestions? Thanks in advance for help!

*on a screenshot the cube is only measure tool.

the code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class test_cuba : MonoBehaviour {
     
         List <Mesh> shtuchki = new List<Mesh>();
 
     void Start () {        
         
         for(int n= 0; n < 10; n++){
             for (int m=0; m<10; m++){
                 MeshFilter mfilter = gameObject.GetComponent<MeshFilter>();
                 Mesh messh = new Mesh();
                 mfilter.sharedMesh = messh;
                 
                 Rect rt = new Rect (n,m,1,1);
                 
                 /*Debug.Log ( rt.x);
                 Debug.Log (rt.y);*/
 
                 messh.vertices = new Vector3 [] {
         
                     new Vector3(rt.x,rt.y,0), // ver0
                     new Vector3(rt.xMax,rt.y,0), // ver1
                     new Vector3(rt.xMax,rt.yMax,0),     // ver2        
                     new Vector3(rt.x,rt.yMax,0), //ver3
             
                 };
         
                 messh.triangles = new int [] {
                     0,1,2,
                     2,3,0,
             
                 };
                 renderer.material.color = Color.white;
                 
                 messh.RecalculateBounds();
                 messh.RecalculateNormals();
                 shtuchki.Add(messh);    
                 
                 Debug.Log("mesh_number: " + shtuchki.Count); 
                 
             }
         }    
         
         
     }    
     
     void Update () {
         
         for(int v=0; v<shtuchki.Count; v++){
             Graphics.DrawMeshNow(shtuchki[v], Vector3.zero, Quaternion.identity, 0);
         }    
         
     }
     
     void OnMouseOver() {
         renderer.material.color = Color.red;
     }
 }
 

ZIP project: https://www.dropbox.com/s/bj883s3ovnrvpuu/graphs.zip

screen shot 2012-11-07 at 20.20.05.png (105.0 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 kerbo · Nov 07, 2012 at 10:38 PM 0
Share

$$anonymous$$aybe the solution is to create for each mesh element in array its own GameObject with $$anonymous$$eshFilter an $$anonymous$$esh Collider and then unite them as children of a main parent GameObject?

1 Reply

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

Answer by FakeBerenger · Nov 07, 2012 at 11:14 PM

You're writing over the same mesh at each loop iteration, so the only mesh you see is the last one. You can either append all the triangles in a single mesh (but you won't be able to change the color of a single one, not easily at least), or as Kerbo says, create a game object with it's own meshFilter for each triangle.

Don't forget to add a mesh collider, or the OnMouseXXX won't work (they use raycasts)

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 kerbo · Nov 08, 2012 at 08:12 PM 0
Share

Thank you for quick answer!

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

11 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

Related Questions

Trouble Creating a Procedural Mesh on a Rotated Game Object 1 Answer

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

Converting a number of runtime-created prefab GameObject cube's for export 0 Answers

Generate a highpoly sphere with mesh collider procedurally 2 Answers

How do you completely clear a mesh? 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