创建三点返回无法将未定义或null转换为对象

时间:2019-07-19 14:32:33

标签: javascript three.js

这是代码的一部分。我在两个返回值上测试了geometrymaterial变量。删除这些变量,错误消失。

var actionZ = 0;
var rotationA = 1.1;
var movementSpeed = 1;
var totalObjects = 40000;
var rotated = false;
var container = document.createElement('div');
    container.className = 'home-background';
document.body.appendChild( container );

var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight,1, 2000)
camera.position.z = 2000;

var scene = new THREE.Scene();
scene.add(camera);
scene.fog = new THREE.FogExp2( 0x00b4f1, 0.0003 );
var geometry = new THREE.Geometry();
var i = 0;
for (i = 0; i < totalObjects; i ++) {
  var vertex = new THREE.Vector3();
  vertex.x = Math.random()*40000-20000;
  vertex.y = Math.random()*7000-3500;
  vertex.z = Math.random()*7000-3500;
  geometry.vertices.push( vertex );
}

var material = new THREE.PointsMaterial( { size: 3, color: 0x00b4f1});
var particles = new THREE.Points( geometry, material );

1 个答案:

答案 0 :(得分:1)

使用R106创建THREE.Points时,THREE.Geometry中当前存在错误。您可以使用THREE.BufferGeometry或最新的dev版本来避免此问题。 R107将于7月底发布。这是解决此问题的相关PR:

https://github.com/mrdoob/three.js/pull/16932