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
2
Question by Elenesski · May 20, 2013 at 05:47 AM · meshdynamic

Can you generate a mesh at runtime?

I am a total beginner to unity but a veteran programmer with 10 years of C# and even more OO development. I am thinking about writing a 3D space-based game that involves the creation of an object that is an "engine" consisting of various parts. Once the object is created, I don't need to "render" the inner structure of the object in real time, the movement of a shell, a mesh, to cover the object is all I would need to move the object in 3D space.

I have scanned the documentation looking for something that tells me this is possible, but cannot find anything. Even Unity's video documentation says that all scene objects must be created in a 3D tool and then imported; yet, I see other videos that imply this kind of strategy is possible.

Is it possible for unity to generate a "mesh" within the game itself, or are all 3D objects prefabricated without any kind of dynamic way to create them?

I fully acknowledge that the actual mesh creation (the calculation of the location of all the triangles) would have be be written by me in some fashion, even if what I need is fundamentally possible.

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

3 Replies

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

Answer by DaveA · May 20, 2013 at 06:26 AM

You REALLY scanned the docs? Cuz here it is: http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html

Comment
Add comment · Show 2 · 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 Elenesski · May 20, 2013 at 01:49 PM 0
Share

Seriously I did. But when you know where to look, it's easy, when you don't ... it's hard to take the first step.

avatar image AlucardJay · May 20, 2013 at 01:59 PM 0
Share

You can also use your title as a search string, just include the keyword Unity : http://www.google.com/search?btnG=1&pws=0&q=Unity+Can+you+generate+a+mesh+at+runtime

avatar image
3

Answer by Bunnybomb7670 · May 20, 2013 at 06:05 AM

You can yes, you can procedurally generate a mesh, however It is not recommended for high geometry meshes because your going to have a very painful job of making it. To create a mesh, you do :

 var newVertices : Vector3[]; // stores vertices of mesh
 var newUV : Vector2[]; // stores UV ( texture coords )
 var newTriangles : int[]; // stores triangles
 function Update () {
     var mesh : Mesh = GetComponent(MeshFilter).mesh;
     mesh.Clear(); // clear all the mesh data..
     // Do some calculations...
     mesh.vertices = newVertices; // assign the meshes vertices
     mesh.uv = newUV; // assign the meshes UVs
     mesh.triangles = newTriangles; // assign the meshes triangles
 }

Looking at that code, you can see the basic structure of a mesh. The mesh basically stores an array of upto 65000 vertices and lots of triangles ( not sure of the limit ) aswell as UVs , Vertex Colors and much more.

Vertices accept a vector3 for a coordinate, triangles are integers, each integer is a vertex index, so for example , a Triangle array with the values 1 , 2 , 3 means it would create a triangle between the vertices array index 1 , 2 , 3 . You may need to do some messing around sometimes because depending on the direction which you define your triangles, clockwise or anticlockwise, your going to be flipping the triangles normal direction and possibly making it invisible.

Overall, I can say that if you want to make a high poly detailed mesh, I do recommend that you design it yourself in a 3D modelling program such as blender, It will take less time to do.

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 Elenesski · May 20, 2013 at 01:52 PM 0
Share

I plan on calculating all the points, then use a memento.

avatar image
1

Answer by RhoneRanger · May 20, 2013 at 06:25 AM

Look into the Instantiate function, where you load in a mesh at a certain position.

 GameObject go = Instantiate(MyMesh,myPosition,Quaternion.identity) as GameObject;
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 Bunnybomb7670 · May 20, 2013 at 06:41 AM 0
Share

he means procedurally, "Even Unity's video documentation says that all scene objects must be created in a 3D tool and then imported"

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

17 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

Related Questions

Voxel Mesh has Lines Between the Voxels 1 Answer

Help with generating dynamic mesh 0 Answers

Dynamically Generate Plane Mesh in App from Vertices 1 Answer

Why do meshes break batches on certain positions 1 Answer

how to add multiple vertices in a mesh at runtime 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