この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
vci:script:reference:exportavatar [2019/12/20 18:56] h-eguchi |
vci:script:reference:exportavatar [2023/07/28 14:04] (現在) Ramen APIリファレンスへリンク修正 |
||
|---|---|---|---|
| ライン 1: | ライン 1: | ||
| - | ===== ExportAvatar ===== | + | ~~NOTOC~~ |
| + | ====== ExportAvatar(アバター情報) ====== | ||
| + | <WRAP center round important 80%> | ||
| + | このページは過去の情報となります。\\ | ||
| + | 新しいスクリプトリファレンスは**[[https://developer.virtualcast.jp/vci-docs/api/|こちら]]**になります。 | ||
| + | </WRAP> | ||
| アバター情報を取得します。 | アバター情報を取得します。 | ||
| + | [[https://developer.virtualcast.jp/vci-docs/api/classes/ExportStudio/index.html|ExportStudio]]の''GetOwner'', ''GetAvatars''から取得できます。\\ | ||
| - | [[vci:script:reference:exportstudio|ExportStudio]]の''GetOwner'', ''GetAvatars''から取得できます。 | ||
| - | ===== 関数一覧 ===== | ||
| - | **関数一覧は[EmbeddedScriptWorkspace]フォルダ内の[types.lua]を開くと最新の関数一覧を確認できます。**\\ | + | ^ 名前 ^ 説明 ^ バージョン ^ |
| + | | [[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**| | | ||
| - | ==== ExportAvatar ==== | + | **※1**\\ |
| + | ** アバター情報の読込中や、アバター切替時にnilが返されることがあるので、使用する際はnilチェックを入れてください。 **\\ | ||
| + | **※2**\\ | ||
| + | ** ルームではHipボーンの位置を取得します ** | ||
| - | ^ 関数名 ^ 説明 ^ | + | ==== 概要 ==== |
| - | | GetName fun(): string | ユーザー名を取得します | | + | |
| - | | GetId fun(): string | ユーザーIDを取得します。スタジオ内のみで有効な値です。スタジオを抜けるとIDが変わります。 | | + | |
| - | | IsOwner fun(): bool| VCIの所有者かどうかを示す値を返します。 | | + | |
| - | | GetLocalPosition fun(): Vector3 | 足元のローカル座標を取得します。 **※1**| | + | |
| - | | GetPosition fun(): Vector3 | 足元のワールド座標を取得します。 **※1**| | + | |
| - | | GetLocalRotation fun(): Quaternion | ローカル回転を取得します。 **※1**| | + | |
| - | | GetRotation fun(): Quaternion | ワールド回転を取得します。 **※1**| | + | |
| - | | GetLocalScale fun(): Vector3 | 縮尺を取得します。 **※1**| | + | |
| - | | GetRight fun(): Vector3 | 右方向(+X)のベクトルを取得します。 **※1**| | + | |
| - | | GetUp fun(): Vector3 | 上方向(+Y)ベクトルを取得します。 **※1**| | + | |
| - | | GetForward fun(): Vector3 | 正面(+Z)ベクトルを取得します。 **※1**| | + | |
| - | | GetLocalToWorldMatrix fun(): Vector3 | ローカル座標からワールド座標に変換した時の行列を取得します。 **※1**| | + | |
| - | | GetBoneTransform fun(boneName: string): usertype | ボーン情報を取得します。 **※1**| | + | |
| - | **※1**\\ | + | - [[https://developer.virtualcast.jp/vci-docs/api/classes/ExportStudio/index.html|ExportStudio]]の''GetOwner'', ''GetAvatars''を実行してアバター情報を取得する。 |
| - | ** アバター情報の読込中や、アバター切替時にnilが返されることがあるので、使用する際はnilチェックを入れてください。 ** | + | - 取得したアバター情報に対して''GetBoneTransform'', ''GetName''を実行して詳細な情報を取り出す。 |
| - | \\ | + | |
| - | ---- | + | |
| - | ==== GetBoneTransformについて ==== | + | === 注意点 === |
| - | GetBoneTransformは、[[https://docs.unity3d.com/ja/current/ScriptReference/HumanBodyBones.html|HumanBodyBones]]の変数を入力して、ボーン情報を得るための関数です。無効なボーン名や、対応していないボーンを指定した場合は、nilが返ります。 | + | * GetBoneTransform()は**初回実行時**に関してはnilが返されます。\\ また、アバター読み込み時の場合、nilが返される場合があります。 |
| + | * ''vci.studio.GetAvatars()''でアバターを取得した際のIndex番号に割り振られているプレイヤーはクライアント毎に異なります。 | ||
| + | * 処理の内容によってはboneのnilのチェックを行う必要がります。 | ||
| + | |||
| + | === 基本サンプル === | ||
| - | 使用例 | ||
| <file lua main.lua> | <file lua main.lua> | ||
| - | -- オーナー情報を取得する。 | + | -- 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 | ||
| + | </file> | ||
| + | |||
| + | === スタジオ内に居るプレイヤーの一覧を出力するサンプル === | ||
| + | |||
| + | <file lua main.lua> | ||
| + | -- スタジオ内に居るプレイヤーの一覧を表示する | ||
| + | local _avatars = vci.studio.GetAvatars() | ||
| + | for i = 1, #_avatars do | ||
| + | print("avatars["..tostring(i).."]: ".._avatars[i].GetName()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | ==== テンプレート ==== | ||
| + | |||
| + | <file lua main.lua> | ||
| + | -- 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) | ||
| + | </file> | ||
| + | |||
| + | _ownerAvaterに関係する処理をVCIの持ち主のクライアントのみで実行する場合のサンプルです。\\ | ||
| + | VCIの持ち主が代表して実行し、リモートのクライアントからは_ownerAvaterにアクセスしないイメージです。\\ | ||
| + | 同期変数やメッセージを使って状態を同期させます。 | ||
| + | |||
| + | ===== GetName ===== | ||
| + | **GetName fun(): string** | ||
| + | |||
| + | VCI所有者のユーザー名を表示します。 | ||
| + | |||
| + | === サンプル === | ||
| + | |||
| + | <file lua main.lua> | ||
| + | function onUse(use) | ||
| + | local owner = vci.studio.GetOwner() | ||
| + | print(owner.GetName()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | === 実行結果 === | ||
| + | |||
| + | <code lua> | ||
| + | "バーチャルキャストちゃん" | ||
| + | </code> | ||
| + | |||
| + | |||
| + | ===== GetId ===== | ||
| + | **GetId fun(): string** | ||
| + | |||
| + | VCI所有者のユーザーIDを取得します。\\ | ||
| + | スタジオ内のみで有効な値です。スタジオを抜けるとIDが変わります。 | ||
| + | |||
| + | === サンプル === | ||
| + | <file lua main.lua> | ||
| + | function onUse(use) | ||
| + | local owner = vci.studio.GetOwner() | ||
| + | print(owner.GetId()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | === 実行結果 === | ||
| + | <code lua> | ||
| + | ""79325077"" | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== IsOwner ===== | ||
| + | **IsOwner fun(): bool** | ||
| + | |||
| + | VCIの所有者かどうかを示す値を返します。 | ||
| + | |||
| + | === サンプル === | ||
| + | <file lua main.lua> | ||
| + | function onUse(use) | ||
| + | local owner = vci.studio.GetOwner() | ||
| + | print(owner.IsOwner()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | === 実行結果 === | ||
| + | <code lua> | ||
| + | true | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== GetLocalPosition / GetPosition ===== | ||
| + | **GetLocalPosition fun(): Vector3**\\ | ||
| + | **GetPosition fun(): Vector3** | ||
| + | |||
| + | それぞれVCI所有者の足元のローカル、ワールド座標を取得します。 | ||
| + | |||
| + | === サンプル === | ||
| + | <file lua main.lua> | ||
| + | function onUse(use) | ||
| + | local owner = vci.studio.GetOwner() | ||
| + | print(owner.GetLocalPosition()) | ||
| + | print(owner.GetPosition()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | === 実行結果 === | ||
| + | <code lua> | ||
| + | (1.8, 0.0 , 1.7) | ||
| + | (1.8, 0.0 , 1.7) | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== GetLocalRotation / GetRotation ===== | ||
| + | **GetLocalRotation fun(): Quaternion**\\ | ||
| + | **GetRotation fun(): Quaternion** | ||
| + | |||
| + | それぞれVCI所有者のローカル、ワールド回転を取得します。 | ||
| + | |||
| + | === サンプル === | ||
| + | <file lua main.lua> | ||
| + | function onUse(use) | ||
| + | local owner = vci.studio.GetOwner() | ||
| + | print(owner.GetLocalRotation()) | ||
| + | print(owner.GetRotation()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | === 実行結果 === | ||
| + | <code lua> | ||
| + | (0.0, 0.4, 0.0, 0.9) | ||
| + | (0.0, 0.4, 0.0, 0.9) | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== GetLocalScale ===== | ||
| + | **GetLocalScale fun(): Vector3** | ||
| + | |||
| + | VCI所有者の縮尺を取得します。 | ||
| + | |||
| + | === サンプル === | ||
| + | <file lua main.lua> | ||
| + | function onUse(use) | ||
| + | local owner = vci.studio.GetOwner() | ||
| + | print(owner.GetLocalScale()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | === 実行結果 === | ||
| + | <code lua> | ||
| + | (1.0, 1.0, 1.0) | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | ===== GetRight / GetUp / GetForward ===== | ||
| + | **GetRight fun(): Vector3**\\ | ||
| + | **GetUp fun(): Vector3**\\ | ||
| + | **GetForward fun(): Vector3** | ||
| + | |||
| + | GetRight()は右方向(+X)のベクトル、owner.GetUp()は上方向(+Y)ベクトル、owner.GetForward()は正面(+Z)ベクトルを取得します。\\ | ||
| + | サンプルはそれぞれVCI所有者のベクトルを取得しています。 | ||
| + | |||
| + | === サンプル === | ||
| + | <file lua main.lua> | ||
| + | function onUse(use) | ||
| + | local owner = vci.studio.GetOwner() | ||
| + | print(owner.GetRight()) | ||
| + | print(owner.GetUp()) | ||
| + | print(owner.GetForward()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | === 実行結果 === | ||
| + | <code lua> | ||
| + | (1.0, 0.0, -0.3) | ||
| + | (0.0, 1.0, 0.1) | ||
| + | (0.3, -0.1, 1.0) | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== GetLocalToWorldMatrix ===== | ||
| + | **GetLocalToWorldMatrix fun(): Matrix4x4** | ||
| + | |||
| + | 3つのベクトルと現在の座標を取得できる。 | ||
| + | |||
| + | === サンプル === | ||
| + | <file lua main.lua> | ||
| + | function onUse(use) | ||
| + | local owner = vci.studio.GetOwner() | ||
| + | print(owner.GetRight()) | ||
| + | print(owner.GetUp()) | ||
| + | print(owner.GetForward()) | ||
| + | print(owner.GetLocalPosition()) | ||
| + | print(owner.GetLocalToWorldMatrix()) | ||
| + | end | ||
| + | </file> | ||
| + | |||
| + | === 実行結果 === | ||
| + | <code lua> | ||
| + | (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 | ||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== GetBoneTransform ===== | ||
| + | |||
| + | GetBoneTransformは、UnityHumanoidAvaterの[[https://docs.unity3d.com/ja/2018.4/ScriptReference/HumanBodyBones.html|HumanBodyBones]]の変数名から、ボーン情報を得るための関数です。\\ | ||
| + | 無効なボーン名や、対応していないボーンを指定した場合は、nilが返ります。 | ||
| + | |||
| + | UnityHumanoidAvaterに関しては、[[unity:humanoid|こちら]]をご覧ください。 | ||
| + | |||
| + | === サンプル === | ||
| + | <file lua main.lua> | ||
| + | -- VCI所有者情報を取得する。 | ||
| local owner = vci.studio.GetOwner() | local owner = vci.studio.GetOwner() | ||
| ---- サブアイテムを取得する | ---- サブアイテムを取得する | ||
| - | local subItem = vci.assets.GetSubItem("SubItem1") | + | local subItem = vci.assets.GetTransform("SubItem1") |
| -- 右手の位置にサブアイテムを動かす。 | -- 右手の位置にサブアイテムを動かす。 | ||
| ライン 54: | ライン 335: | ||
| | position | Vector3 | ボーンのワールド座標 | | | position | Vector3 | ボーンのワールド座標 | | ||
| | rotation| Quaternion| ボーンのワールド回転 | | | rotation| Quaternion| ボーンのワールド回転 | | ||
| + | |||
| + | |||
| + | |||