Skip to content

Instantly share code, notes, and snippets.

@cmdr2
cmdr2 / GenerateMesh02.cs
Last active November 1, 2023 14:28
A mesh extrusion along a bezier curve (Unity3d)
[RequireComponent(typeof(MeshFilter))]
public class GenerateMesh02 : MonoBehaviour {
/* scratchpad */
private MeshFilter mf;
void Start () {
mf = GetComponent<MeshFilter> ();
GenerateMesh ();
import sys
import os
import platform
from importlib.metadata import version as pkg_version
from sdkit.utils import log
from easydiffusion import app
# future home of scripts/check_modules.py
@cmdr2
cmdr2 / Math3d.cs
Created November 11, 2021 07:34
Useful 3D math functions from the old Unity 3D wiki (which has been shut down). Source: the archived version from July, 2021 at https://web.archive.org/web/20210507045029/https://wiki.unity3d.com/index.php/3d_Math_functions
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public class Math3d {
private static Transform tempChild = null;
private static Transform tempParent = null;
import time
MODEL_PATH = "F:/models/stable-diffusion/sd-v1-4.ckpt"
CONFIG_PATH = "F:/models/stable-diffusion/v1-inference.yaml"
def diff():
print('diffusers')
import torch
from transformers import logging as tr_logging
tr_logging.set_verbosity_error() # suppress unnecessary logging
@cmdr2
cmdr2 / diffusers_tensor_rt_directml.py
Last active June 1, 2023 06:28
TensorRT and DirectML with regular diffusers pipelines
import torch
import tensorrt as trt
from polygraphy import cuda
import sys
from packaging import version
from diffusers import StableDiffusionPipeline
from diffusers.pipelines.onnx_utils import OnnxRuntimeModel, ORT_TO_NP_TYPE
from dataclasses import dataclass
import numpy as np
import onnxruntime as ort
from sdkit import Context
from sdkit.generate import generate_images
from sdkit.utils import load_tensor_file, save_tensor_file
from ldm.util import instantiate_from_config
from omegaconf import OmegaConf
import time
model_path = "/path/to/models/stable-diffusion/sd-v1-4.ckpt"
@cmdr2
cmdr2 / MarchingCubes.cs
Last active May 3, 2023 03:36
Reimplementation of a simple Marching Cubes algorithm in C# for Unity. Not for production use, it needs performance improvements. Example script to run this in Unity: https://gist.github.com/cmdr2/b5aea11b9bd5259b9198f4fdc027061c
using System.Collections.Generic;
using UnityEngine;
// Reimplementation of http://paulbourke.net/geometry/polygonise/
// in C# for Unity.
//
// Example script to run this in Unity: https://gist.github.com/cmdr2/b5aea11b9bd5259b9198f4fdc027061c
//
// Note: This uses Unity's Linear Interpolation and Vector3
//
@cmdr2
cmdr2 / MarchingCubesExample.cs
Created February 4, 2021 12:27
Simple example usage script for MarchingCubes.cs at https://gist.github.com/cmdr2/b5326aa6fbf3c367747cc5ec31ba831e
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Simple example usage script for MarchingCubes.cs:
// at: https://gist.github.com/cmdr2/b5326aa6fbf3c367747cc5ec31ba831e
//
// Attach to an empty GameObject in the scene
//
// Not optimized, performs poorly! Written for simple readability
import time
MODEL_PATH = "F:/models/stable-diffusion/sd-v1-4.ckpt"
CONFIG_PATH = "F:/models/stable-diffusion/v1-inference.yaml"
DEVICE = "mps" # or "cuda" or "cpu"
def diff():
print('diffusers')
import torch
from transformers import logging as tr_logging
"""
Runs the desired Stable Diffusion models against the desired samplers. Saves the output images
to disk, along with the peak RAM and VRAM usage, as well as the sampling performance.
"""
import argparse
import os
import time
import traceback
from pathlib import Path