Skip to content

Commit

Permalink
Feature/multiple view (#26)
Browse files Browse the repository at this point in the history
* connect CSGManager with ui

* change default material

* add simple thread-worker

* fix missing gizmo from editor

* add cylinder

* fix calculating mouse pos on gizmo

* add multiple views

* install split-grid

* make viewpanels resizable and add 2 cameras

* add two layouts and cleanup code (#25)

* Update src/ThreeEditor/util/CSGManager.ts

* Fix Warnings

Co-authored-by: ostatni5 <26521377+ostatni5@users.noreply.github.com>
Co-authored-by: Jakub Niechaj <quban123@gmail.com>
  • Loading branch information
3 people authored Sep 11, 2021
1 parent 0bed9ef commit 6ce936d
Show file tree
Hide file tree
Showing 32 changed files with 3,392 additions and 3,048 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react-scripts": "4.0.3",
"signals": "^1.0.0",
"three": "^0.132.2",
"split-grid": "^1.0.11",
"throttle-debounce": "^3.0.1",
"typescript": "^4.4.2",
"web-vitals": "^2.1.0"
Expand Down
5 changes: 0 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React from 'react';
import './App.css';
import ThreeEditor from './ThreeEditor/ThreeEditor';
import JsRoot from './JsRoot/JsRoot';
import ZoneManagerPanel from './components/ZoneManagerPanel/ZoneManagerPanel';



function App() {
return (<>
{/* <JsRoot></JsRoot> */}

<ThreeEditor></ThreeEditor>
</>);
}
Expand Down
48 changes: 3 additions & 45 deletions src/ThreeEditor/ThreeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React, { useEffect, useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { initEditor } from './main';
import './css/main.css';
import SampleComponent from './components/SampleComponent';
import { Editor } from './js/Editor';
import * as THREE from 'three';
import CSG from './js/libs/csg/three-csg';
import ZoneManagerPanel from '../components/ZoneManagerPanel/ZoneManagerPanel';
import { CSGManager } from './util/CSGManager';


function ThreeEditor() {
Expand All @@ -17,48 +14,9 @@ function ThreeEditor() {

useEffect(() => {
if (containerEl.current) {
const { editor, viewport, toolbar, sidebar, menubar, resizer } = initEditor(containerEl.current);
const { editor, viewport, toolbar, sidebar, menubar, resizer } = initEditor(containerEl.current); // eslint-disable-line
setEditor(editor);

// Make 2 box meshes..

let meshA = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1));
let meshB = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1));

//offset one of the boxes by half its width..

meshB.position.add(new THREE.Vector3(0.5, 0.5, 0.5));

//Make sure the .matrix of each mesh is current

meshA.updateMatrix();
meshB.updateMatrix();

//Create a bsp tree from each of the meshes

let bspA = CSG.fromMesh(meshA);
let bspB = CSG.fromMesh(meshB);

// Subtract one bsp from the other via .subtract... other supported modes are .union and .intersect

let bspResult = bspA.subtract(bspB);

//Get the resulting mesh from the result bsp, and assign meshA.material to the resulting mesh

let meshResult = CSG.toMesh(bspResult, meshA.matrix, meshA.material);

meshResult.name = 'meshResult';
meshResult.material = new THREE.MeshNormalMaterial();
// editor.sceneHelpers.add(meshResult);


// let manager = new CSGManager(editor);
// let zone = manager.createZone();

// zone.addUnion();
// zone.addOperation(0, { object: meshA, mode: 'union' });
// zone.addOperation(0, { object: meshB, mode: 'left-subtraction' });

}
return () => {

Expand All @@ -71,7 +29,7 @@ function ThreeEditor() {
{editor &&
<>
<SampleComponent signal={editor.signals.objectSelected} ></SampleComponent>
<ZoneManagerPanel editor={editor}></ZoneManagerPanel>
{/* <ZoneManagerPanel editor={editor}></ZoneManagerPanel> */}
</>
}
</div>
Expand Down
27 changes: 27 additions & 0 deletions src/ThreeEditor/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,30 @@ select {
}

}


.grid {
display: grid;
grid-template-rows: 1fr 10px 1fr;
grid-template-columns: 1fr 10px 1fr;
}

.gutter-col {
grid-row: 1/-1;
cursor: col-resize;
background-color: rgb(53, 203, 248);
}

.gutter-col-1 {
grid-column: 2;
}

.gutter-row {
grid-column: 1/-1;
cursor: row-resize;
background-color: rgb(53, 248, 248);
}

.gutter-row-1 {
grid-row: 2;
}
24 changes: 12 additions & 12 deletions src/ThreeEditor/js/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,47 @@ function Config() {
'settings/shortcuts/focus': 'f'
};

if ( window.localStorage[ name ] === undefined ) {
if (window.localStorage[name] === undefined) {

window.localStorage[ name ] = JSON.stringify( storage );
window.localStorage[name] = JSON.stringify(storage);

} else {

var data = JSON.parse( window.localStorage[ name ] );
var data = JSON.parse(window.localStorage[name]);

for ( var key in data ) {
for (var key in data) {

storage[ key ] = data[ key ];
storage[key] = data[key];

}

}

return {

getKey: function ( key ) {
getKey: function (key) {

return storage[ key ];
return storage[key];

},

setKey: function () { // key, value, key, value ...

for ( var i = 0, l = arguments.length; i < l; i += 2 ) {
for (var i = 0, l = arguments.length; i < l; i += 2) {

storage[ arguments[ i ] ] = arguments[ i + 1 ];
storage[arguments[i]] = arguments[i + 1];

}

window.localStorage[ name ] = JSON.stringify( storage );
window.localStorage[name] = JSON.stringify(storage);

console.log( '[' + /\d\d\:\d\d\:\d\d/.exec( new Date() )[ 0 ] + ']', 'Saved config to LocalStorage.' );
console.log('[' + /\d\d\:\d\d\:\d\d/.exec(new Date())[0] + ']', 'Saved config to LocalStorage.'); // eslint-disable-line

},

clear: function () {

delete window.localStorage[ name ];
delete window.localStorage[name];

}

Expand Down
4 changes: 3 additions & 1 deletion src/ThreeEditor/js/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ function Editor() {

viewportCameraChanged: new Signal(),

animationStopped: new Signal()
animationStopped: new Signal(),

layoutChanged: new Signal() // Layout signal

};

Expand Down
Loading

0 comments on commit 6ce936d

Please sign in to comment.