@galacean/engine-loader 1.2.0-alpha.0 → 1.2.0-alpha.2

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.
Files changed (31) hide show
  1. package/dist/main.js +450 -277
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +449 -277
  4. package/dist/module.js +439 -267
  5. package/dist/module.js.map +1 -1
  6. package/package.json +4 -5
  7. package/types/GLTFLoader.d.ts +7 -1
  8. package/types/PrimitiveMeshLoader.d.ts +1 -0
  9. package/types/gltf/GLTFSchema.d.ts +1 -1
  10. package/types/gltf/GLTFUtils.d.ts +1 -1
  11. package/types/gltf/extensions/EXT_meshopt_compression.d.ts +13 -0
  12. package/types/gltf/extensions/GLTFExtensionParser.d.ts +1 -1
  13. package/types/gltf/extensions/GLTFExtensionSchema.d.ts +10 -10
  14. package/types/gltf/extensions/MeshoptDecoder.d.ts +8 -0
  15. package/types/gltf/extensions/index.d.ts +1 -1
  16. package/types/gltf/index.d.ts +2 -1
  17. package/types/gltf/parser/GLTFBufferViewParser.d.ts +5 -0
  18. package/types/gltf/parser/GLTFParser.d.ts +1 -1
  19. package/types/gltf/parser/GLTFParserContext.d.ts +7 -6
  20. package/types/gltf/parser/index.d.ts +2 -1
  21. package/types/index.d.ts +3 -1
  22. package/types/ktx2/BinomialLLCTranscoder/BinomialLLCTranscoder.d.ts +13 -0
  23. package/types/ktx2/BinomialLLCTranscoder/TranscodeWorkerCode.d.ts +33 -0
  24. package/types/ktx2/KTX2Loader.d.ts +4 -3
  25. package/types/ktx2/KhronosTranscoder/KhronosTranscoder.d.ts +17 -0
  26. package/types/ktx2/KhronosTranscoder/TranscoderWorkerCode.d.ts +34 -0
  27. package/types/ktx2/TranscodeResult.d.ts +10 -0
  28. package/types/ktx2/constants.d.ts +7 -0
  29. package/types/ktx2/zstddec.d.ts +62 -0
  30. package/types/resource-deserialize/resources/schema/BasicSchema.d.ts +2 -0
  31. package/types/gltf/parser/GLTFJSONParser.d.ts +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacean/engine-loader",
3
- "version": "1.2.0-alpha.0",
3
+ "version": "1.2.0-alpha.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -15,10 +15,9 @@
15
15
  "types/**/*"
16
16
  ],
17
17
  "dependencies": {
18
- "@galacean/engine-rhi-webgl": "1.2.0-alpha.0",
19
- "@galacean/engine-core": "1.2.0-alpha.0",
20
- "@galacean/engine-draco": "1.2.0-alpha.0",
21
- "@galacean/engine-math": "1.2.0-alpha.0"
18
+ "@galacean/engine-core": "1.2.0-alpha.2",
19
+ "@galacean/engine-math": "1.2.0-alpha.2",
20
+ "@galacean/engine-rhi-webgl": "1.2.0-alpha.2"
22
21
  },
