├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── package.json ├── src ├── index.html ├── index.ts └── style.css ├── tsconfig.json └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # Dist and OSX 36 | dist 37 | lib 38 | .DS_Store 39 | 40 | # Lock 41 | yarn.lock 42 | package-lock.json 43 | 44 | # awesome-typescript 45 | .awcache 46 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib", 3 | "edenDevelopEnvironment.autoFormatOnSave": true 4 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright © 2016-present Huang Qi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Typescript Three.js Webpack Starter 2 | 3 | - Typescript support. 4 | - Webpack 5 | - Html plugin 6 | 7 | ## Usage 8 | 9 | ### Install Typscript 10 | 11 | ``` 12 | npm install typescript -g 13 | ``` 14 | 15 | ### Start 16 | 17 | ``` 18 | $ git clone https://github.com/pinqy520/three-typescript-starter.git 19 | $ cd three-typescript-starter 20 | $ npm install # or yarn 21 | $ npm start 22 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "three-typescript-starter", 3 | "version": "1.0.0", 4 | "description": "three.js + typescript", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "webpack serve --inline --open" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/pinqy520/three-typescript-starter.git" 13 | }, 14 | "keywords": [], 15 | "author": "Huang Qi", 16 | "license": "MIT", 17 | "bugs": { 18 | "url": "https://github.com/pinqy520/three-typescript-starter/issues" 19 | }, 20 | "homepage": "https://github.com/pinqy520/three-typescript-starter#readme", 21 | "devDependencies": { 22 | "css-loader": "latest", 23 | "html-webpack-plugin": "latest", 24 | "progress-bar-webpack-plugin": "latest", 25 | "style-loader": "latest", 26 | "ts-loader": "latest", 27 | "typescript": "latest", 28 | "webpack": "latest", 29 | "webpack-cli": "latest", 30 | "webpack-dev-server": "latest" 31 | }, 32 | "dependencies": { 33 | "three": "latest" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Three.js Starter 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | // add styles 2 | import './style.css'; 3 | // three.js 4 | import * as THREE from 'three'; 5 | 6 | // create the scene 7 | const scene = new THREE.Scene(); 8 | 9 | // create the camera 10 | const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); 11 | 12 | const renderer = new THREE.WebGLRenderer(); 13 | 14 | // set size 15 | renderer.setSize(window.innerWidth, window.innerHeight); 16 | 17 | // add canvas to dom 18 | document.body.appendChild(renderer.domElement); 19 | 20 | // add axis to the scene 21 | const axis = new THREE.AxesHelper(10); 22 | 23 | scene.add(axis); 24 | 25 | // add lights 26 | const light = new THREE.DirectionalLight(0xffffff, 1.0); 27 | 28 | light.position.set(100, 100, 100); 29 | 30 | scene.add(light); 31 | 32 | const light2 = new THREE.DirectionalLight(0xffffff, 1.0); 33 | 34 | light2.position.set(-100, 100, -100); 35 | 36 | scene.add(light2); 37 | 38 | const material = new THREE.MeshBasicMaterial({ 39 | color: 0xaaaaaa, 40 | wireframe: true, 41 | }); 42 | 43 | // create a box and add it to the scene 44 | const box = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), material); 45 | 46 | scene.add(box); 47 | 48 | box.position.x = 0.5; 49 | box.rotation.y = 0.5; 50 | 51 | camera.position.x = 5; 52 | camera.position.y = 5; 53 | camera.position.z = 5; 54 | 55 | camera.lookAt(scene.position); 56 | 57 | function animate(): void { 58 | requestAnimationFrame(animate); 59 | render(); 60 | } 61 | 62 | function render(): void { 63 | const timer = 0.002 * Date.now(); 64 | box.position.y = 0.5 + 0.5 * Math.sin(timer); 65 | box.rotation.x += 0.1; 66 | renderer.render(scene, camera); 67 | } 68 | 69 | animate(); 70 | -------------------------------------------------------------------------------- /src/style.css: -------------------------------------------------------------------------------- 1 | /* Styles go here. */ 2 | 3 | html, 4 | body { 5 | margin: 0; 6 | padding: 0; 7 | } 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "experimentalDecorators": true, 7 | "emitDecoratorMetadata": true, 8 | "preserveConstEnums": true, 9 | "suppressImplicitAnyIndexErrors": true, 10 | "outDir": "./lib/", 11 | "sourceMap": true 12 | }, 13 | "exclude": [ 14 | "node_modules", 15 | "lib" 16 | ] 17 | } -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path'); 2 | 3 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 4 | const ProgressBarPlugin = require('progress-bar-webpack-plugin'); 5 | 6 | module.exports = { 7 | mode: 'development', 8 | 9 | entry: './src/index.ts', 10 | output: { 11 | filename: 'bundle.js', 12 | path: resolve(__dirname, 'dist'), 13 | }, 14 | 15 | resolve: { 16 | extensions: ['.ts', '.tsx', '.js', '.jsx'], 17 | }, 18 | 19 | devtool: 'source-map', 20 | 21 | module: { 22 | rules: [ 23 | { 24 | test: /\.tsx?$/, 25 | use: ['ts-loader'], 26 | }, 27 | { 28 | test: /\.(jpe?g|png|gif|svg)$/i, 29 | use: [ 30 | 'file-loader?hash=sha512&digest=hex&name=images/[hash].[ext]', 31 | 'image-webpack-loader?bypassOnDebug&optipng.optimizationLevel=7&gifsicle.interlaced=false', 32 | ], 33 | }, 34 | { 35 | test: /\.css$/i, 36 | use: ['style-loader', 'css-loader'], 37 | }, 38 | ], 39 | }, 40 | resolve: { 41 | extensions: ['.ts', '.tsx', '.js', '.jsx'], 42 | }, 43 | plugins: [ 44 | new ProgressBarPlugin(), 45 | new HtmlWebpackPlugin({ 46 | template: `${__dirname}/src/index.html`, 47 | filename: 'index.html', 48 | inject: 'body', 49 | }), 50 | ], 51 | }; 52 | --------------------------------------------------------------------------------