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