hulahula Posted April 9, 2018 Share Posted April 9, 2018 Hello guys I have one issue . I unable to import meshes when i using Class () but everything works except for importing meshes. You can see my code here : class Player { constructor(scene) { this.scene = scene; this._skeleton; BABYLON.SceneLoader.ImportMesh("", "", "skull.babylon", this.scene, function (newMeshes, particleSystems, skeletons) { skull = newMeshes[0]; this._skeleton = skeletons[0]; skull.rotation.y= Math.PI; scene.beginAnimation(skeletons[0], 0, 501, true, 1) this.collider = BABYLON.Mesh.CreateBox("collider_box", .32, scene, false); this.collider.position.y = .151; this.collider.rotation.y = 0; this.collider.ellipsoid = new BABYLON.Vector3(0.155, 1.14, 0.155); this.collider.ellipsoidOffset = new BABYLON.Vector3(0, 1.0, 0); this.collider.isVisible = false; skull.parent= this.collider; }); } get mesh (){ return this.collider; } } Why is this didn't work ? It is becouse babylon-loaders doesn't support Class () or do I do something wrong ? Thank you in advance for your answers Quote Link to comment Share on other sites More sharing options...
Guest Posted April 9, 2018 Share Posted April 9, 2018 What error do you get? Can you repro in the PG? Quote Link to comment Share on other sites More sharing options...
MarianG Posted April 9, 2018 Share Posted April 9, 2018 try add let _this = this before ImportMesh function, and on Import function use _this instead of this. Quote Link to comment Share on other sites More sharing options...
hulahula Posted April 9, 2018 Author Share Posted April 9, 2018 This error : BJS - [18:33:41]: Unable to import meshes from skull.babylon: Error in onSuccess callback. I can't repro my code literally but here is exampel how it looks like http://www.babylonjs-playground.com/#JUKXQD#5 Quote Link to comment Share on other sites More sharing options...
hulahula Posted April 9, 2018 Author Share Posted April 9, 2018 @MarianG sorry for my dumb question ..but you mean like this ? class Player { constructor(scene) { let _this = this; _this.scene = scene; _this.import = BABYLON.SceneLoader.ImportMesh("", "", "skull_color.babylon", _this.scene,function(newMeshes, particleSystems, skeletons) { }); } } I m self-taught so ... I'm slow in this Quote Link to comment Share on other sites More sharing options...
MarianG Posted April 9, 2018 Share Posted April 9, 2018 1 hour ago, Alenvei said: This error : BJS - [18:33:41]: Unable to import meshes from skull.babylon: Error in onSuccess callback. I can't repro my code literally but here is exampel how it looks like http://www.babylonjs-playground.com/#JUKXQD#5 in this situation, it's not the problem that I thought. No problem, try with a try catch each line, ps: but I think the problem comes from here 5 hours ago, Alenvei said: this._skeleton = skeletons[0]; try console skeletons, maybe it's empty hulahula 1 Quote Link to comment Share on other sites More sharing options...
hulahula Posted April 9, 2018 Author Share Posted April 9, 2018 Thank you very much @MarianG you was right : this._skeleton = skeleton[0] made a problem with import meshes MarianG 1 Quote Link to comment Share on other sites More sharing options...
hulahula Posted April 9, 2018 Author Share Posted April 9, 2018 @MarianG I have littel problem when iI trying scope _this.collider ... here is my code : class Player { constructor(scene,camera) { let _this = this; BABYLON.SceneLoader.ImportMesh("", "", "skull_color.babylon", this.scene,function (newMeshes, particleSystems, skeletons) { skull = newMeshes[0]; skull.rotation.y= Math.PI; skull.position.y=-0.15; //var anim = scene.beginAnimation(skeletons[0], 0, 501, true, 1.5); scene.beginAnimation(skeletons[0], 0, 501, true, 1) _this.collider = BABYLON.Mesh.CreateBox("collider_box", .32, scene, false); _this. collider.position.y = .151; _this. collider.rotation.y = 0; _this. collider.ellipsoid = new BABYLON.Vector3(0.155, 1.14, 0.155); _this.collider.ellipsoidOffset = new BABYLON.Vector3(0, 1.0, 0); // _this. collider.isVisible = false; skull.parent = _this.collider; camera.target = _this.collider; } get mesh (){ return _this.collider; } } When i trying to call it in main.js this error shows up Uncaught ReferenceError: _this is not defined. Quote Link to comment Share on other sites More sharing options...
hulahula Posted April 9, 2018 Author Share Posted April 9, 2018 ok I solved that in get mesh(){ return _this.collider } I changed _this.collider to this.collider and now is it working perfectly . Quote Link to comment Share on other sites More sharing options...
MarianG Posted April 9, 2018 Share Posted April 9, 2018 Great! Well done Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.