Work on asset loading

This commit is contained in:
Emil Axelsson
2017-10-19 13:24:21 +02:00
parent 97f78a09df
commit 27dea20520
7 changed files with 41 additions and 28 deletions

View File

@@ -1,13 +1,9 @@
local registerSpiceKernels = function (spiceAsset, kernels)
local oldInit = spiceAsset.onInitialize;
spiceAsset.onInitialize(function ()
print "loading spice kernels...."
for i, kernel in ipairs(kernels) do
openspace.spice.loadKernel(kernel)
end
end)
local oldDeinit = spiceAsset.onDeinitialize;
spiceAsset.onDeinitialize(function ()
for i = #kernels, 1, -1 do
kernel = kernels[i]
@@ -16,6 +12,19 @@ local registerSpiceKernels = function (spiceAsset, kernels)
end)
end
local registerSceneGraphNodes = function (sceneAsset, nodes)
sceneAsset.onInitialize(function ()
for i, node in ipairs(nodes) do
openspace.addSceneGraphNode(node)
end
end)
sceneAsset.onDeinitialize(function ()
for i = #nodes, 1, -1 do
node = nodes[i]
openspace.removeSceneGraphNode(node)
end
end)
end
asset.export("registerSceneGraphNodes", registerSceneGraphNodes);
asset.export("registerSpiceKernels", registerSpiceKernels);
asset.export("registerSynchronizations", registerSynchronizations);
asset.export("registerSpiceKernels", registerSpiceKernels);

View File

@@ -1,18 +1,18 @@
local assetHelper = asset.import("assethelper")
local transforms = asset.import("./transforms")
assetHelper.registerSynchronizations(asset, {
{
Type = "HTTPSynchronization",
--- todo...
}
})
--assetHelper.registerSynchronizations(asset, {
-- {
-- Type = "HTTPSynchronization",
-- --- todo...
-- }
--})
--asset.onSynchronize = function (onFinish)
-- onFinish(true)
--end
asset.Earth = {
Earth = {
Name = "Earth",
Parent = transforms.EarthIau.Name,
Renderable = {
@@ -36,6 +36,5 @@ asset.Earth = {
}
assetHelper.registerSceneGraphNodes(asset, {
asset.Earth,
asset.EarthMarker
Earth
})

View File

@@ -16,7 +16,7 @@ local EarthBarycenter = {
local EarthInertial = {
-- The default reference frame for Earth-orbiting satellites
Name = "EarthInertial",
Parent = asset.EarthBarycenter.Name,
Parent = EarthBarycenter.Name,
Transform = {
Rotation = {
Type = "SpiceRotation",
@@ -28,7 +28,7 @@ local EarthInertial = {
local EarthIau = {
Name = "EarthIau",
Parent = asset.EarthBarycenter.Name,
Parent = EarthBarycenter.Name,
Transform = {
Rotation = {
Type = "SpiceRotation",

View File

@@ -2,15 +2,15 @@ local assetHelper = asset.import("assethelper")
asset.import("spice/base")
-- Barycenter of the solar system, expressed in the Galactic frame
asset.SolarSystemBarycenter = {
local SolarSystemBarycenter = {
Name = "SolarSystemBarycenter"
-- No parent; this node is attached to the scene graph root
}
-- Spice frame for the Sun
asset.SunIau = {
local SunIau = {
Name = "SunIau",
Parent = asset.SolarSystemBarycenter.Name,
Parent = SolarSystemBarycenter.Name,
Transform = {
Translation = {
Type = "SpiceTranslation",
@@ -29,3 +29,6 @@ assetHelper.registerSceneGraphNodes(asset, {
asset.SolarSystemBarycenter,
asset.SunIau
})
asset.export("SolarSystemBarycenter", SolarSystemBarycenter)
asset.export("SunIau", SunIau)

View File

@@ -334,7 +334,6 @@ void GUI::initialize() {
style.GrabMinSize = 10.f;
style.GrabRounding = 16.f;
ImGuiStyle& style = ImGui::GetStyle();
style.Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.13f, 0.13f, 0.96f);

View File

@@ -618,10 +618,12 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) {
_renderEngine->startFading(1, 3.0);
if (_scene) {
_renderEngine->setCamera(_scene->camera());
_navigationHandler->setCamera(_scene->camera());
_navigationHandler->setFocusNode(_scene->camera()->parent());
Camera* camera = _scene->camera();
if (camera) {
_renderEngine->setCamera(camera);
_navigationHandler->setCamera(camera);
_navigationHandler->setFocusNode(camera->parent());
}
// Write keyboard documentation.
if (configurationManager().hasKey(ConfigurationManager::KeyKeyboardShortcuts)) {
keyBindingManager().writeDocumentation(
@@ -1339,6 +1341,7 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() {
{
"addTag",
&luascriptfunctions::addTag,
{},
"string, string",
"Adds a tag (second argument) to a scene graph node (first argument)"
}

View File

@@ -106,7 +106,7 @@ Asset* AssetLoader::loadAsset(std::string path) {
}
ghoul::lua::runScriptFile(*_luaState, path);
_importedAssets.emplace(asset->id(), std::move(asset));
_importedAssets.emplace(rawAsset->id(), std::move(asset));
return rawAsset;
}
@@ -118,11 +118,11 @@ std::string AssetLoader::generateAssetPath(const std::string& baseDirectory,
baseDirectory :
_assetRootDirectory;
return directory.path() +
return ghoul::filesystem::File(directory.path() +
ghoul::filesystem::FileSystem::PathSeparator +
assetPath +
"." +
AssetFileSuffix;
AssetFileSuffix);
}
Asset* AssetLoader::getAsset(std::string name) {