Q: Is there any way to visualize raycasts?
Answer:
To visualize a raycast, you would need to draw a debug line.
Today it is possible to draw a debug line in a script but not through the Livelink.js SDK. As a reminder, scripts are written in C++ and run server-side (directly alongside the rendering engine). They have access to functions within our rendering engine like drawDebugLine
.
Within the custom code node of a script, you can use the function:
void engine_context::drawDebugLine(const glm::vec3 &start, const glm::vec3 &end, line_color color);
The different line_colors available to you are as follows:
enum class line_color : uint32_t
{
white = 0x00FFFFFF,
red = 0x000000FF,
green = 0x0000FF00,
blue = 0x00FF0000,
yellow = 0x0000FFFF,
magenta = 0x00FF00FF,
cyan = 0x00FFFF00
};
So, in your custom code, you would visualize a raycast like so:
// Raycast
const auto optRaycastResult = g_pEngineContext->physicsRaycast(rayOrigin, moveDir, rayLength, ftl_query_filter_flag::static_block);
// Draw raycast
g_pEngineContext->drawDebugLine(rayOrigin, rayOrigin + moveDir * rayLength, line_color::magenta);
g_pEngineContext
is a pointer to the engine_context (which holds engine functions like engine_context::physicsRaycast
and engine_context::drawDebugLine
) that is globally defined and can be used by any custom code node.