jdurrant Posted March 5, 2015 Share Posted March 5, 2015 I create a groundmesh using these commands:var groundMaterial = new BABYLON.StandardMaterial("ground", scene);groundMaterial.backFaceCulling = false;groundMaterial.diffuseTexture = new BABYLON.Texture("assets/ground/ground.png", scene);groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);var highres_ground = BABYLON.Mesh.CreateGroundFromHeightMap("highres_ground", "assets/ground/ground.png", 500, 500, 50, -100, 0, scene, false);highres_ground.material = groundMaterial;highres_ground.checkCollisions = true;I'd like to excise just part of this groundmesh using CSG. So I run this command:highresCSG = BABYLON.CSG.FromMesh(highres_ground);But I get this error: TypeError: subMeshes is undefined When I replace highres_ground with a simple cube, I don't get the error:var highres_ground = BABYLON.Mesh.CreateBox("box", 20, scene);Any suggestions on how I can convert groundmesh into a standard mesh that can be manipulated with CSG? Thanks for your help. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 5, 2015 Share Posted March 5, 2015 Hey sounds interestingcan you create a repro on the playground? Quote Link to comment Share on other sites More sharing options...
jdurrant Posted March 5, 2015 Author Share Posted March 5, 2015 In preparing the files to show you the "problem," I discovered the solution on my own. I didn't realize (though I should have) that BABYLON.Mesh.CreateGroundFromHeightMap is async. I was trying to use CSG before the groundmesh was ready. In case it's helpful to others, wrapping the CSG commands in a scene.executeWhenReady fixed the problem for me:var cube = BABYLON.Mesh.CreateBox("box", 20, scene);cubeCSG = BABYLON.CSG.FromMesh(cube);var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "ground.png", 500, 500, 50, -100, 0, scene, false);scene.executeWhenReady(function () { groundCSG = BABYLON.CSG.FromMesh(ground); var subCSG = groundCSG.intersect(cubeCSG); subCSG.toMesh("csg", new BABYLON.StandardMaterial("mat", scene), scene); cube.dispose(); ground.dispose(); });Thanks for all your incredible work on babylon.js, by the way. It's a great package. Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 5, 2015 Share Posted March 5, 2015 Another way would be to use the onReady callback in the CreateGroundFromHeightMap function :var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "ground.png", 500, 500, 50, -100, 0, scene, false, function(/*groundMesh*/) { groundCSG = BABYLON.CSG.FromMesh(ground); var subCSG = groundCSG.intersect(cubeCSG); subCSG.toMesh("csg", new BABYLON.StandardMaterial("mat", scene), scene); cube.dispose(); ground.dispose();});It was added recently (to 2.0) Quote Link to comment Share on other sites More sharing options...
jdurrant Posted March 6, 2015 Author Share Posted March 6, 2015 Even better, since "nested" calls to scene.executeWhenReady don't seem to work. Thanks for your help. 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.