User specified (or calculated) world rotation 1. If a TransformParent exists and no LocalRotation exists, the value will be used as the object to world translation irrespective of the parent object to world matrix. 2. If a TransformParent exists and a LocalRotation exists, the calculated world rotation will be stored in this value by the TransformSystem. 3. If a TrasformMatrix exists, the value will be stored as the rotation part of the matrix.
Example #1
0
 public void Execute([ReadOnly] ref Unity.Transforms.Position pos,
                     [ReadOnly] ref Unity.Transforms.Rotation rot,
                     ref SphereCollider sphere_collider)
 {
     sphere_collider.position_ = math.mul(rot.Value, sphere_collider.offset_position_) + pos.Value;
     sphere_collider.updated_  = 1; // true
 }
Example #2
0
            public void Execute(int index)
            {
                Entity colliderEntity = ColliderEntity[index];

                Unity.Transforms.Position cp = PositionFromEntity[colliderEntity];
                cp.Value = PositionFromEntity[Collider[index].RigidBodyEntity].Value;
                PositionFromEntity[colliderEntity] = cp;

                Unity.Transforms.Rotation cr = RotationFromEntity[colliderEntity];
                cr.Value = RotationFromEntity[Collider[index].RigidBodyEntity].Value;
                RotationFromEntity[colliderEntity] = cr;
            }
Example #3
0
            public void Execute(int index)
            {
                Entity transformEntity         = Entities[index];
                Entity followedRigidBodyEntity = FollowRigidbody[index].RigidBodyEntity;

                Unity.Transforms.Position p = PositionFromEntity[transformEntity];
                p.Value = PositionFromEntity[followedRigidBodyEntity].Value;
                PositionFromEntity[transformEntity] = p;

                Unity.Transforms.Rotation r = RotationFromEntity[transformEntity];
                r.Value = RotationFromEntity[followedRigidBodyEntity].Value;
                RotationFromEntity[transformEntity] = r;
            }
            public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
            {
                if (batchInChunk.Has(RotationEulerXyzTypeHandle))
                {
                    if (!batchInChunk.DidChange(RotationEulerXyzTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = batchInChunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerXYZs = batchInChunk.GetNativeArray(RotationEulerXyzTypeHandle);
                    for (var i = 0; i < batchInChunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerXYZ(chunkRotationEulerXYZs[i].Value)
                        };
                    }
                }
                else if (batchInChunk.Has(RotationEulerXzyTypeHandle))
                {
                    if (!batchInChunk.DidChange(RotationEulerXzyTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = batchInChunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerXZYs = batchInChunk.GetNativeArray(RotationEulerXzyTypeHandle);
                    for (var i = 0; i < batchInChunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerXZY(chunkRotationEulerXZYs[i].Value)
                        };
                    }
                }
                else if (batchInChunk.Has(RotationEulerYxzTypeHandle))
                {
                    if (!batchInChunk.DidChange(RotationEulerYxzTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = batchInChunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerYXZs = batchInChunk.GetNativeArray(RotationEulerYxzTypeHandle);
                    for (var i = 0; i < batchInChunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerYXZ(chunkRotationEulerYXZs[i].Value)
                        };
                    }
                }
                else if (batchInChunk.Has(RotationEulerYzxTypeHandle))
                {
                    if (!batchInChunk.DidChange(RotationEulerYzxTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = batchInChunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerYZXs = batchInChunk.GetNativeArray(RotationEulerYzxTypeHandle);
                    for (var i = 0; i < batchInChunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerYZX(chunkRotationEulerYZXs[i].Value)
                        };
                    }
                }
                else if (batchInChunk.Has(RotationEulerZxyTypeHandle))
                {
                    if (!batchInChunk.DidChange(RotationEulerZxyTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = batchInChunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerZXYs = batchInChunk.GetNativeArray(RotationEulerZxyTypeHandle);
                    for (var i = 0; i < batchInChunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerZXY(chunkRotationEulerZXYs[i].Value)
                        };
                    }
                }
                else if (batchInChunk.Has(RotationEulerZyxTypeHandle))
                {
                    if (!batchInChunk.DidChange(RotationEulerZyxTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = batchInChunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerZYXs = batchInChunk.GetNativeArray(RotationEulerZyxTypeHandle);
                    for (var i = 0; i < batchInChunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerZYX(chunkRotationEulerZYXs[i].Value)
                        };
                    }
                }
            }
Example #5
0
            public void Execute(int index, TransformAccess transform)
            {
                if (!ChangedIndices.TryGetValue(index, out var selfChanged))
                {
                    return;
                }
                int  id      = Hierarchy.GetInstanceIdForIndex(index);
                var  iter    = ConvertedEntities.GetEntities(id);
                bool isFirst = true;

                while (iter.MoveNext())
                {
                    var e = iter.Current;
                    if (!LocalToWorld.HasComponent(e))
                    {
                        continue;
                    }

                    // check whether this is a primary entity or needs to have its transform copied from the primary
                    if (!isFirst && !CopyTransformFromRoot.HasComponent(e))
                    {
                        continue;
                    }
                    isFirst = false;

                    LocalToWorld[e] = new LocalToWorld {
                        Value = transform.localToWorldMatrix
                    };
                    if (selfChanged)
                    {
                        if (!Translation.HasComponent(e))
                        {
                            // static entity
                            continue;
                        }

                        Translation[e] = new Translation {
                            Value = transform.localPosition
                        };
                        if (Rotation.HasComponent(e))
                        {
                            Rotation[e] = new Rotation {
                                Value = transform.localRotation
                            }
                        }
                        ;

                        float3 scale;
                        if (Parent.HasComponent(e))
                        {
                            scale = CalculateLossyScale(transform.localToWorldMatrix, transform.rotation);
                        }
                        else
                        {
                            scale = transform.localScale;
                        }

                        if (math.any(scale != new float3(1)))
                        {
                            var scaleComponent = new NonUniformScale {
                                Value = transform.localScale
                            };
                            if (NonUniformScale.HasComponent(e))
                            {
                                NonUniformScale[e] = scaleComponent;
                            }
                            else
                            {
                                Ecb.AddComponent(index, e, scaleComponent);
                            }
                        }
                        else
                        {
                            if (NonUniformScale.HasComponent(e))
                            {
                                Ecb.RemoveComponent <NonUniformScale>(index, e);
                            }
                        }
                    }
                }
            }