Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@vctrl/viewer

vectreal38AGPL-3.0-only0.9.5TypeScript support: included

vctrl/viewer is a React component library for rendering and interacting with 3D models. It's part of the vectreal ecosystem and is designed to work seamlessly with the vctrl/hooks package for model loading and management.

vectreal, react, 3d, model, viewer, react-component, react-three-fiber, react-three-drei, threejs, react-three-gltf, gltf, glb, usdz, model-viewer

readme

vctrl/viewer

Version and release packages to NPM @vctrl/viewer | NPM Downloads Code sandbox Storybook vctrl/viewer

This library is still undergoing heavy development until the first major version is released. This may lead to breaking changes in upcoming updates.

Overview

vctrl/viewer is a React component library for rendering and interacting with 3D models. It's part of the vectreal-core ecosystem and is designed to work seamlessly with the @vctrl/hooks package for model loading and management.

Table of Contents

Features

  • Easy-to-use React component for 3D model visualization
  • Integration with Three.js and React Three Fiber
  • Customizable camera, controls, and grid options
  • Support for various 3D model formats (via vctrl/hooks)
  • Responsive design with automatic resizing
  • Custom loading component support

Installation

To install the package, use npm or yarn:

npm install @vctrl/viewer
# or
yarn add @vctrl/viewer

Usage

Here's a basic example of how to use the VectrealViewer component:

import React from 'react';

// Use vctrl/hooks for loading a local model
import { useLoadModel } from '@vctrl/hooks/useLoadModel';

// You could also use the `useGLTF` hook from `@react-three/drei`
// import { useGLTF } from '@react-three/drei'

import { VectrealViewer } from '@vctrl/viewer';
import '@vctrl/viewer/css';

function App() {
  const { file } = useLoadModel();
  // const { scene: model } = useGLTF('/model.glb');

  return <VectrealViewer model={file.model} />;
}

export default App;

You must also import the CSS bundle for the viewer to work as expected. See the full example here.

You can also load any model supported by the react-three-drei loading hooks and pass it into the VectrealViewer using the model prop.

API Reference

VectrealViewer Component

The main component exported by this package.

Props

Prop Type Description
model Object3D (Optional when using `use-load-model` context) The 3D model to display
className string (Optional) Additional CSS classes for the viewer container
cameraOptions CameraProps (Optional) Configuration for the camera
controlsOptions ControlsProps (Optional) Configuration for the OrbitControls
envOptions EnvProps (Optional) Configuration for the Stage and Environment Component
gridOptions GridProps (Optional) Configuration for the grid
loader () => JSX.Element (Optional) Custom loading component

Customization

Camera Options

You can customize the camera by passing a cameraOptions prop:

<VectrealViewer
  cameraOptions={{
    initialCameraPosition: new Vector3(0, 5, 5),
    fov: 75,
    aspect: 1,
    near: 0.1,
    far: 1000,
  }}
/>

Controls Options

Customize the controls based on OrbitControls with the controlsOptions prop:

<VectrealViewer
  controlsOptions={{
    maxPolarAngle: Math.PI / 2,
    autoRotate: true,
    controlsTimeout: 2000,
  }}
/>

Environment/Stage Options

Customize the @react-three/drei Stage and Environment components with the controlsOptions prop:

<VectrealViewer
  envOptions={{
    env: {
      preset: 'studio',
    },
    stage: {
      adjustCamera: 1.5,
    },
    backgroundColor: 'maroon',
  }}
/>

Grid Options

Configure the grid display with the gridOptions prop:

<VectrealViewer
  gridOptions={{
    showGrid: true,
    cellSize: 0.5,
    sectionSize: 5,
    sectionColor: 'rgb(134, 73, 33)',
    cellColor: 'rgb(100, 100, 100)',
  }}
/>

Development

This package is part of a monorepo workspace managed with Nx. To contribute or modify the package:

  1. Clone the monorepo
  2. Install dependencies: npm install or yarn install
  3. Make your changes
  4. Build the package: nx build vctrl/viewer
  5. Test your changes: nx test vctrl/viewer

License

Please refer to the LICENSE file in the package root for licensing information.

Contributing

Contributions are welcome! Please read the contributing guidelines in the vectreal-core monorepo before submitting pull requests.

Support

For issues, feature requests, or questions, please file an issue in the GitHub repository.

changelog

0.9.5 (2025-03-14)

🩹 Fixes

  • apps/official-website: Editor Model loading (c041f2a)
  • apps/official-website/editor: missing import for useState and improved loading state handling (7b37f54)
  • packages/hooks: ensure buffers are converted to Uint8Array before adding to zip file (4e1f99d)

❤️ Thank You

  • Mo
  • Schlomoh

0.9.4 (2024-11-24)

