Skip to content

Instantly share code, notes, and snippets.

View zadvorsky's full-sized avatar

Szenia Zadvornykh zadvorsky

View GitHub Profile
@zadvorsky
zadvorsky / Geometry.js
Created June 1, 2021 02:12
Three.js deprecated `Geometry` in favor of `BufferGeometry` some time ago, though they still offer the `Geometry` class as an external ES6 module. This is that same class, but modified to use the global THREE namespace, so it can be included in a regular script tag for older projects without a build step. Once included, the script defines `THREE…
const _m1 = new THREE.Matrix4();
const _obj = new THREE.Object3D();
const _offset = new THREE.Vector3();
class Geometry extends THREE.EventDispatcher {
constructor() {
super();
@zadvorsky
zadvorsky / CameraStore.js
Created February 9, 2021 20:40
Store a THREE.js camera position and (Orbit) controls target between page refreshes. Handy if you're working on a scene and refreshing often.
/**
* Use the Web Storage API to save camera position and target between page refreshes.
*
* @param {Object} options
* @param {*} options.camera - The camera you want to store the position of.
* @param {*} [options.controls] - A controls object with a `.target` property.
* @param {String} [options.name="main"] - An optional label. Useful if you want to store multiple cameras.
* @param {Boolean} [options.session=true] - Indicates if you want to use local or session storage.
* See https://developer.mozilla.org/en-US/docs/Web/API/Storage
*/
@zadvorsky
zadvorsky / 01_load_basic.js
Last active August 12, 2020 03:23
Three.js Promise Loading
const material = new THREE.MeshStandardMaterial({
map: new THREE.TextureLoader().load('map.jpg'),
normalMap: new THREE.TextureLoader().load('normalMap.jpg')
});
const loader = new THREE.JSONLoader();
loader.load('geometry.json', geometry => {
const mesh = new THREE.Mesh(geometry, material);