Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

Commit

Permalink
Slice workers
Browse files Browse the repository at this point in the history
and ViewCube camera type switch. Fixup other many functions
  • Loading branch information
Владислав Чалый committed Feb 7, 2023
1 parent 483c422 commit d5d10bd
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 143 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## About

<p>
ProtoUV it's open-source slicer for a photopolymer 3d printers, written on TypeScript with base on Electron. Uses <a href="https://facebook.github.io/react/">React</a>, <a href="https://threejs.org/">ThreeJs</a>, <a href="https://threejs.org/">ThreeJs</a>, <a href="https://www.electronjs.org/">Electron</a>, <a href="https://github.com/sn4k3/UVtools">uvtools</a> and many other deps.
ProtoUV it's open-source slicer for a photopolymer 3d printers, written on TypeScript with base on Electron. Uses <a href="https://facebook.github.io/react/">React</a>, <a href="https://threejs.org/">ThreeJs</a>, <a href="https://github.com/gkjohnson/three-mesh-bvh">three-mesh-bvh</a>, <a href="https://www.electronjs.org/">Electron</a>, <a href="https://github.com/sn4k3/UVtools">uvtools</a> and many other deps.
</p>
<img src="assets/screen.png" width="100%" />

Expand Down
2 changes: 1 addition & 1 deletion assets/defaultconfigs/Creality-LD-002H.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{
"Name": "Default",
"ConnectionSphere": 0.4,
"Head": 0.35,
"Head": 0.3,
"Body": 0.5,
"Indent": 0.6,
"Angle": 56,
Expand Down
2 changes: 1 addition & 1 deletion assets/defaultconfigs/Default Printer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{
"Name": "Default",
"ConnectionSphere": 0.4,
"Head": 0.35,
"Head": 0.3,
"Body": 0.5,
"Indent": 0.6,
"Angle": 56,
Expand Down
2 changes: 1 addition & 1 deletion assets/defaultconfigs/Voxelab Proxima 6.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{
"Name": "Default",
"ConnectionSphere": 0.4,
"Head": 0.35,
"Head": 0.3,
"Body": 0.5,
"Indent": 0.6,
"Angle": 56,
Expand Down
2 changes: 1 addition & 1 deletion assets/workers/slice.worker.bundle.js

Large diffs are not rendered by default.

83 changes: 62 additions & 21 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ const userData = electron.app.getPath('userData');

let mainWindow: BrowserWindow | null = null;
let mainWindowIsFocused: boolean | undefined;
const workers = [] as BrowserWindow[];

const RESOURCES_PATH = app.isPackaged
? path.join((process as any).resourcesPath, 'assets')
: path.join(__dirname, '../../assets');

ipcMain.on('electron.assetsPath', (event: any) => {
event.returnValue = RESOURCES_PATH;
});
ipcMain.on('electron.userData', (event: any) => {
event.returnValue = userData;
});
Expand Down Expand Up @@ -50,10 +42,6 @@ ipcMain.on('electron.openFileDialog', (event: any) => {
});
}
});
ipcMain.on('electron.isWorker', (_) => {
const worker = workers.find(x => _.sender === x.webContents);
_.returnValue = !!worker;
});

if (process.env.NODE_ENV === 'production') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -91,10 +79,18 @@ const createWindow = async () => {
await installExtensions();
}

const RESOURCES_PATH = app.isPackaged
? path.join((process as any).resourcesPath, 'assets')
: path.join(__dirname, '../../assets');

const getAssetPath = (...paths: string[]): string => {
return path.join(RESOURCES_PATH, ...paths);
};

ipcMain.on('electron.assetsPath', (event: any) => {
event.returnValue = RESOURCES_PATH;
});

mainWindow = new BrowserWindow({
show: false,
width: 1200,
Expand All @@ -115,6 +111,7 @@ const createWindow = async () => {
},
titleBarStyle: 'hidden',
});

mainWindow.setMenu(null);
mainWindow.loadURL(resolveHtmlPath('index.html'));

Expand Down Expand Up @@ -143,6 +140,7 @@ const createWindow = async () => {
});
}
});

mainWindow.on('closed', () => {
mainWindow = null;
});
Expand All @@ -153,24 +151,21 @@ const createWindow = async () => {
return { action: 'deny' };
});

