Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache usdz archive traversal for subsequent lookup/queries on external references. #1578

Closed
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
4 changes: 2 additions & 2 deletions pxr/usd/ar/packageUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ _FindMatchingOpeningDelimiter(
{
size_t numOpenNeeded = 1;
std::string::const_reverse_iterator revIt(closingDelimIt);
for (; revIt != path.rend() && numOpenNeeded != 0; ++revIt) {
for (const auto rend = path.rend(); revIt != rend && numOpenNeeded != 0; ++revIt) {
if (*revIt == '[' || *revIt == ']') {
// Ignore this delimiter if it's been escaped.
auto prevCharIt = revIt + 1;
if (prevCharIt != path.rend() && *prevCharIt == '\\') {
if (prevCharIt != rend && *prevCharIt == '\\') {
continue;
}
numOpenNeeded += (*revIt == '[') ? -1 : 1;
Expand Down
18 changes: 18 additions & 0 deletions pxr/usd/usd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ pxr_build_test(testUsdUsdzResolver
testenv/testUsdUsdzResolver.cpp
)

pxr_build_test(testUsdUsdzLargeArchive
LIBRARIES
tf
usd
usdGeom
CPPFILES
testenv/testUsdUsdzLargeArchive.cpp
)

pxr_install_test_dir(
SRC testenv/testUsdAppliedAPISchemas
DEST testUsdAppliedAPISchemas
Expand Down Expand Up @@ -646,6 +655,11 @@ pxr_install_test_dir(
DEST testUsdZipFile
)

pxr_install_test_dir(
SRC testenv/testUsdUsdzLargeArchive
DEST testUsdUsdzLargeArchive
)

pxr_register_test(testUsdAppliedAPISchemas
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdAppliedAPISchemas"
Expand Down Expand Up @@ -1084,3 +1098,7 @@ pxr_register_test(testUsdUsdzResolver
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUsdzResolver"
EXPECTED_RETURN_CODE 0
)
pxr_register_test(testUsdUsdzLargeArchive
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdUsdzLargeArchive"
EXPECTED_RETURN_CODE 0
)
106 changes: 106 additions & 0 deletions pxr/usd/usd/testenv/testUsdUsdzLargeArchive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// Copyright 2021 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//

#include "pxr/pxr.h"

#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdGeom/mesh.h"

#include <ctime>
#include <iostream>

PXR_NAMESPACE_USING_DIRECTIVE;

static bool
AttributesEqual(UsdAttribute a, UsdAttribute b)
{
if (a.IsValid() != b.IsValid()) {
return false;
}
if (!a.IsValid()) {
return true;
}
VtValue va, vb;
if (!a.Get(&va) || !b.Get(&vb)) {
return false;
}
return va == vb;
}

// Test that calling ArResolver::OpenAsset on a file within a .usdz
// file produces the expected result.
static void
TestOpenLargeArchive()
{
std::cout << "TestOpenLargeArchive...";
const std::string usdzFile("test.usdz");
const auto startTime = std::clock();
auto stage = UsdStage::Open(usdzFile);
const auto endTime = std::clock();

// Testing the time to open is possibly not the greatest, but the file in question
// took over 15 seconds without caching, and less than 2.5 seconds with;
// So conservatively, we should be able to open it in 5 seconds in processor time ?
//
const auto elapsedTime = float(endTime - startTime) / CLOCKS_PER_SEC;
std::cout << "stage creation took " << elapsedTime << std::endl;

if (!stage) {
TF_FATAL_ERROR("Failed to load stage at '%s'", usdzFile.c_str());
}
if (elapsedTime > 5.f) {
TF_FATAL_ERROR("Open of '%s' took %f seconds in proc time", usdzFile.c_str(), elapsedTime);
}

UsdPrim scene = stage->GetPrimAtPath(SdfPath("/scene"));
TF_AXIOM(scene);

UsdGeomMesh baseMesh;
size_t numChildren = 0;
for (UsdPrim child : scene.GetAllChildren()) {
TF_AXIOM(child.IsA<UsdGeomMesh>());

UsdGeomMesh mesh(child);
if (baseMesh) {
TF_AXIOM(AttributesEqual(baseMesh.GetFaceVertexCountsAttr(), mesh.GetFaceVertexCountsAttr()));
TF_AXIOM(AttributesEqual(baseMesh.GetFaceVertexIndicesAttr(), mesh.GetFaceVertexIndicesAttr()));
TF_AXIOM(AttributesEqual(baseMesh.GetPointsAttr(), mesh.GetPointsAttr()));
TF_AXIOM(AttributesEqual(baseMesh.GetSubdivisionSchemeAttr(), mesh.GetSubdivisionSchemeAttr()));
}
else {
baseMesh = std::move(mesh);
}
++numChildren;
}
TF_AXIOM(numChildren == 25000);
}

int main(int argc, char** argv)
{
TestOpenLargeArchive();

std::cout << "Passed!" << std::endl;

return EXIT_SUCCESS;
}
Binary file not shown.
Loading