├── .gitignore ├── LICENSE.md ├── bundler ├── webpack.common.js ├── webpack.dev.js └── webpack.prod.js ├── package-lock.json ├── package.json ├── readme.md ├── src ├── debug.js ├── index.html ├── main.css └── script.js └── static ├── .gitkeep ├── cover.jpg ├── favicon ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico └── site.webmanifest ├── models └── gltf │ └── Skull.glb ├── particle-texture.jpg ├── shaders └── LensDistortionShader.js └── youtube.png /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | .vercel 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Attribution-NonCommercial-NoDerivatives 4.0 International 2 | 3 | > _Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible._ 4 | > 5 | > ### Using Creative Commons Public Licenses 6 | > 7 | > Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. 8 | > 9 | > - **Considerations for licensors:** Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). 10 | > 11 | > - **Considerations for the public:** By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). 12 | 13 | ## Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License 14 | 15 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 16 | 17 | ### Section 1 – Definitions. 18 | 19 | a. **Adapted Material** means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 20 | 21 | b. **Copyright and Similar Rights** means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 22 | 23 | e. **Effective Technological Measures** means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 24 | 25 | f. **Exceptions and Limitations** means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 26 | 27 | h. **Licensed Material** means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 28 | 29 | i. **Licensed Rights** means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 30 | 31 | h. **Licensor** means the individual(s) or entity(ies) granting rights under this Public License. 32 | 33 | i. **NonCommercial** means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. 34 | 35 | j. **Share** means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 36 | 37 | k. **Sui Generis Database Rights** means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 38 | 39 | l. **You** means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 40 | 41 | ### Section 2 – Scope. 42 | 43 | a. **_License grant._** 44 | 45 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 46 | 47 | A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and 48 | 49 | B. produce and reproduce, but not Share, Adapted Material for NonCommercial purposes only. 50 | 51 | 2. **Exceptions and Limitations.** For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 52 | 53 | 3. **Term.** The term of this Public License is specified in Section 6(a). 54 | 55 | 4. **Media and formats; technical modifications allowed.** The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 56 | 57 | 5. **Downstream recipients.** 58 | 59 | A. **Offer from the Licensor – Licensed Material.** Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 60 | 61 | B. **No downstream restrictions.** You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 62 | 63 | 6. **No endorsement.** Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 64 | 65 | b. **_Other rights._** 66 | 67 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 68 | 69 | 2. Patent and trademark rights are not licensed under this Public License. 70 | 71 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. 72 | 73 | ### Section 3 – License Conditions. 74 | 75 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 76 | 77 | a. **_Attribution._** 78 | 79 | 1. If You Share the Licensed Material, You must: 80 | 81 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 82 | 83 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 84 | 85 | ii. a copyright notice; 86 | 87 | iii. a notice that refers to this Public License; 88 | 89 | iv. a notice that refers to the disclaimer of warranties; 90 | 91 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 92 | 93 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 94 | 95 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 96 | 97 | For the avoidance of doubt, You do not have permission under this Public License to Share Adapted Material. 98 | 99 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 100 | 101 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 102 | 103 | ### Section 4 – Sui Generis Database Rights. 104 | 105 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 106 | 107 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only and provided You do not Share Adapted Material; 108 | 109 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and 110 | 111 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 112 | 113 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 114 | 115 | ### Section 5 – Disclaimer of Warranties and Limitation of Liability. 116 | 117 | a. **Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.** 118 | 119 | b. **To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.** 120 | 121 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 122 | 123 | ### Section 6 – Term and Termination. 124 | 125 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 126 | 127 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 128 | 129 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 130 | 131 | 2. upon express reinstatement by the Licensor. 132 | 133 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 134 | 135 | c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 136 | 137 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 138 | 139 | ### Section 7 – Other Terms and Conditions. 140 | 141 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 142 | 143 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 144 | 145 | ### Section 8 – Interpretation. 146 | 147 | a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 148 | 149 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 150 | 151 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 152 | 153 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 154 | 155 | > Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. 156 | > 157 | > Creative Commons may be contacted at [creativecommons.org](http://creativecommons.org). 158 | -------------------------------------------------------------------------------- /bundler/webpack.common.js: -------------------------------------------------------------------------------- 1 | const CopyWebpackPlugin = require('copy-webpack-plugin') 2 | const HtmlWebpackPlugin = require('html-webpack-plugin') 3 | const MiniCSSExtractPlugin = require('mini-css-extract-plugin') 4 | const path = require('path') 5 | 6 | module.exports = { 7 | entry: path.resolve(__dirname, '../src/script.js'), 8 | output: 9 | { 10 | hashFunction: 'xxhash64', 11 | filename: 'bundle.[contenthash].js', 12 | path: path.resolve(__dirname, '../dist') 13 | }, 14 | devtool: 'source-map', 15 | plugins: 16 | [ 17 | new CopyWebpackPlugin({ 18 | patterns: [ 19 | { from: path.resolve(__dirname, '../static') } 20 | ] 21 | }), 22 | new HtmlWebpackPlugin({ 23 | template: path.resolve(__dirname, '../src/index.html'), 24 | minify: true 25 | }), 26 | new MiniCSSExtractPlugin() 27 | ], 28 | module: 29 | { 30 | rules: 31 | [ 32 | // HTML 33 | { 34 | test: /\.(html)$/, 35 | use: 36 | [ 37 | 'html-loader' 38 | ] 39 | }, 40 | 41 | // JS 42 | { 43 | test: /\.js$/, 44 | exclude: /node_modules/, 45 | use: 46 | [ 47 | 'babel-loader' 48 | ] 49 | }, 50 | 51 | // CSS 52 | { 53 | test: /\.css$/, 54 | use: 55 | [ 56 | MiniCSSExtractPlugin.loader, 57 | 'css-loader' 58 | ] 59 | }, 60 | 61 | // Images 62 | { 63 | test: /\.(jpg|png|gif|svg)$/, 64 | type: 'asset/resource', 65 | generator: 66 | { 67 | filename: 'assets/images/[hash][ext]' 68 | } 69 | }, 70 | 71 | // Fonts 72 | { 73 | test: /\.(ttf|eot|woff|woff2)$/, 74 | type: 'asset/resource', 75 | generator: 76 | { 77 | filename: 'assets/fonts/[hash][ext]' 78 | } 79 | }, 80 | 81 | // Shaders 82 | { 83 | test: /\.(glsl|vs|fs|vert|frag)$/, 84 | type: 'asset/source', 85 | generator: 86 | { 87 | filename: 'assets/images/[hash][ext]' 88 | } 89 | } 90 | ] 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /bundler/webpack.dev.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const { merge } = require('webpack-merge') 3 | const commonConfiguration = require('./webpack.common.js') 4 | const ip = require('internal-ip') 5 | const portFinderSync = require('portfinder-sync') 6 | 7 | const infoColor = (_message) => 8 | { 9 | return `\u001b[1m\u001b[34m${_message}\u001b[39m\u001b[22m` 10 | } 11 | 12 | module.exports = merge( 13 | commonConfiguration, 14 | { 15 | stats: 'errors-warnings', 16 | mode: 'development', 17 | devServer: 18 | { 19 | host: 'local-ip', 20 | port: portFinderSync.getPort(8080), 21 | open: true, 22 | https: false, 23 | allowedHosts: 'all', 24 | hot: false, 25 | watchFiles: ['src/**', 'static/**'], 26 | static: 27 | { 28 | watch: true, 29 | directory: path.join(__dirname, '../static') 30 | }, 31 | client: 32 | { 33 | logging: 'none', 34 | overlay: true, 35 | progress: false 36 | }, 37 | onAfterSetupMiddleware: function(devServer) 38 | { 39 | const port = devServer.options.port 40 | const https = devServer.options.https ? 's' : '' 41 | const localIp = ip.v4.sync() 42 | const domain1 = `http${https}://${localIp}:${port}` 43 | const domain2 = `http${https}://localhost:${port}` 44 | 45 | console.log(`Project running at:\n - ${infoColor(domain1)}\n - ${infoColor(domain2)}`) 46 | } 47 | } 48 | } 49 | ) 50 | -------------------------------------------------------------------------------- /bundler/webpack.prod.js: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge') 2 | const commonConfiguration = require('./webpack.common.js') 3 | const { CleanWebpackPlugin } = require('clean-webpack-plugin') 4 | 5 | module.exports = merge( 6 | commonConfiguration, 7 | { 8 | mode: 'production', 9 | devtool: false, 10 | plugins: 11 | [ 12 | new CleanWebpackPlugin() 13 | ] 14 | } 15 | ) 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "repository": "#", 3 | "license": "UNLICENSED", 4 | "author": "Anderson Mancini (https://twitter.com/Andersonmancini)", 5 | "scripts": { 6 | "build": "webpack --config ./bundler/webpack.prod.js", 7 | "dev": "webpack serve --config ./bundler/webpack.dev.js" 8 | }, 9 | "dependencies": { 10 | "@babel/core": "^7.15.8", 11 | "@babel/preset-env": "^7.15.8", 12 | "babel-loader": "^8.2.3", 13 | "clean-webpack-plugin": "^4.0.0", 14 | "copy-webpack-plugin": "^9.0.1", 15 | "css-loader": "^6.5.0", 16 | "file-loader": "^6.2.0", 17 | "html-loader": "^3.0.0", 18 | "html-webpack-plugin": "^5.5.0", 19 | "lil-gui": "^0.11.0", 20 | "mini-css-extract-plugin": "^2.4.3", 21 | "portfinder-sync": "0.0.2", 22 | "raw-loader": "^4.0.2", 23 | "style-loader": "^3.3.1", 24 | "three": "^0.134.0", 25 | "webpack": "^5.60.0", 26 | "webpack-cli": "^4.9.1", 27 | "webpack-dev-server": "^4.4.0", 28 | "webpack-merge": "^5.8.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # THREEJS Particle System Skull 2 |

