Some more work on RenderableFov

Make registerting path tokens through Lua scripts work
This commit is contained in:
Alexander Bock
2017-03-13 09:52:06 -04:00
parent ea4d9c8e44
commit d61bb20992
4 changed files with 152 additions and 145 deletions
@@ -130,6 +130,7 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _lineWidth("lineWidth", "Line Width", 1.f, 1.f, 20.f)
, _drawSolid("solidDraw", "Draw as Quads", false)
, _standOffDistance("standOffDistance", "Standoff Distance", 0.9999, 0.999, 1.0)
, _colors({
{
"colors.defaultStart",
@@ -208,6 +209,7 @@ RenderableFov::RenderableFov(const ghoul::Dictionary& dictionary)
addProperty(_lineWidth);
addProperty(_drawSolid);
addProperty(_standOffDistance);
addProperty(_colors.defaultStart);
addProperty(_colors.defaultEnd);
@@ -448,7 +450,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
glm::vec3 srfVec = r.surfaceVector * 1000.0;
// Standoff distance, we would otherwise end up *exactly* on the surface
srfVec *= 0.999;
srfVec *= _standOffDistance;
second = {
srfVec.x, srfVec.y, srfVec.z,
@@ -543,7 +545,7 @@ void RenderableFov::computeIntercepts(const UpdateData& data, const std::string&
// Convert the KM scale that SPICE uses to meter
// Standoff distance, we would otherwise end up *exactly* on the surface
return r.surfaceVector * 1000.0 * 0.999;
return r.surfaceVector * 1000.0 * _standOffDistance.value();
};
for (size_t m = 0; m < InterpolationSteps; ++m) {
@@ -28,6 +28,7 @@
#include <openspace/rendering/renderable.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/doubleproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec4property.h>
#include <openspace/util/spicemanager.h>
@@ -91,6 +92,7 @@ private:
// properties
properties::FloatProperty _lineWidth;
properties::BoolProperty _drawSolid;
properties::DoubleProperty _standOffDistance;
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
// instance variables
+14 -14
View File
@@ -375,50 +375,50 @@ void ScriptEngine::addBaseLibrary() {
"printDebug",
&luascriptfunctions::printDebug,
"*",
"Logs the passed value to the installed LogManager with a "
"LogLevel of 'Debug'"
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Debug'"
},
{
"printInfo",
&luascriptfunctions::printInfo,
"*",
"Logs the passed value to the installed LogManager with a "
" LogLevel of 'Info'"
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Info'"
},
{
"printWarning",
&luascriptfunctions::printWarning,
"*",
"Logs the passed value to the installed LogManager with "
"a LogLevel of 'Warning'"
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Warning'"
},
{
"printError",
&luascriptfunctions::printError,
"*",
"Logs the passed value to the installed LogManager with a "
"LogLevel of 'Error'"
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Error'"
},
{
"printFatal",
&luascriptfunctions::printFatal,
"*",
"Logs the passed value to the installed LogManager with a "
"LogLevel of 'Fatal'"
"Logs the passed value to the installed LogManager with a LogLevel of "
"'Fatal'"
},
{
"absPath",
&luascriptfunctions::absolutePath,
"string",
"Returns the absolute path to the passed path, resolving"
" path tokens as well as resolving relative paths"
"Returns the absolute path to the passed path, resolving path tokens as "
"well as resolving relative paths"
},
{
"setPathToken",
&luascriptfunctions::setPathToken,
"string, string",
"Registers a new path token provided by the"
" first argument to the path provided in the second argument"
"Registers a new path token provided by the first argument to the path "
"provided in the second argument"
}
}
};
+132 -129
View File
@@ -26,142 +26,145 @@ namespace openspace {
namespace luascriptfunctions {
int printInternal(ghoul::logging::LogLevel level, lua_State* L) {
using ghoul::lua::luaTypeToString;
const std::string _loggerCat = "print";
int printInternal(ghoul::logging::LogLevel level, lua_State* L) {
using ghoul::lua::luaTypeToString;
const std::string _loggerCat = "print";
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
const int type = lua_type(L, -1);
switch (type) {
case LUA_TNONE:
case LUA_TLIGHTUSERDATA:
case LUA_TTABLE:
case LUA_TFUNCTION:
case LUA_TUSERDATA:
case LUA_TTHREAD:
LOGC(level, "print", "Function parameter was of type '" <<
luaTypeToString(type) << "'");
case LUA_TNIL:
break;
case LUA_TBOOLEAN:
LOGC(level, "print", lua_toboolean(L, -1));
break;
case LUA_TNUMBER:
LOGC(level, "print", lua_tonumber(L, -1));
break;
case LUA_TSTRING:
LOGC(level, "print", lua_tostring(L, -1));
break;
}
return 0;
int nArguments = lua_gettop(L);
if (nArguments != 1) {
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
}
/**
* \ingroup LuaScripts
* printTrace(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Trace'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printTrace(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Trace, L);
const int type = lua_type(L, -1);
switch (type) {
case LUA_TNONE:
case LUA_TLIGHTUSERDATA:
case LUA_TTABLE:
case LUA_TFUNCTION:
case LUA_TUSERDATA:
case LUA_TTHREAD:
LOGC(level, "print", "Function parameter was of type '" <<
luaTypeToString(type) << "'");
case LUA_TNIL:
break;
case LUA_TBOOLEAN:
LOGC(level, "print", lua_toboolean(L, -1));
break;
case LUA_TNUMBER:
LOGC(level, "print", lua_tonumber(L, -1));
break;
case LUA_TSTRING:
LOGC(level, "print", lua_tostring(L, -1));
break;
}
return 0;
}
/**
* \ingroup LuaScripts
* printTrace(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Trace'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printTrace(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Trace, L);
}
/**
* \ingroup LuaScripts
* printDebug(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Debug'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printDebug(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Debug, L);
}
/**
* \ingroup LuaScripts
* printInfo(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Info'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printInfo(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Info, L);
}
/**
* \ingroup LuaScripts
* printWarning(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Warning'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printWarning(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Warning, L);
}
/**
* \ingroup LuaScripts
* printError(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Error'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printError(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Error, L);
}
/**
* \ingroup LuaScripts
* printFatal(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Fatal'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printFatal(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Fatal, L);
}
/**
* \ingroup LuaScripts
* absPath(string):
* Passes the argument to FileSystem::absolutePath, which resolves occuring path
* tokens and returns the absolute path.
*/
int absolutePath(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 1) {
return luaL_error(L, "Expected %d arguments, got %d", 1, nArguments);
}
/**
* \ingroup LuaScripts
* printDebug(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Debug'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printDebug(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Debug, L);
std::string path = luaL_checkstring(L, -1);
path = absPath(path);
lua_pushstring(L, path.c_str());
return 1;
}
/**
* \ingroup LuaScripts
* setPathToken(string, string):
* Registers the path token provided by the first argument to the path in the second
* argument. If the path token already exists, it will be silently overridden.
*/
int setPathToken(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 2) {
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
}
/**
* \ingroup LuaScripts
* printInfo(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Info'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printInfo(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Info, L);
}
/**
* \ingroup LuaScripts
* printWarning(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Warning'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printWarning(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Warning, L);
}
/**
* \ingroup LuaScripts
* printError(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Error'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printError(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Error, L);
}
/**
* \ingroup LuaScripts
* printFatal(*):
* Logs the passed value to the installed LogManager with a LogLevel of 'Fatal'.
* For Boolean, numbers, and strings, the internal values are printed, for all other
* types, the type is printed instead
*/
int printFatal(lua_State* L) {
return printInternal(ghoul::logging::LogLevel::Fatal, L);
}
/**
* \ingroup LuaScripts
* absPath(string):
* Passes the argument to FileSystem::absolutePath, which resolves occuring path
* tokens and returns the absolute path.
*/
int absolutePath(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 1)
return luaL_error(L, "Expected %d arguments, got %d", 1, nArguments);
std::string path = luaL_checkstring(L, -1);
path = absPath(path);
lua_pushstring(L, path.c_str());
return 1;
}
/**
* \ingroup LuaScripts
* setPathToken(string, string):
* Registers the path token provided by the first argument to the path in the second
* argument. If the path token already exists, it will be silently overridden.
*/
int setPathToken(lua_State* L) {
int nArguments = lua_gettop(L);
if (nArguments != 2)
return luaL_error(L, "Expected %i arguments, got %i", 2, nArguments);
std::string pathToken = luaL_checkstring(L, -1);
std::string path = luaL_checkstring(L, -2);
FileSys.registerPathToken(
pathToken,
path,
ghoul::filesystem::FileSystem::Override::Yes
);
return 0;
}
std::string path = luaL_checkstring(L, -1);
std::string pathToken = luaL_checkstring(L, -2);
FileSys.registerPathToken(
pathToken,
path,
ghoul::filesystem::FileSystem::Override::Yes
);
return 0;
}
} // namespace luascriptfunctions