Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ktx2 loader #1625

Merged
merged 18 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"preinstall": "npx only-allow pnpm",
"test": "cross-env TS_NODE_PROJECT=tsconfig.tests.json floss --path tests -r ts-node/register",
"test-debug": "cross-env TS_NODE_PROJECT=tsconfig.tests.json floss --path tests -r ts-node/register --debug",
"test-cov": "cross-env TS_NODE_PROJECT=tsconfig.tests.json nyc --reporter=lcov floss --path tests -r ts-node/register",
"test-cov": "cross-env TS_NODE_PROJECT=tsconfig.tests.json IS_COV=1 nyc --reporter=lcov floss --path tests -r ts-node/register",
"build": "npm run b:module && npm run b:types",
"lint": "eslint packages/*/src --ext .ts",
"watch": "cross-env NODE_ENV=development BUILD_TYPE=MODULE rollup -cw -m inline",
Expand Down
23 changes: 15 additions & 8 deletions packages/core/src/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,23 @@ export class Engine extends EventDispatcher {
*/
protected _initialize(configuration: EngineConfiguration): Promise<Engine> {
const physics = configuration.physics;
const initializePromises: Promise<any>[] = [];
if (physics) {
return physics.initialize().then(() => {
PhysicsScene._nativePhysics = physics;
this._nativePhysicsManager = physics.createPhysicsManager();
this._physicsInitialized = true;
return this;
});
} else {
return Promise.resolve(this);
initializePromises.push(
physics.initialize().then(() => {
PhysicsScene._nativePhysics = physics;
this._nativePhysicsManager = physics.createPhysicsManager();
this._physicsInitialized = true;
return this;
})
);
}
const loaders = ResourceManager._loaders;
for (let key in loaders) {
const loader = loaders[key];
if (loader.initialize) initializePromises.push(loader.initialize(this, configuration));
}
return Promise.all(initializePromises).then(() => this);
}

private _createSpriteMaterial(): Material {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/asset/AssetType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export enum AssetType {
KTX = "KTX",
/** Cube Compress Texture. */
KTXCube = "KTXCube",
/** KTX2 Compress Texture */
KTX2 = "KTX2",
/** Sprite. */
Sprite = "Sprite",
/** Sprite Atlas. */
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/asset/Loader.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Engine, EngineConfiguration } from "../Engine";
import { AssetPromise } from "./AssetPromise";
import { LoadItem } from "./LoadItem";
import { request, RequestConfig } from "./request";
Expand Down Expand Up @@ -27,7 +28,7 @@ export abstract class Loader<T> {
private static _engineObjects: { [key: string]: any } = {};

constructor(public readonly useCache: boolean) {}

request: <U>(url: string, config: RequestConfig) => AssetPromise<U> = request;
initialize?(engine: Engine, configuration: EngineConfiguration): Promise<void>;
abstract load(item: LoadItem, resourceManager: ResourceManager): AssetPromise<T> | Record<string, AssetPromise<any>>;
request: <U>(url: string, config: RequestConfig) => AssetPromise<U> = request;
}
4 changes: 2 additions & 2 deletions packages/core/src/asset/ResourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { ReferResource } from "./ReferResource";
* ResourceManager
*/
export class ResourceManager {
/** Loader collection. */
private static _loaders: { [key: string]: Loader<any> } = {};
/** @internal */
static _loaders: { [key: string]: Loader<any> } = {};
private static _extTypeMapping: { [key: string]: string } = {};

/**
Expand Down
52 changes: 26 additions & 26 deletions packages/core/src/texture/enums/TextureFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,61 @@
* Texture format enumeration.
*/
export enum TextureFormat {
/** RGB format,8 bits per channel. */
/** RGB format, 8 bits per channel. */
R8G8B8,
/** RGBA format,8 bits per channel. */
/** RGBA format, 8 bits per channel. */
R8G8B8A8,
/** RGBA format,4 bits per channel. */
/** RGBA format, 4 bits per channel. */
R4G4B4A4,
/** RGBA format,5 bits in R channel,5 bits in G channel,5 bits in B channel, 1 bit in A channel. */
/** RGBA format, 5 bits in R channel, 5 bits in G channel, 5 bits in B channel, 1 bit in A channel. */
R5G5B5A1,
/** RGB format,5 bits in R channel,6 bits in G channel,5 bits in B channel. */
/** RGB format, 5 bits in R channel, 6 bits in G channel, 5 bits in B channel. */
R5G6B5,
/** Transparent format,8 bits. */
/** Transparent format, 8 bits. */
Alpha8,
/** Luminance/alpha in RGB channel, alpha in A channel. */
LuminanceAlpha,
/** RGBA format,16 bits per channel. */
/** RGBA format, 16 bits per channel. */
R16G16B16A16,
/** RGBA format,32 bits per channel. */
/** RGBA format, 32 bits per channel. */
R32G32B32A32,

/** RGB compressed format*/
/** RGB compressed format. */
DXT1,
/** RGBA compressed format*/
/** RGBA compressed format. */
DXT5,
/** RGB compressed format,4 bits per pixel*/
/** RGB compressed format, 4 bits per pixel. */
ETC1_RGB,
/** RGB compressed format,4 bits per pixel*/
/** RGB compressed format, 4 bits per pixel. */
ETC2_RGB,
/** RGBA compressed format,5 bits per pixel,4 bit in RGB, 1 bit in A. */
/** RGBA compressed format, 5 bits per pixel, 4 bit in RGB, 1 bit in A. */
ETC2_RGBA5,
/** RGB compressed format,8 bits per pixel. */
/** RGB compressed format, 8 bits per pixel. */
ETC2_RGBA8,
/** RGB compressed format,2 bits per pixel. */
/** RGB compressed format, 2 bits per pixel. */
PVRTC_RGB2,
/** RGBA compressed format,2 bits per pixel. */
/** RGBA compressed format, 2 bits per pixel. */
PVRTC_RGBA2,
/** RGB compressed format,4 bits per pixel. */
/** RGB compressed format, 4 bits per pixel. */
PVRTC_RGB4,
/** RGBA compressed format,4 bits per pixel. */
/** RGBA compressed format, 4 bits per pixel. */
PVRTC_RGBA4,
/** RGB(A) compressed format,128 bits per 4x4 pixel block. */
/** RGB(A) compressed format, 128 bits per 4x4 pixel block. */
ASTC_4x4,
/** RGB(A) compressed format,128 bits per 5x5 pixel block. */
/** RGB(A) compressed format, 128 bits per 5x5 pixel block. */
ASTC_5x5,
/** RGB(A) compressed format,128 bits per 6x6 pixel block. */
/** RGB(A) compressed format, 128 bits per 6x6 pixel block. */
ASTC_6x6,
/** RGB(A) compressed format,128 bits per 8x8 pixel block. */
/** RGB(A) compressed format, 128 bits per 8x8 pixel block. */
ASTC_8x8,
/** RGB(A) compressed format,128 bits per 10x10 pixel block. */
/** RGB(A) compressed format, 128 bits per 10x10 pixel block. */
ASTC_10x10,
/** RGB(A) compressed format,128 bits per 12x12 pixel block. */
/** RGB(A) compressed format, 128 bits per 12x12 pixel block. */
ASTC_12x12,

/** Automatic depth format,engine will automatically select the supported precision. */
/** Automatic depth format, engine will automatically select the supported precision. */
Depth,
/** Automatic depth setncil format, engine will automatically select the supported precision. */
/** Automatic depth stencil format, engine will automatically select the supported precision. */
DepthStencil,
/** 16-bit depth format. */
Depth16,
Expand Down
9 changes: 6 additions & 3 deletions packages/loader/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./AnimationClipLoader";
import "./AnimatorControllerLoader";
import "./BufferLoader";
import "./EnvLoader";
Expand All @@ -14,11 +15,13 @@ import "./SpriteAtlasLoader";
import "./SpriteLoader";
import "./Texture2DLoader";
import "./TextureCubeLoader";
import "./AnimationClipLoader";
import "./ktx2/KTX2Loader";

export { parseSingleKTX } from "./compressed-texture";
export type { GLTFParams } from "./GLTFLoader";
export * from "./resource-deserialize";
export * from "./SceneLoader";
export type { Texture2DParams } from "./Texture2DLoader";
export { parseSingleKTX } from "./compressed-texture";
export * from "./gltf";
export { KTX2Loader } from "./ktx2/KTX2Loader";
gz65555 marked this conversation as resolved.
Show resolved Hide resolved
export { KTX2TargetFormat } from "./ktx2/KTX2TargetFormat";
GuoLei1990 marked this conversation as resolved.
Show resolved Hide resolved
export * from "./resource-deserialize";
Loading