x3d-image 2.0.29 → 2.0.30

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.
Files changed (3) hide show
  1. package/README.md +5 -1
  2. package/package.json +1 -1
  3. package/src/image.js +41 -11
package/README.md CHANGED
@@ -60,7 +60,11 @@ 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, default is "CANNON". Useful when rendering glTF files with PhysicalMaterial nodes.
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.
64
68
 
65
69
  ### -v
66
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x3d-image",
3
- "version": "2.0.29",
3
+ "version": "2.0.30",
4
4
  "description": "Render image files from X3D",
5
5
  "main": "src/main.js",
6
6
  "bin": {
package/src/image.js CHANGED
@@ -104,17 +104,25 @@ 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, default is "CANNON". Useful when rendering glTF files with PhysicalMaterial nodes.`,
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
+ })
118
126
  .example ([
119
127
  [
120
128
  "npx x3d-image -s 1600x900 -i file.x3d -o file.jpg",
@@ -157,16 +165,18 @@ async function generate (argv)
157
165
  mimeType = mimeTypeFromPath (output),
158
166
  size = arg (args .size, i) .split ("x"),
159
167
  width = parseInt (size [0]) || 1280,
160
- height = parseInt (size [1]) || 720,
161
- color = arg (args .background, i);
168
+ height = parseInt (size [1]) || 720;
162
169
 
163
170
  browser .endUpdate ();
164
171
 
165
172
  await browser .resize (width, height);
166
173
  await browser .loadURL (new X3D .MFString (input)) .catch (Function .prototype);
167
174
 
168
- if (color .length)
169
- await addBackground (browser, browser .currentScene, color);
175
+ if (arg (args .rotation, i))
176
+ await addTransform (browser, browser .currentScene, arg (args .rotation, i));
177
+
178
+ if (arg (args .background, i))
179
+ await addBackground (browser, browser .currentScene, arg (args .background, i));
170
180
 
171
181
  if (arg (args ["environment-light"], i))
172
182
  await addEnvironmentLight (browser, browser .currentScene, arg (args ["environment-light"], i));
@@ -217,11 +227,25 @@ function mimeTypeFromPath (filename)
217
227
  }
218
228
  }
219
229
 
220
- const EnvironmentLights = new Map ([
221
- ["CANNON", "cannon-exterior:2"],
222
- ["HELIPAD", "helipad:1"],
223
- ["FOOTPRINT", "footprint-court:1"],
224
- ]);
230
+ async function addTransform (browser, scene, rotation)
231
+ {
232
+ scene .addComponent (browser .getComponent ("Grouping"));
233
+
234
+ await browser .loadComponents (scene);
235
+
236
+ const transform = scene .createNode ("Transform");
237
+
238
+ const r = new X3D .SFRotation ();
239
+
240
+ r .fromString (rotation, scene);
241
+
242
+ transform .children = scene .rootNodes;
243
+ transform .rotation = r;
244
+
245
+ scene .rootNodes = new X3D .MFNode (transform);
246
+
247
+ await browser .nextFrame ();
248
+ }
225
249
 
226
250
  let background = null;
227
251
 
@@ -251,6 +275,12 @@ async function addBackground (browser, scene, color)
251
275
  await browser .nextFrame ();
252
276
  }
253
277
 
278
+ const EnvironmentLights = new Map ([
279
+ ["CANNON", "cannon-exterior:2"],
280
+ ["HELIPAD", "helipad:1"],
281
+ ["FOOTPRINT", "footprint-court:1"],
282
+ ]);
283
+
254
284
  let environmentLight = null;
255
285
 
256
286
  async function addEnvironmentLight (browser, scene, name)