[ENGINE ONLY] Scene loading and model loading

Hi, I am really new to PlayCanvas and evaluating it atm. Until now really like it and thinking of switching my project from CopperLicht to PlayCanvas engine. By now I am not thinking of using the Editor, so I am curious in help with Engine only stuff. Has anyone an example how to archieve dynamic scene loading and loading of models? I read that PlayCanvas have some JSON format for models and is able to convert e.g. FBX to such format. I am also curious how to load scenes and models via API from a Server. Surely I have a lot to learn and I am at the beginning of setting up an environment. By the short time I use this forum I very much like your support and want to thank you in advance for help. Best, Ingo

This would be a good start - engine only exmples (without using the editor). They all have a link to source code as well. http://playcanvas.github.io/#animation/blend.html

Regarding the models - you can convert fxb to json files and load that, but perhaps loading glb models directly would be a better option - it does not need the Editor, and loads faster too. Most of those examples do that.

1 Like

Thanks @mvaligursky for your fast reply, I try those out.
I am thinking of starting with this example: https://launch.playcanvas.com/980178?debug=true
Can I use this model for testing purposes? And in what way is this source code different from those on http://playcanvas.github.io?

For testing you can use code / models from any public projects.

The project you linked was created in the editor, so it might not load anything manually, you drag & drop those assets into the Editor, place them in the scene and this gets automatically loaded, so no need to do the basics.

@mvaligursky Thanks for clarifying. So the script code which I see in the editor is not compatible with engine only? Sorry for maybe asking silly question :slight_smile:

all code runs on top of the engine, so it is the same … but editor helps you avoid having to write a lot of code as it lets you do it visually in the Editor. For example to create a light - in engine you write a code to create it, add it to scene and specify some coordinates / colors. In Editor you click on Create Light menu, move it in the scene with the mouse, pick color in a color picker, while having real time preview of what it does.

I’d recommend you give the Editor a go … it makes writing games a lot easier. Find some video tutorials to get you started.

Hi,

can someone tell me if there is a root scene at the time of app creation ( new .pc.Application() )?
The API tells:
loadSceneHierarchy: Load a scene file, create and initialize the Entity hierarchy and add the hierarchy to the application root Entity.

But when I load a scene (engine only) this.app.scenes.list().length is 0 So no added scene, it is maybe
because there is no root scene (root entity). How is it? And how do I handle those generated resource_ids - must I genereate them manually? Can’t this.app.root be seen as the initial scene to add others? Here is my basic scene so far :slight_smile:

{
    "name": "Intro",
    "settings": {},
    "entities": {
        "c7a6791a-8bd8-4866-bd8b-eda21fd6b793": {
            "name": "Intro",
            "parent": null,
            "resource_id": "c7a6791a-8bd8-4866-bd8b-eda21fd6b793",
            "tags": [],
            "enabled": true,
            "components": {},
            "scale": [],
            "position": [],
            "rotation": [],
            "children": []
        }
    },
    "created": "2020-10-16T10:22:56.486Z",
    "id": 1
}```

TLDR, there’s no real concept of scenes in the sense that the app knows what has been loaded. Scene loading in PlayCanvas is effectively loading a JSON that has entity data and adding them to app.root (which is the engine’s root graph node) .

app.scenes is a scene registry, not what scenes are loaded. The Editor builds populate this registry with the scenes that are bundled with the build so that the developer can query it (e.g get the URL for a scene of the name ‘XXXXXXXX’).

The resource_ids must be unique for every entity in all the scenes.

You could create your own ‘scene’ format and loader and ignore the Engine’s one completely.

Hi, I need to load and add a scene not remote, but via an JSON object, how can I archive this?

Something like app.scenes.loadScene(JSONObject) and not a path or name