merpnderp

Members
  • Content count

    2
  • Joined

  • Last visited

  1. merpnderp

    Something wrong with my mesh

    Wingnut, I don't know how many times I've looked through this code for an error. I've played with the UV mapping to go from 0,size and 0,size-1, started UV's from each corner, played with the normals. I was so focused on that, I never would have found the param order bug. Thank you!
  2. I'm creating a mesh from scratch but when I add a texture, I get nothing. The plane is simply white. Are my UV coords or normals not set up correctly for Babylonjs or am I missing something else? import { Mesh, VertexBuffer, StandardMaterial, Texture } from 'babylonjs' export default function CreateMesh(height, width, scene) { const mesh = new Mesh('TerrainMesh', scene) const indices = [] const vertices = [] const normals = [] const uvs = [] const startX = -width / 2 const startY = -height / 2 let index = 0 for (let y = 0; y < height; y++) { for (let x = 0; x < width; x++) { vertices.push(startX + x, 0, startY + y) uvs.push(x / (width), y / (width - 1)) normals.push(0, 1, 0) if (x < width - 1 && y < height - 1) { indices.push(index, index + width + 1, index + width) indices.push(index + width + 1, index, index + 1) } index++ } } mesh.setVerticesData(VertexBuffer.PositionKind, vertices) mesh.setVerticesData(uvs, VertexBuffer.UVKind) mesh.setVerticesData(normals, VertexBuffer.NormalKind) mesh.setIndices(indices) let groundMaterial = new StandardMaterial("ground", scene) groundMaterial.diffuseTexture = new Texture("textures/earth.jpg", scene) mesh.material = groundMaterial return mesh }