獲取鼠標通過地點的元素
// 獲取鼠標通過地點的元素css
intersectObjects(pointer,camera,obj) { var domElement = viewer.impl.canvas; var pointerVector = new THREE.Vector3(); var pointerDir = new THREE.Vector3(); var ray = new THREE.Raycaster(); var rect = domElement.getBoundingClientRect(); var x = ( ( pointer.clientX - rect.left ) / rect.width ) * 2 - 1; var y = - ( ( pointer.clientY - rect.top ) / rect.height ) * 2 + 1; if (camera.isPerspective) { pointerVector.set(x, y, 0.5); pointerVector.unproject(camera); ray.set(camera.position, pointerVector.sub(camera.position).normalize()); } else { pointerVector.set(x, y, -1); pointerVector.unproject(camera); pointerDir.set(0, 0, -1); ray.set(pointerVector, pointerDir.transformDirection(camera.matrixWorld)); } var intersections = ray.intersectObjects( obj, true ); return intersections[0] ? intersections[0] : false; } // 鼠標滑太小球市時觸發的事件 hoverIntersectObjects(event){ var flag =true; var pointer = event.pointers ? event.pointers[ 0 ] : event; var camera = viewer.getCamera(); var objects = viewer.impl.overlayScenes.lable.scene.children; var obj = viewer.vmethods.intersectObjects(pointer,camera,objects).object; if(obj){ //隱藏不可選 if(!obj.visible)return; if(this.oldObj) this.oldObj.material.color.setHex( this.oldObj.currentHex ); this.oldObj=obj; this.oldObj.currentHex = obj.material.color.getHex(); this.oldObj.material.color.setHex( 0x660000); viewer.impl.invalidate(false, false, true); var pos=viewer.worldToClient(this.oldObj.position); var posX=pos.x-$(".k-tooltip").width()/2; var posY=pos.y-$(".k-tooltip").height()-20; $(".k-tooltip").css({"left":posX,"top":posY}); $(".k-tooltip").show(); $(".k-tooltip .name").text(this.oldObj.name); }else{ if(this.oldObj) { this.oldObj.material.color.setHex( this.oldObj.currentHex ); viewer.impl.invalidate(false, false, true) $(".k-tooltip").hide(); } } }