Custom Geometry
Create custom meshes with vertex data:
// Create a custom mesh (triangle)
const customMesh = new BABYLON.Mesh("custom", scene);
// Define vertex data
const vertexData = new BABYLON.VertexData();
// Positions (3 vertices, each with x,y,z coordinates)
vertexData.positions = [
0, 1, 0, // Top vertex
-1, -1, 0, // Bottom left vertex
1, -1, 0 // Bottom right vertex
];
// Indices (defines triangles using position indices)
vertexData.indices = [0, 1, 2]; // Counter-clockwise winding
// Normals (perpendicular vectors for lighting calculations)
vertexData.normals = [
0, 0, 1,
0, 0, 1,
0, 0, 1
];
// UV coordinates for texturing
vertexData.uvs = [
0.5, 0, // Top vertex UV
0, 1, // Bottom left UV
1, 1 // Bottom right UV
];
// Apply the vertex data to the mesh
vertexData.applyToMesh(customMesh);