Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Chitransh · Jun 19, 2013 at 11:29 PM · importcomponentvuforiaaugmented realitymodels

How to use ObjImporter script available on unity wiki?

  1. I copied this (http://wiki.unity3d.com/index.php?title=ObjImporter) into a script.

  2. It gave an error (type should be of a monobehaviour to attach a component). So i added "monobehaviour" to the class defination public class ObjImporter : MonoBehaviour{ }

  3. I used the following script

    using UnityEngine; using System.Collections; using System.IO;

    public class importOBJ : MonoBehaviour {

      // Use this for initialization
         public GameObject emptyPrefabWithMeshRenderer;
         public string meshPath;
         public GameObject spawnedPrefab;
             
         void Start () {
             Mesh importedMesh= GetComponent("ObjImporter").ImportFile(meshPath);
             spawnedPrefab=Instantiate(emptyPrefabWithMeshRenderer,transform.position,transform.rotation);
             spawnedPrefab.GetComponent(MeshFilter).mesh=importedMesh;
         
         }
         
         // Update is called once per frame
         void Update () {
         
         }
     }
     
    
  4. It gives the error "UnityEngine.Component does not contain the definition for ImportFile"

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
0

Answer by Slayerkris · Jun 20, 2013 at 09:45 AM

 Mesh importedMesh= GetComponent<ObjImporter>().ImportFile(meshPath);

This should make it work.

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 Chitransh · Jun 20, 2013 at 01:15 PM 0
Share

thanks a lot...:). I shall try this as well, but I have made it work by using a plugin.

avatar image
0

Answer by akeplinger · Nov 17, 2014 at 08:59 PM

Using ObjImporter and a sampling of some OBJ test files found online I'm not seeing the uv maps after calling ImportFile()

After assigning the mesh I am calling the following: GetComponent().mesh.RecalculateBounds(); GetComponent().mesh.RecalculateNormals();

It may be the models that I'm testing with. At first the normals were incorrect, but the Recalculate commands resolved that.

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 nick.mann · Feb 18, 2015 at 02:40 PM 0
Share

When trying to use this importer my code is similar to that above:

public GameObject emptyObject; public string objPath = "C:/Users/Nick $$anonymous$$ann/Desktop/Zombie.obj"; public GameObject spawnedPrefab;

 public void LoadOBJAtRuntime(){
     (*)$$anonymous$$esh imported$$anonymous$$esh = GetComponent<ObjImporter> ().ImportFile (objPath);
     spawnedPrefab=Instantiate(emptyObject,transform.position,transform.rotation) as GameObject;
     spawnedPrefab.GetComponent<$$anonymous$$eshFilter>().mesh=imported$$anonymous$$esh;
 }

I get a NullReferenceException:Object reference not set to an instance of an object on the first line of LoadOBJAtRuntime. (*)

Any ideas?

avatar image
0

Answer by vagelis199 · Nov 07, 2020 at 11:32 PM

@Chitransh You're not supposed to use ObjImporter in Mono Behaviour that's why you get that error at the beginning, it is its own public class that could be accessed by calling ObjImporter()

     //create a ObjImporter Object
     ObjImporter ImporterMesh = new ObjImporter();
     // create a mesh and use ObjImporter to import your obj file and make it a mesh
     Mesh MyMesh  =  ImporterMesh.ImportFile(ObjPath);
     // then asign the mesh object to a mesh filter in your scene
     GameObject.GetComponent<MeshFilter>().mesh = MyMesh;
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

Unity 5.3.4f1 + Vuforia 5.5.9 = error 3 Answers

Heating Issue in AR android app 1 Answer

How to control an Vuforia AR character using the Third Person Controller in Unity? 1 Answer

Augmented Reality on a large cylindrical cloumn 0 Answers

I cant get a Video to play on an imported object from Blender 2.8 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