forked from PixarAnimationStudios/OpenUSD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Alembic Facesets as UsdGeomSubsets in usdAbc
This work is a continuation of Adam Ferrall-Nunge's work in PixarAnimationStudios#219, which added support for Alembic facesets to USD. At that time they were represented as Faceset data on the parent prim, which was subsequently read by pxrUsdIn and expanded back to faceset nodes. Since then, USD introduced the GeomSubset prim type. To a large extent this simplified the problem: The exact same hierarchy is maintained between Alembic and USD with only the type changing (Alembic "Faceset" to USD "GeomSubset"). pxrUsdIn already has support for GeomSubset, so there was no need to make any pxrUsdIn changes for Katana.
- Loading branch information
1 parent
1845291
commit 2125eab
Showing
5 changed files
with
300 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/pxrpythonsubst | ||
# | ||
# Copyright 2019 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. | ||
|
||
from pxr import Usd, UsdAbc, UsdGeom, Gf | ||
import unittest | ||
|
||
|
||
class TestUsdAbcFaceset(unittest.TestCase): | ||
def test_RoundTrip(self): | ||
usdFile = 'original.usda' | ||
abcFile = 'converted.abc' | ||
self.assertTrue(UsdAbc._WriteAlembic(usdFile, abcFile)) | ||
|
||
stage = Usd.Stage.Open(abcFile) | ||
prim = stage.GetPrimAtPath('/cube1') | ||
self.assertTrue(prim.IsValid()) | ||
|
||
faceset1prim = stage.GetPrimAtPath('/cube1/faceset1') | ||
faceset2prim = stage.GetPrimAtPath('/cube1/faceset2') | ||
self.assertTrue(faceset1prim.IsValid()) | ||
self.assertTrue(faceset2prim.IsValid()) | ||
|
||
faceset1 = UsdGeom.Subset(faceset1prim) | ||
faceset2 = UsdGeom.Subset(faceset2prim) | ||
|
||
self.assertEqual(faceset1.GetFamilyNameAttr().Get(), 'nonOverlapping') | ||
self.assertEqual(faceset2.GetFamilyNameAttr().Get(), 'nonOverlapping') | ||
|
||
self.assertEqual(faceset1.GetElementTypeAttr().Get(), 'face') | ||
self.assertEqual(faceset2.GetElementTypeAttr().Get(), 'face') | ||
|
||
# Validate the indices for faceset1 (which is animated) | ||
indices = faceset1.GetIndicesAttr() | ||
|
||
timeSamples = indices.GetTimeSamples() | ||
expectedTimeSamples = [0.0, 1.0] | ||
|
||
self.assertEqual(len(timeSamples), len(expectedTimeSamples)) | ||
|
||
for c, e in zip(timeSamples, expectedTimeSamples): | ||
self.assertTrue(Gf.IsClose(c, e, 1e-5)) | ||
|
||
expectedFaceIndices = {0.0: [0, 3, 5], 1.0: [3]} | ||
for time, expectedValue in expectedFaceIndices.iteritems(): | ||
faceIndices = indices.Get(time) | ||
for c, e in zip(faceIndices, expectedValue): | ||
self.assertEqual(c, e) | ||
|
||
# Validate the indices for faceset2 (which was constant, but promoted | ||
# to a single sample at 0 during conversion) | ||
indices = faceset2.GetIndicesAttr() | ||
|
||
timeSamples = indices.GetTimeSamples() | ||
expectedTimeSamples = [0.0] | ||
|
||
self.assertEqual(len(timeSamples), len(expectedTimeSamples)) | ||
|
||
for c, e in zip(timeSamples, expectedTimeSamples): | ||
self.assertTrue(Gf.IsClose(c, e, 1e-5)) | ||
|
||
expectedFaceIndices = {0.0: [1, 2, 4]} | ||
for time, expectedValue in expectedFaceIndices.items(): | ||
faceIndices = indices.Get(time) | ||
for c, e in zip(faceIndices, expectedValue): | ||
self.assertEqual(c, e) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
44 changes: 44 additions & 0 deletions
44
pxr/usd/plugin/usdAbc/testenv/testUsdAbcFaceset/original.usda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#usda 1.0 | ||
( | ||
defaultPrim = "cube1" | ||
upAxis = "Y" | ||
) | ||
|
||
def Mesh "cube1" | ||
{ | ||
float3[] extent = [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)] | ||
|
||
int[] faceVertexCounts = [4, 4, 4, 4, 4, 4] | ||
int[] faceVertexIndices = [2, 3, 1, 0, 6, 7, 3, 2, 4, 5, 7, 6, 0, 1, 5, 4, 3, 7, 5, 1, 6, 2, 0, 4] | ||
normal3f[] normals = [(0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 1, 0), (0, 1, 0), (0, 1, 0), (0, 1, 0), (0, 0, -1), (0, 0, -1), (0, 0, -1), (0, 0, -1), (0, -1, 0), (0, -1, 0), (0, -1, 0), (0, -1, 0), (1, 0, 0), (1, 0, 0), (1, 0, 0), (1, 0, 0), (-1, 0, 0), (-1, 0, 0), (-1, 0, 0), (-1, 0, 0)] ( | ||
interpolation = "faceVarying" | ||
) | ||
uniform token orientation = "leftHanded" | ||
point3f[] points = [(-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (-0.5, 0.5, 0.5), (0.5, 0.5, 0.5), (-0.5, -0.5, -0.5), (0.5, -0.5, -0.5), (-0.5, 0.5, -0.5), (0.5, 0.5, -0.5)] ( | ||
interpolation = "vertex" | ||
) | ||
float2[] primvars:uv = [(0, 1), (1, 1), (1, 0), (0, 0), (0, 2), (1, 2), (1, 1), (0, 1), (0, 3), (1, 3), (1, 2), (0, 2), (0, 4), (1, 4), (1, 3), (0, 3), (1, 1), (2, 1), (2, 0), (1, 0), (-1, 1), (0, 1), (0, 0), (-1, 0)] ( | ||
interpolation = "faceVarying" | ||
) | ||
uniform token subdivisionScheme = "none" | ||
|
||
int[] faceVertexCounts = [4, 4, 4, 4, 4, 4] | ||
|
||
def GeomSubset "faceset1" | ||
{ | ||
uniform token elementType = "face" | ||
uniform token familyName = "partition" | ||
int[] indices.timeSamples = { | ||
0: [0, 3, 5], | ||
1: [3], | ||
} | ||
} | ||
|
||
def GeomSubset "faceset2" | ||
{ | ||
uniform token elementType = "face" | ||
uniform token familyName = "partition" | ||
int[] indices = [1, 2, 4]; | ||
} | ||
|
||
} |