Jump to content

Help me re: creating meshes from scratch


djvs
 Share

Recommended Posts

I'm completely in the dark when it comes to creating meshes from scratch. I figured it out as far as positions, indices, applying vertex data...I have this basic example, creating a barn-wall style pentagon from 5 x,y,z primitive vertex arrays -


var v2pent = (v3s, mesh) => {
  // clockwise from tl, 0 1 4, 1 3 4, 1 2 3
  var vtxdt = new BABYLON.VertexData
  vtxdt.positions = _.flatten(_.map([0,1,4,1,3,4,1,2,3], i => v3s[i]))
  vtxdt.indices = [0,1,2,3,4,5,6,7,8]
// these two lines added to try to debug, no help
//  vtxdt.normals = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]
//  vtxdt.uvs = _.flatten(_.map([0,1,4,1,3,4,1,2,3], i => [v3s[i][0],v3s[i][1]] ))

  var mesh = mesh || new BABYLON.Mesh('t1', scene)
  vtxdt.applyToMesh(mesh, true)
  return mesh
}

It sort of works, but the meshes are always dark gray to black (not picking up light?), and more importantly right now, not coming up when they're the foreground-most mesh when calling scene.pick - the other pentagon wall behind it will pick it up first! Help very much appreciated - I've read pretty much all the relevant docs and am totally confused. I don't know if its the uv and/or normal calculation, or if there's some helper function in the library to generate those for me (besides just ComputeNormals)? Is it something I could solve with BABYLON.Mesh.DOUBLESIDE, or an equivalent?

The material used in this case is the following by the way:


var wallMaterial = new BABYLON.TriPlanarMaterial("metal", scene);
wallMaterial.tileSize = 12;
wallMaterial.diffuseTextureX = metalTexture;
wallMaterial.diffuseTextureZ = metalTexture;
wallMaterial.backFaceCulling = false;

 

(copy and pasted from my issue here https://github.com/BabylonJS/Babylon.js/issues/2735)

1504484725.png

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...