@haiyue/animation-spec 0.1.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/LICENSE +21 -0
- package/README.md +190 -0
- package/SPECIFICATION.md +108 -0
- package/bin/hya-convert.mjs +31 -0
- package/dist/binary.d.ts +7 -0
- package/dist/chunks/types-l6nBVYwx.js +8 -0
- package/dist/chunks/types-l6nBVYwx.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/extensions.d.ts +19 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +2927 -0
- package/dist/index.js.map +1 -0
- package/dist/lottie-merge-path.d.ts +11 -0
- package/dist/lottie.d.ts +62 -0
- package/dist/lottie.js +2642 -0
- package/dist/lottie.js.map +1 -0
- package/dist/native3d/Animation3DError.d.ts +8 -0
- package/dist/native3d/Animation3DParser.d.ts +7 -0
- package/dist/native3d/Animation3DTypes.d.ts +285 -0
- package/dist/native3d/index.d.ts +5 -0
- package/dist/native3d.d.ts +2 -0
- package/dist/native3d.js +907 -0
- package/dist/native3d.js.map +1 -0
- package/dist/parser.d.ts +2 -0
- package/dist/state-machine.d.ts +130 -0
- package/dist/text-selector.d.ts +2 -0
- package/dist/types.d.ts +419 -0
- package/dist/validation.d.ts +32 -0
- package/package.json +69 -0
- package/schema/animation-3d-carrier.schema.json +73 -0
- package/schema/animation-3d-extension.schema.json +573 -0
- package/schema/animation-3d.contract.json +130 -0
- package/schema/animation.schema.json +611 -0
- package/schema/fixtures/native-3d-mixed-invalid.hya.json +50 -0
- package/schema/fixtures/native-3d-valid.hya.json +284 -0
- package/src/binary.ts +1441 -0
- package/src/errors.ts +18 -0
- package/src/extensions.ts +55 -0
- package/src/index.ts +90 -0
- package/src/lottie-merge-path.ts +204 -0
- package/src/lottie.ts +3073 -0
- package/src/native3d/Animation3DError.ts +20 -0
- package/src/native3d/Animation3DParser.ts +964 -0
- package/src/native3d/Animation3DTypes.ts +322 -0
- package/src/native3d/index.ts +14 -0
- package/src/native3d.ts +2 -0
- package/src/parser.ts +41 -0
- package/src/state-machine.ts +645 -0
- package/src/text-selector.ts +7 -0
- package/src/types.ts +483 -0
- package/src/validation.ts +1286 -0
- package/test/fixtures/basic-lottie.json +31 -0
package/dist/native3d.js
ADDED
|
@@ -0,0 +1,907 @@
|
|
|
1
|
+
import { AnimationExtensionRegistry, parseAnimation } from './index.js';
|
|
2
|
+
import './chunks/types-l6nBVYwx.js';
|
|
3
|
+
|
|
4
|
+
const NATIVE_3D_ANIMATION_EXTENSION_ID = 'org.haiyue.animation-3d@1';
|
|
5
|
+
const NATIVE_3D_ANIMATION_FORMAT = 'haiyue-animation-3d@1';
|
|
6
|
+
const NATIVE_3D_CLIP_FORMAT = 'haiyue-animation3d-clip@1';
|
|
7
|
+
const NATIVE_3D_STATE_MACHINE_FORMAT = 'haiyue-animation3d-state-machine@1';
|
|
8
|
+
|
|
9
|
+
/** Stable native-3D extension diagnostic. */
|
|
10
|
+
class Native3DAnimationFormatError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
path;
|
|
13
|
+
name = 'Native3DAnimationFormatError';
|
|
14
|
+
constructor(code, message, path) {
|
|
15
|
+
super(`${message} (${path})`);
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.path = path;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const EXTENSION_PATH = `$.extensions.${NATIVE_3D_ANIMATION_EXTENSION_ID}`;
|
|
22
|
+
const MODEL_MIME_TYPES = new Set(['model/gltf-binary', 'model/gltf+json']);
|
|
23
|
+
const FORBIDDEN_URI_SCHEMES = new Set(['blob', 'file', 'javascript']);
|
|
24
|
+
const DEFAULT_LIMITS = Object.freeze({
|
|
25
|
+
maxMaterials: 10_000,
|
|
26
|
+
maxNodes: 100_000,
|
|
27
|
+
maxComponents: 200_000,
|
|
28
|
+
maxClips: 10_000,
|
|
29
|
+
maxTracks: 200_000,
|
|
30
|
+
maxKeyframes: 5_000_000,
|
|
31
|
+
maxParticleCapacity: 2_000_000,
|
|
32
|
+
maxStateMachineDepth: 64,
|
|
33
|
+
});
|
|
34
|
+
function createNative3DAnimationExtensionHandler(options = {}, onValidated) {
|
|
35
|
+
return Object.freeze({
|
|
36
|
+
id: NATIVE_3D_ANIMATION_EXTENSION_ID,
|
|
37
|
+
validateDocument(value) {
|
|
38
|
+
onValidated?.(parseNative3DAnimationPayload(value, options));
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Parses the required 3D extension and rejects mixed 2D/3D carriers. */
|
|
43
|
+
function parseNative3DAnimation(source, options = {}) {
|
|
44
|
+
const extensions = new AnimationExtensionRegistry();
|
|
45
|
+
let payload;
|
|
46
|
+
extensions.register(createNative3DAnimationExtensionHandler(options, value => { payload = value; }));
|
|
47
|
+
const coreOptions = {
|
|
48
|
+
...pickCoreLimits(options),
|
|
49
|
+
extensions,
|
|
50
|
+
...(options.copyFloatData === undefined ? {} : { copyFloatData: options.copyFloatData }),
|
|
51
|
+
};
|
|
52
|
+
const document = parseAnimation(source, coreOptions);
|
|
53
|
+
if (!payload) {
|
|
54
|
+
throw new Native3DAnimationFormatError('E_ANIMATION_3D_INVALID_PAYLOAD', `Required extension "${NATIVE_3D_ANIMATION_EXTENSION_ID}" has no document payload.`, EXTENSION_PATH);
|
|
55
|
+
}
|
|
56
|
+
validateCarrier(document, payload);
|
|
57
|
+
validateResourceReferences(document.resources, payload);
|
|
58
|
+
return Object.freeze({ document, payload, resources: document.resources });
|
|
59
|
+
}
|
|
60
|
+
/** Validates and canonicalizes the extension before any runtime allocation. */
|
|
61
|
+
function parseNative3DAnimationPayload(value, options = {}) {
|
|
62
|
+
const limits = resolveLimits(options);
|
|
63
|
+
const root = object(value, EXTENSION_PATH, [
|
|
64
|
+
'format', 'mode', 'coordinateSystem', 'viewport', 'materials', 'nodes', 'clips',
|
|
65
|
+
], ['format', 'mode', 'coordinateSystem', 'viewport', 'materials', 'nodes', 'clips', 'stateMachine']);
|
|
66
|
+
exact(root.format, NATIVE_3D_ANIMATION_FORMAT, `${EXTENSION_PATH}.format`);
|
|
67
|
+
exact(root.mode, 'native-3d', `${EXTENSION_PATH}.mode`);
|
|
68
|
+
const coordinateSystem = parseCoordinateSystem(root.coordinateSystem, `${EXTENSION_PATH}.coordinateSystem`);
|
|
69
|
+
const viewport = parseViewport(root.viewport, `${EXTENSION_PATH}.viewport`);
|
|
70
|
+
const materialValues = array(root.materials, `${EXTENSION_PATH}.materials`);
|
|
71
|
+
budget(materialValues.length, limits.maxMaterials, 'materials', `${EXTENSION_PATH}.materials`);
|
|
72
|
+
const materialIds = new Set();
|
|
73
|
+
const materials = materialValues.map((entry, index) => {
|
|
74
|
+
const material = parseMaterial(entry, `${EXTENSION_PATH}.materials[${index}]`);
|
|
75
|
+
unique(materialIds, material.id, `${EXTENSION_PATH}.materials[${index}].id`, 'material');
|
|
76
|
+
return material;
|
|
77
|
+
});
|
|
78
|
+
const nodeValues = array(root.nodes, `${EXTENSION_PATH}.nodes`);
|
|
79
|
+
budget(nodeValues.length, limits.maxNodes, 'nodes', `${EXTENSION_PATH}.nodes`);
|
|
80
|
+
const nodeIds = new Set();
|
|
81
|
+
const componentIds = new Set();
|
|
82
|
+
let componentCount = 0;
|
|
83
|
+
let particleCapacity = 0;
|
|
84
|
+
const nodes = nodeValues.map((entry, index) => {
|
|
85
|
+
const path = `${EXTENSION_PATH}.nodes[${index}]`;
|
|
86
|
+
const node = parseNode(entry, path);
|
|
87
|
+
unique(nodeIds, node.id, `${path}.id`, 'node');
|
|
88
|
+
for (let componentIndex = 0; componentIndex < node.components.length; componentIndex++) {
|
|
89
|
+
const component = node.components[componentIndex];
|
|
90
|
+
unique(componentIds, component.id, `${path}.components[${componentIndex}].id`, 'component');
|
|
91
|
+
componentCount++;
|
|
92
|
+
if (component.kind === 'particle3d')
|
|
93
|
+
particleCapacity += component.descriptor.maxParticles;
|
|
94
|
+
}
|
|
95
|
+
budget(componentCount, limits.maxComponents, 'components', `${path}.components`);
|
|
96
|
+
budget(particleCapacity, limits.maxParticleCapacity, 'particle capacity', `${path}.components`);
|
|
97
|
+
return node;
|
|
98
|
+
});
|
|
99
|
+
validateNodeSemantics(nodes, nodeIds, materialIds);
|
|
100
|
+
const clipValues = array(root.clips, `${EXTENSION_PATH}.clips`);
|
|
101
|
+
budget(clipValues.length, limits.maxClips, 'clips', `${EXTENSION_PATH}.clips`);
|
|
102
|
+
const clipIds = new Set();
|
|
103
|
+
const bindingIds = new Set();
|
|
104
|
+
let trackCount = 0;
|
|
105
|
+
let keyframeCount = 0;
|
|
106
|
+
const clips = clipValues.map((entry, index) => {
|
|
107
|
+
const path = `${EXTENSION_PATH}.clips[${index}]`;
|
|
108
|
+
const clip = parseClip(entry, path);
|
|
109
|
+
unique(clipIds, clip.id, `${path}.id`, 'clip');
|
|
110
|
+
trackCount += clip.tracks.length;
|
|
111
|
+
keyframeCount += clip.tracks.reduce((sum, track) => sum + track.times.length, 0);
|
|
112
|
+
budget(trackCount, limits.maxTracks, 'tracks', `${path}.tracks`);
|
|
113
|
+
budget(keyframeCount, limits.maxKeyframes, 'keyframes', `${path}.tracks`);
|
|
114
|
+
const clipBindingIds = new Set();
|
|
115
|
+
for (let trackIndex = 0; trackIndex < clip.tracks.length; trackIndex++) {
|
|
116
|
+
const track = clip.tracks[trackIndex];
|
|
117
|
+
unique(clipBindingIds, track.binding.id, `${path}.tracks[${trackIndex}].binding.id`, 'binding');
|
|
118
|
+
bindingIds.add(track.binding.id);
|
|
119
|
+
validateBindingTarget(track.binding, nodes, materialIds, `${path}.tracks[${trackIndex}].binding`);
|
|
120
|
+
}
|
|
121
|
+
return clip;
|
|
122
|
+
});
|
|
123
|
+
const stateMachine = root.stateMachine === undefined || root.stateMachine === null
|
|
124
|
+
? root.stateMachine
|
|
125
|
+
: parseStateMachine(root.stateMachine, `${EXTENSION_PATH}.stateMachine`, limits.maxStateMachineDepth);
|
|
126
|
+
if (stateMachine)
|
|
127
|
+
validateStateMachineReferences(stateMachine, clipIds, bindingIds, `${EXTENSION_PATH}.stateMachine`);
|
|
128
|
+
return deepFreeze({
|
|
129
|
+
format: NATIVE_3D_ANIMATION_FORMAT,
|
|
130
|
+
mode: 'native-3d',
|
|
131
|
+
coordinateSystem,
|
|
132
|
+
viewport,
|
|
133
|
+
materials,
|
|
134
|
+
nodes,
|
|
135
|
+
clips,
|
|
136
|
+
...(root.stateMachine === undefined ? {} : { stateMachine: stateMachine ?? null }),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function parseCoordinateSystem(value, path) {
|
|
140
|
+
const item = object(value, path, ['handedness', 'upAxis', 'forwardAxis', 'unit', 'angles', 'rotationStorage'], ['handedness', 'upAxis', 'forwardAxis', 'unit', 'angles', 'rotationStorage']);
|
|
141
|
+
exact(item.handedness, 'right', `${path}.handedness`);
|
|
142
|
+
exact(item.upAxis, '+y', `${path}.upAxis`);
|
|
143
|
+
exact(item.forwardAxis, '-z', `${path}.forwardAxis`);
|
|
144
|
+
exact(item.unit, 'meter', `${path}.unit`);
|
|
145
|
+
exact(item.angles, 'radian', `${path}.angles`);
|
|
146
|
+
exact(item.rotationStorage, 'normalized-xyzw-quaternion', `${path}.rotationStorage`);
|
|
147
|
+
return Object.freeze({
|
|
148
|
+
handedness: 'right', upAxis: '+y', forwardAxis: '-z', unit: 'meter', angles: 'radian',
|
|
149
|
+
rotationStorage: 'normalized-xyzw-quaternion',
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function parseViewport(value, path) {
|
|
153
|
+
const item = object(value, path, ['width', 'height'], ['width', 'height']);
|
|
154
|
+
return Object.freeze({ width: positive(item.width, `${path}.width`), height: positive(item.height, `${path}.height`) });
|
|
155
|
+
}
|
|
156
|
+
function parseMaterial(value, path) {
|
|
157
|
+
const item = object(value, path, ['id', 'name', 'baseColorFactor', 'metallicFactor', 'roughnessFactor', 'emissiveFactor', 'alphaMode', 'doubleSided'], ['id', 'name', 'baseColorFactor', 'metallicFactor', 'roughnessFactor', 'emissiveFactor', 'alphaMode', 'alphaCutoff', 'doubleSided', 'baseColorTexture', 'normalTexture', 'metallicRoughnessTexture', 'emissiveTexture']);
|
|
158
|
+
return Object.freeze({
|
|
159
|
+
id: nonEmpty(item.id, `${path}.id`),
|
|
160
|
+
name: string(item.name, `${path}.name`),
|
|
161
|
+
baseColorFactor: vec4(item.baseColorFactor, `${path}.baseColorFactor`, 0, 1),
|
|
162
|
+
metallicFactor: bounded(item.metallicFactor, `${path}.metallicFactor`, 0, 1),
|
|
163
|
+
roughnessFactor: bounded(item.roughnessFactor, `${path}.roughnessFactor`, 0, 1),
|
|
164
|
+
emissiveFactor: vec3(item.emissiveFactor, `${path}.emissiveFactor`, 0),
|
|
165
|
+
alphaMode: enumeration(item.alphaMode, ['opaque', 'mask', 'blend'], `${path}.alphaMode`),
|
|
166
|
+
...(item.alphaCutoff === undefined ? {} : { alphaCutoff: bounded(item.alphaCutoff, `${path}.alphaCutoff`, 0, 1) }),
|
|
167
|
+
doubleSided: boolean(item.doubleSided, `${path}.doubleSided`),
|
|
168
|
+
...optionalStrings(item, path, ['baseColorTexture', 'normalTexture', 'metallicRoughnessTexture', 'emissiveTexture']),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function parseNode(value, path) {
|
|
172
|
+
const item = object(value, path, ['id', 'name', 'transform', 'components'], ['id', 'name', 'parent', 'start', 'duration', 'transform', 'components']);
|
|
173
|
+
const components = array(item.components, `${path}.components`).map((entry, index) => (parseComponent(entry, `${path}.components[${index}]`)));
|
|
174
|
+
return Object.freeze({
|
|
175
|
+
id: nonEmpty(item.id, `${path}.id`),
|
|
176
|
+
name: string(item.name, `${path}.name`),
|
|
177
|
+
...(item.parent === undefined ? {} : { parent: nonEmpty(item.parent, `${path}.parent`) }),
|
|
178
|
+
...(item.start === undefined ? {} : { start: nonNegative(item.start, `${path}.start`) }),
|
|
179
|
+
...(item.duration === undefined ? {} : { duration: positive(item.duration, `${path}.duration`) }),
|
|
180
|
+
transform: parseTransform(item.transform, `${path}.transform`),
|
|
181
|
+
components: Object.freeze(components),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function parseTransform(value, path) {
|
|
185
|
+
const item = object(value, path, ['translation', 'rotation', 'scale'], ['translation', 'rotation', 'scale']);
|
|
186
|
+
const rotation = vec4(item.rotation, `${path}.rotation`);
|
|
187
|
+
assertNormalizedQuaternion(rotation, `${path}.rotation`);
|
|
188
|
+
return Object.freeze({
|
|
189
|
+
translation: vec3(item.translation, `${path}.translation`),
|
|
190
|
+
rotation,
|
|
191
|
+
scale: vec3(item.scale, `${path}.scale`),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function parseComponent(value, path) {
|
|
195
|
+
const kind = object(value, path).kind;
|
|
196
|
+
if (kind === 'camera3d') {
|
|
197
|
+
const item = object(value, path, ['id', 'kind', 'projection'], ['id', 'kind', 'projection']);
|
|
198
|
+
return Object.freeze({ id: nonEmpty(item.id, `${path}.id`), kind, projection: parseCamera(item.projection, `${path}.projection`) });
|
|
199
|
+
}
|
|
200
|
+
if (kind === 'primitive3d') {
|
|
201
|
+
const item = object(value, path, ['id', 'kind', 'primitive', 'materialId'], ['id', 'kind', 'primitive', 'materialId']);
|
|
202
|
+
return Object.freeze({
|
|
203
|
+
id: nonEmpty(item.id, `${path}.id`), kind,
|
|
204
|
+
primitive: enumeration(item.primitive, ['box', 'sphere', 'plane', 'cylinder', 'cone'], `${path}.primitive`),
|
|
205
|
+
materialId: nonEmpty(item.materialId, `${path}.materialId`),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (kind === 'model3d') {
|
|
209
|
+
const item = object(value, path, ['id', 'kind', 'resource'], ['id', 'kind', 'resource', 'materialOverrides']);
|
|
210
|
+
const materialOverrides = item.materialOverrides === undefined ? undefined : array(item.materialOverrides, `${path}.materialOverrides`).map((entry, index) => {
|
|
211
|
+
const overridePath = `${path}.materialOverrides[${index}]`;
|
|
212
|
+
const override = object(entry, overridePath, ['slot', 'materialId'], ['slot', 'materialId']);
|
|
213
|
+
return Object.freeze({ slot: nonEmpty(override.slot, `${overridePath}.slot`), materialId: nonEmpty(override.materialId, `${overridePath}.materialId`) });
|
|
214
|
+
});
|
|
215
|
+
return Object.freeze({
|
|
216
|
+
id: nonEmpty(item.id, `${path}.id`), kind, resource: nonEmpty(item.resource, `${path}.resource`),
|
|
217
|
+
...(materialOverrides ? { materialOverrides: Object.freeze(materialOverrides) } : {}),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (kind === 'particle3d') {
|
|
221
|
+
const item = object(value, path, ['id', 'kind', 'descriptor'], ['id', 'kind', 'descriptor']);
|
|
222
|
+
return Object.freeze({
|
|
223
|
+
id: nonEmpty(item.id, `${path}.id`), kind,
|
|
224
|
+
descriptor: parseParticle(item.descriptor, `${path}.descriptor`),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
invalid(`Unsupported component kind "${String(kind)}".`, `${path}.kind`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
|
|
228
|
+
}
|
|
229
|
+
function parseCamera(value, path) {
|
|
230
|
+
const kind = object(value, path).kind;
|
|
231
|
+
if (kind === 'perspective') {
|
|
232
|
+
const item = object(value, path, ['kind', 'fovYRadians', 'near', 'far'], ['kind', 'fovYRadians', 'near', 'far']);
|
|
233
|
+
const near = positive(item.near, `${path}.near`);
|
|
234
|
+
const far = positive(item.far, `${path}.far`);
|
|
235
|
+
if (far <= near)
|
|
236
|
+
invalid('Camera far must be greater than near.', `${path}.far`);
|
|
237
|
+
return Object.freeze({
|
|
238
|
+
kind, fovYRadians: bounded(item.fovYRadians, `${path}.fovYRadians`, Number.MIN_VALUE, Math.PI, false), near, far,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
if (kind === 'orthographic') {
|
|
242
|
+
const item = object(value, path, ['kind', 'orthoHeight', 'near', 'far'], ['kind', 'orthoHeight', 'near', 'far']);
|
|
243
|
+
const near = nonNegative(item.near, `${path}.near`);
|
|
244
|
+
const far = positive(item.far, `${path}.far`);
|
|
245
|
+
if (far <= near)
|
|
246
|
+
invalid('Camera far must be greater than near.', `${path}.far`);
|
|
247
|
+
return Object.freeze({ kind, orthoHeight: positive(item.orthoHeight, `${path}.orthoHeight`), near, far });
|
|
248
|
+
}
|
|
249
|
+
invalid(`Unsupported camera projection "${String(kind)}".`, `${path}.kind`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
|
|
250
|
+
}
|
|
251
|
+
function parseParticle(value, path) {
|
|
252
|
+
const required = ['maxParticles', 'emissionRate', 'burst', 'duration', 'loop', 'seed', 'lifetime', 'speed', 'direction', 'spread', 'gravity', 'startSize', 'endSize', 'rotation', 'angularVelocity', 'startColor', 'endColor', 'shape', 'blendMode', 'radial', 'opacity', 'depthTest', 'depthWrite', 'sortMode'];
|
|
253
|
+
const item = object(value, path, required, [...required, 'shapeSize', 'shapeRadius', 'textureResource']);
|
|
254
|
+
return Object.freeze({
|
|
255
|
+
maxParticles: integer(item.maxParticles, `${path}.maxParticles`, 1, 1_000_000),
|
|
256
|
+
emissionRate: nonNegative(item.emissionRate, `${path}.emissionRate`),
|
|
257
|
+
burst: integer(item.burst, `${path}.burst`, 0, 1_000_000),
|
|
258
|
+
duration: positive(item.duration, `${path}.duration`),
|
|
259
|
+
loop: boolean(item.loop, `${path}.loop`),
|
|
260
|
+
seed: integer(item.seed, `${path}.seed`, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER),
|
|
261
|
+
lifetime: range(item.lifetime, `${path}.lifetime`, 0),
|
|
262
|
+
speed: range(item.speed, `${path}.speed`),
|
|
263
|
+
direction: vec3(item.direction, `${path}.direction`),
|
|
264
|
+
spread: bounded(item.spread, `${path}.spread`, 0, Math.PI),
|
|
265
|
+
gravity: vec3(item.gravity, `${path}.gravity`),
|
|
266
|
+
startSize: range(item.startSize, `${path}.startSize`, 0),
|
|
267
|
+
endSize: range(item.endSize, `${path}.endSize`, 0),
|
|
268
|
+
rotation: range(item.rotation, `${path}.rotation`),
|
|
269
|
+
angularVelocity: range(item.angularVelocity, `${path}.angularVelocity`),
|
|
270
|
+
startColor: vec4(item.startColor, `${path}.startColor`, 0, 1),
|
|
271
|
+
endColor: vec4(item.endColor, `${path}.endColor`, 0, 1),
|
|
272
|
+
shape: enumeration(item.shape, ['point', 'box', 'sphere'], `${path}.shape`),
|
|
273
|
+
...(item.shapeSize === undefined ? {} : { shapeSize: vec3(item.shapeSize, `${path}.shapeSize`, 0) }),
|
|
274
|
+
...(item.shapeRadius === undefined ? {} : { shapeRadius: nonNegative(item.shapeRadius, `${path}.shapeRadius`) }),
|
|
275
|
+
blendMode: enumeration(item.blendMode, ['normal', 'additive'], `${path}.blendMode`),
|
|
276
|
+
...(item.textureResource === undefined ? {} : { textureResource: nonEmpty(item.textureResource, `${path}.textureResource`) }),
|
|
277
|
+
radial: boolean(item.radial, `${path}.radial`),
|
|
278
|
+
opacity: bounded(item.opacity, `${path}.opacity`, 0, 1),
|
|
279
|
+
depthTest: boolean(item.depthTest, `${path}.depthTest`),
|
|
280
|
+
depthWrite: boolean(item.depthWrite, `${path}.depthWrite`),
|
|
281
|
+
sortMode: enumeration(item.sortMode, ['none', 'back-to-front'], `${path}.sortMode`),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
function parseClip(value, path) {
|
|
285
|
+
const item = object(value, path, ['format', 'id', 'name', 'duration', 'tracks', 'events'], ['format', 'id', 'name', 'duration', 'tracks', 'events']);
|
|
286
|
+
exact(item.format, NATIVE_3D_CLIP_FORMAT, `${path}.format`);
|
|
287
|
+
const duration = positive(item.duration, `${path}.duration`);
|
|
288
|
+
const trackIds = new Set();
|
|
289
|
+
const tracks = array(item.tracks, `${path}.tracks`).map((entry, index) => {
|
|
290
|
+
const trackPath = `${path}.tracks[${index}]`;
|
|
291
|
+
const track = parseTrack(entry, trackPath, duration);
|
|
292
|
+
unique(trackIds, track.id, `${trackPath}.id`, 'track');
|
|
293
|
+
return track;
|
|
294
|
+
});
|
|
295
|
+
const eventIds = new Set();
|
|
296
|
+
const events = array(item.events, `${path}.events`).map((entry, index) => {
|
|
297
|
+
const eventPath = `${path}.events[${index}]`;
|
|
298
|
+
const event = parseEvent(entry, eventPath, duration);
|
|
299
|
+
unique(eventIds, event.id, `${eventPath}.id`, 'event');
|
|
300
|
+
return event;
|
|
301
|
+
});
|
|
302
|
+
return Object.freeze({
|
|
303
|
+
format: NATIVE_3D_CLIP_FORMAT,
|
|
304
|
+
id: nonEmpty(item.id, `${path}.id`),
|
|
305
|
+
name: string(item.name, `${path}.name`),
|
|
306
|
+
duration,
|
|
307
|
+
tracks: Object.freeze(tracks),
|
|
308
|
+
events: Object.freeze(events),
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
function parseTrack(value, path, duration) {
|
|
312
|
+
const item = object(value, path, ['id', 'binding', 'interpolation', 'times', 'values'], ['id', 'binding', 'interpolation', 'times', 'values']);
|
|
313
|
+
const binding = parseBinding(item.binding, `${path}.binding`);
|
|
314
|
+
const interpolation = enumeration(item.interpolation, ['step', 'linear', 'cubic-spline'], `${path}.interpolation`);
|
|
315
|
+
const times = numericArray(item.times, `${path}.times`, 1);
|
|
316
|
+
for (let index = 0; index < times.length; index++) {
|
|
317
|
+
const time = times[index];
|
|
318
|
+
if (time < 0 || time > duration)
|
|
319
|
+
invalid('Track time must lie within clip duration.', `${path}.times[${index}]`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
320
|
+
if (index > 0 && time <= times[index - 1])
|
|
321
|
+
invalid('Track times must be strictly increasing.', `${path}.times[${index}]`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
322
|
+
}
|
|
323
|
+
const values = numericArray(item.values, `${path}.values`, 1);
|
|
324
|
+
const expected = times.length * binding.valueSize * (interpolation === 'cubic-spline' ? 3 : 1);
|
|
325
|
+
if (values.length !== expected) {
|
|
326
|
+
invalid(`Track values length ${values.length} does not match expected ${expected}.`, `${path}.values`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
327
|
+
}
|
|
328
|
+
if (binding.path === 'transform.rotation')
|
|
329
|
+
validateTrackQuaternions(values, times.length, interpolation, `${path}.values`);
|
|
330
|
+
return Object.freeze({ id: nonEmpty(item.id, `${path}.id`), binding, interpolation, times, values });
|
|
331
|
+
}
|
|
332
|
+
function parseBinding(value, path) {
|
|
333
|
+
const base = object(value, path);
|
|
334
|
+
const target = parseBindingTarget(base.target, `${path}.target`);
|
|
335
|
+
const id = nonEmpty(base.id, `${path}.id`);
|
|
336
|
+
if (base.path === 'transform.translation' || base.path === 'transform.scale') {
|
|
337
|
+
const item = object(value, path, ['id', 'target', 'path', 'valueType', 'valueSize'], ['id', 'target', 'path', 'valueType', 'valueSize']);
|
|
338
|
+
exact(item.valueType, 'vec3', `${path}.valueType`);
|
|
339
|
+
exact(item.valueSize, 3, `${path}.valueSize`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
340
|
+
return Object.freeze({ id, target, path: base.path, valueType: 'vec3', valueSize: 3 });
|
|
341
|
+
}
|
|
342
|
+
if (base.path === 'transform.rotation') {
|
|
343
|
+
const item = object(value, path, ['id', 'target', 'path', 'valueType', 'valueSize'], ['id', 'target', 'path', 'valueType', 'valueSize']);
|
|
344
|
+
exact(item.valueType, 'quaternion', `${path}.valueType`);
|
|
345
|
+
exact(item.valueSize, 4, `${path}.valueSize`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
346
|
+
return Object.freeze({ id, target, path: base.path, valueType: 'quaternion', valueSize: 4 });
|
|
347
|
+
}
|
|
348
|
+
if (base.path === 'morph.weights') {
|
|
349
|
+
const item = object(value, path, ['id', 'target', 'path', 'valueType', 'valueSize'], ['id', 'target', 'path', 'valueType', 'valueSize']);
|
|
350
|
+
exact(item.valueType, 'weights', `${path}.valueType`);
|
|
351
|
+
return Object.freeze({ id, target, path: base.path, valueType: 'weights', valueSize: integer(item.valueSize, `${path}.valueSize`, 1, 65_536) });
|
|
352
|
+
}
|
|
353
|
+
if (base.path === 'property') {
|
|
354
|
+
const item = object(value, path, ['id', 'target', 'path', 'component', 'property', 'valueType', 'valueSize'], ['id', 'target', 'path', 'component', 'property', 'valueType', 'valueSize']);
|
|
355
|
+
const component = enumeration(item.component, ['material3d', 'camera3d'], `${path}.component`);
|
|
356
|
+
const property = enumeration(item.property, ['baseColorFactor', 'metallicFactor', 'roughnessFactor', 'emissiveFactor', 'alphaCutoff', 'fovYRadians', 'near', 'far', 'orthoHeight'], `${path}.property`);
|
|
357
|
+
const contract = propertyContract(component, property, `${path}.property`);
|
|
358
|
+
exact(item.valueType, contract.valueType, `${path}.valueType`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
359
|
+
exact(item.valueSize, contract.valueSize, `${path}.valueSize`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
360
|
+
return Object.freeze({ id, target, path: 'property', component, property, ...contract });
|
|
361
|
+
}
|
|
362
|
+
invalid(`Unsupported binding path "${String(base.path)}".`, `${path}.path`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
|
|
363
|
+
}
|
|
364
|
+
function parseBindingTarget(value, path) {
|
|
365
|
+
const kind = object(value, path).kind;
|
|
366
|
+
if (kind === 'node-id') {
|
|
367
|
+
const item = object(value, path, ['kind', 'nodeId'], ['kind', 'nodeId']);
|
|
368
|
+
return Object.freeze({ kind, nodeId: nonEmpty(item.nodeId, `${path}.nodeId`) });
|
|
369
|
+
}
|
|
370
|
+
if (kind === 'node-path') {
|
|
371
|
+
const item = object(value, path, ['kind', 'segments'], ['kind', 'segments']);
|
|
372
|
+
const segments = array(item.segments, `${path}.segments`);
|
|
373
|
+
if (segments.length === 0)
|
|
374
|
+
invalid('Node path must contain at least one segment.', `${path}.segments`);
|
|
375
|
+
return Object.freeze({ kind, segments: Object.freeze(segments.map((segment, index) => nonEmpty(segment, `${path}.segments[${index}]`))) });
|
|
376
|
+
}
|
|
377
|
+
if (kind === 'slot') {
|
|
378
|
+
const item = object(value, path, ['kind', 'slot'], ['kind', 'slot']);
|
|
379
|
+
return Object.freeze({ kind, slot: nonEmpty(item.slot, `${path}.slot`) });
|
|
380
|
+
}
|
|
381
|
+
invalid(`Unsupported binding target "${String(kind)}".`, `${path}.kind`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
|
|
382
|
+
}
|
|
383
|
+
function parseEvent(value, path, duration) {
|
|
384
|
+
const item = object(value, path, ['id', 'time', 'name'], ['id', 'time', 'name', 'payload']);
|
|
385
|
+
const time = nonNegative(item.time, `${path}.time`);
|
|
386
|
+
if (time > duration)
|
|
387
|
+
invalid('Event time must lie within clip duration.', `${path}.time`);
|
|
388
|
+
return Object.freeze({
|
|
389
|
+
id: nonEmpty(item.id, `${path}.id`), time, name: nonEmpty(item.name, `${path}.name`),
|
|
390
|
+
...(item.payload === undefined ? {} : { payload: parseJsonObject(item.payload, `${path}.payload`) }),
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function parseStateMachine(value, path, maxDepth) {
|
|
394
|
+
const item = object(value, path, ['format', 'id', 'name', 'parameters', 'layers'], ['format', 'id', 'name', 'parameters', 'layers']);
|
|
395
|
+
exact(item.format, NATIVE_3D_STATE_MACHINE_FORMAT, `${path}.format`);
|
|
396
|
+
const parameterNames = new Set();
|
|
397
|
+
const parameters = array(item.parameters, `${path}.parameters`).map((entry, index) => {
|
|
398
|
+
const parameterPath = `${path}.parameters[${index}]`;
|
|
399
|
+
const parameter = parseParameter(entry, parameterPath);
|
|
400
|
+
unique(parameterNames, parameter.name, `${parameterPath}.name`, 'state-machine parameter');
|
|
401
|
+
return parameter;
|
|
402
|
+
});
|
|
403
|
+
const layerIds = new Set();
|
|
404
|
+
const layers = array(item.layers, `${path}.layers`).map((entry, index) => {
|
|
405
|
+
const layerPath = `${path}.layers[${index}]`;
|
|
406
|
+
const layer = parseLayer(entry, layerPath, maxDepth);
|
|
407
|
+
unique(layerIds, layer.id, `${layerPath}.id`, 'state-machine layer');
|
|
408
|
+
return layer;
|
|
409
|
+
});
|
|
410
|
+
return Object.freeze({
|
|
411
|
+
format: NATIVE_3D_STATE_MACHINE_FORMAT,
|
|
412
|
+
id: nonEmpty(item.id, `${path}.id`), name: string(item.name, `${path}.name`),
|
|
413
|
+
parameters: Object.freeze(parameters), layers: Object.freeze(layers),
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function parseParameter(value, path) {
|
|
417
|
+
const base = object(value, path);
|
|
418
|
+
const name = nonEmpty(base.name, `${path}.name`);
|
|
419
|
+
if (base.type === 'trigger') {
|
|
420
|
+
object(value, path, ['name', 'type'], ['name', 'type']);
|
|
421
|
+
return Object.freeze({ name, type: 'trigger' });
|
|
422
|
+
}
|
|
423
|
+
object(value, path, ['name', 'type', 'defaultValue'], ['name', 'type', 'defaultValue']);
|
|
424
|
+
if (base.type === 'float')
|
|
425
|
+
return Object.freeze({ name, type: 'float', defaultValue: finite(base.defaultValue, `${path}.defaultValue`) });
|
|
426
|
+
if (base.type === 'integer')
|
|
427
|
+
return Object.freeze({ name, type: 'integer', defaultValue: integer(base.defaultValue, `${path}.defaultValue`, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER) });
|
|
428
|
+
if (base.type === 'boolean')
|
|
429
|
+
return Object.freeze({ name, type: 'boolean', defaultValue: boolean(base.defaultValue, `${path}.defaultValue`) });
|
|
430
|
+
invalid(`Unsupported parameter type "${String(base.type)}".`, `${path}.type`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
|
|
431
|
+
}
|
|
432
|
+
function parseLayer(value, path, maxDepth) {
|
|
433
|
+
const item = object(value, path, ['id', 'name', 'initialStateId', 'states', 'transitions'], ['id', 'name', 'initialStateId', 'states', 'transitions', 'blendMode', 'weight', 'mask']);
|
|
434
|
+
const stateIds = new Set();
|
|
435
|
+
const states = array(item.states, `${path}.states`).map((entry, index) => {
|
|
436
|
+
const statePath = `${path}.states[${index}]`;
|
|
437
|
+
const state = parseState(entry, statePath, maxDepth);
|
|
438
|
+
unique(stateIds, state.id, `${statePath}.id`, 'state');
|
|
439
|
+
return state;
|
|
440
|
+
});
|
|
441
|
+
const transitionIds = new Set();
|
|
442
|
+
const transitions = array(item.transitions, `${path}.transitions`).map((entry, index) => {
|
|
443
|
+
const transitionPath = `${path}.transitions[${index}]`;
|
|
444
|
+
const transition = parseTransition(entry, transitionPath);
|
|
445
|
+
unique(transitionIds, transition.id, `${transitionPath}.id`, 'transition');
|
|
446
|
+
return transition;
|
|
447
|
+
});
|
|
448
|
+
const mask = item.mask === undefined ? undefined : parseMask(item.mask, `${path}.mask`);
|
|
449
|
+
return Object.freeze({
|
|
450
|
+
id: nonEmpty(item.id, `${path}.id`), name: string(item.name, `${path}.name`),
|
|
451
|
+
initialStateId: nonEmpty(item.initialStateId, `${path}.initialStateId`),
|
|
452
|
+
states: Object.freeze(states), transitions: Object.freeze(transitions),
|
|
453
|
+
...(item.blendMode === undefined ? {} : { blendMode: enumeration(item.blendMode, ['override', 'additive'], `${path}.blendMode`) }),
|
|
454
|
+
...(item.weight === undefined ? {} : { weight: bounded(item.weight, `${path}.weight`, 0, 1) }),
|
|
455
|
+
...(mask ? { mask } : {}),
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
function parseState(value, path, maxDepth) {
|
|
459
|
+
const item = object(value, path, ['id', 'name', 'motion'], ['id', 'name', 'motion', 'speed', 'speedParameter', 'loop']);
|
|
460
|
+
return Object.freeze({
|
|
461
|
+
id: nonEmpty(item.id, `${path}.id`), name: string(item.name, `${path}.name`),
|
|
462
|
+
motion: parseMotion(item.motion, `${path}.motion`, 0, maxDepth),
|
|
463
|
+
...(item.speed === undefined ? {} : { speed: finite(item.speed, `${path}.speed`) }),
|
|
464
|
+
...(item.speedParameter === undefined ? {} : { speedParameter: nonEmpty(item.speedParameter, `${path}.speedParameter`) }),
|
|
465
|
+
...(item.loop === undefined ? {} : { loop: enumeration(item.loop, ['once', 'repeat', 'ping-pong'], `${path}.loop`) }),
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
function parseMotion(value, path, depth, maxDepth) {
|
|
469
|
+
if (depth >= maxDepth)
|
|
470
|
+
budget(depth + 1, maxDepth, 'state-machine motion depth', path);
|
|
471
|
+
const base = object(value, path);
|
|
472
|
+
if (base.kind === 'clip') {
|
|
473
|
+
const item = object(value, path, ['kind', 'clipId'], ['kind', 'clipId']);
|
|
474
|
+
return Object.freeze({ kind: 'clip', clipId: nonEmpty(item.clipId, `${path}.clipId`) });
|
|
475
|
+
}
|
|
476
|
+
if (base.kind === 'blend-1d') {
|
|
477
|
+
const item = object(value, path, ['kind', 'parameter', 'children'], ['kind', 'parameter', 'children']);
|
|
478
|
+
const children = nonEmptyArray(item.children, `${path}.children`).map((entry, index) => {
|
|
479
|
+
const childPath = `${path}.children[${index}]`;
|
|
480
|
+
const child = object(entry, childPath, ['threshold', 'motion'], ['threshold', 'motion']);
|
|
481
|
+
return Object.freeze({ threshold: finite(child.threshold, `${childPath}.threshold`), motion: parseMotion(child.motion, `${childPath}.motion`, depth + 1, maxDepth) });
|
|
482
|
+
});
|
|
483
|
+
return Object.freeze({ kind: 'blend-1d', parameter: nonEmpty(item.parameter, `${path}.parameter`), children: Object.freeze(children) });
|
|
484
|
+
}
|
|
485
|
+
if (base.kind === 'blend-2d') {
|
|
486
|
+
const item = object(value, path, ['kind', 'algorithm', 'parameterX', 'parameterY', 'children'], ['kind', 'algorithm', 'parameterX', 'parameterY', 'children']);
|
|
487
|
+
const children = nonEmptyArray(item.children, `${path}.children`).map((entry, index) => {
|
|
488
|
+
const childPath = `${path}.children[${index}]`;
|
|
489
|
+
const child = object(entry, childPath, ['position', 'motion'], ['position', 'motion']);
|
|
490
|
+
return Object.freeze({ position: vec2(child.position, `${childPath}.position`), motion: parseMotion(child.motion, `${childPath}.motion`, depth + 1, maxDepth) });
|
|
491
|
+
});
|
|
492
|
+
return Object.freeze({
|
|
493
|
+
kind: 'blend-2d', algorithm: enumeration(item.algorithm, ['cartesian', 'directional'], `${path}.algorithm`),
|
|
494
|
+
parameterX: nonEmpty(item.parameterX, `${path}.parameterX`), parameterY: nonEmpty(item.parameterY, `${path}.parameterY`),
|
|
495
|
+
children: Object.freeze(children),
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
invalid(`Unsupported motion kind "${String(base.kind)}".`, `${path}.kind`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
|
|
499
|
+
}
|
|
500
|
+
function parseTransition(value, path) {
|
|
501
|
+
const item = object(value, path, ['id', 'from', 'to', 'conditions', 'duration'], ['id', 'from', 'to', 'conditions', 'duration', 'hasExitTime', 'exitTime', 'destinationOffset', 'interruption']);
|
|
502
|
+
const conditions = array(item.conditions, `${path}.conditions`).map((entry, index) => parseCondition(entry, `${path}.conditions[${index}]`));
|
|
503
|
+
return Object.freeze({
|
|
504
|
+
id: nonEmpty(item.id, `${path}.id`), from: nonEmpty(item.from, `${path}.from`), to: nonEmpty(item.to, `${path}.to`),
|
|
505
|
+
conditions: Object.freeze(conditions), duration: nonNegative(item.duration, `${path}.duration`),
|
|
506
|
+
...(item.hasExitTime === undefined ? {} : { hasExitTime: boolean(item.hasExitTime, `${path}.hasExitTime`) }),
|
|
507
|
+
...(item.exitTime === undefined ? {} : { exitTime: nonNegative(item.exitTime, `${path}.exitTime`) }),
|
|
508
|
+
...(item.destinationOffset === undefined ? {} : { destinationOffset: nonNegative(item.destinationOffset, `${path}.destinationOffset`) }),
|
|
509
|
+
...(item.interruption === undefined ? {} : { interruption: enumeration(item.interruption, ['none', 'source', 'destination', 'source-then-destination', 'destination-then-source'], `${path}.interruption`) }),
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
function parseCondition(value, path) {
|
|
513
|
+
const item = object(value, path, ['parameter', 'operator'], ['parameter', 'operator', 'value']);
|
|
514
|
+
const operator = enumeration(item.operator, ['greater', 'greater-or-equal', 'less', 'less-or-equal', 'equal', 'not-equal', 'is-true', 'is-false', 'triggered'], `${path}.operator`);
|
|
515
|
+
return Object.freeze({
|
|
516
|
+
parameter: nonEmpty(item.parameter, `${path}.parameter`), operator,
|
|
517
|
+
...(item.value === undefined ? {} : { value: typeof item.value === 'boolean' ? item.value : finite(item.value, `${path}.value`) }),
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
function parseMask(value, path) {
|
|
521
|
+
const item = object(value, path, [], ['include', 'exclude']);
|
|
522
|
+
const parseList = (entry, entryPath) => {
|
|
523
|
+
const seen = new Set();
|
|
524
|
+
return Object.freeze(array(entry, entryPath).map((value, index) => {
|
|
525
|
+
const result = nonEmpty(value, `${entryPath}[${index}]`);
|
|
526
|
+
unique(seen, result, `${entryPath}[${index}]`, 'mask binding');
|
|
527
|
+
return result;
|
|
528
|
+
}));
|
|
529
|
+
};
|
|
530
|
+
return Object.freeze({
|
|
531
|
+
...(item.include === undefined ? {} : { include: parseList(item.include, `${path}.include`) }),
|
|
532
|
+
...(item.exclude === undefined ? {} : { exclude: parseList(item.exclude, `${path}.exclude`) }),
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
function validateCarrier(document, payload) {
|
|
536
|
+
if (document.extensionsUsed.length !== 1 || document.extensionsUsed[0] !== NATIVE_3D_ANIMATION_EXTENSION_ID
|
|
537
|
+
|| document.extensionsRequired.length !== 1 || document.extensionsRequired[0] !== NATIVE_3D_ANIMATION_EXTENSION_ID) {
|
|
538
|
+
invalid(`Native 3D carrier must use and require only "${NATIVE_3D_ANIMATION_EXTENSION_ID}".`, '$.extensionsRequired');
|
|
539
|
+
}
|
|
540
|
+
if (document.nodes.length > 0) {
|
|
541
|
+
invalid('Native 3D carrier cannot contain core 2D nodes.', '$.nodes', 'E_ANIMATION_3D_MIXED_DIMENSIONS');
|
|
542
|
+
}
|
|
543
|
+
if (document.tracks.length > 0) {
|
|
544
|
+
invalid('Native 3D carrier cannot contain core 2D tracks.', '$.tracks', 'E_ANIMATION_3D_MIXED_DIMENSIONS');
|
|
545
|
+
}
|
|
546
|
+
if (document.canvas.width !== payload.viewport.width || document.canvas.height !== payload.viewport.height) {
|
|
547
|
+
invalid('Core canvas and native 3D viewport dimensions must match.', `${EXTENSION_PATH}.viewport`);
|
|
548
|
+
}
|
|
549
|
+
for (let index = 0; index < payload.nodes.length; index++) {
|
|
550
|
+
const node = payload.nodes[index];
|
|
551
|
+
const start = node.start ?? 0;
|
|
552
|
+
if (start > document.duration || start + (node.duration ?? document.duration - start) > document.duration + 1e-6) {
|
|
553
|
+
invalid('Node time range must fit inside composition duration.', `${EXTENSION_PATH}.nodes[${index}]`);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
for (let index = 0; index < payload.clips.length; index++) {
|
|
557
|
+
if (payload.clips[index].duration > document.duration + 1e-6) {
|
|
558
|
+
invalid('Clip duration must fit inside composition duration.', `${EXTENSION_PATH}.clips[${index}].duration`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
function validateNodeSemantics(nodes, nodeIds, materialIds) {
|
|
563
|
+
const byId = new Map(nodes.map(node => [node.id, node]));
|
|
564
|
+
for (let index = 0; index < nodes.length; index++) {
|
|
565
|
+
const node = nodes[index];
|
|
566
|
+
if (node.parent !== undefined && !nodeIds.has(node.parent)) {
|
|
567
|
+
invalid(`Node parent "${node.parent}" does not exist.`, `${EXTENSION_PATH}.nodes[${index}].parent`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
568
|
+
}
|
|
569
|
+
if (node.parent === node.id)
|
|
570
|
+
invalid('Node cannot parent itself.', `${EXTENSION_PATH}.nodes[${index}].parent`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
571
|
+
for (let componentIndex = 0; componentIndex < node.components.length; componentIndex++) {
|
|
572
|
+
const component = node.components[componentIndex];
|
|
573
|
+
const path = `${EXTENSION_PATH}.nodes[${index}].components[${componentIndex}]`;
|
|
574
|
+
if (component.kind === 'primitive3d' && !materialIds.has(component.materialId)) {
|
|
575
|
+
invalid(`Primitive material "${component.materialId}" does not exist.`, `${path}.materialId`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
|
|
576
|
+
}
|
|
577
|
+
if (component.kind === 'model3d') {
|
|
578
|
+
for (let overrideIndex = 0; overrideIndex < (component.materialOverrides?.length ?? 0); overrideIndex++) {
|
|
579
|
+
const materialId = component.materialOverrides[overrideIndex].materialId;
|
|
580
|
+
if (!materialIds.has(materialId))
|
|
581
|
+
invalid(`Material override "${materialId}" does not exist.`, `${path}.materialOverrides[${overrideIndex}].materialId`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
for (const node of nodes) {
|
|
587
|
+
const visited = new Set();
|
|
588
|
+
let current = node;
|
|
589
|
+
while (current?.parent) {
|
|
590
|
+
if (visited.has(current.id))
|
|
591
|
+
invalid('Node hierarchy contains a cycle.', `${EXTENSION_PATH}.nodes`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
592
|
+
visited.add(current.id);
|
|
593
|
+
current = byId.get(current.parent);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function validateResourceReferences(resources, payload) {
|
|
598
|
+
const byId = new Map(resources.map(resource => [resource.id, resource]));
|
|
599
|
+
for (let index = 0; index < resources.length; index++) {
|
|
600
|
+
const resource = resources[index];
|
|
601
|
+
const scheme = uriScheme(resource.uri);
|
|
602
|
+
if (scheme && FORBIDDEN_URI_SCHEMES.has(scheme)) {
|
|
603
|
+
invalid(`Delivery URI scheme "${scheme}:" is forbidden.`, `$.resources[${index}].uri`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
for (let materialIndex = 0; materialIndex < payload.materials.length; materialIndex++) {
|
|
607
|
+
const material = payload.materials[materialIndex];
|
|
608
|
+
for (const key of ['baseColorTexture', 'normalTexture', 'metallicRoughnessTexture', 'emissiveTexture']) {
|
|
609
|
+
const id = material[key];
|
|
610
|
+
if (id === undefined)
|
|
611
|
+
continue;
|
|
612
|
+
const resource = byId.get(id);
|
|
613
|
+
if (!resource || resource.type !== 'image')
|
|
614
|
+
invalid(`Material texture "${id}" must reference an image resource.`, `${EXTENSION_PATH}.materials[${materialIndex}].${key}`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
for (let nodeIndex = 0; nodeIndex < payload.nodes.length; nodeIndex++) {
|
|
618
|
+
const node = payload.nodes[nodeIndex];
|
|
619
|
+
for (let componentIndex = 0; componentIndex < node.components.length; componentIndex++) {
|
|
620
|
+
const component = node.components[componentIndex];
|
|
621
|
+
const path = `${EXTENSION_PATH}.nodes[${nodeIndex}].components[${componentIndex}]`;
|
|
622
|
+
if (component.kind === 'model3d') {
|
|
623
|
+
const resource = byId.get(component.resource);
|
|
624
|
+
if (!resource || resource.type !== 'binary' || !resource.mimeType || !MODEL_MIME_TYPES.has(resource.mimeType)) {
|
|
625
|
+
invalid(`Model "${component.resource}" must reference a binary glTF/GLB resource.`, `${path}.resource`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
if (component.kind === 'particle3d' && component.descriptor.textureResource !== undefined) {
|
|
629
|
+
const resource = byId.get(component.descriptor.textureResource);
|
|
630
|
+
if (!resource || resource.type !== 'image')
|
|
631
|
+
invalid(`Particle texture "${component.descriptor.textureResource}" must reference an image resource.`, `${path}.descriptor.textureResource`, 'E_ANIMATION_3D_UNKNOWN_RESOURCE');
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function validateBindingTarget(binding, nodes, materialIds, path) {
|
|
637
|
+
const byId = new Map(nodes.map(node => [node.id, node]));
|
|
638
|
+
const target = binding.target;
|
|
639
|
+
if (target.kind === 'node-id' && !byId.has(target.nodeId)) {
|
|
640
|
+
invalid(`Binding node "${target.nodeId}" does not exist.`, `${path}.target.nodeId`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
641
|
+
}
|
|
642
|
+
if (target.kind === 'node-path' && !byId.has(target.segments[0])) {
|
|
643
|
+
invalid(`Binding node path root "${target.segments[0]}" does not exist.`, `${path}.target.segments[0]`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
644
|
+
}
|
|
645
|
+
if (binding.path === 'property' && binding.component === 'material3d') {
|
|
646
|
+
if (target.kind !== 'slot' || !materialIds.has(target.slot))
|
|
647
|
+
invalid('Material property bindings require a material-id slot target.', `${path}.target`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
648
|
+
}
|
|
649
|
+
if (binding.path === 'property' && binding.component === 'camera3d') {
|
|
650
|
+
if (target.kind !== 'node-id' || !byId.get(target.nodeId)?.components.some(component => component.kind === 'camera3d')) {
|
|
651
|
+
invalid('Camera property bindings require a node-id target with Camera3D.', `${path}.target`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function validateStateMachineReferences(machine, clipIds, bindingIds, path) {
|
|
656
|
+
const parameterNames = new Set(machine.parameters.map(parameter => parameter.name));
|
|
657
|
+
const visitMotion = (motion, motionPath) => {
|
|
658
|
+
if (motion.kind === 'clip') {
|
|
659
|
+
if (!clipIds.has(motion.clipId))
|
|
660
|
+
invalid(`Motion clip "${motion.clipId}" does not exist.`, `${motionPath}.clipId`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
for (let index = 0; index < motion.children.length; index++)
|
|
664
|
+
visitMotion(motion.children[index].motion, `${motionPath}.children[${index}].motion`);
|
|
665
|
+
};
|
|
666
|
+
for (let layerIndex = 0; layerIndex < machine.layers.length; layerIndex++) {
|
|
667
|
+
const layer = machine.layers[layerIndex];
|
|
668
|
+
const layerPath = `${path}.layers[${layerIndex}]`;
|
|
669
|
+
const stateIds = new Set(layer.states.map(state => state.id));
|
|
670
|
+
if (!stateIds.has(layer.initialStateId))
|
|
671
|
+
invalid(`Initial state "${layer.initialStateId}" does not exist.`, `${layerPath}.initialStateId`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
672
|
+
for (let stateIndex = 0; stateIndex < layer.states.length; stateIndex++) {
|
|
673
|
+
const state = layer.states[stateIndex];
|
|
674
|
+
visitMotion(state.motion, `${layerPath}.states[${stateIndex}].motion`);
|
|
675
|
+
if (state.speedParameter && !parameterNames.has(state.speedParameter))
|
|
676
|
+
invalid(`Speed parameter "${state.speedParameter}" does not exist.`, `${layerPath}.states[${stateIndex}].speedParameter`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
677
|
+
}
|
|
678
|
+
for (let transitionIndex = 0; transitionIndex < layer.transitions.length; transitionIndex++) {
|
|
679
|
+
const transition = layer.transitions[transitionIndex];
|
|
680
|
+
const transitionPath = `${layerPath}.transitions[${transitionIndex}]`;
|
|
681
|
+
if (transition.from !== '*' && !stateIds.has(transition.from))
|
|
682
|
+
invalid(`Transition source "${transition.from}" does not exist.`, `${transitionPath}.from`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
683
|
+
if (!stateIds.has(transition.to))
|
|
684
|
+
invalid(`Transition destination "${transition.to}" does not exist.`, `${transitionPath}.to`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
685
|
+
for (let conditionIndex = 0; conditionIndex < transition.conditions.length; conditionIndex++) {
|
|
686
|
+
if (!parameterNames.has(transition.conditions[conditionIndex].parameter))
|
|
687
|
+
invalid(`Condition parameter "${transition.conditions[conditionIndex].parameter}" does not exist.`, `${transitionPath}.conditions[${conditionIndex}].parameter`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
for (const [kind, values] of [['include', layer.mask?.include], ['exclude', layer.mask?.exclude]]) {
|
|
691
|
+
for (let index = 0; index < (values?.length ?? 0); index++) {
|
|
692
|
+
if (!bindingIds.has(values[index]))
|
|
693
|
+
invalid(`Mask binding "${values[index]}" does not exist.`, `${layerPath}.mask.${kind}[${index}]`, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
function propertyContract(component, property, path) {
|
|
699
|
+
const material = { baseColorFactor: ['vec4', 4], metallicFactor: ['scalar', 1], roughnessFactor: ['scalar', 1], emissiveFactor: ['vec3', 3], alphaCutoff: ['scalar', 1] };
|
|
700
|
+
const camera = { fovYRadians: ['scalar', 1], near: ['scalar', 1], far: ['scalar', 1], orthoHeight: ['scalar', 1] };
|
|
701
|
+
const contract = component === 'material3d'
|
|
702
|
+
? material[property]
|
|
703
|
+
: camera[property];
|
|
704
|
+
if (!contract)
|
|
705
|
+
invalid(`Property "${property}" is not valid for ${component}.`, path, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
706
|
+
return { valueType: contract[0], valueSize: contract[1] };
|
|
707
|
+
}
|
|
708
|
+
function validateTrackQuaternions(values, keyCount, interpolation, path) {
|
|
709
|
+
const stride = interpolation === 'cubic-spline' ? 12 : 4;
|
|
710
|
+
const valueOffset = interpolation === 'cubic-spline' ? 4 : 0;
|
|
711
|
+
for (let index = 0; index < keyCount; index++) {
|
|
712
|
+
assertNormalizedQuaternion(values.slice(index * stride + valueOffset, index * stride + valueOffset + 4), `${path}[${index * stride + valueOffset}]`);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
function assertNormalizedQuaternion(value, path) {
|
|
716
|
+
const length = Math.hypot(...value);
|
|
717
|
+
if (Math.abs(length - 1) > 1e-4)
|
|
718
|
+
invalid('Quaternion must be normalized XYZW.', path, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
719
|
+
}
|
|
720
|
+
function pickCoreLimits(options) {
|
|
721
|
+
const keys = ['maxInputBytes', 'maxMetadataBytes', 'maxNodes', 'maxComponents', 'maxTracks', 'maxKeyframes', 'maxResources', 'maxPathValues', 'maxTextCharacters', 'maxParticleCapacity'];
|
|
722
|
+
const result = {};
|
|
723
|
+
for (const key of keys)
|
|
724
|
+
if (options[key] !== undefined)
|
|
725
|
+
result[key] = options[key];
|
|
726
|
+
return result;
|
|
727
|
+
}
|
|
728
|
+
function resolveLimits(options) {
|
|
729
|
+
return Object.freeze({
|
|
730
|
+
maxMaterials: positiveLimit(options.maxMaterials, DEFAULT_LIMITS.maxMaterials, 'maxMaterials'),
|
|
731
|
+
maxNodes: positiveLimit(options.maxNodes, DEFAULT_LIMITS.maxNodes, 'maxNodes'),
|
|
732
|
+
maxComponents: positiveLimit(options.maxComponents, DEFAULT_LIMITS.maxComponents, 'maxComponents'),
|
|
733
|
+
maxClips: positiveLimit(options.maxClips, DEFAULT_LIMITS.maxClips, 'maxClips'),
|
|
734
|
+
maxTracks: positiveLimit(options.maxTracks, DEFAULT_LIMITS.maxTracks, 'maxTracks'),
|
|
735
|
+
maxKeyframes: positiveLimit(options.maxKeyframes, DEFAULT_LIMITS.maxKeyframes, 'maxKeyframes'),
|
|
736
|
+
maxParticleCapacity: positiveLimit(options.maxParticleCapacity, DEFAULT_LIMITS.maxParticleCapacity, 'maxParticleCapacity'),
|
|
737
|
+
maxStateMachineDepth: positiveLimit(options.maxStateMachineDepth, DEFAULT_LIMITS.maxStateMachineDepth, 'maxStateMachineDepth'),
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
function positiveLimit(value, fallback, name) {
|
|
741
|
+
if (value === undefined)
|
|
742
|
+
return fallback;
|
|
743
|
+
if (!Number.isSafeInteger(value) || value <= 0)
|
|
744
|
+
throw new RangeError(`${name} must be a positive safe integer.`);
|
|
745
|
+
return value;
|
|
746
|
+
}
|
|
747
|
+
function object(value, path, required = [], allowed) {
|
|
748
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
749
|
+
invalid('Expected an object.', path);
|
|
750
|
+
const result = value;
|
|
751
|
+
for (const key of required)
|
|
752
|
+
if (!(key in result))
|
|
753
|
+
invalid(`Missing required property "${key}".`, `${path}.${key}`);
|
|
754
|
+
if (allowed) {
|
|
755
|
+
const allowedSet = new Set(allowed);
|
|
756
|
+
for (const key of Object.keys(result))
|
|
757
|
+
if (!allowedSet.has(key))
|
|
758
|
+
invalid(`Unknown property "${key}".`, `${path}.${key}`, 'E_ANIMATION_3D_UNSUPPORTED_FEATURE');
|
|
759
|
+
}
|
|
760
|
+
return result;
|
|
761
|
+
}
|
|
762
|
+
function array(value, path) {
|
|
763
|
+
if (!Array.isArray(value))
|
|
764
|
+
invalid('Expected an array.', path);
|
|
765
|
+
return value;
|
|
766
|
+
}
|
|
767
|
+
function nonEmptyArray(value, path) {
|
|
768
|
+
const result = array(value, path);
|
|
769
|
+
if (result.length === 0)
|
|
770
|
+
invalid('Expected at least one item.', path);
|
|
771
|
+
return result;
|
|
772
|
+
}
|
|
773
|
+
function numericArray(value, path, minimumLength = 0) {
|
|
774
|
+
const result = array(value, path);
|
|
775
|
+
if (result.length < minimumLength)
|
|
776
|
+
invalid(`Expected at least ${minimumLength} numeric value(s).`, path);
|
|
777
|
+
return Object.freeze(result.map((entry, index) => finite(entry, `${path}[${index}]`)));
|
|
778
|
+
}
|
|
779
|
+
function vec2(value, path) {
|
|
780
|
+
return tuple(value, path, 2);
|
|
781
|
+
}
|
|
782
|
+
function vec3(value, path, minimum = -Number.MAX_VALUE, maximum = Number.MAX_VALUE) {
|
|
783
|
+
return tuple(value, path, 3, minimum, maximum);
|
|
784
|
+
}
|
|
785
|
+
function vec4(value, path, minimum = -Number.MAX_VALUE, maximum = Number.MAX_VALUE) {
|
|
786
|
+
return tuple(value, path, 4, minimum, maximum);
|
|
787
|
+
}
|
|
788
|
+
function tuple(value, path, size, minimum = -Number.MAX_VALUE, maximum = Number.MAX_VALUE) {
|
|
789
|
+
const result = array(value, path);
|
|
790
|
+
if (result.length !== size)
|
|
791
|
+
invalid(`Expected exactly ${size} numbers.`, path);
|
|
792
|
+
return Object.freeze(result.map((entry, index) => bounded(entry, `${path}[${index}]`, minimum, maximum)));
|
|
793
|
+
}
|
|
794
|
+
function range(value, path, minimum = -Number.MAX_VALUE) {
|
|
795
|
+
if (Array.isArray(value)) {
|
|
796
|
+
const result = tuple(value, path, 2, minimum);
|
|
797
|
+
if (result[0] > result[1])
|
|
798
|
+
invalid('Range minimum cannot exceed maximum.', path);
|
|
799
|
+
return result;
|
|
800
|
+
}
|
|
801
|
+
return bounded(value, path, minimum);
|
|
802
|
+
}
|
|
803
|
+
function finite(value, path) {
|
|
804
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
805
|
+
invalid('Expected a finite number.', path);
|
|
806
|
+
return value;
|
|
807
|
+
}
|
|
808
|
+
function positive(value, path) {
|
|
809
|
+
const result = finite(value, path);
|
|
810
|
+
if (result <= 0)
|
|
811
|
+
invalid('Expected a positive number.', path);
|
|
812
|
+
return result;
|
|
813
|
+
}
|
|
814
|
+
function nonNegative(value, path) {
|
|
815
|
+
const result = finite(value, path);
|
|
816
|
+
if (result < 0)
|
|
817
|
+
invalid('Expected a non-negative number.', path);
|
|
818
|
+
return result;
|
|
819
|
+
}
|
|
820
|
+
function bounded(value, path, minimum, maximum = Number.MAX_VALUE, inclusiveMaximum = true) {
|
|
821
|
+
const result = finite(value, path);
|
|
822
|
+
if (result < minimum || (inclusiveMaximum ? result > maximum : result >= maximum))
|
|
823
|
+
invalid(`Expected a number in ${inclusiveMaximum ? '[' : '('}${minimum}, ${maximum}${inclusiveMaximum ? ']' : ')'}.`, path);
|
|
824
|
+
return result;
|
|
825
|
+
}
|
|
826
|
+
function integer(value, path, minimum, maximum) {
|
|
827
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < minimum || value > maximum)
|
|
828
|
+
invalid(`Expected a safe integer in [${minimum}, ${maximum}].`, path);
|
|
829
|
+
return value;
|
|
830
|
+
}
|
|
831
|
+
function string(value, path) {
|
|
832
|
+
if (typeof value !== 'string')
|
|
833
|
+
invalid('Expected a string.', path);
|
|
834
|
+
return value;
|
|
835
|
+
}
|
|
836
|
+
function nonEmpty(value, path) {
|
|
837
|
+
const result = string(value, path);
|
|
838
|
+
if (result.length === 0)
|
|
839
|
+
invalid('Expected a non-empty string.', path);
|
|
840
|
+
return result;
|
|
841
|
+
}
|
|
842
|
+
function boolean(value, path) {
|
|
843
|
+
if (typeof value !== 'boolean')
|
|
844
|
+
invalid('Expected a boolean.', path);
|
|
845
|
+
return value;
|
|
846
|
+
}
|
|
847
|
+
function enumeration(value, values, path) {
|
|
848
|
+
if (typeof value !== 'string' || !values.includes(value))
|
|
849
|
+
invalid(`Expected one of ${values.join(', ')}.`, path);
|
|
850
|
+
return value;
|
|
851
|
+
}
|
|
852
|
+
function exact(value, expected, path, code = 'E_ANIMATION_3D_INVALID_PAYLOAD') {
|
|
853
|
+
if (value !== expected)
|
|
854
|
+
invalid(`Expected ${JSON.stringify(expected)}.`, path, code);
|
|
855
|
+
}
|
|
856
|
+
function unique(seen, value, path, label) {
|
|
857
|
+
if (seen.has(value))
|
|
858
|
+
invalid(`Duplicate ${label} id "${value}".`, path, 'E_ANIMATION_3D_BINDING_MISMATCH');
|
|
859
|
+
seen.add(value);
|
|
860
|
+
}
|
|
861
|
+
function budget(actual, maximum, label, path) {
|
|
862
|
+
if (actual > maximum)
|
|
863
|
+
invalid(`${label} count ${actual} exceeds limit ${maximum}.`, path, 'E_ANIMATION_3D_LIMIT_EXCEEDED');
|
|
864
|
+
}
|
|
865
|
+
function optionalStrings(item, path, keys) {
|
|
866
|
+
const result = {};
|
|
867
|
+
for (const key of keys)
|
|
868
|
+
if (item[key] !== undefined)
|
|
869
|
+
result[key] = nonEmpty(item[key], `${path}.${key}`);
|
|
870
|
+
return result;
|
|
871
|
+
}
|
|
872
|
+
function parseJsonObject(value, path, depth = 0) {
|
|
873
|
+
if (depth > 64)
|
|
874
|
+
budget(depth, 64, 'event payload depth', path);
|
|
875
|
+
const item = object(value, path);
|
|
876
|
+
const result = {};
|
|
877
|
+
for (const [key, child] of Object.entries(item))
|
|
878
|
+
result[key] = parseJsonValue(child, `${path}.${key}`, depth + 1);
|
|
879
|
+
return Object.freeze(result);
|
|
880
|
+
}
|
|
881
|
+
function parseJsonValue(value, path, depth) {
|
|
882
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
883
|
+
return value;
|
|
884
|
+
if (typeof value === 'number')
|
|
885
|
+
return finite(value, path);
|
|
886
|
+
if (Array.isArray(value))
|
|
887
|
+
return Object.freeze(value.map((child, index) => parseJsonValue(child, `${path}[${index}]`, depth + 1)));
|
|
888
|
+
return parseJsonObject(value, path, depth);
|
|
889
|
+
}
|
|
890
|
+
function uriScheme(uri) {
|
|
891
|
+
const match = /^([a-z][a-z0-9+.-]*):/i.exec(uri);
|
|
892
|
+
return match?.[1]?.toLowerCase() ?? null;
|
|
893
|
+
}
|
|
894
|
+
function deepFreeze(value) {
|
|
895
|
+
if (value && typeof value === 'object' && !Object.isFrozen(value)) {
|
|
896
|
+
for (const child of Object.values(value))
|
|
897
|
+
deepFreeze(child);
|
|
898
|
+
Object.freeze(value);
|
|
899
|
+
}
|
|
900
|
+
return value;
|
|
901
|
+
}
|
|
902
|
+
function invalid(message, path, code = 'E_ANIMATION_3D_INVALID_PAYLOAD') {
|
|
903
|
+
throw new Native3DAnimationFormatError(code, message, path);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
export { NATIVE_3D_ANIMATION_EXTENSION_ID, NATIVE_3D_ANIMATION_FORMAT, NATIVE_3D_CLIP_FORMAT, NATIVE_3D_STATE_MACHINE_FORMAT, Native3DAnimationFormatError, createNative3DAnimationExtensionHandler, parseNative3DAnimation, parseNative3DAnimationPayload };
|
|
907
|
+
//# sourceMappingURL=native3d.js.map
|