private const uint CCD_STAY_DEAD_FRAMES      = 320; //5 seconds

        /// <summary>
        /// Tests for a violation of limits that can be checked before an actor has been built
        /// </summary>
        /// <param name="newPrimaryShape"></param>
        /// <param name="newChildShapes"></param>
        /// <returns></returns>
        internal bool DynamicsPrecheck(PhysicsShape newPrimaryShape, Dictionary <PhysxPrim, RelatedShapes> newChildShapes)
        {
            int totalComplexity = newPrimaryShape.Complexity;

            if (newChildShapes != null)
            {
                foreach (var shape in newChildShapes)
                {
                    totalComplexity += shape.Value.ChildShape.Complexity;
                }
            }

            //check to make sure it is ok to make this physical
            if (totalComplexity > PhysxPrim.MAX_DYNAMIC_COMPLEXITY)
            {
                //too complex, back out
                newPrimaryShape.DecRef();

                if (newChildShapes != null)
                {
                    foreach (var shape in newChildShapes)
                    {
                        shape.Value.ChildShape.DecRef();
                    }
                }

                this.TriggerComplexityError(String.Format("({0} of {1} convex hulls)", totalComplexity, PhysxPrim.MAX_DYNAMIC_COMPLEXITY));
                return(false);
            }

            return(true);
        }
示例#2
0
        private const uint CCD_STAY_DEAD_FRAMES = 320; //5 seconds

        /// <summary>
        /// Tests for a violation of limits that can be checked before an actor has been built
        /// </summary>
        /// <param name="newPrimaryShape"></param>
        /// <param name="newChildShapes"></param>
        /// <returns></returns>
        internal bool DynamicsPrecheck(PhysicsShape newPrimaryShape, Dictionary<PhysxPrim, RelatedShapes> newChildShapes)
        {
            int totalComplexity = newPrimaryShape.Complexity;

            if (newChildShapes != null)
            {
                foreach (var shape in newChildShapes)
                {
                    totalComplexity += shape.Value.ChildShape.Complexity;
                }
            }

            //check to make sure it is ok to make this physical
            if (totalComplexity > PhysxPrim.MAX_DYNAMIC_COMPLEXITY)
            {
                //too complex, back out
                newPrimaryShape.DecRef();

                if (newChildShapes != null)
                {
                    foreach (var shape in newChildShapes)
                    {
                        shape.Value.ChildShape.DecRef();
                    }
                }

                this.TriggerComplexityError(String.Format("({0} of {1} convex hulls)", totalComplexity, PhysxPrim.MAX_DYNAMIC_COMPLEXITY));
                return false;
            }

            return true;
        }
示例#3
0
        private void CombineChildShape(PhysicsShape childShape, PhysxPrim newChild, OpenMetaverse.Vector3 localPos, OpenMetaverse.Quaternion localRot, 
            bool delayInertiaRecalc)
        {
            //calculate the local rotation for the new shape we'll add to replace the combined child
            PhysX.Math.Matrix localPose = PhysUtil.PositionToMatrix(localPos, localRot);

            if (!_isPhysical || this.CheckComplexityLimitsWithNewChild(childShape))
            {
                try
                {
                    List<PhysX.Shape> actorShapes = childShape.AssignToActor(_actor, newChild.PhysxProperties.PhysxMaterial.PhyMaterial, localPose, _isPhysical);

                    _childShapes.Add(newChild, new RelatedShapes { ChildShape = childShape, PhyShapes = actorShapes });
                    foreach (PhysX.Shape shape in actorShapes)
                    {
                        _shapeToPrimIndex.Add(shape, newChild);
                    }

                    CollisionGroup.SetCollisionGroup(_collisionGroup, actorShapes);

                    if (!delayInertiaRecalc) UpdateMassAndInertia();

                    if (newChild.Properties.WantsCollisionNotification)
                    {
                        this.EnableChildCollisionEventsSync(newChild, true);
                    }

                    newChild._isPhysical = _isPhysical;
                }
                catch (NullReferenceException e) //this catch is in place to try and find an obscure bug where a cast inside the C++/CLI side of the physx sdk throws
                {
                    m_log.ErrorFormat("[InWorldz.PhysX] Unable to assign child shapes to a physactor: {0}, Material: {1}, Pose: {2}", e, newChild.PhysxProperties.PhysxMaterial.PhyMaterial, localPose);
                    _childShapes.Add(newChild, new RelatedShapes { ChildShape = childShape, PhyShapes = new List<PhysX.Shape>(0) });
                    childShape.DecRef();
                }
            }
            else
            {
                //too complex, free the child shape and issue a warning to the owner
                _childShapes.Add(newChild, new RelatedShapes { ChildShape = childShape, PhyShapes = new List<PhysX.Shape>(0) });

                childShape.DecRef();
            }
        }