Language:

サイドバー

バーチャルキャスト公式Wiki

メニュー

Steam版

デバイス

アセット

配信

その他

リリース情報

デベロッパー向け


開発環境

GLB

vci:script:reference:color

Color(色の指定)

このページは過去の情報となります。
新しいスクリプトリファレンスはこちらになります。

Effekseer (エフェクト)のエフェクトのカラーや、マテリアルの色を変更したりする時に使用します。

名前 説明 バージョン
_new 初期化 新しいColorを宣言する時に使用します
ToString 色を文字列に変換します
GetHashCode ハッシュ値を取得します
Lerp AのカラーからBのカラーまで補間します
LerpUnclamped AのカラーからBのカラーまで補間します(clampされません)
_toVector4(使用不可) vector4とcolor型の変換
_toColor(使用不可) vector4とcolor型の変換
HSVToRGB HSVで指定してカラーを作成します
red 赤(レッド) RGBA(1, 0, 0, 1)
green 緑(グリーン) RGBA(0, 1, 0, 1)
blue 青(ブルー) RGBA(0, 0, 1, 1)
white 白(ホワイト) RGBA(1, 1, 1, 1)
black 黒(ブラック) RGBA(0, 0, 0, 1)
yellow 黄(イエロー) RGBA(1, 0.922, 0.016, 1)
cyan 水(シアン) RGBA(0, 1, 1, 1)
magenta 紫(マゼンダ) RGBA(1, 0, 1, 1)
gray 灰(グレー) RGBA(0.5, 0.5, 0.5, 1)
clear 透明(クリア) RGBA(0, 0, 0, 0)
grayscale カラーをグレースケールにした時の濃さを求めます
linear カラーをリニアに変換します
gamma カラーをガンマに変換します
maxcolorcomponent RGBの要素で最も大きい値を返します
r Color の Red(赤) の要素にだけアクセスします
g Color の Green(緑) の要素にだけアクセスします
b Color の Blue(青) の要素にだけアクセスします
a Color の alpha(透明度) の要素にだけアクセスします

RGBについて


プログラムでは色を赤(Red)、青(Blue)、緑(Green)に分けて指定する事で表現します。
この表現をそれぞれの頭文字をとってRGB(RGBカラーモデル)と呼びます。
RGBに加えて、透明度(alpha)の指定が入ったものをRGBAと呼びます。

色を作成する場合、RGBAの成分を混ぜる事で表現しています。
例えば、紫色であればRとBの値を大きくし、黄色であればRとGの値を大きくとります。
全ての値が1の時は白になり、0の時は黒になります。また、RGBを同じ値にする事でグレーになります。

printで色を確認する

  • ユーティリティで用意されているcolorの確認を行えます。

サンプル

main.lua
    -- RGB
    print("red : "..tostring(Color.red))
    print("green : "..tostring(Color.green))
    print("blue : "..tostring(Color.blue))
 
    -- white gray black
    print("white : "..tostring(Color.white))
    print("gray : "..tostring(Color.gray))
    print("black : "..tostring(Color.black))
    -- clear
    print("white : "..tostring(Color.clear))
 
    -- cyan magenta yellow
    print("cyan : "..tostring(Color.cyan))
    print("magenta : "..tostring(Color.magenta))
    print("yellow : "..tostring(Color.yellow))

__new

第1引数:red(number) 第2引数:green(number) 第3引数:blue(number) 第4引数:alpha(number)

  • RGBAを直接指定してカラーを作成します。指定する範囲は 0 から 1 です。

サンプル

main.lua
function onUse()
 
    -- グレーを作成します
    local color = Color.__new(0.5, 0.5, 0.5, 1.0)
 
    -- CubeColorのマテリアルをcolorに変更します
    vci.assets.SetMaterialColorFromName("CubeColor", color)
 
end

実行結果

(CubeColorのマテリアルの色がグレーに変化します)

ToString

ToString fun(): string

サンプル

main.lua
function onUse()
    print("red : "..tostring(Color.red))
