Skip to content

Instantly share code, notes, and snippets.

Avatar

Elie Michel eliemichel

View GitHub Profile
@eliemichel
eliemichel / webgpu-raii.h
Created May 14, 2023 10:58
An example of RAII wrapper for WebGPU's wgpu::Buffer
View webgpu-raii.h
// Using https://github.com/eliemichel/WebGPU-Cpp
#include <webgpu/webgpu.hpp>
namespace raii {
class Buffer {
public:
// Whenever a RAII instance is created, we create an underlying resource
Buffer(wgpu::Device device, const wgpu::BufferDescriptor& bufferDesc)
: m_raw(device.createBuffer(bufferDesc))
{}
@eliemichel
eliemichel / save_texture.h
Last active April 22, 2023 13:55
A single-header utility file to save a given WebGPU Texture MIP level into an image
View save_texture.h
#include "stb_image_write.h"
#include <webgpu/webgpu.hpp>
#include <filesystem>
#include <string>
bool saveTexture(const std::filesystem::path path, wgpu::Device device, wgpu::Texture texture, int mipLevel) {
using namespace wgpu;
@eliemichel
eliemichel / save_texture_view.h
Last active April 22, 2023 08:47
A single-header utility file to save a WebGPU TextureView into an image
View save_texture_view.h
#include "stb_image_write.h"
#include <webgpu/webgpu.hpp>
#include <filesystem>h
#include <string>
std::filesystem::path resolvePath(int frame) {
std::filesystem::path base = "render/frame" + std::to_string(frame) + ".png";
create_directories(base.parent_path());
@eliemichel
eliemichel / local_import.py
Last active October 18, 2022 21:55
Import a module from another text in the same .blend file
View local_import.py
def local_import(module_name):
exec('\n'.join([l.body for l in bpy.data.texts[module_name].lines]))
for k, v in locals().items():
globals()[k] = v
# Example
import bpy
import bmesh
import numpy as np
local_import('tiny_timer.py')
@eliemichel
eliemichel / tiny_timer.py
Created October 18, 2022 21:46
A minimal profiling module
View tiny_timer.py
# Credits 2020-2022 to Élie Michel <elie.michel@exppad.com>
# Released in Public Domain
#
# The Software is provided "as is", without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and non-infringement. In no event shall the
# authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising
# from, out of or in connection with the software or the use or other dealings
# in the Software.
@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
View blender_duplicate_node.py
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
"""
View node_geo_pizza.cc
// [...]
/**
* 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
View git_resolve.py
# 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
View CMakeLists.txt
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
View TinyTimer.h
/**
* 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: