Skip to content

Instantly share code, notes, and snippets.

View eliemichel's full-sized avatar

Elie Michel eliemichel

View GitHub Profile
struct Ray {
vec3 origin;
vec3 direction;
};
bool intersectRaySphere(out vec3 intersection, in Ray ray, in vec3 center, in float radius) {
vec3 o = center - ray.origin;
float d2 = dot(ray.direction, ray.direction);
float r2 = radius * radius;
@eliemichel
eliemichel / blender_duplicate_node.py
Last active May 30, 2022 17:06
Snippet for reproducing the Shift+D in a node graph editor in Blender
import bpy
def duplicate_node(n1, node_group=None, duplicate_links=False):
"""
Duplicate a node (without duplicating its links)
@param n1 The node to duplicate
@param node_group (optional) Group in which the node must be duplicated
@param duplicate_links Whether to keep input links or not
@return the new duplicate node
"""
// [...]
/**
* Create a new Mesh representing a simple pizza (really just a disc with
* a few quads on top of it).
* olive_count is the number of olives topping the pizza
* radius is the radius of the pizza
* base_polys is filled with the range of polygons belonging to the base
* olive_polys is filled with the range of polygons representing the olives
*/
@eliemichel
eliemichel / git_resolve.py
Last active April 8, 2022 07:55
Resolve conflicted areas of a file in favor of theirs or ours and leave correctly merged areas as is
# This is an automation of https://stackoverflow.com/questions/71783590/git-merge-strategy-option-theirs-for-individual-files
# Example:
# git_resolve.py --theirs path/to/some/file
import os
import argparse
from shutil import copyfile
import subprocess
parser = argparse.ArgumentParser(description='Resolve conflicted areas of a file during a git merge')
@eliemichel
eliemichel / CMakeLists.txt
Last active July 13, 2021 16:54
Linking issue with OpenVDB - Windows 10, Visual Studio 16 2019, static linking
cmake_minimum_required(VERSION 3.7..3.20)
project(MyTest LANGUAGES CXX)
set(OpenVDB_INSTALL_DIR "" CACHE STRING "Directory specified as CMAKE_INSTALL_PREFIX when building OpenVDB")
list(APPEND CMAKE_MODULE_PATH "${OpenVDB_INSTALL_DIR}/lib/cmake/OpenVDB")
set(OPENVDB_USE_STATIC_LIBS ON)
find_package(OpenVDB COMPONENTS openvdb REQUIRED)
@eliemichel
eliemichel / TinyTimer.h
Created June 7, 2021 15:39
A simple C++ timer library
/**
* A simple timer library.
*
* Basic usage:
* using TinyTimer::Timer;
* Timer timer;
* // .. do something
* cout << "Something took " << timer.ellapsed() << " seconds" << endl;
*
* One can also consolidate several timings to measure standard deviation:
@eliemichel
eliemichel / apply_temporal_mapping.jsx
Created August 8, 2020 14:59
Temporal Stabilization for AfterEffects
// Select the layer to apply remapping to
// (the rush or any edited version of the rush as long as
// the in/out timings match the original)
var layer = app.project.activeItem.selectedLayers[0];
var timeRemapping = layer.property("ADBE Time Remapping");
// Remove previous keys
while (timeRemapping.numKeys > 0) {
timeRemapping.removeKey(1);
@eliemichel
eliemichel / MOD_pizza.c
Created September 14, 2019 09:03
Dummy Blender modifier
#include "BKE_modifier.h"
#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
static Mesh *pizza_applyModifier(struct ModifierData *md,
const struct ModifierEvalContext *ctx,
struct Mesh *mesh)
{
printf("PIZZA is cooking on data @%p\n", md);
return mesh;
@eliemichel
eliemichel / eliemichel_bezierspline_PythonModule.py
Created April 24, 2019 10:04
Script of a BezierSpline Houdini Digital Asset
# BezierSpline
# (Houdini Digital Asset Module)
# Shared under the terms of the MIT License
# Copyright (c) 2019 Elie Michel
# This is a wip, expect more docstring eventually
from __future__ import print_function
# Utils
# Varint decoding: https://developers.google.com/protocol-buffers/docs/encoding
import struct
def readVarint(f):
multiplier = 1
value = 0
b = 0xff
while b & 128:
b = struct.unpack('B', f.read(1))[0]
value += multiplier * (b & 127)