Skip to content

Instantly share code, notes, and snippets.

@scurest
scurest / simplify_shaders_for_export.py
Last active September 22, 2024 20:15
Simplify Blender shaders to a simple diffuse texture for export (written for GLideN64-Scene-Ripper)
# Fixes shaders from GLideN64-Scene-Ripper for OBJ/etc export.
# Instructions: select objects you want to fix, then run this
# script from the Text editor.
# Tested with Blender 3.6.
import bpy
# Whether to connect the diffuse texture's alpha to the
# Principled Alpha socket in the simplified material.
CONNECT_ALPHA = True
import array
import struct
from . import hxapy_header as hxa
# *** Read functions
def read_u8(f):
return f.read(1)[0]
import bpy
#### SETUP MESH AND MATERIALS
# Create mesh
bpy.ops.mesh.primitive_cube_add()
ob = bpy.context.object
# Create materials
# https://stackoverflow.com/a/568618
def gen_primes():
D = {}
q = 2
while True:
if q not in D:
yield q
D[q * q] = [q]
else:
for p in D[q]:
@scurest
scurest / checker.html
Last active February 6, 2023 16:30
Hacked up version of checker.html with ZIP support
<!DOCTYPE html>
<html>
<head>
<title>Model Checker</title>
<style type="text/css">
body {
font-family: Arial,Verdana,sans-serif;
}
.filebox {
font-size: 20px;
@scurest
scurest / spline.py
Created March 5, 2020 13:53
Sympy derivation of conversion from glTF to Blender bezier curve
from sympy import *
# glTF equation taken from Appendix C of the spec
# When time = t_cur, the value of the curve is p
v_k, v_kp1, t_k, t_kp1, b_k, a_kp1, t_cur = symbols('v_k v_kp1 t_k t_kp1 b_k a_kp1 t_cur')
t = (t_cur - t_k) / (t_kp1 - t_k)
p0 = v_k
m0 = (t_kp1 - t_k) * b_k
#!/usr/bin/env python3
# Splits apicula's .daes into multiple .daes with one animation each.
# Original script by Inferry: <https://www.vg-resource.com/thread-30547-post-634261.html#pid634261>
import sys, os, copy
import xml.etree.ElementTree as ET
ET.register_namespace('', "http://www.collada.org/2005/11/COLLADASchema")
def main(path):
tree = ET.parse(path)
@scurest
scurest / extract_nds_models.py
Created May 11, 2019 13:31
Use ndstool and apicula to extract model files from an NDS ROM with the original filesystem structure.
#!/usr/bin/env python3
# Use ndstool to dump the FS off an NDS ROM, then use apicula to recursively
# search all files for models, etc.
import sys, os, subprocess, random, shutil
# !!! IMPORTANT !!!
# Change these to the paths to ndstool and apicula on your system.
NDSTOOL_CMD = 'ndstool'
APICULA_CMD = 'apicula'
@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;
@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.