Skip to content

Instantly share code, notes, and snippets.

@taikomatsu
taikomatsu / convert_hdri_to_png.py
Created May 30, 2019 17:21
Convert HDRI to png
import os
import os.path
import imageio
import numpy as np
from PIL import Image
# .hdrや.exrなど、読み込む際にfreeimageを使う必要があるフォーマット用にfreeimageをダウンロードしてくれるらしい
imageio.plugins.freeimage.download()
def list_hdri(dirname):
@taikomatsu
taikomatsu / display_hdr_qt.py
Created May 29, 2019 17:33
Display hdr using PySide2
from PySide2 import QtWidgets, QtGui
from PySide2 import QtCore
import sys
import imageio
import numpy as np
from PIL import Image, ImageQt
imgpath = 'myhdri.hdr'
imageio.plugins.freeimage.download()
img = imageio.imread(imgpath)
import numpy as np
import imageio
from PIL import Image
import matplotlib.pyplot as plt
# imageioで画像を読み込み
imgpath = 'myhdri.hdr'
imageio.plugins.freeimage.download()
img = imageio.imread(imgpath)
@taikomatsu
taikomatsu / readhdr.py
Created May 27, 2019 13:14
Read hdr using imageio
import imageio
imgpath = 'myhdri.hdr'
# freeimageがインストールされていないシステムでも以下の一行を実行すればHDRが読める
imageio.plugins.freeimage.download()
img = imageio.imread(imgpath)
# 画像サイズも確認可能
print(img.shape)
@taikomatsu
taikomatsu / bias_gain_short.vfl
Last active April 19, 2019 14:01
bias & gain for VEX short ver
float bias(float b; float x) {
return pow(x, log(b)/log(0.5));
}
float gain(float g; float x) {
return (x<0.5) ? bias(1-g, 2*x)*.5 : 1-bias(1-g, 2-2*x)*.5;
}
// usage example
float x = v@P.x;
//v@P.y = bias(0.8, x);
@taikomatsu
taikomatsu / bias_gain.vfl
Last active January 22, 2019 11:01
bias & gain for VEX
float bias(float b; float x) {
return pow(x, log(b)/log(0.5));
}
float gain(float g; float x) {
if (x<0.5)
return bias(1-g, 2*x)/2;
else
return 1-bias(1-g, 2-2*x)/2;
}
@taikomatsu
taikomatsu / easy_angle_difference_detection.py
Created April 13, 2018 09:12
超手抜き版エッジから正しいポジションを復元させるやーつ。任意の軸とエッジ(2点)の角度の差をdegreeでなんとなく取得する。
from pymel.core import *
import math
pt0, pt1 = selected(fl=True)
p0 = dt.Vector(xform(pt0, q=True, ws=True, t=True, a=True))
p1 = dt.Vector(xform(pt1, q=True, ws=True, t=True, a=True))
diff = p0-p1
axis = dt.Vector(0, 0, 1)
print(math.degrees(math.acos(diff.normal().dot(axis))))
@taikomatsu
taikomatsu / check_dynArray_value.py
Last active December 20, 2017 19:30
dynamic attributeの値をチェックする。主にSOuPやMash使ってる時用かも。
# とりあえず大急ぎで書いてる
# あれこれ書き方忘れてたので参考ページもメモ
# https://area.autodesk.jp/column/tutorial/maya_atoz/attribute_plug/
# http://ianwaters.co.uk/wp/mash/accessing-mash-point-data-with-the-maya-api/
from maya import OpenMaya
import pymel.core as pm
def mdg_from_name(name):
@taikomatsu
taikomatsu / convert_focal_aov.py
Created October 9, 2017 04:54
Convert AOV from Focal Length / Focal Length from AOV (Maya)
# Mayaで諸事情によりカメラスケール使えなかった時用に調べて書いた
# degreeとmmで計算してます
import math
def focal_to_aov(focal, aperture):
'''
focal: focal length
aperture: horizontal aperture (mm)
'''
@taikomatsu
taikomatsu / remove_filepath_expression.py
Created April 25, 2017 15:08
Remove expressions from file knob on all Reads in Nuke.
import nuke
import os.path
reads = nuke.allNodes('Read')
err_cnt = 0
for i, r in enumerate(reads):
raw = r.knob('file').getValue()
evaluated = r.knob('file').getEvaluatedValue()
full_path = '{}/{}'.format(os.path.dirname(evaluated), os.path.basename(raw))
try: