// Copyright (c) Wojciech Figat. All rights reserved. #pragma once #include "Engine/Level/Actor.h" #include "Engine/Scripting/ScriptingObjectReference.h" class Spline; /// /// Physical simulation actor for ropes, chains and cables represented by a spline. /// /// API_CLASS() class FLAXENGINE_API SplineRopeBody : public Actor { API_AUTO_SERIALIZATION(); DECLARE_SCENE_OBJECT(SplineRopeBody); private: struct Mass { Vector3 Position; Real SegmentLength; Vector3 PrevPosition; bool Unconstrained; }; Spline* _spline = nullptr; Transform _splineTransform; float _time = 0.0f; Array _masses; public: /// /// The target actor to attach the rope end to. If unset the rope end will run freely. /// API_FIELD(Attributes="EditorOrder(0), DefaultValue(null), EditorDisplay(\"Rope\")") ScriptingObjectReference AttachEnd; /// /// The world gravity scale. Can be used to adjust gravity force or disable it. /// API_FIELD(Attributes="EditorOrder(10), EditorDisplay(\"Rope\")") float GravityScale = 1.0f; /// /// The scale of velocity applied to rope. The greater the value, the more suppressed the movement. Lower values increase movement freedom. /// API_FIELD(Attributes="EditorOrder(15), EditorDisplay(\"Rope\"), Limit(0, 0.99f, 0.001f)") float Drag = 0.1f; /// /// The maximum bones stretch scale. The value of 0 means no stretch, 1 - can stretch up to double length. /// API_FIELD(Attributes = "EditorOrder(19), EditorDisplay(\"Rope\"), Limit(0)") float StretchLimit = 0.0f; /// /// The additional, external force applied to rope (world-space). This can be eg. wind force. /// API_FIELD(Attributes="EditorOrder(20), EditorDisplay(\"Rope\")") Vector3 AdditionalForce = Vector3::Zero; /// /// If checked, the physics solver will use stiffness constraint for rope. It will be less likely to bend over and will preserve more it's shape. /// API_FIELD(Attributes="EditorOrder(30), EditorDisplay(\"Rope\")") bool EnableStiffness = false; /// /// The rope simulation update substep (in seconds). Defines the frequency of physics update. /// API_FIELD(Attributes="EditorOrder(40), Limit(0, 0.1f, 0.0001f), EditorDisplay(\"Rope\")") float SubstepTime = 0.02f; private: void Tick(); public: // [Actor] void OnEnable() override; void OnDisable() override; void OnTransformChanged() override; void OnParentChanged() override; };