Skip to content

Instantly share code, notes, and snippets.

View BigRoy's full-sized avatar

Roy Nieterau BigRoy

View GitHub Profile
@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_export_look_only.py
Last active February 16, 2025 10:22
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_isolate_selected_debug_shading_shelf_button.py
Last active January 24, 2024 18:16
Houdini Solaris shader/render debug "isolate selected" type of behavior similar to Arnold Render View (use as shelf script - CTRL+ click disables it)
from typing import Tuple
import hou
import toolutils
from pxr import UsdShade, Sdf
POST_LAYER_NAME = "isolate_shaders"
# Prioritize outputs if there are multiple
@BigRoy
BigRoy / maya_query_mesh_hard_edges.py
Created January 31, 2024 19:28
Maya get all hard edges (note that a mesh may still display smooth if e.g. it had locked normals)
from maya import cmds
import maya.api.OpenMaya as om
def get_fn_mesh(mesh):
sel = om.MSelectionList()
sel.add(mesh)
dag = sel.getDagPath(0)
return om.MFnMesh(dag)
hard_edged_meshes = []
@BigRoy
BigRoy / usd_python_list_all_used_assets.py
Last active February 27, 2024 23:14
USD find all used assets in Stage or Layer using Python - e.g. findin all used textures
from pxr import UsdUtils, Sdf
stage = hou.pwd().editableStage()
# Given a Sdf.Layer you can use UsdUtils.ComputeAllDependencies
# which returns the layers, assets and any unresolved paths
layer = stage.Flatten()
layers, assets, unresolved_paths = UsdUtils.ComputeAllDependencies(layer.identifier)
for path in assets:
print(path)
@BigRoy
BigRoy / maya_connect_objects_to_nurbscurve_pointoncurveinfo.py
Created February 8, 2024 10:40
Maya: Connect Objects translation to param u on NurbsCurve via pointOnCurveInfo node.
"""Connect objects (transforms) to a nurbsCurve by pointOnCurve node.
Select the objects, then select the nurbsCurve last.
Run the script.
Voila.
Updated version of: https://polycount.com/discussion/161754/eye-rig-script-problem
"""
@BigRoy
BigRoy / ayon_load_by_representation_id.py
Created February 8, 2024 12:57
AYON Pipeline - Load a representation container instance by representation id in Python
from openpype.pipeline.load.plugins import discover_loader_plugins
from openpype.pipeline.load.utils import loaders_from_representation, load_container
loader_name = "GpuCacheLoader"
representation_id = '6b7b5b6e-c677-11ee-b580-18c04d958ef6'
all_loaders = discover_loader_plugins()
loaders = loaders_from_representation(all_loaders, representation_id)
Loader = next((i for i in loaders if i.__name__ == loader_name), None)
@BigRoy
BigRoy / houdini_lop_attributewrangle_reset_scale.py
Last active February 20, 2024 11:44
Houdini AttributeWrange LOP: remove any scaling - make sure primitive scale is {1, 1, 1}, for example useful for cameras.
// Remove any scaling from parent prims
matrix transform = usd_worldtransform(0, @primpath);
vector scale = cracktransform(0, 0, 2, {0, 0, 0}, transform);
if (scale != {1, 1, 1}) {
usd_addscale(0, @primpath, "remove_scale", 1 / scale);
}
@BigRoy
BigRoy / houdini_lop_materiallibrary_get_material_to_houdini_node_mapping.py
Last active February 23, 2024 15:51
Houdini Solaris Material Library LOP get the USD Material Prim Path mapping to the Houdini Material node in the Material Library
import logging
from typing import Dict
import hou
log = logging.getLogger(__name__)
def get_material_library_paths(material_lib: hou.LopNode) -> Dict[str, str]:
"""Return Houdini material node path to USD path mapping
@BigRoy
BigRoy / houdini_lop_get_houdini_editor_node_from_usd_shader.py
Created February 23, 2024 15:16
Houdini Solaris find the Houdini Editor Node for a Shader or Material in a Houdini Material Library
import os
import logging
from typing import List
import hou
import loputils
from pxr import Usd, UsdShade
log = logging.getLogger(__name__)