# Can't load .obj file

**URL:** <https://forum.babylonjs.com/t/cant-load-obj-file/2779>\
**Category:** Questions\
**Created:** [April 25, 2019, 4:16pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779 "2019-04-25T16:16:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sme](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Sme](https://forum.babylonjs.com/u/Sme)\
**Post date:** [April 25, 2019, 4:16pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/1 "2019-04-25T16:16:56Z")

</div>

I’m sure this is an easy fix, but I am getting an error when loading my .obj file:

```
SyntaxError: Unexpected token m in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.importMesh (babylon.js:16)
    at babylon.js:16
    at f (babylon.js:16)
    at XMLHttpRequest.p (babylon.js:16)

```

I am using SceneLoader.ImportMeshAsync(). Also, I am calling import ‘babylonjs-loaders’;.

The first few lines of the .obj file are:

```
mtllib lowpoly_nature.mtl

o Object.1
v -198.714966 -221.212341 0.255110
v -192.917786 -225.607422 0.254375
v -189.864487 -231.214478 0.254341

```

But I’m not sure what I am doing wrong… any help would be appreciated 🙂

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [April 25, 2019, 4:30pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/2 "2019-04-25T16:30:27Z")

</div>

have you included the importers?

---

<div class="post-metadata">

**Author:** ![Sme](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Sme](https://forum.babylonjs.com/u/Sme)\
**Post date:** [April 25, 2019, 4:39pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/3 "2019-04-25T16:39:23Z")

</div>

Do you mean babylonjs-loaders? Yes

---

<div class="post-metadata">

**Author:** ![Sme](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Sme](https://forum.babylonjs.com/u/Sme)\
**Post date:** [April 25, 2019, 4:43pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/4 "2019-04-25T16:43:34Z")

</div>

> [@Sme](#):
>
> mtllib lowpoly\_nature.mtl

I removed this line from the .obj file, and it can load now. But I still can’t see my mesh 😓

---

<div class="post-metadata">

**Author:** ![Galen](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/galen/32/539_2.png) [@Galen](https://forum.babylonjs.com/u/Galen)\
**Post date:** [April 25, 2019, 7:48pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/5 "2019-04-25T19:48:38Z")

</div>

If your OBJ file doesn’t include a MTL file, then it generally will not load. There is also a reference to a texture if one was used, but the OBJ file will load without this.

FYI - if you remove the reference to the MTL file, it defaults to a generic material.

Galen

---

<div class="post-metadata">

**Author:** ![Sme](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Sme](https://forum.babylonjs.com/u/Sme)\
**Post date:** [April 29, 2019, 4:37pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/6 "2019-04-29T16:37:41Z")

</div>

I just decided to convert the .obj into a .babylon file in blender.

On a side note, does anybody know how to clone a mesh? I’m not sure why this isn’t working (I only see one Babylon Logo box still):

[https://www.babylonjs-playground.com/#17LHMG#8](https://www.babylonjs-playground.com/#17LHMG#8)

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [April 29, 2019, 5:21pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/7 "2019-04-29T17:21:03Z")

</div>

SceneLoader.ImportMeshAsync returns a promise - use then

Also because of auto position of camera you will then need to scale logo to see both

[https://www.babylonjs-playground.com/#17LHMG#9](https://www.babylonjs-playground.com/#17LHMG#9)

---

<div class="post-metadata">

**Author:** ![Sme](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Sme](https://forum.babylonjs.com/u/Sme)\
**Post date:** [April 30, 2019, 3:51pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/8 "2019-04-30T15:51:17Z")

</div>

Oh I see. Actually you can also do it using the await/async pattern, but it seems like the problem I had was I was trying to use the mesh at index 0, when I should have been using the mesh at index 1. It turns out that is the same problem I was having when trying to import the .obj file too, haha. Guess I need to debug a bit better before asking questions… Thanks for the help by the way.

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [April 30, 2019, 5:28pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/9 "2019-04-30T17:28:36Z")

</div>

> [@Sme](#):
>
> Actually you can also do it using the await/async pattern

I learn something new every day 😃

---

<div class="post-metadata">

**Author:** ![Sme](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Sme](https://forum.babylonjs.com/u/Sme)\
**Post date:** [April 30, 2019, 6:41pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/10 "2019-04-30T18:41:33Z")

</div>

Coming from a .NET background, its what I’m more used to haha. But it seems like a lot of javascript developers are more used to using then()

Ok, now I have a new problem. I can finally load the .obj file correctly, and the material is working too. But there is no ‘shading’ on the object. I tried messing around with the emissive/diffuse colors, but had no effect. I don’t need it to be ‘textured’, just having plain colors is fine (in this case, brown for the trunk and green for the leaves). But I am at least needing some ‘shading’ (sorry if I’m not using the proper terminology here).

![palmtree](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/7/774ebe5467cc2500fad1c2f0c4b3fa10d0480720.jpeg)

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [April 30, 2019, 7:17pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/11 "2019-04-30T19:17:57Z")

</div>

Could be positioning of lights? You may be better off asking a new question where the title indicates the problem.

---

<div class="post-metadata">

**Author:** ![Sme](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Sme](https://forum.babylonjs.com/u/Sme)\
**Post date:** [April 30, 2019, 7:47pm UTC](https://forum.babylonjs.com/t/cant-load-obj-file/2779/12 "2019-04-30T19:47:58Z")

</div>

Yeah, but I’m afraid I’d end up spamming this forum haha.

Anyways, after some fiddling, I was able to fix it by calling convertToFlatShadedMesh() on the mesh. Seems like everything is finally ok now.

Thanks again for the help.
