// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "Collider.h" #include "Engine/Content/AssetReference.h" #include "Engine/Physics/CollisionData.h" class Spline; /// /// A collider represented by an arbitrary mesh that goes over the spline. /// /// /// API_CLASS() class FLAXENGINE_API SplineCollider : public Collider { DECLARE_SCENE_OBJECT(SplineCollider); private: Spline* _spline = nullptr; void* _triangleMesh = nullptr; Array _vertexBuffer; Array _indexBuffer; Transform _preTransform = Transform::Identity; public: /// /// Linked collision data asset that contains convex mesh or triangle mesh used to represent a spline collider shape. /// API_FIELD(Attributes="EditorOrder(100), DefaultValue(null), EditorDisplay(\"Collider\")") AssetReference CollisionData; /// /// Gets the transformation applied to the collision data model geometry before placing it over the spline. Can be used to change the way model goes over the spline. /// API_PROPERTY(Attributes="EditorOrder(101), EditorDisplay(\"Collider\")") Transform GetPreTransform() const; /// /// Sets the transformation applied to the collision data model geometry before placing it over the spline. Can be used to change the way model goes over the spline. /// API_PROPERTY() void SetPreTransform(const Transform& value); /// /// Extracts the collision data geometry into list of triangles. /// /// The output vertex buffer. /// The output index buffer. void ExtractGeometry(Array& vertexBuffer, Array& indexBuffer) const; private: void OnCollisionDataChanged(); void OnCollisionDataLoaded(); void OnSplineUpdated(); public: // [Collider] bool CanAttach(RigidBody* rigidBody) const override; bool CanBeTrigger() const override; #if USE_EDITOR void OnDebugDrawSelected() override; #endif bool IntersectsItself(const Ray& ray, Real& distance, Vector3& normal) override; void Serialize(SerializeStream& stream, const void* otherObj) override; void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override; void OnParentChanged() override; void EndPlay() override; protected: // [Collider] #if USE_EDITOR void DrawPhysicsDebug(RenderView& view) override; #endif void UpdateBounds() override; void GetGeometry(CollisionShape& collision) override; };