feat: 添加天空和地面

This commit is contained in:
caoqianming 2023-08-30 10:29:57 +08:00
parent 2b98daca58
commit ae7cf80c64
4 changed files with 258 additions and 175 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.DS_Store
node_modules
/dist
.VSCodeCounter/
# local env files
.env.local

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@
<el-row :gutter="16" style="height: 34px;margin-top: 4px">
<el-col :span="24" class="panel_item">
<span class="panel_label">
<img src="/img/elec.png" style="height: 24px"/>
<img src="/img/elec.png" style="height: 24px" />
动力电消耗</span>
<span class="panel_value">{{ factoryData.elec_consume }}</span>
<span class="panel_unit">KWH</span>
@ -22,7 +22,7 @@
<el-row :gutter="16" style="height: 34px;margin-top: 4px">
<el-col :span="24" class="panel_item">
<span class="panel_label">
<img src="/img/coal.png" style="height: 24px"/>
<img src="/img/coal.png" style="height: 24px" />
原煤消耗
</span>
<span class="panel_value">{{ factoryData.coal_consume }}</span>
@ -32,7 +32,7 @@
<el-row :gutter="16" style="height: 34px;margin-top: 4px">
<el-col :span="24" class="panel_item">
<span class="panel_label">
<img src="/img/water.png" style="height: 24px"/>
<img src="/img/water.png" style="height: 24px" />
工业水消耗</span>
<span class="panel_value">{{ factoryData.water_consume }}</span>
<span class="panel_unit">T</span>
@ -46,7 +46,7 @@
<el-row :gutter="16" style="height: 34px;margin-top: 4px">
<el-col :span="24" class="panel_item">
<span class="panel_label">
<img src="/img/cair.png" style="height: 24px"/>
<img src="/img/cair.png" style="height: 24px" />
压缩空气消耗</span>
<span class="panel_value">{{ factoryData.cair_consume }}</span>
<span class="panel_unit">T</span>
@ -57,11 +57,11 @@
<div class="model">
<div id="loadingScreen">
<el-progress type="circle" :percentage="loadedPercent" :width=220 status="warning">
<template #default="{ percentage }">
<div style="font-size: 30px; color: white; font-weight: bold">{{ percentage }}%</div>
<div style="font-size: 18px; color: white; margin-top: 10px">工厂模型加载中</div>
</template>
</el-progress>
<template #default="{ percentage }">
<div style="font-size: 30px; color: white; font-weight: bold">{{ percentage }}%</div>
<div style="font-size: 18px; color: white; margin-top: 10px">工厂模型加载中</div>
</template>
</el-progress>
<!-- 工厂模型加载中.....{{ loadedPercent }}% -->
</div>
<canvas id="renderCanvas"></canvas>
@ -72,7 +72,7 @@
<el-row :gutter="16" style="height: 34px;margin-top: 4px">
<el-col :span="24" class="panel_item">
<span class="panel_label">
<img src="/img/elec.png" style="height: 24px"/>
<img src="/img/elec.png" style="height: 24px" />
单位产品电耗</span>
<span class="panel_value">{{ sectionData.elec_consume_unit }}</span>
<span class="panel_unit">KWH/T</span>
@ -81,7 +81,7 @@
<el-row :gutter="16" style="height: 34px;margin-top: 4px">
<el-col :span="24" class="panel_item">
<span class="panel_label">
<img src="/img/total_production.png" style="height: 24px"/>
<img src="/img/total_production.png" style="height: 24px" />
产品产量</span>
<span class="panel_value">{{ sectionData.total_production }}</span>
<span class="panel_unit">T</span>
@ -95,7 +95,7 @@
<el-row :gutter="16" style="height: 34px;margin-top: 4px">
<el-col :span="24" class="panel_item">
<span class="panel_label">
<img src="/img/run_rate.png" style="height: 24px"/>
<img src="/img/run_rate.png" style="height: 24px" />
运转率</span>
<span class="panel_value">{{ sectionData.run_rate }}</span>
<span class="panel_unit">%</span>
@ -104,7 +104,7 @@
<el-row :gutter="16" style="height: 34px;margin-top: 4px">
<el-col :span="24" class="panel_item" v-if="showKgcet">
<span class="panel_label">
<img src="/img/coal.png" style="height: 24px"/>
<img src="/img/coal.png" style="height: 24px" />
单位产品标煤耗
</span>
<span class="panel_value">{{ sectionData.coal_consume_unit }}</span>
@ -114,9 +114,8 @@
</div>
</div>
<div class="dropdown">
<div class="dropdown-item" v-for="(val, index) in sectionNames" :key="val" @click="handleSectionClick(val, index)"
:class="{ active: activeSection === index }"
>{{ val }}</div>
<div class="dropdown-item" v-for="(val, index) in sectionNames" :key="val" @click="handleSectionClick(val, index)"
:class="{ active: activeSection === index }">{{ val }}</div>
</div>
<div class="left_other animate__animated animate__backInLeft">
<div class="panel">
@ -153,13 +152,15 @@
import * as echarts from "echarts";
import * as BABYLON from "babylonjs"
import * as BABYLON_GUI from "babylonjs-gui"
import * as BABYLON_GRID from "@/utils/gridMaterial"
import * as BABYLON_MATERIAL from "@/utils/babylonMaterial"
import 'babylonjs-loaders';
import 'animate.css';
export default {
data() {
return {
factoryData: {'coal_consume': 100, 'elec_consume': 100, 'water_consume': 100, 'cair_consume': 100},
sectionData: {'elec_consume_unit': 0, 'total_production': 0, 'run_rate': 100, 'coal_consume_unit': 0},
factoryData: { 'coal_consume': 100, 'elec_consume': 100, 'water_consume': 100, 'cair_consume': 100 },
sectionData: { 'elec_consume_unit': 0, 'total_production': 0, 'run_rate': 100, 'coal_consume_unit': 0 },
initialAlpha: -Math.PI / 0.89,
initialBeta: Math.PI / 3.3,
initialRadius: 18,
@ -183,57 +184,57 @@ export default {
activeSectionName: '回转窑',
updateTime: '2023-08-17 16:00:00',
basicOption: {
backgroundColor: '',
tooltip: {},
// legend: {
// data: [''],
// top: 0,
// },
xAxis: {
data: ['一月', '二月', '三月', '四月', '五月', '六月'],
},
yAxis: {},
series: [
{
name: '销量',
type: 'bar',
label: {
show: true,
position: 'top'
},
backgroundColor: '',
tooltip: {},
// legend: {
// data: [''],
// top: 0,
// },
xAxis: {
data: ['一月', '二月', '三月', '四月', '五月', '六月'],
},
yAxis: {},
series: [
{
name: '销量',
type: 'bar',
label: {
show: true,
position: 'top'
},
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#83bff6' },
{ offset: 0.5, color: '#188df0' },
{ offset: 1, color: '#188df0' }
])
},
emphasis: {
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#83bff6' },
{ offset: 0.5, color: '#188df0' },
{ offset: 1, color: '#188df0' }
])
},
emphasis: {
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#2378f7' },
{ offset: 0.7, color: '#2378f7' },
{ offset: 1, color: '#83bff6' }
])
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#2378f7' },
{ offset: 0.7, color: '#2378f7' },
{ offset: 1, color: '#83bff6' }
])
}
},
data: [5, 20, 36, 10, 10, 20]
}
],
grid: { //
top: "5%",
left: "12%",
right: "0px",
bottom: "15%"
}
},
data: [5, 20, 36, 10, 10, 20]
}
],
grid: { //
top: "5%",
left: "12%",
right: "0px",
bottom: "15%"
}
},
chart1Option: {},
chart2Option: {},
chart3Option: {},
chart4Option: {},
chart5Option: {},
chart6Option: {}
}
}
},
mounted() {
var that = this;
@ -248,48 +249,48 @@ export default {
});
},
beforeUnmount(){
beforeUnmount() {
//
const canvas = document.getElementById('renderCanvas');
if (canvas) {
canvas.parentNode.removeChild(canvas);
}
if (canvas) {
canvas.parentNode.removeChild(canvas);
}
},
methods: {
getFactoryData(){
getFactoryData() {
},
getSectionData(){
getSectionData() {
},
initCharts(){
initCharts() {
//
this.setChart('chart1');
this.chart2Option = Object.assign({}, this.basicOption)
this.chart2Option.series[0].type = 'line'
this.setChart('chart2', this.chart2Option);
this.chart3Option = Object.assign({}, this.basicOption)
this.chart3Option.series = [
{
name: 'Forest',
type: 'bar',
label: {
show: true,
position: 'top'
},
emphasis: {
focus: 'series'
},
data: [320, 332, 301, 334, 390, 380]
},
{
name: 'Steppe',
type: 'bar',
emphasis: {
focus: 'series'
},
data: [220, 182, 191, 234, 290, 280]
}]
this.chart3Option.series = [
{
name: 'Forest',
type: 'bar',
label: {
show: true,
position: 'top'
},
emphasis: {
focus: 'series'
},
data: [320, 332, 301, 334, 390, 380]
},
{
name: 'Steppe',
type: 'bar',
emphasis: {
focus: 'series'
},
data: [220, 182, 191, 234, 290, 280]
}]
this.setChart('chart3', this.chart3Option);
this.chart4Option = Object.assign({}, this.basicOption)
this.chart4Option.series[0].smooth = true
@ -333,7 +334,9 @@ export default {
left_other.style.width = '22%';
right_other.style.position = 'absolute';
right_other.style.width = '22%';
model.style.height = (windowHeight - 50) + 'px';
model.style.position = 'absolute';
model.style.height = (windowHeight - 3) + 'px';
model.style.top = 0
var chartHeight = (windowHeight - 400) / 3 + 'px';
var charts = document.getElementsByClassName('chart')
for (var i = 0; i < charts.length; i++) {
@ -353,6 +356,7 @@ export default {
left_other.style.width = '100%';
right_other.style.position = 'static';
right_other.style.width = '100%';
model.style.position = 'relative';
model.style.height = chartHeight;
var charts = document.getElementsByClassName('chart')
for (var i = 0; i < charts.length; i++) {
@ -405,29 +409,95 @@ export default {
// Add your code here matching the playground format
const createScene = function () {
const scene = new BABYLON.Scene(engine);
scene.clearColor = BABYLON.Color3(1, 0, 1);
// const groundMat = new BABYLON.StandardMaterial("groundMat");
// groundMat.diffuseTexture = new BABYLON.Texture("img/ground_big.jpg");
// groundMat.diffuseTexture.hasAlpha = false;
// const ground = BABYLON.MeshBuilder.CreateGround("ground", {width:40, height:40});
// ground.material = groundMat;
// ground.position.y = - 0.1
scene.clearColor = BABYLON.Color3.Black(); //BABYLON.Color3(1, 0, 1);
const ground = BABYLON.MeshBuilder.CreateGround("ground", { width: 100, height: 100 });
const groundMaterial = new BABYLON_GRID.GridMaterial("groundMaterial", scene);
groundMaterial.majorUnitFrequency = 5;
groundMaterial.minorUnitVisibility = 0.5;
groundMaterial.gridRatio = 2;
// groundMaterial.opacity = 0.99;
ground.material = groundMaterial;
ground.position.y = -0.1
// const groundMat = new BABYLON.StandardMaterial("groundMat");
// groundMat.diffuseTexture = new BABYLON.Texture("img/ground_big.jpg");
// groundMat.diffuseTexture.hasAlpha = false;
// groundMat.diffuseTexture.uScale = 15.0;//Repeat 5 times on the Vertical Axes
// groundMat.diffuseTexture.vScale = 15.0;
// groundMat.shadowLevel = 0.4;
// const ground = BABYLON.MeshBuilder.CreateGround("ground", {width:40, height:40});
// ground.material = groundMat;
// ground.position.y = - 0.1
//
// const backgroundImage = new BABYLON.Layer('', 'img/bj.png', scene, true);
//
// const backgroundImage = new BABYLON.Layer('', 'img/bj.png', scene, true);
const camera = new BABYLON.ArcRotateCamera("camera", that.initialAlpha, that.initialBeta, that.initialRadius, new BABYLON.Vector3(0, 0, 1.2));
that.initialTarget = camera.getTarget();
camera.upperBetaLimit = Math.PI / 2.2; //
camera.upperBetaLimit = Math.PI / 2.3; //
camera.attachControl(canvas, true);
camera.maxZ = 1000; //
//
camera.lowerRadiusLimit = 6;
camera.upperRadiusLimit = 26;
camera.upperRadiusLimit = 18;
//
const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0));
light.intensity = 1.6;
// skybox
const skybox = BABYLON.MeshBuilder.CreateBox("skyBox", { size: 150 }, scene);
var skyboxMaterial = new BABYLON_MATERIAL.SkyMaterial("skyMaterial", scene);
skyboxMaterial.backFaceCulling = false;
// const skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
// skyboxMaterial.backFaceCulling = false;
// skyboxMaterial.disableLighting = true;
// skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("img/skybox", scene);
// skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
// skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
// skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
skybox.material = skyboxMaterial;
/*
* Keys:
* - 1: Day
* - 2: Evening
* - 3: Increase Luminance
* - 4: Decrease Luminance
* - 5: Increase Turbidity
* - 6: Decrease Turbidity
* - 7: Move horizon to -50
* - 8: Restore horizon to 0
*/
var setSkyConfig = function (property, from, to) {
var keys = [
{ frame: 0, value: from },
{ frame: 100, value: to }
];
var animation = new BABYLON.Animation("animation", property, 100, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
animation.setKeys(keys);
scene.stopAnimation(skybox);
scene.beginDirectAnimation(skybox, [animation], 0, 100, false, 1);
};
window.addEventListener("keydown", function (evt) {
switch (evt.keyCode) {
case 49: setSkyConfig("material.inclination", skyboxMaterial.inclination, 0); break; // 1
case 50: setSkyConfig("material.inclination", skyboxMaterial.inclination, -0.5); break; // 2
case 51: setSkyConfig("material.luminance", skyboxMaterial.luminance, 0.1); break; // 3
case 52: setSkyConfig("material.luminance", skyboxMaterial.luminance, 1.0); break; // 4
case 53: setSkyConfig("material.turbidity", skyboxMaterial.turbidity, 40); break; // 5
case 54: setSkyConfig("material.turbidity", skyboxMaterial.turbidity, 5); break; // 6
case 55: setSkyConfig("material.cameraOffset.y", skyboxMaterial.cameraOffset.y, 50); break; // 7
case 56: setSkyConfig("material.cameraOffset.y", skyboxMaterial.cameraOffset.y, 0); break; // 8
default: break;
}
});
// Set to Day
setSkyConfig("material.inclination", skyboxMaterial.inclination, 0);
// GUI
const advancedTexture = BABYLON_GUI.AdvancedDynamicTexture.CreateFullscreenUI("myUI");
@ -462,12 +532,12 @@ export default {
}
})
// mesh
// mesh
const mesh_rect = new BABYLON_GUI.Rectangle('mesh_rect');
mesh_rect.width = "80px";
mesh_rect.height = "20px";
mesh_rect.backgroundColor = 'black'
mesh_rect.alpha = 0.8
mesh_rect.background = 'orange'
mesh_rect.alpha = 0.6
mesh_rect.isVisible = false;
advancedTexture.addControl(mesh_rect);
@ -484,7 +554,7 @@ export default {
var value = that.sectionNames[key];
var mesh = scene.getMeshByName(key);
if(mesh){
if (mesh) {
var rect1 = new BABYLON_GUI.Rectangle(value + '_rect');
rect1.width = "60px";
rect1.height = "30px";
@ -502,11 +572,12 @@ export default {
rect1.linkWithMesh(mesh);
rect1.linkOffsetY = -30;
console.log(rect1)
rect1.onPointerDownObservable.add(() => {
var mesh = rect1.linkedMesh;
if(camera.target != mesh.position){
if (camera.target != mesh.position) {
console.log('fly to')
//
//
var cameraPosition = new BABYLON.Vector3(
mesh.position.x + 9 * Math.sin(camera.beta) * Math.cos(Math.PI),
mesh.position.y + 9 * Math.cos(camera.beta),
@ -514,39 +585,38 @@ export default {
);
var ease = new BABYLON.CubicEase();
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
BABYLON.Animation.CreateAndStartAnimation('at5', camera, 'position', 45, 200, camera.position, cameraPosition, 0, ease);
BABYLON.Animation.CreateAndStartAnimation('at51', camera, 'target', 45, 200, camera.target, mesh.position, 0, ease);
}
});
}
});
//
// StackPanel
// const data_view = new BABYLON_GUI.StackPanel(value + '_data_view');
// data_view.width = '100px'; // StackPanel
// data_view.bottom = rect1.bottom + 50 + 'px';
// data_view.background = 'darkblue'
// data_view.cornerRadius = 4;
// //
// const textLines = [": 123", ": 123"];
const data_view = new BABYLON_GUI.StackPanel(value + '_data_view');
data_view.width = '100px'; // StackPanel
data_view.bottom = rect1.bottom + 50 + 'px';
data_view.background = 'darkblue'
data_view.cornerRadius = 4;
//
const textLines = ["电耗: 123", "产量: 123"];
// for (let i = 0; i < textLines.length; i++) {
// let textLine = textLines[i];
// const textA = new BABYLON_GUI.TextBlock();
// textA.height = "20px"
// textA.color = "white"
// textA.text = textLine;
// // text.fontSize = textLines[i].fontSize;
for (let i = 0; i < textLines.length; i++) {
let textLine = textLines[i];
const textA = new BABYLON_GUI.TextBlock();
textA.height = "20px"
textA.color = "white"
textA.text = textLine;
// text.fontSize = textLines[i].fontSize;
// data_view.addControl(textA);
// }
data_view.addControl(textA);
}
// // StackPanelGUI
// advancedTexture.addControl(data_view);
// data_view.linkWithMesh(mesh);
// data_view.linkOffsetY = -80;
// StackPanelGUI
advancedTexture.addControl(data_view);
data_view.linkWithMesh(mesh);
data_view.linkOffsetY = -80;
}
}
engine.hideLoadingUI()
@ -624,26 +694,26 @@ export default {
engine.resize();
});
},
handleSectionClick(val, index){
handleSectionClick(val, index) {
this.activeSectionName = val;
this.activeSection = index;
if (val == '回转窑'){
if (val == '回转窑') {
this.showKgcet = true;
}else{
} else {
this.showKgcet = false;
}
const element_main = document.querySelector('.right_main');
element_main.classList.add('animate__animated', 'animate__fadeIn');
element_main.addEventListener('animationend', () => {
//
element_main.classList.remove('animate__fadeIn');
});
//
element_main.classList.remove('animate__fadeIn');
});
const element = document.querySelector('.right_other');
element.classList.add('animate__animated', 'animate__fadeIn');
element.addEventListener('animationend', () => {
//
//
element.classList.remove('animate__fadeIn');
});
});
},
}
@ -657,6 +727,8 @@ export default {
}
header {
position: relative;
z-index: 10;
height: 50px;
/* 调整头部高度 */
background-image: url('/public/img/header.png');
@ -667,9 +739,11 @@ header {
justify-content: space-between;
align-items: center;
}
.title_left {
flex: 1;
}
.title {
flex: 1;
text-align: center;
@ -677,6 +751,7 @@ header {
font-size: 24px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}
.title_right {
flex: 1;
font-size: 20px;
@ -685,6 +760,7 @@ header {
}
.model {
top: 0;
width: 100%;
background-image: url('/public/img/bj.png');
background-size: cover;
@ -708,6 +784,7 @@ header {
.left_main,
.right_main {
z-index: 10;
position: absolute;
top: 40px;
width: 20%;
@ -780,19 +857,20 @@ header {
width: 100%;
height: 220px;
}
.dropdown {
/* top: 20%;
/* top: 20%;
font-size: 18px;
right: 22%;
position: absolute; */
bottom: 3%;
font-size: 18px;
left: 50%;
position: absolute;
transform: translateX(-50%);
}
/* .dropdown-item {
bottom: 3%;
font-size: 18px;
left: 50%;
position: absolute;
transform: translateX(-50%);
}
/* .dropdown-item {
padding: 12px 16px;
text-decoration: none;
display: block;
@ -803,32 +881,32 @@ header {
border: 1px solid #99fffe;
}
*/
.dropdown-item {
text-decoration: none;
display: inline-block;
color: white;
width:8vw;
height:3.4vw;
font-size: 1vw;
text-align:center;
background:url(./../../../public/img/menu.png) no-repeat;
background-size:100%;
line-height:3.7vw;
margin: 0 0.1vw 0.1vw 0.1vw;
}
.dropdown-item {
text-decoration: none;
display: inline-block;
color: white;
width: 8vw;
height: 3.4vw;
font-size: 1vw;
text-align: center;
background: url(./../../../public/img/menu.png) no-repeat;
background-size: 100%;
line-height: 3.7vw;
margin: 0 0.1vw 0.1vw 0.1vw;
}
.dropdown-item:hover, .dropdown-item.active{
/* background-color: #ddd; */
width:8.2vw;
height:3.5vw;
font-size: 1vw;
line-height:3.7vw;
margin:0;
text-decoration: none;
display: inline-block;
color: white;
text-align:center;
background:url(./../../../public/img/menu_active.png) no-repeat;
background-size:100%;
}
</style>
.dropdown-item:hover,
.dropdown-item.active {
/* background-color: #ddd; */
width: 8.2vw;
height: 3.5vw;
font-size: 1vw;
line-height: 3.7vw;
margin: 0;
text-decoration: none;
display: inline-block;
color: white;
text-align: center;
background: url(./../../../public/img/menu_active.png) no-repeat;
background-size: 100%;
}</style>