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
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.
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.
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).