Skip to content

Instantly share code, notes, and snippets.

@viktorasm
viktorasm / code.py
Created December 7, 2023 22:52
path from a to b, chatgpt edition
import maya.cmds as cmds
import maya.api.OpenMaya as om
from typing import List, Optional
def get_locator_position(locator_name: str) -> om.MVector:
"""Retrieve the position of a given locator"""
if not cmds.objExists(locator_name):
raise ValueError(f"Locator '{locator_name}' does not exist.")
return om.MVector(
@viktorasm
viktorasm / output
Last active October 18, 2022 19:39
whole number solution for sqrt(a)+sqrt(b) = sqrt(n), using integer math only (youtube video pxHd8tLI65Q)
solving for 2023
((0, 2023), (7, 1792), (28, 1575), (63, 1372), (112, 1183), (175, 1008), (252, 847), (343, 700), (448, 567), (567, 448), (700, 343), (847, 252), (1008, 175), (1183, 112), (1372, 63), (1575, 28), (1792, 7), (2023, 0))
solving for 897289125379227
num results for the large number test: 17294404
Process finished with exit code 0
print "-------------------------------------------"
import sys
import os
import platform
from maya import cmds
print "Environment info:"
print "Maya version:", cmds.about(installedVersion=True)
print "Maya API version:", cmds.about(apiVersion=True)
print "OS:", cmds.about(operatingSystem=True), cmds.about(operatingSystemVersion=True)
@viktorasm
viktorasm / mapping.py
Created November 12, 2020 18:47
linear-to-smooth curve mapping, based on a paper https://arxiv.org/abs/2010.09714
def curve_mapping(x, s, t):
"""
provides a linear-to-smooth curve mapping
based on a paper https://arxiv.org/abs/2010.09714
"""
epsilon = 0.000001
if x < 0:
return 0
@viktorasm
viktorasm / test.py
Created August 14, 2020 16:57
A bug in Autodesk Maya API
"""
This is a test for Autodesk Maya to demonstrate that when skin cluster inputs are not transform nodes,
Maya simply crashes using MFnSkinCluster.setWeights() API call.
1. Run this script a few times to demonstrate that everything works as expected: you have a simple skinned mesh,
and you set weights for single joint, single vertex.
2. set "enable_bug_and_crash_maya" to True and rerun script - might need few reruns of the script.
Eventually, maya crashes.
"""
@viktorasm
viktorasm / benchmark.py
Created January 5, 2020 12:54
Python equality test for old vs new objects
import cProfile
import pstats
from random import random
class SampleObject:
def __init__(self):
self.sample_data = random()
class SampleObjectNew(object):
@viktorasm
viktorasm / ngSkinTools_diagnostics.py
Last active March 30, 2022 15:12
A little utility to run inside Maya's script editor (Python tab!) to troubleshoot ngSkinTools installation issues.
print "-------------------------------------------"
import sys
import os
from maya import cmds
print "Environment info:"
print "Maya version:", cmds.about(installedVersion=True)
print "Maya API version:", cmds.about(apiVersion=True)
print cmds.about(operatingSystem=True), cmds.about(operatingSystemVersion=True)
@viktorasm
viktorasm / ngSkinTools_import_without_ui.py
Created January 23, 2019 15:36
Example of JSON import into ngSkinTools by skipping UI settings screen.
from ngSkinTools.importExport import JsonImporter
from ngSkinTools.influenceMapping import InfluenceMapping
from ngSkinTools.mllInterface import MllInterface
from ngSkinTools.ui.events import LayerEvents
from ngSkinTools.ui.layerDataModel import LayerDataModel
def ngSkinToolsImport(fileName, targetMesh):
'''
loads a JSON file (previously exported with ngSkinTools exporter) and loads data onto provided mesh.
# this is an example script how ngSkinTools can be automated
# to configure left-right influence mapping
# this example assumes that the scene has a skinned pPlane1
# which has ngSkinTools info already initialized. if not,
# see http://www.ngskintools.com/documentation/api/mll-interface.html
# for tips to how to do that programatically
# for this we use "manual mapping overrides" feature:
# the same where you can correct automatic associations by hand,
# only this time we choose to 'bake' the whole mapping using the
// how I'd "fix" https://akrzemi1.wordpress.com/2017/01/02/not-detecting-bugs/
//
// * Explicitly state "code assumes input vectors are same length"
// * Explicitly request inlining of loop's inner funcion
// * real world code will probably not use "v1, v2" naming
// * instead of relying "compiler will optimize away helper constructs",
// just don't use any.
//
// in general, it's a similar case, when instead of ...
// struct x = {a[++i], b[i]}