diff --git a/models/simple-skin-test-002.usda b/models/simple-skin-test-002.usda new file mode 100755 index 00000000..9deba940 --- /dev/null +++ b/models/simple-skin-test-002.usda @@ -0,0 +1,85 @@ +#usda 1.0 +( + defaultPrim = "root" + doc = "Blender v4.1.0" + metersPerUnit = 1 + upAxis = "Z" +) + +def Xform "root" ( + customData = { + dictionary Blender = { + bool generated = 1 + } + } +) +{ + def SkelRoot "Armature" + { + matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, -4.371138828673793e-8, -1, 0), (0, 1, -4.371138828673793e-8, 0), (0, -1.6482605934143066, 0, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform"] + + def Skeleton "Armature" ( + prepend apiSchemas = ["SkelBindingAPI"] + ) + { + uniform matrix4d[] bindTransforms = [( (1, 0, 0, 0), (0, 0, 1, 0), (0, -1, 0, 0), (0, 0, 0, 1) ), ( (1, 0, 0, 0), (0, 0, 1, 0), (0, -1, 0, 0), (0, 0, 1, 1) ), ( (1, 0, 0, 0), (0, 0, 1, 0), (0, -1, 0, 0), (0, 0, 2.353059768676758, 1) )] + uniform token[] joints = ["Bone", "Bone/Bone_001", "Bone/Bone_001/Bone_002"] + uniform matrix4d[] restTransforms = [( (1, 0, 0, 0), (0, 0, 1, 0), (0, -1, 0, 0), (0, 0, 0, 1) ), ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 1, 0, 1) ), ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 1.3530597686767578, 0, 1) )] + } + + def Xform "Grid" + { + matrix4d xformOp:transform = ( (2.5, 0, 0, 0), (0, -1.092784742695585e-7, 2.5, 0), (0, -1, -4.371138828673793e-8, 0), (0, -7.204776153457715e-8, 1.6482605934143066, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform"] + + def Mesh "Grid" ( + prepend apiSchemas = ["SkelBindingAPI"] + ) + { + float3[] extent = [(-1, -1, 0), (1, 1, 0)] + int[] faceVertexCounts = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4] + int[] faceVertexIndices = [0, 1, 12, 11, 1, 2, 13, 12, 2, 3, 14, 13, 3, 4, 15, 14, 4, 5, 16, 15, 5, 6, 17, 16, 6, 7, 18, 17, 7, 8, 19, 18, 8, 9, 20, 19, 9, 10, 21, 20, 11, 12, 23, 22, 12, 13, 24, 23, 13, 14, 25, 24, 14, 15, 26, 25, 15, 16, 27, 26, 16, 17, 28, 27, 17, 18, 29, 28, 18, 19, 30, 29, 19, 20, 31, 30, 20, 21, 32, 31, 22, 23, 34, 33, 23, 24, 35, 34, 24, 25, 36, 35, 25, 26, 37, 36, 26, 27, 38, 37, 27, 28, 39, 38, 28, 29, 40, 39, 29, 30, 41, 40, 30, 31, 42, 41, 31, 32, 43, 42, 33, 34, 45, 44, 34, 35, 46, 45, 35, 36, 47, 46, 36, 37, 48, 47, 37, 38, 49, 48, 38, 39, 50, 49, 39, 40, 51, 50, 40, 41, 52, 51, 41, 42, 53, 52, 42, 43, 54, 53, 44, 45, 56, 55, 45, 46, 57, 56, 46, 47, 58, 57, 47, 48, 59, 58, 48, 49, 60, 59, 49, 50, 61, 60, 50, 51, 62, 61, 51, 52, 63, 62, 52, 53, 64, 63, 53, 54, 65, 64, 55, 56, 67, 66, 56, 57, 68, 67, 57, 58, 69, 68, 58, 59, 70, 69, 59, 60, 71, 70, 60, 61, 72, 71, 61, 62, 73, 72, 62, 63, 74, 73, 63, 64, 75, 74, 64, 65, 76, 75, 66, 67, 78, 77, 67, 68, 79, 78, 68, 69, 80, 79, 69, 70, 81, 80, 70, 71, 82, 81, 71, 72, 83, 82, 72, 73, 84, 83, 73, 74, 85, 84, 74, 75, 86, 85, 75, 76, 87, 86, 77, 78, 89, 88, 78, 79, 90, 89, 79, 80, 91, 90, 80, 81, 92, 91, 81, 82, 93, 92, 82, 83, 94, 93, 83, 84, 95, 94, 84, 85, 96, 95, 85, 86, 97, 96, 86, 87, 98, 97, 88, 89, 100, 99, 89, 90, 101, 100, 90, 91, 102, 101, 91, 92, 103, 102, 92, 93, 104, 103, 93, 94, 105, 104, 94, 95, 106, 105, 95, 96, 107, 106, 96, 97, 108, 107, 97, 98, 109, 108, 99, 100, 111, 110, 100, 101, 112, 111, 101, 102, 113, 112, 102, 103, 114, 113, 103, 104, 115, 114, 104, 105, 116, 115, 105, 106, 117, 116, 106, 107, 118, 117, 107, 108, 119, 118, 108, 109, 120, 119] + normal3f[] normals = [(0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 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, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1)] ( + interpolation = "faceVarying" + ) + point3f[] points = [(-1, -1, 0), (-0.8, -1, 0), (-0.6, -1, 0), (-0.39999998, -1, 0), (-0.19999999, -1, 0), (0, -1, 0), (0.20000005, -1, 0), (0.39999998, -1, 0), (0.6, -1, 0), (0.8000001, -1, 0), (1, -1, 0), (-1, -0.8, 0), (-0.8, -0.8, 0), (-0.6, -0.8, 0), (-0.39999998, -0.8, 0), (-0.19999999, -0.8, 0), (0, -0.8, 0), (0.20000005, -0.8, 0), (0.39999998, -0.8, 0), (0.6, -0.8, 0), (0.8000001, -0.8, 0), (1, -0.8, 0), (-1, -0.6, 0), (-0.8, -0.6, 0), (-0.6, -0.6, 0), (-0.39999998, -0.6, 0), (-0.19999999, -0.6, 0), (0, -0.6, 0), (0.20000005, -0.6, 0), (0.39999998, -0.6, 0), (0.6, -0.6, 0), (0.8000001, -0.6, 0), (1, -0.6, 0), (-1, -0.39999998, 0), (-0.8, -0.39999998, 0), (-0.6, -0.39999998, 0), (-0.39999998, -0.39999998, 0), (-0.19999999, -0.39999998, 0), (0, -0.39999998, 0), (0.20000005, -0.39999998, 0), (0.39999998, -0.39999998, 0), (0.6, -0.39999998, 0), (0.8000001, -0.39999998, 0), (1, -0.39999998, 0), (-1, -0.19999999, 0), (-0.8, -0.19999999, 0), (-0.6, -0.19999999, 0), (-0.39999998, -0.19999999, 0), (-0.19999999, -0.19999999, 0), (0, -0.19999999, 0), (0.20000005, -0.19999999, 0), (0.39999998, -0.19999999, 0), (0.6, -0.19999999, 0), (0.8000001, -0.19999999, 0), (1, -0.19999999, 0), (-1, 0, 0), (-0.8, 0, 0), (-0.6, 0, 0), (-0.39999998, 0, 0), (-0.19999999, 0, 0), (0, 0, 0), (0.20000005, 0, 0), (0.39999998, 0, 0), (0.6, 0, 0), (0.8000001, 0, 0), (1, 0, 0), (-1, 0.20000005, 0), (-0.8, 0.20000005, 0), (-0.6, 0.20000005, 0), (-0.39999998, 0.20000005, 0), (-0.19999999, 0.20000005, 0), (0, 0.20000005, 0), (0.20000005, 0.20000005, 0), (0.39999998, 0.20000005, 0), (0.6, 0.20000005, 0), (0.8000001, 0.20000005, 0), (1, 0.20000005, 0), (-1, 0.39999998, 0), (-0.8, 0.39999998, 0), (-0.6, 0.39999998, 0), (-0.39999998, 0.39999998, 0), (-0.19999999, 0.39999998, 0), (0, 0.39999998, 0), (0.20000005, 0.39999998, 0), (0.39999998, 0.39999998, 0), (0.6, 0.39999998, 0), (0.8000001, 0.39999998, 0), (1, 0.39999998, 0), (-1, 0.6, 0), (-0.8, 0.6, 0), (-0.6, 0.6, 0), (-0.39999998, 0.6, 0), (-0.19999999, 0.6, 0), (0, 0.6, 0), (0.20000005, 0.6, 0), (0.39999998, 0.6, 0), (0.6, 0.6, 0), (0.8000001, 0.6, 0), (1, 0.6, 0), (-1, 0.8000001, 0), (-0.8, 0.8000001, 0), (-0.6, 0.8000001, 0), (-0.39999998, 0.8000001, 0), (-0.19999999, 0.8000001, 0), (0, 0.8000001, 0), (0.20000005, 0.8000001, 0), (0.39999998, 0.8000001, 0), (0.6, 0.8000001, 0), (0.8000001, 0.8000001, 0), (1, 0.8000001, 0), (-1, 1, 0), (-0.8, 1, 0), (-0.6, 1, 0), (-0.39999998, 1, 0), (-0.19999999, 1, 0), (0, 1, 0), (0.20000005, 1, 0), (0.39999998, 1, 0), (0.6, 1, 0), (0.8000001, 1, 0), (1, 1, 0)] + bool[] primvars:sharp_face = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ( + interpolation = "uniform" + ) + matrix4d primvars:skel:geomBindTransform = ( (2.5, 0, 0, 0), (0, -1.092784742695585e-7, 2.5, 0), (0, -1, -4.371138828673793e-8, 0), (0, -7.204776153457714e-8, 1.6482605934143064, 1) ) + int[] primvars:skel:jointIndices = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 0, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 0, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 0, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 2, 0, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 2, 0, 2, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2] ( + elementSize = 3 + interpolation = "vertex" + ) + float[] primvars:skel:jointWeights = [0.71452814, 0.204105, 0.081366844, 0.7401806, 0.18752068, 0.072298735, 0.7844931, 0.15820847, 0.057298444, 0.8488479, 0.12084445, 0.030307641, 0.9160761, 0.08321627, 0.0007075891, 0.9368209, 0.06317909, 0, 0.9160761, 0.083216295, 0.0007075853, 0.8488479, 0.120844476, 0.030307604, 0.7844931, 0.1582085, 0.05729842, 0.74018055, 0.18752073, 0.07229871, 0.71452814, 0.20410506, 0.08136681, 0.6863128, 0.22252177, 0.09116545, 0.71463394, 0.20521887, 0.080147214, 0.76386565, 0.17412813, 0.06200622, 0.83968514, 0.12948035, 0.030834466, 0.9262034, 0.073796585, 0, 0.98093307, 0.019066913, 0, 0.92620337, 0.073796615, 0, 0.8396852, 0.12948039, 0.03083444, 0.76386565, 0.17412817, 0.0620062, 0.7146339, 0.2052189, 0.080147184, 0.6863128, 0.22252181, 0.09116542, 0.623612, 0.26261422, 0.11377381, 0.65084183, 0.24917112, 0.09998709, 0.69990355, 0.2232409, 0.0768556, 0.77845085, 0.17577292, 0.045776192, 0.90417856, 0.095821425, 0, 1, 0, 0, 0.9041785, 0.09582148, 0, 0.77845085, 0.17577296, 0.045776173, 0.6999035, 0.22324093, 0.07685557, 0.6508418, 0.24917117, 0.09998705, 0.623612, 0.26261428, 0.11377376, 0.5261385, 0.3214126, 0.15244891, 0.54335177, 0.32121485, 0.13543342, 0.5747275, 0.31912547, 0.106147036, 0.6325978, 0.30003127, 0.067370914, 0.7695054, 0.22798856, 0.0025060356, 1, 0, 0, 0.7695053, 0.22798865, 0.0025060547, 0.6325978, 0.30003133, 0.06737091, 0.5747275, 0.31912553, 0.10614702, 0.5433517, 0.32121488, 0.13543338, 0.52613854, 0.32141268, 0.15244886, 0.40195563, 0.38684985, 0.21119457, 0.3931016, 0.4152662, 0.19163214, 0.3757099, 0.46754423, 0.15674597, 0.335652, 0.5581968, 0.106151186, 0.23700586, 0.72288525, 0.040108945, 1, 0, 0, 0.23700586, 0.72288513, 0.040108982, 0.33565196, 0.55819684, 0.10615117, 0.3757098, 0.46754423, 0.15674593, 0.39310157, 0.41526625, 0.19163209, 0.4019556, 0.3868499, 0.21119449, 0.29468194, 0.4115832, 0.29373497, 0.27600732, 0.448837, 0.27515563, 0.24118742, 0.5183081, 0.24050447, 0.18257143, 0.635303, 0.18212552, 0.09265959, 0.8148586, 0.09248185, 1, 0, 0, 0.092659615, 0.81485856, 0.09248189, 0.18257141, 0.6353031, 0.18212551, 0.2411874, 0.51830816, 0.24050443, 0.27600732, 0.4488371, 0.2751556, 0.2946819, 0.41158327, 0.29373488, 0.21198818, 0.38727075, 0.40074116, 0.19234331, 0.41567397, 0.39198264, 0.15731324, 0.4679197, 0.374767, 0.106520906, 0.55849195, 0.33498713, 0.040402245, 0.722923, 0.23667476, 1, 0, 0, 0.040402267, 0.7229229, 0.2366748, 0.1065209, 0.558492, 0.33498716, 0.15731323, 0.4679198, 0.37476698, 0.19234335, 0.4156741, 0.39198264, 0.21198817, 0.38727084, 0.40074104, 0.15318756, 0.3222759, 0.52453655, 0.13611011, 0.32207507, 0.5418148, 0.10671558, 0.31996664, 0.57331777, 0.06778035, 0.30076495, 0.6314547, 0.002909995, 0.2283845, 0.7687055, 1, 0, 0, 0.0029100063, 0.22838452, 0.7687055, 0.06778034, 0.30076498, 0.6314547, 0.10671557, 0.3199667, 0.5733177, 0.13611011, 0.32207516, 0.54181474, 0.15318753, 0.322276, 0.52453643, 0.11453424, 0.26394036, 0.62152547, 0.100717895, 0.25055367, 0.6487285, 0.07753962, 0.22472976, 0.6977306, 0.046959527, 0.17721938, 0.7758211, 0.09716844, 0.90283155, 0, 1, 0, 0, 0.097168475, 0.90283155, 0, 0.046959497, 0.17721939, 0.77582115, 0.07753961, 0.22472985, 0.69773054, 0.10071788, 0.25055376, 0.6487283, 0.11453422, 0.26394045, 0.62152535, 0.09199252, 0.2242808, 0.68372667, 0.08099504, 0.20716038, 0.71184456, 0.06291457, 0.17647527, 0.7606101, 0.03291412, 0.13245848, 0.8346274, 0.07841547, 0.92158455, 0, 0.031303994, 0.96869606, 0, 0.0784155, 0.9215845, 0, 0.032914095, 0.13245852, 0.8346274, 0.062914565, 0.17647532, 0.7606101, 0.080995046, 0.20716049, 0.71184444, 0.09199251, 0.22428092, 0.68372655, 0.082243025, 0.20611735, 0.7116397, 0.073220745, 0.18977642, 0.7370029, 0.05832198, 0.16097036, 0.7807076, 0.032688748, 0.12429418, 0.84301704, 0.0036484797, 0.087782755, 0.90856874, 0.06865118, 0.9313488, 0, 0.0036484685, 0.08778278, 0.90856874, 0.03268872, 0.124294214, 0.84301704, 0.058321975, 0.16097042, 0.7807076, 0.07322074, 0.1897765, 0.73700273, 0.08224301, 0.2061174, 0.7116396] ( + elementSize = 3 + interpolation = "vertex" + ) + texCoord2f[] primvars:UVMap = [(0, 0), (0.1, 0), (0.1, 0.1), (0, 0.1), (0.1, 0), (0.2, 0), (0.2, 0.1), (0.1, 0.1), (0.2, 0), (0.3, 0), (0.3, 0.1), (0.20000002, 0.1), (0.3, 0), (0.4, 0), (0.4, 0.1), (0.3, 0.1), (0.4, 0), (0.5, 0), (0.5, 0.1), (0.4, 0.1), (0.5, 0), (0.6, 0), (0.6, 0.1), (0.5, 0.1), (0.6, 0), (0.70000005, 0), (0.70000005, 0.1), (0.6, 0.1), (0.70000005, 0), (0.8000001, 0), (0.8000001, 0.1), (0.70000005, 0.1), (0.8000001, 0), (0.9000001, 0), (0.9000001, 0.1), (0.8000001, 0.1), (0.9000001, 0), (1.0000001, 0), (1.0000001, 0.1), (0.9000001, 0.1), (0, 0.1), (0.1, 0.1), (0.1, 0.2), (0, 0.2), (0.1, 0.1), (0.2, 0.1), (0.2, 0.2), (0.1, 0.2), (0.2, 0.1), (0.3, 0.1), (0.3, 0.2), (0.20000002, 0.2), (0.3, 0.1), (0.4, 0.1), (0.4, 0.2), (0.3, 0.2), (0.4, 0.1), (0.5, 0.1), (0.5, 0.2), (0.4, 0.2), (0.5, 0.1), (0.6, 0.1), (0.6, 0.2), (0.5, 0.2), (0.6, 0.1), (0.70000005, 0.1), (0.70000005, 0.2), (0.6, 0.2), (0.70000005, 0.1), (0.8000001, 0.1), (0.8000001, 0.2), (0.70000005, 0.2), (0.8000001, 0.1), (0.9000001, 0.1), (0.9000001, 0.2), (0.8000001, 0.2), (0.9000001, 0.1), (1.0000001, 0.1), (1.0000001, 0.2), (0.9000001, 0.2), (0, 0.20000002), (0.1, 0.20000002), (0.1, 0.3), (0, 0.3), (0.1, 0.20000002), (0.2, 0.20000002), (0.2, 0.3), (0.1, 0.3), (0.2, 0.20000002), (0.3, 0.20000002), (0.3, 0.3), (0.20000002, 0.3), (0.3, 0.20000002), (0.4, 0.20000002), (0.4, 0.3), (0.3, 0.3), (0.4, 0.20000002), (0.5, 0.20000002), (0.5, 0.3), (0.4, 0.3), (0.5, 0.20000002), (0.6, 0.20000002), (0.6, 0.3), (0.5, 0.3), (0.6, 0.20000002), (0.70000005, 0.20000002), (0.70000005, 0.3), (0.6, 0.3), (0.70000005, 0.20000002), (0.8000001, 0.20000002), (0.8000001, 0.3), (0.70000005, 0.3), (0.8000001, 0.20000002), (0.9000001, 0.20000002), (0.9000001, 0.3), (0.8000001, 0.3), (0.9000001, 0.20000002), (1.0000001, 0.20000002), (1.0000001, 0.3), (0.9000001, 0.3), (0, 0.3), (0.1, 0.3), (0.1, 0.4), (0, 0.4), (0.1, 0.3), (0.2, 0.3), (0.2, 0.4), (0.1, 0.4), (0.2, 0.3), (0.3, 0.3), (0.3, 0.4), (0.20000002, 0.4), (0.3, 0.3), (0.4, 0.3), (0.4, 0.4), (0.3, 0.4), (0.4, 0.3), (0.5, 0.3), (0.5, 0.4), (0.4, 0.4), (0.5, 0.3), (0.6, 0.3), (0.6, 0.4), (0.5, 0.4), (0.6, 0.3), (0.70000005, 0.3), (0.70000005, 0.4), (0.6, 0.4), (0.70000005, 0.3), (0.8000001, 0.3), (0.8000001, 0.4), (0.70000005, 0.4), (0.8000001, 0.3), (0.9000001, 0.3), (0.9000001, 0.4), (0.8000001, 0.4), (0.9000001, 0.3), (1.0000001, 0.3), (1.0000001, 0.4), (0.9000001, 0.4), (0, 0.4), (0.1, 0.4), (0.1, 0.5), (0, 0.5), (0.1, 0.4), (0.2, 0.4), (0.2, 0.5), (0.1, 0.5), (0.2, 0.4), (0.3, 0.4), (0.3, 0.5), (0.20000002, 0.5), (0.3, 0.4), (0.4, 0.4), (0.4, 0.5), (0.3, 0.5), (0.4, 0.4), (0.5, 0.4), (0.5, 0.5), (0.4, 0.5), (0.5, 0.4), (0.6, 0.4), (0.6, 0.5), (0.5, 0.5), (0.6, 0.4), (0.70000005, 0.4), (0.70000005, 0.5), (0.6, 0.5), (0.70000005, 0.4), (0.8000001, 0.4), (0.8000001, 0.5), (0.70000005, 0.5), (0.8000001, 0.4), (0.9000001, 0.4), (0.9000001, 0.5), (0.8000001, 0.5), (0.9000001, 0.4), (1.0000001, 0.4), (1.0000001, 0.5), (0.9000001, 0.5), (0, 0.5), (0.1, 0.5), (0.1, 0.6), (0, 0.6), (0.1, 0.5), (0.2, 0.5), (0.2, 0.6), (0.1, 0.6), (0.2, 0.5), (0.3, 0.5), (0.3, 0.6), (0.20000002, 0.6), (0.3, 0.5), (0.4, 0.5), (0.4, 0.6), (0.3, 0.6), (0.4, 0.5), (0.5, 0.5), (0.5, 0.6), (0.4, 0.6), (0.5, 0.5), (0.6, 0.5), (0.6, 0.6), (0.5, 0.6), (0.6, 0.5), (0.70000005, 0.5), (0.70000005, 0.6), (0.6, 0.6), (0.70000005, 0.5), (0.8000001, 0.5), (0.8000001, 0.6), (0.70000005, 0.6), (0.8000001, 0.5), (0.9000001, 0.5), (0.9000001, 0.6), (0.8000001, 0.6), (0.9000001, 0.5), (1.0000001, 0.5), (1.0000001, 0.6), (0.9000001, 0.6), (0, 0.6), (0.1, 0.6), (0.1, 0.70000005), (0, 0.70000005), (0.1, 0.6), (0.2, 0.6), (0.2, 0.70000005), (0.1, 0.70000005), (0.2, 0.6), (0.3, 0.6), (0.3, 0.70000005), (0.20000002, 0.70000005), (0.3, 0.6), (0.4, 0.6), (0.4, 0.70000005), (0.3, 0.70000005), (0.4, 0.6), (0.5, 0.6), (0.5, 0.70000005), (0.4, 0.70000005), (0.5, 0.6), (0.6, 0.6), (0.6, 0.70000005), (0.5, 0.70000005), (0.6, 0.6), (0.70000005, 0.6), (0.70000005, 0.70000005), (0.6, 0.70000005), (0.70000005, 0.6), (0.8000001, 0.6), (0.8000001, 0.70000005), (0.70000005, 0.70000005), (0.8000001, 0.6), (0.9000001, 0.6), (0.9000001, 0.70000005), (0.8000001, 0.70000005), (0.9000001, 0.6), (1.0000001, 0.6), (1.0000001, 0.70000005), (0.9000001, 0.70000005), (0, 0.70000005), (0.1, 0.70000005), (0.1, 0.8000001), (0, 0.8000001), (0.1, 0.70000005), (0.2, 0.70000005), (0.2, 0.8000001), (0.1, 0.8000001), (0.2, 0.70000005), (0.3, 0.70000005), (0.3, 0.8000001), (0.20000002, 0.8000001), (0.3, 0.70000005), (0.4, 0.70000005), (0.4, 0.8000001), (0.3, 0.8000001), (0.4, 0.70000005), (0.5, 0.70000005), (0.5, 0.8000001), (0.4, 0.8000001), (0.5, 0.70000005), (0.6, 0.70000005), (0.6, 0.8000001), (0.5, 0.8000001), (0.6, 0.70000005), (0.70000005, 0.70000005), (0.70000005, 0.8000001), (0.6, 0.8000001), (0.70000005, 0.70000005), (0.8000001, 0.70000005), (0.8000001, 0.8000001), (0.70000005, 0.8000001), (0.8000001, 0.70000005), (0.9000001, 0.70000005), (0.9000001, 0.8000001), (0.8000001, 0.8000001), (0.9000001, 0.70000005), (1.0000001, 0.70000005), (1.0000001, 0.8000001), (0.9000001, 0.8000001), (0, 0.8000001), (0.1, 0.8000001), (0.1, 0.9000001), (0, 0.9000001), (0.1, 0.8000001), (0.2, 0.8000001), (0.2, 0.9000001), (0.1, 0.9000001), (0.2, 0.8000001), (0.3, 0.8000001), (0.3, 0.9000001), (0.20000002, 0.9000001), (0.3, 0.8000001), (0.4, 0.8000001), (0.4, 0.9000001), (0.3, 0.9000001), (0.4, 0.8000001), (0.5, 0.8000001), (0.5, 0.9000001), (0.4, 0.9000001), (0.5, 0.8000001), (0.6, 0.8000001), (0.6, 0.9000001), (0.5, 0.9000001), (0.6, 0.8000001), (0.70000005, 0.8000001), (0.70000005, 0.9000001), (0.6, 0.9000001), (0.70000005, 0.8000001), (0.8000001, 0.8000001), (0.8000001, 0.9000001), (0.70000005, 0.9000001), (0.8000001, 0.8000001), (0.9000001, 0.8000001), (0.9000001, 0.9000001), (0.8000001, 0.9000001), (0.9000001, 0.8000001), (1.0000001, 0.8000001), (1.0000001, 0.9000001), (0.9000001, 0.9000001), (0, 0.9000001), (0.1, 0.9000001), (0.1, 1.0000001), (0, 1.0000001), (0.1, 0.9000001), (0.2, 0.9000001), (0.2, 1.0000001), (0.1, 1.0000001), (0.2, 0.9000001), (0.3, 0.9000001), (0.3, 1.0000001), (0.20000002, 1.0000001), (0.3, 0.9000001), (0.4, 0.9000001), (0.4, 1.0000001), (0.3, 1.0000001), (0.4, 0.9000001), (0.5, 0.9000001), (0.5, 1.0000001), (0.4, 1.0000001), (0.5, 0.9000001), (0.6, 0.9000001), (0.6, 1.0000001), (0.5, 1.0000001), (0.6, 0.9000001), (0.70000005, 0.9000001), (0.70000005, 1.0000001), (0.6, 1.0000001), (0.70000005, 0.9000001), (0.8000001, 0.9000001), (0.8000001, 1.0000001), (0.70000005, 1.0000001), (0.8000001, 0.9000001), (0.9000001, 0.9000001), (0.9000001, 1.0000001), (0.8000001, 1.0000001), (0.9000001, 0.9000001), (1.0000001, 0.9000001), (1.0000001, 1.0000001), (0.9000001, 1.0000001)] ( + interpolation = "faceVarying" + ) + rel skel:skeleton = + uniform token subdivisionScheme = "none" + } + } + } + + def Xform "Camera" + { + matrix4d xformOp:transform = ( (0.6859206557273865, 0.7276763319969177, 0, 0), (-0.32401347160339355, 0.305420845746994, 0.8953956365585327, 0), (0.6515582203865051, -0.6141703724861145, 0.44527140259742737, 0), (7.358891487121582, -6.925790786743164, 4.958309173583984, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform"] + + def Camera "Camera" + { + float2 clippingRange = (0.1, 100) + float focalLength = 0.5 + float horizontalAperture = 0.36 + float horizontalApertureOffset = 0 + token projection = "perspective" + float verticalAperture = 0.2025 + float verticalApertureOffset = 0 + } + } +} + diff --git a/models/uv-tex-facevarying-002.usda b/models/uv-tex-facevarying-002.usda new file mode 100644 index 00000000..fdc84218 --- /dev/null +++ b/models/uv-tex-facevarying-002.usda @@ -0,0 +1,104 @@ +#usda 1.0 +# uvmap has different UV value in shared vertex, so vertex index rebuild is requierd in Tydra RenderMesh. +( + defaultPrim = "root" + doc = "Blender v4.1.0" + metersPerUnit = 1 + upAxis = "Z" +) + +def Xform "root" ( + customData = { + dictionary Blender = { + bool generated = 1 + } + } +) +{ + def Xform "Camera" + { + matrix4d xformOp:transform = ( (0.6859206557273865, 0.7276763319969177, 0, 0), (-0.32401347160339355, 0.305420845746994, 0.8953956365585327, 0), (0.6515582203865051, -0.6141703724861145, 0.44527140259742737, 0), (7.358891487121582, -6.925790786743164, 4.958309173583984, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform"] + + def Camera "Camera" + { + float2 clippingRange = (0.1, 100) + float focalLength = 0.5 + float horizontalAperture = 0.36 + float horizontalApertureOffset = 0 + token projection = "perspective" + float verticalAperture = 0.2025 + float verticalApertureOffset = 0 + } + } + + def Xform "Grid" + { + matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform"] + + def Mesh "Grid" ( + prepend apiSchemas = ["MaterialBindingAPI"] + ) + { + uniform bool doubleSided = 1 + float3[] extent = [(-1, -1, 0), (1, 1, 0)] + int[] faceVertexCounts = [4, 4] + int[] faceVertexIndices = [0, 1, 3, 2, 2, 3, 5, 4] + rel material:binding = + normal3f[] normals = [(0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1)] ( + interpolation = "faceVarying" + ) + point3f[] points = [(-1, -1, 0), (1, -1, 0), (-1, 0, 0), (1, 0, 0), (-1, 1, 0), (1, 1, 0)] + bool[] primvars:sharp_face = [1, 1] ( + interpolation = "uniform" + ) + # modified 5th item. + texCoord2f[] primvars:UVMap = [(0, 0), (1, 0), (1, 0.5), (0, 0.5), (0, 0.6), (1, 0.5), (1, 1), (0, 1)] ( + interpolation = "faceVarying" + ) + uniform token subdivisionScheme = "none" + } + } + + def Scope "_materials" + { + def Material "Material_001" + { + token outputs:surface.connect = + + def Shader "Principled_BSDF" + { + uniform token info:id = "UsdPreviewSurface" + float inputs:clearcoat = 0 + float inputs:clearcoatRoughness = 0.03 + color3f inputs:diffuseColor.connect = + float inputs:ior = 1.5 + float inputs:metallic = 0 + float inputs:opacity = 1 + float inputs:roughness = 0.5 + float inputs:specular = 0.5 + token outputs:surface + } + + def Shader "Image_Texture" + { + uniform token info:id = "UsdUVTexture" + asset inputs:file = @./textures/texture-cat.jpg@ + token inputs:sourceColorSpace = "sRGB" + float2 inputs:st.connect = + token inputs:wrapS = "repeat" + token inputs:wrapT = "repeat" + float3 outputs:rgb + } + + def Shader "uvmap" + { + uniform token info:id = "UsdPrimvarReader_float2" + token inputs:varname = "UVMap" + float2 outputs:result + } + } + } +} + diff --git a/src/tydra/render-data.cc b/src/tydra/render-data.cc index c0baee9a..80ebcd5a 100644 --- a/src/tydra/render-data.cc +++ b/src/tydra/render-data.cc @@ -18,6 +18,7 @@ // - [ ] Adjust normal vector computation with handness? // - [ ] Node xform animation // - [ ] Better build of index buffer +// - [ ] Preserve the order of 'points' variable(mesh.points, Skin indices/weights, BlendShape points, ...) as much as possible. // - Implement spatial hash // #include @@ -1686,7 +1687,8 @@ static void GenerateBasis(const vec3 &n, vec3 *tangent, #endif struct ComputeTangentPackedVertexData { - value::float3 position; + //value::float3 position; + uint32_t point_index; value::float3 normal; value::float2 uv; @@ -1729,17 +1731,18 @@ struct ComputeTangentPackedVertexDataEqual { template struct ComputeTangentVertexInput { - std::vector positions; + //std::vector positions; + std::vector point_indices; std::vector normals; std::vector uvs; - size_t size() const { return positions.size(); } + size_t size() const { return point_indices.size(); } void get(size_t idx, PackedVert &output) const { - if (idx < positions.size()) { - output.position = positions[idx]; + if (idx < point_indices.size()) { + output.point_index = point_indices[idx]; } else { - output.position = {0.0f, 0.0f, 0.0f}; + output.point_index = ~0u; // never should reach here though. } if (idx < normals.size()) { output.normal = normals[idx]; @@ -1756,14 +1759,16 @@ struct ComputeTangentVertexInput { template struct ComputeTangentVertexOutput { - std::vector positions; + //std::vector positions; + std::vector point_indices; std::vector normals; std::vector uvs; - size_t size() const { return positions.size(); } + size_t size() const { return point_indices.size(); } void push_back(const PackedVert &v) { - positions.push_back(v.position); + //positions.push_back(v.position); + point_indices.push_back(v.point_index); normals.push_back(v.normal); uvs.push_back(v.uv); } @@ -2048,29 +2053,31 @@ static bool ComputeTangentsAndBinormals( if (is_facevarying_input) { // input position is still in 'vertex' variability. for (size_t i = 0; i < faceVertexIndices.size(); i++) { - vertex_input.positions.push_back(vertices[faceVertexIndices[i]]); + vertex_input.point_indices.push_back(faceVertexIndices[i]); } vertex_input.normals = normals; vertex_input.uvs = texcoords; } else { // expand to facevarying. for (size_t i = 0; i < faceVertexIndices.size(); i++) { - vertex_input.positions.push_back(vertices[faceVertexIndices[i]]); + vertex_input.point_indices.push_back(faceVertexIndices[i]); vertex_input.normals.push_back(normals[faceVertexIndices[i]]); vertex_input.uvs.push_back(texcoords[faceVertexIndices[i]]); } } + std::vector vertex_point_indices; + BuildIndices, ComputeTangentVertexOutput, ComputeTangentPackedVertexData, ComputeTangentPackedVertexDataHasher, ComputeTangentPackedVertexDataEqual>( - vertex_input, vertex_output, vertex_indices); + vertex_input, vertex_output, vertex_indices, vertex_point_indices); DCOUT("faceVertexIndices.size : " << faceVertexIndices.size()); DCOUT("# of indices after the build: " << vertex_indices.size() << ", reduced " << (faceVertexIndices.size() - vertex_indices.size()) << " indices."); - // We only need indices. Discard vertex_output + // We only need indices. Discard vertex_output and vertrex_point_indices } const uint32_t num_verts = @@ -2428,7 +2435,7 @@ bool RenderSceneConverter::BuildVertexIndicesImpl(RenderMesh &mesh) { DefaultVertexInput vertex_input; size_t num_fvs = fvIndices.size(); - vertex_input.positions.assign(num_fvs, {0.0f, 0.0f, 0.0f}); + vertex_input.point_indices = fvIndices; vertex_input.uv0s.assign(num_fvs, {0.0f, 0.0f}); vertex_input.uv1s.assign(num_fvs, {0.0f, 0.0f}); vertex_input.normals.assign(num_fvs, {0.0f, 0.0f, 0.0f}); @@ -2557,11 +2564,6 @@ bool RenderSceneConverter::BuildVertexIndicesImpl(RenderMesh &mesh) { PUSH_ERROR_AND_RETURN(fmt::format("Invalid faceVertexIndex {}. Must be less than {}", fvi, num_fvs)); } - // - // position is 'vertex' varying, others are 'facevarying' - // - vertex_input.positions[i] = mesh.points[fvi]; - if (normals_ptr) { vertex_input.normals[i] = normals_ptr[i]; } @@ -2586,13 +2588,21 @@ bool RenderSceneConverter::BuildVertexIndicesImpl(RenderMesh &mesh) { } std::vector out_indices; + std::vector out_point_indices; // to reorder position data DefaultVertexOutput vertex_output; BuildIndices, DefaultVertexOutput, DefaultPackedVertexData, DefaultPackedVertexDataHasher, DefaultPackedVertexDataEqual>(vertex_input, vertex_output, - out_indices); + out_indices, out_point_indices); + + if (out_indices.size() != out_point_indices.size()) { + PUSH_ERROR_AND_RETURN("Internal error. out_indices.size != out_point_indices."); + } + + DCOUT("faceVertexIndices.size : " << fvIndices.size()); + DCOUT("# of indices after the build: " << out_indices.size() << ", reduced " << (fvIndices.size() - out_indices.size()) << " indices."); if (mesh.is_triangulated()) { mesh.triangulatedFaceVertexIndices = out_indices; @@ -2600,9 +2610,54 @@ bool RenderSceneConverter::BuildVertexIndicesImpl(RenderMesh &mesh) { mesh.usdFaceVertexIndices = out_indices; } - mesh.points = vertex_output.positions; + // + // Reorder 'vertex' varying attributes(points, jointIndices/jointWeights, BlendShape points, ...) + // TODO: Preserve input order as much as possible. + // + { + uint32_t numPoints = *std::max_element(out_indices.begin(), out_indices.end()) + 1; + { + std::vector tmp_points(numPoints); + for (size_t i = 0; i < out_point_indices.size(); i++) { + if (out_point_indices[i] >= mesh.points.size()) { + PUSH_ERROR_AND_RETURN("Internal error. point index out-of-range."); + } + tmp_points[out_indices[i]] = mesh.points[out_point_indices[i]]; + } + mesh.points.swap(tmp_points); + } - // attributes are now 'vertex' variability + if (mesh.joint_and_weights.jointIndices.size()) { + if (mesh.joint_and_weights.elementSize < 1) { + PUSH_ERROR_AND_RETURN("Internal error. Invalid elementSize in mesh.joint_and_weights."); + } + uint32_t elementSize = uint32_t(mesh.joint_and_weights.elementSize); + std::vector tmp_indices(numPoints * elementSize); + std::vector tmp_weights(numPoints * elementSize); + for (size_t i = 0; i < out_point_indices.size(); i++) { + if ((elementSize * out_point_indices[i]) >= mesh.joint_and_weights.jointIndices.size()) { + PUSH_ERROR_AND_RETURN("Internal error. point index exceeds jointIndices.size."); + } + for (size_t k = 0; k < elementSize; k++) { + tmp_indices[elementSize * out_indices[i] + k] = mesh.joint_and_weights.jointIndices[elementSize * out_point_indices[i] + k]; + } + + if ((elementSize * out_point_indices[i]) >= mesh.joint_and_weights.jointWeights.size()) { + PUSH_ERROR_AND_RETURN("Internal error. point index exceeds jointWeights.size."); + } + + for (size_t k = 0; k < elementSize; k++) { + tmp_weights[elementSize * out_indices[i] + k] = mesh.joint_and_weights.jointWeights[elementSize * out_point_indices[i] + k]; + } + } + mesh.joint_and_weights.jointIndices.swap(tmp_indices); + mesh.joint_and_weights.jointWeights.swap(tmp_weights); + } + + // TODO: Reorder BlendShape points + } + + // Other 'facevarying' attributes are now 'vertex' variability if (normals_ptr) { mesh.normals.set_buffer( reinterpret_cast(vertex_output.normals.data()), @@ -5759,6 +5814,14 @@ std::string DumpMesh(const RenderMesh &mesh, uint32_t indent) { ss << pprint::Indent(indent + 1) << "}\n"; } + if (mesh.joint_and_weights.jointIndices.size()) { + ss << pprint::Indent(indent + 1) << "skin {\n"; + ss << pprint::Indent(indent + 2) << "geomBindTransform " << quote(tinyusdz::to_string(mesh.joint_and_weights.geomBindTransform)) << "\n"; + ss << pprint::Indent(indent + 2) << "elementSize " << mesh.joint_and_weights.elementSize << "\n"; + ss << pprint::Indent(indent + 2) << "jointIndices " << quote(value::print_array_snipped(mesh.joint_and_weights.jointIndices)) << "\n"; + ss << pprint::Indent(indent + 2) << "jointWeights " << quote(value::print_array_snipped(mesh.joint_and_weights.jointWeights)) << "\n"; + ss << pprint::Indent(indent + 1) << "}\n"; + } if (mesh.material_subsetMap.size()) { ss << pprint::Indent(indent + 1) << "material_subsets {\n"; for (const auto &msubset : mesh.material_subsetMap) { diff --git a/src/tydra/render-data.hh b/src/tydra/render-data.hh index 496799b4..0ee6636f 100644 --- a/src/tydra/render-data.hh +++ b/src/tydra/render-data.hh @@ -731,15 +731,15 @@ struct JointAndWeight { value::matrix4d::identity()}; // matrix4d primvars:skel:geomBindTransform // - // NOTE: both jointIndices and jointWeights' USD interpolation must be - // 'vertex' + // NOTE: variability of jointIndices and jointWeights are 'vertex' + // NOTE: Values in jointIndices and jointWeights will be reordered when `MeshConverterConfig::build_vertex_indices` is set true. // std::vector jointIndices; // int[] primvars:skel:jointIndices // NOTE: weight is converted from USD as-is. not normalized. std::vector jointWeights; // float[] primvars:skel:jointWeight; - int elementSize{1}; + int elementSize{1}; // # of weights per vertex }; struct MaterialPath { @@ -1331,7 +1331,8 @@ struct RenderSceneConverterConfig { // TODO: Polish interface to support arbitrary vertex configuration. // struct DefaultPackedVertexData { - value::float3 position; + //value::float3 position; + uint32_t point_index; value::float3 normal; value::float2 uv0; value::float2 uv1; @@ -1379,7 +1380,8 @@ struct DefaultPackedVertexDataEqual { template struct DefaultVertexInput { - std::vector positions; + //std::vector positions; + std::vector point_indices; std::vector normals; std::vector uv0s; std::vector uv1s; @@ -1388,13 +1390,13 @@ struct DefaultVertexInput { std::vector colors; std::vector opacities; - size_t size() const { return positions.size(); } + size_t size() const { return point_indices.size(); } void get(size_t idx, PackedVert &output) const { - if (idx < positions.size()) { - output.position = positions[idx]; + if (idx < point_indices.size()) { + output.point_index = point_indices[idx]; } else { - output.position = {0.0f, 0.0f, 0.0f}; + output.point_index = ~0u; // this case should not happen though } if (idx < normals.size()) { output.normal = normals[idx]; @@ -1436,7 +1438,8 @@ struct DefaultVertexInput { template struct DefaultVertexOutput { - std::vector positions; + //std::vector positions; + std::vector point_indices; std::vector normals; std::vector uv0s; std::vector uv1s; @@ -1445,10 +1448,10 @@ struct DefaultVertexOutput { std::vector colors; std::vector opacities; - size_t size() const { return positions.size(); } + size_t size() const { return point_indices.size(); } void push_back(const PackedVert &v) { - positions.push_back(v.position); + point_indices.push_back(v.point_index); normals.push_back(v.normal); uv0s.push_back(v.uv0); uv1s.push_back(v.uv1); @@ -1465,7 +1468,8 @@ struct DefaultVertexOutput { template void BuildIndices(const VertexInput &input, VertexOutput &output, - std::vector &out_indices) { + std::vector &out_indices, std::vector &out_point_indices) +{ // TODO: Use LSH(locally sensitive hashing) or BVH for kNN point query. std::unordered_map vertexToIndexMap; @@ -1489,9 +1493,12 @@ void BuildIndices(const VertexInput &input, VertexOutput &output, if (found) { out_indices.push_back(index); } else { - out_indices.push_back(uint32_t(output.size())); + uint32_t new_index = uint32_t(output.size()); + out_indices.push_back(new_index); output.push_back(v); + vertexToIndexMap[v] = new_index; } + out_point_indices.push_back(v.point_index); } }