23
22
  "scripts": {
24
23
  "b:types": "tsc"
@@ -1,6 +1,12 @@
1
- import { AssetPromise, Loader, LoadItem, ResourceManager } from "@galacean/engine-core";
1
+ import { AssetPromise, Engine, EngineConfiguration, Loader, LoadItem, ResourceManager } from "@galacean/engine-core";
2
2
  import { GLTFResource } from "./gltf/GLTFResource";
3
3
  export declare class GLTFLoader extends Loader<GLTFResource> {
4
+ /**
5
+ * Release glTF loader memory(includes meshopt workers).
6
+ * @remarks If use loader after releasing, we should release again.
7
+ */
8
+ static release(): void;
9
+ initialize(_: Engine, configuration: EngineConfiguration): Promise<void>;
4
10
  load(item: LoadItem, resourceManager: ResourceManager): AssetPromise<GLTFResource>;
5
11
  }
6
12
  /**
@@ -0,0 +1 @@
1
+ export {};
@@ -419,7 +419,7 @@ export interface IBufferView extends IChildRootProperty {
419
419
  */
420
420
  byteOffset?: number;
421
421
  /**
422
- * The lenth of the bufferView in bytes
422
+ * The length of the bufferView in bytes
423
423
  */
424
424
  byteLength: number;
425
425
  /**
@@ -30,7 +30,7 @@ export declare class GLTFUtils {
30
30
  /**
31
31
  * Get accessor data.
32
32
  */
33
- static processingSparseData(bufferViews: IBufferView[], accessor: IAccessor, buffers: ArrayBuffer[], bufferInfo: BufferInfo): void;
33
+ static processingSparseData(context: GLTFParserContext, accessor: IAccessor, bufferInfo: BufferInfo): Promise<void>;
34
34
  static getIndexFormat(type: AccessorComponentType): IndexFormat;
35
35
  static getElementFormat(type: AccessorComponentType, size: number, normalized?: boolean): VertexElementFormat;
36
36
  /**
@@ -0,0 +1,13 @@
1
+ declare module "@galacean/engine-core" {
2
+ interface EngineConfiguration {
3
+ /** glTF loader options. */
4
+ glTF?: {
5
+ /** Meshopt options. If set this option and workCount is great than 0, workers will be created. */
6
+ meshOpt?: {
7
+ /** Worker count for transcoder, default is 4. */
8
+ workerCount: number;
9
+ };
10
+ };
11
+ }
12
+ }
13
+ export {};
@@ -19,7 +19,7 @@ export declare abstract class GLTFExtensionParser {
19
19
  * @param extensionOwnerSchema - The extension owner schema
20
20
  * @returns The resource or promise
21
21
  */
22
- createAndParse(context: GLTFParserContext, extensionSchema: GLTFExtensionSchema, extensionOwnerSchema: GLTFExtensionOwnerSchema, ...extra: any[]): EngineObject | Promise<EngineObject>;
22
+ createAndParse(context: GLTFParserContext, extensionSchema: GLTFExtensionSchema, extensionOwnerSchema: GLTFExtensionOwnerSchema, ...extra: any[]): EngineObject | Promise<EngineObject | Uint8Array>;
23
23
  /**
24
24
  * Additive parse to the resource.
25
25
  * @param context - The parser context
@@ -18,15 +18,6 @@ export interface IKHRLightsPunctual_Light {
18
18
  export interface IKHRLightsPunctual {
19
19
  lights: IKHRLightsPunctual_Light[];
20
20
  }
21
- /**
22
- * Interfaces from the KHR_draco_mesh_compression extension
23
- */
24
- export interface IKHRDracoMeshCompression {
25
- bufferView: number;
26
- attributes: {
27
- [name: string]: number;
28
- };
29
- }
30
21
  /**
31
22
  * Interfaces from the KHR_materials_clearcoat extension
32
23
  */
@@ -142,6 +133,15 @@ export interface IKHRXmp {
142
133
  export interface IKHRXmp_Node {
143
134
  packet: number;
144
135
  }
136
+ export interface IEXTMeshoptCompressionSchema {
137
+ buffer: number;
138
+ byteOffset?: number;
139
+ byteLength: number;
140
+ byteStride: number;
141
+ mode: "ATTRIBUTES" | "TRIANGLES" | "INDICES";
142
+ count: number;
143
+ filter?: "NONE" | "OCTAHEDRAL" | "QUATERNION" | "EXPONENTIAL";
144
+ }
145
145
  export interface IGalaceanMaterialRemap {
146
146
  refId: string;
147
147
  key?: string;
@@ -154,4 +154,4 @@ export interface IGalaceanAnimation {
154
154
  parameter: any;
155
155
  }[];
156
156
  }
157
- export type GLTFExtensionSchema = IKHRLightsPunctual_Light | IKHRDracoMeshCompression | IKHRMaterialsClearcoat | IKHRMaterialsIor | IKHRMaterialsUnlit | IKHRMaterialsPbrSpecularGlossiness | IKHRMaterialsSheen | IKHRMaterialsSpecular | IKHRMaterialsTransmission | IKHRMaterialsTranslucency | IKHRMaterialVariants_Mapping | IKHRMaterialVariants_Variants | IKHRMaterialsAnisotropy | IKHRTextureBasisU | IKHRTextureTransform | IKHRXmp | IKHRXmp_Node | IGalaceanAnimation | Object;
157
+ export type GLTFExtensionSchema = IKHRLightsPunctual_Light | IKHRMaterialsClearcoat | IKHRMaterialsIor | IKHRMaterialsUnlit | IKHRMaterialsPbrSpecularGlossiness | IKHRMaterialsSheen | IKHRMaterialsSpecular | IKHRMaterialsTransmission | IKHRMaterialsTranslucency | IKHRMaterialVariants_Mapping | IKHRMaterialVariants_Variants | IKHRMaterialsAnisotropy | IKHRTextureBasisU | IKHRTextureTransform | IKHRXmp | IKHRXmp_Node | IGalaceanAnimation | Object;
@@ -0,0 +1,8 @@
1
+ declare const MeshoptDecoder: {
2
+ workerCount: number;
3
+ ready: Promise<void>;
4
+ useWorkers: () => void;
5
+ decodeGltfBuffer: (count: any, stride: any, source: any, mode: any, filter: any) => Promise<Uint8Array>;
6
+ release(): void;
7
+ };
8
+ export { MeshoptDecoder };
@@ -1,4 +1,3 @@
1
- import "./KHR_draco_mesh_compression";
2
1
  import "./KHR_lights_punctual";
3
2
  import "./KHR_materials_clearcoat";
4
3
  import "./KHR_materials_ior";
@@ -14,6 +13,7 @@ import "./KHR_texture_transform";
14
13
  import "./KHR_materials_ior";
15
14
  import "./GALACEAN_materials_remap";
16
15
  import "./GALACEAN_animation_event";
16
+ import "./EXT_meshopt_compression";
17
17
  import "./KHR_materials_anisotropy";
18
18
  export { GLTFExtensionParser, GLTFExtensionMode } from "./GLTFExtensionParser";
19
19
  export * from "./GLTFExtensionSchema";
@@ -2,4 +2,5 @@ export { GLTFResource } from "./GLTFResource";
2
2
  export { GLTFUtils } from "./GLTFUtils";
3
3
  export * from "./parser";
4
4
  export * from "./extensions/index";
5
- export type { IMaterial, IMeshPrimitive, ITextureInfo, INode, GLTFExtensionOwnerSchema } from "./GLTFSchema";
5
+ export { AccessorType } from "./GLTFSchema";
6
+ export type { IMaterial, IMeshPrimitive, ITextureInfo, INode, GLTFExtensionOwnerSchema, IGLTF, IMesh } from "./GLTFSchema";
@@ -0,0 +1,5 @@
1
+ import { GLTFParserContext } from "./GLTFParserContext";
2
+ import { GLTFParser } from "./GLTFParser";
3
+ export declare class GLTFBufferViewParser extends GLTFParser {
4
+ parse(context: GLTFParserContext, index: number): Promise<Uint8Array>;
5
+ }
@@ -17,7 +17,7 @@ export declare abstract class GLTFParser {
17
17
  */
18
18
  static executeExtensionsCreateAndParse(extensions: {
19
19
  [key: string]: any;
20
- }, context: GLTFParserContext, ownerSchema: GLTFExtensionOwnerSchema, ...extra: any[]): EngineObject | void | Promise<EngineObject | void>;
20
+ }, context: GLTFParserContext, ownerSchema: GLTFExtensionOwnerSchema, ...extra: any[]): EngineObject | void | Promise<EngineObject | Uint8Array | void>;
21
21
  /**
22
22
  * Execute all parses of extension to parse resource.
23
23
  * @param extensions - Related extensions field
@@ -59,11 +59,12 @@ export declare enum GLTFParserType {
59
59
  Validator = 1,
60
60
  Scene = 2,
61
61
  Buffer = 3,
62
- Texture = 4,
63
- Material = 5,
64
- Mesh = 6,
65
- Entity = 7,
66
- Skin = 8,
67
- Animation = 9
62
+ BufferView = 4,
63
+ Texture = 5,
64
+ Material = 6,
65
+ Mesh = 7,
66
+ Entity = 8,
67
+ Skin = 9,
68
+ Animation = 10
68
69
  }
69
70
  export declare function registerGLTFParser(pipeline: GLTFParserType): (Parser: new () => GLTFParser) => void;
@@ -9,4 +9,5 @@ export { GLTFSceneParser } from "./GLTFSceneParser";
9
9
  export { GLTFSkinParser } from "./GLTFSkinParser";
10
10
  export { GLTFTextureParser } from "./GLTFTextureParser";
11
11
  export { GLTFValidator } from "./GLTFValidator";
12
- export { GLTFParserContext, GLTFParserType, registerGLTFParser } from "./GLTFParserContext";
12
+ export { GLTFParserContext, GLTFParserType, registerGLTFParser, BufferInfo } from "./GLTFParserContext";
13
+ export { GLTFBufferViewParser } from "./GLTFBufferViewParser";
package/types/index.d.ts CHANGED
@@ -10,13 +10,15 @@ import "./KTXCubeLoader";
10
10
  import "./KTXLoader";
11
11
  import "./MaterialLoader";
12
12
  import "./MeshLoader";
13
+ import "./PrimitiveMeshLoader";
14
+ import "./ProjectLoader";
13
15
  import "./SourceFontLoader";
14
16
  import "./SpriteAtlasLoader";
15
17
  import "./SpriteLoader";
16
18
  import "./Texture2DLoader";
17
19
  import "./TextureCubeLoader";
18
- import "./ProjectLoader";
19
20
  import "./ktx2/KTX2Loader";
21
+ export { GLTFLoader } from "./GLTFLoader";
20
22
  export type { GLTFParams } from "./GLTFLoader";
21
23
  export * from "./SceneLoader";
22
24
  export type { Texture2DParams } from "./Texture2DLoader";
@@ -0,0 +1,13 @@
1
+ import { KTX2TargetFormat } from "../KTX2TargetFormat";
2
+ import { TranscodeResult } from "../TranscodeResult";
3
+ /** @internal */
4
+ export declare class BinomialLLCTranscoder {
5
+ readonly workerLimit: number;
6
+ static MessageId: number;
7
+ private _transcodeWorkerPool;
8
+ private _initPromise;
9
+ constructor(workerLimit: number);
10
+ init(): Promise<any>;
11
+ transcode(buffer: ArrayBuffer, format: KTX2TargetFormat): Promise<TranscodeResult>;
12
+ destroy(): void;
13
+ }
@@ -0,0 +1,33 @@
1
+ type MessageType = "init" | "transcode";
2
+ export interface IBaseMessage {
3
+ type: MessageType;
4
+ }
5
+ export interface IInitMessage extends IBaseMessage {
6
+ type: "init";
7
+ transcoderWasm: ArrayBuffer;
8
+ }
9
+ export interface ITranscodeMessage extends IBaseMessage {
10
+ type: "transcode";
11
+ format: number;
12
+ buffer: ArrayBuffer;
13
+ }
14
+ export type IMessage = IInitMessage | ITranscodeMessage;
15
+ export type TranscodeResult = {
16
+ width: number;
17
+ height: number;
18
+ hasAlpha: boolean;
19
+ format: number;
20
+ faces: Array<{
21
+ data: Uint8Array;
22
+ width: number;
23
+ height: number;
24
+ }>[];
25
+ faceCount: number;
26
+ };
27
+ export type TranscodeResponse = {
28
+ id: number;
29
+ type: "transcoded";
30
+ } & TranscodeResult;
31
+ /** @internal */
32
+ export declare function TranscodeWorkerCode(): void;
33
+ export {};
@@ -8,9 +8,10 @@ export declare class KTX2Loader extends Loader<Texture2D | TextureCube> {
8
8
  private static _priorityFormats;
9
9
  private static _supportedMap;
10
10
  /**
11
- * Destroy ktx2 transcoder worker.
11
+ * Release ktx2 transcoder worker.
12
+ * @remarks If use loader after releasing, we should release again.
12
13
  */
13
- static destroy(): void;
14
+ static release(): void;
14
15
  /** @internal */
15
16
  static _parseBuffer(buffer: Uint8Array, engine: Engine, params?: KTX2Params): Promise<{
16
17
  engine: Engine;
@@ -50,7 +51,7 @@ export declare enum KTX2Transcoder {
50
51
  }
51
52
  declare module "@galacean/engine-core" {
52
53
  interface EngineConfiguration {
53
- /** KTX2 loader options. */
54
+ /** KTX2 loader options. If set this option and workCount is great than 0, workers will be created. */
54
55
  ktx2Loader?: {
55
56
  /** Worker count for transcoder, default is 4. */
56
57
  workerCount?: number;
@@ -0,0 +1,17 @@
1
+ import { KTX2Container } from "../KTX2Container";
2
+ import { KTX2TargetFormat } from "../KTX2TargetFormat";
3
+ import { TranscodeResult } from "./TranscoderWorkerCode";
4
+ /** @internal */
5
+ export declare class KhronosTranscoder {
6
+ readonly workerLimit: number;
7
+ readonly type: KTX2TargetFormat;
8
+ static transcoderMap: {
9
+ 0: string;
10
+ };
11
+ private _transcodeWorkerPool;
12
+ private _initPromise;
13
+ constructor(workerLimit: number, type: KTX2TargetFormat);
14
+ init(): Promise<any>;
15
+ transcode(ktx2Container: KTX2Container): Promise<TranscodeResult>;
16
+ destroy(): void;
17
+ }
@@ -0,0 +1,34 @@
1
+ export interface EncodedData {
2
+ buffer: Uint8Array;
3
+ levelWidth: number;
4
+ levelHeight: number;
5
+ uncompressedByteLength: number;
6
+ }
7
+ type MessageType = "init" | "transcode";
8
+ export interface IBaseMessage {
9
+ type: MessageType;
10
+ }
11
+ export interface IInitMessage extends IBaseMessage {
12
+ type: "init";
13
+ transcoderWasm: ArrayBuffer;
14
+ }
15
+ export interface ITranscodeMessage extends IBaseMessage {
16
+ type: "transcode";
17
+ format: number;
18
+ needZstd: boolean;
19
+ data: EncodedData[][];
20
+ }
21
+ export type IMessage = IInitMessage | ITranscodeMessage;
22
+ export type TranscodeResult = {
23
+ data: Array<{
24
+ data: Uint8Array;
25
+ width: number;
26
+ height: number;
27
+ }>;
28
+ };
29
+ export type TranscodeResponse = {
30
+ id: number;
31
+ type: "transcoded";
32
+ } & TranscodeResult;
33
+ export declare function TranscodeWorkerCode(): void;
34
+ export {};
@@ -0,0 +1,10 @@
1
+ export interface TranscodeResult {
2
+ width: number;
3
+ height: number;
4
+ hasAlpha: boolean;
5
+ mipmaps: Array<{
6
+ data: Uint8Array;
7
+ width: number;
8
+ height: number;
9
+ }>;
10
+ }
@@ -0,0 +1,7 @@
1
+ export declare enum SupercompressionScheme {
2
+ None = 0,
3
+ BasisLZ = 1,
4
+ Zstd = 2,
5
+ ZLib = 3
6
+ }
7
+ export declare const KHR_DF_SAMPLE_DATATYPE_SIGNED = 64;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * From https://github.com/donmccurdy/zstddec by Don McCurdy
3
+ */
4
+ interface DecoderExports {
5
+ memory: Uint8Array;
6
+ ZSTD_findDecompressedSize: (compressedPtr: number, compressedSize: number) => number;
7
+ ZSTD_decompress: (uncompressedPtr: number, uncompressedSize: number, compressedPtr: number, compressedSize: number) => number;
8
+ malloc: (ptr: number) => number;
9
+ free: (ptr: number) => void;
10
+ }
11
+ /**
12
+ * ZSTD (Zstandard) decoder.
13
+ */
14
+ export declare class ZSTDDecoder {
15
+ static heap: Uint8Array;
16
+ static IMPORT_OBJECT: {
17
+ env: {
18
+ emscripten_notify_memory_growth: () => void;
19
+ };
20
+ };
21
+ static instance: {
22
+ exports: DecoderExports;
23
+ };
24
+ static WasmModuleURL: string;
25
+ _initPromise: Promise<any>;
26
+ init(): Promise<void>;
27
+ _init(result: WebAssembly.WebAssemblyInstantiatedSource): void;
28
+ decode(array: Uint8Array, uncompressedSize?: number): Uint8Array;
29
+ }
30
+ export {};
31
+ /**
32
+ * BSD License
33
+ *
34
+ * For Zstandard software
35
+ *
36
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.
37
+ *
38
+ * Redistribution and use in source and binary forms, with or without modification,
39
+ * are permitted provided that the following conditions are met:
40
+ *
41
+ * * Redistributions of source code must retain the above copyright notice, this
42
+ * list of conditions and the following disclaimer.
43
+ *
44
+ * * Redistributions in binary form must reproduce the above copyright notice,
45
+ * this list of conditions and the following disclaimer in the documentation
46
+ * and/or other materials provided with the distribution.
47
+ *
48
+ * * Neither the name Facebook nor the names of its contributors may be used to
49
+ * endorse or promote products derived from this software without specific
50
+ * prior written permission.
51
+ *
52
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
53
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
56
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
57
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
58
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
59
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62
+ */
@@ -1,3 +1,4 @@
1
+ import { Layer } from "@galacean/engine-core";
1
2
  export interface IVector3 {
2
3
  x: number;
3
4
  y: number;
@@ -33,6 +34,7 @@ export interface IBasicEntity {
33
34
  scale?: IVector3;
34
35
  children?: Array<string>;
35
36
  parent?: string;
37
+ layer?: Layer;
36
38
  }
37
39
  export type IEntity = IBasicEntity | IRefEntity;
38
40
  export interface IRefEntity extends IBasicEntity {
@@ -1,7 +0,0 @@
1
- import { IGLTF } from "../GLTFSchema";
2
- import { GLTFParser } from "./GLTFParser";
3
- import { GLTFParserContext } from "./GLTFParserContext";
4
- export declare class GLTFJSONParser extends GLTFParser {
5
- parse(context: GLTFParserContext): Promise<IGLTF>;
6
- private _isGLB;
7
- }