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: use loader #828

Merged
merged 9 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
31 changes: 29 additions & 2 deletions docs/api/composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ The `useLoader` composable allows you to load assets using the [THREE.js loaders
```ts
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader'

const { scene } = await useLoader(THREE.GLTFLoader, 'path/to/asset.gltf')
const { scene } = await useLoader(GLTFLoader, 'path/to/asset.gltf')
```

Since the `useLoader` 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. See [Suspense](https://vuejs.org/guide/built-ins/suspense.html#suspense) for more information.
Expand All @@ -234,6 +234,33 @@ Since the `useLoader` composable returns a promise, you can use it with `async/a
</template>
```

### UseLoader as component

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

```vue
<script setup lang="ts">
import { UseLoader } from '@tresjs/core'
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader'
</script>

<Suspense>
<UseLoader v-slot="{ data }" :loader="GLTFLoader" url="path/to/asset.gltf">
<primitive :object="data.scene" />
</Suspense>
```

### Props

| Prop | type |
| ---- | --- |
| **loader** | `THREE.Loader` |
| **url** | `String` |

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

## useTexture

The `useTexture` composable allows you to load textures using the [THREE.js texture loader](https://threejs.org/docs/#api/en/loaders/TextureLoader). It returns a promise with the loaded texture(s).
Expand Down Expand Up @@ -312,7 +339,7 @@ You can also use `UseTexture` (with uppercase) as component like so:
</Suspense>
```

## Props
### Props

| Prop | type |
| ---- | --- |
Expand Down
29 changes: 28 additions & 1 deletion docs/es/api/composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ Dado que el composable `useLoader` devuelve una promesa, puedes usarlo con `asyn
</template>
```

### UseLoader como componente

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

```vue
<script setup lang="ts">
import { UseLoader } from '@tresjs/core'
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader'
</script>

<Suspense>
<UseLoader v-slot="{ data }" :loader="GLTFLoader" url="path/to/asset.gltf">
<primitive :object="data.scene" />
</Suspense>
```

### Props

| Prop | type |
| ---- | --- |
| **loader** | `THREE.Loader` |
| **url** | `String` |

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

## useTexture

El composable `useTexture` te permite cargar texturas utilizando el [cargador de texturas de THREE.js](https://threejs.org/docs/#api/en/loaders/TextureLoader). Retorna una promesa con la(s) textura(s) cargada(s).
Expand Down Expand Up @@ -165,7 +192,7 @@ Puedes usar `UseTexture` como componente, de la siguiente forma:
</Suspense>
```

## Props
### Props

| Prop | type |
| ---- | --- |
Expand Down
21 changes: 21 additions & 0 deletions playground/vue/src/pages/loaders/componentDemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script setup>
import { OrbitControls } from '@tresjs/cientos'
import { TresCanvas, UseLoader } from '@tresjs/core'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'

const url = 'https://raw.githubusercontent.com/Tresjs/assets/main/models/gltf/blender-cube.glb'
</script>

<template>
<TresCanvas window-size clear-color="#333">
<TresPerspectiveCamera :position="[0, 3, 7]" :look-at="[0, 0, 0]" />
<OrbitControls />
<Suspense>
<UseLoader v-slot="{ data }" :loader="GLTFLoader" :url="url">
<primitive :object="data.scene" />
</useloader>
</Suspense>
<TresDirectionalLight :position="[0, 10, 0]" :intensity="1" />
<TresAmbientLight :intensity="0.5" />
</TresCanvas>
</template>
5 changes: 5 additions & 0 deletions playground/vue/src/router/routes/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ export const loaderRoutes = [
name: 'FBX Loader',
component: () => import('../../pages/loaders/fbx-loader/index.vue'),
},
{
path: '/loader/component',
name: 'Loader Component',
component: () => import('../../pages/loaders/componentDemo.vue'),
},
]
Loading