wangqiujuan0808 2023-12-15 09:22:39 +08:00
parent 6afd75b70b
commit 2b7ca3ce54
2 changed files with 141546 additions and 71 deletions

141444
public/jzc/scene3.gltf Normal file

File diff suppressed because one or more lines are too long

View File

@ -34,10 +34,12 @@ onMounted(() => {
init();
loadSence();
renderScene();
document.addEventListener("click", onMouseDown);
//
document.addEventListener('click', onMouseDown);
// document.addEventListener("mousemove", onMouseMove);
});
let scene, renderer, camera, controls, pointsArr = true;
let biggerSphereMesh = null;
let i = 1;
let mouse = new THREE.Vector2();
let labelRenderer = new CSS2DRenderer(); //CSS2DRenderer
@ -59,6 +61,7 @@ Bus.on('clickBuild', (isParent) => {
//
// nearCamera(Floor);
boxLight(Floor);
return;
}
@ -105,7 +108,7 @@ const loadSence = () => {
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('/draco/gltf/')//
gltfLoader.setDRACOLoader(dracoLoader)
gltfLoader.load('/jzc/scene2.gltf', (gltf) => {
gltfLoader.load('/jzc/scene3.gltf', (gltf) => {
var model = gltf.scene;
// console.log(roamdObjects);
roamdObjects = model.children[0].children;
@ -189,19 +192,36 @@ const onMouseMove = (event) => {
}
//
const onMouseDown = (event) => {
var raycaster = new THREE.Raycaster()
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);
var vector = new THREE.Vector3();//
vector.set(
(event.clientX / window.innerWidth) * 2 - 1,
- (event.clientY / window.innerHeight) * 2 + 1,
0.5);
vector.unproject(camera);
var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
var intersects = raycaster.intersectObjects(scene.children);
if (intersects.length > 0) {
const clickedObject = intersects[0].object;
var selectedObject = isSelent(clickedObject);
console.log(123, selectedObject);
boxLight(selectedObject);
// nearCamera(selectedObject)
var selected = intersects[0];//
console.log("x坐标:" + selected.point.x);
console.log("y坐标:" + selected.point.y);
console.log("z坐标:" + selected.point.z);
}
// var raycaster = new THREE.Raycaster()
// 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);
// console.log(123, event);
// if (intersects.length > 0) {
// const clickedObject = intersects[0].object;
// console.log('', clickedObject);
// var selectedObject = isSelent(clickedObject);
// //
// boxLight(selectedObject);
// }
}
const boxLight = (selectedObject) => {
@ -246,47 +266,75 @@ const centerSelectedGroup = (obj) => {
//
const roam = () => {
//
controls.enableDamping = false; //
controls.dampingFactor = 0.05; // 0 1 default = 0.25
controls.screenSpacePanning = false; // 使default = false
controls.minDistance = 100;
controls.maxDistance = 200;
controls.maxPolarAngle = Math.PI / 2; // atorbit
//
controls.enablePan = false; // pan
controls.enableKeys = true;
controls.keyPanSpeed = 30; // 7 WSAD
controls.enableZoom = false; //
controls.keyRotateSpeed = 90; // 30QE
controls.spaceingFactor = 0.4; //0.4
//
const path = new THREE.CatmullRomCurve3([
new THREE.Vector3(-50, 20, 90), //
new THREE.Vector3(-10, 40, 40), //
new THREE.Vector3(0, 0, 0), //
new THREE.Vector3(60, -60, 0), //
new THREE.Vector3(90, -40, 60), //
new THREE.Vector3(120, 30, 30), //
// //
// new THREE.Vector3(-10, 0, 10),
// //
// new THREE.Vector3(-5,10,-10),
// new THREE.Vector3(2, 5, -5),
// //
// new THREE.Vector3(10, 0, 10),
new THREE.Vector3(130.076658411178222, 58.489999368786826, -32.514521795452985), //
new THREE.Vector3(128.938067229663826, 55.0220540878815, 30.184599697589874) //
]);
pointsArr = path.getSpacedPoints(500);
// console.log(pointsArr);
i = 100;
d(path)
pointsArr = path.getSpacedPoints(50);
i = 0;
console.log(pointsArr[i]);
// 线pointsArr[i]
camera.position.copy(pointsArr[i]);
// pointsArr[i + 1]
camera.lookAt(pointsArr[i + 1]);
renders();
// controls.target.copy(pointsArr[i+1])
setTimeout(() => {
renders();
}, 1000);
}
let num = 0;
function d(cameraCurve) {
let sphereCurve = null;
//100
//0.6
sphereCurve = cameraCurve.clone()
sphereCurve.points.forEach(point => {
point.x *= 0.6
point.y *= 0.2
point.z *= 0.6
return point
})
//100
const pathPoints = sphereCurve.getPoints(100)
pathPoints.forEach(point => {
const sphere = new THREE.SphereGeometry(0.2)
const sphereMaterial = new THREE.MeshBasicMaterial({
color: 0x0000ff
})
const sphereMesh = new THREE.Mesh(sphere, sphereMaterial)
sphereMesh.position.set(point.x, point.y, point.z)
scene.add(sphereMesh)
})
//线
const geometry = new THREE.BufferGeometry().setFromPoints(pathPoints)
const material = new THREE.LineBasicMaterial({
color: 0xff0000
})
const curveObject = new THREE.Line(geometry, material)
scene.add(curveObject)
//绿沿
const biggerSphere = new THREE.SphereGeometry(2)
const sphereMaterial1 = new THREE.MeshBasicMaterial({ color: 0x0ff00 })
biggerSphereMesh = new THREE.Mesh(biggerSphere, sphereMaterial1)
biggerSphereMesh.position.set(
pathPoints[0].x,
pathPoints[0].y,
pathPoints[0].z
)
scene.add(biggerSphereMesh)
}
let num = 1;
const renders = () => {
/* angle += 0.01;
// yXOZ
@ -295,14 +343,21 @@ const renders = () => {
if (num < pointsArr.length - 1) {
//
camera.position.copy(pointsArr[num]);
// camera.position.set(pointsArr[num]);
// 线pointsArr[num]pointsArr[num+1]线线
// 线线线
camera.lookAt(pointsArr[num + 1]);
biggerSphereMesh.position.copy(pointsArr[num]
)
// controls.target.copy(pointsArr[num+1])
num += 1; //
requestAnimationFrame(renders);
controls.update();
} else {
num = 0
}
requestAnimationFrame(renders);
};
let roamdObjects = ref([]);
@ -404,30 +459,6 @@ const removeLabel = () => {
display: flex;
flex-direction: column;
&::before {
// content: "";
// display: inline-block;
// width: 0;
// height: 0;
// border: 12px solid transparent;
// border-right-color: #ffffffb3;
// position: absolute;
// left: -23px;
// top: 0;
}
.arrow_outer {
// position: absolute;
// left: -22px;
// top: 6px;
// margin: 0;
// width: 12px;
// height: 12px;
// background-color: #eb6852;
// border-radius: 100%;
// border: 1px solid #fff;
}
span {
line-height: 24px;
}