Skip to content

Instantly share code, notes, and snippets.

View xwipeoutx's full-sized avatar

Steve Leigh xwipeoutx

View GitHub Profile
@xwipeoutx
xwipeoutx / SceneViewRect.cs
Last active October 1, 2024 04:57
Find the rectangle a rect transform will use on a SceneView. Good for labels and stuff.
var sceneView = SceneView.currentDrawingSceneView;
var canvas = rectTransform.GetComponentInParent<Canvas>();
var zoomFactor = sceneView.position.height / (sceneView.camera.orthographicSize * 2);
var pivotPosition = HandleUtility.WorldToGUIPoint(rectTransform.position);
var sizeOnCanvas = RectTransformUtility.PixelAdjustRect(rectTransform, canvas).size;
var size = sizeOnCanvas * zoomFactor + buffer * Vector2.one;
var pos = pivotPosition - size * new Vector2(rectTransform.pivot.x, 1 - rectTransform.pivot.y);
var sceneViewRect = new Rect(pos, size);
@xwipeoutx
xwipeoutx / SaneMeshes.cs
Last active September 5, 2024 05:41
When working with FBX files, sometimes meshes inside them have the same name - which Unity will import in an undefined order/guid mapping. This causes all sorts of problems between platforms especially. This script applies a deterministic order (based on vert positions, triangles, etc.) to those as a post-processor step.
using System.Linq;
using UnityEditor;
using UnityEngine;
public class SaneMeshes : AssetPostprocessor
{
private void OnPostprocessModel(GameObject go)
{
Debug.Log("Post processing a model!");
@xwipeoutx
xwipeoutx / delete-old-github-artifacts.ps1
Created August 30, 2024 01:13
Powershell script to delete github artifacts older than N days old.
# Variables
$repo = "Owner/RepoName"
$daysAgo = 14
$twoWeeksAgo = (Get-Date).AddDays(-$daysAgo).ToString("yyyy-MM-ddTHH:mm:ssZ")
# Fetch all artifacts older than 2 weeks
$artifacts = gh api "repos/$repo/actions/artifacts" --paginate --jq ".artifacts | map(select(.created_at < `"`"$twoWeeksAgo`"`"`"))" | ConvertFrom-Json
# Check if there are any artifacts
@xwipeoutx
xwipeoutx / generate-icons.js
Last active December 14, 2020 22:19
Generates all the UWP icons with sensible naming, based of a couple initial files.
let imageConversion = require("image-conversion");
var fs = require("fs");
let jimp = require("jimp");
let ImageJs = require("image-js");
let output = "public/images/icon";
const scales = [100, 125, 150, 200, 240, 400];
const iconTargetSizes = [16,24,32,48,256];
const iconTargetDecorations = ['unplated_targetsize', 'targetsize'];
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
namespace Project.Scripts.Editor
@xwipeoutx
xwipeoutx / ar-hello-world-astronaut.html
Last active August 8, 2020 11:40
Hello, World of WebXR - an astronaut in your living room.
<html>
<head>
<title>Model Viewer Example</title>
<script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
<script nomodule src="https://unpkg.com/@google/model-viewer/dist/model-viewer-legacy.js"></script>
</head>
<body>
<model-viewer src="https://stevesspace.com/assets/models/Astronaut.glb"
ar ar-modes="webxr scene-viewer quick-look" ar-scale="auto" camera-controls
alt="A 3D model of an astronaut"
export async function getParcel(coords: {lat: number, lng: number}): Promise<Feature> {
let url = `https://gisservices.information.qld.gov.au/arcgis/rest/services/PlanningCadastre/LandParcelPropertyFramework/MapServer/4/query?geometry=${coords.lng}%2C${coords.lat}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelIntersects&outFields=*&returnGeometry=true&outSR=4326&f=geojson`
let response = await fetch(url);
let collection = await response.json();
return (collection && collection.features[0]) || null;
}
@xwipeoutx
xwipeoutx / xr-tech-interview.md
Last active May 8, 2024 14:31
XR Tech Interview Questions

XR specific tech interview

AR / VR / MR / XR

  • Explain what is AR / VR / XR / MR, how are they connected? Why would you choose one over another?
  • Your client is saying "I want a HoloLens app that can do X".  How do you qualify if they're wasting their money?
  • Tell me about some logistical implications of this tech in the enterprise?
  • How does developing an XR app differ from a traditional 2D or 3D game / app?
  • Specifically, what are some downsides to translucent displays (HoloLens, Magic Leap), and how do you accommodate for them?
@xwipeoutx
xwipeoutx / mr-setup.md
Last active December 21, 2018 01:52
Setting up for mixed reality

If you want to prepare your PC beforehand, I would

  • Install Unity Hub. This handled multiple Unity versions on the same PC and is a life saver
  • Install the latest Unity from (whatever it happens to be - there won't be any major releases soon AFAIK). Include all the UWP/Windows store things and the IL2CPP scripting engine support
    • If you're more interested in doing AR for the tablet or phone, then install those SDKs too - it's really up to you what you want to get out of it
    • Careful with the installer and it telling you to install VS 2018. There's a checklist here - but I wouldn't worry about the emulator. It sucks.
  • Do a quick "Hello, world"
  • -or- do my old "Hello, world!" tutorial (I will

Git Extensions

Path to mergetool:

C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe

Mergetool command:

"C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe" /m /r="$MERGED" "$LOCAL" "$BASE" "$REMOTE"