Polish RenderableCartesianAxes - documentation, examples, and make fading work correctly (#3478)

* Make `RenderableCartesianAxes` fade and fix opacity setting

* Update existing documentation of cartesian axes

* Add example with custom colros and parent node

* Apply suggestions from code review

Co-authored-by: Alexander Bock <alexander.bock@liu.se>

* Include earth asset instead of using string identifer

---------

Co-authored-by: Alexander Bock <alexander.bock@liu.se>
This commit is contained in:
Emma Broman
2025-01-17 13:18:45 +01:00
committed by GitHub
parent 5134946fbf
commit 16aa150f10
5 changed files with 73 additions and 6 deletions
@@ -1,6 +1,6 @@
-- Basic
-- This asset creates a SceneGraphNode that only displays coordinate axes. The
-- parent is not set which defaults to placing the axes at the center the Sun.
-- This example creates a SceneGraphNode that only displays coordinate axes. The
-- parent is not set which defaults to placing the axes at the center of the Sun.
local Node = {
Identifier = "RenderableCartesianAxes_Example",
@@ -0,0 +1,32 @@
-- Custom Colors
-- This example creates a set of cartesian coordinate axes with specified colors, instead
-- of using the default which is red (X), green (Y), and blue (Z). The parent is not set
-- which defaults to placing the axes at the center of the Solar System.
local Node = {
Identifier = "RenderableCartesianAxes_Example_CustomColors",
Transform = {
Scale = {
Type = "StaticScale",
Scale = 30000000
}
},
Renderable = {
Type = "RenderableCartesianAxes",
XColor = { 0.0, 1.0, 1.0 }, -- Cyan
YColor = { 1.0, 0.0, 1.0 }, -- Magenta
ZColor = { 1.0, 1.0, 0.0 } -- Yellow
},
GUI = {
Name = "RenderableCartesianAxes - Custom Colors",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)
@@ -0,0 +1,31 @@
-- With Parent
-- This example creates a SceneGraphNode that displays coordinate axes of the given parent
-- node, in this case Earth.
local earth = asset.require("scene/solarsystem/planets/earth/earth")
local Node = {
Identifier = "RenderableCartesianAxes_Example_Parent",
Parent = earth.Earth.Identifier,
Transform = {
Scale = {
Type = "StaticScale",
Scale = 30000000
}
},
Renderable = {
Type = "RenderableCartesianAxes"
},
GUI = {
Name = "RenderableCartesianAxes - With Parent",
Path = "/Examples"
}
}
asset.onInitialize(function()
openspace.addSceneGraphNode(Node)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(Node)
end)
@@ -65,9 +65,9 @@ namespace {
//
// To add the axes, create a scene graph node with the RenderableCartesianAxes
// renderable and add it as a child to the other scene graph node, i.e. specify the
// other node as the Parent of the node with this renderable. Also, the axes have to
// other node as the `Parent` of the node with this renderable. Also, the axes have to
// be scaled to match the parent object for the axes to be visible in the scene, for
// example using a StaticScale.
// example using a [StaticScale](#base_scale_static).
struct [[codegen::Dictionary(RenderableCartesianAxes)]] Parameters {
// [[codegen::verbatim(XColorInfo.description)]]
std::optional<glm::vec3> xColor [[codegen::color()]];
@@ -95,6 +95,9 @@ RenderableCartesianAxes::RenderableCartesianAxes(const ghoul::Dictionary& dictio
, _zColor(ZColorInfo, glm::vec3(0.f, 0.f, 1.f), glm::vec3(0.f), glm::vec3(1.f))
{
const Parameters p = codegen::bake<Parameters>(dictionary);
addProperty(Fadeable::_opacity);
_xColor = p.xColor.value_or(_xColor);
_xColor.setViewOption(properties::Property::ViewOptions::Color);
addProperty(_xColor);
@@ -195,6 +198,7 @@ void RenderableCartesianAxes::render(const RenderData& data, RendererTasks&) {
_program->setUniform("xColor", _xColor);
_program->setUniform("yColor", _yColor);
_program->setUniform("zColor", _zColor);
_program->setUniform("opacity", opacity());
// Changes GL state:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+2 -2
View File
@@ -31,7 +31,7 @@ in vec3 vs_positionModelSpace;
uniform vec3 xColor;
uniform vec3 yColor;
uniform vec3 zColor;
uniform float opacity;
Fragment getFragment() {
Fragment frag;
@@ -44,7 +44,7 @@ Fragment getFragment() {
frag.color.rgb = colorComponents.x * xColor +
colorComponents.y * yColor +
colorComponents.z * zColor;
frag.color.a = 1.0;
frag.color.a = opacity;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vs_positionViewSpace;