Creating a model in the editor

Is it possible to construct a model in the editor? I’m currently doing mesh combining at run time, but to save the planet from all that extra energy I take up doing the same thing again and again on every device - I was thinking of doing the combining in the editor and creating a combined model (of course it’s improved load speed I’m really after).

I could I guess create and download an FBX but that’s a pretty big job. It’s not so difficult to create with entities or even the .json format - but I can’t see a way of getting that recognised. Is there any one of the editor hooks that would let me do this?

Currently there is no such feature, but as you are familiar with model format already, you could in Editor get model data (asset.resource) and combine it, preserving mesh instances, and combining vertex buffer if needed. Then to upload it back you could use Editor API method for that.

editor.call('assets:create', {
    name: 'model.json',
    type: 'model',
    source: false,
    preload: true,
    parent: editor.call('assets:panel:currentFolder'),
    filename: 'model.json',
    file: new Blob([ JSON.stringify({ your: "data here" }, { type: 'application/json' }),
});

That’s exactly what I was looking for Max, thanks. Is that really “mode” in the last code line? Or model?

That is just an example of JSON data. It should be a JSON object with your model data, that is stringified. Updated it a bit, as new Blob was incorrect.

Ah cool, I got it now. So I’ve already made up an object in your JSON format I think. I’ll just stick that in there then?

Hey Max. Is there any way I can associate the materials with the model? I didn’t spot that in the JSON file I looked at…

Materials are being meta information of the asset, and stored in data field of the asset.
To look at the examples, select any model asset and try in console:

editor.call('selector:items')[0].get('data');

This will console log the data field, and you can see its format.
Then simply add data field to argument object you are passing to assets:create method.

Cool :slight_smile: That’s great thanks Max

All working now Max, 170 draw calls reduced to 8, no runtime overhead! Woo hoo

1 Like

This is really cool! I wish there would be an Editor functionality to generate model from multiple entities with models.