Skip to content

Commit

Permalink
wip Migrates to using web components
Browse files Browse the repository at this point in the history
  • Loading branch information
swapkats committed Jul 8, 2020
1 parent 59109d6 commit 3a85ee3
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 120 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@babel/preset-typescript"
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-class-properties"
]
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ It aims to move away from slow auditorial learning process like books to step in

Finally Perspective.wiki is a public wiki anyone can edit the mind maps and maintain them just like wikipedia.

## How we'll build it

### Tecnical Stack
### Stack

1. Three.js
2. Neo4j with Apollo
3. Node
2. Web components (Lit-Element)
3. redux-observable & RxJS
4. Neo4j with Apollo
5. Node


## Contribute
Expand Down
35 changes: 35 additions & 0 deletions app/elements/map-scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
LitElement, html, css, customElement, property,
} from 'lit-element';
import { WebGLRenderer } from 'three';
import api from '../api';
import './three-scene';

@customElement('map-scene')
class MapScene extends LitElement {
constructor() {
super();
}

connectedCallback = () => {
api.getMap()
.then((res) => {
this.map = res.data.Map[0];
});
}

@property({ attribute: false })
map = null;

static getStyles() {
return css`
:host {
// display: block;
// height: 100%;
// width: 100%;
}
`;
}

render = () => html`<slot></slot>`
}
13 changes: 13 additions & 0 deletions app/elements/three-camera.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
LitElement, html, css, customElement, property,
} from 'lit-element';
import { PerspectiveCamera } from 'three';

@customElement('three-camera')
export default class ThreeCamera extends LitElement {
constructor() {
super();
const camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
}
}
13 changes: 13 additions & 0 deletions app/elements/three-controls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
LitElement, html, css, customElement, property,
} from 'lit-element';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';

@customElement('three-controls')
export default class ThreeControls extends LitElement {
constructor() {
super();
// const controls = new OrbitControls(camera, renderer.domElement);
// controls.update();
}
}
86 changes: 86 additions & 0 deletions app/elements/three-renderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
LitElement, html, css, customElement, property, internalProperty,
} from 'lit-element';
import { WebGLRenderer } from 'three';

@customElement('three-renderer')
export default class ThreeRenderer extends LitElement {
constructor() {
super();
this.renderer = new WebGLRenderer();
this.renderer.setClearColor(this.clearColor);
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.appendChild(this.renderer.domElement);

// const render = () => {
// renderer.render(scene, camera);
// };

// const animate = () => {
// requestAnimationFrame(animate);

// // controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true

// render();
// };

// animate();
}

@property({ type: String, attribute: 'clear-color' })
clearColor = 'red';

@property({ type: Number, reflect: true })
width = 0;

@property({ type: Number, reflect: true })
height = 0;

@internalProperty()
renderer: WebGLRenderer;

animateRenderer = () => {
requestAnimationFrame(this.animateRenderer);

// TODO: implement this
// this.renderer.render(scene, camera);
}

connectedCallback = () => {
super.connectedCallback();

this.animateRenderer();
}

attributeChangedCallback = (name: string, old: any, value: any) => {
super.attributeChangedCallback(name, old, value);

console.debug(`${name} changed`);

switch (name) {
case 'clear-color':
this.renderer.setClearColor(value);
break;
case 'width':
this.renderer.setSize(value, this.height);
break;
case 'height':
this.renderer.setSize(this.width, value);
break;
default:
console.debug(`${name} changed`);
}
}

static getStyles() {
return css`
:host {
display: block;
height: 100%;
width: 100%;
}
`;
}

render = () => html`<slot></slot>`
}
17 changes: 17 additions & 0 deletions app/elements/three-scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
LitElement, html, css, customElement, property, internalProperty,
} from 'lit-element';
import { WebGLRenderer, Scene } from 'three';

