public static void UndoRootTransform(Scene scene, UsdAsset stageRoot, ref Vector3 localScale, ref Quaternion localRotation) { localScale /= stageRoot.LastScale; float invertPrev = stageRoot.LastHandedness == BasisTransformation.FastWithNegativeScale ? -1 : 1; if (scene.UpAxis == Scene.UpAxes.Z) { localRotation *= Quaternion.AngleAxis(-1 * invertPrev * 90, Vector3.right); } if (stageRoot.LastHandedness == BasisTransformation.FastWithNegativeScale) { // Convert from right-handed (USD) to left-handed (Unity). if (scene.UpAxis == Scene.UpAxes.Z) { localScale.y *= -1; } else { localScale.z *= -1; } } }
private void ReloadFromUsdAsCoroutine(UsdAsset stageRoot) { var options = new SceneImportOptions(); stageRoot.StateToOptions(ref options); var parent = stageRoot.gameObject.transform.parent; var root = parent ? parent.gameObject : null; stageRoot.ImportUsdAsCoroutine(root, stageRoot.usdFullPath, stageRoot.m_usdTimeOffset, options, targetFrameMilliseconds: 5); }
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner) { var usdPlayable = ScriptPlayable <UsdPlayableBehaviour> .Create(graph); UsdPlayableBehaviour behaviour = usdPlayable.GetBehaviour(); m_sourceUsdAsset = SourceUsdAsset.Resolve(graph.GetResolver()); if (m_sourceUsdAsset != null) { behaviour.playableAsset = this; name = System.IO.Path.GetFileName(m_sourceUsdAsset.usdFullPath); } return(usdPlayable); }
private void DetachFromUsd(UsdAsset stageRoot) { stageRoot.RemoveAllUsdComponents(); Repaint(); }
private void DestroyAllImportedObjects(UsdAsset stageRoot) { stageRoot.DestroyAllImportedObjects(); Repaint(); }
private void ReloadFromUsd(UsdAsset stageRoot, bool forceRebuild) { stageRoot.Reload(forceRebuild); Repaint(); }
private void DrawSimpleInspector(UsdAsset usdAsset) { GUILayout.Label("Source Asset", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("USD File"); usdAsset.usdFullPath = EditorGUILayout.TextField(usdAsset.usdFullPath, EditorStyles.textField); if (GUILayout.Button("...")) { string lastDir; if (string.IsNullOrEmpty(usdAsset.usdFullPath)) { lastDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); } else { lastDir = Path.GetDirectoryName(usdAsset.usdFullPath); } string importFilepath = EditorUtility.OpenFilePanelWithFilters("Usd Asset", lastDir, new string[] { "Usd", "us*" }); if (string.IsNullOrEmpty(importFilepath)) { return; } usdAsset.usdFullPath = importFilepath; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("USD Root Path"); usdAsset.m_usdRootPath = EditorGUILayout.TextField(usdAsset.m_usdRootPath, EditorStyles.textField); EditorGUILayout.EndHorizontal(); GUILayout.Label("Import Settings", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); var op = LinearUnits.Custom; if (usdAsset.m_scale == 1) { op = LinearUnits.Meters; } else if (usdAsset.m_scale == .1f) { op = LinearUnits.Decimeters; } else if (usdAsset.m_scale == .01f) { op = LinearUnits.Centimeters; } else if (usdAsset.m_scale == .001f) { op = LinearUnits.Millimeters; } else if (usdAsset.m_scale == 1000f) { op = LinearUnits.Kilometers; } var newOp = (LinearUnits)EditorGUILayout.EnumPopup("Original Scale", op); if (newOp == LinearUnits.Custom) { // Force the UI to stay on the "custom" selection by adding an offset. float offset = op == newOp ? 0 : 0.01f; usdAsset.m_scale = EditorGUILayout.FloatField(usdAsset.m_scale + offset); } op = newOp; EditorGUILayout.EndHorizontal(); switch (op) { case LinearUnits.Millimeters: usdAsset.m_scale = .001f; break; case LinearUnits.Centimeters: usdAsset.m_scale = .01f; break; case LinearUnits.Decimeters: usdAsset.m_scale = .1f; break; case LinearUnits.Meters: usdAsset.m_scale = 1f; break; case LinearUnits.Kilometers: usdAsset.m_scale = 1000; break; } usdAsset.m_materialImportMode = (MaterialImportMode)EditorGUILayout.EnumPopup("Materials", usdAsset.m_materialImportMode); usdAsset.m_payloadPolicy = (PayloadPolicy)EditorGUILayout.EnumPopup("Payload Policy", usdAsset.m_payloadPolicy); GUILayout.Label("Object Types", EditorStyles.boldLabel); usdAsset.m_importCameras = EditorGUILayout.Toggle("Import Cameras", usdAsset.m_importCameras); usdAsset.m_importMeshes = EditorGUILayout.Toggle("Import Meshes", usdAsset.m_importMeshes); usdAsset.m_importSkinning = EditorGUILayout.Toggle("Import Skinning", usdAsset.m_importSkinning); usdAsset.m_importTransforms = EditorGUILayout.Toggle("Import Transforms", usdAsset.m_importTransforms); }
/// <summary> /// Applies the contents of this USD file to a foreign root object. /// </summary> /// <remarks> /// The idea here is that one may have many animation clips, but only a single GameObject in /// the Unity scenegraph. /// </remarks> public void SetTime(double time, UsdAsset foreignRoot, bool saveMeshUpdates) { var scene = GetScene(); if (scene == null) { Debug.LogWarning("Null scene from GetScene() at " + UnityTypeConverter.GetPath(transform)); return; } // Careful not to update any local members here, if this data is driven from a prefab, we // dont want those changes to be baked back into the asset. time += foreignRoot.m_usdTimeOffset; float usdTime = (float)(scene.StartTime + time * scene.Stage.GetTimeCodesPerSecond()); if (usdTime > scene.EndTime) { return; } if (usdTime < scene.StartTime) { return; } scene.Time = usdTime; var options = new SceneImportOptions(); foreignRoot.StateToOptions(ref options); PrepOptionsForTimeChange(ref options); if (foreignRoot.m_lastPrimMap == null) { foreignRoot.m_lastPrimMap = new PrimMap(); options.importHierarchy = true; } if (m_usdVariabilityCache) { if (m_lastAccessMask == null) { m_lastAccessMask = new AccessMask(); scene.IsPopulatingAccessMask = true; } } else { m_lastAccessMask = null; } if (m_debugPrintVariabilityCache && m_lastAccessMask != null && !scene.IsPopulatingAccessMask) { var sb = new System.Text.StringBuilder(); foreach (var kvp in m_lastAccessMask.Included) { sb.AppendLine(kvp.Key); foreach (var member in kvp.Value) { sb.AppendLine(" ." + member.Name); } sb.AppendLine(); } Debug.Log(sb.ToString()); } scene.AccessMask = m_lastAccessMask; SceneImporter.ImportUsd(foreignRoot.gameObject, scene, foreignRoot.m_lastPrimMap, options); scene.AccessMask = null; if (m_lastAccessMask != null) { scene.IsPopulatingAccessMask = false; } }