0

I'm trying to clone() a Mesh created with BABYLON.Mesh.CreateGroundFromHeightMap() but it never renders.

// Ground
var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
groundMaterial.emissiveTexture = new BABYLON.Texture("textures/earth.jpg", scene);

var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "textures/worldHeightMap.jpg", 200, 200, 250, 0, 10, scene, false);
ground.material = groundMaterial;

// Cloned Ground
var groundMaterial2 = new BABYLON.StandardMaterial("ground2", scene);
groundMaterial2.emissiveColor = new BABYLON.Color3(1, 0, 0);
groundMaterial2.alpha = 0.5;

var ground2 = ground.clone("ground2");
ground2.position = new BABYLON.Vector3(0, 1, 0);
ground2.material = groundMaterial2;

http://babylonjs-playground.azurewebsites.net/#YA6VT#1

dahlbyk
  • 75,175
  • 8
  • 100
  • 122

1 Answers1

0

Since CreateGroundFromHeightMap() loads its VertexData from an image, the Mesh is not ready to be cloned until it has been loaded. By using CreateGroundFromHeightMap's optional onReady parameter we can delay the clone() until everything is ready.

// Ground
var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
groundMaterial.emissiveTexture = new BABYLON.Texture("textures/earth.jpg", scene);

var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "textures/worldHeightMap.jpg", 200, 200, 250, 0, 10, scene, false,
    mesh => {
        // Cloned Ground
        var groundMaterial2 = new BABYLON.StandardMaterial("ground2", scene);
        groundMaterial2.emissiveColor = new BABYLON.Color3(1, 0, 0);
        groundMaterial2.alpha = 0.5;

        var ground2 = mesh.clone("ground2");
        ground2.position = new BABYLON.Vector3(0, 1, 0);
        ground2.material = groundMaterial2;
    });
ground.material = groundMaterial;

http://babylonjs-playground.azurewebsites.net/#YA6VT#2

dahlbyk
  • 75,175
  • 8
  • 100
  • 122