-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
110 lines (86 loc) · 3.26 KB
/
index.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
const HFS = 'C:\\Program Files\\Side Effects Software\\Houdini 18.0.597';
// this is necessary in order that the module can find the Houdini dll libraries from the place it expects to:
process.env.PATH = `${HFS}\\bin;${process.env.PATH}`;
process.env.HFS = HFS;
const hapi = require('bindings')('hapi.node');
const net = require('net');
const HOST = 'localhost';
const PORT = 8080;
const client = new net.Socket();
const path = require('path');
const fs = require('fs');
const directoryPath_WAITING = path.join(__dirname, 'client/data/forLoading/done'); //dump when done processing
const directoryPath_THREEJS = path.join(__dirname, 'client/data/forLoading/THREE'); //give
const directoryPath_HOUDINI = path.join(__dirname, 'client/data/forLoading/HOUDINI'); //get
const { spawn, exec, execFile } = require('child_process');
const { spawnSync, execSync, execFileSync } = require( 'child_process' );
let state = {
files: {},
}
exports.state = state;
client.connect(PORT, HOST, function() {
console.log('CONNECTED TO: ' + HOST +':'+ PORT);
// GPT will create the kind of data used and sent by these calls in and out of node-hapi.cpp
console.log('test');
//TODO: make one import and one export after testing FBX
//for now "make" an object/scene and save as .hip .obj .FBX
//TODO: use pass-in for declaring what ext type
//hapi.make_OBJ();
hapi.load_hdanc();
//hapi.import_FBX(); //TODO: commented out while working on JS side
//hapi.export_FBX(); //TODO: commented out while working on JS side
//console.log('testPoint');
//hapi.testPoint(); //TODO: commented out while working on JS side
// setTimeout(()=>{
// console.log("chao")
// }, 100000)
// let regEx = /(\/*.obj)/;
// try {
// fs.readdir(directoryPath, function (err, files) {
// if (err) {
// return console.log('Unable to scan directory: ' + err);
// }
// console.log(regEx);
// files.forEach(function (file) {
// let match = file.match(regEx);
// if ( match ) {
// console.log(`\nattempting to convert to json`, file);
// try {
// const cmd = 'node -r esm obj2three.js scenes/' + file;
// const convert = execSync(
// cmd,
// {
// //cwd: 'node-hapi/',
// stdio: ['pipe', 'pipe', 'pipe']
// });
// state.file = convert;
// } catch (error) {
// console.log(`error: `, error);
// }
// }
// });
// });
// } catch( error ) {
// client.write( `file conversion error: ${error}` );
// }
})
client.on('data', function(data) {
console.log('on "DATA":', typeof data, data.byteLength, data.byteOffset, data)
// let pkt = data.buffer
// session.process(pkt)
// console.log('NODE: after process data.buffer')
})
client.on('close', function() {
//session.close()
console.log('session.close | Connection closed')
})
client.on('error', function(err) {
console.log("socket error", err)
//session.close()
client.disconnect()
socket.close()
// disconnect client & session.close() ?
})
console.log("ok")
//client.write(Buffer.from(session.handshake(1)))
console.log(exports.state);