Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build-linux:
runs-on: ubuntu-latest
container:
image: "alicevision/alicevision-deps:2026.02.17-rocky9-cuda12.1.1"
image: "alicevision/alicevision-deps:2026.03.30-rocky9-cuda12.1.1"
env:
DEPS_INSTALL_DIR: /opt/AliceVision_install
BUILD_TYPE: Release
Expand Down Expand Up @@ -41,6 +41,7 @@ jobs:
-DALICEVISION_USE_CCTAG=ON \
-DALICEVISION_USE_POPSIFT=ON \
-DALICEVISION_USE_ALEMBIC=ON \
-DALICEVISION_USE_USD=ON \
-DOpenCV_DIR="${DEPS_INSTALL_DIR}/share/OpenCV" \
-DCeres_DIR="${DEPS_INSTALL_DIR}/share/Ceres" \
-DAlembic_DIR="${DEPS_INSTALL_DIR}/lib/cmake/Alembic" \
Expand Down
6 changes: 4 additions & 2 deletions docker/Dockerfile_rocky_deps
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ RUN --mount=type=cache,target=/var/cache/dnf \
xerces-c-devel \
yaml-cpp \
yasm \
ninja-build \
&& dnf update -y

# =============================================================================
Expand Down Expand Up @@ -153,15 +154,16 @@ COPY dl/deps ${AV_BUILD}/external/download/
# =============================================================================
WORKDIR "${AV_BUILD}"

