threejs-3d-viewer
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

3D Model Viewer

A React component for displaying 3D models (GLTF/GLB) using Three.js.

Installation

Install the package using npm or yarn:

npm install threejs-3d-viewer
# or
yarn add threejs-3d-viewer

Usage

Import the ModelPreview component and use it in your React application:

import React from 'react';
import { ModelPreview } from 'threejs-3d-viewer';

function App() {
  return (
    <div style={{ width: '100vw', height: '100vh' }}>
      <ModelPreview modelUrl="path/to/your/model.glb" />
    </div>
  );
}

export default App;

Props

The ModelPreview component accepts the following props:

Prop Type Default Description
modelUrl string Required URL or path to the 3D model file (GLTF/GLB).
backgroundColor string '#e0e0e0' Background color of the canvas.
environmentMap string studio_small_08_4k.exr (internal) Optional URL or path to a custom HDRI environment map.

Example with Custom Environment and Background

import React from 'react';
import { ModelPreview } from 'threejs-3d-viewer';
import myCustomHdri from './assets/my_custom_environment.exr?url'; // Ensure your bundler handles .exr?url imports

function App() {
  return (
    <div style={{ width: '800px', height: '600px' }}>
      <ModelPreview
        modelUrl="path/to/your/model.glb"
        backgroundColor="#333333"
        environmentMap={myCustomHdri}
      />
    </div>
  );
}

export default App;

Development

To build the package locally:

npm run build

License

MIT

Package Sidebar

Install

npm i threejs-3d-viewer

Weekly Downloads

33

Version

1.0.5

License

ISC

Unpacked Size

14.3 MB

Total Files

8

Last publish

Collaborators

  • joaofranco03