3d-spinner 0.9.4 → 0.9.5

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 (51) hide show
  1. package/dist/animations/charged-orb.js +4 -2
  2. package/dist/animations/ghost-train.js +3 -1
  3. package/dist/animations/spin.d.ts +3 -1
  4. package/dist/animations/spin.js +6 -1
  5. package/dist/cjs/animations/charged-orb.cjs +170 -28
  6. package/dist/cjs/animations/grid-assembly.cjs +164 -26
  7. package/dist/cjs/animations/object-motion.cjs +156 -24
  8. package/dist/cjs/animations/particles.cjs +167 -26
  9. package/dist/cjs/animations/spin.cjs +169 -27
  10. package/dist/cjs/engines/little-3d-engine/little-3d-engine.cjs +193 -45
  11. package/dist/cjs/engines/little-3d-engine/loaders/obj.cjs +51 -13
  12. package/dist/cjs/engines/little-3d-engine/renderers/canvas2d-textured.cjs +56 -6
  13. package/dist/cjs/engines/little-3d-engine/renderers/webgl-textured.cjs +55 -6
  14. package/dist/cjs/engines/little-3d-engine/renderers/webgpu-textured.cjs +64 -11
  15. package/dist/cjs/prefabs/prefabs.cjs +186 -40
  16. package/dist/engines/little-3d-engine/core/geometry.d.ts +15 -2
  17. package/dist/engines/little-3d-engine/core/geometry.js +25 -3
  18. package/dist/engines/little-3d-engine/core/light.d.ts +28 -4
  19. package/dist/engines/little-3d-engine/core/light.js +48 -7
  20. package/dist/engines/little-3d-engine/core/mesh.d.ts +33 -0
  21. package/dist/engines/little-3d-engine/core/mesh.js +12 -0
  22. package/dist/engines/little-3d-engine/little-3d-engine.d.ts +2 -2
  23. package/dist/engines/little-3d-engine/little-3d-engine.js +1 -1
  24. package/dist/engines/little-3d-engine/loaders/obj.d.ts +8 -7
  25. package/dist/engines/little-3d-engine/loaders/obj.js +74 -20
  26. package/dist/engines/little-3d-engine/renderers/canvas2d.js +23 -1
  27. package/dist/engines/little-3d-engine/renderers/webgl.js +34 -5
  28. package/dist/engines/little-3d-engine/renderers/webgpu.js +43 -10
  29. package/dist/engines/little-3d-engine/shapes/complex/plane.d.ts +8 -3
  30. package/dist/engines/little-3d-engine/shapes/complex/plane.js +10 -4
  31. package/dist/engines/little-3d-engine/shapes/primitives/cube.d.ts +3 -2
  32. package/dist/engines/little-3d-engine/shapes/primitives/cube.js +4 -2
  33. package/dist/engines/little-3d-engine/shapes/primitives/octahedron.d.ts +3 -2
  34. package/dist/engines/little-3d-engine/shapes/primitives/octahedron.js +4 -2
  35. package/dist/engines/little-3d-engine/shapes/primitives/pyramid.d.ts +3 -2
  36. package/dist/engines/little-3d-engine/shapes/primitives/pyramid.js +4 -2
  37. package/dist/engines/little-3d-engine/shapes/primitives/quad.d.ts +3 -2
  38. package/dist/engines/little-3d-engine/shapes/primitives/quad.js +4 -2
  39. package/dist/engines/little-3d-engine/shapes/primitives/spheres/cube-sphere.d.ts +3 -2
  40. package/dist/engines/little-3d-engine/shapes/primitives/spheres/cube-sphere.js +4 -2
  41. package/dist/engines/little-3d-engine/shapes/primitives/spheres/icosphere.d.ts +3 -2
  42. package/dist/engines/little-3d-engine/shapes/primitives/spheres/icosphere.js +4 -2
  43. package/dist/engines/little-3d-engine/shapes/primitives/spheres/octa-sphere.d.ts +3 -2
  44. package/dist/engines/little-3d-engine/shapes/primitives/spheres/octa-sphere.js +4 -2
  45. package/dist/engines/little-3d-engine/shapes/primitives/spheres/uv-sphere.d.ts +3 -2
  46. package/dist/engines/little-3d-engine/shapes/primitives/spheres/uv-sphere.js +4 -2
  47. package/dist/engines/little-3d-engine/shapes/primitives/tetrahedron.d.ts +3 -2
  48. package/dist/engines/little-3d-engine/shapes/primitives/tetrahedron.js +4 -2
  49. package/dist/umd/spinner.global.js +255 -63
  50. package/dist/umd/spinner.global.min.js +58 -17
  51. package/package.json +1 -1
