Skip to content

Commit

Permalink
Added OffsetCurveOperation. Cleaned up some node names and removed un…
Browse files Browse the repository at this point in the history
…used OffsetOperation
  • Loading branch information
jasonbeverage committed Feb 5, 2025
1 parent 7b044a2 commit c7b2855
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 79 deletions.
65 changes: 39 additions & 26 deletions src/osgEarthImGui/NodeGraphGUI
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace osgEarth
_proceduralModelLayer->getNodeGraph()->operations.push_back(std::make_shared<ColorValue>());
}

if (ImGui::MenuItem("Join"))
if (ImGui::MenuItem("Join Nodes"))
{
_proceduralModelLayer->getNodeGraph()->operations.push_back(std::make_shared<JoinNodesOperation>());
}
Expand Down Expand Up @@ -150,6 +150,11 @@ namespace osgEarth
_proceduralModelLayer->getNodeGraph()->operations.push_back(std::make_shared<BufferOperation>());
}

if (ImGui::MenuItem("Offset Curve Features"))
{
_proceduralModelLayer->getNodeGraph()->operations.push_back(std::make_shared<OffsetCurveOperation>());
}

if (ImGui::MenuItem("Offset Features"))
{
_proceduralModelLayer->getNodeGraph()->operations.push_back(std::make_shared<OffsetFeaturesOperation>());
Expand Down Expand Up @@ -251,12 +256,7 @@ namespace osgEarth
}
#endif

if (ImGui::MenuItem("Offset"))
{
_proceduralModelLayer->getNodeGraph()->operations.push_back(std::make_shared<OffsetOperation>());
}

if (ImGui::MenuItem("Join"))
if (ImGui::MenuItem("Join Features"))
{
_proceduralModelLayer->getNodeGraph()->operations.push_back(std::make_shared<JoinOperation>());
}
Expand Down Expand Up @@ -354,28 +354,12 @@ namespace osgEarth
if (colorValue)
{
ImGui::PushItemWidth(100.0f);
osg::Vec4 color = colorValue->getValue();
if (ImGui::ColorEdit4("Color", (float*)color._v, ImGuiColorEditFlags_NoInputs))
{
colorValue->setColor(color);
updateNodeGraph();
}
ImGui::PopItemWidth();
}

OffsetOperation* offset = dynamic_cast<OffsetOperation*>(o.get());
if (offset)
{
ImGui::PushItemWidth(100.0f);
float o = offset->getOffset();
if (ImGui::InputFloat("Offset", &o))
if (ImGui::ColorEdit4("Color", (float*)colorValue->color._v, ImGuiColorEditFlags_NoInputs))
{
offset->setOffset(o);
updateNodeGraph();

}
ImGui::PopItemWidth();
}
}

ImageMaskOperation* imageMask = dynamic_cast<ImageMaskOperation*>(o.get());
if (imageMask)
Expand Down Expand Up @@ -705,6 +689,7 @@ namespace osgEarth
updateNodeGraph();
}


ImGui::PushItemWidth(100.0f);
bool singleSided = op->getSingleSided();
if (ImGui::Checkbox("Single Sided", &singleSided))
Expand All @@ -718,6 +703,34 @@ namespace osgEarth
ImGui::PopItemWidth();
}

if (auto* op = dynamic_cast<OffsetCurveOperation*>(o.get()))
{
ImGui::PushItemWidth(100.0f);
if (ImGui::InputInt("Quad Segments", &op->quadSegs))
{
updateNodeGraph();
}
ImGui::PopItemWidth();

ImGui::PushItemWidth(100.0f);
const char* items[] = { "Round", "Mitre", "Bevel" };
int item_current = static_cast<int>(op->joinStyle);
if (ImGui::Combo("Join Style", &item_current, items, IM_ARRAYSIZE(items)))
{
op->joinStyle = static_cast<BufferParameters::JoinStyle>(item_current);
updateNodeGraph();
}

float v = op->mitreLimit;
ImGui::PushItemWidth(100.0f);
if (ImGui::InputFloat("Mitre Limit", &v, 0.0f, 0.0f, "%.5f"))
{
op->mitreLimit;
updateNodeGraph();
}
ImGui::PopItemWidth();
}


