adobeSlash Posted April 6, 2016 Share Posted April 6, 2016 (edited) 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 April 6, 2016 by adobeSlash more information about the file system Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 6, 2016 Author Share Posted April 6, 2016 (edited) 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 April 6, 2016 by adobeSlash adding information Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 6, 2016 Share Posted April 6, 2016 Seems like your scene is undefined or not sent to the object. I don't see the code calling the ground object, so I can't really tel you where it went wrong. But this is the scene object for sure. Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 6, 2016 Author Share Posted April 6, 2016 Love you dude ! That's works now. My scene was undefined for some obscure reason.... but now it's ok ! Thank a lot for you time. Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 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 Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 7, 2016 Share Posted April 7, 2016 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. Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 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 ... Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 I need you experience. But I suppose that it's impossible to call console.log into a callback isn't ? So it can explain why i can't see my debug message... Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 7, 2016 Share Posted April 7, 2016 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. Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 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 Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 7, 2016 Share Posted April 7, 2016 check that the scene file is downloaded correctly. If you want to share a working URL we can all look together. Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 Just now, RaananW said: check that the scene file is downloaded correctly. If you want to share a working URL we can all look together. You can check this out at : http://datageneration.apps.eu01.cf.canopy-cloud.com/ How can I check if the scene file is correctly loaded ? Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 If the url doesn't work here is a zip file with the source code and assets datageneration.zip Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 7, 2016 Share Posted April 7, 2016 Ok, I think I found the problem. You are trying to use PBMMaterial without including it in your scene. You can try loading the .js file, or move to 2.4, which has PBRMaterial integrated in the framework. adobeSlash 1 Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 !!!!!!!!!! It works !! To help people understand which part of my code require PBMMaterial ? It's look like 2.4 use cannon.js for physics : BJS - [10:19:15]: CannonJS is not available. Please make sure you included the js file. Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 7, 2016 Share Posted April 7, 2016 you can choose which physics engine to use. default changed, but providing new BABYLON.OimoJSPlugin() as the second param to the enablePhysics function will bring everything back to normal. Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 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()); Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 7, 2016 Share Posted April 7, 2016 way too much code If you want to explain what's wrong and contain it in a single function, or maybe share an exception or a playground, i could help. Quote Link to comment Share on other sites More sharing options...
adobeSlash Posted April 7, 2016 Author Share Posted April 7, 2016 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}); Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 7, 2016 Share Posted April 7, 2016 ... Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 7, 2016 Share Posted April 7, 2016 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 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.