|
|
@ -1,9 +1,47 @@ |
|
|
|
<script setup lang="ts"> |
|
|
|
import * as THREE from 'three' |
|
|
|
import { onMounted, ref } from 'vue' |
|
|
|
|
|
|
|
const container = ref<HTMLDivElement>() |
|
|
|
let scene: THREE.Scene |
|
|
|
let camera: THREE.PerspectiveCamera |
|
|
|
let renderer: THREE.WebGLRenderer |
|
|
|
// let controls: OrbitControls |
|
|
|
// let twinModel: THREE.Group // 数字孪生模型 |
|
|
|
|
|
|
|
const initThree = () => { |
|
|
|
scene = new THREE.Scene() |
|
|
|
scene.background = new THREE.Color(0xEEEEEE) |
|
|
|
// 创建相机 |
|
|
|
camera = new THREE.PerspectiveCamera( |
|
|
|
75, |
|
|
|
container.value?.clientWidth / container.value?.clientHeight, |
|
|
|
0.1, |
|
|
|
1000, |
|
|
|
) |
|
|
|
camera.position.set(5, 5, 5) |
|
|
|
// 创建渲染器 |
|
|
|
renderer = new THREE.WebGLRenderer({ antialias: true }) |
|
|
|
renderer.setSize(container.value?.clientWidth || 0, container.value?.clientHeight || 0) |
|
|
|
renderer.setPixelRatio(window.devicePixelRatio) |
|
|
|
container.value?.appendChild(renderer.domElement) |
|
|
|
|
|
|
|
// 添加环境光 |
|
|
|
const ambientLight = new THREE.AmbientLight(0xFFFFFF, 0.8) |
|
|
|
scene.add(ambientLight) |
|
|
|
// 添加点光源 |
|
|
|
const pointLight = new THREE.PointLight(0xFFFFFF, 1) |
|
|
|
pointLight.position.set(5, 5, 5) |
|
|
|
scene.add(pointLight) |
|
|
|
} |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
initThree() |
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|
<template> |
|
|
|
<div>数据模型</div> |
|
|
|
<div ref="container" /> |
|
|
|
</template> |
|
|
|
|
|
|
|
<style scoped lang="scss"> |
|
|
|