Skip to content
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

provide default slot props in TresCanvas #573

Closed
4 tasks done
userquin opened this issue Mar 4, 2024 · 1 comment
Closed
4 tasks done

provide default slot props in TresCanvas #573

userquin opened this issue Mar 4, 2024 · 1 comment

Comments

@userquin
Copy link
Member

userquin commented Mar 4, 2024

Description

Right now there is no way to access the TresCanvas context without hacking the script setup using TresCanvas:

Hack
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core';
import { computed, ref, onMounted } from 'vue';

import { extend, useTresContext } from '@tresjs/core';
import { OrbitControls } from 'three/addons/controls/OrbitControls';
import { TextGeometry } from 'three/addons/geometries/TextGeometry';

const trescanvas = ref();
const state = ref();

onMounted(() => {
  setTimeout(() => {
    state.value = trescanvas.value?.context;
  }, 0);
});

// Add the element to the catalogue
extend({ TextGeometry, OrbitControls });
</script>

<template>
  <TresCanvas ref="trescanvas" shadows alpha>
    <TresPerspectiveCamera :position="[5, 5, 5]" />
    <TresOrbitControls
      v-if="state?.renderer"
      :args="[state?.camera, state?.renderer?.domElement]"
    />
    <TresMesh>
      <TresTextGeometry :args="['TresJS', { font, ...fontOptions }]" center />
      <TresMeshMatcapMaterial :matcap="matcapTexture" />
    </TresMesh>
  </TresCanvas>
</template>

Suggested solution

Add default slot props, we¡ve the default slot there without any binding:

<canvas
    ref="canvas"
    :data-scene="scene.uuid"
    :class="$attrs.class"
    :data-tres="`tresjs ${pkg.version}`"
    :style="{
      display: 'block',
      width: '100%',
      height: '100%',
      position: windowSize ? 'fixed' : 'relative',
      top: 0,
      left: 0,
      pointerEvents: 'auto',
      touchAction: 'none',
      ...$attrs.style as Object,
    }"
 >
   <slot v-bind="context" />
</canvas>

then in the sfc template:

<TresCanvas shadows alpha v-slot="{ camera, renderer }">
  <TresPerspectiveCamera :position="[5, 5, 5]" />
  <TresOrbitControls
    v-if="renderer"
    :args="[camera, renderer.domElement]"
  />
</TresCanvas>

Alternative

check the hack in the description

Additional context

related #565

Validations

@andretchen0
Copy link
Contributor

Closed as duplicate. See #572 .

@andretchen0 andretchen0 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants