Skip to content

Commit

Permalink
feat: html iphone demo (Tresjs#82)
Browse files Browse the repository at this point in the history
* feat: html iphone demo

* feat(html-phone): added hover to closeup button
  • Loading branch information
alvarosabu authored Dec 8, 2023
1 parent b42d1b7 commit 69f839e
Show file tree
Hide file tree
Showing 9 changed files with 3,239 additions and 1,782 deletions.
70 changes: 70 additions & 0 deletions components/content/html-phone/iPhone.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<script setup lang="ts">
import { Html, useGLTF } from '@tresjs/cientos'
import { Color, MeshStandardMaterial } from 'three'
const { nodes } = await useGLTF('/models/iphone/iphonex.glb', { draco: true })
const model = nodes['iphonex']
const back = nodes['iphonexback']
const { seekByName } = useSeek()
const screen = seekByName(model, 'SCREEN')
const bottomTab = seekByName(model, 'BottomTab')
screen?.position.set(0, 0, 0.01)
screen.material.transparent = true
screen.material.opacity = 0.5
console.log(nodes)
bottomTab.material = new MeshStandardMaterial({
color: new Color('#000000'),
emissive: new Color('#000000'),
})
const emit = defineEmits(['view-clicked'])
const closeUp = ref(false)
function onViewClose() {
closeUp.value = true
emit('view-clicked')
}
</script>

<template>
<Levioso :speed="closeUp ? 0: 1" :rotationFactor="closeUp ? 0: 1">
<TresGroup :position="[0, 1, 0]" ref="">
<primitive :object="model">
<Html :distance-factor="1.39" transform :position="[1, 0, 0.2]" :occlude="[back]" v-if="!closeUp">
<button @click="onViewClose"
class="
p-6
flex
items-center
rounded-full
text-4xl
hover:bg-dark
hover:text-white
transition-colors
duration-200
ease-in-out
"
>
<i class="i-carbon-view" />
</button>
</Html>
<Html
transform
wrapper-class="webpage"
:distance-factor="1.39"
center
:occlude="[back]"
:position="[0.17, -0.25, 0.05]"
>
<iframe
class="rounded-xl overflow-hidden w-[430px] h-[852px] bg-white dark:bg-dark"
src="https://tresjs.org"
frameborder="0"
/>
</Html>

</primitive>
<primitive :object="back" />
</TresGroup>
</Levioso>
</template>
95 changes: 95 additions & 0 deletions components/content/html-phone/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { BasicShadowMap, SRGBColorSpace, NoToneMapping, PerspectiveCamera } from 'three'
import gsap from 'gsap'
const gl = {
shadows: true,
alpha: true,
shadowMapType: BasicShadowMap,
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}
const cameraRef = ref<PerspectiveCamera | null>(null)
const onViewClicked = () => {
gsap.to(cameraRef.value.position, {
duration: 1,
x: 0,
y: 3,
z: 3,
ease: 'power2.inOut',
onUpdate: () => {
cameraRef.value.lookAt(0, 3, 0)
},
})
}
const { hasFinishLoading, progress } = await useProgress()
</script>

<template>
<div class="hero absolute z-30 prose p-24">
<h2 class="text-6xl opacity-0 animate-fade-in animate-delay-1s animate-forwards transition-all ease-in-out">iTres</h2>
<p class="text-2xl opacity-0 animate-fade-in animate-delay-2s animate-forwards transition-all ease-in-out">New fancy phone, mind-blowing. Head turning. </p>
<p class="opacity-0 animate-fade-in animate-delay-4s animate-forwards transition-all ease-in-out">Only $2999.99</p>
</div>
<Transition
name="fade-overlay"
enter-active-class="opacity-1 transition-opacity duration-200"
leave-active-class="opacity-0 transition-opacity duration-200"
>
<div
v-show="!hasFinishLoading"
class="absolute t-0 l-0 w-full h-full z-20 flex justify-center items-center text-black font-mono"
>
<div class="w-200px text-black text-center">
<p class="animate-tada">
🤳
</p>
Loading... {{ progress }} %
</div>
</div>
</Transition>
<TresCanvas v-bind="gl">
<TresPerspectiveCamera
ref="cameraRef"
:position="[5, 5, 5]"
:look-at="[0, 2, 0]"
/>
<Suspense>
<IPhone @view-clicked="onViewClicked" />
</Suspense>
<ContactShadows
:blur="3.5"
:resolution="512"
:opacity="1"
/>
<Suspense>
<Environment
background
:blur="0.9"
preset="city"
/>
</Suspense>
<TresAmbientLight :intensity="1" />
<TresDirectionalLight
:intensity="2"
:position="[2, 3, 0]"
:cast-shadow="true"
:shadow-camera-far="50"
:shadow-camera-left="-10"
:shadow-camera-right="10"
:shadow-camera-top="10"
:shadow-camera-bottom="-10"
/>
</TresCanvas>
</template>

<style scoped>
@import url('https://fonts.cdnfonts.com/css/sf-pro-display');
.hero {
font-family: 'SF Pro Display';
}
</style>
12 changes: 12 additions & 0 deletions content/experiments/html-phone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
thumbnail: /html-phone.png
title: HTML iPhone
slug: html-phone
author: alvarosabu
status: published
description: Using HTML abstraction to render a page inside a model
tags: ['html', 'gltf']
---

::html-phone
::
2 changes: 1 addition & 1 deletion content/experiments/nuxt-stones.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ slug: nuxt-stones
status: published
author: alvarosabu
description: Nuxt Stone is a simple scene with a stone model and a Nuxt logo. The scene is rendered with baked lighting and post-processing effects.
tags: ['gltf', 'baked', 'emission', 'post-processing']
tags: ['gltf', 'baked', 'emission', 'post-processing', 'bloom']
---

<NuxtStones />
11 changes: 9 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ export default defineNuxtConfig({
],
},
},
modules: ['@tresjs/nuxt', '@unocss/nuxt', 'nuxt-svgo', '@nuxt/content', '@nuxt/image-edge'],
modules: [
'@tresjs/nuxt',
'@unocss/nuxt',
'nuxt-svgo',
'@nuxt/content',
'@nuxt/image-edge',
"@nuxt/image"
],
css: ['@unocss/reset/tailwind-compat.css', '@tresjs/leches/styles'],
declare: ['*.glsl'],
unocss: {
Expand Down Expand Up @@ -106,4 +113,4 @@ export default defineNuxtConfig({
build: {
transpile: ['fsevents', 'postprocessing'],
},
})
})
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue"
},
"dependencies": {
"@tresjs/post-processing": "^0.4.0",
"@tresjs/post-processing": "^0.7.0",
"mdast-util-to-string": "^4.0.0",
"three": "^0.157.0",
"three": "^0.158.0",
"three-custom-shader-material": "^5.4.0",
"unist-util-stringify-position": "^4.0.0"
},
"devDependencies": {
"@iconify-json/carbon": "^1.1.21",
"@iconify-json/game-icons": "^1.1.3",
"@iconify-json/ic": "^1.1.14",
"@iconify-json/logos": "^1.1.37",
"@nuxt/content": "^2.8.2",
"@nuxt/image-edge": "1.0.0-rc.3-28290977.ffac767",
"@tresjs/cientos": "3.5.0",
"@tresjs/core": "^3.3.0",
"@iconify-json/carbon": "^1.1.24",
"@iconify-json/game-icons": "^1.1.6",
"@iconify-json/ic": "^1.1.16",
"@iconify-json/logos": "^1.1.40",
"@nuxt/content": "^2.8.5",
"@nuxt/image": "^1.1.0",
"@nuxt/image-edge": "1.1.0-28355789.b3279fe",
"@tresjs/cientos": "3.6.0",
"@tresjs/core": "^3.5.1",
"@tresjs/eslint-config-vue": "^0.2.1",
"@tresjs/leches": "^0.12.0",
"@tresjs/nuxt": "1.2.0",
"@tresjs/leches": "0.15.0-next.1",
"@tresjs/nuxt": "1.3.0",
"@tweakpane/plugin-essentials": "^0.2.0",
"@types/three": "^0.157.0",
"@unocss/nuxt": "^0.55.3",
"gsap": "^3.12.2",
"nuxt": "^3.7.4",
"nuxt-svgo": "^3.5.5",
"postprocessing": "^6.33.2",
"vite-plugin-glsl": "^1.1.2",
"vite-svg-loader": "^4.0.0"
"@types/three": "^0.159.0",
"@unocss/nuxt": "^0.58.0",
"gsap": "^3.12.3",
"nuxt": "^3.8.2",
"nuxt-svgo": "^3.7.0",
"postprocessing": "^6.33.4",
"vite-plugin-glsl": "^1.2.0",
"vite-svg-loader": "^5.1.0"
}
}
Loading

0 comments on commit 69f839e

Please sign in to comment.