色を簡単に変えたい
イメージした色に変えたいので、
swatchオブジェクトを使ってみました。
ちょうどDMXの機材の規格と同じ 0~255のRGBを返すので、それぞれチャンネルに設定していきます。
(カーブが一緒かは定かではないが、だいたい良さげ)
この機種はWなんてのもある。(さらに明るくできる感じ)
こんな風に使ってます
[s dmx]の先に[dmxusbpro]オブジェクトがあります。
詳しくは前回の記事 MaxでDMX(照明)を動かすを参照してください。
照明のはまりどころ
照明機材はRGBの明るさとは別に、Dimming(調光)というフェーダーがあります。
このフェーダーの明るさが掛け合わされる。
はまるポイントとして、
このチャンネル(ここでは3ch)に値が初期値だと、RGBのチャンネルをいくら変更しても光らない場合がありえます。
あと点滅したりとか。
さらにDMX制御の場合、同じチャンネルに様々な特殊演出が入っています。
点滅とかの周期も機種によって異なるので、合わせようとすると少し大変です。
この[if]オブジェクトと[zmap]で他の機材と簡易的に似た動作になるようにしています。
2台目のは10chがこのDimming関連で0-127が調光、128-256がストロボ演出のようでした。
11,12,13chがRGBでした。
(照明機材側でDMXの開始チャンネルを10にしています)
UnityにOSCを送る
UnityにOSCを送りたかったので
udpsendも送っています。
参考:NEAREAL様のUnityOSC で OSC を受信する / MaxMSP で送信する
UnityでOSC受信する
Unity内の照明も同じRGBで変えています。
ちょっと回転とかバグってますが、色変更のところはちゃんと動いているのでソースも載せておきます。
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;
}
}
}