Skip to content

Instantly share code, notes, and snippets.

View donmccurdy's full-sized avatar

Don McCurdy donmccurdy

View GitHub Profile
@donmccurdy
donmccurdy / delete_tweets.js
Last active November 11, 2024 21:42
Delete Tweets
// To delete tweets, navigate to your Twitter/X profile, open your browser's JavaScript console, and paste the script below.
async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
async function deleteTweets() {
const tweetsRemaining = document.querySelectorAll('[role="heading"]+div')[1].textContent;
console.log('Remaining: ', tweetsRemaining);
window.scrollBy(0, 10000);
@donmccurdy
donmccurdy / index.html
Created May 31, 2024 17:31
ThreeJS BrightnessContrastShader + ACESFilmicToneMapping - strange behaviour ?
<div>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/"
}
}
</script>
@donmccurdy
donmccurdy / generate-points.ts
Created March 18, 2024 18:53
Generate a point cloud in glTF format, using glTF Transform.
import { Document, NodeIO, Primitive } from '@gltf-transform/core';
const document = new Document();
const buffer = document.createBuffer();
const position = document.createAccessor()
.setType('VEC3')
.setBuffer(buffer)
.setArray(new Float32Array([
0, 0, 0, // ax,ay,az
@donmccurdy
donmccurdy / vertex-count-method.ts
Created March 17, 2024 14:38
Draft enum, describing different methods for computing vertex counts.
/**
* Various methods of estimating a vertex count. For some background on why
* multiple definitions of a vertex count should exist, see [_Vertex Count
* Higher in Engine than in 3D Software_](https://shahriyarshahrabi.medium.com/vertex-count-higher-in-engine-than-in-3d-software-badc348ada66).
*
* NOTICE: Many rendering features, such as volumetric transmission, may lead
* to additional passes over some or all vertices. Such tradeoffs are
* implementation-dependent, and not considered here.
*/
export enum VertexCountMethod {
@donmccurdy
donmccurdy / scan-missing-dependencies.ts
Last active March 15, 2024 18:49
Scan a monorepo for missing or transitive dependencies in subpackages.
import {readFile} from 'node:fs/promises';
import {join} from 'node:path';
import glob from 'glob';
import builtinModules from 'builtin-modules';
const IMPORT_IDENTIFIER_REGEX = /(?:\A|\r|\n|\r\n)import[^'"]*['"]([\@\.\/\w_-]+)['"]/g;
const BUILTIN_MODULES = new Set<string>(builtinModules);
const pkgPaths = glob.sync(join('modules', '*', 'package.json'));
@donmccurdy
donmccurdy / ocio_tonemap_gen.sh
Created December 13, 2023 15:07
Applies tone mapping (display transform + look) to source OpenEXR images using Blender's AgX OCIO config.
#!/usr/bin/env bash
OCIO="/Applications/Blender 4.0.app/Contents/Resources/4.0/datafiles/colormanagement/config.ocio"
OCIO_LOOK="AgX - Base Contrast"
# Source: https://github.com/sobotka/Testing_Imagery
declare -a arr=(
"blue_bar_709"
"Matas_Alexa_Mini_sample_BT709"
"mery_lightSaber_lin_srgb"
@donmccurdy
donmccurdy / gen-torus.js
Last active August 19, 2023 13:54
Sample code for generating a torus-shaped GLB from scratch using glTF Transform.
import { Document, NodeIO } from '@gltf-transform/core';
function createTorus(radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2) {
const indicesArray = [];
const positionArray = [];
const texcoordArray = [];
const vertex = [0, 0, 0];
// generate positions and uvs
@donmccurdy
donmccurdy / batch_process.sh
Created January 31, 2023 02:35
Example script for batch CLI processing with glTF Transform.
#!/bin/bash
FILES="./path/to/models/*.glb"
for file in $FILES; do
echo "Compressing $file..."
gltf-transform draco "${file%.glb}.glb" "${file%.glb}-draco.glb"
done
@donmccurdy
donmccurdy / EXTRACT_GEOMETRY.mjs
Last active September 27, 2022 04:22
Example Node.js script using glTF-Transform to extract geometry from a glTF document and create a geometry-only three.js scene graph.
import { NodeIO } from '@gltf-transform/core';
import { KHRONOS_EXTENSIONS } from '@gltf-transform/extensions';
import draco3d from 'draco3dgltf';
// set up I/O
const io = new NodeIO()
.registerExtensions(KHRONOS_EXTENSIONS)
.registerDependencies({'draco3d.decoder': await draco3d.createDecoderModule()});
const document = await io.read('path/to/file.glb');
@donmccurdy
donmccurdy / generate_lods.mjs
Last active June 18, 2024 04:45
Example implementation of MSFT_lod in glTF-Transform.
import { Extension, ExtensionProperty, Node, NodeIO, PropertyType } from '@gltf-transform/core';
import { weld, dedup, simplifyPrimitive } from '@gltf-transform/functions';
import { MeshoptSimplifier } from 'meshoptimizer';
/******************************************************************************
* Example implementation of MSFT_lod for glTF-Transform.
*
* ⚠️ NOTICE: This code is provided for the sake of example, and is not tested or
* maintained. For a full implementation, refer to:
* https://github.com/takahirox/glTF-Transform-lod-script