Skip to content

Instantly share code, notes, and snippets.

View rondreas's full-sized avatar

Andreas Rånman rondreas

View GitHub Profile
@rondreas
rondreas / selectHardEdges.cpp
Created February 26, 2018 16:41
MEL Command for selecting hard edges,
//
// Copyright (C) Andreas Rånman
//
// File: selectHardEdgesCmd.cpp
//
// MEL Command: selectHardEdges
//
// Author: Maya Plug-in Wizard 2.0
//
@rondreas
rondreas / SDFSphere.cs
Last active September 13, 2018 14:41
Attempting to get a grip on shaders after being inspired by: http://blog.camposanto.com/post/171934927979/hi-im-matt-wilde-an-old-man-from-the-north-of
using UnityEngine;
[ExecuteInEditMode]
public class SDFSphere : MonoBehaviour {
private void Update()
{
// Set a global value that we can use in our shader.
Shader.SetGlobalVector("_sdfSphere_position", this.transform.position);
}
@rondreas
rondreas / Replacer.cs
Created October 10, 2018 11:44
Unity Editor Tool to attempt replace selected GameObjects with any asset matching the name of selected.
using UnityEngine;
using UnityEditor;
public class Replacer : EditorWindow
{
[MenuItem("Window/Replacer")]
public static void ShowWindow()
{
EditorWindow.GetWindow<Replacer>("Replace GameObject");
}
// Implementation of effect described at: https://willweissman.wordpress.com/tutorials/shaders/unity-shaderlab-object-outlines/
Shader "Custom/DrawSimple" {
SubShader{
ZWrite Off
ZTest Always
Lighting Off
Pass {
CGPROGRAM
#pragma vertex VShader
@rondreas
rondreas / fixNormals.py
Last active November 19, 2018 15:33
hardsurface modelling script to set normals for all vertices on a face.
import pymel.core as pm
def faceNormal():
""" """
# Store old selection,
selection = pm.selected()
# Convert selection to faces,
pm.mel.ConvertSelectionToFaces()
@rondreas
rondreas / toggleComponents.py
Created November 19, 2018 16:44
Quick script to allow hotkeying a toggle for converting selection, to imitate the default command of CTRL + F9/F10/F11.
"""
Quick script to allow hotkeying a toggle for converting selection, to imitate the default
command of CTRL + F9/F10/F11.
"""
import pymel.core as pm
class eSelection(object):
@rondreas
rondreas / eSelection.py
Created November 20, 2018 16:03
snippet for blog post on toggleComponent
class eSelection(object):
""" Enum for selection convertion. """
object = 0
face = 1
edge = 2
vert = 3
def getActive():
""" Check current selection to find if we're currently only selecting a specific component. """
if all(isinstance(x, pm.MeshFace) for x in pm.selected()):
return eSelection.face
if all(isinstance(x, pm.MeshEdge) for x in pm.selected()):
return eSelection.edge
if all(isinstance(x, pm.MeshVertex) for x in pm.selected()):
# Replace selection with transform, for all selected vertices.
pm.select( [shape.getTransform() for shape in pm.ls(pm.polyListComponentConversion( fromVertex = True ))], replace = True )