创建 THREE.Points 返回无法将 undefined 或 null 转换为对象 [英] Creating THREE.Points return Cannot convert undefined or null to object

查看:57
本文介绍了创建 THREE.Points 返回无法将 undefined 或 null 转换为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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

这篇关于创建 THREE.Points 返回无法将 undefined 或 null 转换为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