RUN cmake "${AV_DEV}" \
RUN mkdir -p "${AV_INSTALL}/bin" \
&& mkdir -p "${AV_INSTALL}/lib" \
&& cmake "${AV_DEV}" \
-DCMAKE_BUILD_TYPE=Release \
-DALICEVISION_BUILD_DEPENDENCIES:BOOL=ON \
-DAV_BUILD_ALICEVISION:BOOL=OFF \
-DAV_BUILD_ZLIB:BOOL=ON \
-DAV_BUILD_CCTAG:BOOL=ON \
-DCMAKE_INSTALL_PREFIX="${AV_INSTALL}" \
-DAV_BUILD_DEPENDENCIES_PARALLEL=0 \
&& mkdir -p "${AV_INSTALL}/lib" \
&& ln -sf lib "${AV_INSTALL}/lib64" \
&& { test -e /usr/local/cuda/lib64/libcublas.so \
|| ln -s /usr/lib/x86_64-linux-gnu/libcublas.so \
Expand Down
4 changes: 2 additions & 2 deletions docker/build-rocky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ test -e docker/fetch.sh || {
exit 1
}

test -z "$AV_DEPS_VERSION" && AV_DEPS_VERSION=2025.09.12
test -z "$AV_VERSION" && AV_VERSION="$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)"
test -z "$AV_DEPS_VERSION" && AV_DEPS_VERSION=2026.03.30
test -z "$AV_VERSION" && AV_VERSION="develop-$(git rev-parse --short HEAD)"
test -z "$CUDA_VERSION" && CUDA_VERSION=12.1.1
test -z "$ROCKY_VERSION" && ROCKY_VERSION=9
test -z "$REPO_OWNER" && REPO_OWNER=alicevision
Expand Down
16 changes: 13 additions & 3 deletions docker/fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ for dep in \
suitesparse \
tbb \
turbojpeg \
onnxruntime
onnxruntime \
usd
do
STAMP="external/src/${dep}-stamp/download-${dep}.cmake"
if [ -f "${STAMP}" ]; then
Expand All @@ -100,8 +101,17 @@ do
done

# OpenCV lives under a different prefix (legacy layout kept as-is)
cmake -P "opencv-prefix/src/opencv-stamp/download-opencv.cmake"
cmake -P "opencv_contrib-prefix/src/opencv_contrib-stamp/download-opencv_contrib.cmake"
if [ -f "opencv-prefix/src/opencv-stamp/download-opencv.cmake" ]; then
cmake -P "opencv-prefix/src/opencv-stamp/download-opencv.cmake"
else
echo "WARNING: opencv download script not found — skipping opencv"
fi

if [ -f "opencv_contrib-prefix/src/opencv_contrib-stamp/download-opencv_contrib.cmake" ]; then
cmake -P "opencv_contrib-prefix/src/opencv_contrib-stamp/download-opencv_contrib.cmake"
else
echo "WARNING: opencv_contrib download script not found — skipping opencv_contrib"
fi

# ---------------------------------------------------------------------------
# Git-based deps → gitclone-<dep>.cmake (no download-*.cmake for these)
Expand Down
44 changes: 44 additions & 0 deletions meshroom/aliceVision/ExportMeshUSD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
__version__ = "1.0"

from meshroom.core import desc
from meshroom.core.utils import VERBOSE_LEVEL


class ExportMeshUSD(desc.AVCommandLineNode):
commandLine = "aliceVision_exportMeshUSD {allParams}"
size = desc.DynamicNodeSize("input")

category = "Export"
documentation = """ Export a mesh (OBJ file) to USD format. """

inputs = [
desc.File(
name="input",
label="Input",
description="Input mesh file.",
value="",
),
desc.ChoiceParam(
name="fileType",
label="USD File Format",
description="Output USD file format.",
value="usda",
values=["usda", "usdc", "usdz"]
),
desc.ChoiceParam(
name="verboseLevel",
label="Verbose Level",
description="Verbosity level (fatal, error, warning, info, debug, trace).",
values=VERBOSE_LEVEL,
value="info",
),
]

outputs = [
desc.File(
name="output",
label="Output",
description="Path to the output file.",
value="{nodeCacheFolder}/output.{fileTypeValue}",
),
]
33 changes: 18 additions & 15 deletions meshroom/aliceVision/ExportUSD.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.0"
__version__ = "2.0"

from meshroom.core import desc
from meshroom.core.utils import VERBOSE_LEVEL
Expand All @@ -8,22 +8,25 @@ class ExportUSD(desc.AVCommandLineNode):
commandLine = "aliceVision_exportUSD {allParams}"
size = desc.DynamicNodeSize("input")

category = "Utils"
documentation = """ Export a mesh (OBJ file) to USD format. """
category = "Export"
documentation = """
Convert cameras from an SfM scene into an animated camera in USD format.
Based on the input image filenames, this node detects video sequences and creates the corresponding animated camera.
"""

inputs = [
desc.File(
name="input",
label="Input",
description="Input mesh file.",
label="Input SfMData",
description="SfMData file containing a complete SfM.",
value="",
),
desc.ChoiceParam(
name="fileType",
label="USD File Format",
description="Output USD file format.",
value="usda",
values=["usda", "usdc", "usdz"]
desc.FloatParam(
name="frameRate",
label="Camera Frame Rate",
description="Define the camera's frames per second.",
value=24.0,
range=(1.0, 60.0, 1.0),
),
desc.ChoiceParam(
name="verboseLevel",
Expand All @@ -37,8 +40,8 @@ class ExportUSD(desc.AVCommandLineNode):
outputs = [
desc.File(
name="output",
label="Output",
description="Path to the output file.",
value="{nodeCacheFolder}/output.{fileTypeValue}",
),
label="USD filename",
description="Output usd filename",
value="{nodeCacheFolder}/animated.usda",
)
]
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ option(ALICEVISION_USE_ONNX_GPU "Use CUDA with ONNX Runtime" ON)
trilean_option(ALICEVISION_USE_CUDA "Enable CUDA" ON)
trilean_option(ALICEVISION_USE_OPENCV "Enable use of OpenCV algorithms" OFF)
trilean_option(ALICEVISION_USE_OPENCV_CONTRIB "Enable use of OpenCV algorithms from extra modules" AUTO)
trilean_option(ALICEVISION_USE_USD "Enable USD" AUTO)
option(ALICEVISION_USE_OCVSIFT "Add or not OpenCV SIFT in available features" OFF)
mark_as_advanced(FORCE ALICEVISION_USE_OCVSIFT)

Expand Down
21 changes: 21 additions & 0 deletions src/aliceVision/sfmDataIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ if (ALICEVISION_HAVE_ALEMBIC)
)
endif()

if (ALICEVISION_HAVE_USD)

list(APPEND sfmDataIO_files_headers
UsdExporter.hpp
)
list(APPEND sfmDataIO_files_sources
UsdExporter.cpp
)
endif()

alicevision_add_library(aliceVision_sfmDataIO
SOURCES ${sfmDataIO_files_headers} ${sfmDataIO_files_sources}
PUBLIC_LINKS
Expand All @@ -60,6 +70,17 @@ if (ALICEVISION_HAVE_ALEMBIC)
)
endif()

if (ALICEVISION_HAVE_USD)
target_link_libraries(aliceVision_sfmDataIO
PRIVATE usd
usdGeom
gf
tf
vt
sdf
)
endif()

# Unit tests

alicevision_add_test(sfmDataIO_test.cpp
Expand Down
134 changes: 134 additions & 0 deletions src/aliceVision/sfmDataIO/UsdExporter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// This file is part of the AliceVision project.
// Copyright (c) 2025 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include <aliceVision/sfmDataIO/UsdExporter.hpp>
#include <aliceVision/camera/IntrinsicScaleOffset.hpp>
#include <aliceVision/system/Logger.hpp>

#include <pxr/usd/usd/stage.h>

#include <pxr/usd/usdGeom/xform.h>
#include <pxr/usd/usdGeom/points.h>
#include <pxr/usd/usdGeom/camera.h>

#include <pxr/base/gf/vec3f.h>
#include <pxr/base/vt/array.h>


PXR_NAMESPACE_USING_DIRECTIVE

namespace aliceVision {
namespace sfmDataIO {


UsdExporter::UsdExporter(const std::string & filename, double frameRate)
{
_stage = UsdStage::CreateNew(filename);
if (!_stage)
{
ALICEVISION_THROW_ERROR("UsdStage::CreateNew failed");
}

UsdGeomXform worldPrim = UsdGeomXform::Define(_stage, SdfPath("/World"));

_stage->SetTimeCodesPerSecond(frameRate);
_stage->SetFramesPerSecond(frameRate);
_startTimeCode = std::numeric_limits<IndexT>::max();
_endTimeCode = 0;
}

void UsdExporter::terminate()
{
// If no frames have been exported, _startTimeCode will still be at its sentinel value.
// In that case, avoid writing invalid start/end time codes to the USD stage.
if (_startTimeCode == std::numeric_limits<IndexT>::max())
{
ALICEVISION_LOG_WARNING("UsdExporter::terminate called but no frames have been exported; "
"skipping start/end time code settings.");
}
else
{
_stage->SetStartTimeCode(_startTimeCode);
_stage->SetEndTimeCode(_endTimeCode);
}

_stage->Save();
}

void UsdExporter::createNewCamera(const std::string & cameraName)
{
SdfPath cameraPath("/World/" + cameraName);
UsdGeomCamera camera = UsdGeomCamera::Define(_stage, cameraPath);

UsdAttribute projectionAttr = camera.GetProjectionAttr();
projectionAttr.Set(UsdGeomTokens->perspective);

UsdGeomXformable xformable(camera);
UsdGeomXformOp motion = xformable.MakeMatrixXform();
GfMatrix4d identity(1.0);
motion.Set(identity);
}

void UsdExporter::addFrame(const std::string & cameraName, const sfmData::CameraPose & pose, const camera::Pinhole & intrinsic, IndexT frameId)
{
SdfPath cameraPath("/World/" + cameraName);
UsdGeomCamera camera = UsdGeomCamera::Get(_stage, cameraPath);

_startTimeCode = std::min(_startTimeCode, frameId);
_endTimeCode = std::max(_endTimeCode, frameId);

UsdAttribute focalLengthAttr = camera.GetFocalLengthAttr();
UsdAttribute horizontalApertureAttr = camera.GetHorizontalApertureAttr();
UsdAttribute verticalApertureAttr = camera.GetVerticalApertureAttr();
UsdAttribute horizontalApertureOffsetAttr = camera.GetHorizontalApertureOffsetAttr();
UsdAttribute verticalApertureOffsetAttr = camera.GetVerticalApertureOffsetAttr();

horizontalApertureAttr.Set(static_cast<float>(intrinsic.sensorWidth()));
verticalApertureAttr.Set(static_cast<float>(intrinsic.sensorHeight()));

UsdTimeCode t(frameId);
double pixToMillimeters = intrinsic.sensorWidth() / intrinsic.w();

horizontalApertureOffsetAttr.Set(static_cast<float>(intrinsic.getOffset().x() * pixToMillimeters), t);
verticalApertureOffsetAttr.Set(static_cast<float>(intrinsic.getOffset().y() * pixToMillimeters), t);
focalLengthAttr.Set(static_cast<float>(intrinsic.getFocalLength()), t);



//Transform sfmData pose to usd pose
Eigen::Matrix4d glTransform = Eigen::Matrix4d::Identity();
glTransform(1, 1) = -1.0;
glTransform(2, 2) = -1.0;

// Inverse the pose and change the geometric frame
Eigen::Matrix4d camera_T_world = pose.getTransform().getHomogeneous();
Eigen::Matrix4d world_T_camera = camera_T_world.inverse();
Eigen::Matrix4d world_gl_T_camera_gl = glTransform * world_T_camera * glTransform;

//Copy element by element while transposing
GfMatrix4d usdT;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
usdT[j][i] = world_gl_T_camera_gl(i, j);
}
}

//Assign pose to motion
UsdGeomXformable xformable(camera);
bool dummy = false;
std::vector<UsdGeomXformOp> xformOps = xformable.GetOrderedXformOps(&dummy);


if (!xformOps.empty()) {
UsdGeomXformOp motion = xformOps[0];
motion.Set(usdT, t);
}
}

} // namespace sfmDataIO
} // namespace aliceVision
Loading
Loading