threedviewer 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +133 -96
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  # ThreeDViewer
2
3
 
3
4
  ThreeDViewer is a React component library for easily integrating Three.js-based 3D viewers into your web applications. It provides a simple and customizable way to display and interact with 3D objects in your React projects.
@@ -9,6 +10,7 @@ ThreeDViewer is a React component library for easily integrating Three.js-based
9
10
  - Support for various 3D object formats
10
11
  - Built-in camera controls
11
12
  - Responsive design
13
+ - Ability to handle external scenes and Three.js objects
12
14
 
13
15
  ## Installation
14
16
 
@@ -26,7 +28,7 @@ yarn add threedviewer
26
28
 
27
29
  ## Usage
28
30
 
29
- Here's a basic example of how to use the SimpleViewer component:
31
+ Here's a basic example of how to use the `SimpleViewer` component:
30
32
 
31
33
  ```jsx
32
34
  import React from 'react';
@@ -34,21 +36,92 @@ import { SimpleViewer } from 'threedviewer';
34
36
  import * as THREE from 'three';
35
37
 
36
38
  function App() {
37
- // Create a simple cube
38
- const geometry = new THREE.BoxGeometry(1, 1, 1);
39
- const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
40
- const cube = new THREE.Mesh(geometry, material);
41
-
42
- return (
43
- <div style={{ width: '100%', height: '400px' }}>
44
- <SimpleViewer object={cube} />
45
- </div>
46
- );
39
+ // Create a simple cube
40
+ const geometry = new THREE.BoxGeometry(1, 1, 1);
41
+ const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
42
+ const cube = new THREE.Mesh(geometry, material);
43
+
44
+ return (
45
+ <div style={{ width: '100%', height: '400px' }}>
46
+ <SimpleViewer object={cube} />
47
+ </div>
48
+ );
49
+ }
50
+
51
+ export default App;
52
+ ```
53
+
54
+ ## Handling External Scenes and Advanced Usage
55
+
56
+ ThreeDViewer now supports handling external Three.js scenes and objects, allowing for more advanced configurations and custom controls. Here's an example that integrates external camera, scene, and controls:
57
+
58
+ ```tsx
59
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
60
+ import * as THREE from 'three';
61
+ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
62
+ import { SimpleViewer, type SimpleViewerOptions, defaultOptions } from 'threedviewer';
63
+
64
+ function App() {
65
+ const mountRef = useRef<HTMLDivElement | null>(null);
66
+ const rendererRef = useRef<THREE.WebGLRenderer | null>(null);
67
+ const cameraRef = useRef<THREE.PerspectiveCamera | null>(null);
68
+ const sceneRef = useRef<THREE.Scene | null>(null);
69
+ const controlsRef = useRef<OrbitControls | null>(null);
70
+
71
+ const [camera, setCamera] = useState<THREE.PerspectiveCamera | null>(null);
72
+ const [scene, setScene] = useState<THREE.Scene | null>(null);
73
+
74
+ useEffect(() => {
75
+ if (cameraRef.current) {
76
+ setCamera(cameraRef.current);
77
+ }
78
+ if (sceneRef.current) {
79
+ setScene(sceneRef.current);
80
+ }
81
+ }, []);
82
+
83
+ const options: SimpleViewerOptions = useMemo(() => ({
84
+ ...defaultOptions,
85
+ staticScene: false,
86
+ backgroundColor: '#000000',
87
+ camera: {
88
+ ...defaultOptions.camera,
89
+ position: [12 * 6, 12 * 6, 12 * 6],
90
+ target: [0, 0, 0],
91
+ fov: 60,
92
+ autoFitToObject: false,
93
+ },
94
+ lights: {
95
+ ...defaultOptions.lights,
96
+ ambient: { intensity: 0.5 },
97
+ directional: { position: [10, 10, 5] },
98
+ },
99
+ helpers: {
100
+ ...defaultOptions.helpers,
101
+ grid: true,
102
+ axes: true,
103
+ },
104
+ threeBaseRefs: {
105
+ scene: sceneRef,
106
+ camera: cameraRef,
107
+ mountPoint: mountRef,
108
+ controls: controlsRef,
109
+ renderer: rendererRef,
110
+ },
111
+ }), []);
112
+
113
+ return (
114
+ <div style={{ width: '100%', height: '100vh' }}>
115
+ <SimpleViewer object={null} options={options} />
116
+ </div>
117
+ );
47
118
  }
48
119
 
49
120
  export default App;
50
121
  ```
51
122
 
123
+ In this example, we demonstrate how to use external scene references, handle camera controls, and customize the viewer options, allowing more flexibility in your 3D environment.
124
+
52
125
  ## API
53
126
 
54
127
  ### SimpleViewer
@@ -56,119 +129,83 @@ export default App;
56
129
  The main component for displaying 3D objects.
57
130
 
58
131
  Props:
59
- - `object` (required): A Three.js Object3D to be displayed in the viewer.
132
+ - `object` (required): A Three.js `Object3D` to be displayed in the viewer.
60
133
  - `options` (optional): An object containing viewer options (see below).
61
134
 
62
135
  ## Configuration Options
63
136
 
64
- SimpleViewer accepts an `options` prop for customization. Here's an overview of available options:
137
+ `SimpleViewer` accepts an `options` prop for customization. Here's an overview of available options:
65
138
 
