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

feat: add skipExtensionInRelativePath flag to avoid ".png" extensions… #494

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions lib/writeResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = writeResources;
* @param {Boolean} [options.separateBuffers=false] Whether to save buffers as separate files.
* @param {Boolean} [options.separateShaders=false] Whether to save shaders as separate files.
* @param {Boolean} [options.separateTextures=false] Whether to save images as separate files.
* @param {Boolean} [options.skipExtensionInRelativePath=false] If set, skip adding the extension to the name of output images.
* @param {Boolean} [options.dataUris=false] Write embedded resources as data uris instead of buffer views.
* @param {Boolean} [options.dracoOptions.uncompressedFallback=false] If set, add uncompressed fallback versions of the compressed meshes.
* @param {Object} [options.bufferStorage] When defined, the glTF buffer's underlying Buffer object will be saved here instead of encoded as a data uri or saved as a separate resource.
Expand Down Expand Up @@ -169,12 +170,14 @@ function getRelativePath(gltf, object, index, extension, options) {
}

const name = getName(gltf, object, index, extension, options);
relativePath = name + extension;

const skipExtension = defaultValue(options.skipExtensionInRelativePath, false);
relativePath = name + (skipExtension ? '' : extension);

// Check if a file of the same name already exists, and if so, append a number
const number = 1;
while (defined(options.separateResources[relativePath])) {
relativePath = name + '_' + number + extension;
relativePath = name + '_' + number + (skipExtension ? '' : extension);
}
return relativePath;
}
Expand Down