2021-03-26 13:38:49 +08:00
|
|
|
|
2021-03-21 03:08:15 +08:00
|
|
|
|
|
|
|
import * as THREE from '../node_modules/three/src/Three';
|
|
|
|
import { OrbitControls } from './OrbitControls'
|
|
|
|
import { TrackballControls } from './trackball'
|
2021-03-25 16:04:13 +08:00
|
|
|
import { Sketcher } from './sketcher/Sketcher'
|
2021-03-26 17:25:28 +08:00
|
|
|
import Stats from './stats.module.js';
|
2021-03-21 03:08:15 +08:00
|
|
|
|
2021-03-26 17:25:28 +08:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import { createStore, applyMiddleware } from 'redux'
|
2021-03-21 03:08:15 +08:00
|
|
|
|
2021-03-27 03:18:11 +08:00
|
|
|
import { Root } from './app.jsx'
|
2021-03-21 03:08:15 +08:00
|
|
|
|
2021-03-26 17:25:28 +08:00
|
|
|
function main(store) {
|
2021-03-21 03:08:15 +08:00
|
|
|
var stats = new Stats();
|
|
|
|
stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
|
2021-03-26 17:25:28 +08:00
|
|
|
document.getElementById('stats').appendChild(stats.dom);
|
2021-03-21 03:08:15 +08:00
|
|
|
|
|
|
|
const canvas = document.querySelector('#c');
|
|
|
|
const renderer = new THREE.WebGLRenderer({ canvas });
|
|
|
|
|
|
|
|
const scene = new THREE.Scene();
|
2021-03-27 03:18:11 +08:00
|
|
|
window.scene = scene;
|
2021-03-26 13:38:49 +08:00
|
|
|
scene.background = new THREE.Color(0xb0b0b0);
|
2021-03-21 03:08:15 +08:00
|
|
|
|
|
|
|
const helpersGroup = new THREE.Group();
|
|
|
|
scene.add(helpersGroup);
|
2021-03-26 13:38:49 +08:00
|
|
|
const axesHelper = new THREE.AxesHelper(5);
|
|
|
|
helpersGroup.add(axesHelper);
|
2021-03-21 03:08:15 +08:00
|
|
|
|
|
|
|
const size = 1;
|
|
|
|
const near = 5;
|
|
|
|
const far = 50;
|
|
|
|
const camera = new THREE.OrthographicCamera(-size, size, size, -size, near, far);
|
|
|
|
camera.zoom = 0.1;
|
2021-03-26 17:25:28 +08:00
|
|
|
camera.position.set(0, 0, 30);
|
2021-03-26 13:38:49 +08:00
|
|
|
|
|
|
|
// const controls = new OrbitControls(camera, view1Elem);
|
|
|
|
const controls = new TrackballControls(camera, canvas);
|
2021-03-21 03:08:15 +08:00
|
|
|
controls.target.set(0, 0, 0);
|
|
|
|
controls.update()
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-26 12:30:35 +08:00
|
|
|
const color = 0xFFFFFF;
|
|
|
|
const intensity = 1;
|
|
|
|
const light1 = new THREE.DirectionalLight(color, intensity);
|
|
|
|
light1.position.set(10, 10, 10);
|
|
|
|
scene.add(light1);
|
|
|
|
|
|
|
|
const light2 = new THREE.DirectionalLight(color, intensity);
|
|
|
|
light2.position.set(-10, -10, -5);
|
|
|
|
scene.add(light2);
|
2021-03-26 13:38:49 +08:00
|
|
|
|
|
|
|
const ambient = new THREE.AmbientLight(color, intensity);
|
|
|
|
scene.add(ambient);
|
|
|
|
|
|
|
|
|
|
|
|
const sketchPlane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
|
|
|
|
const sketcher = new Sketcher(camera, canvas, sketchPlane)
|
|
|
|
window.sketcher = sketcher
|
|
|
|
scene.add(sketcher)
|
2021-03-21 03:08:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
function resizeRendererToDisplaySize(renderer) {
|
|
|
|
const canvas = renderer.domElement;
|
|
|
|
const width = canvas.clientWidth;
|
|
|
|
const height = canvas.clientHeight;
|
|
|
|
const needResize = canvas.width !== width || canvas.height !== height;
|
|
|
|
if (needResize) {
|
|
|
|
renderer.setSize(width, height, false);
|
|
|
|
}
|
|
|
|
return needResize;
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
stats.begin();
|
2021-03-26 13:38:49 +08:00
|
|
|
if (resizeRendererToDisplaySize(renderer)) {
|
|
|
|
const canvas = renderer.domElement;
|
|
|
|
camera.left = -canvas.clientWidth / canvas.clientHeight;
|
|
|
|
camera.right = canvas.clientWidth / canvas.clientHeight;
|
2021-03-21 03:08:15 +08:00
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
}
|
2021-03-26 13:38:49 +08:00
|
|
|
renderer.render(scene, camera);
|
2021-03-21 03:08:15 +08:00
|
|
|
stats.end();
|
|
|
|
}
|
|
|
|
controls.addEventListener('change', render);
|
|
|
|
controls.addEventListener('start', render);
|
|
|
|
sketcher.addEventListener('change', render);
|
|
|
|
window.addEventListener('resize', render);
|
|
|
|
render();
|
|
|
|
}
|
|
|
|
|
2021-03-26 17:25:28 +08:00
|
|
|
function todos(state = [], action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case 'ADD_TODO':
|
|
|
|
return state.concat([action.text])
|
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const store = createStore(todos, ['Use Redux'])
|
|
|
|
|
|
|
|
store.dispatch({
|
|
|
|
type: 'ADD_TODO',
|
|
|
|
text: 'Read the docs'
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(store.getState())
|
|
|
|
|
|
|
|
|
|
|
|
// main(store);
|
2021-03-27 03:18:11 +08:00
|
|
|
main(store);
|
2021-03-26 17:25:28 +08:00
|
|
|
|
|
|
|
|
2021-03-27 03:18:11 +08:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2021-03-26 17:25:28 +08:00
|
|
|
|
2021-03-27 03:18:11 +08:00
|
|
|
const root = document.getElementById('react');
|
|
|
|
ReactDOM.render(
|
|
|
|
React.createElement(Root, { store: store }, null)
|
|
|
|
, root
|
|
|
|
);
|
2021-03-26 17:25:28 +08:00
|
|
|
|
2021-03-27 03:18:11 +08:00
|
|
|
});
|