by Anderson Mancini

3 | 4 |

5 | 6 |

7 | 8 | # Live Link 9 | Click here: https://threejs-particle-skull.vercel.app 10 | 11 | # Introduction 12 | This project converts any GLTF looaded model into a particle system using threejs points material. It is using my previous three.js boilerplate. 13 | 14 | You can replace the model and change the camera animations to make your own scene. 15 | 16 | Resources: [Threejs](https://threejs.org/), [WebGL](https://github.com/KhronosGroup/WebGL), [webpack](https://webpack.js.org/) , [Babel](https://babeljs.io/ ), [ESLint](https://eslint.org/) 17 | 18 | # Show, don't tell 19 | Here you can see a video on how I created it 20 | 21 | 22 | # Getting Started 23 | Download and install Node.js on your computer (https://nodejs.org/en/download/). 24 | 25 | Then, open VSCODE, drag the project folder to it. Open VSCODE terminal and install dependencies (you need to do this only in the first time) 26 | ``` 27 | npm install 28 | ``` 29 | 30 | Run this command in your terminal to open a local server at localhost:8080 31 | ``` 32 | npm run dev 33 | ``` 34 | 35 | # Notes 36 | Would be really appreciated if you are willing to give me a star here on GitHub 🎉 or buy me a coffee ☕ https://www.buymeacoffee.com/andersonmancini. The money will be used to produce more content about threejs or to buy new courses. -------------------------------------------------------------------------------- /src/debug.js: -------------------------------------------------------------------------------- 1 | import { GUI } from 'three/examples/jsm/libs/dat.gui.module.js' 2 | const gui = new GUI() 3 | 4 | // create parameters for GUI 5 | var params = {color: sunLight.color.getHex(), color2: ambient.color.getHex(), color3: scene.background.getHex()} 6 | 7 | // create a function to be called by GUI 8 | const update = function () { 9 | var colorObj = new THREE.Color( params.color ) 10 | var colorObj2 = new THREE.Color( params.color2 ) 11 | var colorObj3 = new THREE.Color( params.color3 ) 12 | sunLight.color.set(colorObj) 13 | ambient.color.set(colorObj2) 14 | scene.background.set(colorObj3) 15 | } 16 | 17 | ////////////////////////////////////////////////// 18 | //// GUI CONFIG 19 | gui.add(sunLight, 'intensity').min(0).max(10).step(0.0001).name('Dir intensity') 20 | gui.add(sunLight.position, 'x').min(-100).max(100).step(0.00001).name('Dir X pos') 21 | gui.add(sunLight.position, 'y').min(0).max(100).step(0.00001).name('Dir Y pos') 22 | gui.add(sunLight.position, 'z').min(-100).max(100).step(0.00001).name('Dir Z pos') 23 | gui.addColor(params,'color').name('Dir color').onChange(update) 24 | gui.addColor(params,'color2').name('Amb color').onChange(update) 25 | gui.add(ambient, 'intensity').min(0).max(10).step(0.001).name('Amb intensity') 26 | gui.addColor(params,'color3').name('BG color').onChange(update) 27 | 28 | ////////////////////////////////////////////////// 29 | //// ON MOUSE MOVE TO GET CAMERA POSITION 30 | document.addEventListener('mousemove', (event) => { 31 | event.preventDefault() 32 | 33 | console.log(camera.position) 34 | 35 | }, false) -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Threejs Particle Skull - by Anderson Mancini 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
38 |

