javascript - × TypeError: Cannot read property 'center' of undefined from three.module.js
问题描述
我已经编写了几个月的代码,并尝试了解更多有关three.js/react 的内容。我目前正在学习 [https://redstapler.co/three-js-realistic-rain-tutorial/] 的教程,我正在创建一个逼真的雨背景。教程很棒,到目前为止一切都很好,直到我开始实施下雨。
在教程中,他使用
rainGeo = new THREE.Geometry();
for(let i=0;i<rainCount;i++) {
rainDrop = new THREE.Vector3(
Math.random() * 400 -200,
Math.random() * 500 - 250,
Math.random() * 400 - 200
);
rainDrop.velocity = {};
rainDrop.velocity = 0;
rainGeo.vertices.push(rainDrop);
}
rainMaterial = new THREE.PointsMaterial({
color: 0xaaaaaa,
size: 0.1,
transparent: true
});
rain = new THREE.Points(rainGeo,rainMaterial);
scene.add(rain);
我只是不知道从这里去哪里。我目前拥有的是:
this.rainCount = 15000
this.rainGeo = []
this.geoR = new THREE.BufferGeometry();
for( let i=0; i< this.rainCount; i++) {
this.rainGeo.push(
new THREE.Vector3(
Math.random() * 400 - 200,
Math.random() * 400 - 250,
Math.random() * 400 - 200
)
)
};
this.rainMaterial = new THREE.PointsMaterial({
color: 0xaaaaaa,
size: 0.1,
transparent: true
})
this.rain = new THREE.Points(this.rainGeo, this.rainMaterial);
this.scene.add(this.rain)
`
`
解决方案
现在,您正在创建一个sTHREE.Points
数组Vector3
作为第一个参数的实例。这是错误的,因为需要一个实例BufferGeometry
。尝试这个:
const count = 15000;
const points = [];
for(let i=0; i< count; i++) {
points.push(
new THREE.Vector3(
Math.random() * 400 - 200,
Math.random() * 400 - 250,
Math.random() * 400 - 200
)
)
};
this.geoR = new THREE.BufferGeometry().setFromPoints(points);
this.rainMaterial = new THREE.PointsMaterial({
color: 0xaaaaaa,
size: 0.1,
transparent: true
});
this.rain = new THREE.Points(this.geoR, this.rainMaterial);
this.scene.add(this.rain)
推荐阅读
- c - 当动态加载的多个 DLL 具有相同名称的函数时可以吗?
- node.js - ssh 没有这样的文件或目录
- ios - 检查构建 SDK 版本
- azure-devops - 为什么 System.JobId 有时不是唯一的?
- rust - 一个RefCell的元素可以吗
> 存储在结构中修改同一 Vec 中另一个元素的值? - javascript - DOM 改变不更新点击事件
- sql - 如何从 oracle sql 中的帐户列中删除前 3 个和后 5 个字符?
- python - 有没有办法在 Spyder 中释放已使用的内存?
- javascript - 如何让 Python 在打开的 chrome 选项卡上运行 JavaScript?
- r - 将网站表转换为数据框的 R 函数