-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry pick glTF parse support custom extsnions and parser (#1534)
* glTF parse support custom extsnions and parser (#1008) * feat: glTF parse support custom extsnions and parser Co-authored-by: ChenMo <gl3336563@163.com> Co-authored-by: zhuxudong <callzhuxudong@163.com>
- Loading branch information
1 parent
2155a84
commit 6553494
Showing
37 changed files
with
964 additions
and
784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { AssetPromise } from "@galacean/engine-core"; | ||
import { GLTFResource } from "./GLTFResource"; | ||
import { GLTFAnimationParser } from "./parser/GLTFAnimationParser"; | ||
import { GLTFBufferParser } from "./parser/GLTFBufferParser"; | ||
import { GLTFEntityParser } from "./parser/GLTFEntityParser"; | ||
import { GLTFMaterialParser } from "./parser/GLTFMaterialParser"; | ||
import { GLTFMeshParser } from "./parser/GLTFMeshParser"; | ||
import { GLTFParser } from "./parser/GLTFParser"; | ||
import { GLTFParserContext } from "./parser/GLTFParserContext"; | ||
import { GLTFSceneParser } from "./parser/GLTFSceneParser"; | ||
import { GLTFSkinParser } from "./parser/GLTFSkinParser"; | ||
import { GLTFTextureParser } from "./parser/GLTFTextureParser"; | ||
import { GLTFValidator } from "./parser/GLTFValidator"; | ||
|
||
/** | ||
* GLTF pipeline. | ||
*/ | ||
export class GLTFPipeline { | ||
/** | ||
* Default pipeline. | ||
*/ | ||
static defaultPipeline = new GLTFPipeline( | ||
GLTFBufferParser, | ||
GLTFValidator, | ||
GLTFTextureParser, | ||
GLTFMaterialParser, | ||
GLTFMeshParser, | ||
GLTFEntityParser, | ||
GLTFSkinParser, | ||
GLTFAnimationParser, | ||
GLTFSceneParser | ||
); | ||
|
||
private _parsers: GLTFParser[] = []; | ||
|
||
/** | ||
* Constructor of GLTFPipeline. | ||
* @param parsers - Parsers to be executed in order | ||
*/ | ||
constructor(...parsers: (new () => GLTFParser)[]) { | ||
parsers.forEach((pipe: new () => GLTFParser, index: number) => { | ||
this._parsers[index] = new pipe(); | ||
}); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
_parse(context: GLTFParserContext): AssetPromise<GLTFResource> { | ||
const glTFResource = context.glTFResource; | ||
let lastParser; | ||
|
||
return new AssetPromise<GLTFResource>((resolve, reject) => { | ||
this._parsers.forEach((parser: GLTFParser) => { | ||
if (lastParser) { | ||
lastParser = lastParser.then(() => { | ||
return parser.parse(context); | ||
}); | ||
if (lastParser.cancel) { | ||
context.chainPromises.push(lastParser); | ||
} | ||
} else { | ||
lastParser = parser.parse(context); | ||
} | ||
}); | ||
|
||
if (lastParser) { | ||
lastParser | ||
.then(() => { | ||
resolve(glTFResource); | ||
}) | ||
.catch(reject); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
17 changes: 10 additions & 7 deletions
17
packages/loader/src/gltf/extensions/GALACEAN_materials_remap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/loader/src/gltf/extensions/GLTFExtensionParser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { EngineObject } from "@galacean/engine-core"; | ||
import { GLTFExtensionOwnerSchema } from "../GLTFSchema"; | ||
import { GLTFParserContext } from "../parser/GLTFParserContext"; | ||
import { GLTFExtensionSchema } from "./GLTFExtensionSchema"; | ||
|
||
/** | ||
* Base class of glTF extension parser. | ||
*/ | ||
export abstract class GLTFExtensionParser { | ||
/** | ||
* @internal | ||
* The extension mode. | ||
*/ | ||
_mode: GLTFExtensionMode; | ||
|
||
/** | ||
* Initialize the parser. | ||
* @remarks Some plugins require initialization. | ||
* @returns The void or promise | ||
*/ | ||
initialize(): void | Promise<void> {} | ||
|
||
/** | ||
* Create and parse the resource. | ||
* @remarks This method overrides the default resource creation. | ||
* @param context - The parser context | ||
* @param extensionSchema - The extension schema | ||
* @param extensionOwnerSchema - The extension owner schema | ||
* @returns The resource or promise | ||
*/ | ||
createAndParse( | ||
context: GLTFParserContext, | ||
extensionSchema: GLTFExtensionSchema, | ||
extensionOwnerSchema: GLTFExtensionOwnerSchema, | ||
...extra | ||
): EngineObject | Promise<EngineObject> { | ||
throw "Not implemented."; | ||
} | ||
|
||
/** | ||
* Additive parse to the resource. | ||
* @param context - The parser context | ||
* @param parseResource - The parsed resource | ||
* @param extensionSchema - The extension schema | ||
* @param extensionOwnerSchema - The extension owner schema | ||
* @returns The void or promise | ||
*/ | ||
additiveParse( | ||
context: GLTFParserContext, | ||
parseResource: EngineObject, | ||
extensionSchema: GLTFExtensionSchema, | ||
extensionOwnerSchema: GLTFExtensionOwnerSchema, | ||
...extra | ||
): void | Promise<void> { | ||
throw "Not implemented."; | ||
} | ||
} | ||
|
||
/** | ||
* glTF Extension mode. | ||
*/ | ||
export enum GLTFExtensionMode { | ||
/** | ||
* Cerate instance and parse mode. | ||
* @remarks | ||
* If the glTF property has multiple extensions of `CreateAndParse` mode, only execute the last one. | ||
* If this method is registered, the default pipeline processing will be ignored. | ||
*/ | ||
CreateAndParse, | ||
|
||
/** Additive parse mode. */ | ||
AdditiveParse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.