import { PlaneGeometry, MeshLambertMaterial, Mesh, TextureLoader } from "three";

export function createTerrain(props) {
  const loader = new TextureLoader();
  const height = loader.load("img/textures/leafy-autumn-forest-floor.jpg");
  //                                         w            h
  const geometry = new PlaneGeometry(props.width, props.height, 64, 64);

  const material = new MeshLambertMaterial({
    color: props.color,
    flatShading: true,
    map: height,
    //displacementMap: height,
    //displacementScale: 5,
  });

  const plane = new Mesh(geometry, material);
  plane.position.set(0, 0, 0);
  plane.rotation.x -= Math.PI * 0.5;

  //Storing our original vertices position on a new attribute
  plane.geometry.attributes.position.originalPosition =
    plane.geometry.attributes.position.array;

  // eslint-disable-next-line @typescript-eslint/no-empty-function
  plane.tick = () => {};

  return plane;
}
