Jump to content

TypeError: undefined is not an object (evaluating 's._addPendingData')


adobeSlash
 Share

Recommended Posts

Hello everyone !

This is my first post here and i'm not used to so apologies if I do some begginers mistakes.

I look for it in internet but nothing about this error : TypeError: undefined is not an object (evaluating 's._addPendingData')
I'm just trying to import a mesh into my scene.
This is my code :

var Ground = function(x, z, game, scene) {
  // Call the super class BABYLON.Mesh
  GameObject.call(this, "ground", game);

console.log("Adding the ground");
  BABYLON.SceneLoader.ImportMesh("", "assets/", "scene.babylon", scene, function (newMeshes, particleSystems) {
      this = newMeshes[0];

      this.isVisible = true;
      this.parent = this;
      this.shadows.getShadowMap().renderList.push(ground);

      this.position = new BABYLON.Vector3(x, 0.75, z);

      this.receiveShadows = true;

  });
console.log("Ground added");

  //console.log("number of meshes : " + game.assets['ground'].meshes.length);
  //var ground = game.assets['ground'].meshes;

};
// Our object is a GameObject
Ground.prototype = Object.create(GameObject.prototype);
// And its constructor is the Ground function described above.
Ground.prototype.constructor = Ground;

and my file architecture :

Main Folder
-- Ground
-- assets
  -- scene/babylon
 

Does someone have information for me ? 

Thank you in advance, enjoy your day

UPDATE : 

I've made some changes to my code and i put all my files on a server (cloud foundry, so you guys can see my code : http://datageneration.apps.eu01.cf.canopy-cloud.com/)
 

var Ground = function(x, z, game, scene) {
  // Call the super class BABYLON.Mesh
  GameObject.call(this, "ground", game);

console.log("Adding the ground");
  BABYLON.SceneLoader.ImportMesh("", "assets/", "scene.babylon", scene, function (newMeshes, particleSystems) {
      this.meshes = newMeshes[0];

      this.meshes.isVisible = true;
      this.meshes.parent = this;
      this.meshes.shadows.getShadowMap().renderList.push(ground);

      this.meshes.position = new BABYLON.Vector3(x, 0.75, z);

      this.meshes.receiveShadows = true;

  });
console.log("Ground added");

  //console.log("number of meshes : " + game.assets['ground'].meshes.length);
  //var ground = game.assets['ground'].meshes;

};
// Our object is a GameObject
Ground.prototype = Object.create(GameObject.prototype);
// And its constructor is the Ground function described above.
Ground.prototype.constructor = Ground;

 

The error is the same but without the 's.' : Uncaught TypeError: Cannot read property '_addPendingData' of undefined

Thank you for you consideration

EDIT :

If you need it this is the complet file system : 
 

Block.js                                  636B
Game.js                                   3.5K
GameObject.js                             356B
Ground.js                                 927B
Level.js                                  1.2K
Player.js                                 4.2K
assets/                                      -
index.html                                704B
js/                                          -
levels.js                                 771B
old/                                         -

cd assets/

key.babylon                              47.7K
key.babylon.manifest                       78B
scene.babylon                           163.5K
scene.babylon.manifest                     79B
skybox/                                      -

cd ../js

Oimo.js                                 302.5K
babylon.2.3.js                          948.4K
cannon.js                               384.2K
hand-1.3.7.js                            29.6K

 

Edited by adobeSlash
more information about the file system
Link to comment
Share on other sites

It's not the same post. This one has been edited once more and I've made some changes in some code you'r pointing in your solution. But I don't know why there is two post.. better to close the other one I think. 

SO ! I made changes in my code and using yours : 

var Ground = function(x, z, game, scene) { 
      console.log("Adding the ground");
      BABYLON.SceneLoader.ImportMesh("", "assets/", "scene.babylon", scene, function (newMeshes) {
            this.mesh = newMeshes[0];
            this.mesh.isVisible = true;      
            this.mesh.shadows.getShadowMap().renderList.push(this.mesh);
            this.mesh.position = new BABYLON.Vector3(x, 0.75, z);
            this.mesh.receiveShadows = true;
            console.log("Ground added");
      });
};

  //console.log("number of meshes : " + game.assets['ground'].meshes.length);
  //var ground = game.assets['ground'].meshes;

// Our object is a GameObject
Ground.prototype = Object.create(GameObject.prototype);
// And its constructor is the Ground function described above.
Ground.prototype.constructor = Ground;

