@solidrt/3d 0.0.58 → 0.0.60

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 (70) hide show
  1. package/AGENTS.md +734 -264
  2. package/README.md +4 -2
  3. package/examples/README.md +50 -4
  4. package/examples/bloom.tsx +113 -0
  5. package/examples/cascades.tsx +4 -4
  6. package/examples/collision.tsx +6 -6
  7. package/examples/exits.tsx +96 -0
  8. package/examples/first-person.tsx +5 -5
  9. package/examples/fleet.tsx +4 -4
  10. package/examples/fog.tsx +5 -5
  11. package/examples/instanced.tsx +70 -50
  12. package/examples/lamps.tsx +4 -4
  13. package/examples/lod.tsx +125 -0
  14. package/examples/materials.tsx +9 -9
  15. package/examples/morph.tsx +174 -0
  16. package/examples/normals.tsx +118 -0
  17. package/examples/{lit.tsx → phong.tsx} +9 -9
  18. package/examples/polyhedra.tsx +61 -0
  19. package/examples/scene-atlas.tsx +70 -0
  20. package/examples/scene-views.tsx +5 -5
  21. package/examples/shadows.tsx +9 -9
  22. package/examples/sky-lit.tsx +3 -3
  23. package/examples/skybox.tsx +5 -5
  24. package/examples/standard.tsx +2 -2
  25. package/examples/streams.tsx +122 -0
  26. package/examples/sweep-paths.tsx +5 -5
  27. package/examples/wireframe.tsx +24 -2
  28. package/package.json +3 -3
  29. package/src/clip.ts +18 -5
  30. package/src/color.ts +11 -2
  31. package/src/components/context.tsx +11 -2
  32. package/src/components/directional-light.tsx +2 -2
  33. package/src/components/first-person-camera.tsx +4 -4
  34. package/src/components/group.tsx +9 -5
  35. package/src/components/hemisphere-light.tsx +2 -2
  36. package/src/components/index.ts +4 -1
  37. package/src/components/instanced-mesh.tsx +28 -10
  38. package/src/components/lod.tsx +102 -0
  39. package/src/components/mesh.tsx +24 -6
  40. package/src/components/node-props.ts +35 -5
  41. package/src/components/orbit-camera.tsx +15 -12
  42. package/src/components/point-light.tsx +2 -2
  43. package/src/components/record-mesh.tsx +12 -7
  44. package/src/components/scene.tsx +55 -2
  45. package/src/components/spot-light.tsx +2 -2
  46. package/src/components/sprite.tsx +2 -2
  47. package/src/components/view3d.tsx +18 -1
  48. package/src/environment.ts +9 -8
  49. package/src/first-person.ts +125 -38
  50. package/src/geometry-gpu.ts +172 -39
  51. package/src/geometry.ts +1573 -239
  52. package/src/glsl.ts +398 -113
  53. package/src/gltf.ts +363 -141
  54. package/src/index.ts +31 -21
  55. package/src/light.ts +7 -8
  56. package/src/lod.ts +148 -0
  57. package/src/material.ts +316 -202
  58. package/src/mesh.ts +490 -256
  59. package/src/mixer.ts +27 -14
  60. package/src/model-file.ts +54 -15
  61. package/src/model.ts +86 -21
  62. package/src/motion.ts +17 -0
  63. package/src/node.ts +421 -22
  64. package/src/orbit.ts +378 -116
  65. package/src/profile.ts +4 -25
  66. package/src/resolve.ts +181 -0
  67. package/src/scene-shadows.ts +94 -93
  68. package/src/scene.ts +605 -185
  69. package/src/sweep.ts +27 -8
  70. package/tools/model.ts +3 -1
package/src/sweep.ts CHANGED
@@ -1,14 +1,14 @@
1
- // Swept solids: the generators that run a Profile (profile.ts) along a
2
- // path. extrude() sweeps along a straight line (z), lathe() around a
3
- // circle (about y), sweep() along an arbitrary 3D polyline with mitred
4
- // joints, and tube() is sweep() with a circular profile - the wire, rope
5
- // and pipe primitive. Output is the shared vertex layout of geometry.ts
1
+ // Profile generators: polygon() fills a Profile (profile.ts) as a flat
2
+ // face, the rest sweep it along a path. extrude() sweeps along a straight
3
+ // line (z), lathe() around a circle (about y), sweep() along an arbitrary
4
+ // 3D polyline with mitred joints, and tube() is sweep() with a circular
5
+ // profile - the wire, rope and pipe primitive. Output is the shared vertex layout of geometry.ts
6
6
  // with real texture UVs; winding is CCW seen from outside like every
