Skip to content

Instantly share code, notes, and snippets.

View eelstork's full-sized avatar

T.E.A de Souza eelstork

View GitHub Profile
@eelstork
eelstork / ImportSettings.js
Last active August 29, 2015 14:03
Asset post-processor for blend files.
/**
* put this class in a folder named 'editor'
* (somewhere in Assets folder)
*/
class ImportSettings extends AssetPostprocessor {
function OnPreprocessModel() {
var importer:ModelImporter = assetImporter as ModelImporter;
var name = importer.assetPath.ToLower();
@eelstork
eelstork / nonUniformScaleCheck.js
Created July 2, 2014 08:45
Check for non uniform scale in a transform hierarchy.
// this will check whether t, or one of its ancestors,
// have non uniform scale.
function hasNonUniformAncestor(t:Transform){
while(t){
if(isNonUniformScale(t.localScale))return true;
t = t.parent;
@eelstork
eelstork / export-selected-layers.py
Last active August 29, 2015 14:07
Export a copy of the current file to the OUTPUT folder; only the specified LAYERS are exported. The current file will be saved before exporting.
# =============================================================
# Copyright TEA DE SOUZA 2014. Free to use and
# modify, do not remove this notice.
# =============================================================
#
# Export a copy of the current file to the OUTPUT folder.
# Only the specified LAYERS are exported.
# The current file will be saved before exporting.
#
# =============================================================
@eelstork
eelstork / basic-addon.py
Created November 8, 2014 06:04
basic blender add-on
bl_info = {
"name": "Move X Axis",
"category": "Object",
}
import bpy
class ObjectMoveX(bpy.types.Operator):
"""My Object Moving Script""" # blender will use this as a tooltip for menu items and buttons.
@eelstork
eelstork / read-file.py
Created November 8, 2014 07:49
Look for "export_config.txt" in directory of current blend, then return file content as a string
def outputDir():
p = os.path.dirname(bpy.data.filepath)
p = os.path.join(p,"export_config.txt")
p = open(p,'r').read()
return p;
@eelstork
eelstork / CustomPointerClickHandler.js
Created December 15, 2014 15:05
Demonstrates how to write custom event handler for the event system in Unity 4.6
function OnPointerClick(event:UnityEngine.EventSystems.PointerEventData){
Debug.Log("pointer clicked: "+gameObject);
Debug.Log("Position: "+event.worldPosition);
}
@eelstork
eelstork / Orientation.cs
Last active October 12, 2022 02:00
A C# implementation of aeronautic coordinates for Unity 3D
using UnityEngine;
using System.Collections;
public class Orientation : MonoBehaviour {
Vector3 pitchYawRoll{
get{
return new Vector3(pitch,yaw,roll);
}
set{
@eelstork
eelstork / mixamoToBlenderBoneNames.py
Created September 20, 2015 06:30
Convert Mixamo rig bone names (as imported to Blender via FBX) to standard Blender bone names. This is especially use if your mesh uses the 'mirror' modifier. 1 - Backup your Blend. 2 - In action editor disconnect any animation connected to the rig. 3 - Paste the script in a text window and select "run script". 4 - Notice that all bone names are…
# IMPORTANT: make sure no animation is assigned
# to the rig before you run this script,
# otherwise linked animation data will be corrupted.
import bpy
# ----------------------------------
# Mixamo left/right bone names start with 'Left'/'Right'
# Instead we apply Blender's standard .L/.R suffix
# and get rid of long suffix
@eelstork
eelstork / do_while_hack.cpp
Last active November 23, 2015 07:32
Demonstrates the use of the do{ ... }while(0) hack to secure the use of multi-line macros in conditionals. Note: this code does not compile.
#include <iostream>
#define SAFE_LOG_FIRST_N(arg,n) \
do{ \
static int LOG_OCCURRENCES = 0; \
if (LOG_OCCURRENCES <= n) ++LOG_OCCURRENCES; \
if (LOG_OCCURRENCES <= n) std::cout<<arg; \
} while(0)
#define LOG_FIRST_N(arg,n) \
@eelstork
eelstork / PUNNetworkController.cs
Last active February 28, 2016 11:18
A component that connects to Photon Unity Network and joins or creates a room.
using UnityEngine;
public class PUNNetworkController : MonoBehaviour {
void Start(){ PhotonNetwork.ConnectUsingSettings("v4.2"); }
void OnJoinLobby(){ StartGame (); }
void OnConnectedToMaster(){ StartGame (); }
void StartGame(){ PhotonNetwork.JoinRandomRoom(); }
void OnPhotonRandomJoinFailed(){ PhotonNetwork.CreateRoom("MyMatch"); }
void OnPhotonCreateGameFailed(){ Debug.LogError ("Create game failed"); }