Skip to content

Instantly share code, notes, and snippets.

View lojjic's full-sized avatar

Jason Johnston lojjic

View GitHub Profile
@lojjic
lojjic / Html.tsx
Created April 18, 2023 22:03
A wrapper for Drei's <Html> component that works around some issues when used with the Matterport R3F web component
import { useThree } from '@react-three/fiber';
import React, { useEffect } from 'react';
import { Html as DreiHtml } from '@react-three/drei';
import type { HtmlProps } from '@react-three/drei/web/Html';
export function Html(props: HtmlProps) {
const { gl } = useThree();
const canvas = gl.domElement as HTMLCanvasElement;
// Drei's Html component sets pointerEvents:'none' on the canvas, which breaks MP
alert('HACKED!')
@lojjic
lojjic / r3f instances.jsx
Last active September 14, 2021 16:25
R3F instancing API - with mixed instancing types
// Each InstanceTemplate becomes an InstancedMesh behind the scenes.
// In this example we'll end up with 2 draw calls.
// This proposal uses a string `id` to refer to the templates, but it
// could also possibly be done by reference?
const Example = () => {
return <Instances>
<InstanceTemplate id="instancedBox">
<boxGeometry />
<meshStandardMaterial />
@lojjic
lojjic / js-module-url-fragments.js
Created January 25, 2021 23:19
JS module blocks addressable as fragments
/*
This is an idea I had for allowing multiple modules within a single file, each of
which is addressable via URL fragment. Something like this could simplify bundling,
especially if used in conjunction with Import Maps. It could also be a nice way
to run blocks of code in web workers, where those blocks don't require a separate
file and can themselves import other modules in the same file or other files.
*/
// File_A.js
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#one, #two, #three {
position: absolute;
width: 200px;
height: 200px;
background: #EEE;
@lojjic
lojjic / mediaQuerySrc.js
Created April 7, 2012 04:24
Zepto plugin for conditionally setting the src of images based on CSS media queries.
/**
* Utility for conditionally setting the src of images based on CSS media queries.
* Example usage:
*
* HTML:
*
* <img class="dynamic" data-src-1="one.png" data-src-2="two.png">
*
* JS:
*
@lojjic
lojjic / 149Test
Created March 26, 2012 02:46 — forked from gruber76/149Test.html
"Simple" break for PIE with AngularJS
<html class="no-js" lang="en" xmlns:ng="http://angularjs.org" ng:app>
<HEAD>
</HEAD>
<BODY>
<div id="pieFace" style="
-pie-background: linear-gradient(top, rgba(0, 0, 0, 0.3) 0%, rgba(125, 134, 136, 0.3) 10%, rgba(125, 134, 136, 0.3) 60%, rgba(125, 134, 136, 0.6) 80%, rgba(125, 134, 136, 0.8) 100%);
height: 50px;
width: 50px;
" pie=""></div>
{
data: [{
manufacturer: 'Porsche',
model: '911',
price: 135000,
wiki: 'http://en.wikipedia.org/wiki/Porsche_997',
img: '2004_Porsche_911_Carrera_type_997.jpg'
},{
manufacturer: 'Nissan',
model: 'GT-R',
if(prop == 'marginRight' && out != '0px' && !supports.RightMargin){
/*
selection = window.getSelection();
ranges = [];
for (i = 0, len = selection.rangeCount; i < len; i++) {
ranges.push(selection.getRangeAt(i).cloneRange());
}
*/
/*
var selection = window.getSelection(),