longyvfengyun
2024-05-30 65bfa203472373638e407778c6af06b38f666ad3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<script setup lang="ts">
import {onMounted} from "vue";
import * as THREE from 'three';
import UserAPI from "@/api/user";
import type {Mesh,Camera, Scene, WebGLRenderer} from "three";
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
import stoolGlb from '@/assets/3d/stool.glb';
 
const edit = ref('plus');
const threeRef = ref<HTMLElement|null>(null);
async function getUserList() {
    try {
        const rs = await UserAPI.getUserList();
        console.log(rs);
    }catch (e) {
        console.log(e);
    }
}
 
async function userLogin() {
    try {
        const rs = await UserAPI.login({
            username: '霍东伟',
            password: '123456',
        });
        console.log(rs);
    }catch (e) {
        console.log(e);
    }
}
 
let camera:Camera, scene:Scene, mesh:Mesh, renderer:WebGLRenderer, loader;
 
function animation( time:number ) {
 
    mesh.rotation.x = time / 2000;
    mesh.rotation.y = time / 1000;
 
    renderer.render( scene, camera );
 
}
 
onMounted(()=>{
    const width = (threeRef.value as HTMLElement).offsetWidth, height = (threeRef.value as HTMLElement).offsetHeight;
    camera = new THREE.PerspectiveCamera( 70, width / height, 0.01, 10 );
    camera.position.z = 1;
 
    scene = new THREE.Scene();
 
    const geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
    const material = new THREE.MeshNormalMaterial();
 
    mesh = new THREE.Mesh( geometry, material );
    // scene.add( mesh );
 
    const loader = new GLTFLoader();
    loader.load(stoolGlb, function (gltf) {
        scene.add(gltf.scene);
        // 可以在这里添加更多逻辑,比如设置模型位置、旋转等
    }, function (xhr) {
        console.log((xhr.loaded / xhr.total * 100) + '% loaded');
    }, function (error) {
        console.error('An error happened', error);
    });
 
    const ambientLight = new THREE.AmbientLight(0x404040); // 柔和的白色光
    scene.add(ambientLight);
 
    // 添加定向光
    const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
    directionalLight.position.set(-1, 2, 4).normalize();
    scene.add(directionalLight);
 
    renderer = new THREE.WebGLRenderer( { antialias: true } );
    renderer.setSize( width, height );
    renderer.render( scene, camera );
    renderer.setAnimationLoop( animation );
 
    const controls = new OrbitControls(camera, renderer.domElement);
    controls.enableZoom = true;
    (threeRef.value as HTMLElement).appendChild( renderer.domElement );
});
</script>
 
<template>
    <div class="page-root-container">
        <el-container>
            <el-header></el-header>
            <el-main>
                <div ref="threeRef" style="height:600px">
 
                </div>
                <el-button type="primary" @click="userLogin">123</el-button>
                <el-tag>123</el-tag>
                <el-table></el-table>
                <el-icon>
                    <component :is="edit"></component>
                </el-icon>
                <el-icon>
                    <component :is="edit"></component>
                </el-icon>
                <div class="page-container">
                    <div class="page-content"></div>
                </div>
                <div class="icon-item">
                    <svg-icon icon-class="api" size="40px"></svg-icon>
                </div>
            </el-main>
        </el-container>
    </div>
</template>
 
<style scoped lang="less">
.page-root-container {
    height: 100vh;
}
.page-container {
    .page-content {
        height: 200px;
        background-color: #FF0000;
    }
}
</style>