ConstraintDemo

Overview

Demo for constraining nodes, such as emitters or lights, to the bones of a skeletal model.

How to Use

Description

To constrain a node to the bone of a skeletal model, you must set the world matrix for the bone as the world matrix of the node to be constrained. This can be done after scene update or by executing a callback.

Implementation after scene update

After it updates the world matrix of the nodes and/or skeletons in the scene, SceneUpdater gets the world matrix from the bone to be constrained. Overwriting the world matrix of the node to be constrained with this one allows constraints on the bone.

Because the world matrix of the bone to be constrained is overwritten, code can be optimized by skipping world matrix calculations. World matrix calculations can be skipped by disabling FLAG_IS_WORLDMATRIX_CALCULATION_ENABLED using DisableFlags of the Transform member.

In this demo, constraints are applied in this way by two functions, SetupConstraint and ConstraintLight.

Implementation using a callback

Node constraints can be set even by setting a callback process for overwriting the world matrix in PostCalculateMatrixSignal of the skeleton. A pointer to the skeleton and bone index are passed to the callback function. Target bones are determined based on this information and the world matrix is overwritten as described in the previous section if the bone is a target bone.

However, unlike the method described in the previous section, nodes may not be constrained correctly if the FLAG_IS_WORLDMATRIX_CALCULATION_ENABLED flag is not set appropriately. If the FLAG_IS_WORLDMATRIX_CALCULATION_ENABLED flag is left enabled and the node's world matrix is updated after the skeleton is updated, the world matrix written by the callback will be overwritten.

In this demo, the function SetupCallbackConstraint sets the callback.

Furthermore, you can use SetResourceBasedTransform rather than overwriting the world matrix. This allows you to bind nodes while enabling transforms included in resources.


CONFIDENTIAL