1#include "RiserFlexJointComponent.h"
6#include "Components/Data/TrajectoryComponent.h"
7#include "Components/Geometry/VariableExtrusionComponent.h"
9#include "ProfileGenerator.h"
11#include "Foundation/Geometry/SampleListGenerator.hpp"
16void Cogs::Core::RiserFlexJointComponent::registerType()
38 Method(
Name(
"initialize"), &RiserFlexJointComponent::initialize),
39 Method(
Name(
"update"), &RiserFlexJointComponent::update),
42 DynamicComponent::registerDerivedType<RiserFlexJointComponent>().setFields(fields).setMethods(methods);
45void Cogs::Core::RiserFlexJointComponent::initialize(Context * )
49void Cogs::Core::RiserFlexJointComponent::update()
51 auto variableExtrusion = getComponent<VariableExtrusionComponent>();
53 assert(variableExtrusion &&
"No variable extrusion available for riser.");
55 if (!variableExtrusion->trajectory)
return;
57 auto trajectory = variableExtrusion->trajectory->getComponent<TrajectoryComponent>();
59 if (!trajectory)
return;
61 if (!this->hasChanged() && !variableExtrusion->hasChanged()) {
65 std::vector<float> trajectoryDepths;
67 SampleListGenerator::generateIndexedSamples(startDepth, endDepth, trajectory->indexes.data(),
static_cast<int>(trajectory->indexes.size()), trajectoryDepths);
69 if (trajectoryDepths.size() < 2)
return;
71 if (trajectoryDepths[0] > startDepth || trajectoryDepths[trajectoryDepths.size() - 1] < endDepth)
return;
73 const float radiusScale = variableExtrusion->radiusScale;
75 const float connectorLength = this->connectorLength * radiusScale;
76 const float startConnectorEndDepth = startDepth + connectorLength;
77 const float endConnectorStartDepth = endDepth - connectorLength;
79 const float flexLocation = startDepth + this->flexStart;
80 const float flexLength = this->flexLength;
81 const float flexStart = flexLocation - flexLength * 0.5f;
83 const float innerRadius = this->innerRadius;
84 const float outerRadius = this->outerRadius;
85 const float connectorRadius = this->connectorRadius;
87 const float flexRadius = this->flexOuterRadius;
88 const float innerFlexRadius = this->flexInnerRadius;
90 const float flexBulgeLength = flexLength / 3;
91 const float flexBulgeEnd = flexStart + flexBulgeLength;
93 std::vector<glm::vec2> profile;
94 std::vector<float> depths;
97 ProfileGenerator::generateConnector(depths, profile, startDepth, startConnectorEndDepth, innerRadius, connectorRadius, outerRadius, startDepth);
98 ProfileGenerator::insertPoints(depths, profile, outerRadius, startConnectorEndDepth, flexStart, trajectoryDepths.cbegin(), trajectoryDepths.cend());
99 ProfileGenerator::generateCurvedProfile(depths, profile, flexStart, flexBulgeEnd, outerRadius, flexRadius);
102 profile.push_back(glm::vec2(flexRadius, flexLength)); depths.push_back(flexStart);
103 profile.push_back(glm::vec2(innerFlexRadius, flexLength)); depths.push_back(flexStart);
104 profile.push_back(glm::vec2((innerFlexRadius + outerRadius) / 2, 0)); depths.push_back(flexLocation + flexLength / 6);
105 profile.push_back(glm::vec2(outerRadius, 0)); depths.push_back(flexLocation);
107 ProfileGenerator::insertPoints(depths, profile, outerRadius, flexLocation, endConnectorStartDepth, trajectoryDepths.cbegin(), trajectoryDepths.cend());
108 ProfileGenerator::generateConnector(depths, profile, endConnectorStartDepth, endDepth, outerRadius, connectorRadius, innerRadius, endDepth);
109 ProfileGenerator::insertPointsReverse(depths, profile, innerRadius, startDepth, endDepth, trajectoryDepths.cend());
111 profile.push_back(glm::vec2(innerRadius, 0)); depths.push_back(startDepth);
113 ProfileGenerator::generateConnector(depths, profile, startDepth, startConnectorEndDepth, innerRadius, connectorRadius, outerRadius, startDepth);
114 ProfileGenerator::insertPoints(depths, profile, outerRadius, startConnectorEndDepth, flexStart, trajectoryDepths.cbegin(), trajectoryDepths.cend());
116 profile.push_back(glm::vec2(outerRadius, 0)); depths.push_back(flexStart);
118 profile.push_back(glm::vec2(innerFlexRadius, 0)); depths.push_back(flexStart - flexLength * 0.5f);
119 profile.push_back(glm::vec2(innerFlexRadius, -flexLength)); depths.push_back(flexStart);
121 profile.push_back(glm::vec2(flexRadius, -flexLength)); depths.push_back(flexStart);
125 profile.push_back(glm::vec2(flexRadius, flexLength)); depths.push_back(flexStart + flexLength);
127 profile.push_back(glm::vec2(innerFlexRadius, flexLength)); depths.push_back(flexStart + flexLength);
128 profile.push_back(glm::vec2(innerFlexRadius, 0)); depths.push_back(flexStart + flexLength + flexLength * 0.5f);
130 profile.push_back(glm::vec2(outerRadius, 0)); depths.push_back(flexStart + flexLength);
132 ProfileGenerator::generateConnector(depths, profile, endConnectorStartDepth, endDepth, outerRadius, connectorRadius, innerRadius, endDepth);
133 ProfileGenerator::insertPointsReverse(depths, profile, innerRadius, startDepth, endDepth, trajectoryDepths.cend());
135 profile.push_back(glm::vec2(innerRadius, 0)); depths.push_back(startDepth);
140 variableExtrusion->depths = std::move(depths);
141 variableExtrusion->profile = std::move(profile);
143 variableExtrusion->setChanged();
float flexStart
Offset of the start of the flex from the start depth.
float endDepth
End depth along trajectory.
float flexInnerRadius
Inner radius of the flex bulge.
float connectorLength
Radius of the connectors.
float connectorRadius
Length of the connectors.
float flexOuterRadius
Outer radius of the flex bulge.
bool reverse
If the shape should be reversed.
float startDepth
Start depth along trajectory.
float flexLength
Length of the flex section.
float innerRadius
Inner radius of the joint.
float outerRadius
Outer radius of the joint.
Field definition describing a single data member of a data structure.
Simple method definition.
void reverseProfile(std::vector< float > &depths, std::vector< glm::vec2 > &profile, const float startDepth, const float endDepth)
Reverses the given profile.
Contains geometry calculations and generation.
Contains reflection support.
Represents an unique name.