#Working with PostTransformScale

1 messages · Page 1 of 1 (latest)

violet sleet
#

Hi, previously you could have a non uniform scale, but as of Entities 1.0.0 that is no longer possible, we are being told to use PostTransformScale instead. The way I understand is that whenever an entity has this component, it'll automatically be applied to its transform and be scaled.

I am currently working with a prefab which is supposed to scale based on a value of a component that it has.

I seem to have a couple of issues:

  1. My custom baker does not seem to add the PostTransformScale
  2. When editing the prefab such that it has a non uniform scale to begin with, it is properly added and edited - It is however not reflected visually although when inspecting the entity its PostTransformScale is being updated.

Baker class:

    public class FoodSourceConverterBaker : Baker<FoodSourceConverter>
    {
        public override void Bake(FoodSourceConverter authoring)
        {
            var foodSource = new FoodSourceComponent
            {
                EnergyLevel = authoring.InitialEnergyLevel,
                RegenarationRate = authoring.RegenerationRate,
                MaxEnergyLevel = authoring.MaxEnergyLevel
            };

            AddComponent(foodSource);
            AddComponent(new PostTransformScale { Value = float3x3.Scale(new float3(1, 1, 1)) });
            AddComponent(new PropagateLocalToWorld());
        }
    }

Part of the systems OnUpdate() method:

            // Let scale reflect energy level
            Entities.WithAll<FoodSourceComponent, PostTransformScale>().ForEach((ref PostTransformScale scale, in FoodSourceComponent foodSource) =>
            {
                scale.Value = float3x3.Scale(new float3(1, foodSource.EffectiveSize, 1));
            }).ScheduleParallel();

I am probably missing something stupid, but any help is appreciated!

#

https://docs.unity3d.com/Packages/com.unity.entities@1.0/manual/transforms-concepts.html

Says that the local to world can also be computed using:
LocalToWorld = WorldTransform.ToMatrix() * PostTransformScale

But WorldTransform.ToMatrix() returns a float4x4 where as PostTransformScale is a float3x3 I am not the best at matrix multiplication but I am pretty sure that that is not possible ablobtonguewink

Directly multiplying is not supported either.

Figured out that a float4x4 can be created using float4x4(PostTransformScale.Value, float3.zero) which gives me the same results when inspecting, but it still doesnt visually show up and baking issue still persistent