Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit8d45df8664

README.md

ecs.MorphWeights

Spec for the MorphWeights component, which maps to the native MorphWeights. How strongly an entity blends each morph target its mesh carries: weight i scales target i's per-vertex deltas, and the surface drawn is the mesh's base shape plus the sum of them.

Weights are ordered as the mesh's targets are, one per target the mesh carries. 0 leaves a target out, 1 applies it whole, and values between (or past) either end blend it proportionally. Driving a weight over time deforms the surface, and the motion it makes is reported like any other movement.

Fields

  • weights — one blend weight per morph target, in target order.
ecs.insertSync(id, ecs.MorphWeights { weights = { 1.0, 0.25 } })
ecs.set(id, ecs.MorphWeights { weights = { 0.5, 0.5 } })

Driving a shape by name

A mesh's targets carry the names they were authored under — for an imported model, the ones its source file gave its blend shapes. Read them in target order with renderer.mesh.morphTargets(mesh), and build this array from weights named by shape with renderer.mesh.morphWeights(mesh, byName):

local mesh = entity(id).component.SkinnedModel.model
for i, name in renderer.mesh.morphTargets(mesh) do print(i, name) end

ecs.set(id, ecs.MorphWeights {
    weights = renderer.mesh.morphWeights(mesh, { Eyes_Blink = 1, ["Visemes_Body.AA"] = 0.6 }),
})

Shapes left out of byName sit at 0, and a name the mesh does not carry errors listing the ones it does.