Skip to content

Commit

Permalink
Merge branch 'main' into napfft
Browse files Browse the repository at this point in the history
  • Loading branch information
cklosters authored Jan 13, 2025
2 parents 9bda38e + bd61a04 commit d9553cf
Show file tree
Hide file tree
Showing 44 changed files with 830 additions and 1,118 deletions.
6 changes: 5 additions & 1 deletion cmake/macros_and_functions.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Bootstrap our build environment, setting up architecture, flags, policies, etc used across both NAP
# build contexts
macro(bootstrap_environment)
# Show selected generator
message(STATUS "Generator: ${CMAKE_GENERATOR}")

# Enforce GCC on Linux for now (when doing packaging build at least)
if(UNIX AND NOT APPLE)
if(NOT NAP_BUILD_CONTEXT MATCHES "source" OR DEFINED NAP_PACKAGED_BUILD)
Expand Down Expand Up @@ -455,6 +458,7 @@ macro(set_source_build_configuration)
# Loop over each configuration for multi-configuration systems
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
set(BUILD_CONF ${OUTPUTCONFIG}-${ARCH})
message(STATUS "Build Configuration: ${BUILD_CONF}")

# Separate our outputs for packaging and non packaging (due to differing behaviour in core, plus speeds up
# builds when working in packaging and non-packaging at the same time)
Expand Down Expand Up @@ -495,11 +499,11 @@ macro(set_source_build_configuration)

add_compile_definitions(NAP_BUILD_CONF=${BUILD_CONF})
add_compile_definitions(NAP_BUILD_TYPE=${CMAKE_BUILD_TYPE})
message(STATUS "Build Configuration: ${BUILD_CONF}")
endif()
add_compile_definitions(NAP_BUILD_ARCH=${ARCH})
add_compile_definitions(NAP_BUILD_COMPILER=${CMAKE_CXX_COMPILER_ID})
message(STATUS "Architecture: ${ARCH}" )
message(STATUS "Build Configuration: ${BUILD_CONF}")
endmacro()

