|
@@ -1,24 +1,24 @@
|
|
-# Load Models
|
|
|
|
|
|
+# Cargar Modelos
|
|
|
|
|
|
-> All models used in this guide are from [Alvaro Saburido](https://sketchfab.com/3d-models/aku-aku-7dfcb6edf10b4098bbb965c56fd3055c).
|
|
|
|
|
|
+> Todos los modelos utilizados en esta guía son de [Alvaro Saburido](https://sketchfab.com/3d-models/aku-aku-7dfcb6edf10b4098bbb965c56fd3055c).
|
|
|
|
|
|
-3D models are available in hundreds of file formats, each with different purposes, assorted features, and varying complexity.
|
|
|
|
|
|
+Los modelos 3D están disponibles en cientos de formatos de archivo, cada uno con diferentes propósitos, características variadas y complejidad variable.
|
|
|
|
|
|
-For this guide we are going to focus on loading gLTF (GL Transmission Format) models, which are the most common format for 3D models on the web.
|
|
|
|
|
|
+Para esta guía, nos vamos a centrar en cargar modelos gLTF (GL Transmission Format), que son el formato más común para modelos 3D en la web.
|
|
|
|
|
|
<SandboxDemo url="https://play.tresjs.org/#eNqVVdtu2zgQ/RVC++AsVpacuu12tc7CidsGu+i2Re0+VX2gpbHMhCIJkrLjBvn3DqmLJfeCFPCDNXNmeOZ+H6w0mEulol0FQRLMTKaZssSArdQ/qWClktqSe+JgCyp21JAHstGyJKO5RdmNiTOpYfR3D/tOr5ldSGG15N+BMxBWmoHFFTUsW25pLvf/UxWS5Yfrq4XkUi8VzSAkb+VKCkCVYqLoPNqtBhilonP0sSj44aoS4tAgovgochG6R1ORSWEsKTi5IPepICTjQLV/LiGj317/+eJq+nIUOo3xlExCrK7ASyhXW5qQDeWmFtQQpLY6KEhOI3EIWVlVYT7acJLT8BzIHuNLhuF69Z4J9LhkX9C64fKQillclwsLNbNQKk4t4H9CZr1y7cZrNL5Ig4Kngdc2+vegjYLMsh0saAma1rpEScMskwJNPj0JCf7++pwGjZJLeTum1ukmXjdpdHHrelj9Trys8DFhan5e0qtWh4pPYJ7oS6YdTSkof8OKrW09ZC6FyKQpWcvxJIRpSNyvCwHVTFh8g9kD6s9becfBT0S5dm3qn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WVlVYT7acJLT8BzIHuNLhuF69Z4J9LhkX9C64fKQillclwsLNbNQKk4t4H9CZr1y7cZrNL5Ig4Kngdc2+vegjYLMsh0saAma1rpEScMskwJNPj0JCf7++pwGjZJLeTum1ukmXjdpdHHrelj9Trys8DFhan5e0qtWh4pPYJ7oS6YdTSkof8OKrW09ZC6FyKQpWcvxJIRpSNyvCwHVTFh8g9kD6s9becfBT0S5dm3qnxvin6RBA53Fxyy7CsRdCYIwqDtyXFIV3RgpcLR8q6WNwqRBUjefk/UnySnSYGutMkkcZ7lA+xw42+lIgI2FKuM+fD6NnkWTOGfGxk6M6DTwLTNwXM/cr/iuLdD98777Rjx8xe6B3ioqHsO9w86fRpPovPHcCqOSOZu+bzfjj/HrcHP0+OwF8v0DTNlPA45+ZeDR+e3B5+cTn2AcIbiLymF2GxyuAA35LziuDX7mGoHjHEr2CKct1AX/NHoec7buu3QecVU8YE9ag5tvw4qTjsxkqRgH/U65kRl2JuVc7v/zsm4FepstZLffkd+Yu5rye2wW0DtM97GUVBdga/Wr5Vu4w/+dspR5xZvi/ED5AYzkleNYw3B15Ei7h/Ns//UDhotzZV7d+bltghoQtbitvfRTuxW6XqsFn33iPN6XY/GTLB0jm0bTXsKHx+f0vBJORYEbxS2D/qnVsOlOnLtZPRU2zyV+UU8hdJ/Xb1avf3hij8funpgMBB4PTCXwkNDOCxpfELqnzLbuzlwEo7bnNN1HBbPbao1qjd4wpTbCnvHbDx+jBqMxcUmZiL13ExfcbuIKYx8Legv5eO1S8I1gXJOAPHJ4d3B/7xOmfuXX/AZxnx3Jh3U8Pbus0hoJXnpjtMRknjWeomssr2uMGt4HRjvKK4hwex/OvLZ3Wb+5rUqzEq/LDkgi1zd4mbCGnkZzGfqH4OErWPcr8A==" />
|
|
|
|
|
|
-There are several ways to load models on TresJS:
|
|
|
|
|
|
+Hay varias formas de cargar modelos en TresJS:
|
|
|
|
|
|
::: warning
|
|
::: warning
|
|
-Please note that the examples above we use top level await, make sure you wrap it with a [Suspense](https://vuejs.org/guide/built-ins/suspense.html#suspense) component. See Suspense for more information. .
|
|
|
|
|
|
+Por favor, ten en cuenta que en los ejemplos anteriores utilizamos el await de nivel superior, asegúrate de envolverlo con un componente [Suspense](https://vuejs.org/guide/built-ins/suspense.html#suspense). Consulta Suspense para obtener más información.
|
|
:::
|
|
:::
|
|
|
|
|
|
-## Using `useLoader`
|
|
|
|
|
|
+## Usando `useLoader`
|
|
|
|
|
|
-The `useLoader` composable allows you to pass any type of three.js loader and a URL to load the resource from. It returns a `Promise` with the loaded resource.
|
|
|
|
|
|
+El composable `useLoader` te permite pasar cualquier tipo de cargador de three.js y una URL para cargar el recurso. Devuelve una `Promise` con el recurso cargado.
|
|
|
|
|
|
-For a detailed explanation of how to use `useLoader`, check out the [useLoader](/api/composables#useloader) documentation.
|
|
|
|
|
|
+Para obtener una explicación detallada de cómo usar `useLoader`, consulta la documentación de [useLoader](/api/composables#useloader).
|
|
|
|
|
|
```ts
|
|
```ts
|
|
import { useLoader } from '@tresjs/core'
|
|
import { useLoader } from '@tresjs/core'
|
|
@@ -27,7 +27,7 @@ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader'
|
|
const { scene } = await useLoader(GLTFLoader, '/models/AkuAku.gltf')
|
|
const { scene } = await useLoader(GLTFLoader, '/models/AkuAku.gltf')
|
|
```
|
|
```
|
|
|
|
|
|
-Then you can pass the model scene to a TresJS [`primitive`](/advanced/primitive) component to render it:
|
|
|
|
|
|
+Luego puedes pasar la escena del modelo a un componente [`primitive`](/advanced/primitive) de TresJS para renderizarlo:
|
|
|
|
|
|
```html{2}
|
|
```html{2}
|
|
<TresCanvas>
|
|
<TresCanvas>
|
|
@@ -35,13 +35,13 @@ Then you can pass the model scene to a TresJS [`primitive`](/advanced/primitive)
|
|
</TresCanvas>
|
|
</TresCanvas>
|
|
```
|
|
```
|
|
|
|
|
|
-> The `<primitive />` component is not a standalone component in the Tres source code. Instead, it's a part of the Tres core functionality. When you use `<primitive>`, it is translated to a `createElement` call, which creates the appropriate three.js object based on the provided "object" prop.
|
|
|
|
|
|
+> El componente `<primitive />` no es un componente independiente en el código fuente de Tres. En su lugar, es parte de la funcionalidad principal de Tres. Cuando usas `<primitive>`, se traduce a una llamada a `createElement`, que crea el objeto three.js adecuado según la propiedad "object" proporcionada.
|
|
|
|
|
|
-Notice in the example above that we are using the `Suspense` component to wrap the `TresCanvas` component. This is because `useLoader` returns a `Promise` and we need to wait for it to resolve before rendering the scene.
|
|
|
|
|
|
+Observa en el ejemplo anterior que estamos utilizando el componente `Suspense` para envolver el componente `TresCanvas`. Esto se debe a que `useLoader` devuelve una `Promise` y necesitamos esperar a que se resuelva antes de renderizar la escena.
|
|
|
|
|
|
-## Using `useGLTF`
|
|
|
|
|
|
+## Usando `useGLTF`
|
|
|
|
|
|
-A more convenient way of loading models is using the `useGLTF` composable available from the [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
|
|
|
|
|
|
+Una forma más conveniente de cargar modelos es utilizando el composable `useGLTF` disponible en el paquete [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos).
|
|
|
|
|
|
```ts
|
|
```ts
|
|
import { useGLTF } from '@tresjs/cientos'
|
|
import { useGLTF } from '@tresjs/cientos'
|
|
@@ -49,7 +49,7 @@ import { useGLTF } from '@tresjs/cientos'
|
|
const { scene, nodes, animations, materials } = await useGLTF('/models/AkuAku.gltf')
|
|
const { scene, nodes, animations, materials } = await useGLTF('/models/AkuAku.gltf')
|
|
```
|
|
```
|
|
|
|
|
|
-An advantage of using `useGLTF`is that you can pass a `draco` prop to enable [Draco compression](https://threejs.org/docs/index.html?q=drac#examples/en/loaders/DRACOLoader) for the model. This will reduce the size of the model and improve performance.
|
|
|
|
|
|
+Una ventaja de usar `useGLTF` es que puedes pasar una propiedad `draco` para habilitar la [compresión Draco](https://threejs.org/docs/index.html?q=drac#examples/en/loaders/DRACOLoader) para el modelo. Esto reducirá el tamaño del modelo y mejorará el rendimiento.
|
|
|
|
|
|
```ts
|
|
```ts
|
|
import { useGLTF } from '@tresjs/cientos'
|
|
import { useGLTF } from '@tresjs/cientos'
|
|
@@ -57,7 +57,7 @@ import { useGLTF } from '@tresjs/cientos'
|
|
const { scene, nodes, animations, materials } = await useGLTF('/models/AkuAku.gltf', { draco: true })
|
|
const { scene, nodes, animations, materials } = await useGLTF('/models/AkuAku.gltf', { draco: true })
|
|
```
|
|
```
|
|
|
|
|
|
-Alternatively you can easily select Objects inside the model using `nodes` property
|
|
|
|
|
|
+Alternativamente, puedes seleccionar fácilmente objetos dentro del modelo utilizando la propiedad `nodes`.
|
|
|
|
|
|
```vue
|
|
```vue
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
@@ -79,9 +79,9 @@ const { scene, nodes, animations, materials } = await useGLTF('/models/AkuAku.gl
|
|
</template>
|
|
</template>
|
|
```
|
|
```
|
|
|
|
|
|
-## Using `GLTFModel`
|
|
|
|
|
|
+## Usando `GLTFModel`
|
|
|
|
|
|
-The `GLTFModel` component is a wrapper around `useGLTF` that's available from the [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
|
|
|
|
|
|
+El componente `GLTFModel` es un envoltorio alrededor de `useGLTF` que está disponible en el paquete [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos).
|
|
|
|
|
|
```vue{2,9}
|
|
```vue{2,9}
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
@@ -99,11 +99,11 @@ import { OrbitControls, GLTFModel } from '@tresjs/cientos'
|
|
</template>
|
|
</template>
|
|
```
|
|
```
|
|
|
|
|
|
-This particular approach is more straightforward but gives you less control over the model.
|
|
|
|
|
|
+Este enfoque en particular es más sencillo pero te brinda menos control sobre el modelo.
|
|
|
|
|
|
## useFBX
|
|
## useFBX
|
|
|
|
|
|
-The `useFBX` composable is available from the [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package.
|
|
|
|
|
|
+El composable `useFBX` está disponible en el paquete [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos).
|
|
|
|
|
|
```ts
|
|
```ts
|
|
import { useFBX } from '@tresjs/cientos'
|
|
import { useFBX } from '@tresjs/cientos'
|
|
@@ -111,7 +111,7 @@ import { useFBX } from '@tresjs/cientos'
|
|
const model = await useFBX('/models/AkuAku.fbx')
|
|
const model = await useFBX('/models/AkuAku.fbx')
|
|
```
|
|
```
|
|
|
|
|
|
-Then is as straightforward as adding the scene to your scene:
|
|
|
|
|
|
+Entonces, es tan sencillo como agregar la escena a tu escena:
|
|
|
|
|
|
```html{2}
|
|
```html{2}
|
|
<TresCanvas shadows alpha>
|
|
<TresCanvas shadows alpha>
|
|
@@ -121,7 +121,7 @@ Then is as straightforward as adding the scene to your scene:
|
|
|
|
|
|
## FBXModel
|
|
## FBXModel
|
|
|
|
|
|
-The `FBXModel` component is a wrapper around `useFBX` that's available from the [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos) package. It's similar usage to `GLTFModel`:
|
|
|
|
|
|
+El componente `FBXModel` es un envoltorio alrededor de `useFBX` que está disponible en el paquete [@tresjs/cientos](https://github.com/Tresjs/tres/tree/main/packages/cientos). Su uso es similar al de `GLTFModel`:
|
|
|
|
|
|
```vue{2,9}
|
|
```vue{2,9}
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|