diff --git a/public/images/htmlEditDialog/back-icon.png b/public/images/htmlEditDialog/back-icon.png new file mode 100644 index 0000000..3cce313 Binary files /dev/null and b/public/images/htmlEditDialog/back-icon.png differ diff --git a/public/images/htmlEditDialog/select-icon.png b/public/images/htmlEditDialog/select-icon.png new file mode 100644 index 0000000..88f8a0b Binary files /dev/null and b/public/images/htmlEditDialog/select-icon.png differ diff --git a/public/tunnelModel/chanel.glb b/public/tunnelModel/chanel.glb new file mode 100644 index 0000000..0753024 Binary files /dev/null and b/public/tunnelModel/chanel.glb differ diff --git a/public/tunnelModel/chanel.gltf b/public/tunnelModel/chanel.gltf index 5d4befd..3e24b9b 100644 --- a/public/tunnelModel/chanel.gltf +++ b/public/tunnelModel/chanel.gltf @@ -7,7 +7,7 @@ { "name": "Scene", "nodes": [ - 246 + 247 ] } ], @@ -80,7 +80,7 @@ 0, 1 ], - "name": "Cylinder001", + "name": "chanel", "extras": { "name": "Cylinder001" }, @@ -128,7 +128,7 @@ 0, 1 ], - "name": "Box002", + "name": "chanel", "extras": { "name": "Box002" }, @@ -176,7 +176,7 @@ 0, 1 ], - "name": "Box003", + "name": "chanel", "extras": { "name": "Box003" }, @@ -224,7 +224,7 @@ 0, 1 ], - "name": "Box004", + "name": "chanel", "extras": { "name": "Box004" }, @@ -5918,7 +5918,10 @@ ] }, { - "name": "chanel.glb", + "name": "chanelglb", + "extras": { + "name": "chanel.glb" + }, "children": [ 1, 3, @@ -6044,6 +6047,12 @@ 243, 245 ] + }, + { + "name": "chanel.gltf", + "children": [ + 246 + ] } ], "bufferViews": [ diff --git a/src/App.vue b/src/App.vue index 6e6fd1a..44c9b39 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,9 +1,9 @@ diff --git a/src/components/content/tunnelScene/childComp/EditDev.vue b/src/components/content/tunnelScene/childComp/EditDev.vue deleted file mode 100644 index af005b0..0000000 --- a/src/components/content/tunnelScene/childComp/EditDev.vue +++ /dev/null @@ -1,233 +0,0 @@ - - - - - diff --git a/src/components/content/tunnelScene/childComp/DevInfo.vue b/src/components/content/tunnelScene/displayInfoComp/DevInfo.vue similarity index 100% rename from src/components/content/tunnelScene/childComp/DevInfo.vue rename to src/components/content/tunnelScene/displayInfoComp/DevInfo.vue diff --git a/src/components/content/tunnelScene/editEquComp/childComps/InputNum.vue b/src/components/content/tunnelScene/editEquComp/childComps/InputNum.vue new file mode 100644 index 0000000..8902882 --- /dev/null +++ b/src/components/content/tunnelScene/editEquComp/childComps/InputNum.vue @@ -0,0 +1,60 @@ + + + + + diff --git a/src/components/content/tunnelScene/editEquComp/childComps/SelectInput.vue b/src/components/content/tunnelScene/editEquComp/childComps/SelectInput.vue new file mode 100644 index 0000000..6858ebf --- /dev/null +++ b/src/components/content/tunnelScene/editEquComp/childComps/SelectInput.vue @@ -0,0 +1,99 @@ + + + + + diff --git a/src/components/content/tunnelScene/editEquComp/editDialog.vue b/src/components/content/tunnelScene/editEquComp/editDialog.vue new file mode 100644 index 0000000..ff855b0 --- /dev/null +++ b/src/components/content/tunnelScene/editEquComp/editDialog.vue @@ -0,0 +1,194 @@ + + + + + diff --git a/src/components/content/tunnelScene/sceneClass/addDev/index.js b/src/components/content/tunnelScene/sceneClass/addDev/index.js index e7fbf70..a3e89a9 100644 --- a/src/components/content/tunnelScene/sceneClass/addDev/index.js +++ b/src/components/content/tunnelScene/sceneClass/addDev/index.js @@ -2,8 +2,6 @@ export default function (devInfo) { const dev = this.deviceList[devInfo.checkIndex].clone(); //克隆对应的moxin const p = this.targetPoint.getWorldPosition(new this.THREE.Vector3()); dev.position.copy(p); - // console.log(this.targetPoint); - modelEffectProcess(dev, this.targetPoint) this.scene.add(dev); this.targetPoint.hasDevice = true; //标记还存在设备 // 附着点记录信息 @@ -17,35 +15,16 @@ export default function (devInfo) { return this.targetPoint.info; } -function modelEffectProcess(model, point) { - if (model.children[0].name == "camera") { - console.log(model); - console.log(point); - model.scale.set(0.1, 0.1, 0.1) - - } - if (model.children[0].name == "fan") { - console.log(model); - console.log(point); - - } - if (model.children[0].name == "sensors") { - console.log(model); - console.log(point); - - model.scale.set(0.2, 0.2, 0.2) - } -} - function transformPosition(position, distance) { return `${equal(position.charAt(position.lastIndexOf("_") + 1))}边隧道${equal( position.charAt(position.lastIndexOf("_") + 2) - )}侧设备约${(Number( - position.substring(position.indexOf("_") + 1, position.lastIndexOf("_")) - ) + - 1) * - distance - }米处`; + )}侧设备约${ + (Number( + position.substring(position.indexOf("_") + 1, position.lastIndexOf("_")) + ) + + 1) * + distance + }米处`; } function equal(str) { diff --git a/src/components/content/tunnelScene/sceneClass/addDevice/index.js b/src/components/content/tunnelScene/sceneClass/addDevice/index.js index fc864e4..114dd56 100644 --- a/src/components/content/tunnelScene/sceneClass/addDevice/index.js +++ b/src/components/content/tunnelScene/sceneClass/addDevice/index.js @@ -13,7 +13,6 @@ function handleLoadedDevice(model) { const wp = this.targetPoint.getWorldPosition(new this.THREE.Vector3()); model.position.copy(wp); this.targetPoint.visible = false; - model.scale = 0.1 this.scene.add(model); if (model.name === "camera") { @@ -21,7 +20,6 @@ function handleLoadedDevice(model) { model.translateZ(4); model.translateY(-0.5); } - // 添加的信息请求或初始化的信息 this.targetPoint.info = { name: "摄像头", diff --git a/src/components/content/tunnelScene/sceneClass/demo.js b/src/components/content/tunnelScene/sceneClass/demo.js index 15a9ad9..0d3eba1 100644 --- a/src/components/content/tunnelScene/sceneClass/demo.js +++ b/src/components/content/tunnelScene/sceneClass/demo.js @@ -45,9 +45,9 @@ export default class Demo { 1000 ); - this.camera.position.z = -60; - this.camera.position.y = 20; - this.camera.position.x = -30; + this.camera.position.z = 1.24; + this.camera.position.y = 9.14; + this.camera.position.x = -63.79; this.camera.lookAt(0, 0, 1000); // 初始化渲染器 @@ -58,6 +58,7 @@ export default class Demo { this.renderer.setSize(window.innerWidth, window.innerHeight); this.renderer.domElement.style.position = "absolute"; this.mountedElement.appendChild(this.renderer.domElement); + console.log(this.renderer.domElement); // 创建渲染帧 this.render = () => { this.__renderScope(); @@ -101,6 +102,10 @@ export default class Demo { if (this.intoPointAnimation) { this.intoPointAnimation.update(); } + // 隧道颜色渐变动画 + if (this.opacityTween) { + this.opacityTween.update(); + } } // 添加世界坐标系 @@ -133,6 +138,8 @@ export default class Demo { gltf.scene.traverse((child) => { this._forModels(child); }); + // 初始化场景位置 + gltf.scene.position.set(-5, 0, 10); this.scene.add(gltf.scene); // 加载完后可执行函数 this._afterLoaded(gltf.scene); @@ -156,14 +163,14 @@ export default class Demo { this._ClickModel(this.points); } - // 在此方法中对模型批量操作 + // 在此方法中对模型批量操作,这里遍历附着点 _forModels(child) { // 匹配附着点(这里不适合对单个模型进行保存,批量对模型进行操作) if (child.isMesh && /^point+/.test(child.name)) { this.points.push(child); // 改变为基础材质 child.material = new this.THREE.MeshBasicMaterial(); - + child.scale.set(0.01, 0.01, 0.01); // 遍历一个属性是否存在设备 child.hasDevice = false; //初始化 } @@ -178,7 +185,7 @@ export default class Demo { this.camera, this.renderer.domElement ); - + this.orbitControls.object.position.set(-27.285, 16.356, -54.925); //限制轨道控制器的视角变化 this.orbitControls.maxPolarAngle = Math.PI * (3 / 5); // 监听控制器变化 @@ -242,6 +249,7 @@ export default class Demo { } // 处理点击2次触发事件事件 __handleListenerDBLClickEvent(isClickModels, e) { + e.preventDefault(); // 如果监听到双击则清空单次点击事件 clearTimeout(this.EventTimer); //最后一个是监听器默认参数 @@ -263,6 +271,7 @@ export default class Demo { // 处理点击左右键触发的事件 __handleListenerClickRLEvent(isClickModels, e) { + e.preventDefault(); clearTimeout(this.EventTimer); this.EventTimer = setTimeout(() => { const mouse = new this.THREE.Vector2(); @@ -276,9 +285,9 @@ export default class Demo { this.setBoxHelper(intersects[0].object); // 处理点击左右键事件 - if (e.button === 0) { + if (e.button === 2) { this._handleLClick(intersects[0].object); - } else if (e.button === 2) { + } else if (e.button === 0) { this._handleRClick(intersects[0].object); } }, 400); @@ -309,18 +318,12 @@ export default class Demo { this.tagCSS2DObj.element.style.display = "none"; this.tag2CSS2DObj.element.style.display = "none"; this.tag3CSS2DObj.element.style.display = "none"; - this.tagCSS2DObj.scale.set(0.1, 0.1, 0.1); this.tag2CSS2DObj.scale.set(0.1, 0.1, 0.1); - this.tag3CSS2DObj.scale.set(0.1, 0.1, 0.1); - this.tag3CSS2DObj.position.y = 1000; - - - this.tagCSS2DObj.scale.set(3, 3, 3); - + this.tag3CSS2DObj.scale.set(0.025, 0.025, 0.025); //编辑框 + this.tag3CSS2DObj.position.set(10, 0, 10); + this.tagCSS2DObj.scale.set(0.5, 0.5, 0.5); } - - clearTagsObj() { if (this.preDBLModel) { this.preDBLModel.remove(this.tagCSS2DObj); @@ -378,9 +381,64 @@ export default class Demo { setDistance(distance = 10) { this.distance = distance; } - loadBackground(backColorSet) { - this.scene.background = new this.THREE.TextureLoader().load("/images/background/background.png", function (texture) { - texture.encoding = backColorSet; - }); + loadBackground(hdrLoader, backColorSet) { + // hdrLoader.load("/images/background/background.hdr", (texture) => { + // texture.mapping = this.THREE.EquirectangularReflectionMapping; + // this.scene.background = texture; + // this.scene.environment = texture; + // }) + this.scene.background = new this.THREE.TextureLoader().load( + "/images/background/background.png", + function (texture) { + texture.encoding = backColorSet; + } + ); + } + /** + * + * @param {Boolean} option 是否禁用轨道控制器 + */ + isControlOrbit(option = true) { + this.orbitControls.enabled = option; + + const mesh = this.scene.getObjectByName("chanel"); + const mesh2 = this.scene.getObjectByName("chanel_1"); + const mesh3 = this.scene.getObjectByName("chanel_2"); + const mesh4 = this.scene.getObjectByName("chanel_3"); + + const opacityTween = (startVal, endVal, isNeedLookAt = false) => { + this.opacityTween = new this.TWEEN.Tween({ + opacity: startVal, + lookX: this.orbitControls.target.x, + lookY: this.orbitControls.target.y, + lookZ: this.orbitControls.target.z, + }); + this.opacityTween.to( + { + opacity: endVal, + lookX: 0, + lookY: 0, + lookZ: 0, + }, + 500 + ); + this.opacityTween.start(); + this.opacityTween.onUpdate((obj) => { + mesh.material.opacity = obj.opacity; + mesh2.material.opacity = obj.opacity; + mesh3.material.opacity = obj.opacity; + mesh4.material.opacity = obj.opacity; + if (!isNeedLookAt) return; + this.camera.lookAt(obj.lookX, obj.lookY, obj.lookZ); + this.orbitControls.target.set(obj.lookX, obj.lookY, obj.lookZ); + }); + }; + if (!option) { + // 显示编辑框隧道颜色 + opacityTween(0.5, 0.1); + } else { + // 退出编辑框什么颜色 + opacityTween(0.1, 0.5, true); + } } } diff --git a/src/components/content/tunnelScene/sceneClass/handleDBLclick/index.js b/src/components/content/tunnelScene/sceneClass/handleDBLclick/index.js index dec374e..11849b1 100644 --- a/src/components/content/tunnelScene/sceneClass/handleDBLclick/index.js +++ b/src/components/content/tunnelScene/sceneClass/handleDBLclick/index.js @@ -1,4 +1,5 @@ export function handleDBLClick(e) { + return; this._saveSate(); // 注意位置不能改变 this.clearTagsObj(); diff --git a/src/components/content/tunnelScene/sceneClass/handleOrbitControlsChange/index.js b/src/components/content/tunnelScene/sceneClass/handleOrbitControlsChange/index.js index e30b000..aa8f4c4 100644 --- a/src/components/content/tunnelScene/sceneClass/handleOrbitControlsChange/index.js +++ b/src/components/content/tunnelScene/sceneClass/handleOrbitControlsChange/index.js @@ -5,5 +5,5 @@ export function handleStartChange(e) { export function handleEndChange(e) { // 围绕点到照相机的位置 // console.log("结束"); - // console.log(this.camera.position); + // console.log(this.orbitControls.object.position); } diff --git a/src/components/content/tunnelScene/sceneClass/handleRLclick/handleLclick.js b/src/components/content/tunnelScene/sceneClass/handleRLclick/handleLclick.js index 56023a9..fe85ce2 100644 --- a/src/components/content/tunnelScene/sceneClass/handleRLclick/handleLclick.js +++ b/src/components/content/tunnelScene/sceneClass/handleRLclick/handleLclick.js @@ -1,4 +1,5 @@ export function handleLClick(targetPoint) { + return; this.clearTagsObj(); const worldPosition = new this.THREE.Vector3(); //获取附着点的世界坐标系 @@ -7,11 +8,11 @@ export function handleLClick(targetPoint) { // 显示左键属性栏 this.tag2CSS2DObj.element.style.display = "block"; // 设置标签位置 - this.tag2CSS2DObj.position.set( - worldPosition.x, - worldPosition.y, - worldPosition.z - ); + // this.tag2CSS2DObj.position.set( + // worldPosition.x, + // worldPosition.y, + // worldPosition.z + // ); // 标签定位 this.tag2CSS2DObj.translateY(-15); this.tag2CSS2DObj.translateX(15); diff --git a/src/components/content/tunnelScene/sceneClass/handleRLclick/handleRclick.js b/src/components/content/tunnelScene/sceneClass/handleRLclick/handleRclick.js index 05773c2..87d4875 100644 --- a/src/components/content/tunnelScene/sceneClass/handleRLclick/handleRclick.js +++ b/src/components/content/tunnelScene/sceneClass/handleRLclick/handleRclick.js @@ -14,18 +14,20 @@ export function handleRClick(targetPoint) { worldPosition.y, worldPosition.z ); - this.tag3CSS2DObj.translateY(-15); - this.tag3CSS2DObj.translateX(15); + this.isControlOrbit(false); + + this.tag3CSS2DObj.translateX(-3); + this.tag3CSS2DObj.translateZ(10); this.scene.add(this.tag3CSS2DObj); intoAnimation.call(this); - // 返回给组件的回调函数 - this.displayDevInfo(targetPoint); + + // 返回给编辑组件的回调函数 + this.editDev(targetPoint); } function intoAnimation() { const worldP = this.targetPoint.getWorldPosition(new this.THREE.Vector3()); const positionOBj = this.camera.position; - const start = this.orbitControls.target; this.intoPointAnimation = new this.TWEEN.Tween({ x: positionOBj.x, @@ -35,12 +37,11 @@ function intoAnimation() { yTarget: start.y, zTarget: start.z, }); - this.intoPointAnimation.to( { - x: worldP.x + 20, - y: worldP.y + 20, - z: worldP.z + 50, + x: worldP.x - 10, + y: worldP.y + 3, + z: worldP.z - 12, xTarget: worldP.x, yTarget: worldP.y, zTarget: worldP.z, diff --git a/src/components/content/tunnelScene/sceneClass/removeDevice/index.js b/src/components/content/tunnelScene/sceneClass/removeDevice/index.js deleted file mode 100644 index b34c0c9..0000000 --- a/src/components/content/tunnelScene/sceneClass/removeDevice/index.js +++ /dev/null @@ -1,20 +0,0 @@ -export function removeDev() { - if (!this.targetPoint.hasDevice) { - alert("该附着点不存在设备"); - return; - } else { - // 删除模型逻辑 - const devId = this.targetPoint.info.devId; - - const model = this.scene.getObjectById(devId); - this.scene.remove(model); - - // 附着点可见 - this.targetPoint.visible = true; - this.targetPoint.info = null; - // 按钮可否操作情况 - this.addBtn.disabled = false; - this.removeBtn.disabled = true; - this.targetPoint.hasDevice = false; - } -} diff --git a/src/components/content/tunnelScene/utils/toImg.js b/src/components/content/tunnelScene/utils/toImg.js new file mode 100644 index 0000000..c23213a --- /dev/null +++ b/src/components/content/tunnelScene/utils/toImg.js @@ -0,0 +1,15 @@ +/** + * @param {String} text 把输入的文字转化为base64的img图片 + */ +export default function (text, width = 100, height = 50) { + const canvas = document.createElement("canvas"); + canvas.width = width; + canvas.height = height; + const ctx = canvas.getContext("2d"); + ctx.fillStyle = "white"; + ctx.fillRect(0, 0, width, height); + ctx.fillStyle = "black"; + ctx.font = "30px serif"; + ctx.fillText(text, 0, 30); + return canvas.toDataURL(); +} diff --git a/src/views/tunnel/index.vue b/src/views/tunnel/index.vue index a6975aa..6fd9d9f 100644 --- a/src/views/tunnel/index.vue +++ b/src/views/tunnel/index.vue @@ -1,7 +1,7 @@