三个网格生成 - BufferAttribute.copyVector3sArray向量未定义

时间:2017-12-23 02:30:50

标签: javascript vector three.js mesh

我正在运行时构建一个球体的网格物体(后来将用于生成超形状,因此我会在SphereGeometry之外)。当前的矢量放置似乎工作正常(通过将球放置在适当的坐标处进行测试)。但是,从这些坐标创建网格时,我遇到以下错误:

cmp_data=read.delim("COM AND PAN 2.dat",sep=",", header = TRUE)
rel=read.delim("RELATIONSHIP 2.dat",sep=",",header = TRUE)
dir_data=read.delim("DIR PAN.dat",sep = ",",header = TRUE)

tst_1=data.frame(CMP_PAN="AARCS0272Q")
####CLUSTER-1
##LEVEL2
#TO GET COMPANY NAME
d.1=merge(tst_1,cmp_data,by="CMP_PAN")

# TO GET CONNECTED DIR_PAN
d.2=merge(d.1,rel,by="CMP_PAN",all.x = TRUE)

#TO GET COMPANY LINKED OF LINKED DIR_PAN
d.3=merge(d.2,rel,by="DIR_PAN",all.x = TRUE)

 #TO GET COMPANY NAMES
 d.4=merge(d.3,cmp_data,by.x ="CMP_PAN.y",by.y = "CMP_PAN")
  #PREPARING THE DATA
 d.5=data.frame(CMP_PAN1=d.4$CMP_PAN.x,
 CMP_NAME1=d.4$CMP_NAME.x,
 CMP_PAN2=d.4$CMP_PAN.y,CMP_NAME2=d.4$CMP_NAME.y)
 d.6=unique(d.5)
 d.6=d.6[order(d.6$CMP_PAN1),]

 ###LEVEL-3
 d.7=merge(d.6,rel,by.x = "CMP_PAN2",by.y = "CMP_PAN")
 d.8=merge(d.7,rel,by="DIR_PAN")
 d.9=merge(d.8,cmp_data,by="CMP_PAN")
 #PREPARING THE DATA
 d.10=data.frame(CMP_PAN1=d.9$CMP_PAN1,
 CMP_NAME1=d.9$CMP_NAME1,CMP_PAN2=d.9$CMP_PAN2,
 CMP_NAME2=d.9$CMP_NAME2,CMP_PAN3=d.9$CMP_PAN,CMP_NAME3=d.9$CMP_NAME)
 d.11=unique(d.10)
 d.11=d.11[order(d.11$CMP_PAN1),]
 d.12=data.frame(lapply(d.11,as.character),stringsAsFactors = FALSE)
 d.12.p1=unique(d.12$CMP_PAN1)
 d.12.n1=unique(d.12$CMP_NAME1)
 d.12.p2=unique(d.12$CMP_PAN2)
 d.12.n2=unique(d.12$CMP_NAME2)
 d.12.p3=unique(d.12$CMP_PAN3)
 d.12.n3=unique(d.12$CMP_NAME3)
 max.len=max(length(d.12.p1),length(d.12.n1),
 length(d.12.p2),length(d.12.n2),length(d.12.p3),length(d.12.n3))
 d.13=data.frame(CMP_PAN1=c(d.12.p1,rep("",max.len-length(d.12.p1))),
            CMP_NAME1=c(d.12.n1,rep("",max.len-length(d.12.n1))),
            CMP_PAN2=c(d.12.p2,rep("",max.len-length(d.12.p2))),
            CMP_NAME2=c(d.12.n2,rep("",max.len-length(d.12.n2))),
            CMP_PAN3=c(d.12.p3,rep("",max.len-length(d.12.p3))),
            CMP_NAME3=c(d.12.n3,rep("",max.len-length(d.12.n3))))

  #export(d.13,"check3.csv")

  ###LEVEL -4
  d.14=merge(d.13,rel,by.x = "CMP_PAN3",by.y = "CMP_PAN")
  d.15=merge(d.14,rel,by="DIR_PAN")
  d.16=merge(d.15,cmp_data,by="CMP_PAN")
  #PREPARING THE DATA
  d.17=data.frame(CMP_PAN1=d.16$CMP_PAN1,CMP_NAME1=d.16$CMP_NAME1,
            CMP_PAN2=d.16$CMP_PAN2,CMP_NAME2=d.16$CMP_NAME2,
            CMP_PAN3=d.16$CMP_PAN3,CMP_NAME3=d.16$CMP_NAME3,
            CMP_PAN4=d.16$CMP_PAN,CMP_NAME4=d.16$CMP_NAME)
  d.17=unique(d.17)
  d.17=d.17[order(d.17$CMP_PAN1),]
  d.17=data.frame(lapply(d.17,as.character),stringsAsFactors = FALSE)
  d.17.p1=unique(d.17$CMP_PAN1)
  d.17.n1=unique(d.17$CMP_NAME1)
  d.17.p2=unique(d.17$CMP_PAN2)
  d.17.n2=unique(d.17$CMP_NAME2)
  d.17.p3=unique(d.17$CMP_PAN3)
  d.17.n3=unique(d.17$CMP_NAME3)
  d.17.p4=unique(d.17$CMP_PAN4)
  d.17.n4=unique(d.17$CMP_NAME4)
  max.len1=max(length(d.17.p1),length(d.17.n1),length(d.17.p2),
  length(d.17.n2),length(d.17.p3),length(d.17.n3),
         length(d.17.p4),length(d.17.n4))

  #export(d.17,"ch.csv")
  d.18=data.frame(CMP_PAN1=c(d.17.p1,rep("",max.len1-length(d.17.p1))),
            CMP_NAME1=c(d.17.n1,rep("",max.len1-length(d.17.n1))),
            CMP_PAN2=c(d.17.p2,rep("",max.len1-length(d.17.p2))),
            CMP_NAME2=c(d.17.n2,rep("",max.len1-length(d.17.n2))),
            CMP_PAN3=c(d.17.p3,rep("",max.len1-length(d.17.p3))),
            CMP_NAME3=c(d.17.n3,rep("",max.len1-length(d.17.n3))),
            CMP_PAN4=c(d.17.p4,rep("",max.len1-length(d.17.p4))),
            CMP_NAME4=c(d.17.n4,rep("",max.len1-length(d.17.n4))))

  ##LEVEL-5
  d.19=merge(d.18,rel,by.x = "CMP_PAN4",by.y = "CMP_PAN")
  d.20=merge(d.19,rel,by="DIR_PAN")
  d.21=merge(d.20,cmp_data,by="CMP_PAN")
  #PREPARING THE DATA
  d.22=data.frame(CMP_PAN1=d.21$CMP_PAN1,CMP_NAME1=d.21$CMP_NAME1,
            CMP_PAN2=d.21$CMP_PAN2,CMP_NAME2=d.21$CMP_NAME2,
            CMP_PAN3=d.21$CMP_PAN3,CMP_NAME3=d.21$CMP_NAME3,
            CMP_PAN4=d.21$CMP_PAN4,CMP_NAME4=d.21$CMP_NAME4,
            CMP_PAN5=d.21$CMP_PAN,CMP_NAME5=d.21$CMP_NAME)
  d.22=unique(d.22)
  d.22=d.22[order(d.22$CMP_PAN1),]
  d.22=data.frame(lapply(d.22,as.character),stringsAsFactors = FALSE)
  d.22.p1=unique(d.22$CMP_PAN1)
  d.22.n1=unique(d.22$CMP_NAME1)
  d.22.p2=unique(d.22$CMP_PAN2)
  d.22.n2=unique(d.22$CMP_NAME2)
  d.22.p3=unique(d.22$CMP_PAN3)
  d.22.n3=unique(d.22$CMP_NAME3)
  d.22.p4=unique(d.22$CMP_PAN4)
  d.22.n4=unique(d.22$CMP_NAME4)
  d.22.p5=unique(d.22$CMP_PAN5)
  d.22.n5=unique(d.22$CMP_NAME5)
  max.len2=max(length(d.22.p1),length(d.22.n1),length(d.22.p2),
  length(d.22.n2),length(d.22.p3),length(d.22.n3),
       length(d.22.p4),length(d.22.n4),length(d.22.p5),length(d.22.n5))

  d.23=data.frame(CMP_PAN1=c(d.22.p1,rep("",max.len2-length(d.22.p1))),
            CMP_NAME1=c(d.22.n1,rep("",max.len2-length(d.22.n1))),
            CMP_PAN2=c(d.22.p2,rep("",max.len2-length(d.22.p2))),
            CMP_NAME2=c(d.22.n2,rep("",max.len2-length(d.22.n2))),
            CMP_PAN3=c(d.22.p3,rep("",max.len2-length(d.22.p3))),
            CMP_NAME3=c(d.22.n3,rep("",max.len2-length(d.22.n3))),
            CMP_PAN4=c(d.22.p4,rep("",max.len2-length(d.22.p4))),
            CMP_NAME4=c(d.22.n4,rep("",max.len2-length(d.22.n4))),
            CMP_PAN5=c(d.22.p5,rep("",max.len2-length(d.22.p5))),
            CMP_NAME5=c(d.22.n5,rep("",max.len2-length(d.22.n5))))
   setwd("/Users/riskassessment/Desktop/COMPANY NETWORK/CLUSTER")
   export(d.23,"cluster150.csv")

   pan.x=data.frame(CMP_PAN=d.23$CMP_PAN5)  
   pan.y=rbind(pan1,pan.x)
   pan1=pan.y
   d.24=cmp_data[!cmp_data$CMP_PAN %in%
   pan1$CMP_PAN,]%>% select(CMP_PAN)

   a=sample_n(d.24,1)
   print(a)

