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

feat(app): 680 UseTexture composable as component #757

Merged
merged 10 commits into from
Sep 6, 2024
9 changes: 6 additions & 3 deletions docs/advanced/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ To avoid errors and unwanted sideeffects, resources created programatically with
import { dispose } from '@tresjs/core'
import { useGLTF } from '@tresjs/cientos'

const { nodes } = await useGLTF('https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/blender-cube.glb', {
draco: true,
})
const { nodes } = await useGLTF(
'https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/blender-cube.glb',
{
draco: true,
},
)
const model = nodes.Cube

onUnmounted(() => {
Expand Down
6 changes: 5 additions & 1 deletion docs/advanced/primitive.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ The same pointer events available on the TresJS components are available on the

```html
<template>
<primitive :object="meshWithMaterial" @click="onClick" @pointermove="onPointerMove" />
<primitive
:object="meshWithMaterial"
@click="onClick"
@pointermove="onPointerMove"
/>
</template>
```

Expand Down
32 changes: 32 additions & 0 deletions docs/api/composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,38 @@ const texture = await useTexture({ map: 'path/to/texture.png' }, loadingManager)

Similar to above composable, the `useTexture` composable returns a promise, you can use it with `async/await` or `then/catch`. If you are using it on a component make sure you wrap it with a `Suspense` component.

### UseTexture as component

You can also use `UseTexture` (with uppercase) as component like so:

```html
<Suspense>
<UseTexture v-slot="{ textures }" map="path/to/texture.png">
<TresMesh>
<TresBoxGeometry />
<TresMeshStandardMaterial :map="textures.map" />
</TresMesh>
</UseTexture>
</Suspense>
```

## Props

| Prop | type |
| ---- | --- |
| **map?** | `String` |
| **displacementMap?** | `String` |
| **normalMap?** | `String` |
| **roughnessMap?** | `String` |
| **metalnessMap?** | `String` |
| **aoMap?** | `String` |
| **alphaMap?** | `String` |
| **matcap?** | `String` |

::: warning
The `UseTexture` component needs to be wrapped in a `Suspense` component in order to work
:::

## useSeek

The `useSeek` composable provides utilities to easily traverse and navigate through complex ThreeJS scenes and object children graphs. It exports 4 functions which allow you to find child objects based on specific properties.
Expand Down
32 changes: 32 additions & 0 deletions docs/es/api/composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,38 @@ Luego puedes vincular las texturas al material.

Similar al composable anterior, el composable `useTexture` devuelve una promesa, puedes usarlo con `async/await` o `then/catch`. Si lo estás utilizando en un componente, asegúrate de envolverlo con un componente `Suspense`.

### UseTexture como componente

Puedes usar `UseTexture` como componente, de la siguiente forma:

```html
<Suspense>
<UseTexture v-slot="{ textures }" map="path/to/texture.png">
<TresMesh>
<TresBoxGeometry />
<TresMeshStandardMaterial :map="textures.map" />
</TresMesh>
</UseTexture>
</Suspense>
```

## Props

| Prop | type |
| ---- | --- |
| **map?** | `String` |
| **displacementMap?** | `String` |
| **normalMap?** | `String` |
| **roughnessMap?** | `String` |
| **metalnessMap?** | `String` |
| **aoMap?** | `String` |
| **alphaMap?** | `String` |
| **matcap?** | `String` |

::: warning
El componente `UseTexture` necesita estar envuelto por un `Suspense` para poder funcionar
:::

## useSeek

El composable `useSeek` proporciona utilidades para recorrer y navegar fácilmente a través de escenas y gráficos de objetos complejos de ThreeJS. Exporta 4 funciones que te permiten encontrar objetos secundarios basados en propiedades específicas.
Expand Down
23 changes: 23 additions & 0 deletions playground/vue/src/pages/basic/Textures.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup>
import { TresCanvas, UseTexture } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'

const path = 'https://raw.githubusercontent.com/Tresjs/assets/main/textures/black-rock/Rock035_2K_Displacement.jpg'
</script>

<template>
<TresCanvas window-size clear-color="#111">
<TresPerspectiveCamera :position="[0, 0, 3]" :fov="45" :aspect="1" :near="0.1" :far="1000" />
<OrbitControls />
<Suspense>
<UseTexture v-slot="{ textures }" :map="path" :displacement-map="path">
<TresMesh>
<TresBoxGeometry :args="[1, 1, 1, 50, 50, 50]" />
<TresMeshStandardMaterial :map="textures.map" :displacement-map="textures.displacementMap" :displacement-scale="0.1" />
</TresMesh>
</UseTexture>
</Suspense>
<TresDirectionalLight :position="[4, 4, 4]" />
<TresAmbientLight :intensity="0.5" />
</TresCanvas>
</template>
2 changes: 1 addition & 1 deletion playground/vue/src/pages/issues/701/TheExperience.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const tOrFFast = shallowRef(false)
const elapsed = shallowRef(0)

const pool: {
// eslint-disable-next-line ts/no-unsafe-function-type

click: Function
pos: number[]
group: Group
Expand Down
5 changes: 5 additions & 0 deletions playground/vue/src/router/routes/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ export const basicRoutes = [
name: '@ready',
component: () => import('../../pages/basic/ready/index.vue'),
},
{
path: '/basic/textures',
name: 'Textures',
component: () => import('../../pages/basic/Textures.vue'),
},
]
Loading
Loading