我目前正在处理一个涉及使用 Threejs 制作基于数据库的 3D 对象的项目。
我已经完成了连接等工作,但在尝试创建新对象时却一直失败。
这只是代码的一部分,我知道它不是最好的。但我希望在清理代码之前让它工作起来。 它是以ES6为基础编写的。
问题是,如果你执行该代码,它确实会创建我想要的图形。
代码创建的对象截图。
但是,如果我尝试将其添加到A-Frame中(因为我曾经使用过它),它始终给出错误,提示无法将没有Object3D的对象添加到场景或'this.updateMorphTargets不是函数'。
有人有任何想法吗?
PS:我也尝试了这个https://dev59.com/jo3da4cB1Zd3GeqP6u4q#31924233的方法,但返回“this.updateMorphTargets不是函数”的错误。
谢谢 :)
我已经完成了连接等工作,但在尝试创建新对象时却一直失败。
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 screengrab of the object created by the code.](https://istack.dev59.com/wXkfg.webp)
有人有任何想法吗?
PS:我也尝试了这个https://dev59.com/jo3da4cB1Zd3GeqP6u4q#31924233的方法,但返回“this.updateMorphTargets不是函数”的错误。
谢谢 :)