forked from xianfei/SysMocap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
385 lines (333 loc) · 12.1 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/**
* Main Node Process for SysMocap
*
* A part of SysMocap, open sourced under Mozilla Public License 2.0
*
* https://github.com/xianfei/SysMocap
*
* xianfei 2022.4
*/
// output art text to console
var figlet = require("figlet");
console.log(
"\x1b[95m%s\x1b[0m",
figlet.textSync("SysMocap", {
horizontalLayout: "full",
})
);
console.log(
"\x1b[95m%s\x1b[0m",
"\n Video-based Motion Capture & Character Animation System"
);
console.log("\x1b[94m%s\x1b[0m", "\t\t\t\t\t\tby xianfei");
const sections = [
{
header: "SysMocap",
content:
"A real-time video-based motion capture system for virtual character animating and rendering. It's a free and open-sourced software.",
},
{
header: "Options",
optionList: [
{
name: "help",
type: Boolean,
description: "Print this usage guide.",
},
{
name: "bsmode",
type: Boolean,
description: "Run SysMocap on B/S mode. (experimental)",
},
{
name: "port",
typeLabel: "{underline number}",
description: "The HTTP port when running on B/S mode.",
},
{
name: "reset",
type: Boolean,
description: "Reset preferences and run sysmocap",
},
{
name: "disable-acrylic",
type: Boolean,
description: "(Windows Only) disable acrylic effects",
},
],
},
];
const parser = require("./utils/argv-parser.js");
var argv = parser(process.argv);
if (argv.help) {
var commandLineUsage = require("command-line-usage");
console.log(commandLineUsage(sections));
process.exit(0);
}
if (argv.bsmode) {
console.log("\nRunning SysMocap on B/S mode.\nBooting Server...");
const express = require("express");
const app = express();
app.use(express.static(__dirname));
var port = argv.port ? argv.port : 8080;
app.listen(port, "0.0.0.0", function () {
console.log(
"\x1b[92m%s%d\x1b[0m",
"\nHTTP server listening on port ",
port
);
});
app.get("/", (req, res) => {
res.redirect("/mainview/framework.html");
});
} else {
const { app, BrowserWindow, ipcMain, nativeTheme } = require("electron");
const os = require("os");
const platform = os.platform();
const { Worker } = require("worker_threads");
// Make profile file on user home dir
const path = require("path");
const storage = require("electron-localstorage");
const fs = require("fs");
const _path = path.join(
app.getPath("home"),
app.getName() + "/",
"profile.json"
);
const _path_dir = path.dirname(_path);
if (!fs.existsSync(_path_dir)) {
try {
fs.mkdirSync(_path_dir);
} catch (e) {}
}
storage.setStoragePath(_path);
// Restart with force using the dedicated GPU
const { spawn } = require("child_process");
if (
platform === "win32" &&
// process.env.GPUSET !== "true" &&
storage.getItem("useDgpu")
) {
// Force using discrete GPU when there are multiple GPUs available.
// Improve performance when your PC has discrete GPU
app.commandLine.appendSwitch("force_high_performance_gpu", true);
// spawn(process.execPath, process.argv, {
// env: {
// ...process.env,
// SHIM_MCCOMPAT: "0x800000001", // this forces windows to use the dedicated GPU for the process
// GPUSET: "true",
// },
// detached: true,
// });
// process.exit(0);
}
// Modules to control application life and create native browser window
var blurBrowserWindow;
require("@electron/remote/main").initialize();
// Enable Acrylic Effect on Windows by default
if (platform === "win32")
try {
blurBrowserWindow =
require("electron-acrylic-window").BrowserWindow;
} catch (e) {
blurBrowserWindow = BrowserWindow;
}
// if not on Windows, use electron window
else blurBrowserWindow = BrowserWindow;
global.storagePath = { jsonPath: storage.getStoragePath() };
global.appInfo = { appVersion: app.getVersion(), appName: app.getName() };
// Prevents Chromium from lowering the priority of invisible pages' renderer processes.
// Improve performance when Mocap is running and forward motion data in background
app.commandLine.appendSwitch("disable-renderer-backgrounding", true);
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1180,
height: 750,
titleBarStyle: "hidden",
trafficLightPosition: { x: 15, y: 15 },
// titleBarOverlay: {
// color: '#fff',
// symbolColor: '#111'
// },
webPreferences: {
nodeIntegration: true,
webviewTag: true,
contextIsolation: false,
enableRemoteModule: true,
backgroundThrottling: false,
nodeIntegrationInSubFrames: true,
},
});
// and load the index.html of the app.
mainWindow.loadFile("mainview/framework.html");
nativeTheme.themeSource = "light";
// createWelcomeWindow()
// showDoc()
// Open the DevTools.
// mainWindow.webContents.openDevTools()
require("@electron/remote/main").enable(mainWindow.webContents);
// Emitted when the window is closed.
mainWindow.on("closed", function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
function createModelViewerWindow(args) {
// Create the browser window.
var myBrowserWindow = BrowserWindow;
var addtionalArgs = { backgroundColor: "#eee" };
if (args.useGlass) {
myBrowserWindow = blurBrowserWindow;
addtionalArgs = {
vibrancy: "light",
backgroundColor: "#00000000",
};
}
var viewer = new myBrowserWindow({
width: 820,
height: 540,
titleBarStyle: platform === "darwin" ? "hiddenInset" : "hidden",
autoHideMenuBar: true,
...addtionalArgs,
titleBarOverlay: {
color: args.backgroundColor,
symbolColor: args.color,
},
webPreferences: {
nodeIntegration: true,
webviewTag: true,
contextIsolation: false,
enableRemoteModule: true,
additionalArguments: ["argsData", JSON.stringify(args)],
},
});
// and load the index.html of the app.
viewer.loadFile("modelview/modelview.html");
require("@electron/remote/main").enable(viewer.webContents);
// Open the DevTools.
// viewer.webContents.openDevTools()
// Emitted when the window is closed.
viewer.on("closed", function () {
viewer = null;
});
}
function createPdfViewerWindow(args) {
// Create the browser window.
var viewer = new BrowserWindow({
width: 1180,
height: 750,
autoHideMenuBar: true,
titleBarStyle: "hidden",
trafficLightPosition: { x: 10, y: 8 },
titleBarOverlay: {
color: "#f9f9fa",
symbolColor: "#111111",
},
// vibrancy: "dark",
webPreferences: {
nodeIntegration: true,
webviewTag: true,
contextIsolation: false,
enableRemoteModule: true,
additionalArguments: ["pdfPath", JSON.stringify(args)],
},
});
// and load the index.html of the app.
viewer.loadFile("pdfviewer/viewer.html");
require("@electron/remote/main").enable(viewer.webContents);
// Open the DevTools.
// viewer.webContents.openDevTools()
// Emitted when the window is closed.
viewer.on("closed", function () {
viewer = null;
});
}
function createGpuInfoWindow() {
// Create the browser window.
var viewer = new blurBrowserWindow({
width: 1000,
height: 600,
title: "GPU Info",
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true,
webviewTag: true,
contextIsolation: false,
enableRemoteModule: true,
},
});
// and load the index.html of the app.
viewer.loadURL("chrome://gpu");
// Open the DevTools.
// viewer.webContents.openDevTools()
// Emitted when the window is closed.
viewer.on("closed", function () {
viewer = null;
});
}
function showDoc() {
var docWindow = new BrowserWindow({
width: 1200,
height: 700,
frame: false,
autoHideMenuBar: true,
titleBarStyle: "hidden",
webPreferences: {
nodeIntegration: true,
webviewTag: true,
contextIsolation: false,
enableRemoteModule: true,
},
});
// and load the html of the app.
docWindow.loadFile("documentview/document.html");
require("@electron/remote/main").enable(docWindow.webContents);
docWindow.on("closed", function () {
docWindow = null;
});
// docWindow.toggleDevTools();
}
ipcMain.on("openDocument", function (event, arg) {
showDoc();
});
ipcMain.on("openModelViewer", function (event, arg) {
createModelViewerWindow(arg);
});
ipcMain.on("openGpuInfo", function (event, arg) {
createGpuInfoWindow();
});
ipcMain.on("openPDF", function (event, arg) {
createPdfViewerWindow(arg);
});
ipcMain.on("startWebServer", function (event, ...arg) {
const worker = new Worker(__dirname + "/webserv/worker.js");
worker.postMessage({ type: "startWebServer", arg: arg });
ipcMain.on("sendBoradcast", function (event, arg) {
worker.postMessage({ type: "sendBroadcast", arg: arg });
});
ipcMain.on("stopWebServer", function (event, arg) {
worker.postMessage({ type: "stopWebServer" });
});
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", createWindow);
// Quit when all windows are closed.
app.on("window-all-closed", function () {
app.quit();
});
app.on("activate", function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) createWindow();
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
}