x3d-tidy 2.0.9 → 2.0.10
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 +6 -6
- package/package.json +4 -5
- package/src/infer.js +4 -5
- package/src/main.js +49 -43
package/README.md
CHANGED
|
@@ -10,23 +10,23 @@ X3D converter, beautifier and minimizer
|
|
|
10
10
|
|
|
11
11
|
You can run *x3d-tidy* without installing it using **npx**:
|
|
12
12
|
|
|
13
|
-
**npx x3d-tidy** \[options\] input-file output-file [input-file output-file ...]
|
|
13
|
+
**npx x3d-tidy** \[options\] -i input-file -o output-file [-i input-file -o output-file ...]
|
|
14
14
|
|
|
15
15
|
## Options
|
|
16
16
|
|
|
17
17
|
**x3d-tidy** interprets the following options when it is invoked:
|
|
18
18
|
|
|
19
|
-
### -i *file* ...
|
|
19
|
+
### -i *file(s)* ...
|
|
20
20
|
|
|
21
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(s)* ...
|
|
24
24
|
|
|
25
|
-
Set output file(s).
|
|
25
|
+
Set output file(s). To output it to stdout use only the extension, e.g. ".x3dv".
|
|
26
26
|
|
|
27
27
|
### -s *[**TIDY**, COMPACT, SMALL, CLEAN]*
|
|
28
28
|
|
|
29
|
-
Set output style, default is "TIDY".
|
|
29
|
+
Set output style, default is "TIDY". "TIDY" results in a good readable file, but with larger size, whereas "CLEAN" result in the smallest size possible. The other values are somewhere in between.
|
|
30
30
|
|
|
31
31
|
### -d *integer*
|
|
32
32
|
|
|
@@ -80,7 +80,7 @@ Show help.
|
|
|
80
80
|
Convert an XML encoded file into a VRML encoded file.
|
|
81
81
|
|
|
82
82
|
```sh
|
|
83
|
-
$ npx x3d-tidy file.x3d file.x3dv
|
|
83
|
+
$ npx x3d-tidy -i file.x3d -o file.x3dv
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
Convert an XML encoded file into a VRML encoded file and a JSON encoded file.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x3d-tidy",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "X3D Converter, Beautifier and Minimizer",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -53,10 +53,9 @@
|
|
|
53
53
|
}
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"
|
|
57
|
-
"x_ite": "^
|
|
58
|
-
"
|
|
59
|
-
"x3d-traverse": "^1.0.6",
|
|
56
|
+
"x_ite": "^11.0.1",
|
|
57
|
+
"x_ite-node": "^1.0.20",
|
|
58
|
+
"x3d-traverse": "^1.0.7",
|
|
60
59
|
"yargs": "^17.7.2"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
package/src/infer.js
CHANGED
|
@@ -19,15 +19,14 @@ function getUsedComponents (scene)
|
|
|
19
19
|
{
|
|
20
20
|
const components = new Set ();
|
|
21
21
|
|
|
22
|
-
for (const
|
|
22
|
+
for (const object of scene .traverse (Traverse .PROTO_DECLARATIONS | Traverse .PROTO_DECLARATION_BODY | Traverse .ROOT_NODES | Traverse .PROTOTYPE_INSTANCES))
|
|
23
23
|
{
|
|
24
|
-
if (!(
|
|
24
|
+
if (!(object instanceof X3D .SFNode))
|
|
25
25
|
continue;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
continue;
|
|
27
|
+
const node = object .getValue ();
|
|
29
28
|
|
|
30
|
-
components .add (node .
|
|
29
|
+
components .add (node .getComponentInfo () .name);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
32
|
return components;
|
package/src/main.js
CHANGED
|
@@ -35,6 +35,7 @@ async function convert ()
|
|
|
35
35
|
const args = yargs (hideBin (process .argv))
|
|
36
36
|
.scriptName ("x3d-tidy")
|
|
37
37
|
.usage ("$0 [options] input-file output-file [input-file output-file ...]")
|
|
38
|
+
.wrap (yargs .terminalWidth ())
|
|
38
39
|
.command ("X3D converter, beautifier and minimizer")
|
|
39
40
|
.version (pkg .version)
|
|
40
41
|
.alias ("v", "version")
|
|
@@ -49,84 +50,91 @@ async function convert ()
|
|
|
49
50
|
alias: "i",
|
|
50
51
|
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.",
|
|
51
52
|
array: true,
|
|
53
|
+
default: [ ],
|
|
52
54
|
implies: "output",
|
|
53
55
|
})
|
|
54
56
|
.option ("output",
|
|
55
57
|
{
|
|
56
58
|
type: "string",
|
|
57
59
|
alias: "o",
|
|
58
|
-
description:
|
|
60
|
+
description: `Set output file(s). To output it to stdout use only the extension, e.g. ".x3dv".`,
|
|
59
61
|
array: true,
|
|
62
|
+
default: [ ],
|
|
60
63
|
implies: "input",
|
|
61
64
|
})
|
|
62
65
|
.option ("style",
|
|
63
66
|
{
|
|
64
67
|
type: "string",
|
|
65
68
|
alias: "s",
|
|
66
|
-
description:
|
|
67
|
-
choices: ["
|
|
69
|
+
description: `Set output style, default is "TIDY". "TIDY" results in a good readable file, but with larger size, whereas "CLEAN" result in the smallest size possible. The other values are somewhere in between.`,
|
|
70
|
+
choices: ["TIDY", "COMPACT", "SMALL", "CLEAN"],
|
|
71
|
+
array: true,
|
|
72
|
+
default: ["TIDY"],
|
|
68
73
|
})
|
|
69
74
|
.option ("double",
|
|
70
75
|
{
|
|
71
76
|
type: "number",
|
|
72
77
|
alias: "d",
|
|
73
78
|
description: "Set double precision, default is 15.",
|
|
79
|
+
array: true,
|
|
80
|
+
default: [15],
|
|
74
81
|
})
|
|
75
82
|
.option ("float",
|
|
76
83
|
{
|
|
77
84
|
type: "number",
|
|
78
85
|
alias: "f",
|
|
79
86
|
description: "Set float precision, default is 7.",
|
|
87
|
+
array: true,
|
|
88
|
+
default: [7],
|
|
80
89
|
})
|
|
81
90
|
.option ("infer",
|
|
82
91
|
{
|
|
83
92
|
type: "boolean",
|
|
84
93
|
alias: "r",
|
|
85
94
|
description: "If set, infer profile and components from used nodes.",
|
|
95
|
+
array: true,
|
|
96
|
+
default: [false],
|
|
86
97
|
})
|
|
87
98
|
.option ("metadata",
|
|
88
99
|
{
|
|
89
100
|
type: "boolean",
|
|
90
101
|
alias: "m",
|
|
91
102
|
description: "If set, remove metadata nodes.",
|
|
103
|
+
array: true,
|
|
104
|
+
default: [false],
|
|
92
105
|
})
|
|
106
|
+
.example ([
|
|
107
|
+
[
|
|
108
|
+
"npx x3d-tidy -i file.x3d -o file.x3dv",
|
|
109
|
+
"Convert an XML encoded file into a VRML encoded file."
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"npx x3d-tidy -i file.x3d -o file.x3dv file.x3dj",
|
|
113
|
+
"Convert an XML encoded file into a VRML encoded file and a JSON encoded file."
|
|
114
|
+
],
|
|
115
|
+
])
|
|
93
116
|
.help ()
|
|
94
117
|
.alias ("help", "h") .argv;
|
|
95
118
|
|
|
96
|
-
args .input ??= [ ];
|
|
97
|
-
args .output ??= [ ];
|
|
98
|
-
|
|
99
|
-
if (args .input .length === 0 && args .output .length === 0)
|
|
100
|
-
{
|
|
101
|
-
if (args ._ .length % 2 === 0)
|
|
102
|
-
{
|
|
103
|
-
for (let i = 0; i < args ._ .length; i += 2)
|
|
104
|
-
{
|
|
105
|
-
args .input .push (args ._ [i + 0]);
|
|
106
|
-
args .output .push (args ._ [i + 1]);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
119
|
// Fixes an issue with URL, if it matches a drive letter.
|
|
112
120
|
args .input = args .input .map (input => input .replace (/^([A-Za-z]:)/, "file://$1"));
|
|
113
121
|
|
|
114
122
|
const
|
|
115
|
-
|
|
123
|
+
browser = X3D .createBrowser () .browser,
|
|
116
124
|
scenes = new Map ();
|
|
117
125
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
browser .endUpdate ();
|
|
127
|
+
browser .setBrowserOption ("LoadUrlObjects", false);
|
|
128
|
+
browser .setBrowserOption ("PrimitiveQuality", "HIGH");
|
|
129
|
+
browser .setBrowserOption ("TextureQuality", "HIGH");
|
|
122
130
|
|
|
123
|
-
await
|
|
131
|
+
await browser .loadComponents (browser .getProfile ("Full"));
|
|
124
132
|
|
|
125
133
|
for (const i of args .output .keys ())
|
|
126
134
|
{
|
|
127
135
|
const
|
|
128
|
-
input = new URL (args .input
|
|
129
|
-
scene = scenes .get (input .href) ?? await
|
|
136
|
+
input = new URL (arg (args .input, i), url .pathToFileURL (path .join (process .cwd (), "/"))),
|
|
137
|
+
scene = scenes .get (input .href) ?? await browser .createX3DFromURL (new X3D .MFString (input)),
|
|
130
138
|
generator = scene .getMetaData ("generator") ?.filter (value => !value .startsWith (pkg .name)) ?? [ ];
|
|
131
139
|
|
|
132
140
|
scenes .set (input .href, scene);
|
|
@@ -135,37 +143,35 @@ async function convert ()
|
|
|
135
143
|
scene .setMetaData ("generator", generator);
|
|
136
144
|
scene .setMetaData ("modified", new Date () .toUTCString ());
|
|
137
145
|
|
|
138
|
-
if (args .infer)
|
|
146
|
+
if (arg (args .infer, i))
|
|
139
147
|
infer (scene);
|
|
140
148
|
|
|
141
|
-
if (args .metadata)
|
|
149
|
+
if (arg (args .metadata, i))
|
|
142
150
|
metadata (scene);
|
|
143
151
|
|
|
144
152
|
const options =
|
|
145
153
|
{
|
|
146
154
|
scene: scene,
|
|
147
|
-
style: args .style,
|
|
148
|
-
precision: args .float,
|
|
149
|
-
doublePrecision: args .double,
|
|
155
|
+
style: arg (args .style, i),
|
|
156
|
+
precision: arg (args .float, i),
|
|
157
|
+
doublePrecision: arg (args .double, i),
|
|
150
158
|
};
|
|
151
159
|
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
const output = path .resolve (process .cwd (), args .output [i]);
|
|
160
|
+
const output = path .resolve (process .cwd (), args .output [i]);
|
|
155
161
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
else
|
|
159
|
-
console .log (getContents ({ ... options, type: path .basename (output) }));
|
|
160
|
-
}
|
|
162
|
+
if (path .extname (output))
|
|
163
|
+
fs .writeFileSync (output, getContents ({ ... options, type: path .extname (output) }));
|
|
161
164
|
else
|
|
162
|
-
|
|
163
|
-
console .log (getContents ({ ... options, type: path .extname (input) }));
|
|
164
|
-
}
|
|
165
|
+
console .log (getContents ({ ... options, type: path .basename (output) }));
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
scenes .forEach (scene => scene .dispose ());
|
|
168
|
-
|
|
169
|
+
browser .dispose ();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function arg (arg, i)
|
|
173
|
+
{
|
|
174
|
+
return arg [i] ?? arg .at (-1);
|
|
169
175
|
}
|
|
170
176
|
|
|
171
177
|
function getContents ({ scene, type, style, precision, doublePrecision })
|