@wardic/three 0.0.0-stage → 1.3.1

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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +84 -2
  3. package/THIRD_PARTY_NOTICES.md +145 -0
  4. package/dist/TestStage.d.ts +45 -0
  5. package/dist/TestStage.d.ts.map +1 -0
  6. package/dist/TestStage.js +140 -0
  7. package/dist/TestStage.js.map +1 -0
  8. package/dist/ThreeColours.d.ts +53 -0
  9. package/dist/ThreeColours.d.ts.map +1 -0
  10. package/dist/ThreeColours.js +246 -0
  11. package/dist/ThreeColours.js.map +1 -0
  12. package/dist/ThreeDrag.d.ts +82 -0
  13. package/dist/ThreeDrag.d.ts.map +1 -0
  14. package/dist/ThreeDrag.js +243 -0
  15. package/dist/ThreeDrag.js.map +1 -0
  16. package/dist/ThreeInput.d.ts +69 -0
  17. package/dist/ThreeInput.d.ts.map +1 -0
  18. package/dist/ThreeInput.js +592 -0
  19. package/dist/ThreeInput.js.map +1 -0
  20. package/dist/ThreeInstances.d.ts +47 -0
  21. package/dist/ThreeInstances.d.ts.map +1 -0
  22. package/dist/ThreeInstances.js +392 -0
  23. package/dist/ThreeInstances.js.map +1 -0
  24. package/dist/ThreeRenderer.d.ts +45 -0
  25. package/dist/ThreeRenderer.d.ts.map +1 -0
  26. package/dist/ThreeRenderer.js +121 -0
  27. package/dist/ThreeRenderer.js.map +1 -0
  28. package/dist/ThreeValues.d.ts +15 -0
  29. package/dist/ThreeValues.d.ts.map +1 -0
  30. package/dist/ThreeValues.js +61 -0
  31. package/dist/ThreeValues.js.map +1 -0
  32. package/dist/WardicThree.d.ts +207 -0
  33. package/dist/WardicThree.d.ts.map +1 -0
  34. package/dist/WardicThree.js +162 -0
  35. package/dist/WardicThree.js.map +1 -0
  36. package/dist/index.d.ts +26 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +27 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/internal/dev.d.ts +10 -0
  41. package/dist/internal/dev.d.ts.map +1 -0
  42. package/dist/internal/dev.js +11 -0
  43. package/dist/internal/dev.js.map +1 -0
  44. package/dist/internal/dev.production.d.ts +8 -0
  45. package/dist/internal/dev.production.d.ts.map +1 -0
  46. package/dist/internal/dev.production.js +8 -0
  47. package/dist/internal/dev.production.js.map +1 -0
  48. package/dist/internal/lookup.d.ts +29 -0
  49. package/dist/internal/lookup.d.ts.map +1 -0
  50. package/dist/internal/lookup.js +245 -0
  51. package/dist/internal/lookup.js.map +1 -0
  52. package/dist/internal/shared-material.d.ts +8 -0
  53. package/dist/internal/shared-material.d.ts.map +1 -0
  54. package/dist/internal/shared-material.js +95 -0
  55. package/dist/internal/shared-material.js.map +1 -0
  56. package/dist/solid/feature.d.ts +42 -0
  57. package/dist/solid/feature.d.ts.map +1 -0
  58. package/dist/solid/feature.js +2 -0
  59. package/dist/solid/feature.js.map +1 -0
  60. package/dist/solid/scene-batch.d.ts +10 -0
  61. package/dist/solid/scene-batch.d.ts.map +1 -0
  62. package/dist/solid/scene-batch.js +436 -0
  63. package/dist/solid/scene-batch.js.map +1 -0
  64. package/dist/solid/scene-object.d.ts +27 -0
  65. package/dist/solid/scene-object.d.ts.map +1 -0
  66. package/dist/solid/scene-object.js +111 -0
  67. package/dist/solid/scene-object.js.map +1 -0
  68. package/dist/solid/stage-batches.d.ts +10 -0
  69. package/dist/solid/stage-batches.d.ts.map +1 -0
  70. package/dist/solid/stage-batches.js +6 -0
  71. package/dist/solid/stage-batches.js.map +1 -0
  72. package/dist/solid/stage-drag.d.ts +4 -0
  73. package/dist/solid/stage-drag.d.ts.map +1 -0
  74. package/dist/solid/stage-drag.js +19 -0
  75. package/dist/solid/stage-drag.js.map +1 -0
  76. package/dist/solid/stage.d.ts +107 -0
  77. package/dist/solid/stage.d.ts.map +1 -0
  78. package/dist/solid/stage.js +320 -0
  79. package/dist/solid/stage.js.map +1 -0
  80. package/dist/solid/test-stage.d.ts +29 -0
  81. package/dist/solid/test-stage.d.ts.map +1 -0
  82. package/dist/solid/test-stage.js +16 -0
  83. package/dist/solid/test-stage.js.map +1 -0
  84. package/dist/solid.d.ts +55 -0
  85. package/dist/solid.d.ts.map +1 -0
  86. package/dist/solid.js +9 -0
  87. package/dist/solid.js.map +1 -0
  88. package/package.json +99 -4
  89. package/src/TestStage.ts +177 -0
  90. package/src/ThreeColours.ts +259 -0
  91. package/src/ThreeDrag.ts +341 -0
  92. package/src/ThreeInput.ts +744 -0
  93. package/src/ThreeInstances.ts +481 -0
  94. package/src/ThreeRenderer.ts +159 -0
  95. package/src/ThreeValues.ts +69 -0
  96. package/src/WardicThree.ts +364 -0
  97. package/src/index.ts +26 -0
  98. package/src/internal/dev.production.ts +7 -0
  99. package/src/internal/dev.ts +10 -0
  100. package/src/internal/lookup.ts +247 -0
  101. package/src/internal/shared-material.ts +101 -0
  102. package/src/solid/feature.ts +38 -0
  103. package/src/solid/scene-batch.ts +490 -0
  104. package/src/solid/scene-object.ts +145 -0
  105. package/src/solid/stage-batches.ts +13 -0
  106. package/src/solid/stage-drag.ts +26 -0
  107. package/src/solid/stage.ts +409 -0
  108. package/src/solid/test-stage.ts +40 -0
  109. package/src/solid.ts +111 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `@wardic/three`: Wardic for three.js. Motion's `animate` on a scene's meshes, materials, cameras,
