x3d-image 2.0.29 → 2.0.31
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 +19 -3
- package/package.json +1 -1
- package/src/image.js +75 -17
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ You can run *x3d-image* without installing it using **npx**:
|
|
|
14
14
|
|
|
15
15
|
## Overview
|
|
16
16
|
|
|
17
|
-
*x3d-image* is a command-line tool that renders image files from X3D (Extensible 3D) and other 3D file formats. It allows users to convert 3D scenes into 2D images, supporting various input formats such as X3D (XML, JSON, Classic VRML), VRML, glTF, OBJ, STL, PLY, and SVG.
|
|
17
|
+
*x3d-image* is a command-line tool based on [X_ITE](https://create3000.github.io/x_ite/) that renders image files from X3D (Extensible 3D) and other 3D file formats. It allows users to convert 3D scenes into 2D images, supporting various input formats such as X3D (XML, JSON, Classic VRML), VRML, glTF, OBJ, STL, PLY, and SVG. Output can be in PNG or JPEG formats.
|
|
18
18
|
|
|
19
19
|
Key Features:
|
|
20
20
|
|
|
@@ -60,7 +60,23 @@ Set background to specified color. Color can be any X3D RGBA color or any CSS co
|
|
|
60
60
|
|
|
61
61
|
### -e *[**CANNON**, HELIPAD, FOOTPRINT]*
|
|
62
62
|
|
|
63
|
-
Add an EnvironmentLight node to scene
|
|
63
|
+
Add an EnvironmentLight node to scene. Useful when rendering glTF files with PhysicalMaterial nodes.
|
|
64
|
+
|
|
65
|
+
### -r rotation
|
|
66
|
+
|
|
67
|
+
Creates a parent group with the model as children and sets the specified X3D rotation value.
|
|
68
|
+
|
|
69
|
+
### -c *[SRGB, **LINEAR_WHEN_PHYSICAL_MATERIAL**, LINEAR]*
|
|
70
|
+
|
|
71
|
+
The color space in which color calculations take place.
|
|
72
|
+
|
|
73
|
+
### -x *exposure*
|
|
74
|
+
|
|
75
|
+
The exposure of an image describes the amount of light that is captured.
|
|
76
|
+
|
|
77
|
+
### -t *[**CHAR_SPACING**, SCALING]*
|
|
78
|
+
|
|
79
|
+
Controls how Text.length and Text.maxExtent are handled. Either by adjusting char spacing or by scaling text letters.
|
|
64
80
|
|
|
65
81
|
### -v
|
|
66
82
|
|
|
@@ -113,4 +129,4 @@ $ npx x3d-image -a -e CANNON -i file.gltf -o file.png
|
|
|
113
129
|
|
|
114
130
|
## See Also
|
|
115
131
|
|
|
116
|
-
x3d-
|
|
132
|
+
* [x3d-tidy](https://www.npmjs.com/package/x3d-tidy) — X3D converter, beautifier and minimizer
|
package/package.json
CHANGED
package/src/image.js
CHANGED
|
@@ -104,17 +104,50 @@ async function generate (argv)
|
|
|
104
104
|
alias: "b",
|
|
105
105
|
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.`,
|
|
106
106
|
array: true,
|
|
107
|
-
default: [
|
|
107
|
+
default: [ ],
|
|
108
108
|
})
|
|
109
109
|
.option ("environment-light",
|
|
110
110
|
{
|
|
111
111
|
type: "string",
|
|
112
112
|
alias: "e",
|
|
113
|
-
description: `Add an EnvironmentLight node to scene
|
|
113
|
+
description: `Add an EnvironmentLight node to scene. Useful when rendering glTF files with PhysicalMaterial nodes.`,
|
|
114
114
|
choices: ["CANNON", "HELIPAD", "FOOTPRINT"],
|
|
115
115
|
array: true,
|
|
116
116
|
default: [ ],
|
|
117
117
|
})
|
|
118
|
+
.option ("rotation",
|
|
119
|
+
{
|
|
120
|
+
type: "string",
|
|
121
|
+
alias: "r",
|
|
122
|
+
description: `Creates a parent group with the model as children and sets the specified X3D rotation value.`,
|
|
123
|
+
array: true,
|
|
124
|
+
default: [ ],
|
|
125
|
+
})
|
|
126
|
+
.option ("colorSpace",
|
|
127
|
+
{
|
|
128
|
+
type: "string",
|
|
129
|
+
alias: "c",
|
|
130
|
+
description: `The color space in which color calculations take place.`,
|
|
131
|
+
choices: ["SRGB", "LINEAR_WHEN_PHYSICAL_MATERIAL", "LINEAR"],
|
|
132
|
+
array: true,
|
|
133
|
+
default: ["LINEAR_WHEN_PHYSICAL_MATERIAL"],
|
|
134
|
+
})
|
|
135
|
+
.option ("exposure",
|
|
136
|
+
{
|
|
137
|
+
type: "number",
|
|
138
|
+
alias: "x",
|
|
139
|
+
description: `The exposure of an image describes the amount of light that is captured.`,
|
|
140
|
+
array: true,
|
|
141
|
+
default: [1],
|
|
142
|
+
})
|
|
143
|
+
.option ("text-compression",
|
|
144
|
+
{
|
|
145
|
+
type: "string",
|
|
146
|
+
alias: "t",
|
|
147
|
+
description: `Controls how Text.length and Text.maxExtent are handled. Either by adjusting char spacing or by scaling text letters.`,
|
|
148
|
+
array: true,
|
|
149
|
+
default: ["CHAR_SPACING"],
|
|
150
|
+
})
|
|
118
151
|
.example ([
|
|
119
152
|
[
|
|
120
153
|
"npx x3d-image -s 1600x900 -i file.x3d -o file.jpg",
|
|
@@ -157,31 +190,41 @@ async function generate (argv)
|
|
|
157
190
|
mimeType = mimeTypeFromPath (output),
|
|
158
191
|
size = arg (args .size, i) .split ("x"),
|
|
159
192
|
width = parseInt (size [0]) || 1280,
|
|
160
|
-
height = parseInt (size [1]) || 720
|
|
161
|
-
color = arg (args .background, i);
|
|
193
|
+
height = parseInt (size [1]) || 720;
|
|
162
194
|
|
|
163
195
|
browser .endUpdate ();
|
|
164
196
|
|
|
165
197
|
await browser .resize (width, height);
|
|
166
198
|
await browser .loadURL (new X3D .MFString (input)) .catch (Function .prototype);
|
|
167
199
|
|
|
168
|
-
if (
|
|
169
|
-
await addBackground (browser, browser .currentScene,
|
|
200
|
+
if (arg (args .background, i))
|
|
201
|
+
await addBackground (browser, browser .currentScene, arg (args .background, i));
|
|
170
202
|
|
|
171
203
|
if (arg (args ["environment-light"], i))
|
|
172
204
|
await addEnvironmentLight (browser, browser .currentScene, arg (args ["environment-light"], i));
|
|
173
205
|
|
|
206
|
+
if (arg (args .rotation, i))
|
|
207
|
+
await addTransform (browser, browser .currentScene, arg (args .rotation, i));
|
|
208
|
+
|
|
209
|
+
if (arg (args .colorSpace, i))
|
|
210
|
+
browser .setBrowserOption ("ColorSpace", arg (args .colorSpace, i));
|
|
211
|
+
|
|
212
|
+
if (arg (args .exposure, i))
|
|
213
|
+
browser .setBrowserOption ("Exposure", arg (args .exposure, i));
|
|
214
|
+
|
|
215
|
+
if (arg (args ["text-compression"], i))
|
|
216
|
+
browser .setBrowserOption ("TextCompression", arg (args ["text-compression"], i));
|
|
217
|
+
|
|
174
218
|
if (arg (args ["view-all"], i))
|
|
175
|
-
{
|
|
176
219
|
browser .viewAll (0);
|
|
177
|
-
await browser .nextFrame ();
|
|
178
|
-
}
|
|
179
220
|
|
|
180
221
|
browser .beginUpdate ();
|
|
181
222
|
|
|
182
223
|
if (arg (args .delay, i))
|
|
183
224
|
await sleep (arg (args .delay, i) * 1000);
|
|
184
225
|
|
|
226
|
+
await browser .nextFrame ();
|
|
227
|
+
|
|
185
228
|
const blob = await generateImage (canvas, mimeType, arg (args .quality, i));
|
|
186
229
|
|
|
187
230
|
fs .writeFileSync (output, new DataView (await blob .arrayBuffer ()));
|
|
@@ -217,11 +260,23 @@ function mimeTypeFromPath (filename)
|
|
|
217
260
|
}
|
|
218
261
|
}
|
|
219
262
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
263
|
+
async function addTransform (browser, scene, rotation)
|
|
264
|
+
{
|
|
265
|
+
scene .addComponent (browser .getComponent ("Grouping"));
|
|
266
|
+
|
|
267
|
+
await browser .loadComponents (scene);
|
|
268
|
+
|
|
269
|
+
const transform = scene .createNode ("Transform");
|
|
270
|
+
|
|
271
|
+
const r = new X3D .SFRotation ();
|
|
272
|
+
|
|
273
|
+
r .fromString (rotation, scene);
|
|
274
|
+
|
|
275
|
+
transform .children = scene .rootNodes;
|
|
276
|
+
transform .rotation = r;
|
|
277
|
+
|
|
278
|
+
scene .rootNodes = new X3D .MFNode (transform);
|
|
279
|
+
}
|
|
225
280
|
|
|
226
281
|
let background = null;
|
|
227
282
|
|
|
@@ -247,10 +302,14 @@ async function addBackground (browser, scene, color)
|
|
|
247
302
|
background .transparency = 1 - c .a;
|
|
248
303
|
|
|
249
304
|
scene .addRootNode (background);
|
|
250
|
-
|
|
251
|
-
await browser .nextFrame ();
|
|
252
305
|
}
|
|
253
306
|
|
|
307
|
+
const EnvironmentLights = new Map ([
|
|
308
|
+
["CANNON", "cannon-exterior:2"],
|
|
309
|
+
["HELIPAD", "helipad:1"],
|
|
310
|
+
["FOOTPRINT", "footprint-court:1"],
|
|
311
|
+
]);
|
|
312
|
+
|
|
254
313
|
let environmentLight = null;
|
|
255
314
|
|
|
256
315
|
async function addEnvironmentLight (browser, scene, name)
|
|
@@ -300,7 +359,6 @@ async function addEnvironmentLight (browser, scene, name)
|
|
|
300
359
|
scene .addRootNode (environmentLight);
|
|
301
360
|
|
|
302
361
|
await Promise .all ([
|
|
303
|
-
browser .nextFrame (),
|
|
304
362
|
environmentLight .diffuseTexture .getValue () .requestImmediateLoad (),
|
|
305
363
|
environmentLight .specularTexture .getValue () .requestImmediateLoad (),
|
|
306
364
|
]);
|