x3d-tidy 1.0.0 → 1.0.2
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/.vscode/settings.json +1 -1
- package/README.md +9 -0
- package/bin/x3d-tidy.js +15 -1
- package/package.json +10 -6
- package/src/convert.js +94 -0
- package/src/main.js +32 -0
- package/src/window.html +7 -0
- package/src/window.js +6 -0
- package/test.x3d +32 -0
package/.vscode/settings.json
CHANGED
package/README.md
ADDED
package/bin/x3d-tidy.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
const path = require ("path")
|
|
3
|
+
const { execFile } = require ("child_process")
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
execFile ("electron", [path .resolve (__dirname, ".."), ... process .argv], (error, stdout, stderr) =>
|
|
6
|
+
{
|
|
7
|
+
if (error)
|
|
8
|
+
{
|
|
9
|
+
process .stderr .write (error .message);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (stderr)
|
|
14
|
+
process .stderr .write (stderr);
|
|
15
|
+
|
|
16
|
+
process .stdout .write (stdout);
|
|
17
|
+
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x3d-tidy",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "X3D Beautifier and Minimizer",
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "X3D Converter, Beautifier and Minimizer",
|
|
6
5
|
"bin": {
|
|
7
6
|
"x3d-tidy": "bin/x3d-tidy.js"
|
|
8
7
|
},
|
|
8
|
+
"main": "src/main.js",
|
|
9
9
|
"scripts": {
|
|
10
|
+
"start": "electron .",
|
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
12
|
},
|
|
12
13
|
"repository": {
|
|
@@ -15,17 +16,20 @@
|
|
|
15
16
|
},
|
|
16
17
|
"keywords": [
|
|
17
18
|
"X3D",
|
|
19
|
+
"converter",
|
|
18
20
|
"minimizer",
|
|
19
21
|
"beautifier",
|
|
20
22
|
"tidy"
|
|
21
23
|
],
|
|
22
24
|
"author": "Holger Seelig",
|
|
23
|
-
"license": "GPL",
|
|
25
|
+
"license": "GPL-3.0",
|
|
24
26
|
"bugs": {
|
|
25
27
|
"url": "https://github.com/create3000/x3d-tidy/issues"
|
|
26
28
|
},
|
|
27
29
|
"homepage": "https://github.com/create3000/x3d-tidy#readme",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"electron": "^22.0.0",
|
|
32
|
+
"x_ite": "^8.3.0",
|
|
33
|
+
"yargs": "^17.6.2"
|
|
30
34
|
}
|
|
31
35
|
}
|
package/src/convert.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const
|
|
2
|
+
X3D = require ("x_ite"),
|
|
3
|
+
electron = require ("electron"),
|
|
4
|
+
yargs = require ("yargs"),
|
|
5
|
+
path = require ("path"),
|
|
6
|
+
fs = require ("fs"),
|
|
7
|
+
zlib = require ("zlib")
|
|
8
|
+
|
|
9
|
+
electron .ipcRenderer .on ("convert", async (event, argv) => main (argv))
|
|
10
|
+
|
|
11
|
+
async function main (argv)
|
|
12
|
+
{
|
|
13
|
+
try
|
|
14
|
+
{
|
|
15
|
+
await convert (argv)
|
|
16
|
+
|
|
17
|
+
electron .ipcRenderer .send ("ready")
|
|
18
|
+
}
|
|
19
|
+
catch (error)
|
|
20
|
+
{
|
|
21
|
+
electron .ipcRenderer .send ("error", error .message || error)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function convert (argv)
|
|
26
|
+
{
|
|
27
|
+
const args = yargs (argv) .command ("x3d-tidy", "X3D converter, beautifier and minimizer")
|
|
28
|
+
.fail ((msg, error, yargs) =>
|
|
29
|
+
{
|
|
30
|
+
process .stderr .write (msg)
|
|
31
|
+
process .exit (1)
|
|
32
|
+
})
|
|
33
|
+
.option ("input",
|
|
34
|
+
{
|
|
35
|
+
alias: "i",
|
|
36
|
+
description: "Input filename",
|
|
37
|
+
type: "string",
|
|
38
|
+
demandOption: true,
|
|
39
|
+
})
|
|
40
|
+
.option ("output",
|
|
41
|
+
{
|
|
42
|
+
alias: "o",
|
|
43
|
+
description: "Output filename",
|
|
44
|
+
type: "string",
|
|
45
|
+
})
|
|
46
|
+
.help ()
|
|
47
|
+
.alias ("help", "h") .argv;
|
|
48
|
+
|
|
49
|
+
const
|
|
50
|
+
Browser = X3D .createBrowser () .browser,
|
|
51
|
+
input = path .resolve (process .cwd (), args .input)
|
|
52
|
+
|
|
53
|
+
Browser .endUpdate ()
|
|
54
|
+
|
|
55
|
+
await Browser .loadURL (new X3D .MFString (input))
|
|
56
|
+
|
|
57
|
+
if (args .output)
|
|
58
|
+
{
|
|
59
|
+
const output = path .resolve (process .cwd (), args .output)
|
|
60
|
+
|
|
61
|
+
if (path .extname (output))
|
|
62
|
+
fs .writeFileSync (output, getContents (Browser .currentScene, path .extname (output)))
|
|
63
|
+
else
|
|
64
|
+
process .stdout .write (getContents (Browser .currentScene, path .basename (output)))
|
|
65
|
+
}
|
|
66
|
+
else
|
|
67
|
+
{
|
|
68
|
+
process .stdout .write (getContents (Browser .currentScene, path .extname (input)))
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getContents (scene, type)
|
|
73
|
+
{
|
|
74
|
+
switch (type)
|
|
75
|
+
{
|
|
76
|
+
default:
|
|
77
|
+
case ".x3d":
|
|
78
|
+
return scene .toXMLString ()
|
|
79
|
+
case ".x3dz":
|
|
80
|
+
return zlib .gzipSync (scene .toXMLString ())
|
|
81
|
+
case ".x3dv":
|
|
82
|
+
return scene .toVRMLString ()
|
|
83
|
+
case ".x3dvz":
|
|
84
|
+
return zlib .gzipSync (scene .toVRMLString ())
|
|
85
|
+
case ".x3dj":
|
|
86
|
+
return scene .toJSONString ()
|
|
87
|
+
case ".x3djz":
|
|
88
|
+
return zlib .gzipSync (scene .toJSONString ())
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
process .exit = (status) => electron .ipcRenderer .send (status ? "error" : "ready", "")
|
|
93
|
+
console .log = (s = "") => process .stdout .write (s + "\n")
|
|
94
|
+
console .error = (s = "") => process .stderr .write (s + "\n")
|
package/src/main.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const
|
|
3
|
+
electron = require ("electron"),
|
|
4
|
+
path = require ("path")
|
|
5
|
+
|
|
6
|
+
process .env .ELECTRON_DISABLE_SECURITY_WARNINGS = "true"
|
|
7
|
+
|
|
8
|
+
electron .app .whenReady () .then (async () =>
|
|
9
|
+
{
|
|
10
|
+
const window = new electron .BrowserWindow ({
|
|
11
|
+
show: false,
|
|
12
|
+
webPreferences: {
|
|
13
|
+
offscreen: true,
|
|
14
|
+
preload: path .join (__dirname, "window.js"),
|
|
15
|
+
nodeIntegration: true,
|
|
16
|
+
contextIsolation: false,
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
electron .ipcMain .on ("ready", () => electron .app .quit ())
|
|
21
|
+
|
|
22
|
+
electron .ipcMain .on ("error", (event, message) =>
|
|
23
|
+
{
|
|
24
|
+
process .stderr .write (message)
|
|
25
|
+
process .stderr .write ("\n")
|
|
26
|
+
process .exit (1)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
await window .loadFile (path .join (__dirname, "window.html"))
|
|
30
|
+
|
|
31
|
+
window .webContents .send ("convert", process .argv)
|
|
32
|
+
})
|
package/src/window.html
ADDED
package/src/window.js
ADDED
package/test.x3d
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "http://www.web3d.org/specifications/x3d-3.3.dtd">
|
|
3
|
+
<X3D profile='Interactive' version='4.0' xmlns:xsd='https://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd'>
|
|
4
|
+
<Scene>
|
|
5
|
+
<Background
|
|
6
|
+
skyColor='0.2 0.2 0.2'>
|
|
7
|
+
</Background>
|
|
8
|
+
<Viewpoint
|
|
9
|
+
position='4.75079 5.5764 6.80689'
|
|
10
|
+
orientation='-0.67979594907481 0.70155548858341 0.2137694179717 0.842769006819'>
|
|
11
|
+
</Viewpoint>
|
|
12
|
+
<TouchSensor
|
|
13
|
+
description='Box Geometry'>
|
|
14
|
+
</TouchSensor>
|
|
15
|
+
<Shape>
|
|
16
|
+
<Appearance>
|
|
17
|
+
<Material
|
|
18
|
+
diffuseColor='0 0.5 1'>
|
|
19
|
+
<PixelTexture
|
|
20
|
+
containerField='diffuseTexture'
|
|
21
|
+
image='2 2 1 0xff 0x00 0x00 0xff'>
|
|
22
|
+
<TextureProperties
|
|
23
|
+
boundaryModeS='CLAMP_TO_EDGE'
|
|
24
|
+
boundaryModeT='CLAMP_TO_EDGE'>
|
|
25
|
+
</TextureProperties>
|
|
26
|
+
</PixelTexture>
|
|
27
|
+
</Material>
|
|
28
|
+
</Appearance>
|
|
29
|
+
<Box></Box>
|
|
30
|
+
</Shape>
|
|
31
|
+
</Scene>
|
|
32
|
+
</X3D>
|