Skip to content

Instantly share code, notes, and snippets.

@simonbroggi
simonbroggi / zahl_schreiben.ink
Last active May 11, 2023 19:23
Inkles ink script to print a number translated to german.
=== function zahl_schreiben(x)
~zahl_schreiben_rec(x, true, true, true)
=== function zahl_schreiben_rec(x, start, kurz_einhundert, hundert_und1_bis_12)
~ x = INT(x) // cast to an int, since this function can only handle ints!
{
- x >= 1000000:
~ temp k = x mod 1000000
~ temp millionen = (x - k) / 1000000
{
@simonbroggi
simonbroggi / active_attribute_to_shape_key.py
Created September 30, 2022 16:28
Blender script to convert active attribute to a shape key
import bpy
# convert the activ attribute to a shape key
# the active attribute is expected to be a Vector in the Vertex domain
def active_attribute_to_shape_key(context):
obj = context.active_object
mesh = obj.data
attribute_index = mesh.attributes.active_index
attribute = mesh.attributes[attribute_index]
@simonbroggi
simonbroggi / MainLightNode.hlsl
Last active May 14, 2024 14:09
Unity Shadergraph custom function node for main light data
#ifndef MAINLIGHT_INCLUDED
#define MAINLIGHT_INCLUDED
void GetMainLightData_float(out half3 direction, out half3 color, out half distanceAttenuation, out half shadowAttenuation)
{
#ifdef SHADERGRAPH_PREVIEW
// In Shader Graph Preview we will assume a default light direction and white color
direction = half3(-0.3, -0.8, 0.6);
color = half3(1, 1, 1);
distanceAttenuation = 1.0;
@simonbroggi
simonbroggi / AmbientOcclusionDirection.osl
Created November 22, 2019 11:01
Calculates AO and the average direction where the ambient light came from.
/*
* Ambient Occlusion and Direction.
*
* Calculates AO and the average direction where the ambient light came from.
*
* Original AO code from https://github.com/sambler/osl-shaders/blob/master/ramps/BaAmbientOcclusion/BaAmbientOcclusion.osl
*
*/
void rng_seed(output int rng, int seed)
@simonbroggi
simonbroggi / shapeKeyFromDeformation.py
Created January 25, 2019 17:45
Blender script to generate shapekey from armature (or other) deformation
# generate shapekey from armature (or other) deformation
# deformation should not change the vertex order
import bpy
obj = bpy.context.selected_objects[0]
# use to_mesh to get deformed mesh data
# https://blender.stackexchange.com/questions/34789/how-to-get-vertex-coordinates-after-modifier-in-python
temp_data = obj.to_mesh(bpy.context.scene, True, 'PREVIEW')
@simonbroggi
simonbroggi / BuildAutomation.cs
Last active March 14, 2024 06:01
Build mutliple Unity applications for multiple platforms with one click
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class BuildAutomation {
public struct BuildTargetAndGroup {
public BuildTargetGroup group;
public BuildTarget target;
@simonbroggi
simonbroggi / CaptureFrames.cs
Created October 31, 2017 09:07
Unity3D script to save all frames rendered by an attached camera to png files
using System;
using System.IO;
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class CaptureFrames : MonoBehaviour {
public int frameRate = 30;
string path;
Texture2D renderedImage;
@simonbroggi
simonbroggi / ResourcesSingleton.cs
Last active January 7, 2021 07:46
unity singleton that can be used from editor scripts as well as in game.
using UnityEngine;
using System.Collections;
/**
* Singleton usefull if fields set in editor scripts need to be used in game.
*/
public class ResourcesSingleton : MonoBehaviour {
private static ResourcesSingleton _instance;
public static ResourcesSingleton instance {
@simonbroggi
simonbroggi / AssetExtractor.cs
Last active August 29, 2015 14:14
extract all used images from unity project to a destination folder. http://answers.unity3d.com/questions/57909/find-unused-assets-in-project.html
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class AssetExtractor : EditorWindow {
Vector2 scrollPos;
@simonbroggi
simonbroggi / TouchScriptInputModule.cs
Last active May 7, 2024 09:16
Input Module to use the new unity ui with multitouch from https://github.com/TouchScript
/**
* Input Module to use the new unity ui with multitouch from https://github.com/TouchScript
* Install TouchScript in your unity project, then add an EventSystem and replace the InputModules by this one.
*
*
* Basically modified TouchInputModule from
* https://bitbucket.org/Unity-Technologies/ui/src/5fc21bb4ecf4b40ff6630057edaa070252909b2e/UnityEngine.UI/EventSystem/InputModules/TouchInputModule.cs?at=4.6
* and changing ProcessTouchEvent to take events from TouchScript
*
* Got the TouchScript stuff from