Skip to content

Instantly share code, notes, and snippets.

View CodyJasonBennett's full-sized avatar

Cody Bennett CodyJasonBennett

View GitHub Profile
@CodyJasonBennett
CodyJasonBennett / index.css
Created January 15, 2021 12:02
Chromakey Video three.js
body {
margin: 0;
}
canvas {
display: block;
}
video {
display: none;
@CodyJasonBennett
CodyJasonBennett / index.html
Last active September 19, 2021 20:26
THREE SSR Discord.js
<!DOCTYPE >
<html>
<head>
<meta charset="UTF-8" />
<style>
body {
margin: 0;
}
canvas {
@CodyJasonBennett
CodyJasonBennett / index.js
Last active September 2, 2021 02:46
2D de Casteljau algorithm
function deCasteljauAlgorithm(points, t) {
if (t === 1) return points[points.length - 1];
if (t === 0 || points.length === 1) return points[0];
const calculatedPoints = [];
for (let i = 1; i < points.length; i++) {
const [p1X, p1Y] = points[i - 1];
const [p2X, p2Y] = points[i];
@CodyJasonBennett
CodyJasonBennett / index.js
Created September 2, 2021 04:52
3D de Casteljau algorithm
import { Vector3 } from 'https://cdn.skypack.dev/three';
const tempVector = new Vector3();
function deCasteljauAlgorithm(vectors, t) {
if (t === 1) return vectors[vectors.length - 1];
if (t === 0 || vectors.length === 1) return vectors[0];
const calculatedVectors = [];
@CodyJasonBennett
CodyJasonBennett / rollup.config.js
Last active October 16, 2021 19:17
Rollup - Advanced Vercel API
// rollup.config.js (builds src/api => api -- use `rollup -c` to build)
import { join } from 'path';
import { mkdirSync, copyFileSync, statSync, readdirSync } from 'fs';
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
const API_DIR = join(process.cwd(), 'src/api');
const BUILD_DIR = join(process.cwd(), 'api');
// Copy package.json to build dir
@CodyJasonBennett
CodyJasonBennett / polyfill.js
Created January 18, 2022 00:13
react-native polyfill for usage of three.js loaders
import * as THREE from 'three'
import { Asset } from 'expo-asset'
/**
* Generates an asset based on input type.
*/
const getAsset = (input) => {
if (input instanceof Asset) return input
switch (typeof input) {
@CodyJasonBennett
CodyJasonBennett / WebGLFBO.ts
Last active May 9, 2022 18:07
WebGL 2 FBO w/Multisampled MRT
/**
* Constructs a WebGL FBO with MRT and multi-sampling.
*/
export class WebGLFBO {
readonly gl: WebGL2RenderingContext
readonly width: number
readonly height: number
readonly count: number
readonly samples: number
readonly frameBuffer: WebGLFramebuffer
@CodyJasonBennett
CodyJasonBennett / App.js
Created May 16, 2022 17:27
v7 React Native Canvas
/**
* react-native example using R3F v7.
*
* Dependencies:
* - @react-three/fiber 7.0.29
* - react 17.0.1
* - react-native 0.68.2
* - expo-gl 11.3.0
*/
import * as THREE from 'three'
import { Asset } from 'expo-asset'
/**
* Generates an asset based on input type.
*/
const getAsset = (input) => {
if (input instanceof Asset) return input
switch (typeof input) {
@CodyJasonBennett
CodyJasonBennett / react-native+0.68.1.patch
Created June 15, 2022 04:31
react-native ArrayBuffer => Blob fix
diff --git a/node_modules/react-native/Libraries/Blob/BlobManager.js b/node_modules/react-native/Libraries/Blob/BlobManager.js
index 0d4cee7..9e39534 100644
--- a/node_modules/react-native/Libraries/Blob/BlobManager.js
+++ b/node_modules/react-native/Libraries/Blob/BlobManager.js
@@ -14,6 +14,7 @@ const BlobRegistry = require('./BlobRegistry');
import type {BlobData, BlobOptions, BlobCollector} from './BlobTypes';
import NativeBlobModule from './NativeBlobModule';
import invariant from 'invariant';
+import { getBlobForArrayBuffer } from 'react-native-blob-jsi-helper';