Skip to content

Instantly share code, notes, and snippets.

View zhihuidev's full-sized avatar
🏠
Working from home

Zhihui Wang zhihuidev

🏠
Working from home
View GitHub Profile
@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);
@sergiodxa
sergiodxa / async-thread.js
Last active June 27, 2023 05:38
Use WebWorkers and promises to run sync heavy functions in a worker (process) and get the result in a promise
function asyncThread(fn, ...args) {
if (!window.Worker) throw Promise.reject(
new ReferenceError(`WebWorkers aren't available.`)
);
const fnWorker = `
self.onmessage = function(message) {
(${fn.toString()})
.apply(null, message.data)
.then(result => self.postMessage(result));