emilbusman Posted March 6, 2014 Share Posted March 6, 2014 I'm a newbie going through the basics here. In the section about creating a mesh from a list of vertices, I can't get the code to work. It seems to crash when constructing the mesh in the linevar plane = new BABYLON.Mesh("plane", [3, 3, 2], scene);Any thoughts? I am trying to create a hexagon (once I get the sample code working anyways Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 6, 2014 Share Posted March 6, 2014 THe correct line is:var plane = BABYLON.Mesh.CreatePlane("plane", 3, scene); Quote Link to comment Share on other sites More sharing options...
emilbusman Posted March 7, 2014 Author Share Posted March 7, 2014 THe correct line is:var plane = BABYLON.Mesh.CreatePlane("plane", 3, scene); Thanks for the reply, but that doesn't seem to be what I need either. The section of the walkthrough I am referring to states:You can also create a mesh from a list of vertices and faces:.var plane = new BABYLON.Mesh("plane", [3, 3, 2], scene);var indices = [];var vertices = [];// Verticesvar halfSize = 0.5;vertices.push(-halfSize, -halfSize, 0, 0, 1.0, 0, 0.0, 0.0);vertices.push(halfSize, -halfSize, 0, 0, 1.0, 0, 1.0, 0.0);vertices.push(halfSize, halfSize, 0, 0, 1.0, 0, 1.0, 1.0);vertices.push(-halfSize, halfSize, 0, 0, 1.0, 0, 0.0, 1.0);// Indicesindices.push(0);indices.push(1);indices.push(2);indices.push(0);indices.push(2);indices.push(3);plane.setVertices(vertices, 1);plane.setIndices(indices);return plane;You have to create a blank new mesh and call setVertices and setIndices.using the line you gave me breaks the lines plane.setVertices(vertices, 1); and plane.setIndices(indices); I don't see anything like those two functions in the documentation either. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 7, 2014 Share Posted March 7, 2014 BABYLON.Mesh does not take three argument. his signature is "Name" and "Scene" Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 8, 2014 Share Posted March 8, 2014 Oh sorry I misunderstood. Here is a working sample for a box:BABYLON.Mesh.CreateBox = function (name, size, scene, updatable) { var box = new BABYLON.Mesh(name, scene); var normalsSource = [ new BABYLON.Vector3(0, 0, 1), new BABYLON.Vector3(0, 0, -1), new BABYLON.Vector3(1, 0, 0), new BABYLON.Vector3(-1, 0, 0), new BABYLON.Vector3(0, 1, 0), new BABYLON.Vector3(0, -1, 0) ]; var indices = []; var positions = []; var normals = []; var uvs = []; // Create each face in turn. for (var index = 0; index < normalsSource.length; index++) { var normal = normalsSource[index]; // Get two vectors perpendicular to the face normal and to each other. var side1 = new BABYLON.Vector3(normal.y, normal.z, normal.x); var side2 = BABYLON.Vector3.Cross(normal, side1); // Six indices (two triangles) per face. var verticesLength = positions.length / 3; indices.push(verticesLength); indices.push(verticesLength + 1); indices.push(verticesLength + 2); indices.push(verticesLength); indices.push(verticesLength + 2); indices.push(verticesLength + 3); // Four vertices per face. var vertex = normal.subtract(side1).subtract(side2).scale(size / 2); positions.push(vertex.x, vertex.y, vertex.z); normals.push(normal.x, normal.y, normal.z); uvs.push(1.0, 1.0); vertex = normal.subtract(side1).add(side2).scale(size / 2); positions.push(vertex.x, vertex.y, vertex.z); normals.push(normal.x, normal.y, normal.z); uvs.push(0.0, 1.0); vertex = normal.add(side1).add(side2).scale(size / 2); positions.push(vertex.x, vertex.y, vertex.z); normals.push(normal.x, normal.y, normal.z); uvs.push(0.0, 0.0); vertex = normal.add(side1).subtract(side2).scale(size / 2); positions.push(vertex.x, vertex.y, vertex.z); normals.push(normal.x, normal.y, normal.z); uvs.push(1.0, 0.0); } box.setVerticesData(positions, BABYLON.VertexBuffer.PositionKind, updatable); box.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind, updatable); box.setVerticesData(uvs, BABYLON.VertexBuffer.UVKind, updatable); box.setIndices(indices); return box; }; Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 23, 2014 Share Posted March 23, 2014 Hey emilbusman (and everyone else)... we will make sure that the example in that document... gets updated. Thanks for pointing it out to us. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 11, 2014 Share Posted April 11, 2014 I have updated that document (Thanks to Wingnut) Wingnut 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.