# Set a default build type if none was specified (single-configuration generators only, ie. Linux)
Expand Down
2 changes: 1 addition & 1 deletion cmake/version.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(NAP_MAJOR_VERSION 0)
set(NAP_MINOR_VERSION 7)
set(NAP_PATCH_VERSION 6)
set(NAP_PATCH_VERSION 7)
set(NAP_VERSION "${NAP_MAJOR_VERSION}.${NAP_MINOR_VERSION}.${NAP_PATCH_VERSION}")
# Be careful updating this as it's currently parsed during packaging by package.py
message(STATUS "NAP version: ${NAP_VERSION}")
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ Visit [nap-labs.tech](https://nap-labs.tech/use-cases) for more examples
![Habitat, Heleen Blanken](https://download.nap-labs.tech/shared/habitat_1280.jpg)
[Habitat](https://www.heleenblanken.com/habitatbyheleenblanken) by Heleen Blanken, Naivi and Stijn van Beek
![Shylight, Studio Drift](https://download.nap-labs.tech/shared/shylight_basel_1280.jpg)
[Shylight](https://www.studiodrift.com/work#/work/shylight/) by Studio Drift
[Shylight](https://studiodrift.com/work/shylight/) by Studio Drift
![4DSound System](https://download.nap-labs.tech/shared/4D_1280.jpg)
[4DSound System](https://4dsound.net/)
![NAP Framework](https://download.nap-labs.tech/shared/napkin_multiwindow_demo_hq.jpg)
[NAP Framework](https://nap.tech) editor & demo
[NAP Framework](https://nap-framework.tech) editor & demo

# Where to Start

Expand All @@ -69,7 +69,7 @@ Currently, whether working with the packaged framework release or against the fr

**x86**
```
x86-64: Windows (10 & 11), Visual Studio 2019 - MSVC
x86-64: Windows 10 & 11, Visual Studio (2019 & 2022) - MSVC
x86-64: Ubuntu Linux LTS (v22.04 & v24.04) - GCC
```
**ARM**
Expand Down
43 changes: 33 additions & 10 deletions system_modules/naposc/src/oscsender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RTTI_BEGIN_CLASS(nap::OSCSender, "Sends OSC messages over the network")
RTTI_PROPERTY("IpAddress", &nap::OSCSender::mIPAddress, nap::rtti::EPropertyMetaData::Default, "Target machine IP address")
RTTI_PROPERTY("Port", &nap::OSCSender::mPort, nap::rtti::EPropertyMetaData::Required, "Target machine port")
RTTI_PROPERTY("BufferScale", &nap::OSCSender::mBufferScale, nap::rtti::EPropertyMetaData::Default, "Scale factor applied to OSC message buffer")
RTTI_PROPERTY("AllowFailure", &nap::OSCSender::mAllowFailure, nap::rtti::EPropertyMetaData::Default, "Successful initialization even if UDP socket can not be created")
RTTI_END_CLASS

// Max size in bytes of an OSC message
Expand All @@ -31,30 +32,46 @@ namespace nap
char hostIpAddress[IpEndpointName::ADDRESS_STRING_LENGTH];
host.AddressAsString(hostIpAddress);

// Create socket
mSocket = std::make_unique<UdpTransmitSocket>(host);
nap::Logger::info("Started OSC output connection, ip: %s, port: %d", hostIpAddress, mPort);
// Try to create the socket
mSocket = nullptr;
try
{
mSocket = std::make_unique<UdpTransmitSocket>(host);
nap::Logger::info("Started OSC output connection, ip: %s, port: %d", hostIpAddress, mPort);
}catch (const std::exception& e)
{
// Exception can be thrown in constructor of UdpTransmitSocket, caught here
// If we allow failure, log the error, otherwise return false and fail initialization
if(!errorState.check(mAllowFailure, "Failed to start OSC output connection, ip: %s, port: %d, error: %s", hostIpAddress, mPort, e.what()))
return false;

nap::Logger::error("Failed to start OSC output connection, ip: %s, port: %d, error: %s", hostIpAddress, mPort, e.what());
}

return true;
}


void OSCSender::stop()
{
mSocket.reset(nullptr);
}
if(mSocket!=nullptr)
mSocket.reset(nullptr);
}


bool OSCSender::send(const OSCEvent& oscEvent)
{
if(mSocket==nullptr)
return false;

std::size_t buffer_size = oscEvent.getSize();
buffer_size *= math::max<int>(mBufferScale, 1);
buffer_size += sizeof(osc::BeginMessage);
buffer_size += sizeof(osc::EndMessage);

// Grow the buffer based on the number of bytes that need allocation
// Always allocate more than the bare minimum, that's why we multiply by 2.
if (mBuffer.size() < buffer_size)
if(mBuffer.size() < buffer_size)
mBuffer.resize(buffer_size);

// Create packet
Expand All @@ -71,7 +88,10 @@ namespace nap

void OSCSender::sendQueuedEvents()
{
if (mEventQueue.empty())
if(mSocket== nullptr)
return;

if(mEventQueue.empty())
return;

// Create the buffer
Expand All @@ -83,7 +103,7 @@ namespace nap
buffer_size += sizeof(osc::BundleTerminator);

// Grow the buffer based on the number of bytes that need allocation
if (mBuffer.size() < buffer_size)
if(mBuffer.size() < buffer_size)
mBuffer.resize(buffer_size);

// Create packet, grow buffer if necessary
Expand All @@ -93,7 +113,7 @@ namespace nap
packet << osc::BeginBundle();

// Add all events
while (!(mEventQueue.empty()))
while(!(mEventQueue.empty()))
{
writeToPacket(*(mEventQueue.front().get()), packet);
mEventQueue.pop();
Expand All @@ -117,7 +137,7 @@ namespace nap
outPacket << osc::BeginMessage(oscEvent.getAddress().c_str());

// Add every argument
for (const auto& arg : oscEvent.getArguments())
for(const auto& arg : oscEvent.getArguments())
{
arg->add(outPacket);
}
Expand All @@ -129,6 +149,9 @@ namespace nap

void OSCSender::addEvent(OSCEventPtr oscEvent)
{
if(mSocket==nullptr)
return;

mEventQueueDataSize += (oscEvent->getSize());
mEventQueue.emplace(std::move(oscEvent));
}
Expand Down
1 change: 1 addition & 0 deletions system_modules/naposc/src/oscsender.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace nap
std::string mIPAddress = "127.0.0.1"; ///< Property: 'IpAddress' target machine ip address
int mPort = 8000; ///< Property: 'Port' target machine port
int mBufferScale = 2; ///< Property: 'Scale' scale factor applied to OSC message buffer.
bool mAllowFailure = false; ///< Property: 'AllowFailure' if true, the sender will not fail to init if it fails to create the UDPTransmitSocket on init


/**
Expand Down
56 changes: 36 additions & 20 deletions system_modules/naprender/src/depthsorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ namespace nap
// Static
//////////////////////////////////////////////////////////////////////////

static MaterialInstance* findMaterialInstance(const RenderableComponentInstance& component)
{
// Find get or create material instance method
auto mat_method = rtti::findMethodRecursive(component.get_type(), material::instance::getOrCreateMaterial);
if (!mat_method.is_valid())
return nullptr;

// Make sure it's a material instance pointer
auto mat_return_type = mat_method.get_return_type();
if (!mat_return_type.is_derived_from(RTTI_OF(MaterialInstance)) || !mat_return_type.is_pointer())
return nullptr;

// Get material instance
auto mat_result = mat_method.invoke(component); assert(mat_result.is_valid());
return mat_result.get_value<MaterialInstance*>();
}


static void sortSubsetByDepth(std::vector<RenderableComponentInstance*>& outComps, const std::vector<RenderableComponentInstance*>& subsetComps, const glm::mat4& viewMatrix)
{
// Split into front to back and back to front meshes
Expand All @@ -19,13 +37,12 @@ namespace nap
std::vector<RenderableComponentInstance*> back_to_front;
back_to_front.reserve(subsetComps.size());

for (RenderableComponentInstance* component : subsetComps)
for (auto* component : subsetComps)
{
RenderableMeshComponentInstance* renderable_mesh = rtti_cast<RenderableMeshComponentInstance>(component);
if (renderable_mesh != nullptr)
auto* mat_instance = findMaterialInstance(*component);
if (mat_instance != nullptr)
{
RenderableMeshComponentInstance* renderable_mesh = static_cast<RenderableMeshComponentInstance*>(component);
EBlendMode blend_mode = renderable_mesh->getMaterialInstance().getBlendMode();
auto blend_mode = mat_instance->getBlendMode();
if (blend_mode == EBlendMode::AlphaBlend)
back_to_front.emplace_back(component);
else
Expand Down Expand Up @@ -59,13 +76,12 @@ namespace nap
std::vector<RenderableComponentInstance*> back_to_front;
back_to_front.reserve(subsetComps.size());

for (RenderableComponentInstance* component : subsetComps)
for (auto* component : subsetComps)
{
RenderableMeshComponentInstance* renderable_mesh = rtti_cast<RenderableMeshComponentInstance>(component);
if (renderable_mesh != nullptr)
auto* mat_instance = findMaterialInstance(*component);
if (mat_instance != nullptr)
{
RenderableMeshComponentInstance* renderable_mesh = static_cast<RenderableMeshComponentInstance*>(component);
EBlendMode blend_mode = renderable_mesh->getMaterialInstance().getBlendMode();
EBlendMode blend_mode = mat_instance->getBlendMode();
if (blend_mode == EBlendMode::AlphaBlend)
back_to_front.emplace_back(component);
else
Expand Down Expand Up @@ -103,14 +119,14 @@ namespace nap
bool DepthComparer::operator()(const ComponentInstance* objectA, const ComponentInstance* objectB)
{
// Get the transform of objectA in view space
const EntityInstance& entity_a = *objectA->getEntityInstance();
const TransformComponentInstance& transform_a = entity_a.getComponent<TransformComponentInstance>();
const glm::mat4 view_space_a = mViewMatrix * transform_a.getGlobalTransform();
const auto& entity_a = *objectA->getEntityInstance();
const auto& transform_a = entity_a.getComponent<TransformComponentInstance>();
const auto view_space_a = mViewMatrix * transform_a.getGlobalTransform();

// Get the transform of objectB in view space
const EntityInstance& entity_b = *objectB->getEntityInstance();
const TransformComponentInstance& transform_b = entity_b.getComponent<TransformComponentInstance>();
const glm::mat4 view_space_b = mViewMatrix * transform_b.getGlobalTransform();
const auto& entity_b = *objectB->getEntityInstance();
const auto& transform_b = entity_b.getComponent<TransformComponentInstance>();
const auto view_space_b = mViewMatrix * transform_b.getGlobalTransform();

// Get the z-component (i.e. depth) of both entities
float a_z = view_space_a[3].z;
Expand All @@ -132,13 +148,13 @@ namespace nap
bool ZComparer::operator()(const ComponentInstance* objectA, const ComponentInstance* objectB)
{
// Get the transform of objectA in view space
const EntityInstance& entity_a = *objectA->getEntityInstance();
const TransformComponentInstance& transform_a = entity_a.getComponent<TransformComponentInstance>();
const auto& entity_a = *objectA->getEntityInstance();
const auto& transform_a = entity_a.getComponent<TransformComponentInstance>();
const auto& translate_a = math::extractPosition(transform_a.getGlobalTransform());

// Get the transform of objectB in view space
const EntityInstance& entity_b = *objectB->getEntityInstance();
const TransformComponentInstance& transform_b = entity_b.getComponent<TransformComponentInstance>();
const auto& entity_b = *objectB->getEntityInstance();
const auto& transform_b = entity_b.getComponent<TransformComponentInstance>();
const auto& translate_b = math::extractPosition(transform_b.getGlobalTransform());

// Compare
Expand Down
Loading

0 comments on commit d9553cf

Please sign in to comment.