66
139
  ```javascript
67
140
  const defaultOptions = {
68
- staticScene: true, // This param will stop rendering if there is no activity
69
- backgroundColor: '#f0f0f7',
70
- camera: {
71
- position: [6, 2, 1.2],
72
- target: [0, 0, 0],
73
- fov: 75,
74
- near: 0.1,
75
- far: 100000
76
- },
77
- lights: {
78
- ambient: { color: '#404040', intensity: 1 },
79
- hemisphere: {
80
- skyColor: '#ffffbb',
81
- groundColor: '#080820',
82
- intensity: 1
141
+ staticScene: true, // Stops rendering if there is no activity
142
+ backgroundColor: '#f0f0f7',
143
+ camera: {
144
+ position: [6, 2, 1.2],
145
+ target: [0, 0, 0],
146
+ fov: 75,
147
+ near: 0.1,
148
+ far: 100000
149
+ },
150
+ lights: {
151
+ ambient: { color: '#404040', intensity: 1 },
152
+ hemisphere: { skyColor: '#ffffbb', groundColor: '#080820', intensity: 1 },
153
+ directional: { color: '#ffffff', intensity: 1, position: [6, 6, 6], castShadow: true }
154
+ },
155
+ controls: {
156
+ enableDamping: true,
157
+ dampingFactor: 0.25,
158
+ enableZoom: true,
159
+ enableRotate: true,
160
+ enablePan: true
161
+ },
162
+ helpers: {
163
+ grid: true,
164
+ axes: false,
165
+ boundingBox: true
83
166
  },
84
- directional: {
85
- color: '#ffffff',
86
- intensity: 1,
87
- position: [6, 6, 6],
88
- castShadow: true
89
- }
90
- },
91
- controls: {
92
- enableDamping: true,
93
- dampingFactor: 0.25,
94
- enableZoom: true,
95
- enableRotate: true,
96
- enablePan: true
97
- },
98
- helpers: {
99
- grid: true,
100
- axes: false,
101
- boundingBox: true
102
- },
103
- animationLoop: null // External animation function
167
+ animationLoop: null, // External animation function
104
168
  }
105
169
  ```
106
170
 
107
- To use custom options:
108
-
109
- ```jsx
110
- import React from 'react';
111
- import { SimpleViewer, defaultOptions } from 'threedviewer';
112
- import * as THREE from 'three';
113
-
114
- function App() {
115
- const geometry = new THREE.BoxGeometry(1, 1, 1);
116
- const material = new THREE.MeshStandardMaterial({ color: 0x00ff00 });
117
- const cube = new THREE.Mesh(geometry, material);
118
-
119
- const customOptions = {
120
- ...defaultOptions,
121
- backgroundColor: '#000000',
122
- camera: {
123
- ...defaultOptions.camera,
124
- cameraPosition: [12 * 6, 12 * 6, 12 * 6],
125
- cameraTarget: [0, 0, 0],
126
- fov: 60,
127
- autoFitToObject: false,
128
- },
129
- lights: {
130
- ambient: { intensity: 0.5 },
131
- directional: { position: [10, 10, 5] }
132
- },
133
- };
134
-
135
- return (
136
- <div style={{ width: '100%', height: '400px' }}>
137
- <SimpleViewer object={cube} options={customOptions} />
138
- </div>
139
- );
140
- }
141
-
142
- export default App;
171
+ To use custom options, simply pass them to the `options` prop:
172
+
173
+ ```tsx
174
+ const customOptions = {
175
+ ...defaultOptions,
176
+ backgroundColor: '#000000',
177
+ camera: {
178
+ ...defaultOptions.camera,
179
+ position: [12 * 6, 12 * 6, 12 * 6],
180
+ target: [0, 0, 0],
181
+ fov: 60,
182
+ },
183
+ };
143
184
  ```
144
185
 
145
- This example demonstrates how to override specific options while leaving others at their default values. You only need to specify the options you want to change.
146
-
147
- For detailed explanations of each option, please refer to our [API documentation](link-to-api-docs).
148
-
149
186
  ## Development
150
187
 
151
188
  To set up the project for development:
152
189
 
153
190
  1. Clone the repository:
154
191
  ```
155
- git clone https://github.com/your-username/ThreeDViewer.git
192
+ git clone https://github.com/LEMing/threedviewer.git
156
193
  ```
157
194
 
158
195
  2. Install dependencies:
159
196
  ```
160
197
  cd ThreeDViewer
161
- npm install
198
+ make install
162
199
  ```
163
200
 
164
201
  3. Run the development server:
165
202
  ```
166
- npm run dev
203
+ make dev
167
204
  ```
168
205
 
169
206
  4. Build the project:
170
207
  ```
171
- npm run build
208
+ make build
172
209
  ```
173
210
 
174
211
  ## Testing
@@ -176,7 +213,7 @@ To set up the project for development:
176
213
  Run the test suite with:
177
214
 
178
215
  ```bash
179
- npm test
216
+ make test
180
217
  ```
181
218
 
182
219
  ## Contributing
@@ -185,9 +222,9 @@ Contributions are welcome! Please feel free to submit a Pull Request.
185
222
 
186
223
  ## License
187
224
 
188
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
225
+ This project is licensed under the MIT License
189
226
 
190
227
  ## Acknowledgments
191
228
 
192
- - Three.js for providing the 3D rendering capabilities
193
- - React for the component-based architecture
229
+ - [Three.js](https://threejs.org/) for providing the 3D rendering capabilities
230
+ - [React](https://reactjs.org/) for the component-based architecture
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "threedviewer",
3
3
  "private": false,
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "type": "module",
6
6
  "description": "A 3D viewer based on React and Three.js",
7
7
  "keywords": [