点击终于准了
parent
dc63189d44
commit
24ed8702a8
|
@ -10,12 +10,6 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|||
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
|
||||
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
||||
|
||||
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
|
||||
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
|
||||
import { OutlinePass } from "three/examples/jsm/postprocessing/OutlinePass.js";
|
||||
import { ShaderPass } from "three/examples/jsm/postprocessing/ShaderPass.js";
|
||||
import { FXAAShader } from "three/examples/jsm/shaders/FXAAShader.js";
|
||||
|
||||
onMounted(() => {
|
||||
init();
|
||||
loadSence();
|
||||
|
@ -68,25 +62,37 @@ const enableGroup = [
|
|||
'tanghua_room',
|
||||
'touliao_room',
|
||||
]
|
||||
const isSelent = (obj) => {
|
||||
var o = obj
|
||||
while (true) {
|
||||
if (o.name != "jzgltf" && enableGroup.indexOf(o.name) != -1) {
|
||||
return o;
|
||||
} else {
|
||||
if (o.parent.name == "jzgltf") {
|
||||
return null;
|
||||
} else {
|
||||
o = o.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mouse = new THREE.Vector2();
|
||||
let selectedObjects = ref([]);
|
||||
let selectBoxByClick, selectBoxByMouseon;
|
||||
var marginLeft = 0;
|
||||
var marginTop = 70;
|
||||
// 鼠标移动效果
|
||||
const onMouseMove = (event) => {
|
||||
var raycaster = new THREE.Raycaster()
|
||||
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
mouse.x = ((event.clientX-marginLeft) / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -((event.clientY-marginTop) / window.innerHeight) * 2 + 1;
|
||||
raycaster.setFromCamera(mouse, camera);
|
||||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||
if (intersects.length > 0) {
|
||||
const clickedObject = intersects[0].object;
|
||||
var selectedObject = clickedObject;
|
||||
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
||||
selectedObjects[0] = selectedObject
|
||||
}
|
||||
if (enableGroup.indexOf(selectedObject.parent.name) != -1) {
|
||||
selectedObjects[0] = selectedObject.parent
|
||||
}
|
||||
var selectedObject = isSelent(clickedObject);
|
||||
if (selectedObject) {
|
||||
selectedObjects[0] = selectedObject;
|
||||
if (selectBoxByMouseon) {
|
||||
scene.remove(selectBoxByMouseon);
|
||||
}
|
||||
|
@ -94,23 +100,20 @@ const onMouseMove = (event) => {
|
|||
scene.add(selectBoxByMouseon);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 鼠标点击效果
|
||||
const onMouseDown = (event) => {
|
||||
var raycaster = new THREE.Raycaster()
|
||||
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
|
||||
mouse.x = ((event.clientX-marginLeft) / window.innerWidth) * 2 - 1;
|
||||
mouse.y = -((event.clientY-marginTop) / window.innerHeight) * 2 + 1;
|
||||
raycaster.setFromCamera(mouse, camera);
|
||||
const intersects = raycaster.intersectObjects(scene.children, true);
|
||||
if (intersects.length > 0) {
|
||||
const clickedObject = intersects[0].object;
|
||||
var selectedObject = clickedObject;
|
||||
var selectedObject = isSelent(clickedObject);
|
||||
console.log(selectedObject);
|
||||
if (enableGroup.indexOf(selectedObject.name) != -1) {
|
||||
selectedObjects[0] = selectedObject
|
||||
}
|
||||
if (enableGroup.indexOf(selectedObject.parent.name) != -1) {
|
||||
selectedObjects[0] = selectedObject.parent
|
||||
}
|
||||
if (selectedObject) {
|
||||
selectedObjects[0] = selectedObject;
|
||||
if (selectBoxByClick) {
|
||||
scene.remove(selectBoxByClick);
|
||||
}
|
||||
|
@ -118,5 +121,6 @@ const onMouseDown = (event) => {
|
|||
scene.add(selectBoxByClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style scoped></style>
|
Loading…
Reference in New Issue