Skip to content

Instantly share code, notes, and snippets.

@scurest
scurest / import-dae.py
Last active January 22, 2025 21:26
POC for importing .dae into new Blenders without Collada support by shelling out to an older one with it.
import bpy, os, subprocess, tempfile
# Path to a Blender that supports Collada import
old_blender_exe = 'blender-3.6.1'
def import_dae(filepath):
filepath = os.path.abspath(filepath)
with tempfile.TemporaryDirectory(prefix="dae-import-") as tmpdir:
temp_blend = os.path.join(tmpdir, "temp.blend")
@scurest
scurest / 3d-screenshot-aligner.py
Created November 29, 2024 03:56
Blender script to help align 3D screenshots from eg. Duckstation-3D-Screenshot
# 3d-screenshot-aligner.py
#
# Blender script to help align 3D screenshots from eg.
# Duckstation-3D-Screenshot. Given meshes which are overlapping
# pieces of the same scene, you select the "same" polygon in both
# meshes, and it will move the pieces to align those polys in
# world space.
#
# Blender versions tested: 3.6
#
@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'