TroisJS is a powerful and lightweight library designed to facilitate the creation of 3D graphics and animations within Vue 3 applications, leveraging the capabilities of Three.js and the performance benefits of Vite. Currently stable at version 0.3.4, the library maintains a relatively active release cadence, frequently pushing bug fixes and minor features as seen in recent patch versions (e.g., 0.3.4, 0.3.2). Its primary differentiator is providing a `react-three-fiber`-like component-based API specifically tailored for the Vue ecosystem, allowing developers to compose complex Three.js scenes declaratively using Vue components. It ships with comprehensive TypeScript types, ensuring robust development and better maintainability for large-scale projects. The library aims to abstract away much of the boilerplate associated with direct Three.js integration into a Vue environment, making 3D development more accessible to Vue developers.
npm install troisjsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic TroisJS setup using Vue 3's `createApp` and `script setup` composition API. It initializes a 3D scene with a camera, light, and a rotating box, showing how to register TroisJS components globally via `TroisJSVuePlugin` and access Three.js objects for animation.
Review the type definitions and adjust component props or API calls to match the new TypeScript interfaces. Ensure your project's TypeScript configuration is set up correctly for Vue components.
Update to TroisJS version 0.3.2 or newer, as specific bug fixes for Raycaster issues (e.g., with GltfModel clicks) were implemented in that release. Ensure your scene setup aligns with the library's recommended practices for raycasting.
Upgrade to TroisJS version 0.3.1 or later, which includes a bug fix addressing texture application for `ShaderMaterial`.
Run `npm install troisjs three vue` or `yarn add troisjs three vue` to install the package and its core peer dependencies.
Ensure you have called `app.use(TroisJSVuePlugin)` during your Vue application initialization, or explicitly import and register the component locally within your Vue SFCs if not using the plugin.
Use Vue's lifecycle hooks like `onMounted` or `nextTick` to ensure the component is rendered and its internal Three.js objects are available before attempting to interact with them programmatically. Use `ref` and optional chaining (`?.`) for safer access.