Merge branch 'master' into feature/grid-labels

* Solve conflict in renderablegrid.h
This commit is contained in:
Malin E
2022-09-08 11:31:35 +02:00
10 changed files with 359 additions and 164 deletions

View File

@@ -20,6 +20,10 @@ local speck = asset.syncedResource({
Version = 2
})
local lightDay = 2.59020684E13
local lightMonth = 7.771E14
local lightYear = 9.4605284E15
local radio = {
Identifier = "RadioSphere",
Parent = earth_transforms.EarthBarycenter.Identifier,
@@ -233,16 +237,13 @@ local plane1ld = {
}
},
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "1ld.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "1ld.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 10.3,
TextMinMaxSize = { 0, 30 },
Unit = "Km"
Color = { 0.1, 0.5, 0.6 },
LineWidth = 2.0,
Segments = { 20, 20 },
Size = { 2*lightDay, 2*lightDay }
},
GUI = {
Name = "1ld Grid",
@@ -260,16 +261,13 @@ local plane1lm = {
}
},
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "1lm.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "1lm.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 11.8,
TextMinMaxSize = { 0, 30 },
Unit = "pc"
Color = { 0.1, 0.5, 0.6 },
LineWidth = 2.0,
Segments = { 20, 20 },
Size = { 2*lightMonth, 2*lightMonth }
},
GUI = {
Name = "1lm Grid",
@@ -287,16 +285,13 @@ local plane1ly = {
}
},
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "1ly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "1ly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 13.0,
TextMinMaxSize = { 0, 30 },
Unit = "pc"
Color = { 0.1, 0.5, 0.6 },
LineWidth = 2.0,
Segments = { 20, 20 },
Size = { 2*lightYear, 2*lightYear }
},
GUI = {
Name = "1ly Grid",
@@ -314,16 +309,13 @@ local plane10ly = {
}
},
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "10ly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "10ly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 14.17,
TextMinMaxSize = { 0, 30 },
Unit = "pc"
Color = { 0.1, 0.5, 0.6 },
LineWidth = 2.0,
Segments = { 20, 20 },
Size = { 10*2*lightYear, 10*2*lightYear }
},
GUI = {
Name = "10ly Grid",
@@ -341,16 +333,13 @@ local plane100ly = {
}
},
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "100ly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "100ly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 15.0,
TextMinMaxSize = { 0, 30 },
Unit = "pc"
Color = { 0.1, 0.5, 0.6 },
LineWidth = 2.0,
Segments = { 20, 20 },
Size = { 100*2*lightYear, 100*2*lightYear }
},
GUI = {
Name = "100ly Grid",
@@ -368,16 +357,13 @@ local plane1kly = {
}
},
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "1kly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "1kly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 16.0,
TextMinMaxSize = { 0, 30 },
Unit = "pc"
Color = { 0.1, 0.5, 0.6 },
LineWidth = 2.0,
Segments = { 20, 20 },
Size = { 1E3*2*lightYear, 1E3*2*lightYear }
},
GUI = {
Name = "1kly Grid",
@@ -395,16 +381,13 @@ local plane10kly = {
}
},
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "10kly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "10kly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 17.25,
TextMinMaxSize = { 0, 30 },
Unit = "pc"
Color = { 0.1, 0.5, 0.6 },
LineWidth = 2.0,
Segments = { 20, 20 },
Size = { 10E3*2*lightYear, 10E3*2*lightYear }
},
GUI = {
Name = "10kly Grid",
@@ -415,16 +398,15 @@ local plane10kly = {
local plane100kly = {
Identifier = "100klyGrid",
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "100kly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "100kly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 18.6,
TextMinMaxSize = { 0, 30 },
Unit = "Mpc"
Color = { 0.1, 0.5, 0.6 },
HighlightColor = { 0.3, 0.7, 0.8 },
LineWidth = 2.0,
Segments = { 20, 20 },
HighlightRate = { 5, 5 },
Size = { 100E3*2*lightYear, 100E3*2*lightYear }
},
GUI = {
Name = "100kly Grid",
@@ -435,16 +417,15 @@ local plane100kly = {
local plane1Mly = {
Identifier = "1MlyGrid",
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "1Mly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "1Mly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 19.6,
TextMinMaxSize = { 0, 30 },
Unit = "Mpc"
Color = { 0.1, 0.5, 0.6 },
HighlightColor = { 0.3, 0.7, 0.8 },
LineWidth = 2.0,
Segments = { 20, 20 },
HighlightRate = { 5, 5 },
Size = { 1E6*2*lightYear, 1E6*2*lightYear }
},
GUI = {
Name = "1Mly Grid",
@@ -455,16 +436,15 @@ local plane1Mly = {
local plane10Mly = {
Identifier = "10MlyGrid",
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "10Mly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "10Mly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 20.6,
TextMinMaxSize = { 0, 30 },
Unit = "Mpc"
Color = { 0.1, 0.5, 0.6 },
HighlightColor = { 0.3, 0.7, 0.8 },
LineWidth = 2.0,
Segments = { 20, 20 },
HighlightRate = { 5, 5 },
Size = { 10E6*2*lightYear, 10E6*2*lightYear }
},
GUI = {
Name = "10Mly Grid",
@@ -475,16 +455,15 @@ local plane10Mly = {
local plane100Mly = {
Identifier = "100MlyGrid",
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "100Mly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "100Mly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 21.6,
TextMinMaxSize = { 0, 30 },
Unit = "Mpc"
Color = { 0.1, 0.5, 0.6 },
HighlightColor = { 0.3, 0.7, 0.8 },
LineWidth = 2.0,
Segments = { 20, 20 },
HighlightRate = { 5, 5 },
Size = { 100E6*2*lightYear, 100E6*2*lightYear }
},
GUI = {
Name = "100Mly Grid",
@@ -495,16 +474,15 @@ local plane100Mly = {
local plane20Gly = {
Identifier = "20GlyGrid",
Renderable = {
Type = "RenderableDUMeshes",
Type = "RenderableGrid",
Enabled = false,
Opacity = 0.4,
File = speck .. "20Gly.speck",
MeshColor = {{ 0.1, 0.5, 0.6 }},
LabelFile = speck .. "20Gly.label",
TextColor = { 0.0, 0.2, 0.5 },
TextSize = 23.6,
TextMinMaxSize = { 0, 30 },
Unit = "Mpc"
Color = { 0.1, 0.5, 0.6 },
HighlightColor = { 0.3, 0.7, 0.8 },
LineWidth = 2.0,
Segments = { 40, 40 },
HighlightRate = { 5, 5 },
Size = { 20E9*2*lightYear, 20E9*2*lightYear }
},
GUI = {
Name = "20Gly Grid",
@@ -524,7 +502,7 @@ asset.onInitialize(function()
openspace.addSceneGraphNode(node)
end
end)
asset.onDeinitialize(function()
for i = #nodes, 1, -1 do
local node = nodes[i]

View File

@@ -50,13 +50,15 @@ local function createForwardTimelapse()
-- array complete
openspace.scriptScheduler.loadScheduledScript("]] ..
advance(launchTime, 0, 0, 30, 42) .. [[",
"openspace.time.interpolateDeltaTime(7200)" ..
"openspace.setPropertyValueSingle(\"Dashboard.JWSTStateText.Text\", \"Time speed: 2 hours/second\")"
"openspace.time.interpolateDeltaTime(2400)" ..
"openspace.setPropertyValueSingle(\"Dashboard.JWSTStateText.Text\", \"Time speed: 40 minutes/second\")"
)
-- Make night layer more visible, at around 14:00
openspace.scriptScheduler.loadScheduledScript("]] ..
advance(detachTime, 0, 1, 10, 0) .. [[",
"openspace.time.interpolateDeltaTime(7200)" ..
"openspace.setPropertyValueSingle(\"Dashboard.JWSTStateText.Text\", \"Time speed: 2 hours/second\")" ..
"openspace.setPropertyValueSingle(\"Scene.Earth.Renderable.Layers.NightLayers.Earth_at_Night_2012.Settings.Gamma\", 0.7)" ..
"openspace.setPropertyValueSingle(\"Scene.EarthAtmosphere.Renderable.Enabled\", false)"
)
@@ -280,8 +282,10 @@ local function createBackwardTimelapse()
-- Reset night layer, at around 14:00
openspace.scriptScheduler.loadScheduledScript("]] ..
advance(detachTime, 0, 1, 10, 0) .. [[",
advance(detachTime, 0, 1 + 1, 10, 0) .. [[", -- 1h pre delay so time to interpolate
"",
"openspace.time.interpolateDeltaTime(-2400)" ..
"openspace.setPropertyValueSingle(\"Dashboard.JWSTStateText.Text\", \"Time speed: -40 minutes/second\")" ..
"openspace.setPropertyValueSingle(\"Scene.Earth.Renderable.Layers.NightLayers.Earth_at_Night_2012.Settings.Gamma\", 1.0)" ..
"openspace.setPropertyValueSingle(\"Scene.EarthAtmosphere.Renderable.Enabled\", true)"
)
@@ -520,6 +524,8 @@ local function createActions()
openspace.scriptScheduler.clear(0)
openspace.time.setDeltaTime(1)
openspace.setPropertyValueSingle("Dashboard.JWSTStateText.Text", "")
openspace.setPropertyValueSingle("Scene.Earth.Renderable.Layers.NightLayers.Earth_at_Night_2012.Settings.Gamma", 1.0)
openspace.setPropertyValueSingle("Scene.EarthAtmosphere.Renderable.Enabled", true)
openspace.time.setTime("]] .. detachTime .. [[")
]] .. createForwardTimelapse() .. [[
openspace.time.setDeltaTime(1)

View File

@@ -16,7 +16,7 @@ local toggle_trail = {
local launchTrail = "JWSTTrailLaunch"
local cruiseTrail = "JWSTTrailCruise"
local orbitTrail = "JWSTTrailOrbit"
local coRevOrbitTrail = "JWSTTrailCoRevOrbit"
local visibility
if is_declared("args") then
@@ -31,7 +31,7 @@ local toggle_trail = {
visibility = not (
openspace.getPropertyValue("Scene." .. launchTrail .. ".Renderable.Enabled") or
openspace.getPropertyValue("Scene." .. cruiseTrail .. ".Renderable.Enabled") or
openspace.getPropertyValue("Scene." .. orbitTrail .. ".Renderable.Enabled")
openspace.getPropertyValue("Scene." .. coRevOrbitTrail .. ".Renderable.Enabled")
)
end
@@ -44,7 +44,7 @@ local toggle_trail = {
visibility
)
openspace.setPropertyValueSingle(
"Scene." .. orbitTrail .. ".Renderable.Enabled",
"Scene." .. coRevOrbitTrail .. ".Renderable.Enabled",
visibility
)
]],

View File

@@ -28,12 +28,12 @@ local JWSTTrailLaunch = {
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 'EARTH',
Frame = 'IAU_EARTH',
Kernels = { kernels .. "webb.bsp" }
},
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 'EARTH',
Frame = 'IAU_EARTH',
Kernels = { kernels .. "webb.bsp" }
},
Color = { 0.9, 0.9, 0.0 },
StartTime = launchTime,
EndTime = detachTime,
@@ -61,12 +61,12 @@ local JWSTTrailCruise = {
Renderable = {
Type = "RenderableTrailTrajectory",
Translation = {
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 'EARTH',
Frame = 'GALACTIC',
Kernels = { kernels .. "webb.bsp" }
},
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 'EARTH',
Frame = 'GALACTIC',
Kernels = { kernels .. "webb.bsp" }
},
Color = { 0.9, 0.9, 0.0 },
StartTime = detachTime,
EndTime = L2orbitInsertionTime,
@@ -83,9 +83,10 @@ local JWSTTrailCruise = {
-- Trail of JWST relative to L2 after first month to reach L2
-- Gives a better trail history of the orbit around L2 than if it was relative to Earth
-- This does NOT co-rotate with L2 and gives a saddle look of the trail
local JWSTTrailOrbit = {
Identifier = "JWSTTrailOrbit",
Parent = transforms.L2.Identifier,
Parent = transforms.L2Position.Identifier,
TimeFrame = {
Type = "TimeFrameInterval",
Start = L2orbitInsertionTime,
@@ -94,13 +95,13 @@ local JWSTTrailOrbit = {
Renderable = {
Type = "RenderableTrailOrbit",
Translation = {
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 392, -- L2
Frame = 'GALACTIC',
Kernels = { kernels .. "webb.bsp" }
},
Color = { 0.9, 0.9, 0.0 },
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 392, -- L2
Frame = 'GALACTIC',
Kernels = { kernels .. "webb.bsp" }
},
Color = { 0.863, 0.0, 0.902 },
Period = 182.621099, -- About 6 months
Resolution = 183 -- About a sample rate of once per day
},
@@ -113,6 +114,38 @@ local JWSTTrailOrbit = {
}
}
-- Trail of JWST in orbit around L2 that co-revolves with L2 around the Sun
-- This gives the trail a look of a wheel going along L2 around the Sun
local JWSTTrailCoRevOrbit = {
Identifier = "JWSTTrailCoRevOrbit",
Parent = transforms.L2CoRevFrame.Identifier,
TimeFrame = {
Type = "TimeFrameInterval",
Start = L2orbitInsertionTime,
End = endTime
},
Renderable = {
Type = "RenderableTrailOrbit",
Translation = {
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 392, -- L2
Frame = 'L2_COREV',
Kernels = { kernels .. "webb.bsp" }
},
Color = { 1.0, 0.663, 0.157 },
Period = 365.242198, -- About a year, 2 orbits. 1 orbit would be 182.621099 (6 months)
Resolution = 365 -- About a sample rate of once per day
},
GUI = {
Name = "JWST L2 Co-revolving Orbit Trail",
Path = "/Solar System/Missions/JWST/Trails",
Description = [[
James Webb Space Telescope Orbit Trail that Co-revolves with L2.
]],
}
}
local JWSTSunTrail = {
Identifier = "JWSTSunTrail",
Parent = sunTransforms.SolarSystemBarycenter.Identifier,
@@ -124,12 +157,12 @@ local JWSTSunTrail = {
Renderable = {
Type = "RenderableTrailOrbit",
Translation = {
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 'SSB',
Frame = 'GALACTIC',
Kernels = { kernels .. "webb.bsp" }
},
Type = 'SpiceTranslation',
Target = 170, -- JWST
Observer = 'SSB',
Frame = 'GALACTIC',
Kernels = { kernels .. "webb.bsp" }
},
Color = { 0.0, 0.9, 0.9 },
Period = 365.242,
Resolution = 365 -- About a sample rate of once per day
@@ -147,11 +180,13 @@ asset.onInitialize(function()
openspace.addSceneGraphNode(JWSTTrailLaunch)
openspace.addSceneGraphNode(JWSTTrailCruise)
openspace.addSceneGraphNode(JWSTTrailOrbit)
openspace.addSceneGraphNode(JWSTTrailCoRevOrbit)
openspace.addSceneGraphNode(JWSTSunTrail)
end)
asset.onDeinitialize(function()
openspace.removeSceneGraphNode(JWSTSunTrail)
openspace.removeSceneGraphNode(JWSTTrailCoRevOrbit)
openspace.removeSceneGraphNode(JWSTTrailOrbit)
openspace.removeSceneGraphNode(JWSTTrailCruise)
openspace.removeSceneGraphNode(JWSTTrailLaunch)
@@ -160,6 +195,7 @@ end)
asset.export(JWSTTrailLaunch)
asset.export(JWSTTrailCruise)
asset.export(JWSTTrailOrbit)
asset.export(JWSTTrailCoRevOrbit)
asset.export(JWSTSunTrail)

View File

@@ -12,7 +12,7 @@ local kernels = asset.syncedResource({
Name = "Lagrange Kernels",
Type = "HttpSynchronization",
Identifier = "earth_lagrange_kernels",
Version = 1
Version = 2
})
local L2Position = {
@@ -34,6 +34,30 @@ local L2Position = {
}
}
-- This ref. frame co-revolves with L2 and is needed for a more intuitive trail of JWST in
-- relation to L2
local L2CoRevFrame = {
Identifier = "L2CoRevFrame",
Parent = L2Position.Identifier,
Transform = {
Rotation = {
Type = "SpiceRotation",
SourceFrame = "L2_COREV",
DestinationFrame = 'GALACTIC',
Kernels = {
kernels .. "L2_de431.bsp",
kernels .. "L2_corev.tf"
}
}
},
Tag = { "lagrange_points_earth", "lagrange_points_earth_l2" },
GUI = {
Name = "L2 Co-revolving Reference Frame",
Path = "/Solar System/Planets/Earth/Lagrange points",
Hidden = true
}
}
local L2Small = {
Identifier = "L2Small",
Parent = L2Position.Identifier,
@@ -131,6 +155,7 @@ local L2SunLine = {
local nodes = {
L2Position,
L2CoRevFrame,
L2Small,
L2,
L2SunLine,

View File

@@ -73,12 +73,12 @@
"script": "local list = openspace.getProperty('{planetTrail_solarSystem}.Renderable.Enabled'); for _,v in pairs(list) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)) end local moonlist = openspace.getProperty('{moonTrail_solarSystem}.Renderable.Enabled') for _,v in pairs(moonlist) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)) end openspace.setPropertyValueSingle('Scene.MoonTrail.Renderable.Enabled', true)"
},
{
"documentation": "Toggle JWST launch, cruise and orbit trails, not the Sun trail",
"documentation": "Toggle JWST launch, cruise and L2 co-revolving orbit trails, not the Sun trail",
"gui_path": "/JWST",
"identifier": "profile.toggle.jwst_trails",
"is_local": false,
"name": "Toggle JWST trail",
"script": "local list = {'Scene.JWSTTrailLaunch.Renderable.Enabled', 'Scene.JWSTTrailCruise.Renderable.Enabled', 'Scene.JWSTTrailOrbit.Renderable.Enabled'}; for _,v in pairs(list) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)); end"
"script": "local list = {'Scene.JWSTTrailLaunch.Renderable.Enabled', 'Scene.JWSTTrailCruise.Renderable.Enabled', 'Scene.JWSTTrailCoRevOrbit.Renderable.Enabled'}; for _,v in pairs(list) do openspace.setPropertyValueSingle(v, not openspace.getPropertyValue(v)); end"
}
],
"additional_scripts": [
@@ -294,6 +294,11 @@
"type": "setPropertyValueSingle",
"value": "false"
},
{
"name": "Scene.JWSTTrailOrbit.Renderable.Enabled",
"type": "setPropertyValueSingle",
"value": "false"
},
{
"name": "Scene.JWSTSunTrail.Renderable.Enabled",
"type": "setPropertyValueSingle",

View File

@@ -42,6 +42,12 @@ namespace {
"This value determines the color of the grid lines that are rendered"
};
constexpr openspace::properties::Property::PropertyInfo HighlightColorInfo = {
"HighlightColor",
"Highlight Color",
"This value determines the color of the highlighted lines in the grid"
};
constexpr openspace::properties::Property::PropertyInfo SegmentsInfo = {
"Segments",
"Number of Segments",
@@ -49,12 +55,26 @@ namespace {
"grid in each direction"
};
constexpr openspace::properties::Property::PropertyInfo HighlightRateInfo = {
"HighlightRate",
"Highlight Rate",
"The rate that the columns and rows are highlighted, counted with respect to the "
"center of the grid. If the number of segments in the grid is odd, the "
"highlighting might be offset from the center."
};
constexpr openspace::properties::Property::PropertyInfo LineWidthInfo = {
"LineWidth",
"Line Width",
"This value specifies the line width of the grid"
};
constexpr openspace::properties::Property::PropertyInfo HighlightLineWidthInfo = {
"HighlightLineWidth",
"HighlightLine Width",
"This value specifies the line width of the highlighted lines in the grid"
};
constexpr openspace::properties::Property::PropertyInfo SizeInfo = {
"Size",
"Grid Size",
@@ -78,12 +98,21 @@ namespace {
// [[codegen::verbatim(ColorInfo.description)]]
std::optional<glm::vec3> color [[codegen::color()]];
// [[codegen::verbatim(HighlightColorInfo.description)]]
std::optional<glm::vec3> highlightColor [[codegen::color()]];
// [[codegen::verbatim(SegmentsInfo.description)]]
std::optional<glm::ivec2> segments;
// [[codegen::verbatim(HighlightRateInfo.description)]]
std::optional<glm::ivec2> highlightRate;
// [[codegen::verbatim(LineWidthInfo.description)]]
std::optional<float> lineWidth;
// [[codegen::verbatim(HighlightLineWidthInfo.description)]]
std::optional<float> highlightLineWidth;
// [[codegen::verbatim(SizeInfo.description)]]
std::optional<glm::vec2> size;
@@ -106,8 +135,11 @@ documentation::Documentation RenderableGrid::Documentation() {
RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _color(ColorInfo, glm::vec3(0.5f), glm::vec3(0.f), glm::vec3(1.f))
, _highlightColor(HighlightColorInfo, glm::vec3(0.8f), glm::vec3(0.f), glm::vec3(1.f))
, _segments(SegmentsInfo, glm::uvec2(10), glm::uvec2(1), glm::uvec2(200))
, _highlightRate(HighlightRateInfo, glm::uvec2(0), glm::uvec2(0), glm::uvec2(200))
, _lineWidth(LineWidthInfo, 0.5f, 1.f, 20.f)
, _highlightLineWidth(HighlightLineWidthInfo, 0.5f, 1.f, 20.f)
, _size(SizeInfo, glm::vec2(1.f), glm::vec2(1.f), glm::vec2(1e11f))
, _drawLabels(DrawLabelInfo, false)
{
@@ -120,13 +152,26 @@ RenderableGrid::RenderableGrid(const ghoul::Dictionary& dictionary)
_color.setViewOption(properties::Property::ViewOptions::Color);
addProperty(_color);
// If no highlight color is specified then use the base color
_highlightColor = p.highlightColor.value_or(_color);
_highlightColor.setViewOption(properties::Property::ViewOptions::Color);
addProperty(_highlightColor);
_segments = p.segments.value_or(_segments);
_segments.onChange([&]() { _gridIsDirty = true; });
addProperty(_segments);
_highlightRate = p.highlightRate.value_or(_highlightRate);
_highlightRate.onChange([&]() { _gridIsDirty = true; });
addProperty(_highlightRate);
_lineWidth = p.lineWidth.value_or(_lineWidth);
addProperty(_lineWidth);
// If no highlight line width is specified then use the base line width
_highlightLineWidth = p.highlightLineWidth.value_or(_lineWidth);
addProperty(_highlightLineWidth);
_size.setExponent(10.f);
_size = p.size.value_or(_size);
_size.onChange([&]() { _gridIsDirty = true; });
@@ -172,9 +217,14 @@ void RenderableGrid::initializeGL() {
glGenVertexArrays(1, &_vaoID);
glGenBuffers(1, &_vBufferID);
glGenVertexArrays(1, &_highlightVaoID);
glGenBuffers(1, &_highlightVBufferID);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBindVertexArray(_highlightVaoID);
glBindBuffer(GL_ARRAY_BUFFER, _highlightVBufferID);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
}
@@ -182,9 +232,13 @@ void RenderableGrid::initializeGL() {
void RenderableGrid::deinitializeGL() {
glDeleteVertexArrays(1, &_vaoID);
_vaoID = 0;
glDeleteVertexArrays(1, &_highlightVaoID);
_highlightVaoID = 0;
glDeleteBuffers(1, &_vBufferID);
_vBufferID = 0;
glDeleteBuffers(1, &_highlightVBufferID);
_highlightVBufferID = 0;
BaseModule::ProgramObjectManager.release(
"GridProgram",
@@ -201,7 +255,7 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
glm::scale(glm::dmat4(1.0), data.modelTransform.scale);
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
@@ -225,13 +279,24 @@ void RenderableGrid::render(const RenderData& data, RendererTasks&){
glEnable(GL_LINE_SMOOTH);
glDepthMask(false);
// Render minor grid
glBindVertexArray(_vaoID);
glDrawArrays(_mode, 0, static_cast<GLsizei>(_varray.size()));
glBindVertexArray(0);
_gridProgram->deactivate();
// Render major grid
#ifndef __APPLE__
glLineWidth(_highlightLineWidth);
#else
glLineWidth(1.f);
#endif
_gridProgram->setUniform("gridColor", _highlightColor);
glBindVertexArray(_highlightVaoID);
glDrawArrays(_mode, 0, static_cast<GLsizei>(_highlightArray.size()));
// Restore GL State
glBindVertexArray(0);
_gridProgram->deactivate();
global::renderEngine->openglStateCache().resetBlendState();
global::renderEngine->openglStateCache().resetLineState();
global::renderEngine->openglStateCache().resetDepthState();
@@ -262,50 +327,109 @@ void RenderableGrid::update(const UpdateData&) {
return;
}
const glm::vec2 halfSize = _size.value() / 2.f;
const glm::dvec2 halfSize = static_cast<glm::dvec2>(_size.value()) / 2.0;
const glm::uvec2 nSegments = _segments.value();
const glm::vec2 step = _size.value() / static_cast<glm::vec2>(nSegments);
const glm::dvec2 step =
static_cast<glm::dvec2>(_size.value()) / static_cast<glm::dvec2>(nSegments);
const int nLines = (2 * nSegments.x * nSegments.y) + nSegments.x + nSegments.y;
const int nVertices = 2 * nLines;
_varray.resize(nVertices);
_varray.clear();
_varray.reserve(nVertices);
_highlightArray.clear();
_highlightArray.reserve(nVertices);
// OBS! Could be optimized further by removing duplicate vertices
int nr = 0;
// If the number of segments are uneven the center won't be completly centered
const glm::uvec2 center = glm::uvec2(nSegments.x / 2.f, nSegments.y / 2.f);
for (unsigned int i = 0; i < nSegments.x; ++i) {
for (unsigned int j = 0; j < nSegments.y; ++j) {
const float y0 = -halfSize.y + j * step.y;
const float y1 = y0 + step.y;
const double y0 = -halfSize.y + j * step.y;
const double y1 = y0 + step.y;
const float x0 = -halfSize.x + i * step.x;
const float x1 = x0 + step.x;
const double x0 = -halfSize.x + i * step.x;
const double x1 = x0 + step.x;
_varray[nr++] = { x0, y0, 0.f };
_varray[nr++] = { x0, y1, 0.f };
// Line in y direction
bool shouldHighlight = false;
if (_highlightRate.value().y != 0) {
int rest = static_cast<int>(i - center.y) % _highlightRate.value().y;
shouldHighlight = abs(rest) == 0;
}
_varray[nr++] = { x0, y0, 0.f };
_varray[nr++] = { x1, y0, 0.f };
if (shouldHighlight) {
_highlightArray.push_back({ x0, y0, 0.0 });
_highlightArray.push_back({ x0, y1, 0.0 });
}
else {
_varray.push_back({ x0, y0, 0.0 });
_varray.push_back({ x0, y1, 0.0 });
}
// Line in x direction
shouldHighlight = false;
if (_highlightRate.value().x != 0) {
int rest = static_cast<int>(j - center.x) % _highlightRate.value().x;
shouldHighlight = abs(rest) == 0;
}
if (shouldHighlight) {
_highlightArray.push_back({ x0, y0, 0.0 });
_highlightArray.push_back({ x1, y0, 0.0 });
}
else {
_varray.push_back({ x0, y0, 0.0 });
_varray.push_back({ x1, y0, 0.0 });
}
}
}
// last x row
for (unsigned int i = 0; i < nSegments.x; ++i) {
const float x0 = -halfSize.x + i * step.x;
const float x1 = x0 + step.x;
_varray[nr++] = { x0, halfSize.y, 0.f };
_varray[nr++] = { x1, halfSize.y, 0.f };
const double x0 = -halfSize.x + i * step.x;
const double x1 = x0 + step.x;
bool shouldHighlight = false;
if (_highlightRate.value().x != 0) {
int rest =
static_cast<int>(nSegments.y - center.x) % _highlightRate.value().x;
shouldHighlight = abs(rest) == 0;
}
if (shouldHighlight) {
_highlightArray.push_back({ x0, halfSize.y, 0.0 });
_highlightArray.push_back({ x1, halfSize.y, 0.0 });
}
else {
_varray.push_back({ x0, halfSize.y, 0.0 });
_varray.push_back({ x1, halfSize.y, 0.0 });
}
}
// last y col
for (unsigned int i = 0; i < nSegments.y; ++i) {
const float y0 = -halfSize.y + i * step.y;
const float y1 = y0 + step.y;
_varray[nr++] = { halfSize.x, y0, 0.f };
_varray[nr++] = { halfSize.x, y1, 0.f };
const double y0 = -halfSize.y + i * step.y;
const double y1 = y0 + step.y;
bool shouldHighlight = false;
if (_highlightRate.value().y != 0) {
int rest =
static_cast<int>(nSegments.x - center.y) % _highlightRate.value().y;
shouldHighlight = abs(rest) == 0;
}
if (shouldHighlight) {
_highlightArray.push_back({ halfSize.x, y0, 0.0 });
_highlightArray.push_back({ halfSize.x, y1, 0.0 });
}
else {
_varray.push_back({ halfSize.x, y0, 0.0 });
_varray.push_back({ halfSize.x, y1, 0.0 });
}
}
setBoundingSphere(glm::length(glm::dvec2(halfSize)));
// Minor grid
glBindVertexArray(_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferData(
@@ -314,8 +438,19 @@ void RenderableGrid::update(const UpdateData&) {
_varray.data(),
GL_STATIC_DRAW
);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), nullptr);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr);
// Major grid
glBindVertexArray(_highlightVaoID);
glBindBuffer(GL_ARRAY_BUFFER, _highlightVBufferID);
glBufferData(
GL_ARRAY_BUFFER,
_highlightArray.size() * sizeof(Vertex),
_highlightArray.data(),
GL_STATIC_DRAW
);
glVertexAttribPointer(0, 3, GL_DOUBLE, GL_FALSE, sizeof(Vertex), nullptr);
glBindVertexArray(0);

View File

@@ -57,25 +57,31 @@ public:
protected:
struct Vertex {
float location[3];
double location[3];
};
ghoul::opengl::ProgramObject* _gridProgram = nullptr;
properties::Vec3Property _color;
properties::Vec3Property _highlightColor;
// @TODO (abock, 2021-01-28) This was a UVec2Property before, but it wasn't supported
// be the codegen. As soon as it does, this should be changed back
properties::IVec2Property _segments;
properties::IVec2Property _highlightRate;
properties::FloatProperty _lineWidth;
properties::FloatProperty _highlightLineWidth;
properties::Vec2Property _size;
bool _gridIsDirty = true;
GLuint _vaoID = 0;
GLuint _vBufferID = 0;
GLuint _highlightVaoID = 0;
GLuint _highlightVBufferID = 0;
GLenum _mode = GL_LINES;
std::vector<Vertex> _varray;
std::vector<Vertex> _highlightArray;
// Labels
bool _hasLabels = false;

View File

@@ -37,11 +37,11 @@ void main() {
dvec4 objPosDouble = dvec4(in_position, 1.0);
dvec4 positionViewSpace = modelViewTransform * objPosDouble;
dvec4 positionClipSpace = MVPTransform * objPosDouble;
positionClipSpace.z = 0.0;
vs_depthClipSpace = float(positionClipSpace.w);
vs_positionViewSpace = vec4(positionViewSpace);
gl_Position = vec4(positionClipSpace);
}

View File

@@ -489,10 +489,14 @@ void AssetManager::setUpAssetLuaTable(Asset* asset) {
ZoneScoped
Asset* thisAsset = ghoul::lua::userData<Asset>(L, 1);
ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::localResourceLua");
ghoul::lua::checkArgumentsAndThrow(L, { 0, 1 }, "lua::localResourceLua");
auto [name] = ghoul::lua::values<std::optional<std::string>>(L);
std::filesystem::path path =
name.has_value() ?
thisAsset->path().parent_path() / *name :
thisAsset->path().parent_path();
std::string name = ghoul::lua::value<std::string>(L);
std::filesystem::path path = thisAsset->path().parent_path() / name;
ghoul::lua::push(L, path);
return 1;
},
@@ -514,7 +518,7 @@ void AssetManager::setUpAssetLuaTable(Asset* asset) {
ghoul::Dictionary d = ghoul::lua::value<ghoul::Dictionary>(L);
std::unique_ptr<ResourceSynchronization> s =
ResourceSynchronization::createFromDictionary(d);
std::string uid = d.value<std::string>("Type") + "/" + s->generateUid();
SyncItem* syncItem = nullptr;
auto it = manager->_synchronizations.find(uid);