使用Chrome的调试器,据我所知,顶点和面被按预期分配给网格,但是,当网格传递到渲染周期时,会抛出此问题。此过程的功能是:

three.min.js:532
THREE.BufferAttribute.copyVector3sArray(): vector is undefined 0
copyVector3sArray   @   three.min.js:532
fromDirectGeometry  @   three.min.js:548
fromGeometry    @   three.min.js:547
setFromObject   @   three.min.js:544
get @   three.min.js:67
update  @   three.min.js:76
k   @   three.min.js:155
k   @   three.min.js:156
Wd.render   @   three.min.js:190
render  @   threedVisuals.js:520
superShapes @   threedVisuals.js:512
visualise   @   app.js:155
(anonymous) @   app.js:87

有人能说清楚为什么会这样吗?似乎无法找到任何类似问题,并且计算法线等相关解法也无效(function calcSphere(radius, detailLevel) { var globePoints = []; for (var i = 0; i < detailLevel; i++) { //latitude var lat = map_range(i, 0, detailLevel, -Math.PI / 2, Math.PI / 2); var latPoints = []; for (var j = 0; j < detailLevel; j++) { //longitude var long = map_range(j, 0, detailLevel, -Math.PI, Math.PI); // convert lat and long to cartesian coords var x = radius * Math.sin(long) * Math.cos(lat); var y = radius * Math.sin(long) * Math.sin(lat); var z = radius * Math.cos(long); latPoints.push({ x, y, z }); } globePoints.push(latPoints); } drawSphere(globePoints); } function drawSphere(globePoints) { var sphereGeo = new THREE.Geometry(); for (var i = 0; i < globePoints.length - 1; i++) { for (var j = 0; j < globePoints[i].length - 1; j++) { var curIndex = sphereGeo.vertices.length; //used for tracking cur location in vertices array var v1 = globePoints[i][j]; sphereGeo.vertices.push(new THREE.Vector3(v1.x, v1.y, v1.z)); var v2 = globePoints[i + 1][j]; sphereGeo.vertices.push(new THREE.Vector3(v2.x, v2.y, v2.z)); var v3 = globePoints[i][j + 1]; sphereGeo.vertices.push(new THREE.Vector3(v3.x, v3.y, v3.z)); var v4 = globePoints[i + 1][j + 1]; sphereGeo.vertices.push(new THREE.Vector3(v4.x, v4.y, v4.z)); var f1 = new THREE.Face3( sphereGeo.vertices[curIndex + 0], sphereGeo.vertices[curIndex + 1], sphereGeo.vertices[curIndex + 2]); var f2 = new THREE.Face3( sphereGeo.vertices[curIndex + 1], sphereGeo.vertices[curIndex + 2], sphereGeo.vertices[curIndex + 3]); sphereGeo.faces.push(f1); sphereGeo.faces.push(f2); } } // sphereGeo.computeFaceNormals(); // sphereGeo.computeVertexNormals(); var sphereMat = new THREE.MeshBasicMaterial(); var sphereMesh = new THREE.Mesh(sphereGeo, sphereMat); scene.add(sphereMesh); })。

非常感谢提前!

1 个答案:

答案 0 :(得分:0)

谢谢@ prisoner849,这是一个愚蠢的疏忽。

代码块:

  var f1 = new THREE.Face3(
    sphereGeo.vertices[curIndex + 0],
    sphereGeo.vertices[curIndex + 1],
    sphereGeo.vertices[curIndex + 2]);
  var f2 = new THREE.Face3(
    sphereGeo.vertices[curIndex + 1],
    sphereGeo.vertices[curIndex + 2],
    sphereGeo.vertices[curIndex + 3]);

应该只是:

        var f1 = new THREE.Face3(
          curIndex+0,
          curIndex+1,
          curIndex+2);
        var f2 = new THREE.Face3(
          curIndex+1,
          curIndex+2,
          curIndex+3);

无需直接引用顶点。