Jump to content

Apply texture on mesh created from vectors


Ron
 Share

Recommended Posts

How to apply a texture on a mesh created by the following function :

function drawTriangle(scene) {var triangle = new BABYLON.Mesh('triangle', scene);var positions = [0, 1, 0,-1, -1, 0,1, -1, 0];var normals = [1, 1, 1,1, 1, 1,1, 1, 1];var indices = [];indices.push(0);indices.push(1);indices.push(2);triangle.setVerticesData(positions, BABYLON.VertexBuffer.PositionKind);triangle.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind);triangle.setIndices(indices);return triangle;}

 Have tried the usual textures in the tutorial, but they don't work on this kind of objects

Link to comment
Share on other sites

You have to add uv (texture coordinates). Somethign like this:

function drawTriangle(scene) {var triangle = new BABYLON.Mesh('triangle', scene);var positions = [0, 1, 0,-1, -1, 0,1, -1, 0];var normals = [1, 1, 1,1, 1, 1,1, 1, 1];var uv = [0, 0,1, 0,1, 1]var indices = [];indices.push(0);indices.push(1);indices.push(2);triangle.setVerticesData(positions, BABYLON.VertexBuffer.PositionKind);triangle.setVerticesData(normals, BABYLON.VertexBuffer.NormalKind);triangle.setVerticesData(uv , BABYLON.VertexBuffer.UVKind);triangle.setIndices(indices);return triangle;}
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...