🩹 Fixes

  • packages/viewer: add manual dark mode support in VectrealViewer component using js (aaf5a14)

❤️ Thank You

  • Moritz Becker

0.9.3 (2024-11-24)

🩹 Fixes

  • packages/viewer: the clickable area of the info-popover footer (de4c3d7)
  • packages/viewer: update className description and apply it to the outermost container (3c5c3c1)
  • packages/viewer: add 'storybook-addon-deep-controls' to ignoredDependencies in ESLint configuration (bedcaf6)
  • workflows: update Chromatic workflow to ignore chore branches (4f937a7)

❤️ Thank You

  • Moritz Becker

0.9.2 (2024-11-23)

🩹 Fixes

  • pacakges/official-website: normalize action string for upload event (94035cb)
  • packages/viewer: update CSS selectors for light and dark mode variables (f1d43cd)
  • project: update dependencies and remove obsolete entries (356b1c4)

❤️ Thank You

  • Moritz Becker

0.9.1 (2024-11-07)

🩹 Fixes

  • packages/viewer: dedup div with "vctrl-viewer" classname and add vctrl classnames to popover (a00be5b)

❤️ Thank You

  • Moritz Becker

0.9.0 (2024-11-07)

🚀 Features

  • packages/viewer: update peer dependencies, add Storybook configuration, implement robust styling and remove postcss config files (df8359a)
  • packages/viewer: enhance Storybook configuration with deep controls and auto-generated documentation (7df00eb)

📖 Documentation

  • project: add Storybook badge to README files for vctrl/viewer documentation (c0a0659)

❤️ Thank You

  • Moritz Becker

0.8.0 (2024-11-02)

🚀 Features

  • packages/hooks: optimize model and add normals optimization (6f0bde1)
  • project: added github actions and nx grouping to dependabot (7ffc248)

🩹 Fixes

  • packages/viewer: adjust loading spinner styles (286ccc7)
  • packages/viewer: change tailwind styling to css modules styling (273ec59)

📖 Documentation

  • project: changed the serve command to vctrl (b48b34b)

❤️ Thank You

  • Mo @Schlomoh
  • Moritz Becker
  • Nils Ingwersen

0.7.8 (2024-10-28)

🩹 Fixes

  • packages/viewer: disabled/stuttering SceneControls component (361f6a1)

❤️ Thank You

  • Moritz Becker

0.7.7 (2024-10-26)

📖 Documentation

  • packages/viewer: optimize README.md and add example code (7b7fce8)

❤️ Thank You

  • Moritz Becker

0.7.6 (2024-10-24)

📖 Documentation

  • packages/viewer: add CodeSandbox example link (9d196fa)

❤️ Thank You

  • Moritz Becker

0.7.5 (2024-10-22)

🩹 Fixes

  • packages/viewer: styling in info-popover component (dfdd977)

❤️ Thank You

  • Moritz Becker

0.7.4 (2024-10-22)

🚀 Features

  • apps/official-website: enable offline Google Analytics in Vite config (9b25a2f)
  • apps/official-website: move ga initialization to base-layout & add custom event tracking (660e847)

🩹 Fixes

  • apps/official-website: remove useInitGA hook from app component (c5a7ec1)
  • apps/official-website/editor: fix accept pattern and remove webkitdirectory attribute (7c0f653)
  • packages/hooks: optimize hook volumne + emission material extension registration (6ec7915)
  • project: update postcss configuration in vite (3dad878)

❤️ Thank You

  • Moritz Becker

0.7.3 (2024-10-20)

🩹 Fixes

  • packages/viewer: remove cross dependency to vctrl/hooks (f150b31)

❤️ Thank You

  • Moritz Becker

0.7.2 (2024-10-19)

🩹 Fixes

  • packages: cross dependencies (4fbe8b3)

❤️ Thank You

  • Moritz Becker

0.7.0 (2024-10-19)

🚀 Features

  • apps/official-website: unify optimization handler in editor file-menu (714197e)
  • apps/official-website: add color picker hex value input (41812d5)
  • official-website: add hdr bluriness control to file-menu (8a32492)
  • packages/viewer: add info popover to display additional info (5547fb1)

🩹 Fixes

  • apps/official-website: remove dev check in ga hook (2aecde4)
  • packages: update dependencies in package.json with eslint nx plugin (1eab9b7)
  • packages/viewer: adjust grid component to snap to bottom of model (2e1a294)
  • packages/viewer: default env preset + optional background color (5ecc5d0)
  • project: tailwind setup for packages + apps (3240e01)

📖 Documentation

  • project: small changes - mainly added/changed links (b2a9934)

❤️ Thank You

  • Moritz Becker

0.6.0 (2024-10-11)