But i'm still having the same error : babylon.2.3.js:13 Uncaught TypeError: Cannot read property '_addPendingData' of undefined

As said you can watch it working directly at : http://datageneration.apps.eu01.cf.canopy-cloud.com/ . Maybe that can help...
Thanks a lot for your consideration !

EDIT : I tried my file into the babylon sandbox and it can load it.. so the file is correct..

Edited by adobeSlash
adding information
Link to comment
Share on other sites

Sorry about that.. But...

var Ground = function(x, z, game, scene) { 
      console.log("Adding the ground");
      BABYLON.SceneLoader.ImportMesh("", "assets/", "scene.babylon", scene, function (newMeshes) {
            console.log("I'm in");
            this.mesh = newMeshes[0];
            this.mesh.isVisible = true;      
            this.mesh.shadows.getShadowMap().renderList.push(this.mesh);
            this.mesh.position = new BABYLON.Vector3(x, 0.75, z);
            this.mesh.receiveShadows = true;
            console.log("Ground added : " + this.mesh);
      });
      console.log("scene info : " + scene);
};

It's never printed : " I'm in "....

No error, nothing... so still not working

Link to comment
Share on other sites

that is probably due to your manifest. you set offline to true, so it wont load the file from the network and therefore will never call the success, as it is already there.

Maybe it SHOULD call the success, I need to check exactly what is wrong there.

Try changing your manifest (or removing it completely ) and see if it is executed.

Link to comment
Share on other sites

Thanks for your help ! 

Unfortunately i got the following error if I delete the manifest : 

babylon.2.3.js:2 GET http://datageneration.apps.eu01.cf.canopy-cloud.com/assets/scene/scene.babylon.manifest?1460015970229 404 (Not Found)

I tried to use the Loader : 

// All models to load
  var toLoad = [
    {
      name:"ground",
      folder:"assets/scene/",
      filename:"scene.babylon",
      anims : []
    }
  ];

  // Creates a loader
  var loader =  new BABYLON.AssetsManager(this.scene);
  loader.loadingUIBackgroundColor = "#2c2b29";

  var _this = this;
  // For each object to load
  toLoad.forEach(function(tl) {
    var task = loader.addMeshTask(tl.name, "", tl.folder, tl.filename);
    task.onSuccess = function(t) {
      // Set all mesh invisible
      t.loadedMeshes.forEach(function(mesh) {
        mesh.isVisible = false;
      });
      // Save it in the asset array
      _this.assets[t.name] = {meshes:t.loadedMeshes, anims:tl.anims};
    };
    task.onTaskError = function (task) {
      console.error("error while loading " + task.name);
    }
  });

  loader.onFinish = function () {
    console.log(_this.assets);
    // Init the game
    _this._initGame();

    _this.engine.runRenderLoop(function () {
      _this.scene.render();
    });
  };

  loader.load();

};

But if I print the content of _this.assets it still empty ...

Link to comment
Share on other sites

3 minutes ago, RaananW said:

this 404 is not a problem. And yes, you can have console.log inside a callback.

Ignore the manifest error for now, check if it is actually loading the scene file.

No nothing is loaded ...
To be sure I use the scene debugger and my mesh doesn't appear in the MESHES TREE

Link to comment
Share on other sites

Everything is ok excepted this :

Player.prototype._rotateTo = function(s) {
  // get mesh quaternion
  var mq = this.rotationQuaternion;
  var q = BABYLON.Quaternion.RotationAxis(BABYLON.Axis.Y, s);
  this.rotationQuaternion = q.multiply(mq);
  this.body.body.setQuaternion(this.rotationQuaternion);
  this.body.body.sleeping = false;
};

was working before..
I'm loading my body like this : 

this.body = this.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:1, friction:0.9});

If needed this is the complet code of this class : 

