~~NOTOC~~ ====== ExportAvatar(アバター情報) ====== このページは過去の情報となります。\\ 新しいスクリプトリファレンスは**[[https://developer.virtualcast.jp/vci-docs/api/|こちら]]**になります。 アバター情報を取得します。 [[https://developer.virtualcast.jp/vci-docs/api/classes/ExportStudio/index.html|ExportStudio]]の''GetOwner'', ''GetAvatars''から取得できます。\\ ^ 名前 ^ 説明 ^ バージョン ^ | [[vci/script/reference/exportavatar#GetName]] | ユーザー名を取得 | | | [[vci/script/reference/exportavatar#GetId]] | ユーザーIDを取得 | | | [[vci/script/reference/exportavatar#IsOwner]]| VCIの所有者かどうか | | | [[vci/script/reference/exportavatar#GetLocalPosition / GetPosition]] | 足元の座標を取得 **※1 ※2**| | | [[vci/script/reference/exportavatar#GetLocalRotation / GetRotation]] | 回転を取得 **※1**| | | [[vci/script/reference/exportavatar#GetLocalScale]] | 縮尺を取得 **※1**| | | [[vci/script/reference/exportavatar#GetRight / GetUp / GetForward]] | (X/Y/Z軸)のベクトルを取得 **※1**| | | [[vci/script/reference/exportavatar#GetLocalToWorldMatrix ]] | ローカル→ワールド座標に変換した行列を取得 **※1**| | | [[vci/script/reference/exportavatar#GetBoneTransform]] | ボーン情報を取得 **※1**| | **※1**\\ ** アバター情報の読込中や、アバター切替時にnilが返されることがあるので、使用する際はnilチェックを入れてください。 **\\ **※2**\\ ** ルームではHipボーンの位置を取得します ** ==== 概要 ==== - [[https://developer.virtualcast.jp/vci-docs/api/classes/ExportStudio/index.html|ExportStudio]]の''GetOwner'', ''GetAvatars''を実行してアバター情報を取得する。 - 取得したアバター情報に対して''GetBoneTransform'', ''GetName''を実行して詳細な情報を取り出す。 === 注意点 === * GetBoneTransform()は**初回実行時**に関してはnilが返されます。\\ また、アバター読み込み時の場合、nilが返される場合があります。 * ''vci.studio.GetAvatars()''でアバターを取得した際のIndex番号に割り振られているプレイヤーはクライアント毎に異なります。 * 処理の内容によってはboneのnilのチェックを行う必要がります。 === 基本サンプル === -- VCIの持ち主(VCIを出した人)の情報を取得する local owner = vci.studio.GetOwner() -- VCIの持ち主の名前を表示 print(owner.GetName()) -- boneのnilチェック local hipsBone = owner.GetBoneTransform("Hips") if hipsBone then -- Hipsのpositionを表示する print(hipsBone.position) -- Hipsのrotationを表示する print(hipsBone.rotation) end === スタジオ内に居るプレイヤーの一覧を出力するサンプル === -- スタジオ内に居るプレイヤーの一覧を表示する local _avatars = vci.studio.GetAvatars() for i = 1, #_avatars do print("avatars["..tostring(i).."]: ".._avatars[i].GetName()) end ==== テンプレート ==== -- VCIの持ち主(VCIを出した人)の情報 local _ownerAvater -- 初期化 (VCIの持ち主のみ実行) if vci.assets.IsMine then _ownerAvater = vci.studio.GetOwner() print("ホスト : ".._ownerAvater.GetName()) end -- リモートの確認 if vci.assets.IsMine == false then print("あなたはVCIの持ち主ではありません") end function updateAll() if vci.assets.IsMine then print("VCIの持ち主のみが実行する処理") end end function onUse(switch) -- 各クライアントでonUseFireOnce()を実行する vci.message.Emit("onUseFireOnce", tostring(switch)) end function onUseFireOnce(sender, name, message) print("message : "..tostring(message)) -- VCIの持ち主のみ実行 if vci.assets.IsMine then -- ここで主に部屋主のアバター情報などを取得 print("VCIの持ち主のみ実行する処理") end -- リモートで確認 if vci.assets.IsMine == false then print("VCIの持ち主以外が実行する処理") end end -- Emit "onUseFireOnce" で onUseFireOnce()を実行する vci.message.On("onUseFireOnce", onUseFireOnce) _ownerAvaterに関係する処理をVCIの持ち主のクライアントのみで実行する場合のサンプルです。\\ VCIの持ち主が代表して実行し、リモートのクライアントからは_ownerAvaterにアクセスしないイメージです。\\ 同期変数やメッセージを使って状態を同期させます。 ===== GetName ===== **GetName fun(): string** VCI所有者のユーザー名を表示します。 === サンプル === function onUse(use) local owner = vci.studio.GetOwner() print(owner.GetName()) end === 実行結果 === "バーチャルキャストちゃん" ===== GetId ===== **GetId fun(): string** VCI所有者のユーザーIDを取得します。\\ スタジオ内のみで有効な値です。スタジオを抜けるとIDが変わります。 === サンプル === function onUse(use) local owner = vci.studio.GetOwner() print(owner.GetId()) end === 実行結果 === ""79325077"" ===== IsOwner ===== **IsOwner fun(): bool** VCIの所有者かどうかを示す値を返します。 === サンプル === function onUse(use) local owner = vci.studio.GetOwner() print(owner.IsOwner()) end === 実行結果 === true ===== GetLocalPosition / GetPosition ===== **GetLocalPosition fun(): Vector3**\\ **GetPosition fun(): Vector3** それぞれVCI所有者の足元のローカル、ワールド座標を取得します。 === サンプル === function onUse(use) local owner = vci.studio.GetOwner() print(owner.GetLocalPosition()) print(owner.GetPosition()) end === 実行結果 === (1.8, 0.0 , 1.7) (1.8, 0.0 , 1.7) ===== GetLocalRotation / GetRotation ===== **GetLocalRotation fun(): Quaternion**\\ **GetRotation fun(): Quaternion** それぞれVCI所有者のローカル、ワールド回転を取得します。 === サンプル === function onUse(use) local owner = vci.studio.GetOwner() print(owner.GetLocalRotation()) print(owner.GetRotation()) end === 実行結果 === (0.0, 0.4, 0.0, 0.9) (0.0, 0.4, 0.0, 0.9) ===== GetLocalScale ===== **GetLocalScale fun(): Vector3** VCI所有者の縮尺を取得します。 === サンプル === function onUse(use) local owner = vci.studio.GetOwner() print(owner.GetLocalScale()) end === 実行結果 === (1.0, 1.0, 1.0) ===== GetRight / GetUp / GetForward ===== **GetRight fun(): Vector3**\\ **GetUp fun(): Vector3**\\ **GetForward fun(): Vector3** GetRight()は右方向(+X)のベクトル、owner.GetUp()は上方向(+Y)ベクトル、owner.GetForward()は正面(+Z)ベクトルを取得します。\\ サンプルはそれぞれVCI所有者のベクトルを取得しています。 === サンプル === function onUse(use) local owner = vci.studio.GetOwner() print(owner.GetRight()) print(owner.GetUp()) print(owner.GetForward()) end === 実行結果 === (1.0, 0.0, -0.3) (0.0, 1.0, 0.1) (0.3, -0.1, 1.0) ===== GetLocalToWorldMatrix ===== **GetLocalToWorldMatrix fun(): Matrix4x4** 3つのベクトルと現在の座標を取得できる。 === サンプル === function onUse(use) local owner = vci.studio.GetOwner() print(owner.GetRight()) print(owner.GetUp()) print(owner.GetForward()) print(owner.GetLocalPosition()) print(owner.GetLocalToWorldMatrix()) end === 実行結果 === (0.7, 0.0, 0.7) (0.0, 1.0, 0.0) (-0.7, 0.0, 0.7) (2.0, 0.0, 2.3) 0.68498 -0.02538 -0.72812 1.96983 0.00523 0.99954 -0.02992 0.00000 0.72855 0.01669 0.68479 2.26828 0.00000 0.00000 0.00000 1.00000 ===== GetBoneTransform ===== GetBoneTransformは、UnityHumanoidAvaterの[[https://docs.unity3d.com/ja/2018.4/ScriptReference/HumanBodyBones.html|HumanBodyBones]]の変数名から、ボーン情報を得るための関数です。\\ 無効なボーン名や、対応していないボーンを指定した場合は、nilが返ります。 UnityHumanoidAvaterに関しては、[[unity:humanoid|こちら]]をご覧ください。 === サンプル === -- VCI所有者情報を取得する。 local owner = vci.studio.GetOwner() ---- サブアイテムを取得する local subItem = vci.assets.GetTransform("SubItem1") -- 右手の位置にサブアイテムを動かす。 local rightHand = owner.GetBoneTransform("RightHand") if rightHand then subItem.SetPosition(rightHand.position) subItem.SetRotation(rightHand.rotation) end ボーン情報(Table型) ^ キー ^ 型 ^ 説明 ^ | position | Vector3 | ボーンのワールド座標 | | rotation| Quaternion| ボーンのワールド回転 |