自定义网格[z = sin(x + y)plot]未显示

时间:2014-07-02 18:48:48

标签: three.js dart

Breaking on exception: The null object does not have a method '+'.

当我运行以下函数(绘图计算和绘图时)时出现上述错误:

initGraph() {

  var RANGE = 10,
      INTERVALS = 100,
      UNIT = RANGE / INTERVALS,
      x,
      y,
      z,
      c = 0,
      xi = 0,
      yi = 0;

  addFace4(geom, p1, p2, p3, p4, color) {
    return geom.faces.add(new Face4(p1, p2, p3, p4));
  }

  var geometry = new Geometry();

  z = Math.sin(x + y);

  for (var x = -RANGE; x < RANGE; x++) {
    for (var y = -RANGE; y < RANGE; y++) {

      var ci = yi + xi * UNIT;

      geometry.vertices.add(new Vector3(x.toDouble() * 50, y.toDouble() * 50, z.toDouble() * 50));

      if (y > -RANGE && x > -RANGE) {
        c = '0xFFFFFF';
        //addFace(geometry,ci-1,ci,ci-UNIT,c);
        //addFace(geometry,ci-1,ci-UNIT-1,ci-UNIT,c);
        addFace4(geometry, ci - 1, ci, ci - UNIT, ci - UNIT - 1, c);
        geometry.faceVertexUvs[0].add([new UV(xi / UNIT, yi / UNIT), new UV(xi / UNIT, (yi + 1) / UNIT), new UV((xi + 1) / UNIT, (yi + 1) / UNIT), new UV((xi + 1) / UNIT, yi / UNIT)]);
      }
      yi += 1;
    }
    xi += 1;
    yi = 0;

    geometry.computeFaceNormals();
    var material = new MeshBasicMaterial(color: 0xffff00, side: DoubleSide);
    var mesh = new Mesh(geometry, material);
    scene.add(mesh);
  }
}

变量z似乎为空。我在策划中犯的错误是什么?

1 个答案:

答案 0 :(得分:1)

我不知道抛出此异常的位置,但

x + y // in z = Math.sin(x + y);
如果x未初始化为

,则

无效

...
x = 0,
y = 0,
z = 0,
...