2016年12月30日 星期五

Unreal: Sound Analysis

since: 2016/12/30
update: 2016/12/30

reference:
1. eXifreXi/eXiSoundVis: UE4 Plugin
2. Plugin eXi's Sound Visualization Plugin
3. BigSoundBank.com - Download sounds in WAV, AIFF, MP3 and OGG


A. 版本
     1. Windows 10
     2. Unreal 4.14.1
     3. Visual Studio 2015 Update 2

-----------------------------------------------------------------------------------------------

B. 新增專案
    1. New Project > C++ > Basic Code
         > Name: SoundAnalysis > Create Project

    2. 關閉 Unreal > 在 SoundAnalysis 專案目錄內:
        > 刪除 Binaries 目錄
        > 新增 Plugins 目錄

    3. 到 eXifreXi/eXiSoundVis: UE4 Plugin下載 eXiSoundVis-master.zip 檔案
        解壓縮後更名為 eXiSoundVis 資料夾

    4. 將 eXiSoundVis 資料夾 copy 到專案目錄下的 Plugins 目錄內,
        並刪除
eXiSoundVis 裡的 Binaries 目錄.

    5. 到 BigSoundBank.com 下載.ogg 音效檔 (在此為 0614.ogg)
        > copy 到專案目錄下的 Songs 目錄(自行新增)

    6. Unreal 專案名稱 > Generate Visual Studio project files

    7. 重新開啟 Unreal 專案:
        > Would you like to rebuild them now? > 是(Y)

    8. 檢查 Plugin 是否已裝好:



    9. 檢查是否能正常編譯

   10. 新增 Empty Actor 到場景裡

   11. 新增此 ActorBlueprint

   12. 取名為: Actor_Blueprint

    13. 開啟 Actor_Blueprint, 新增 Sound Vis Component

     結果:

-----------------------------------------------------------------------------------------------

C.  列出專案下的 Songs 目錄內所有的 .ogg 音效檔
    1. 新增 Load Sound File Names 節點

    2. 結果(目前只有一個 0614.ogg 檔案)

-----------------------------------------------------------------------------------------------

D. 載入單一音檔(.ogg) 並加入 "載入完成" 的事件
    1. Add Load Sound File Node & Assign OnFileLoadCompleted Event


    2. 結果:

-----------------------------------------------------------------------------------------------

(舊方法,  不建議使用)
E. 分析音效頻率
    1. 新增 2 個變數:
        startTime: float , default: 0.0
        duration: float, default: 1.0

    startTime:


   duration:


    2. Calculate Freq Spectrum 相關節點

    3. 結果:

-----------------------------------------------------------------------------------------------

(新方法,  建議使用)
F. 分析音效頻率
    1. 新增 Start Calculate Freq Spectrum 相關節點

    2. 產生 OnFrequencySpectrumCalculated Event 節點

    3. 新增 Get Freq Value 相關節點:

    4. 結果:

2016年12月5日 星期一

Unreal: Light Mechanism

since: 2016/12/05
update: 2016/12/14


A. 前置準備
     1. 採用 I touchs: Unreal: VR Template A ~ D 步驟, 完成基本專案設置

     2. 加入點光源到場景裡:

     3. 加入觸發空間到場景裡:

-----------------------------------------------------------------------------------------------

B. After Game BeginPlay 10 second, Turn Off Light (Set Visibility False)
     > Level Blueprint

-----------------------------------------------------------------------------------------------

C. Trigger Volume: Turn Light On / Off

     > Level Blueprint
    1. Check Property (default is right)

    2. Add On Actor Begin/End Overlap

    3. 結果:

    4. Trigger Volume: Turn Light On / Off

-----------------------------------------------------------------------------------------------

D. Turn On Light to Dark (Intensity = 0)

     > Level Blueprint

    1. add  "Set Intensity" node:

    2. Turn On Light to Dark

-----------------------------------------------------------------------------------------------

E.
Trigger Volume: Timeline Light Up / Down


     > Level Blueprint

    1. "Timeline_LightIntensity_Up" Node

    2. "Timeline_LightIntensity_Down" Node

    3. Trigger Volume: Timeline Light Up / Down

-----------------------------------------------------------------------------------------------

F. Unreal: OSC Received set Light Intensity


    1. Send from Processing:

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

int receivePort = 8001;

// osc target
String sendIP = "127.0.0.1";
int sendPort = 8000;

//@add ######
float myIntensity = 0.0;
float maxIntensity = 5000.0;
boolean isUp = true;


void setup() {
  size(400, 400);
  frameRate(25);

  /* start oscP5, listening for incoming messages */
  oscP5 = new OscP5(this, receivePort);

  myRemoteLocation = new NetAddress(sendIP, sendPort);
}

void draw() {
  background(0); 
  sendOSC();
}

void sendOSC() { 

  /* in the following different ways of creating osc messages are shown by example */
  OscMessage myMessage = new OscMessage("/position");

  /* add an float to the osc message */
  myMessage.add(myIntensity);

  /* send the message */
  oscP5.send(myMessage, myRemoteLocation);


  // tune Intensity
  // light isUp

  if (isUp) {
    if (myIntensity < maxIntensity) {
      myIntensity += 100;
    } else {
      myIntensity = maxIntensity;
      isUp = false;
    }
  // light isDown 
  } else {

    if (myIntensity > 0.0) {
      myIntensity -= 100;
    } else {
      myIntensity = 0.0;
      isUp = true;
    }
  }
}


    2. Receieved from Unreal:
     > Level Blueprint

-----------------------------------------------------------------------------------------------

G. Branch Send OSC:
    1. Branch Send OSC:

    2. Map Branch Send OSC:

-----------------------------------------------------------------------------------------------

H. Depending on The Situation, Send OSC

    1. float to integer: Truncate

    2. integer minus integer

    3. Add Variable: lastOSCValue

    4. Type: Integer; default value: 0

    5. Map Branch: When LastOSCValue Changed, Then Send OSC(int: 0 ~ 255)

-----------------------------------------------------------------------------------------------

2016年12月3日 星期六

Unreal: Static Variables in C++

since: 2016/12/03
update: 2016/12/03

reference:
1. Static Keyword Explanation | Orfeas Eleftheriou
2. I touchs: Unreal: BeginPlay and GLog in C++
3. I touchs: Unreal: EndPlay Function in C++
4. I touchs: Unreal: Tick Function in C++


A. Add Static Variables


     1. 延續 I touchs: Unreal: Tick Function in C++ 的專案

     2. 在 LogActor.cppTick Function 內加入以下的內容:
         ....
         //@add ####

        static int32 x = 0;
        x++;
        GLog->Log(FString::FromInt(x));
         ....


   3. 編譯程式

-----------------------------------------------------------------------------------------------

B. 執行結果:

    停止遊戲, 再執行一次: (數值從上次接續開始)