100 lines
2.9 KiB
Vue
100 lines
2.9 KiB
Vue
<script setup lang="ts">
|
|
import { reactive, ref, watch } from 'vue';
|
|
import type { Ref } from 'vue'
|
|
import { useRoute } from 'vue-router';
|
|
|
|
import { Vector3 } from 'three';
|
|
import { TresCanvas } from '@tresjs/core';
|
|
import { StatsGl, OrbitControls } from '@tresjs/cientos'
|
|
|
|
import Env from './env.vue'
|
|
import LoadModels from './load_models.vue'
|
|
import Sidebar from './sidebar.vue'
|
|
import { usePromoSidebar } from '../../stores/promo_sidebar';
|
|
|
|
const minPan = ref(new Vector3(-2, -2, -2))
|
|
const maxPan = ref(new Vector3(2, 2, 2))
|
|
const _v = new Vector3();
|
|
const onChange = (e: any) => {
|
|
if (e.target) {
|
|
_v.copy(e.target);
|
|
e.target.clamp(minPan.value, maxPan.value);
|
|
_v.sub(e.target);
|
|
camera.value.position.sub(_v);
|
|
}
|
|
}
|
|
const loadedPan = (max: any, min: any) => {
|
|
maxPan.value = max
|
|
minPan.value = min
|
|
}
|
|
const sidebar = usePromoSidebar()
|
|
|
|
const camera = ref()
|
|
const cameraPosition = ref([1, 1, 1]) as unknown as Ref<Vector3>
|
|
|
|
const controlsState = reactive({
|
|
maxPolarAngle: (Math.PI / 2) - 0.05,
|
|
minAzimuthAngle: (Math.PI / 2) - 0.02,
|
|
})
|
|
const models_loading = ref(false)
|
|
const set_model_load_status = () => {
|
|
models_loading.value = !models_loading.value
|
|
}
|
|
|
|
const route = useRoute()
|
|
const source = ref(route.params.target ? (route.params.target.toString() + '/') : '1/')
|
|
watch(() => route.params.target, () => {
|
|
let t = '1/'
|
|
if (route.params.target) t = route.params.target.toString() + '/'
|
|
if (source.value !== t) {
|
|
source.value = t
|
|
models_loading.value = false
|
|
sidebar.close()
|
|
}
|
|
}, { deep: true })
|
|
</script>
|
|
<template>
|
|
<div>
|
|
<div :class="[{ 'loading': !models_loading }, 'canvas-wrapper']">
|
|
<TresCanvas shadows window-size>
|
|
<Suspense>
|
|
<StatsGl />
|
|
</Suspense>
|
|
<TresPerspectiveCamera :position="cameraPosition" ref="camera" />
|
|
<OrbitControls v-bind="controlsState" @change="onChange" make-default />
|
|
<Suspense>
|
|
<Env />
|
|
</Suspense>
|
|
<Suspense>
|
|
<LoadModels :source="source" :loaded="set_model_load_status" :loaded_pan="loadedPan" />
|
|
</Suspense>
|
|
<TresMesh cast-shadow>
|
|
|
|
<TresMeshStandardMaterial />
|
|
</TresMesh>
|
|
<TresMesh :position-y="0" :rotate-x="-Math.PI / 2" receive-shadow>
|
|
<TresPlaneGeometry :args="[200, 200]" />
|
|
<TresShadowMaterial :opacity="0.2" />
|
|
</TresMesh>
|
|
</TresCanvas>
|
|
</div>
|
|
<Sidebar />
|
|
</div>
|
|
</template>
|
|
<style scoped lang="scss">
|
|
.canvas-wrapper {
|
|
overflow: hidden;
|
|
height: 100vh;
|
|
width: 100vw;
|
|
position: absolute;
|
|
right: 0;
|
|
left: 0;
|
|
top: 0;
|
|
bottom: 0;
|
|
}
|
|
|
|
.loading {
|
|
filter: blur(10px);
|
|
transition: all 300ms linear;
|
|
}
|
|
</style> |