three-instance-batch 0.1.1 → 0.1.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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/package.json +2 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 qiao-coding
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -37,6 +37,32 @@ function animate() {
37
37
 
38
38
  No `setMatrixAt`. No `needsUpdate`. Just change properties and call `update()`.
39
39
 
40
+ ## Multiple Instances
41
+
42
+ ```ts
43
+ const count = 500
44
+ const instances: Instance[] = []
45
+
46
+ for (let i = 0; i < count; i++) {
47
+ const inst = new Instance(geo, mat)
48
+ const angle = (i / count) * Math.PI * 2
49
+ inst.position.set(Math.cos(angle) * 10, 0, Math.sin(angle) * 10)
50
+ inst.color.setHSL(i / count, 0.8, 0.5)
51
+ instances.push(inst)
52
+ }
53
+ batcher.addInstance(instances)
54
+
55
+ function animate() {
56
+ for (let i = 0; i < instances.length; i++) {
57
+ instances[i].rotation.set(0, Date.now() * 0.001 + i * 0.1, 0)
58
+ instances[i].color.setHSL((Date.now() * 0.0001 + i * 0.002) % 1, 0.8, 0.5)
59
+ }
60
+ batcher.update(camera)
61
+ renderer.render(scene, camera)
62
+ requestAnimationFrame(animate)
63
+ }
64
+ ```
65
+
40
66
  ## How It Works
41
67
 
42
68
  `Instance` wraps `Vector3`, `Euler`, `Quaternion`, and `Color` setter methods at construction time. Any mutation via setter — `position.set()`, `rotation.set()`, `quaternion.setFromEuler()`, `color.setHSL()`, etc. — automatically marks that instance dirty. Note that direct property assignment (`position.x = 5`) is **not** tracked; use `setX()` or `set()` instead.
@@ -173,6 +199,19 @@ The real bottleneck at scale is GPU draw calls and vertex throughput, not JS-sid
173
199
 
174
200
  - Frustum culling collects per-instance visibility but does not yet skip culled instances in the render pass.
175
201
 
202
+ ## Development
203
+
204
+ ```bash
205
+ git clone https://github.com/qiao-coding/three-instance-batch.git
206
+ cd three-instance-batch
207
+ npm install
208
+ npm run test:run # 56 tests
209
+ npm run dev # start demo at localhost:5173
210
+ npm run build # build to dist/
211
+ ```
212
+
213
+ PRs welcome. Open an issue before starting on anything substantial.
214
+
176
215
  ## License
177
216
 
178
217
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-instance-batch",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Declarative instanced rendering for Three.js — Instance describes what, InstanceBatcher decides how to draw",
5
5
  "type": "module",
6
6
  "main": "./dist/three-instance-batch.js",
@@ -28,6 +28,7 @@
28
28
  "url": "https://github.com/qiao-coding/three-instance-batch.git"
29
29
  },
30
30
  "author": "qiao-coding",
31
+ "homepage": "https://github.com/qiao-coding/three-instance-batch#readme",
31
32
  "bugs": {
32
33
  "url": "https://github.com/qiao-coding/three-instance-batch/issues"
33
34
  },