Jump to content

Babylon.js: A double array to 3d


foumfo
 Share

Recommended Posts

On 3/3/2018 at 11:40 AM, JohnK said:

@foumfo at last a PG done with planes so no faces are drawn where they would be hidden, with textures too - https://www.babylonjs-playground.com/#9PP17F#9

As for performance improvements? You would need to check.

So from what I understand, your way would've worked perfectly if we had an array like this for example:

every

array[i][j] = [1,1,0,1]

instead of 1 or 0.

Meaning that we don't have boxes but walls and absent walls correct?

Link to comment
Share on other sites

This is how I managed to create an array that for every block contains 4 walls or absent ones:

        var i = 0, j = 0;
        var walls = [];
        // Initialize the walls array
        for (i = 0; i < map.cells.length; i++) {
            walls[i] = [];
            for (j = 0; j < map.cells[0].length; j++) {
                walls[i][j] = [0,0,0,0];
            }
        }
        //fill the array
        for (i = 0; i < map.cells.length; i++) {
            //left column
            walls[i][0][3] = 1;
            //right column
            walls[i][map.cells[0].length - 1][1] = 1;
            for (j = 0; j < map.cells[0].length; j++) {
                //bottom row
                if (i === 0) {
                    walls[i][j][2] = 1;
                    continue;
                }
                //top row
                else if (i === map.cells.length - 1) {
                    walls[i][j][0] = 1;
                    continue;
                }
                for (var dir = 0; dir <= 3; dir++) {
                    switch(dir) {
                        //check up
                        case 0: 
                            if (map.cells[i + 1][j] === 0) {
                                map.cells[i][j][0] = 1;
                                continue;
                            }
                            else continue;
                        //check right
                        case 1:                            
                            if (map.cells[i][j + 1] === 0) {
                                map.cells[i][j][1] = 1;
                                continue;
                            }
                            else continue;
                        //check down
                        case 2:                            
                            if (map.cells[i - 1][j] === 0) {
                                map.cells[i][j][2] = 1;
                                continue;
                            }
                            else continue;
                        //check left
                        case 3:                            
                            if (map.cells[i][j - 1] === 0) {
                                map.cells[i][j][3] = 1;
                                continue;
                            }
                            else continue;
                    }
                }
            }
        }

map.cells being the original double array filled with 1 & 0.

I could use some help with adding the planes on the scene

Edited by foumfo
changed the code
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...