Browse Source

Merge remote-tracking branch 'origin/master'

master
修宁 6 months ago
parent
commit
2fffe5fb4d
  1. 404
      src/components/Model3DView.vue

404
src/components/Model3DView.vue

@ -16,7 +16,7 @@
<el-button>打开材质</el-button>
</el-upload>
<el-button @click="addConveyor">添加输送线</el-button>
<el-button @click="createShelf">添加货架</el-button>
<el-button @click="createShelf">添加货架2</el-button>
<el-button @click="createGroundStore">添加地堆</el-button>
<div class="demo-color-block">
<span class="demonstration">材质颜色</span>
@ -86,10 +86,9 @@ import { TransformControls } from 'three/examples/jsm/controls/TransformControls
import Split from '@/components/split/split.vue'
import SplitArea from '@/components/split/split-area.vue'
import { renderIcon } from '@/utils/webutils.js'
import textureUrl from '@/assets/images/conveyor/shapes/RibSideSkirtThumbnail.jpg'
import moveUrl from '@/assets/images/conveyor/shapes/move.svg'
import arrowRightUrl from '@/assets/images/conveyor/shapes/arrow-right.svg'
import rackUrl from '@/assets/images/conveyor/shapes/Rack.png'
import rackPlatUrl from "@/assets/images/conveyor/shapes/RackPlatform.png";
import rackBlue from "@/assets/images/conveyor/shapes/Rack-blue.png";
import triangleUrl from "@/assets/images/conveyor/shapes/triangle.png";
// DOM refs
const canvasContainer = ref(null)
@ -169,77 +168,119 @@ watch(() => restate.mode, (newVal) => {
tcontrols.setMode(newVal)
}
})
function addConveyor(){//线
// 1. 10 0.8
const length = 20; // (X)
const width = 0.8; // (Y)
const height = 0.2; // / (Z)
const geometry = new THREE.BoxGeometry(length, width, height);
// 2.
const textureLoader = new THREE.TextureLoader();
textureLoader.load(textureUrl, (texture)=>{
// 3.
texture.wrapS = THREE.RepeatWrapping; // X
texture.wrapT = THREE.RepeatWrapping; // Y
texture.center.set(0.5,0.5)
texture.rotation = Math.PI / 2
texture.repeat.set(1, 1); //
// 4. 线Y
// 256px 0.8m
// repeat.y = 0.8 / (texture.height / texture.width * length)
// repeat.y
texture.repeat.set(1, 20); // Y
// 5.
const material = new THREE.MeshBasicMaterial(
{ map: texture,color: 0x9f9f9f});
// 6.
const conveyorBelt = new THREE.Mesh(geometry, material);
// 7. XPlaneGeometryX/Y
conveyorBelt.rotation.x = -Math.PI / 2; // X/Z
//
conveyorBelt.position.y = height / 2; //
// // 线
addMarkerAt(-9.5, height,0,moveUrl); //
addMarkerAt(0, height,0,arrowRightUrl); //
addMarkerAt(9.5, height,0,moveUrl); //
scene.add(conveyorBelt)
//
let offsetSpeed = 0.01; //
function animate() {
requestAnimationFrame(animate);
// 沿Y
if (texture) {
let currentOffset = texture.offset.y;
currentOffset += offsetSpeed;
// 1
if (currentOffset >= 1) {
currentOffset -= 1;
}
texture.offset.set(texture.offset.x,currentOffset);
}
renderer.render(scene, camera);
}
animate();
function addConveyor(){
const conveyorLength = 10; //
const conveyorWidth = 0.8; //
const conveyorHeight = 0.08; //
const wallHeight = conveyorHeight + 0.15; // 线 0.2
const legWidth = 0.1; // X
const legDepth = 0.1; // Z
const legHeight = 0.8; // Y
// 线
const conveyorGeometry = new THREE.BoxGeometry(conveyorWidth, conveyorHeight, conveyorLength);
const conveyorMaterial = new THREE.MeshBasicMaterial({ color: 0x6a6a6a });
const conveyor = new THREE.Mesh(conveyorGeometry, conveyorMaterial);
conveyor.position.y = conveyorHeight / 2;
//
const wallWidth = 0.05;
const wallGeometry = new THREE.BoxGeometry(wallWidth, wallHeight, conveyorLength);
const wallMaterial = new THREE.MeshBasicMaterial({ color: 0x6a6a6a });
const leftWall = new THREE.Mesh(wallGeometry, wallMaterial);
leftWall.position.set(-(conveyorWidth / 2 + wallWidth / 2), wallHeight / 2, 0);
const rightWall = new THREE.Mesh(wallGeometry, wallMaterial);
rightWall.position.set((conveyorWidth / 2 + wallWidth / 2), wallHeight / 2, 0);
//
const legGeometry = new THREE.BoxGeometry(legWidth, legHeight, legDepth);
const legMaterial = new THREE.MeshBasicMaterial({ color: 0x6a6a6a }); //
const legPositions = [
[conveyorWidth / 2 - legWidth / 2, -(conveyorLength / 2 - legDepth / 2)], //
[-conveyorWidth / 2 + legWidth / 2, -(conveyorLength / 2 - legDepth / 2)], //
[conveyorWidth / 2 - legWidth / 2, +(conveyorLength / 2 - legDepth / 2)], //
[-conveyorWidth / 2 + legWidth / 2, +(conveyorLength / 2 - legDepth / 2)] //
];
const legs = [];
legPositions.forEach(pos => {
const leg = new THREE.Mesh(legGeometry, legMaterial);
leg.position.set(
pos[0],
-legHeight / 2,
pos[1]
);
legs.push(leg);
});
}
function addMarkerAt(x, y,z,textUrl, scale = 1) {
// ====== ======
const beamWidth = conveyorWidth; // 线0.8
const beamLength = conveyorLength-conveyorHeight/2;// 线10
const beamHeight = 0.08; // 0.1
// Shape
const shape = new THREE.Shape();
const radius = beamHeight / 2; // =
//
shape.absarc(-beamLength / 2, 0, radius, Math.PI / 2, -Math.PI / 2, false);
//
shape.absarc(beamLength / 2, 0, radius, -Math.PI / 2, Math.PI / 2, false);
shape.closePath(); //
//
const extrudeSettings = {
depth: beamWidth,
steps: 16,
bevelEnabled: false
};
const beamGeometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
const beamMaterial = new THREE.MeshBasicMaterial({ color: 0x032702 }); //
const beam = new THREE.Mesh(beamGeometry, beamMaterial);
beam.rotation.x = Math.PI / 2;
beam.rotation.z = Math.PI / 2
beam.rotation.y = Math.PI / 2
beam.position.y = beamHeight+conveyorHeight/2; // 线
beam.position.x = -beamWidth/2;
addMarkerAt(0, legHeight+beamHeight+conveyorHeight,0,triangleUrl,1,false);
addMarkerAt(beamWidth/2+wallWidth+0.01, legHeight+wallHeight/2,0,triangleUrl,.5,true);
addMarkerAt(beamWidth/2+wallWidth+0.01, legHeight+wallHeight/2,conveyorLength/4,triangleUrl,.5,true);
addMarkerAt(beamWidth/2+wallWidth+0.01, legHeight+wallHeight/2,-conveyorLength/4,triangleUrl,.5,true);
addMarkerAt(-(beamWidth/2+wallWidth+0.01), legHeight+wallHeight/2,0,triangleUrl,.5,true);
addMarkerAt(-(beamWidth/2+wallWidth+0.01), legHeight+wallHeight/2,conveyorLength/4,triangleUrl,.5,true);
addMarkerAt(-(beamWidth/2+wallWidth+0.01), legHeight+wallHeight/2,-conveyorLength/4,triangleUrl,.5,true);
//
const group = new THREE.Group();
group.add(conveyor);
group.add(leftWall);
group.add(rightWall);
legs.forEach(leg => group.add(leg));
group.add(beam); //
// 沿Z 1
group.position.y = legHeight; //
scene.add(group);
}
function addMarkerAt(x, y,z,textUrl, scale = 1,lip) {
const loader = new THREE.TextureLoader();
loader.load(textUrl, (texture) => {
//
const markerGeometry = new THREE.PlaneGeometry(.6 * scale, 0.5 * scale); //
let markerGeometry
if(lip){
markerGeometry=new THREE.PlaneGeometry(.25 * scale, .25 * scale);
}else{
markerGeometry = new THREE.PlaneGeometry(.45 * scale, .3 * scale); //
}
const markerMaterial = new THREE.MeshBasicMaterial({
map: texture,
@ -257,126 +298,172 @@ function addMarkerAt(x, y,z,textUrl, scale = 1) {
// X/Z 线
marker.rotation.x = -Math.PI / 2; // conveyorBelt
marker.rotation.z = Math.PI / 2; // 90
if(lip){
marker.rotation.y = Math.PI / 2; // 90
}else{
marker.rotation.y = Math.PI;
}
scene.add(marker);
});
}
function createShelf(){//
const textureLoader = new THREE.TextureLoader();
const metalTexture = textureLoader.load('path/to/your/metal/texture.jpg'); //
const shelfLength = 5;
const shelfWidth = 0.8;
const shelfThickness = 0.02;
const rows = 3;
const columns = 4;
const spacingY = 1; //
const gapBetweenPlanks = 0.1; //
const baseHeight = 0; // 0
const unitLength = (shelfLength - (columns - 1) * gapBetweenPlanks) / columns;
//
const material = new THREE.MeshStandardMaterial({
map: metalTexture,
metalness: 1.0,
roughness: 0.5
const textureLoader = new THREE.TextureLoader();
const shelfTexture = textureLoader.load(rackPlatUrl, () => {
renderer.render(scene, camera);
});
const redPoleTexture = textureLoader.load(rackBlue, () => {
renderer.render(scene, camera); //
});
//
const shelfLength = 10; //
const shelfWidth = 0.8; //
const shelfThickness = 0.1; //
const rows = 3; //
const columns = 4; //
const spacingY = 1; //
shelfTexture.wrapS = THREE.RepeatWrapping;
shelfTexture.wrapT = THREE.RepeatWrapping;
shelfTexture.repeat.set(1, 20);
shelfTexture.rotation = Math.PI / 2;
const shelfMaterial = new THREE.MeshPhongMaterial({
map: shelfTexture,
color: 0x999999,
shininess: 60
});
const unitLength = shelfLength / columns; // 2.5m
//
const poleMaterial = new THREE.MeshPhongMaterial({
map: shelfTexture,
color: 0x333333,
shininess: 60
});
//
const baseHeight = 2; //
//
const poleSize = gapBetweenPlanks; //
const totalHeight = rows * spacingY; //
// ---------------------
// 3 × 4
// ---------------------
for (let row = 0; row < rows; row++) {
let currentXOffset = -shelfLength / 2;
for (let col = 0; col < columns; col++) {
const geometry = new THREE.BoxGeometry(unitLength, shelfThickness, shelfWidth);
const mesh = new THREE.Mesh(geometry, material);
const mesh = new THREE.Mesh(geometry, shelfMaterial);
const x = -shelfLength / 2 + unitLength * col + unitLength / 2;
const y = -(shelfThickness + spacingY) * row - shelfThickness / 2 + baseHeight; //
const x = currentXOffset + unitLength / 2;
// Y 使
const y = baseHeight + row * spacingY + shelfThickness / 2;
const z = 0;
mesh.position.set(x, y, z);
scene.add(mesh);
}
}
// ---------------------
//
// ---------------------
const thirdShelfCenterY = -(shelfThickness + spacingY) * 2 - shelfThickness / 2 + baseHeight;
const thirdShelfBottomY = thirdShelfCenterY - shelfThickness / 2;
// ---------------------
// +
// ---------------------
const postWidth = 0.1;
const postDepth = 0.1;
const postHeight = 3.3;
if (row === 0) { //
//
if (col === 0) {
const leftPoleX = currentXOffset - poleSize / 2;
const leftPoleY = baseHeight + totalHeight / 2;
const leftPoleZ = z - shelfWidth / 2 + poleSize / 2;
//
const leftPole = new THREE.Mesh(
new THREE.BoxGeometry(poleSize, totalHeight, poleSize),
poleMaterial
);
leftPole.position.set(leftPoleX, leftPoleY, leftPoleZ);
scene.add(leftPole);
// //
const redLeftPoleZ = z + shelfWidth / 2 - poleSize / 2;
const redLeftPole = new THREE.Mesh(
new THREE.BoxGeometry(poleSize, totalHeight, poleSize),
new THREE.MeshPhongMaterial({
map: redPoleTexture,
color: 0xffffff, //
shininess: 60,
transparent: true,
})
// new THREE.MeshPhongMaterial({ color: 0xff0000, shininess: 60 })
);
redLeftPole.position.set(leftPoleX, leftPoleY, redLeftPoleZ);
scene.add(redLeftPole);
}
//
if (col < columns - 1) {
const gapStartX = currentXOffset + unitLength;
//
const poleX = gapStartX + poleSize / 2;
const poleY = baseHeight + totalHeight / 2;
const poleZ = z- shelfWidth / 2+poleSize/2;
const pole = new THREE.Mesh(
new THREE.BoxGeometry(poleSize, totalHeight, poleSize),
poleMaterial
);
pole.position.set(poleX, poleY, poleZ);
scene.add(pole);
const postPositionsX = [0, 2.5, 5, 7.5, 10];
const postPositionsZ = [-shelfWidth / 2, shelfWidth / 2];
//
const redPoleX = poleX; // X
const redPoleY = poleY; // Y
const redPoleZ = z + shelfWidth / 2-poleSize/2; //
// PNG
const loader = new THREE.TextureLoader();
loader.load(rackUrl, (texture) => {
//
const stickerMaterial = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide //
const redPoleMaterial = new THREE.MeshPhongMaterial({
color: 0xff0000,
shininess: 60
});
postPositionsX.forEach(x => {
postPositionsZ.forEach(z => {
//
const postGeometry = new THREE.BoxGeometry(postWidth, postHeight, postDepth);
const post = new THREE.Mesh(postGeometry, material);
// Y 使
const postCenterY = thirdShelfBottomY + postHeight / 2;
post.position.set(
x - shelfLength / 2,
postCenterY,
z
const redPole = new THREE.Mesh(
new THREE.BoxGeometry(poleSize, totalHeight, poleSize),
redPoleMaterial
);
redPole.position.set(redPoleX, redPoleY, redPoleZ);
scene.add(redPole);
}
scene.add(post);
// ---------------------
//
// ---------------------
const stickerWidth = 0.08; //
const stickerHeight = 0.2; //
const stickerGeometry = new THREE.PlaneGeometry(stickerWidth, stickerHeight);
const sticker = new THREE.Mesh(stickerGeometry, stickerMaterial);
//
if (col === columns - 1) {
const rightPoleX = currentXOffset + unitLength + gapBetweenPlanks - poleSize / 2;
const rightPoleY = baseHeight + totalHeight / 2;
const rightPoleZ = z - shelfWidth / 2 + poleSize / 2;
//
sticker.position.set(
post.position.x + postWidth / 2, //
post.position.y, // Y
post.position.z // Z
//
const rightPole = new THREE.Mesh(
new THREE.BoxGeometry(poleSize, totalHeight, poleSize),
poleMaterial
);
rightPole.position.set(rightPoleX, rightPoleY, rightPoleZ);
scene.add(rightPole);
//
const redRightPoleZ = z + shelfWidth / 2 - poleSize / 2;
const redRightPole = new THREE.Mesh(
new THREE.BoxGeometry(poleSize, totalHeight, poleSize),
new THREE.MeshPhongMaterial({ color: 0xff0000, shininess: 60 })
);
redRightPole.position.set(rightPoleX, rightPoleY, redRightPoleZ);
scene.add(redRightPole);
}
}
//
// 使 dcm.orientation.lookAt(camera.position)
//
sticker.lookAt(new THREE.Vector3(1, 0, 0)); // X
//
sticker.position.x += 0.01;
currentXOffset += unitLength + gapBetweenPlanks;
}
}
scene.add(sticker);
});
});
})
//
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(5, 10, 7);
scene.add(directionalLight);
}
function createGroundStore() {
@ -888,6 +975,7 @@ function cleanupThree() {
padding: 10px;
background: #f5f5f5;
border-bottom: 1px solid #ccc;
flex-wrap: wrap;
}
.dialog-container {

Loading…
Cancel
Save