How can i load model on run time loading fine on static url

Oops. Left it on private. It’s now public.

can you please check the link and suggest the code

You can now access the project I posted with the code that I believe fixes your issue. You still need to tweak it should be pretty straightforward forward.

@yaustar
http://network.daruldev.com/test

their is an error of undefined asset

it is showing :Uncaught TypeError: Cannot read property ‘assets’ of undefined
@yaustar

I’ve modified the PlayCanvas project and set up an example on JSFiddle: https://jsfiddle.net/2yzpdec9/5/

https://playcanvas.com/editor/scene/974566
The code is just a modified version of what was given here: Connect web App with Playcanvas iFrame

What if we want to load on page load not on click when we should load it ?
@Leonidas

  1. You should send first a message from the Playcanvas side to your parent page, that Playcanvas loading has finished, app is ready.

  2. As a response send back from the parent page to Playcanvas the message @yaustar prepared on jsfiddle:

app.contentWindow.postMessage('https://network.daruldev.com/models/eyeball.obj', '*');

Given that the callback is in the initialise function of a script, I would listen for the first render event to send the message.

1 Like

Ah, I forgot this was in an iframe. In which case, I would have some code on the PlayCanvas app that would post a message to the parent to tell it when it’s ready.

I’ve updated the project and JSFiddle to load the model when the PlayCanvas app is ready:

https://jsfiddle.net/v31cxktr/9/
https://playcanvas.com/editor/scene/974566

1 Like

@yaustar
thank you for your help really appreciated, i have some questions , let me know how we can focus on that entity we have load from outside or if we want to change materials or any other properties ?

What do you mean by focus?

You can keep the reference to the Entity that is created on the load process and from there you can access the model and materials to change/modify.

Camera focus

The Model Viewer Starter Kit does this in the Orbit camera: https://playcanvas.com/project/446385/overview/starter-kit-model-viewer

TLDR, It gets the AABB of all the models that you want to have in focus and works out roughly how far back it needs to be to have it all in frame.

can you implement it on example ? i am not able to integrate that

Sorry, I’m afraid I’m pretty rammed with work at the moment.

This is some code that I’m using to focus on one object, simply loop over all your other models and keep adding to the bounds for multiple, I guess.

var bounds = this.targetEntity.model.meshInstances[0].aabb;
// .. add another loop around this for all your other models or so
for (var mesh = 1; mesh < this.targetEntity.model.meshInstances.length; mesh++) {
  bounds.add(this.targetEntity.model.meshInstances[mesh].aabb);
}

If you also have them moved the entities around by transform, you’ll need to manually modify the bounds of them too I think.
Then you can easily get the biggest axis (either x, y or z)

var size = bounds.halfExtents;
var biggest = size.x;
if (biggest < size.y) biggest = size.y;
if (biggest < size.z) biggest = size.z;

and then just use that value multiplied by some zoom factor as your start zoom (I don’t use their starter kit anymore so you’ll have to try something yourself for this).


if you need to change stuff like materials you should check the API reference, as yaustar said you should keep references to entities and then go from there: https://developer.playcanvas.com/en/api/pc.Entity.html. For a material swap try this:

// Sets a new StandardMaterial on each mesh
// a model is built out of meshInstances, each has a material slot
entity.model.meshInstances.forEach(function(mesh) {
  mesh.material = new pc.StandardMaterial();
});
1 Like

if you check our above example you can see that we are load model dynamically

In which case, perform the code after all the models have finished loading :slight_smile:

1 Like

@yaustar
@Ivolutio

how to rotate this loaded model from code when get post message ?