I am trying to load a OBJ file, but I am having problems. Now I get this error:
Unable to load from ./assets/models/knapp.obj: Error in onSuccess callback
My code in index.php looks like this:
<!-- Link to the last version of BabylonJS -->
<script src="https://preview.babylonjs.com/babylon.js"></script>
<!-- Link to the last version of BabylonJS loaders to enable loading filetypes such as .gltf -->
<script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
<!-- Link to pep.js to ensure pointer events work consistently in all browsers -->
<script src="https://code.jquery.com/pep/0.4.1/pep.js"></script>
<!-- Local JS script -->
<script src="script.js"></script>
And inside scripts.js I have this in the import section:
BABYLON.SceneLoader.Append("./assets/models/", "knapp.obj", scene, function (scene) {
scene.createDefaultCameraOrLight(true, true, true);
object.scaling = new BABYLON.Vector3(10, 10, 10);
});
I think your onSuccess callback is shadowing your scene object. The onSuccess callback should have meshes, skeletons, etc. Also, object
may be something like meshes[0]
?
BABYLON.SceneLoader.Append("./assets/models/", "knapp.obj", scene, function (newMeshes) {
scene.createDefaultCameraOrLight(true, true, true);
newMeshes[0].scaling = new BABYLON.Vector3(10, 10, 10);
});
Thanks brianzinn, I tried it and I still get:
BJS - [07:37:11]: Unable to load from ./assets/models/Knapp.01.006.baked.size.obj: Error in onSuccess callback
e._ErrorEnabled @ babylon.js:16
p @ babylon.js:16
_ @ babylon.js:16
(anonymous) @ babylon.js:16
Promise.then (async)
(anonymous) @ babylon.js:16
m @ babylon.js:16
e @ babylon.js:16
g @ babylon.js:16
XMLHttpRequest.send (async)
e.send @ babylon.js:16
s @ babylon.js:16
m @ babylon.js:16
e.RequestFile @ babylon.js:16
t._requestFile @ babylon.js:16
b @ babylon.js:16
e @ babylon.js:16
a.a.OfflineProviderFactory @ babylon.js:16
e._LoadData @ babylon.js:16
e.Append @ babylon.js:16
createScene @ script.js:36
(anonymous) @ script.js:107
A repro in the Playground would definitely help here.
Sorry, what do you mean with a repro in the playground ?
You should try to recreate your problem here: https://playground.babylonjs.com/
That way, it will be easier for people to help you.
It does not work because you can’t mix http and https in the same page: your asset should be delivered through https.
This doc is explaining how to host a file to be used in the Playground: Using External Assets - Babylon.js Documentation
You don’t get the new meshes from the Scene.Append
callback but the scene, so you should do something like:
BABYLON.SceneLoader.Append("temp/", "Knapp.01.006.baked.size.obj", scene, function (scene) {
scene.createDefaultCameraOrLight(true, true, true);
scene.meshes.forEach((m) => m.scaling = new BABYLON.Vector3(10, 10, 10));
});
It works now, but then it is my other code that mess it up.
https://playground.babylonjs.com/#GHYUA1#2
It works now local too, thanks 