static void PopulateSkelCache(ref HierInfo skelRootInfo, UsdSkelCache skelCache) { // // Populate the UsdSkelCache. // var skelRoot = new UsdSkelRoot(skelRootInfo.prim); if (!skelRoot) { return; } if (!skelCache.Populate(skelRoot)) { Debug.LogWarning("Failed to populate skel cache: " + skelRootInfo.prim.GetPath()); return; } try { var binding = new UsdSkelBindingVector(); if (!skelCache.ComputeSkelBindings(skelRoot, binding)) { Debug.LogWarning("ComputeSkelBindings failed: " + skelRootInfo.prim.GetPath()); return; } skelRootInfo.skelBindings = binding; } catch { Debug.LogError("Failed to compute binding for SkelRoot: " + skelRootInfo.prim.GetPath()); } }
public bool Populate(UsdSkelRoot root) { bool ret = UsdCsPINVOKE.UsdSkelCache_Populate(swigCPtr, UsdSkelRoot.getCPtr(root)); if (UsdCsPINVOKE.SWIGPendingException.Pending) { throw UsdCsPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public bool ComputeSkelBindings(UsdSkelRoot skelRoot, UsdSkelBindingVector bindings) { bool ret = UsdCsPINVOKE.UsdSkelCache_ComputeSkelBindings(swigCPtr, UsdSkelRoot.getCPtr(skelRoot), UsdSkelBindingVector.getCPtr(bindings)); if (UsdCsPINVOKE.SWIGPendingException.Pending) { throw UsdCsPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public bool ComputeSkelBinding(UsdSkelRoot skelRoot, UsdSkelSkeleton skel, UsdSkelBinding binding) { bool ret = UsdCsPINVOKE.UsdSkelCache_ComputeSkelBinding(swigCPtr, UsdSkelRoot.getCPtr(skelRoot), UsdSkelSkeleton.getCPtr(skel), UsdSkelBinding.getCPtr(binding)); if (UsdCsPINVOKE.SWIGPendingException.Pending) { throw UsdCsPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static UsdSkelRoot Define(UsdStageWeakPtr stage, SdfPath path) { UsdSkelRoot ret = new UsdSkelRoot(UsdCsPINVOKE.UsdSkelRoot_Define(UsdStageWeakPtr.getCPtr(stage), SdfPath.getCPtr(path)), true); if (UsdCsPINVOKE.SWIGPendingException.Pending) { throw UsdCsPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static UsdSkelRoot Find(UsdPrim prim) { UsdSkelRoot ret = new UsdSkelRoot(UsdCsPINVOKE.UsdSkelRoot_Find(UsdPrim.getCPtr(prim)), true); if (UsdCsPINVOKE.SWIGPendingException.Pending) { throw UsdCsPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
/// <summary> /// If HierInfo represents a UsdSkelRoot, reads the associated skelton joints into the /// skelJoints member. /// </summary> static void ReadSkeletonJoints(ref HierInfo skelRootInfo) { if (skelRootInfo.prim == null) { return; } var skelRoot = new UsdSkelRoot(skelRootInfo.prim); if (!skelRoot) { return; } var processed = new HashSet <SdfPath>(); foreach (UsdSkelBinding binding in skelRootInfo.skelBindings) { var skel = binding.GetSkeleton(); if (!skel) { continue; } // If the same skeleton is referenced multiple times, only process it once. if (processed.Contains(skel.GetPath())) { continue; } processed.Add(skel.GetPath()); var jointsAttr = skel.GetJointsAttr(); if (!jointsAttr) { continue; } var vtJoints = jointsAttr.Get(); if (vtJoints.IsEmpty()) { continue; } var vtStrings = UsdCs.VtValueToVtTokenArray(vtJoints); var joints = UnityTypeConverter.FromVtArray(vtStrings); var skelPath = skel.GetPath(); skelRootInfo.skelJoints = new SdfPath[joints.Length]; for (int i = 0; i < joints.Length; i++) { var jointPath = new SdfPath(joints[i]); if (joints[i] == "/") { skelRootInfo.skelJoints[i] = skelPath; continue; } else if (jointPath.IsAbsolutePath()) { Debug.LogException(new Exception("Unexpected absolute joint path: " + jointPath)); jointPath = new SdfPath(joints[i].TrimStart('/')); } skelRootInfo.skelJoints[i] = skelPath.AppendPath(jointPath); } } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(UsdSkelRoot obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public System.Collections.IEnumerator Import(Scene scene, PrimMap primMap, SceneImportOptions importOptions) { if (importOptions.importSkinning) { Profiler.BeginSample("USD: Populate SkelCache"); foreach (var path in primMap.SkelRoots) { var prim = scene.GetPrimAtPath(path); if (!prim) { continue; } var skelRoot = new UsdSkelRoot(prim); if (!skelRoot) { continue; } } Profiler.EndSample(); } System.Reflection.MemberInfo faceVertexCounts = null; System.Reflection.MemberInfo faceVertexIndices = null; System.Reflection.MemberInfo orientation = null; System.Reflection.MemberInfo purpose = null; System.Reflection.MemberInfo visibility = null; if (scene.AccessMask != null && scene.IsPopulatingAccessMask) { var meshType = typeof(MeshSample); faceVertexCounts = meshType.GetMember("faceVertexCounts")[0]; faceVertexIndices = meshType.GetMember("faceVertexIndices")[0]; orientation = meshType.GetMember("orientation")[0]; purpose = meshType.GetMember("purpose")[0]; visibility = meshType.GetMember("visibility")[0]; } foreach (var pathAndSample in m_readMeshesJob) { if (scene.AccessMask != null && scene.IsPopulatingAccessMask) { HashSet <System.Reflection.MemberInfo> members; if (scene.AccessMask.Included.TryGetValue(pathAndSample.path, out members)) { if (members.Contains(faceVertexCounts) || members.Contains(orientation) || members.Contains(faceVertexIndices)) { members.Add(faceVertexCounts); members.Add(faceVertexIndices); members.Add(orientation); } if (pathAndSample.sample.purpose != Purpose.Default && !members.Contains(purpose)) { members.Add(purpose); } if (pathAndSample.sample.visibility != Visibility.Inherited && !members.Contains(visibility)) { members.Add(visibility); } } } Profiler.BeginSample("USD: Build Meshes"); try { GameObject go = primMap[pathAndSample.path]; NativeImporter.ImportObject(scene, go, scene.GetPrimAtPath(pathAndSample.path), importOptions); if (importOptions.importTransforms) { Profiler.BeginSample("Build Mesh Xform"); XformImporter.BuildXform(pathAndSample.path, pathAndSample.sample, go, importOptions, scene); Profiler.EndSample(); } Profiler.BeginSample("Read Mesh Subsets"); MeshImporter.GeometrySubsets subsets = null; if (primMap == null || !primMap.MeshSubsets.TryGetValue(pathAndSample.path, out subsets)) { subsets = MeshImporter.ReadGeomSubsets(scene, pathAndSample.path); } Profiler.EndSample(); UsdSkelSkinningQuery skinningQuery; if (importOptions.importHierarchy) { if (importOptions.importSkinning && primMap.SkelCache != null) { // This is pre-cached as part of calling skelCache.Populate and IsValid indicates if we // have the data required to setup a skinned mesh. Profiler.BeginSample("Get Skinning Query"); skinningQuery = new UsdSkelSkinningQuery(); primMap.SkinningQueries[pathAndSample.path] = primMap.SkelCache.GetSkinningQuery(scene.GetPrimAtPath(pathAndSample.path)); Profiler.EndSample(); } if (importOptions.importMeshes) { primMap.MeshSubsets[pathAndSample.path] = MeshImporter.ReadGeomSubsets(scene, pathAndSample.path); } } if (importOptions.importSkinning) { primMap.SkinningQueries.TryGetValue(pathAndSample.path, out skinningQuery); /* * Profiler.BeginSample("Get Skinning Query"); * skinningQuery = primMap.SkelCache.GetSkinningQuery(scene.GetPrimAtPath(pathAndSample.path)); * Profiler.EndSample(); */ } if (importOptions.importSkinning && primMap.SkelCache != null && primMap.SkinningQueries.TryGetValue(pathAndSample.path, out skinningQuery) && skinningQuery.IsValid()) { Profiler.BeginSample("USD: Build Skinned Mesh"); m_skinnedMeshImporter(pathAndSample.path, pathAndSample.sample, subsets, go, importOptions); Profiler.EndSample(); } else { Profiler.BeginSample("USD: Build Mesh"); m_meshImporter(pathAndSample.path, pathAndSample.sample, subsets, go, importOptions); Profiler.EndSample(); } } catch (Exception ex) { Debug.LogException( new SceneImporter.ImportException( "Error processing mesh <" + pathAndSample.path + ">", ex)); } Profiler.EndSample(); yield return(null); } // foreach mesh }
static void ReadSkeleton(ref HierInfo info) { if (info.prim == null) { return; } var skelRoot = new UsdSkelRoot(info.prim); if (!skelRoot) { return; } var skelRel = info.prim.GetRelationship(UsdSkelTokens.skelSkeleton); if (!skelRel) { return; } SdfPathVector targets = skelRel.GetForwardedTargets(); if (targets == null || targets.Count == 0) { return; } var skelPrim = info.prim.GetStage().GetPrimAtPath(targets[0]); if (!skelPrim) { return; } var skel = new UsdSkelSkeleton(skelPrim); if (!skel) { return; } var jointsAttr = skel.GetJointsAttr(); if (!jointsAttr) { return; } var vtJoints = jointsAttr.Get(); if (vtJoints.IsEmpty()) { return; } var vtStrings = UsdCs.VtValueToVtTokenArray(vtJoints); var joints = UnityTypeConverter.FromVtArray(vtStrings); var skelPath = skelPrim.GetPath(); info.skelJoints = new SdfPath[joints.Length]; for (int i = 0; i < joints.Length; i++) { var jointPath = new SdfPath(joints[i]); if (joints[i] == "/") { info.skelJoints[i] = skelPath; continue; } else if (jointPath.IsAbsolutePath()) { Debug.LogException(new Exception("Unexpected absolute joint path: " + jointPath)); jointPath = new SdfPath(joints[i].TrimStart('/')); } info.skelJoints[i] = skelPath.AppendPath(jointPath); } }