替换三维模型

This commit is contained in:
luoshiwen 2024-11-29 04:44:13 +08:00
parent fd5ca3e6f5
commit 9806d73d5b
13 changed files with 179 additions and 75 deletions

BIN
dist.rar Normal file

Binary file not shown.

View File

@ -15,5 +15,6 @@
<body>
<div id="app" v-cloak></div>
<script type="module" src="/src/main.js"></script>
<script src="./config.js"></script>
</body>
</html>

4
public/config.js Normal file
View File

@ -0,0 +1,4 @@
const config = {
host:'172.16.1.106',
port:'8083',
}

Binary file not shown.

View File

@ -1 +1 @@
172.16.1.106:5005
10.155.161.49:5005

View File

@ -1,89 +1,97 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity WebGL Player | U3D_TobaccoWarehouseISMDTSystem</title>
<link rel="shortcut icon" href="TemplateData/favicon.ico">
<link rel="stylesheet" href="TemplateData/style.css">
</head>
<style>
</head>
<style>
body,html{
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
<body>
<div id="unity-container" class="unity-desktop" style="width: 100%;height: 100%;">
<canvas id="unity-canvas" tabindex="-1" style="width: 100%;height: 100%;"></canvas>
<div id="unity-loading-bar">
</style>
<body>
<div id="unity-container" class="unity-desktop" style="width: 100%;height:100%">
<canvas id="unity-canvas" style="width: 100%;height:100%" tabindex="-1"></canvas>
<div id="unity-loading-bar">
<div id="unity-logo"></div>
<div id="unity-progress-bar-empty">
<div id="unity-progress-bar-full"></div>
<div id="unity-progress-bar-full"></div>
</div>
</div>
<div id="unity-warning"> </div>
<div id="unity-footer">
</div>
<div id="unity-warning"></div>
<div id="unity-footer">
<div id="unity-webgl-logo"></div>
<div id="unity-fullscreen-button"></div>
<div id="unity-build-title">U3D_TobaccoWarehouseISMDTSystem</div>
</div>
</div>
<script>
</div>
var container = document.querySelector("#unity-container");
var canvas = document.querySelector("#unity-canvas");
var loadingBar = document.querySelector("#unity-loading-bar");
var progressBarFull = document.querySelector("#unity-progress-bar-full");
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
var warningBanner = document.querySelector("#unity-warning");
<button onclick="OpenHtmlMQTT()">Connect</button>
<button onclick="publishMessage()">Publish</button>
<button onclick="disconnectMQTT()">Disconnect</button>
<script src="./js/mqtt.min.js"></script>
// Shows a temporary message banner/ribbon for a few seconds, or
// a permanent error message on top of the canvas if type=='error'.
// If type=='warning', a yellow highlight color is used.
// Modify or remove this function to customize the visually presented
// way that non-critical warnings and error messages are presented to the
// user.
function unityShowBanner(msg, type) {
<script>
var container = document.querySelector("#unity-container");
var canvas = document.querySelector("#unity-canvas");
var loadingBar = document.querySelector("#unity-loading-bar");
var progressBarFull = document.querySelector("#unity-progress-bar-full");
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
var warningBanner = document.querySelector("#unity-warning");
// Shows a temporary message banner/ribbon for a few seconds, or
// a permanent error message on top of the canvas if type=='error'.
// If type=='warning', a yellow highlight color is used.
// Modify or remove this function to customize the visually presented
// way that non-critical warnings and error messages are presented to the
// user.
function unityShowBanner(msg, type) {
function updateBannerVisibility() {
warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
}
var div = document.createElement('div');
div.innerHTML = msg;
warningBanner.appendChild(div);
if (type == 'error') div.style = 'background: red; padding: 10px;';
else {
if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
setTimeout(function() {
warningBanner.removeChild(div);
updateBannerVisibility();
}, 5000);
if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
setTimeout(function () {
warningBanner.removeChild(div);
updateBannerVisibility();
}, 5000);
}
updateBannerVisibility();
}
}
var buildUrl = "Build";
var loaderUrl = buildUrl + "/延安烟厂.loader.js";
var config = {
dataUrl: buildUrl + "/延安烟厂.data.unityweb",
frameworkUrl: buildUrl + "/延安烟厂.framework.js.unityweb",
codeUrl: buildUrl + "/延安烟厂.wasm.unityweb",
var buildUrl = "Build";
var loaderUrl = buildUrl + "/webgl.loader.js";
var config = {
dataUrl: buildUrl + "/webgl.data.unityweb",
frameworkUrl: buildUrl + "/webgl.framework.js.unityweb",
codeUrl: buildUrl + "/webgl.wasm.unityweb",
streamingAssetsUrl: "StreamingAssets",
companyName: "DefaultCompany",
productName: "U3D_TobaccoWarehouseISMDTSystem",
productVersion: "0.1",
showBanner: unityShowBanner,
};
};
// By default, Unity keeps WebGL canvas render target size matched with
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
// Set this to false if you want to decouple this synchronization from
// happening inside the engine, and you would instead like to size up
// the canvas DOM size and WebGL render target sizes yourself.
// config.matchWebGLToCanvasSize = false;
// By default, Unity keeps WebGL canvas render target size matched with
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
// Set this to false if you want to decouple this synchronization from
// happening inside the engine, and you would instead like to size up
// the canvas DOM size and WebGL render target sizes yourself.
// config.matchWebGLToCanvasSize = false;
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
// Mobile device style: fill the whole browser client area with the game canvas:
var meta = document.createElement('meta');
@ -98,32 +106,113 @@
// config.devicePixelRatio = 1;
} else {
} else {
// Desktop style: Render the game canvas in a window that can be maximized to fullscreen:
// canvas.style.width = "1920px";
// canvas.style.height = "1080px";
}
// canvas.style.width = "960px";
// canvas.style.height = "600px";
}
loadingBar.style.display = "block";
var script = document.createElement("script");
script.src = loaderUrl;
script.onload = () => {
//----------------------------------------------------------------------------------MQTT-----------------------------------------------------------------------------
let client;
function OpenHtmlMQTT() {
client = mqtt.connect('ws://10.155.161.49:8083/mqtt');
client.on('connect', () => {
console.log('连接...');
const devices = [
"cm1",//去加盖机
Array.from({length: 7}, (_, i) => `elv${i + 1}`),//提升机
Array.from({length: 7}, (_, i) => `convoyor510${i + 1}`),//输送机
Array.from({length: 51}, (_, i) => `convoyor52${String(i + 1).padStart(2, '0')}`),//输送机
Array.from({length: 30}, (_, i) => `convoyor54${String(i + 1).padStart(2, '0')}`),//输送机
Array.from({ length: 4 }, (_, i) => `dpm${i + 1}`),//拆码垛机
Array.from({ length: 2 }, (_, i) => `fxj${i + 1}`),////机械手臂
Array.from({length: 8}, (_, i) => `car${i + 1}`),//小车
"fe1",//落地时提升机
Array.from({length: 2}, (_, i) => `qcbd${i + 1}`)//快换电池装置
];
devices.forEach(device => {
console.log(device);
client.subscribe(device, {
onSuccess: () => {
console.log(`已订阅: ${device}`);
},
onFailure: (err) => {
console.error(`订阅失败: ${device}:`, err);
}
});
});
// client.subscribe('car1', (err) => {
// if (!err) {
// console.log('Subscribed to car1');
// }
// });
//
});
client.on('message', (topic, message) => {
const mes = JSON.stringify({device: topic, message: message.toString()});
// console.log(mes);
unityInstance.SendMessage('APP', 'Message', mes)
});
client.on('error', (err) => {
console.error('Connection error: ', err);
});
}
function publishMessage() {
if (client) {
client.publish('car1', 'Hello');
}
}
function disconnectMQTT() {
if (client) {
client.end(() => {
console.log('关闭连接');
});
}
}
//----------------------------------------------------------------------------------MQTT-----------------------------------------------------------------------------
loadingBar.style.display = "block";
var script = document.createElement("script");
script.src = loaderUrl;
script.onload = () => {
createUnityInstance(canvas, config, (progress) => {
progressBarFull.style.width = 100 * progress + "%";
}).then((unityInstance) => {
loadingBar.style.display = "none";
fullscreenButton.onclick = () => {
unityInstance.SetFullscreen(1);
};
}).catch((message) => {
alert(message);
});
progressBarFull.style.width = 100 * progress + "%";
}).then((unityInstance) => {
loadingBar.style.display = "none";
// 为window添加unityInstance对象
window.unityInstance = unityInstance
fullscreenButton.onclick = () => {
unityInstance.SetFullscreen(1);
};
}).catch((message) => {
alert(message);
});
};
document.body.appendChild(script);
document.body.appendChild(script);
</script>
</body>
</script>
</body>
</html>

