Add imaging support for UsdGeomTetMesh
authorklucknav <klucknav@users.noreply.github.com>
Sat, 3 Feb 2024 04:02:54 +0000 (20:02 -0800)
committerpixar-oss <pixar-oss@users.noreply.github.com>
Mon, 5 Feb 2024 20:21:02 +0000 (12:21 -0800)
(Internal change: 2314180)
(Internal change: 2314671)

pxr/usdImaging/usdImaging/CMakeLists.txt
pxr/usdImaging/usdImaging/plugInfo.json
pxr/usdImaging/usdImaging/tetMeshAdapter.cpp [new file with mode: 0644]
pxr/usdImaging/usdImaging/tetMeshAdapter.h [new file with mode: 0644]
pxr/usdImaging/usdImagingGL/CMakeLists.txt
pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/baseline/testUsdImagingGLTetMesh_000.png [new file with mode: 0644]
pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/baseline/testUsdImagingGLTetMesh_010.png [new file with mode: 0644]
pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/tetMesh.usda [new file with mode: 0644]

index c7f7e20615881a2f614074de65f3d25b7a66de47..58067500d1dbadea4648bdcbcf33c6dc12f317ba 100644 (file)
@@ -129,6 +129,7 @@ pxr_library(usdImaging
         sceneIndices
         sphereAdapter
         sphereLightAdapter
+        tetMeshAdapter
         textureUtils
         volumeAdapter
 
index 0143606c8addd3edac329a1d54511b2f2b928027..93d8eb78dccc02e080c61719525ac009590120ae 100644 (file)
                         "isInternal": true,
                         "primTypeName": "Mesh"
                     },
