Files
FreeCADWasmDev/web/teaching/cases/production-line-reference.html

94 lines
7.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="data:," />
<title>生产线参考模型 · 27 个 GLB</title>
<style>
html, body { margin: 0; height: 100%; background: #0d1318; color: #dbe6ee; font: 14px/1.5 system-ui, "Noto Sans SC", sans-serif; overflow: hidden; }
header { position: fixed; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: #0b1116e6; border-bottom: 1px solid #2a3a45; }
header h1 { margin: 0; font-size: 16px; }
header select { background: #0b1014; color: #dbe6ee; border: 1px solid #3f3f3f; border-radius: 4px; padding: 3px 6px; max-width: 240px; }
header .stats { color: #93a6b3; font-size: 12px; }
#view { position: fixed; inset: 48px 0 0 0; }
#hint { position: fixed; left: 16px; bottom: 12px; color: #6f8390; font-size: 12px; z-index: 2; }
</style>
<script type="importmap">{ "imports": { "three": "./vendor/three.module.js" } }</script>
</head>
<body>
<header>
<h1>生产线参考模型</h1>
<select id="model" aria-label="Reference model"></select>
<span class="stats" id="stats">加载中…</span>
</header>
<div id="view"></div>
<p id="hint">左键旋转 · 滚轮缩放 · 右键平移</p>
<script type="module">
import * as THREE from "three";
import { OrbitControls } from "./vendor/OrbitControls.js";
import { GLTFLoader } from "./vendor/GLTFLoader.js";
const MODELS = [{"file":"ABB_IRB_120.glb","name":"ABB_IRB_120","label":"ABB IRB 120 机器人","dims":[219.36,687.567,699.587],"parts":11},{"file":"Tool.glb","name":"ToolFrame","label":"工具坐标系","dims":[72.244,72.244,72.244],"parts":3},{"file":"三柜子.glb","name":"CabinetA","label":"主控制柜","dims":[1499.932,744.225,754],"parts":8},{"file":"三柜子1.glb","name":"CabinetB","label":"长控制柜","dims":[2969.994,774.283,774.001],"parts":8},{"file":"三色灯.glb","name":"StackLight","label":"三色警示灯","dims":[50,40,468],"parts":2},{"file":"上料.glb","name":"Loader","label":"上料机构","dims":[374.932,140,212],"parts":2},{"file":"传送带送料装置.glb","name":"ConveyorFeeder","label":"传送带送料装置","dims":[613.967,270.043,204.607],"parts":6},{"file":"原料上料.glb","name":"RawFeeder","label":"原料上料装置","dims":[210,208,204.1],"parts":5},{"file":"原料装配.glb","name":"RawAssembly","label":"原料装配平台","dims":[498.3,144.929,338.125],"parts":3},{"file":"原点.glb","name":"OriginMarker","label":"原点标记","dims":[141.682,141.682,141.682],"parts":3},{"file":"地面平面.glb","name":"GroundPlane","label":"地面与地线","dims":[4867.482,3673.23,310.061],"parts":2},{"file":"夹取送料装置.glb","name":"PickFeeder","label":"夹取送料装置","dims":[1026,277.257,455.018],"parts":5},{"file":"平面.001.glb","name":"Plane001","label":"地面平面 001","dims":[4867.482,3673.23,310.061],"parts":2},{"file":"平面.glb","name":"Plane","label":"地面平面","dims":[4867.482,3673.23,310.061],"parts":2},{"file":"推料装置.glb","name":"Pusher","label":"推料装置","dims":[490,336,587.8],"parts":2},{"file":"料仓.glb","name":"Hopper","label":"料仓","dims":[280,250,200],"parts":2},{"file":"新版2.glb","name":"SensorBlock","label":"新版检测块","dims":[21.992,21.967,7],"parts":1},{"file":"旋转运送装置.glb","name":"RotaryTransfer","label":"旋转运送装置","dims":[536.869,536.268,202],"parts":2},{"file":"显示屏.glb","name":"DisplayA","label":"显示屏 A","dims":[249,161.2,312],"parts":2},{"file":"显示屏1.glb","name":"DisplayB","label":"显示屏 B","dims":[249,161.2,312],"parts":2},{"file":"柜门.glb","name":"CabinetDoor","label":"柜门","dims":[30,560,560],"parts":1},{"file":"检测台.glb","name":"InspectionTable","label":"检测台","dims":[75,148.486,325],"parts":1},{"file":"物料存储区.glb","name":"MaterialStore","label":"物料存储区","dims":[351.815,82.979,412.75],"parts":5},{"file":"称重平台.glb","name":"WeighPlatform","label":"称重平台","dims":[200,199.316,175],"parts":2},{"file":"辅助夹爪.glb","name":"AuxGripper","label":"辅助夹爪","dims":[73.312,94.272,102.394],"parts":3},{"file":"运送支架.glb","name":"TransportBracket","label":"运送支架","dims":[60,113.5,310],"parts":1},{"file":"运送检测装置.glb","name":"TransportInspector","label":"运送检测装置","dims":[75,148.486,325],"parts":2}];
const host = document.getElementById("view");
const select = document.getElementById("model");
for (const model of MODELS) {
const option = document.createElement("option");
option.value = model.file;
option.textContent = model.label;
select.appendChild(option);
}
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0d1318);
const camera = new THREE.PerspectiveCamera(42, host.clientWidth / host.clientHeight, 0.001, 1000);
camera.up.set(0, 0, 1);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(host.clientWidth, host.clientHeight);
host.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xffffff, 0x334455, 2.4));
const key = new THREE.DirectionalLight(0xffffff, 2.2); key.position.set(400, 700, 500); scene.add(key);
const fill = new THREE.DirectionalLight(0xffffff, 0.8); fill.position.set(-600, 200, -400); scene.add(fill);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true; controls.dampingFactor = 0.08;
let root = null;
const load = async file => {
document.getElementById("stats").textContent = "加载中…";
if (root) {
scene.remove(root);
root.traverse(child => { if (child.isMesh) { child.geometry?.dispose(); child.material?.dispose?.(); } });
root = null;
}
const gltf = await new GLTFLoader().loadAsync("./line-models/" + encodeURIComponent(file));
root = gltf.scene;
scene.add(root);
const box = new THREE.Box3().setFromObject(root);
const size = box.getSize(new THREE.Vector3());
const center = box.getCenter(new THREE.Vector3());
root.position.sub(center);
const maxSize = Math.max(size.x, size.y, size.z) || 1;
camera.position.set(maxSize * 1.4, -maxSize * 2.0, maxSize * 1.1);
camera.near = maxSize / 500; camera.far = maxSize * 50; camera.updateProjectionMatrix();
controls.target.set(0, 0, 0); controls.update();
let meshes = 0;
root.traverse(child => { if (child.isMesh) meshes++; });
const stats = meshes + " 个网格 · 包围盒 " + size.x.toFixed(2) + " × " + size.y.toFixed(2) + " × " + size.z.toFixed(2) + " m";
document.getElementById("stats").textContent = stats;
window.__lineReferenceStats = { file, meshes, size: [size.x, size.y, size.z], stats };
};
select.addEventListener("change", () => load(select.value).catch(error => {
document.getElementById("stats").textContent = "加载失败:" + String(error?.message ?? error);
}));
addEventListener("resize", () => {
camera.aspect = host.clientWidth / host.clientHeight; camera.updateProjectionMatrix();
renderer.setSize(host.clientWidth, host.clientHeight);
});
const animate = () => { requestAnimationFrame(animate); controls.update(); renderer.render(scene, camera); };
animate();
await load(MODELS[0].file);
window.__lineReferenceReady = true;
</script>
</body>
</html>