I’m working with the API adding assets at runtime. I got a model downloaded from PlayCanvas to programmatically load and display (see code at bottom).
When I download a model from PlayCanvas it gives me a nice package that includes all the textures and materials along with the geo. It includes a mapping file which describes the location of the relevant materials. In the back of my mind I was sorta hoping that when the asset was displayed the textures and stuff would ‘programagically’ already be referenced. But no, the only thing displayed was the raw geo.
Is there built-in functionality in the API which parses the mapping file, loads all the resources, and attaches the materials to the geo or do I have to parse the mapping file manually and load/map all the resources individually?
function loadObject(){
var pc_cube_entity, pc_cube_asset;
//create asset
pc_cube_asset = new pc.Asset("pc_cube", "model", {
url: "./assets/playcanvas_cube/playcanvas.json"
});
app.assets.add(pc_cube_asset);
//add asset to registry
pc_cube_asset.on("load", function (err, model) {
//add entity to world
pc_cube_entity = new pc.Entity();
pc_cube_entity.addComponent("model", {
type: "asset",
asset: this
});
app.root.addChild(pc_cube_entity);
});
app.assets.load(pc_cube_asset);
}