+                    "UsdImagingTetMeshAdapter": {
+                        "bases": [
+                            "UsdImagingGprimAdapter"
+                        ],
+                        "isInternal": true,
+                        "primTypeName": "TetMesh"
+                    },
                     "UsdImagingNurbsCurvesAdapter": {
                         "bases": [
                             "UsdImagingGprimAdapter"
diff --git a/pxr/usdImaging/usdImaging/tetMeshAdapter.cpp b/pxr/usdImaging/usdImaging/tetMeshAdapter.cpp
new file mode 100644 (file)
index 0000000..145aab0
--- /dev/null
@@ -0,0 +1,125 @@
+//
+// Copyright 2023 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/usdImaging/usdImaging/tetMeshAdapter.h"
+
+#include "pxr/usdImaging/usdImaging/dataSourceMesh.h"
+#include "pxr/usdImaging/usdImaging/indexProxy.h"
+#include "pxr/usdImaging/usdImaging/tokens.h"
+
+#include "pxr/imaging/hd/mesh.h"
+#include "pxr/imaging/hd/tokens.h"
+
+#include "pxr/imaging/pxOsd/meshTopology.h"
+#include "pxr/imaging/pxOsd/tokens.h"
+
+#include "pxr/base/tf/type.h"
+
+PXR_NAMESPACE_OPEN_SCOPE
+
+
+TF_REGISTRY_FUNCTION(TfType)
+{
+    using Adapter = UsdImagingTetMeshAdapter;
+    TfType t = TfType::Define<Adapter, TfType::Bases<Adapter::BaseAdapter> >();
+    t.SetFactory< UsdImagingPrimAdapterFactory<Adapter> >();
+}
+
+UsdImagingTetMeshAdapter::~UsdImagingTetMeshAdapter() = default;
+
+SdfPath
+UsdImagingTetMeshAdapter::Populate(UsdPrim const& prim,
+                            UsdImagingIndexProxy* index,
+                            UsdImagingInstancerContext const* instancerContext)
+{
+    return _AddRprim(HdPrimTypeTokens->mesh,
+                     prim, index, GetMaterialUsdPath(prim), instancerContext);
+}
+
+bool
+UsdImagingTetMeshAdapter::IsSupported(UsdImagingIndexProxy const* index) const
+{
+    return index->IsRprimTypeSupported(HdPrimTypeTokens->mesh);
+}
+
+void
+UsdImagingTetMeshAdapter::TrackVariability(UsdPrim const& prim,
+        SdfPath const& cachePath,
+        HdDirtyBits* timeVaryingBits,
+        UsdImagingInstancerContext const* instancerContext) const
+{
+    BaseAdapter::TrackVariability(
+        prim, cachePath, timeVaryingBits, instancerContext);
+
+    // Discover time-varying points.
+    _IsVarying(prim,
+               UsdGeomTokens->points,
+               HdChangeTracker::DirtyPoints,
+               UsdImagingTokens->usdVaryingPrimvar,
+               timeVaryingBits,
+               /*isInherited*/false);
+
+    _IsVarying(prim,
+            UsdGeomTokens->tetVertexIndices,
+            HdChangeTracker::DirtyTopology,
+            UsdImagingTokens->usdVaryingTopology,
+            timeVaryingBits,
+            /*isInherited*/false);
+}
+
+/*virtual*/ 
+VtValue
+UsdImagingTetMeshAdapter::GetTopology(UsdPrim const& prim,
+                                       SdfPath const& cachePath,
+                                       UsdTimeCode time) const
+{
+    TRACE_FUNCTION();
+    HF_MALLOC_TAG_FUNCTION();
+
+    // Compute the surfaceFaceIndices for the Tet Mesh
+    VtVec3iArray surfaceFaceIndices;
+    UsdGeomTetMesh::ComputeSurfaceFaces(
+        UsdGeomTetMesh(prim), &surfaceFaceIndices, time);
+
+    // Compute faceVertexIndices and faceVertexCounts for the HdMeshTopology
+    const size_t numCounts = surfaceFaceIndices.size();
+    VtIntArray faceVertexIndices;
+    VtIntArray faceVertexCounts(numCounts);
+    for (size_t i = 0; i < numCounts; ++i) {
+        faceVertexIndices.push_back(surfaceFaceIndices[i][0]);
+        faceVertexIndices.push_back(surfaceFaceIndices[i][1]);
+        faceVertexIndices.push_back(surfaceFaceIndices[i][2]);
+        faceVertexCounts[i] = 3;
+    }
+
+    // Create and return the HdMeshTopology
+    HdMeshTopology tetMeshTopology(
+        PxOsdOpenSubdivTokens->catmullClark,
+        _Get<TfToken>(prim, UsdGeomTokens->orientation, time),
+        faceVertexCounts,
+        faceVertexIndices);
+
+    return VtValue(tetMeshTopology);
+}
+
+
+PXR_NAMESPACE_CLOSE_SCOPE
\ No newline at end of file
diff --git a/pxr/usdImaging/usdImaging/tetMeshAdapter.h b/pxr/usdImaging/usdImaging/tetMeshAdapter.h
new file mode 100644 (file)
index 0000000..8e8b4e7
--- /dev/null
@@ -0,0 +1,91 @@
+//
+// Copyright 2023 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.
+//
+#ifndef PXR_USD_IMAGING_USD_IMAGING_TET_MESH_ADAPTER_H
+#define PXR_USD_IMAGING_USD_IMAGING_TET_MESH_ADAPTER_H
+
+/// \file usdImaging/tetMeshAdapter.h
+
+#include "pxr/pxr.h"
+#include "pxr/usdImaging/usdImaging/api.h"
+#include "pxr/usdImaging/usdImaging/primAdapter.h"
+#include "pxr/usdImaging/usdImaging/gprimAdapter.h"
+
+PXR_NAMESPACE_OPEN_SCOPE
+
+
+/// \class UsdImagingTetMeshAdapter
+///
+/// Delegate support for UsdGeomTetMesh.
+///
+class UsdImagingTetMeshAdapter : public UsdImagingGprimAdapter
+{
+public:
+    using BaseAdapter = UsdImagingGprimAdapter;
+
+    UsdImagingTetMeshAdapter()
+        : UsdImagingGprimAdapter()
+    {}
+
+    USDIMAGING_API
+    ~UsdImagingTetMeshAdapter() override;
+
+    // ---------------------------------------------------------------------- //
+    /// \name Initialization
+    // ---------------------------------------------------------------------- //
+
+    USDIMAGING_API
+    SdfPath Populate(
+        UsdPrim const& prim, 
+        UsdImagingIndexProxy* index,
+        UsdImagingInstancerContext const* instancerContext = nullptr) override;
+
+    USDIMAGING_API
+    bool IsSupported(UsdImagingIndexProxy const* index) const override;
+
+    // ---------------------------------------------------------------------- //
+    /// \name Parallel Setup and Resolve
+    // ---------------------------------------------------------------------- //
+
+    /// Thread Safe.
+    USDIMAGING_API
+    void TrackVariability(UsdPrim const& prim,
+                                  SdfPath const& cachePath,
+                                  HdDirtyBits* timeVaryingBits,
+                                  UsdImagingInstancerContext const* 
+                                      instancerContext = nullptr) const;
+
+    // ---------------------------------------------------------------------- //
+    /// \name Data access
+    // ---------------------------------------------------------------------- //
+
+    USDIMAGING_API
+    VtValue GetTopology(UsdPrim const& prim,
+                        SdfPath const& cachePath,
+                        UsdTimeCode time) const override;
+
+};
+
+PXR_NAMESPACE_CLOSE_SCOPE
+
+#endif // PXR_USD_IMAGING_USD_IMAGING_TET_MESH_ADAPTER_H
\ No newline at end of file
index 71c0d6efc6d449f2f18310f893ed3eecf4f3e5b6..9ffa1359588168dda279007ca8a20c4a2ffd1580 100644 (file)
@@ -279,6 +279,11 @@ pxr_install_test_dir(
     DEST testUsdImagingGLEmptyMesh
 )
 
+pxr_install_test_dir(
+    SRC testenv/testUsdImagingGLTetMesh
+    DEST testUsdImagingGLTetMesh
+)
+
 pxr_install_test_dir(
     SRC testenv/testUsdImagingGLPrimitiveDrawing
     DEST testUsdImagingGLPrimitiveDrawing
@@ -1250,6 +1255,18 @@ pxr_register_test(testUsdImagingGLEmptyMesh
     TESTENV testUsdImagingGLEmptyMesh
 )
 
+pxr_register_test(testUsdImagingGLTetMesh
+    COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdImagingGLBasicDrawing -lighting -offscreen -times 0 10 -stage tetMesh.usda -camera /Camera -write testUsdImagingGLTetMesh.png"
+    IMAGE_DIFF_COMPARE
+        testUsdImagingGLTetMesh_000.png
+        testUsdImagingGLTetMesh_010.png
+    FAIL 1
+    FAIL_PERCENT 1
+    PERCEPTUAL
+    EXPECTED_RETURN_CODE 0
+    TESTENV testUsdImagingGLTetMesh
+)
+
 pxr_register_test(testUsdImagingGLPrimitiveDrawing
     COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdImagingGLBasicDrawing -offscreen -frameAll -stage primitives.usda -write testUsdImagingGLPrimitiveDrawing.png"
     IMAGE_DIFF_COMPARE
diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/baseline/testUsdImagingGLTetMesh_000.png b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/baseline/testUsdImagingGLTetMesh_000.png
new file mode 100644 (file)
index 0000000..fe32c51
Binary files /dev/null and b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/baseline/testUsdImagingGLTetMesh_000.png differ
diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/baseline/testUsdImagingGLTetMesh_010.png b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/baseline/testUsdImagingGLTetMesh_010.png
new file mode 100644 (file)
index 0000000..cbb3c5f
Binary files /dev/null and b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/baseline/testUsdImagingGLTetMesh_010.png differ
diff --git a/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/tetMesh.usda b/pxr/usdImaging/usdImagingGL/testenv/testUsdImagingGLTetMesh/tetMesh.usda
new file mode 100644 (file)
index 0000000..8ad0302
--- /dev/null
@@ -0,0 +1,60 @@
+#usda 1.0
+(
+    upAxis = "Y"
+    endTimeCode = 15
+    startTimeCode = 0
+)
+
+def TetMesh "tetMesh1"
+{
+    color3f[] primvars:displayColor = [(0, 1, 0)]
+    point3f[] points.timeSamples = {
+        0: [(0, 0, 0), (2, 0, 0), (0, -2, 0), (0, 0, 2), (0, 0, -2)],
+        10: [(0, 0, 3), (2, 0, 3), (0, -2, 3), (0, 0, 5), (0, 0, -3), (2, 0, -3), (0, -2, -3), (0, 0, -5)],
+    }
+    int4[] tetVertexIndices.timeSamples = {
+        0: [(0, 1, 2, 3), (0, 2, 1, 4)],
+        10: [(0, 1, 2, 3), (4, 6, 5, 7)],
+    }
+    
+    double3 xformOp:translate = (-2.5, 0, 0)
+    float xformOp:rotateX:Zup = 90 
+    uniform token[] xformOpOrder = ["xformOp:rotateX:Zup","xformOp:translate"]
+}
+
+def TetMesh "tetMesh2"
+{
+    color3f[] primvars:displayColor = [(0, 0, 1)]
+    point3f[] points = [(0, 0, 0), (2, 0, 0), (0, -2, 0), (0, 0, 2), (0, 0, -2)]
+    int4[] tetVertexIndices = [(0, 1, 2, 3), (0, 2, 1, 4)]
+    
+    float xformOp:rotateX:Zup = 90 
+    uniform token[] xformOpOrder = ["xformOp:rotateX:Zup"]
+}
+
+def Mesh "regMesh"
+{
+    color3f[] primvars:displayColor = [(1, 0, 0)]
+    int[] faceVertexCounts.timeSamples = {
+        0: [3, 3, 3, 3, 3, 3],
+        10: [3, 3, 3, 3, 3, 3, 3, 3],
+    }
+    int[] faceVertexIndices.timeSamples = {
+        0: [0, 1, 3, 0, 2, 4, 0, 3, 2, 0, 4, 1, 1, 2, 3, 2, 1, 4],
+        10: [0, 1, 3, 0, 2, 1, 0, 3, 2, 1, 2, 3, 4, 5, 6, 4, 6, 7, 4, 7, 5, 6, 5, 7],
+    }
+    point3f[] points.timeSamples = {
+        0: [(0, 0, 0), (2, 0, 0), (0, -2, 0), (0, 0, 2), (0, 0, -2)],
+        10: [(0, 0, 3), (2, 0, 3), (0, -2, 3), (0, 0, 5), (0, 0, -3), (2, 0, -3), (0, -2, -3), (0, 0, -5)],
+    }
+    double3 xformOp:translate = (2.5, 0, 0)
+    float xformOp:rotateX:Zup = 90 
+    uniform token[] xformOpOrder = ["xformOp:rotateX:Zup","xformOp:translate"]
+}
+
+
+def Camera "Camera"
+{
+    double3 xformOp:translate = (1.25, 0, 35)
+    uniform token[] xformOpOrder = ["xformOp:translate"]
+}