🚀 Features

  • apps/official-website: integrate texture compression optimization (c3933d3)
  • official-website: rework the reports modal of the editor (1808e07)
  • packages/hooks: add tetxure compression optimization (41555ad)

🩹 Fixes

  • apps/official-website: reset optimize on Reports dismount (db5656a)
  • apps/official-website: add use-accept-pattern hook for unified patterns across inputs (4bf83a8)
  • packages/hooks: loading of model buffer failed because of wrong types in development (1c4e734)

📖 Documentation

  • packages/hooks: add docstrings (e9465e4)
  • project: update readme documentations with viewer envOptions, options for optimizations and new texture compression optimization + misc. (0a1df16)

❤️ Thank You

  • Moritz Becker

0.5.0 (2024-10-09)

🚀 Features

  • apps/official-website: add vite-PWA (2765158)
  • apps/official-website: add Reports card component to editor (3b43ac7)
  • official-website: add lazy loading for page components (fe63d3d)
  • packages/hooks: advance on use-optimize-model hook (0c0b57e)
  • packages/hooks: rework optimizations hook integration + new way of creating optimize return object of use-load-model + added load-start event to event-system (2121bb5)

🩹 Fixes

  • apps/official-website: use actual optimizations in editor file-menu (d56034b)
  • apps/official-website: remove link canonical tag from index.html (7c0bb3b)
  • packages/hooks: export use-export-model from hooks package (f00e75f)

❤️ Thank You

  • Moritz Becker

0.4.0 (2024-10-07)

🚀 Features

  • apps/official-website: add environment controls to file-menu (f93f461)
  • apps/official-website: add basic env controls inside editor file menu (8c64913)
  • packages/viewer: add environment controls to VectrealViewer (218abdd)
  • shared: add tooltip component (fede1b2)

🩹 Fixes

  • official-website: font-family (2a6fca7)
  • packages/hooks: dependency externalization (6364c5d)
  • packages/viewer: center default loading spinner (6155c54)
  • shared: menubar disabled styling (8f564a5)

📖 Documentation

  • packages/viewer: add docstring to VectrealViewer component (bf37cf2)

❤️ Thank You

  • Moritz Becker

0.3.2 (2024-10-04)

🩹 Fixes

  • packages: dependency management on build (e25cade)

❤️ Thank You

  • Moritz Becker

0.3.1 (2024-09-22)

🩹 Fixes

  • project: remove unused deps and fix nx project with nx reset (c937184)

❤️ Thank You

  • Moritz Becker

0.3.0 (2024-09-22)

🚀 Features

  • packages/hooks: add use-export-model (60964b9)

🩹 Fixes

  • packages/hooks: use saveAs instead of custom utils function for saving file (30d78c1)

📖 Documentation

  • packages/hooks: add docstrings to new functoins (7ff1649)
  • packages/hooks: add docstrings to functions (06dd1b3)
  • packages/hooks: update readme (7449fc4)
  • packages/hooks: finalize docs for vctrl/hooks (8f9d6ca)
  • packages/viewer: update first example for viewer usage (eac73ed)

❤️ Thank You

  • Moritz Becker

0.2.2 (2024-09-13)

This was a version bump only, there were no code changes.

0.2.1 (2024-09-13)

🩹 Fixes

  • apps/official-website: change viewer import to use named syntax (6fd958a)
  • packages/viewer: add directory option to file input (a97d2c9)
  • packages/viewer: extension change of ìndex file (06b030b)
  • packages/viewer: memoize certain scene options (0051955)
  • project: extend paths in tsconfig.json (0a19d37)

📖 Documentation

  • packages/viewer: add WIP info to the top (3d1d729)
  • project: add mention of use-optimize-model hook (4212893)

❤️ Thank You

  • Moritz Becker

0.2.0 (2024-09-11)

🚀 Features

  • apps/official-website: add editor context provider (f42659a)
  • packages/hooks: add optimizer hook (78b9cd5)
  • project: Move shadcn components into shared library project and modify tsconfig paths (1f15bef)

🩹 Fixes

  • packages: rework build/publish executors (bfad14f)
  • packages/hooks: add meshopt decoder to gltf loader (87e2198)
  • packages/viewer: optimize initial props + rendering (42bbd6e)
  • project: remove playwright for apps/official-website (c2d7035)

📖 Documentation

  • packages/hooks: small changes (6dae863)
  • packages/hooks: add hooks/use-optimize-model to documentation (d5404cf)

❤️ Thank You

  • Moritz Becker

0.1.0 (2024-09-09)

🚀 Features

  • apps/official-website: add logo to nav-bar (aef2e1a)
  • apps/official-website: add seo meta information (14c93e5)

🩹 Fixes

  • packages: nx release executor configuration (9539735)
  • packages: publish docs along side build output (470496c)
  • packages/viewer: release executor package path (b55d888)

