update: 2016/12/19
reference:
1. VR Template Guide for Unreal Engine 4 – Tom Looman
2. Creating a basic VR demo using Unreal
3. 虚幻引擎 4.14 版发布!
4. monsieurgustav/UE4-OSC
5. Using Raycasts (Tracing) in Blueprints | Unreal Engine
A. 版本:
1. Windows 10
2. Unreal 4.14.0
3. Visual Studio 2015 Update 2
-----------------------------------------------------------------------------------------------
B. 新增專案
1. New Project > Blueprint > Virtual Reality
> Name: VR_Template > Create Project
> Content > VirtualRealityBP > Maps
> 滑鼠雙擊 MotionControllerMap
> Edit > Project Settings...
> 將 Editor Startup Map 與 Game Default Map 皆設為: MotionControllerMap
C. 將 Blueprint 專案轉換成 C++ 專案
1. Add New > New C++ Class...
> None > Next
> Create Class
> File > Save All > Exit (養成存檔的好習慣)
6. 在檔案總管, 將專案下的 Source > VR_Template 目錄內的:
MyClass.h 與 MyClass.cpp 刪除
> 右鍵 > Generate Visual Studio project files
10. 重新開啟 Unreal 專案:
> .... rebuild .... > 是
-----------------------------------------------------------------------------------------------
D. 加入 OSC 功能
1. 在專案目錄下新增 Plugins 資料夾
> 下載 monsieurgustav/UE4-OSC 的檔案
> 解壓縮後, 將整個 OSC 目錄複製到 Plugins 資料夾內
E. Send OSC (Pickup / Drop)
1. 開啟 BP_PickupCube
> 不作修改
> 加入 SendOSC 相關節點
> 不作修改
> 加入 SendOSC 相關節點
F. OSC Received (Level Blueprint)
1. 從 Event BeginPlay 連結 Add Osc Receiver Component 節點
> 再連結 Assign On Osc Received 節點
2. 結果:
> 產生 Bind Event to OnOscReceived 與 OnOscReceived_Event_0 節點
G. Get Player Location (Level Blueprint)
H. Move Player Location (MotionControllerPawn)
1. 滑鼠雙擊 MotionControllerPawn 來開啟
I. Get Actor from any Blueprint (ex: MotionControllerPawn)
1. 新增一個 Sphere, 取名為 MySphere, 調整位置大小後, 設為可移動.
-----------------------------------------------------------------------------------------------
J. Send OSC Bundle
1. Processing: send; Unreal: receive
a. send by Processing:
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
void setup() {
size(400,400);
frameRate(25);
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,12000);
/* 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("127.0.0.1",8000);
}
void draw() {
background(0);
delay(500); //delay 0.5 second
sendMyOSC();
}
//void mousePressed() {
void sendMyOSC() {
/* create an osc bundle */
OscBundle myBundle = new OscBundle();
/* createa new osc message object */
OscMessage myMessage = new OscMessage("/position");
myMessage.add(123.0);
/* add an osc message to the osc bundle */
myBundle.add(myMessage);
/* reset and clear the myMessage object for refill. */
myMessage.clear();
/* refill the osc message object again */
myMessage.setAddrPattern("/position2");
myMessage.add(456.0);
myBundle.add(myMessage);
myBundle.setTimetag(myBundle.now() + 10000);
/* send the osc bundle, containing 2 osc messages, to a remote location. */
oscP5.send(myBundle, myRemoteLocation);
}
b. received by Unreal:(Level Blueprint)
2. Unreal: send; Processing: receive
a. send by Unreal: (might in BP_PickupCube)
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
void setup() {
size(400,400);
frameRate(25);
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,12000);
/* 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("127.0.0.1",8000);
}
void draw() {
background(0);
}
/* 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());
print(" typetag: "+theOscMessage.typetag());
println(" timetag: "+theOscMessage.timetag());
// get values format:
//int myInt = theOscMessage.get(0).intValue();
//float myFloat = theOscMessage.get(1).floatValue();
//String myStr = theOscMessage.get(0).stringValue();
if(theOscMessage.checkAddrPattern("/position") == true) {
float myFloat = theOscMessage.get(0).floatValue(); // get the first osc argument
println("/position myFloat: "+myFloat);
}
else if (theOscMessage.checkAddrPattern("/position2") == true) {
float myFloat = theOscMessage.get(0).floatValue(); // get the first osc argument
println("/position2 myFloat: "+myFloat);
}
}
c. 結果:
K. Ray Casts(光線投射)
1. Capsule Trace By Channel (Level Blueprint)
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。