Skip to content

v-log

Problem

When you have to log your instance you have to use the template reference and then log them:

vue
<script setup lang="ts">
import { shallowRef, watch } from 'vue'

const sphereRef = shallowRef()

watch(sphereRef, (value) => {
  console.log(value) // Really for a log?!!! 😫
})
</script>

<template>
  <TresCanvas>
    <TresPerspectiveCamera :position="[0, 2, 5]" />
    <Sphere
      ref="sphereRef"
      :scale="0.5"
    />
    <OrbitControls />
  </TresCanvas>
</template>

Don't you think this is A LOT of code just for a simple log?

Usage

With the new directive v-log provided by TresJS, you can do this by just adding v-log to the instance.

vue
<script setup lang="ts">
import { vLog } from '@tresjs/core'
import { OrbitControls, Sphere } from '@tresjs/cientos'
</script>
<template>
    <TresCanvas >
    <TresPerspectiveCamera :position="[0, 2, 5]" />
    <Sphere
      ref="sphereRef"
      :scale="0.5"
      v-log:material  <!-- will print just the material 🎉 -->
    />
    <OrbitControls v-log />
  </TresCanvas>
</template>

Note that you can pass a modifier with the name of a property, for example v-log:material, and it will directly log the material property 😍