[Solved] Dynamic asset loading of json model throws "Unexpected end of JSON input"

I try to host my own json model file to be used in the playcanvas script.
I have tried hosting both in AWS S3 bucket as well as a simple local python server. But in both cases I get
“Uncaught SyntaxError: Unexpected end of JSON input”.
I can download the json file just fine with all the content in a browser. See my hosting below.

However the asset loads fine from this url (form someone else)

Not sure how, Am i supposed to set some headers to get playcanvas to download right ?


Your project link is broken. I guess we have to access to this scene.

I tested your json and it’s valid.

However, I tested it like
pc.app.assets.loadFromUrl("https://s3-us-west-1.amazonaws.com/exkuisite-floorplans/Gas+Station.json", "model", function(result) {console.log(result)});

And the problem is not it JSON.

Server returns this:

But for https://s3-us-west-1.amazonaws.com/exkuisite-floorplans/Gas+Station.mapping.json.

This file is missing and your model depends on it.
All you have to do is place it along the model’s json.

Thanks for checking @mikefinch
AWS S3 hosting doesn’t add CORS header allow all by default, so it was throwing when accessed via API !
After seeing your code i realized i could actually debug using “console.log” in play canvas, haha.
This is going to be soo convenient going forward to debug stuff.
Saved my day <3


But still, you have mapping.json on github but not on hosting.

Oh that explains why it isn’t loading any colors when i load from my url. I thought all I need to host is the json file to load a model with material and colors. I guess not ?
I do see when i load the json from github link, browser also downloads some images and a .mapping json file and what appears to be a material json file !
As a newbie, this is pretty confusing.
Right now I get my models from a designer in fbx file, and then

  1. I use the playcanvas editor to convert it to json.(drag drop)
  2. Host that json file that editor created
    I thought these 2 steps are enough to use that fbx model in playcanvase. But i guess not.
    What’s the best way to convert these fbx files to be able to load dynamically ?

You are doing everithing right! When you downloaded your asset, just host the whole directory.

As a side question, is there a reason you want to self host the assets on your servers instead of it being in the project?

PS when you download the model json file from the editor, it should package the mappings, textures etc as a zip which all need to be upload to your server as is (unless you are willing to edit the files and change the files paths)

Thanks @mikefinch @yaustar
Yes, For following reasons I’m thinking to self host:

  1. I’m building a website where people can view there floor plans and add furniture and design their home. So there are going to be lots of 3d floor plan models coming soon and hundreds of furniture models being added. And the website has to show them as options as and when new models arrive. It seems easy to give someone access to a S3 bucket and ask them to upload models than give them permission to the editor, where they can fuck something up.

  2. These model files can potentially go beyond the size limit that I have on my paid account.

  3. I want to load these models dynamically and only load models that the customer tries out in the website. Thereby also reducing page load time.

  4. It doesn’t seem too convenient to manage 100s of assets in editor. (I may be wrong ?) Also will the editor get too slow if i have so many models in there perhaps ?

To get a sense of it, here’s my site http://exkuisite.surge.sh/

@yaustar As a newbie, I’d love your feedback on the above reasons to host dynamically. Am I wrong with any of those hypothesis ?

  1. Seems to be more of a workflow issue where the lack of version control in PlayCanvas doesn’t help. That said, the Organisation plans does have upload/download of projects so you can backup revisions of the project. (I use a Python script which can be used to automate the process with CI systems). Using S3/external server is valid and not a bad way to go. The downside is that you can’t preload any of the assets or will need a custom loading script to do the preload.

  2. That’s fair. Just be cautious of the individual size of the files in terms of time for the end user to download and view the asset.

  3. That can be done within the PlayCanvas editor by unticking the Preload checkbox on the assets (eg https://developer.playcanvas.com/en/tutorials/load-assets-with-a-progress-bar/)

  4. It’s doable and IIRC, there is some lazy loading in the assets view so performance shouldn’t be a problem.

TL;DR: Your approach is fine and builds will be faster as the data is external. The downside is that the standard download of the assets from the editor don’t include the DXT, ETC1 and PVR textures which really help with VRAM usage, especially in your case.The only way I’ve seen to get them is either through a web publish or exporting the project which is a little cumbersome.

I think another user has done offline conversions of the texture files but offhand, I can’t remember how the mappings work.

Thanks @yaustar. Appreciate your answer :slight_smile: