Three.js|Three.js 新旧版本创建几何对象差异
昨天遇到个小问题,也搞了挺长时间:用Three.js在webgl中绘制三维对象,从网上抄的一段代码,运行报错:
THREE.Geometry is not a constructor
【Three.js|Three.js 新旧版本创建几何对象差异】纳尼,找不到Geometry对象?
function createLine(){
let start = new THREE.Vector3(7, 1.8, -2);
let end = new THREE.Vector3(1.6,1.8, -2);
// 就是这里创建的对象找不到 *****
let geometry = new THREE.Geometry();
// ****************************let lineMaterial = new THREE.LineBasicMaterial({color: 0x00ff00});
geometry.vertices.push(start);
geometry.vertices.push(end);
let line = new THREE.Line(lineGeometry, lineMaterial);
scene.add(line);
return line;
}
一开始还以为是模块导入问题,折腾了一阵才发现,THREE模块中竟然真的就没有Geometry!难道网上的代码是愚人节贴的?遇事不决问google,终于确认人家是升级了。新版的Three.js不再提供Geometry对象,代之以BufferGeometry,代码修改如下:
function createLine(){
let start = new THREE.Vector3(7, 1.8, -2);
let end = new THREE.Vector3(1.6,1.8, -2);
let lineMaterial = new THREE.LineBasicMaterial({color: 0x00ff00});
let pointsArray = [start, end];
let lineGeometry = new THREE.BufferGeometry().setFromPoints(pointsArray);
let line = new THREE.Line(lineGeometry, lineMaterial);
scene.add(line);
return line;
}
推荐阅读
- 【Hadoop踩雷】Mac下安装Hadoop3以及Java版本问题
- C语言的版本比较
- [源码解析]|[源码解析] NVIDIA HugeCTR,GPU版本参数服务器---(3)
- K8S|K8S 生态周报| Istio 即将发布重大安全更新,多个版本受影响
- Caffe在Windows10下CPU版本的安装(cpu+anaconda3+vs2013+pycaffe)
- 中单直通王者(三)(英雄池要跟上版本,选将放机灵点,听到没!)
- Centos6源码编译安装2.4版本http服务步骤
- C语言静态动态两版本通讯录实战源码
- 命令行上传小程序版本至微信后台
- 170824共读024-【你的新旧知识体系打通了吗】