Skip to content

Instantly share code, notes, and snippets.

@bhouston
Created July 6, 2023 13:04
Show Gist options
  • Save bhouston/cf3d4be00e2cb2a91423321cd81ada80 to your computer and use it in GitHub Desktop.
Save bhouston/cf3d4be00e2cb2a91423321cd81ada80 to your computer and use it in GitHub Desktop.
Meta Threads.net ThreeJS WebGL Code
__d(
'useThrottledImpl',
['cr:1708227'],
function (a, b, c, d, e, f, g) {
'use strict';
g['default'] = b('cr:1708227');
},
98
);
__d(
'useThrottled',
['useThrottledImpl'],
function (a, b, c, d, e, f, g) {
'use strict';
f.exports = c('useThrottledImpl');
},
34
);
__d(
'BarcelonaAnimatedSpiral.react',
[
'Alea',
'BarcelonaGalaxyFallback.react',
'FBLogger',
'OrbitControls.three.r138',
'bx',
'emptyFunction',
'react',
'stylex',
'three.r138',
'useThrottled'
],
function (a, b, c, d, e, f, g) {
'use strict';
var h = d('react');
b = d('react');
var i = b.useCallback,
j = b.useEffect,
k = b.useLayoutEffect,
l = b.useRef,
m = b.useState,
n = c('Alea')(1);
function o(a, b) {
var d,
e = new (c('three.r138').Scene)();
e.rotation.x = -Math.PI / 8;
e.background = null;
var f = new (c('three.r138').PerspectiveCamera)(
75,
a.clientWidth / a.clientHeight,
0.1,
1e3
);
f.position.y = -75;
f.position.z = 400;
var g = new (c('three.r138').WebGLRenderer)({
alpha: !0,
pixelRatio: (d = window.devicePixelRatio) != null ? d : 1
});
g.setSize(a.clientWidth, a.clientHeight);
g.setClearAlpha(0);
d = new (c('three.r138').AmbientLight)(16777215, 0.2);
e.add(d);
d = new (c('three.r138').SpotLight)(16777215, 1.2, 0, Math.PI / 4, 1, 1);
d.position.set(-450, 100, 650);
d.shadow.radius = 100;
e.add(d);
var h = new (c('three.r138').Object3D)();
h.position.set(300, 300, -300);
d.target = h;
e.add(h);
var i = new (c('OrbitControls.three.r138'))(f, g.domElement);
i.maxDistance = 485;
i.minDistance = 200;
i.maxZoom = 485;
i.minZoom = 200;
i.zoomSpeed = 0.5;
i.enableDamping = !0;
i.dampingFactor = 0.05;
i.enableRotate = !0;
i.rotateSpeed = 0.2;
i.update();
d = new (c('three.r138').TextureLoader)();
var j = d.load(c('bx').getURL(c('bx')('10056'))),
k = null;
h = new (c('three.r138').FileLoader)();
h.setResponseType('text');
h.load(
c('bx').getURL(c('bx')('10055')),
function (a) {
try {
a = JSON.parse(a);
var d = new (c('three.r138').SphereGeometry)(1.4, 32, 32);
d = d.clone();
d = new (c('three.r138').InstancedBufferGeometry)().copy(d);
d.instanceCount = a.length;
var h = -800,
l = -800,
m = 800,
o = 800,
p = [],
q = [],
r = [],
s = [];
for (var t = 0; t < a.length; t++) {
var u = a[t],
v = u.x,
w = u.y;
u = u.z;
var x = ((v - h) / (m - h)) * 0.99,
y = ((w - l) / (o - l)) * 0.99;
p.push(x, y);
q.push(v, w, u);
x = 0.3 + n() * 1.5;
r.push(x, x, x);
y = 0.5 + n() * 1.2;
s.push(y);
}
d.setAttribute(
'instanceBrightness',
new (c('three.r138').InstancedBufferAttribute)(
new Float32Array(s),
1
)
);
d.setAttribute(
'instanceScale',
new (c('three.r138').InstancedBufferAttribute)(
new Float32Array(r),
3
)
);
d.setAttribute(
'instancePosition',
new (c('three.r138').InstancedBufferAttribute)(
new Float32Array(q),
3
)
);
d.setAttribute(
'instanceUV',
new (c('three.r138').InstancedBufferAttribute)(
new Float32Array(p),
2
)
);
v = new (c('three.r138').MeshPhongMaterial)({
map: j,
reflectivity: 1
});
v.onBeforeCompile = function (a) {
(a.vertexShader =
'attribute vec3 instancePosition;\nattribute vec2 instanceUV;\nattribute vec3 instanceScale;\nattribute float instanceBrightness;\nvarying float vBrightness;\n' +
a.vertexShader),
(a.vertexShader = a.vertexShader.replace(
'#include <begin_vertex>',
[
'vec3 transformed = vec3( position * instanceScale + instancePosition );',
'vUv = instanceUV;',
'vBrightness = instanceBrightness;'
].join('\n')
)),
(a.fragmentShader =
'\n varying float vBrightness;\n ' +
a.fragmentShader +
'\n '),
(a.fragmentShader = a.fragmentShader.replace(
'vec4 diffuseColor = vec4( diffuse, opacity );',
[
'vec4 diffuseColor = vec4( diffuse * vBrightness, opacity );'
].join('\n')
));
};
k = new (c('three.r138').Mesh)(d, v);
e.add(k);
k.position.y = 115;
w = function a() {
window.requestAnimationFrame(a),
g.render(e, f),
i.update(),
k && (k.rotation.z -= 25e-5);
};
w();
} catch (a) {
b(a);
}
},
function (a) {},
function (a) {
b(a);
}
);
a.appendChild(g.domElement);
d = function () {
var a;
e.remove(k);
g.dispose();
(a = k) == null ? void 0 : a.geometry.dispose();
(a = k) == null ? void 0 : a.material.dispose();
(a = k) == null
? void 0
: (a = a.material.map) == null
? void 0
: a.dispose();
};
return { renderer: g, camera: f, dispose: d };
}
var p = {
root: {
width: 'xn9wirt',
height: 'x1dr59a3',
cursor: 'x1jm3nie',
opacity: 'xg01cxk',
':active_cursor': 'xch2mbi',
$$css: !0
},
rootVisible: {
transitionProperty: 'x19991ni',
transitionDuration: 'x16fj20d',
transitionTimingFunction: 'x1lizcpb',
opacity: 'x1hc1fzr',
$$css: !0
}
};
function a(a) {
var b = l(null),
d = l(null),
e = l(null),
f = l(c('emptyFunction'));
a = m(!1);
var g = a[0],
n = a[1];
a = m(!1);
var q = a[0],
r = a[1],
s = function () {
c('FBLogger')('barcelona_web').mustfix('Error loading 3D galaxy'),
r(!0);
};
k(
function () {
var a = b.current,
c = function () {
g && f.current();
};
if (g || a == null || a.children.length > 0) return c;
if (d.current == null || e.current == null) {
try {
a = o(a, s);
var h = a.camera,
i = a.dispose;
a = a.renderer;
d.current = a;
e.current = h;
f.current = i;
} catch (a) {
s();
}
n(!0);
}
return c;
},
[g]
);
a = i(function () {
var a = b.current,
c = e.current,
f = d.current;
if (c == null || f == null || a == null) return;
c.aspect = a.clientWidth / a.clientHeight;
c.updateProjectionMatrix();
f.setSize(a.clientWidth, a.clientHeight);
}, []);
var t = c('useThrottled')(a, 250);
j(
function () {
window.addEventListener('resize', t);
return function () {
window.removeEventListener('resize', t);
};
},
[t]
);
return q
? h.jsx(c('BarcelonaGalaxyFallback.react'), {})
: h.jsx('div', {
className: c('stylex')(p.root, g && p.rootVisible),
ref: b
});
}
a.displayName = a.name + ' [from ' + f.id + ']';
g['default'] = a;
},
98
);
__d(
'useThrottledComet',
['CometThrottle', 'react', 'useStable'],
function (a, b, c, d, e, f, g) {
'use strict';
b = d('react');
var h = b.useEffect,
i = b.useLayoutEffect,
j = b.useRef;
function a(a, b) {
b === void 0 && (b = 100);
var d = j(a);
i(
function () {
d.current = a;
},
[a]
);
var e = c('useStable')(function () {
return c('CometThrottle')(function () {
var a = arguments;
return d.current == null ? void 0 : d.current.apply(d, a);
}, b);
});
h(function () {
return function () {
e.cancel();
};
}, []);
return e;
}
g['default'] = a;
},
98
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment