Exemple #1
0
        public FrictionModel RestoreLocalDataFrom(agx.FrictionModel native)
        {
            SolveType = Convert(native.getSolveType());
            Type      = FindType(native);

            return(this);
        }
 /// <summary>
 /// Callback from AgXUnity.FrictionModel when the friction model type has been changed.
 /// </summary>
 /// <param name="frictionModel"></param>
 private void OnFrictionModelNativeInstanceChanged(agx.FrictionModel frictionModel)
 {
     if (Native != null)
     {
         Native.setFrictionModel(frictionModel);
     }
 }
Exemple #3
0
        protected override bool Initialize()
        {
            if (m_frictionModel != null)
            {
                return(true);
            }

            m_frictionModel = CreateNative(Type, SolveType);

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Finds friction model type given native instance.
        /// </summary>
        /// <param name="native">Native friction model.</param>
        /// <returns>Native friction model type.</returns>
        public static EType FindType(agx.FrictionModel native)
        {
            if (native == null || native.asIterativeProjectedConeFriction() != null)
            {
                return(EType.IterativeProjectedFriction);
            }
            else if (native.asBoxFrictionModel() != null)
            {
                return(EType.BoxFriction);
            }

            return(EType.ScaleBoxFriction);
        }
Exemple #5
0
        public FrictionModel RestoreLocalDataFrom(agx.FrictionModel native)
        {
            SolveType = Convert(native.getSolveType());
            Type      = FindType(native);

            // TODO: How do we handle oriented when restoring from file?
            if (Type == EType.ConstantNormalForceBoxFriction)
            {
                NormalForceMagnitude      = System.Convert.ToSingle(native.asConstantNormalForceOrientedBoxFrictionModel().getNormalForceMagnitude());
                ScaleNormalForceWithDepth = native.asConstantNormalForceOrientedBoxFrictionModel().getEnableScaleWithDepth();
            }

            return(this);
        }
Exemple #6
0
        /// <summary>
        /// Create native friction model given solve type and friction model type.
        /// </summary>
        /// <param name="type">Friction model type.</param>
        /// <param name="solveType">Solve type.</param>
        /// <returns>New native instance.</returns>
        public agx.FrictionModel CreateNative(EType type,
                                              ESolveType solveType)
        {
            agx.Frame referenceFrame = null;
            if (m_orientedFrictionReferenceObject != null)
            {
                referenceFrame = m_orientedFrictionReferenceObject.GetComponent <RigidBody>() != null?
                                 m_orientedFrictionReferenceObject.GetComponent <RigidBody>().Native.getFrame() :
                                     m_orientedFrictionReferenceObject.GetComponent <Collide.Shape>() != null?
                                     m_orientedFrictionReferenceObject.GetComponent <Collide.Shape>().NativeGeometry.getFrame() :
                                         null;
            }

            agx.FrictionModel frictionModel = null;
            if (type == EType.IterativeProjectedFriction)
            {
                frictionModel = referenceFrame != null ?
                                new agx.OrientedIterativeProjectedConeFrictionModel(referenceFrame,
                                                                                    Convert(m_orientedFrictionPrimaryDirection).ToHandedVec3(),
                                                                                    Convert(solveType)) :
                                new agx.IterativeProjectedConeFriction(Convert(solveType));
            }
            else if (type == EType.ScaleBoxFriction)
            {
                frictionModel = referenceFrame != null ?
                                new agx.OrientedScaleBoxFrictionModel(referenceFrame,
                                                                      Convert(m_orientedFrictionPrimaryDirection).ToHandedVec3(),
                                                                      Convert(solveType)) :
                                new agx.ScaleBoxFrictionModel(Convert(solveType));
            }
            else if (type == EType.BoxFriction)
            {
                frictionModel = referenceFrame != null ?
                                new agx.OrientedBoxFrictionModel(referenceFrame,
                                                                 Convert(m_orientedFrictionPrimaryDirection).ToHandedVec3(),
                                                                 Convert(solveType)) :
                                new agx.BoxFrictionModel(Convert(solveType));
            }
            else if (type == EType.ConstantNormalForceBoxFriction)
            {
                frictionModel = new agx.ConstantNormalForceOrientedBoxFrictionModel(NormalForceMagnitude,
                                                                                    referenceFrame,
                                                                                    Convert(m_orientedFrictionPrimaryDirection).ToHandedVec3(),
                                                                                    Convert(solveType),
                                                                                    ScaleNormalForceWithDepth);
            }

            return(frictionModel);
        }
Exemple #7
0
        /// <summary>
        /// Create native friction model given solve type and friction model type.
        /// </summary>
        /// <param name="type">Friction model type.</param>
        /// <param name="solveType">Solve type.</param>
        /// <returns>New native instance.</returns>
        public static agx.FrictionModel CreateNative(EType type, ESolveType solveType)
        {
            agx.FrictionModel frictionModel = null;
            if (type == EType.IterativeProjectedFriction)
            {
                frictionModel = new agx.IterativeProjectedConeFriction(Convert(solveType));
            }
            else if (type == EType.ScaleBoxFriction)
            {
                frictionModel = new agx.ScaleBoxFrictionModel(Convert(solveType));
            }
            else if (type == EType.BoxFriction)
            {
                frictionModel = new agx.BoxFrictionModel(Convert(solveType));
            }

            return(frictionModel);
        }
Exemple #8
0
        /// <summary>
        /// Finds friction model type given native instance.
        /// </summary>
        /// <param name="native">Native friction model.</param>
        /// <returns>Native friction model type.</returns>
        public static EType FindType(agx.FrictionModel native)
        {
            if (native == null || native.asIterativeProjectedConeFriction() != null)
            {
                return(EType.IterativeProjectedFriction);
            }
            else if (native.asScaleBoxFrictionModel() != null)
            {
                return(EType.ScaleBoxFriction);
            }
            else if (native.asConstantNormalForceOrientedBoxFrictionModel() != null)
            {
                return(EType.ConstantNormalForceBoxFriction);
            }
            else if (native.asBoxFrictionModel() != null)
            {
                return(EType.BoxFriction);
            }

            Debug.LogWarning("Unknown native friction model type - returning default.");

            return(EType.IterativeProjectedFriction);
        }
Exemple #9
0
 public override void Destroy()
 {
     m_frictionModel = null;
 }