chore(docs): fix gem on SSR and improve it (#726)

* chore(docs): fix gem on SSR and improve it

* chore: update loading bar color
This commit is contained in:
Sébastien Chopin 2021-10-12 01:33:32 +02:00 committed by GitHub
parent e34875ff7c
commit ca83015b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 13 deletions

View File

@ -1,14 +1,18 @@
<template> <template>
<canvas class="webgl" /> <canvas class="webgl" :style="{ opacity: ready ? 1 : 0 }" />
</template> </template>
<script> <script>
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
export default { export default {
mounted () { data () {
return {
ready: false
}
},
async mounted () {
const THREE = await import('three').then(m => m.default || m)
const { OrbitControls } = await import('three/examples/jsm/controls/OrbitControls.js' /* webpackChunkName: "gem" */).then(m => m.default || m)
const { GLTFLoader } = await import('three/examples/jsm/loaders/GLTFLoader.js' /* webpackChunkName: "gem" */).then(m => m.default || m)
// Canvas // Canvas
const canvas = document.querySelector('canvas.webgl') const canvas = document.querySelector('canvas.webgl')
@ -23,35 +27,37 @@ export default {
gltfLoader.load( gltfLoader.load(
'/3D/gem.gltf', '/3D/gem.gltf',
(gltf) => { (gltf) => {
console.log(gltf)
// Gem // Gem
gem = gltf.scene.children[6] gem = gltf.scene.children[6]
console.log(gltf.scene.children[6])
// Material setup // Material setup
const textureLoader = new THREE.TextureLoader() const textureLoader = new THREE.TextureLoader()
const roughnessTexture = textureLoader.load('/3D/roughness.jpeg') const roughnessTexture = textureLoader.load('/3D/roughness.jpeg')
gem.material.roughnessMap = roughnessTexture gem.material.roughnessMap = roughnessTexture
gem.material.displacementScale = 0.15 gem.material.displacementScale = 0.15
gem.material.emissiveIntensity = 1 gem.material.emissiveIntensity = 0.4
gem.material.refractionRatio = 1 gem.material.refractionRatio = 1
gem.rotation.z = 0.5 gem.rotation.z = 0
scene.add(gem) scene.add(gem)
light = gltf.scene.children[0] light = gltf.scene.children[0]
scene.add(light) scene.add(light)
this.ready = true
} }
) )
// Lights // Lights
const ambientLight = new THREE.AmbientLight(0xFFFFFF, 2) const ambientLight = new THREE.AmbientLight(0xFFFFFF, 2)
scene.add(ambientLight) scene.add(ambientLight)
const directionalLight = new THREE.DirectionalLight(0xFFFFFF, 3) const directionalLight = new THREE.DirectionalLight(0xFFFFFF, 3)
directionalLight.position.set(1, 1, 1) directionalLight.position.set(1, 1, 1)
scene.add(directionalLight) scene.add(directionalLight)
const directionalLight2 = new THREE.DirectionalLight(0xFFFFFF, 3)
directionalLight2.position.set(-1, -1, -1)
scene.add(directionalLight2)
// Settings // Settings
const sizes = { const sizes = {
width: 200, width: 200,
@ -98,7 +104,7 @@ export default {
const deltaTime = elapsedTime - previousTime const deltaTime = elapsedTime - previousTime
previousTime = elapsedTime previousTime = elapsedTime
if (gem) { if (gem) {
gem.rotation.y = 0.5 * elapsedTime gem.rotation.y = 1.1 * elapsedTime
} }
// Update controls // Update controls
@ -119,5 +125,9 @@ export default {
<style scoped> <style scoped>
.webgl { .webgl {
outline: none; outline: none;
width: 200px;
height: 200px;
opacity: 0;
transition: opacity 1s ease;
} }
</style></style> </style>

View File

@ -54,6 +54,9 @@ export default withDocus({
class: ['min-w-xs'] class: ['min-w-xs']
} }
}, },
loading: {
color: '#00DC82'
},
css: [resolve(__dirname, './assets/nuxt.css')], css: [resolve(__dirname, './assets/nuxt.css')],
windicss: { windicss: {
root: resolve(__dirname), root: resolve(__dirname),