【发布时间】:2018-03-26 11:07:24
【问题描述】:
我目前正在开展一个项目,该项目涉及基于数据库在 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 is not a function”错误。
谢谢:)
【问题讨论】:
标签: javascript three.js aframe