Skip to content

Instantly share code, notes, and snippets.

View dendenxu's full-sized avatar
🚲
Riding bike

Zhen Xu dendenxu

🚲
Riding bike
View GitHub Profile
@dendenxu
dendenxu / dllmain.cpp
Created August 6, 2025 10:44 — forked from aidnzz/dllmain.cpp
Injecting raw input into roblox
#define NOMINMAX
#include <mutex>
#include <string_view>
#include <windows.h>
#include "minhook.h"
#pragma comment(lib, "libminhook-x86")
@dendenxu
dendenxu / benchmark_torch_loop_subdivision.py
Created October 8, 2022 14:50
Differentiable pytorch implementation of A Halfedge Refinement Rule for Parallel Loop Subdivision: http://kenneth.vanhoey.free.fr/index.php?page=research&lang=en#VD22, the original paper uses OpenGL and OpenMP, we provide a pytorch implementation of half-edge and triangle conversion, parallel loop subdivision algorithm (with considerations for e…
# NOTE: THIS WON'T RUN, PLZ IMPLEMENT YOUR OWN load_mesh AND export_mesh, THEN CHANGE IMPORTS ACCORDINGLY
import time
import torch
from tqdm import tqdm
# fmt: off
import sys
sys.path.append('.')
@dendenxu
dendenxu / fast_small_matrix_inverse.py
Last active October 8, 2022 14:42
Faster pytorch inverse of small matrices (batched) than torch.inverse (which sometimes uses CPU and does not batch properly), with some decomposition methods, added a faster version
import torch
def torch_inverse_2x2(A: torch.Tensor, eps=torch.finfo(torch.float).eps):
B = torch.zeros_like(A)
# for readability
a = A[..., 0, 0]
b = A[..., 0, 1]
c = A[..., 1, 0]
d = A[..., 1, 1]
# slightly slower but save 20% of space (??) by
@dendenxu
dendenxu / moller_trumbore_winding_number_inside_mesh.py
Last active October 25, 2024 12:58
Hierarchical Winding Distance Remesh -> implemented a winding distance field and hierarchical formulation -> Batched `pytorch` implementation of the Moller Trumbore algorithm (ray-stabbing) & Generalized Winding Number for determining points inside mesh: https://www.cs.utah.edu/~ladislav/jacobson13robust/jacobson13robust.html
import torch
import mcubes
import trimesh
import numpy as np
from pytorch3d.ops.knn import knn_points
from tqdm import tqdm
from functools import reduce
from torch_scatter import scatter
from pytorch3d.structures import Meshes
from typing import Callable, Tuple, Union