App.assets.loadFromUrl error

Hello,

I am working directly with the PlayCanvas engine, using the app.assets.loadFromUrl() function to parse .json models (converted from .fbx). On several models I am getting the critical following error when loading:

TypeError: materials[i] is undefined on line 20331.

There seems to be a check missing for undefined materials there, so I added the following:

if(materials[i] && materials[i].data.parameters) {

Now, loading continues normally by-passing undefined materials.

Best regards,
Leonidas Maliokas

1 Like

May I add (Leonidas and I are working together on this), how can there be undefined materials since we are talking of FBX models converted to PC JSON? Does the converter create undefined material references under certain circumstances?

No, as far as I’m aware, you can’t get undefined materials. Can you share the FBX that generates a mesh instances -> material mapping that is undefined?

Will, I have shared a Google Drive folder with you. All the models are uploaded there (both in PC JSON and FBX format). The ones in question are:
Joan_robot_JSON.zip
Vasilis_bike.json.zip
Vasilis_objects_JSON.zip
(the Maria model works fine, in fact it is the only one imported from iClone to MAX, then made into an FBX)

So I’m experimenting with the model called Joan_robot. I import it to PC then export an archive from it, then loading it locally with the latest engine. I’m not getting any errors. Are you using the latest engine?

I do see a problem with some materials not having a name 'causing them to not be included in the archive and maybe that’s the problem. Could you try to give your materials a name inside the FBX? The names we use come from the material names inside the FBX file. Check if having all your materials have a name fixes the error on your end. We are looking into fixing the archive issue on ours.

I deployed a fix that makes sure all materials are exported with a name in a model archive so that might fix your problem. We’re also going to prevent materials with empty names to be created when we convert an FBX at some point soon.

But you need to check if that is the problem if it still fails let me know.

Leonidas has only started working with the engine offline so I guess he uses the latest version, but he will have to confirm if that is so.

These materials are surely “left-overs”, not used inside the model. When Leonidas omitted them with his fix, the models did load and look just fine. I don’t know why they get exported inside the FBX from MAX, that’s an issue for our 3D artist to comment on, although I believe she won’t know why either…

The fix you mentioned (plus the soon-to-come one) will probably fix this issue.

We were using the latest PlayCanvas engine built from source directly from the main fork on github (PlayCanvas Engine v0.178.1-dev revision -).

I see that you have just committed some changes, we will update to that.