@flighthq/materials 0.2.1-next.841.373388f → 0.3.0-next.1032.e2b99fc
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/dist/anisotropyPbrExtension.d.ts +4 -0
- package/dist/anisotropyPbrExtension.d.ts.map +1 -0
- package/dist/anisotropyPbrExtension.js +19 -0
- package/dist/anisotropyPbrExtension.js.map +1 -0
- package/dist/classicMaterials.d.ts +1 -1
- package/dist/classicMaterials.d.ts.map +1 -1
- package/dist/classicMaterials.js +1 -1
- package/dist/classicMaterials.js.map +1 -1
- package/dist/clearcoatPbrExtension.d.ts +4 -0
- package/dist/clearcoatPbrExtension.d.ts.map +1 -0
- package/dist/clearcoatPbrExtension.js +28 -0
- package/dist/clearcoatPbrExtension.js.map +1 -0
- package/dist/colorScaleBias.d.ts +18 -0
- package/dist/colorScaleBias.d.ts.map +1 -0
- package/dist/colorScaleBias.js +120 -0
- package/dist/colorScaleBias.js.map +1 -0
- package/dist/contract.d.ts +21 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +21 -0
- package/dist/contract.js.map +1 -0
- package/dist/customShaderMaterial.d.ts +1 -1
- package/dist/customShaderMaterial.d.ts.map +1 -1
- package/dist/customShaderMaterial.js +1 -1
- package/dist/customShaderMaterial.js.map +1 -1
- package/dist/extendedPbrMaterial.d.ts +3 -0
- package/dist/extendedPbrMaterial.d.ts.map +1 -0
- package/dist/extendedPbrMaterial.js +12 -0
- package/dist/extendedPbrMaterial.js.map +1 -0
- package/dist/index.d.ts +1 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -11
- package/dist/index.js.map +1 -1
- package/dist/iridescencePbrExtension.d.ts +4 -0
- package/dist/iridescencePbrExtension.d.ts.map +1 -0
- package/dist/iridescencePbrExtension.js +27 -0
- package/dist/iridescencePbrExtension.js.map +1 -0
- package/dist/material.d.ts +1 -1
- package/dist/material.d.ts.map +1 -1
- package/dist/material.js +1 -1
- package/dist/material.js.map +1 -1
- package/dist/materialPresets.d.ts +2 -2
- package/dist/materialPresets.d.ts.map +1 -1
- package/dist/materialPresets.js +22 -10
- package/dist/materialPresets.js.map +1 -1
- package/dist/materialValidation.d.ts +1 -1
- package/dist/materialValidation.d.ts.map +1 -1
- package/dist/pbrExtension.d.ts +3 -0
- package/dist/pbrExtension.d.ts.map +1 -0
- package/dist/pbrExtension.js +5 -0
- package/dist/pbrExtension.js.map +1 -0
- package/dist/pbrMaterials.d.ts +1 -1
- package/dist/pbrMaterials.d.ts.map +1 -1
- package/dist/pbrMaterials.js +2 -2
- package/dist/pbrMaterials.js.map +1 -1
- package/dist/phongToPbr.d.ts +1 -1
- package/dist/phongToPbr.d.ts.map +1 -1
- package/dist/phongToPbr.js +1 -1
- package/dist/phongToPbr.js.map +1 -1
- package/dist/sheenPbrExtension.d.ts +4 -0
- package/dist/sheenPbrExtension.d.ts.map +1 -0
- package/dist/sheenPbrExtension.js +21 -0
- package/dist/sheenPbrExtension.js.map +1 -0
- package/dist/specularPbrExtension.d.ts +4 -0
- package/dist/specularPbrExtension.d.ts.map +1 -0
- package/dist/specularPbrExtension.js +21 -0
- package/dist/specularPbrExtension.js.map +1 -0
- package/dist/standardMaterial.d.ts +3 -0
- package/dist/standardMaterial.d.ts.map +1 -0
- package/dist/standardMaterial.js +9 -0
- package/dist/standardMaterial.js.map +1 -0
- package/dist/surfaceMaterial.d.ts +1 -1
- package/dist/surfaceMaterial.d.ts.map +1 -1
- package/dist/surfaceMaterial.js +1 -1
- package/dist/surfaceMaterial.js.map +1 -1
- package/dist/transmissionVolumePbrExtension.d.ts +4 -0
- package/dist/transmissionVolumePbrExtension.d.ts.map +1 -0
- package/dist/transmissionVolumePbrExtension.js +30 -0
- package/dist/transmissionVolumePbrExtension.js.map +1 -0
- package/dist/unlitMaterials.d.ts +1 -1
- package/dist/unlitMaterials.d.ts.map +1 -1
- package/dist/unlitMaterials.js +3 -5
- package/dist/unlitMaterials.js.map +1 -1
- package/dist/wrappedDiffusePbrExtension.d.ts +4 -0
- package/dist/wrappedDiffusePbrExtension.d.ts.map +1 -0
- package/dist/wrappedDiffusePbrExtension.js +24 -0
- package/dist/wrappedDiffusePbrExtension.js.map +1 -0
- package/package.json +8 -4
- package/src/anisotropyPbrExtension.test.ts +23 -0
- package/src/classicMaterials.test.ts +1 -1
- package/src/clearcoatPbrExtension.test.ts +24 -0
- package/src/colorScaleBias.test.ts +442 -0
- package/src/customShaderMaterial.test.ts +1 -1
- package/src/extendedPbrMaterial.test.ts +32 -0
- package/src/iridescencePbrExtension.test.ts +30 -0
- package/src/material.test.ts +2 -2
- package/src/materialPresets.test.ts +27 -11
- package/src/pbrExtension.test.ts +10 -0
- package/src/pbrMaterials.test.ts +2 -2
- package/src/phongToPbr.test.ts +1 -1
- package/src/sheenPbrExtension.test.ts +23 -0
- package/src/specularPbrExtension.test.ts +23 -0
- package/src/standardMaterial.test.ts +16 -0
- package/src/surfaceMaterial.test.ts +1 -1
- package/src/transmissionVolumePbrExtension.test.ts +31 -0
- package/src/unlitMaterials.test.ts +1 -1
- package/src/wrappedDiffusePbrExtension.test.ts +27 -0
- package/dist/colorTransform.d.ts +0 -18
- package/dist/colorTransform.d.ts.map +0 -1
- package/dist/colorTransform.js +0 -119
- package/dist/colorTransform.js.map +0 -1
- package/dist/pbrExtensionMaterials.d.ts +0 -9
- package/dist/pbrExtensionMaterials.d.ts.map +0 -1
- package/dist/pbrExtensionMaterials.js +0 -93
- package/dist/pbrExtensionMaterials.js.map +0 -1
- package/src/colorTransform.test.ts +0 -441
- package/src/pbrExtensionMaterials.test.ts +0 -123
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cloneColorScaleBias,
|
|
3
|
+
concatColorScaleBias,
|
|
4
|
+
copyColorScaleBias,
|
|
5
|
+
copyColorScaleBiasToArrays,
|
|
6
|
+
createColorScaleBias,
|
|
7
|
+
equalsColorScaleBias,
|
|
8
|
+
equalsColorScaleBiasScales,
|
|
9
|
+
equalsColorScaleBiasBiases,
|
|
10
|
+
getColorScaleBiasBiasRgb,
|
|
11
|
+
getColorScaleBiasBiasRgba,
|
|
12
|
+
invertColorScaleBias,
|
|
13
|
+
isIdentityColorScaleBias,
|
|
14
|
+
setColorScaleBias,
|
|
15
|
+
setColorScaleBiasIdentity,
|
|
16
|
+
setColorScaleBiasBiasRgb,
|
|
17
|
+
setColorScaleBiasBiasRgba,
|
|
18
|
+
} from '@flighthq/materials/contract';
|
|
19
|
+
|
|
20
|
+
describe('cloneColorScaleBias', () => {
|
|
21
|
+
it('returns a new object with identical values', () => {
|
|
22
|
+
const ct = createColorScaleBias({ redScale: 0.5, greenBias: 64 });
|
|
23
|
+
const cloned = cloneColorScaleBias(ct);
|
|
24
|
+
expect(cloned).not.toBe(ct);
|
|
25
|
+
expect(cloned.redScale).toBe(0.5);
|
|
26
|
+
expect(cloned.greenBias).toBe(64);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('does not share references', () => {
|
|
30
|
+
const ct = createColorScaleBias({ redBias: 10 });
|
|
31
|
+
const c = cloneColorScaleBias(ct);
|
|
32
|
+
c.redBias = 99;
|
|
33
|
+
expect(ct.redBias).toBe(10);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('concatColorScaleBias', () => {
|
|
38
|
+
it('composes two setColorScaleBiasIdentity transforms into setColorScaleBiasIdentity', () => {
|
|
39
|
+
const a = createColorScaleBias();
|
|
40
|
+
const b = createColorScaleBias();
|
|
41
|
+
const out = createColorScaleBias({ redScale: 0, greenScale: 0, blueScale: 0, alphaScale: 0 });
|
|
42
|
+
concatColorScaleBias(out, a, b);
|
|
43
|
+
expect(out.redScale).toBe(1);
|
|
44
|
+
expect(out.greenScale).toBe(1);
|
|
45
|
+
expect(out.blueScale).toBe(1);
|
|
46
|
+
expect(out.alphaScale).toBe(1);
|
|
47
|
+
expect(out.redBias).toBe(0);
|
|
48
|
+
expect(out.greenBias).toBe(0);
|
|
49
|
+
expect(out.blueBias).toBe(0);
|
|
50
|
+
expect(out.alphaBias).toBe(0);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('multiplies scales', () => {
|
|
54
|
+
const a = createColorScaleBias({ redScale: 2, greenScale: 0.5 });
|
|
55
|
+
const b = createColorScaleBias({ redScale: 3, greenScale: 4 });
|
|
56
|
+
const out = createColorScaleBias();
|
|
57
|
+
concatColorScaleBias(out, a, b);
|
|
58
|
+
expect(out.redScale).toBe(6);
|
|
59
|
+
expect(out.greenScale).toBe(2);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('combines biases: out.bias = source.scale * other.bias + source.bias', () => {
|
|
63
|
+
const source = createColorScaleBias({ redScale: 2, redBias: 10 });
|
|
64
|
+
const other = createColorScaleBias({ redBias: 5 });
|
|
65
|
+
const out = createColorScaleBias();
|
|
66
|
+
concatColorScaleBias(out, source, other);
|
|
67
|
+
expect(out.redBias).toBe(2 * 5 + 10);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('produces correct result when out aliases source', () => {
|
|
71
|
+
const a = createColorScaleBias({
|
|
72
|
+
redScale: 2,
|
|
73
|
+
greenScale: 0.5,
|
|
74
|
+
blueScale: 3,
|
|
75
|
+
alphaScale: 0.25,
|
|
76
|
+
redBias: 10,
|
|
77
|
+
greenBias: 20,
|
|
78
|
+
blueBias: 30,
|
|
79
|
+
alphaBias: 40,
|
|
80
|
+
});
|
|
81
|
+
const b = createColorScaleBias({
|
|
82
|
+
redScale: 3,
|
|
83
|
+
greenScale: 4,
|
|
84
|
+
blueScale: 0.5,
|
|
85
|
+
alphaScale: 2,
|
|
86
|
+
redBias: 5,
|
|
87
|
+
greenBias: 15,
|
|
88
|
+
blueBias: 25,
|
|
89
|
+
alphaBias: 35,
|
|
90
|
+
});
|
|
91
|
+
const ref = createColorScaleBias();
|
|
92
|
+
concatColorScaleBias(ref, a, b);
|
|
93
|
+
concatColorScaleBias(a, a, b);
|
|
94
|
+
expect(a.redScale).toBe(ref.redScale);
|
|
95
|
+
expect(a.greenScale).toBe(ref.greenScale);
|
|
96
|
+
expect(a.blueScale).toBe(ref.blueScale);
|
|
97
|
+
expect(a.alphaScale).toBe(ref.alphaScale);
|
|
98
|
+
expect(a.redBias).toBe(ref.redBias);
|
|
99
|
+
expect(a.greenBias).toBe(ref.greenBias);
|
|
100
|
+
expect(a.blueBias).toBe(ref.blueBias);
|
|
101
|
+
expect(a.alphaBias).toBe(ref.alphaBias);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('produces correct result when out aliases other', () => {
|
|
105
|
+
const a = createColorScaleBias({
|
|
106
|
+
redScale: 2,
|
|
107
|
+
greenScale: 0.5,
|
|
108
|
+
blueScale: 3,
|
|
109
|
+
alphaScale: 0.25,
|
|
110
|
+
redBias: 10,
|
|
111
|
+
greenBias: 20,
|
|
112
|
+
blueBias: 30,
|
|
113
|
+
alphaBias: 40,
|
|
114
|
+
});
|
|
115
|
+
const b = createColorScaleBias({
|
|
116
|
+
redScale: 3,
|
|
117
|
+
greenScale: 4,
|
|
118
|
+
blueScale: 0.5,
|
|
119
|
+
alphaScale: 2,
|
|
120
|
+
redBias: 5,
|
|
121
|
+
greenBias: 15,
|
|
122
|
+
blueBias: 25,
|
|
123
|
+
alphaBias: 35,
|
|
124
|
+
});
|
|
125
|
+
const ref = createColorScaleBias();
|
|
126
|
+
concatColorScaleBias(ref, a, b);
|
|
127
|
+
concatColorScaleBias(b, a, b);
|
|
128
|
+
expect(b.redScale).toBe(ref.redScale);
|
|
129
|
+
expect(b.greenScale).toBe(ref.greenScale);
|
|
130
|
+
expect(b.blueScale).toBe(ref.blueScale);
|
|
131
|
+
expect(b.alphaScale).toBe(ref.alphaScale);
|
|
132
|
+
expect(b.redBias).toBe(ref.redBias);
|
|
133
|
+
expect(b.greenBias).toBe(ref.greenBias);
|
|
134
|
+
expect(b.blueBias).toBe(ref.blueBias);
|
|
135
|
+
expect(b.alphaBias).toBe(ref.alphaBias);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('copyColorScaleBias', () => {
|
|
140
|
+
it('copies all fields from source to out', () => {
|
|
141
|
+
const source = createColorScaleBias({ redScale: 0.5, greenBias: 128, alphaScale: 0.8, blueBias: 64 });
|
|
142
|
+
const out = createColorScaleBias();
|
|
143
|
+
copyColorScaleBias(out, source);
|
|
144
|
+
expect(out.redScale).toBe(0.5);
|
|
145
|
+
expect(out.greenScale).toBe(1);
|
|
146
|
+
expect(out.blueScale).toBe(1);
|
|
147
|
+
expect(out.alphaScale).toBe(0.8);
|
|
148
|
+
expect(out.redBias).toBe(0);
|
|
149
|
+
expect(out.greenBias).toBe(128);
|
|
150
|
+
expect(out.blueBias).toBe(64);
|
|
151
|
+
expect(out.alphaBias).toBe(0);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('does not share references between out and source', () => {
|
|
155
|
+
const source = createColorScaleBias({ redBias: 50 });
|
|
156
|
+
const out = createColorScaleBias();
|
|
157
|
+
copyColorScaleBias(out, source);
|
|
158
|
+
out.redBias = 99;
|
|
159
|
+
expect(source.redBias).toBe(50);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('copyColorScaleBiasToArrays', () => {
|
|
164
|
+
it('writes scales and biases into parallel arrays', () => {
|
|
165
|
+
const ct = createColorScaleBias({
|
|
166
|
+
redScale: 0.5,
|
|
167
|
+
greenScale: 0.25,
|
|
168
|
+
blueScale: 2,
|
|
169
|
+
alphaScale: 0.8,
|
|
170
|
+
});
|
|
171
|
+
setColorScaleBias(ct, 0.5, 0.25, 2, 0.8, 10, 20, 30, 40);
|
|
172
|
+
const scales: number[] = [];
|
|
173
|
+
const biases: number[] = [];
|
|
174
|
+
copyColorScaleBiasToArrays(scales, biases, ct);
|
|
175
|
+
expect(scales).toEqual([0.5, 0.25, 2, 0.8]);
|
|
176
|
+
expect(biases).toEqual([10, 20, 30, 40]);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('writes into existing arrays without creating new ones', () => {
|
|
180
|
+
const ct = createColorScaleBias();
|
|
181
|
+
const scales = [9, 9, 9, 9];
|
|
182
|
+
const biases = [9, 9, 9, 9];
|
|
183
|
+
copyColorScaleBiasToArrays(scales, biases, ct);
|
|
184
|
+
expect(scales).toEqual([1, 1, 1, 1]);
|
|
185
|
+
expect(biases).toEqual([0, 0, 0, 0]);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('createColorScaleBias', () => {
|
|
190
|
+
it('initializes scales to 1 and biases to 0 by default', () => {
|
|
191
|
+
const ct = createColorScaleBias();
|
|
192
|
+
expect(ct.redScale).toBe(1);
|
|
193
|
+
expect(ct.greenScale).toBe(1);
|
|
194
|
+
expect(ct.blueScale).toBe(1);
|
|
195
|
+
expect(ct.alphaScale).toBe(1);
|
|
196
|
+
expect(ct.redBias).toBe(0);
|
|
197
|
+
expect(ct.greenBias).toBe(0);
|
|
198
|
+
expect(ct.blueBias).toBe(0);
|
|
199
|
+
expect(ct.alphaBias).toBe(0);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('applies partial overrides', () => {
|
|
203
|
+
const ct = createColorScaleBias({ redScale: 0.5, blueBias: 128 });
|
|
204
|
+
expect(ct.redScale).toBe(0.5);
|
|
205
|
+
expect(ct.greenScale).toBe(1);
|
|
206
|
+
expect(ct.blueBias).toBe(128);
|
|
207
|
+
expect(ct.alphaBias).toBe(0);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe('equalsColorScaleBias', () => {
|
|
212
|
+
it('returns true for two setColorScaleBiasIdentity transforms', () => {
|
|
213
|
+
expect(equalsColorScaleBias(createColorScaleBias(), createColorScaleBias())).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('returns false when any field differs', () => {
|
|
217
|
+
expect(equalsColorScaleBias(createColorScaleBias({ redScale: 0.5 }), createColorScaleBias())).toBe(false);
|
|
218
|
+
expect(equalsColorScaleBias(createColorScaleBias({ redBias: 1 }), createColorScaleBias())).toBe(false);
|
|
219
|
+
expect(equalsColorScaleBias(createColorScaleBias({ alphaScale: 0 }), createColorScaleBias())).toBe(false);
|
|
220
|
+
expect(equalsColorScaleBias(createColorScaleBias({ alphaBias: 1 }), createColorScaleBias())).toBe(false);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('returns true for matching non-setColorScaleBiasIdentity transforms', () => {
|
|
224
|
+
const a = createColorScaleBias({ redScale: 0.5, greenBias: 128 });
|
|
225
|
+
const b = createColorScaleBias({ redScale: 0.5, greenBias: 128 });
|
|
226
|
+
expect(equalsColorScaleBias(a, b)).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe('equalsColorScaleBiasBiases', () => {
|
|
231
|
+
it('returns true when all biases match', () => {
|
|
232
|
+
const a = createColorScaleBias({ redBias: 64, greenBias: 128 });
|
|
233
|
+
const b = createColorScaleBias({ redBias: 64, greenBias: 128 });
|
|
234
|
+
expect(equalsColorScaleBiasBiases(a, b)).toBe(true);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('returns false when any bias differs', () => {
|
|
238
|
+
expect(equalsColorScaleBiasBiases(createColorScaleBias({ redBias: 1 }), createColorScaleBias())).toBe(false);
|
|
239
|
+
expect(equalsColorScaleBiasBiases(createColorScaleBias({ alphaBias: 1 }), createColorScaleBias())).toBe(false);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('ignores alpha when compareAlpha is false', () => {
|
|
243
|
+
const a = createColorScaleBias({ alphaBias: 50 });
|
|
244
|
+
const b = createColorScaleBias({ alphaBias: 0 });
|
|
245
|
+
expect(equalsColorScaleBiasBiases(a, b, false)).toBe(true);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('still compares RGB when compareAlpha is false', () => {
|
|
249
|
+
const a = createColorScaleBias({ redBias: 50 });
|
|
250
|
+
const b = createColorScaleBias({ redBias: 0 });
|
|
251
|
+
expect(equalsColorScaleBiasBiases(a, b, false)).toBe(false);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe('equalsColorScaleBiasScales', () => {
|
|
256
|
+
it('returns true when all scales match', () => {
|
|
257
|
+
const a = createColorScaleBias({ redScale: 0.5, greenScale: 0.25 });
|
|
258
|
+
const b = createColorScaleBias({ redScale: 0.5, greenScale: 0.25 });
|
|
259
|
+
expect(equalsColorScaleBiasScales(a, b)).toBe(true);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('returns false when any scale differs', () => {
|
|
263
|
+
expect(equalsColorScaleBiasScales(createColorScaleBias({ redScale: 0.5 }), createColorScaleBias())).toBe(false);
|
|
264
|
+
expect(equalsColorScaleBiasScales(createColorScaleBias({ alphaScale: 0.5 }), createColorScaleBias())).toBe(false);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('ignores alpha when compareAlpha is false', () => {
|
|
268
|
+
const a = createColorScaleBias({ alphaScale: 0.5 });
|
|
269
|
+
const b = createColorScaleBias({ alphaScale: 1 });
|
|
270
|
+
expect(equalsColorScaleBiasScales(a, b, false)).toBe(true);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('still compares RGB when compareAlpha is false', () => {
|
|
274
|
+
const a = createColorScaleBias({ redScale: 0.5 });
|
|
275
|
+
const b = createColorScaleBias({ redScale: 1 });
|
|
276
|
+
expect(equalsColorScaleBiasScales(a, b, false)).toBe(false);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe('getColorScaleBiasBiasRgb', () => {
|
|
281
|
+
it('packs red, green, blue biases into a single integer', () => {
|
|
282
|
+
const ct = createColorScaleBias({ redBias: 1, greenBias: 0x80 / 255, blueBias: 0x10 / 255 });
|
|
283
|
+
const packed = getColorScaleBiasBiasRgb(ct);
|
|
284
|
+
expect((packed >> 16) & 0xff).toBe(0xff);
|
|
285
|
+
expect((packed >> 8) & 0xff).toBe(0x80);
|
|
286
|
+
expect(packed & 0xff).toBe(0x10);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('returns 0 when all biases are 0', () => {
|
|
290
|
+
expect(getColorScaleBiasBiasRgb(createColorScaleBias())).toBe(0);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
describe('getColorScaleBiasBiasRgba', () => {
|
|
295
|
+
it('packs red, green, blue, alpha biases into a single integer', () => {
|
|
296
|
+
const ct = createColorScaleBias({
|
|
297
|
+
redBias: 0x10 / 255,
|
|
298
|
+
greenBias: 0x20 / 255,
|
|
299
|
+
blueBias: 0x30 / 255,
|
|
300
|
+
alphaBias: 0x40 / 255,
|
|
301
|
+
});
|
|
302
|
+
const packed = getColorScaleBiasBiasRgba(ct);
|
|
303
|
+
expect((packed >> 24) & 0xff).toBe(0x10);
|
|
304
|
+
expect((packed >> 16) & 0xff).toBe(0x20);
|
|
305
|
+
expect((packed >> 8) & 0xff).toBe(0x30);
|
|
306
|
+
expect(packed & 0xff).toBe(0x40);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('returns 0 when all biases are 0', () => {
|
|
310
|
+
expect(getColorScaleBiasBiasRgba(createColorScaleBias())).toBe(0);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe('invertColorScaleBias', () => {
|
|
315
|
+
it('reciprocates scales', () => {
|
|
316
|
+
const source = createColorScaleBias({
|
|
317
|
+
redScale: 2,
|
|
318
|
+
greenScale: 4,
|
|
319
|
+
blueScale: 0.5,
|
|
320
|
+
alphaScale: 0.25,
|
|
321
|
+
});
|
|
322
|
+
const out = createColorScaleBias();
|
|
323
|
+
invertColorScaleBias(out, source);
|
|
324
|
+
expect(out.redScale).toBe(0.5);
|
|
325
|
+
expect(out.greenScale).toBe(0.25);
|
|
326
|
+
expect(out.blueScale).toBe(2);
|
|
327
|
+
expect(out.alphaScale).toBe(4);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('negates biases', () => {
|
|
331
|
+
const source = createColorScaleBias({ redBias: 64, greenBias: -32, blueBias: 128, alphaBias: -10 });
|
|
332
|
+
const out = createColorScaleBias();
|
|
333
|
+
invertColorScaleBias(out, source);
|
|
334
|
+
expect(out.redBias).toBe(-64);
|
|
335
|
+
expect(out.greenBias).toBe(32);
|
|
336
|
+
expect(out.blueBias).toBe(-128);
|
|
337
|
+
expect(out.alphaBias).toBe(10);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('uses 1 when scale is 0 to avoid division by zero', () => {
|
|
341
|
+
const source = createColorScaleBias({
|
|
342
|
+
redScale: 0,
|
|
343
|
+
greenScale: 0,
|
|
344
|
+
blueScale: 0,
|
|
345
|
+
alphaScale: 0,
|
|
346
|
+
});
|
|
347
|
+
const out = createColorScaleBias();
|
|
348
|
+
invertColorScaleBias(out, source);
|
|
349
|
+
expect(out.redScale).toBe(1);
|
|
350
|
+
expect(out.greenScale).toBe(1);
|
|
351
|
+
expect(out.blueScale).toBe(1);
|
|
352
|
+
expect(out.alphaScale).toBe(1);
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
describe('isIdentityColorScaleBias', () => {
|
|
357
|
+
it('returns true for a default transform', () => {
|
|
358
|
+
expect(isIdentityColorScaleBias(createColorScaleBias())).toBe(true);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('returns false when any scale differs from 1', () => {
|
|
362
|
+
expect(isIdentityColorScaleBias(createColorScaleBias({ redScale: 0.5 }))).toBe(false);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('returns false when any bias is non-zero', () => {
|
|
366
|
+
expect(isIdentityColorScaleBias(createColorScaleBias({ greenBias: 1 }))).toBe(false);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('returns true when alphaScale differs but compareAlphaScale is false', () => {
|
|
370
|
+
expect(isIdentityColorScaleBias(createColorScaleBias({ alphaScale: 0 }), false)).toBe(true);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
describe('setColorScaleBias', () => {
|
|
375
|
+
it('sets all eight fields', () => {
|
|
376
|
+
const ct = createColorScaleBias();
|
|
377
|
+
setColorScaleBias(ct, 0.1, 0.2, 0.3, 0.4, 10, 20, 30, 40);
|
|
378
|
+
expect(ct.redScale).toBe(0.1);
|
|
379
|
+
expect(ct.greenScale).toBe(0.2);
|
|
380
|
+
expect(ct.blueScale).toBe(0.3);
|
|
381
|
+
expect(ct.alphaScale).toBe(0.4);
|
|
382
|
+
expect(ct.redBias).toBe(10);
|
|
383
|
+
expect(ct.greenBias).toBe(20);
|
|
384
|
+
expect(ct.blueBias).toBe(30);
|
|
385
|
+
expect(ct.alphaBias).toBe(40);
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
describe('setColorScaleBiasBiasRgb', () => {
|
|
390
|
+
it('unpacks red, green, blue from a packed integer', () => {
|
|
391
|
+
const ct = createColorScaleBias();
|
|
392
|
+
setColorScaleBiasBiasRgb(ct, (0xab << 16) | (0xcd << 8) | 0xef);
|
|
393
|
+
expect(ct.redBias).toBeCloseTo(0xab / 255);
|
|
394
|
+
expect(ct.greenBias).toBeCloseTo(0xcd / 255);
|
|
395
|
+
expect(ct.blueBias).toBeCloseTo(0xef / 255);
|
|
396
|
+
expect(ct.alphaBias).toBe(0);
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('zeroes RGB scales and keeps alphaScale at 1', () => {
|
|
400
|
+
const ct = createColorScaleBias();
|
|
401
|
+
setColorScaleBiasBiasRgb(ct, 0xffffff);
|
|
402
|
+
expect(ct.redScale).toBe(0);
|
|
403
|
+
expect(ct.greenScale).toBe(0);
|
|
404
|
+
expect(ct.blueScale).toBe(0);
|
|
405
|
+
expect(ct.alphaScale).toBe(1);
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
describe('setColorScaleBiasBiasRgba', () => {
|
|
410
|
+
it('unpacks red, green, blue, alpha from a packed integer', () => {
|
|
411
|
+
const ct = createColorScaleBias();
|
|
412
|
+
setColorScaleBiasBiasRgba(ct, (0x10 << 24) | (0x20 << 16) | (0x30 << 8) | 0x40);
|
|
413
|
+
expect(ct.redBias).toBeCloseTo(0x10 / 255);
|
|
414
|
+
expect(ct.greenBias).toBeCloseTo(0x20 / 255);
|
|
415
|
+
expect(ct.blueBias).toBeCloseTo(0x30 / 255);
|
|
416
|
+
expect(ct.alphaBias).toBeCloseTo(0x40 / 255);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('zeroes all scales including alpha', () => {
|
|
420
|
+
const ct = createColorScaleBias();
|
|
421
|
+
setColorScaleBiasBiasRgba(ct, 0xffffffff);
|
|
422
|
+
expect(ct.redScale).toBe(0);
|
|
423
|
+
expect(ct.greenScale).toBe(0);
|
|
424
|
+
expect(ct.blueScale).toBe(0);
|
|
425
|
+
expect(ct.alphaScale).toBe(0);
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
describe('setColorScaleBiasIdentity', () => {
|
|
430
|
+
it('resets scales to 1 and biases to 0', () => {
|
|
431
|
+
const ct = createColorScaleBias({ redScale: 0.5, greenBias: 128, alphaScale: 0, blueBias: 64 });
|
|
432
|
+
setColorScaleBiasIdentity(ct);
|
|
433
|
+
expect(ct.redScale).toBe(1);
|
|
434
|
+
expect(ct.greenScale).toBe(1);
|
|
435
|
+
expect(ct.blueScale).toBe(1);
|
|
436
|
+
expect(ct.alphaScale).toBe(1);
|
|
437
|
+
expect(ct.redBias).toBe(0);
|
|
438
|
+
expect(ct.greenBias).toBe(0);
|
|
439
|
+
expect(ct.blueBias).toBe(0);
|
|
440
|
+
expect(ct.alphaBias).toBe(0);
|
|
441
|
+
});
|
|
442
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import { ExtendedPbrMaterialKind } from '@flighthq/types/contract';
|
|
3
|
+
|
|
4
|
+
import { createClearcoatPbrExtension } from './clearcoatPbrExtension';
|
|
5
|
+
import { createExtendedPbrMaterial } from './extendedPbrMaterial';
|
|
6
|
+
import { createStandardPbrMaterialProperties } from './pbrMaterials';
|
|
7
|
+
|
|
8
|
+
describe('createExtendedPbrMaterial', () => {
|
|
9
|
+
it('composes a standard property block with an ordered extension list', () => {
|
|
10
|
+
const standard = createStandardPbrMaterialProperties({ roughness: 0.25 });
|
|
11
|
+
const extensions = [createClearcoatPbrExtension(), createEntity({ kind: 'VendorPbrExtension' })];
|
|
12
|
+
|
|
13
|
+
const material = createExtendedPbrMaterial({ extensions, standard });
|
|
14
|
+
|
|
15
|
+
expect(material.kind).toBe(ExtendedPbrMaterialKind);
|
|
16
|
+
expect(material.standard).toBe(standard);
|
|
17
|
+
expect(material.extensions).toBe(extensions);
|
|
18
|
+
expect(material.extensions.map((extension) => extension.kind)).toEqual([
|
|
19
|
+
'ClearcoatPbrExtension',
|
|
20
|
+
'VendorPbrExtension',
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('defaults to a lean standard block and an empty per-material list', () => {
|
|
25
|
+
const a = createExtendedPbrMaterial();
|
|
26
|
+
const b = createExtendedPbrMaterial();
|
|
27
|
+
|
|
28
|
+
expect(a.standard.roughness).toBe(1);
|
|
29
|
+
expect(a.extensions).toEqual([]);
|
|
30
|
+
expect(a.extensions).not.toBe(b.extensions);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
2
|
+
|
|
3
|
+
import { createIridescencePbrExtension, isValidIridescencePbrExtension } from './iridescencePbrExtension';
|
|
4
|
+
|
|
5
|
+
describe('createIridescencePbrExtension', () => {
|
|
6
|
+
it('creates an Entity with glTF thickness defaults and independent UV sets', () => {
|
|
7
|
+
const value = createIridescencePbrExtension({ iridescenceThicknessMapUvSet: 1 });
|
|
8
|
+
expect(EntityRuntimeKey in value).toBe(true);
|
|
9
|
+
expect(value.iridescenceIor).toBe(1.3);
|
|
10
|
+
expect(value.iridescenceThicknessMin).toBe(100);
|
|
11
|
+
expect(value.iridescenceThicknessMax).toBe(400);
|
|
12
|
+
expect(value.iridescenceThicknessMapUvSet).toBe(1);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('isValidIridescencePbrExtension', () => {
|
|
17
|
+
it('rejects invalid strength, IOR, thickness ordering, and UV selection', () => {
|
|
18
|
+
expect(isValidIridescencePbrExtension(createIridescencePbrExtension())).toBe(true);
|
|
19
|
+
expect(isValidIridescencePbrExtension(createIridescencePbrExtension({ iridescence: -1 }))).toBe(false);
|
|
20
|
+
expect(isValidIridescencePbrExtension(createIridescencePbrExtension({ iridescenceIor: 0.5 }))).toBe(false);
|
|
21
|
+
expect(
|
|
22
|
+
isValidIridescencePbrExtension(
|
|
23
|
+
createIridescencePbrExtension({ iridescenceThicknessMax: 100, iridescenceThicknessMin: 200 }),
|
|
24
|
+
),
|
|
25
|
+
).toBe(false);
|
|
26
|
+
const invalidUv = createIridescencePbrExtension();
|
|
27
|
+
Reflect.set(invalidUv, 'iridescenceMapUvSet', 2);
|
|
28
|
+
expect(isValidIridescencePbrExtension(invalidUv)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|
package/src/material.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StandardPbrMaterial } from '@flighthq/types';
|
|
2
|
-
import { StandardPbrMaterialKind } from '@flighthq/types';
|
|
1
|
+
import type { StandardPbrMaterial } from '@flighthq/types/contract';
|
|
2
|
+
import { StandardPbrMaterialKind } from '@flighthq/types/contract';
|
|
3
3
|
|
|
4
4
|
import { cloneMaterial, copyMaterial, createMaterial, equalsMaterial, getMaterialOfKind } from './material';
|
|
5
5
|
import { createStandardPbrMaterial } from './pbrMaterials';
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ExtendedPbrMaterialKind,
|
|
3
|
+
StandardPbrMaterialKind,
|
|
4
|
+
TransmissionVolumePbrExtensionKind,
|
|
5
|
+
} from '@flighthq/types/contract';
|
|
2
6
|
|
|
3
7
|
import {
|
|
4
8
|
createAluminumStandardPbrMaterial,
|
|
5
9
|
createCarbonStandardPbrMaterial,
|
|
6
|
-
|
|
10
|
+
createGlassExtendedPbrMaterial,
|
|
7
11
|
createGoldStandardPbrMaterial,
|
|
8
12
|
createIronStandardPbrMaterial,
|
|
9
13
|
createMarbleStandardPbrMaterial,
|
|
@@ -36,16 +40,28 @@ describe('createCarbonStandardPbrMaterial', () => {
|
|
|
36
40
|
});
|
|
37
41
|
});
|
|
38
42
|
|
|
39
|
-
describe('
|
|
40
|
-
it('
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
expect(
|
|
44
|
-
expect(
|
|
43
|
+
describe('createGlassExtendedPbrMaterial', () => {
|
|
44
|
+
it('composes clear glass without nesting a standard material entity', () => {
|
|
45
|
+
const material = createGlassExtendedPbrMaterial();
|
|
46
|
+
const extension = material.extensions[0];
|
|
47
|
+
expect(material.kind).toBe(ExtendedPbrMaterialKind);
|
|
48
|
+
expect(material.standard.baseColor).toBe(0xffffffff);
|
|
49
|
+
expect(material.standard.metallic).toBe(0);
|
|
50
|
+
expect(material.standard.roughness).toBe(0);
|
|
51
|
+
expect('kind' in material.standard).toBe(false);
|
|
52
|
+
expect(extension?.kind).toBe(TransmissionVolumePbrExtensionKind);
|
|
45
53
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
|
|
55
|
+
it('applies surface, standard, and transmission-volume overrides independently', () => {
|
|
56
|
+
const material = createGlassExtendedPbrMaterial({
|
|
57
|
+
alphaMode: 'blend',
|
|
58
|
+
standard: { roughness: 0.2 },
|
|
59
|
+
transmissionVolume: { ior: 1.7 },
|
|
60
|
+
});
|
|
61
|
+
const extension = material.extensions[0];
|
|
62
|
+
expect(material.alphaMode).toBe('blend');
|
|
63
|
+
expect(material.standard.roughness).toBe(0.2);
|
|
64
|
+
expect(extension).toMatchObject({ ior: 1.7, transmission: 1 });
|
|
49
65
|
});
|
|
50
66
|
});
|
|
51
67
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isValidPbrUvSet } from './pbrExtension';
|
|
2
|
+
|
|
3
|
+
describe('isValidPbrUvSet', () => {
|
|
4
|
+
it('accepts the two canonical mesh UV channels only', () => {
|
|
5
|
+
expect(isValidPbrUvSet(0)).toBe(true);
|
|
6
|
+
expect(isValidPbrUvSet(1)).toBe(true);
|
|
7
|
+
expect(isValidPbrUvSet(2)).toBe(false);
|
|
8
|
+
expect(isValidPbrUvSet(NaN)).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
});
|
package/src/pbrMaterials.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Texture } from '@flighthq/types';
|
|
2
|
-
import { SpecularGlossinessPbrMaterialKind, StandardPbrMaterialKind } from '@flighthq/types';
|
|
1
|
+
import type { Texture } from '@flighthq/types/contract';
|
|
2
|
+
import { SpecularGlossinessPbrMaterialKind, StandardPbrMaterialKind } from '@flighthq/types/contract';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
convertSpecularGlossinessToStandardPbr,
|
package/src/phongToPbr.test.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
2
|
+
|
|
3
|
+
import { createSheenPbrExtension, isValidSheenPbrExtension } from './sheenPbrExtension';
|
|
4
|
+
|
|
5
|
+
describe('createSheenPbrExtension', () => {
|
|
6
|
+
it('creates an Entity with independent color and roughness UV sets', () => {
|
|
7
|
+
const value = createSheenPbrExtension({ sheenColorMapUvSet: 1 });
|
|
8
|
+
expect(EntityRuntimeKey in value).toBe(true);
|
|
9
|
+
expect(value.sheenColor).toBe(0x000000ff);
|
|
10
|
+
expect(value.sheenColorMapUvSet).toBe(1);
|
|
11
|
+
expect(value.sheenRoughnessMapUvSet).toBe(0);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('isValidSheenPbrExtension', () => {
|
|
16
|
+
it('rejects invalid roughness and UV selection', () => {
|
|
17
|
+
expect(isValidSheenPbrExtension(createSheenPbrExtension({ sheenRoughness: 1 }))).toBe(true);
|
|
18
|
+
expect(isValidSheenPbrExtension(createSheenPbrExtension({ sheenRoughness: NaN }))).toBe(false);
|
|
19
|
+
const invalidUv = createSheenPbrExtension();
|
|
20
|
+
Reflect.set(invalidUv, 'sheenRoughnessMapUvSet', -1);
|
|
21
|
+
expect(isValidSheenPbrExtension(invalidUv)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EntityRuntimeKey } from '@flighthq/types/contract';
|
|
2
|
+
|
|
3
|
+
import { createSpecularPbrExtension, isValidSpecularPbrExtension } from './specularPbrExtension';
|
|
4
|
+
|
|
5
|
+
describe('createSpecularPbrExtension', () => {
|
|
6
|
+
it('creates an Entity with independent strength and color UV sets', () => {
|
|
7
|
+
const value = createSpecularPbrExtension({ specularColorMapUvSet: 1 });
|
|
8
|
+
expect(EntityRuntimeKey in value).toBe(true);
|
|
9
|
+
expect(value.specular).toBe(1);
|
|
10
|
+
expect(value.specularMapUvSet).toBe(0);
|
|
11
|
+
expect(value.specularColorMapUvSet).toBe(1);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('isValidSpecularPbrExtension', () => {
|
|
16
|
+
it('rejects invalid strength and UV selection', () => {
|
|
17
|
+
expect(isValidSpecularPbrExtension(createSpecularPbrExtension())).toBe(true);
|
|
18
|
+
expect(isValidSpecularPbrExtension(createSpecularPbrExtension({ specular: -1 }))).toBe(false);
|
|
19
|
+
const invalidUv = createSpecularPbrExtension();
|
|
20
|
+
Reflect.set(invalidUv, 'specularMapUvSet', 2);
|
|
21
|
+
expect(isValidSpecularPbrExtension(invalidUv)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StandardMaterialKind } from '@flighthq/types/contract';
|
|
2
|
+
|
|
3
|
+
import { createStandardMaterial } from './standardMaterial';
|
|
4
|
+
|
|
5
|
+
describe('createStandardMaterial', () => {
|
|
6
|
+
it('creates the authorable unlit textured material used by the default 2D pipeline', () => {
|
|
7
|
+
const material = createStandardMaterial();
|
|
8
|
+
|
|
9
|
+
expect(material.kind).toBe(StandardMaterialKind);
|
|
10
|
+
expect(material.name).toBeNull();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('preserves an authored name', () => {
|
|
14
|
+
expect(createStandardMaterial({ name: 'ui' }).name).toBe('ui');
|
|
15
|
+
});
|
|
16
|
+
});
|