Exemple #1
0
        protected bool FinishDisplayListEntry(ref DisplayListEntry de, ref DisplayListCamera dlc,
                                              ref LocalToWorld tx, ref PrivateTransformData ptd, bool doNotClip)
        {
            de.inSortingGroup = ptd.inSortingGroup;
#if UNITY_USE_TINYMATH
            de.finalMatrix = tinymath.mul(dlc.inverseWorld, tx.Value);
#else
            de.finalMatrix = math.mul(dlc.inverseWorld, tx.Value);
#endif
            if (doNotClip)
            {
                return(true);
            }
            // z-clip
            float z = de.finalMatrix[2][3];
            if (z < dlc.clipZNear || z > dlc.clipZFar)
            {
                return(false);
            }
            // bounds clip
#if DEBUG
            if (!(de.inBounds.width > 0.0f) || !(de.inBounds.height > 0.0f))
            {
                Debug.LogFormat("Entity {0} has zero or negative size ({1},{2})! This is checked in DEVELOPMENT builds only!", de.e, de.inBounds.width, de.inBounds.height);
                return(false);
            }
#endif
            return(true);
        }
Exemple #2
0
        static Entity ComputeWorldTransformAndSortingGroupRec(Entity e, int maxDepth, EntityManager mgr)
        {
            PrivateTransformData ptf = mgr.GetComponentData <PrivateTransformData>(e);

            if (ptf.flags == 0)
            {
                return(ptf.inSortingGroup);
            }

            Entity        ep  = mgr.GetComponentData <Parent>(e).Value;
            LocalToParent tol = mgr.GetComponentData <LocalToParent>(e);
            LocalToWorld  tow = mgr.GetComponentData <LocalToWorld>(e);

            if (ep == Entity.Null)
            {
                // local and global the same
                ptf.inSortingGroup = Entity.Null;
                tow.Value          = tol.Value;
            }
            else
            {
                Assert.IsTrue(mgr.Exists(ep), "An entity has a Parent parent set to an entity that was deleted. Did you mean to use TransformHelpers.DestroyTree?");
                Assert.IsTrue(mgr.HasComponent <Parent>(ep), "An entity has a Parent parent set to an entity that is not a Parent.");
                Assert.IsTrue(!mgr.HasComponent <Disabled>(ep), "An entity has a Parent parent that is disabled. The child must be disabled itself to avoid rendering it. Use TransformHelpers.DisableTree to disable a hierarchy.");
                if (maxDepth <= 0)
                {
                    tow.Value = float4x4.identity;
                    Assert.IsTrue(false, "Transform hierarchy is too deep or has a cycle. Run TransformHelpers.DebugCheckAllNodes to debug.");
                    return(Entity.Null);
                }
                // we have a parent!
                Entity   ptinsg = ComputeWorldTransformAndSortingGroupRec(ep, maxDepth - 1, mgr);
                float4x4 matp   = mgr.GetComponentData <LocalToWorld>(ep).Value;
#if UNITY_USE_TINYMATH
                tow.Value = tinymath.mul(matp, tol.Value);
#else
                tow.Value = math.mul(matp, tol.Value);
#endif
                if (mgr.HasComponent <SortingGroup>(ep))
                {
                    // parent is head of a group?
                    ptf.inSortingGroup = ep;
                }
                else
                {
                    // take whatever group parent is in
                    ptf.inSortingGroup = ptinsg;
                }
            }

            ptf.flags = 0;
            mgr.SetComponentData <LocalToWorld>(e, tow);
            mgr.SetComponentData <PrivateTransformData>(e, ptf);
            return(ptf.inSortingGroup);
        }