Jump to content

[SOLVED] Custom UV vertex Data with Duplicate Points on Facets


Pryme8
 Share

Recommended Posts

So I am getting ready to do dynamic LOD terrain by using chunking and T-Junctions and so I was making the function to create the mesh data.
I am fully aware of http://babylonjsguide.github.io/advanced/Custom but in it, there is nothing that covers the thing I need to know because its only shows building one facet.

http://playground.babylonjs.com/#IJTGJ3

So I have my first variance of the 8 T-Junctions and now I am wondering how I do the uv set up because all of the facets share the 0 position/point.  
do I just repeat the uv data on that point? 

so for example if I was just gonna do the first two facets:
var uv = [
//facet 0
0,1,
0.5, 0.5,
0.5, 1,
//facet 1
0.5, 0.5,
1, 1,
0.5, 1
];

Notice how I use 0.5, 0.5 twice?  This will be repeated for every facet because they all share the 0 point?  I figured this is correct but before I make assumptions It would be worth asking!

Update/EDIT ***
just need to know if this is correct, I guess I could write up a quick shader to show UV positions but I'm being lazy and want to go to bed.

    var mesh = new BABYLON.Mesh('tPlane', scene);
    var vData = new BABYLON.VertexData();
    var hs = size*0.5;
    var points = 
    [
        0,0,0,          //0
        -1*hs,0,1*hs,   //1
        0,0,1*hs,       //2
        1*hs,0,1*hs,    //3
        1*hs,0,0,       //4
        1*hs,0,-1*hs,   //5
        0,0,-1*hs,      //6
        -1*hs,0,-1*hs,  //7
        -1*hs,0,0       //8

    ];
    var indices = 
    [
        1,0,2,
        0,3,2,
        0,4,3,
        0,5,4,
        0,6,5,
        7,6,0,
        8,7,0,
        1,8,0
    ];

    var normals = [];

    BABYLON.VertexData.ComputeNormals(points, indices, normals);
    
    var uv =
    [
        0,1, 0.5, 0.5, 0.5, 1,
        0.5, 0.5, 1, 1, 0.5, 1,
        0.5, 0.5, 1, 0.5, 1, 1,
        0.5, 0.5, 1, 0, 1, 0.5,
        0.5, 0.5, 0.5, 0, 1, 0,
        0, 0, 0, 0.5, 0.5, 0.5,
        0, 0.5, 0, 0, 0.5, 0.5,
        0, 1, 0, 0.5, 0.5, 0.5
    ];

    vData.positions = points;
    vData.indices = indices;
    vData.normals = normals;
    vData.uv = uv;

    vData.applyToMesh(mesh);

http://playground.babylonjs.com/#IJTGJ3#2

Link to comment
Share on other sites

Nearly there

1) Each point has to be matched to one position on the image, so 8 points then 8 uv pairs

2) You missed the line vData.uv = uv from the playground  BUT

3) vData.uvs  needs the s

Hope this PG helps http://playground.babylonjs.com/#IJTGJ3#3

If you have a plane with left front corner at (p, q) and width w and height h, the for any point (x, z) in the plane for a straight mapping of an image onto the plane

the uv pair for (x, z) is ( (x - p)/w, (z - q)/h )

Of course you can mess around with the uvs if you want.

Link to comment
Share on other sites

thank you john, I have struggled with a equation to do UVs and "the uv pair for (x, z) is ( (x - p)/w, (z - q)/h )" makes a lot of since now thank you!

I thought it was per facet but now I understand its per position point!  Your a boss!

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...