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 Chelmney_ · Aug 22, 2013 at 09:20 PM · editormeshobjectcolorvoxel

Colored Voxel Meshs

Hey,

I'm trying to make a voxel editor for Ludum Dare starting tomorrow and I'm pretty much good to go except for one final aspect: Making my meshes colored. Basically I let the user put down a bunch of cubes wherever his cursor is at and when he clicks "Save" I combine the cubes into one mesh to reduce the draw calls and then save it as a prefab. This works and it lets me use the objects in the editor, but currently the meshes are missing textures, they are pink. Does anybody know how I could extend it to carry over the colors of each individual cube over to the mesh? I know it's possible and I also know I'm probably going to need vertex colors, but I have absolutely no experience when it comes to 3D mesh manipulation so I would appreciate if somebody could tell me what exactly I'm going to have to do.

Greetings,

Chelmney

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Aug 22, 2013 at 11:10 PM

Each mesh has 'colors' array. The array must be the same length as the 'vertices' array, and the colors array must be set after the vertices array. Each triangle is defined by three vertices, and the vertex color at some point in that triangle is interpolated from the color of the three vertices.

So how easy or hard it will be to add color will depend on how you are combining your cubes. In particular it will depend on whether you are sharing vertices between cubes. A vertex can only have one color, so there is no way to have two different colors for two cubes that share vertices. If you are currently sharing vertices, you will have to add logic to break this sharing. That's what @DaveA means by "Up to 8 cubes per vertex position."

If they do not share vertices, then things become much easier. You just have to set the color for the new vertices added to the combined mesh. If you are using Unity's built-in cube, there will be 24 vertices.

Note vertex color will only show up with a shader that uses vertex colors.

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
avatar image
0

Answer by DaveA · Aug 22, 2013 at 09:46 PM

Use sub-meshes. Each sub-mesh has its own material, hence can have own color and texture.

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 robertbu · Aug 22, 2013 at 10:04 PM 2
Share

@DaveA - It appears from the question that the only property he wants to set is color, and the reason he is combining blocks is performance. From a performance standpoint wouldn't he be better of just setting the vertex colors for the vertices associated with each block and not using submeshes? If he uses multiple different materials wouldn't he get a separate draw call for each block? He would need a shader that handles vertex color, but the whole mesh would draw in a single draw call. At least that is how I understand it from my shaky understanding of meshes.

avatar image DaveA · Aug 22, 2013 at 10:37 PM 0
Share

Yeah that's probably right. So he'll have to duplicate vertices for adjacent cubes that have different colors though, wouldn't he? Up to 8 cubes per vertex position. Fun little algorithm.

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

16 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

Related Questions

Render voxels with RGB data passed to them 1 Answer

How to check if object is skewed ? 2 Answers

Alter Meshes in Editor by Script without warning 2 Answers

Changing Mesh Vertex Colors in editor 0 Answers

How to make colored voxels?!? 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