From 61e30cbd7d5548ba4c94e105319c8bff878f88db Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期四, 28 三月 2024 08:56:45 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/pages/map/drawer/shelf/shelfThree.js | 208 +++++++++++++++++++++++++---------------------------
1 files changed, 100 insertions(+), 108 deletions(-)
diff --git a/zy-asrs-flow/src/pages/map/drawer/shelf/shelfThree.js b/zy-asrs-flow/src/pages/map/drawer/shelf/shelfThree.js
index b3f856f..4de41d5 100644
--- a/zy-asrs-flow/src/pages/map/drawer/shelf/shelfThree.js
+++ b/zy-asrs-flow/src/pages/map/drawer/shelf/shelfThree.js
@@ -5,8 +5,8 @@
const help = false;
const debugCamera = {
- x: 100,
- y: 300,
+ x: 200,
+ y: 200,
z: 200
}
@@ -14,21 +14,18 @@
constructor(dom) {
const { current: container } = dom;
- this.scene = initScene();
- this.camera = initCamera(this.scene);
- this.renderer = initRenderer(container);
- this.controls = initControls(this.camera, this.renderer);
- windowResize(this.camera, this.renderer);
+ this.fullWidth = container.offsetWidth;
+ this.fullHeight = container.offsetHeight;
+ this.scene = this.initScene();
+ this.camera = this.initCamera();
+ this.renderer = this.initRenderer(container);
+ this.controls = this.initControls();
+ this.stats = this.initStats(container);
+ this.windowResize();
+ this.initRaycaster(container);
initLight(this.scene);
- this.stats = initStats(container);
-
this.objects = [];
- this.agvList = [];
- this.agvDataList = [];
- this.conveyorDataList = [];
-
- this.initRaycaster(container, this.camera, this.objects);
}
startup = () => {
@@ -56,12 +53,75 @@
this.objects.push(object);
}
- build = () => {
- // 1.build floor
- buildFloor(this.scene);
+ initScene = () => {
+ const scene = new THREE.Scene();
+ // scene.background = new THREE.Color(0xf0f0f0);
+ // scene.background = new THREE.Color(0x333333);
+ if (help) {
+ scene.add(new THREE.AxesHelper(1000));
+ }
+ return scene;
}
- initRaycaster = (container, camera, objects) => {
+ initCamera = () => {
+ const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 10000);
+ camera.position.set(debugCamera.x, debugCamera.y, debugCamera.z);
+ this.scene.add(camera);
+ return camera;
+ }
+
+ initRenderer = (container) => {
+ const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
+ renderer.setClearAlpha(0);
+ // renderer.useLegacyLights = false; // 鏃х増鍏夋簮 閲嶈
+ renderer.shadowMap.enabled = true;
+ // this.renderer.shadowMap.type = THREE.BasicShadowMap; // 鏈�浣庨槾褰�
+ // this.renderer.toneMapping = THREE.ReinhardToneMapping;
+ renderer.toneMapping = THREE.ACESFilmicToneMapping;
+ renderer.setPixelRatio(window.devicePixelRatio);
+ renderer.setSize(300, 500);
+ container.appendChild(renderer.domElement);
+ return renderer;
+ }
+
+ initControls = () => {
+ const controls = new OrbitControls(this.camera, this.renderer.domElement);
+ // controls.enableRotate = false; // 绂佺敤鏁翠綋鏃嬭浆鍔熻兘
+ controls.enablePan = true; // 鍏佽骞崇Щ
+ controls.enableDamping = true; // 寮�鍚樆灏�
+ controls.dampingFactor = 0.08; // 闃诲凹鍥犲瓙
+ controls.enableZoom = true; // 鍏佽缂╂斁
+ // controls.minDistance = 1; // 鏈�灏忕缉鏀捐窛绂�
+ // controls.maxDistance = 30; // 鏈�澶х缉鏀捐窛绂�
+ controls.minPolarAngle = 0; // 鏈�灏忎刊浠拌搴︼紙鍚戜笅鐪嬶級
+ controls.maxPolarAngle = Math.PI / 2.1; // 鏈�澶т刊浠拌搴︼紙鍚戜笂鐪嬶級
+ controls.rotateSpeed = 0.6; // 瑙嗚绉诲姩閫熷害鍑忔參
+ controls.autoRotate = true; // 鑷姩鏃嬭浆
+
+ controls.target = new THREE.Vector3(0, 0, 0) // 骞虫浛 camera鐨刲ookAt
+ return controls;
+ }
+
+ initStats = (container) => {
+ const stats = new Stats();
+ container.appendChild(stats.dom);
+ if (!help) {
+ stats.domElement.style.display = 'none';
+ }
+ return stats;
+ }
+
+ windowResize = () => {
+ let that = this;
+ window.addEventListener('resize', function () {
+ that.camera.aspect = window.innerWidth / window.innerHeight;
+ that.camera.updateProjectionMatrix();
+ that.renderer.setSize(that.fullWidth, that.fullHeight);
+ }, false);
+ }
+
+ initRaycaster = (container) => {
+ let that = this;
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
@@ -80,8 +140,8 @@
event.preventDefault();
mouse.x = (x / window.innerWidth) * 2 - 1;
mouse.y = -(y / window.innerHeight) * 2 + 1;
- raycaster.setFromCamera(mouse, camera);
- let intersects = raycaster.intersectObjects(objects, true);
+ raycaster.setFromCamera(mouse, that.camera);
+ let intersects = raycaster.intersectObjects(that.objects, true);
if (intersects.length === 0) {
this.handleClick("null");
return;
@@ -100,27 +160,15 @@
}, false);
}
+ build = () => {
+ // 1.build floor
+ buildFloor(this.scene);
+ }
+
handleClick = () => {
}
};
-
-const initScene = () => {
- const scene = new THREE.Scene();
- // scene.background = new THREE.Color(0xf0f0f0);
- scene.background = new THREE.Color(0x333333);
- if (help) {
- scene.add(new THREE.AxesHelper(1000));
- }
- return scene;
-}
-
-const initCamera = (scene) => {
- const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 10000);
- camera.position.set(debugCamera.x, debugCamera.y, debugCamera.z);
- scene.add(camera);
- return camera;
-}
const initLight = (scene) => {
@@ -152,77 +200,21 @@
}
}
-const initRenderer = (container) => {
- const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
- renderer.setClearAlpha(0);
- // renderer.useLegacyLights = false; // 鏃х増鍏夋簮 閲嶈
- renderer.shadowMap.enabled = true;
- // this.renderer.shadowMap.type = THREE.BasicShadowMap; // 鏈�浣庨槾褰�
- // this.renderer.toneMapping = THREE.ReinhardToneMapping;
- renderer.toneMapping = THREE.ACESFilmicToneMapping;
- renderer.setPixelRatio(window.devicePixelRatio);
- renderer.setSize(window.innerWidth, window.innerHeight);
- container.appendChild(renderer.domElement);
- return renderer;
-}
-
-const initControls = (camera, renderer) => {
- const controls = new OrbitControls(camera, renderer.domElement);
- // controls.enableRotate = false; // 绂佺敤鏁翠綋鏃嬭浆鍔熻兘
- controls.enablePan = true; // 鍏佽骞崇Щ
- controls.enableDamping = true; // 寮�鍚樆灏�
- controls.dampingFactor = 0.08; // 闃诲凹鍥犲瓙
- controls.enableZoom = true; // 鍏佽缂╂斁
- // controls.minDistance = 1; // 鏈�灏忕缉鏀捐窛绂�
- // controls.maxDistance = 30; // 鏈�澶х缉鏀捐窛绂�
- controls.minPolarAngle = 0; // 鏈�灏忎刊浠拌搴︼紙鍚戜笅鐪嬶級
- controls.maxPolarAngle = Math.PI / 2.1; // 鏈�澶т刊浠拌搴︼紙鍚戜笂鐪嬶級
- controls.rotateSpeed = 0.6; // 瑙嗚绉诲姩閫熷害鍑忔參
- // controls.autoRotate = true; // 鑷姩鏃嬭浆
-
- controls.target = new THREE.Vector3(debugCamera.x, 0, debugCamera.z) // 骞虫浛 camera鐨刲ookAt
- return controls;
-}
-
-const windowResize = (camera, renderer) => {
- window.addEventListener('resize', function () {
- camera.aspect = window.innerWidth / window.innerHeight;
- camera.updateProjectionMatrix();
- renderer.setSize(window.innerWidth, window.innerHeight);
- }, false);
-}
-
-const initStats = (container) => {
- const stats = new Stats();
- container.appendChild(stats.dom);
- if (!help) {
- stats.domElement.style.display = 'none';
- }
- return stats;
-}
-
const buildFloor = (scene) => {
- // const size = 10000;
- // const divisions = 100;
- // const helper = new THREE.GridHelper(size, divisions);
- // helper.position.x = size / 2;
- // helper.position.z = size / 2;
- // helper.material.opacity = 0.25;
- // helper.material.transparent = true;
- // scene.add(helper);
- // return helper;
+ const boxGeometry = new THREE.BoxGeometry(100, 100, 100); // 216涓洪暱搴︼紝10涓哄搴︼紝10涓洪珮搴�
+ const boxMaterial = new THREE.MeshBasicMaterial({ color: 0x40739e });
+ const boxMesh = new THREE.Mesh(boxGeometry, boxMaterial);
+ boxMesh.position.set(0, 0, 0); // 鏍规嵁浣犵殑闇�姹傝缃綅缃�
+ scene.add(boxMesh)
+ return boxMesh;
- const width = 3500;
- const length = 7500;
- const floorGeometry = new THREE.BoxGeometry(width, 1, length); // 216涓洪暱搴︼紝10涓哄搴︼紝10涓洪珮搴�
- const floorMaterial = new THREE.MeshBasicMaterial({
- color: 0xffffff,
- transparent: true,
- opacity: 0.1,
- });
- const floorMesh = new THREE.Mesh(floorGeometry, floorMaterial);
- floorMesh.position.set(width / 2, -1, length / 2); // 鏍规嵁浣犵殑闇�姹傝缃綅缃�
- floorMesh.name = 'floor';
- scene.add(floorMesh);
- return floorMesh;
+ const size = 100;
+ const divisions = 100;
+ const helper = new THREE.GridHelper(size, divisions);
+ helper.position.x = size / 2;
+ helper.position.z = size / 2;
+ helper.material.opacity = 0.25;
+ helper.material.transparent = true;
+ scene.add(helper);
+ return helper;
}
\ No newline at end of file
--
Gitblit v1.9.1