Skip to content

Instantly share code, notes, and snippets.

View BigRoy's full-sized avatar

Roy Nieterau BigRoy

View GitHub Profile
@BigRoy
BigRoy / maya_usd_export_look_only.py
Last active February 6, 2024 20:10
Maya USD Export Chaser to keep only 'lookdev' related specs in the output file, to make a "look" overlay USD file from native maya geometry export - using Arnold job context in this case, to export materials and e.g. arnold subdiv opinions only
import logging
from maya.api import OpenMaya
import mayaUsd.lib as mayaUsdLib
from pxr import Sdf
def log_errors(fn):
"""Decorator to log errors on error"""
def wrap(*args, **kwargs):
@BigRoy
BigRoy / houdini_solaris_attribute_wrangle_lop_set_cam_focus_distance.vex
Last active January 5, 2024 11:10
Houdini Solaris set camera focus distance
string targetpath = "/focus_point"; // Target prim to focus on
// Compute Z-plane distance to target prim transform from camera transform
matrix cam = usd_worldtransform(0, @primpath);
matrix target = usd_worldtransform(0, targetpath);
vector origin = set(0, 0, 0);
matrix local_diff = target * invert(cam);
vector local_pos = ptransform(origin, local_diff);
float dist = -local_pos.z; // inverted, because -Z is direction camera looks at
@BigRoy
BigRoy / maya_usd_rise_vfx_create_default_assembly_rig_setup_example.py
Created December 27, 2023 17:23
Create Default Assembly Rig Setup as shown in How RISE VFX Reached New Creative Heights with USD in Maya talk
"""Create Default Assembly Rig Setup as shown in How RISE VFX Reached New Creative Heights with USD in Maya talk
See: https://youtu.be/8UIW-g1_heg?t=1902
"""
import pxr
import ufe
import pymel.core as pm
from mayaUsd import lib as mayaUsdLib
USD_SCHEMA = "UsdSchemaBase"
@BigRoy
BigRoy / ayon_docker_notes.md
Last active April 4, 2024 12:04
Ayon docker, install, setup and management notes

Note these are not any official notes - just random scribbles

Bootstrap

Running bootstrap wont give you the latest dev versions, only whats been released on the bootstrap server by the ynput team.

Updating it from time to time is a good way to see what progress has been made in terms of addons etc. It shouldnt remove old addon version, only add the new ones. That way you can still use older addons should you need. You would need to create a new bundle to accommodate that.

@BigRoy
BigRoy / maya_force_temporary_value.py
Created December 20, 2023 14:49
Maya force an attribute value during context, even for referenced, locked and animated attributes
from maya import cmds
import maya.api.OpenMaya as om
import contextlib
def pairwise(iterable):
"""s -> (s0,s1), (s2,s3), (s4, s5), ..."""
a = iter(iterable)
return zip(a, a)
@BigRoy
BigRoy / usd_print_prim_spec_without_children.py
Created December 8, 2023 14:51
USD Python API print Sdf.PrimSpec as text without children (e.g. somewhat like Maya LookdevX "Print selected as text")
from pxr import Usd, Sdf
def should_copy_children_fn(
children_field,
src_layer, src_path, field_in_src,
dest_layer, dest_path, field_in_dest
):
"""Filter function for Sdf.CopySpec to exclude children prims"""
if children_field == "primChildren":
@BigRoy
BigRoy / maya_usd_light_link_basic_ui.py
Last active February 15, 2024 04:38
Quick and dirty example functions/UI to light link with USD in Python for Maya
@BigRoy
BigRoy / usd_import_layer.py
Created November 28, 2023 12:15
USD Python API import layer into an existing layer at given path
from collections.abc import Callable
from pxr import Sdf
def import_layer(
path: str,
target_layer: Sdf.Layer,
target_path: Sdf.Path,
copy_spec_fn: Callable[[Sdf.Layer, Sdf.Path, Sdf.Layer, Sdf.Path], bool] = Sdf.CopySpec
):
@BigRoy
BigRoy / usd_print_simple_diff_to_layer_on_disk.py
Created November 23, 2023 16:15
USD simple print diff of dirty layer in memory to the original state on disk.
import difflib
from pxr import Sdf
# Purely as an example, say this `layer` is one that's currently already
# available and is dirty currently
identifier = r"C:\Users\User\Desktop\asset.usd"
layer = Sdf.Layer.FindOrOpen(identifier)
layer.Reload() # just so we can re-run this script
layer.subLayerPaths.append("./hello_world.usd") # making a change, making it dirty
@BigRoy
BigRoy / usd_get_registered_prim_type_schemas.py
Created November 19, 2023 22:59
Get all registered prim types to create by a nice plug-in grouping
from pxr import Usd, Plug, Tf
from collections import defaultdict
NICE_NAMES = {
"usdGeom": "Geometry",
"usdLux": "Lighting",
"mayaUsd_Schemas": "Maya Reference",
"usdMedia": "Media",
"usdRender": "Render",
"usdRi": "RenderMan",