x3d-image 2.3.0 → 2.4.0

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.
package/README.md CHANGED
@@ -46,9 +46,13 @@ The color space in which color calculations take place.
46
46
 
47
47
  Wait the specified number of seconds before generating the image.
48
48
 
49
- ### -e *[**CANNON**, HELIPAD, FOOTPRINT]*
49
+ ### -e *extension(s)* ...
50
50
 
51
- Add an EnvironmentLight node to scene. Useful when rendering glTF files with PhysicalMaterial nodes.
51
+ Set output file extension(s), e.g. ".x3dv" or ".tidy.x3d". The output file will have the same basename as the input file. Use either "-e" or "-o".
52
+
53
+ ### -g
54
+
55
+ Whether to use a logarithmic depth buffer. It may be necessary to use this if dealing with huge differences in scale in a single scene. It is automatically enabled if a GeoViewpoint is bound.
52
56
 
53
57
  ### -h
54
58
 
@@ -60,7 +64,7 @@ Set input file(s). This can be either a local file path or a URL. If there are l
60
64
 
61
65
  ### -l
62
66
 
63
- Whether to use a logarithmic depth buffer. It may be necessary to use this if dealing with huge differences in scale in a single scene. It is automatically enabled if a GeoViewpoint is bound.
67
+ Log output filenames to stdout.
64
68
 
65
69
  ### -m *[**NONE**, ACES_NARKOWICZ, ACES_HILL, ACES_HILL_EXPOSURE_BOOST, KHR_PBR_NEUTRAL]*
66
70
 
@@ -94,6 +98,10 @@ Controls how Text.length and Text.maxExtent are handled. Either by adjusting cha
94
98
 
95
99
  Show version.
96
100
 
101
+ ### -w *[**CANNON**, HELIPAD, FOOTPRINT]*
102
+
103
+ Add an EnvironmentLight node to scene. Useful when rendering glTF files with PhysicalMaterial nodes.
104
+
97
105
  ### -x *exposure*
98
106
 
99
107
  The exposure of an image describes the amount of light that is captured.
@@ -136,7 +144,7 @@ $ npx x3d-image -s 1600x900 -i file1.x3d -o file1.png -i file2.x3d -o file2.png
136
144
  Render image of glTF file with view-all and environment light.
137
145
 
138
146
  ```sh
139
- $ npx x3d-image -a -e CANNON -i file.gltf -o file.png
147
+ $ npx x3d-image -a -w CANNON -i file.gltf -e .png
140
148
  ```
141
149
 
142
150
  ## See Also
package/bin/x3d-image.js CHANGED
@@ -4,15 +4,16 @@
4
4
  const os = require ("os");
5
5
  const path = require ("path");
6
6
  const { spawn } = require ("child_process");
7
- const win = os .platform () === "win32";
8
- const cwd = process .cwd ();
7
+ const dir = process .cwd ();
8
+ const cwd = path .resolve (__dirname, "..");
9
9
  const args = process .argv .slice (2);
10
10
 
11
- process .chdir (path .resolve (__dirname, ".."));
11
+ args .unshift ("start", "--silent", "--");
12
+ args .push ("--cwd", dir);
12
13
 
13
- const p = win
14
- ? spawn ("cmd.exe", ["/c", "npm.cmd", "start", "--silent", "--", ... args], { cwd })
15
- : spawn ("npm", ["start", "--silent", "--", ... args], { cwd });
14
+ const p = os .platform () === "win32"
15
+ ? spawn ("cmd.exe", ["/c", "npm.cmd", ... args], { cwd })
16
+ : spawn ("npm", args, { cwd });
16
17
 
17
18
  p .stdout .pipe (process .stdout);
18
19
  p .stderr .pipe (process .stderr);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x3d-image",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Render image files from X3D",
5
5
  "main": "src/main.js",
6
6
  "bin": {
package/src/image.js CHANGED
@@ -12,7 +12,7 @@ const
12
12
 
13
13
  // Redirect console messages.
14
14
 
15
- process .exit = (code) => electron .ipcRenderer .send ("exit", code);
15
+ process .exit = (code = 0) => { throw code };
16
16
  console .log = (... messages) => electron .ipcRenderer .send ("log", messages);
17
17
  console .warn = (... messages) => electron .ipcRenderer .send ("warn", messages);
18
18
  console .error = (... messages) => electron .ipcRenderer .send ("error", messages);
@@ -29,8 +29,15 @@ async function main (argv)
29
29
  }
30
30
  catch (error)
31
31
  {
32
- console .error (error .message || error);
33
- process .exit (1);
32
+ if (typeof error === "number")
33
+ {
34
+ electron .ipcRenderer .send ("exit", error);
35
+ }
36
+ else
37
+ {
38
+ console .error (error .message || error);
39
+ electron .ipcRenderer .send ("exit", 1);
40
+ }
34
41
  }
