|
| 1 | +<template> |
| 2 | + <div class="demoA"> |
| 3 | + <div |
| 4 | + ref="tipRef" |
| 5 | + class="demoA-tip" |
| 6 | + :style="{ |
| 7 | + transform: `translate(${tipLeft}px, ${tipTop + 50}px)`, |
| 8 | + zIndex: showTip ? 99 : -1 |
| 9 | + }" |
| 10 | + > |
| 11 | + <div class="demoA-tip-title">{{ tipTitle }}</div> |
| 12 | + <div class="demoA-tip-content">{{ tipContent }}</div> |
| 13 | + </div> |
| 14 | + <div ref="containerRef" class="demoA-container"></div> |
| 15 | + <div class="demoA-bottom-bar"> |
| 16 | + <div |
| 17 | + v-for="space in spacesConfig" |
| 18 | + :key="space.id" |
| 19 | + class="demoA-bottom-card" |
| 20 | + :style="{ |
| 21 | + backgroundImage: `url(${space.cubeSpaceTextureUrls.left})` |
| 22 | + }" |
| 23 | + @click="handleSwitchSpace(space)" |
| 24 | + ></div> |
| 25 | + </div> |
| 26 | + </div> |
| 27 | +</template> |
| 28 | + |
| 29 | +<script setup lang="ts"> |
| 30 | +/* eslint-disable import/no-named-as-default-member */ |
| 31 | +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ |
| 32 | +import {onMounted, ref} from 'vue' |
| 33 | +import type {SpaceConfig} from '@nicepkg/vr360-core' |
| 34 | +import {Vr360} from '@nicepkg/vr360-core' |
| 35 | +import textures from '../../../../textures.json' |
| 36 | +
|
| 37 | +const containerRef = ref<HTMLElement>() |
| 38 | +
|
| 39 | +const tipRef = ref<HTMLElement>() |
| 40 | +const tipLeft = ref(0) |
| 41 | +const tipTop = ref(0) |
| 42 | +const showTip = ref(false) |
| 43 | +const tipTitle = ref('') |
| 44 | +const tipContent = ref('') |
| 45 | +
|
| 46 | +let vr360: InstanceType<typeof Vr360> |
| 47 | +
|
| 48 | +const spacesConfig = ref<SpaceConfig[]>([ |
| 49 | + { |
| 50 | + id: 'roomA', |
| 51 | + camera: { |
| 52 | + position: { |
| 53 | + x: 0, |
| 54 | + y: 0, |
| 55 | + z: 0 |
| 56 | + } |
| 57 | + }, |
| 58 | + tips: [ |
| 59 | + { |
| 60 | + id: '1', |
| 61 | + position: {x: 0, y: -10, z: 40}, |
| 62 | + content: { |
| 63 | + title: '豪华跑车', |
| 64 | + text: '比奥迪还贵的豪华跑车' |
| 65 | + } |
| 66 | + }, |
| 67 | + { |
| 68 | + id: '2', |
| 69 | + textureUrl: textures.hotpot, |
| 70 | + targetSpaceId: 'roomB', |
| 71 | + position: {x: -10, y: -4, z: 40}, |
| 72 | + content: { |
| 73 | + title: '去客厅', |
| 74 | + text: '一起去尊贵的客厅吧' |
| 75 | + } |
| 76 | + } |
| 77 | + ], |
| 78 | + cubeSpaceTextureUrls: textures.firstHouseDoor |
| 79 | + }, |
| 80 | + { |
| 81 | + id: 'roomB', |
| 82 | + camera: { |
| 83 | + position: { |
| 84 | + x: 0, |
| 85 | + y: 0, |
| 86 | + z: 0 |
| 87 | + } |
| 88 | + }, |
| 89 | + tips: [ |
| 90 | + { |
| 91 | + id: '3', |
| 92 | + position: {x: -2, y: -25, z: 40}, |
| 93 | + content: { |
| 94 | + title: '香奈儿垃圾桶', |
| 95 | + text: '里面装着主人不用的奢侈品' |
| 96 | + } |
| 97 | + }, |
| 98 | + { |
| 99 | + id: '4', |
| 100 | + position: {x: -20, y: 0, z: 40}, |
| 101 | + content: { |
| 102 | + title: '宇宙牌冰箱', |
| 103 | + text: '装着超级多零食' |
| 104 | + } |
| 105 | + }, |
| 106 | + { |
| 107 | + id: '5', |
| 108 | + textureUrl: textures.hotpot, |
| 109 | + targetSpaceId: 'roomA', |
| 110 | + position: { |
| 111 | + x: -8, |
| 112 | + y: 0, |
| 113 | + z: -40 |
| 114 | + }, |
| 115 | + content: { |
| 116 | + title: '去门口', |
| 117 | + text: '一起去门口吧' |
| 118 | + } |
| 119 | + } |
| 120 | + ], |
| 121 | + cubeSpaceTextureUrls: textures.firstHouseLivingRoom |
| 122 | + } |
| 123 | +]) |
| 124 | +
|
| 125 | +function handleSwitchSpace(space: SpaceConfig) { |
| 126 | + vr360.switchSpace(space.id) |
| 127 | +} |
| 128 | +
|
| 129 | +onMounted(() => { |
| 130 | + vr360 = new Vr360({ |
| 131 | + container: containerRef.value!, |
| 132 | + tipContainer: tipRef.value!, |
| 133 | + spacesConfig: spacesConfig.value |
| 134 | + }) |
| 135 | +
|
| 136 | + vr360.controls.autoRotate = true |
| 137 | +
|
| 138 | + vr360.render() |
| 139 | +
|
| 140 | + vr360.listenResize() |
| 141 | +
|
| 142 | + vr360.on('showTip', e => { |
| 143 | + vr360!.controls.autoRotate = false |
| 144 | + const {top, left, tip} = e |
| 145 | + showTip.value = true |
| 146 | + tipLeft.value = left |
| 147 | + tipTop.value = top |
| 148 | + tipTitle.value = tip.content.title |
| 149 | + tipContent.value = tip.content.text |
| 150 | + }) |
| 151 | +
|
| 152 | + vr360.on('hideTip', () => { |
| 153 | + vr360!.controls.autoRotate = true |
| 154 | + showTip.value = false |
| 155 | + }) |
| 156 | +}) |
| 157 | +</script> |
| 158 | +<style> |
| 159 | +.demoA { |
| 160 | + position: relative; |
| 161 | + display: flex; |
| 162 | + flex-direction: column; |
| 163 | + width: 100%; |
| 164 | + height: 500px; |
| 165 | + margin-bottom: 4rem; |
| 166 | + overflow: hidden; |
| 167 | + background-color: var(--c-bg); |
| 168 | + border: 1px solid var(--c-border); |
| 169 | + border-radius: 8px; |
| 170 | +} |
| 171 | +
|
| 172 | +.demoA-tip { |
| 173 | + position: absolute; |
| 174 | + top: 0; |
| 175 | + left: 0; |
| 176 | + z-index: 99; |
| 177 | + display: flex; |
| 178 | + flex-direction: column; |
| 179 | + justify-content: center; |
| 180 | + width: 240px; |
| 181 | + height: 60px; |
| 182 | + padding: 4px; |
| 183 | + color: #fff; |
| 184 | + cursor: pointer; |
| 185 | + background-color: rgba(0, 0, 0, 0.5); |
| 186 | + border-radius: 4px; |
| 187 | +} |
| 188 | +
|
| 189 | +.demoA-tip-title { |
| 190 | + font-weight: bold; |
| 191 | +} |
| 192 | +
|
| 193 | +.demoA-container { |
| 194 | + width: 100%; |
| 195 | + height: 100%; |
| 196 | +} |
| 197 | +
|
| 198 | +.demoA-bottom-bar { |
| 199 | + display: flex; |
| 200 | + align-items: center; |
| 201 | + width: 100%; |
| 202 | + height: 100px; |
| 203 | +} |
| 204 | +
|
| 205 | +.demoA-bottom-card { |
| 206 | + width: 140px; |
| 207 | + height: 70px; |
| 208 | + margin-left: 1rem; |
| 209 | + cursor: pointer; |
| 210 | + background-repeat: no-repeat; |
| 211 | + background-size: cover; |
| 212 | + border-radius: 4px; |
| 213 | +} |
| 214 | +</style> |
0 commit comments