threejs绘图

threejs绘图

function test17(){
    var group = new THREE.Group();
    var list1 = [[[58.0,-18.0,3452.0],[59.0,-18.0,3446.0],[59.0,18.0,3446.0],[58.0,17.0,3452.0]],[[58.0,17.0,3452.0],[59.0,18.0,3446.0],[60.0,18.0,3440.0],[62.0,18.0,3435.0],[65.0,18.0,3431.0],[69.0,18.0,3426.0],[73.0,18.0,3423.0],[78.0,18.0,3420.0],[84.0,17.0,3418.0],[89.0,18.0,3417.0],[95.0,18.0,3417.0],[198.0,18.0,34.0],[193.0,18.0,34.0],[188.0,18.0,33.0],[183.0,18.0,30.0],[178.0,18.0,27.0],[174.0,18.0,24.0],[171.0,18.0,20.0],[168.0,18.0,15.0],[166.0,18.0,10.0],[165.0,18.0,5.0],[164.0,18.0,0.0],[0.0,18.0,0.0],[-105.0,18.0,3452.0]],[[78.0,-18.0,3420.0],[84.0,-18.0,3418.0],[84.0,17.0,3418.0],[78.0,18.0,3420.0]],[[164.0,-18.0,0.0],[165.0,-18.0,5.0],[166.0,-18.0,10.0],[168.0,-18.0,15.0],[171.0,-17.0,20.0],[174.0,-18.0,24.0],[178.0,-18.0,27.0],[183.0,-18.0,30.0],[188.0,-18.0,33.0],[193.0,-18.0,34.0],[198.0,-18.0,34.0],[95.0,-18.0,3417.0],[89.0,-18.0,3417.0],[84.0,-18.0,3418.0],[78.0,-18.0,3420.0],[73.0,-18.0,3423.0],[69.0,-18.0,3426.0],[65.0,-18.0,3431.0],[62.0,-18.0,3435.0],[60.0,-18.0,3440.0],[59.0,-18.0,3446.0],[58.0,-18.0,3452.0],[-105.0,-18.0,3452.0],[0.0,-17.0,0.0]],[[178.0,-18.0,27.0],[174.0,-18.0,24.0],[174.0,18.0,24.0],[178.0,18.0,27.0]],[[-105.0,-18.0,3452.0],[58.0,-18.0,3452.0],[58.0,17.0,3452.0],[-105.0,18.0,3452.0]],[[65.0,-18.0,3431.0],[69.0,-18.0,3426.0],[69.0,18.0,3426.0],[65.0,18.0,3431.0]],[[183.0,-18.0,30.0],[178.0,-18.0,27.0],[178.0,18.0,27.0],[183.0,18.0,30.0]],[[0.0,-17.0,0.0],[-105.0,-18.0,3452.0],[-105.0,18.0,3452.0],[0.0,18.0,0.0]],[[89.0,-18.0,3417.0],[95.0,-18.0,3417.0],[95.0,18.0,3417.0],[89.0,18.0,3417.0]],[[60.0,-18.0,3440.0],[62.0,-18.0,3435.0],[62.0,18.0,3435.0],[60.0,18.0,3440.0]],[[95.0,-18.0,3417.0],[198.0,-18.0,34.0],[198.0,18.0,34.0],[95.0,18.0,3417.0]],[[166.0,-18.0,10.0],[165.0,-18.0,5.0],[165.0,18.0,5.0],[166.0,18.0,10.0]],[[62.0,-18.0,3435.0],[65.0,-18.0,3431.0],[65.0,18.0,3431.0],[62.0,18.0,3435.0]],[[164.0,-18.0,0.0],[0.0,-17.0,0.0],[0.0,18.0,0.0],[164.0,18.0,0.0]],[[59.0,-18.0,3446.0],[60.0,-18.0,3440.0],[60.0,18.0,3440.0],[59.0,18.0,3446.0]],[[168.0,-18.0,15.0],[166.0,-18.0,10.0],[166.0,18.0,10.0],[168.0,18.0,15.0]],[[193.0,-18.0,34.0],[188.0,-18.0,33.0],[188.0,18.0,33.0],[193.0,18.0,34.0]],[[171.0,-17.0,20.0],[168.0,-18.0,15.0],[168.0,18.0,15.0],[171.0,18.0,20.0]],[[165.0,-18.0,5.0],[164.0,-18.0,0.0],[164.0,18.0,0.0],[165.0,18.0,5.0]],[[198.0,-18.0,34.0],[193.0,-18.0,34.0],[193.0,18.0,34.0],[198.0,18.0,34.0]],[[174.0,-18.0,24.0],[171.0,-17.0,20.0],[171.0,18.0,20.0],[174.0,18.0,24.0]],[[84.0,-18.0,3418.0],[89.0,-18.0,3417.0],[89.0,18.0,3417.0],[84.0,17.0,3418.0]],[[69.0,-18.0,3426.0],[73.0,-18.0,3423.0],[73.0,18.0,3423.0],[69.0,18.0,3426.0]],[[73.0,-18.0,3423.0],[78.0,-18.0,3420.0],[78.0,18.0,3420.0],[73.0,18.0,3423.0]],[[188.0,-18.0,33.0],[183.0,-18.0,30.0],[183.0,18.0,30.0],[188.0,18.0,33.0]]];



    console.log(list1);


    var list2 = [[[3,0,1]],[[1,0,23],[23,22,21],[20,19,18],[17,16,15],[15,14,13],[10,9,8],[8,7,6],[6,5,4],[4,3,2],[2,1,23],[20,18,17],[17,15,13],[10,8,6],[6,4,2],[2,23,21],[17,13,12],[10,6,2],[2,21,20],[11,10,2],[2,20,17]],[[2,3,0],[0,1,2]],[[22,23,0],[0,1,2],[4,5,6],[6,7,8],[12,13,14],[15,16,17],[20,21,22],[6,8,9],[11,12,14],[11,14,15],[11,15,17],[17,18,20],[0,2,4],[10,11,17],[17,20,22],[22,0,4],[22,4,6]],[[1,0,3]],[[2,3,0],[0,1,2]],[[1,0,3],[3,2,1]],[[1,0,3],[3,2,1]],[[1,0,3],[3,2,1]],[[2,3,0],[0,1,2]],[[2,3,0],[0,1,2]],[[2,3,0],[0,1,2]],[[2,3,0],[0,1,2]],[[2,3,0],[0,1,2]],[[1,0,3],[3,2,1]],[[1,0,3]],[[0,3,2]],[[1,0,3],[3,2,1]],[[1,0,3],[3,2,1]],[[2,3,0],[0,1,2]],[[1,0,3],[3,2,1]],[[2,3,0]],[[2,3,0],[0,1,2]],[[2,3,0],[0,1,2]],[[3,0,1]],[[1,0,3],[3,2,1]]];

    
    console.log(list2);
    
    for(var k=0;k<list1.length;k++){
        //console.log(list1[k]);

        var triangleGeometry = new THREE.Geometry();
        
        var index_arr = list1[k];
        for(var m=0;m<index_arr.length;m++){
            var index_p = index_arr[m];

            console.log(index_p);
            if(typeof(index_p) !="undefined")
            {
                triangleGeometry.vertices.push(new THREE.Vector3(index_p[0],index_p[1],index_p[2]));
            }
            
        }

        var index_group = list2[k];
        for(var m=0;m<index_group.length;m++){
            var index_g = index_group[m];

            console.log(index_g);

            
            triangleGeometry.faces.push(new THREE.Face3(index_g[0],index_g[1],index_g[2]));

            var hex = Math.random() * 0xffffff;
            triangleGeometry.faces[m].color.setHex(hex);
                
        }

        //var triangleMaterial = new THREE.MeshBasicMaterial({ color:0xff0000, side:THREE.DoubleSide });   
        var triangleMaterial = new THREE.MeshBasicMaterial({ vertexColors: THREE.FaceColors, side:THREE.DoubleSide,overdraw: 0.99 });
        
        var mesh = new THREE.Mesh(triangleGeometry, triangleMaterial);

        group.add( mesh );
    }
     
    
    return group;
}

 

 

 

#########################

posted @ 2021-11-13 19:19  西北逍遥  阅读(124)  评论(0编辑  收藏  举报