var Player = function (game) {
  GameObject.call(this, "player", game);

  var vertexData = BABYLON.VertexData.CreateSphere(16, 0.75, BABYLON.Mesh.DEFAULTSIDE);

  // Create the player box
  //var vertexData = BABYLON.VertexData.CreateBox(0.5, BABYLON.Mesh.DEFAULTSIDE);
  vertexData.applyToMesh(this);

  this.position.y = Player.START_HEIGHT;

  this.body = this.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:1, friction:0.9});

  var _this = this;
  this.getScene().registerBeforeRender(function() {
    if (_this.position.y < -10) {
      _this.game.reset();
    }
  });

  // Two boolean giving the direction (forward/backward)
  this.directions = [0,0];
  // Two boolean giving the rotation (right/left)
  this.rotations = [0,0];
  this.rotationQuaternion = new BABYLON.Quaternion();
  
  var _this = this;
  this.getScene().registerBeforeRender(function() {
    // Move the player is possible
    _this.move();
    //...
    // Reset the game if the player position is below 10
    if (_this.position.y < -10) {
      _this.game.reset();
    }
  });
  window.addEventListener("keydown", function(e) {
    switch (e.keyCode) {
      case 39: // right
        _this.rotations[0] = 1;
        break;
      case 37: // left
        _this.rotations[1] = 1;
        break;
      case 38://bot:
        _this.directions[0] = 1;
        break;
      case 40://top:
        _this.directions[1] = 1;
        break;
    }
  });
  window.addEventListener("keyup", function(e) {
    switch (e.keyCode) {
      case 39: // right
      case 37: // left
        _this.rotations = [0,0];
        break;
      case 38://bot:
      case 40://top:
        _this.directions = [0,0];
        break;
    }
  });
};
Player.START_HEIGHT = 5;

// Our object is a GameObject
Player.prototype = Object.create(GameObject.prototype);
Player.prototype.constructor = Player;

Player.prototype.move = function() {
  if (this.directions[0] != 0) {
    this._moveTo(-1);
  }
  if (this.directions[1] != 0) {
    this._moveTo(1);
  }
  if (this.rotations[0]  != 0) {
    this._rotateTo(0.05);
  }
  if (this.rotations[1]  != 0) {
    this._rotateTo(-0.05);
  }

};

Player.prototype._moveTo = function(s) {
  // Compute the world matrix of the player
  this.computeWorldMatrix();
  // Moving forward along the global z-axis
  var v = new BABYLON.Vector3(0,0,s);
  // Get the world matrix
  var m = this.getWorldMatrix();
  // Transform the global vector into local vector
  var v2 = BABYLON.Vector3.TransformCoordinates(v, m);
  v2.subtractInPlace(this.position);
  v2.normalize().scaleInPlace(0.5);
  this.applyImpulse(v2, this.position);
  // Add this new vector to the player position
  //this.position.addInPlace(v2);
};

Player.prototype._rotateTo = function(s) {
  // get mesh quaternion
  var mq = this.rotationQuaternion;
  var q = BABYLON.Quaternion.RotationAxis(BABYLON.Axis.Y, s);
  this.rotationQuaternion = q.multiply(mq);
  this.body.body.setQuaternion(this.rotationQuaternion);
  this.body.body.sleeping = false;
};

Player.prototype.reset = function (pos) {

  //this.position = pos;
  //this.position.y = Player.START_HEIGHT;
  this.body.resetPosition(pos.x, Player.START_HEIGHT, pos.z);
  this.body.resetRotation(0,0,0);
  //this.body.body.linear
  this.rotations = [0,0];
  this.directions = [0,0];
}

The physics is initialized like that : 

scene.enablePhysics(new BABYLON.Vector3(0, -10, 0), new BABYLON.OimoJSPlugin());

 

Link to comment
Share on other sites

Understood !

this two lines : 

this.body.body.setQuaternion(this.rotationQuaternion);
this.body.body.sleeping = false;

was working good before switching from 2.3 to 2.4

now I have the following errors : 

Uncaught TypeError: Cannot read property 'setQuaternion' of undefined

So I supposed it's came from the new physics rules... 
My body is instantiated like that : 

this.body = this.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor, {mass:1, friction:0.9});

 

Link to comment
Share on other sites

On 4/7/2016 at 3:21 AM, adobeSlash said:

this two lines : 


this.body.body.setQuaternion(this.rotationQuaternion);
this.body.body.sleeping = false;

was working good before switching from 2.3 to 2.4

So - this is the old architecture and was always knd of a hack (this way of handling things was never an official way using BabylonJS).

What you are doing here is getting the physics body and changing it directly.

It is now no longer needed. you can get the physicsImpostor of the mesh (if you use the old method it would be mesh.physicsImpostor) and use the wakeUp() method which will wake up the impostor (or, set sleep to false :) )

To change the quaternion, simply change the mesh's quaternion, Babylon will do the rest. This is described in here - http://doc.babylonjs.com/overviews/Using_The_Physics_Engine#bidirectional-transformation-linking

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