three-zoo 0.5.0 → 0.5.2

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 +90 -67
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,116 +1,139 @@
1
- # three-zoo
2
-
3
- A modest collection of Three.js utilities designed to simplify common 3D development tasks.
4
-
5
- ## Install
1
+ <p align="center">
2
+ <h1 align="center">🦁 three-zoo</h1>
3
+ <p align="center">
4
+ A modest collection of Three.js utilities designed to simplify common 3D development tasks.
5
+ </p>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="https://www.npmjs.com/package/three-zoo"><img src="https://img.shields.io/npm/v/three-zoo.svg" alt="npm version"></a>
10
+ <a href="https://bundlephobia.com/package/three-zoo"><img src="https://badgen.net/bundlephobia/min/three-zoo" alt="bundle size (min)"></a>
11
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
12
+ <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-%5E5.8.0-blue" alt="TypeScript"></a>
13
+ <a href="https://threejs.org/"><img src="https://img.shields.io/badge/Three.js-%5E0.175.0-green" alt="Three.js"></a>
14
+ </p>
15
+
16
+ ## Features
17
+
18
+ - 📷 **DualFovCamera** - Independent horizontal and vertical FOV control with auto-fitting
19
+ - 🔍 **SceneTraversal** - Find and manipulate objects and materials in scene graphs
20
+ - 🎭 **SkinnedMeshBaker** - Convert animated meshes to static geometry for optimization
21
+ - ☀️ **Sun** - Intuitive spherical positioning for directional lights with HDR integration
22
+
23
+ ## Installation
6
24
 
7
25
  ```bash
8
26
  npm install three-zoo
9
27
  ```
10
28
 
11
- ## Overview
29
+ ## Quick Start
12
30
 
13
- **three-zoo** provides focused solutions for recurring challenges in 3D web development:
31
+ ```typescript
32
+ import { DualFovCamera, SceneTraversal, Sun } from 'three-zoo';
14
33
 
15
- - **Advanced camera controls** with independent FOV management and auto-fitting
16
- - **Intuitive lighting** with spherical positioning and HDR integration
17
- - **Scene graph utilities** for finding and manipulating objects and materials
18
- - **Animation baking** to convert skinned meshes to static geometry
34
+ // Camera with independent FOV control
35
+ const camera = new DualFovCamera(90, 60);
36
+ camera.fitVerticalFovToMesh(characterMesh);
37
+ camera.lookAtMeshCenterOfMass(characterMesh);
19
38
 
20
- Each utility is designed to work seamlessly with existing Three.js workflows without imposing architectural constraints.
39
+ // Scene traversal and manipulation
40
+ const enemies = SceneTraversal.filterObjects(scene, /^enemy_/);
41
+ const glassMaterials = SceneTraversal.filterMaterials(scene, /glass/i);
21
42
 
22
- ## Tools
43
+ // Intuitive sun positioning
44
+ const sun = new Sun();
45
+ sun.elevation = Math.PI / 4;
46
+ sun.azimuth = Math.PI / 2;
47
+ sun.configureShadowsForBoundingBox(sceneBounds);
48
+ ```
23
49
 
24
- ### DualFovCamera
50
+ ## DualFovCamera
25
51
 
26
- Camera with independent horizontal and vertical field of view control, plus advanced fitting capabilities:
52
+ Advanced camera with independent horizontal and vertical field of view:
27
53
 
28
54
  ```typescript
29
- const camera = new DualFovCamera(90, 60); // hFov, vFov
30
- camera.horizontalFov = 100; // Change horizontal FOV
31
- camera.verticalFov = 70; // Change vertical FOV
55
+ const camera = new DualFovCamera(90, 60);
56
+
57
+ // Independent FOV control
58
+ camera.horizontalFov = 100;
59
+ camera.verticalFov = 70;
32
60
 
33
- // Automatically adjust FOV to fit objects
61
+ // Auto-fit objects in view
34
62
  camera.fitVerticalFovToPoints(vertices);
35
63
  camera.fitVerticalFovToBox(boundingBox);
36
64
  camera.fitVerticalFovToMesh(skinnedMesh);
37
65
 
38
- // Point camera at mesh center of mass
66
+ // Smart camera positioning
39
67
  camera.lookAtMeshCenterOfMass(skinnedMesh);
40
-
41
- // Get actual FOV after aspect ratio calculations
42
- const actualHFov = camera.getActualHorizontalFov();
43
- const actualVFov = camera.getActualVerticalFov();
44
68
  ```
45
69
 
46
- ### Sun
70
+ ## SceneTraversal
47
71
 
