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
0
Question by laurG · Aug 20, 2017 at 12:57 AM · importingobj

Does anyone know a way of importing vertex colors from a .obj file?

Hi!

I'm working on a Mesh Combiner tool for merge meshes to reduce draw calls on mobile platforms. The tool must be able to save the combined mesh on disc to be used as a prefab.

Easiest way I found was to write my own parser for .obj file and it works great, except Unity does not want to load the vertex color part.

Looking into the sharedMesh variable of the MeshFilter component that has the original meshes (imported from .fbx file), the colors are all there. Doing the same on the .obj file I created, the array with the colors is empty.

I know for a fact that the colors are parsed, because I obviously checked the .obj file while working on the parser.

In conclusion, it seems that Unity ignores vertex color information from an .obj file.

Does anyone know a way of importing vertex colors from an. obj file?

Thank you in advance!

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
Best Answer

Answer by Bunny83 · Aug 20, 2017 at 02:11 AM

Uhm, the OBJ format doesn't support any vertex colors. It only supports position, normal and one set of texture coordinates. It also has support for parameter space vertices which are used to define free-form geometry. However most trivial parsers don't support this at all. Anyways the standard does not define any vertex colors. So if your file actually contains vertex colors it's either a custom extension of the OBJ format which nobody understands or the format you deal with is not an OBJ file in the first place. OBJ is a very simple and trivial format. It's not really suitable for what you want to do.

Do you actually work on an editor extension or on a runtime script / framework? Keep in mind that at runtime you can't create new assets / prefabs. Inside the editor you can simply serialize your "Mesh" instance into an .asset file. This will create a new "model asset" which supports everything the Mesh class supports. It's the actual Mesh asset format that Unity uses to store your imported meshes in your project after it has been imported.

If you still want to somehow use your "OBJ" file, you should post a stripped down example OBJ file that you're using that contains "vertex colors".

Comment
Add comment · Show 3 · 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 Bunny83 · Aug 20, 2017 at 02:13 AM 0
Share

ps: This statement is a bit confusing as well:

Unity does not want to load the vertex color part

Didn't you say that you used your own OBJ parser? That would mean you do the loading, not Unity.

avatar image laurG · Aug 20, 2017 at 03:29 AM 0
Share

Hei @Bunny83. Thanks for the fast reply.

I read around forums and you are right: the standard .obj file format does not support vertex colors, but they are used informally by some people.

As for the parser, I only created the exporting (writing to file) part, since I was relying on Unity to load it back.

Anyway, I actually found this fbx exporter (https://github.com/$$anonymous$$ellanHiggins/UnityFBXExporter) which is the better version of what I was trying to do. Now I just create my mesh and set it to a $$anonymous$$eshFilter on an object that I instantiate, then call the function from this fbx exporter component to save my scene object into an fbx file. And it works perfectly!

I don't use any of this at runtime, only in editor to setup my environment (which is procedurally generated using prefabs, that's why I can't just save the scene as it is and have to save the newly created meshes into files).

avatar image Bunny83 laurG · Aug 20, 2017 at 10:47 PM 0
Share

Well, as i said if the meshes are created procedurally in Unity, just save the mesh as asset by using AssetDatabase.CreateAsset and just pass in the mesh object. $$anonymous$$esh assets can be stored in a generic ".asset" file.

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

68 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

Related Questions

How to import file inside of unity program? 0 Answers

Import Project from Asset store 6 Answers

Empty triangles when loading 3D model with > 65.534 triangles 1 Answer

Where are the textures for the mouse in the Swords and Shovels tutorial? Or just the "Source Assets" folder mentioned in the video. 0 Answers

Blender Racetrack Unity Import Odd 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