3
+ * lights and uniforms, by Motion's key names in three's own types, on frames the Host loop pumps. The
4
+ * root re-exports each module as a namespace; code imports the subpath,
5
+ * `import * as WardicThree from "@wardic/three/WardicThree"`.
6
+ *
7
+ * @example
8
+ * import { WardicThree } from "@wardic/three"
9
+ *
10
+ * const wardic = WardicThree.make()
11
+ * renderer.setAnimationLoop((time) => {
12
+ * wardic.frame(time)
13
+ * renderer.render(scene, camera)
14
+ * })
15
+ * wardic.animate(cube, { y: 2, rotateY: 180 })
16
+ *
17
+ * @module
18
+ */
19
+ export * as TestStage from "./TestStage.ts";
20
+ export * as ThreeColours from "./ThreeColours.ts";
21
+ export * as ThreeInput from "./ThreeInput.ts";
22
+ export * as ThreeInstances from "./ThreeInstances.ts";
23
+ export * as ThreeRenderer from "./ThreeRenderer.ts";
24
+ export * as ThreeValues from "./ThreeValues.ts";
25
+ export * as WardicThree from "./WardicThree.ts";
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `@wardic/three`: Wardic for three.js. Motion's `animate` on a scene's meshes, materials, cameras,
3
+ * lights and uniforms, by Motion's key names in three's own types, on frames the Host loop pumps. The
4
+ * root re-exports each module as a namespace; code imports the subpath,
5
+ * `import * as WardicThree from "@wardic/three/WardicThree"`.
6
+ *
7
+ * @example
8
+ * import { WardicThree } from "@wardic/three"
9
+ *
10
+ * const wardic = WardicThree.make()
11
+ * renderer.setAnimationLoop((time) => {
12
+ * wardic.frame(time)
13
+ * renderer.render(scene, camera)
14
+ * })
15
+ * wardic.animate(cube, { y: 2, rotateY: 180 })
16
+ *
17
+ * @module
18
+ */
19
+ // #883 (ADR-0068, ADR-0069, ADR-0073): shipped from 1.3 (#564), with `@wardic/object`.
20
+ export * as TestStage from "./TestStage.js";
21
+ export * as ThreeColours from "./ThreeColours.js";
22
+ export * as ThreeInput from "./ThreeInput.js";
23
+ export * as ThreeInstances from "./ThreeInstances.js";
24
+ export * as ThreeRenderer from "./ThreeRenderer.js";
25
+ export * as ThreeValues from "./ThreeValues.js";
26
+ export * as WardicThree from "./WardicThree.js";
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,uFAAuF;AACvF,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Development: on. The package's `development` export condition resolves this module, as Foldkit's
3
+ * `DEV` is (#791, Q10); a production build resolves `dev.production.ts`, so a check under `DEV` and
4
+ * what it calls are dropped from it. Tested in a plain `if` or `&&`, never through `Bool`, as a
5
+ * build-time flag is (`docs/agents/effect-first.md`, *Pitfalls*).
6
+ *
7
+ * @module
8
+ */
9
+ export declare const DEV = true;
10
+ //# sourceMappingURL=dev.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/internal/dev.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,GAAG,OAAO,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Development: on. The package's `development` export condition resolves this module, as Foldkit's
3
+ * `DEV` is (#791, Q10); a production build resolves `dev.production.ts`, so a check under `DEV` and
4
+ * what it calls are dropped from it. Tested in a plain `if` or `&&`, never through `Bool`, as a
5
+ * build-time flag is (`docs/agents/effect-first.md`, *Pitfalls*).
6
+ *
7
+ * @module
8
+ */
9
+ // #883 (ADR-0073, *Amendment (#883)*, Q6): the shared-material warning's gate.
10
+ export const DEV = true;
11
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/internal/dev.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Development: off. What a build that doesn't resolve the `development` export condition gets for
3
+ * `@wardic/three/internal/dev` (#883, Q6): `dev.ts` is the other half.
4
+ *
5
+ * @module
6
+ */
7
+ export declare const DEV = false;
8
+ //# sourceMappingURL=dev.production.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.production.d.ts","sourceRoot":"","sources":["../../src/internal/dev.production.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,GAAG,QAAQ,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Development: off. What a build that doesn't resolve the `development` export condition gets for
3
+ * `@wardic/three/internal/dev` (#883, Q6): `dev.ts` is the other half.
4
+ *
5
+ * @module
6
+ */
7
+ export const DEV = false;
8
+ //# sourceMappingURL=dev.production.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.production.js","sourceRoot":"","sources":["../../src/internal/dev.production.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,CAAA"}
@@ -0,0 +1,29 @@
1
+ /** Any object Wardic reads a key of. */
2
+ type Holder = Record<string, unknown>;
3
+ /** Degrees to radians: a rotation's keys are in degrees, three's `rotation` in radians. */
4
+ export declare const RADIANS: number;
5
+ /** Whether `key` is a scene object's transform key. */
6
+ export declare const isTransformKey: (key: string) => boolean;
7
+ /** Whether `subject` is a scene object: three's `Object3D`, by its flag (ADR-0069 decision 3). */
8
+ export declare const isObject3D: (subject: unknown) => boolean;
9
+ /** Whether `holder` is a material, by its flag. */
10
+ export declare const isMaterial: (holder: unknown) => boolean;
11
+ /** The materials `subject` draws with: its `material`, or each of an array of them. None for a Subject without one. */
12
+ export declare const materialsOf: (subject: Holder) => ReadonlyArray<Holder>;
13
+ /** Where a key is written: each holder's own property, by its name, in parallel lists. */
14
+ export interface Place {
15
+ readonly holders: ReadonlyArray<Holder>;
16
+ readonly props: ReadonlyArray<string>;
17
+ /** The Subject's `material` the place was found under: found again once it changes. */
18
+ readonly material: unknown;
19
+ }
20
+ /** The Color `key` names on `subject`: its own, else its material's (the first of an array that has one), its own uniform's or its material's. */
21
+ export declare const colourOf: (subject: object, key: string) => Holder | undefined;
22
+ /** Where `key` lives on `subject`, kept until its material changes. */
23
+ export declare const placeOf: (subject: Holder, key: string) => Place | undefined;
24
+ /** `subject`'s value for `key` now, where the lookup finds it: `undefined` where it's nowhere. */
25
+ export declare const read: (subject: object, key: string) => unknown;
26
+ /** `value` written to `key` on `subject`, where the lookup finds it, with `opacity`'s rule after it: nowhere, nothing written. */
27
+ export declare const write: (subject: Holder, key: string, value: unknown) => void;
28
+ export {};
29
+ //# sourceMappingURL=lookup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../../src/internal/lookup.ts"],"names":[],"mappings":"AAcA,wCAAwC;AACxC,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAErC,2FAA2F;AAC3F,eAAO,MAAM,OAAO,QAAgB,CAAA;AAKpC,uDAAuD;AACvD,eAAO,MAAM,cAAc,QAAS,MAAM,KAAG,OAA8B,CAAA;AAE3E,kGAAkG;AAClG,eAAO,MAAM,UAAU,YAAa,OAAO,KAAG,OAAiF,CAAA;AAE/H,mDAAmD;AACnD,eAAO,MAAM,UAAU,WAAY,OAAO,KAAG,OAA+E,CAAA;AAQ5H,uHAAuH;AACvH,eAAO,MAAM,WAAW,YAAa,MAAM,KAAG,aAAa,CAAC,MAAM,CAKjE,CAAA;AAED,0FAA0F;AAC1F,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACvC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACrC,uFAAuF;IACvF,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B;AAgGD,kJAAkJ;AAClJ,eAAO,MAAM,QAAQ,YAAa,MAAM,OAAO,MAAM,KAAG,MAAM,GAAG,SAShE,CAAA;AAMD,uEAAuE;AACvE,eAAO,MAAM,OAAO,YAAa,MAAM,OAAO,MAAM,KAAG,KAAK,GAAG,SAe9D,CAAA;AAuBD,kGAAkG;AAClG,eAAO,MAAM,IAAI,YAAa,MAAM,OAAO,MAAM,KAAG,OAMnD,CAAA;AAyBD,kIAAkI;AAClI,eAAO,MAAM,KAAK,YAAa,MAAM,OAAO,MAAM,SAAS,OAAO,KAAG,IAUpE,CAAA"}
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Where a key a three.js Subject animates lives, read and written alike: a scene object's transform
3
+ * keys on its `position`, `rotation` (in degrees) and `scale`; any other key the Subject's own number,
4
+ * else found on its material, its uniforms or a vector's axis, as Motion's `motion/three` finds it.
5
+ *
6
+ * @internal
7
+ */
8
+ // `@wardic/three`'s lookup (#883; ADR-0069 decisions 4–6, ADR-0073 decision 23 and *Amendment (#883)*, Q3).
9
+ // A key's place is found once per Subject and kept, so a frame's write allocates nothing; it's found
10
+ // again once the Subject's material changes. Plain code: the writer calls it per frame.
11
+ import { DEV } from "@wardic/three/internal/dev";
12
+ import * as Predicate from "effect/Predicate";
13
+ import * as SharedMaterial from "./shared-material.js";
14
+ /** Degrees to radians: a rotation's keys are in degrees, three's `rotation` in radians. */
15
+ export const RADIANS = Math.PI / 180;
16
+ /** The transform keys a scene object takes (ADR-0069 decision 4): written as its position, rotation and scale. */
17
+ const TRANSFORMS = new Set(["x", "y", "z", "rotateX", "rotateY", "rotateZ", "scale", "scaleX", "scaleY", "scaleZ"]);
18
+ /** Whether `key` is a scene object's transform key. */
19
+ export const isTransformKey = (key) => TRANSFORMS.has(key);
20
+ /** Whether `subject` is a scene object: three's `Object3D`, by its flag (ADR-0069 decision 3). */
21
+ export const isObject3D = (subject) => Predicate.isObject(subject) && subject.isObject3D === true;
22
+ /** Whether `holder` is a material, by its flag. */
23
+ export const isMaterial = (holder) => Predicate.isObject(holder) && holder.isMaterial === true;
24
+ /** Whether `value` is a uniform: an object holding a `value`, a `ShaderMaterial`'s or a bare uniforms object's. */
25
+ const isUniform = (value) => Predicate.isObject(value) && "value" in value;
26
+ /** Whether `value` is a key's value Wardic animates: a number, or a string. */
27
+ const isAnimatable = (value) => Predicate.isNumber(value) || Predicate.isString(value);
28
+ /** The materials `subject` draws with: its `material`, or each of an array of them. None for a Subject without one. */
29
+ export const materialsOf = (subject) => {
30
+ const material = subject.material;
31
+ if (Array.isArray(material))
32
+ return material.filter(isMaterial);
33
+ if (isMaterial(material))
34
+ return [material];
35
+ return [];
36
+ };
37
+ /** A key at `holder` itself: a TSL uniform node set for it (three draws the node over the property), its number, or a uniform it names. */
38
+ const atHolder = (holder, key) => {
39
+ const node = holder[`${key}Node`];
40
+ if (Predicate.isObject(node) && node.isUniformNode === true)
41
+ return [node, "value"];
42
+ const own = holder[key];
43
+ if (isAnimatable(own))
44
+ return [holder, key];
45
+ if (isUniform(own) && isAnimatable(own.value))
46
+ return [own, "value"];
47
+ return undefined;
48
+ };
49
+ /** A key among `uniforms`: the uniform of its name. */
50
+ const inUniforms = (uniforms, key) => {
51
+ if (!Predicate.isObject(uniforms))
52
+ return undefined;
53
+ const uniform = uniforms[key];
54
+ if (isUniform(uniform) && isAnimatable(uniform.value))
55
+ return [uniform, "value"];
56
+ return undefined;
57
+ };
58
+ /** The axes a vector key may end in, `positionX` is `position.x`, and a colour's channels, `colorR` is `color.r`. */
59
+ const AXES = { X: "x", Y: "y", Z: "z", W: "w", R: "r", G: "g", B: "b" };
60
+ /**
61
+ * A key as a vector's axis or a colour's channel at `holder`, `normalScaleX` → `holder.normalScale.x`,
62
+ * `colorR` → `holder.color.r`, or a uniform's, `uOffsetX` → `uniforms.uOffset.value.x`.
63
+ */
64
+ const asAxis = (holder, key) => {
65
+ const axis = AXES[key.slice(-1)];
66
+ if (Predicate.isUndefined(axis))
67
+ return undefined;
68
+ const base = key.slice(0, -1);
69
+ const vector = holder[base];
70
+ if (Predicate.isObject(vector) && Predicate.isNumber(vector[axis]))
71
+ return [vector, axis];
72
+ // A bare uniforms object's: `uSkyR` → `uniforms.uSky.value.r`.
73
+ if (isUniform(vector) && Predicate.isObject(vector.value) && Predicate.isNumber(vector.value[axis]))
74
+ return [vector.value, axis];
75
+ const uniforms = holder.uniforms;
76
+ if (!Predicate.isObject(uniforms))
77
+ return undefined;
78
+ const uniform = uniforms[base];
79
+ if (!isUniform(uniform))
80
+ return undefined;
81
+ const value = uniform.value;
82
+ if (Predicate.isObject(value) && Predicate.isNumber(value[axis]))
83
+ return [value, axis];
84
+ return undefined;
85
+ };
86
+ /** A place on each holder that has the key one way: the materials of an array, each that has it. */
87
+ const placeIn = (holders, find, key, material) => {
88
+ const found = [];
89
+ const props = [];
90
+ for (const holder of holders) {
91
+ const at = find(holder, key);
92
+ if (Predicate.isUndefined(at))
93
+ continue;
94
+ found.push(at[0]);
95
+ props.push(at[1]);
96
+ }
97
+ if (found.length === 0)
98
+ return undefined;
99
+ return { holders: found, props, material };
100
+ };
101
+ /**
102
+ * Where `key` lives on `subject`, in Motion's order: the Subject itself (a TSL uniform node, its number,
103
+ * a uniform it names), then its material's (each of an array of them), then its uniforms', then a vector's
104
+ * axis. `undefined` where it's nowhere. Not the transform keys of a scene object: they're its own.
105
+ */
106
+ const find = (subject, key) => {
107
+ const material = subject.material;
108
+ const own = placeIn([subject], atHolder, key, material);
109
+ if (Predicate.isNotUndefined(own))
110
+ return own;
111
+ const materials = materialsOf(subject);
112
+ const onMaterial = placeIn(materials, atHolder, key, material);
113
+ if (Predicate.isNotUndefined(onMaterial)) {
114
+ if (DEV)
115
+ SharedMaterial.check(subject, key, materials);
116
+ return onMaterial;
117
+ }
118
+ const uniforms = placeIn([subject, ...materials], (holder, name) => inUniforms(holder.uniforms, name), key, material);
119
+ if (Predicate.isNotUndefined(uniforms))
120
+ return uniforms;
121
+ const axis = placeIn([subject], asAxis, key, material);
122
+ if (Predicate.isNotUndefined(axis))
123
+ return axis;
124
+ return placeIn(materials, asAxis, key, material);
125
+ };
126
+ /** Whether `value` is a three `Color`, by its flag. */
127
+ const isColor = (value) => Predicate.isObject(value) && value.isColor === true;
128
+ /** The Color at `holder`'s `key`: its own, or a uniform's value it names. */
129
+ const colourAt = (holder, key) => {
130
+ const own = holder[key];
131
+ if (isColor(own))
132
+ return own;
133
+ // A bare uniforms object's.
134
+ if (isUniform(own) && isColor(own.value))
135
+ return own.value;
136
+ const uniforms = holder.uniforms;
137
+ if (!Predicate.isObject(uniforms))
138
+ return undefined;
139
+ const uniform = uniforms[key];
140
+ if (isUniform(uniform) && isColor(uniform.value))
141
+ return uniform.value;
142
+ return undefined;
143
+ };
144
+ /** The Color `key` names on `subject`: its own, else its material's (the first of an array that has one), its own uniform's or its material's. */
145
+ export const colourOf = (subject, key) => {
146
+ const holder = subject;
147
+ const own = colourAt(holder, key);
148
+ if (Predicate.isNotUndefined(own))
149
+ return own;
150
+ for (const material of materialsOf(holder)) {
151
+ const found = colourAt(material, key);
152
+ if (Predicate.isNotUndefined(found))
153
+ return found;
154
+ }
155
+ return undefined;
156
+ };
157
+ /** Each Subject's places, by key, as found. */
158
+ // Module state: held weakly by the Subject, so it goes with it.
159
+ const PLACES = new WeakMap();
160
+ /** Where `key` lives on `subject`, kept until its material changes. */
161
+ export const placeOf = (subject, key) => {
162
+ let places = PLACES.get(subject);
163
+ if (Predicate.isUndefined(places)) {
164
+ places = new Map();
165
+ PLACES.set(subject, places);
166
+ }
167
+ const kept = places.get(key);
168
+ if (Predicate.isNotUndefined(kept) && kept.material === subject.material)
169
+ return kept;
170
+ const found = find(subject, key);
171
+ if (Predicate.isUndefined(found)) {
172
+ places.delete(key);
173
+ return undefined;
174
+ }
175
+ places.set(key, found);
176
+ return found;
177
+ };
178
+ /** Where a transform key is read on a scene object: its vector, its axis, and its unit (degrees for a rotation). */
179
+ const TRANSFORM_READS = {
180
+ x: ["position", "x", 1],
181
+ y: ["position", "y", 1],
182
+ z: ["position", "z", 1],
183
+ rotateX: ["rotation", "x", RADIANS],
184
+ rotateY: ["rotation", "y", RADIANS],
185
+ rotateZ: ["rotation", "z", RADIANS],
186
+ // `scale` is its `x`, as Motion's.
187
+ scale: ["scale", "x", 1],
188
+ scaleX: ["scale", "x", 1],
189
+ scaleY: ["scale", "y", 1],
190
+ scaleZ: ["scale", "z", 1],
191
+ };
192
+ /** A scene object's transform key, read from its position, rotation in degrees, or scale. */
193
+ const readTransform = (subject, key) => {
194
+ const [vector, axis, per] = TRANSFORM_READS[key];
195
+ return subject[vector][axis] / per;
196
+ };
197
+ /** `subject`'s value for `key` now, where the lookup finds it: `undefined` where it's nowhere. */
198
+ export const read = (subject, key) => {
199
+ const holder = subject;
200
+ if (isObject3D(holder) && isTransformKey(key))
201
+ return readTransform(holder, key);
202
+ const place = placeOf(holder, key);
203
+ if (Predicate.isUndefined(place))
204
+ return undefined;
205
+ return place.holders[0][place.props[0]];
206
+ };
207
+ /** Materials whose `transparent` Wardic set, so it puts it back once their opacity is 1 again. */
208
+ // Module state: held weakly by the material.
209
+ const MADE_TRANSPARENT = new WeakSet();
210
+ /**
211
+ * three's rule after `opacity` on a material: below 1 it's drawn transparent, and once it's back at 1
212
+ * Wardic puts back the `transparent` it set. `needsUpdate` only on a flip, which recompiles it.
213
+ */
214
+ const ruleOpacity = (material, opacity) => {
215
+ if (!Predicate.isNumber(opacity))
216
+ return;
217
+ if (opacity < 1) {
218
+ if (material.transparent === true)
219
+ return;
220
+ material.transparent = true;
221
+ material.needsUpdate = true;
222
+ MADE_TRANSPARENT.add(material);
223
+ return;
224
+ }
225
+ if (!MADE_TRANSPARENT.has(material))
226
+ return;
227
+ MADE_TRANSPARENT.delete(material);
228
+ material.transparent = false;
229
+ material.needsUpdate = true;
230
+ };
231
+ /** `value` written to `key` on `subject`, where the lookup finds it, with `opacity`'s rule after it: nowhere, nothing written. */
232
+ export const write = (subject, key, value) => {
233
+ const place = placeOf(subject, key);
234
+ if (Predicate.isUndefined(place))
235
+ return;
236
+ const holders = place.holders;
237
+ const props = place.props;
238
+ for (let i = 0; i < holders.length; i++) {
239
+ const holder = holders[i];
240
+ holder[props[i]] = value;
241
+ if (key === "opacity" && holder.isMaterial === true)
242
+ ruleOpacity(holder, value);
243
+ }
244
+ };
245
+ //# sourceMappingURL=lookup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../src/internal/lookup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,4GAA4G;AAC5G,qGAAqG;AACrG,wFAAwF;AACxF,OAAO,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAA;AAChD,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAA;AAKtD,2FAA2F;AAC3F,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAA;AAEpC,kHAAkH;AAClH,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAA;AAExI,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAE3E,kG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CAAA;IACnC,IAAI,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC;QAAE,OAAM;IACxC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAA;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;QACzB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;QACxB,IAAI,GAAG,KAAK,SAAS,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI;YAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IACjF,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ /** Any object of the scene. */
2
+ type Holder = Record<string, unknown>;
3
+ /** The warning, naming the mesh, the key, the material, and up to three of the others. */
4
+ export declare const message: (mesh: Holder, key: string, material: Holder, others: ReadonlyArray<Holder>) => string;
5
+ /** Warn, once per material, where `key` found on `mesh`'s `materials` changes other meshes too. */
6
+ export declare const check: (mesh: Holder, key: string, materials: ReadonlyArray<Holder>) => void;
7
+ export {};
8
+ //# sourceMappingURL=shared-material.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-material.d.ts","sourceRoot":"","sources":["../../src/internal/shared-material.ts"],"names":[],"mappings":"AAeA,+BAA+B;AAC/B,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAqErC,0FAA0F;AAC1F,eAAO,MAAM,OAAO,SAAU,MAAM,OAAO,MAAM,YAAY,MAAM,UAAU,aAAa,CAAC,MAAM,CAAC,KAAG,MAKpG,CAAA;AAED,mGAAmG;AACnG,eAAO,MAAM,KAAK,SAAU,MAAM,OAAO,MAAM,aAAa,aAAa,CAAC,MAAM,CAAC,KAAG,IAMhF,CAAA"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The dev warning at a key Wardic finds on a mesh's material that other meshes share: they all change
3
+ * with it. Once per material, at the first key found on it, by one walk of the mesh's scene.
4
+ *
5
+ * @internal
6
+ */
7
+ // ADR-0073 decision 23 (Q27, Q33) and *Amendment (#883)*, Q6: in dev only, under `DEV`; three has no
8
+ // link from a material back to its meshes, so the walk is from the mesh's root.
9
+ import * as Arr from "effect/Array";
10
+ import * as Predicate from "effect/Predicate";
11
+ /** Materials already checked: each is walked for once. */
12
+ // Module state: held weakly by the material.
13
+ const CHECKED = new WeakSet();
14
+ /** What an object is called in the warning: its `name`, else its type's. */
15
+ const nameOf = (object) => {
16
+ if (Predicate.isString(object.name) && object.name !== "")
17
+ return object.name;
18
+ if (Predicate.isString(object.type))
19
+ return `a ${object.type}`;
20
+ return "an object";
21
+ };
22
+ /** How the code to fix it names `mesh`: its name, as a variable, else `mesh`. */
23
+ const variableOf = (mesh) => {
24
+ if (Predicate.isString(mesh.name) && /^[A-Za-z_$][\w$]*$/.test(mesh.name))
25
+ return mesh.name;
26
+ return "mesh";
27
+ };
28
+ /** The root of `object`'s graph: its scene, where it's in one. */
29
+ const rootOf = (object) => {
30
+ if (Predicate.isObject(object.parent))
31
+ return rootOf(object.parent);
32
+ return object;
33
+ };
34
+ /** Whether `object` draws with `material`: as its material, or one of an array of them. */
35
+ const drawsWith = (object, material) => {
36
+ const own = object.material;
37
+ if (Arr.isArray(own))
38
+ return Arr.contains(own, material);
39
+ return own === material;
40
+ };
41
+ /** The other objects of `mesh`'s scene that draw with `material`. */
42
+ const sharersOf = (mesh, material) => {
43
+ const root = rootOf(mesh);
44
+ const found = [];
45
+ if (!Predicate.isFunction(root.traverse))
46
+ return found;
47
+ const traverse = root.traverse;
48
+ traverse.call(root, (object) => {
49
+ if (object !== mesh && drawsWith(object, material))
50
+ found.push(object);
51
+ });
52
+ return found;
53
+ };
54
+ /** A material's kind, as three names it: its type, else "material". */
55
+ const kindOf = (material) => {
56
+ if (Predicate.isString(material.type))
57
+ return material.type;
58
+ return "material";
59
+ };
60
+ /** Up to three of `others`' names, and an ellipsis for the rest. */
61
+ const listOf = (others) => {
62
+ const listed = Arr.join(Arr.map(Arr.take(others, 3), nameOf), ", ");
63
+ if (others.length > 3)
64
+ return `${listed}, …`;
65
+ return listed;
66
+ };
67
+ /** How many others share it. */
68
+ const shareOf = (others) => {
69
+ if (others.length === 1)
70
+ return "1 other mesh shares";
71
+ return `${others.length} other meshes share`;
72
+ };
73
+ /** What the key does to every one of them, and to the mesh alone: an opacity fades. */
74
+ const changeOf = (key) => {
75
+ if (key === "opacity")
76
+ return ["fades", "fade"];
77
+ return [`changes its ${key}`, "change"];
78
+ };
79
+ /** The warning, naming the mesh, the key, the material, and up to three of the others. */
80
+ export const message = (mesh, key, material, others) => {
81
+ const meshName = nameOf(mesh);
82
+ const [every, alone] = changeOf(key);
83
+ const name = variableOf(mesh);
84
+ return `[wardic] ${meshName}'s ${key} is on a ${kindOf(material)} that ${shareOf(others)} (${listOf(others)}).\nEvery one of them ${every}. Give ${meshName} its own material (${name}.material = ${name}.material.clone()) to ${alone} it alone.`;
85
+ };
86
+ /** Warn, once per material, where `key` found on `mesh`'s `materials` changes other meshes too. */
87
+ export const check = (mesh, key, materials) => Arr.forEach(materials, (material) => {
88
+ if (CHECKED.has(material))
89
+ return;
90
+ CHECKED.add(material);
91
+ const others = sharersOf(mesh, material);
92
+ if (others.length > 0)
93
+ console.warn(message(mesh, key, material, others));
94
+ });
95
+ //# sourceMappingURL=shared-material.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-material.js","sourceRoot":"","sources":["../../src/internal/shared-material.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qGAAqG;AACrG,gFAAgF;AAChF,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAS7C,0DAA0D;AAC1D,6CAA6C;AA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AG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;AAC3E,CAAC,CAAC,CAAA"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A Stage's features (#885's PR 5): what a scene app adds to `createStage`'s `features` for what it uses,
3
+ * as a page's Features are given to its provider, so a scene that uses none carries none of their code.
4
+ *
5
+ * - **`stageDrag`** drags a ward's Subject (`ward(mesh, { drag })`), `@wardic/three`'s `ThreeDrag`.
6
+ * - **`stageBatches`** makes `createBatch`'s scene Batches (`object`, `instances`).
7
+ *
8
+ * A ward's `drag`, or a scene's `createBatch`, on a Stage without its feature is an error in development
9
+ * naming it.
10
+ *
11
+ * @module
12
+ */
13
+ import type { Stage, StageDrag, StageWardEnvironment } from "@wardic/solid";
14
+ import type { Camera, Object3D } from "three";
15
+ import type * as WardicThree from "../WardicThree.ts";
16
+ /** What a Stage drags with: its camera and its canvas, once there is one. A Stage adopting a runtime has neither. */
17
+ export interface StageView {
18
+ readonly camera: Camera | (() => Camera);
19
+ /** Its canvas, where it is on the page. */
20
+ readonly canvas: () => {
21
+ readonly getBoundingClientRect: () => {
22
+ readonly left: number;
23
+ readonly top: number;
24
+ readonly width: number;
25
+ readonly height: number;
26
+ };
27
+ } | undefined;
28
+ }
29
+ /** What a feature builds on: the Stage's runtime, its view, its wards' environment, and its scene. */
30
+ export interface StageParts {
31
+ readonly runtime: WardicThree.WardicThree;
32
+ readonly view: StageView | undefined;
33
+ readonly scene: Object3D | undefined;
34
+ }
35
+ /** A Stage's feature: the drag it gives, or the Batches it makes, from its parts. */
36
+ export interface StageFeature {
37
+ /** Its drag: none on a Stage with no view of its own. */
38
+ readonly drag?: ((parts: StageParts) => StageDrag | undefined) | undefined;
39
+ /** Its Batches, made on its wards' environment. */
40
+ readonly batch?: ((parts: StageParts, environment: StageWardEnvironment) => NonNullable<Stage["batch"]>) | undefined;
41
+ }
42
+ //# sourceMappingURL=feature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.d.ts","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C,GAAG,SAAS,CAAA;CACrH"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.js","sourceRoot":"","sources":["../../src/solid/feature.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { StageBatchBinding, StageBatchHooks, StageCountBatchConfig, StageKeyedBatchConfig, StageWardEnvironment } from "@wardic/solid";
2
+ import type { Object3D } from "three";
3
+ /** What a scene's Batches run on: the Stage's ward environment, and its scene. */
4
+ export interface SceneBatchContext {
5
+ readonly environment: StageWardEnvironment;
6
+ readonly scene: Object3D | undefined;
7
+ }
8
+ /** A scene's Batch on `context`, as `createBatch` drives it. */
9
+ export declare const bindSceneBatch: (context: SceneBatchContext, config: StageKeyedBatchConfig<unknown> | StageCountBatchConfig, hooks: StageBatchHooks) => StageBatchBinding;
10
+ //# sourceMappingURL=scene-batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene-batch.d.ts","sourceRoot":"","sources":["../../src/solid/scene-batch.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAA0C,qBAAqB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAWnL,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAMrC,kFAAkF;AAClF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,WAAW,EAAE,oBAAoB,CAAA;IAC1C,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAA;CACrC;AAgDD,gEAAgE;AAChE,eAAO,MAAM,cAAc,YAAa,iBAAiB,UAAU,qBAAqB,CAAC,OAAO,CAAC,GAAG,qBAAqB,SAAS,eAAe,KAAG,iBA0YnJ,CAAA"}