@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.
- package/AGENTS.md +734 -264
- package/README.md +4 -2
- package/examples/README.md +50 -4
- package/examples/bloom.tsx +113 -0
- package/examples/cascades.tsx +4 -4
- package/examples/collision.tsx +6 -6
- package/examples/exits.tsx +96 -0
- package/examples/first-person.tsx +5 -5
- package/examples/fleet.tsx +4 -4
- package/examples/fog.tsx +5 -5
- package/examples/instanced.tsx +70 -50
- package/examples/lamps.tsx +4 -4
- package/examples/lod.tsx +125 -0
- package/examples/materials.tsx +9 -9
- package/examples/morph.tsx +174 -0
- package/examples/normals.tsx +118 -0
- package/examples/{lit.tsx → phong.tsx} +9 -9
- package/examples/polyhedra.tsx +61 -0
- package/examples/scene-atlas.tsx +70 -0
- package/examples/scene-views.tsx +5 -5
- package/examples/shadows.tsx +9 -9
- package/examples/sky-lit.tsx +3 -3
- package/examples/skybox.tsx +5 -5
- package/examples/standard.tsx +2 -2
- package/examples/streams.tsx +122 -0
- package/examples/sweep-paths.tsx +5 -5
- package/examples/wireframe.tsx +24 -2
- package/package.json +3 -3
- package/src/clip.ts +18 -5
- package/src/color.ts +11 -2
- package/src/components/context.tsx +11 -2
- package/src/components/directional-light.tsx +2 -2
- package/src/components/first-person-camera.tsx +4 -4
- package/src/components/group.tsx +9 -5
- package/src/components/hemisphere-light.tsx +2 -2
- package/src/components/index.ts +4 -1
- package/src/components/instanced-mesh.tsx +28 -10
- package/src/components/lod.tsx +102 -0
- package/src/components/mesh.tsx +24 -6
- package/src/components/node-props.ts +35 -5
- package/src/components/orbit-camera.tsx +15 -12
- package/src/components/point-light.tsx +2 -2
- package/src/components/record-mesh.tsx +12 -7
- package/src/components/scene.tsx +55 -2
- package/src/components/spot-light.tsx +2 -2
- package/src/components/sprite.tsx +2 -2
- package/src/components/view3d.tsx +18 -1
- package/src/environment.ts +9 -8
- package/src/first-person.ts +125 -38
- package/src/geometry-gpu.ts +172 -39
- package/src/geometry.ts +1573 -239
- package/src/glsl.ts +398 -113
- package/src/gltf.ts +363 -141
- package/src/index.ts +31 -21
- package/src/light.ts +7 -8
- package/src/lod.ts +148 -0
- package/src/material.ts +316 -202
- package/src/mesh.ts +490 -256
- package/src/mixer.ts +27 -14
- package/src/model-file.ts +54 -15
- package/src/model.ts +86 -21
- package/src/motion.ts +17 -0
- package/src/node.ts +421 -22
- package/src/orbit.ts +378 -116
- package/src/profile.ts +4 -25
- package/src/resolve.ts +181 -0
- package/src/scene-shadows.ts +94 -93
- package/src/scene.ts +605 -185
- package/src/sweep.ts +27 -8
- package/tools/model.ts +3 -1
package/src/sweep.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
//
|
|
2
|
-
// path. extrude() sweeps along a straight
|
|
3
|
-
// circle (about y), sweep() along an arbitrary
|
|
4
|
-
// joints, and tube() is sweep() with a circular
|
|
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 {
|
|
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 /
|
|
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 /
|
|
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.
|
|
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
|
)
|