Creating THREE.Points return Cannot convert undefined or null to object

浪尽此生 提交于 2019-12-13 03:49:07

问题


This is a part of the code. I tested the geometry and material variables on both return values. Removing these variables, the error disappear.

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:


There is currently a bug in R106 when creating THREE.Points with THREE.Geometry. You can avoid the issue by using THREE.BufferGeometry or by using the latest dev version. R107 will be released at the end of July. Here is the related PR that fixed the issue:

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



来源:https://stackoverflow.com/questions/57114631/creating-three-points-return-cannot-convert-undefined-or-null-to-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!