Skip to content

Instantly share code, notes, and snippets.

View donmccurdy's full-sized avatar

Don McCurdy donmccurdy

View GitHub Profile
@donmccurdy
donmccurdy / README.md
Last active April 10, 2024 14:51
Convert legacy three.js (JSON) files to glTF 2.0

legacythree2gltf.js

Converts legacy JSON models (created by the three.js Blender exporter, for THREE.JSONLoader) to glTF 2.0. When original .blend files are available, prefer direct export from Blender 2.80+.

NOTE: JSON files created with .toJSON() use a newer JSON format, which isn't deprecated, and these are still supported by THREE.ObjectLoader. This converter does not support that newer type of JSON file.

Installation:

npm install canvas vblob three
@donmccurdy
donmccurdy / MAX_BONE_WEIGHTS.md
Last active April 2, 2024 22:43
Vertex bone influence limits for 3D tools
engine max influences / vertex
BabylonJS 8
Cesium 4
Godot 8
Love3D 4
three.js 4
UE4 8
Unity 1, 2, 4, or Unlimited
Windows MR 4
@donmccurdy
donmccurdy / README.md
Last active April 1, 2024 18:15
Divide glTF Document

Divide glTF Document

Example script showing how to use glTF-Transform (https://gltf-transform.donmccurdy.com/) to divide a glTF asset — along an axis — into two GLBs, each occupying half the original bounding box. This is just a rough illustration, and has only been tested against a point cloud containing a single mesh. A production implementation would want to do more than this:

  • support >2 divisions
  • for primitives that lie fully in one division, don't write an empty primitive to the others
  • support triangles, lines, etc.

For input with significant outliers (e.g. noisy point clouds), dividing by the center of the bounding box may give unexpected results.

@donmccurdy
donmccurdy / installing-live-server.md
Last active March 27, 2024 20:30
Installing Node.js live-server

Installing Node.js live-server

The NodeJS live-server package runs a temporary server displaying any HTML/CSS/JS resources in the current folder. It automatically reloads the page in your browser when any of these files change.

OS X

  • Verify that Node.js is installed. If you see anything when you run which npm in a terminal, it is. If not, follow the instructions at nodejs.org to install.
  • Install live-server: npm install -g live-server
  • Move your terminal to where your pages live: cd <path-to-content>
  • Start the server: live-server .
@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'));
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no,user-scalable=no,maximum-scale=1">
<title>Examples • Slow Mouse</title>
<script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
<script src="https://cdn.rawgit.com/donmccurdy/aframe-extras/v3.3.0/dist/aframe-extras.min.js"></script>
<script>
AFRAME.registerComponent('slowmouse-controls', {
@donmccurdy
donmccurdy / wildcard-to-regexp.js
Last active February 21, 2024 06:49
Wildcard and glob matching in JavaScript.
/**
* Creates a RegExp from the given string, converting asterisks to .* expressions,
* and escaping all other characters.
*/
function wildcardToRegExp (s) {
return new RegExp('^' + s.split(/\*+/).map(regExpEscape).join('.*') + '$');
}
/**
* RegExp-escapes all characters in the given string.
@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"