Skip to content

Instantly share code, notes, and snippets.

@tamask
tamask / Mathutil.cginc
Created Feb 28, 2019
Various math util functions for cg
View Mathutil.cginc
#ifndef _MATHUTIL
#define _MATHUTIL
#define PI 3.141592653589793115997963468544185161590576171875
inline float floorq(float v, float q) {
return floor(v / q) * q;
}
inline float ceilq(float v, float q) {
@tamask
tamask / Billboard.cginc
Last active Feb 28, 2019
Matrix for shader-based billboarding in Unity
View Billboard.cginc
#ifndef _BILLBOARD
#define _BILLBOARD
#include "UnityCG.cginc"
/*
About BILLBOARD_MATRIX
----------------------
@tamask
tamask / io_export_curve.py
Created Feb 8, 2019
Blender: Export the active curve object (U-component only)
View io_export_curve.py
# This exporter just serializes Blender's bpy curve data API verbatim,
# so the exported json structure mirrors the variable names and
# arrays. The exporter only goes so far to export the U-component of
# the curve data, since we're more interested in curves and not NURBS
# surfaces for use in videogames. An asset importer in Unity need only
# look up the Blender Python API to choose how to interpret this data.
import bpy
import json
from bpy_extras.io_utils import ExportHelper
@tamask
tamask / Color.cginc
Last active Feb 28, 2019
Unity color conversion and uv-encoded color unpacking
View Color.cginc
#ifndef _COLOR
#define _COLOR
inline float3 hue2rgb(in float h)
{
float r = abs(h * 6 - 3) - 1;
float g = 2 - abs(h * 6 - 2);
float b = 2 - abs(h * 6 - 4);
return saturate(float3(r, g, b));
}
@tamask
tamask / uvdata.py
Created Jan 29, 2019
Simple tool for packing colors into UV maps
View uvdata.py
'''
Simple tool for packing colors into UV maps
'''
import bpy
import math
import mathutils
def v2_to_float(v2, precision=4096):
'''Pack two 0-1 float values into a single float'''
@tamask
tamask / MeshInfo.cs
Created Jan 15, 2019
Unity: display mesh info for selected object
View MeshInfo.cs
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(MeshFilter))]
public class MeshInfo : Editor {
protected MeshFilter meshFilter;
protected Mesh mesh;
protected Vector3[] lines;
public void OnEnable() {
@tamask
tamask / io_fbx_target.py
Last active Feb 6, 2019
Autoexport to an FBX target file (Blender 2.80)
View io_fbx_target.py
import os
import bpy
import bpy_extras
import mathutils as mu
from io_scene_fbx import ExportFBX
bl_info = {
'name': 'Autoexport FBX Target (.fbx)',
'author': 'Tamas Kemenczy',
'blender': (2, 80, 0),
View AutoHotkey.ahk
; Capslock remapping should be done in the registry to avoid key repeat issues in here
; Capslock::Ctrl
; WheelUp::
; Send {WheelDown}
; Return
; WheelDown::
; Send {WheelUp}
; Return
@tamask
tamask / log.py
Created Aug 8, 2018
Route system output (stdout/stderr) of Blender to the app console (put in scripts/startup)
View log.py
import os
import sys
import bpy
output = None
input = None
info = None
error = None
write = None
@tamask
tamask / export_beziers.py
Last active Aug 5, 2018
Blender exporter for beziers
View export_beziers.py
import os
import bpy
import math
import mathutils
bl_info = {
'name': 'Export Beziers (.svg)',
'author': 'Tamas Kemenczy',
'version': (0, 1),
'blender': (2, 6, 9),
You can’t perform that action at this time.