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); } }
protected override bool Initialize() { if (m_frictionModel != null) { return(true); } m_frictionModel = CreateNative(Type, SolveType); return(true); }
/// <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); }
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); }
/// <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); }
/// <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); }
/// <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); }
public override void Destroy() { m_frictionModel = null; }