Skull and Bones

39 |
40 | 41 | -------------------------------------------------------------------------------- /src/main.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | margin: 0; 3 | padding: 0; 4 | overscroll-behavior: none; 5 | overflow: hidden; 6 | } 7 | 8 | .main--container{ 9 | position: absolute; 10 | display: flex; 11 | width: 100%; 12 | height: 100%; 13 | align-content: center; 14 | align-items: center; 15 | pointer-events: none; 16 | } 17 | 18 | .main--title{ 19 | color: white; 20 | font-size: 7em; 21 | font-family: 'Rubik Glitch', cursive; 22 | font-weight: 100; 23 | margin-left: 10%; 24 | width: 510px; 25 | line-height: 90px; 26 | transform: translateX(30%); 27 | opacity: 0; 28 | transition: all 0.8s cubic-bezier(0.55, 0.055, 0.675, 0.19); 29 | } 30 | 31 | .main--title.ended{ 32 | transform: translateX(0); 33 | opacity: 1; 34 | mix-blend-mode: soft-light; 35 | } 36 | 37 | .main--title.ended:after { 38 | /* This value is the OPPOSITE color of our background */ 39 | color: rgb(0, 255, 255); 40 | 41 | } 42 | 43 | 44 | @media only screen and (max-width: 660px) { 45 | .main--title{ 46 | font-size: 5em; 47 | line-height: 0.8em; 48 | } 49 | } -------------------------------------------------------------------------------- /src/script.js: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | ///// IMPORT 3 | import './main.css' 4 | import * as THREE from 'three' 5 | import { TWEEN } from 'three/examples/jsm/libs/tween.module.min.js' 6 | import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js' 7 | import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js' 8 | import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js' 9 | import { MeshSurfaceSampler } from 'three/examples/jsm/math/MeshSurfaceSampler.js' 10 | import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js' 11 | import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js' 12 | import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js' 13 | import { LensDistortionShader } from '../static/shaders/LensDistortionShader.js' 14 | 15 | ///////////////////////////////////////////////////////////////////////// 16 | //// DRACO LOADER TO LOAD DRACO COMPRESSED MODELS FROM BLENDER 17 | const dracoLoader = new DRACOLoader() 18 | const loader = new GLTFLoader() 19 | dracoLoader.setDecoderPath('https://www.gstatic.com/draco/v1/decoders/') 20 | dracoLoader.setDecoderConfig({ type: 'js' }) 21 | loader.setDRACOLoader(dracoLoader) 22 | 23 | ///////////////////////////////////////////////////////////////////////// 24 | ///// DIV CONTAINER CREATION TO HOLD THREEJS EXPERIENCE 25 | const container = document.createElement('div') 26 | document.body.appendChild(container) 27 | 28 | ///////////////////////////////////////////////////////////////////////// 29 | ///// SCENE CREATION 30 | const scene = new THREE.Scene() 31 | scene.background = new THREE.Color(0xc0c0c) 32 | 33 | ///////////////////////////////////////////////////////////////////////// 34 | ///// RENDERER CONFIG 35 | const renderer = new THREE.WebGLRenderer({ antialias: false, powerPreference: "high-performance" }) // turn on antialias 36 | renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)) //set pixel ratio 37 | renderer.setSize(window.innerWidth, window.innerHeight) // make it full screen 38 | renderer.outputEncoding = THREE.sRGBEncoding // set color encoding 39 | container.appendChild(renderer.domElement) // add the renderer to html div 40 | 41 | ///////////////////////////////////////////////////////////////////////// 42 | ///// CAMERAS CONFIG 43 | const camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 1, 100) 44 | camera.position.set(34,16,-20) 45 | scene.add(camera) 46 | 47 | ///////////////////////////////////////////////////////////////////////// 48 | ///// MAKE EXPERIENCE FULL SCREEN 49 | window.addEventListener('resize', () => { 50 | const width = window.innerWidth 51 | const height = window.innerHeight 52 | camera.aspect = width / height 53 | camera.updateProjectionMatrix() 54 | 55 | renderer.setSize(width, height) 56 | composer.setSize(width, height) 57 | renderer.setPixelRatio(2) 58 | m.uniforms.iResolution.value.set(width, height) 59 | }) 60 | 61 | ///////////////////////////////////////////////////////////////////////// 62 | ///// CREATE ORBIT CONTROLS 63 | const controls = new OrbitControls(camera, renderer.domElement) 64 | 65 | ///////////////////////////////////////////////////////////////////////// 66 | ///// LOADING GLB/GLTF MODEL FROM BLENDER 67 | loader.load('models/gltf/Skull.glb', function (gltf) { 68 | 69 | gltf.scene.traverse((obj) => { 70 | if (obj.isMesh) { 71 | sampler = new MeshSurfaceSampler(obj).build() 72 | } 73 | }) 74 | 75 | transformMesh() 76 | }) 77 | 78 | ///////////////////////////////////////////////////////////////////////// 79 | ///// TRANSFORM MESH INTO POINTS 80 | let sampler 81 | let uniforms = { mousePos: {value: new THREE.Vector3()}} 82 | let pointsGeometry = new THREE.BufferGeometry() 83 | const cursor = {x:0, y:0} 84 | const vertices = [] 85 | const tempPosition = new THREE.Vector3() 86 | 87 | function transformMesh(){ 88 | // Loop to sample a coordinate for each points 89 | for (let i = 0; i < 99000; i ++) { 90 | // Sample a random position in the model 91 | sampler.sample(tempPosition) 92 | // Push the coordinates of the sampled coordinates into the array 93 | vertices.push(tempPosition.x, tempPosition.y, tempPosition.z) 94 | } 95 | 96 | // Define all points positions from the previously created array 97 | pointsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3)) 98 | 99 | // Define the matrial of the points 100 | const pointsMaterial = new THREE.PointsMaterial({ 101 | color: 0x5c0b17, 102 | size: 0.1, 103 | blending: THREE.AdditiveBlending, 104 | transparent: true, 105 | opacity: 0.8, 106 | depthWrite: false, 107 | sizeAttenuation: true, 108 | alphaMap: new THREE.TextureLoader().load('particle-texture.jpg') 109 | }) 110 | 111 | // Create the custom vertex shader injection 112 | pointsMaterial.onBeforeCompile = function(shader) { 113 | shader.uniforms.mousePos = uniforms.mousePos 114 | 115 | shader.vertexShader = ` 116 | uniform vec3 mousePos; 117 | varying float vNormal; 118 | 119 | ${shader.vertexShader}`.replace( 120 | `#include `, 121 | `#include 122 | vec3 seg = position - mousePos; 123 | vec3 dir = normalize(seg); 124 | float dist = length(seg); 125 | if (dist < 1.5){ 126 | float force = clamp(1.0 / (dist * dist), -0., .5); 127 | transformed += dir * force; 128 | vNormal = force /0.5; 129 | } 130 | ` 131 | ) 132 | } 133 | 134 | // Create an instance of points based on the geometry & material 135 | const points = new THREE.Points(pointsGeometry, pointsMaterial) 136 | 137 | // Add them into the main group 138 | scene.add(points) 139 | 140 | } 141 | 142 | ///////////////////////////////////////////////////////////////////////// 143 | //// INTRO CAMERA ANIMATION USING TWEEN 144 | function introAnimation() { 145 | controls.enabled = false //disable orbit controls to animate the camera 146 | 147 | new TWEEN.Tween(camera.position.set(0,-1,0 )).to({ // from camera position 148 | x: 2, //desired x position to go 149 | y: -0.4, //desired y position to go 150 | z: 6.1 //desired z position to go 151 | }, 6500) // time take to animate 152 | .easing(TWEEN.Easing.Quadratic.InOut).start() // define delay, easing 153 | .onComplete(function () { //on finish animation 154 | controls.enabled = true //enable orbit controls 155 | document.querySelector('.main--title').classList.add('ended') 156 | setOrbitControlsLimits() //enable controls limits 157 | TWEEN.remove(this) // remove the animation from memory 158 | }) 159 | } 160 | 161 | introAnimation() // call intro animation on start 162 | 163 | ///////////////////////////////////////////////////////////////////////// 164 | //// DEFINE ORBIT CONTROLS LIMITS 165 | function setOrbitControlsLimits(){ 166 | controls.enableDamping = true 167 | controls.dampingFactor = 0.04 168 | controls.minDistance = 0.5 169 | controls.maxDistance = 9 170 | controls.enableRotate = true 171 | controls.enableZoom = true 172 | controls.zoomSpeed = 0.5 173 | controls.autoRotate = true 174 | } 175 | 176 | ///////////////////////////////////////////////////////////////////////// 177 | ///// POST PROCESSING EFFECTS 178 | let width = window.innerWidth 179 | let height = window.innerHeight 180 | const renderPass = new RenderPass( scene, camera ) 181 | const renderTarget = new THREE.WebGLRenderTarget( width, height, 182 | { 183 | minFilter: THREE.LinearFilter, 184 | magFilter: THREE.LinearFilter, 185 | format: THREE.RGBAFormat 186 | } 187 | ) 188 | 189 | const composer = new EffectComposer(renderer, renderTarget) 190 | composer.setPixelRatio(Math.min(window.devicePixelRatio, 2)) 191 | 192 | /////DISTORT PASS ////////////////////////////////////////////////////////////// 193 | const distortPass = new ShaderPass( LensDistortionShader ) 194 | distortPass.material.defines.CHROMA_SAMPLES = 4 195 | distortPass.enabled = true 196 | distortPass.material.uniforms.baseIor.value = 0.910 197 | distortPass.material.uniforms.bandOffset.value = 0.0019 198 | distortPass.material.uniforms.jitterIntensity.value = 20.7 199 | distortPass.material.defines.BAND_MODE = 2 200 | 201 | composer.addPass( renderPass ) 202 | composer.addPass( distortPass ) 203 | 204 | ///////////////////////////////////////////////////////////////////////// 205 | //// CUSTOM SHADER ANIMATED BACKGROUND 206 | let g = new THREE.PlaneBufferGeometry(2, 2) 207 | let m = new THREE.ShaderMaterial({ 208 | side: THREE.DoubleSide, 209 | depthTest: false, 210 | uniforms: { 211 | iTime: { value: 0 }, 212 | iResolution: { value: new THREE.Vector2() }, 213 | mousePos: {value: new THREE.Vector2()} 214 | }, 215 | vertexShader: ` 216 | varying vec2 vUv; 217 | void main(){ 218 | vUv = uv; 219 | gl_Position = vec4( position, 1.0 ); 220 | }`, 221 | fragmentShader: ` 222 | varying vec2 vUv; 223 | uniform float iTime; 224 | uniform vec2 iResolution; 225 | uniform vec2 mousePos; 226 | 227 | #define N 16 228 | #define PI 3.14159265 229 | #define depth 1.0 230 | #define rate 0.3 231 | #define huecenter 0.5 232 | 233 | vec3 hsv2rgb( in vec3 c ) 234 | { 235 | vec3 rgb = clamp( abs(mod(c.y*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, .3 ); 236 | return c.x * mix( vec3(.1), rgb, 1.0); 237 | } 238 | 239 | void main(){ 240 | vec2 v = gl_FragCoord.xy/iResolution.xy; 241 | float t = iTime * 0.08; 242 | float r = 1.8; 243 | float d = 0.0; 244 | for (int i = 1; i < N; i++) { 245 | d = (PI / float(N)) * (float(i) * 14.0); 246 | r += length(vec2(rate*v.y, rate*v.x)) + 1.21; 247 | v = vec2(v.x+cos(v.y+cos(r)+d)+cos(t),v.y-sin(v.x+cos(r)+d)+sin(t)); 248 | } 249 | r = (sin(r*0.09)*0.5)+0.5; 250 | vec3 hsv = vec3( 251 | mod(mousePos.x + huecenter, 1.0), 1.0-0.5*pow(max(r,0.0)*1.2,0.5), 1.0-0.2*pow(max(r,0.4)*2.2,6.0) 252 | ); 253 | gl_FragColor = vec4(hsv2rgb(hsv), 1.0); 254 | }` 255 | }) 256 | 257 | const p = new THREE.Mesh(g, m) 258 | scene.add(p) 259 | 260 | m.uniforms.iResolution.value.set(width, height) 261 | 262 | ///////////////////////////////////////////////////////////////////////// 263 | //// RENDER LOOP FUNCTION 264 | const clock = new THREE.Clock() 265 | function rendeLoop() { 266 | 267 | TWEEN.update() // update animations 268 | 269 | controls.update() // update orbit controls 270 | 271 | composer.render() //render the scene with the composer 272 | distortPass.material.uniforms.jitterOffset.value += 0.01 273 | const time = clock.getElapsedTime() 274 | m.uniforms.iTime.value = time 275 | 276 | requestAnimationFrame(rendeLoop) //loop the render function 277 | } 278 | 279 | rendeLoop() //start rendering 280 | 281 | ////////////////////////////////////////////////// 282 | //// ON MOUSE MOVE TO GET CAMERA POSITION 283 | document.addEventListener('mousemove', (event) => { 284 | event.preventDefault() 285 | cursor.x = event.clientX / window.innerWidth -0.5 286 | cursor.y = event.clientY / window.innerHeight -0.5 287 | uniforms.mousePos.value.set(cursor.x, cursor.y, 0) 288 | m.uniforms.mousePos.value.set(cursor.x, cursor.y) 289 | 290 | }, false) -------------------------------------------------------------------------------- /static/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/.gitkeep -------------------------------------------------------------------------------- /static/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/cover.jpg -------------------------------------------------------------------------------- /static/favicon/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/favicon/android-chrome-192x192.png -------------------------------------------------------------------------------- /static/favicon/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/favicon/android-chrome-512x512.png -------------------------------------------------------------------------------- /static/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /static/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /static/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /static/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/favicon/favicon.ico -------------------------------------------------------------------------------- /static/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | {"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} -------------------------------------------------------------------------------- /static/models/gltf/Skull.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/models/gltf/Skull.glb -------------------------------------------------------------------------------- /static/particle-texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/particle-texture.jpg -------------------------------------------------------------------------------- /static/shaders/LensDistortionShader.js: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/4t2fRz 2 | 3 | export const LensDistortionShader = { 4 | 5 | defines: { 6 | 7 | // 0: NONE, 1: RGB, 2: RYGCBV 8 | BAND_MODE: 2, 9 | 10 | CHROMA_SAMPLES: 1, 11 | 12 | }, 13 | 14 | uniforms: { 15 | 16 | tDiffuse: { value: null }, 17 | baseIor: { value: 0.075 }, 18 | bandOffset: { value: 0.003 }, 19 | jitterIntensity: { value: 1.0 }, 20 | jitterOffset: { value: 0.0 }, 21 | 22 | }, 23 | 24 | vertexShader: /* glsl */` 25 | 26 | varying vec2 vUv; 27 | varying vec3 viewDir; 28 | 29 | void main() { 30 | 31 | vUv = uv; 32 | gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); 33 | viewDir = normalize( ( modelViewMatrix * vec4( position, 1.0 ) ).xyz ); 34 | 35 | } 36 | 37 | `, 38 | 39 | fragmentShader: /* glsl */` 40 | 41 | varying vec2 vUv; 42 | varying vec3 viewDir; 43 | uniform float baseIor; 44 | uniform float bandOffset; 45 | uniform float jitterIntensity; 46 | uniform float jitterOffset; 47 | uniform sampler2D tDiffuse; 48 | 49 | #include 50 | void main() { 51 | 52 | vec3 normal = vec3( ( 2.0 * vUv - vec2( 1.0 ) ), 1.0 ); 53 | normal.z = 1.0; 54 | normal = normalize( normal ); 55 | 56 | vec3 color; 57 | 58 | // if NO BANDS 59 | #if BAND_MODE == 0 60 | 61 | vec3 refracted = refract( vec3( 0.0, 0.0, - 1.0 ), normal, baseIor ); 62 | color = texture2D( tDiffuse, vUv + refracted.xy ).rgb; 63 | 64 | // if RGB or RYGCBV BANDS 65 | #else 66 | 67 | float index, randValue, offsetValue; 68 | float r, g, b, r_ior, g_ior, b_ior; 69 | vec3 r_refracted, g_refracted, b_refracted; 70 | vec4 r_sample, g_sample, b_sample; 71 | 72 | #if BAND_MODE == 2 73 | float y, c, v, y_ior, c_ior, v_ior; 74 | vec3 y_refracted, c_refracted, v_refracted; 75 | vec4 y_sample, c_sample, v_sample; 76 | #endif 77 | 78 | for ( int i = 0; i < CHROMA_SAMPLES; i ++ ) { 79 | 80 | index = float( i ); 81 | randValue = rand( sin( index + 1. ) * gl_FragCoord.xy + vec2( jitterOffset, - jitterOffset ) ) - 0.5; 82 | offsetValue = index / float( CHROMA_SAMPLES ) + randValue * jitterIntensity; 83 | #if BAND_MODE == 1 84 | randValue *= 2.0; 85 | #endif 86 | 87 | // Paper describing functions for creating yellow, cyan, and violet bands and reforming 88 | // them into RGB: 89 | // https://web.archive.org/web/20061108181225/http://home.iitk.ac.in/~shankars/reports/dispersionraytrace.pdf 90 | r_ior = 1.0 + bandOffset * ( 0.0 + offsetValue ); 91 | g_ior = 1.0 + bandOffset * ( 2.0 + offsetValue ); 92 | b_ior = 1.0 + bandOffset * ( 4.0 + offsetValue ); 93 | 94 | r_refracted = refract( vec3( 0.0, 0.0, - 1.0 ), normal, baseIor / r_ior ); 95 | g_refracted = refract( vec3( 0.0, 0.0, - 1.0 ), normal, baseIor / g_ior ); 96 | b_refracted = refract( vec3( 0.0, 0.0, - 1.0 ), normal, baseIor / b_ior ); 97 | 98 | r_sample = texture2D( tDiffuse, vUv + r_refracted.xy ); 99 | g_sample = texture2D( tDiffuse, vUv + g_refracted.xy ); 100 | b_sample = texture2D( tDiffuse, vUv + b_refracted.xy ); 101 | 102 | #if BAND_MODE == 2 103 | y_ior = 1.0 + bandOffset * ( 1.0 + offsetValue ); 104 | c_ior = 1.0 + bandOffset * ( 3.0 + offsetValue ); 105 | v_ior = 1.0 + bandOffset * ( 5.0 + offsetValue ); 106 | 107 | y_refracted = refract( vec3( 0.0, 0.0, - 1.0 ), normal, baseIor / y_ior ); 108 | c_refracted = refract( vec3( 0.0, 0.0, - 1.0 ), normal, baseIor / c_ior ); 109 | v_refracted = refract( vec3( 0.0, 0.0, - 1.0 ), normal, baseIor / v_ior ); 110 | 111 | y_sample = texture2D( tDiffuse, vUv + y_refracted.xy ); 112 | c_sample = texture2D( tDiffuse, vUv + c_refracted.xy ); 113 | v_sample = texture2D( tDiffuse, vUv + v_refracted.xy ); 114 | 115 | r = r_sample.r / 2.0; 116 | y = ( 2.0 * y_sample.r + 2.0 * y_sample.g - y_sample.b ) / 6.0; 117 | g = g_sample.g / 2.0; 118 | c = ( 2.0 * c_sample.g + 2.0 * c_sample.b - c_sample.r ) / 6.0; 119 | b = b_sample.b / 2.0; 120 | v = ( 2.0 * v_sample.b + 2.0 * v_sample.r - v_sample.g ) / 6.0; 121 | 122 | color.r += r + ( 2.0 * v + 2.0 * y - c ) / 3.0; 123 | color.g += g + ( 2.0 * y + 2.0 * c - v ) / 3.0; 124 | color.b += b + ( 2.0 * c + 2.0 * v - y ) / 3.0; 125 | #else 126 | color.r += r_sample.r; 127 | color.g += g_sample.g; 128 | color.b += b_sample.b; 129 | #endif 130 | 131 | } 132 | 133 | color /= float( CHROMA_SAMPLES ); 134 | 135 | #endif 136 | 137 | gl_FragColor = vec4( color, 1.0 ); 138 | 139 | } 140 | 141 | `, 142 | 143 | }; -------------------------------------------------------------------------------- /static/youtube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ektogamat/threejs-particle-skull/6208e52a338728ee4d1098ea90eac1853c74efad/static/youtube.png --------------------------------------------------------------------------------