VoxelPainter with cube positionning function

Hi guys,

It’s a bit hard for me to explain my problem, so I’ll try to be the most precisely as I can without blah-blah. Sorry guys !

What I am using : three.js examples

What I actually have after my modifications :

How I set X/Y of my rollOver :

var gridSize = 1200;
var gridCoords = {};
var iCount = 0, uCount = 0;

for(var i = -((gridSize / 2) - 25); i <= ((gridSize / 2) - 25); i = i + 50) {
    uCount = 0;
    
    for(var u = -((gridSize / 2) - 25); u <= ((gridSize / 2) - 25); u = u + 50) {
        gridCoords[i+":"+(u * -1)] = {x:iCount,z:uCount,xCoords:i,zCoords:(u * -1)};
        
        uCount++;
    }
    
    iCount++;
}

For this example :

122

How I place a cube :

function addCube(coords) {
    var voxel = new THREE.Mesh(cubeGeo, cubeMaterial);
                
    voxel.position.copy(coords.point).add(coords.face.normal);
    voxel.position.divideScalar(50).floor().multiplyScalar(50).addScalar(25);
    scene.add(voxel);

    objects.push(voxel);
}

Where coords = intersect with the grid on my mousedown event.

My objective : Edit addCube(var coords) to replace with addCube(var x, var z) where x & z are thoses showed on the top-right of my screenshot. Whatever I try, it doesn’t work. I don’t even know how to calculate coords without copying them from my rollOver. Any idea ? :frowning:

Got this working, there is still many improvement to make (ugh ! that “for”) :

 function addCube(x, z) {
    var voxel = new THREE.Mesh(cubeGeo, cubeMaterial);
    
    for(var i in gridCoords) {
        if(gridCoords[i].x == x && gridCoords[i].z == z) {
            voxel.position.x = gridCoords[i].xCoords;
            voxel.position.z = gridCoords[i].zCoords;
            voxel.position.y = 1;
        }
    }

    voxel.position.divideScalar(50).floor().multiplyScalar(50).addScalar(25);
    scene.add(voxel);

    objects.push(voxel);
}