@luma.gl/engine 10.0.0-alpha.14 → 10.0.0-alpha.15
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/arrow/index.cjs.map +2 -2
- package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.cjs +12 -13
- package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.d.ts.map +1 -1
- package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.js +22 -17
- package/dist/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.js.map +1 -1
- package/dist/lighting/index.cjs +12 -2
- package/dist/lighting/index.cjs.map +3 -3
- package/dist/lighting/index.d.ts +4 -0
- package/dist/lighting/index.d.ts.map +1 -1
- package/dist/lighting/index.js +2 -0
- package/dist/lighting/index.js.map +1 -1
- package/dist/lighting/lightmap-atlas.cjs +246 -0
- package/dist/lighting/lightmap-atlas.d.ts +53 -0
- package/dist/lighting/lightmap-atlas.d.ts.map +1 -0
- package/dist/lighting/lightmap-atlas.js +279 -0
- package/dist/lighting/lightmap-atlas.js.map +1 -0
- package/dist/lighting/reflection-probe.cjs +321 -0
- package/dist/lighting/reflection-probe.d.ts +77 -0
- package/dist/lighting/reflection-probe.d.ts.map +1 -0
- package/dist/lighting/reflection-probe.js +298 -0
- package/dist/lighting/reflection-probe.js.map +1 -0
- package/package.json +8 -8
- package/src/arrow/renderers/splats/conversion/make-gpu-splat-data-from-gltf.ts +23 -19
- package/src/lighting/index.ts +18 -0
- package/src/lighting/lightmap-atlas.ts +348 -0
- package/src/lighting/reflection-probe.ts +360 -0
- package/src/splats/README.md +1 -1
package/dist/lighting/index.d.ts
CHANGED
|
@@ -28,4 +28,8 @@ export { readLightmapData, createLightmapFromData, encodeLightmapData, decodeLig
|
|
|
28
28
|
export type { LightmapData } from "./lightmap-data.js";
|
|
29
29
|
export { sampleLightmapEnvironment } from "./lightmap-environment.js";
|
|
30
30
|
export type { LightmapEnvironment, LightmapEnvironmentSample } from "./lightmap-environment.js";
|
|
31
|
+
export { ReflectionProbe } from "./reflection-probe.js";
|
|
32
|
+
export type { ReflectionProbeProps, ReflectionProbeUpdate, ReflectionProbeView } from "./reflection-probe.js";
|
|
33
|
+
export { createLightmapAtlas, validateLightmapAtlas, getLightmapAtlasDebugData } from "./lightmap-atlas.js";
|
|
34
|
+
export type { LightmapAtlas, LightmapAtlasInput, LightmapAtlasOptions, LightmapAtlasChart } from "./lightmap-atlas.js";
|
|
31
35
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lighting/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,EAC/B,sBAAsB,EACvB,qCAAkC;AACnC,YAAY,EACV,6BAA6B,EAC7B,8BAA8B,EAC/B,qCAAkC;AACnC,OAAO,EAAC,0BAA0B,EAAC,0BAAuB;AAE1D,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EAC1B,0BAAuB;AACxB,YAAY,EAAC,wBAAwB,EAAE,WAAW,EAAE,oBAAoB,EAAC,0BAAuB;AAChG,OAAO,EAAC,yBAAyB,EAAE,yBAAyB,EAAC,6BAA0B;AACvF,YAAY,EAAC,sBAAsB,EAAE,6BAA6B,EAAC,6BAA0B;AAE7F,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACtB,uBAAoB;AACrB,YAAY,EAAC,qBAAqB,EAAE,mBAAmB,EAAC,uBAAoB;AAE5E,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAClB,iCAA8B;AAC/B,YAAY,EACV,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,mB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A0B,EAC1B,8BAA8B,EAC/B,kCAA+B;AAChC,YAAY,EACV,uBAAuB,EACvB,+BAA+B,EAC/B,0BAA0B,EAC1B,0BAA0B,EAC1B,oCAAoC,EACrC,kCAA+B;AAChC,OAAO,EAAC,oBAAoB,EAAC,oCAAiC;AAC9D,YAAY,EACV,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC9B,oCAAiC;AAElC,OAAO,EAAC,sBAAsB,EAAC,uBAAoB;AACnD,YAAY,EAAC,6BAA6B,EAAC,uBAAoB;AAC/D,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,4BAAyB;AACnE,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EACjB,4BAAyB;AAC1B,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EACnB,2BAAwB;AACzB,YAAY,EAAC,YAAY,EAAC,2BAAwB;AAClD,OAAO,EAAC,yBAAyB,EAAC,kCAA+B;AACjE,YAAY,EAAC,mBAAmB,EAAE,yBAAyB,EAAC,kCAA+B;AAE3F,OAAO,EAAC,eAAe,EAAC,8BAA2B;AACnD,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACpB,8BAA2B;AAC5B,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EAC1B,4BAAyB;AAC1B,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EACnB,4BAAyB"}
|
package/dist/lighting/index.js
CHANGED
|
@@ -17,4 +17,6 @@ export { createPBRLightmapModel } from "./pbr-model.js";
|
|
|
17
17
|
export { LightmapBaker, LightmapBakeResult } from "./lightmap-baker.js";
|
|
18
18
|
export { readLightmapData, createLightmapFromData, encodeLightmapData, decodeLightmapData } from "./lightmap-data.js";
|
|
19
19
|
export { sampleLightmapEnvironment } from "./lightmap-environment.js";
|
|
20
|
+
export { ReflectionProbe } from "./reflection-probe.js";
|
|
21
|
+
export { createLightmapAtlas, validateLightmapAtlas, getLightmapAtlasDebugData } from "./lightmap-atlas.js";
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lighting/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,EAC/B,sBAAsB,EACvB,qCAAkC;AAKnC,OAAO,EAAC,0BAA0B,EAAC,0BAAuB;AAE1D,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EAC1B,0BAAuB;AAExB,OAAO,EAAC,yBAAyB,EAAE,yBAAyB,EAAC,6BAA0B;AAGvF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACtB,uBAAoB;AAGrB,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAClB,iCAA8B;AAY/B,OAAO,EAAC,uBAAuB,EAAC,4BAAyB;AAGzD,OAAO,EAAC,cAAc,EAAC,8BAA2B;AAOlD,OAAO,EAAC,sCAAsC,EAAC,sCAAmC;AAElF,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AAGxD,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,EAC1B,0BAA0B,EAC1B,8BAA8B,EAC/B,kCAA+B;AAQhC,OAAO,EAAC,oBAAoB,EAAC,oCAAiC;AAO9D,OAAO,EAAC,sBAAsB,EAAC,uBAAoB;AAEnD,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,4BAAyB;AAOnE,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EACnB,2BAAwB;AAEzB,OAAO,EAAC,yBAAyB,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AyB"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var lightmap_atlas_exports = {};
|
|
19
|
+
__export(lightmap_atlas_exports, {
|
|
20
|
+
createLightmapAtlas: () => createLightmapAtlas,
|
|
21
|
+
getLightmapAtlasDebugData: () => getLightmapAtlasDebugData,
|
|
22
|
+
validateLightmapAtlas: () => validateLightmapAtlas
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(lightmap_atlas_exports);
|
|
25
|
+
var import_core = require("@luma.gl/core");
|
|
26
|
+
var import_core2 = require("@math.gl/core");
|
|
27
|
+
var import_geometry = require("../geometry/geometry.cjs");
|
|
28
|
+
function createLightmapAtlas(inputs, options) {
|
|
29
|
+
const { width, height, texelsPerUnit, padding = 2, uvSet = 1 } = options;
|
|
30
|
+
(0, import_core.assert)(Number.isSafeInteger(width) && width > 0 && Number.isSafeInteger(height) && height > 0);
|
|
31
|
+
(0, import_core.assert)(Number.isFinite(texelsPerUnit) && texelsPerUnit > 0);
|
|
32
|
+
(0, import_core.assert)(Number.isInteger(padding) && padding >= 0 && padding <= 16);
|
|
33
|
+
(0, import_core.assert)(uvSet === 0 || uvSet === 1);
|
|
34
|
+
(0, import_core.assert)(new Set(inputs.map((input) => input.id)).size === inputs.length);
|
|
35
|
+
const charts = [];
|
|
36
|
+
const meshes = inputs.map((input, meshIndex) => {
|
|
37
|
+
var _a;
|
|
38
|
+
const source = input.geometry;
|
|
39
|
+
const positions = source.attributes["POSITION"];
|
|
40
|
+
(0, import_core.assert)(source.topology === "triangle-list" && (positions == null ? void 0 : positions.size) === 3 && !positions.normalized);
|
|
41
|
+
const indices = (_a = source.indices) == null ? void 0 : _a.value;
|
|
42
|
+
const vertexCount = source.vertexCount;
|
|
43
|
+
(0, import_core.assert)(!indices || vertexCount <= indices.length);
|
|
44
|
+
(0, import_core.assert)(vertexCount > 0 && vertexCount % 3 === 0);
|
|
45
|
+
const attributes = {};
|
|
46
|
+
for (const [name, attribute] of Object.entries(source.attributes)) {
|
|
47
|
+
const { size, value } = attribute;
|
|
48
|
+
(0, import_core.assert)(size && !attribute.constant && value.length === positions.value.length / 3 * size && !attribute["byteStride"] && !attribute["byteOffset"] && !attribute["divisor"]);
|
|
49
|
+
const copied = value.slice(0, 0);
|
|
50
|
+
const expanded = new copied.constructor(vertexCount * size);
|
|
51
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
52
|
+
const sourceVertex = indices ? indices[vertex] : vertex;
|
|
53
|
+
(0, import_core.assert)(Number.isInteger(sourceVertex) && sourceVertex >= 0 && sourceVertex < value.length / size);
|
|
54
|
+
for (let component = 0; component < size; component++)
|
|
55
|
+
expanded[vertex * size + component] = value[sourceVertex * size + component];
|
|
56
|
+
}
|
|
57
|
+
attributes[name] = { ...attribute, value: expanded };
|
|
58
|
+
}
|
|
59
|
+
const coordinates = new Float32Array(vertexCount * 2);
|
|
60
|
+
attributes[`TEXCOORD_${uvSet}`] = { size: 2, value: coordinates };
|
|
61
|
+
const matrix = input.modelMatrix ?? new import_core2.Matrix4();
|
|
62
|
+
(0, import_core.assert)(matrix.every(Number.isFinite) && matrix[3] === 0 && matrix[7] === 0 && matrix[11] === 0 && matrix[15] === 1);
|
|
63
|
+
const getPoints = (firstVertex) => [0, 1, 2].map((offset) => {
|
|
64
|
+
const vertex = indices ? indices[firstVertex + offset] : firstVertex + offset;
|
|
65
|
+
const point = new import_core2.Vector3(positions.value.slice(vertex * 3, vertex * 3 + 3));
|
|
66
|
+
(0, import_core.assert)(point.every(Number.isFinite));
|
|
67
|
+
return point.transformAsPoint(matrix);
|
|
68
|
+
});
|
|
69
|
+
for (let firstVertex = 0; firstVertex < vertexCount; ) {
|
|
70
|
+
const points = getPoints(firstVertex);
|
|
71
|
+
const edges = points.map((point, index) => new import_core2.Vector3(points[(index + 1) % 3]).subtract(point));
|
|
72
|
+
const lengths = edges.map((edge) => edge.len());
|
|
73
|
+
const start = lengths.indexOf(Math.max(...lengths));
|
|
74
|
+
const end = (start + 1) % 3;
|
|
75
|
+
const third = (start + 2) % 3;
|
|
76
|
+
const horizontal = edges[start].clone().normalize();
|
|
77
|
+
const relative = new import_core2.Vector3(points[third]).subtract(points[start]);
|
|
78
|
+
const projected = relative.dot(horizontal);
|
|
79
|
+
const altitude = new import_core2.Vector3(edges[start]).cross(relative).len() / lengths[start];
|
|
80
|
+
(0, import_core.assert)(Number.isFinite(altitude) && altitude > 0 && lengths[start] > 0);
|
|
81
|
+
const local = new Array(6).fill(0);
|
|
82
|
+
local[end * 2] = lengths[start] * texelsPerUnit;
|
|
83
|
+
local[third * 2] = projected * texelsPerUnit;
|
|
84
|
+
local[third * 2 + 1] = altitude * texelsPerUnit;
|
|
85
|
+
let worldArea = lengths[start] * altitude / 2;
|
|
86
|
+
if (options.mergeCoplanarPairs && firstVertex + 6 <= vertexCount) {
|
|
87
|
+
const second = getPoints(firstVertex + 3);
|
|
88
|
+
const shared = second.map((point) => points.findIndex((candidate) => candidate.every((component, index) => component === point[index])));
|
|
89
|
+
if (shared.filter((index) => index >= 0).length === 2 && new Set(shared).size === 3) {
|
|
90
|
+
const normal = edges[start].clone().cross(relative).normalize();
|
|
91
|
+
const vertical = normal.clone().cross(horizontal);
|
|
92
|
+
const opposite = shared.indexOf(-1);
|
|
93
|
+
const delta = second[opposite].clone().subtract(points[start]);
|
|
94
|
+
const projectedPoint = [delta.dot(horizontal), delta.dot(vertical)];
|
|
95
|
+
const [sharedFirst, sharedSecond] = shared.filter((index) => index >= 0);
|
|
96
|
+
const unshared = [0, 1, 2].find((index) => !shared.includes(index));
|
|
97
|
+
const side = (x, y) => (local[sharedSecond * 2] - local[sharedFirst * 2]) * (y - local[sharedFirst * 2 + 1]) - (local[sharedSecond * 2 + 1] - local[sharedFirst * 2 + 1]) * (x - local[sharedFirst * 2]);
|
|
98
|
+
const secondArea = second[1].clone().subtract(second[0]).cross(second[2].clone().subtract(second[0]));
|
|
99
|
+
if (Math.abs(delta.dot(normal)) <= 1e-7 * delta.len() && secondArea.dot(normal) > 0 && side(local[unshared * 2], local[unshared * 2 + 1]) * side(projectedPoint[0] * texelsPerUnit, projectedPoint[1] * texelsPerUnit) < 0) {
|
|
100
|
+
for (const index of shared) {
|
|
101
|
+
if (index >= 0)
|
|
102
|
+
local.push(local[index * 2], local[index * 2 + 1]);
|
|
103
|
+
else
|
|
104
|
+
local.push(projectedPoint[0] * texelsPerUnit, projectedPoint[1] * texelsPerUnit);
|
|
105
|
+
}
|
|
106
|
+
worldArea += secondArea.len() / 2;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const horizontalCoordinates = local.filter((_, index) => index % 2 === 0);
|
|
111
|
+
const verticalCoordinates = local.filter((_, index) => index % 2 === 1);
|
|
112
|
+
const chartVertexCount = local.length / 2;
|
|
113
|
+
const minimumX = chartVertexCount === 3 ? 0 : Math.min(...horizontalCoordinates);
|
|
114
|
+
const minimumY = chartVertexCount === 3 ? 0 : Math.min(...verticalCoordinates);
|
|
115
|
+
charts.push({
|
|
116
|
+
id: charts.length + 1,
|
|
117
|
+
meshId: input.id,
|
|
118
|
+
meshIndex,
|
|
119
|
+
firstVertex,
|
|
120
|
+
vertexCount: chartVertexCount,
|
|
121
|
+
rectangle: {
|
|
122
|
+
x: 0,
|
|
123
|
+
y: 0,
|
|
124
|
+
width: Math.ceil(chartVertexCount === 3 ? lengths[start] * texelsPerUnit : Math.max(...horizontalCoordinates) - minimumX) + 1 + padding * 2,
|
|
125
|
+
height: Math.ceil(Math.max(...verticalCoordinates) - minimumY) + 1 + padding * 2
|
|
126
|
+
},
|
|
127
|
+
worldArea,
|
|
128
|
+
coordinates: local.map((value, index) => value - (index % 2 ? minimumY : minimumX))
|
|
129
|
+
});
|
|
130
|
+
firstVertex += chartVertexCount;
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
id: input.id,
|
|
134
|
+
geometry: new import_geometry.Geometry({
|
|
135
|
+
id: `${source.id}-lightmap`,
|
|
136
|
+
topology: "triangle-list",
|
|
137
|
+
vertexCount,
|
|
138
|
+
attributes
|
|
139
|
+
})
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
(0, import_core.assert)(charts.length <= 2048);
|
|
143
|
+
let cursorX = 0;
|
|
144
|
+
let cursorY = 0;
|
|
145
|
+
let shelfHeight = 0;
|
|
146
|
+
let allocatedPixels = 0;
|
|
147
|
+
for (const chart of [...charts].sort((left, right) => right.rectangle.height - left.rectangle.height || right.rectangle.width - left.rectangle.width || left.id - right.id)) {
|
|
148
|
+
const rectangle = chart.rectangle;
|
|
149
|
+
if (cursorX + rectangle.width > width) {
|
|
150
|
+
cursorX = 0;
|
|
151
|
+
cursorY += shelfHeight;
|
|
152
|
+
shelfHeight = 0;
|
|
153
|
+
}
|
|
154
|
+
(0, import_core.assert)(rectangle.width <= width && cursorY + rectangle.height <= height);
|
|
155
|
+
rectangle.x = cursorX;
|
|
156
|
+
rectangle.y = cursorY;
|
|
157
|
+
cursorX += rectangle.width;
|
|
158
|
+
shelfHeight = Math.max(shelfHeight, rectangle.height);
|
|
159
|
+
allocatedPixels += rectangle.width * rectangle.height;
|
|
160
|
+
const coordinates = meshes[chart.meshIndex].geometry.attributes[`TEXCOORD_${uvSet}`].value;
|
|
161
|
+
for (let vertex = 0; vertex < chart.vertexCount; vertex++) {
|
|
162
|
+
coordinates[(chart.firstVertex + vertex) * 2] = (rectangle.x + padding + 0.5 + chart.coordinates[vertex * 2]) / width;
|
|
163
|
+
coordinates[(chart.firstVertex + vertex) * 2 + 1] = (rectangle.y + padding + 0.5 + chart.coordinates[vertex * 2 + 1]) / height;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const chartOwners = new Float32Array(width * height);
|
|
167
|
+
for (const { id, rectangle } of charts)
|
|
168
|
+
for (let row = rectangle.y; row < rectangle.y + rectangle.height; row++)
|
|
169
|
+
chartOwners.fill(id, row * width + rectangle.x, row * width + rectangle.x + rectangle.width);
|
|
170
|
+
return {
|
|
171
|
+
width,
|
|
172
|
+
height,
|
|
173
|
+
texelsPerUnit,
|
|
174
|
+
padding,
|
|
175
|
+
uvSet,
|
|
176
|
+
meshes,
|
|
177
|
+
charts: charts.map(({ coordinates, meshIndex, ...chart }) => chart),
|
|
178
|
+
chartOwners,
|
|
179
|
+
occupancy: allocatedPixels / (width * height)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function validateLightmapAtlas(atlas) {
|
|
183
|
+
var _a;
|
|
184
|
+
const errors = [];
|
|
185
|
+
if (!Number.isSafeInteger(atlas.width) || atlas.width <= 0 || !Number.isSafeInteger(atlas.height) || atlas.height <= 0 || atlas.chartOwners.length !== atlas.width * atlas.height)
|
|
186
|
+
return ["Invalid atlas dimensions or ownership data length"];
|
|
187
|
+
const occupied = new Uint8Array(atlas.width * atlas.height);
|
|
188
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
189
|
+
for (const chart of atlas.charts) {
|
|
190
|
+
const { x, y, width, height } = chart.rectangle;
|
|
191
|
+
if (!Number.isInteger(chart.id) || chart.id <= 0 || chart.id > 2048 || identifiers.has(chart.id))
|
|
192
|
+
errors.push(`Invalid chart ID ${chart.id}`);
|
|
193
|
+
identifiers.add(chart.id);
|
|
194
|
+
if (![x, y, width, height].every(Number.isInteger) || x < 0 || y < 0 || width <= 0 || height <= 0 || x + width > atlas.width || y + height > atlas.height) {
|
|
195
|
+
errors.push(`Chart ${chart.id} is outside the atlas`);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
let overlaps = false;
|
|
199
|
+
let ownershipMismatch = false;
|
|
200
|
+
for (let row = y; row < y + height; row++)
|
|
201
|
+
for (let column = x; column < x + width; column++) {
|
|
202
|
+
const pixel = row * atlas.width + column;
|
|
203
|
+
overlaps ||= Boolean(occupied[pixel]);
|
|
204
|
+
occupied[pixel] = 1;
|
|
205
|
+
ownershipMismatch ||= atlas.chartOwners[pixel] !== chart.id;
|
|
206
|
+
}
|
|
207
|
+
if (overlaps)
|
|
208
|
+
errors.push(`Chart ${chart.id} overlaps another chart`);
|
|
209
|
+
if (ownershipMismatch)
|
|
210
|
+
errors.push(`Chart ${chart.id} has inconsistent gutter ownership`);
|
|
211
|
+
const mesh = atlas.meshes.find((candidate) => candidate.id === chart.meshId);
|
|
212
|
+
const coordinates = (_a = mesh == null ? void 0 : mesh.geometry.attributes[`TEXCOORD_${atlas.uvSet}`]) == null ? void 0 : _a.value;
|
|
213
|
+
if (!coordinates || !Number.isInteger(chart.firstVertex) || !Number.isInteger(chart.vertexCount) || chart.vertexCount <= 0 || chart.firstVertex < 0 || chart.firstVertex + chart.vertexCount > coordinates.length / 2) {
|
|
214
|
+
errors.push(`Chart ${chart.id} has an invalid draw range`);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
for (let vertex = chart.firstVertex; vertex < chart.firstVertex + chart.vertexCount; vertex++) {
|
|
218
|
+
const horizontal = coordinates[vertex * 2] * atlas.width;
|
|
219
|
+
const vertical = coordinates[vertex * 2 + 1] * atlas.height;
|
|
220
|
+
if (!Number.isFinite(horizontal) || !Number.isFinite(vertical) || horizontal < x + atlas.padding || horizontal > x + width - atlas.padding || vertical < y + atlas.padding || vertical > y + height - atlas.padding) {
|
|
221
|
+
errors.push(`Chart ${chart.id} has UVs outside its padded rectangle`);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (atlas.chartOwners.some((owner, pixel) => !occupied[pixel] && owner !== 0))
|
|
227
|
+
errors.push("Unallocated pixels have chart owners");
|
|
228
|
+
return errors;
|
|
229
|
+
}
|
|
230
|
+
function getLightmapAtlasDebugData(atlas) {
|
|
231
|
+
const pixels = new Uint8ClampedArray(atlas.width * atlas.height * 4);
|
|
232
|
+
for (let pixel = 0; pixel < atlas.chartOwners.length; pixel++) {
|
|
233
|
+
const identifier = atlas.chartOwners[pixel];
|
|
234
|
+
pixels[pixel * 4] = identifier ? 64 + identifier * 67 % 192 : 0;
|
|
235
|
+
pixels[pixel * 4 + 1] = identifier ? 64 + identifier * 103 % 192 : 0;
|
|
236
|
+
pixels[pixel * 4 + 2] = identifier ? 64 + identifier * 137 % 192 : 0;
|
|
237
|
+
pixels[pixel * 4 + 3] = 255;
|
|
238
|
+
}
|
|
239
|
+
return pixels;
|
|
240
|
+
}
|
|
241
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
242
|
+
0 && (module.exports = {
|
|
243
|
+
createLightmapAtlas,
|
|
244
|
+
getLightmapAtlasDebugData,
|
|
245
|
+
validateLightmapAtlas
|
|
246
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Matrix4 } from '@math.gl/core';
|
|
2
|
+
import { Geometry } from "../geometry/geometry.js";
|
|
3
|
+
export type LightmapAtlasInput = {
|
|
4
|
+
/** Stable application-owned identity; unique within an atlas. */
|
|
5
|
+
id: string;
|
|
6
|
+
geometry: Geometry;
|
|
7
|
+
/** Used only to measure world-space texel density. Output positions stay in object space. */
|
|
8
|
+
modelMatrix?: Matrix4;
|
|
9
|
+
};
|
|
10
|
+
export type LightmapAtlasOptions = {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
texelsPerUnit: number;
|
|
14
|
+
padding?: number;
|
|
15
|
+
uvSet?: 0 | 1;
|
|
16
|
+
/** Join consecutive coplanar triangles that form a quad. */
|
|
17
|
+
mergeCoplanarPairs?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type LightmapAtlasChart = {
|
|
20
|
+
id: number;
|
|
21
|
+
meshId: string;
|
|
22
|
+
firstVertex: number;
|
|
23
|
+
vertexCount: number;
|
|
24
|
+
/** Integer pixel rectangle including padding, measured from the atlas top left. */
|
|
25
|
+
rectangle: {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
};
|
|
31
|
+
worldArea: number;
|
|
32
|
+
};
|
|
33
|
+
export type LightmapAtlas = Required<Omit<LightmapAtlasOptions, 'mergeCoplanarPairs'>> & {
|
|
34
|
+
meshes: {
|
|
35
|
+
id: string;
|
|
36
|
+
geometry: Geometry;
|
|
37
|
+
}[];
|
|
38
|
+
charts: LightmapAtlasChart[];
|
|
39
|
+
/** Independent row-major r32float data, suitable for LightmapBaker chartTexture. Zero is unused. */
|
|
40
|
+
chartOwners: Float32Array;
|
|
41
|
+
/** Fraction of atlas pixels reserved by chart rectangles, including gutters. */
|
|
42
|
+
occupancy: number;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Prepare an independent CPU atlas. Each triangle receives a planar chart; no seam heuristics,
|
|
46
|
+
* GPU allocation, texture upload, submission, or source mutation occurs here.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createLightmapAtlas(inputs: readonly LightmapAtlasInput[], options: LightmapAtlasOptions): LightmapAtlas;
|
|
49
|
+
/** Explicit diagnostic pass; returns actionable chart errors without allocating GPU resources. */
|
|
50
|
+
export declare function validateLightmapAtlas(atlas: LightmapAtlas): string[];
|
|
51
|
+
/** Independent RGBA8 chart-ownership preview. Unallocated pixels are opaque black. */
|
|
52
|
+
export declare function getLightmapAtlasDebugData(atlas: LightmapAtlas): Uint8ClampedArray;
|
|
53
|
+
//# sourceMappingURL=lightmap-atlas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightmap-atlas.d.ts","sourceRoot":"","sources":["../../src/lighting/lightmap-atlas.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,OAAO,EAAU,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAC,QAAQ,EAAyB,gCAA6B;AAEtE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,iEAAiE;IACjE,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,6FAA6F;IAC7F,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACd,4DAA4D;IAC5D,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,mFAAmF;IACnF,SAAS,EAAE;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAC;IACjE,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAC,GAAG;IACvF,MAAM,EAAE;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAA;KAAC,EAAE,CAAC;IAC3C,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,oGAAoG;IACpG,WAAW,EAAE,YAAY,CAAC;IAC1B,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAGF;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,kBAAkB,EAAE,EACrC,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CA6Mf;AAED,kGAAkG;AAClG,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,EAAE,CA6EpE;AAED,sFAAsF;AACtF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,aAAa,GAAG,iBAAiB,CAUjF"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
3
|
+
import { assert } from '@luma.gl/core';
|
|
4
|
+
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
5
|
+
import { Geometry } from "../geometry/geometry.js";
|
|
6
|
+
/**
|
|
7
|
+
* Prepare an independent CPU atlas. Each triangle receives a planar chart; no seam heuristics,
|
|
8
|
+
* GPU allocation, texture upload, submission, or source mutation occurs here.
|
|
9
|
+
*/
|
|
10
|
+
export function createLightmapAtlas(inputs, options) {
|
|
11
|
+
const { width, height, texelsPerUnit, padding = 2, uvSet = 1 } = options;
|
|
12
|
+
// Dimensions, density and gutters must be explicit and finite. Chart IDs stay exact in float16.
|
|
13
|
+
assert(Number.isSafeInteger(width) && width > 0 && Number.isSafeInteger(height) && height > 0);
|
|
14
|
+
assert(Number.isFinite(texelsPerUnit) && texelsPerUnit > 0);
|
|
15
|
+
assert(Number.isInteger(padding) && padding >= 0 && padding <= 16);
|
|
16
|
+
assert(uvSet === 0 || uvSet === 1);
|
|
17
|
+
assert(new Set(inputs.map(input => input.id)).size === inputs.length);
|
|
18
|
+
const charts = [];
|
|
19
|
+
const meshes = inputs.map((input, meshIndex) => {
|
|
20
|
+
const source = input.geometry;
|
|
21
|
+
const positions = source.attributes['POSITION'];
|
|
22
|
+
// Only tightly packed, per-vertex triangle-list attributes are supported.
|
|
23
|
+
assert(source.topology === 'triangle-list' && positions?.size === 3 && !positions.normalized);
|
|
24
|
+
const indices = source.indices?.value;
|
|
25
|
+
const vertexCount = source.vertexCount;
|
|
26
|
+
assert(!indices || vertexCount <= indices.length);
|
|
27
|
+
assert(vertexCount > 0 && vertexCount % 3 === 0);
|
|
28
|
+
const attributes = {};
|
|
29
|
+
for (const [name, attribute] of Object.entries(source.attributes)) {
|
|
30
|
+
const { size, value } = attribute;
|
|
31
|
+
assert(size &&
|
|
32
|
+
!attribute.constant &&
|
|
33
|
+
value.length === (positions.value.length / 3) * size &&
|
|
34
|
+
!attribute['byteStride'] &&
|
|
35
|
+
!attribute['byteOffset'] &&
|
|
36
|
+
!attribute['divisor']);
|
|
37
|
+
const copied = value.slice(0, 0);
|
|
38
|
+
// Keep the original numeric storage type, including normalized integer attributes.
|
|
39
|
+
const expanded = new copied.constructor(vertexCount * size);
|
|
40
|
+
for (let vertex = 0; vertex < vertexCount; vertex++) {
|
|
41
|
+
const sourceVertex = indices ? indices[vertex] : vertex;
|
|
42
|
+
assert(Number.isInteger(sourceVertex) && sourceVertex >= 0 && sourceVertex < value.length / size);
|
|
43
|
+
for (let component = 0; component < size; component++)
|
|
44
|
+
expanded[vertex * size + component] = value[sourceVertex * size + component];
|
|
45
|
+
}
|
|
46
|
+
attributes[name] = { ...attribute, value: expanded };
|
|
47
|
+
}
|
|
48
|
+
const coordinates = new Float32Array(vertexCount * 2);
|
|
49
|
+
attributes[`TEXCOORD_${uvSet}`] = { size: 2, value: coordinates };
|
|
50
|
+
const matrix = input.modelMatrix ?? new Matrix4();
|
|
51
|
+
// Affine transforms only; a projective matrix has no uniform world-space density.
|
|
52
|
+
assert(matrix.every(Number.isFinite) &&
|
|
53
|
+
matrix[3] === 0 &&
|
|
54
|
+
matrix[7] === 0 &&
|
|
55
|
+
matrix[11] === 0 &&
|
|
56
|
+
matrix[15] === 1);
|
|
57
|
+
const getPoints = (firstVertex) => [0, 1, 2].map(offset => {
|
|
58
|
+
const vertex = indices ? indices[firstVertex + offset] : firstVertex + offset;
|
|
59
|
+
const point = new Vector3(positions.value.slice(vertex * 3, vertex * 3 + 3));
|
|
60
|
+
assert(point.every(Number.isFinite));
|
|
61
|
+
return point.transformAsPoint(matrix);
|
|
62
|
+
});
|
|
63
|
+
for (let firstVertex = 0; firstVertex < vertexCount;) {
|
|
64
|
+
const points = getPoints(firstVertex);
|
|
65
|
+
const edges = points.map((point, index) => new Vector3(points[(index + 1) % 3]).subtract(point));
|
|
66
|
+
const lengths = edges.map(edge => edge.len());
|
|
67
|
+
const start = lengths.indexOf(Math.max(...lengths));
|
|
68
|
+
const end = (start + 1) % 3;
|
|
69
|
+
const third = (start + 2) % 3;
|
|
70
|
+
const horizontal = edges[start].clone().normalize();
|
|
71
|
+
const relative = new Vector3(points[third]).subtract(points[start]);
|
|
72
|
+
const projected = relative.dot(horizontal);
|
|
73
|
+
const altitude = new Vector3(edges[start]).cross(relative).len() / lengths[start];
|
|
74
|
+
// Degenerate transformed triangles cannot receive lightmap samples.
|
|
75
|
+
assert(Number.isFinite(altitude) && altitude > 0 && lengths[start] > 0);
|
|
76
|
+
const local = new Array(6).fill(0);
|
|
77
|
+
local[end * 2] = lengths[start] * texelsPerUnit;
|
|
78
|
+
local[third * 2] = projected * texelsPerUnit;
|
|
79
|
+
local[third * 2 + 1] = altitude * texelsPerUnit;
|
|
80
|
+
let worldArea = (lengths[start] * altitude) / 2;
|
|
81
|
+
if (options.mergeCoplanarPairs && firstVertex + 6 <= vertexCount) {
|
|
82
|
+
const second = getPoints(firstVertex + 3);
|
|
83
|
+
const shared = second.map(point => points.findIndex(candidate => candidate.every((component, index) => component === point[index])));
|
|
84
|
+
if (shared.filter(index => index >= 0).length === 2 && new Set(shared).size === 3) {
|
|
85
|
+
const normal = edges[start].clone().cross(relative).normalize();
|
|
86
|
+
const vertical = normal.clone().cross(horizontal);
|
|
87
|
+
const opposite = shared.indexOf(-1);
|
|
88
|
+
const delta = second[opposite].clone().subtract(points[start]);
|
|
89
|
+
const projectedPoint = [delta.dot(horizontal), delta.dot(vertical)];
|
|
90
|
+
const [sharedFirst, sharedSecond] = shared.filter(index => index >= 0);
|
|
91
|
+
const unshared = [0, 1, 2].find(index => !shared.includes(index));
|
|
92
|
+
const side = (x, y) => (local[sharedSecond * 2] - local[sharedFirst * 2]) * (y - local[sharedFirst * 2 + 1]) -
|
|
93
|
+
(local[sharedSecond * 2 + 1] - local[sharedFirst * 2 + 1]) *
|
|
94
|
+
(x - local[sharedFirst * 2]);
|
|
95
|
+
const secondArea = second[1]
|
|
96
|
+
.clone()
|
|
97
|
+
.subtract(second[0])
|
|
98
|
+
.cross(second[2].clone().subtract(second[0]));
|
|
99
|
+
if (Math.abs(delta.dot(normal)) <= 1e-7 * delta.len() &&
|
|
100
|
+
secondArea.dot(normal) > 0 &&
|
|
101
|
+
side(local[unshared * 2], local[unshared * 2 + 1]) *
|
|
102
|
+
side(projectedPoint[0] * texelsPerUnit, projectedPoint[1] * texelsPerUnit) <
|
|
103
|
+
0) {
|
|
104
|
+
for (const index of shared) {
|
|
105
|
+
if (index >= 0)
|
|
106
|
+
local.push(local[index * 2], local[index * 2 + 1]);
|
|
107
|
+
else
|
|
108
|
+
local.push(projectedPoint[0] * texelsPerUnit, projectedPoint[1] * texelsPerUnit);
|
|
109
|
+
}
|
|
110
|
+
worldArea += secondArea.len() / 2;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const horizontalCoordinates = local.filter((_, index) => index % 2 === 0);
|
|
115
|
+
const verticalCoordinates = local.filter((_, index) => index % 2 === 1);
|
|
116
|
+
const chartVertexCount = local.length / 2;
|
|
117
|
+
const minimumX = chartVertexCount === 3 ? 0 : Math.min(...horizontalCoordinates);
|
|
118
|
+
const minimumY = chartVertexCount === 3 ? 0 : Math.min(...verticalCoordinates);
|
|
119
|
+
charts.push({
|
|
120
|
+
id: charts.length + 1,
|
|
121
|
+
meshId: input.id,
|
|
122
|
+
meshIndex,
|
|
123
|
+
firstVertex,
|
|
124
|
+
vertexCount: chartVertexCount,
|
|
125
|
+
rectangle: {
|
|
126
|
+
x: 0,
|
|
127
|
+
y: 0,
|
|
128
|
+
width: Math.ceil(chartVertexCount === 3
|
|
129
|
+
? lengths[start] * texelsPerUnit
|
|
130
|
+
: Math.max(...horizontalCoordinates) - minimumX) +
|
|
131
|
+
1 +
|
|
132
|
+
padding * 2,
|
|
133
|
+
height: Math.ceil(Math.max(...verticalCoordinates) - minimumY) + 1 + padding * 2
|
|
134
|
+
},
|
|
135
|
+
worldArea,
|
|
136
|
+
coordinates: local.map((value, index) => value - (index % 2 ? minimumY : minimumX))
|
|
137
|
+
});
|
|
138
|
+
firstVertex += chartVertexCount;
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
id: input.id,
|
|
142
|
+
geometry: new Geometry({
|
|
143
|
+
id: `${source.id}-lightmap`,
|
|
144
|
+
topology: 'triangle-list',
|
|
145
|
+
vertexCount,
|
|
146
|
+
attributes
|
|
147
|
+
})
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
// Positive integer chart IDs must survive the default rgba16float bake target exactly.
|
|
151
|
+
assert(charts.length <= 2048);
|
|
152
|
+
let cursorX = 0;
|
|
153
|
+
let cursorY = 0;
|
|
154
|
+
let shelfHeight = 0;
|
|
155
|
+
let allocatedPixels = 0;
|
|
156
|
+
for (const chart of [...charts].sort((left, right) => right.rectangle.height - left.rectangle.height ||
|
|
157
|
+
right.rectangle.width - left.rectangle.width ||
|
|
158
|
+
left.id - right.id)) {
|
|
159
|
+
const rectangle = chart.rectangle;
|
|
160
|
+
if (cursorX + rectangle.width > width) {
|
|
161
|
+
cursorX = 0;
|
|
162
|
+
cursorY += shelfHeight;
|
|
163
|
+
shelfHeight = 0;
|
|
164
|
+
}
|
|
165
|
+
// Packing never silently changes density. Increase dimensions or lower texelsPerUnit.
|
|
166
|
+
assert(rectangle.width <= width && cursorY + rectangle.height <= height);
|
|
167
|
+
rectangle.x = cursorX;
|
|
168
|
+
rectangle.y = cursorY;
|
|
169
|
+
cursorX += rectangle.width;
|
|
170
|
+
shelfHeight = Math.max(shelfHeight, rectangle.height);
|
|
171
|
+
allocatedPixels += rectangle.width * rectangle.height;
|
|
172
|
+
const coordinates = meshes[chart.meshIndex].geometry.attributes[`TEXCOORD_${uvSet}`].value;
|
|
173
|
+
for (let vertex = 0; vertex < chart.vertexCount; vertex++) {
|
|
174
|
+
coordinates[(chart.firstVertex + vertex) * 2] =
|
|
175
|
+
(rectangle.x + padding + 0.5 + chart.coordinates[vertex * 2]) / width;
|
|
176
|
+
coordinates[(chart.firstVertex + vertex) * 2 + 1] =
|
|
177
|
+
(rectangle.y + padding + 0.5 + chart.coordinates[vertex * 2 + 1]) / height;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const chartOwners = new Float32Array(width * height);
|
|
181
|
+
for (const { id, rectangle } of charts)
|
|
182
|
+
for (let row = rectangle.y; row < rectangle.y + rectangle.height; row++)
|
|
183
|
+
chartOwners.fill(id, row * width + rectangle.x, row * width + rectangle.x + rectangle.width);
|
|
184
|
+
return {
|
|
185
|
+
width,
|
|
186
|
+
height,
|
|
187
|
+
texelsPerUnit,
|
|
188
|
+
padding,
|
|
189
|
+
uvSet,
|
|
190
|
+
meshes,
|
|
191
|
+
charts: charts.map(({ coordinates, meshIndex, ...chart }) => chart),
|
|
192
|
+
chartOwners,
|
|
193
|
+
occupancy: allocatedPixels / (width * height)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/** Explicit diagnostic pass; returns actionable chart errors without allocating GPU resources. */
|
|
197
|
+
export function validateLightmapAtlas(atlas) {
|
|
198
|
+
const errors = [];
|
|
199
|
+
if (!Number.isSafeInteger(atlas.width) ||
|
|
200
|
+
atlas.width <= 0 ||
|
|
201
|
+
!Number.isSafeInteger(atlas.height) ||
|
|
202
|
+
atlas.height <= 0 ||
|
|
203
|
+
atlas.chartOwners.length !== atlas.width * atlas.height)
|
|
204
|
+
return ['Invalid atlas dimensions or ownership data length'];
|
|
205
|
+
const occupied = new Uint8Array(atlas.width * atlas.height);
|
|
206
|
+
const identifiers = new Set();
|
|
207
|
+
for (const chart of atlas.charts) {
|
|
208
|
+
const { x, y, width, height } = chart.rectangle;
|
|
209
|
+
if (!Number.isInteger(chart.id) ||
|
|
210
|
+
chart.id <= 0 ||
|
|
211
|
+
chart.id > 2048 ||
|
|
212
|
+
identifiers.has(chart.id))
|
|
213
|
+
errors.push(`Invalid chart ID ${chart.id}`);
|
|
214
|
+
identifiers.add(chart.id);
|
|
215
|
+
if (![x, y, width, height].every(Number.isInteger) ||
|
|
216
|
+
x < 0 ||
|
|
217
|
+
y < 0 ||
|
|
218
|
+
width <= 0 ||
|
|
219
|
+
height <= 0 ||
|
|
220
|
+
x + width > atlas.width ||
|
|
221
|
+
y + height > atlas.height) {
|
|
222
|
+
errors.push(`Chart ${chart.id} is outside the atlas`);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
let overlaps = false;
|
|
226
|
+
let ownershipMismatch = false;
|
|
227
|
+
for (let row = y; row < y + height; row++)
|
|
228
|
+
for (let column = x; column < x + width; column++) {
|
|
229
|
+
const pixel = row * atlas.width + column;
|
|
230
|
+
overlaps ||= Boolean(occupied[pixel]);
|
|
231
|
+
occupied[pixel] = 1;
|
|
232
|
+
ownershipMismatch ||= atlas.chartOwners[pixel] !== chart.id;
|
|
233
|
+
}
|
|
234
|
+
if (overlaps)
|
|
235
|
+
errors.push(`Chart ${chart.id} overlaps another chart`);
|
|
236
|
+
if (ownershipMismatch)
|
|
237
|
+
errors.push(`Chart ${chart.id} has inconsistent gutter ownership`);
|
|
238
|
+
const mesh = atlas.meshes.find(candidate => candidate.id === chart.meshId);
|
|
239
|
+
const coordinates = mesh?.geometry.attributes[`TEXCOORD_${atlas.uvSet}`]?.value;
|
|
240
|
+
if (!coordinates ||
|
|
241
|
+
!Number.isInteger(chart.firstVertex) ||
|
|
242
|
+
!Number.isInteger(chart.vertexCount) ||
|
|
243
|
+
chart.vertexCount <= 0 ||
|
|
244
|
+
chart.firstVertex < 0 ||
|
|
245
|
+
chart.firstVertex + chart.vertexCount > coordinates.length / 2) {
|
|
246
|
+
errors.push(`Chart ${chart.id} has an invalid draw range`);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
for (let vertex = chart.firstVertex; vertex < chart.firstVertex + chart.vertexCount; vertex++) {
|
|
250
|
+
const horizontal = coordinates[vertex * 2] * atlas.width;
|
|
251
|
+
const vertical = coordinates[vertex * 2 + 1] * atlas.height;
|
|
252
|
+
if (!Number.isFinite(horizontal) ||
|
|
253
|
+
!Number.isFinite(vertical) ||
|
|
254
|
+
horizontal < x + atlas.padding ||
|
|
255
|
+
horizontal > x + width - atlas.padding ||
|
|
256
|
+
vertical < y + atlas.padding ||
|
|
257
|
+
vertical > y + height - atlas.padding) {
|
|
258
|
+
errors.push(`Chart ${chart.id} has UVs outside its padded rectangle`);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (atlas.chartOwners.some((owner, pixel) => !occupied[pixel] && owner !== 0))
|
|
264
|
+
errors.push('Unallocated pixels have chart owners');
|
|
265
|
+
return errors;
|
|
266
|
+
}
|
|
267
|
+
/** Independent RGBA8 chart-ownership preview. Unallocated pixels are opaque black. */
|
|
268
|
+
export function getLightmapAtlasDebugData(atlas) {
|
|
269
|
+
const pixels = new Uint8ClampedArray(atlas.width * atlas.height * 4);
|
|
270
|
+
for (let pixel = 0; pixel < atlas.chartOwners.length; pixel++) {
|
|
271
|
+
const identifier = atlas.chartOwners[pixel];
|
|
272
|
+
pixels[pixel * 4] = identifier ? 64 + ((identifier * 67) % 192) : 0;
|
|
273
|
+
pixels[pixel * 4 + 1] = identifier ? 64 + ((identifier * 103) % 192) : 0;
|
|
274
|
+
pixels[pixel * 4 + 2] = identifier ? 64 + ((identifier * 137) % 192) : 0;
|
|
275
|
+
pixels[pixel * 4 + 3] = 255;
|
|
276
|
+
}
|
|
277
|
+
return pixels;
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=lightmap-atlas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightmap-atlas.js","sourceRoot":"","sources":["../../src/lighting/lightmap-atlas.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAC,QAAQ,EAAyB,gCAA6B;AAqCtE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAqC,EACrC,OAA6B;IAE7B,MAAM,EAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAC,GAAG,OAAO,CAAC;IACvE,gGAAgG;IAChG,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;IAC/F,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,aAAa,GAAG,CAAC,CAAC,CAAC;IAC5D,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,IAAI,OAAO,IAAI,EAAE,CAAC,CAAC;IACnE,MAAM,CAAC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