en:vci:sample:material:uvanimation

Flip book animation

This example is an advanced application of the “Switching signage” example.
A poster that changes texture when used

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: 2023/10/02 20:52 by pastatto

Page Tools