[vci楽器制作メモ]太鼓リズムマシーン

出来たのがこれ。

 

やりたかった機能は以下です。
 
  • Useしたらアニメーション太鼓が叩かれるアニメーションが始まり音も流れ出す。
  • 横のプラスマイナスのキューブをタッチしたら流れる太鼓の音のBPMを変えられる。表示も変わる。

 

vciのバージョンはUniVCI-0.17です。

 

スクリプトの全体

bool_loop = false
bool_clock = false
count = 1

--テクスチャの中の分割数
local TOTAL = 9
bgmvol = 0.5

--キューブに触れるとcountを計算、テクスチャを動かす。

function onTriggerEnter(item, hit)
    if item == "Cube1" then
        if count >= TOTAL-1 then
            count = 0
        else
            count = count + 1
       end
        SetTextureOffset(count)
    end

    if item == "Cube" then
        if count < 1 then
            count = 8
        else
            count = count -1
        end
        SetTextureOffset(count)
    end
end

--Useするとアニメーションを動かす。bool_loopとbool_clockをtrueにする。

function onUse(use)
    if use == "taiko" then
        if bool_loop == false then
            vci.assets._ALL_PlayAnimationFromName("taiko_motion2",true)
            bool_loop = true
            bool_clock = true
        else
            vci.assets._ALL_StopAnimation()
            vci.assets.audio._ALL_Stop("taiko_sound")

    bool_loop = false
        end
    end
end

 

--bool_loopがtrueの時音を鳴らすタイミング計算

--bool_clockがtrueになったら再生した時間を記録してすぐfalseに戻す。

--clockStartでos.clockを引いた数がBPMを越えたら音を鳴らす。

function updateAll()
    if bool_loop == true then
        if bool_clock == true then
            clockStart = os.clock() --再生した時間を記録
            bool_clock = false
        end
        if os.clock() - clockStart > 60*(1/(110 +(count *10 ))) then
            vci.assets.audio._ALL_Play("taiko_sound", bgmvol, false)
            bool_clock = true
        end
 end

end

 

--画像の表示場所計算

function SetTextureOffset( count )
    local offset = Vector2.zero
    -- y shift
    local Yshift = math.floor(count / 3)
    offset.y = -(1/3) * Yshift

    -- x shift
    local Xshift = count % 3
    offset.x = (1/3) * Xshift
    vci.assets._ALL_SetMaterialTextureOffsetFromIndex(8, offset)
end

SetTextureOffset(count)

 

 

 

 

f:id:alakialaca:20190606032804p:plain

テンポの表示を変える。

 

 

↓の「Useすると柄が変わるポスター」がわかりやすい。

https://virtualcast.jp/wiki/doku.php?id=vci:sample:onuse:no5

 

このイベント関数で、テクスチャの表示区間?場所?を変えます。

↓のような画像があるとして、

f:id:alakialaca:20190606042624j:plain

1の部分、2の部分と表示場所を移して行く感じです。オフセット移動とか書かれてもわかりづらいよ。。。

f:id:alakialaca:20190606042600p:plain

続きを読む

[vci楽器制作メモ]ギターみたいにストロークで音を鳴らす。

とりあえず完成図。vciのバージョンはUniVCI-0.17です。

 

 

「キューブを手が通ったら、もうひとつの手が接触しているコードを鳴らす。」

がやりたいことです。

 

スクリプトはこういう感じでしました。

 

bool_C = false
bool_Dm = false
bool_Em = false
bool_F = false
bool_G = false
bool_Am = false
vol =0.25

function onTriggerEnter(item, hit)
    if hit == "HandPointMarker" and item =="C" then
        bool_C = true
    end
    if hit == "HandPointMarker" and item =="Dm" then
        bool_Dm = true
    end
    if hit == "HandPointMarker" and item =="Em" then
        bool_Em = true
    end
    if hit == "HandPointMarker" and item =="F" then
        bool_F = true
    end
    if hit == "HandPointMarker" and item =="G" then
        bool_G = true
    end
    if hit == "HandPointMarker" and item =="Am" then
        bool_Am = true
    end

    if hit == "HandPointMarker" and item =="Cube" and bool_C == true then
        vci.assets.audio._ALL_Play("C",vol,false)
    end
    if hit == "HandPointMarker" and item =="Cube" and bool_Dm == true then
        vci.assets.audio._ALL_Play("Dm",vol,false)
    end
    if hit == "HandPointMarker" and item =="Cube" and bool_Em == true then
        vci.assets.audio._ALL_Play("Em",vol,false)
    end
    if hit == "HandPointMarker" and item =="Cube" and bool_F == true then
        vci.assets.audio._ALL_Play("F",vol,false)
    end
    if hit == "HandPointMarker" and item =="Cube" and bool_G == true then
        vci.assets.audio._ALL_Play("G",vol,false)
    end
    if hit == "HandPointMarker" and item =="Cube" and bool_Am == true then
        vci.assets.audio._ALL_Play("Am",vol,false)
    end

end

function onTriggerExit(item, hit)
    if hit == "HandPointMarker" and item =="C" then
        bool_C = false
    end
    if hit == "HandPointMarker" and item =="Dm" then
        bool_Dm = false
    end
    if hit == "HandPointMarker" and item =="Em" then
        bool_Em = false
    end
    if hit == "HandPointMarker" and item =="F" then
        bool_F = false
    end
    if hit == "HandPointMarker" and item =="G" then
    bool_G = false
    end
    if hit == "HandPointMarker" and item =="Am" then
        bool_Am = false
    end
