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

Update GLTFExporter / GLTFLoader signatures #196

Merged
merged 4 commits into from
May 2, 2022
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
107 changes: 102 additions & 5 deletions types/three/examples/jsm/exporters/GLTFExporter.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,117 @@
import { Object3D, AnimationClip } from '../../../src/Three';
import { Object3D, AnimationClip, Texture, Material, Mesh } from '../../../src/Three';

export interface GLTFExporterOptions {
binary?: boolean;
/**
* Export position, rotation and scale instead of matrix per node. Default is false
*/
trs?: boolean;

/**
* Export only visible objects. Default is true.
*/
onlyVisible?: boolean;

/**
* Export just the attributes within the drawRange, if defined, instead of exporting the whole array. Default is true.
*/
truncateDrawRange?: boolean;

/**
* Export in binary (.glb) format, returning an ArrayBuffer. Default is false.
*/
binary?: boolean;

/**
* Export with images embedded into the glTF asset. Default is true.
*/
embedImages?: boolean;

/**
* Restricts the image maximum size (both width and height) to the given value. This option works only if embedImages is true. Default is Infinity.
*/
maxTextureSize?: number;

/**
* List of animations to be included in the export.
*/
animations?: AnimationClip[];

/**
* Generate indices for non-index geometry and export with them. Default is false.
*/
forceIndices?: boolean;
forcePowerOfTwoTextures?: boolean;

/**
* Export custom glTF extensions defined on an object's userData.gltfExtensions property. Default is false.
*/
includeCustomExtensions?: boolean;
}

export class GLTFExporter {
constructor();

parse(input: Object3D, onCompleted: (gltf: object) => void, options: GLTFExporterOptions): void;
parseAsync(input: Object3D, options: GLTFExporterOptions): Promise<void>;
register(callback: (writer: GLTFWriter) => GLTFExporterPlugin): this;
unregister(callback: (writer: GLTFWriter) => GLTFExporterPlugin): this;

/**
* Generates a .gltf (JSON) or .glb (binary) output from the input (Scenes or Objects)
*
* @param input Scenes or objects to export. Valid options:
* - Export scenes
* ```js
* exporter.parse( scene1, ... )
* exporter.parse( [ scene1, scene2 ], ... )
* ```
* - Export objects (It will create a new Scene to hold all the objects)
* ```js
* exporter.parse( object1, ... )
* exporter.parse( [ object1, object2 ], ... )
* ```
* - Mix scenes and objects (It will export the scenes as usual but it will create a new scene to hold all the single objects).
* ```js
* exporter.parse( [ scene1, object1, object2, scene2 ], ... )
* ```
* @param onDone Will be called when the export completes. The argument will be the generated glTF JSON or binary ArrayBuffer.
* @param onError Will be called if there are any errors during the gltf generation.
* @param options Export options
*/
parse(
input: Object3D | Object3D[],
onDone: (gltf: ArrayBuffer | { [key: string]: any }) => void,
onError: (error: ErrorEvent) => void,
options?: GLTFExporterOptions,
): void;

parseAsync(
input: Object3D | Object3D[],
options?: GLTFExporterOptions,
): Promise<ArrayBuffer | { [key: string]: any }>;
}

export class GLTFWriter {
constructor();

setPlugins(plugins: GLTFExporterPlugin[]);

/**
* Parse scenes and generate GLTF output
*
* @param input Scene or Array of THREE.Scenes
* @param onDone Callback on completed
* @param options options
*/
write(
input: Object3D | Object3D[],
onDone: (gltf: ArrayBuffer | { [key: string]: any }) => void,
options?: GLTFExporterOptions,
): Promise<void>;
}

export interface GLTFExporterPlugin {
writeTexture?: (map: Texture, textureDef: { [key: string]: any }) => void;
writeMaterial?: (material: Material, materialDef: { [key: string]: any }) => void;
writeMesh?: (mesh: Mesh, meshDef: { [key: string]: any }) => void;
writeNode?: (object: Object3D, nodeDef: { [key: string]: any }) => void;
beforeParse?: (input: Object3D | Object3D[]) => void;
afterParse?: (input: Object3D | Object3D[]) => void;
}
7 changes: 6 additions & 1 deletion types/three/examples/jsm/loaders/GLTFLoader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ export class GLTFParser {

fileLoader: FileLoader;
textureLoader: TextureLoader | ImageBitmapLoader;
plugins: GLTFLoaderPlugin;
plugins: { [name: string]: GLTFLoaderPlugin };
extensions: { [name: string]: any };
associations: Map<Object3D | Material | Texture, GLTFReference>;

setExtensions(extensions: { [name: string]: any }): void;
setPlugins(plugins: { [name: string]: GLTFLoaderPlugin }): void;

parse(onLoad: (gltf: GLTF) => void, onError?: (event: ErrorEvent) => void): void;

getDependency: (type: string, index: number) => Promise<any>;
getDependencies: (type: string) => Promise<any[]>;
loadBuffer: (bufferIndex: number) => Promise<ArrayBuffer>;
Expand Down