Skip to content

Commit

Permalink
finish drag&drop; revert to electron 7 because of child_process not f…
Browse files Browse the repository at this point in the history
…iring issues
  • Loading branch information
potree committed Aug 11, 2020
1 parent 7116265 commit 2bf6675
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 39 deletions.
69 changes: 42 additions & 27 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -395,22 +395,28 @@
viewer.postMessage(message, {duration: 15000});

const { spawn } = require('child_process');
const converter = spawn('./libs/PotreeConverter/PotreeConverter.exe', [

let exe = './libs/PotreeConverter/PotreeConverter.exe';
let parameters = [
...inputPaths,
"-o", chosenPath,
"--overwrite"
]);
];

const converter = spawn(exe, parameters);

let placeholder = null;
let outputBuffer = "";
converter.stdout.on('data', (data) => {
console.log("==");
console.log(`stdout: ${data}`);

const string = new TextDecoder("utf-8").decode(data);

if(!placeholder){ // match for AABB
console.log("stdout", string);
outputBuffer += string;

if(!placeholder){
// match for AABB
const regexp = /(.*AABB): ({[.\s\S]*?})/g;
const matches = string.matchAll(regexp);
const matches = outputBuffer.matchAll(regexp);

for (const match of matches) {
try{
Expand All @@ -421,19 +427,18 @@

if(name === "cubicAABB"){
placeholder = createPlaceholder(aabb);

outputBuffer = "";
}
}catch(e){
console.error(match[0]);
console.error(e);
}
}
}

window.placeholder = placeholder;

if(placeholder){ // match for progress
}else{
// match for progress
const regexp = /INDEXING: ([\w\.]*) of ([\w\.]*) processed/g;
const matches = string.matchAll(regexp);
const matches = outputBuffer.matchAll(regexp);

for(const match of matches){

Expand All @@ -443,6 +448,8 @@

const text = `${percent}%`;
placeholder.text.setText(text);

outputBuffer = "";
}
}

Expand Down Expand Up @@ -484,22 +491,28 @@
output: ${chosenPath}`;
viewer.postMessage(message, {duration: 15000});

const { spawn } = require('child_process');
const converter = spawn('./libs/PotreeConverter2/Converter.exe', [
const { spawn, fork, execFile } = require('child_process');

let exe = './libs/PotreeConverter2/Converter.exe';
let parameters = [
...inputPaths,
"-o", chosenPath
]);
];

const converter = spawn(exe, parameters);

let placeholder = null;
let outputBuffer = "";
converter.stdout.on('data', (data) => {
console.log("==");
console.log(`stdout: ${data}`);

const string = new TextDecoder("utf-8").decode(data);
console.log("stdout", string);
outputBuffer += string;

if(!placeholder){ // match for AABB
if(!placeholder){
// match for AABB
const regexp = /(.*AABB): ({[.\s\S]*?})/g;
const matches = string.matchAll(regexp);
const matches = outputBuffer.matchAll(regexp);

for (const match of matches) {
try{
Expand All @@ -510,27 +523,29 @@

if(name === "cubicAABB"){
placeholder = createPlaceholder(aabb);
placeholder.text.setText("0%");

outputBuffer = "";
}
}catch(e){
console.error(match[0]);
console.error(e);
}
}
}

window.placeholder = placeholder;

if(placeholder){ // match for progress
}else{
// match for progress

let regexp = /\[(\d+)%,/g;

const matches = string.replace(/'/g, "").matchAll(regexp);
const matches = outputBuffer.replace(/'/g, "").matchAll(regexp);

for(const match of matches){
const percent = parseInt(match[1].replace(/\D/g,''));

const text = `${percent}%`;
placeholder.text.setText(text);

outputBuffer = "";
}

}
Expand All @@ -542,7 +557,7 @@
console.error(`stderr: ${data}`);
});

converter.on('close', (code) => {
converter.on('exit', (code) => {
console.log(`child process exited with code ${code}`);

const cloudJS = `${chosenPath}/metadata.json`;
Expand Down
49 changes: 38 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ function createWindow () {
width: 1600,
height: 1200,
webPreferences: {
nodeIntegration: true
nodeIntegration: true,
backgroundThrottling: false,
}

})

// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
// mainWindow.loadURL(url.format({
// pathname: path.join(__dirname, 'index.html'),
// protocol: 'file:',
// slashes: true
// }));
mainWindow.loadFile(path.join(__dirname, 'index.html'));


//let menu = new Menu();
Expand Down Expand Up @@ -56,13 +58,38 @@ function createWindow () {

let menu = Menu.buildFromTemplate(template);
mainWindow.setMenu(menu);
//mainWindow.setMenu(null);

//mainWindow.webContents.on('new-window', function(event, url){
// event.preventDefault();
// open(url);
//});

{
const { ipcMain } = require('electron');

ipcMain.on('asynchronous-message', (event, arg) => {
console.log(arg) // prints "ping"
event.reply('asynchronous-reply', 'pong')
})

ipcMain.on('synchronous-message', (event, arg) => {
console.log(arg) // prints "ping"
event.returnValue = 'pong'
})
}

// {
// const { spawn, fork, execFile } = require('child_process');
// let inputPaths = ["D:/dev/pointclouds/bunny_20M.las"];
// let chosenPath = "D:/dev/pointclouds/bunny_20M.las_converted";

// const process = spawn('./libs/PotreeConverter2/Converter.exe', [
// ...inputPaths,
// "-o", chosenPath
// ], {

// });

// process.stdout.on('data', (data) => {
// console.log(`stdout: ${data}`);
// });
// }



Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"author": "Markus Schuetz",
"license": "no license available at this time",
"dependencies": {
"electron": "~9.1.2"
"electron": "~7.0.0"
}
}

0 comments on commit 2bf6675

Please sign in to comment.