x3d-image 1.0.95 → 1.0.96
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 +12 -6
- package/package.json +2 -2
- package/src/image.js +42 -20
- package/src/main.js +8 -0
package/README.md
CHANGED
|
@@ -10,19 +10,19 @@ Render image files from X3D.
|
|
|
10
10
|
|
|
11
11
|
You can run *x3d-image* without installing it using **npx**:
|
|
12
12
|
|
|
13
|
-
**npx x3d-image** \[options\]
|
|
13
|
+
**npx x3d-image** \[options\] input-file output-file [input-file output-file ...]
|
|
14
14
|
|
|
15
15
|
## Options
|
|
16
16
|
|
|
17
17
|
**x3d-image** interprets the following options when it is invoked:
|
|
18
18
|
|
|
19
|
-
### -i *file*
|
|
19
|
+
### -i *file* ...
|
|
20
20
|
|
|
21
|
-
Set input file. This can be either a local file path or a URL.
|
|
21
|
+
Set input file(s). This can be either a local file path or a URL. If there are less input files than output files, the last input file is used for the remaining output files.
|
|
22
22
|
|
|
23
|
-
### -o *file*
|
|
23
|
+
### -o *file* ...
|
|
24
24
|
|
|
25
|
-
Set output file.
|
|
25
|
+
Set output file(s).
|
|
26
26
|
|
|
27
27
|
### -s WIDTHxHEIGHT
|
|
28
28
|
|
|
@@ -74,7 +74,13 @@ Show help.
|
|
|
74
74
|
Render an JPEG image from X3D with size 1600x900.
|
|
75
75
|
|
|
76
76
|
```sh
|
|
77
|
-
$ npx x3d-image -s 1600x900
|
|
77
|
+
$ npx x3d-image -s 1600x900 file.x3d file.jpg
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Render an two PNG image from two X3D files.
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
$ npx x3d-image -s 1600x900 file1.x3d file1.png file2.x3d file2.png
|
|
78
84
|
```
|
|
79
85
|
|
|
80
86
|
## See Also
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x3d-image",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.96",
|
|
4
4
|
"description": "Render image files from X3D",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"colors": "^1.4.0",
|
|
55
55
|
"electron": "^33.2.1",
|
|
56
|
-
"x_ite": "^
|
|
56
|
+
"x_ite": "^11.0.0",
|
|
57
57
|
"yargs": "^17.7.2"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
package/src/image.js
CHANGED
|
@@ -36,10 +36,10 @@ async function main (argv)
|
|
|
36
36
|
|
|
37
37
|
async function generate (argv)
|
|
38
38
|
{
|
|
39
|
-
const args = yargs (argv)
|
|
39
|
+
const args = yargs (argv .slice (2))
|
|
40
40
|
.scriptName ("x3d-image")
|
|
41
|
-
.usage ("$0
|
|
42
|
-
.command ("
|
|
41
|
+
.usage ("$0 [options] input-file output-file [input-file output-file ...]")
|
|
42
|
+
.command ("Render image files from X3D")
|
|
43
43
|
.version (pkg .version)
|
|
44
44
|
.alias ("v", "version")
|
|
45
45
|
.fail ((msg, error, yargs) =>
|
|
@@ -51,15 +51,17 @@ async function generate (argv)
|
|
|
51
51
|
{
|
|
52
52
|
type: "string",
|
|
53
53
|
alias: "i",
|
|
54
|
-
description: "Set input file.",
|
|
55
|
-
|
|
54
|
+
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.",
|
|
55
|
+
array: true,
|
|
56
|
+
implies: "output",
|
|
56
57
|
})
|
|
57
58
|
.option ("output",
|
|
58
59
|
{
|
|
59
60
|
type: "string",
|
|
60
61
|
alias: "o",
|
|
61
|
-
description: "Set output file. To output it to stdout use only the extension, e.g. '.x3dv'.",
|
|
62
|
-
|
|
62
|
+
description: "Set output file(s). To output it to stdout use only the extension, e.g. '.x3dv'.",
|
|
63
|
+
array: true,
|
|
64
|
+
implies: "input",
|
|
63
65
|
})
|
|
64
66
|
.option ("size",
|
|
65
67
|
{
|
|
@@ -97,34 +99,54 @@ async function generate (argv)
|
|
|
97
99
|
if (args .help)
|
|
98
100
|
return;
|
|
99
101
|
|
|
102
|
+
args .input ??= [ ];
|
|
103
|
+
args .output ??= [ ];
|
|
104
|
+
|
|
105
|
+
if (args .input .length === 0 && args .output .length === 0)
|
|
106
|
+
{
|
|
107
|
+
if (args ._ .length % 2 === 0)
|
|
108
|
+
{
|
|
109
|
+
for (let i = 0; i < args ._ .length; i += 2)
|
|
110
|
+
{
|
|
111
|
+
args .input .push (args ._ [i + 0]);
|
|
112
|
+
args .output .push (args ._ [i + 1]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
100
116
|
const
|
|
101
117
|
canvas = document .getElementById ("browser"),
|
|
102
118
|
Browser = canvas .browser,
|
|
103
|
-
input = new URL (args .input, url .pathToFileURL (path .join (process .cwd (), "/"))),
|
|
104
|
-
output = path .resolve (process .cwd (), args .output),
|
|
105
119
|
size = args .size .split ("x"),
|
|
106
120
|
width = parseInt (size [0]) || 1280,
|
|
107
|
-
height = parseInt (size [1]) || 720
|
|
108
|
-
mimeType = mimeTypeFromPath (output);
|
|
121
|
+
height = parseInt (size [1]) || 720;
|
|
109
122
|
|
|
110
123
|
Browser .setBrowserOption ("PrimitiveQuality", "HIGH");
|
|
111
124
|
Browser .setBrowserOption ("TextureQuality", "HIGH");
|
|
112
125
|
|
|
113
126
|
await Browser .resize (width, height);
|
|
114
|
-
await Browser .loadURL (new X3D .MFString (input));
|
|
115
127
|
|
|
116
|
-
|
|
128
|
+
for (const i of args .output .keys ())
|
|
117
129
|
{
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
130
|
+
const
|
|
131
|
+
input = new URL (args .input [i] ?? args .input .at (-1), url .pathToFileURL (path .join (process .cwd (), "/"))),
|
|
132
|
+
output = path .resolve (process .cwd (), args .output [i]),
|
|
133
|
+
mimeType = mimeTypeFromPath (output);
|
|
121
134
|
|
|
122
|
-
|
|
123
|
-
await sleep (args .delay * 1000);
|
|
135
|
+
await Browser .loadURL (new X3D .MFString (input));
|
|
124
136
|
|
|
125
|
-
|
|
137
|
+
if (args ["view-all"])
|
|
138
|
+
{
|
|
139
|
+
Browser .viewAll (0);
|
|
140
|
+
await Browser .nextFrame ();
|
|
141
|
+
}
|
|
126
142
|
|
|
127
|
-
|
|
143
|
+
if (args .delay)
|
|
144
|
+
await sleep (args .delay * 1000);
|
|
145
|
+
|
|
146
|
+
const blob = await generateImage (canvas, mimeType, args .quality);
|
|
147
|
+
|
|
148
|
+
fs .writeFileSync (output, new DataView (await blob .arrayBuffer ()));
|
|
149
|
+
}
|
|
128
150
|
|
|
129
151
|
Browser .dispose ();
|
|
130
152
|
}
|
package/src/main.js
CHANGED
|
@@ -5,18 +5,26 @@ const
|
|
|
5
5
|
path = require ("path"),
|
|
6
6
|
colors = require ("colors");
|
|
7
7
|
|
|
8
|
+
// Restore argv.
|
|
9
|
+
|
|
8
10
|
process .argv = process .argv .concat (JSON .parse (atob (process .argv .pop ())));
|
|
9
11
|
process .chdir (process .argv .pop ());
|
|
10
12
|
|
|
13
|
+
// Set env vars for Electron.
|
|
14
|
+
|
|
11
15
|
process .env .ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
|
|
12
16
|
// process .env .ELECTRON_ENABLE_LOGGING = 1;
|
|
13
17
|
|
|
18
|
+
// Hide Electron.
|
|
19
|
+
|
|
14
20
|
if (process .platform === "darwin")
|
|
15
21
|
{
|
|
16
22
|
electron .app .setActivationPolicy ("accessory");
|
|
17
23
|
electron .app .dock .hide ();
|
|
18
24
|
}
|
|
19
25
|
|
|
26
|
+
// Start app and handle events.
|
|
27
|
+
|
|
20
28
|
electron .app .whenReady () .then (async () =>
|
|
21
29
|
{
|
|
22
30
|
const window = new electron .BrowserWindow ({
|