Skip to content

Instantly share code, notes, and snippets.

View JokerMartini's full-sized avatar
😀

John Martini JokerMartini

😀
View GitHub Profile
@JokerMartini
JokerMartini / Instancing + Hierarchy | .py
Last active April 27, 2021 15:17
PySide + Python: Demonstrates a way to handle a hierarchy of nodes along with instancing.
# Imports
# ------------------------------------------------------------------------------
import sys
import uuid
import json
from random import randint
from PySide import QtCore, QtGui
NODES = []
HIERARCHY = {}
@JokerMartini
JokerMartini / Collect all nodes and children | .mxs
Created December 3, 2015 14:06
Maxscript: Collects all parents and their children nodes recursively
fn get_all_nodes nodes:#() =
(
allnodes = #()
for n in nodes do
(
append allnodes n
join allnodes (get_all_nodes nodes:(n.children))
)
@JokerMartini
JokerMartini / Collect attribute from class object in list | .py
Last active July 5, 2017 14:16
Python: Collect attribute from a list of objects where attribute exists
existing_names = [getattr(x, "name", "") for x in nodes if type(x).__name__ == node_class]
@JokerMartini
JokerMartini / Recursive function for list of objects | .py
Created December 3, 2015 13:22
Python: Returns flat list of objects from recursive function
def get_nodes(items=[], ages=[]):
myresults = []
print "Searching..."
# pseudo code
for item in items:
if item.age in ages:
print "\t","valid age"
myresults.append(item)
myresults.extend( get_nodes(items=item.children, ages=ages) )
@JokerMartini
JokerMartini / Maxscript Sorting Arrays of Structs | .ms
Created December 2, 2015 15:16
Maxscript: Sorting arrays of arrays and arrays of structs
fn sortbyage v1 v2 =
(
if v1.age < v2.age then -1 else if v1.age > v2.age then 1 else 0
)
fn sortbyname v1 v2 =
(
act = stricmp v1.name v2.name
if act == 0 then sortbyage v1 v2 else act
)
qsort <an_array_of_persons> sortbyname
@JokerMartini
JokerMartini / Progress Bar | .ms
Created November 23, 2015 12:25
Maxscript: Progress bar example in 3ds Max using maxscript.
/********************************************************
:Created By: John Martini
:Company: JokerMartini
:Site: http://JokerMartini.com
:Email: [email protected]
:Client:
:Purpose:
:History:
:Todo:
:Bugs:
@JokerMartini
JokerMartini / Flip Align Node to Vector | .ms
Last active September 18, 2023 09:06
Maxscript: Creates a camera and flips it around an origin. Aligns camera to vector.
-- test scene setup
delete objects
tm = Inverse( viewport.getTM() )
camA = FreeCamera wirecolor:orange transform:tm
tm = camA.transform
origin = [0,0,0]
fn flip_tm_along_vector tm:undefined origin:[0,0,0] =
(
--Bobo: The other way would be to use MatrixFromNormal, set the .row4 to the position of the object and assign to the .transform property.
(
s = sphere pos:[10,20,30]
t = teapot radius:5
theMesh = snapshotasmesh s
for f = 1 to theMesh.numfaces do
(
theClone = instance t
theClone.transform = matrixFromNormal (getFaceNormal theMesh f)
@JokerMartini
JokerMartini / Mirror Matrix Across Axis | .ms
Last active September 18, 2023 09:07
Maxscript: Mirrors and object's matrix across an axis in 3ds Max.
--Create a point
p=point pos:[-20,0,0] size:20 axistripod:true box:true
--Rotate it 90 in z
rotate p (eulerAngles 0 0 45)
--Get the transform matrix to work with.
tm=p.transform
--Mirror the tm across the world matrix in x
@JokerMartini
JokerMartini / Colorpicker | .py
Created November 12, 2015 17:16
Pyside Pthon: A simple color picker using pyside and python.
import sys
from PySide import QtGui
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()