public int BlendshapeAnimTest(float [] keyTimesInSeconds, float [] keyValues, System.Type componentType, string componentName) { var prefabPath = FindPathInUnitTests("Models/blendshape.fbx"); Assert.That(prefabPath, Is.Not.Null); // add prefab to scene GameObject originalGO = AddAssetToScene(prefabPath); KeyData keyData = new PropertyKeyData { targetObject = originalGO, propertyName = componentName, componentType = componentType, keyTimes = keyTimesInSeconds, keyFloatValues = keyValues }; var tester = new AnimTester { keyData = keyData, testName = componentName, path = GetRandomFbxFilePath() }; var exportOptions = new ExportModelSettingsSerialize(); exportOptions.SetAnimatedSkinnedMesh(true); tester.exportOptions = exportOptions; return(tester.DoIt()); }
// 处理UV并导出模型 public static void ExportMesh(CombinMeshEditor cme) { int w = cme.combinTextureWidth; int h = cme.combinTextureHeight; for (int i = 0; i < cme.nodeList.Count; ++i) { CombinNode ti = cme.nodeList[i]; Matrix2x2 matrix = Matrix2x2.identity.Clone(); matrix.Rotate(-ti.rotation * Mathf.PI / 180); for (int j = 0; j < ti.objects.Count; ++j) { Mesh mesh = ti.meshs[j]; string fileDir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(mesh)); string fbxName = Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(mesh)) + "_combin.FBX"; Vector2[] uvBak = new Vector2[mesh.uv.Length]; Array.Copy(mesh.uv, uvBak, mesh.uv.Length); Vector2[] uv = new Vector2[mesh.uv.Length]; for (int mi = 0; mi < mesh.uv.Length; ++mi) { Vector2 u = Vector2.zero; Vector2 v = mesh.uv[mi]; v.x -= 0.5f; v.y -= 0.5f; v = matrix * v; v.x += 0.5f; v.y += 0.5f; u.x = v.x * ti.rect.width / w + ti.rect.x / w; u.y = v.y * ti.rect.height / h + (h - ti.rect.y - ti.rect.height) / h; uv[mi] = u; } mesh.uv = uv; var options = new ExportModelSettingsSerialize(); options.exportFormat = ExportSettings.ExportFormat.Binary; options.include = ExportSettings.Include.Model; options.objectPosition = ExportSettings.ObjectPosition.LocalCentered; options.exportUnrendered = true; ModelExporter.ExportObject(fileDir + "/" + fbxName, ti.objects[j], options); mesh.uv = uvBak; } } }
public void ExportSingleTimelineClipTest() { string cubeSpecialPath = FindPathInUnitTests("Scene/CubeSpecial.prefab"); GameObject myCube = AddAssetToScene(cubeSpecialPath); string folderPath = GetRandomFileNamePath(extName: ""); string filePath = null; TimelineClip timelineClipToExport = null; UnityEditor.Selection.activeObject = myCube; PlayableDirector pd = myCube.GetComponent <PlayableDirector>(); if (pd != null) { foreach (PlayableBinding output in pd.playableAsset.outputs) { AnimationTrack at = output.sourceObject as AnimationTrack; var atComponent = pd.GetGenericBinding(at) as Component; Assert.That(atComponent, Is.Not.Null); var atObject = atComponent.gameObject; // One file by animation clip foreach (TimelineClip timeLineClip in at.GetClips()) { Assert.That(timeLineClip.animationClip, Is.Not.Null); filePath = $"{folderPath}/{atObject.name}@Recorded.fbx"; timelineClipToExport = timeLineClip; break; } } } Assert.That(filePath, Is.Not.Null); var exportOptions = new ExportModelSettingsSerialize(); exportOptions.SetModelAnimIncludeOption(ExportSettings.Include.Anim); ModelExporter.ExportTimelineClip(filePath, timelineClipToExport, pd, exportOptions); FileAssert.Exists(filePath); }
/// <summary> /// Exports a single hierarchy to a random fbx file. /// </summary> /// <returns>The exported fbx file path.</returns> /// <param name="hierarchy">Hierarchy.</param> /// <param name="animOnly">If set to <c>true</c> export animation only.</param> internal GameObject ExportToFbx( GameObject hierarchy, bool animOnly = false, ExportSettings.LODExportType lodExportType = ExportSettings.LODExportType.All ) { string filename = GetRandomFbxFilePath(); var exportOptions = new ExportModelSettingsSerialize(); exportOptions.SetLODExportType(lodExportType); if (animOnly) { exportOptions.SetModelAnimIncludeOption(ExportSettings.Include.Anim); } var exportedFilePath = ModelExporter.ExportObject( filename, hierarchy, exportOptions ); Assert.That(exportedFilePath, Is.EqualTo(filename)); var exported = AssetDatabase.LoadMainAssetAtPath(filename) as GameObject; return(exported); }
public override void Init() { base.Init(); m_centerObjectsSetting = new ExportModelSettingsSerialize(); }