7
7
  // generator, so cull: "back" works. Indices pick Uint16Array or
8
8
  // Uint32Array by vertex count - filleted profiles times many path points
9
9
  // make dense outputs routine here.
10
10
 
11
- import { STANDARD_FLOATS, packGeometry } from "./geometry.ts"
11
+ import { BASE_FLOATS, packGeometry } from "./geometry.ts"
12
12
  import type { Geometry, GeometryOptions } from "./geometry.ts"
13
13
  import { add, cross, dot, normalize, scale, sub } from "./math.ts"
14
14
  import type { Vec3 } from "./math.ts"
@@ -58,7 +58,7 @@ function emitCap(
58
58
  mirrorU: boolean,
59
59
  flip: boolean,
60
60
  ): void {
61
- let base = verts.length / STANDARD_FLOATS
61
+ let base = verts.length / BASE_FLOATS
62
62
  for (let i = 0; i < px.length; i++) {
63
63
  let p = place(px[i]!, py[i]!)
64
64
  let u = mirrorU ? (b.maxX - px[i]!) / b.w : (px[i]! - b.minX) / b.w
@@ -70,6 +70,25 @@ function emitCap(
70
70
  }
71
71
  }
72
72
 
73
+ /**
74
+ * The profile filled as a flat face in the XY plane facing +z - the
75
+ * general case of circle()/ring() for arbitrary outlines, and the 2D
76
+ * counterpart of polyhedron(). UVs map the
77
+ * profile's bounding box to the unit square like plane(); rotate flat the
78
+ * same way: `rotation={[-Math.PI / 2, 0, 0]}`.
79
+ */
80
+ export function polygon(profile: Profile, options: GeometryOptions = {}): Geometry {
81
+ let pts = normalizeProfile(profile)
82
+ let { minX, maxY, w, h } = profileBounds(pts)
83
+ let px = pts.map((p) => p.x)
84
+ let py = pts.map((p) => p.y)
85
+ let verts: number[] = []
86
+ for (let p of pts) {
87
+ verts.push(p.x, p.y, 0, 0, 0, 1, (p.x - minX) / w, (maxY - p.y) / h)
88
+ }
89
+ return packGeometry(verts, earClip(px, py), options)
90
+ }
91
+
73
92
  /**
74
93
  * The profile swept along z, centered on the origin: z runs from depth/2
75
94
  * down to -depth/2, caps at both ends. `bevel` rounds both rims with a
@@ -348,7 +367,7 @@ export function sweep(profile: Profile, path: SweepPath, options: GeometryOption
348
367
  let verts: number[] = []
349
368
  let indices: number[] = []
350
369
  let emitRing = (pos: Vec3[], normals: Vec3[], v: number): number => {
351
- let base = verts.length / STANDARD_FLOATS
370
+ let base = verts.length / BASE_FLOATS
352
371
  for (let k = 0; k < entries.length; k++) {
353
372
  let q = pos[k]!
354
373
  let m = normals[k]!
package/tools/model.ts CHANGED
@@ -45,9 +45,11 @@ let encoded = encodeModel(data)
45
45
  writeFileSync(output, encoded)
46
46
 
47
47
  let triangles = data.parts.reduce((n, p) => n + p.geometry.indices.length / 3, 0)
48
- let vertices = data.parts.reduce((n, p) => n + p.geometry.vertices.length / layoutStride(p.geometry.layout), 0)
48
+ let vertices = data.parts.reduce((n, p) => n + p.geometry.vertices.byteLength / layoutStride(p.geometry.layout), 0)
49
+ let targets = data.parts.reduce((n, p) => n + (p.geometry.morphs?.names.length ?? 0), 0)
49
50
  console.log(
50
51
  `${output}: ${data.nodes.length} nodes, ${data.parts.length} parts, ${vertices} vertices, ${triangles} triangles, ` +
52
+ (targets > 0 ? `${targets} morph targets, ` : "") +
51
53
  `${data.clips.length} clips, ${data.materials.length} materials, ${data.images.length} images, ${(encoded.byteLength / 1024).toFixed(0)} KiB ` +
52
54
  `(parsed in ${parsed.toFixed(0)} ms)`,
53
55
  )