48
- Directional light with intuitive spherical positioning and automatic shadow configuration:
72
+ Navigate and manipulate Three.js scene graphs:
49
73
 
50
74
  ```typescript
51
- const sun = new Sun();
52
-
53
- // Spherical positioning
54
- sun.elevation = Math.PI / 4; // 45° above horizon
55
- sun.azimuth = Math.PI / 2; // 90° rotation
56
- sun.distance = 100; // Distance from origin
57
-
58
- // Automatically configure shadows for optimal coverage
59
- sun.configureShadowsForBoundingBox(sceneBounds);
60
-
61
- // Position sun based on brightest point in HDR environment map
62
- sun.setDirectionFromHDRTexture(hdrTexture, 50);
63
- ```
64
-
65
- ### SceneTraversal
66
-
67
- Scene graph navigation and batch operations for finding and manipulating objects:
75
+ // Find by name
76
+ const player = SceneTraversal.getObjectByName(scene, 'Player');
77
+ const metal = SceneTraversal.getMaterialByName(scene, 'MetalMaterial');
68
78
 
69
- ```typescript
70
- // Find objects and materials by name
71
- const obj = SceneTraversal.getObjectByName(scene, 'player');
72
- const material = SceneTraversal.getMaterialByName(scene, 'metal');
73
-
74
- // Filter with patterns or custom functions
79
+ // Filter with patterns
75
80
  const enemies = SceneTraversal.filterObjects(scene, /^enemy_/);
76
- const glassMaterials = SceneTraversal.filterMaterials(scene, /glass/i);
81
+ const glassMats = SceneTraversal.filterMaterials(scene, /glass/i);
77
82
 
78
- // Find objects that use specific materials
79
- const meshesWithGlass = SceneTraversal.findMaterialUsers(scene, /glass/i);
83
+ // Find material users
84
+ const glassObjects = SceneTraversal.findMaterialUsers(scene, /glass/i);
80
85
 
81
- // Batch operations on specific object types
82
- SceneTraversal.enumerateObjectsByType(scene, Mesh, (mesh) => {
83
- mesh.castShadow = true;
84
- });
85
-
86
- // Process all materials in the scene
86
+ // Batch operations
87
87
  SceneTraversal.enumerateMaterials(scene, (material) => {
88
88
  if ('roughness' in material) material.roughness = 0.8;
89
89
  });
90
90
  ```
91
91
 
92
- ### SkinnedMeshBaker
92
+ ## SkinnedMeshBaker
93
93
 
94
- Converts animated skinned meshes to static geometry:
94
+ Convert animated meshes to static geometry:
95
95
 
96
96
  ```typescript
97
- // Bake current pose to static mesh
97
+ // Bake current pose
98
98
  const staticMesh = SkinnedMeshBaker.bakePose(skinnedMesh);
99
99
 
100
100
  // Bake specific animation frame
101
101
  const frameMesh = SkinnedMeshBaker.bakeAnimationFrame(
102
- armature, // Root object with bones
103
- skinnedMesh, // Mesh to bake
104
- 1.5, // Time in seconds
105
- animationClip // Animation to sample
102
+ armature,
103
+ skinnedMesh,
104
+ 1.5, // Time in seconds
105
+ animationClip
106
106
  );
107
107
  ```
108
108
 
109
+ ## Sun
110
+
111
+ Directional light with spherical positioning:
112
+
113
+ ```typescript
114
+ const sun = new Sun();
115
+
116
+ // Spherical coordinates
117
+ sun.elevation = Math.PI / 4; // 45° above horizon
118
+ sun.azimuth = Math.PI / 2; // 90° rotation
119
+ sun.distance = 100; // Distance from origin
120
+
121
+ // Automatic shadow configuration
122
+ sun.configureShadowsForBoundingBox(sceneBounds);
123
+
124
+ // Position from HDR environment map
125
+ sun.setDirectionFromHDRTexture(hdrTexture, 50);
126
+ ```
127
+
109
128
  ## Requirements
110
129
 
111
- - Three.js >= 0.150.0
130
+ - Three.js ^0.175.0 (peer dependency)
112
131
  - TypeScript support included
113
132
 
133
+ ## Contributing
134
+
135
+ Contributions are welcome! Please feel free to submit issues and pull requests.
136
+
114
137
  ## License
115
138
 
116
- MIT
139
+ MIT © [jango](https://github.com/jango-git)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-zoo",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Some reusable bits for building things with Three.js ",
5
5
  "scripts": {
6
6
  "clean": "rm -rf dist",