Json with No FBX

Is it possible to place a model into an entity using the Json file with no FBX in the Project.

So for example, I’ve downloaded the content from a previous project… I have all the assets except the FBX, and then attempt to recreate the same project manually with the Json files… Is this possible?

All attempts so far dont work. The play canvas editor does not appear to function with the Json files if there is no adjacent FBX.

Any ideas?

Unfortunately, the PlayCanvas editor won’t let you upload JSON files and mark it as a ‘model’.

However you can load it into the asset registry as a model at runtime. Once you have done that, you can assign it to any model components.

Hi yaustar,

Do you have a sample script to provide as guidance?
So far I’ve found the following:-

// Create a new Entity
_instance = new pc.Entity();

// Add a new Model Component and add it to the Entity.
_instance.addComponent(“model”, {
type: ‘asset’,

// load entity by id
_instance.model.asset = this.app.assets.get(assetID);
// load entity by model name
_instance.model.asset = this.app.assets.find(“assetName.json”, “model”);


However, this wont work, as the runtime, is looking for a ‘model’, and I’ve only got the Json file. That or I’m not using the api correctly.

Any steer that you could provide on this would be a really great help.

It’s not something I’ve done before to be honest.

In theory, you should be able to create a new model asset with the URL to the JSON file and add it to the asset repository.

var Ground = this.app.assets.find(“Ground.json”, “json”); //works

var ground = this.app.root.findByPath(“Root/ground”); //works
ground.model.asset = Ground._resources[0].model; //works

var test = ground.model.model.meshInstances[0];//does not work, the second model is null along with meshInstances

considering that there is no fbx. and the json files are available, what would I need to do to get the model to render? I’m aloud to set the texture and materials, but then nothing shows up.

Any help would be greatly appreciated.

Not quite right. You missed the part where you need to create a new model asset use the JSON as the resource.

Here is a quick example I just whipped up: https://playcanvas.com/editor/scene/623195

Perfect, I can now see the Json Model data in the Browser. This is just prefect.

Now I’m trying to figure out how to restore an existing coded workflow.

Essentially, I’ve got the code that is expecting that the model is loaded in specific hierarchy.



Keep in mind that at design time only the structure exists…no model data is loaded until runtime, but the code is attempting to load material data (i.e. the materials exists, but are not on the model.

So I have attempted this:

// Create a new Basic material
var material = new pc.BasicMaterial();

// Set the material to have a texture map that is multiplied by a red color
material.color.set(1, 0, 0);

// Notify the material that it has been modified
ground.model.material = material;

but when the code executes:

var x = floor.model.model.meshInstances[0];

The first [model] is not null, but the second [model] one is.

Remember, I am not trying to update the root

No, this good, but I want to update the design time structure;

//Code Start
object.attributes.add(“Ground_ModelJsonAsset”, {type: “asset”});

var Ground_ModelAsset = new pc.Asset(“Ground_ModelJsonAsset”, ‘model’, {url: this.Ground_ModelJsonAsset.file.url});

var Ground_ModelEntity = new pc.Entity();
Ground_ModelEntity.addComponent(“model”, {type: ‘asset’,asset: Ground_ModelAsset});
var ground = this.app.root.findByPath(“Root/ground”);
ground.addComponent(Ground.type, Ground_ModelAsset); //**Is this right?

With the above technique, I get warnings, but no errors:
addComponent: Entity already has model component

and nothing shows up in the scene.

What I am hoping to do at this point is:

  1. Get the material that was created at design time (call it ground_MAT)
  2. Assign it to to the Ground object that has had the Json object added as a Model.

I think we are almost there… just need a bit of help.

Many thanks again.

Finally, with the predefined design time structure, if I ensure that it has a Model and then call addComponent, it does not fail, but the console states that the Entity already has a model.

If I remove the Model from the Entity (in design mode) and then run the code, I then get the following:
Error: Invalid model type: model

It seems like you have a specific problem that is relatively unique to your project.

To be honest, it would be faster to hire someone for a couple of hours to look at your project and engineer a solution that works for you rather then going back and forth with someone outside the project.

That said, given the information you have here so far, this is how I would approach it.

The core problem is loading the JSON when in the editor, they are not marked as a model type.

All the other problems you are running into are symptoms of the workarounds or adding the model dynamically.

However, while you need to generate the model asset and component dynamically, you don’t need to do the same for the entities, materials etc. They can be created in the editor via the normal methods.

What I would do is to create a script that encapsulates this so you can add it to an entity, assign the JSON and material asset(s) and it will do all the legwork.

Project: https://playcanvas.com/editor/scene/623195
Code: https://playcanvas.com/editor/code/564140?tabs=13232242

This is absolutely what I was after. Perfect.