自定义网格[z = sin(x+y) plot]不出现。

时间:2021-01-08 01:20:58
Breaking on exception: The null object does not have a method '+'.

I get the above error when I run the following function (that does the plot calculations and drawing):

当我运行下面的函数(做绘图计算)时,会得到上面的错误:

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);
  }
}

The variable z appears to be null. What are the mistakes that I am making with the plotting?

变量z看起来是空的。我在情节设计中犯的错误是什么?

1 个解决方案

#1


1  

I don't know where this exception is thrown but

我不知道这个异常是在哪里抛出的

x + y // in z = Math.sin(x + y);

can't work if x isn't initialized like

如果x不是初始化为

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

#1


1  

I don't know where this exception is thrown but

我不知道这个异常是在哪里抛出的

x + y // in z = Math.sin(x + y);

can't work if x isn't initialized like

如果x不是初始化为

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