@flighthq/lighting 0.1.0 → 0.2.0
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sceneLights.d.ts +3 -0
- package/dist/sceneLights.d.ts.map +1 -0
- package/dist/sceneLights.js +20 -0
- package/dist/sceneLights.js.map +1 -0
- package/package.json +9 -4
- package/src/sceneLights.test.ts +36 -0
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sceneLights.d.ts","sourceRoot":"","sources":["../src/sceneLights.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAYnD,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,WAAW,CAQvF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Constructs a `SceneLights` draw-argument, filling every absent slot: the single ambient/directional
|
|
2
|
+
// terms default to `null` and the punctual arrays to empty. Prefer this over a bare object literal —
|
|
3
|
+
// a literal that omits a slot passes `undefined` where the packer expects a light-or-null, which the
|
|
4
|
+
// strict `!== null` presence check reads as "present" and then dereferences (the classic
|
|
5
|
+
// `undefined.direction` crash). Going through the constructor makes an omitted slot unrepresentable.
|
|
6
|
+
//
|
|
7
|
+
// `SceneLights` is a per-draw argument (lights are not scene members), so it is NOT an Entity: it
|
|
8
|
+
// carries no GPU binding identity of its own — the packed `SceneLightBlock` is what a backend caches,
|
|
9
|
+
// keyed off the render state. The individual lights it references (`createPointLight`, …) are the
|
|
10
|
+
// entities. This is the constructor for the plain-data collection, not an entity factory.
|
|
11
|
+
export function createSceneLights(options) {
|
|
12
|
+
return {
|
|
13
|
+
ambient: options?.ambient ?? null,
|
|
14
|
+
directional: options?.directional ?? null,
|
|
15
|
+
hemisphere: options?.hemisphere ?? [],
|
|
16
|
+
point: options?.point ?? [],
|
|
17
|
+
spot: options?.spot ?? [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=sceneLights.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sceneLights.js","sourceRoot":"","sources":["../src/sceneLights.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,qGAAqG;AACrG,qGAAqG;AACrG,yFAAyF;AACzF,qGAAqG;AACrG,EAAE;AACF,kGAAkG;AAClG,sGAAsG;AACtG,kGAAkG;AAClG,0FAA0F;AAC1F,MAAM,UAAU,iBAAiB,CAAC,OAAwC;IACxE,OAAO;QACL,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI;QACjC,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI,IAAI;QACzC,UAAU,EAAE,OAAO,EAAE,UAAU,IAAI,EAAE;QACrC,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE;QAC3B,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE;KAC1B,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/lighting",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/flighthq/flight.git",
|
|
7
|
+
"directory": "packages/lighting"
|
|
8
|
+
},
|
|
4
9
|
"type": "module",
|
|
5
10
|
"main": "dist/index.js",
|
|
6
11
|
"types": "dist/index.d.ts",
|
|
@@ -27,9 +32,9 @@
|
|
|
27
32
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
28
33
|
},
|
|
29
34
|
"dependencies": {
|
|
30
|
-
"@flighthq/entity": "0.
|
|
31
|
-
"@flighthq/geometry": "0.
|
|
32
|
-
"@flighthq/types": "0.
|
|
35
|
+
"@flighthq/entity": "0.2.0",
|
|
36
|
+
"@flighthq/geometry": "0.2.0",
|
|
37
|
+
"@flighthq/types": "0.2.0"
|
|
33
38
|
},
|
|
34
39
|
"devDependencies": {
|
|
35
40
|
"typescript": "^5.3.0"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createAmbientLight } from './ambientLight';
|
|
4
|
+
import { createDirectionalLight } from './directionalLight';
|
|
5
|
+
import { createPointLight } from './pointLight';
|
|
6
|
+
import { createSceneLights } from './sceneLights';
|
|
7
|
+
|
|
8
|
+
describe('createSceneLights', () => {
|
|
9
|
+
it('fills every absent slot — singles to null, punctual arrays to empty', () => {
|
|
10
|
+
const lights = createSceneLights();
|
|
11
|
+
expect(lights.ambient).toBeNull();
|
|
12
|
+
expect(lights.directional).toBeNull();
|
|
13
|
+
expect(lights.point).toEqual([]);
|
|
14
|
+
expect(lights.spot).toEqual([]);
|
|
15
|
+
expect(lights.hemisphere).toEqual([]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('carries the provided lights and defaults the omitted ones (no undefined slot)', () => {
|
|
19
|
+
const point = createPointLight({ intensity: 2 });
|
|
20
|
+
const lights = createSceneLights({ point: [point] });
|
|
21
|
+
// The omitted directional must be null, not undefined — a literal that dropped it would crash the
|
|
22
|
+
// packer's strict `!== null` check; the constructor makes that unrepresentable.
|
|
23
|
+
expect(lights.directional).toBeNull();
|
|
24
|
+
expect(lights.ambient).toBeNull();
|
|
25
|
+
expect(lights.point).toEqual([point]);
|
|
26
|
+
expect(Object.prototype.hasOwnProperty.call(lights, 'directional')).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('passes through ambient + directional when supplied', () => {
|
|
30
|
+
const ambient = createAmbientLight({ intensity: 0.2 });
|
|
31
|
+
const directional = createDirectionalLight({ intensity: 3 });
|
|
32
|
+
const lights = createSceneLights({ ambient, directional });
|
|
33
|
+
expect(lights.ambient).toBe(ambient);
|
|
34
|
+
expect(lights.directional).toBe(directional);
|
|
35
|
+
});
|
|
36
|
+
});
|