Jump to content

Class() - unable to import meshes


hulahula
 Share

Recommended Posts

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 :)

 

Link to comment
Share on other sites

  @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 :D

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...