for (auto& attr : o->getInputAttributes())
{
Expand Down Expand Up @@ -758,7 +771,7 @@ namespace osgEarth
}
}

ImNodes::EndNodeEditor();
ImNodes::EndNodeEditor();

int start_attr, end_attr;
if (ImNodes::IsLinkCreated(&start_attr, &end_attr))
Expand Down
96 changes: 43 additions & 53 deletions src/osgEarthProcedural/NodeGraph
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,11 @@ namespace osgEarth
virtual void execute(const NodeGraphContext& context)
{
NodeGraphResult result;
result.vectorValue.push_back(_color);
result.vectorValue.push_back(color);
set_output("Color", result);
}

const osg::Vec4& getValue() const { return _color; }
void setColor(const osg::Vec4& color) { _color = color; }

osg::Vec4 _color;
osg::Vec4 color = Color::Red;
};

class OSGEARTHPROCEDURAL_EXPORT RandomValuePerFeature : public NodeGraphOperation
Expand Down Expand Up @@ -1621,6 +1618,46 @@ namespace osgEarth
bool _singleSided = false;
};

class OSGEARTHPROCEDURAL_EXPORT OffsetCurveOperation : public NodeGraphOperation
{
public:
OffsetCurveOperation()
{
_name = "Offset Curve";

addInputAttribute("Features", NodeAttribute::FEATURES);
addInputAttribute("Distance", NodeAttribute::FLOAT);
addOutputAttribute("Features", NodeAttribute::FEATURES);
}

virtual void execute(const NodeGraphContext& context) override
{
auto features = get_input("Features");
auto distance = get_input("Distance");

if (features && distance)
{
FeatureList output;

for (auto& f : features->featuresValue)
{
osg::ref_ptr<Geometry> geom;
if (f->getGeometry()->offsetCurve(distance->floatValue, quadSegs, joinStyle, mitreLimit, geom))
{
Feature* newFeature = new Feature(*f);
newFeature->setGeometry(geom.get());
output.push_back(newFeature);
}
}
set_output("Features", output);
}
}

int quadSegs = 8;
BufferParameters::JoinStyle joinStyle = BufferParameters::JOIN_MITRE;
double mitreLimit = 5.0;
};

class OSGEARTHPROCEDURAL_EXPORT CurrentLODOperation : public NodeGraphOperation
{
public:
Expand Down Expand Up @@ -1845,54 +1882,7 @@ namespace osgEarth
float _minHeading = 0.0f;
float _maxHeading = 360.0f;
Random _prng;
};

class OSGEARTHPROCEDURAL_EXPORT OffsetOperation : public NodeGraphOperation
{
public:
OffsetOperation()
{
_name = "Offset";

addInputAttribute("Features", NodeAttribute::FEATURES);
addOutputAttribute("Features", NodeAttribute::FEATURES);
}

virtual void execute(const NodeGraphContext& context) override
{
auto features = get_input("Features");
if (features)
{
for (auto& f : features->featuresValue)
{
GeometryIterator itr(f->getGeometry());
while (itr.hasMore())
{
Geometry* g = itr.next();
for (Geometry::iterator v = g->begin(); v != g->end(); ++v)
{
v->z() += _offset;
}
}
}
// These are modified in place, this is faster but is destructive to the features from the input
set_output("Features", features->featuresValue);
}
}

float getOffset() const
{
return _offset;
}

void setOffset(float offset)
{
_offset = offset;
}

float _offset = 0.0f;
};

};

class OSGEARTHPROCEDURAL_EXPORT FeaturesToLinesOperation : public NodeGraphOperation
{
Expand Down

0 comments on commit c7b2855

Please sign in to comment.