153 Star 2.1K Fork 525

ICEGL/icegl-three-vue-tres

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
theBasic.vue 3.21 KB
一键复制 编辑 原始数据 按行查看 历史
地虎降天龙 提交于 2024-07-18 10:39 . 升级了
<template>
<TresCanvas v-bind="state" window-size>
<TresPerspectiveCamera :position="[15, 15, 15]" :fov="45" :near="0.1" :far="1000" :look-at="[0, 0, 0]" />
<OrbitControls v-bind="controlsState" />
<TresAmbientLight :intensity="0.5" />
<TresMesh ref="sphereRef" :position="[0, 4, 0]" cast-shadow @pointer-enter="onPointerEnter" @pointer-leave="onPointerLeave">
<TresSphereGeometry :args="[2, 32, 32]" />
<TresMeshToonMaterial color="#006060" />
</TresMesh>
<TresMesh ref="sphereRef2" :position="[4, 4, 0]" cast-shadow @pointer-enter="onPointerEnter" @pointer-leave="onPointerLeave">
<TresSphereGeometry :args="[2, 32, 32]" />
<TresMeshToonMaterial color="#006060" />
</TresMesh>
<TresMesh :rotation="[-Math.PI / 2, 0, 0]" receive-shadow>
<TresPlaneGeometry :args="[20, 20, 20, 20]" />
<TresMeshToonMaterial />
</TresMesh>
<TresDirectionalLight ref="TDirectionalLight" :position="[10, 8, 4]" :intensity="1" cast-shadow />
<TresDirectionalLight :position="[10, 2, 4]" :intensity="1" cast-shadow />
<TresGridHelper :position-y="0.1" />
</TresCanvas>
</template>
<script setup lang="ts">
import { SRGBColorSpace, BasicShadowMap, NoToneMapping } from 'three'
import { reactive, ref, onMounted, shallowRef, watchEffect } from 'vue'
import { useRenderLoop } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
const state = reactive({
clearColor: '#201919',
shadows: true,
alpha: false,
shadowMapType: BasicShadowMap,
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
})
const controlsState = reactive({
enableDamping: true,
dampingFactor: 0.05,
enableZoom: true,
autoRotate: false,
autoRotateSpeed: 2,
maxPolarAngle: Math.PI,
minPolarAngle: 0,
maxAzimuthAngle: Math.PI,
minAzimuthAngle: -Math.PI,
enablePan: true,
keyPanSpeed: 7,
maxDistance: 100,
minDistance: 0,
minZoom: 0,
maxZoom: 100,
zoomSpeed: 1,
enableRotate: true,
rotateSpeed: 1,
})
const sphereRef = ref()
const sphereRef2 = ref()
const TDirectionalLight = shallowRef()
// const { onLoop, pause, resume } = useRenderLoop()
const { onLoop } = useRenderLoop()
onLoop(({ elapsed }) => {
if (!sphereRef.value) return
sphereRef.value.position.y += Math.sin(elapsed) * 0.01
sphereRef2.value.position.y += Math.sin(elapsed) * 0.01
})
function onPointerEnter(ev: any) {
if (ev) {
ev.object.material.color.set('#DFFF45')
// pause()
}
}
function onPointerLeave(ev: any) {
if (ev) {
ev.eventObject.material.color.set('#006060')
// resume()
}
}
watchEffect(() => {
if (TDirectionalLight.value) {
TDirectionalLight.value.shadow.mapSize.set(1000, 1000)
TDirectionalLight.value.shadow.camera.near = 0.5 // default
// TDirectionalLight.value.shadow.camera.far = 50000; // default
TDirectionalLight.value.shadow.camera.top = 20
TDirectionalLight.value.shadow.camera.right = 20
TDirectionalLight.value.shadow.camera.left = -20
TDirectionalLight.value.shadow.camera.bottom = -20
}
})
onMounted(() => {})
</script>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/ice-gl/icegl-three-vue-tres.git
git@gitee.com:ice-gl/icegl-three-vue-tres.git
ice-gl
icegl-three-vue-tres
icegl-three-vue-tres
master

搜索帮助