Jump to content

Wrong variable in uvs in VertexData.CreateGround?


Recommended Posts

Never very confident in these things but in BJS2.5 shouldn't line 33527

uvs.push(col / subdivisionsX, 1.0 - row / subdivisionsX);

in the VertexData.CreateGround function below be

uvs.push(col / subdivisionsX, 1.0 - row / subdivisionsY);

Fairly minor as I expect most grounds will be square. Then again the code may be correct and I have misunderstood something.

VertexData.CreateGround = function (options) {
            var indices = [];
            var positions = [];
            var normals = [];
            var uvs = [];
            var row, col;
            var width = options.width || 1;
            var height = options.height || 1;
            var subdivisionsX = options.subdivisionsX || options.subdivisions || 1;
            var subdivisionsY = options.subdivisionsY || options.subdivisions || 1;
            for (row = 0; row <= subdivisionsY; row++) {
                for (col = 0; col <= subdivisionsX; col++) {
                    var position = new BABYLON.Vector3((col * width) / subdivisionsX - (width / 2.0), 0, ((subdivisionsY - row) * height) / subdivisionsY - (height / 2.0));
                    var normal = new BABYLON.Vector3(0, 1.0, 0);
                    positions.push(position.x, position.y, position.z);
                    normals.push(normal.x, normal.y, normal.z);
                    uvs.push(col / subdivisionsX, 1.0 - row / subdivisionsX);


Link to comment
Share on other sites

@adam yes I understand the reasons for subdivisionsX and subdivisionsY my contention is that dividing the row by subdivisionsX rather than subdivisionsY you will get the wrong uv values in the z-direction. I am suggesting that a correction is made to the line I state.


Link to comment
Share on other sites

Usually you cover the ground with some nondescript texture. If for some reason you wanted all of the image over the ground then the current code does not allow that.


However I can see that if you use a typical ground type image then the current method does not stretch the image in the z direction ( I think) so perhaps that the reason for dividing by subdivisionsX rather than subdivisionsY.

Link to comment
Share on other sites

Well, all the subdivisions vars were updated to subdivisionsX.  So I guess it was on purpose. :)  


That worked for me, so I left that way (I didn't want any stretching of the texture).

18 minutes ago, JohnK said:

good contribution to BabylonJS.:)


edit: I should have said all the subdivisions vars were changed to subdivisionsX that were not required to be changed to subdivisionsY for the new feature. (I've written a lot of code since then)

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.

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.


  • Recently Browsing   0 members

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