├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── lib └── index.ts ├── package-lock.json ├── package.json ├── tsconfig.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | *.sublime-project 4 | *.sublime-workspace 5 | .DS_Store 6 | Thumbs.db 7 | /node_modules 8 | npm-debug.log* 9 | yarn-debug.log* 10 | 11 | *.js 12 | *.d.ts -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | .idea 3 | .vscode 4 | *.sublime-project 5 | *.sublime-workspace 6 | .DS_Store 7 | Thumbs.db 8 | node_modules 9 | tslint.json 10 | tsconfig.json 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Evolution Gaming 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Babylonjs texture generator 2 | 3 | ## About 4 | 5 | This is a tool that generates PVRTC, ETC1, ETC2, ASTC, DXT textures from png and jpg files. It can run on node or as a gulp task. 6 | 7 | It is meant to work with [Babylon.js](https://github.com/BabylonJS/Babylon.js). The tool is a port of two [.bat files](https://github.com/BabylonJS/Babylon.js/tree/master/Tools/CompressedTextured). 8 | 9 | ## Installation 10 | 11 | In order to use the tool, you need to have installed: 12 | 13 | * PVRTexToolCLI ([download](https://www.imgtec.com/developers/powervr-sdk-tools/installers/)) 14 | * ASTC Evaluation Codec ([download](https://github.com/ARM-software/astc-encoder/tree/master/Binary)) 15 | * Add *ASTC Evaluation Codec* to your path, a process which depends on your OS. ([documentation](http://cdn.imgtec.com/sdk-documentation/PVRTexTool.User+Manual.pdf) at page 5) 16 | * Run `npm run build` in terminal 17 | 18 | ## Usage 19 | 20 | Import/require the exposed function `generateTextures` to your script. It accepts one argument as an object with the following attributes: 21 | 22 | * `PVRTexToolCLI` - *string*: The absolute path to the PVRTexToolCLI tool. 23 | * `inputDir` - *string*: The directory where the image files are located. It will be read recursively and all the images will be used in order to generate the new textures. 24 | * `quality` - *string (optional), (options "low"/"high", default: "high")*: The quality of the exported textures. 25 | * `exportFormats` - *string[] (optional) (options "PVRTC"/"ETC1"/"ETC2"/"ASTC"/"DXT", default: ["PVRTC", "ETC1", "ETC2", "ASTC", "DXT"])*: The format of the exported textures. 26 | * `async` - *boolean (optional, default: false)*: Whether the task should run asynchronously. 27 | 28 | Example usage: 29 | ```javascript 30 | import generateTextures from "babylonjs-texture-generator"; 31 | // Alternatively 32 | // const generateTextures = require("babylonjs-texture-generator"); 33 | 34 | createGpuTexture({ 35 | PVRTexToolCLI: "/Applications/Imagination/PowerVR_Graphics/PowerVR_Tools/PVRTexTool/CLI/OSX_x86/PVRTexToolCLI", 36 | inputDir: "/src", 37 | quality: "high", 38 | async: false, 39 | exportFormats: ["PVRTC", "ETC1", "ETC2", "ASTC", "DXT"] 40 | }); 41 | ``` 42 | 43 | ### Limitations 44 | 45 | Currently DXT files can not be exported on MacOS. 46 | -------------------------------------------------------------------------------- /lib/index.ts: -------------------------------------------------------------------------------- 1 | import { join } from "path"; 2 | import { 3 | stat, statSync, readdir, readdirSync, open, openSync, read, readSync, close, closeSync, Stats, existsSync, 4 | } from "fs"; 5 | import * as shelljs from "shelljs"; 6 | 7 | export enum TextureType { 8 | PVRTC = "PVRTC", 9 | ETC1 = "ETC1", 10 | ETC2 = "ETC2", 11 | ASTC = "ASTC", 12 | DXT = "DXT", 13 | } 14 | 15 | export enum TextureQuality { 16 | HIGH = "high", 17 | LOW = "low", 18 | } 19 | 20 | export interface TextureGeneratorProps { 21 | PVRTexToolCLI: string; 22 | inputDir: string; 23 | quality: TextureQuality; 24 | exportFormats: TextureType[]; 25 | async: boolean; 26 | } 27 | 28 | interface CliConverterProps { 29 | PVRTexToolCLI: string; 30 | file: string; 31 | quality?: string; 32 | hasAlpha?: boolean; 33 | async: boolean; 34 | isCube: boolean; 35 | } 36 | 37 | type ImageConverterProps = CliConverterProps & { exportFormats: string[] }; 38 | 39 | // Cubeface file-name-suffixes in texture's face order. 40 | const cubeFacesSuffixes = ["_px", "_nx", "_py", "_ny", "_pz", "_nz"]; 41 | 42 | /** 43 | * Generates gpu textures from png and jpg files 44 | */ 45 | export default function generateTextures( 46 | { 47 | PVRTexToolCLI, 48 | inputDir, 49 | quality = TextureQuality.HIGH, 50 | exportFormats = [TextureType.PVRTC, TextureType.ETC1, TextureType.ETC2, TextureType.ASTC, TextureType.DXT], 51 | async = false, 52 | }: TextureGeneratorProps) { 53 | // Mac does not support DXT format 54 | const indexOfDXT = exportFormats.indexOf(TextureType.DXT); 55 | if (process.platform === "darwin" && indexOfDXT >= 0) { 56 | console.warn("DXT format is not supported on MacOS"); 57 | exportFormats.splice(indexOfDXT, 1); 58 | } 59 | readImages({ PVRTexToolCLI, inputDir, quality, exportFormats, async }); 60 | } 61 | 62 | function readImages({ PVRTexToolCLI, inputDir, quality, exportFormats, async }: TextureGeneratorProps) { 63 | const openFileOrDir = (stats: Stats, filePath: string, fileName: string) => { 64 | if (stats.isDirectory()) { 65 | readImages({ PVRTexToolCLI, inputDir: filePath, quality, exportFormats, async }); 66 | } else { 67 | const extension = fileName.substr(fileName.lastIndexOf(".") + 1).toLowerCase(); 68 | 69 | const possibleCubeFaces = getCubeTextureFiles(filePath, fileName); 70 | let isCube = false; 71 | if (possibleCubeFaces.length > 0) { 72 | // But only convertImage on the first face 73 | const exp = new RegExp(cubeFacesSuffixes[0] + "." + extension + "$"); 74 | if (!exp.test(fileName)) { 75 | return; 76 | } 77 | isCube = true; 78 | filePath = possibleCubeFaces; 79 | } 80 | 81 | if (["jpg", "jpeg"].indexOf(extension) >= 0) { 82 | convertImage({ PVRTexToolCLI, file: filePath, quality, hasAlpha: false, exportFormats, async, isCube }); 83 | } else if (extension === "png") { 84 | if (async) { 85 | hasAlphaAsync(filePath, (hasAlpha: boolean) => { 86 | convertImage({ 87 | PVRTexToolCLI, 88 | file: filePath, 89 | quality, 90 | hasAlpha, 91 | exportFormats, 92 | async, 93 | isCube, 94 | }); 95 | }); 96 | } else { 97 | convertImage({ 98 | PVRTexToolCLI, 99 | file: filePath, 100 | quality, 101 | hasAlpha: hasAlphaSync(filePath), 102 | exportFormats, 103 | async, 104 | isCube, 105 | }); 106 | } 107 | } 108 | } 109 | }; 110 | if (async) { 111 | readdir(inputDir, (err: NodeJS.ErrnoException, files: string[]) => { 112 | if (err) { 113 | throw err; 114 | } 115 | files.forEach((fileName: string) => { 116 | const filePath = join(inputDir, fileName); 117 | stat(filePath, (statErr: NodeJS.ErrnoException, stats: Stats) => { 118 | if (statErr) { 119 | throw statErr; 120 | } 121 | openFileOrDir(stats, filePath, fileName); 122 | }); 123 | }); 124 | }); 125 | } else { 126 | readdirSync(inputDir).forEach((fileName: string) => { 127 | const filePath = join(inputDir, fileName); 128 | openFileOrDir(statSync(filePath), filePath, fileName); 129 | }); 130 | } 131 | } 132 | 133 | function hasAlphaAsync(file: string, callback: (hasAlpha: boolean) => void) { 134 | const buffer = new Buffer(1); 135 | open(file, "r", (err: NodeJS.ErrnoException, fd: number) => { 136 | if (err) { 137 | throw err; 138 | } 139 | read(fd, buffer, 0, 1, 25, (readErr: NodeJS.ErrnoException, bytesRead: number, buf: Buffer) => { 140 | if (readErr) { 141 | throw readErr; 142 | } 143 | callback(6 === buf[0]); 144 | close(fd, () => { return; }); 145 | }); 146 | }); 147 | } 148 | 149 | function hasAlphaSync(file: string): boolean { 150 | const buffer = new Buffer(1); 151 | const fd: number = openSync(file, "r"); 152 | readSync(fd, buffer, 0, 1, 25); 153 | closeSync(fd); 154 | return 6 === buffer[0]; 155 | } 156 | 157 | function getCubeTextureFiles(filePath: string, fileName: string): string { 158 | const extension = fileName.substr(fileName.lastIndexOf(".") + 1).toLowerCase(); 159 | 160 | const exp = new RegExp("(" + cubeFacesSuffixes.join("|") + ")." + extension + "$"); 161 | let paths = ""; 162 | if (exp.test(fileName)) { 163 | // Check other faces exist 164 | const exp2 = new RegExp(fileName + "$"); 165 | const prePath = filePath.replace(exp2, ""); 166 | const preFileName = fileName.replace(exp, ""); 167 | for (let i = 0; i < cubeFacesSuffixes.length; i++) { 168 | const fpath = prePath + preFileName + cubeFacesSuffixes[i] + "." + extension; 169 | if (existsSync(fpath)) { 170 | paths += fpath + (i === 5 ? "" : ","); 171 | } else { 172 | return ""; 173 | } 174 | } 175 | } 176 | return paths; 177 | } 178 | 179 | function convertImage({ PVRTexToolCLI, file, quality, hasAlpha, exportFormats, async, isCube }: ImageConverterProps) { 180 | if (exportFormats.indexOf(TextureType.PVRTC) >= 0) { 181 | convertToPVRTC({ PVRTexToolCLI, file, quality, hasAlpha, async, isCube }); 182 | } 183 | if (exportFormats.indexOf(TextureType.ETC1) >= 0) { 184 | convertToETC1({ PVRTexToolCLI, file, quality, hasAlpha, async, isCube }); 185 | } 186 | if (exportFormats.indexOf(TextureType.ETC2) >= 0) { 187 | convertToETC2({ PVRTexToolCLI, file, quality, hasAlpha, async, isCube }); 188 | } 189 | if (exportFormats.indexOf(TextureType.ASTC) >= 0) { 190 | convertToASTC({ PVRTexToolCLI, file, quality, async, isCube }); 191 | } 192 | if (exportFormats.indexOf(TextureType.DXT) >= 0) { 193 | convertToDXT({ PVRTexToolCLI, file, hasAlpha, async, isCube }); 194 | } 195 | } 196 | 197 | function convertToPVRTC({ PVRTexToolCLI, file, quality, hasAlpha, async, isCube }: CliConverterProps) { 198 | const filename = isCube 199 | ? file.substr(0, file.split(",")[0].lastIndexOf(cubeFacesSuffixes[0] + ".")) 200 | : file.substr(0, file.lastIndexOf(".")); 201 | const format = hasAlpha ? "PVRTC1_2" : "PVRTC1_2_RGB"; 202 | const fileQuality = quality === TextureQuality.HIGH ? "pvrtcbest" : "pvrtcfastest"; 203 | // tslint:disable:max-line-length 204 | shelljs.exec( 205 | `${PVRTexToolCLI} -i "${file}" ${isCube ? "-cube" : "-flip y"} -pot + -square + -m -dither -f ${format},UBN,lRGB -q ${fileQuality} -o "${filename}-pvrtc.ktx"`, 206 | { async }, 207 | ); 208 | // tslint:enable:max-line-length 209 | } 210 | 211 | function convertToETC1({ PVRTexToolCLI, file, quality, hasAlpha, async, isCube }: CliConverterProps) { 212 | if (hasAlpha) { 213 | return; 214 | } 215 | const filename = isCube 216 | ? file.substr(0, file.split(",")[0].lastIndexOf(cubeFacesSuffixes[0] + ".")) 217 | : file.substr(0, file.lastIndexOf(".")); 218 | const fileQuality = quality === TextureQuality.HIGH ? "etcslowperceptual" : "etcfast"; 219 | // tslint:disable:max-line-length 220 | shelljs.exec( 221 | `${PVRTexToolCLI} -i "${file}" ${isCube ? "-cube" : "-flip y"} -pot + -m -f ETC1,UBN,lRGB -q ${fileQuality} -o "${filename}-etc1.ktx"`, 222 | { async }, 223 | ); 224 | // tslint:enable:max-line-length 225 | } 226 | 227 | function convertToETC2({ PVRTexToolCLI, file, quality, hasAlpha, async, isCube }: CliConverterProps) { 228 | const filename = isCube 229 | ? file.substr(0, file.split(",")[0].lastIndexOf(cubeFacesSuffixes[0] + ".")) 230 | : file.substr(0, file.lastIndexOf(".")); 231 | const format = hasAlpha ? "ETC2_RGBA" : "ETC2_RGB"; 232 | const fileQuality = quality === TextureQuality.HIGH ? "etcslowperceptual" : "etcfast"; 233 | // tslint:disable:max-line-length 234 | shelljs.exec( 235 | `${PVRTexToolCLI} -i "${file}" ${isCube ? "-cube" : "-flip y"} -pot + -m -f ${format},UBN,lRGB -q ${fileQuality} -o "${filename}-etc2.ktx"`, 236 | { async }, 237 | ); 238 | // tslint:enable:max-line-length 239 | } 240 | 241 | function convertToASTC({ PVRTexToolCLI, file, quality, async, isCube }: CliConverterProps) { 242 | const filename = isCube 243 | ? file.substr(0, file.split(",")[0].lastIndexOf(cubeFacesSuffixes[0] + ".")) 244 | : file.substr(0, file.lastIndexOf(".")); 245 | const fileQuality = quality === TextureQuality.HIGH ? "astcexhaustive" : "astcveryfast"; 246 | // tslint:disable:max-line-length 247 | shelljs.exec( 248 | `${PVRTexToolCLI} -i "${file}" ${isCube ? "-cube" : "-flip y"} -pot + -m -f ASTC_8x8,UBN,lRGB -q ${fileQuality} -o "${filename}-astc.ktx"`, 249 | { async }, 250 | ); 251 | // tslint:enable:max-line-length 252 | } 253 | 254 | function convertToDXT({ PVRTexToolCLI, file, hasAlpha, async, isCube }: CliConverterProps) { 255 | const filename = isCube 256 | ? file.substr(0, file.split(",")[0].lastIndexOf(cubeFacesSuffixes[0] + ".")) 257 | : file.substr(0, file.lastIndexOf(".")); 258 | const format = hasAlpha ? "BC2" : "BC1"; 259 | // tslint:disable:max-line-length 260 | shelljs.exec( 261 | `${PVRTexToolCLI} -i "${file}" ${isCube ? "-cube" : "-flip y"} -pot + -m -f ${format},UBN,lRGB -o "${filename}-dxt.ktx"`, 262 | { async }, 263 | ); 264 | // tslint:enable:max-line-length 265 | } 266 | 267 | if (module && module.hasOwnProperty("exports")) { 268 | module.exports = generateTextures; 269 | } 270 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babylonjs-texture-generator", 3 | "version": "1.0.2", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/node": { 8 | "version": "8.0.14", 9 | "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.14.tgz", 10 | "integrity": "sha512-lrtgE/5FeTdcuxgsDbLUIFJ33dTp4TkbKkTDZt/ueUMeqmGYqJRQd908q5Yj9EzzWSMonEhMr1q/CQlgVGEt4w==" 11 | }, 12 | "@types/shelljs": { 13 | "version": "0.7.2", 14 | "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.7.2.tgz", 15 | "integrity": "sha512-NanpA4ybcKXr32Zg7sgHvOfir/AeoOdN7+8TpnWueHkmPhVZLSPWU4LLl7y7d2FG08jaxE18HZjlATjttmjHCQ==", 16 | "requires": { 17 | "@types/node": "8.0.14" 18 | } 19 | }, 20 | "ansi-regex": { 21 | "version": "2.1.1", 22 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", 23 | "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", 24 | "dev": true 25 | }, 26 | "ansi-styles": { 27 | "version": "2.2.1", 28 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", 29 | "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", 30 | "dev": true 31 | }, 32 | "babel-code-frame": { 33 | "version": "6.22.0", 34 | "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.22.0.tgz", 35 | "integrity": "sha1-AnYgvuVnqIwyVhV05/0IAdMxGOQ=", 36 | "dev": true, 37 | "requires": { 38 | "chalk": "1.1.3", 39 | "esutils": "2.0.2", 40 | "js-tokens": "3.0.2" 41 | } 42 | }, 43 | "balanced-match": { 44 | "version": "1.0.0", 45 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 46 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" 47 | }, 48 | "brace-expansion": { 49 | "version": "1.1.8", 50 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", 51 | "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", 52 | "requires": { 53 | "balanced-match": "1.0.0", 54 | "concat-map": "0.0.1" 55 | } 56 | }, 57 | "chalk": { 58 | "version": "1.1.3", 59 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", 60 | "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", 61 | "dev": true, 62 | "requires": { 63 | "ansi-styles": "2.2.1", 64 | "escape-string-regexp": "1.0.5", 65 | "has-ansi": "2.0.0", 66 | "strip-ansi": "3.0.1", 67 | "supports-color": "2.0.0" 68 | } 69 | }, 70 | "colors": { 71 | "version": "1.1.2", 72 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz", 73 | "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=", 74 | "dev": true 75 | }, 76 | "commander": { 77 | "version": "2.11.0", 78 | "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", 79 | "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==", 80 | "dev": true 81 | }, 82 | "concat-map": { 83 | "version": "0.0.1", 84 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 85 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" 86 | }, 87 | "diff": { 88 | "version": "3.3.0", 89 | "resolved": "https://registry.npmjs.org/diff/-/diff-3.3.0.tgz", 90 | "integrity": "sha512-w0XZubFWn0Adlsapj9EAWX0FqWdO4tz8kc3RiYdWLh4k/V8PTb6i0SMgXt0vRM3zyKnT8tKO7mUlieRQHIjMNg==", 91 | "dev": true 92 | }, 93 | "doctrine": { 94 | "version": "0.7.2", 95 | "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-0.7.2.tgz", 96 | "integrity": "sha1-fLhgNZujvpDgQLJrcpzkv6ZUxSM=", 97 | "dev": true, 98 | "requires": { 99 | "esutils": "1.1.6", 100 | "isarray": "0.0.1" 101 | }, 102 | "dependencies": { 103 | "esutils": { 104 | "version": "1.1.6", 105 | "resolved": "https://registry.npmjs.org/esutils/-/esutils-1.1.6.tgz", 106 | "integrity": "sha1-wBzKqa5LiXxtDD4hCuUvPHqEQ3U=", 107 | "dev": true 108 | } 109 | } 110 | }, 111 | "escape-string-regexp": { 112 | "version": "1.0.5", 113 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 114 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", 115 | "dev": true 116 | }, 117 | "esutils": { 118 | "version": "2.0.2", 119 | "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", 120 | "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", 121 | "dev": true 122 | }, 123 | "fs.realpath": { 124 | "version": "1.0.0", 125 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 126 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" 127 | }, 128 | "glob": { 129 | "version": "7.1.2", 130 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", 131 | "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", 132 | "requires": { 133 | "fs.realpath": "1.0.0", 134 | "inflight": "1.0.6", 135 | "inherits": "2.0.3", 136 | "minimatch": "3.0.4", 137 | "once": "1.4.0", 138 | "path-is-absolute": "1.0.1" 139 | } 140 | }, 141 | "has-ansi": { 142 | "version": "2.0.0", 143 | "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", 144 | "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", 145 | "dev": true, 146 | "requires": { 147 | "ansi-regex": "2.1.1" 148 | } 149 | }, 150 | "inflight": { 151 | "version": "1.0.6", 152 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 153 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 154 | "requires": { 155 | "once": "1.4.0", 156 | "wrappy": "1.0.2" 157 | } 158 | }, 159 | "inherits": { 160 | "version": "2.0.3", 161 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 162 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 163 | }, 164 | "interpret": { 165 | "version": "1.0.3", 166 | "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.0.3.tgz", 167 | "integrity": "sha1-y8NcYu7uc/Gat7EKgBURQBr8D5A=" 168 | }, 169 | "isarray": { 170 | "version": "0.0.1", 171 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", 172 | "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", 173 | "dev": true 174 | }, 175 | "js-tokens": { 176 | "version": "3.0.2", 177 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", 178 | "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", 179 | "dev": true 180 | }, 181 | "minimatch": { 182 | "version": "3.0.4", 183 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 184 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 185 | "requires": { 186 | "brace-expansion": "1.1.8" 187 | } 188 | }, 189 | "once": { 190 | "version": "1.4.0", 191 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 192 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 193 | "requires": { 194 | "wrappy": "1.0.2" 195 | } 196 | }, 197 | "path-is-absolute": { 198 | "version": "1.0.1", 199 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 200 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" 201 | }, 202 | "path-parse": { 203 | "version": "1.0.5", 204 | "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", 205 | "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=" 206 | }, 207 | "rechoir": { 208 | "version": "0.6.2", 209 | "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", 210 | "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", 211 | "requires": { 212 | "resolve": "1.3.3" 213 | } 214 | }, 215 | "resolve": { 216 | "version": "1.3.3", 217 | "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz", 218 | "integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=", 219 | "requires": { 220 | "path-parse": "1.0.5" 221 | } 222 | }, 223 | "semver": { 224 | "version": "5.3.0", 225 | "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz", 226 | "integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=", 227 | "dev": true 228 | }, 229 | "shelljs": { 230 | "version": "0.7.8", 231 | "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.8.tgz", 232 | "integrity": "sha1-3svPh0sNHl+3LhSxZKloMEjprLM=", 233 | "requires": { 234 | "glob": "7.1.2", 235 | "interpret": "1.0.3", 236 | "rechoir": "0.6.2" 237 | } 238 | }, 239 | "strip-ansi": { 240 | "version": "3.0.1", 241 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", 242 | "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", 243 | "dev": true, 244 | "requires": { 245 | "ansi-regex": "2.1.1" 246 | } 247 | }, 248 | "supports-color": { 249 | "version": "2.0.0", 250 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", 251 | "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", 252 | "dev": true 253 | }, 254 | "tslib": { 255 | "version": "1.7.1", 256 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.7.1.tgz", 257 | "integrity": "sha1-vIAEFkaRkjp5/oN4u+s9ogF1OOw=", 258 | "dev": true 259 | }, 260 | "tslint": { 261 | "version": "5.5.0", 262 | "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.5.0.tgz", 263 | "integrity": "sha1-EOjas+MGH6YelELozuOYKs8gpqo=", 264 | "dev": true, 265 | "requires": { 266 | "babel-code-frame": "6.22.0", 267 | "colors": "1.1.2", 268 | "commander": "2.11.0", 269 | "diff": "3.3.0", 270 | "glob": "7.1.2", 271 | "minimatch": "3.0.4", 272 | "resolve": "1.3.3", 273 | "semver": "5.3.0", 274 | "tslib": "1.7.1", 275 | "tsutils": "2.7.1" 276 | } 277 | }, 278 | "tslint-eslint-rules": { 279 | "version": "3.4.0", 280 | "resolved": "https://registry.npmjs.org/tslint-eslint-rules/-/tslint-eslint-rules-3.4.0.tgz", 281 | "integrity": "sha1-aU6YgSHkgWi9t4eaPMPJ+QuQofI=", 282 | "dev": true, 283 | "requires": { 284 | "doctrine": "0.7.2" 285 | } 286 | }, 287 | "tsutils": { 288 | "version": "2.7.1", 289 | "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.7.1.tgz", 290 | "integrity": "sha1-QRoOlGZSWisoaSYKVWINcpIVXiQ=", 291 | "dev": true, 292 | "requires": { 293 | "tslib": "1.7.1" 294 | } 295 | }, 296 | "typescript": { 297 | "version": "2.4.1", 298 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.4.1.tgz", 299 | "integrity": "sha1-w8yxbdqgsjFN4DHn5v7onlujRrw=", 300 | "dev": true 301 | }, 302 | "wrappy": { 303 | "version": "1.0.2", 304 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 305 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" 306 | } 307 | } 308 | } 309 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babylonjs-texture-generator", 3 | "version": "1.1.0", 4 | "description": "A tool that generates PVRTC, ETC1, ETC2, ASTC, DXT textures from png and jpg files.", 5 | "main": "index.js", 6 | "types": "index.d.ts", 7 | "scripts": { 8 | "build": "npm run lint && node ./node_modules/typescript/lib/tsc.js", 9 | "lint": "node ./node_modules/tslint/bin/tslint './lib/*.ts' --type-check -p .", 10 | "prepublishOnly": "npm run build", 11 | "start": "node ./node_modules/typescript/lib/tsc.js", 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "author": "Evolution Gaming", 15 | "license": "Apache 2.0", 16 | "repository": "https://github.com/evolution-gaming/babylonjs-texture-generator", 17 | "keywords": [ 18 | "babylonjs", 19 | "textures", 20 | "pvrtc", 21 | "etc1", 22 | "etc2", 23 | "astc", 24 | "pvrtextool", 25 | "pvrtextoolcli" 26 | ], 27 | "dependencies": { 28 | "@types/shelljs": "^0.7.2", 29 | "shelljs": "^0.7.8" 30 | }, 31 | "devDependencies": { 32 | "@types/node": "^8.0.14", 33 | "tslint": "^5.5.0", 34 | "tslint-eslint-rules": "3.4.0", 35 | "typescript": "^2.4.1" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "module": "commonjs", 5 | "outDir": "./", 6 | "strict": true, 7 | "target": "es5" 8 | }, 9 | "files": [ 10 | "lib/index.ts" 11 | ] 12 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["tslint:latest", "tslint-eslint-rules"], 3 | "rules": { 4 | "arrow-parens": false, 5 | "array-type": false, 6 | "ban": [ 7 | true, 8 | [ "_", "forEach" ], 9 | [ "_", "each" ] 10 | ], 11 | "interface-name": [true, "never-prefix"], 12 | "interface-over-type-literal": false, 13 | "import-spacing": false, 14 | "jsx-no-multiline-js": false, 15 | "jsx-wrap-multiline": false, 16 | "jsx-boolean-value": false, 17 | "ban-types": false, 18 | "linebreak-style": [true, "LF"], 19 | "max-classes-per-file": [true, 3], 20 | "no-angle-bracket-type-assertion": true, 21 | "no-default-export": false, 22 | "no-inferrable-types": true, 23 | "no-invalid-this": [ 24 | true, 25 | "check-function-in-method" 26 | ], 27 | "no-null-keyword": false, 28 | "no-require-imports": false, 29 | "no-string-literal": false, 30 | "no-switch-case-fall-through": true, 31 | "no-use-before-declare": true, 32 | "no-var-requires": false, 33 | "object-literal-key-quotes": [true, "consistent-as-needed"], 34 | "object-literal-sort-keys": false, 35 | "ordered-imports": false, 36 | "prefer-for-of": false, 37 | "space-in-parens": [true, "never"], 38 | "triple-equals": [ 39 | true, 40 | "allow-null-check", 41 | "allow-undefined-check" 42 | ], 43 | "variable-name": [ 44 | true, 45 | "check-format", 46 | "allow-leading-underscore", 47 | "ban-keywords", 48 | "allow-pascal-case" 49 | ], 50 | "no-console": false, 51 | "no-constant-condition": true, 52 | "no-control-regex": true, 53 | "no-duplicate-case": true, 54 | "no-empty-character-class": true, 55 | "no-empty-interface": false, 56 | "no-ex-assign": true, 57 | "no-extra-boolean-cast": true, 58 | "no-extra-semi": false, 59 | "no-inner-declarations": [ 60 | true, 61 | "both" 62 | ], 63 | "no-invalid-regexp": true, 64 | "no-irregular-whitespace": true, 65 | "no-regex-spaces": true, 66 | "no-sparse-arrays": true, 67 | "no-unexpected-multiline": true, 68 | "space-before-function-paren": [ 69 | true, 70 | { 71 | "anonymous": "always", 72 | "named": "never", 73 | "asyncArrow": "always" 74 | } 75 | ], 76 | "valid-typeof": true, 77 | "array-bracket-spacing": [ 78 | true, 79 | "never" 80 | ], 81 | "block-spacing": [ 82 | true, 83 | "always" 84 | ], 85 | "brace-style": [ 86 | true, 87 | "1tbs", 88 | { 89 | "allowSingleLine": true 90 | } 91 | ], 92 | "ter-indent": [true, 4, { 93 | "SwitchCase": 1 94 | }], 95 | "object-curly-spacing": [ 96 | true, 97 | "always" 98 | ] 99 | } 100 | } 101 | --------------------------------------------------------------------------------