@@ -1,8 +1,9 @@
1
- import type { Mesh } from "../../core/mesh.js";
1
+ import { type Material, type Mesh } from "../../core/mesh.js";
2
2
  /**
3
3
  * Build a regular octahedron mesh centered on the origin.
4
4
  *
5
5
  * @param size Distance between opposite vertices. Defaults to `1`.
6
6
  * @param colors Eight CSS colors, one per triangular face. Defaults to a built-in palette.
7
+ * @param material Optional surface material applied to every face.
7
8
  */
8
- export declare function octahedron(size?: number, colors?: string[]): Mesh;
9
+ export declare function octahedron(size?: number, colors?: string[], material?: Material): Mesh;
@@ -1,3 +1,4 @@
1
+ import { attachMaterial } from "../../core/mesh.js";
1
2
  const DEFAULT_COLORS = [
2
3
  "#3b82f6",
3
4
  "#8b5cf6",
@@ -13,8 +14,9 @@ const DEFAULT_COLORS = [
13
14
  *
14
15
  * @param size Distance between opposite vertices. Defaults to `1`.
15
16
  * @param colors Eight CSS colors, one per triangular face. Defaults to a built-in palette.
17
+ * @param material Optional surface material applied to every face.
16
18
  */
17
- export function octahedron(size = 1, colors = DEFAULT_COLORS) {
19
+ export function octahedron(size = 1, colors = DEFAULT_COLORS, material) {
18
20
  const r = size / 2;
19
21
  const vertices = [
20
22
  { x: r, y: 0, z: 0 },
@@ -34,5 +36,5 @@ export function octahedron(size = 1, colors = DEFAULT_COLORS) {
34
36
  { indices: [5, 3, 1], color: colors[6 % colors.length] },
35
37
  { indices: [5, 0, 3], color: colors[7 % colors.length] },
36
38
  ];
37
- return { vertices, faces };
39
+ return attachMaterial({ vertices, faces }, material);
38
40
  }
@@ -1,9 +1,10 @@
1
- import type { Mesh } from "../../core/mesh.js";
1
+ import { type Material, type Mesh } from "../../core/mesh.js";
2
2
  /**
3
3
  * Build a square pyramid mesh centered on the origin, base down.
4
4
  *
5
5
  * @param size Base edge length (also the height). Defaults to `1`.
6
6
  * @param colors Five CSS colors: the square base, then the four triangular sides.
7
7
  * Defaults to a built-in palette.
8
+ * @param material Optional surface material applied to every face.
8
9
  */
9
- export declare function pyramid(size?: number, colors?: string[]): Mesh;
10
+ export declare function pyramid(size?: number, colors?: string[], material?: Material): Mesh;
@@ -1,3 +1,4 @@
1
+ import { attachMaterial } from "../../core/mesh.js";
1
2
  const DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981"];
2
3
  /**
3
4
  * Build a square pyramid mesh centered on the origin, base down.
@@ -5,8 +6,9 @@ const DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981"];
5
6
  * @param size Base edge length (also the height). Defaults to `1`.
6
7
  * @param colors Five CSS colors: the square base, then the four triangular sides.
7
8
  * Defaults to a built-in palette.
9
+ * @param material Optional surface material applied to every face.
8
10
  */
9
- export function pyramid(size = 1, colors = DEFAULT_COLORS) {
11
+ export function pyramid(size = 1, colors = DEFAULT_COLORS, material) {
10
12
  const h = size / 2;
11
13
  const vertices = [
12
14
  { x: -h, y: -h, z: h },
@@ -22,5 +24,5 @@ export function pyramid(size = 1, colors = DEFAULT_COLORS) {
22
24
  { indices: [4, 2, 3], color: colors[3 % colors.length] },
23
25
  { indices: [4, 3, 0], color: colors[4 % colors.length] },
24
26
  ];
25
- return { vertices, faces };
27
+ return attachMaterial({ vertices, faces }, material);
26
28
  }
@@ -1,9 +1,10 @@
1
- import type { Mesh } from "../../core/mesh.js";
1
+ import { type Material, type Mesh } from "../../core/mesh.js";
2
2
  /**
3
3
  * Build a flat square in the XY plane, facing +Z, as a single four-vertex
4
4
  * face. Useful as a billboard when kept facing the camera.
5
5
  *
6
6
  * @param size Edge length. Defaults to `1`.
7
7
  * @param colors CSS color for the face. Defaults to a built-in blue.
8
+ * @param material Optional surface material applied to every face.
8
9
  */
9
- export declare function quad(size?: number, colors?: string[]): Mesh;
10
+ export declare function quad(size?: number, colors?: string[], material?: Material): Mesh;
@@ -1,3 +1,4 @@
1
+ import { attachMaterial } from "../../core/mesh.js";
1
2
  const DEFAULT_COLORS = ["#3b82f6"];
2
3
  /**
3
4
  * Build a flat square in the XY plane, facing +Z, as a single four-vertex
@@ -5,8 +6,9 @@ const DEFAULT_COLORS = ["#3b82f6"];
5
6
  *
6
7
  * @param size Edge length. Defaults to `1`.
7
8
  * @param colors CSS color for the face. Defaults to a built-in blue.
9
+ * @param material Optional surface material applied to every face.
8
10
  */
9
- export function quad(size = 1, colors = DEFAULT_COLORS) {
11
+ export function quad(size = 1, colors = DEFAULT_COLORS, material) {
10
12
  const s = size / 2;
11
13
  const vertices = [
12
14
  { x: -s, y: -s, z: 0 },
@@ -14,5 +16,5 @@ export function quad(size = 1, colors = DEFAULT_COLORS) {
14
16
  { x: s, y: s, z: 0 },
15
17
  { x: -s, y: s, z: 0 },
16
18
  ];
17
- return { vertices, faces: [{ indices: [0, 1, 2, 3], color: colors[0] }] };
19
+ return attachMaterial({ vertices, faces: [{ indices: [0, 1, 2, 3], color: colors[0] }] }, material);
18
20
  }
@@ -1,4 +1,4 @@
1
- import type { Mesh } from "../../../core/mesh.js";
1
+ import { type Material, type Mesh } from "../../../core/mesh.js";
2
2
  /**
3
3
  * Build a cube-sphere (spherified cube) centered on the origin: each cube face
4
4
  * is gridded and projected onto the sphere. Even, all-quad, no poles.
@@ -7,5 +7,6 @@ import type { Mesh } from "../../../core/mesh.js";
7
7
  * @param detail Subdivisions per cube face edge, `1` = simplest (6 quads).
8
8
  * Defaults to `1`.
9
9
  * @param colors CSS colors cycled across faces. Defaults to a built-in palette.
10
+ * @param material Optional surface material applied to every face.
10
11
  */
11
- export declare function cubeSphere(size?: number, detail?: number, colors?: string[]): Mesh;
12
+ export declare function cubeSphere(size?: number, detail?: number, colors?: string[], material?: Material): Mesh;
@@ -1,3 +1,4 @@
1
+ import { attachMaterial } from "../../../core/mesh.js";
1
2
  const DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
2
3
  // right x up == normal for each face, so generated quads wind CCW outward.
3
4
  const CUBE_FACES = [
@@ -16,8 +17,9 @@ const CUBE_FACES = [
16
17
  * @param detail Subdivisions per cube face edge, `1` = simplest (6 quads).
17
18
  * Defaults to `1`.
18
19
  * @param colors CSS colors cycled across faces. Defaults to a built-in palette.
20
+ * @param material Optional surface material applied to every face.
19
21
  */
20
- export function cubeSphere(size = 1, detail = 1, colors = DEFAULT_COLORS) {
22
+ export function cubeSphere(size = 1, detail = 1, colors = DEFAULT_COLORS, material) {
21
23
  const r = size / 2;
22
24
  const n = Math.max(1, Math.floor(detail));
23
25
  const vertices = [];
@@ -46,5 +48,5 @@ export function cubeSphere(size = 1, detail = 1, colors = DEFAULT_COLORS) {
46
48
  }
47
49
  }
48
50
  }
49
- return { vertices, faces };
51
+ return attachMaterial({ vertices, faces }, material);
50
52
  }
@@ -1,4 +1,4 @@
1
- import type { Mesh } from "../../../core/mesh.js";
1
+ import { type Material, type Mesh } from "../../../core/mesh.js";
2
2
  /**
3
3
  * Build an icosphere (subdivided icosahedron) centered on the origin. Gives the
4
4
  * most uniform triangle distribution of the sphere types.
@@ -7,5 +7,6 @@ import type { Mesh } from "../../../core/mesh.js";
7
7
  * @param detail Subdivision level, `1` = base icosahedron (20 faces). Each level
8
8
  * splits every triangle into four. Defaults to `1`.
9
9
  * @param colors CSS colors cycled across faces. Defaults to a built-in palette.
10
+ * @param material Optional surface material applied to every face.
10
11
  */
11
- export declare function icosphere(size?: number, detail?: number, colors?: string[]): Mesh;
12
+ export declare function icosphere(size?: number, detail?: number, colors?: string[], material?: Material): Mesh;
@@ -1,4 +1,5 @@
1
1
  import { sphereFromTriangles } from "../../../core/geometry.js";
2
+ import { attachMaterial } from "../../../core/mesh.js";
2
3
  const DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
3
4
  const T = (1 + Math.sqrt(5)) / 2;
4
5
  const SEED_VERTICES = [
@@ -45,7 +46,8 @@ const SEED_FACES = [
45
46
  * @param detail Subdivision level, `1` = base icosahedron (20 faces). Each level
46
47
  * splits every triangle into four. Defaults to `1`.
47
48
  * @param colors CSS colors cycled across faces. Defaults to a built-in palette.
49
+ * @param material Optional surface material applied to every face.
48
50
  */
49
- export function icosphere(size = 1, detail = 1, colors = DEFAULT_COLORS) {
50
- return sphereFromTriangles(SEED_VERTICES, SEED_FACES, size, detail, colors);
51
+ export function icosphere(size = 1, detail = 1, colors = DEFAULT_COLORS, material) {
52
+ return attachMaterial(sphereFromTriangles(SEED_VERTICES, SEED_FACES, size, detail, colors), material);
51
53
  }
@@ -1,4 +1,4 @@
1
- import type { Mesh } from "../../../core/mesh.js";
1
+ import { type Material, type Mesh } from "../../../core/mesh.js";
2
2
  /**
3
3
  * Build an octa-sphere (subdivided octahedron) centered on the origin.
4
4
  *
@@ -6,5 +6,6 @@ import type { Mesh } from "../../../core/mesh.js";
6
6
  * @param detail Subdivision level, `1` = base octahedron (8 faces). Each level
7
7
  * splits every triangle into four. Defaults to `1`.
8
8
  * @param colors CSS colors cycled across faces. Defaults to a built-in palette.
9
+ * @param material Optional surface material applied to every face.
9
10
  */
10
- export declare function octaSphere(size?: number, detail?: number, colors?: string[]): Mesh;
11
+ export declare function octaSphere(size?: number, detail?: number, colors?: string[], material?: Material): Mesh;
@@ -1,4 +1,5 @@
1
1
  import { sphereFromTriangles } from "../../../core/geometry.js";
2
+ import { attachMaterial } from "../../../core/mesh.js";
2
3
  const DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
3
4
  const SEED_VERTICES = [
4
5
  { x: 1, y: 0, z: 0 },
@@ -25,7 +26,8 @@ const SEED_FACES = [
25
26
  * @param detail Subdivision level, `1` = base octahedron (8 faces). Each level
26
27
  * splits every triangle into four. Defaults to `1`.
27
28
  * @param colors CSS colors cycled across faces. Defaults to a built-in palette.
29
+ * @param material Optional surface material applied to every face.
28
30
  */
29
- export function octaSphere(size = 1, detail = 1, colors = DEFAULT_COLORS) {
30
- return sphereFromTriangles(SEED_VERTICES, SEED_FACES, size, detail, colors);
31
+ export function octaSphere(size = 1, detail = 1, colors = DEFAULT_COLORS, material) {
32
+ return attachMaterial(sphereFromTriangles(SEED_VERTICES, SEED_FACES, size, detail, colors), material);
31
33
  }
@@ -1,4 +1,4 @@
1
- import type { Mesh } from "../../../core/mesh.js";
1
+ import { type Material, type Mesh } from "../../../core/mesh.js";
2
2
  /**
3
3
  * Build a UV (latitude/longitude) sphere centered on the origin.
4
4
  *
@@ -6,5 +6,6 @@ import type { Mesh } from "../../../core/mesh.js";
6
6
  * @param detail Tessellation level, `1` = simplest. Higher values add rings and
7
7
  * segments. Defaults to `1`.
8
8
  * @param colors CSS colors cycled across faces. Defaults to a built-in palette.
9
+ * @param material Optional surface material applied to every face.
9
10
  */
10
- export declare function uvSphere(size?: number, detail?: number, colors?: string[]): Mesh;
11
+ export declare function uvSphere(size?: number, detail?: number, colors?: string[], material?: Material): Mesh;
@@ -1,3 +1,4 @@
1
+ import { attachMaterial } from "../../../core/mesh.js";
1
2
  const DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "#ef4444"];
2
3
  /**
3
4
  * Build a UV (latitude/longitude) sphere centered on the origin.
@@ -6,8 +7,9 @@ const DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b", "#10b981", "
6
7
  * @param detail Tessellation level, `1` = simplest. Higher values add rings and
7
8
  * segments. Defaults to `1`.
8
9
  * @param colors CSS colors cycled across faces. Defaults to a built-in palette.
10
+ * @param material Optional surface material applied to every face.
9
11
  */
10
- export function uvSphere(size = 1, detail = 1, colors = DEFAULT_COLORS) {
12
+ export function uvSphere(size = 1, detail = 1, colors = DEFAULT_COLORS, material) {
11
13
  const r = size / 2;
12
14
  const d = Math.max(1, Math.floor(detail));
13
15
  const slices = Math.max(4, d * 4);
@@ -46,5 +48,5 @@ export function uvSphere(size = 1, detail = 1, colors = DEFAULT_COLORS) {
46
48
  color: color(),
47
49
  });
48
50
  }
49
- return { vertices, faces };
51
+ return attachMaterial({ vertices, faces }, material);
50
52
  }
@@ -1,8 +1,9 @@
1
- import type { Mesh } from "../../core/mesh.js";
1
+ import { type Material, type Mesh } from "../../core/mesh.js";
2
2
  /**
3
3
  * Build a regular tetrahedron mesh centered on the origin.
4
4
  *
5
5
  * @param size Approximate diameter. Defaults to `1`.
6
6
  * @param colors Four CSS colors, one per triangular face. Defaults to a built-in palette.
7
+ * @param material Optional surface material applied to every face.
7
8
  */
8
- export declare function tetrahedron(size?: number, colors?: string[]): Mesh;
9
+ export declare function tetrahedron(size?: number, colors?: string[], material?: Material): Mesh;
@@ -1,11 +1,13 @@
1
+ import { attachMaterial } from "../../core/mesh.js";
1
2
  const DEFAULT_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#f59e0b"];
2
3
  /**
3
4
  * Build a regular tetrahedron mesh centered on the origin.
4
5
  *
5
6
  * @param size Approximate diameter. Defaults to `1`.
6
7
  * @param colors Four CSS colors, one per triangular face. Defaults to a built-in palette.
8
+ * @param material Optional surface material applied to every face.
7
9
  */
8
- export function tetrahedron(size = 1, colors = DEFAULT_COLORS) {
10
+ export function tetrahedron(size = 1, colors = DEFAULT_COLORS, material) {
9
11
  const s = size / 2;
10
12
  const vertices = [
11
13
  { x: s, y: s, z: s },
@@ -19,5 +21,5 @@ export function tetrahedron(size = 1, colors = DEFAULT_COLORS) {
19
21
  { indices: [0, 2, 3], color: colors[2 % colors.length] },
20
22
  { indices: [1, 3, 2], color: colors[3 % colors.length] },
21
23
  ];
22
- return { vertices, faces };
24
+ return attachMaterial({ vertices, faces }, material);
23
25
  }