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 Schnodahipfe · Jun 27, 2013 at 10:03 AM · shadermeshmaterialimportexport

Mesh Obj export/import WITH SHADER REFERENCE

Hi everyone,

I've been playing around with the ObjExporter to export several meshes to an .obj file at once. In order to make Unity use existing materials when importing a previously exported mesh I simply put a folder called "Materials" with the original materials into the obj's folder before the import and changing the default import settings.

As I see it the ObjExporter doesn't properly export the materials (it only writes grey materials to the .mtl file). However, the .mtl file is still useful in the way that it tells unity which mesh uses which material and with the correct import setting it simply uses existing materials with the same name that is used in the .mtl file and referenced in the .obj file by usemtl .

In addition to the material reference I really need a reference to shaders. In my case game objects in the scene may have the same material but I assign different shaders to them during runtime.

Is there anything like "`useshader`" that I can write to the .obj file so that unity uses the material specified by usemtl with the specified shader (which preferably lies within a folder called "Shaders" next to the "Materials" folder ???

This is really important because the shaders are assigned dynamically to a lot of objects and I just can't assign them myself after import !!!

Thanks in advance for your help!

EDIT

Another idea that just came to me is to write the references to a file during the .obj export and write a custom import script that assigns the shaders afer the model was imported according to this file. How would I go about doing this ???

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

Answer by Schnodahipfe · Jul 03, 2013 at 09:13 AM

So in the end I wrote the references to a TextAsset. Then, in another project where I import the previously exported mesh, I had to attach a script to the GameObject (that was initialized from prefab, which is turn was created by unity from the .obj and .mtl files), which reads the TextAsset and assigns the shaders accordingly.

Not really a pretty solution :-/ . Does anyone have a better solution in mind?

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 OllyNicholson · Jun 27, 2013 at 10:35 AM

I believe the best way to do this would be to reference materials instead at runtime as that is primarily where you choose which shader to use (think of your unity project as the master material library) So in other words setup the appropriate library of materials in Unity first, then when you assign the material at runtime as discussed here for example:

http://answers.unity3d.com/questions/8993/change-material-of-an-object.html

It uses the appropriate shader you have setup for it in Unity.

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 Schnodahipfe · Jun 27, 2013 at 11:54 AM 0
Share

I think I didn't really phrase my question well enough. I generate meshes at runtime and save these to an .obj file. I want someone else to be able to import these in another project and it's supposed to look the same as in my generated scene.

The problem is, that I assign different shaders (with different Offset values) to make certain objects be displayed on top of others. However, the .mtl file only references "static" materials which have exactly one shader (the initial one I also use during the creation of the meshes).

What I want to do is tell unity "Use this material when importing, but don't use the shader that is already specified in this material, but use the one that I specified in my file".

I've done some more research and I think the only way to do this is to save the information which mesh object uses which shader in a file. Then in a custom AssetPostprocessor I could read this file and the reassign the shaders accordingly.

avatar image
0

Answer by InfiniteDesign · Oct 19, 2013 at 11:11 PM

sketchup(with plugin) exports .obj with a .mtl that unity recognizes and assigns correctly as long as there is only a single colour per sketchup group....maybe you can import into sketchup and export to something unity recognizes.....

nothings for sure here. goodluck

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

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

exporting custom point/vertex attribute from Houdini to unity 0 Answers

Create a hole in a mesh using a shader 0 Answers

How to combine several Materials into one? 0 Answers

Weird problem on the normals of an imported model. please help!! 4 Answers

How to light back side of quad mesh same way as front side? 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