private static string AxisSystemToString(FbxAxisSystem fbxAxisSystem) { return(string.Format("[{0}, {1}, {2}]", fbxAxisSystem.GetUpVector().ToString(), fbxAxisSystem.GetFrontVector().ToString(), fbxAxisSystem.GetCoorSystem().ToString())); }
/// <summary> /// Process fbxScene. If system units don't match then bake the convertion into the position /// and vertices of objects. /// </summary> public void ProcessScene(FbxScene fbxScene) { Debug.Log(string.Format("Scene name: {0}", fbxScene.GetName())); var fbxSettings = fbxScene.GetGlobalSettings(); FbxSystemUnit fbxSystemUnit = fbxSettings.GetSystemUnit(); if (fbxSystemUnit != UnitySystemUnit) { Debug.Log(string.Format("converting system unit to match Unity. Expected {0}, found {1}", UnitySystemUnit, fbxSystemUnit)); ConvertScene(fbxScene, UnitySystemUnit); } else { Debug.Log(string.Format("file system units {0}", fbxSystemUnit)); } // The Unity axis system has Y up, Z forward, X to the right (left-handed). FbxAxisSystem fbxAxisSystem = fbxSettings.GetAxisSystem(); if (fbxAxisSystem != UnityAxisSystem) { Debug.LogWarning(string.Format("file axis system do not match Unity, Expected {0} found {1}", AxisSystemToString(UnityAxisSystem), AxisSystemToString(fbxAxisSystem))); } ProcessNode(fbxScene.GetRootNode()); return; }
public FbxAxisSystem(FbxAxisSystem pAxisSystem) : this(NativeMethods.new_FbxAxisSystem__SWIG_2(FbxAxisSystem.getCPtr(pAxisSystem)), true) { if (NativeMethods.SWIGPendingException.Pending) { throw NativeMethods.SWIGPendingException.Retrieve(); } }
public FbxAxisSystem(FbxAxisSystem pAxisSystem) : this(fbx_wrapperPINVOKE.new_FbxAxisSystem__SWIG_2(FbxAxisSystem.getCPtr(pAxisSystem)), true) { if (fbx_wrapperPINVOKE.SWIGPendingException.Pending) { throw fbx_wrapperPINVOKE.SWIGPendingException.Retrieve(); } }
public void SetOriginalUpAxis(FbxAxisSystem pAxisSystem) { FbxWrapperNativePINVOKE.FbxGlobalSettings_SetOriginalUpAxis(swigCPtr, FbxAxisSystem.getCPtr(pAxisSystem)); if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } }
public void SetAxisSystem(FbxAxisSystem pAxisSystem) { NativeMethods.FbxGlobalSettings_SetAxisSystem(swigCPtr, FbxAxisSystem.getCPtr(pAxisSystem)); if (NativeMethods.SWIGPendingException.Pending) { throw NativeMethods.SWIGPendingException.Retrieve(); } }
public void ConvertChildren(FbxNode pRoot, FbxAxisSystem pSrcSystem) { fbx_wrapperPINVOKE.FbxAxisSystem_ConvertChildren(swigCPtr, FbxNode.getCPtr(pRoot), FbxAxisSystem.getCPtr(pSrcSystem)); if (fbx_wrapperPINVOKE.SWIGPendingException.Pending) { throw fbx_wrapperPINVOKE.SWIGPendingException.Retrieve(); } }
public bool Equals(FbxAxisSystem other) { if (object.ReferenceEquals(other, null)) { return(false); } return(_equals(other)); }
public void SetAxisSystem(FbxAxisSystem pAxisSystem) { fbx_wrapperPINVOKE.FbxGlobalSettings_SetAxisSystem(swigCPtr, FbxAxisSystem.getCPtr(pAxisSystem)); if (fbx_wrapperPINVOKE.SWIGPendingException.Pending) { throw fbx_wrapperPINVOKE.SWIGPendingException.Retrieve(); } }
public static bool InsertFbxRoot(FbxScene pScene, FbxAxisSystem pDstAxis, FbxSystemUnit pDstUnit) { bool ret = FbxWrapperNativePINVOKE.FbxRootNodeUtility_InsertFbxRoot__SWIG_1(FbxScene.getCPtr(pScene), FbxAxisSystem.getCPtr(pDstAxis), FbxSystemUnit.getCPtr(pDstUnit)); if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public bool ne(FbxAxisSystem pAxisSystem) { bool ret = fbx_wrapperPINVOKE.FbxAxisSystem_ne(swigCPtr, FbxAxisSystem.getCPtr(pAxisSystem)); if (fbx_wrapperPINVOKE.SWIGPendingException.Pending) { throw fbx_wrapperPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public bool eq(FbxAxisSystem pAxisSystem) { bool ret = FbxWrapperNativePINVOKE.FbxAxisSystem_eq(swigCPtr, FbxAxisSystem.getCPtr(pAxisSystem)); if (FbxWrapperNativePINVOKE.SWIGPendingException.Pending) { throw FbxWrapperNativePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static bool InsertFbxRoot(FbxScene pScene, FbxAxisSystem pDstAxis, FbxSystemUnit pDstUnit, FbxSystemUnit.ConversionOptions pUnitOptions) { bool ret = fbx_wrapperPINVOKE.FbxRootNodeUtility_InsertFbxRoot__SWIG_0(FbxScene.getCPtr(pScene), FbxAxisSystem.getCPtr(pDstAxis), FbxSystemUnit.getCPtr(pDstUnit), FbxSystemUnit.ConversionOptions.getCPtr(pUnitOptions)); if (fbx_wrapperPINVOKE.SWIGPendingException.Pending) { throw fbx_wrapperPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
private bool _equals(FbxAxisSystem pAxisSystem) { bool ret = NativeMethods.FbxAxisSystem__equals(swigCPtr, FbxAxisSystem.getCPtr(pAxisSystem)); if (NativeMethods.SWIGPendingException.Pending) { throw NativeMethods.SWIGPendingException.Retrieve(); } return(ret); }
public FbxAxisSystem GetAxisSystem() { FbxAxisSystem ret = new FbxAxisSystem(NativeMethods.FbxGlobalSettings_GetAxisSystem(swigCPtr), true); if (NativeMethods.SWIGPendingException.Pending) { throw NativeMethods.SWIGPendingException.Retrieve(); } return(ret); }
public FbxAxisSystem assign(FbxAxisSystem pAxisSystem) { FbxAxisSystem ret = new FbxAxisSystem(fbx_wrapperPINVOKE.FbxAxisSystem_assign(swigCPtr, FbxAxisSystem.getCPtr(pAxisSystem)), false); if (fbx_wrapperPINVOKE.SWIGPendingException.Pending) { throw fbx_wrapperPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
/// <summary> /// Process fbx scene by doing nothing /// </summary> public void ProcessScene(FbxScene fbxScene, IEnumerable <UnityEngine.Object> unitySelectionSet) { FbxDocumentInfo sceneInfo = fbxScene.GetSceneInfo(); if (sceneInfo != null) { MsgLine.Add(kBorderLine); MsgLine.Add("Scene Meta-Data"); MsgLine.Add(kBorderLine); MsgLine.Add(kPadding + string.Format("Title: \"{0}\"", sceneInfo.mTitle)); MsgLine.Add(kPadding + string.Format("Subject: \"{0}\"", sceneInfo.mSubject)); MsgLine.Add(kPadding + string.Format("Author: \"{0}\"", sceneInfo.mAuthor)); MsgLine.Add(kPadding + string.Format("Keywords: \"{0}\"", sceneInfo.mKeywords)); MsgLine.Add(kPadding + string.Format("Revision: \"{0}\"", sceneInfo.mRevision)); MsgLine.Add(kPadding + string.Format("Comment: \"{0}\"", sceneInfo.mComment)); } var fbxSettings = fbxScene.GetGlobalSettings(); MsgLine.Add(kBorderLine); MsgLine.Add("Global Settings"); MsgLine.Add(kBorderLine); FbxSystemUnit fbxSystemUnit = fbxSettings.GetSystemUnit(); if (fbxSystemUnit != UnitySystemUnit) { Debug.LogWarning(string.Format("file system unit do not match Unity. Expected {0} Found {1}", UnitySystemUnit.ToString(), fbxSystemUnit.ToString())); } MsgLine.Add(kPadding + string.Format("SystemUnits: {0}", fbxSystemUnit.ToString())); // The Unity axis system has Y up, Z forward, X to the right. FbxAxisSystem fbxAxisSystem = fbxSettings.GetAxisSystem(); if (fbxAxisSystem != UnityAxisSystem) { Debug.LogWarning(string.Format("file axis system do not match Unity, Expected [{0}, {1}, {2}] Found [{3}, {4}, {5}]", UnityAxisSystem.GetUpVector().ToString(), UnityAxisSystem.GetFrontVector().ToString(), UnityAxisSystem.GetCoorSystem().ToString(), fbxAxisSystem.GetUpVector().ToString(), fbxAxisSystem.GetFrontVector().ToString(), fbxAxisSystem.GetCoorSystem().ToString())); } MsgLine.Add(kPadding + string.Format("AxisSystem: {0}", AxisSystemToString(fbxAxisSystem))); // print report Debug.Log(string.Join(kNewLine, MsgLine.ToArray())); return; }
/// <summary> /// Try to import into the given scene. /// Return the nodes we created. /// </summary> Dictionary <GameObject, FbxNode> TryImport(Settings settings, FbxScene scene) { using (var importer = FbxImporter.Create(scene.GetFbxManager(), "")) { if (!importer.Initialize(settings.m_FileName)) { return(null); } if (!importer.Import(scene)) { return(null); } // Unity: Y-up, right is +X, forward is +Z (left-handed) var axes = new FbxAxisSystem( FbxAxisSystem.EUpVector.eYAxis, FbxAxisSystem.EFrontVector.eParityOdd, FbxAxisSystem.ECoordSystem.eLeftHanded); // Convert as needed. switch (settings.m_Conversion) { case Settings.Conversion.Legacy: axes.ConvertScene(scene); break; case Settings.Conversion.Deep: axes.DeepConvertScene(scene); break; case Settings.Conversion.None: break; } // The root node is this node. We won't set ourselves up to match the FBX root; // normally it's just a null. var root = scene.GetRootNode(); var nodes = new Dictionary <GameObject, FbxNode>(); CreateChildren(this.transform, root, nodes); return(nodes); } }
public void CreateDocument() { Scene = FbxScene.Create(SdkManager, ""); FbxDocumentInfo SceneInfo = FbxDocumentInfo.Create(SdkManager, "SceneInfo"); SceneInfo.mTitle = new FbxString("Unreal FBX Exporter"); SceneInfo.mSubject = new FbxString("Export FBX meshes from Unreal"); SceneInfo.Original_ApplicationVendor.Set(new FbxString("Epic Games")); SceneInfo.Original_ApplicationName.Set(new FbxString("Unreal Engine")); SceneInfo.Original_ApplicationVersion.Set(new FbxString("4.18")); SceneInfo.LastSaved_ApplicationVendor.Set(new FbxString("Epic Games")); SceneInfo.LastSaved_ApplicationName.Set(new FbxString("Unreal Engine")); SceneInfo.LastSaved_ApplicationVersion.Set(new FbxString("4.18")); FbxAxisSystem.EFrontVector FrontVector = (FbxAxisSystem.EFrontVector)(0 - FbxAxisSystem.EFrontVector.eParityOdd); if (bForceFrontXAxis) { FrontVector = FbxAxisSystem.EFrontVector.eParityEven; } FbxAxisSystem UnrealZUp = new FbxAxisSystem(FbxAxisSystem.EUpVector.eZAxis, FrontVector, FbxAxisSystem.ECoordSystem.eRightHanded); //const FbxAxisSystem UnrealZUp(FbxAxisSystem.EUpVector, FrontVector, FbxAxisSystem::eRightHanded); Scene.GetGlobalSettings().SetAxisSystem(FbxAxisSystem.Max); Scene.GetGlobalSettings().SetOriginalUpAxis(FbxAxisSystem.Max); Scene.GetGlobalSettings().SetSystemUnit(FbxSystemUnit.cm); Scene.SetSceneInfo(SceneInfo); // setup anim stack AnimStack = FbxAnimStack.Create(Scene, "Unreal Take"); //KFbxSet<KTime>(AnimStack.LocalStart, KTIME_ONE_SECOND); AnimStack.Description.Set((new FbxString("Animation Take for Unreal."))); // this take contains one base layer. In fact having at least one layer is mandatory. AnimLayer = FbxAnimLayer.Create(Scene, "Base Layer"); AnimStack.AddMember(AnimLayer); //if(Mathf) }
/// <summary> /// Export all the objects in the set. /// Return the number of objects in the set that we exported. /// </summary> public int ExportAll(IEnumerable <UnityEngine.Object> unityExportSet) { // Create the FBX manager using (var fbxManager = FbxManager.Create()) { // Configure IO settings. fbxManager.SetIOSettings(FbxIOSettings.Create(fbxManager, Globals.IOSROOT)); // Create the exporter var fbxExporter = FbxExporter.Create(fbxManager, "Exporter"); // Initialize the exporter. int fileFormat = fbxManager.GetIOPluginRegistry().FindWriterIDByDescription("FBX ascii (*.fbx)"); bool status = fbxExporter.Initialize(LastFilePath, fileFormat, fbxManager.GetIOSettings()); // Check that initialization of the fbxExporter was successful if (!status) { return(0); } // By default, FBX exports in its most recent version. You might want to specify // an older version for compatibility with other applications. fbxExporter.SetFileExportVersion("FBX201400"); // Create a scene var fbxScene = FbxScene.Create(fbxManager, "Scene"); // create scene info FbxDocumentInfo fbxSceneInfo = FbxDocumentInfo.Create(fbxManager, "SceneInfo"); // set some scene info values fbxSceneInfo.mTitle = Title; fbxSceneInfo.mSubject = Subject; fbxSceneInfo.mAuthor = "Unity Technologies"; fbxSceneInfo.mRevision = "1.0"; fbxSceneInfo.mKeywords = Keywords; fbxSceneInfo.mComment = Comments; fbxScene.SetSceneInfo(fbxSceneInfo); var fbxSettings = fbxScene.GetGlobalSettings(); fbxSettings.SetSystemUnit(FbxSystemUnit.m); // Unity unit is meters // The Unity axis system has Y up, Z forward, X to the right. // Export as Maya axis system. var axisSystem = new FbxAxisSystem(FbxAxisSystem.MayaYUp); fbxSettings.SetAxisSystem(axisSystem); FbxNode fbxRootNode = fbxScene.GetRootNode(); // export set of objects foreach (var obj in unityExportSet) { var unityGo = GetGameObject(obj); if (unityGo) { this.ExportComponents(unityGo, fbxScene, fbxRootNode); } } // Export the scene to the file. status = fbxExporter.Export(fbxScene); // cleanup fbxScene.Destroy(); fbxExporter.Destroy(); return(status == true ? NumNodes : 0); } }
public FbxAxisSystem GetAxisSystem() { FbxAxisSystem ret = new FbxAxisSystem(FbxWrapperNativePINVOKE.FbxGlobalSettings_GetAxisSystem(swigCPtr), true); return(ret); }
static bool LoadFBX(ImportContext context, string virtualFileName, out List <MeshData> geometries) { geometries = null; var settings = context.settings; ImportFBX.LoadNativeLibrary(); FbxManager manager = null; FbxIOSettings setting = null; FbxImporter importer = null; FbxScene scene = null; try { manager = FbxManager.Create(); setting = FbxIOSettings.Create(manager, "IOSRoot"); manager.SetIOSettings(setting); importer = FbxImporter.Create(manager, ""); var realFileName = VirtualPathUtility.GetRealPathByVirtual(virtualFileName); //VirtualFileStream stream = null; //ToDo : FromStream bool status; if (!string.IsNullOrEmpty(realFileName) && File.Exists(realFileName)) { status = importer.Initialize(realFileName, -1, setting); } else { return(false); //throw new NotImplementedException(); //ToDo : .... //stream = VirtualFile.Open( settings.virtualFileName ); //FbxStream fbxStream = null; //SWIGTYPE_p_void streamData = null; //status = impoter.Initialize( fbxStream, streamData, -1, setting ); } if (!status) { return(false); } scene = FbxScene.Create(manager, "scene1"); status = importer.Import(scene); if (!status) { return(false); } //convert axis if (context.settings.component.ForceFrontXAxis) { //Через такой конструктор не получится создать такие же оси как EPreDefinedAxisSystem.eMax - Front Axis имеет обратное направление, а направление задать нельзя. //new FbxAxisSystem( FbxAxisSystem.EUpVector.eZAxis, FbxAxisSystem.EFrontVector.eParityOdd, FbxAxisSystem.ECoordSystem.eRightHanded ); //FromFBX Docs: //The enum values ParityEven and ParityOdd denote the first one and the second one of the remain two axes in addition to the up axis. //For example if the up axis is X, the remain two axes will be Y And Z, so the ParityEven is Y, and the ParityOdd is Z ; //We desire to convert the scene from Y-Up to Z-Up. Using the predefined axis system: Max (UpVector = +Z, FrontVector = -Y, CoordSystem = +X (RightHanded)) var maxAxisSystem = new FbxAxisSystem(FbxAxisSystem.EPreDefinedAxisSystem.eMax); if (!scene.GetGlobalSettings().GetAxisSystem().eq(maxAxisSystem)) { maxAxisSystem.ConvertScene(scene); //No conversion will take place if the scene current axis system is equal to the new one. So condition can be removed. } } //convert units if (!scene.GetGlobalSettings().GetSystemUnit().eq(FbxSystemUnit.m)) { FbxSystemUnit.m.ConvertScene(scene); } var additionalTransform = new Matrix4(settings.component.Rotation.Value.ToMatrix3() * Matrix3.FromScale(settings.component.Scale), settings.component.Position); var options = new ImportOptions { NormalsOptions = NormalsAndTangentsLoadOptions.FromFileIfPresentOrCalculate, TangentsOptions = NormalsAndTangentsLoadOptions.FromFileIfPresentOrCalculate, ImportPostProcessFlags = ImportPostProcessFlags.FixInfacingNormals }; options.ImportPostProcessFlags |= ImportPostProcessFlags.SmoothNormals | ImportPostProcessFlags.SmoothTangents; if (context.settings.component.FlipUVs) { options.ImportPostProcessFlags |= ImportPostProcessFlags.FlipUVs; } //if( importContext.settings.component.MergeMeshGeometries ) // options.ImportPostProcessFlags |= ImportPostProcessFlags.MergeGeometriesByMaterials; var sceneLoader = new SceneLoader(); sceneLoader.Load(scene, manager, options, additionalTransform); geometries = sceneLoader.Geometries; //foreach( var geometry in sceneLoader.Geometries ) // ImportGeometry( context, destinationMesh, geometry ); ////check is it a billboard //MeshGetIsBillboard( context, destinationMesh ); //stream?.Dispose(); } finally { //Особенности удаления. //Создается через функцию: impoter = FbxImporter.Create(manager, ""); //В таких случаях(создание не через конструктор, а возврат указателя из функции) SWIG задает флажок что объект не владеет ссылкой, поэтому Dispose ничего не делает. //Хотя в SWIG можно задать в конфигурации: %newobject FbxImporter::Create; Тогда объект будет владеть ссылкой. Но все равно в С++ наследники FbxObject не имеют public destructor //поэтому в Dispose вставлен: throw new MethodAccessException("C++ destructor does not have public access"). Поэтому удалять только через Destroy. try { scene?.Destroy(); } catch { } try { importer?.Destroy(); } catch { } try { setting?.Destroy(); } catch { } try { manager?.Destroy(); } catch { } } return(true); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FbxAxisSystem obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public bool GetAxisInfo(FbxAxisSystem pAxisSystem, FbxSystemUnit pSystemUnits) { bool ret = fbx_wrapperPINVOKE.FbxImporter_GetAxisInfo(swigCPtr, FbxAxisSystem.getCPtr(pAxisSystem), FbxSystemUnit.getCPtr(pSystemUnits)); return(ret); }
static void ImportScene(ImportContext context) { var settings = context.settings; var scene = context.scene; if (context.settings.component.ForceFrontXAxis) { //Через такой конструктор не получится создать такие же оси как EPreDefinedAxisSystem.eMax - Front Axis имеет обратное направление, а направление задать нельзя. //new FbxAxisSystem( FbxAxisSystem.EUpVector.eZAxis, FbxAxisSystem.EFrontVector.eParityOdd, FbxAxisSystem.ECoordSystem.eRightHanded ); //FromFBX Docs: //The enum values ParityEven and ParityOdd denote the first one and the second one of the remain two axes in addition to the up axis. //For example if the up axis is X, the remain two axes will be Y And Z, so the ParityEven is Y, and the ParityOdd is Z ; //We desire to convert the scene from Y-Up to Z-Up. Using the predefined axis system: Max (UpVector = +Z, FrontVector = -Y, CoordSystem = +X (RightHanded)) var maxAxisSystem = new FbxAxisSystem(FbxAxisSystem.EPreDefinedAxisSystem.eMax); if (!scene.GetGlobalSettings().GetAxisSystem().eq(maxAxisSystem)) { maxAxisSystem.ConvertScene(scene); //No conversion will take place if the scene current axis system is equal to the new one. So condition can be removed. } } //convert units if (!scene.GetGlobalSettings().GetSystemUnit().eq(FbxSystemUnit.m)) { FbxSystemUnit.m.ConvertScene(scene); } //get materials data var materialsData = GetMaterialsData(context); //create Materials group context.materialsGroup = context.settings.component.GetComponent("Materials"); if (context.materialsGroup == null /*&& materialsData.Count != 0*/ && settings.updateMaterials) { context.materialsGroup = context.settings.component.CreateComponent <Component>(); context.materialsGroup.Name = "Materials"; } //create materials foreach (var data in materialsData) { Component_Material material = null; if (context.settings.updateMaterials) { material = CreateMaterial(context.materialsGroup, data); } else { if (context.materialsGroup != null) { material = context.materialsGroup.GetComponent(data.Name) as Component_Material; } } if (material != null) { context.materialByIndex.Add(data.Index, material); } } //------------------------- var additionalTransform = new Matrix4(settings.component.Rotation.Value.ToMatrix3() * Matrix3.FromScale(settings.component.Scale), settings.component.Position); var options = new ImportOptions { NormalsOptions = NormalsAndTangentsLoadOptions.FromFileIfPresentOrCalculate, TangentsOptions = NormalsAndTangentsLoadOptions.FromFileIfPresentOrCalculate, ImportPostProcessFlags = ImportPostProcessFlags.FixInfacingNormals }; options.ImportPostProcessFlags |= ImportPostProcessFlags.SmoothNormals | ImportPostProcessFlags.SmoothTangents; if (context.settings.component.FlipUVs) { options.ImportPostProcessFlags |= ImportPostProcessFlags.FlipUVs; } var sceneLoader = new SceneLoader(); var mode = settings.component.Mode.Value; if (mode == Component_Import3D.ModeEnum.Auto) { mode = Component_Import3D.ModeEnum.OneMesh; } //create one mesh (OneMesh mode) if (mode == Component_Import3D.ModeEnum.OneMesh && settings.updateMeshes) { sceneLoader.Load(scene, context.manager, options, additionalTransform); Component_Skeleton skeletonComponent = CreateSkeletonComponent(context, sceneLoader.Skeleton, out int[] newIndexFromOldIndex, out SkeletonBone[] oldBoneFromNewIndex, additionalTransform);
public virtual bool GetAxisInfo(FbxAxisSystem arg0, FbxSystemUnit arg1) { bool ret = fbx_wrapperPINVOKE.FbxReader_GetAxisInfo(swigCPtr, FbxAxisSystem.getCPtr(arg0), FbxSystemUnit.getCPtr(arg1)); return(ret); }