howdoideletemyaccountpleas Posted November 6, 2017 Share Posted November 6, 2017 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 } Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 6, 2017 Share Posted November 6, 2017 Hello! can you repro the issue in the Playground? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 6, 2017 Share Posted November 6, 2017 Hi guys! First time posters... my treat (sometimes). (I have no life/purpose) heh https://www.babylonjs-playground.com/#RGZPJH#7 I found problem, too... https://www.babylonjs-playground.com/#RGZPJH#8 mesh.setVerticesData(VertexBuffer.PositionKind, vertices) // correct params order mesh.setVerticesData(uvs, VertexBuffer.UVKind) // reversed params mesh.setVerticesData(normals, VertexBuffer.NormalKind) // reversed params I've made this mistake a few HUNDRED times, myself. Party-on! GameMonetize, JohnK and howdoideletemyaccountpleas 2 1 Quote Link to comment Share on other sites More sharing options...
howdoideletemyaccountpleas Posted November 6, 2017 Author Share Posted November 6, 2017 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! Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 6, 2017 Share Posted November 6, 2017 heh... MY pleasure. I had to add 'BABYLON.' to many places... to make the playground run. During adding BABYLON.VertexBuffer, the code gods gave us a gift. howdoideletemyaccountpleas 1 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.