Skip to content

Instantly share code, notes, and snippets.

View eliemichel's full-sized avatar

Elie Michel eliemichel

View GitHub Profile
@eliemichel
eliemichel / packHalf2x16.py
Created December 29, 2023 01:20
An efficient numpy implementation of GLSL packHalf2x16 and unpackHalf2x16
"""
An efficient numpy implementation of GLSL packHalf2x16 and unpackHalf2x16.
Author: Elie Michel <elie.michel@exppad.com>
License: MIT - 2023
"""
def packHalf2x16(x, y):
"""
Pack two floats into a single uint32, like GLSL's packHalf2x16 function
(but vectorized for numpy arrays).
@eliemichel
eliemichel / extract_marmoset_archive.py
Last active December 14, 2023 08:17
Extract the items contained in a Marmoset Viewer's .mview archive file
import struct
import os
# Parameter
archive = "vivfox.mview"
def readCString(f):
"""This is the most naive implementation possible, don't use in prod"""
str = ""
c = f.read(1)
@eliemichel
eliemichel / list_marmoset_archive.py
Last active December 14, 2023 08:05
List the items contained in a Marmoset Viewer's .mview archive file
import struct
def readCString(f):
"""This is the most naive implementation possible, don't use in prod"""
str = ""
c = f.read(1)
while c != '\0':
str += c
c = f.read(1)
return str
@eliemichel
eliemichel / save_texture.h
Last active July 2, 2023 13:46
A single-header utility file to save a given WebGPU Texture MIP level into an image
#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 / webgpu-raii.h
Created May 14, 2023 10:58
An example of RAII wrapper for WebGPU's wgpu::Buffer
// 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_view.h
Last active April 22, 2023 08:47
A single-header utility file to save a WebGPU TextureView into an image
#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 / marmoset.js
Created March 1, 2019 22:46
Marmoset viewer embedded code, as is
/*
(Built: Mon, Sep 24, 2018 4:38:25 PM)
Marmoset Viewer Code and Tools
Copyright (c) 2018 Marmoset LLC.
All rights reserved.
Redistribution and use of this software are permitted provided
that the software remains whole and unmodified and this copyright
notice remains attached. Use or inclusion of any portion of this
import bpy
class IconPanel(bpy.types.Panel):
"""Creates a Panel width all possible icons"""
bl_label = "Icons"
bl_idname = "icons_panel"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
@eliemichel
eliemichel / local_import.py
Last active October 18, 2022 21:55
Import a module from another text in the same .blend file
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
# 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.