❤️ Thank You

  • Moritz Becker

0.0.9-4 (2024-09-08)

🩹 Fixes

  • packages/viewer: release executor package path (074af1b)

❤️ Thank You

  • Moritz Becker

0.0.9-3 (2024-09-08)

🚀 Features

  • apps/official-website: add logo to nav-bar (aef2e1a)
  • apps/official-website: add seo meta information (14c93e5)

🩹 Fixes

  • packages: nx release executor configuration (a6ae69c)

❤️ Thank You

  • Moritz Becker

0.0.9-2 (2024-08-29)

🩹 Fixes

  • packages: re-active build executor generating package.json files (4f34274)

❤️ Thank You

  • Moritz Becker

0.0.9-1 (2024-08-29)

🩹 Fixes

  • packages: prevent nx vite executor from changing package.json file (09fc53e)

❤️ Thank You

  • Moritz Becker

0.0.9 (2024-08-29)

🩹 Fixes

  • packages/hooks: remove files field from package.json (028a371)

❤️ Thank You

  • Moritz Becker

0.0.8 (2024-08-29)

This was a version bump only, there were no code changes.

0.0.7-9 (2024-08-29)

This was a version bump only, there were no code changes.

0.0.7-8 (2024-08-29)

🩹 Fixes

  • ci/cd: build command in version release gh workflow (ee9e3ea)
  • packages: Error verifying sigstore provenance bundleso add repository.url to packages package.json (681e94e)
  • packages: remove git type from repository fields in package.json files (629c1c8)
  • packages: change package.json files repository url type (db99ba5)
  • packages: also add repository.url to root + move .npmrc to root (3598f23)
  • project: nx version migration (837419d)

📖 Documentation

  • packages: update package descriptions and co. (b62cf76)
  • packages/viewer: add link to github in contributing section (98499e7)
  • project: clean up readme files (eadf146)

❤️ Thank You

  • Moritz Becker

0.0.7-7 (2024-08-29)

🩹 Fixes

  • packages: also add repository.url to root + move .npmrc to root (4410952)

❤️ Thank You

  • Moritz Becker

0.0.7-5 (2024-08-28)

🩹 Fixes

  • packages: change package.json files repository url type (f0aaece)

❤️ Thank You

  • Moritz Becker

0.0.7-4 (2024-08-28)

🩹 Fixes

  • packages: remove git type from repository fields in package.json files (f552727)

❤️ Thank You

  • Moritz Becker

0.0.7-3 (2024-08-28)

🩹 Fixes

  • packages: Error verifying sigstore provenance bundleso add repository.url to packages package.json (5c91ad6)

❤️ Thank You

  • Moritz Becker

0.0.7-2 (2024-08-28)

📖 Documentation

  • packages: update package descriptions and co. (1244950)

❤️ Thank You

  • Moritz Becker

0.0.7 (2024-08-28)

🩹 Fixes

  • ci/cd: build command in version release gh workflow (6a02c51)

📖 Documentation

  • packages/viewer: add link to github in contributing section (11e6dd8)
  • project: clean up readme files (fa9bab4)

❤️ Thank You

  • Moritz Becker

0.0.6 (2024-08-28)

📖 Documentation

  • packages/viewer: add link to github in contributing section (ae4c19c)

❤️ Thank You

  • Moritz Becker

0.0.3-3 (2024-08-28)

🩹 Fixes

  • project: versioning action (970f6f9)
  • project: npm/git release mechanism (f373e1f)

📖 Documentation

  • packages: add vctrl/hooks and vctrl/viewer documentation readme (ccb2ddd)
  • packages: add status badge to packages readme files (c64afab)
  • project: add status badges to docs (1f6ad74)
  • project: clean up readme files (a0a2f11)

❤️ Thank You

  • Moritz Becker

0.0.3-2 (2024-08-27)

🩹 Fixes

  • official-website/Dockerfile: use npm install instead of npm ci (fd3a78f)
  • package-lock.json: replace old lock file (11d5344)

❤️ Thank You

  • Moritz Becker

0.0.3-0 (2024-08-27)

🩹 Fixes

  • official-website/Dockerfile: use npm install instead of npm ci (fd3a78f)

❤️ Thank You

  • Moritz Becker

0.0.2 (2024-08-27)

This was a version bump only, there were no code changes.

0.0.2-4 (2024-08-27)

🩹 Fixes

  • package-lock.json: replace old lock file (11d5344)

❤️ Thank You

  • Moritz Becker

v0.0.2-2 (2024-08-27)

This was a version bump only, there were no code changes.

0.0.2-1 (2024-08-27)

This was a version bump only, there were no code changes.

0.0.2-0 (2024-08-27)

This was a version bump only, there were no code changes.