ipcMain.on('prepare-to-slicing', (_) => {
ipcMain.on('prepare-to-slicing', () => {
if (fs.existsSync(userData + '/slicing'))
{
fs.rmSync(userData + '/slicing', { recursive: true, force: true });
}

fs.mkdirSync(userData + '/slicing');

mainWindow?.webContents.send('prepare-to-slicing-ready');
mainWindow?.webContents.send('prepare-to-slicing');
});
ipcMain.on('sliced-layer-save', (_, screenshot: string, path: string) => {
fs.writeFileSync(userData + '/slicing/' + path, atob(screenshot), 'binary' );
});
ipcMain.on('sliced-finalize-done', (_,
ipcMain.on('sliced-finalize', (_,
gcode: string, pathToUVTools: string,
encoder: string, extencion: string
) => {

try {
fs.writeFileSync(userData + '/slicing/run.gcode', gcode);

Expand All @@ -185,8 +180,13 @@ const createWindow = async () => {

const _process = child(executablePath, parameters);

_process.stdout!.on('data', (data) => console.log(`stdout: ${data}`));
_process.stderr!.on('data', (data) => console.error(`stderr: ${data}`));
_process.stdout!.on('data', (data) => {
console.log(`stdout: ${data}`);
});

_process.stderr!.on('data', (data) => {
console.error(`stderr: ${data}`);
});
_process.on('close', (code) => {
if (code === 1) {
mainWindow?.webContents.send('sliced-finalize-result', 'done');
Expand Down Expand Up @@ -247,6 +247,46 @@ const createWindow = async () => {
mainWindow?.webContents.send('sliced-finalize-result-save', 'finalize error: ' + e);
}
});

let workers: BrowserWindow[] = [];

ipcMain.on('worker', (_, scene: string) => {
console.log(123);
const worker = new BrowserWindow({
//show: false,
//titleBarStyle: 'hidden',
webPreferences: {
preload: app.isPackaged
? path.join(__dirname, 'preload.js')
: path.join(__dirname, '../../.erb/dll/preload.js'),
webSecurity: false,
sandbox: false,
nodeIntegration: true,
devTools: isDebug,
nodeIntegrationInWorker: true,
nodeIntegrationInSubFrames: true
},
titleBarStyle: 'hidden',
});
console.log(scene);
worker.loadURL(resolveHtmlPath('index.html'));
worker.webContents.send('worker', scene);
workers.push(worker);

const send = () => mainWindow?.webContents.send('worker-info', workers.length);
const interval = setInterval(() => {
send();
if (!workers.length) {
clearInterval(interval);
}
}, 500);

send();
});
ipcMain.on('worker-shutdown', (e) => {
workers = workers.filter(worker => worker.webContents !== e.sender);
e.sender.delete();
});
};

/**
Expand All @@ -261,7 +301,8 @@ app.on('window-all-closed', () => {
}
});

app.whenReady()
app
.whenReady()
.then(() => {
createWindow();
app.on('activate', () => {
Expand Down
1 change: 0 additions & 1 deletion src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const body = {
userData: () => ipcRenderer.sendSync('electron.userData'),
isDebug: () => ipcRenderer.sendSync('electron.isDebug'),
assetsPath: () => ipcRenderer.sendSync('electron.assetsPath'),
isWorker: () => ipcRenderer.sendSync('electron.isWorker'),
ipcRenderer: {
...ipcRenderer,
send: (channel: any, ...args: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const _supportCreator = (
const to = path[path.length-1].clone().setY(path[path.length-1].y + platformHeight);
mesh1.add(createCylinder(material, from, to, to.distanceTo(from), platformWidth * 0.75, platformWidth).mesh);
}
mesh1.add(createContactSphere(material, path[0], connectionSphere).mesh);
mesh1.add(createContactSphere(material, path[0], body).mesh);
mesh1.add(createCylinder(material, path[0], to, to.distanceTo(path[0]), body, head).mesh);
mesh1.add(createContactSphere(material, to, connectionSphere).mesh);

Expand Down
15 changes: 7 additions & 8 deletions src/renderer/Main/Components/ViewChange/LockLookAtCenterApp.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import { IconButton, Tooltip } from '@mui/material';
import { MdCenterFocusStrong } from '@react-icons/all-files/md/MdCenterFocusStrong';
import { MdCenterFocusWeak } from '@react-icons/all-files/md/MdCenterFocusWeak';
import { useState } from 'react';
import { observer } from 'mobx-react';
import { AppStore } from '../../../AppStore';
import { config, saveConfig } from '../../../Shared/Config';
import { colors } from '../../../Shared/Config';

export const LockLookAtCenterApp = () => {
const [isActive, setterIsActive] = useState(config.scene.isFixedCenter);
export const LockLookAtCenterApp = observer(() => {
AppStore.sceneStore.orbitControls.enablePan = !config.scene.isFixedCenter;

return <Tooltip title={'look at center (doubleclick change)'} arrow placement="bottom"
return <Tooltip title={'look at center. use doubleclick to lock change'} arrow placement="bottom"
PopperProps={{ sx: { userSelect: 'none' } }}>
<IconButton
size='small'
onDoubleClick={() => {
config.scene.isFixedCenter = !isActive;
setterIsActive(config.scene.isFixedCenter);
config.scene.isFixedCenter = !config.scene.isFixedCenter;
saveConfig();
AppStore.sceneStore.animate();
}}
onClick={() => {
AppStore.sceneStore.orbitControls.target.set(AppStore.sceneStore.gridSize.x / 2, 0, AppStore.sceneStore.gridSize.z / 2);
AppStore.sceneStore.animate();
}}>
{isActive
{config.scene.isFixedCenter
? <MdCenterFocusStrong color={colors.background.light}/>
: <MdCenterFocusWeak color={colors.background.light}/>}
</IconButton>
</Tooltip>;
};
});
32 changes: 28 additions & 4 deletions src/renderer/Main/Console/ConsoleApp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Fade, Typography } from '@mui/material';
import { observer } from 'mobx-react';
import { useState } from 'react';
import { ConsoleColors } from './ConsoleStore';
import { AppStore } from '../../AppStore';
import { colors } from '../../Shared/Config';
import { linearGenerator } from '../../Shared/Libs/Tools';
Expand All @@ -23,7 +24,6 @@ export const ConsoleApp = observer((props: {mt?: string, mb?: string}) => {
position: 'fixed',
bottom: 0,
overflow: 'hidden',
color: colors.typography.background,
margin: Sizes.twelve,
marginLeft: Sizes.twelve,
marginBottom: Sizes.sum(Sizes.twentyFour, Sizes.eight),
Expand All @@ -32,9 +32,33 @@ export const ConsoleApp = observer((props: {mt?: string, mb?: string}) => {
pointerEvents: selectable ? 'unset' : 'none',
...props
}}>
{AppStore.console.list.slice().reverse().map(x => <Typography key={linearGenerator.next().value} variant={'body2'}>
{x.time} {'>'} {x.text}
</Typography>)}
{AppStore.console.list.slice().reverse().map(x => {
let color;

switch (x.color) {
case ConsoleColors.Message:
color = colors.background.light;
break;
case ConsoleColors.Success:
color = colors.interact.success;
break;
case ConsoleColors.Error:
color = colors.interact.danger;
break;
}

return <Typography key={linearGenerator.next().value} variant={'body2'} sx={{
color: colors.background.light,
textShadow: '0px 0px 4px #2C130C',
...(x.color === ConsoleColors.Message ? {} : {
color,
fontWeight: 0
}),
'-webkit-font-smoothing': 'antialiased'
}}>
{x.time} {'>'} {x.text}
</Typography>;
})}
</Box>
</Fade>;
});
12 changes: 10 additions & 2 deletions src/renderer/Main/Console/ConsoleStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ export class ConsoleStore {
public list: Array<{
text: string;
time: string;
color: ConsoleColors;
}> = [];

private timerHide?: NodeJS.Timeout;

public Add = (text: string) => {
public Add = (text: string, color: ConsoleColors = 0) => {
const date = new Date()
.toISOString()
.replace(/T/, ' ')
.replace(/\..+/, '')
.split(' ')[1];
const log = {
text: text.toLowerCase(),
time: date
time: date,
color: color
};

if (this.timerHide)
Expand All @@ -53,3 +55,9 @@ export class ConsoleStore {
}
};
}

export enum ConsoleColors {
Message,
Success,
Error,
}
6 changes: 0 additions & 6 deletions src/renderer/Main/Scene/SceneInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,12 +920,6 @@ export class SceneInitializer extends SceneBase {

if (this.activeCamera.position.y >= 0)
{
// this.renderer.setSize( 333, 333 );
// this.renderer.render( this.scene, this.activeCamera );
// const screenshot = this.renderer.domElement.toDataURL('image/png');
// console.log(screenshot);
// bridge.ipcRenderer.send('capture-page', screenshot.replace('data:image/png;base64,','')
// );
if (!this.clippingSceneWorking) {
this.outlineEffectRenderer.renderOutline(this.scene, this.activeCamera);
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Main/Scene/SceneStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class SceneStore extends SceneInitializer {
makeObservable(this);

setTimeout(() => {
if (bridge.isDebug() && !bridge.isWorker())
if (bridge.isDebug())
{
AppStore.sceneStore.handleLoadFile('C:\\Users\\admin\\Downloads\\Old\\V7_Infinity_Cube_Hinge.stl');
}
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/Shared/Config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { observable } from 'mobx';
import { Restore } from './Libs/Restore';

export const _default = {
Expand Down Expand Up @@ -70,6 +71,9 @@ const storage = new Restore({
defaults: _default
});

export const saveConfig = () => storage.fullSave();
export const config = storage.get('settings') as typeof _default.settings;
export const saveConfig = () => {
storage.data.settings = config;
storage.fullSave();
};
export const config = observable(storage.get('settings')) as typeof _default.settings;
export const colors = (storage.get('settings') as typeof _default.settings).colors;
Loading

0 comments on commit d5d10bd

Please sign in to comment.