@customElement('three-scene')
class ThreeScene extends LitElement {
constructor() {
super();
this.scene = new Scene();
}

@internalProperty()
scene: Scene;

render = () => html`<slot></slot>`
}
81 changes: 45 additions & 36 deletions app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,49 @@ import {
Scene, PerspectiveCamera, WebGLRenderer, BoxGeometry, MeshBasicMaterial, Mesh,
} from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import {
LitElement, html, css, customElement, property,
} from 'lit-element';
import renderApp from './app';

const scene = new Scene();

const camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

const renderer = new WebGLRenderer();
renderer.setClearColor('#111');
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

renderApp({ scene });

camera.position.z = 5;
const controls = new OrbitControls(camera, renderer.domElement);

const render = () => {
renderer.render(scene, camera);
};

const animate = () => {
requestAnimationFrame(animate);

// controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true

render();
};

animate();

controls.update();

const resize = () => {
renderer.setSize(window.innerWidth, window.innerHeight);
};

window.addEventListener('resize', resize);
import './elements/three-renderer';
import './elements/three-scene';
import './elements/three-camera';
import './elements/three-controls';
import './elements/map-scene';

@customElement('perspective-app')
class PerspectiveApp extends LitElement {
constructor() {
super();

window.addEventListener('resize', this.handleResize);
}

handleResize = () => {
this.width = window.innerWidth;
this.height = window.innerHeight;
}

static getStyles() {
return css`
:host {
height: 100%;
width: 100%;
}
`;
}

@property({ type: Number, attribute: false })
width = window.innerWidth;

@property({ type: Number, attribute: false })
height = window.innerHeight;

render = () => html`<three-renderer clear-color="red" width="${this.width}" height="${this.height}">
<three-scene>
<map-scene map="Music"><map-scene>
</three-scene>
<three-camera></three-camera>
<three-controls></three-controls>
</three-renderer>`
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@babel/cli": "^7.10.4",
"@babel/core": "^7.10.4",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-decorators": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@typescript-eslint/eslint-plugin": "^3.5.0",
Expand All @@ -55,6 +56,7 @@
"nodemon": "^2.0.4",
"pm2": "^4.4.0",
"three": "^0.118.3",
"lit-element": "^2.3.1",
"ts-node": "^8.10.2",
"tsc": "^1.20150623.0"
},
Expand Down
5 changes: 5 additions & 0 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,8 @@ textarea {
}
}


html, body {
min-height: 100%;
height: 100%;
}
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!doctype html><html class="no-js" lang=""><head><meta charset="utf-8"><title></title><meta name="description" content=""><meta name="viewport" content="width=device-width,initial-scale=1"><meta property="og:title" content=""><meta property="og:type" content=""><meta property="og:url" content=""><meta property="og:image" content=""><link rel="manifest" href="site.webmanifest"><link rel="apple-touch-icon" href="icon.png"><link rel="stylesheet" href="css/normalize.css"><link rel="stylesheet" href="css/main.css"><meta name="theme-color" content="#fafafa"></head><body><script src="js/vendor/modernizr-3.11.2.min.js"></script><script src="js/plugins.js"></script><script src="js/main.js"></script><script>window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
<!doctype html><html class="no-js" lang=""><head><meta charset="utf-8"><title></title><meta name="description" content=""><meta name="viewport" content="width=device-width,initial-scale=1"><meta property="og:title" content=""><meta property="og:type" content=""><meta property="og:url" content=""><meta property="og:image" content=""><link rel="manifest" href="site.webmanifest"><link rel="apple-touch-icon" href="icon.png"><link rel="stylesheet" href="css/normalize.css"><link rel="stylesheet" href="css/main.css"><meta name="theme-color" content="#fafafa"></head><body><perspective-app></perspective-app><script>window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
ga('create', 'UA-XXXXX-Y', 'auto'); ga('set', 'anonymizeIp', true); ga('set', 'transport', 'beacon'); ga('send', 'pageview')</script><script src="https://www.google-analytics.com/analytics.js" async></script></body></html>
Empty file removed public/js/main.js
Empty file.
3 changes: 0 additions & 3 deletions public/js/vendor/modernizr-3.11.2.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */

/* Advanced Options */
Expand Down
Loading

0 comments on commit 3a85ee3

Please sign in to comment.