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 sanderm · Nov 04, 2014 at 11:21 AM · importruntimeobj

Problem loading .obj runtime

I save my gameobject on disk using http://wiki.unity3d.com/index.php?title=ExportOBJ.

all is good - Blender opens nicely.

I load from disk using http://wiki.unity3d.com/index.php?title=ObjImporter

Loaded object looks like broken or empty alt text

I am struggling with it for a week now. I have googled and tried but nothing works. I think I am missing something simple here.

 ObjImporter oi = new ObjImporter ();
         objToSpawn = new GameObject("TAG_0");
         //Add Components
         objToSpawn.transform.parent = o.transform;
         objToSpawn.AddComponent<MeshFilter>();
         objToSpawn.AddComponent<MeshRenderer>();
         var asd = oi.ImportFile (filepath);
         objToSpawn.GetComponent<MeshFilter> ().mesh = asd;
         objToSpawn.AddComponent<MeshCollider>().mesh = asd;
 
     //http://docs.unity3d.com/ScriptReference/Mesh-uv.html
         Vector3[] vertices = objToSpawn.GetComponent<MeshFilter>().mesh.vertices;
         Vector2[] uvs = new Vector2[vertices.Length];
         int i = 0;
         while (i < uvs.Length) {
             uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
             i++;
         }
         objToSpawn.GetComponent<MeshFilter>().mesh.uv = uvs;
 
         objToSpawn.GetComponent<MeshFilter> ().mesh.RecalculateNormals();
         objToSpawn.GetComponent<MeshFilter> ().mesh.RecalculateBounds ();
 
         GameObject primitive = GameObject.CreatePrimitive(PrimitiveType.Plane);
         primitive.active = false;
         Material diffuse = primitive.GetComponent<MeshRenderer>().sharedMaterial;
         DestroyImmediate(primitive);
 
         //fix diffuse
         objToSpawn.renderer.sharedMaterial = diffuse;
         objToSpawn.renderer.material.color = Color.red;

thank in advance fro anykind of help

brokenobj.png (1.6 kB)
Comment
Add comment · Show 4
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 AlwaysSunny · Nov 04, 2014 at 11:21 AM 0
Share

Looks like inverted normals, possible unintended edge splitting - anything else?

Are you making any edits in Blender? What happens if you export then import without making any changes whatsoever?

avatar image sanderm · Nov 04, 2014 at 04:29 PM 0
Share

I made no changes in Blender - I opened in Blender only to confirm visually the result, did not save/export in Blender. This object is generated with unity#d obj exporter.

Other user case - I also made simple cube in Blender - exported to .obj and imported using objImport - visually same case, seems broken or inverted somehow.

But thank You AlwaysSunny, I will gooogle "inverted normals" and see what comes out.

avatar image billyjoetyler · Nov 04, 2014 at 05:24 PM 0
Share

In blender go into edit mode select everything and press Ctrl+N and it will set or normals to face outwards.

avatar image sanderm · Nov 04, 2014 at 06:27 PM 0
Share

actually problem has quite nothing to di with blender. Export is done using ExportOBJ and import is done using ObjImport.

$$anonymous$$esh itself seems to be right in editor view. I try now to add material or texture to it runtime.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Gf15a4 · Nov 04, 2014 at 10:41 PM

Why are you loading objects like that? Theres a much simpler way... Using resources load... You can load any object as long as its prefab or imported properly

http://docs.unity3d.com/ScriptReference/Resources.Load.html

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Material from .obj not being imported in Android App 0 Answers

Add Script to Project at Runtime 1 Answer

Unity is removing vertices from my mesh when I want to keep them 1 Answer

Unity 5 - Import mesh vertices / edges only 0 Answers

Importing 3ds-file 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