0.9.5 • Published 4 months ago

@vctrl/viewer v0.9.5

Weekly downloads
-
License
AGPL-3.0-only
Repository
github
Last release
4 months ago

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

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.

0.9.5

4 months ago

0.9.4

8 months ago

0.9.3

8 months ago

0.9.2

8 months ago

0.9.0

8 months ago

0.9.1

8 months ago

0.8.0

9 months ago

0.7.8

9 months ago

0.7.7

9 months ago

0.7.6

9 months ago

0.7.5

9 months ago

0.7.4

9 months ago

0.7.3

9 months ago

0.7.0

9 months ago

0.0.3-3

11 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.1

10 months ago

0.0.9

11 months ago

0.0.9-2

11 months ago

0.0.8

11 months ago

0.0.9-1

11 months ago

0.5.0

9 months ago

0.3.2

10 months ago

0.0.7-9

11 months ago

0.4.0

9 months ago

0.3.1

10 months ago

0.2.2

10 months ago

0.0.7-8

11 months ago

0.0.7-7

11 months ago

0.0.7

11 months ago

0.6.0

9 months ago

0.0.9-4

10 months ago

0.0.3-2

11 months ago

0.0.3-0

11 months ago

0.0.2

11 months ago

0.0.2-2

11 months ago