0
Design.prototype.get3dPointZAxis = function(event) {
var mouseX = event.clientX - this.container.getClientRects()[0].left;
var mouseY = event.clientY - this.container.getClientRects()[0].top;
var vector = new THREE.Vector3((mouseX/this.container.offsetWidth) * 2 - 1, mouseY /this.container.offsetHeight) * 2 + 1, 0.5);
this.projector.unprojectVector(vector, this.camera);
var dir = vector.sub(this.camera.position).normalize();
var distance = - this.camera.position.z/dir.z;
var pos = this.camera.position.clone().add(dir.multiplyScalar(distance));
return pos;
};如何將運行時繪製的二維線(例如如何在Microsoft繪製中繪製)轉換爲使用Three.js的三維矩形?
Design.prototype.stopDraw= function(event) {
this.twoDLine.push(this.tempLine.geometry);
this.tempLine = null;
this.lastPoint = null;
};
Design.prototype.startDraw= function(event) {
this.lastPoint = this.get3dPointZAxis(event);
};
Design.prototype.handleMouseMove = function(event) {
if (this.lastPoint) {
var pos = this.get3dPointZAxis(event);
if (!this.tempLine) {
var material = new THREE.LineBasicMaterial({
color: 0x0089ff
});
var geometry = new THREE.Geometry();
geometry.vertices.push(this.lastPoint);
geometry.vertices.push(pos);
this.tempLine = new THREE.Line(geometry, material);
this.scene.add(this.tempLine);
}
else {
this.tempLine.geometry.verticesNeedUpdate = true;
this.tempLine.geometry.vertices[1] = pos;
}
}
};
我正在使用鼠標事件在容器內繪製2D線條和形狀。我需要將這些線條和形狀轉換爲3D。我正在嘗試以下技術......但沒有結果。請請幫忙!
Design.prototype.convertTo3D = function() {
console.log("convertTo3D");
this.tempLine.geometry.vertices.z = 10;
};
我已經將2D行存儲在數組行TARarw []中。在事件觸發器上,創建的線將消失,並將被一個長方體替換爲與2D線相同的方向和相同的位置 – user3359133