@y-media/jewelry3dviewer
v0.0.39
Published
A sophisticated 3D ring configurator built with React, Three.js, and React Three Fiber. This application allows users to customize and view engagement rings with realistic diamond rendering and metal finishes.
Keywords
Readme
Diamond Ring Viewer
A sophisticated 3D ring configurator built with React, Three.js, and React Three Fiber. This application allows users to customize and view engagement rings with realistic diamond rendering and metal finishes.
Features
- Interactive 3D ring visualization
- Real-time material and color customization
- Realistic diamond rendering with caustics and refraction
- Customizable engraving
- Multiple metal options (White Gold, Yellow Gold, Rose Gold)
- Various stone color options
- Environment-based lighting and reflections
- Optional bloom and shadow effects
Technical Implementation
Scene Organization
The application uses Three.js layers for organized rendering:
- Layer 0: Environment (for reflections)
- Layer 1: Metal parts (head and shank)
- Layer 2: Diamonds
Component Structure
The scene is built from separate GLB models:
head.glb: Contains the crown and prongsshank.glb: Contains the ring band and accent stones
Meshes are categorized by naming convention:
DIA-*: Diamond componentsMTL-*: Metal componentsMTL-ENG-SHANK-1: Special engraving surface
Diamond Rendering System
CubeCamera and Caustics Integration
The application uses a sophisticated system for realistic diamond rendering:
<CubeCamera key={cameraKey} resolution={256} frames={1} envMap={modifiedGemTexture}>
{(texture) => (
<Caustics
backfaces
color={stoneColor}
lightSource={[5, 5, -10]}
ior={1.8}
intensity={0.1}>
<Diamonds material={MeshRefractionMaterial} />
</Caustics>
)}
</CubeCamera>Key features:
- Environment-mapped reflections using CubeCamera
- Realistic light refraction through stones
- Configurable caustics effects
- Layer-based reflection capture
- Optional simplified transmission material for performance
Stone Positioning
- Automatic stone offset calculation from shank center
- Dynamic positioning based on shank geometry
- Configurable stone offset distance
- Bounding box calculations for accurate placement
Materials and Lighting
Metal Materials
- Uses
MeshStandardMaterial - Configurable properties:
- Metalness
- Roughness
- Color
- Preset metal options:
- White Gold
- Yellow Gold
- Rose Gold
Diamond Materials
Two rendering modes:
- With Caustics:
- Uses
MeshRefractionMaterial - Full reflection and refraction
- Real-time environment mapping
- Uses
- Without Caustics:
- Uses
MeshTransmissionMaterial - Simplified transparency
- Better performance
- Uses
Environment and Effects
- HDR environment mapping
- Optional bloom effects
- Accumulative shadows
- Auto-rotation option
- Dynamic engraving with text rendering
Configuration Options
The application provides several customizable parameters:
- Caustics toggle
- Gem exposure
- Metal properties (metalness, roughness)
- Stone offset
- Shadow settings
- Bloom effects
- Auto-rotation
- IOR (Index of Refraction)
- Various material-specific parameters
Performance Considerations
- Layer-based rendering for optimal reflection calculations
- Optional caustics for performance vs quality trade-off
- Configurable bloom resolution
- Optimized environment map loading
- Preloaded assets for faster initialization
Development
This project is built with:
- React + Vite
- Three.js
- React Three Fiber
- React Three Drei
- Leva for controls
Available Scripts
npm run dev: Start development servernpm run build: Build for productionnpm run preview: Preview production build
ESLint Configuration
For production applications, we recommend:
- Using TypeScript with type-aware lint rules
- Checking out the TS template
- Integrating
typescript-eslint
Assets
Required 3D models and textures:
/public/source/head.glb/public/source/shank.glb/public/source/GEM-immersive.hdr/public/source/MTL-immersive.hdr
