如何解决我想在three.js的以下部分中获取“ intersect.point.y”的值
以下功能是在滑块移动时获取分频器值。 滑块移动时,“ intersect.point.x”值正确更改,但“ intersect.point.y”值未更改。 滑块移动时如何设置是否获得正确的“ intersect.point.y”值?
onMouseMove(事件){
if (Math.abs(event.offsetX - this._dividerCanvasCoord()) < TopRightView.DIVIDER_THRESHOLD) {
this.container.style.cursor = "ew-resize"
} else {
this.container.style.cursor = "auto"
}
if (this.dividerMoving) {
let snapThreshold = 0.5
var intersect = this.hitObject(event,[this.plane.children[0]])
// console.log(intersect.point.x,this.divider,"111111111")
this.divider = !!intersect ? intersect.point.x : this.divider
console.log(intersect.point.x,intersect.point.y);
this.plane.children[0].material.uniforms.hidden.value = false
if (this.divider < snapThreshold - this.planeWidth / 2 && this.snappable) {
this.divider = -this.planeWidth / 2
this.plane.children[0].material.uniforms.hidden.value = true
} else if (this.divider > -snapThreshold + this.planeWidth / 2 && this.snappable) {
this.divider = this.planeWidth / 2
this.plane.children[0].material.uniforms.hidden.value = true
}
this.plane.children[0].material.uniforms.divider.value = this.divider
if (
this.divider > snapThreshold - this.planeWidth / 2 &&
this.divider < -snapThreshold + this.planeWidth / 2
) {
this.snappable = true
}
}
}
hitObject(event,objects) {
// console.log(event.offsetX,event.offsetY)
this.raycaster.setFromCamera(
new THREE.Vector2(
(event.offsetX / this.width) * 2 - 1,-(event.offsetY / this.height) * 2 + 1
),this.camera
);
return this.raycaster.intersectObjects(objects,true)[0];
}
async init(){
this.renderer = new THREE.WebGLRenderer({ antialias: true,alpha: true });
this.renderer.setSize(this.width,this.height);
this.container.appendChild(this.renderer.domElement);
this.renderer.setClearColor(param.BACK_COLORS[this.id],0);
this.camera = new THREE.OrthographicCamera(
param.orthoWidth / (-2),param.orthoWidth / 2,param.orthoHeight / 2,param.orthoHeight / (-2),0.05,1000
);
this.camera.position.fromArray(param.CAMERA_POSITIONS[this.id]);
this.scene = new THREE.Scene();
this.scene.background = new THREE.Color(param.BACK_COLORS[this.id]);
this.scene.add(new THREE.AmbientLight(0xffffff,1.0));
this.controls = new THREE.OrbitControls(this.camera,this.renderer.domElement);
this.controls.screenSpacePanning = true;
this.controls.enableRotate = false;
this.raycaster = new THREE.Raycaster();
await this._initMeshes();
this._calibrateCamera();
this.animate();
this.container.addEventListener('mousemove',(event) => { this.onMouseMove(event) },false);
this.container.addEventListener('mousedown',(event) => { this.onMouseDown(event) },false);
this.container.addEventListener('mouseup',(event) => { this.onMouseUp(event) },false);
this.container.addEventListener('mouseout',false);
this.renderer.domElement.addEventListener(
'wheel',(event) => { this.onWheel(event) },false
);
// this.controls.addEventListener('end',() => { console.log(">>> end") });
}
_calibrateCamera() {
this.camera.left = -this.planeWidth / 2;
this.camera.right = this.planeWidth / 2;
this.camera.top = this.planeWidth / 2 * this.height / this.width;
this.camera.bottom = -this.camera.top;
let offsets = [param.CAMERA_OFFSETS[this.id].x,param.CAMERA_OFFSETS[this.id].z];
[...param.PLANE_AXES[this.id]].forEach((a,i) => {
this.camera.position[a] = offsets[i];
this.controls.target[a] = offsets[i];
});
this.camera.updateProjectionMatrix();
this.controls.saveState();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。