# Getting Started Cientos (Spanish word for "hundreds", pronounced `/ฮธjentos/`) is a collection of useful ready-to-go helpers and components that are not part of the **core** package. The name uses the word in Spanish to multiply by 100, to refer to the potential reach of the package to hold amazing abstractions. ::prose-note The cientos package uses three-stdlib module under the hood instead of the `three/examples/jsm` module. This means that you don't need to extend the catalogue of components using the extend method, cientos does that for you. :: It just works. ๐Ÿ’ฏ ## Next Steps Continue your journey: - [Installation guide](https://cientos.tresjs.org/getting-started/installation) - [Usage](https://cientos.tresjs.org/getting-started/usage) - [Upgrade guide](https://cientos.tresjs.org/getting-started/upgrade-guide) # Installation Guide ## Manual installation If you prefer to set up Cientos manually or add it to an existing [Tres.js](https://tresjs.org/){rel=""nofollow""} project ::code-group ```bash [pnpm] pnpm add @tresjs/cientos ``` ```bash [npm] npm install @tresjs/cientos ``` ```bash [yarn] yarn add @tresjs/cientos ``` :: ## Via `create-tres` wizard When using `create-tres` to create a new project, the cli will prompt you to install cientos. ::code-group ```bash [npm] npx create-tres my-tres-project ``` ```bash [yarn] yarn create tres my-tres-project ``` ```bash [pnpm] pnpm create tres my-tres-project ``` :: ::read-more --- to: https://docs.tresjs.org/getting-started/installation#quick-start-recommended --- For more information about the `create-tres` wizard please refer to this link. :: ## Nuxt :u-icon{name="i-simple-icons-nuxt"} If you're using nuxt, installing our nuxt module will detect automatically cientos. ::read-more --- to: https://docs.tresjs.org/getting-started/installation#nuxt-project --- For more information about the Nuxt module please refer to this link. :: # Usage ## Basic Usage All instances of cientos provide one (or many) examples of how to use it, similar to this one: ```js import { OrbitControls } from '@tresjs/cientos' ``` Now you can use the `OrbitControls` component in your scene. ```vue ``` ::prose-note Note that you donโ€™t need to include the **Tres** prefix (for example, ``) to use the component. All cientos components have the same name as their three-stdlib counterpart. :: ### Props All the props are listed with their respective instance and in case it is not specified all the props are **reactive**, for example: ```vue {3,15-16} ``` ::prose-note All the props and properties are **reactive** unless the docs of the instance says the contrary. :: ### Events Some instances fire events which you can listen to as you normally would do using Vue [emits](https://vuejs.org/guide/components/events.html#emitting-and-listening-to-events){rel=""nofollow""}, for example: ```vue {3,5,11} ``` ### Exposed properties All instances expose a `instance` property by default which contains the base of its abstractions. For example: ```vue {2} ``` # Loading Models Cientos gives you three ways to get a `.glb`/`.gltf` model on screen. They are not alternatives to each other so much as three points on the same line: the further down this page you go, the more control you get over the model's tree. | Approach | Control | Typed | Best for | | :----------------------------------------------------------------------------------- | :------------------------------- | :------- | :------------------------------------------------- | | [``](https://cientos.tresjs.org/api/loaders/gltf-model) | Whole scene, as-is | No | Dropping a model in as-is | | [`useGLTF`](https://cientos.tresjs.org/api/loaders/use-gltf) | Pick nodes and materials by hand | Optional | Reusing parts of a model | | [`tres gltf` codegen](https://cientos.tresjs.org/#generate-a-component-with-the-cli) | Every node is an element | Yes | Production scenes, interaction, per-node overrides | ## Drop the model in The fastest path. `GLTFModel` loads the file and renders its scene graph untouched: ```vue [TheModel.vue] ``` You get the whole model or nothing. There is no way to swap one mesh's material, attach a click handler to a door, or hide a node, because none of them exist as elements in your template. ## Pick the parts you need `useGLTF` hands you the parsed `nodes` and `materials`, so you compose the scene yourself: ```vue [TheModel.vue] ``` This is the right tool when you only want a couple of nodes out of a bigger file. For a whole model it stops scaling: you are hand-writing an element per node, re-reading the tree in Blender to find the names, and re-writing all of it when the artist re-exports. ::prose-note `nodes` and `materials` are keyed by the names in the file, so their shape is only known at runtime. Pass the shape as generics to get them typed, see [Typed nodes and materials](https://cientos.tresjs.org/#typed-nodes-and-materials) below. :: ## Generate a component with the CLI `@tresjs/cli` writes that element-per-node component for you, typed, from the model itself: ```bash npx @tresjs/cli gltf public/models/mug.glb # โœ” src/models/Mug.gen.vue # 1 slot: Mug ``` ```vue [src/models/Mug.gen.vue] ``` Import it like any other component: ```vue [App.vue] ``` ### Overriding a node Every named node is a `` whose fallback is the generated markup, so you change one mesh from the parent without touching the generated file: ```vue [App.vue] ``` Regenerate after the artist re-exports and the override survives, because it never lived in the generated file. If the node is renamed, the override becomes a **type error** instead of quietly doing nothing at runtime. ::prose-warning Treat `*.gen.vue` files as build output: edit the parent, not the generated file. The CLI refuses to overwrite a file it did not generate, so a hand-edited one needs `--force` to regenerate. :: ::read-more{to="https://docs.tresjs.org/cli/gltf"} Full `tres gltf` reference: slots, animations, shadows, Draco and every flag. :: ## Typed nodes and materials `useGLTF` takes two generics that type `nodes` and `materials`. The CLI writes them for you, but you can also declare them by hand: ```ts import type { Mesh, MeshStandardMaterial } from 'three' import { useGLTF } from '@tresjs/cientos' interface ModelNodes { Body: Mesh } interface ModelMaterials { Skin: MeshStandardMaterial } const { nodes, materials } = useGLTF('/models/robot.glb') nodes.value.Body.geometry // Mesh, not any ``` ::prose-note The names come from the file at runtime, so these interfaces are a claim about the model, not a proof. That is exactly why generating them from the model is worth it. :: ## Animated models Clips live on the loaded `state`, and [`useAnimations`](https://cientos.tresjs.org/api/miscellaneous/use-animations) turns them into actions: ```vue [Knight.vue] ``` A generated component wires all of that up and exposes `actions` keyed by a union of the model's clip names, so `actions.Idle` type-checks and `actions.Idl` does not: ```vue [App.vue] ``` ::prose-note Keep the element carrying the animation `ref` mounted and gate its **children** on loading. A `ref` on a `v-if`ed element is still `undefined` one flush after the clips land, and the mixer would then be built with no root to bind against. :: ## Draco-compressed models Pass `draco: true` and the loader pulls the decoder from Google's CDN, or point `decoderPath` at a local copy: ```ts const { state } = useGLTF('/models/mug.glb', { draco: true }) ``` A Draco model renders nothing without it. The CLI detects compression while parsing and writes `{ draco: true }` into the generated component for you. ## Where to find models - [poly.pizza](https://poly.pizza/){rel=""nofollow""} โ€” free 3D models - [Pmndrs Market](https://market.pmnd.rs/){rel=""nofollow""} โ€” free assets, curated - [KayKit](https://kaylousberg.itch.io/){rel=""nofollow""} โ€” animated CC0 character packs # Upgrade Guide ## From v4 to v5 Cientos doesn't have any breaking changes from v4 to v5 but please check the [Upgrade Guide](https://docs.tresjs.org/getting-started/upgrade-guide){rel=""nofollow""} of the core. ## Migration Guide from v3 The following are the breaking changes introduced in v4. We recommend reading through all of them to ensure a smooth transition. ### Updated defineExport properties Since the beginning we exported our components' underlying `Three.js` instances using the name `value`. This created a very ambiguous situation with some components. When we access them using a `ref` in the `