Skip to content

Instantly share code, notes, and snippets.

@Farfarer
Farfarer / characterMotor.js
Created October 15, 2012 09:22
Solve simple IK for character legs on differing ground height for Unity3D.
function LateUpdate () {
if ( collision.grounded ) {
IKOn = true;
}
else {
IKOn = false;
}
ik.solveLegIK ();
}
Shader "Custom/Skin Shader" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Diffuse (RGB)", 2D) = "white" {}
_SpecularTex ("Specular (R) Gloss (G) SSS Mask (B)", 2D) = "yellow" {}
_BumpMap ("Normal (Normal)", 2D) = "bump" {}
// BRDF Lookup texture, light direction on x and curvature on y.
_BRDFTex ("BRDF Lookup (RGB)", 2D) = "gray" {}
// Curvature scale. Multiplier for the curvature - best to keep this very low - between 0.02 and 0.002.
_CurvatureScale ("Curvature Scale", Float) = 0.005
@Farfarer
Farfarer / CombineNormalMapsWizard.cs
Created February 12, 2013 10:40
Combines a base and a detail normal map to a new normal map texture, for Unity3D.
using UnityEditor;
using UnityEngine;
using System.IO;
// PLACE IN EDITOR FOLDER
class CombineNormalMapsWizard : ScriptableWizard {
public Texture2D baseNormal = null;
@Farfarer
Farfarer / CubemapToEquirectangularWizard.cs
Last active March 6, 2023 05:45
Create dynamic equirectangular maps for Unity. These have the benefit that, as they're flat images, you can sample lower mips to get blurry reflections. The straight cubemap version (detailed here: http://www.farfarer.com/blog/2011/07/25/dynamic-ambient-lighting-in-unity/ ) will give you hard seams when you sample mips from the cubemap. Although…
// Wizard to convert a cubemap to an equirectangular cubemap.
// Put this into an /Editor folder
// Run it from Tools > Cubemap to Equirectangular Map
using UnityEditor;
using UnityEngine;
using System.IO;
class CubemapToEquirectangularWizard : ScriptableWizard {
@Farfarer
Farfarer / SmoothingAngleFix.cs
Last active February 2, 2017 15:27
Auto-fix Unity's tangent space generation when importing models.
// Place this file into a directory called Editor inside of your Assets directory.
// Unity 5.3+:
// Models imported after you do that will have:
// - Normals set to Import.
// - Set the bool "useMikk" to true:
// Tangents set to Calculate Tangent Space (MikkTSpace).
// - Set the bool "useMikk" to false:
// Tangents set to Split Tangents (UnityTSpace).
#!/usr/bin/env python
# To install this plugin, simply copy this file (selectAxisUVs.py) into folder called "lxserv" in your modo scripts folder (and restart modo, if it's open).
# If you are unsure where your modo scripts folder is, you can open modo, then select System > Open User Scripts Folder.
# If there is no folder called "lxserv" in your MODO Scripts folder, simply create one and then put this file in there.
# Once MODO has been restarted, you can run the command via ffr.selectaxisuv
#
# Any issues, please drop me a line at jamesohare@gmail.com.
#
# James O'Hare
@Farfarer
Farfarer / sampleModoUVCode.cpp
Last active May 13, 2022 03:33
Modo C++ SDK UV code sample
// A couple of things to make life easier.
#define MIN_UV_GAP 0.0000005f
#define LXx_V2NEARLYEQ(a,b) ((abs((a)[0]-(b)[0]) < MIN_UV_GAP) && (abs((a)[1]-(b)[1]) < MIN_UV_GAP))
typedef std::vector <LXtPolygonID> PolygonList;
// The visitors we'll use.
// Visitors allow us to iterate over elements and filter that iteration by flags set upon them, known as mark modes.
// Simple one to set the supplied mark mode on polygons.
class MarkPolys : public CLxImpl_AbstractVisitor
import math
# Given a matrix, return euler angles of rotation as (X,Y,Z) in radians.
# Matrix is assumed to be either a lx.object.Matrix or a list[3][3] of floats.
def matrixToEuler (matrix, rotOrder):
if type(matrix) != list:
m = matrix.Get3 ()
else:
m = matrix
@Farfarer
Farfarer / xNormalHelpers.py
Created January 5, 2015 10:09
Just a few helper bits for xNormal/python.
#!/usr/bin/env python
import lx
import subprocess
import os
# Paths for xNormal.
path_xnormal_basedir = r'C:\Program Files\Santiago Orgaz'
path_xnormal_exedir = r'\x64\xNormal.exe'
path_xnormal = r'C:\Program Files\Santiago Orgaz\xNormal 3.18.9\x64\xNormal.exe'
#!/usr/bin/env python
import lx
import lxu
import lxifc
import lxu.command
class ListUVMaps (lxifc.Visitor):
def __init__ (self, meshmap):
self.meshmap = meshmap