Tresjs / tres

Declarative ThreeJS using Vue Components
https://tresjs.org
MIT License
2.16k stars 102 forks source link

provide default slot props in TresCanvas #573

Closed userquin closed 6 months ago

userquin commented 6 months ago

Description

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

Hack ```html ```

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 commented 6 months ago

Closed as duplicate. See #572 .