esnho Posted January 4, 2016 Share Posted January 4, 2016 Hello,I'm tryng to create an object wich holds mine ground in a scene, I'm using this code but it doesn't works, in console I receive a "n is undefined" message.But with the vector creation, for example, there's no problems.... var terreno = { noiseTexture : "media/noise2.jpg", distortAmount : 10, offset : -20, xmin : -200, zmin : -200, xmax : 200, zmax : 200, precision : { "w" : 80, "h" : 80 }, subdivisions : { 'h' : 1, 'w' : 1 }, // Create the Tiled Ground create : new function(name, scene) { //"Tiled Ground" this.scene = scene; this.name = name; this.v = new BABYLON.Vector3(1, 10, 0); this.tiledGround = new BABYLON.Mesh.CreateTiledGround(name, this.xmin, this.zmin, this.xmax, this.zmax, this.subdivisions, this.precision, scene); } }; Quote Link to comment Share on other sites More sharing options...
jerome Posted January 4, 2016 Share Posted January 4, 2016 mmh....I guess "new function(name, scene)" creates a new JS object, so the keyword this used inside this function could not refer to the upper object terreno.Did you display with console.log() what were the values of this.xmin, this.subdivsions, etc just before calling CreateTiledGround() ? It just looks like a classic javascript "this" scope issue. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted January 4, 2016 Share Posted January 4, 2016 I think this should fix your problem as suggests Jerome :var that = this;precision : {......// Create the Tiled Groundcreate : function(name, scene) { //"Tiled Ground" that.scene = scene; that.name = name; that.v = new BABYLON.Vector3(1, 10, 0); that.tiledGround = new BABYLON.Mesh.CreateTiledGround(name, that.xmin, that.zmin, that.xmax, that.zmax, that.subdivisions, that.precision, that.scene); } Quote Link to comment Share on other sites More sharing options...
esnho Posted January 4, 2016 Author Share Posted January 4, 2016 I fixed changing the function declaration: create : function(name, scene)Thank you jerome 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.