Skip to content

Instantly share code, notes, and snippets.

Avatar

Tai Komatsu taikomatsu

View GitHub Profile
@taikomatsu
taikomatsu / convert_acv_to_nuke.py
Last active Sep 13, 2020
Convert .acv exported from AE to ColorLookup in Nuke.
View convert_acv_to_nuke.py
# import acv
import struct
filepath = 'C:/users/hoge/curve.acv'
luts = []
with open(filepath, 'rb') as f:
header = f.read(4)
for i in range(len('mrgba')):
ncvs = struct.unpack('>BB', f.read(2))[1]
ipairs = [struct.unpack('>BBBB', f.read(4))[1::2] for k in range(ncvs)]
pairs = [(ix/255., iy/255.) for iy, ix in ipairs]
@taikomatsu
taikomatsu / read_acv.py
Last active Sep 13, 2020
Read .acv(binary tone curve file) to convert to Nuke (wip)
View read_acv.py
# AEの.acvファイルをNukeに持っていく用にリサーチ
# 冒頭4バイトはヘッダ?処理に必要そうなものではなかったので一旦無視
# その後はマスター, R, G, B, Aと全5チャンネル分の情報が、
# 制御点の個数, (制御点の位置(x), 制御点の値(y)) x 個数分 という感じで全チャンネル分記載されていた
### 注意 ###
# Jupyterで書いてたためPython3.xなのでそのままだとDCCでは使えないかもしれない、、
filepath = 'C:/users/hoge/curve.acv'
with open(filepath, 'rb') as f:
@taikomatsu
taikomatsu / assign_mat.py
Created Jun 12, 2020
Assign a material to selected objects in Blender
View assign_mat.py
# reference:
# https://blender.stackexchange.com/questions/23433/how-to-assign-a-new-material-to-an-object-in-the-scene-from-python
import bpy
mat = bpy.data.materials.get('my_material')
for o in bpy.context.selected_objects:
if o.data.materials:
ob.data.materials[0] = mat
else:
o.data.materials.append(mat)
View carve_each_curves.vfl
// carveする値。ここにバラバラの値を入れればバラバラにcarveも可能。
float carve = fit(f@Frame, 1, 24, 1, 0);
int pts[] = primpoints(0, i@primnum);
// carve後のcurveのポイントを保持する配列
int newpts[] = {};
foreach (int pt; pts) {
float u = point(0, "curveu", pt);
// carveの向きはここの条件やcarveの変化を変えればOK
if (u<carve)
removepoint(0, pt);
View convert_hdri_to_png.py
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
Display hdr using PySide2
View display_hdr_qt.py
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)
View displayhdr.py
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
Read hdr using imageio
View readhdr.py
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 Apr 19, 2019
bias & gain for VEX short ver
View bias_gain_short.vfl
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 Jan 22, 2019
bias & gain for VEX
View bias_gain.vfl
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;
}
You can’t perform that action at this time.