LoginSignup
3
2

More than 5 years have passed since last update.

MAXでDMXのLED色変更 (おまけ:Unityの照明の色変更)

Last updated at Posted at 2017-12-17

色を簡単に変えたい

イメージした色に変えたいので、
swatchオブジェクトを使ってみました。
ちょうどDMXの機材の規格と同じ 0~255のRGBを返すので、それぞれチャンネルに設定していきます。
(カーブが一緒かは定かではないが、だいたい良さげ)

image.png

下の方の[pak 4 0]とかはチャンネルを示しています。
image.png

この機種はWなんてのもある。(さらに明るくできる感じ)

こんな風に使ってます

image.png

[s dmx]の先に[dmxusbpro]オブジェクトがあります。
詳しくは前回の記事 MaxでDMX(照明)を動かすを参照してください。

照明のはまりどころ

image.png

照明機材はRGBの明るさとは別に、Dimming(調光)というフェーダーがあります。
このフェーダーの明るさが掛け合わされる。

はまるポイントとして、
このチャンネル(ここでは3ch)に値が初期値だと、RGBのチャンネルをいくら変更しても光らない場合がありえます。 
あと点滅したりとか。

さらにDMX制御の場合、同じチャンネルに様々な特殊演出が入っています。
image.png

点滅とかの周期も機種によって異なるので、合わせようとすると少し大変です。
この[if]オブジェクトと[zmap]で他の機材と簡易的に似た動作になるようにしています。

2台目のは10chがこのDimming関連で0-127が調光、128-256がストロボ演出のようでした。
11,12,13chがRGBでした。
(照明機材側でDMXの開始チャンネルを10にしています)

UnityにOSCを送る

UnityにOSCを送りたかったので
image.png
udpsendも送っています。

参考:NEAREAL様のUnityOSC で OSC を受信する / MaxMSP で送信する

image.png

UnityでOSC受信する

Unity内の照明も同じRGBで変えています。

ちょっと回転とかバグってますが、色変更のところはちゃんと動いているのでソースも載せておきます。

OSCController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OSCController : MonoBehaviour {

    public Light sport1;
    public Light sport2;
    public Light sport3;
    public GameObject go;

    public string serverId = "MaxMSP";
    public string serverIp = "127.0.0.1";
    public int    serverPort = 12000;
    // Use this for initialization
    void Start () {
        OSCHandler.Instance.Init(this.serverId, this.serverIp, this.serverPort);
        to = go.transform;
        from = go.transform;
    }

    private long latestTimeStamp = 0;

    public Transform from = null;
    public Transform to = null;
    public float rotationSpeed = 10.0f;

    // Update is called once per frame
    void Update () {
        OSCHandler.Instance.UpdateLogs();

        foreach (KeyValuePair<string, ServerLog> item in OSCHandler.Instance.Servers)
        {
            if (item.Value.packets.Count == 0)
            {
                continue;
            }

            int latestPacketIndex = item.Value.packets.Count - 1;

            if (this.latestTimeStamp == item.Value.packets[latestPacketIndex].TimeStamp)
            {
                continue;
            }

            this.latestTimeStamp = item.Value.packets[latestPacketIndex].TimeStamp;

            Debug.Log("Receive : "
                + item.Value.packets[latestPacketIndex].TimeStamp
                + " / "
                + item.Value.packets[latestPacketIndex].Address
                + " / "
                + item.Value.packets[latestPacketIndex].Data[0]
            //+ item.Value.packets[latestPacketIndex].Data[1]
            //+ item.Value.packets[latestPacketIndex].Data[2]
            );

            if (item.Value.packets [latestPacketIndex].Address == "/color") {
                Color newColor = new Color ((int)item.Value.packets [latestPacketIndex].Data [0] / 255.0f,
                                    (int)item.Value.packets [latestPacketIndex].Data [1] / 255.0f,
                                    (int)item.Value.packets [latestPacketIndex].Data [2] / 255.0f

                                );
                sport1.color = newColor;
                sport2.color = newColor;
                sport3.color = newColor;
            }


            if (item.Value.packets [latestPacketIndex].Address == "/rotate") {
                //go.transform.Rotate (0, (int)item.Value.packets [latestPacketIndex].Data [0] / 255.0f * 360.0f, 0);
                to.transform.Rotate (0, (((int)item.Value.packets [latestPacketIndex].Data [0] / 255.0f) - 0.5f )*180.0f , 0);
            }

            float rotationStep = rotationSpeed * Time.deltaTime;
            Quaternion rotation = Quaternion.RotateTowards (from.rotation, to.rotation, rotationStep);
            from.rotation = rotation;

        }
    }
}

動画:音でUnityの画面外まで光らせてみた

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2