Thank you for your answer! Apparently it is exactly that what I am missing. I’ve read the documentation you sent, implemented it ,and now it does not give any errors. However, when I try to load said .obj from a string, it does nothing apparently. Now, I’m not sure if it’s because I’m not using the method as it should be used, or because the content of the string should be modified beforehand. Maybe someone around here as some experience with this, so I will post my code here to see if someone has any idea that helps ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/win10/slight_smile.png?v=9)
I’m doing this project in typescript, and these are the two main files:
index.ts
import { Main } from './main';
import 'babylonjs-materials';
import 'babylonjs-loaders';
window.addEventListener('DOMContentLoaded', () => {
const main = new Main('renderCanvas');
main.createScene();
main.useHiddenFunction();
});
main.ts
import * as BABYLON from 'babylonjs';
import { OBJFileLoader } from 'babylonjs-loaders';
export class Main {
private _canvas: HTMLCanvasElement;
private _engine: BABYLON.Engine;
private _scene: BABYLON.Scene;
private _camera: BABYLON.ArcRotateCamera;
private _light: any;
private _my_obj: string;
constructor(canvasElement: string) {
// Create canvas and engine
this._canvas = <HTMLCanvasElement>document.getElementById(canvasElement);
this._engine = new BABYLON.Engine(this._canvas, true);
}
/**
* Creates the BABYLONJS Scene
*/
createScene(): void {
// create a basic BJS Scene object
this._scene = new BABYLON.Scene(this._engine);
// create an ArcRotateCamera
this._camera = new BABYLON.ArcRotateCamera(
'camera',
2.127076697832047,
0.8671560465713813,
50,
BABYLON.Vector3.Zero(),
this._scene
);
this._camera.attachControl(this._canvas, true);
this._light = new BABYLON.HemisphericLight(
'light',
new BABYLON.Vector3(0, 1, 0),
this._scene
);
this._engine.runRenderLoop(() => {
this._scene.render();
});
}
useHiddenFunction(): void {
const my_obj = https://paste.ee/p/GTN5R;
const mesh_load_options = {
ComputeNormals: false,
ImportVertexColors: false,
InvertY: false,
InvertTextureY: true,
UVScaling: new BABYLON.Vector2(1, 1),
MaterialLoadingFailsSilently: true,
OptimizeWithUV: false,
SkipMaterials: true
};
const object_loader = new OBJFileLoader(mesh_load_options);
var promise_aft = object_loader.importMeshAsync('shark', this._scene, my_obj, '').then(
(value) => {
console.log('I passed!');
console.log(value);
},
(error) => {
console.log('I failed :(');
console.log(error);
}
);
console.log(promise_aft);
}
Some notes about index.ts:
- that url that you can see is not written like that in the code. In the actual code I have the content that is in that pastebin url. I just typed the URL there so that it is cleaner in this post.
- I’m not very familiar with Promises (yet), but if I understood everything right, if the promise “is accepted” something should come out of it. I would think that it would return the mesh (actually it should return an object that includes the created mesh), but instead it returns said object, with an empty array of meshes.
So I see that my code is not crashing, which is a good sign, but it is not doing anything either, which is not a good sign. Does anybody have any idea why the mesh contained in the string is not imported onto the scene?
Thank you! ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/win10/slight_smile.png?v=9)
P.D. I included this question as an extra post in my previous question, to keep it all organized. If I should post it as a sepparate question in the forum, please let me know.
P.D.2 I included the code written in the post instead of a PG, because I wanted to show the
import { OBJFileLoader} from 'babylonjs-loaders'
to check that I’m doing everything right. I think this would not show up in a PG