wangqiujuan0808 2023-12-10 20:15:56 +08:00
parent 59bbb8358c
commit 07189fa6a7
4 changed files with 130 additions and 152 deletions

View File

@ -42,7 +42,8 @@
"vue": "3.2.45",
"vue-cropper": "1.0.3",
"vue-router": "4.1.4",
"mitt": "^3.0.1"
"mitt": "^3.0.1",
"gsap": "^3.11.3"
},
"devDependencies": {
"@vitejs/plugin-vue": "3.1.0",

BIN
public/jz/glb/scene.glb Normal file

Binary file not shown.

View File

@ -1392,7 +1392,7 @@
-54.6457,
1
],
"name": "4",
"name": "set3",
"extras": {
"name": "4"
},

View File

@ -37,6 +37,7 @@ import homeIcon from '@/assets/image/bg7.jpg'
import TWEEN from "@tweenjs/tween.js";
import Bus from '@/utils/bus.js'
import bimStore from '@/store/modules/bim';
import gsap from "gsap";
let scene = ref(null);
let renderer = ref(null);
@ -50,6 +51,7 @@ let labelRenderer = new CSS2DRenderer(); //新建CSS2DRenderer
let positionObj = ref(null);
//
let selectedObjects = ref([]);
let curve = ref(null);
const props = defineProps({
background: { //
@ -94,10 +96,12 @@ Bus.on('clickBuild', (isParent) => {
// })
//
outlineObj([Floor]);
//
nearCamera(Floor);
return;
}
//
toHomeView();
// toHomeView();
})
//
Bus.on('clickDevice', (isParent) => {
@ -107,10 +111,12 @@ Bus.on('clickDevice', (isParent) => {
console.log(1, Floor);
//
outlineObj([Floor])
//
// nearCamera(Floor);
return;
}
//
toHomeView();
// toHomeView();
})
//
@ -124,65 +130,11 @@ onMounted(() => {
loadSence();
//
renderScene();
document.addEventListener("click", onMouseDown);
// document.addEventListener("click", onMouseDown);
document.addEventListener("mousemove", onMouseDown);
});
const setLabel = () => {
if(isAddLabel.value) {
addLabel();
} else {
removeLabel();
}
isAddLabel.value = !isAddLabel.value;
}
const removeLabel = () => {
document.body.removeChild(labelRenderer.domElement);
}
//
const addLabel = () => {
let obj = gltfObj.value.scene.getObjectByName('set2');
let text = "设备二";
let pointLabel = createLableObj(text);
obj.add(pointLabel);
labelRenderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.domElement.style.position = "absolute";
labelRenderer.domElement.style.top = 0;
labelRenderer.domElement.style.pointerEvents = 'none';//
document.body.appendChild(labelRenderer.domElement);
// HTML
document.getElementById("dom").appendChild(renderer.domElement);
};
const createLableObj = (text) => {
let laberDiv = document.createElement("div"); //div
laberDiv.className = "laber_name";
laberDiv.innerHTML = `<div class="arrow_outer"></div><span>设备名称:${text}</span><span>状态:启用</span><span>压力50 Pa</span>`
let pointLabel = new CSS2DObject(laberDiv);
return pointLabel;
};
//
const cleanColor = () => {
//
if (objArr.length > 0 && objM.length > 0) {
objArr.forEach((ele, index) => {
console.log(objM[index]);
ele.material = objM[index]
})
objArr = [];
objM = [];
}
gltfObj.value.scene.traverse(e => {
objArr.push(e);
objM.push(e.material);
})
}
const init = () => {
//
// scene = new THREE.Scene("#00ffff");
// const texture = new THREE.TextureLoader().load(homeIcon);
// texture.mapping = THREE.EquirectangularReflectionMapping;
@ -190,46 +142,44 @@ const init = () => {
// scene.environment = texture
scene = new THREE.Scene();
console.log(123, props.background);
scene.background = new THREE.Color(props.background);
const canvas = document.querySelector("#three");
var cubeLoader = new THREE.CubeTextureLoader();
// WebGLRenderer使
renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true, preserveDrawingBuffer: true });
//
renderer.toneMappingExposure = 2;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
//
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.25, 2000)
//
camera.position.set(-92.936, 180.990, -28.179);
camera.lookAt(scene.position);
//
// controls
orbit = new OrbitControls(camera, renderer.domElement);
orbit.autoRotate = true;
setTimeout(function () {
orbit.autoRotate = false;
}, 7000);
// renderer.setClearColor(new THREE.Color("#0e0934"));
orbit.maxPolarAngle = Math.PI / 2.1;
orbit.maxDistance = 12;
renderer.setSize(window.innerWidth, window.innerHeight);
// 0x4444440x888888,threejs
// intensity 0.5
var alight = new THREE.AmbientLight(props.light, 1);
alight.name = "aLight";
scene.add(alight);
};
// 线
makeCurve();
};
//
const loadSence = () => {
const gltfLoader = new GLTFLoader();
gltfLoader.load(props.sceneUrl, (gltf) => {
// model.value = gltf.scene;
gltfObj.value = gltf;
var model = gltf.scene;
scene.add(model);
});
};
//
const renderScene = () => {
// orbit.update(); //
// 使requestAnimationFrame
@ -242,40 +192,46 @@ const renderScene = () => {
}
};
//
const initTween = (targetX, targetY, targetZ) => {
let initPosition = {
x: camera.position.x,
y: camera.position.y,
z: camera.position.z,
};
let tween = new TWEEN.Tween(initPosition)
.to({ x: targetX, y: targetY, z: targetZ }, 2000)
.easing(TWEEN.Easing.Sinusoidal.InOut);
let onUpdate = (pos) => {
let x = pos.x;
let y = pos.y;
let z = pos.z;
if (pos.z < 0) {
camera.position.set(x, y, z - 12);
} else {
camera.position.set(x, y, z + 12);
const makeCurve = () => {
curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(11.5, 0, 18),
new THREE.Vector3(11.5, 0, 34),
new THREE.Vector3(35, 0, 34),
new THREE.Vector3(35, 0, 31),
new THREE.Vector3(11.5, 0, 31),
]);
// 线Helper
const points = curve.getPoints(0.1);
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: 0xff0000,
});
// 线
const line = new THREE.Line(geometry, material);
scene.add(line)
}
};
tween.onUpdate(onUpdate);
tween.start();
if (positionObj.z < 0) {
orbit.target.set(
positionObj.x,
positionObj.y - 0.4,
-12
);
} else {
orbit.target.set(
positionObj.x,
positionObj.y - 0.4,
12
);
const changePosition = (t) => {
const position = curve.getPointAt(t); // t: 线
mesh.position.copy(position);
}
const changeLookAt = (t) => {
const tangent = curve.getTangentAt(t);
const lookAtVec = tangent.add(mesh.position); // 线
mesh.lookAt(lookAtVec);
}
const loopTime = 10 * 1000; // loopTime:
const walk = () => {
let time = Date.now();
setInterval(() => {
let t = (time % loopTime) / loopTime; //
changePosition(t);
changeLookAt(t);
}, 1000)
}
//
@ -360,54 +316,75 @@ const outlineObj = (selectedObject_list) => {
composer.addPass(effectFXAA)
}
const nearCamera = (intersects) => {
console.log(5555, intersects)
//
if (!intersects[0]) {
return;
} else {
if (intersects[0].object.name) {
selectedObjects = [];
selectedObjects.push(intersects[0].object);
positionObj = {
x: intersects[0].object.position.x,
y: intersects[0].object.position.y,
z: intersects[0].object.position.z,
};
const nearCamera = (floor) => {
orbit.reset();
gsap.to(camera.position, {
x: floor.position.x - 40,
y: floor.position.y + 60,
z: floor.position.z,
duration: 2,
ease: "power1.inOut",
onComplete: () => {
},
});
initTween(
positionObj.x,
positionObj.y,
positionObj.z + 10
);
}
}
}
const toHomeView = () => {
camera.position.set(-92.936, 180.990, -28.179);
camera.lookAt(scene.position);
// cleanColor();
orbit.reset();
outlineObj([]);
}
//
const toHomeView1 = () => {
let initPosition = {
x: camera.position.x,
y: camera.position.y,
z: camera.position.z,
const setLabel = () => {
if(isAddLabel.value) {
addLabel();
} else {
removeLabel();
}
isAddLabel.value = !isAddLabel.value;
}
const removeLabel = () => {
document.body.removeChild(labelRenderer.domElement);
}
//
const addLabel = () => {
let obj = gltfObj.value.scene.getObjectByName('set2');
let text = "设备二";
let pointLabel = createLableObj(text);
obj.add(pointLabel);
labelRenderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.domElement.style.position = "absolute";
labelRenderer.domElement.style.top = 0;
labelRenderer.domElement.style.pointerEvents = 'none';//
document.body.appendChild(labelRenderer.domElement);
// HTML
document.getElementById("dom").appendChild(renderer.domElement);
};
let tween = new TWEEN.Tween(initPosition)
.to({ x: 0, y: -(5 * 24) / 12, z: (6 * 100) / 5 }, 2000)
.easing(TWEEN.Easing.Sinusoidal.InOut);
let onUpdate = (pos) => {
let x = pos.x;
let y = pos.y;
let z = pos.z;
camera.position.set(x, y, z);
const createLableObj = (text) => {
let laberDiv = document.createElement("div"); //div
laberDiv.className = "laber_name";
laberDiv.innerHTML = `<div class="arrow_outer"></div><span>设备名称:${text}</span><span>状态:启用</span><span>压力50 Pa</span>`
let pointLabel = new CSS2DObject(laberDiv);
return pointLabel;
};
tween.onUpdate(onUpdate);
tween.start();
orbit.target.set(0, 0, 0);
//
const cleanColor = () => {
//
if (objArr.length > 0 && objM.length > 0) {
objArr.forEach((ele, index) => {
console.log(objM[index]);
ele.material = objM[index]
})
objArr = [];
objM = [];
}
gltfObj.value.scene.traverse(e => {
objArr.push(e);
objM.push(e.material);
})
}
</script>
<style lang='scss'>