Skip to content

fix: create a local raycast for the HTML component #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions playground/vue/src/pages/misc/HTMLDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@
import { Html, OrbitControls } from '@tresjs/cientos'
import { TresCanvas } from '@tresjs/core'
import { TresLeches, useControls } from '@tresjs/leches'
import { BasicShadowMap, NoToneMapping, SRGBColorSpace } from 'three'
import { reactive, ref } from 'vue'
import Card from './Card.vue'
import '@tresjs/leches/styles'

const gl = {
clearColor: '#82DBC5',
shadows: true,
alpha: false,
shadowMapType: BasicShadowMap,
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}

const sphereRef = ref(null)
const torusRef = ref(null)

Expand All @@ -33,7 +23,7 @@ const { showHtml } = useControls({

<template>
<TresLeches />
<TresCanvas v-bind="gl">
<TresCanvas clear-color="#82DBC5" shadows>
<TresPerspectiveCamera :position="[3, 0, 8]" />
<OrbitControls />
<TresMesh
Expand Down
20 changes: 4 additions & 16 deletions playground/vue/src/pages/misc/LaptopDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,18 @@
import { ContactShadows, Html, Levioso, OrbitControls, useGLTF } from '@tresjs/cientos'
import { TresCanvas } from '@tresjs/core'

import { BasicShadowMap, NoToneMapping, SRGBColorSpace } from 'three'

const gl = {
clearColor: '#241a1a',
shadows: true,
alpha: false,
shadowMapType: BasicShadowMap,
outputColorSpace: SRGBColorSpace,
toneMapping: NoToneMapping,
}

const { nodes }
= await useGLTF('https://vazxmixjsiawhamofees.supabase.co/storage/v1/object/public/models/macbook/model.gltf', { draco: true })
= useGLTF('https://vazxmixjsiawhamofees.supabase.co/storage/v1/object/public/models/macbook/model.gltf', { draco: true })

// eslint-disable-next-line no-console
console.log(nodes)
const laptop = computed(() => nodes.value.Macbook)
</script>

<template>
<TresCanvas v-bind="gl">
<TresCanvas clear-color="#241a1a" shadows>
<TresPerspectiveCamera :position="[-5, 4, 3]" />
<OrbitControls />
<Levioso>
<primitive :object="nodes.Macbook">
<primitive v-if="laptop" :object="laptop">
<Html
transform
wrapper-class="webpage"
Expand Down
10 changes: 6 additions & 4 deletions src/core/misc/html/HTML.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<script setup lang="ts">
import { useLoop, useTresContext } from '@tresjs/core'
import type {
OrthographicCamera,
} from 'three'
import {
DoubleSide,
PlaneGeometry,
Raycaster,
ShaderMaterial,
Vector3,
} from 'three'
import { computed, createVNode, isRef, onUnmounted, ref, render, toRefs, useAttrs, watch, watchEffect } from 'vue'
import type { TresCamera, TresObject, TresObject3D } from '@tresjs/core'
import type { Mutable } from '@vueuse/core'
import type {
OrthographicCamera,
} from 'three'

import type { VNode } from 'vue'
import fragmentShader from './shaders/fragment.glsl'
Expand Down Expand Up @@ -97,13 +98,14 @@ const {
zIndexRange,
} = toRefs(props)

const { renderer, scene, camera, raycaster, sizes } = useTresContext()
const { renderer, scene, camera, sizes } = useTresContext()

const el = computed(() => document.createElement(as.value))

const previousPosition = ref([0, 0, 0])
const previousZoom = ref(0)
const vnode = ref<VNode>()
const raycaster = ref<Raycaster>(new Raycaster())

const styles = computed(() => {
if (transform.value) {
Expand Down