[英]Creating a new object in three.js
我目前正在开发一个涉及基于数据库在Threejs中制作3D对象的项目。
我已经有了连接等,但是当我尝试创建一个新对象时它仍然失败。
this.type = 'CustomObject';
let shape = new THREE.Shape();
const maxSize = coords.reduce((prev, current) => (Math.abs(prev.value) > Math.abs(current.value)) ? prev : current); // max Size but Abs
// console.log("Max size before check : "+ maxSize.value);
//Check weither maxSize is positive or negative.
let height = Math.abs(maxSize.value);
shape.moveTo(0, 0);
for (let i = 0; i < coords.length; i++) {
// console.log(coords[i]);
shape.lineTo(coords[i].id, coords[i].value);
}
shape.lineTo(coords[coords.length - 1].id, -height - 3);
shape.lineTo(0, -height - 3);
shape.lineTo(0, 0);
// let geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
let extrudeSettings = {
steps: 4,
amount: 20,
bevelEnabled: false,
bevelThickness: 1,
bevelSize: 1,
bevelSegments: 1
};
this.geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
this.material = new THREE.MeshBasicMaterial({color: 0xCbcbcb});
let object = new THREE.Mesh( this.geometry, this.material );
this.createdGraph = object;
console.log(this.createdGraph.Object3D);
this.scene.add(this.createdGraph);
}
这只是代码的一部分,我知道它不是最好的。 但是我想在清理它之前先做它。 它是在考虑ES6的情况下编写的。
问题是,如果你执行代码,它确实创建了我想要的数字。
但是如果我尝试将它添加到A-Frame(因为我之前已经使用它),它会不断给我一个错误,我不能在没有Object3D的情况下向场景添加一个对象,或者'this.updateMorphTargets不是功能'。
有人有想法么 ?
PS我也试过这个https://stackoverflow.com/a/31924233的想法,但是回来的'this.updateMorphTargets不是函数'错误。
谢谢 :)
我不确定哪些部分会给你错误,
我已经将你的代码复制到一个小提琴中,添加了3个coords,它正在工作 。
从你的代码判断,你有一个糟糕的场景引用,在它的框架中
this.el.sceneEl
假设this
是任何实体,并且this.scene
不引用场景。
此外,将three.js对象称为object3D
,而不是Object3D
<a-entity foo> </a-entity>
并放置一个实体:
<a-entity foo> </a-entity>
this.el.sceneEl.object3D.add(object)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.