end

 
 

Booleanの変数をコードの数作成し、

HandPointMakerがコードのオブジェクトに入っている間(onTriggerEnter)はtrue、出たら(onTriggerExit)falseにして、

キューブにHandPointMakerが入ると、trueになっているコードを鳴らすというものです。

 

 

 

 

 

 

 

 

 

 

 

 

 

vci で複数のオブジェクトをまとめて掴み動かす。

こういう感じに、まとめて動かせるようにしたかった。

もちろん、コード各々違う音も出ますよ。

f:id:alakialaca:20190519113530g:plain

 

元動画はこっち。

 

一体にしたいアイテムをVCI Sub Itemアタッチした空のオブジェクト(GameObject)の子どもにして、まとめると一緒に動かせられました。

f:id:alakialaca:20190519113826j:plain

VCI Sub Itemの親はVCI Objectの直下にしないといけないため、

まとめたアイテムからVCI Sub Itemを削除する必要があるのと、

f:id:alakialaca:20190519115349j:plain

 

掴むためにGameObjectにコライダーを入れる必要があるのが注意点です。

しかし、GameObjectのコライダーとまとめたオブジェクトのコライダーが重なるため、

GameObjectのコライダーのIs Triggerのチェックをつけました。

 

f:id:alakialaca:20190519115853j:plain


とりあえず、僕はこうやってやったっていうメモです。

他にもこういう方法があるというのがあれば教えて欲しいです。

 

 

2019/06/04追記 

 

以下のVCI サンプラー 改造手順を見て知ったのですが、

 

https://3d.nicovideo.jp/works/td55549

 Fixed Jointを使えば、オブジェクトをGameObjectの子どもにしなくても済みました。

これをすればGameObjectの子どもに対してonTriggerEnterなども使える。

なるほどー

f:id:alakialaca:20190604033353p:plain

 

 

 

 

[vci楽器制作メモ]叩いたら音を出す。そして弾き語りをする。

vciを使って弾き語り用のVR楽器(ただ叩いたらコードが鳴る)を作ってみたメモです。vciのバージョンはUniVCI-0.17です。

以下のようになりました。 

 

Lua言語なんて初めて聞いたのでさっぱりわからなかったけど、下の画像の様に配置して

f:id:alakialaca:20190509022050j:plain

 

続きを読む

vciでattempt to perform arithmetic on a nil valueのエラー

この度初めてthe seed onlineのvciのスクリプトいじってみました。

VR環境の中でデバッグできるのスゴーいって思いながら見てみると

 

attempt to perform arithmetic on a nil value

のエラーでスクリプトが読み込めてない。

 

f:id:alakialaca:20190422021321j:plain

原因はVCIObjectのプロパティのmain.luaのNameの一番最初にスペースが入っていたからでした。

 

⬇️よくみたらmainの前にインデントが

f:id:alakialaca:20190422021605j:plain

 

しかもファイル名の変更では、一番最初にスペースを入れられないため、エクスポートのし直しでした。

 

 

 

 

 

 

crystal reports 重複したデータを非表示、改ページしたら表示。

下記サイトに書いてある、

 http://d.hatena.ne.jp/haradago/touch/20090220/p1

 

OnFirstRecord() = false AND {テーブル.項目A}=Previous({テーブル.項目A})

スクリプトで重複したデータの非表示はできるのですが、改ページが行われた際に非表示のまま。

 

 

 そこで、

「指定行で改ページしたい」を参考に

https://www6.atwiki.jp/we_hate_sunshine/pages/58.html

 

//ヘッダー

WhilePrintingRecords;
numberVar line := 0;

 

//  詳細
WhilePrintingRecords;
numberVar line;
line := line + 1;

 

// 表示条件
WhilePrintingRecords;
numberVar line;

OnFirstRecord() = false AND {テーブル.項目A}=Previous({テーブル.項目A}) AND rowcount<>1

 

とすることで、改ページした時は一つ目を表示ができた。

 

crystal構文とやらの変数??の扱い不思議。

毎回宣言するのが不思議な感じ。

 

 

a command is already in progress のエラー

Oracleをpostgressに移行の作業を手伝いをしたときのことです。

 

Npgsplというオープンソースでデータベースにアクセスされていて、

この a command is already in progressのエラーが起こった。

 

調べてみると、英語の記事えエラーの文言も少し違うし、しかもC#のしか出てこなかったけど、

 

https://stackoverflow.com/questions/36283841/c-sharp-winforms-npgsql-3-0-5-an-operation-already-in-progress-error-when-tryi


f:id:alakialaca:20190318123412j:image

新しいコマンドを実行する前に破棄する必要があるみたい。

ソース内で連続して複数回データ読み込まれていたので、これっぽい。

 

 

先輩に聞くとそんなことないでしょ。

と初めに言われたが、

 

実際、読み込みを2つ並べるとエラーがおき、

ちゃんとcloseしてから、読み込みするとうまくいく。

 

postgres移行前のソースでは、複数の読み込みをしてたからoracleではできるんですかね。

 

そしてDBの読み込み部はusing句でくくると良いみたい。

using句でくくるとcloseしなくてよいのは、

「using close」でググったらいっぱいでてくるけど、↓下記のサイトがわかりやすい。

https://qiita.com/iiokazuya/items/dfa0b66898a2b39fc1e9