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 /
avatar image
1
Question by Wolfie · Jan 03, 2017 at 10:29 PM · c#meshlistvoxelmodelling

How can I add complex mesh data directly to a list through code?

I'm attempting to create a voxel system that uses a variety of custom block shapes.

Each chunk has lists for vertices, UVs, triangles and suchlike that are easily populated through code when creating cubes, as the components for each face are very short, simple and logical. However, when implementing more complex meshes for each face, although it's still possible, it soon becomes prohibitively complex.

Therefore, is there a way I can import mesh data from a 3D modelling application and add those data to my vertex/uv/triangle lists directly through code. I know I could instantiate a lot of prefabs and then combine their meshes, but this seems very inefficient.

     // Mesh prefabs
     public Mesh testMesh;
     public Mesh testCollisionMesh;
 
     // Lists to hold mesh data, including for collision mesh
     public List<Vector3> vertexList = new List<Vector3>();
     public List<int> triangleList = new List<int>();
     public List<Vector2> uvList = new List<Vector2>();
     public List<Vector3> collisionVertexList = new List<Vector3>();
     public List<int> collisionTriangleList = new List<int>();
 

The lists here are where I'm storing the data for creating my procedural meshes. The Mesh variables at the top have the mesh component of an imported model dragged onto them in the inspector.

How can I add data to my lists from the arrays in the mesh variables? I swear this can't be too difficult, but nothing I try seems to work. Going from lists to arrays isn't so hard, so I've no idea why I can't find a way to do the reverse without the console lighting up like a christmas tree.

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
1

Answer by Bunny83 · Jan 04, 2017 at 02:51 AM

Well, if you want to integrate / combine an existing mesh into a larger mesh chunk you simply have to add all of it's vertices and remember the index of the first vertex that you add. When you add the triangle indices you just have to add the offset where the first vertex is located to all the indices.

The vertex positions has to be in a unique space. So the matrices localToWorld and worldToLocal of the Transform component are quite useful if you want to integrate an existing mesh object into another mesh. If you don't have an existing object, creating the desired transformation matrix is quite easy with the Matrix4x4.TRS

Of course a vertex can consist of a position, color, normal, uv coordinates and other vertex properties. So when adding a vertex you want to copy all of it's properties. Keep in mind that the normals / tangents need to be transformed as well.

Combining meshes into a single mesh of course requires that all meshes use the same material. A bit more complicated than combining the meshes is to integrate seperate textures into an atlas system and adjust the UV coordinates accordingly. Though your question is way too unspecific to go into more detail as it highly depends on your system.

There are already many games out there that use such a system. Even some minecraft mods use imported meshes. Games like SpaceEngineers(custom engine) and Robocraft(Unity) also use high complexity meshes in their voxel systems.

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 Wolfie · Jan 04, 2017 at 06:55 PM 0
Share

Thanks for having a stab at this, it's much appreciated and there's still a lot of useful information in your answer. However I think I might have worded my question poorly - I've updated the question to clarify what exactly I'm looking for.

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

270 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 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 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 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 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 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 to create a custom cuboids at runtime? 1 Answer

Distribute terrain in zones 3 Answers

Cube Voxel not working. Help please 1 Answer

Procedural generated mesh problem 1 Answer

How come do I keep getting this error on my voxel script 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