Custom attributes

Intermediate

You can import custom attributes created in modeling tools such as Maya.

Currently, you can only import custom animated attributes. Attributes that aren't animated can't be imported.

Maya properties

1. Import custom attributes

  • Import the animation. For instructions, see Import animations.

  • In the Asset View, select the animation asset.

Assets in Asset View

  • In the Property Grid, select Import custom attributes.

Custom attributes

When the assets are built, Xenko imports the custom attributes from the FBX file.

2. Control custom attributes with a script

Add a script to read the custom attributes and copy their value to another property. This can be a separate script, or part of another animation script.

To look up an attribute, use NodeName_AttributeName. For example, if you have the node myNode with the custom attribute myAttribute, use myNode_myAttribute.

Example script

```csusing Xenko.Animations;using Xenko.Engine;using Xenko.Rendering;using Xenko.Audio;using Xenko.Rendering.Materials;

namespace Sample{ public class HologramScript : SyncScript { public Material MyMaterial;

  1. private AnimationComponent animationComponent;
  2. private AnimationProcessor animationProcessor;
  3. public override void Start()
  4. {
  5. base.Start();
  6. animationComponent = Entity.GetOrCreate<AnimationComponent>();
  7. animationProcessor =

SceneSystem.SceneInstance.Processors.OfType().FirstOrDefault(); }

  1. public override void Update()
  2. {
  3. if (animationProcessor == null || MyMaterial == null)
  4. return;

// Animation result may be Null if animation hasn't been played yet. var animResult = animationProcessor.GetAnimationClipResult(animationComponent); if (animResult == null) return;

// Read the value of the animated custom attribute: float emmisiveIntensity; unsafe { fixed (byte* structures = animResult.Data) { foreach (var channel in animResult.Channels) { if (!channel.IsUserCustomProperty) continue;

  1. var structureData = (float*)(structures + channel.Offset);
  2. var factor = *structureData++;
  3. if (factor == 0.0f)
  4. continue;
  5. var value = *structureData;
  6. if (channel.PropertyName ==

"myNode_myProperty") emmisiveIntensity = value; } } }

// Bind the material parameter:

MyMaterial.Passes[0].Parameters.Set(MaterialKeys.EmissiveIntensity, emmisiveIntensity) } } }