Skip to content

Instantly share code, notes, and snippets.

@scurest
scurest / palin.cxx
Created July 30, 2017 18:09
Palindromic decompositions
#include <iostream>
#include <string>
#include <vector>
struct range {
const char* start;
const char* end;
};
/// Check if a range is palindromic.
@scurest
scurest / gltf_merge_anim.py
Created August 16, 2017 05:34
Quick code to convert a glTF with multiple non-overlapping animations to one with a single animation.
#!/bin/env python
"""Merge mutiple glTF 2.0 animations into one."""
import json
import sys
def merge(gltf):
# Maps (node, path) to (input, output, interpolation)
target_to_sampler = {}
for animation in gltf.get('animations', []):
for channel in animation['channels']:
#!/bin/env python
"""Generate a glTF like MetalRoughSpheres, but with factors instead of textures.
Output is written to MetalRoughFactorSpheres.gltf and MetalRoughFactorSpheres.bin.
"""
from math import sqrt
import base64
import json
import struct
@scurest
scurest / Triangle2.gltf
Created September 4, 2017 06:28
Same as Triangle.gltf, but with a duplicate mesh.
{
"scenes" : [
{
"nodes" : [ 0 ]
}
],
"nodes" : [
{
"mesh" : 0
}
@scurest
scurest / mrspheres.py
Last active September 7, 2017 23:23
Generates MetalRoughSpheres
#!/bin/env python
"""Generates MetalRoughSpheres.
Output is written to MetalRoughSpheres.gltf and MetalRoughSpheres.bin.
"""
from math import sqrt
import base64
import json
import struct
@scurest
scurest / f32-in.c
Created October 24, 2017 19:17
Tests rountripping floating-point numbers by printfing them in zig and then scanfing them in C
#include <stdio.h>
#include <stdint.h>
#include <math.h>
uint32_t f2i(float x) { return *(uint32_t*)(&x); }
float i2f(uint32_t x) { return *(float*)(&x); }
int main() {
uint32_t i = 0;
while (1) {
@scurest
scurest / apicula_material_vertex_color.py
Last active March 21, 2018 19:38
Make all materials in Blender (2.79) be influenced by vertex color.
import bpy
for mat in bpy.data.materials:
mat.use_nodes = True
out_node = mat.node_tree.nodes[0]
mat_node = mat.node_tree.nodes[1]
mat_node.location = -140, 425
mat_node.material = bpy.data.materials[mat.name]
{
"accessors": [
{
"bufferView": 0,
"componentType": 5126,
"count": 1728,
"type": "VEC3",
"byteOffset": 0,
"min": [
-12.592718124389648,
@scurest
scurest / iqm-animation-notes.txt
Last active December 23, 2019 22:30
Notes on how IQM 2 animations work
Notes on how IQM 2 animations work:
(see http://sauerbraten.org/iqm/iqm.txt)
There is just one global animation strip for the whole file. Each iqmanim is
defined by picking out one subrange of frames from this global strip.
Every joint has one iqmpose. Every iqmpose has ten channels for the ten TRS
properties (Tx Ty Tz Qx Qy Qz Qw Sx Sy Sz). Every channel maps a frame
number to the value of that TRS property at that frame. A channel can be
either constant or variable.
@scurest
scurest / top_hn.rs
Created February 27, 2019 10:23
V language comparison task in Rust
extern crate crossbeam;
extern crate reqwest;
extern crate serde;
extern crate serde_json;
use crossbeam::atomic::AtomicCell;
use crossbeam::thread::scope;
use reqwest::Client;
use serde::Deserialize;