10
public/model/js/mqtt.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,4 @@
import mqtt from "mqtt";
class mqttHandle {
constructor() {
@ -9,9 +10,9 @@ class mqttHandle {
cleanSession: true,
connectTimeout: 7000, // 超时时间
reconnectPeriod: 7000, // 重连时间间隔
host: '172.16.1.106',
host: config.host,
// host: '172.16.1.253',
port: '8083',
port: config.port,
// 认证信息
clientId: Number(new Date()).toString(),
// clientId: 'JBFY',
@ -33,7 +34,7 @@ class mqttHandle {
// console.log("connectUrl",connectUrl)
const { host, port, endpoint, ...options } = this.connect;
// const connectUrl = 'ws://138.227.208.100:1884/mqtt';
const connectUrl = 'ws://172.16.1.106:8083/mqtt';
const connectUrl = `ws://${config.host}:${config.port}/mqtt`;
// const connectUrl = 'ws://172.16.1.253:1884/mqtt';
if (this.mqttClient == undefined) {
this.mqttClient = mqtt.connect(connectUrl, options);

View File

@ -1,7 +1,7 @@
<template>
<Nav />
<div class="unity">
<!-- <iframe src="model/index.html" frameborder="0"></iframe> -->
<iframe src="model/index.html" frameborder="0"></iframe>
</div>
<div class="home">
<div class="home-left">
@ -488,6 +488,7 @@ function drawInventoryNewsEcahrt(result) {
name: "特殊箱子",
value: 0,
};
// for (let i = 0; i < scaleData.length; i++) {
// if (scaleData[i].name === "") {
// box.value = box.value + scaleData[i].value;
@ -906,9 +907,7 @@ function realInfo(topic, message) {
const u8arr = new Uint8Array(message);
const temp = utf8decoder.decode(u8arr); //
console.log("temp", temp)
// window.parent.getMqttData(temp)
const msg = JSON.parse(temp); //JSON
console.log(msg,'xxxxxxxxxx');
msg.forEach((el) => {
el.msg = "维修提醒";
el.reminderMsg = el.facCode + " 需要维修";