since: 2016/06/23
update: 2016/11/25
reference:
1. [Plugin] OSC for UE4
2. monsieurgustav/UE4-OSC
3. UE4-OSCの送受信を行う - Qiita
4. I touchs: Unreal: OSC Plugin For UE4 ---- 1/4
5. I touchs: Unreal: OSC Plugin For UE4 ---- 2/4
6. I touchs: Unreal: OSC Plugin For UE4 ---- 3/4
Stage 4/4: OSC Sender
A. 新增 OSCSender Blueprint
1. >
Content Browser
>
AddNew >
Blueprint Class >
Actor
> 命名為
OSCSender > 滑鼠雙擊打開
2. 在
Event Graph 裡, 新增
Send Osc Node 並與
Event Tick 連結
3. 新增取得
Actor 位置與
OSC Address 的變數:
Type:
Actor Reference 變數名稱:
Source ,
可編輯
Type:
Name 變數名稱:
Address,
可編輯
-----------------------------------------------------------------------------------------------
B. OscSender Event Graph
1. 由
GetActorLocation 取得
Source 的位置
2. 將其座標拆成
三個 float 當成
Send Osc 的
Data
3.
Send Osc 的
Address 值將在
Level Editor 裡設定
-----------------------------------------------------------------------------------------------
C. OSC Sendr 設定
1. 回到
Level Editor, 將
OSCSender 從
Content Browser 拖拉到
場景裡.
在 OSCSender 選取的情況下, 到 Details 裡
> 將
OSC 的
Source 設為:
MyCube
> 將
OSC 的
Address 設為:
/position
2. 結果:
進入關卡後, OSCSender 發送 MyCube 本身的位置給 OSCReceiver,
而 OSCReceiver 將此座標更新給 MyCylinder.
> MyCylinder 跟隨著 MyCube 上下移動了.
-----------------------------------------------------------------------------------------------
D. 備註
1. 可供測試用的
Processing code:
(version 2.2.1)
/**
* oscP5sendreceive by andreas schlegel
* example shows how to send and receive osc messages.
* oscP5 website at http://www.sojamo.de/oscP5
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
int receivePort = 8000;
String sendIP = "127.0.0.1";
int sendPort = 8000;
void setup() {
size(400,400);
frameRate(25);
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this, receivePort);
/* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
* an ip address and a port number. myRemoteLocation is used as parameter in
* oscP5.send() when sending osc packets to another computer, device,
* application. usage see below. for testing purposes the listening port
* and the port of the remote location address are the same, hence you will
* send messages back to this sketch.
*/
myRemoteLocation = new NetAddress(sendIP, sendPort);
}
void draw() {
background(0);
}
void mousePressed() {
/* in the following different ways of creating osc messages are shown by example */
OscMessage myMessage = new OscMessage("/position");
//myMessage.add(123); /* add an int to the osc message */
myMessage.add(100.0);
myMessage.add(200.0);
myMessage.add(300.0);
/* send the message */
oscP5.send(myMessage, myRemoteLocation);
}
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
/* print the address pattern and the typetag of the received OscMessage */
print("### received an osc message.");
print(" addrpattern: "+theOscMessage.addrPattern());
println(" typetag: "+theOscMessage.typetag());
theOscMessage.print();
}
2. 一般情況下,
OSC Receiver 端先啟動, 再啟動
OSC Sender 端
-----------------------------------------------------------------------------------------------
E. VR 事件觸發 send OSC
1.
說明: 原本要使用 Trigger Volume 來處理事件的觸發, 但是在 VR 裡沒有作用,
下次再使用手把的方式來試試.
2. 先做 "修正 VR 的地平線水平高度" 的處理:
參考: I touchs: Unreal: Begin A Virtual Reality Project
> C. 修正 VR 的地平線水平高度
3. 匯入
.obj 檔, 來源:
2150_tid_rock.zip.zip
4. 滑鼠雙擊
VR_Pawn , 進入編輯畫面.
5. 新增
Static Mesh Component
6. 取名為
StoneMesh 並拖拉到
Camera 下方
7. 在
StoneMesh 點選的情況下, 到右邊 Details:
調整
Location 位置, 與
Scale 數值, 並指定所要使用的
Static Mesh.
說明: a. 此處的
Location 是相對於其
parent (Camera) 的座標.
b. 由於
Static Mesh 主要用來作事件觸發, 不需要顯示出來,
因此可以縮放到很小.
8. 調整 Collision 下的:
> 確認
勾選:
Generate Overlap Events
>
Collision Presets:
Trigger
9. 新增
Event:
On Component Begin Overlap
與
On Component End Overlap
10.
結果:
11.補上
Send OSC 的機制
12. 新增一個
Sphere 到場景裡, 調整大小並靠近
PlayerStart 位置.
13. 點選
Sphere, 在其
Details 裡, 調整
Collision 屬性:
> 確認
勾選:
Generate Overlap Events
>
Collision Presets:
Trigger