--- title: Primitives description: Use the primitive component to directly integrate any Three.js object within your Vue application. --- ## What are Primitives? The `` component is a versatile low-level component in TresJS that allows you to directly use any Three.js object within your Vue application without an abstraction. It acts as a bridge between Vue's reactivity system and THREE's scene graph. This component is particularly useful when you need: - **Direct Three.js Integration**: Use existing Three.js objects without wrapper components - **Complex Model Rendering**: Display models loaded from external sources like GLTF files - **Performance Optimization**: Bypass component overhead for specific use cases - **Third-party Library Integration**: Integrate objects from Three.js ecosystem libraries ## Basic Usage The simplest way to use the `` component is by passing a Three.js object to the `object` prop: ```vue [basic-primitive.vue] ``` ## Props The `` component accepts the following props: ### `object` - **Type**: `Object3D | Ref` - **Required**: `true` The primary Three.js object which the primitive component will render. This should be either a plain Three.js object or a reactive reference (preferably `shallowRef`). ```vue ``` ### `dispose` - **Type**: `boolean | 'default' | ((self: TresInstance) => void) | null` - **Default**: `'default'` (no disposal for primitives) Controls how the primitive's resources are disposed when removed from the scene: - `'default'` - Default behavior: don't dispose primitive resources - `false` or `null` - Explicitly disable disposal - `true` - Force disposal of the primitive and its resources - `function` - Custom disposal function ```vue ``` ### `attach` - **Type**: `string | ((parent: any, self: TresInstance) => () => void)` - **Optional** Specifies how to attach the primitive to its parent. Can be a property name or a custom attachment function. ::code-group ```vue [Material Attachment] ``` ```vue [Geometry Attachment] ``` ```vue [Custom Attachment Function] ``` :: ### `visible` - **Type**: `boolean` - **Default**: `true` Controls the visibility of the primitive object. ```vue ``` ### Pass-through Props Any other props are passed through to the underlying Three.js object, allowing you to modify its properties directly: ```vue ``` ## Events The `` component supports all the pointer events available on TresJS components, allowing you to interact with the object in the scene: ```vue [primitive-events.vue] ``` ::read-more{to="/api/events/pointer-events"} :: ## Children via Slots You can add children to the `` component using slots. This is particularly useful when you want to add additional objects or materials which are not part of the main object: ```vue [primitive-children.vue] ``` ## Usage with Models The `` component is especially powerful when working with complex models loaded from external sources. Here's how to use it with GLTF models: ::code-group ```vue [TheModel.vue] ``` ```vue [app.vue] ``` :: ### Working with Multiple Model Parts If you are working with complex models, you may want to access and manipulate specific parts: ```vue [primitive-model-parts.vue] ``` ## Performance Considerations When using primitives, keep these performance tips in mind: ::note **Reactivity Optimization**: Use [`shallowRef`](https://vuejs.org/api/reactivity-advanced.html#shallowref) instead of [`ref`](https://vuejs.org/api/reactivity-core.html#ref) for Three.js objects to avoid deep reactivity overhead, as Three.js objects have complex internal structures that don't benefit from Vue's reactivity system. :: ```vue ``` ::warning **Manual Disposal Required**: TresJS does NOT automatically dispose primitive resources by default. This is intentional to avoid altering the user's `:object`. You must manually dispose of geometries, materials, and textures when they're no longer needed to prevent memory leaks. :: ```vue ``` ### Controlling Disposal Behavior You can override the default behavior using the `dispose` prop: ```vue ``` ## Common Use Cases ### 1. Integrating Third-party Libraries ```vue ``` ### 2. Custom Geometries ```vue ``` ### 3. Particle Systems ```vue ``` The `` component provides the flexibility to integrate any Three.js object seamlessly into your TresJS application while maintaining the benefits of Vue's reactivity and component system.