11import { usePageFrontmatter , withBase } from "@vuepress/client" ;
2- import { type Mesh , type default as Three } from "three" ;
3- import { type OrbitControls } from "three/examples/jsm/controls/OrbitControls.js" ;
4- import { type STLLoader } from "three/examples/jsm/loaders/STLLoader.js" ;
5- import {
6- type VNode ,
7- computed ,
8- defineComponent ,
9- h ,
10- onMounted ,
11- ref ,
12- watch ,
13- } from "vue" ;
14- import { type ThemeProjectHomePageFrontmatter } from "vuepress-theme-hope" ;
2+ // eslint-disable-next-line
3+ import type * as Three from "three" ;
4+ // eslint-disable-next-line
5+ import type { Mesh } from "three" ;
6+ import type { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js" ;
7+ import type { STLLoader } from "three/examples/jsm/loaders/STLLoader.js" ;
8+ import type { VNode } from "vue" ;
9+ import { computed , defineComponent , h , onMounted , ref , watch } from "vue" ;
10+ import type { ThemeProjectHomePageFrontmatter } from "vuepress-theme-hope" ;
1511
1612// @ts -ignore
1713import { useWindowSize } from "@theme-hope/composables/index" ;
14+ // @ts -ignore
15+ import { useDarkmode } from "@theme-hope/modules/outlook/composables/index" ;
1816
1917import "./hope-logo.scss" ;
2018
19+ const BASE = "https://theme-hope-assets.vuejs.press/model/" ;
20+
2121export default defineComponent ( {
2222 name : "HopeLogo" ,
2323
2424 setup ( ) {
2525 const frontmatter = usePageFrontmatter < ThemeProjectHomePageFrontmatter > ( ) ;
26+ const { isDarkmode } = useDarkmode ( ) ;
2627 const { isMobile } = useWindowSize ( ) ;
2728
2829 const ready = ref ( false ) ;
@@ -45,15 +46,16 @@ export default defineComponent({
4546 const scene = new three . Scene ( ) ;
4647 const stlLoader = new STLLoaderConstructor ( ) ;
4748 const textureLoader = new three . TextureLoader ( ) ;
48- const roughnessTexture = textureLoader . load (
49- withBase ( "/assets/model/roughness.jpeg" )
50- ) ;
49+ const roughnessTexture = textureLoader . load ( BASE + "roughness.jpeg" ) ;
5150 // Models
5251 let logo1 : Mesh ;
5352 let logo2 : Mesh ;
5453
5554 // Lights
56- const ambientLight = new three . AmbientLight ( 0xffffff , 2 ) ;
55+ const ambientLight = new three . AmbientLight (
56+ 0xffffff ,
57+ isDarkmode . value ? 3 : 4
58+ ) ;
5759 const directionalLight = new three . DirectionalLight ( 0xffffff , 3 ) ;
5860 const directionalLight2 = new three . DirectionalLight ( 0xffffff , 3 ) ;
5961
@@ -117,10 +119,10 @@ export default defineComponent({
117119
118120 await Promise . all ( [
119121 new Promise < void > ( ( resolve ) =>
120- stlLoader . load ( withBase ( "/assets/model/ logo1.stl") , ( geometry ) => {
122+ stlLoader . load ( BASE + " logo1.stl", ( geometry ) => {
121123 const material = new three . MeshPhysicalMaterial ( {
122124 color : 0x284c39 ,
123- metalness : 0.45 ,
125+ metalness : 0.3 ,
124126 roughness : 0.5 ,
125127 roughnessMap : roughnessTexture ,
126128 displacementScale : 0.15 ,
@@ -140,7 +142,7 @@ export default defineComponent({
140142 } )
141143 ) ,
142144 new Promise < void > ( ( resolve ) =>
143- stlLoader . load ( withBase ( "/assets/model/ logo2.stl") , ( geometry ) => {
145+ stlLoader . load ( BASE + " logo2.stl", ( geometry ) => {
144146 const material = new three . MeshPhysicalMaterial ( {
145147 color : 0x35495e ,
146148 metalness : 0.7 ,
@@ -169,25 +171,26 @@ export default defineComponent({
169171
170172 onMounted ( ( ) =>
171173 Promise . all ( [
172- import ( /* webpackChunkName: "hope-logo" */ "three" ) . then (
173- ( m ) => m . default || m
174- ) ,
174+ import ( /* webpackChunkName: "hope-logo" */ "three" ) . then ( ( m ) => m ) ,
175175 import (
176176 /* webpackChunkName: "hope-logo" */ "three/examples/jsm/controls/OrbitControls.js"
177- ) . then ( ( m ) => m . default || m ) ,
177+ ) . then ( ( m ) => m ) ,
178178 import (
179179 /* webpackChunkName: "hope-logo" */ "three/examples/jsm/loaders/STLLoader.js"
180- ) . then ( ( m ) => m . default || m ) ,
180+ ) . then ( ( m ) => m ) ,
181181 ] ) . then ( ( [ THREE , { OrbitControls } , { STLLoader } ] ) => {
182182 void renderLogo ( THREE , STLLoader , OrbitControls ) ;
183183
184- watch ( isMobile , ( ) => renderLogo ( THREE , STLLoader , OrbitControls ) ) ;
184+ watch ( [ isDarkmode , isMobile ] , ( ) =>
185+ renderLogo ( THREE , STLLoader , OrbitControls )
186+ ) ;
185187 } )
186188 ) ;
187189
188190 return ( ) : ( VNode | null ) [ ] => [
189191 ! ready . value
190192 ? h ( "img" , {
193+ class : "vp-hero-image" ,
191194 src : withBase ( frontmatter . value . heroImage ! ) ,
192195 alt : "vuepress-theme-hope" ,
193196 } )
0 commit comments