# Adding geo at runtime redux

**URL:** <https://forum.playcanvas.com/t/adding-geo-at-runtime-redux/5944>\
**Category:** Help & Support\
**Created:** [February 5, 2018, 2:43pm UTC](https://forum.playcanvas.com/t/adding-geo-at-runtime-redux/5944 "2018-02-05T14:43:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhinrichs](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/jhinrichs/32/9380_2.png) [@jhinrichs](https://forum.playcanvas.com/u/jhinrichs)\
**Post date:** [February 5, 2018, 2:43pm UTC](https://forum.playcanvas.com/t/adding-geo-at-runtime-redux/5944/1 "2018-02-05T14:43:28Z")

</div>

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

```

}

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [February 5, 2018, 3:35pm UTC](https://forum.playcanvas.com/t/adding-geo-at-runtime-redux/5944/2 "2018-02-05T15:35:12Z")

</div>

This is how I’ve done it in the past: [Load 3D models at run time from a PlayCanvas application](https://forum.playcanvas.com/t/load-3d-models-at-run-time-from-a-playcanvas-application/4749/4?u=yaustar)

```javascript
var Sandbox = pc.createScript('sandbox');

Sandbox.URL = 'https://raw.githubusercontent.com/yaustar/3dmodel-Playcanvas/master/Gas%20Station.json';

// initialize code called once per entity
Sandbox.prototype.initialize = function() {
    this.app.assets.loadFromUrl(Sandbox.URL, "model", function (err, asset) {
        var entity = new pc.Entity();
        entity.addComponent("model");
        entity.model.model = asset.resource;
        pc.app.root.addChild(entity);
    });
};

// swap method called for script hot-reloading
// inherit your script state here
// Sandbox.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/

```

---

<div class="post-metadata">

**Author:** ![jhinrichs](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/jhinrichs/32/9380_2.png) [@jhinrichs](https://forum.playcanvas.com/u/jhinrichs)\
**Post date:** [February 5, 2018, 3:50pm UTC](https://forum.playcanvas.com/t/adding-geo-at-runtime-redux/5944/3 "2018-02-05T15:50:19Z")

</div>

It looks like that code will load the geo but not all the materials and textures. I was hoping there was something built into the API that would load all the textures and materials based on the mapping files that come when you download an asset from PlayCanvas.

Are you guys aware of anything like that or do I have to load every texture and material manually and then attach them to the newly created entity?

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [February 5, 2018, 4:20pm UTC](https://forum.playcanvas.com/t/adding-geo-at-runtime-redux/5944/4 "2018-02-05T16:20:32Z")

</div>

> [@jhinrichs](#):
>
> It looks like that code will load the geo but not all the materials and textures

It should load. Are there any errors in the console? The assets will have to uploaded in the correct folder names which are GUID based. eg `6836758`

eg: [GitHub - yaustar/3dmodel-Playcanvas](https://github.com/yaustar/3dmodel-Playcanvas)

---

<div class="post-metadata">

**Author:** ![jhinrichs](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/jhinrichs/32/9380_2.png) [@jhinrichs](https://forum.playcanvas.com/u/jhinrichs)\
**Post date:** [February 5, 2018, 4:51pm UTC](https://forum.playcanvas.com/t/adding-geo-at-runtime-redux/5944/5 "2018-02-05T16:51:52Z")

</div>

Ah, you are awesome! That worked…thanks a lot.
