Favivon - Correção

This commit is contained in:
2026-05-30 19:59:39 -03:00
parent 76ddaa815d
commit d7dfd221f0
32859 changed files with 5459654 additions and 404 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+12
View File
@@ -0,0 +1,12 @@
type API = {
ready: Promise<void>;
supported: boolean;
decodeVertexBuffer: (target: Uint8Array, count: number, size: number, source: Uint8Array, filter?: string) => void;
decodeIndexBuffer: (target: Uint8Array, count: number, size: number, source: Uint8Array) => void;
decodeIndexSequence: (target: Uint8Array, count: number, size: number, source: Uint8Array) => void;
decodeGltfBuffer: (target: Uint8Array, count: number, size: number, source: Uint8Array, mode: string, filter?: string) => void;
};
declare const MeshoptDecoder: () => API | {
supported: boolean;
};
export { MeshoptDecoder };
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+326
View File
@@ -0,0 +1,326 @@
"use strict";
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const MotionControllerConstants = {
Handedness: {
NONE: "none",
LEFT: "left",
RIGHT: "right"
},
ComponentState: {
DEFAULT: "default",
TOUCHED: "touched",
PRESSED: "pressed"
},
ComponentProperty: {
BUTTON: "button",
X_AXIS: "xAxis",
Y_AXIS: "yAxis",
STATE: "state"
},
ComponentType: {
TRIGGER: "trigger",
SQUEEZE: "squeeze",
TOUCHPAD: "touchpad",
THUMBSTICK: "thumbstick",
BUTTON: "button"
},
ButtonTouchThreshold: 0.05,
AxisTouchThreshold: 0.1,
VisualResponseProperty: {
TRANSFORM: "transform",
VISIBILITY: "visibility"
}
};
async function fetchJsonFile(path) {
const response = await fetch(path);
if (!response.ok) {
throw new Error(response.statusText);
} else {
return response.json();
}
}
async function fetchProfilesList(basePath) {
if (!basePath) {
throw new Error("No basePath supplied");
}
const profileListFileName = "profilesList.json";
const profilesList = await fetchJsonFile(`${basePath}/${profileListFileName}`);
return profilesList;
}
async function fetchProfile(xrInputSource, basePath, defaultProfile = null, getAssetPath = true) {
if (!xrInputSource) {
throw new Error("No xrInputSource supplied");
}
if (!basePath) {
throw new Error("No basePath supplied");
}
const supportedProfilesList = await fetchProfilesList(basePath);
let match = void 0;
xrInputSource.profiles.some((profileId) => {
const supportedProfile = supportedProfilesList[profileId];
if (supportedProfile) {
match = {
profileId,
profilePath: `${basePath}/${supportedProfile.path}`,
deprecated: !!supportedProfile.deprecated
};
}
return !!match;
});
if (!match) {
if (!defaultProfile) {
throw new Error("No matching profile name found");
}
const supportedProfile = supportedProfilesList[defaultProfile];
if (!supportedProfile) {
throw new Error(`No matching profile name found and default profile "${defaultProfile}" missing.`);
}
match = {
profileId: defaultProfile,
profilePath: `${basePath}/${supportedProfile.path}`,
deprecated: !!supportedProfile.deprecated
};
}
const profile = await fetchJsonFile(match.profilePath);
let assetPath = void 0;
if (getAssetPath) {
let layout;
if (xrInputSource.handedness === "any") {
layout = profile.layouts[Object.keys(profile.layouts)[0]];
} else {
layout = profile.layouts[xrInputSource.handedness];
}
if (!layout) {
throw new Error(`No matching handedness, ${xrInputSource.handedness}, in profile ${match.profileId}`);
}
if (layout.assetPath) {
assetPath = match.profilePath.replace("profile.json", layout.assetPath);
}
}
return { profile, assetPath };
}
const defaultComponentValues = {
xAxis: 0,
yAxis: 0,
button: 0,
state: MotionControllerConstants.ComponentState.DEFAULT
};
function normalizeAxes(x = 0, y = 0) {
let xAxis = x;
let yAxis = y;
const hypotenuse = Math.sqrt(x * x + y * y);
if (hypotenuse > 1) {
const theta = Math.atan2(y, x);
xAxis = Math.cos(theta);
yAxis = Math.sin(theta);
}
const result = {
normalizedXAxis: xAxis * 0.5 + 0.5,
normalizedYAxis: yAxis * 0.5 + 0.5
};
return result;
}
class VisualResponse {
constructor(visualResponseDescription) {
__publicField(this, "value");
__publicField(this, "componentProperty");
__publicField(this, "states");
__publicField(this, "valueNodeName");
__publicField(this, "valueNodeProperty");
__publicField(this, "minNodeName");
__publicField(this, "maxNodeName");
__publicField(this, "valueNode");
__publicField(this, "minNode");
__publicField(this, "maxNode");
this.componentProperty = visualResponseDescription.componentProperty;
this.states = visualResponseDescription.states;
this.valueNodeName = visualResponseDescription.valueNodeName;
this.valueNodeProperty = visualResponseDescription.valueNodeProperty;
if (this.valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM) {
this.minNodeName = visualResponseDescription.minNodeName;
this.maxNodeName = visualResponseDescription.maxNodeName;
}
this.value = 0;
this.updateFromComponent(defaultComponentValues);
}
/**
* Computes the visual response's interpolation weight based on component state
* @param {Object} componentValues - The component from which to update
* @param {number | undefined} xAxis - The reported X axis value of the component
* @param {number | undefined} yAxis - The reported Y axis value of the component
* @param {number | undefined} button - The reported value of the component's button
* @param {string} state - The component's active state
*/
updateFromComponent({
xAxis,
yAxis,
button,
state
}) {
const { normalizedXAxis, normalizedYAxis } = normalizeAxes(xAxis, yAxis);
switch (this.componentProperty) {
case MotionControllerConstants.ComponentProperty.X_AXIS:
this.value = this.states.includes(state) ? normalizedXAxis : 0.5;
break;
case MotionControllerConstants.ComponentProperty.Y_AXIS:
this.value = this.states.includes(state) ? normalizedYAxis : 0.5;
break;
case MotionControllerConstants.ComponentProperty.BUTTON:
this.value = this.states.includes(state) && button ? button : 0;
break;
case MotionControllerConstants.ComponentProperty.STATE:
if (this.valueNodeProperty === MotionControllerConstants.VisualResponseProperty.VISIBILITY) {
this.value = this.states.includes(state);
} else {
this.value = this.states.includes(state) ? 1 : 0;
}
break;
default:
throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`);
}
}
}
class Component {
/**
* @param {string} componentId - Id of the component
* @param {InputProfileComponent} componentDescription - Description of the component to be created
*/
constructor(componentId, componentDescription) {
__publicField(this, "id");
__publicField(this, "values");
__publicField(this, "type");
__publicField(this, "gamepadIndices");
__publicField(this, "rootNodeName");
__publicField(this, "visualResponses");
__publicField(this, "touchPointNodeName");
__publicField(this, "touchPointNode");
if (!componentId || !componentDescription || !componentDescription.visualResponses || !componentDescription.gamepadIndices || Object.keys(componentDescription.gamepadIndices).length === 0) {
throw new Error("Invalid arguments supplied");
}
this.id = componentId;
this.type = componentDescription.type;
this.rootNodeName = componentDescription.rootNodeName;
this.touchPointNodeName = componentDescription.touchPointNodeName;
this.visualResponses = {};
Object.keys(componentDescription.visualResponses).forEach((responseName) => {
const visualResponse = new VisualResponse(componentDescription.visualResponses[responseName]);
this.visualResponses[responseName] = visualResponse;
});
this.gamepadIndices = Object.assign({}, componentDescription.gamepadIndices);
this.values = {
state: MotionControllerConstants.ComponentState.DEFAULT,
button: this.gamepadIndices.button !== void 0 ? 0 : void 0,
xAxis: this.gamepadIndices.xAxis !== void 0 ? 0 : void 0,
yAxis: this.gamepadIndices.yAxis !== void 0 ? 0 : void 0
};
}
get data() {
const data = { id: this.id, ...this.values };
return data;
}
/**
* @description Poll for updated data based on current gamepad state
* @param {Object} gamepad - The gamepad object from which the component data should be polled
*/
updateFromGamepad(gamepad) {
this.values.state = MotionControllerConstants.ComponentState.DEFAULT;
if (this.gamepadIndices.button !== void 0 && gamepad.buttons.length > this.gamepadIndices.button) {
const gamepadButton = gamepad.buttons[this.gamepadIndices.button];
this.values.button = gamepadButton.value;
this.values.button = this.values.button < 0 ? 0 : this.values.button;
this.values.button = this.values.button > 1 ? 1 : this.values.button;
if (gamepadButton.pressed || this.values.button === 1) {
this.values.state = MotionControllerConstants.ComponentState.PRESSED;
} else if (gamepadButton.touched || this.values.button > MotionControllerConstants.ButtonTouchThreshold) {
this.values.state = MotionControllerConstants.ComponentState.TOUCHED;
}
}
if (this.gamepadIndices.xAxis !== void 0 && gamepad.axes.length > this.gamepadIndices.xAxis) {
this.values.xAxis = gamepad.axes[this.gamepadIndices.xAxis];
this.values.xAxis = this.values.xAxis < -1 ? -1 : this.values.xAxis;
this.values.xAxis = this.values.xAxis > 1 ? 1 : this.values.xAxis;
if (this.values.state === MotionControllerConstants.ComponentState.DEFAULT && Math.abs(this.values.xAxis) > MotionControllerConstants.AxisTouchThreshold) {
this.values.state = MotionControllerConstants.ComponentState.TOUCHED;
}
}
if (this.gamepadIndices.yAxis !== void 0 && gamepad.axes.length > this.gamepadIndices.yAxis) {
this.values.yAxis = gamepad.axes[this.gamepadIndices.yAxis];
this.values.yAxis = this.values.yAxis < -1 ? -1 : this.values.yAxis;
this.values.yAxis = this.values.yAxis > 1 ? 1 : this.values.yAxis;
if (this.values.state === MotionControllerConstants.ComponentState.DEFAULT && Math.abs(this.values.yAxis) > MotionControllerConstants.AxisTouchThreshold) {
this.values.state = MotionControllerConstants.ComponentState.TOUCHED;
}
}
Object.values(this.visualResponses).forEach((visualResponse) => {
visualResponse.updateFromComponent(this.values);
});
}
}
class MotionController {
/**
* @param {XRInputSource} xrInputSource - The XRInputSource to build the MotionController around
* @param {Profile} profile - The best matched profile description for the supplied xrInputSource
* @param {string} assetUrl
*/
constructor(xrInputSource, profile, assetUrl) {
__publicField(this, "xrInputSource");
__publicField(this, "assetUrl");
__publicField(this, "layoutDescription");
__publicField(this, "id");
__publicField(this, "components");
if (!xrInputSource) {
throw new Error("No xrInputSource supplied");
}
if (!profile) {
throw new Error("No profile supplied");
}
if (!profile.layouts[xrInputSource.handedness]) {
throw new Error("No layout for " + xrInputSource.handedness + " handedness");
}
this.xrInputSource = xrInputSource;
this.assetUrl = assetUrl;
this.id = profile.profileId;
this.layoutDescription = profile.layouts[xrInputSource.handedness];
this.components = {};
Object.keys(this.layoutDescription.components).forEach((componentId) => {
const componentDescription = this.layoutDescription.components[componentId];
this.components[componentId] = new Component(componentId, componentDescription);
});
this.updateFromGamepad();
}
get gripSpace() {
return this.xrInputSource.gripSpace;
}
get targetRaySpace() {
return this.xrInputSource.targetRaySpace;
}
/**
* @description Returns a subset of component data for simplified debugging
*/
get data() {
const data = [];
Object.values(this.components).forEach((component) => {
data.push(component.data);
});
return data;
}
/**
* @description Poll for updated data based on current gamepad state
*/
updateFromGamepad() {
Object.values(this.components).forEach((component) => {
component.updateFromGamepad(this.xrInputSource.gamepad);
});
}
}
exports.MotionController = MotionController;
exports.MotionControllerConstants = MotionControllerConstants;
exports.fetchProfile = fetchProfile;
exports.fetchProfilesList = fetchProfilesList;
//# sourceMappingURL=MotionControllers.cjs.map
File diff suppressed because one or more lines are too long
+176
View File
@@ -0,0 +1,176 @@
/**
* @webxr-input-profiles/motion-controllers 1.0.0 https://github.com/immersive-web/webxr-input-profiles
*/
/// <reference types="webxr" />
import type { Object3D } from 'three';
interface GamepadIndices {
button: number;
xAxis?: number;
yAxis?: number;
}
interface VisualResponseDescription {
componentProperty: string;
states: string[];
valueNodeProperty: string;
valueNodeName: string;
minNodeName?: string;
maxNodeName?: string;
}
type VisualResponses = Record<string, VisualResponseDescription>;
interface ComponentDescription {
type: string;
gamepadIndices: GamepadIndices;
rootNodeName: string;
visualResponses: VisualResponses;
touchPointNodeName?: string;
}
interface Components {
[componentKey: string]: ComponentDescription;
}
interface LayoutDescription {
selectComponentId: string;
components: Components;
gamepadMapping: string;
rootNodeName: string;
assetPath: string;
}
type Layouts = Partial<Record<XRHandedness, LayoutDescription>>;
export interface Profile {
profileId: string;
fallbackProfileIds: string[];
layouts: Layouts;
}
interface ProfilesList {
[profileId: string]: {
path: string;
deprecated?: boolean;
} | undefined;
}
declare const MotionControllerConstants: {
Handedness: {
NONE: string;
LEFT: string;
RIGHT: string;
};
ComponentState: {
DEFAULT: string;
TOUCHED: string;
PRESSED: string;
};
ComponentProperty: {
BUTTON: string;
X_AXIS: string;
Y_AXIS: string;
STATE: string;
};
ComponentType: {
TRIGGER: string;
SQUEEZE: string;
TOUCHPAD: string;
THUMBSTICK: string;
BUTTON: string;
};
ButtonTouchThreshold: number;
AxisTouchThreshold: number;
VisualResponseProperty: {
TRANSFORM: string;
VISIBILITY: string;
};
};
declare function fetchProfilesList(basePath: string): Promise<ProfilesList>;
declare function fetchProfile(xrInputSource: XRInputSource, basePath: string, defaultProfile?: string | null, getAssetPath?: boolean): Promise<{
profile: Profile;
assetPath: string | undefined;
}>;
/**
* Contains the description of how the 3D model should visually respond to a specific user input.
* This is accomplished by initializing the object with the name of a node in the 3D model and
* property that need to be modified in response to user input, the name of the nodes representing
* the allowable range of motion, and the name of the input which triggers the change. In response
* to the named input changing, this object computes the appropriate weighting to use for
* interpolating between the range of motion nodes.
*/
declare class VisualResponse implements VisualResponseDescription {
value: number | boolean;
componentProperty: string;
states: string[];
valueNodeName: string;
valueNodeProperty: string;
minNodeName?: string;
maxNodeName?: string;
valueNode: Object3D | undefined;
minNode: Object3D | undefined;
maxNode: Object3D | undefined;
constructor(visualResponseDescription: VisualResponseDescription);
/**
* Computes the visual response's interpolation weight based on component state
* @param {Object} componentValues - The component from which to update
* @param {number | undefined} xAxis - The reported X axis value of the component
* @param {number | undefined} yAxis - The reported Y axis value of the component
* @param {number | undefined} button - The reported value of the component's button
* @param {string} state - The component's active state
*/
updateFromComponent({ xAxis, yAxis, button, state, }: {
xAxis?: number;
yAxis?: number;
button?: number;
state: string;
}): void;
}
declare class Component implements ComponentDescription {
id: string;
values: {
state: string;
button: number | undefined;
xAxis: number | undefined;
yAxis: number | undefined;
};
type: string;
gamepadIndices: GamepadIndices;
rootNodeName: string;
visualResponses: Record<string, VisualResponse>;
touchPointNodeName?: string | undefined;
touchPointNode?: Object3D;
/**
* @param {string} componentId - Id of the component
* @param {InputProfileComponent} componentDescription - Description of the component to be created
*/
constructor(componentId: string, componentDescription: ComponentDescription);
get data(): {
id: Component['id'];
} & Component['values'];
/**
* @description Poll for updated data based on current gamepad state
* @param {Object} gamepad - The gamepad object from which the component data should be polled
*/
updateFromGamepad(gamepad: Gamepad): void;
}
/**
* @description Builds a motion controller with components and visual responses based on the
* supplied profile description. Data is polled from the xrInputSource's gamepad.
* @author Nell Waliczek / https://github.com/NellWaliczek
*/
declare class MotionController {
xrInputSource: XRInputSource;
assetUrl: string;
layoutDescription: LayoutDescription;
id: string;
components: Record<string, Component>;
/**
* @param {XRInputSource} xrInputSource - The XRInputSource to build the MotionController around
* @param {Profile} profile - The best matched profile description for the supplied xrInputSource
* @param {string} assetUrl
*/
constructor(xrInputSource: XRInputSource, profile: Profile, assetUrl: string);
get gripSpace(): XRInputSource['gripSpace'];
get targetRaySpace(): XRInputSource['targetRaySpace'];
/**
* @description Returns a subset of component data for simplified debugging
*/
get data(): Array<Component['data']>;
/**
* @description Poll for updated data based on current gamepad state
*/
updateFromGamepad(): void;
}
export { MotionControllerConstants, MotionController, fetchProfile, fetchProfilesList };
+326
View File
@@ -0,0 +1,326 @@
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
const MotionControllerConstants = {
Handedness: {
NONE: "none",
LEFT: "left",
RIGHT: "right"
},
ComponentState: {
DEFAULT: "default",
TOUCHED: "touched",
PRESSED: "pressed"
},
ComponentProperty: {
BUTTON: "button",
X_AXIS: "xAxis",
Y_AXIS: "yAxis",
STATE: "state"
},
ComponentType: {
TRIGGER: "trigger",
SQUEEZE: "squeeze",
TOUCHPAD: "touchpad",
THUMBSTICK: "thumbstick",
BUTTON: "button"
},
ButtonTouchThreshold: 0.05,
AxisTouchThreshold: 0.1,
VisualResponseProperty: {
TRANSFORM: "transform",
VISIBILITY: "visibility"
}
};
async function fetchJsonFile(path) {
const response = await fetch(path);
if (!response.ok) {
throw new Error(response.statusText);
} else {
return response.json();
}
}
async function fetchProfilesList(basePath) {
if (!basePath) {
throw new Error("No basePath supplied");
}
const profileListFileName = "profilesList.json";
const profilesList = await fetchJsonFile(`${basePath}/${profileListFileName}`);
return profilesList;
}
async function fetchProfile(xrInputSource, basePath, defaultProfile = null, getAssetPath = true) {
if (!xrInputSource) {
throw new Error("No xrInputSource supplied");
}
if (!basePath) {
throw new Error("No basePath supplied");
}
const supportedProfilesList = await fetchProfilesList(basePath);
let match = void 0;
xrInputSource.profiles.some((profileId) => {
const supportedProfile = supportedProfilesList[profileId];
if (supportedProfile) {
match = {
profileId,
profilePath: `${basePath}/${supportedProfile.path}`,
deprecated: !!supportedProfile.deprecated
};
}
return !!match;
});
if (!match) {
if (!defaultProfile) {
throw new Error("No matching profile name found");
}
const supportedProfile = supportedProfilesList[defaultProfile];
if (!supportedProfile) {
throw new Error(`No matching profile name found and default profile "${defaultProfile}" missing.`);
}
match = {
profileId: defaultProfile,
profilePath: `${basePath}/${supportedProfile.path}`,
deprecated: !!supportedProfile.deprecated
};
}
const profile = await fetchJsonFile(match.profilePath);
let assetPath = void 0;
if (getAssetPath) {
let layout;
if (xrInputSource.handedness === "any") {
layout = profile.layouts[Object.keys(profile.layouts)[0]];
} else {
layout = profile.layouts[xrInputSource.handedness];
}
if (!layout) {
throw new Error(`No matching handedness, ${xrInputSource.handedness}, in profile ${match.profileId}`);
}
if (layout.assetPath) {
assetPath = match.profilePath.replace("profile.json", layout.assetPath);
}
}
return { profile, assetPath };
}
const defaultComponentValues = {
xAxis: 0,
yAxis: 0,
button: 0,
state: MotionControllerConstants.ComponentState.DEFAULT
};
function normalizeAxes(x = 0, y = 0) {
let xAxis = x;
let yAxis = y;
const hypotenuse = Math.sqrt(x * x + y * y);
if (hypotenuse > 1) {
const theta = Math.atan2(y, x);
xAxis = Math.cos(theta);
yAxis = Math.sin(theta);
}
const result = {
normalizedXAxis: xAxis * 0.5 + 0.5,
normalizedYAxis: yAxis * 0.5 + 0.5
};
return result;
}
class VisualResponse {
constructor(visualResponseDescription) {
__publicField(this, "value");
__publicField(this, "componentProperty");
__publicField(this, "states");
__publicField(this, "valueNodeName");
__publicField(this, "valueNodeProperty");
__publicField(this, "minNodeName");
__publicField(this, "maxNodeName");
__publicField(this, "valueNode");
__publicField(this, "minNode");
__publicField(this, "maxNode");
this.componentProperty = visualResponseDescription.componentProperty;
this.states = visualResponseDescription.states;
this.valueNodeName = visualResponseDescription.valueNodeName;
this.valueNodeProperty = visualResponseDescription.valueNodeProperty;
if (this.valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM) {
this.minNodeName = visualResponseDescription.minNodeName;
this.maxNodeName = visualResponseDescription.maxNodeName;
}
this.value = 0;
this.updateFromComponent(defaultComponentValues);
}
/**
* Computes the visual response's interpolation weight based on component state
* @param {Object} componentValues - The component from which to update
* @param {number | undefined} xAxis - The reported X axis value of the component
* @param {number | undefined} yAxis - The reported Y axis value of the component
* @param {number | undefined} button - The reported value of the component's button
* @param {string} state - The component's active state
*/
updateFromComponent({
xAxis,
yAxis,
button,
state
}) {
const { normalizedXAxis, normalizedYAxis } = normalizeAxes(xAxis, yAxis);
switch (this.componentProperty) {
case MotionControllerConstants.ComponentProperty.X_AXIS:
this.value = this.states.includes(state) ? normalizedXAxis : 0.5;
break;
case MotionControllerConstants.ComponentProperty.Y_AXIS:
this.value = this.states.includes(state) ? normalizedYAxis : 0.5;
break;
case MotionControllerConstants.ComponentProperty.BUTTON:
this.value = this.states.includes(state) && button ? button : 0;
break;
case MotionControllerConstants.ComponentProperty.STATE:
if (this.valueNodeProperty === MotionControllerConstants.VisualResponseProperty.VISIBILITY) {
this.value = this.states.includes(state);
} else {
this.value = this.states.includes(state) ? 1 : 0;
}
break;
default:
throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`);
}
}
}
class Component {
/**
* @param {string} componentId - Id of the component
* @param {InputProfileComponent} componentDescription - Description of the component to be created
*/
constructor(componentId, componentDescription) {
__publicField(this, "id");
__publicField(this, "values");
__publicField(this, "type");
__publicField(this, "gamepadIndices");
__publicField(this, "rootNodeName");
__publicField(this, "visualResponses");
__publicField(this, "touchPointNodeName");
__publicField(this, "touchPointNode");
if (!componentId || !componentDescription || !componentDescription.visualResponses || !componentDescription.gamepadIndices || Object.keys(componentDescription.gamepadIndices).length === 0) {
throw new Error("Invalid arguments supplied");
}
this.id = componentId;
this.type = componentDescription.type;
this.rootNodeName = componentDescription.rootNodeName;
this.touchPointNodeName = componentDescription.touchPointNodeName;
this.visualResponses = {};
Object.keys(componentDescription.visualResponses).forEach((responseName) => {
const visualResponse = new VisualResponse(componentDescription.visualResponses[responseName]);
this.visualResponses[responseName] = visualResponse;
});
this.gamepadIndices = Object.assign({}, componentDescription.gamepadIndices);
this.values = {
state: MotionControllerConstants.ComponentState.DEFAULT,
button: this.gamepadIndices.button !== void 0 ? 0 : void 0,
xAxis: this.gamepadIndices.xAxis !== void 0 ? 0 : void 0,
yAxis: this.gamepadIndices.yAxis !== void 0 ? 0 : void 0
};
}
get data() {
const data = { id: this.id, ...this.values };
return data;
}
/**
* @description Poll for updated data based on current gamepad state
* @param {Object} gamepad - The gamepad object from which the component data should be polled
*/
updateFromGamepad(gamepad) {
this.values.state = MotionControllerConstants.ComponentState.DEFAULT;
if (this.gamepadIndices.button !== void 0 && gamepad.buttons.length > this.gamepadIndices.button) {
const gamepadButton = gamepad.buttons[this.gamepadIndices.button];
this.values.button = gamepadButton.value;
this.values.button = this.values.button < 0 ? 0 : this.values.button;
this.values.button = this.values.button > 1 ? 1 : this.values.button;
if (gamepadButton.pressed || this.values.button === 1) {
this.values.state = MotionControllerConstants.ComponentState.PRESSED;
} else if (gamepadButton.touched || this.values.button > MotionControllerConstants.ButtonTouchThreshold) {
this.values.state = MotionControllerConstants.ComponentState.TOUCHED;
}
}
if (this.gamepadIndices.xAxis !== void 0 && gamepad.axes.length > this.gamepadIndices.xAxis) {
this.values.xAxis = gamepad.axes[this.gamepadIndices.xAxis];
this.values.xAxis = this.values.xAxis < -1 ? -1 : this.values.xAxis;
this.values.xAxis = this.values.xAxis > 1 ? 1 : this.values.xAxis;
if (this.values.state === MotionControllerConstants.ComponentState.DEFAULT && Math.abs(this.values.xAxis) > MotionControllerConstants.AxisTouchThreshold) {
this.values.state = MotionControllerConstants.ComponentState.TOUCHED;
}
}
if (this.gamepadIndices.yAxis !== void 0 && gamepad.axes.length > this.gamepadIndices.yAxis) {
this.values.yAxis = gamepad.axes[this.gamepadIndices.yAxis];
this.values.yAxis = this.values.yAxis < -1 ? -1 : this.values.yAxis;
this.values.yAxis = this.values.yAxis > 1 ? 1 : this.values.yAxis;
if (this.values.state === MotionControllerConstants.ComponentState.DEFAULT && Math.abs(this.values.yAxis) > MotionControllerConstants.AxisTouchThreshold) {
this.values.state = MotionControllerConstants.ComponentState.TOUCHED;
}
}
Object.values(this.visualResponses).forEach((visualResponse) => {
visualResponse.updateFromComponent(this.values);
});
}
}
class MotionController {
/**
* @param {XRInputSource} xrInputSource - The XRInputSource to build the MotionController around
* @param {Profile} profile - The best matched profile description for the supplied xrInputSource
* @param {string} assetUrl
*/
constructor(xrInputSource, profile, assetUrl) {
__publicField(this, "xrInputSource");
__publicField(this, "assetUrl");
__publicField(this, "layoutDescription");
__publicField(this, "id");
__publicField(this, "components");
if (!xrInputSource) {
throw new Error("No xrInputSource supplied");
}
if (!profile) {
throw new Error("No profile supplied");
}
if (!profile.layouts[xrInputSource.handedness]) {
throw new Error("No layout for " + xrInputSource.handedness + " handedness");
}
this.xrInputSource = xrInputSource;
this.assetUrl = assetUrl;
this.id = profile.profileId;
this.layoutDescription = profile.layouts[xrInputSource.handedness];
this.components = {};
Object.keys(this.layoutDescription.components).forEach((componentId) => {
const componentDescription = this.layoutDescription.components[componentId];
this.components[componentId] = new Component(componentId, componentDescription);
});
this.updateFromGamepad();
}
get gripSpace() {
return this.xrInputSource.gripSpace;
}
get targetRaySpace() {
return this.xrInputSource.targetRaySpace;
}
/**
* @description Returns a subset of component data for simplified debugging
*/
get data() {
const data = [];
Object.values(this.components).forEach((component) => {
data.push(component.data);
});
return data;
}
/**
* @description Poll for updated data based on current gamepad state
*/
updateFromGamepad() {
Object.values(this.components).forEach((component) => {
component.updateFromGamepad(this.xrInputSource.gamepad);
});
}
}
export {
MotionController,
MotionControllerConstants,
fetchProfile,
fetchProfilesList
};
//# sourceMappingURL=MotionControllers.js.map
File diff suppressed because one or more lines are too long
+8581
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+8581
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+319
View File
@@ -0,0 +1,319 @@
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const KHR_SUPERCOMPRESSION_NONE = 0;
const KHR_SUPERCOMPRESSION_ZSTD = 2;
const KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0;
const KHR_DF_VENDORID_KHRONOS = 0;
const KHR_DF_VERSION = 2;
const KHR_DF_MODEL_UNSPECIFIED = 0;
const KHR_DF_FLAG_ALPHA_STRAIGHT = 0;
const KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1;
const KHR_DF_TRANSFER_SRGB = 2;
const KHR_DF_PRIMARIES_UNSPECIFIED = 0;
const KHR_DF_PRIMARIES_BT709 = 1;
const KHR_DF_PRIMARIES_DISPLAYP3 = 10;
const KHR_DF_SAMPLE_DATATYPE_SIGNED = 64;
const VK_FORMAT_UNDEFINED = 0;
const VK_FORMAT_R8_UNORM = 9;
const VK_FORMAT_R8_SRGB = 15;
const VK_FORMAT_R8G8_UNORM = 16;
const VK_FORMAT_R8G8_SRGB = 22;
const VK_FORMAT_R8G8B8A8_UNORM = 37;
const VK_FORMAT_R8G8B8A8_SRGB = 43;
const VK_FORMAT_R16_SFLOAT = 76;
const VK_FORMAT_R16G16_SFLOAT = 83;
const VK_FORMAT_R16G16B16A16_SFLOAT = 97;
const VK_FORMAT_R32_SFLOAT = 100;
const VK_FORMAT_R32G32_SFLOAT = 103;
const VK_FORMAT_R32G32B32A32_SFLOAT = 109;
const VK_FORMAT_ASTC_6x6_UNORM_BLOCK = 165;
const VK_FORMAT_ASTC_6x6_SRGB_BLOCK = 166;
class KTX2Container {
constructor() {
this.vkFormat = VK_FORMAT_UNDEFINED;
this.typeSize = 1;
this.pixelWidth = 0;
this.pixelHeight = 0;
this.pixelDepth = 0;
this.layerCount = 0;
this.faceCount = 1;
this.supercompressionScheme = KHR_SUPERCOMPRESSION_NONE;
this.levels = [];
this.dataFormatDescriptor = [
{
vendorId: KHR_DF_VENDORID_KHRONOS,
descriptorType: KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT,
descriptorBlockSize: 0,
versionNumber: KHR_DF_VERSION,
colorModel: KHR_DF_MODEL_UNSPECIFIED,
colorPrimaries: KHR_DF_PRIMARIES_BT709,
transferFunction: KHR_DF_TRANSFER_SRGB,
flags: KHR_DF_FLAG_ALPHA_STRAIGHT,
texelBlockDimension: [0, 0, 0, 0],
bytesPlane: [0, 0, 0, 0, 0, 0, 0, 0],
samples: []
}
];
this.keyValue = {};
this.globalData = null;
}
}
class BufferReader {
constructor(data, byteOffset, byteLength, littleEndian) {
this._dataView = void 0;
this._littleEndian = void 0;
this._offset = void 0;
this._dataView = new DataView(data.buffer, data.byteOffset + byteOffset, byteLength);
this._littleEndian = littleEndian;
this._offset = 0;
}
_nextUint8() {
const value = this._dataView.getUint8(this._offset);
this._offset += 1;
return value;
}
_nextUint16() {
const value = this._dataView.getUint16(this._offset, this._littleEndian);
this._offset += 2;
return value;
}
_nextUint32() {
const value = this._dataView.getUint32(this._offset, this._littleEndian);
this._offset += 4;
return value;
}
_nextUint64() {
const left = this._dataView.getUint32(this._offset, this._littleEndian);
const right = this._dataView.getUint32(this._offset + 4, this._littleEndian);
const value = left + 2 ** 32 * right;
this._offset += 8;
return value;
}
_nextInt32() {
const value = this._dataView.getInt32(this._offset, this._littleEndian);
this._offset += 4;
return value;
}
_nextUint8Array(len) {
const value = new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + this._offset, len);
this._offset += len;
return value;
}
_skip(bytes) {
this._offset += bytes;
return this;
}
_scan(maxByteLength, term) {
if (term === void 0) {
term = 0;
}
const byteOffset = this._offset;
let byteLength = 0;
while (this._dataView.getUint8(this._offset) !== term && byteLength < maxByteLength) {
byteLength++;
this._offset++;
}
if (byteLength < maxByteLength)
this._offset++;
return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
}
}
const KTX2_ID = [
// '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
171,
75,
84,
88,
32,
50,
48,
187,
13,
10,
26,
10
];
function decodeText(buffer) {
if (typeof TextDecoder !== "undefined") {
return new TextDecoder().decode(buffer);
}
return Buffer.from(buffer).toString("utf8");
}
function read(data) {
const id = new Uint8Array(data.buffer, data.byteOffset, KTX2_ID.length);
if (id[0] !== KTX2_ID[0] || // '´'
id[1] !== KTX2_ID[1] || // 'K'
id[2] !== KTX2_ID[2] || // 'T'
id[3] !== KTX2_ID[3] || // 'X'
id[4] !== KTX2_ID[4] || // ' '
id[5] !== KTX2_ID[5] || // '2'
id[6] !== KTX2_ID[6] || // '0'
id[7] !== KTX2_ID[7] || // 'ª'
id[8] !== KTX2_ID[8] || // '\r'
id[9] !== KTX2_ID[9] || // '\n'
id[10] !== KTX2_ID[10] || // '\x1A'
id[11] !== KTX2_ID[11]) {
throw new Error("Missing KTX 2.0 identifier.");
}
const container = new KTX2Container();
const headerByteLength = 17 * Uint32Array.BYTES_PER_ELEMENT;
const headerReader = new BufferReader(data, KTX2_ID.length, headerByteLength, true);
container.vkFormat = headerReader._nextUint32();
container.typeSize = headerReader._nextUint32();
container.pixelWidth = headerReader._nextUint32();
container.pixelHeight = headerReader._nextUint32();
container.pixelDepth = headerReader._nextUint32();
container.layerCount = headerReader._nextUint32();
container.faceCount = headerReader._nextUint32();
const levelCount = headerReader._nextUint32();
container.supercompressionScheme = headerReader._nextUint32();
const dfdByteOffset = headerReader._nextUint32();
const dfdByteLength = headerReader._nextUint32();
const kvdByteOffset = headerReader._nextUint32();
const kvdByteLength = headerReader._nextUint32();
const sgdByteOffset = headerReader._nextUint64();
const sgdByteLength = headerReader._nextUint64();
const levelByteLength = levelCount * 3 * 8;
const levelReader = new BufferReader(data, KTX2_ID.length + headerByteLength, levelByteLength, true);
for (let i = 0; i < levelCount; i++) {
container.levels.push({
levelData: new Uint8Array(data.buffer, data.byteOffset + levelReader._nextUint64(), levelReader._nextUint64()),
uncompressedByteLength: levelReader._nextUint64()
});
}
const dfdReader = new BufferReader(data, dfdByteOffset, dfdByteLength, true);
const dfd = {
vendorId: dfdReader._skip(
4
/* totalSize */
)._nextUint16(),
descriptorType: dfdReader._nextUint16(),
versionNumber: dfdReader._nextUint16(),
descriptorBlockSize: dfdReader._nextUint16(),
colorModel: dfdReader._nextUint8(),
colorPrimaries: dfdReader._nextUint8(),
transferFunction: dfdReader._nextUint8(),
flags: dfdReader._nextUint8(),
texelBlockDimension: [
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8()
],
bytesPlane: [
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8()
],
samples: []
};
const sampleStart = 6;
const sampleWords = 4;
const numSamples = (dfd.descriptorBlockSize / 4 - sampleStart) / sampleWords;
for (let i = 0; i < numSamples; i++) {
const sample = {
bitOffset: dfdReader._nextUint16(),
bitLength: dfdReader._nextUint8(),
channelType: dfdReader._nextUint8(),
samplePosition: [dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8()],
sampleLower: -Infinity,
sampleUpper: Infinity
};
if (sample.channelType & KHR_DF_SAMPLE_DATATYPE_SIGNED) {
sample.sampleLower = dfdReader._nextInt32();
sample.sampleUpper = dfdReader._nextInt32();
} else {
sample.sampleLower = dfdReader._nextUint32();
sample.sampleUpper = dfdReader._nextUint32();
}
dfd.samples[i] = sample;
}
container.dataFormatDescriptor.length = 0;
container.dataFormatDescriptor.push(dfd);
const kvdReader = new BufferReader(data, kvdByteOffset, kvdByteLength, true);
while (kvdReader._offset < kvdByteLength) {
const keyValueByteLength = kvdReader._nextUint32();
const keyData = kvdReader._scan(keyValueByteLength);
const key = decodeText(keyData);
container.keyValue[key] = kvdReader._nextUint8Array(keyValueByteLength - keyData.byteLength - 1);
if (key.match(/^ktx/i)) {
const text = decodeText(container.keyValue[key]);
container.keyValue[key] = text.substring(0, text.lastIndexOf("\0"));
}
const kvPadding = keyValueByteLength % 4 ? 4 - keyValueByteLength % 4 : 0;
kvdReader._skip(kvPadding);
}
if (sgdByteLength <= 0)
return container;
const sgdReader = new BufferReader(data, sgdByteOffset, sgdByteLength, true);
const endpointCount = sgdReader._nextUint16();
const selectorCount = sgdReader._nextUint16();
const endpointsByteLength = sgdReader._nextUint32();
const selectorsByteLength = sgdReader._nextUint32();
const tablesByteLength = sgdReader._nextUint32();
const extendedByteLength = sgdReader._nextUint32();
const imageDescs = [];
for (let i = 0; i < levelCount; i++) {
imageDescs.push({
imageFlags: sgdReader._nextUint32(),
rgbSliceByteOffset: sgdReader._nextUint32(),
rgbSliceByteLength: sgdReader._nextUint32(),
alphaSliceByteOffset: sgdReader._nextUint32(),
alphaSliceByteLength: sgdReader._nextUint32()
});
}
const endpointsByteOffset = sgdByteOffset + sgdReader._offset;
const selectorsByteOffset = endpointsByteOffset + endpointsByteLength;
const tablesByteOffset = selectorsByteOffset + selectorsByteLength;
const extendedByteOffset = tablesByteOffset + tablesByteLength;
const endpointsData = new Uint8Array(data.buffer, data.byteOffset + endpointsByteOffset, endpointsByteLength);
const selectorsData = new Uint8Array(data.buffer, data.byteOffset + selectorsByteOffset, selectorsByteLength);
const tablesData = new Uint8Array(data.buffer, data.byteOffset + tablesByteOffset, tablesByteLength);
const extendedData = new Uint8Array(data.buffer, data.byteOffset + extendedByteOffset, extendedByteLength);
container.globalData = {
endpointCount,
selectorCount,
imageDescs,
endpointsData,
selectorsData,
tablesData,
extendedData
};
return container;
}
exports.KHR_DF_FLAG_ALPHA_PREMULTIPLIED = KHR_DF_FLAG_ALPHA_PREMULTIPLIED;
exports.KHR_DF_FLAG_ALPHA_STRAIGHT = KHR_DF_FLAG_ALPHA_STRAIGHT;
exports.KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT;
exports.KHR_DF_MODEL_UNSPECIFIED = KHR_DF_MODEL_UNSPECIFIED;
exports.KHR_DF_PRIMARIES_BT709 = KHR_DF_PRIMARIES_BT709;
exports.KHR_DF_PRIMARIES_DISPLAYP3 = KHR_DF_PRIMARIES_DISPLAYP3;
exports.KHR_DF_PRIMARIES_UNSPECIFIED = KHR_DF_PRIMARIES_UNSPECIFIED;
exports.KHR_DF_SAMPLE_DATATYPE_SIGNED = KHR_DF_SAMPLE_DATATYPE_SIGNED;
exports.KHR_DF_TRANSFER_SRGB = KHR_DF_TRANSFER_SRGB;
exports.KHR_DF_VENDORID_KHRONOS = KHR_DF_VENDORID_KHRONOS;
exports.KHR_DF_VERSION = KHR_DF_VERSION;
exports.KHR_SUPERCOMPRESSION_NONE = KHR_SUPERCOMPRESSION_NONE;
exports.KHR_SUPERCOMPRESSION_ZSTD = KHR_SUPERCOMPRESSION_ZSTD;
exports.KTX2Container = KTX2Container;
exports.VK_FORMAT_ASTC_6x6_SRGB_BLOCK = VK_FORMAT_ASTC_6x6_SRGB_BLOCK;
exports.VK_FORMAT_ASTC_6x6_UNORM_BLOCK = VK_FORMAT_ASTC_6x6_UNORM_BLOCK;
exports.VK_FORMAT_R16G16B16A16_SFLOAT = VK_FORMAT_R16G16B16A16_SFLOAT;
exports.VK_FORMAT_R16G16_SFLOAT = VK_FORMAT_R16G16_SFLOAT;
exports.VK_FORMAT_R16_SFLOAT = VK_FORMAT_R16_SFLOAT;
exports.VK_FORMAT_R32G32B32A32_SFLOAT = VK_FORMAT_R32G32B32A32_SFLOAT;
exports.VK_FORMAT_R32G32_SFLOAT = VK_FORMAT_R32G32_SFLOAT;
exports.VK_FORMAT_R32_SFLOAT = VK_FORMAT_R32_SFLOAT;
exports.VK_FORMAT_R8G8B8A8_SRGB = VK_FORMAT_R8G8B8A8_SRGB;
exports.VK_FORMAT_R8G8B8A8_UNORM = VK_FORMAT_R8G8B8A8_UNORM;
exports.VK_FORMAT_R8G8_SRGB = VK_FORMAT_R8G8_SRGB;
exports.VK_FORMAT_R8G8_UNORM = VK_FORMAT_R8G8_UNORM;
exports.VK_FORMAT_R8_SRGB = VK_FORMAT_R8_SRGB;
exports.VK_FORMAT_R8_UNORM = VK_FORMAT_R8_UNORM;
exports.VK_FORMAT_UNDEFINED = VK_FORMAT_UNDEFINED;
exports.read = read;
//# sourceMappingURL=ktx-parse.cjs.map
File diff suppressed because one or more lines are too long
+319
View File
@@ -0,0 +1,319 @@
const KHR_SUPERCOMPRESSION_NONE = 0;
const KHR_SUPERCOMPRESSION_ZSTD = 2;
const KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT = 0;
const KHR_DF_VENDORID_KHRONOS = 0;
const KHR_DF_VERSION = 2;
const KHR_DF_MODEL_UNSPECIFIED = 0;
const KHR_DF_FLAG_ALPHA_STRAIGHT = 0;
const KHR_DF_FLAG_ALPHA_PREMULTIPLIED = 1;
const KHR_DF_TRANSFER_SRGB = 2;
const KHR_DF_PRIMARIES_UNSPECIFIED = 0;
const KHR_DF_PRIMARIES_BT709 = 1;
const KHR_DF_PRIMARIES_DISPLAYP3 = 10;
const KHR_DF_SAMPLE_DATATYPE_SIGNED = 64;
const VK_FORMAT_UNDEFINED = 0;
const VK_FORMAT_R8_UNORM = 9;
const VK_FORMAT_R8_SRGB = 15;
const VK_FORMAT_R8G8_UNORM = 16;
const VK_FORMAT_R8G8_SRGB = 22;
const VK_FORMAT_R8G8B8A8_UNORM = 37;
const VK_FORMAT_R8G8B8A8_SRGB = 43;
const VK_FORMAT_R16_SFLOAT = 76;
const VK_FORMAT_R16G16_SFLOAT = 83;
const VK_FORMAT_R16G16B16A16_SFLOAT = 97;
const VK_FORMAT_R32_SFLOAT = 100;
const VK_FORMAT_R32G32_SFLOAT = 103;
const VK_FORMAT_R32G32B32A32_SFLOAT = 109;
const VK_FORMAT_ASTC_6x6_UNORM_BLOCK = 165;
const VK_FORMAT_ASTC_6x6_SRGB_BLOCK = 166;
class KTX2Container {
constructor() {
this.vkFormat = VK_FORMAT_UNDEFINED;
this.typeSize = 1;
this.pixelWidth = 0;
this.pixelHeight = 0;
this.pixelDepth = 0;
this.layerCount = 0;
this.faceCount = 1;
this.supercompressionScheme = KHR_SUPERCOMPRESSION_NONE;
this.levels = [];
this.dataFormatDescriptor = [
{
vendorId: KHR_DF_VENDORID_KHRONOS,
descriptorType: KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT,
descriptorBlockSize: 0,
versionNumber: KHR_DF_VERSION,
colorModel: KHR_DF_MODEL_UNSPECIFIED,
colorPrimaries: KHR_DF_PRIMARIES_BT709,
transferFunction: KHR_DF_TRANSFER_SRGB,
flags: KHR_DF_FLAG_ALPHA_STRAIGHT,
texelBlockDimension: [0, 0, 0, 0],
bytesPlane: [0, 0, 0, 0, 0, 0, 0, 0],
samples: []
}
];
this.keyValue = {};
this.globalData = null;
}
}
class BufferReader {
constructor(data, byteOffset, byteLength, littleEndian) {
this._dataView = void 0;
this._littleEndian = void 0;
this._offset = void 0;
this._dataView = new DataView(data.buffer, data.byteOffset + byteOffset, byteLength);
this._littleEndian = littleEndian;
this._offset = 0;
}
_nextUint8() {
const value = this._dataView.getUint8(this._offset);
this._offset += 1;
return value;
}
_nextUint16() {
const value = this._dataView.getUint16(this._offset, this._littleEndian);
this._offset += 2;
return value;
}
_nextUint32() {
const value = this._dataView.getUint32(this._offset, this._littleEndian);
this._offset += 4;
return value;
}
_nextUint64() {
const left = this._dataView.getUint32(this._offset, this._littleEndian);
const right = this._dataView.getUint32(this._offset + 4, this._littleEndian);
const value = left + 2 ** 32 * right;
this._offset += 8;
return value;
}
_nextInt32() {
const value = this._dataView.getInt32(this._offset, this._littleEndian);
this._offset += 4;
return value;
}
_nextUint8Array(len) {
const value = new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + this._offset, len);
this._offset += len;
return value;
}
_skip(bytes) {
this._offset += bytes;
return this;
}
_scan(maxByteLength, term) {
if (term === void 0) {
term = 0;
}
const byteOffset = this._offset;
let byteLength = 0;
while (this._dataView.getUint8(this._offset) !== term && byteLength < maxByteLength) {
byteLength++;
this._offset++;
}
if (byteLength < maxByteLength)
this._offset++;
return new Uint8Array(this._dataView.buffer, this._dataView.byteOffset + byteOffset, byteLength);
}
}
const KTX2_ID = [
// '´', 'K', 'T', 'X', '2', '0', 'ª', '\r', '\n', '\x1A', '\n'
171,
75,
84,
88,
32,
50,
48,
187,
13,
10,
26,
10
];
function decodeText(buffer) {
if (typeof TextDecoder !== "undefined") {
return new TextDecoder().decode(buffer);
}
return Buffer.from(buffer).toString("utf8");
}
function read(data) {
const id = new Uint8Array(data.buffer, data.byteOffset, KTX2_ID.length);
if (id[0] !== KTX2_ID[0] || // '´'
id[1] !== KTX2_ID[1] || // 'K'
id[2] !== KTX2_ID[2] || // 'T'
id[3] !== KTX2_ID[3] || // 'X'
id[4] !== KTX2_ID[4] || // ' '
id[5] !== KTX2_ID[5] || // '2'
id[6] !== KTX2_ID[6] || // '0'
id[7] !== KTX2_ID[7] || // 'ª'
id[8] !== KTX2_ID[8] || // '\r'
id[9] !== KTX2_ID[9] || // '\n'
id[10] !== KTX2_ID[10] || // '\x1A'
id[11] !== KTX2_ID[11]) {
throw new Error("Missing KTX 2.0 identifier.");
}
const container = new KTX2Container();
const headerByteLength = 17 * Uint32Array.BYTES_PER_ELEMENT;
const headerReader = new BufferReader(data, KTX2_ID.length, headerByteLength, true);
container.vkFormat = headerReader._nextUint32();
container.typeSize = headerReader._nextUint32();
container.pixelWidth = headerReader._nextUint32();
container.pixelHeight = headerReader._nextUint32();
container.pixelDepth = headerReader._nextUint32();
container.layerCount = headerReader._nextUint32();
container.faceCount = headerReader._nextUint32();
const levelCount = headerReader._nextUint32();
container.supercompressionScheme = headerReader._nextUint32();
const dfdByteOffset = headerReader._nextUint32();
const dfdByteLength = headerReader._nextUint32();
const kvdByteOffset = headerReader._nextUint32();
const kvdByteLength = headerReader._nextUint32();
const sgdByteOffset = headerReader._nextUint64();
const sgdByteLength = headerReader._nextUint64();
const levelByteLength = levelCount * 3 * 8;
const levelReader = new BufferReader(data, KTX2_ID.length + headerByteLength, levelByteLength, true);
for (let i = 0; i < levelCount; i++) {
container.levels.push({
levelData: new Uint8Array(data.buffer, data.byteOffset + levelReader._nextUint64(), levelReader._nextUint64()),
uncompressedByteLength: levelReader._nextUint64()
});
}
const dfdReader = new BufferReader(data, dfdByteOffset, dfdByteLength, true);
const dfd = {
vendorId: dfdReader._skip(
4
/* totalSize */
)._nextUint16(),
descriptorType: dfdReader._nextUint16(),
versionNumber: dfdReader._nextUint16(),
descriptorBlockSize: dfdReader._nextUint16(),
colorModel: dfdReader._nextUint8(),
colorPrimaries: dfdReader._nextUint8(),
transferFunction: dfdReader._nextUint8(),
flags: dfdReader._nextUint8(),
texelBlockDimension: [
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8()
],
bytesPlane: [
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8(),
dfdReader._nextUint8()
],
samples: []
};
const sampleStart = 6;
const sampleWords = 4;
const numSamples = (dfd.descriptorBlockSize / 4 - sampleStart) / sampleWords;
for (let i = 0; i < numSamples; i++) {
const sample = {
bitOffset: dfdReader._nextUint16(),
bitLength: dfdReader._nextUint8(),
channelType: dfdReader._nextUint8(),
samplePosition: [dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8(), dfdReader._nextUint8()],
sampleLower: -Infinity,
sampleUpper: Infinity
};
if (sample.channelType & KHR_DF_SAMPLE_DATATYPE_SIGNED) {
sample.sampleLower = dfdReader._nextInt32();
sample.sampleUpper = dfdReader._nextInt32();
} else {
sample.sampleLower = dfdReader._nextUint32();
sample.sampleUpper = dfdReader._nextUint32();
}
dfd.samples[i] = sample;
}
container.dataFormatDescriptor.length = 0;
container.dataFormatDescriptor.push(dfd);
const kvdReader = new BufferReader(data, kvdByteOffset, kvdByteLength, true);
while (kvdReader._offset < kvdByteLength) {
const keyValueByteLength = kvdReader._nextUint32();
const keyData = kvdReader._scan(keyValueByteLength);
const key = decodeText(keyData);
container.keyValue[key] = kvdReader._nextUint8Array(keyValueByteLength - keyData.byteLength - 1);
if (key.match(/^ktx/i)) {
const text = decodeText(container.keyValue[key]);
container.keyValue[key] = text.substring(0, text.lastIndexOf("\0"));
}
const kvPadding = keyValueByteLength % 4 ? 4 - keyValueByteLength % 4 : 0;
kvdReader._skip(kvPadding);
}
if (sgdByteLength <= 0)
return container;
const sgdReader = new BufferReader(data, sgdByteOffset, sgdByteLength, true);
const endpointCount = sgdReader._nextUint16();
const selectorCount = sgdReader._nextUint16();
const endpointsByteLength = sgdReader._nextUint32();
const selectorsByteLength = sgdReader._nextUint32();
const tablesByteLength = sgdReader._nextUint32();
const extendedByteLength = sgdReader._nextUint32();
const imageDescs = [];
for (let i = 0; i < levelCount; i++) {
imageDescs.push({
imageFlags: sgdReader._nextUint32(),
rgbSliceByteOffset: sgdReader._nextUint32(),
rgbSliceByteLength: sgdReader._nextUint32(),
alphaSliceByteOffset: sgdReader._nextUint32(),
alphaSliceByteLength: sgdReader._nextUint32()
});
}
const endpointsByteOffset = sgdByteOffset + sgdReader._offset;
const selectorsByteOffset = endpointsByteOffset + endpointsByteLength;
const tablesByteOffset = selectorsByteOffset + selectorsByteLength;
const extendedByteOffset = tablesByteOffset + tablesByteLength;
const endpointsData = new Uint8Array(data.buffer, data.byteOffset + endpointsByteOffset, endpointsByteLength);
const selectorsData = new Uint8Array(data.buffer, data.byteOffset + selectorsByteOffset, selectorsByteLength);
const tablesData = new Uint8Array(data.buffer, data.byteOffset + tablesByteOffset, tablesByteLength);
const extendedData = new Uint8Array(data.buffer, data.byteOffset + extendedByteOffset, extendedByteLength);
container.globalData = {
endpointCount,
selectorCount,
imageDescs,
endpointsData,
selectorsData,
tablesData,
extendedData
};
return container;
}
export {
KHR_DF_FLAG_ALPHA_PREMULTIPLIED,
KHR_DF_FLAG_ALPHA_STRAIGHT,
KHR_DF_KHR_DESCRIPTORTYPE_BASICFORMAT,
KHR_DF_MODEL_UNSPECIFIED,
KHR_DF_PRIMARIES_BT709,
KHR_DF_PRIMARIES_DISPLAYP3,
KHR_DF_PRIMARIES_UNSPECIFIED,
KHR_DF_SAMPLE_DATATYPE_SIGNED,
KHR_DF_TRANSFER_SRGB,
KHR_DF_VENDORID_KHRONOS,
KHR_DF_VERSION,
KHR_SUPERCOMPRESSION_NONE,
KHR_SUPERCOMPRESSION_ZSTD,
KTX2Container,
VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
VK_FORMAT_R16G16B16A16_SFLOAT,
VK_FORMAT_R16G16_SFLOAT,
VK_FORMAT_R16_SFLOAT,
VK_FORMAT_R32G32B32A32_SFLOAT,
VK_FORMAT_R32G32_SFLOAT,
VK_FORMAT_R32_SFLOAT,
VK_FORMAT_R8G8B8A8_SRGB,
VK_FORMAT_R8G8B8A8_UNORM,
VK_FORMAT_R8G8_SRGB,
VK_FORMAT_R8G8_UNORM,
VK_FORMAT_R8_SRGB,
VK_FORMAT_R8_UNORM,
VK_FORMAT_UNDEFINED,
read
};
//# sourceMappingURL=ktx-parse.js.map
File diff suppressed because one or more lines are too long
+13580
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+13581
View File
File diff suppressed because it is too large Load Diff
+1
View File
File diff suppressed because one or more lines are too long
+10749
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+10749
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+12072
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+12072
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+50
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
/**
* ZSTD (Zstandard) decoder.
*/
export declare class ZSTDDecoder {
init(): Promise<void>;
_init(result: WebAssembly.WebAssemblyInstantiatedSource): void;
decode(array: Uint8Array, uncompressedSize?: number): Uint8Array;
}
+50
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long