====== アイテムを使ったときに柄が変わるポスター ====== > このデータは「**バーチャルキャスト1.5.1a以降**」で動作します。 [[https://developer.virtualcast.jp/vci-docs/api/classes/ExportMaterial/SetTextureOffset.html|SetTextureOffset]] を利用したマテリアル操作のサンプルVCIです。 === サンプルデータ === https://virtualcast.jp/products/92a21f83e35159f9faedf0436043e6c7a3dbb75e0b1d5fef5408568578bffc01 {{ :vci:sample:material:切替ポスター.zip |}} ===== 解説 ===== アイテムを使ったときに絵柄が切り替わります。 {{vci:sample:material:board.png?400|}} 使用しているテクスチャは以下のように3x3の画像をタイリングしたものを\\ 「**vci.assets.material._ALL_SetTextureOffsetFromIndex**」でUVのOffset移動を行っています。 Material名を指定する「**vci.assets.material._ALL_SetTextureOffset**」でも変更可能です。\\ 本サンプルでは「board_5tai7」というMaterial名で指定できます。 {{vci:sample:material:board_5tai7.png?400|}} 看板が表示される面のUVは3x3の1マス分を指定しています。\\ (UVの設定はblender、Mayaなどの3Dツールをご使用ください) {{vci:sample:material:uv_sample.png?400|}} ===== VCIスクリプト ===== local assets = vci.assets local count = 0 if vci.state.Get("COUNT") then count = vci.state.Get("COUNT") end local TOTAL = 6 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 assets.material._ALL_SetTextureOffsetFromIndex(0, offset) end SetTextureOffset(count) function onUse(use) if count >= TOTAL-1 then count = 0 else count = count + 1 end vci.state.Set("COUNT", count) SetTextureOffset(count) end