end

実行結果

"red : RGBA(1.000, 0.000, 0.000, 1.000)"

GetHashCode

GetHashCode fun(): number

サンプル

main.lua
function onUse(use)
    print(Color.red.GetHashCode())
    local col = Color.__new(1,0,0,1)
    print(col.GetHashCode())
end

実行結果

541065216
541065216

説明
ハッシュ値を取得します

Lerp

Lerp fun(a: Color, b: Color, t: number): Color

サンプル

main.lua
function updateAll()
    local time = 0.5 * math.sin(os.time()) + 0.5
    local color = Color.Lerp(Color.red, Color.blue, time)
    vci.assets.SetMaterialColorFromName("CubeColor", color)
end

実行結果

名前が''CubeColor''のマテリアルが赤と青の間で徐々に色が変わります。

説明
第一引数のカラーから第二引数のカラーまで補間します

LerpUnclamped

LerpUnclamped fun(a: Color, b: Color, t: number): Color

サンプル

main.lua
function updateAll()
    local time = math.sin(os.time()) + 1
    local color = Color.LerpUnclamped(Color.red, Color.gray, time)
    vci.assets.SetMaterialColorFromName("CubeColor", color)
end

実行結果

名前が''CubeColor''のマテリアルが(1, 0, 0, 1)(0, 1, 1, 1)の間で徐々に色が変わります。

説明
第一引数のカラーから第二引数のカラーまで補間します(clampされません)

HSVToRGB

第1引数:Hue(number) 第2引数:Saturation(number) 第3引数:Value(number)

  • HSVを指定してカラーを作成します。指定する範囲は 0 から 1 です。
  • RGBで色を作成するのは直感的ではないので、HSVで指定すると直感的に色が選べます。
  • 詳細は VCIでHSVtoRGBを実装する にも掲載されています。

サンプル

main.lua
local _hue = 0
 
function update()
 
    -- hueを毎フレーム0.01ずらす
    _hue = _hue + 0.01
 
    -- hueが1を越えたらリセット
    if _hue > 1.0 then
        _hue = 0
    end
 
    -- _hueの値を使ってColorを適用する
    local color = Color.HSVToRGB(_hue, 1, 1)
    vci.assets.SetMaterialColorFromName("CubeColor", color)
 
end

実行結果

(CubeColorが虹色に変化します)

grayscale

grayscale number

サンプル

main.lua
function onUse(use)
    local color = Color.__new(1, 0.2, 0.58)
    print(color.grayscale)
    print(0.299 * color.r + 0.587 * color.g + 0.114 * color.b)
end

実行結果

(0.482520014047623)
(0.482519999846816)

説明
カラーをグレースケールにした時の濃さを求めます

linear変換 / gamma変換

  • カラーをlinearとgammaに変換できます。

サンプル

main.lua
function onUse()
 
    -- gray 0.5
    local col = Color.__new(0.5, 0.5, 0.5, 1.0)
    print(col.ToString())
 
    -- linear
    print(col.linear.ToString())
 
    -- gamma
    print(col.gamma.ToString())
 
end

実行結果

RGBA(0.500, 0.500, 0.500, 1.000)
RGBA(0.241, 0.241, 0.241, 1.000)
RGBA(0.735, 0.735, 0.735, 1.000)

maxColorComponent

maxColorComponent number サンプル

main.lua
function onUse(use)
    local color = Color.__new(0.75, 0.2, 0.58)
    print(color.maxColorComponent)
end

実行結果

0.75

説明
RGBの要素で最も大きい値を返します

r g b a

サンプル

main.lua
function onUse(use)
    local color = Color.__new(0.75, 0.2, 0.58)
    print(color.r)
    color.r = 1
    print(color.r)
    print(color.g)
    print(color.b)
    print(color.a)
end

実行結果

0.75
1
0.200000002980232
0.579999983310699
1

説明
各要素にアクセスします。

vci/script/reference/color.txt · 最終更新: 2023/06/01 11:12 by pastatto

ページ用ツール