Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript threeJS程序平面顶点未对齐_Javascript_Three.js_Vertices_Procedural Generation_Simplex Noise - Fatal编程技术网

Javascript threeJS程序平面顶点未对齐

Javascript threeJS程序平面顶点未对齐,javascript,three.js,vertices,procedural-generation,simplex-noise,Javascript,Three.js,Vertices,Procedural Generation,Simplex Noise,我使用threeJS结合单纯形噪声算法生成一个50x50平面的瓷砖系统。现在,我在x+y中循环,并添加每个平面。然后,我使用单纯形噪声算法来计算平面的四个顶点z位置 我使用当前的x/y作为左上角的垂直([0]),其余部分可以在最初生成平铺的函数中看到: PerlinSimplex.noiseDetail(4,0.5); x=0; y=0; while (x<32) { while (y<32)

我使用threeJS结合单纯形噪声算法生成一个50x50平面的瓷砖系统。现在,我在x+y中循环,并添加每个平面。然后,我使用单纯形噪声算法来计算平面的四个顶点z位置

我使用当前的x/y作为左上角的垂直([0]),其余部分可以在最初生成平铺的函数中看到:

        PerlinSimplex.noiseDetail(4,0.5);

        x=0;
        y=0;

        while (x<32) {
            while (y<32) {
                l=(x*tilesize)+(tilesize/2);
                t=(y*tilesize)+(tilesize/2);
                //fScl= .07;
                fScl= 1;
                xx=x*fScl;
                yy=y*fScl;

                tl=Math.floor((PerlinSimplex.noise(xx,yy))*100);
                bl=Math.floor((PerlinSimplex.noise(xx,yy-1))*100);
                br=Math.floor((PerlinSimplex.noise(xx+1,yy-1))*100);
                tr=Math.floor((PerlinSimplex.noise(xx+1,yy))*100);

                addTile(t,l,tl,tr,bl,br);
                y++;
            }
            y=0;
            x++;
        }
(请注意,我意识到我不需要为每个平面创建新的几何图形)

好的,结果如下:

如您所见,顶点没有对齐。我尝试过很多事情,但现在完全被难倒了。我很确定我已经将正确的顶点设置为TL、TR等。你能发现为什么顶点没有对齐吗

谢谢:)
杰克

好的,结果证明我把t和l传递到函数中的方法是错误的。啊

:)

    function addTile(x,y,tl,tr,bl,br) {

        var geo=new THREE.PlaneGeometry(tilesize, tilesize);
        geo.dynamic = true;

        geos.push(geo);

        var plane = new THREE.Mesh(geo, col);
        plane.overdraw = true;

        plane.geometry.vertices[0].z=tl;
        plane.geometry.vertices[1].z=tr;
        plane.geometry.vertices[2].z=bl;
        plane.geometry.vertices[3].z=br;


        plane.geometry.computeFaceNormals();
        plane.geometry.computeVertexNormals();    
        plane.geometry.__dirtyNormals = true;

        plane.position.x=x;
        plane.position.y=y;
        plane.position.z=0;

        scene.add(plane);

        planes.push(plane);

        plane.geometry.verticesNeedUpdate = true;

        // changes to the normals
        plane.geometry.normalsNeedUpdate = true;

    }