This translation is older than the original page and might be outdated. See what has changed.
Translations of this page:

Sidebar

en:vci:sample:material:uvanimation

Flip book animation

Example data:
https://seed.online/items/4cbaeb00d4adbb4ca26947a4a874e565929e0bdd20b8af4aab5f699c68c73bc6

This example is an advanced application of the “Switching signage” example.
https://virtualcast.jp/wiki/doku.php?id=%E3%83%A2%E3%83%87%E3%83%AB%E4%BD%9C%E6%88%90:vci%E4%BD%9C%E6%88%90:%E5%88%87%E6%9B%BF%E3%83%9D%E3%82%B9%E3%82%BF%E3%83%BC

It automatically shifts the tiled texture to create a flip-book like animation
The UV assigned to the model is a single cell of the 4-by-4 matrix texture.
(To set the UV, use 3D modeling software like blender and Maya)

As shown in the image below, prepare a 4-by-4 texture and use
vci.assets._ALL_SetMaterialTextureOffsetFromIndex to shift the UV offset.

The same change can be done using vci.assets._ALL_SetMaterialTextureOffsetFromName which specifies a Material by its name.
The material in the example can be specified by the name “v”.

The number is counted up from left to right and top to bottom

main.lua
local assets = vci.assets
local count = 0
 
local timecount=0
 
--Synchronization management using a sync variable
if vci.state.Get("COUNT") then
    count = vci.state.Get("COUNT")
end
 
 
--The total number of switchable textures... This time its 4x4
local TOTAL = 16
 
-- The number of separation in vertical and horizontal directions: 4 
function SetTextureOffset( count )
    local offset = Vector2.zero
 
    -- y shift
    local Yshift = math.floor(count / 4)
    offset.y = -(1/4) * Yshift
 
    -- x shift
    local Xshift = count % 4
    offset.x = (1/4) * Xshift
 
    assets._ALL_SetMaterialTextureOffsetFromIndex(0, offset)
end
 
SetTextureOffset(count)
 
--use the update as the updateAll result in duplicate processing between users
function update()
    timecount=timecount+1
    --Flip the image in how many frames
    if timecount>3 then
        anim()
        timecount=0
    end
end
 
--Proprietary function
function anim()
    if count >= TOTAL then
        count = 0
    else
        count = count + 1
    end
    vci.state.Set("COUNT", count)
    SetTextureOffset(count)
end
en/vci/sample/material/uvanimation.txt · Last modified: 2021/11/18 18:22 by numa

Page Tools