35
42
  }
36
43
 
@@ -63,15 +70,17 @@ async function generate (argv)
63
70
  description: `Set background to specified color. Color can be any X3D RGBA color or any CSS color. Use PNG as output image format for transparent backgrounds.`,
64
71
  array: true,
65
72
  default: [ ],
73
+ requiresArg: true,
66
74
  })
67
75
  .option ("colorSpace",
68
76
  {
69
77
  type: "string",
70
78
  alias: "c",
71
79
  description: `The color space in which color calculations take place.`,
72
- choices: ["SRGB", "LINEAR_WHEN_PHYSICAL_MATERIAL", "LINEAR"],
73
80
  array: true,
74
81
  default: ["LINEAR_WHEN_PHYSICAL_MATERIAL"],
82
+ choices: ["SRGB", "LINEAR_WHEN_PHYSICAL_MATERIAL", "LINEAR"],
83
+ requiresArg: true,
75
84
  })
76
85
  .option ("delay",
77
86
  {
@@ -80,15 +89,25 @@ async function generate (argv)
80
89
  description: "Wait the specified number of seconds before generating the image.",
81
90
  array: true,
82
91
  default: [0],
92
+ requiresArg: true,
83
93
  })
84
- .option ("environment-light",
94
+ .option ("extension",
85
95
  {
86
96
  type: "string",
87
97
  alias: "e",
88
- description: `Add an EnvironmentLight node to scene. Useful when rendering glTF files with PhysicalMaterial nodes.`,
89
- choices: ["CANNON", "HELIPAD", "FOOTPRINT"],
98
+ description: `Set output file extension(s), e.g. ".x3dv" or ".tidy.x3d". The output file will have the same basename as the input file.`,
90
99
  array: true,
91
- default: [ ],
100
+ requiresArg: true,
101
+ implies: "input",
102
+ conflicts: "output",
103
+ })
104
+ .option ("logarithmic-depth-buffer",
105
+ {
106
+ type: "boolean",
107
+ alias: "g",
108
+ description: `Whether to use a logarithmic depth buffer. It may be necessary to use this if dealing with huge differences in scale in a single scene. It is automatically enabled if a GeoViewpoint is bound.`,
109
+ array: true,
110
+ default: [false],
92
111
  })
93
112
  .option ("input",
94
113
  {
@@ -96,25 +115,25 @@ async function generate (argv)
96
115
  alias: "i",
97
116
  description: "Set input file(s). If there are less input files than output files, the last input file is used for the remaining output files.",
98
117
  array: true,
99
- default: [ ],
100
- implies: "output",
118
+ requiresArg: true,
119
+ demandOption: true,
101
120
  })
102
- .option ("logarithmic-depth-buffer",
121
+ .option ("log",
103
122
  {
104
123
  type: "boolean",
105
124
  alias: "l",
106
- description: `Whether to use a logarithmic depth buffer. It may be necessary to use this if dealing with huge differences in scale in a single scene. It is automatically enabled if a GeoViewpoint is bound.`,
107
- array: true,
108
- default: [false],
125
+ description: `Log output filenames to stdout.`,
126
+ implies: "input",
109
127
  })
110
128
  .option ("tone-mapping",
111
129
  {
112
130
  type: "string",
113
131
  alias: "m",
114
132
  description: `Whether tone mapping should be applied.`,
115
- choices: ["NONE", "ACES_NARKOWICZ", "ACES_HILL", "ACES_HILL_EXPOSURE_BOOST", "KHR_PBR_NEUTRAL"],
116
133
  array: true,
117
134
  default: ["NONE"],
135
+ choices: ["NONE", "ACES_NARKOWICZ", "ACES_HILL", "ACES_HILL_EXPOSURE_BOOST", "KHR_PBR_NEUTRAL"],
136
+ requiresArg: true,
118
137
  })
119
138
  .option ("order-independent-transparency",
120
139
  {
@@ -130,7 +149,7 @@ async function generate (argv)
130
149
  alias: "o",
131
150
  description: "Set output file(s). This can be either a *.png or *.jpg file.",
132
151
  array: true,
133
- default: [ ],
152
+ requiresArg: true,
134
153
  implies: "input",
135
154
  })
136
155
  .option ("quality",
@@ -140,6 +159,7 @@ async function generate (argv)
140
159
  description: "A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as JPEG).",
141
160
  array: true,
142
161
  default: [1],
162
+ requiresArg: true,
143
163
  })
144
164
  .option ("rotation",
145
165
  {
@@ -148,6 +168,7 @@ async function generate (argv)
148
168
  description: `Creates a parent group with the model as children and sets the specified X3D rotation value.`,
149
169
  array: true,
150
170
  default: [ ],
171
+ requiresArg: true,
151
172
  })
152
173
  .option ("size",
153
174
  {
@@ -156,6 +177,7 @@ async function generate (argv)
156
177
  description: "Set image size in pixels.",
157
178
  array: true,
158
179
  default: ["1280x720"],
180
+ requiresArg: true,
159
181
  })
160
182
  .option ("text-compression",
161
183
  {
@@ -164,6 +186,18 @@ async function generate (argv)
164
186
  description: `Controls how Text.length and Text.maxExtent are handled. Either by adjusting char spacing or by scaling text letters.`,
165
187
  array: true,
166
188
  default: ["CHAR_SPACING"],
189
+ choices: ["CHAR_SPACING", "SCALING"],
190
+ requiresArg: true,
191
+ })
192
+ .option ("environment-light",
193
+ {
194
+ type: "string",
195
+ alias: "w",
196
+ description: `Add an EnvironmentLight node to scene. Useful when rendering glTF files with PhysicalMaterial nodes.`,
197
+ array: true,
198
+ default: [ ],
199
+ choices: ["CANNON", "HELIPAD", "FOOTPRINT"],
200
+ requiresArg: true,
167
201
  })
168
202
  .option ("exposure",
169
203
  {
@@ -172,6 +206,14 @@ async function generate (argv)
172
206
  description: `The exposure of an image describes the amount of light that is captured.`,
173
207
  array: true,
174
208
  default: [1],
209
+ requiresArg: true,
210
+ })
211
+ .check (args =>
212
+ {
213
+ if (!args .output && !args .extension)
214
+ throw new Error ("Missing argument output or extension.");
215
+
216
+ return true;
175
217
  })
176
218
  .example ([
177
219
  [
@@ -183,19 +225,13 @@ async function generate (argv)
183
225
  "Render two PNG images from two X3D files."
184
226
  ],
185
227
  [
186
- "npx x3d-image -a -e CANNON -i file.gltf -o file.png",
228
+ "npx x3d-image -a -w CANNON -i file.gltf -e .png",
187
229
  "Render image of glTF file with view-all and environment light."
188
230
  ],
189
231
  ])
190
232
  .help ()
191
233
  .alias ("help", "h") .argv;
192
234
 
193
- if (args .version)
194
- return;
195
-
196
- if (args .help)
197
- return;
198
-
199
235
  const
200
236
  canvas = document .getElementById ("browser"),
201
237
  browser = canvas .browser;
@@ -204,14 +240,37 @@ async function generate (argv)
204
240
  browser .setBrowserOption ("TextureQuality", "HIGH");
205
241
  browser .setBrowserOption ("Mute", true);
206
242
 
207
- if (!args .input .length)
208
- console .warn ("No input files specified.");
243
+ const argc = Math .max (args .input .length, args .output ?.length ?? args .extension ?.length);
209
244
 
210
- for (const i of args .output .keys ())
245
+ for (let i = 0; i < argc; ++ i)
211
246
  {
247
+ // Create input filename.
248
+
249
+ const input = new URL (arg (args .input, i), url .pathToFileURL (path .join (process .cwd (), "/")));
250
+
251
+ // Create output filename.
252
+
253
+ let output;
254
+
255
+ if (args .output)
256
+ {
257
+ output = path .resolve (process .cwd (), arg (args .output, i));
258
+ }
259
+ else if (args .extension)
260
+ {
261
+ const
262
+ filename = url .fileURLToPath (input),
263
+ extension = arg (args .extension, i);
264
+
265
+ output = `${filename .slice (0, -path. extname (filename) .length)}${extension}`;
266
+ }
267
+
268
+ if (args .log)
269
+ console .log (output);
270
+
271
+ // Load scene.
272
+
212
273
  const
213
- input = new URL (arg (args .input, i), url .pathToFileURL (path .join (process .cwd (), "/"))),
214
- output = path .resolve (process .cwd (), args .output [i]),
215
274
  mimeType = mimeTypeFromPath (output),
216
275
  size = arg (args .size, i) .split ("x"),
217
276
  width = parseInt (size [0]) || 1280,
@@ -259,6 +318,8 @@ async function generate (argv)
259
318
 
260
319
  await browser .nextFrame ();
261
320
 
321
+ // Generate image.
322
+
262
323
  const blob = await generateImage (canvas, mimeType, arg (args .quality, i));
263
324
 
264
325
  fs .writeFileSync (output, new DataView (await blob .arrayBuffer ()));
package/src/main.js CHANGED
@@ -5,6 +5,11 @@ const
5
5
  path = require ("path"),
6
6
  colors = require ("colors");
7
7
 
8
+ // Restore cwd.
9
+
10
+ if (process .argv .at (-2) === "--cwd")
11
+ process .chdir (process .argv .at (-1));
12
+
8
13
  // Set env vars for Electron.
9
14
 
10
15
  process .env .ELECTRON_DISABLE_SECURITY_WARNINGS = "true";