mesh.getHeightAtCoordinates(x, z) return 0 except that at these coordinates it is not 0

Hi, I’m working on a project where I’d like a mesh to be laid on a ground depending on the coordinates given. So far so good. But when I go over a ground that has been modified with a function that lets you change the vertices to create either a difference in level or a hole (made using this doc: Babylon.js docs )

and well the modifications made are not taken into account in spite of a ‘mesh.computeWorldMatrix(true)’ and the mesh posed remains in y=0…

to lay a mesh I use this function

    getPositionInSphere(sphereRadius, pos_middle_sphere) {
        var y = (Math.random() - 0.5) * 2 * sphereRadius;
        
        var radiusAtY = Math.sqrt(Math.pow(sphereRadius, 2) - Math.pow(y, 2));
  
        var theta = Math.random() * 2 * Math.PI;
    
        var x = (radiusAtY * Math.cos(theta))+pos_middle_sphere[0];
        var z = (radiusAtY * Math.sin(theta))+pos_middle_sphere[2];
        var y = this.meshSupport.getHeightAtCoordinates(x, z);            
        
        return new BABYLON.Vector3(x, y, z);
    }

EDIT:
to modify the ground I use the doc and I also modify the normals so that I can use it to orientate the mesh so that it is against the ground and not floating

Are you able to setup a repro in the Playground? Else it will be hard to help.

Do you call GroundMesh.updateCoordinateHeights to make sure the internal representation of the height field is updated with your changes?

hello more needs i just found the error while doing some tests!!! i had put the line ‘mesh.convertToFlatShadedMesh()’ which broke everything. problem solved!

I didn’t put the line you said, but I think adding it won’t do any harm?

If it works without it, then you don’t need to add it.

1 Like