Skip to content

Instantly share code, notes, and snippets.

View rondreas's full-sized avatar

Andreas Rånman rondreas

View GitHub Profile
use std::collections::HashSet;
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
enum HandType {
HighCard,
OnePair,
TwoPair,
ThreeOfAKind,
FullHouse,
FourOfAKind,
@rondreas
rondreas / wait_for_it.rs
Created December 6, 2023 07:55
Advent of Code 2023 Day 6: Wait For It
fn main() {
// test input
let times = [7u64, 15u64, 30u64];
let distances = [9u64, 40u64, 200u64];
for time_held in 1..6 {
let time_left = 7 - time_held;
let distace_travelled = time_held * time_left;
if distace_travelled > 9 {
}
//
// Advent of Code 2023 - Day 5: If You Give A Seed A Fertilizer
//
use std::ops::Range;
use std::cmp::min;
fn main() {
// replace CR LF with LF, to run nicely on windows also,
let input = include_str!("input.txt").replace("\r\n", "\n");
@rondreas
rondreas / delete_vmap.cfg
Created November 21, 2023 12:46
Modo is missing a mesh operator for deleting vertex maps, here it is as a Python plugin
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<atom type="CommandHelp">
<hash type="Item" key="py.delete.vmap@en_US">
<atom type="UserName">Delete Vertex Map</atom>
<hash type="Channel" key="name">
<atom type="UserName">Name</atom>
</hash>
<hash type="Channel" key="type">
<atom type="UserName">Type</atom>
@rondreas
rondreas / HelloWorld.cpp
Created April 17, 2023 13:56
Minimal example of what is required to make a console command
#include "HAL/IConsoleManager.h"
#if !UE_BUILD_SHIPPING
static FAutoConsoleCommand HelloWorld(
TEXT("hello.world"),
TEXT("Print Hello, World! to the console log"),
FConsoleCommandDelegate::CreateLambda([](){
GLog->Log(TEXT("Hello, World!"));
})
);
@rondreas
rondreas / ue_menu.py
Created February 27, 2023 08:45
Another unreal menu, extending the context menu for folders in the content browser
import unreal
@unreal.uclass()
class MyEntry(unreal.ToolMenuEntryScript):
@unreal.ufunction(override=True)
def execute(self, context):
print("Hello!")
@rondreas
rondreas / get_static_meshes.py
Created February 17, 2023 11:32
Testing new asset registry method for getting assets by class
import unreal
if __name__ == "__main__":
asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
static_class = unreal.StaticMesh.static_class()
package = static_class.get_package()
top_level_asset = unreal.TopLevelAssetPath(package.get_name(), static_class.get_name())
static_meshes = asset_registry.get_assets_by_class(top_level_asset)
@rondreas
rondreas / cmod_double.py
Created February 14, 2023 13:11
Implemented a channel modifier that accepts a float input and return the value multiplied by two.
"""
Manual implementation of the SDK chanmod double
"""
import lx
import lxifc
@rondreas
rondreas / component_under_mouse.py
Created January 25, 2023 12:01
Example of getting viewport under mouse, and from there hit position and which component was closest to the hit
"""
Command to print the component under the mouse using lx api in Foundry Modo
To try it out, map the command to a hotkey and execute while mouse is over corresponding component.
py.mouse.component type:{vert|edge|poly}
You will likely want to use the already existing method
@rondreas
rondreas / get_active_tool.py
Created January 6, 2023 11:13
functions for gettings the currently active tools in modo
import lx
def get_command(name: str) -> lx.object.Command:
""" Spawn and return the command of given name """
cmd_svc = lx.service.Command()
try:
tag = cmd_svc.Lookup(name)
return cmd_svc.Spawn(tag, name)
except RuntimeError as e: