From ddd0f49e2deb89f45fde892e1ff0953ec0ca2621 Mon Sep 17 00:00:00 2001 From: 584911253@qq.com <584911253@qq.com> Date: 星期四, 16 三月 2023 13:39:08 +0800 Subject: [PATCH] 三维截取功能修改 --- src/views/Tools/LayerTree.vue | 2 src/views/Synthesis/LeftMenu.vue | 217 +++++++++++++++++++++++++++--------------------------- 2 files changed, 110 insertions(+), 109 deletions(-) diff --git a/src/views/Synthesis/LeftMenu.vue b/src/views/Synthesis/LeftMenu.vue index 4cf4a26..c0211f6 100644 --- a/src/views/Synthesis/LeftMenu.vue +++ b/src/views/Synthesis/LeftMenu.vue @@ -1554,7 +1554,7 @@ var that = this; that.modelClip = !that.modelClip; if (that.modelClip) { - that.$store.state.propertiesFlag = '3'; + // that.$store.state.propertiesFlag = '3'; if (window.model) { that.modelClipping(); } @@ -1579,7 +1579,7 @@ } } else { - that.$store.state.propertiesFlag = ''; + // that.$store.state.propertiesFlag = ''; Viewer.entities.removeAll(); } // window.model = sgworld.Creator.create3DTilesets( @@ -1757,138 +1757,139 @@ //妯″瀷瑁佸垏 modelClipping() { const scene = Viewer.scene; - let targetY = 0.0; + let targetY = 40.0; let planeEntities = []; let selectedPlane; - // let clippingPlanes = new Cesium.ClippingPlaneCollection({ - // planes: [ // ClippingPlane瀵硅薄鏁扮粍闆嗗悎 - // new Cesium.ClippingPlane( // 瑁佸垏闈� - // new Cesium.Cartesian3(0.0, 0.0, -1.0), // 娉曠嚎鏂瑰悜 - // 0// 鍘熺偣鍒板钩闈㈢殑鏈�鐭窛绂伙紝璁剧疆0灏卞ソ - // ), - // ], - // enabled: true, - // edgeWidth: 1.0, // 妯″瀷琚鍒囬儴鍒嗙殑鎴潰绾垮 - // }); let clippingPlanes = new Cesium.ClippingPlaneCollection({ planes: [ // ClippingPlane瀵硅薄鏁扮粍闆嗗悎 - //鍓嶅悗鍒囧壊 - new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 1, 0), 0), //鍚� - new Cesium.ClippingPlane(new Cesium.Cartesian3(0, -1, 0), 0), //鍓� - // 宸﹀彸鍒囧壊 - new Cesium.ClippingPlane(new Cesium.Cartesian3(1.0, 0.0, 0), 0), //宸� - new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0), 0), //鍙� - // 涓婁笅鍒囧壊 - new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, -1), 0), //涓娾啋涓� - // new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, 1), 0), //涓嬧啋涓娿�� + new Cesium.ClippingPlane( // 瑁佸垏闈� + new Cesium.Cartesian3(0.0, 0.0, -1.0), // 娉曠嚎鏂瑰悜 + 0// 鍘熺偣鍒板钩闈㈢殑鏈�鐭窛绂伙紝璁剧疆0灏卞ソ + ), ], enabled: true, edgeWidth: 1.0, // 妯″瀷琚鍒囬儴鍒嗙殑鎴潰绾垮 - unionClippingRegions: true, //true 鎵嶈兘澶氫釜鍒囧壊 }); + // let clippingPlanes = new Cesium.ClippingPlaneCollection({ + // planes: [ // ClippingPlane瀵硅薄鏁扮粍闆嗗悎 + // //鍓嶅悗鍒囧壊 + // new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 1, 0), 0), //鍚� + // new Cesium.ClippingPlane(new Cesium.Cartesian3(0, -1, 0), 0), //鍓� + // // 宸﹀彸鍒囧壊 + // new Cesium.ClippingPlane(new Cesium.Cartesian3(1.0, 0.0, 0), 0), //宸� + // new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0), 0), //鍙� + // // 涓婁笅鍒囧壊 + // new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, -1), 0), //涓娾啋涓� + // // new Cesium.ClippingPlane(new Cesium.Cartesian3(0, 0.0, 1), 0), //涓嬧啋涓娿�� + // ], + // enabled: true, + // edgeWidth: 1.0, // 妯″瀷琚鍒囬儴鍒嗙殑鎴潰绾垮 + // unionClippingRegions: true, //true 鎵嶈兘澶氫釜鍒囧壊 + // }); let boundingSphere = window.model.boundingSphere; // 鍒涘缓涓�涓潗鏍囪酱锛屼究浜庢祴璇� - var transform = Cesium.Transforms.eastNorthUpToFixedFrame(boundingSphere.center); - var modelMatrixPrimitive = Viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({ - // modelMatrix: transform, - length: 140.0 - })); + // var transform = Cesium.Transforms.eastNorthUpToFixedFrame(boundingSphere.center); + // var modelMatrixPrimitive = Viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({ + // // modelMatrix: transform, + // length: 140.0 + // })); // // 鍒涘缓娣诲姞瑁佸壀骞抽潰 - // for (let i = 0; i < clippingPlanes.length; ++i) { - // const plane = clippingPlanes.get(i); - // const planeEntity = Viewer.entities.add({ - // position: boundingSphere.center, - // plane: { - // dimensions: new Cesium.Cartesian2( - // boundingSphere.radius * 1.5, - // boundingSphere.radius * 1.5 - // ),//鍒囬潰鐨勯暱鍜屽 - // material: Cesium.Color.WHITE.withAlpha(0.1), - // plane: new Cesium.CallbackProperty( - // // 娣诲姞缁戝畾浜嬩欢锛屼笉鏂皟鐢� - // createPlaneUpdateFunction(plane), - // false - // ), - // outline: true, - // outlineColor: Cesium.Color.WHITE, - // }, - // }); - // planeEntities.push(planeEntity); - // } - // 鍒涘缓娣诲姞瑁佸壀骞抽潰 - let m_box; for (let i = 0; i < clippingPlanes.length; ++i) { - let plane = clippingPlanes.get(i); - let getPlaneType = getType4Plane(plane); - let planeEntity = Viewer.entities.add({ //娣诲姞骞抽潰瀹炰綋 鐩磋瑁佸垏闈� - id: 'ClipPlane' + i, - position: boundingSphere.center,// 鏍规嵁3dtiles鍚屾璋冩暣瑁佸垏闈㈤珮搴� + const plane = clippingPlanes.get(i); + const planeEntity = Viewer.entities.add({ + position: boundingSphere.center, plane: { - dimensions: new Cesium.Cartesian2(80, 80),//鍒囬潰鐨勯暱鍜屽 - plane: new Cesium.CallbackProperty(createPlaneUpdateFunction_box(plane, getPlaneType, boundingSphere.center), false), - material: Cesium.Color.WHITE.withAlpha(0.01), - outline: false, + dimensions: new Cesium.Cartesian2( + boundingSphere.radius * 1.5, + boundingSphere.radius * 1.5 + ),//鍒囬潰鐨勯暱鍜屽 + material: Cesium.Color.WHITE.withAlpha(0.1), + plane: new Cesium.CallbackProperty( + // 娣诲姞缁戝畾浜嬩欢锛屼笉鏂皟鐢� + createPlaneUpdateFunction(plane), + false + ), + outline: true, outlineColor: Cesium.Color.WHITE, - } + }, }); - if (!m_box) { - m_box = Viewer.entities.add({ - id: 'ClopBox', - modelMatrixPrimitive: modelMatrixPrimitive, - position: boundingSphere.center, - box: { - dimensions: new Cesium.Cartesian3(boundingSphere.radius * 1.2, boundingSphere.radius * 1.2, 40), - material: Cesium.Color.WHITE.withAlpha(0.3), - } - }) - } + planeEntities.push(planeEntity); } + // 鍒涘缓娣诲姞瑁佸壀骞抽潰 + // let m_box; + // for (let i = 0; i < clippingPlanes.length; ++i) { + // let plane = clippingPlanes.get(i); + // let getPlaneType = getType4Plane(plane); + // let planeEntity = Viewer.entities.add({ //娣诲姞骞抽潰瀹炰綋 鐩磋瑁佸垏闈� + // id: 'ClipPlane' + i, + // position: boundingSphere.center,// 鏍规嵁3dtiles鍚屾璋冩暣瑁佸垏闈㈤珮搴� + // plane: { + // dimensions: new Cesium.Cartesian2(80, 80),//鍒囬潰鐨勯暱鍜屽 + // plane: new Cesium.CallbackProperty(createPlaneUpdateFunction_box(plane, getPlaneType, boundingSphere.center), false), + // material: Cesium.Color.WHITE.withAlpha(0.2), + // outline: false, + // outlineColor: Cesium.Color.WHITE, + // } + // }); + // if (!m_box) { + // m_box = Viewer.entities.add({ + // id: 'ClopBox', + // modelMatrixPrimitive: modelMatrixPrimitive, + // position: boundingSphere.center, + // box: { + // dimensions: new Cesium.Cartesian3(boundingSphere.radius * 1.2, boundingSphere.radius * 1.2, 40), + // material: Cesium.Color.WHITE.withAlpha(0.3), + // } + // }) + // } + // } window.model.clippingPlanes = clippingPlanes; // 缁戝畾涓婄Щ鍔ㄤ簨浠� - // const downHandler = new Cesium.ScreenSpaceEventHandler( - // Viewer.scene.canvas - // ); - // downHandler.setInputAction(function (movement) { - // const pickedObject = scene.pick(movement.position); - // if ( - // Cesium.defined(pickedObject) && - // Cesium.defined(pickedObject.id.plane) - // ) { - // selectedPlane = pickedObject.id.plane; - // selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.05); - // selectedPlane.outlineColor = Cesium.Color.WHITE; - // scene.screenSpaceCameraController.enableInputs = false; - // } - // }, Cesium.ScreenSpaceEventType.LEFT_DOWN); + const downHandler = new Cesium.ScreenSpaceEventHandler( + Viewer.scene.canvas + ); + downHandler.setInputAction(function (movement) { + const pickedObject = scene.pick(movement.position); + if ( + Cesium.defined(pickedObject) && + Cesium.defined(pickedObject.id.plane) + ) { + selectedPlane = pickedObject.id.plane; + selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.05); + selectedPlane.outlineColor = Cesium.Color.WHITE; + scene.screenSpaceCameraController.enableInputs = false; + } + }, Cesium.ScreenSpaceEventType.LEFT_DOWN); // 缁戝畾涓嬬Щ鍔ㄤ簨浠� - // const upHandler = new Cesium.ScreenSpaceEventHandler( - // Viewer.scene.canvas - // ); - // upHandler.setInputAction(function () { - // if (Cesium.defined(selectedPlane)) { - // selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.1); - // selectedPlane.outlineColor = Cesium.Color.WHITE; - // selectedPlane = undefined; - // } - // scene.screenSpaceCameraController.enableInputs = true; - // }, Cesium.ScreenSpaceEventType.LEFT_UP); + const upHandler = new Cesium.ScreenSpaceEventHandler( + Viewer.scene.canvas + ); + upHandler.setInputAction(function () { + if (Cesium.defined(selectedPlane)) { + selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.1); + selectedPlane.outlineColor = Cesium.Color.WHITE; + selectedPlane = undefined; + } + scene.screenSpaceCameraController.enableInputs = true; + }, Cesium.ScreenSpaceEventType.LEFT_UP); // Update plane on mouse move - // const moveHandler = new Cesium.ScreenSpaceEventHandler( - // Viewer.scene.canvas - // ); - // moveHandler.setInputAction(function (movement) { - // if (Cesium.defined(selectedPlane)) { - // const deltaY = movement.startPosition.y - movement.endPosition.y; - // targetY += deltaY; - // console.log("targetY----",targetY) - // } - // }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); + const moveHandler = new Cesium.ScreenSpaceEventHandler( + Viewer.scene.canvas + ); + moveHandler.setInputAction(function (movement) { + if (Cesium.defined(selectedPlane)) { + const deltaY = movement.startPosition.y - movement.endPosition.y; + targetY += deltaY; + // console.log("targetY----",targetY) + } + }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); function createPlaneUpdateFunction(plane) { return function () { plane.distance = targetY; + // console.log("targetY----",targetY) return plane; }; } diff --git a/src/views/Tools/LayerTree.vue b/src/views/Tools/LayerTree.vue index 35b2b83..07d8332 100644 --- a/src/views/Tools/LayerTree.vue +++ b/src/views/Tools/LayerTree.vue @@ -650,7 +650,7 @@ this.tileSet(tileset, parseFloat(res.elev)) Viewer.flyTo(tileset); }); - // window.model = tileset + window.model = tileset } }, -- Gitblit v1.9.3