コード例 #1
0
ファイル: TwoBodyTire.cs プロジェクト: cyhunter/AGXUnity
        protected override bool Initialize()
        {
            if (!agx.Runtime.instance().isModuleEnabled("AgX-Tires"))
            {
                Debug.LogError("TwoBodyTire requires a valid license for the AGX Dynamics module: AgX-Tires", this);
                return(false);
            }

            if (TireRigidBody == null || RimRigidBody == null)
            {
                Debug.LogError("TwoBodyTire failed to initialize: Tire or Rim rigid body is null.", this);
                return(false);
            }

            var nativeTireRigidBody = TireRigidBody.GetInitialized <RigidBody>()?.Native;
            var nativeRimRigidBody  = RimRigidBody.GetInitialized <RigidBody>()?.Native;

            if (nativeTireRigidBody == null || nativeRimRigidBody == null)
            {
                Debug.LogError("TwoBodyTire failed to initialize: Tire or Rim rigid body failed to initialize.", this);
                return(false);
            }

            Native = new agxModel.TwoBodyTire(nativeTireRigidBody,
                                              TireRadius,
                                              nativeRimRigidBody,
                                              RimRadius,
                                              FindNativeTransform(TireRigidBody));
            GetSimulation().add(Native);

            if (TireRimConstraint != null)
            {
                // Disable the tire rim constraint since agx.TwoBodyTire will
                // create an additional constraint between the tire and the rim
                // with tire properties applied.
                if (TireRimConstraint.GetInitialized <Constraint>().IsEnabled)
                {
                    m_tireRimConstraintInitialState = TireRimConstraint.enabled;
                    TireRimConstraint.enabled       = false;
                }

                // The "hinge" is replacing the TireRimConstraint, take the
                // solve type from disabled rim constraint.
                Native.getHinge().setSolveType(Constraint.Convert(TireRimConstraint.SolveType));
            }

            if (Properties != null)
            {
                Properties.Register(this);
            }

            return(true);
        }
コード例 #2
0
        protected override bool Initialize()
        {
            if (!agx.Runtime.instance().isModuleEnabled("AgX-Tires"))
            {
                Debug.LogError("TwoBodyTire requires a valid license for the AGX Dynamics module: AgX-Tires", this);
                return(false);
            }

            if (TireRigidBody == null || RimRigidBody == null)
            {
                Debug.LogError("TwoBodyTire failed to initialize: Tire or Rim rigid body is null.", this);
                return(false);
            }

            var nativeTireRigidBody = TireRigidBody.GetInitialized <RigidBody>()?.Native;
            var nativeRimRigidBody  = RimRigidBody.GetInitialized <RigidBody>()?.Native;

            if (nativeTireRigidBody == null || nativeRimRigidBody == null)
            {
                Debug.LogError("TwoBodyTire failed to initialize: Tire or Rim rigid body failed to initialize.", this);
                return(false);
            }

            Native = new agxModel.TwoBodyTire(nativeTireRigidBody,
                                              TireRadius,
                                              nativeRimRigidBody,
                                              RimRadius,
                                              FindNativeTransform(TireRigidBody));
            GetSimulation().add(Native);

            if (TireRimConstraint != null && TireRimConstraint.GetInitialized <Constraint>().IsEnabled)
            {
                m_tireRimConstraintInitialState = TireRimConstraint.enabled;
                TireRimConstraint.enabled       = false;
            }

            if (Properties != null)
            {
                Properties.Register(this);
            }

            return(true);
        }