#pragma once #include #include #include #include "datatypes/cframe.h" #include "datatypes/color3.h" #include "datatypes/vector.h" #include "objects/base/instance.h" #include "rendering/surface.h" #include #include #include #include "annotation.h" namespace rp = reactphysics3d; // For easy construction from C++. Maybe should be removed? struct PartConstructParams { glm::vec3 position; glm::vec3 rotation; glm::vec3 size; Color3 color; bool anchored = false; bool locked = false; }; class Snap; class DEF_INST_(explorer_icon="part") Part : public Instance { AUTOGEN_PREAMBLE protected: // Joints where this part is Part0 std::vector> primaryJoints; // Joints where this part is Part1 std::vector> secondaryJoints; void trackJoint(std::shared_ptr); void untrackJoint(std::shared_ptr); SurfaceType surfaceFromFace(NormalId); bool checkJointContinuity(std::shared_ptr); bool checkJointContinuityUp(std::shared_ptr); bool checkJointContinuityDown(std::shared_ptr); bool checkSurfacesTouching(CFrame surfaceFrame, Vector3 size, Vector3 myFace, Vector3 otherFace, std::shared_ptr otherPart); friend JointInstance; void OnAncestryChanged(std::optional> child, std::optional> newParent) override; void onUpdated(std::string); public: DEF_PROP_CATEGORY(DATA) DEF_PROP_(on_update=onUpdated) Vector3 velocity; [[ def_prop(name="CFrame", on_update=onUpdated), cframe_position_prop(name="Position"), cframe_rotation_prop(name="Rotation") ]] CFrame cframe; DEF_PROP_CATEGORY(PART) DEF_PROP_(on_update=onUpdated) glm::vec3 size; DEF_PROP_CATEGORY(APPEARANCE) DEF_PROP Color3 color; DEF_PROP float transparency = 0.f; bool selected = false; DEF_PROP_CATEGORY(BEHAVIOR) DEF_PROP bool anchored = false; DEF_PROP bool locked = false; DEF_PROP_CATEGORY(SURFACE) DEF_PROP SurfaceType topSurface = SurfaceType::SurfaceStuds; DEF_PROP SurfaceType bottomSurface = SurfaceType::SurfaceInlets; DEF_PROP SurfaceType leftSurface = SurfaceType::SurfaceSmooth; DEF_PROP SurfaceType rightSurface = SurfaceType::SurfaceSmooth; DEF_PROP SurfaceType frontSurface = SurfaceType::SurfaceSmooth; DEF_PROP SurfaceType backSurface = SurfaceType::SurfaceSmooth; rp::RigidBody* rigidBody = nullptr; inline SurfaceType GetSurfaceFromFace(NormalId face) { return surfaceFromFace(face); } Part(); Part(PartConstructParams params); ~Part() override; static inline std::shared_ptr New() { return std::make_shared(); }; static inline std::shared_ptr New(PartConstructParams params) { return std::make_shared(params); }; static inline InstanceRef Create() { return std::make_shared(); }; inline Vector3 position() { return cframe.Position(); } void MakeJoints(); void BreakJoints(); // Calculate size of axis-aligned bounding box Vector3 GetAABB(); };